More cleanups

Change-Id: Id5967944b949a2aec57e4fe9fdcdc04c11b8c35a
This commit is contained in:
John Reck
2014-06-27 14:45:25 -07:00
parent 81af3aef9a
commit 918ad523b2
11 changed files with 43 additions and 141 deletions

View File

@@ -122,16 +122,8 @@ final class HardwareLayer {
/**
* Indicates that this layer has lost its texture.
*/
public void detachSurfaceTexture(final SurfaceTexture surface) {
mRenderer.safelyRun(new Runnable() {
@Override
public void run() {
surface.detachFromGLContext();
// SurfaceTexture owns the texture name and detachFromGLContext
// should have deleted it
nOnTextureDestroyed(mFinalizer.get());
}
});
public void detachSurfaceTexture() {
mRenderer.detachSurfaceTexture(mFinalizer.get());
}
public long getLayer() {
@@ -148,21 +140,10 @@ final class HardwareLayer {
mRenderer.pushLayerUpdate(this);
}
/**
* This should only be used by HardwareRenderer! Do not call directly
*/
SurfaceTexture createSurfaceTexture() {
SurfaceTexture st = new SurfaceTexture(nGetTexName(mFinalizer.get()));
nSetSurfaceTexture(mFinalizer.get(), st, true);
return st;
}
static HardwareLayer adoptTextureLayer(HardwareRenderer renderer, long layer) {
return new HardwareLayer(renderer, layer);
}
private static native void nOnTextureDestroyed(long layerUpdater);
private static native boolean nPrepare(long layerUpdater, int width, int height, boolean isOpaque);
private static native void nSetLayerPaint(long layerUpdater, long paint);
private static native void nSetTransform(long layerUpdater, long matrix);

View File

@@ -245,15 +245,10 @@ public abstract class HardwareRenderer {
abstract void invalidate(Surface surface);
/**
* This method ensures the hardware renderer is in a valid state
* before executing the specified action.
*
* This method will attempt to set a valid state even if the window
* the renderer is attached to was destroyed.
*
* @return true if the action was run
* Detaches the layer's surface texture from the GL context and releases
* the texture id
*/
abstract boolean safelyRun(Runnable action);
abstract void detachSurfaceTexture(long hardwareLayer);
/**
* Setup the hardware renderer for drawing. This is called whenever the
@@ -315,8 +310,6 @@ public abstract class HardwareRenderer {
* as soon as possible.
*
* @param layer The hardware layer that needs an update
*
* @see #flushLayerUpdates()
*/
abstract void pushLayerUpdate(HardwareLayer layer);
@@ -326,13 +319,6 @@ public abstract class HardwareRenderer {
*/
abstract void onLayerDestroyed(HardwareLayer layer);
/**
* Forces all enqueued layer updates to be executed immediately.
*
* @see #pushLayerUpdate(HardwareLayer)
*/
abstract void flushLayerUpdates();
/**
* Interface used to receive callbacks whenever a view is drawn by
* a hardware renderer instance.
@@ -374,16 +360,6 @@ public abstract class HardwareRenderer {
*/
abstract HardwareLayer createTextureLayer();
/**
* Creates a new {@link SurfaceTexture} that can be used to render into the
* specified hardware layer.
*
* @param layer The layer to render into using a {@link android.graphics.SurfaceTexture}
*
* @return A {@link SurfaceTexture}
*/
abstract SurfaceTexture createSurfaceTexture(HardwareLayer layer);
abstract boolean copyLayerInto(HardwareLayer layer, Bitmap bitmap);
/**

View File

@@ -122,8 +122,7 @@ public class TextureView extends View {
private int mSaveCount;
private final Object[] mNativeWindowLock = new Object[0];
// Used from native code, do not write!
@SuppressWarnings({"UnusedDeclaration"})
// Set by native code, do not write!
private long mNativeWindow;
/**
@@ -142,7 +141,6 @@ public class TextureView extends View {
* @param context The context to associate this view with.
* @param attrs The attributes of the XML tag that is inflating the view.
*/
@SuppressWarnings({"UnusedDeclaration"})
public TextureView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
@@ -157,7 +155,6 @@ public class TextureView extends View {
* reference to a style resource that supplies default values for
* the view. Can be 0 to not look for defaults.
*/
@SuppressWarnings({"UnusedDeclaration"})
public TextureView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
@@ -176,7 +173,6 @@ public class TextureView extends View {
* defStyleAttr is 0 or can not be found in the theme. Can be 0
* to not look for defaults.
*/
@SuppressWarnings({"UnusedDeclaration"})
public TextureView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
@@ -234,7 +230,7 @@ public class TextureView extends View {
private void destroySurface() {
if (mLayer != null) {
mLayer.detachSurfaceTexture(mSurface);
mLayer.detachSurfaceTexture();
boolean shouldRelease = true;
if (mListener != null) {
@@ -362,7 +358,8 @@ public class TextureView extends View {
mLayer = mAttachInfo.mHardwareRenderer.createTextureLayer();
if (!mUpdateSurface) {
// Create a new SurfaceTexture for the layer.
mSurface = mAttachInfo.mHardwareRenderer.createSurfaceTexture(mLayer);
mSurface = new SurfaceTexture(false);
mLayer.setSurfaceTexture(mSurface);
}
mSurface.setDefaultBufferSize(getWidth(), getHeight());
nCreateNativeWindow(mSurface);

View File

@@ -19,8 +19,6 @@ package android.view;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.graphics.SurfaceTexture;
import android.graphics.drawable.Drawable;
import android.os.IBinder;
import android.os.RemoteException;
@@ -35,9 +33,6 @@ import android.view.View.AttachInfo;
import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
/**
@@ -152,9 +147,8 @@ public class ThreadedRenderer extends HardwareRenderer {
}
@Override
boolean safelyRun(Runnable action) {
nRunWithGlContext(mNativeProxy, action);
return true;
void detachSurfaceTexture(long hardwareLayer) {
nDetachSurfaceTexture(mNativeProxy, hardwareLayer);
}
@Override
@@ -269,18 +263,6 @@ public class ThreadedRenderer extends HardwareRenderer {
return HardwareLayer.adoptTextureLayer(this, layer);
}
@Override
SurfaceTexture createSurfaceTexture(final HardwareLayer layer) {
final SurfaceTexture[] ret = new SurfaceTexture[1];
nRunWithGlContext(mNativeProxy, new Runnable() {
@Override
public void run() {
ret[0] = layer.createSurfaceTexture();
}
});
return ret[0];
}
@Override
boolean copyLayerInto(final HardwareLayer layer, final Bitmap bitmap) {
return nCopyLayerInto(mNativeProxy,
@@ -292,11 +274,6 @@ public class ThreadedRenderer extends HardwareRenderer {
nPushLayerUpdate(mNativeProxy, layer.getDeferredLayerUpdater());
}
@Override
void flushLayerUpdates() {
// TODO: Figure out what this should do or remove it
}
@Override
void onLayerDestroyed(HardwareLayer layer) {
nCancelLayerUpdate(mNativeProxy, layer.getDeferredLayerUpdater());
@@ -415,7 +392,6 @@ public class ThreadedRenderer extends HardwareRenderer {
private static native void nSetOpaque(long nativeProxy, boolean opaque);
private static native int nSyncAndDrawFrame(long nativeProxy,
long frameTimeNanos, long recordDuration, float density);
private static native void nRunWithGlContext(long nativeProxy, Runnable runnable);
private static native void nDestroyCanvasAndSurface(long nativeProxy);
private static native void nInvokeFunctor(long functor, boolean waitForCompletion);
@@ -425,6 +401,7 @@ public class ThreadedRenderer extends HardwareRenderer {
private static native boolean nCopyLayerInto(long nativeProxy, long layer, long bitmap);
private static native void nPushLayerUpdate(long nativeProxy, long layer);
private static native void nCancelLayerUpdate(long nativeProxy, long layer);
private static native void nDetachSurfaceTexture(long nativeProxy, long layer);
private static native void nFlushCaches(long nativeProxy, int flushMode);

View File

@@ -640,17 +640,6 @@ public final class ViewRootImpl implements ViewParent,
// TODO Implement
}
void flushHardwareLayerUpdates() {
if (mAttachInfo.mHardwareRenderer != null && mAttachInfo.mHardwareRenderer.isEnabled()) {
mAttachInfo.mHardwareRenderer.flushLayerUpdates();
}
}
void dispatchFlushHardwareLayerUpdates() {
mHandler.removeMessages(MSG_FLUSH_LAYER_UPDATES);
mHandler.sendMessageAtFrontOfQueue(mHandler.obtainMessage(MSG_FLUSH_LAYER_UPDATES));
}
public void detachFunctor(long functor) {
// TODO: Make the resize buffer some other way to not need this block
mBlockResizeBuffer = true;
@@ -2999,8 +2988,7 @@ public final class ViewRootImpl implements ViewParent,
private final static int MSG_DISPATCH_DONE_ANIMATING = 22;
private final static int MSG_INVALIDATE_WORLD = 23;
private final static int MSG_WINDOW_MOVED = 24;
private final static int MSG_FLUSH_LAYER_UPDATES = 25;
private final static int MSG_SYNTHESIZE_INPUT_EVENT = 26;
private final static int MSG_SYNTHESIZE_INPUT_EVENT = 25;
final class ViewRootHandler extends Handler {
@Override
@@ -3048,8 +3036,6 @@ public final class ViewRootImpl implements ViewParent,
return "MSG_DISPATCH_DONE_ANIMATING";
case MSG_WINDOW_MOVED:
return "MSG_WINDOW_MOVED";
case MSG_FLUSH_LAYER_UPDATES:
return "MSG_FLUSH_LAYER_UPDATES";
case MSG_SYNTHESIZE_INPUT_EVENT:
return "MSG_SYNTHESIZE_INPUT_EVENT";
}
@@ -3277,9 +3263,6 @@ public final class ViewRootImpl implements ViewParent,
invalidateWorld(mView);
}
} break;
case MSG_FLUSH_LAYER_UPDATES: {
flushHardwareLayerUpdates();
} break;
}
}
}

View File

@@ -43,12 +43,6 @@ using namespace uirenderer;
#ifdef USE_OPENGL_RENDERER
static void android_view_HardwareLayer_onTextureDestroyed(JNIEnv* env, jobject clazz,
jlong layerUpdaterPtr) {
DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
layer->backingLayer()->clearTexture();
}
static jboolean android_view_HardwareLayer_prepare(JNIEnv* env, jobject clazz,
jlong layerUpdaterPtr, jint width, jint height, jboolean isOpaque) {
DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerUpdaterPtr);
@@ -110,8 +104,6 @@ const char* const kClassPathName = "android/view/HardwareLayer";
static JNINativeMethod gMethods[] = {
#ifdef USE_OPENGL_RENDERER
{ "nOnTextureDestroyed", "(J)V", (void*) android_view_HardwareLayer_onTextureDestroyed },
{ "nPrepare", "(JIIZ)Z", (void*) android_view_HardwareLayer_prepare },
{ "nSetLayerPaint", "(JJ)V", (void*) android_view_HardwareLayer_setLayerPaint },
{ "nSetTransform", "(JJ)V", (void*) android_view_HardwareLayer_setTransform },

View File

@@ -47,8 +47,6 @@ namespace android {
using namespace android::uirenderer;
using namespace android::uirenderer::renderthread;
static jmethodID gRunnableMethod;
static JNIEnv* getenv(JavaVM* vm) {
JNIEnv* env;
if (vm->GetEnv(reinterpret_cast<void**>(&env), JNI_VERSION_1_6) != JNI_OK) {
@@ -57,25 +55,6 @@ static JNIEnv* getenv(JavaVM* vm) {
return env;
}
class JavaTask : public RenderTask {
public:
JavaTask(JNIEnv* env, jobject jrunnable) {
env->GetJavaVM(&mVm);
mRunnable = env->NewGlobalRef(jrunnable);
}
virtual void run() {
JNIEnv* env = getenv(mVm);
env->CallVoidMethod(mRunnable, gRunnableMethod);
env->DeleteGlobalRef(mRunnable);
delete this;
};
private:
JavaVM* mVm;
jobject mRunnable;
};
class OnFinishedEvent {
public:
OnFinishedEvent(BaseRenderNodeAnimator* animator, AnimationListener* listener)
@@ -276,13 +255,6 @@ static void android_view_ThreadedRenderer_invokeFunctor(JNIEnv* env, jobject cla
RenderProxy::invokeFunctor(functor, waitForCompletion);
}
static void android_view_ThreadedRenderer_runWithGlContext(JNIEnv* env, jobject clazz,
jlong proxyPtr, jobject jrunnable) {
RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
RenderTask* task = new JavaTask(env, jrunnable);
proxy->runWithGlContext(task);
}
static jlong android_view_ThreadedRenderer_createDisplayListLayer(JNIEnv* env, jobject clazz,
jlong proxyPtr, jint width, jint height) {
RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
@@ -319,6 +291,13 @@ static void android_view_ThreadedRenderer_cancelLayerUpdate(JNIEnv* env, jobject
proxy->cancelLayerUpdate(layer);
}
static void android_view_ThreadedRenderer_detachSurfaceTexture(JNIEnv* env, jobject clazz,
jlong proxyPtr, jlong layerPtr) {
RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
DeferredLayerUpdater* layer = reinterpret_cast<DeferredLayerUpdater*>(layerPtr);
proxy->detachSurfaceTexture(layer);
}
static void android_view_ThreadedRenderer_flushCaches(JNIEnv* env, jobject clazz,
jlong proxyPtr, jint flushMode) {
RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr);
@@ -380,12 +359,12 @@ static JNINativeMethod gMethods[] = {
{ "nSyncAndDrawFrame", "(JJJF)I", (void*) android_view_ThreadedRenderer_syncAndDrawFrame },
{ "nDestroyCanvasAndSurface", "(J)V", (void*) android_view_ThreadedRenderer_destroyCanvasAndSurface },
{ "nInvokeFunctor", "(JZ)V", (void*) android_view_ThreadedRenderer_invokeFunctor },
{ "nRunWithGlContext", "(JLjava/lang/Runnable;)V", (void*) android_view_ThreadedRenderer_runWithGlContext },
{ "nCreateDisplayListLayer", "(JII)J", (void*) android_view_ThreadedRenderer_createDisplayListLayer },
{ "nCreateTextureLayer", "(J)J", (void*) android_view_ThreadedRenderer_createTextureLayer },
{ "nCopyLayerInto", "(JJJ)Z", (void*) android_view_ThreadedRenderer_copyLayerInto },
{ "nPushLayerUpdate", "(JJ)V", (void*) android_view_ThreadedRenderer_pushLayerUpdate },
{ "nCancelLayerUpdate", "(JJ)V", (void*) android_view_ThreadedRenderer_cancelLayerUpdate },
{ "nDetachSurfaceTexture", "(JJ)V", (void*) android_view_ThreadedRenderer_detachSurfaceTexture },
{ "nFlushCaches", "(JI)V", (void*) android_view_ThreadedRenderer_flushCaches },
{ "nFence", "(J)V", (void*) android_view_ThreadedRenderer_fence },
{ "nNotifyFramePending", "(J)V", (void*) android_view_ThreadedRenderer_notifyFramePending },
@@ -396,11 +375,6 @@ static JNINativeMethod gMethods[] = {
};
int register_android_view_ThreadedRenderer(JNIEnv* env) {
#ifdef USE_OPENGL_RENDERER
jclass cls = env->FindClass("java/lang/Runnable");
gRunnableMethod = env->GetMethodID(cls, "run", "()V");
env->DeleteLocalRef(cls);
#endif
return AndroidRuntime::registerNativeMethods(env, kClassPathName, gMethods, NELEM(gMethods));
}

View File

@@ -119,5 +119,13 @@ void DeferredLayerUpdater::doUpdateTexImage() {
}
}
void DeferredLayerUpdater::detachSurfaceTexture() {
if (mSurfaceTexture.get()) {
mSurfaceTexture->detachFromContext();
mSurfaceTexture = 0;
mLayer->clearTexture();
}
}
} /* namespace uirenderer */
} /* namespace android */

View File

@@ -81,6 +81,8 @@ public:
return mLayer;
}
ANDROID_API void detachSurfaceTexture();
private:
// Generic properties
uint32_t mWidth;

View File

@@ -301,6 +301,17 @@ void RenderProxy::cancelLayerUpdate(DeferredLayerUpdater* layer) {
mDrawFrameTask.removeLayerUpdate(layer);
}
CREATE_BRIDGE1(detachSurfaceTexture, DeferredLayerUpdater* layer) {
args->layer->detachSurfaceTexture();
return NULL;
}
void RenderProxy::detachSurfaceTexture(DeferredLayerUpdater* layer) {
SETUP_TASK(detachSurfaceTexture);
args->layer = layer;
postAndWait(task);
}
CREATE_BRIDGE2(flushCaches, CanvasContext* context, Caches::FlushMode flushMode) {
args->context->flushCaches(args->flushMode);
return NULL;

View File

@@ -83,6 +83,7 @@ public:
ANDROID_API bool copyLayerInto(DeferredLayerUpdater* layer, SkBitmap* bitmap);
ANDROID_API void pushLayerUpdate(DeferredLayerUpdater* layer);
ANDROID_API void cancelLayerUpdate(DeferredLayerUpdater* layer);
ANDROID_API void detachSurfaceTexture(DeferredLayerUpdater* layer);
ANDROID_API void flushCaches(Caches::FlushMode flushMode);