Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 918ad523 authored by John Reck's avatar John Reck
Browse files

More cleanups

Change-Id: Id5967944b949a2aec57e4fe9fdcdc04c11b8c35a
parent 81af3aef
Loading
Loading
Loading
Loading
+2 −21
Original line number Diff line number Diff line
@@ -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);
+3 −27
Original line number Diff line number Diff line
@@ -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);

    /**
+4 −7
Original line number Diff line number Diff line
@@ -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);
+3 −26
Original line number Diff line number Diff line
@@ -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);

+1 −18
Original line number Diff line number Diff line
@@ -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;
            }
        }
    }
Loading