Loading core/java/android/view/Surface.java +24 −5 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.annotation.NonNull; import android.annotation.UnsupportedAppUsage; import android.content.res.CompatibilityInfo.Translator; import android.graphics.Canvas; import android.graphics.ColorSpace; import android.graphics.GraphicBuffer; import android.graphics.Matrix; import android.graphics.RecordingCanvas; Loading Loading @@ -80,7 +81,8 @@ public class Surface implements Parcelable { private static native long nativeGetNextFrameNumber(long nativeObject); private static native int nativeSetScalingMode(long nativeObject, int scalingMode); private static native int nativeForceScopedDisconnect(long nativeObject); private static native int nativeAttachAndQueueBuffer(long nativeObject, GraphicBuffer buffer); private static native int nativeAttachAndQueueBufferWithColorSpace(long nativeObject, GraphicBuffer buffer, int colorSpaceId); private static native int nativeSetSharedBufferModeEnabled(long nativeObject, boolean enabled); private static native int nativeSetAutoRefreshEnabled(long nativeObject, boolean enabled); Loading Loading @@ -699,20 +701,37 @@ public class Surface implements Parcelable { } /** * Transfer ownership of buffer and present it on the Surface. * Transfer ownership of buffer with a color space and present it on the Surface. * The supported color spaces are SRGB and Display P3, other color spaces will be * treated as SRGB. * @hide */ public void attachAndQueueBuffer(GraphicBuffer buffer) { public void attachAndQueueBufferWithColorSpace(GraphicBuffer buffer, ColorSpace colorSpace) { synchronized (mLock) { checkNotReleasedLocked(); int err = nativeAttachAndQueueBuffer(mNativeObject, buffer); if (colorSpace == null) { colorSpace = ColorSpace.get(ColorSpace.Named.SRGB); } int err = nativeAttachAndQueueBufferWithColorSpace(mNativeObject, buffer, colorSpace.getId()); if (err != 0) { throw new RuntimeException( "Failed to attach and queue buffer to Surface (bad object?)"); "Failed to attach and queue buffer to Surface (bad object?), " + "native error: " + err); } } } /** * Deprecated, use attachAndQueueBufferWithColorSpace instead. * Transfer ownership of buffer and present it on the Surface. * The color space of the buffer is treated as SRGB. * @hide */ public void attachAndQueueBuffer(GraphicBuffer buffer) { attachAndQueueBufferWithColorSpace(buffer, ColorSpace.get(ColorSpace.Named.SRGB)); } /** * Returns whether or not this Surface is backed by a single-buffered SurfaceTexture * @hide Loading core/java/android/view/SurfaceControl.java +2 −1 Original line number Diff line number Diff line Loading @@ -1846,7 +1846,8 @@ public final class SurfaceControl implements Parcelable { final ScreenshotGraphicBuffer buffer = screenshotToBuffer(display, sourceCrop, width, height, useIdentityTransform, rotation); try { consumer.attachAndQueueBuffer(buffer.getGraphicBuffer()); consumer.attachAndQueueBufferWithColorSpace(buffer.getGraphicBuffer(), buffer.getColorSpace()); } catch (RuntimeException e) { Log.w(TAG, "Failed to take screenshot - " + e.getMessage()); } Loading core/jni/android_view_Surface.cpp +24 −4 Original line number Diff line number Diff line Loading @@ -74,6 +74,24 @@ static struct { jfieldID bottom; } gRectClassInfo; class JNamedColorSpace { public: // ColorSpace.Named.SRGB.ordinal() = 0; static constexpr jint SRGB = 0; // ColorSpace.Named.DISPLAY_P3.ordinal() = 7; static constexpr jint DISPLAY_P3 = 7; }; constexpr ui::Dataspace fromNamedColorSpaceValueToDataspace(const jint colorSpace) { switch (colorSpace) { case JNamedColorSpace::DISPLAY_P3: return ui::Dataspace::DISPLAY_P3; default: return ui::Dataspace::V0_SRGB; } } // ---------------------------------------------------------------------------- // this is just a pointer we use to pass to inc/decStrong Loading Loading @@ -411,11 +429,12 @@ static jint nativeForceScopedDisconnect(JNIEnv *env, jclass clazz, jlong nativeO return surface->disconnect(-1, IGraphicBufferProducer::DisconnectMode::AllLocal); } static jint nativeAttachAndQueueBuffer(JNIEnv *env, jclass clazz, jlong nativeObject, jobject graphicBuffer) { static jint nativeAttachAndQueueBufferWithColorSpace(JNIEnv *env, jclass clazz, jlong nativeObject, jobject graphicBuffer, jint colorSpaceId) { Surface* surface = reinterpret_cast<Surface*>(nativeObject); sp<GraphicBuffer> bp = graphicBufferForJavaObject(env, graphicBuffer); int err = Surface::attachAndQueueBuffer(surface, bp); int err = Surface::attachAndQueueBufferWithDataspace(surface, bp, fromNamedColorSpaceValueToDataspace(colorSpaceId)); return err; } Loading Loading @@ -517,7 +536,8 @@ static const JNINativeMethod gSurfaceMethods[] = { {"nativeGetNextFrameNumber", "(J)J", (void*)nativeGetNextFrameNumber }, {"nativeSetScalingMode", "(JI)I", (void*)nativeSetScalingMode }, {"nativeForceScopedDisconnect", "(J)I", (void*)nativeForceScopedDisconnect}, {"nativeAttachAndQueueBuffer", "(JLandroid/graphics/GraphicBuffer;)I", (void*)nativeAttachAndQueueBuffer}, {"nativeAttachAndQueueBufferWithColorSpace", "(JLandroid/graphics/GraphicBuffer;I)I", (void*)nativeAttachAndQueueBufferWithColorSpace}, {"nativeSetSharedBufferModeEnabled", "(JZ)I", (void*)nativeSetSharedBufferModeEnabled}, {"nativeSetAutoRefreshEnabled", "(JZ)I", (void*)nativeSetAutoRefreshEnabled}, Loading services/core/java/com/android/server/wm/ScreenRotationAnimation.java +2 −1 Original line number Diff line number Diff line Loading @@ -279,7 +279,8 @@ class ScreenRotationAnimation { mService.mDisplayManagerInternal.screenshot(displayId); if (gb != null) { try { surface.attachAndQueueBuffer(gb.getGraphicBuffer()); surface.attachAndQueueBufferWithColorSpace(gb.getGraphicBuffer(), gb.getColorSpace()); } catch (RuntimeException e) { Slog.w(TAG, "Failed to attach screenshot - " + e.getMessage()); } Loading services/core/java/com/android/server/wm/TaskScreenshotAnimatable.java +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ class TaskScreenshotAnimatable implements SurfaceAnimator.Animatable { if (buffer != null) { final Surface surface = new Surface(); surface.copyFrom(mSurfaceControl); surface.attachAndQueueBuffer(buffer); surface.attachAndQueueBufferWithColorSpace(buffer, screenshotBuffer.getColorSpace()); surface.release(); } getPendingTransaction().show(mSurfaceControl); Loading Loading
core/java/android/view/Surface.java +24 −5 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.annotation.NonNull; import android.annotation.UnsupportedAppUsage; import android.content.res.CompatibilityInfo.Translator; import android.graphics.Canvas; import android.graphics.ColorSpace; import android.graphics.GraphicBuffer; import android.graphics.Matrix; import android.graphics.RecordingCanvas; Loading Loading @@ -80,7 +81,8 @@ public class Surface implements Parcelable { private static native long nativeGetNextFrameNumber(long nativeObject); private static native int nativeSetScalingMode(long nativeObject, int scalingMode); private static native int nativeForceScopedDisconnect(long nativeObject); private static native int nativeAttachAndQueueBuffer(long nativeObject, GraphicBuffer buffer); private static native int nativeAttachAndQueueBufferWithColorSpace(long nativeObject, GraphicBuffer buffer, int colorSpaceId); private static native int nativeSetSharedBufferModeEnabled(long nativeObject, boolean enabled); private static native int nativeSetAutoRefreshEnabled(long nativeObject, boolean enabled); Loading Loading @@ -699,20 +701,37 @@ public class Surface implements Parcelable { } /** * Transfer ownership of buffer and present it on the Surface. * Transfer ownership of buffer with a color space and present it on the Surface. * The supported color spaces are SRGB and Display P3, other color spaces will be * treated as SRGB. * @hide */ public void attachAndQueueBuffer(GraphicBuffer buffer) { public void attachAndQueueBufferWithColorSpace(GraphicBuffer buffer, ColorSpace colorSpace) { synchronized (mLock) { checkNotReleasedLocked(); int err = nativeAttachAndQueueBuffer(mNativeObject, buffer); if (colorSpace == null) { colorSpace = ColorSpace.get(ColorSpace.Named.SRGB); } int err = nativeAttachAndQueueBufferWithColorSpace(mNativeObject, buffer, colorSpace.getId()); if (err != 0) { throw new RuntimeException( "Failed to attach and queue buffer to Surface (bad object?)"); "Failed to attach and queue buffer to Surface (bad object?), " + "native error: " + err); } } } /** * Deprecated, use attachAndQueueBufferWithColorSpace instead. * Transfer ownership of buffer and present it on the Surface. * The color space of the buffer is treated as SRGB. * @hide */ public void attachAndQueueBuffer(GraphicBuffer buffer) { attachAndQueueBufferWithColorSpace(buffer, ColorSpace.get(ColorSpace.Named.SRGB)); } /** * Returns whether or not this Surface is backed by a single-buffered SurfaceTexture * @hide Loading
core/java/android/view/SurfaceControl.java +2 −1 Original line number Diff line number Diff line Loading @@ -1846,7 +1846,8 @@ public final class SurfaceControl implements Parcelable { final ScreenshotGraphicBuffer buffer = screenshotToBuffer(display, sourceCrop, width, height, useIdentityTransform, rotation); try { consumer.attachAndQueueBuffer(buffer.getGraphicBuffer()); consumer.attachAndQueueBufferWithColorSpace(buffer.getGraphicBuffer(), buffer.getColorSpace()); } catch (RuntimeException e) { Log.w(TAG, "Failed to take screenshot - " + e.getMessage()); } Loading
core/jni/android_view_Surface.cpp +24 −4 Original line number Diff line number Diff line Loading @@ -74,6 +74,24 @@ static struct { jfieldID bottom; } gRectClassInfo; class JNamedColorSpace { public: // ColorSpace.Named.SRGB.ordinal() = 0; static constexpr jint SRGB = 0; // ColorSpace.Named.DISPLAY_P3.ordinal() = 7; static constexpr jint DISPLAY_P3 = 7; }; constexpr ui::Dataspace fromNamedColorSpaceValueToDataspace(const jint colorSpace) { switch (colorSpace) { case JNamedColorSpace::DISPLAY_P3: return ui::Dataspace::DISPLAY_P3; default: return ui::Dataspace::V0_SRGB; } } // ---------------------------------------------------------------------------- // this is just a pointer we use to pass to inc/decStrong Loading Loading @@ -411,11 +429,12 @@ static jint nativeForceScopedDisconnect(JNIEnv *env, jclass clazz, jlong nativeO return surface->disconnect(-1, IGraphicBufferProducer::DisconnectMode::AllLocal); } static jint nativeAttachAndQueueBuffer(JNIEnv *env, jclass clazz, jlong nativeObject, jobject graphicBuffer) { static jint nativeAttachAndQueueBufferWithColorSpace(JNIEnv *env, jclass clazz, jlong nativeObject, jobject graphicBuffer, jint colorSpaceId) { Surface* surface = reinterpret_cast<Surface*>(nativeObject); sp<GraphicBuffer> bp = graphicBufferForJavaObject(env, graphicBuffer); int err = Surface::attachAndQueueBuffer(surface, bp); int err = Surface::attachAndQueueBufferWithDataspace(surface, bp, fromNamedColorSpaceValueToDataspace(colorSpaceId)); return err; } Loading Loading @@ -517,7 +536,8 @@ static const JNINativeMethod gSurfaceMethods[] = { {"nativeGetNextFrameNumber", "(J)J", (void*)nativeGetNextFrameNumber }, {"nativeSetScalingMode", "(JI)I", (void*)nativeSetScalingMode }, {"nativeForceScopedDisconnect", "(J)I", (void*)nativeForceScopedDisconnect}, {"nativeAttachAndQueueBuffer", "(JLandroid/graphics/GraphicBuffer;)I", (void*)nativeAttachAndQueueBuffer}, {"nativeAttachAndQueueBufferWithColorSpace", "(JLandroid/graphics/GraphicBuffer;I)I", (void*)nativeAttachAndQueueBufferWithColorSpace}, {"nativeSetSharedBufferModeEnabled", "(JZ)I", (void*)nativeSetSharedBufferModeEnabled}, {"nativeSetAutoRefreshEnabled", "(JZ)I", (void*)nativeSetAutoRefreshEnabled}, Loading
services/core/java/com/android/server/wm/ScreenRotationAnimation.java +2 −1 Original line number Diff line number Diff line Loading @@ -279,7 +279,8 @@ class ScreenRotationAnimation { mService.mDisplayManagerInternal.screenshot(displayId); if (gb != null) { try { surface.attachAndQueueBuffer(gb.getGraphicBuffer()); surface.attachAndQueueBufferWithColorSpace(gb.getGraphicBuffer(), gb.getColorSpace()); } catch (RuntimeException e) { Slog.w(TAG, "Failed to attach screenshot - " + e.getMessage()); } Loading
services/core/java/com/android/server/wm/TaskScreenshotAnimatable.java +1 −1 Original line number Diff line number Diff line Loading @@ -68,7 +68,7 @@ class TaskScreenshotAnimatable implements SurfaceAnimator.Animatable { if (buffer != null) { final Surface surface = new Surface(); surface.copyFrom(mSurfaceControl); surface.attachAndQueueBuffer(buffer); surface.attachAndQueueBufferWithColorSpace(buffer, screenshotBuffer.getColorSpace()); surface.release(); } getPendingTransaction().show(mSurfaceControl); Loading