From 87d429262b31ad003069ffb0045ce2f6b59d4df9 Mon Sep 17 00:00:00 2001 From: Leon Scroggins III Date: Fri, 8 May 2020 15:40:19 -0400 Subject: [PATCH] Move TextureLayer into android.graphics Bug: 155905258 Test: make and boot It is tightly integrated with android.graphics.HardwareRenderer, and this follows on I30d34055b6870dc1039f190a88f4a747cee17300, which moved the native component into android_graphics_TextureLayer.cpp, and Ifa044281a3c36cbc1b413175711e9b172cda640f, which registers its JNI along with other graphics classes. Make TextureLayer AutoCloseable, replacing destroy() with close(). Add annotations where appropriate. Change-Id: I1b146ff02a20751246636144c88fe6f8eec43514 --- core/java/android/view/TextureView.java | 3 +- .../android/graphics/HardwareRenderer.java | 1 - .../android/graphics/RecordingCanvas.java | 5 +-- .../java/android/graphics}/TextureLayer.java | 37 +++++++++---------- libs/hwui/apex/jni_runtime.cpp | 4 +- .../jni/android_graphics_TextureLayer.cpp | 4 +- 6 files changed, 26 insertions(+), 28 deletions(-) rename {core/java/android/view => graphics/java/android/graphics}/TextureLayer.java (84%) diff --git a/core/java/android/view/TextureView.java b/core/java/android/view/TextureView.java index 277b872a8cd03..a02070a21ac8d 100644 --- a/core/java/android/view/TextureView.java +++ b/core/java/android/view/TextureView.java @@ -27,6 +27,7 @@ import android.graphics.Paint; import android.graphics.RecordingCanvas; import android.graphics.Rect; import android.graphics.SurfaceTexture; +import android.graphics.TextureLayer; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Log; @@ -247,7 +248,7 @@ public class TextureView extends View { private void destroyHardwareLayer() { if (mLayer != null) { mLayer.detachSurfaceTexture(); - mLayer.destroy(); + mLayer.close(); mLayer = null; mMatrixChanged = true; } diff --git a/graphics/java/android/graphics/HardwareRenderer.java b/graphics/java/android/graphics/HardwareRenderer.java index 87060ca57e977..6dd1f99399894 100644 --- a/graphics/java/android/graphics/HardwareRenderer.java +++ b/graphics/java/android/graphics/HardwareRenderer.java @@ -39,7 +39,6 @@ import android.view.NativeVectorDrawableAnimator; import android.view.PixelCopy; import android.view.Surface; import android.view.SurfaceHolder; -import android.view.TextureLayer; import android.view.animation.AnimationUtils; import java.io.File; diff --git a/graphics/java/android/graphics/RecordingCanvas.java b/graphics/java/android/graphics/RecordingCanvas.java index 88b32c867f363..22aacdecaf5d5 100644 --- a/graphics/java/android/graphics/RecordingCanvas.java +++ b/graphics/java/android/graphics/RecordingCanvas.java @@ -19,7 +19,6 @@ package android.graphics; import android.annotation.NonNull; import android.annotation.Nullable; import android.util.Pools.SynchronizedPool; -import android.view.TextureLayer; import dalvik.annotation.optimization.CriticalNative; import dalvik.annotation.optimization.FastNative; @@ -214,9 +213,9 @@ public final class RecordingCanvas extends BaseRecordingCanvas { * Draws the specified layer onto this canvas. * * @param layer The layer to composite on this canvas - * @hide + * @hide TODO: Make this a SystemApi for b/155905258 */ - public void drawTextureLayer(TextureLayer layer) { + public void drawTextureLayer(@NonNull TextureLayer layer) { nDrawTextureLayer(mNativeCanvasWrapper, layer.getLayerHandle()); } diff --git a/core/java/android/view/TextureLayer.java b/graphics/java/android/graphics/TextureLayer.java similarity index 84% rename from core/java/android/view/TextureLayer.java rename to graphics/java/android/graphics/TextureLayer.java index abf4d9f5c3df0..ac1bd69020622 100644 --- a/core/java/android/view/TextureLayer.java +++ b/graphics/java/android/graphics/TextureLayer.java @@ -14,14 +14,11 @@ * limitations under the License. */ -package android.view; +package android.graphics; +import android.annotation.NonNull; import android.annotation.Nullable; -import android.graphics.Bitmap; -import android.graphics.HardwareRenderer; -import android.graphics.Matrix; -import android.graphics.Paint; -import android.graphics.SurfaceTexture; +import android.view.View; import com.android.internal.util.VirtualRefBasePtr; @@ -30,13 +27,13 @@ import com.android.internal.util.VirtualRefBasePtr; * frame when drawn in a HW accelerated Canvas. This is backed by a DeferredLayerUpdater on * the native side. * - * @hide + * @hide TODO: Make this a SystemApi for b/155905258 */ -public final class TextureLayer { +public final class TextureLayer implements AutoCloseable { private HardwareRenderer mRenderer; private VirtualRefBasePtr mFinalizer; - private TextureLayer(HardwareRenderer renderer, long deferredUpdater) { + private TextureLayer(@NonNull HardwareRenderer renderer, long deferredUpdater) { if (renderer == null || deferredUpdater == 0) { throw new IllegalArgumentException("Either hardware renderer: " + renderer + " or deferredUpdater: " + deferredUpdater + " is invalid"); @@ -61,14 +58,15 @@ public final class TextureLayer { * * @return True if the layer can be rendered into, false otherwise */ - public boolean isValid() { + private boolean isValid() { return mFinalizer != null && mFinalizer.get() != 0; } /** * Destroys resources without waiting for a GC. */ - public void destroy() { + @Override + public void close() { if (!isValid()) { // Already destroyed return; @@ -79,7 +77,7 @@ public final class TextureLayer { mFinalizer = null; } - public long getDeferredLayerUpdater() { + /*package*/ long getDeferredLayerUpdater() { return mFinalizer.get(); } @@ -90,7 +88,7 @@ public final class TextureLayer { * * @return True if the copy was successful, false otherwise */ - public boolean copyInto(Bitmap bitmap) { + public boolean copyInto(@NonNull Bitmap bitmap) { return mRenderer.copyLayerInto(this, bitmap); } @@ -114,7 +112,7 @@ public final class TextureLayer { * * @param matrix The transform to apply to the layer. */ - public void setTransform(Matrix matrix) { + public void setTransform(@NonNull Matrix matrix) { nSetTransform(mFinalizer.get(), matrix.ni()); mRenderer.pushLayerUpdate(this); } @@ -126,11 +124,11 @@ public final class TextureLayer { mRenderer.detachSurfaceTexture(mFinalizer.get()); } - public long getLayerHandle() { + /*package*/ long getLayerHandle() { return mFinalizer.get(); } - public void setSurfaceTexture(SurfaceTexture surface) { + public void setSurfaceTexture(@NonNull SurfaceTexture surface) { nSetSurfaceTexture(mFinalizer.get(), surface); mRenderer.pushLayerUpdate(this); } @@ -140,8 +138,8 @@ public final class TextureLayer { mRenderer.pushLayerUpdate(this); } - /** @hide */ - public static TextureLayer adoptTextureLayer(HardwareRenderer renderer, long layer) { + /*package*/ static TextureLayer adoptTextureLayer(@NonNull HardwareRenderer renderer, + long layer) { return new TextureLayer(renderer, layer); } @@ -149,6 +147,7 @@ public final class TextureLayer { boolean isOpaque); private static native void nSetLayerPaint(long layerUpdater, long paint); private static native void nSetTransform(long layerUpdater, long matrix); - private static native void nSetSurfaceTexture(long layerUpdater, SurfaceTexture surface); + private static native void nSetSurfaceTexture(long layerUpdater, + @NonNull SurfaceTexture surface); private static native void nUpdateSurfaceTexture(long layerUpdater); } diff --git a/libs/hwui/apex/jni_runtime.cpp b/libs/hwui/apex/jni_runtime.cpp index a114e2f421570..b933813550d4b 100644 --- a/libs/hwui/apex/jni_runtime.cpp +++ b/libs/hwui/apex/jni_runtime.cpp @@ -61,6 +61,7 @@ extern int register_android_graphics_Path(JNIEnv* env); extern int register_android_graphics_PathMeasure(JNIEnv* env); extern int register_android_graphics_Picture(JNIEnv*); extern int register_android_graphics_Region(JNIEnv* env); +extern int register_android_graphics_TextureLayer(JNIEnv* env); extern int register_android_graphics_animation_NativeInterpolatorFactory(JNIEnv* env); extern int register_android_graphics_animation_RenderNodeAnimator(JNIEnv* env); extern int register_android_graphics_drawable_AnimatedVectorDrawable(JNIEnv* env); @@ -76,7 +77,6 @@ extern int register_android_graphics_text_LineBreaker(JNIEnv *env); extern int register_android_util_PathParser(JNIEnv* env); extern int register_android_view_DisplayListCanvas(JNIEnv* env); extern int register_android_view_RenderNode(JNIEnv* env); -extern int register_android_view_TextureLayer(JNIEnv* env); extern int register_android_view_ThreadedRenderer(JNIEnv* env); #ifdef NDEBUG @@ -123,6 +123,7 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_graphics_Picture), REG_JNI(register_android_graphics_Region), REG_JNI(register_android_graphics_Shader), + REG_JNI(register_android_graphics_TextureLayer), REG_JNI(register_android_graphics_Typeface), REG_JNI(register_android_graphics_YuvImage), REG_JNI(register_android_graphics_animation_NativeInterpolatorFactory), @@ -140,7 +141,6 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_util_PathParser), REG_JNI(register_android_view_RenderNode), REG_JNI(register_android_view_DisplayListCanvas), - REG_JNI(register_android_view_TextureLayer), REG_JNI(register_android_view_ThreadedRenderer), }; diff --git a/libs/hwui/jni/android_graphics_TextureLayer.cpp b/libs/hwui/jni/android_graphics_TextureLayer.cpp index bd20269d3751d..4dbb24ce43472 100644 --- a/libs/hwui/jni/android_graphics_TextureLayer.cpp +++ b/libs/hwui/jni/android_graphics_TextureLayer.cpp @@ -67,7 +67,7 @@ static void TextureLayer_updateSurfaceTexture(JNIEnv* env, jobject clazz, // JNI Glue // ---------------------------------------------------------------------------- -const char* const kClassPathName = "android/view/TextureLayer"; +const char* const kClassPathName = "android/graphics/TextureLayer"; static const JNINativeMethod gMethods[] = { { "nPrepare", "(JIIZ)Z", (void*) TextureLayer_prepare }, @@ -78,7 +78,7 @@ static const JNINativeMethod gMethods[] = { { "nUpdateSurfaceTexture", "(J)V", (void*) TextureLayer_updateSurfaceTexture }, }; -int register_android_view_TextureLayer(JNIEnv* env) { +int register_android_graphics_TextureLayer(JNIEnv* env) { return RegisterMethodsOrDie(env, kClassPathName, gMethods, NELEM(gMethods)); }