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

Commit 3445e4ee authored by Rob Carr's avatar Rob Carr Committed by Automerger Merge Worker
Browse files

Merge "SurfaceView: Fix overlocking of mSurfaceLock" into tm-dev am: ec6577d1

parents 7c760957 ec6577d1
Loading
Loading
Loading
Loading
+112 −104
Original line number Original line Diff line number Diff line
@@ -720,8 +720,13 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
    private void releaseSurfaces(boolean releaseSurfacePackage) {
    private void releaseSurfaces(boolean releaseSurfacePackage) {
        mSurfaceAlpha = 1f;
        mSurfaceAlpha = 1f;
	
	
        synchronized (mSurfaceControlLock) {
        mSurfaceLock.lock();
        try {
            mSurface.destroy();
            mSurface.destroy();
        } finally {
            mSurfaceLock.unlock();
        }
        synchronized (mSurfaceControlLock) {
            if (mBlastBufferQueue != null) {
            if (mBlastBufferQueue != null) {
                mBlastBufferQueue.destroy();
                mBlastBufferQueue.destroy();
                mBlastBufferQueue = null;
                mBlastBufferQueue = null;
@@ -770,8 +775,6 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
            Transaction surfaceUpdateTransaction) {
            Transaction surfaceUpdateTransaction) {
        boolean realSizeChanged = false;
        boolean realSizeChanged = false;


        mSurfaceLock.lock();
        try {
        mDrawingStopped = !mVisible;
        mDrawingStopped = !mVisible;


        if (DEBUG) Log.i(TAG, System.identityHashCode(this) + " "
        if (DEBUG) Log.i(TAG, System.identityHashCode(this) + " "
@@ -811,7 +814,6 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
            setBufferSize(surfaceUpdateTransaction);
            setBufferSize(surfaceUpdateTransaction);
        }
        }
        if (sizeChanged || creating || !isHardwareAccelerated()) {
        if (sizeChanged || creating || !isHardwareAccelerated()) {

            // Set a window crop when creating the surface or changing its size to
            // Set a window crop when creating the surface or changing its size to
            // crop the buffer to the surface size since the buffer producer may
            // crop the buffer to the surface size since the buffer producer may
            // use SCALING_MODE_SCALE and submit a larger size than the surface
            // use SCALING_MODE_SCALE and submit a larger size than the surface
@@ -849,7 +851,6 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
        }
        }
        applyTransactionOnVriDraw(surfaceUpdateTransaction);
        applyTransactionOnVriDraw(surfaceUpdateTransaction);
        updateEmbeddedAccessibilityMatrix(false);
        updateEmbeddedAccessibilityMatrix(false);

         mSurfaceFrame.left = 0;
         mSurfaceFrame.left = 0;
        mSurfaceFrame.top = 0;
        mSurfaceFrame.top = 0;
        if (translator == null) {
        if (translator == null) {
@@ -866,9 +867,7 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
                || mLastSurfaceHeight != surfaceHeight;
                || mLastSurfaceHeight != surfaceHeight;
        mLastSurfaceWidth = surfaceWidth;
        mLastSurfaceWidth = surfaceWidth;
        mLastSurfaceHeight = surfaceHeight;
        mLastSurfaceHeight = surfaceHeight;
        } finally {

            mSurfaceLock.unlock();
        }
        return realSizeChanged;
        return realSizeChanged;
    }
    }


@@ -1103,21 +1102,30 @@ public class SurfaceView extends View implements ViewRootImpl.SurfaceChangedCall
     *                          Surface for compatibility reasons.
     *                          Surface for compatibility reasons.
     */
     */
    private void copySurface(boolean surfaceControlCreated, boolean bufferSizeChanged) {
    private void copySurface(boolean surfaceControlCreated, boolean bufferSizeChanged) {
        if (surfaceControlCreated) {
            mSurface.copyFrom(mBlastBufferQueue);
        }

        if (bufferSizeChanged && getContext().getApplicationInfo().targetSdkVersion
                < Build.VERSION_CODES.O) {
        // Some legacy applications use the underlying native {@link Surface} object
        // Some legacy applications use the underlying native {@link Surface} object
        // as a key to whether anything has changed. In these cases, updates to the
        // as a key to whether anything has changed. In these cases, updates to the
        // existing {@link Surface} will be ignored when the size changes.
        // existing {@link Surface} will be ignored when the size changes.
        // Therefore, we must explicitly recreate the {@link Surface} in these
        // Therefore, we must explicitly recreate the {@link Surface} in these
        // cases.
        // cases.
        boolean needsWorkaround = bufferSizeChanged &&
            getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.O;
       if (!surfaceControlCreated && !needsWorkaround) {
           return;
       }
       mSurfaceLock.lock();
       try {
           if (surfaceControlCreated) {
               mSurface.copyFrom(mBlastBufferQueue);
           }

           if (needsWorkaround) {
               if (mBlastBufferQueue != null) {
               if (mBlastBufferQueue != null) {
                   mSurface.transferFrom(mBlastBufferQueue.createSurfaceWithHandle());
                   mSurface.transferFrom(mBlastBufferQueue.createSurfaceWithHandle());
               }
               }
           }
           }
       } finally {
           mSurfaceLock.unlock();
       }
    }
    }


    private void setBufferSize(Transaction transaction) {
    private void setBufferSize(Transaction transaction) {