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

Commit 39cab792 authored by Chavi Weingarten's avatar Chavi Weingarten Committed by Android (Google) Code Review
Browse files

Merge "Screenshot secure layers in ColorFade"

parents 57895c35 3ce0539b
Loading
Loading
Loading
Loading
+1 −33
Original line number Diff line number Diff line
@@ -1968,37 +1968,6 @@ public final class SurfaceControl implements Parcelable {
        return getPhysicalDisplayToken(physicalDisplayIds[0]);
    }

    /**
     * @see SurfaceControl#screenshot(IBinder, Surface, Rect, int, int, boolean, int)
     * @hide
     */
    public static void screenshot(IBinder display, Surface consumer) {
        screenshot(display, consumer, new Rect(), 0, 0, false, 0);
    }

    /**
     * Copy the current screen contents into the provided {@link Surface}
     *
     * @param consumer The {@link Surface} to take the screenshot into.
     * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)
     * @hide
     */
    public static void screenshot(IBinder display, Surface consumer, Rect sourceCrop, int width,
            int height, boolean useIdentityTransform, int rotation) {
        if (consumer == null) {
            throw new IllegalArgumentException("consumer must not be null");
        }

        final ScreenshotHardwareBuffer buffer = screenshotToBuffer(display, sourceCrop, width,
                height, useIdentityTransform, rotation);
        try {
            consumer.attachAndQueueBufferWithColorSpace(buffer.getHardwareBuffer(),
                    buffer.getColorSpace());
        } catch (RuntimeException e) {
            Log.w(TAG, "Failed to take screenshot - " + e.getMessage());
        }
    }

    /**
     * @see SurfaceControl#screenshot(Rect, int, int, boolean, int)}
     * @hide
@@ -2014,8 +1983,7 @@ public final class SurfaceControl implements Parcelable {
     * a software Bitmap using {@link Bitmap#copy(Bitmap.Config, boolean)}
     *
     * CAVEAT: Versions of screenshot that return a {@link Bitmap} can be extremely slow; avoid use
     * unless absolutely necessary; prefer the versions that use a {@link Surface} such as
     * {@link SurfaceControl#screenshot(IBinder, Surface)} or {@link HardwareBuffer} such as
     * unless absolutely necessary; prefer the versions that use a {@link HardwareBuffer} such as
     * {@link SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}.
     *
     * @see SurfaceControl#screenshotToBuffer(IBinder, Rect, int, int, boolean, int)}
+16 −9
Original line number Diff line number Diff line
@@ -491,7 +491,14 @@ final class ColorFade {

                mIsWideColor = SurfaceControl.getActiveColorMode(token)
                        == Display.COLOR_MODE_DISPLAY_P3;
                SurfaceControl.screenshot(token, s);
                SurfaceControl.ScreenshotHardwareBuffer screenshotBuffer =
                        mDisplayManagerInternal.systemScreenshot(mDisplayId);
                s.attachAndQueueBufferWithColorSpace(screenshotBuffer.getHardwareBuffer(),
                        screenshotBuffer.getColorSpace());

                if (screenshotBuffer.containsSecureLayers()) {
                    mTransaction.setSecure(mSurfaceControl, true).apply();
                }
                st.updateTexImage();
                st.getTransformMatrix(mTexMatrix);
            } finally {
@@ -586,7 +593,6 @@ final class ColorFade {
        }

        if (mSurfaceControl == null) {
            Transaction t = new Transaction();
            try {
                final SurfaceControl.Builder builder = new SurfaceControl.Builder(mSurfaceSession)
                        .setName("ColorFade")
@@ -602,15 +608,16 @@ final class ColorFade {
                return false;
            }

            t.setLayerStack(mSurfaceControl, mDisplayLayerStack);
            t.setWindowCrop(mSurfaceControl, mDisplayWidth, mDisplayHeight);
            mTransaction.setLayerStack(mSurfaceControl, mDisplayLayerStack);
            mTransaction.setWindowCrop(mSurfaceControl, mDisplayWidth, mDisplayHeight);
            mSurfaceLayout = new NaturalSurfaceLayout(mDisplayManagerInternal,
                    mDisplayId, mSurfaceControl);
            mSurfaceLayout.onDisplayTransaction(mTransaction);
            mTransaction.apply();

            mSurface = new Surface();
            mSurface.copyFrom(mSurfaceControl);

            mSurfaceLayout = new NaturalSurfaceLayout(mDisplayManagerInternal,
                    mDisplayId, mSurfaceControl);
            mSurfaceLayout.onDisplayTransaction(t);
            t.apply();
        }
        return true;
    }
@@ -652,7 +659,7 @@ final class ColorFade {
        if (mSurfaceControl != null) {
            mSurfaceLayout.dispose();
            mSurfaceLayout = null;
            new Transaction().remove(mSurfaceControl).apply();
            mTransaction.remove(mSurfaceControl).apply();
            mSurface.release();
            mSurfaceControl = null;
            mSurfaceVisible = false;