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
This commit is contained in:
Leon Scroggins III
2020-05-08 15:40:19 -04:00
parent 737506bbef
commit 87d429262b
6 changed files with 26 additions and 28 deletions

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -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());
}

View File

@@ -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);
}

View File

@@ -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),
};

View File

@@ -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));
}