diff options
Diffstat (limited to 'libs/hwui/renderthread/EglManager.cpp')
-rw-r--r-- | libs/hwui/renderthread/EglManager.cpp | 46 |
1 files changed, 37 insertions, 9 deletions
diff --git a/libs/hwui/renderthread/EglManager.cpp b/libs/hwui/renderthread/EglManager.cpp index 5f8d7ad3373a..675df4118876 100644 --- a/libs/hwui/renderthread/EglManager.cpp +++ b/libs/hwui/renderthread/EglManager.cpp @@ -20,6 +20,7 @@ #include <log/log.h> #include <private/gui/SyncFeatures.h> #include <utils/Trace.h> +#include "utils/Color.h" #include "utils/StringUtils.h" #include "DeviceInfo.h" @@ -27,6 +28,7 @@ #include "Properties.h" #include <EGL/eglext.h> +#include <GLES/gl.h> #include <string> #include <vector> @@ -75,6 +77,7 @@ static struct { bool pixelFormatFloat = false; bool glColorSpace = false; bool scRGB = false; + bool displayP3 = false; bool contextPriority = false; bool surfacelessContext = false; } EglExtensions; @@ -125,6 +128,17 @@ void EglManager::initialize() { createPBufferSurface(); makeCurrent(mPBufferSurface, nullptr, /* force */ true); DeviceInfo::initialize(); + + mSurfaceColorGamut = DataSpaceToColorGamut( + static_cast<android_dataspace>(DeviceInfo::get()->getTargetDataSpace())); + + LOG_ALWAYS_FATAL_IF(mSurfaceColorGamut == SkColorSpace::kDCIP3_D65_Gamut && + !EglExtensions.displayP3, "EGL doesn't support Display P3."); + + mSurfaceColorType = PixelFormatToColorType( + static_cast<android_pixel_format>(DeviceInfo::get()->getTargetPixelFormat())); + mSurfaceColorSpace = DataSpaceToColorSpace( + static_cast<android_dataspace>(DeviceInfo::get()->getTargetDataSpace())); } void EglManager::initExtensions() { @@ -148,6 +162,7 @@ void EglManager::initExtensions() { #else EglExtensions.scRGB = extensions.has("EGL_EXT_gl_colorspace_scrgb"); #endif + EglExtensions.displayP3 = extensions.has("EGL_EXT_gl_colorspace_display_p3"); EglExtensions.contextPriority = extensions.has("EGL_IMG_context_priority"); EglExtensions.surfacelessContext = extensions.has("EGL_KHR_surfaceless_context"); } @@ -160,6 +175,10 @@ void EglManager::loadConfigs() { ALOGD("Swap behavior %d", static_cast<int>(mSwapBehavior)); EGLint swapBehavior = (mSwapBehavior == SwapBehavior::Preserved) ? EGL_SWAP_BEHAVIOR_PRESERVED_BIT : 0; + + // Note: The default pixel format is RGBA_8888, when other formats are + // available, we should check the target pixel format and configure the + // attributes list properly. EGLint attribs[] = {EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, EGL_RED_SIZE, @@ -255,11 +274,12 @@ void EglManager::createPBufferSurface() { } } -EGLSurface EglManager::createSurface(EGLNativeWindowType window, bool wideColorGamut) { +EGLSurface EglManager::createSurface(EGLNativeWindowType window, ColorMode colorMode) { LOG_ALWAYS_FATAL_IF(!hasEglContext(), "Not initialized"); - wideColorGamut = wideColorGamut && EglExtensions.glColorSpace && EglExtensions.scRGB && - EglExtensions.pixelFormatFloat && EglExtensions.noConfigContext; + bool wideColorGamut = colorMode == ColorMode::WideColorGamut && EglExtensions.glColorSpace && + EglExtensions.scRGB && EglExtensions.pixelFormatFloat && + EglExtensions.noConfigContext; // The color space we want to use depends on whether linear blending is turned // on and whether the app has requested wide color gamut rendering. When wide @@ -269,9 +289,9 @@ EGLSurface EglManager::createSurface(EGLNativeWindowType window, bool wideColorG // When wide gamut rendering is off: // - Blending is done by default in gamma space, which requires using a // linear EGL color space (the GPU uses the color values as is) - // - If linear blending is on, we must use the sRGB EGL color space (the - // GPU will perform sRGB to linear and linear to SRGB conversions before - // and after blending) + // - If linear blending is on, we must use the non-linear EGL color space + // (the GPU will perform sRGB to linear and linear to SRGB conversions + // before and after blending) // // When wide gamut rendering is on we cannot rely on the GPU performing // linear blending for us. We use two different color spaces to tag the @@ -279,7 +299,7 @@ EGLSurface EglManager::createSurface(EGLNativeWindowType window, bool wideColorG // - Gamma blending (default) requires the use of the scRGB-nl color space // - Linear blending requires the use of the scRGB color space - // Not all Android targets support the EGL_GL_COLOR_SPACE_KHR extension + // Not all Android targets support the EGL_GL_COLORSPACE_KHR extension // We insert to placeholders to set EGL_GL_COLORSPACE_KHR and its value. // According to section 3.4.1 of the EGL specification, the attributes // list is considered empty if the first entry is EGL_NONE @@ -291,13 +311,21 @@ EGLSurface EglManager::createSurface(EGLNativeWindowType window, bool wideColorG if (wideColorGamut) { attribs[1] = EGL_GL_COLORSPACE_SCRGB_LINEAR_EXT; } else { - attribs[1] = EGL_GL_COLORSPACE_SRGB_KHR; + if (mSurfaceColorGamut == SkColorSpace::kDCIP3_D65_Gamut) { + attribs[1] = EGL_GL_COLORSPACE_DISPLAY_P3_EXT; + } else { + attribs[1] = EGL_GL_COLORSPACE_SRGB_KHR; + } } #else if (wideColorGamut) { attribs[1] = EGL_GL_COLORSPACE_SCRGB_EXT; } else { - attribs[1] = EGL_GL_COLORSPACE_LINEAR_KHR; + if (mSurfaceColorGamut == SkColorSpace::kDCIP3_D65_Gamut) { + attribs[1] = EGL_GL_COLORSPACE_DISPLAY_P3_EXT; + } else { + attribs[1] = EGL_GL_COLORSPACE_LINEAR_KHR; + } } #endif } |