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

Commit 532431d1 authored by Chiawei Wang's avatar Chiawei Wang Committed by Android (Google) Code Review
Browse files

Merge "Add ability to make task snapshots store in RGB565"

parents 11f3c8ac 02202d10
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
@@ -90,7 +90,8 @@ public final class SurfaceControl implements Parcelable {
            Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation,
            boolean captureSecureLayers);
    private static native ScreenshotGraphicBuffer nativeCaptureLayers(IBinder displayToken,
            long layerObject, Rect sourceCrop, float frameScale, long[] excludeLayerObjects);
            long layerObject, Rect sourceCrop, float frameScale, long[] excludeLayerObjects,
            int format);
    private static native long nativeMirrorSurface(long mirrorOfObject);
    private static native long nativeCreateTransaction();
    private static native long nativeGetNativeTransactionFinalizer();
@@ -1869,8 +1870,27 @@ public final class SurfaceControl implements Parcelable {
     */
    public static ScreenshotGraphicBuffer captureLayers(SurfaceControl layer, Rect sourceCrop,
            float frameScale) {
        return captureLayers(layer, sourceCrop, frameScale, PixelFormat.RGBA_8888);
    }

    /**
     * Captures a layer and its children and returns a {@link GraphicBuffer} with the content.
     *
     * @param layer            The root layer to capture.
     * @param sourceCrop       The portion of the root surface to capture; caller may pass in 'new
     *                         Rect()' or null if no cropping is desired.
     * @param frameScale       The desired scale of the returned buffer; the raw
     *                         screen will be scaled up/down.
     * @param format           The desired pixel format of the returned buffer.
     *
     * @return Returns a GraphicBuffer that contains the layer capture.
     * @hide
     */
    public static ScreenshotGraphicBuffer captureLayers(SurfaceControl layer, Rect sourceCrop,
            float frameScale, int format) {
        final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
        return nativeCaptureLayers(displayToken, layer.mNativeObject, sourceCrop, frameScale, null);
        return nativeCaptureLayers(displayToken, layer.mNativeObject, sourceCrop, frameScale, null,
                format);
    }

    /**
@@ -1885,7 +1905,7 @@ public final class SurfaceControl implements Parcelable {
            nativeExcludeObjects[i] = exclude[i].mNativeObject;
        }
        return nativeCaptureLayers(displayToken, layer.mNativeObject, sourceCrop, frameScale,
                nativeExcludeObjects);
                nativeExcludeObjects, PixelFormat.RGBA_8888);
    }

    /**
+5 −4
Original line number Diff line number Diff line
@@ -274,7 +274,7 @@ static jobject nativeScreenshot(JNIEnv* env, jclass clazz,

static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject displayTokenObj,
        jlong layerObject, jobject sourceCropObj, jfloat frameScale,
        jlongArray excludeObjectArray) {
        jlongArray excludeObjectArray, jint format) {

    auto layer = reinterpret_cast<SurfaceControl *>(layerObject);
    if (layer == NULL) {
@@ -311,8 +311,9 @@ static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject displayTok
        dataspace = pickDataspaceFromColorMode(colorMode);
    }
    status_t res = ScreenshotClient::captureChildLayers(layer->getHandle(), dataspace,
                                                        ui::PixelFormat::RGBA_8888, sourceCrop,
                                                        excludeHandles, frameScale, &buffer);
                                                        static_cast<ui::PixelFormat>(format),
                                                        sourceCrop, excludeHandles, frameScale,
                                                        &buffer);
    if (res != NO_ERROR) {
        return NULL;
    }
@@ -1386,7 +1387,7 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
            (void*)nativeScreenshot },
    {"nativeCaptureLayers",
            "(Landroid/os/IBinder;JLandroid/graphics/Rect;"
            "F[J)"
            "F[JI)"
            "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
            (void*)nativeCaptureLayers },
    {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
+3 −0
Original line number Diff line number Diff line
@@ -2652,6 +2652,9 @@
    <!-- The amount to scale fullscreen snapshots for Overview and snapshot starting windows. -->
    <item name="config_fullTaskSnapshotScale" format="float" type="dimen">1.0</item>

    <!-- Feature flag to store TaskSnapshot in 16 bit pixel format to save memory. -->
    <bool name="config_use16BitTaskSnapshotPixelFormat">false</bool>

    <!-- Determines whether recent tasks are provided to the user. Default device has recents
         property. If this is false, then the following recents config flags are ignored. -->
    <bool name="config_hasRecents">true</bool>
+1 −0
Original line number Diff line number Diff line
@@ -356,6 +356,7 @@
  <java-symbol type="bool" name="config_enableNewAutoSelectNetworkUI"/>
  <java-symbol type="bool" name="config_disableUsbPermissionDialogs"/>
  <java-symbol type="dimen" name="config_fullTaskSnapshotScale" />
  <java-symbol type="bool" name="config_use16BitTaskSnapshotPixelFormat" />
  <java-symbol type="bool" name="config_lowRamTaskSnapshotsAndRecents" />
  <java-symbol type="bool" name="config_hasRecents" />
  <java-symbol type="string" name="config_recentsComponentName" />
+19 −4
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.server.wm;

import static android.view.WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;

import static com.android.server.wm.TaskSnapshotPersister.DISABLE_FULL_SIZED_BITMAPS;
import static com.android.server.wm.WindowManagerDebugConfig.DEBUG_SCREENSHOT;
import static com.android.server.wm.WindowManagerDebugConfig.TAG_WITH_CLASS_NAME;
@@ -248,6 +250,12 @@ class TaskSnapshotController {
    @Nullable
    SurfaceControl.ScreenshotGraphicBuffer createTaskSnapshot(@NonNull Task task,
            float scaleFraction) {
        return createTaskSnapshot(task, scaleFraction, PixelFormat.RGBA_8888);
    }

    @Nullable
    SurfaceControl.ScreenshotGraphicBuffer createTaskSnapshot(@NonNull Task task,
            float scaleFraction, int pixelFormat) {
        if (task.getSurfaceControl() == null) {
            if (DEBUG_SCREENSHOT) {
                Slog.w(TAG_WM, "Failed to take screenshot. No surface control for " + task);
@@ -258,7 +266,7 @@ class TaskSnapshotController {
        mTmpRect.offsetTo(0, 0);
        final SurfaceControl.ScreenshotGraphicBuffer screenshotBuffer =
                SurfaceControl.captureLayers(
                        task.getSurfaceControl(), mTmpRect, scaleFraction);
                        task.getSurfaceControl(), mTmpRect, scaleFraction, pixelFormat);
        final GraphicBuffer buffer = screenshotBuffer != null ? screenshotBuffer.getGraphicBuffer()
                : null;
        if (buffer == null || buffer.getWidth() <= 1 || buffer.getHeight() <= 1) {
@@ -299,8 +307,14 @@ class TaskSnapshotController {
            Slog.w(TAG_WM, "Failed to take screenshot. No main window for " + task);
            return null;
        }
        final boolean isWindowTranslucent = mainWindow.getAttrs().format != PixelFormat.OPAQUE;
        final boolean isShowWallpaper = (mainWindow.getAttrs().flags & FLAG_SHOW_WALLPAPER) != 0;
        final int pixelFormat = mPersister.use16BitFormat() && activity.fillsParent()
                && !(isWindowTranslucent && isShowWallpaper)
                ? PixelFormat.RGB_565
                : PixelFormat.RGBA_8888;
        final SurfaceControl.ScreenshotGraphicBuffer screenshotBuffer =
                createTaskSnapshot(task, scaleFraction);
                createTaskSnapshot(task, scaleFraction, pixelFormat);

        if (screenshotBuffer == null) {
            if (DEBUG_SCREENSHOT) {
@@ -308,7 +322,8 @@ class TaskSnapshotController {
            }
            return null;
        }
        final boolean isWindowTranslucent = mainWindow.getAttrs().format != PixelFormat.OPAQUE;
        final boolean isTranslucent = PixelFormat.formatHasAlpha(pixelFormat)
                && (!activity.fillsParent() || isWindowTranslucent);
        return new TaskSnapshot(
                System.currentTimeMillis() /* id */,
                activity.mActivityComponent, screenshotBuffer.getGraphicBuffer(),
@@ -316,7 +331,7 @@ class TaskSnapshotController {
                activity.getTask().getConfiguration().orientation,
                getInsets(mainWindow), isLowRamDevice /* reduced */, scaleFraction /* scale */,
                true /* isRealSnapshot */, task.getWindowingMode(), getSystemUiVisibility(task),
                !activity.fillsParent() || isWindowTranslucent);
                isTranslucent);
    }

    private boolean shouldDisableSnapshots() {
Loading