Loading core/java/android/app/ActivityThread.java +1 −0 Original line number Diff line number Diff line Loading @@ -3949,6 +3949,7 @@ public final class ActivityThread { ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); // Cleanup hardware accelerated stuff // TODO: Do we actually want to do this in response to all config changes? WindowManagerGlobal.getInstance().trimLocalMemory(); freeTextLayoutCachesIfNeeded(configDiff); Loading core/java/android/view/GLRenderer.java +9 −32 Original line number Diff line number Diff line Loading @@ -477,17 +477,21 @@ public class GLRenderer extends HardwareRenderer { @Override void flushLayerUpdates() { if (validate()) { mGlCanvas.flushLayerUpdates(); } } @Override HardwareLayer createTextureLayer() { validate(); return HardwareLayer.createTextureLayer(this); } @Override public HardwareLayer createDisplayListLayer(int width, int height) { return HardwareLayer.createRenderLayer(this, width, height); validate(); return HardwareLayer.createDisplayListLayer(this, width, height); } @Override Loading @@ -510,6 +514,9 @@ public class GLRenderer extends HardwareRenderer { @Override boolean copyLayerInto(HardwareLayer layer, Bitmap bitmap) { if (!validate()) { throw new IllegalStateException("Could not acquire hardware rendering context"); } layer.flushChanges(); return GLES20Canvas.nCopyLayer(layer.getLayer(), bitmap.mNativeBitmap); } Loading Loading @@ -537,35 +544,6 @@ public class GLRenderer extends HardwareRenderer { return true; } @Override void destroyLayers(final View view) { if (view != null) { safelyRun(new Runnable() { @Override public void run() { if (mCanvas != null) { mCanvas.clearLayerUpdates(); } destroyHardwareLayer(view); GLES20Canvas.flushCaches(GLES20Canvas.FLUSH_CACHES_LAYERS); } }); } } private static void destroyHardwareLayer(View view) { view.destroyLayer(true); if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; int count = group.getChildCount(); for (int i = 0; i < count; i++) { destroyHardwareLayer(group.getChildAt(i)); } } } @Override void destroyHardwareResources(final View view) { if (view != null) { Loading Loading @@ -1069,7 +1047,6 @@ public class GLRenderer extends HardwareRenderer { return true; } @Override boolean validate() { return checkRenderContext() != SURFACE_STATE_ERROR; } Loading core/java/android/view/HardwareLayer.java +26 −6 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ import android.graphics.SurfaceTexture; */ final class HardwareLayer { private static final int LAYER_TYPE_TEXTURE = 1; private static final int LAYER_TYPE_RENDER = 2; private static final int LAYER_TYPE_DISPLAY_LIST = 2; private HardwareRenderer mRenderer; private Finalizer mFinalizer; Loading Loading @@ -99,6 +99,10 @@ final class HardwareLayer { doDestroyLayerUpdater(); } public long getDeferredLayerUpdater() { return mFinalizer.mDeferredUpdater; } /** * Destroys the deferred layer updater but not the backing layer. The * backing layer is instead returned and is the caller's responsibility Loading @@ -120,7 +124,7 @@ final class HardwareLayer { } public DisplayList startRecording() { assertType(LAYER_TYPE_RENDER); assertType(LAYER_TYPE_DISPLAY_LIST); if (mDisplayList == null) { mDisplayList = DisplayList.create("HardwareLayer"); Loading Loading @@ -172,10 +176,18 @@ final class HardwareLayer { /** * Indicates that this layer has lost its texture. */ public void onTextureDestroyed() { public void detachSurfaceTexture(final SurfaceTexture surface) { assertType(LAYER_TYPE_TEXTURE); mRenderer.safelyRun(new Runnable() { @Override public void run() { surface.detachFromGLContext(); // SurfaceTexture owns the texture name and detachFromGLContext // should have deleted it nOnTextureDestroyed(mFinalizer.mDeferredUpdater); } }); } /** * This exists to minimize impact into the current HardwareLayer paths as Loading Loading @@ -226,12 +238,20 @@ final class HardwareLayer { return new HardwareLayer(renderer, nCreateTextureLayer(), LAYER_TYPE_TEXTURE); } static HardwareLayer adoptTextureLayer(HardwareRenderer renderer, long layer) { return new HardwareLayer(renderer, layer, LAYER_TYPE_TEXTURE); } /** * This should only be used by HardwareRenderer! Do not call directly */ static HardwareLayer createRenderLayer(HardwareRenderer renderer, static HardwareLayer createDisplayListLayer(HardwareRenderer renderer, int width, int height) { return new HardwareLayer(renderer, nCreateRenderLayer(width, height), LAYER_TYPE_RENDER); return new HardwareLayer(renderer, nCreateRenderLayer(width, height), LAYER_TYPE_DISPLAY_LIST); } static HardwareLayer adoptDisplayListLayer(HardwareRenderer renderer, long layer) { return new HardwareLayer(renderer, layer, LAYER_TYPE_DISPLAY_LIST); } /** This also creates the underlying layer */ Loading core/java/android/view/HardwareRenderer.java +0 −16 Original line number Diff line number Diff line Loading @@ -233,13 +233,6 @@ public abstract class HardwareRenderer { */ abstract void updateSurface(Surface surface) throws OutOfResourcesException; /** * Destroys the layers used by the specified view hierarchy. * * @param view The root of the view hierarchy */ abstract void destroyLayers(View view); /** * Destroys all hardware rendering resources associated with the specified * view hierarchy. Loading @@ -256,15 +249,6 @@ public abstract class HardwareRenderer { */ abstract void invalidate(Surface surface); /** * This method should be invoked to ensure the hardware renderer is in * valid state (for instance, to ensure the correct EGL context is bound * to the current thread.) * * @return true if the renderer is now valid, false otherwise */ abstract boolean validate(); /** * This method ensures the hardware renderer is in a valid state * before executing the specified action. Loading core/java/android/view/TextureView.java +2 −24 Original line number Diff line number Diff line Loading @@ -231,26 +231,12 @@ public class TextureView extends View { @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mLayer != null) { boolean success = executeHardwareAction(new Runnable() { @Override public void run() { destroySurface(); } }); if (!success) { Log.w(LOG_TAG, "TextureView was not able to destroy its surface: " + this); } } } private void destroySurface() { if (mLayer != null) { mSurface.detachFromGLContext(); // SurfaceTexture owns the texture name and detachFromGLContext // should have deleted it mLayer.onTextureDestroyed(); mLayer.detachSurfaceTexture(mSurface); boolean shouldRelease = true; if (mListener != null) { Loading Loading @@ -608,14 +594,6 @@ public class TextureView extends View { */ public Bitmap getBitmap(Bitmap bitmap) { if (bitmap != null && isAvailable()) { AttachInfo info = mAttachInfo; if (info != null && info.mHardwareRenderer != null && info.mHardwareRenderer.isEnabled()) { if (!info.mHardwareRenderer.validate()) { throw new IllegalStateException("Could not acquire hardware rendering context"); } } applyUpdate(); applyTransformMatrix(); Loading Loading
core/java/android/app/ActivityThread.java +1 −0 Original line number Diff line number Diff line Loading @@ -3949,6 +3949,7 @@ public final class ActivityThread { ArrayList<ComponentCallbacks2> callbacks = collectComponentCallbacks(false, config); // Cleanup hardware accelerated stuff // TODO: Do we actually want to do this in response to all config changes? WindowManagerGlobal.getInstance().trimLocalMemory(); freeTextLayoutCachesIfNeeded(configDiff); Loading
core/java/android/view/GLRenderer.java +9 −32 Original line number Diff line number Diff line Loading @@ -477,17 +477,21 @@ public class GLRenderer extends HardwareRenderer { @Override void flushLayerUpdates() { if (validate()) { mGlCanvas.flushLayerUpdates(); } } @Override HardwareLayer createTextureLayer() { validate(); return HardwareLayer.createTextureLayer(this); } @Override public HardwareLayer createDisplayListLayer(int width, int height) { return HardwareLayer.createRenderLayer(this, width, height); validate(); return HardwareLayer.createDisplayListLayer(this, width, height); } @Override Loading @@ -510,6 +514,9 @@ public class GLRenderer extends HardwareRenderer { @Override boolean copyLayerInto(HardwareLayer layer, Bitmap bitmap) { if (!validate()) { throw new IllegalStateException("Could not acquire hardware rendering context"); } layer.flushChanges(); return GLES20Canvas.nCopyLayer(layer.getLayer(), bitmap.mNativeBitmap); } Loading Loading @@ -537,35 +544,6 @@ public class GLRenderer extends HardwareRenderer { return true; } @Override void destroyLayers(final View view) { if (view != null) { safelyRun(new Runnable() { @Override public void run() { if (mCanvas != null) { mCanvas.clearLayerUpdates(); } destroyHardwareLayer(view); GLES20Canvas.flushCaches(GLES20Canvas.FLUSH_CACHES_LAYERS); } }); } } private static void destroyHardwareLayer(View view) { view.destroyLayer(true); if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; int count = group.getChildCount(); for (int i = 0; i < count; i++) { destroyHardwareLayer(group.getChildAt(i)); } } } @Override void destroyHardwareResources(final View view) { if (view != null) { Loading Loading @@ -1069,7 +1047,6 @@ public class GLRenderer extends HardwareRenderer { return true; } @Override boolean validate() { return checkRenderContext() != SURFACE_STATE_ERROR; } Loading
core/java/android/view/HardwareLayer.java +26 −6 Original line number Diff line number Diff line Loading @@ -33,7 +33,7 @@ import android.graphics.SurfaceTexture; */ final class HardwareLayer { private static final int LAYER_TYPE_TEXTURE = 1; private static final int LAYER_TYPE_RENDER = 2; private static final int LAYER_TYPE_DISPLAY_LIST = 2; private HardwareRenderer mRenderer; private Finalizer mFinalizer; Loading Loading @@ -99,6 +99,10 @@ final class HardwareLayer { doDestroyLayerUpdater(); } public long getDeferredLayerUpdater() { return mFinalizer.mDeferredUpdater; } /** * Destroys the deferred layer updater but not the backing layer. The * backing layer is instead returned and is the caller's responsibility Loading @@ -120,7 +124,7 @@ final class HardwareLayer { } public DisplayList startRecording() { assertType(LAYER_TYPE_RENDER); assertType(LAYER_TYPE_DISPLAY_LIST); if (mDisplayList == null) { mDisplayList = DisplayList.create("HardwareLayer"); Loading Loading @@ -172,10 +176,18 @@ final class HardwareLayer { /** * Indicates that this layer has lost its texture. */ public void onTextureDestroyed() { public void detachSurfaceTexture(final SurfaceTexture surface) { assertType(LAYER_TYPE_TEXTURE); mRenderer.safelyRun(new Runnable() { @Override public void run() { surface.detachFromGLContext(); // SurfaceTexture owns the texture name and detachFromGLContext // should have deleted it nOnTextureDestroyed(mFinalizer.mDeferredUpdater); } }); } /** * This exists to minimize impact into the current HardwareLayer paths as Loading Loading @@ -226,12 +238,20 @@ final class HardwareLayer { return new HardwareLayer(renderer, nCreateTextureLayer(), LAYER_TYPE_TEXTURE); } static HardwareLayer adoptTextureLayer(HardwareRenderer renderer, long layer) { return new HardwareLayer(renderer, layer, LAYER_TYPE_TEXTURE); } /** * This should only be used by HardwareRenderer! Do not call directly */ static HardwareLayer createRenderLayer(HardwareRenderer renderer, static HardwareLayer createDisplayListLayer(HardwareRenderer renderer, int width, int height) { return new HardwareLayer(renderer, nCreateRenderLayer(width, height), LAYER_TYPE_RENDER); return new HardwareLayer(renderer, nCreateRenderLayer(width, height), LAYER_TYPE_DISPLAY_LIST); } static HardwareLayer adoptDisplayListLayer(HardwareRenderer renderer, long layer) { return new HardwareLayer(renderer, layer, LAYER_TYPE_DISPLAY_LIST); } /** This also creates the underlying layer */ Loading
core/java/android/view/HardwareRenderer.java +0 −16 Original line number Diff line number Diff line Loading @@ -233,13 +233,6 @@ public abstract class HardwareRenderer { */ abstract void updateSurface(Surface surface) throws OutOfResourcesException; /** * Destroys the layers used by the specified view hierarchy. * * @param view The root of the view hierarchy */ abstract void destroyLayers(View view); /** * Destroys all hardware rendering resources associated with the specified * view hierarchy. Loading @@ -256,15 +249,6 @@ public abstract class HardwareRenderer { */ abstract void invalidate(Surface surface); /** * This method should be invoked to ensure the hardware renderer is in * valid state (for instance, to ensure the correct EGL context is bound * to the current thread.) * * @return true if the renderer is now valid, false otherwise */ abstract boolean validate(); /** * This method ensures the hardware renderer is in a valid state * before executing the specified action. Loading
core/java/android/view/TextureView.java +2 −24 Original line number Diff line number Diff line Loading @@ -231,26 +231,12 @@ public class TextureView extends View { @Override protected void onDetachedFromWindow() { super.onDetachedFromWindow(); if (mLayer != null) { boolean success = executeHardwareAction(new Runnable() { @Override public void run() { destroySurface(); } }); if (!success) { Log.w(LOG_TAG, "TextureView was not able to destroy its surface: " + this); } } } private void destroySurface() { if (mLayer != null) { mSurface.detachFromGLContext(); // SurfaceTexture owns the texture name and detachFromGLContext // should have deleted it mLayer.onTextureDestroyed(); mLayer.detachSurfaceTexture(mSurface); boolean shouldRelease = true; if (mListener != null) { Loading Loading @@ -608,14 +594,6 @@ public class TextureView extends View { */ public Bitmap getBitmap(Bitmap bitmap) { if (bitmap != null && isAvailable()) { AttachInfo info = mAttachInfo; if (info != null && info.mHardwareRenderer != null && info.mHardwareRenderer.isEnabled()) { if (!info.mHardwareRenderer.validate()) { throw new IllegalStateException("Could not acquire hardware rendering context"); } } applyUpdate(); applyTransformMatrix(); Loading