Loading core/java/android/view/Surface.java +5 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.FloatRange; import android.annotation.IntDef; import android.annotation.NonNull; import android.compat.annotation.UnsupportedAppUsage; import android.content.pm.ActivityInfo; import android.content.res.CompatibilityInfo.Translator; import android.graphics.Canvas; import android.graphics.ColorSpace; Loading Loading @@ -1001,7 +1002,10 @@ public class Surface implements Parcelable { mHardwareRenderer = new HardwareRenderer(); mHardwareRenderer.setContentRoot(mRenderNode); mHardwareRenderer.setSurface(Surface.this, true); mHardwareRenderer.setWideGamut(isWideColorGamut); mHardwareRenderer.setColorMode( isWideColorGamut ? ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT : ActivityInfo.COLOR_MODE_DEFAULT); mHardwareRenderer.setLightSourceAlpha(0.0f, 0.0f); mHardwareRenderer.setLightSourceGeometry(0.0f, 0.0f, 0.0f, 0.0f); } Loading core/java/android/view/ViewRootImpl.java +10 −20 Original line number Diff line number Diff line Loading @@ -1329,13 +1329,9 @@ public final class ViewRootImpl implements ViewParent, final boolean hasSurfaceInsets = insets.left != 0 || insets.right != 0 || insets.top != 0 || insets.bottom != 0; final boolean translucent = attrs.format != PixelFormat.OPAQUE || hasSurfaceInsets; final boolean wideGamut = mContext.getResources().getConfiguration().isScreenWideColorGamut() && attrs.getColorMode() == ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT; mAttachInfo.mThreadedRenderer = ThreadedRenderer.create(mContext, translucent, attrs.getTitle().toString()); mAttachInfo.mThreadedRenderer.setWideGamut(wideGamut); updateColorModeIfNeeded(attrs.getColorMode()); updateForceDarkMode(); if (mAttachInfo.mThreadedRenderer != null) { mAttachInfo.mHardwareAccelerated = Loading Loading @@ -2648,7 +2644,7 @@ public final class ViewRootImpl implements ViewParent, & WindowManagerGlobal.RELAYOUT_RES_SURFACE_RESIZED) != 0; final boolean alwaysConsumeSystemBarsChanged = mPendingAlwaysConsumeSystemBars != mAttachInfo.mAlwaysConsumeSystemBars; final boolean colorModeChanged = hasColorModeChanged(lp.getColorMode()); updateColorModeIfNeeded(lp.getColorMode()); surfaceCreated = !hadSurface && mSurface.isValid(); surfaceDestroyed = hadSurface && !mSurface.isValid(); surfaceReplaced = (surfaceGenerationId != mSurface.getGenerationId()) Loading Loading @@ -2677,10 +2673,6 @@ public final class ViewRootImpl implements ViewParent, // hierarchy is measured below. dispatchApplyInsets = true; } if (colorModeChanged && mAttachInfo.mThreadedRenderer != null) { mAttachInfo.mThreadedRenderer.setWideGamut( lp.getColorMode() == ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT); } if (surfaceCreated) { // If we are creating a new surface, then we need to Loading Loading @@ -2725,7 +2717,7 @@ public final class ViewRootImpl implements ViewParent, mAttachInfo.mThreadedRenderer.destroy(); } } else if ((surfaceReplaced || surfaceSizeChanged || windowRelayoutWasForced || colorModeChanged) || surfaceSizeChanged || windowRelayoutWasForced) && mSurfaceHolder == null && mAttachInfo.mThreadedRenderer != null && mSurface.isValid()) { Loading Loading @@ -4557,18 +4549,16 @@ public final class ViewRootImpl implements ViewParent, } } private boolean hasColorModeChanged(int colorMode) { private void updateColorModeIfNeeded(int colorMode) { if (mAttachInfo.mThreadedRenderer == null) { return false; } final boolean isWideGamut = colorMode == ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT; if (mAttachInfo.mThreadedRenderer.isWideGamut() == isWideGamut) { return false; return; } if (isWideGamut && !mContext.getResources().getConfiguration().isScreenWideColorGamut()) { return false; // TODO: Centralize this sanitization? Why do we let setting bad modes? // Alternatively, can we just let HWUI figure it out? Do we need to care here? if (!mContext.getResources().getConfiguration().isScreenWideColorGamut()) { colorMode = ActivityInfo.COLOR_MODE_DEFAULT; } return true; mAttachInfo.mThreadedRenderer.setColorMode(colorMode); } @Override Loading graphics/java/android/graphics/HardwareRenderer.java +13 −18 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityManager; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.hardware.display.DisplayManager; import android.os.IBinder; Loading Loading @@ -157,7 +158,7 @@ public class HardwareRenderer { protected RenderNode mRootNode; private boolean mOpaque = true; private boolean mForceDark = false; private boolean mIsWideGamut = false; private @ActivityInfo.ColorMode int mColorMode = ActivityInfo.COLOR_MODE_DEFAULT; /** * Creates a new instance of a HardwareRenderer. The HardwareRenderer will default Loading @@ -167,7 +168,7 @@ public class HardwareRenderer { ProcessInitializer.sInstance.initDisplayInfo(); mRootNode = RenderNode.adopt(nCreateRootRenderNode()); mRootNode.setClipToBounds(false); mNativeProxy = nCreateProxy(!mOpaque, mIsWideGamut, mRootNode.mNativeRenderNode); mNativeProxy = nCreateProxy(!mOpaque, mRootNode.mNativeRenderNode); if (mNativeProxy == 0) { throw new OutOfMemoryError("Unable to create hardware renderer"); } Loading Loading @@ -619,17 +620,17 @@ public class HardwareRenderer { } /** * Enable/disable wide gamut rendering on this renderer. Whether or not the actual rendering * will be wide gamut depends on the hardware support for such rendering. * Sets the desired color mode on this renderer. Whether or not the actual rendering * will use the requested colorMode depends on the hardware support for such rendering. * * @param wideGamut true if this renderer should render in wide gamut, false if it should * render in sRGB * TODO: Figure out color... * @param colorMode The @{@link ActivityInfo.ColorMode} to request * @hide */ public void setWideGamut(boolean wideGamut) { mIsWideGamut = wideGamut; nSetWideGamut(mNativeProxy, wideGamut); public void setColorMode(@ActivityInfo.ColorMode int colorMode) { if (mColorMode != colorMode) { mColorMode = colorMode; nSetColorMode(mNativeProxy, colorMode); } } /** Loading Loading @@ -804,11 +805,6 @@ public class HardwareRenderer { nSetPictureCaptureCallback(mNativeProxy, callback); } /** @hide */ public boolean isWideGamut() { return mIsWideGamut; } /** called by native */ static void invokePictureCapturedCallback(long picturePtr, PictureCapturedCallback callback) { Picture picture = new Picture(picturePtr); Loading Loading @@ -1207,8 +1203,7 @@ public class HardwareRenderer { private static native long nCreateRootRenderNode(); private static native long nCreateProxy(boolean translucent, boolean isWideGamut, long rootRenderNode); private static native long nCreateProxy(boolean translucent, long rootRenderNode); private static native void nDeleteProxy(long nativeProxy); Loading @@ -1230,7 +1225,7 @@ public class HardwareRenderer { private static native void nSetOpaque(long nativeProxy, boolean opaque); private static native void nSetWideGamut(long nativeProxy, boolean wideGamut); private static native void nSetColorMode(long nativeProxy, int colorMode); private static native int nSyncAndDrawFrame(long nativeProxy, long[] frameInfo, int size); Loading libs/hwui/ColorMode.h 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once namespace android::uirenderer { // Must match the constants in ActivityInfo.java enum class ColorMode { // SRGB means HWUI will produce buffer in SRGB color space. Default = 0, // WideColorGamut selects the most optimal colorspace & format for the device's display // Most commonly DisplayP3 + RGBA_8888 currently. WideColorGamut = 1, // HDR Rec2020 + F16 Hdr = 2, // HDR Rec2020 + 1010102 Hdr10 = 3, }; } // namespace android::uirenderer libs/hwui/jni/android_graphics_HardwareRenderer.cpp +6 −7 Original line number Diff line number Diff line Loading @@ -143,11 +143,10 @@ static jlong android_view_ThreadedRenderer_createRootRenderNode(JNIEnv* env, job } static jlong android_view_ThreadedRenderer_createProxy(JNIEnv* env, jobject clazz, jboolean translucent, jboolean isWideGamut, jlong rootRenderNodePtr) { jboolean translucent, jlong rootRenderNodePtr) { RootRenderNode* rootRenderNode = reinterpret_cast<RootRenderNode*>(rootRenderNodePtr); ContextFactoryImpl factory(rootRenderNode); RenderProxy* proxy = new RenderProxy(translucent, rootRenderNode, &factory); proxy->setWideGamut(isWideGamut); return (jlong) proxy; } Loading Loading @@ -218,10 +217,10 @@ static void android_view_ThreadedRenderer_setOpaque(JNIEnv* env, jobject clazz, proxy->setOpaque(opaque); } static void android_view_ThreadedRenderer_setWideGamut(JNIEnv* env, jobject clazz, jlong proxyPtr, jboolean wideGamut) { static void android_view_ThreadedRenderer_setColorMode(JNIEnv* env, jobject clazz, jlong proxyPtr, jint colorMode) { RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); proxy->setWideGamut(wideGamut); proxy->setColorMode(static_cast<ColorMode>(colorMode)); } static int android_view_ThreadedRenderer_syncAndDrawFrame(JNIEnv* env, jobject clazz, Loading Loading @@ -659,7 +658,7 @@ static const JNINativeMethod gMethods[] = { (void*)android_view_ThreadedRenderer_setProcessStatsBuffer}, {"nGetRenderThreadTid", "(J)I", (void*)android_view_ThreadedRenderer_getRenderThreadTid}, {"nCreateRootRenderNode", "()J", (void*)android_view_ThreadedRenderer_createRootRenderNode}, {"nCreateProxy", "(ZZJ)J", (void*)android_view_ThreadedRenderer_createProxy}, {"nCreateProxy", "(ZJ)J", (void*)android_view_ThreadedRenderer_createProxy}, {"nDeleteProxy", "(J)V", (void*)android_view_ThreadedRenderer_deleteProxy}, {"nLoadSystemProperties", "(J)Z", (void*)android_view_ThreadedRenderer_loadSystemProperties}, Loading @@ -671,7 +670,7 @@ static const JNINativeMethod gMethods[] = { {"nSetLightAlpha", "(JFF)V", (void*)android_view_ThreadedRenderer_setLightAlpha}, {"nSetLightGeometry", "(JFFFF)V", (void*)android_view_ThreadedRenderer_setLightGeometry}, {"nSetOpaque", "(JZ)V", (void*)android_view_ThreadedRenderer_setOpaque}, {"nSetWideGamut", "(JZ)V", (void*)android_view_ThreadedRenderer_setWideGamut}, {"nSetColorMode", "(JI)V", (void*)android_view_ThreadedRenderer_setColorMode}, {"nSyncAndDrawFrame", "(J[JI)I", (void*)android_view_ThreadedRenderer_syncAndDrawFrame}, {"nDestroy", "(JJ)V", (void*)android_view_ThreadedRenderer_destroy}, {"nRegisterAnimatingRenderNode", "(JJ)V", Loading Loading
core/java/android/view/Surface.java +5 −1 Original line number Diff line number Diff line Loading @@ -22,6 +22,7 @@ import android.annotation.FloatRange; import android.annotation.IntDef; import android.annotation.NonNull; import android.compat.annotation.UnsupportedAppUsage; import android.content.pm.ActivityInfo; import android.content.res.CompatibilityInfo.Translator; import android.graphics.Canvas; import android.graphics.ColorSpace; Loading Loading @@ -1001,7 +1002,10 @@ public class Surface implements Parcelable { mHardwareRenderer = new HardwareRenderer(); mHardwareRenderer.setContentRoot(mRenderNode); mHardwareRenderer.setSurface(Surface.this, true); mHardwareRenderer.setWideGamut(isWideColorGamut); mHardwareRenderer.setColorMode( isWideColorGamut ? ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT : ActivityInfo.COLOR_MODE_DEFAULT); mHardwareRenderer.setLightSourceAlpha(0.0f, 0.0f); mHardwareRenderer.setLightSourceGeometry(0.0f, 0.0f, 0.0f, 0.0f); } Loading
core/java/android/view/ViewRootImpl.java +10 −20 Original line number Diff line number Diff line Loading @@ -1329,13 +1329,9 @@ public final class ViewRootImpl implements ViewParent, final boolean hasSurfaceInsets = insets.left != 0 || insets.right != 0 || insets.top != 0 || insets.bottom != 0; final boolean translucent = attrs.format != PixelFormat.OPAQUE || hasSurfaceInsets; final boolean wideGamut = mContext.getResources().getConfiguration().isScreenWideColorGamut() && attrs.getColorMode() == ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT; mAttachInfo.mThreadedRenderer = ThreadedRenderer.create(mContext, translucent, attrs.getTitle().toString()); mAttachInfo.mThreadedRenderer.setWideGamut(wideGamut); updateColorModeIfNeeded(attrs.getColorMode()); updateForceDarkMode(); if (mAttachInfo.mThreadedRenderer != null) { mAttachInfo.mHardwareAccelerated = Loading Loading @@ -2648,7 +2644,7 @@ public final class ViewRootImpl implements ViewParent, & WindowManagerGlobal.RELAYOUT_RES_SURFACE_RESIZED) != 0; final boolean alwaysConsumeSystemBarsChanged = mPendingAlwaysConsumeSystemBars != mAttachInfo.mAlwaysConsumeSystemBars; final boolean colorModeChanged = hasColorModeChanged(lp.getColorMode()); updateColorModeIfNeeded(lp.getColorMode()); surfaceCreated = !hadSurface && mSurface.isValid(); surfaceDestroyed = hadSurface && !mSurface.isValid(); surfaceReplaced = (surfaceGenerationId != mSurface.getGenerationId()) Loading Loading @@ -2677,10 +2673,6 @@ public final class ViewRootImpl implements ViewParent, // hierarchy is measured below. dispatchApplyInsets = true; } if (colorModeChanged && mAttachInfo.mThreadedRenderer != null) { mAttachInfo.mThreadedRenderer.setWideGamut( lp.getColorMode() == ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT); } if (surfaceCreated) { // If we are creating a new surface, then we need to Loading Loading @@ -2725,7 +2717,7 @@ public final class ViewRootImpl implements ViewParent, mAttachInfo.mThreadedRenderer.destroy(); } } else if ((surfaceReplaced || surfaceSizeChanged || windowRelayoutWasForced || colorModeChanged) || surfaceSizeChanged || windowRelayoutWasForced) && mSurfaceHolder == null && mAttachInfo.mThreadedRenderer != null && mSurface.isValid()) { Loading Loading @@ -4557,18 +4549,16 @@ public final class ViewRootImpl implements ViewParent, } } private boolean hasColorModeChanged(int colorMode) { private void updateColorModeIfNeeded(int colorMode) { if (mAttachInfo.mThreadedRenderer == null) { return false; } final boolean isWideGamut = colorMode == ActivityInfo.COLOR_MODE_WIDE_COLOR_GAMUT; if (mAttachInfo.mThreadedRenderer.isWideGamut() == isWideGamut) { return false; return; } if (isWideGamut && !mContext.getResources().getConfiguration().isScreenWideColorGamut()) { return false; // TODO: Centralize this sanitization? Why do we let setting bad modes? // Alternatively, can we just let HWUI figure it out? Do we need to care here? if (!mContext.getResources().getConfiguration().isScreenWideColorGamut()) { colorMode = ActivityInfo.COLOR_MODE_DEFAULT; } return true; mAttachInfo.mThreadedRenderer.setColorMode(colorMode); } @Override Loading
graphics/java/android/graphics/HardwareRenderer.java +13 −18 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.annotation.Nullable; import android.app.Activity; import android.app.ActivityManager; import android.content.Context; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.hardware.display.DisplayManager; import android.os.IBinder; Loading Loading @@ -157,7 +158,7 @@ public class HardwareRenderer { protected RenderNode mRootNode; private boolean mOpaque = true; private boolean mForceDark = false; private boolean mIsWideGamut = false; private @ActivityInfo.ColorMode int mColorMode = ActivityInfo.COLOR_MODE_DEFAULT; /** * Creates a new instance of a HardwareRenderer. The HardwareRenderer will default Loading @@ -167,7 +168,7 @@ public class HardwareRenderer { ProcessInitializer.sInstance.initDisplayInfo(); mRootNode = RenderNode.adopt(nCreateRootRenderNode()); mRootNode.setClipToBounds(false); mNativeProxy = nCreateProxy(!mOpaque, mIsWideGamut, mRootNode.mNativeRenderNode); mNativeProxy = nCreateProxy(!mOpaque, mRootNode.mNativeRenderNode); if (mNativeProxy == 0) { throw new OutOfMemoryError("Unable to create hardware renderer"); } Loading Loading @@ -619,17 +620,17 @@ public class HardwareRenderer { } /** * Enable/disable wide gamut rendering on this renderer. Whether or not the actual rendering * will be wide gamut depends on the hardware support for such rendering. * Sets the desired color mode on this renderer. Whether or not the actual rendering * will use the requested colorMode depends on the hardware support for such rendering. * * @param wideGamut true if this renderer should render in wide gamut, false if it should * render in sRGB * TODO: Figure out color... * @param colorMode The @{@link ActivityInfo.ColorMode} to request * @hide */ public void setWideGamut(boolean wideGamut) { mIsWideGamut = wideGamut; nSetWideGamut(mNativeProxy, wideGamut); public void setColorMode(@ActivityInfo.ColorMode int colorMode) { if (mColorMode != colorMode) { mColorMode = colorMode; nSetColorMode(mNativeProxy, colorMode); } } /** Loading Loading @@ -804,11 +805,6 @@ public class HardwareRenderer { nSetPictureCaptureCallback(mNativeProxy, callback); } /** @hide */ public boolean isWideGamut() { return mIsWideGamut; } /** called by native */ static void invokePictureCapturedCallback(long picturePtr, PictureCapturedCallback callback) { Picture picture = new Picture(picturePtr); Loading Loading @@ -1207,8 +1203,7 @@ public class HardwareRenderer { private static native long nCreateRootRenderNode(); private static native long nCreateProxy(boolean translucent, boolean isWideGamut, long rootRenderNode); private static native long nCreateProxy(boolean translucent, long rootRenderNode); private static native void nDeleteProxy(long nativeProxy); Loading @@ -1230,7 +1225,7 @@ public class HardwareRenderer { private static native void nSetOpaque(long nativeProxy, boolean opaque); private static native void nSetWideGamut(long nativeProxy, boolean wideGamut); private static native void nSetColorMode(long nativeProxy, int colorMode); private static native int nSyncAndDrawFrame(long nativeProxy, long[] frameInfo, int size); Loading
libs/hwui/ColorMode.h 0 → 100644 +34 −0 Original line number Diff line number Diff line /* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once namespace android::uirenderer { // Must match the constants in ActivityInfo.java enum class ColorMode { // SRGB means HWUI will produce buffer in SRGB color space. Default = 0, // WideColorGamut selects the most optimal colorspace & format for the device's display // Most commonly DisplayP3 + RGBA_8888 currently. WideColorGamut = 1, // HDR Rec2020 + F16 Hdr = 2, // HDR Rec2020 + 1010102 Hdr10 = 3, }; } // namespace android::uirenderer
libs/hwui/jni/android_graphics_HardwareRenderer.cpp +6 −7 Original line number Diff line number Diff line Loading @@ -143,11 +143,10 @@ static jlong android_view_ThreadedRenderer_createRootRenderNode(JNIEnv* env, job } static jlong android_view_ThreadedRenderer_createProxy(JNIEnv* env, jobject clazz, jboolean translucent, jboolean isWideGamut, jlong rootRenderNodePtr) { jboolean translucent, jlong rootRenderNodePtr) { RootRenderNode* rootRenderNode = reinterpret_cast<RootRenderNode*>(rootRenderNodePtr); ContextFactoryImpl factory(rootRenderNode); RenderProxy* proxy = new RenderProxy(translucent, rootRenderNode, &factory); proxy->setWideGamut(isWideGamut); return (jlong) proxy; } Loading Loading @@ -218,10 +217,10 @@ static void android_view_ThreadedRenderer_setOpaque(JNIEnv* env, jobject clazz, proxy->setOpaque(opaque); } static void android_view_ThreadedRenderer_setWideGamut(JNIEnv* env, jobject clazz, jlong proxyPtr, jboolean wideGamut) { static void android_view_ThreadedRenderer_setColorMode(JNIEnv* env, jobject clazz, jlong proxyPtr, jint colorMode) { RenderProxy* proxy = reinterpret_cast<RenderProxy*>(proxyPtr); proxy->setWideGamut(wideGamut); proxy->setColorMode(static_cast<ColorMode>(colorMode)); } static int android_view_ThreadedRenderer_syncAndDrawFrame(JNIEnv* env, jobject clazz, Loading Loading @@ -659,7 +658,7 @@ static const JNINativeMethod gMethods[] = { (void*)android_view_ThreadedRenderer_setProcessStatsBuffer}, {"nGetRenderThreadTid", "(J)I", (void*)android_view_ThreadedRenderer_getRenderThreadTid}, {"nCreateRootRenderNode", "()J", (void*)android_view_ThreadedRenderer_createRootRenderNode}, {"nCreateProxy", "(ZZJ)J", (void*)android_view_ThreadedRenderer_createProxy}, {"nCreateProxy", "(ZJ)J", (void*)android_view_ThreadedRenderer_createProxy}, {"nDeleteProxy", "(J)V", (void*)android_view_ThreadedRenderer_deleteProxy}, {"nLoadSystemProperties", "(J)Z", (void*)android_view_ThreadedRenderer_loadSystemProperties}, Loading @@ -671,7 +670,7 @@ static const JNINativeMethod gMethods[] = { {"nSetLightAlpha", "(JFF)V", (void*)android_view_ThreadedRenderer_setLightAlpha}, {"nSetLightGeometry", "(JFFFF)V", (void*)android_view_ThreadedRenderer_setLightGeometry}, {"nSetOpaque", "(JZ)V", (void*)android_view_ThreadedRenderer_setOpaque}, {"nSetWideGamut", "(JZ)V", (void*)android_view_ThreadedRenderer_setWideGamut}, {"nSetColorMode", "(JI)V", (void*)android_view_ThreadedRenderer_setColorMode}, {"nSyncAndDrawFrame", "(J[JI)I", (void*)android_view_ThreadedRenderer_syncAndDrawFrame}, {"nDestroy", "(JJ)V", (void*)android_view_ThreadedRenderer_destroy}, {"nRegisterAnimatingRenderNode", "(JJ)V", Loading