Merge "Determine the dataspace of the screenshot buffer based on display color mode." into qt-dev

This commit is contained in:
Peiyong Lin
2019-04-12 16:57:38 +00:00
committed by Android (Google) Code Review
7 changed files with 47 additions and 27 deletions

View File

@@ -1838,17 +1838,17 @@ public class ActivityManager {
private final float mScale; private final float mScale;
private final int mSystemUiVisibility; private final int mSystemUiVisibility;
private final boolean mIsTranslucent; private final boolean mIsTranslucent;
// Must be one of the named color spaces, otherwise, always use SRGB color space.
// TODO(b/116112787) TaskSnapshot must also book keep the color space from hardware bitmap private final ColorSpace mColorSpace;
// when created.
private final ColorSpace mColorSpace = ColorSpace.get(ColorSpace.Named.SRGB);
public TaskSnapshot(@NonNull ComponentName topActivityComponent, GraphicBuffer snapshot, public TaskSnapshot(@NonNull ComponentName topActivityComponent, GraphicBuffer snapshot,
int orientation, Rect contentInsets, boolean reducedResolution, float scale, @NonNull ColorSpace colorSpace, int orientation, Rect contentInsets,
boolean isRealSnapshot, int windowingMode, int systemUiVisibility, boolean reducedResolution, float scale, boolean isRealSnapshot, int windowingMode,
boolean isTranslucent) { int systemUiVisibility, boolean isTranslucent) {
mTopActivityComponent = topActivityComponent; mTopActivityComponent = topActivityComponent;
mSnapshot = snapshot; mSnapshot = snapshot;
mColorSpace = colorSpace.getId() < 0
? ColorSpace.get(ColorSpace.Named.SRGB) : colorSpace;
mOrientation = orientation; mOrientation = orientation;
mContentInsets = new Rect(contentInsets); mContentInsets = new Rect(contentInsets);
mReducedResolution = reducedResolution; mReducedResolution = reducedResolution;
@@ -1862,6 +1862,10 @@ public class ActivityManager {
private TaskSnapshot(Parcel source) { private TaskSnapshot(Parcel source) {
mTopActivityComponent = ComponentName.readFromParcel(source); mTopActivityComponent = ComponentName.readFromParcel(source);
mSnapshot = source.readParcelable(null /* classLoader */); mSnapshot = source.readParcelable(null /* classLoader */);
int colorSpaceId = source.readInt();
mColorSpace = colorSpaceId >= 0
? ColorSpace.get(ColorSpace.Named.values()[colorSpaceId])
: ColorSpace.get(ColorSpace.Named.SRGB);
mOrientation = source.readInt(); mOrientation = source.readInt();
mContentInsets = source.readParcelable(null /* classLoader */); mContentInsets = source.readParcelable(null /* classLoader */);
mReducedResolution = source.readBoolean(); mReducedResolution = source.readBoolean();
@@ -1968,6 +1972,7 @@ public class ActivityManager {
public void writeToParcel(Parcel dest, int flags) { public void writeToParcel(Parcel dest, int flags) {
ComponentName.writeToParcel(mTopActivityComponent, dest); ComponentName.writeToParcel(mTopActivityComponent, dest);
dest.writeParcelable(mSnapshot, 0); dest.writeParcelable(mSnapshot, 0);
dest.writeInt(mColorSpace.getId());
dest.writeInt(mOrientation); dest.writeInt(mOrientation);
dest.writeParcelable(mContentInsets, 0); dest.writeParcelable(mContentInsets, 0);
dest.writeBoolean(mReducedResolution); dest.writeBoolean(mReducedResolution);
@@ -1985,6 +1990,7 @@ public class ActivityManager {
return "TaskSnapshot{" return "TaskSnapshot{"
+ " mTopActivityComponent=" + mTopActivityComponent.flattenToShortString() + " mTopActivityComponent=" + mTopActivityComponent.flattenToShortString()
+ " mSnapshot=" + mSnapshot + " (" + width + "x" + height + ")" + " mSnapshot=" + mSnapshot + " (" + width + "x" + height + ")"
+ " mColorSpace=" + mColorSpace.toString()
+ " mOrientation=" + mOrientation + " mOrientation=" + mOrientation
+ " mContentInsets=" + mContentInsets.toShortString() + " mContentInsets=" + mContentInsets.toShortString()
+ " mReducedResolution=" + mReducedResolution + " mScale=" + mScale + " mReducedResolution=" + mReducedResolution + " mScale=" + mScale

View File

@@ -90,8 +90,8 @@ public final class SurfaceControl implements Parcelable {
private static native ScreenshotGraphicBuffer nativeScreenshot(IBinder displayToken, private static native ScreenshotGraphicBuffer nativeScreenshot(IBinder displayToken,
Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation, Rect sourceCrop, int width, int height, boolean useIdentityTransform, int rotation,
boolean captureSecureLayers); boolean captureSecureLayers);
private static native ScreenshotGraphicBuffer nativeCaptureLayers(IBinder layerHandleToken, private static native ScreenshotGraphicBuffer nativeCaptureLayers(IBinder displayToken,
Rect sourceCrop, float frameScale, IBinder[] excludeLayers); IBinder layerHandleToken, Rect sourceCrop, float frameScale, IBinder[] excludeLayers);
private static native long nativeCreateTransaction(); private static native long nativeCreateTransaction();
private static native long nativeGetNativeTransactionFinalizer(); private static native long nativeGetNativeTransactionFinalizer();
@@ -1998,7 +1998,8 @@ public final class SurfaceControl implements Parcelable {
*/ */
public static ScreenshotGraphicBuffer captureLayers(IBinder layerHandleToken, Rect sourceCrop, public static ScreenshotGraphicBuffer captureLayers(IBinder layerHandleToken, Rect sourceCrop,
float frameScale) { float frameScale) {
return nativeCaptureLayers(layerHandleToken, sourceCrop, frameScale, null); final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
return nativeCaptureLayers(displayToken, layerHandleToken, sourceCrop, frameScale, null);
} }
/** /**
@@ -2007,7 +2008,8 @@ public final class SurfaceControl implements Parcelable {
*/ */
public static ScreenshotGraphicBuffer captureLayersExcluding(IBinder layerHandleToken, public static ScreenshotGraphicBuffer captureLayersExcluding(IBinder layerHandleToken,
Rect sourceCrop, float frameScale, IBinder[] exclude) { Rect sourceCrop, float frameScale, IBinder[] exclude) {
return nativeCaptureLayers(layerHandleToken, sourceCrop, frameScale, exclude); final IBinder displayToken = SurfaceControl.getInternalDisplayToken();
return nativeCaptureLayers(displayToken, layerHandleToken, sourceCrop, frameScale, exclude);
} }
/** /**

View File

@@ -271,8 +271,9 @@ static jobject nativeScreenshot(JNIEnv* env, jclass clazz,
capturedSecureLayers); capturedSecureLayers);
} }
static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandleToken, static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject displayTokenObj,
jobject sourceCropObj, jfloat frameScale, jobjectArray excludeArray) { jobject layerHandleToken, jobject sourceCropObj, jfloat frameScale,
jobjectArray excludeArray) {
sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken); sp<IBinder> layerHandle = ibinderForJavaObject(env, layerHandleToken);
if (layerHandle == NULL) { if (layerHandle == NULL) {
@@ -301,7 +302,12 @@ static jobject nativeCaptureLayers(JNIEnv* env, jclass clazz, jobject layerHandl
} }
sp<GraphicBuffer> buffer; sp<GraphicBuffer> buffer;
const ui::Dataspace dataspace = ui::Dataspace::V0_SRGB; ui::Dataspace dataspace = ui::Dataspace::V0_SRGB;
sp<IBinder> displayToken = ibinderForJavaObject(env, displayTokenObj);
if (displayToken != nullptr) {
const ui::ColorMode colorMode = SurfaceComposerClient::getActiveColorMode(displayToken);
dataspace = pickDataspaceFromColorMode(colorMode);
}
status_t res = ScreenshotClient::captureChildLayers(layerHandle, dataspace, status_t res = ScreenshotClient::captureChildLayers(layerHandle, dataspace,
ui::PixelFormat::RGBA_8888, sourceCrop, ui::PixelFormat::RGBA_8888, sourceCrop,
excludeHandles, frameScale, &buffer); excludeHandles, frameScale, &buffer);
@@ -1373,7 +1379,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
"Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;", "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
(void*)nativeScreenshot }, (void*)nativeScreenshot },
{"nativeCaptureLayers", {"nativeCaptureLayers",
"(Landroid/os/IBinder;Landroid/graphics/Rect;F[Landroid/os/IBinder;)" "(Landroid/os/IBinder;Landroid/os/IBinder;Landroid/graphics/Rect;"
"F[Landroid/os/IBinder;)"
"Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;", "Landroid/view/SurfaceControl$ScreenshotGraphicBuffer;",
(void*)nativeCaptureLayers }, (void*)nativeCaptureLayers },
{"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V", {"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",

View File

@@ -292,9 +292,9 @@ class TaskSnapshotController {
} }
final boolean isWindowTranslucent = mainWindow.getAttrs().format != PixelFormat.OPAQUE; final boolean isWindowTranslucent = mainWindow.getAttrs().format != PixelFormat.OPAQUE;
return new TaskSnapshot(appWindowToken.mActivityComponent, buffer, return new TaskSnapshot(appWindowToken.mActivityComponent, buffer,
appWindowToken.getConfiguration().orientation, getInsets(mainWindow), screenshotBuffer.getColorSpace(), appWindowToken.getConfiguration().orientation,
isLowRamDevice /* reduced */, scaleFraction /* scale */, true /* isRealSnapshot */, getInsets(mainWindow), isLowRamDevice /* reduced */, scaleFraction /* scale */,
task.getWindowingMode(), getSystemUiVisibility(task), true /* isRealSnapshot */, task.getWindowingMode(), getSystemUiVisibility(task),
!appWindowToken.fillsParent() || isWindowTranslucent); !appWindowToken.fillsParent() || isWindowTranslucent);
} }
@@ -383,10 +383,10 @@ class TaskSnapshotController {
// Note, the app theme snapshot is never translucent because we enforce a non-translucent // Note, the app theme snapshot is never translucent because we enforce a non-translucent
// color above // color above
return new TaskSnapshot(topChild.mActivityComponent, hwBitmap.createGraphicBufferHandle(), return new TaskSnapshot(topChild.mActivityComponent, hwBitmap.createGraphicBufferHandle(),
topChild.getConfiguration().orientation, mainWindow.getStableInsets(), hwBitmap.getColorSpace(), topChild.getConfiguration().orientation,
ActivityManager.isLowRamDeviceStatic() /* reduced */, 1.0f /* scale */, mainWindow.getStableInsets(), ActivityManager.isLowRamDeviceStatic() /* reduced */,
false /* isRealSnapshot */, task.getWindowingMode(), getSystemUiVisibility(task), 1.0f /* scale */, false /* isRealSnapshot */, task.getWindowingMode(),
false); getSystemUiVisibility(task), false);
} }
/** /**

View File

@@ -89,7 +89,8 @@ class TaskSnapshotLoader {
} }
ComponentName topActivityComponent = ComponentName.unflattenFromString( ComponentName topActivityComponent = ComponentName.unflattenFromString(
proto.topActivityComponent); proto.topActivityComponent);
return new TaskSnapshot(topActivityComponent, buffer, proto.orientation, return new TaskSnapshot(topActivityComponent, buffer, bitmap.getColorSpace(),
proto.orientation,
new Rect(proto.insetLeft, proto.insetTop, proto.insetRight, proto.insetBottom), new Rect(proto.insetLeft, proto.insetTop, proto.insetRight, proto.insetBottom),
reducedResolution, reducedResolution ? mPersister.getReducedScale() : 1f, reducedResolution, reducedResolution ? mPersister.getReducedScale() : 1f,
proto.isRealSnapshot, proto.windowingMode, proto.systemUiVisibility, proto.isRealSnapshot, proto.windowingMode, proto.systemUiVisibility,

View File

@@ -27,6 +27,7 @@ import android.app.ActivityManager.TaskSnapshot;
import android.content.ComponentName; import android.content.ComponentName;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.ColorSpace;
import android.graphics.GraphicBuffer; import android.graphics.GraphicBuffer;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.graphics.Rect; import android.graphics.Rect;
@@ -127,8 +128,9 @@ class TaskSnapshotPersisterTestBase extends WindowTestsBase {
Canvas c = buffer.lockCanvas(); Canvas c = buffer.lockCanvas();
c.drawColor(Color.RED); c.drawColor(Color.RED);
buffer.unlockCanvasAndPost(c); buffer.unlockCanvasAndPost(c);
return new TaskSnapshot(new ComponentName("", ""), buffer, ORIENTATION_PORTRAIT, return new TaskSnapshot(new ComponentName("", ""), buffer,
TEST_INSETS, mScale < 1f /* reducedResolution */, mScale, mIsRealSnapshot, ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT, TEST_INSETS,
mScale < 1f /* reducedResolution */, mScale, mIsRealSnapshot,
mWindowingMode, mSystemUiVisibility, mIsTranslucent); mWindowingMode, mSystemUiVisibility, mIsTranslucent);
} }
} }

View File

@@ -35,6 +35,7 @@ import android.app.ActivityManager.TaskSnapshot;
import android.content.ComponentName; import android.content.ComponentName;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.ColorSpace;
import android.graphics.GraphicBuffer; import android.graphics.GraphicBuffer;
import android.graphics.PixelFormat; import android.graphics.PixelFormat;
import android.graphics.Rect; import android.graphics.Rect;
@@ -64,8 +65,9 @@ public class TaskSnapshotSurfaceTest extends WindowTestsBase {
final GraphicBuffer buffer = GraphicBuffer.create(width, height, PixelFormat.RGBA_8888, final GraphicBuffer buffer = GraphicBuffer.create(width, height, PixelFormat.RGBA_8888,
GraphicBuffer.USAGE_SW_READ_RARELY | GraphicBuffer.USAGE_SW_WRITE_NEVER); GraphicBuffer.USAGE_SW_READ_RARELY | GraphicBuffer.USAGE_SW_WRITE_NEVER);
final TaskSnapshot snapshot = new TaskSnapshot(new ComponentName("", ""), buffer, final TaskSnapshot snapshot = new TaskSnapshot(new ComponentName("", ""), buffer,
ORIENTATION_PORTRAIT, contentInsets, false, 1.0f, true /* isRealSnapshot */, ColorSpace.get(ColorSpace.Named.SRGB), ORIENTATION_PORTRAIT, contentInsets, false,
WINDOWING_MODE_FULLSCREEN, 0 /* systemUiVisibility */, false /* isTranslucent */); 1.0f, true /* isRealSnapshot */, WINDOWING_MODE_FULLSCREEN,
0 /* systemUiVisibility */, false /* isTranslucent */);
mSurface = new TaskSnapshotSurface(mWm, new Window(), new SurfaceControl(), snapshot, "Test", mSurface = new TaskSnapshotSurface(mWm, new Window(), new SurfaceControl(), snapshot, "Test",
createTaskDescription(Color.WHITE, Color.RED, Color.BLUE), sysuiVis, windowFlags, 0, createTaskDescription(Color.WHITE, Color.RED, Color.BLUE), sysuiVis, windowFlags, 0,
taskBounds, ORIENTATION_PORTRAIT); taskBounds, ORIENTATION_PORTRAIT);