From: Courtney Goeltzenleuchter Date: Fri, 7 Jul 2017 20:55:40 +0000 (-0600) Subject: Check wide-color support before adding extensions X-Git-Tag: android-x86-9.0-r1~279^2~1 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=e5d6f994158d554c692afae0f547d89c75abde71;p=android-x86%2Fframeworks-native.git Check wide-color support before adding extensions Don't want applications seeing the wide-color EGL extensions if the device or display cannot support wide-color. Bug: 63170158 Test: adb shell /data/nativetest/test-opengl-gl2_basic/test-opengl-gl2_basic Verify that EGL_EXT_gl_colorspace_scrgb, EGL_EXT_gl_colorspace_scrgb_linear, EGL_EXT_gl_colorspace_display_p3_linear and EGL_EXT_gl_colorspace_display_p3 are not present on devices that do not support wide-color, e.g. Nexus 6P Change-Id: I46a26a67f2d6da9c5aad50d884ef02a62ccb6945 --- diff --git a/opengl/libs/Android.bp b/opengl/libs/Android.bp index a3446368de..b4cc2113e9 100644 --- a/opengl/libs/Android.bp +++ b/opengl/libs/Android.bp @@ -127,7 +127,14 @@ cc_library_shared { "EGL/Loader.cpp", "EGL/BlobCache.cpp", ], - shared_libs: ["libvndksupport"], + shared_libs: [ + "libvndksupport", + "android.hardware.configstore@1.0", + "android.hardware.configstore-utils", + "libhidlbase", + "libhidltransport", + "libutils", + ], static_libs: ["libEGL_getProcAddress"], ldflags: ["-Wl,--exclude-libs=ALL"], export_include_dirs: ["EGL/include"], diff --git a/opengl/libs/EGL/eglApi.cpp b/opengl/libs/EGL/eglApi.cpp index 2fa36faf53..0214b0eb56 100644 --- a/opengl/libs/EGL/eglApi.cpp +++ b/opengl/libs/EGL/eglApi.cpp @@ -87,10 +87,6 @@ char const * const gBuiltinExtensionString = "EGL_ANDROID_get_native_client_buffer " "EGL_ANDROID_front_buffer_auto_refresh " "EGL_ANDROID_get_frame_timestamps " - "EGL_EXT_gl_colorspace_scrgb " - "EGL_EXT_gl_colorspace_scrgb_linear " - "EGL_EXT_gl_colorspace_display_p3_linear " - "EGL_EXT_gl_colorspace_display_p3 " ; char const * const gExtensionString = @@ -529,19 +525,25 @@ static EGLBoolean stripColorSpaceAttribute(egl_display_ptr dp, const EGLint* att return stripped; } -static EGLBoolean getColorSpaceAttribute(egl_display_ptr dp, const EGLint* attrib_list, - EGLint& colorSpace, android_dataspace& dataSpace) { +static EGLBoolean getColorSpaceAttribute(egl_display_ptr dp, NativeWindowType window, + const EGLint* attrib_list, EGLint& colorSpace, + android_dataspace& dataSpace) { colorSpace = EGL_GL_COLORSPACE_LINEAR_KHR; dataSpace = HAL_DATASPACE_UNKNOWN; + if (attrib_list && dp->haveExtension("EGL_KHR_gl_colorspace")) { for (const EGLint* attr = attrib_list; *attr != EGL_NONE; attr += 2) { if (*attr == EGL_GL_COLORSPACE_KHR) { colorSpace = attr[1]; bool found = false; + bool verify = true; // Verify that color space is allowed if (colorSpace == EGL_GL_COLORSPACE_SRGB_KHR || colorSpace == EGL_GL_COLORSPACE_LINEAR_KHR) { + // SRGB and LINEAR are always supported when EGL_KHR_gl_colorspace + // is available, so no need to verify. found = true; + verify = false; } else if (colorSpace == EGL_EXT_gl_colorspace_bt2020_linear && dp->haveExtension("EGL_EXT_gl_colorspace_bt2020_linear")) { found = true; @@ -564,6 +566,31 @@ static EGLBoolean getColorSpaceAttribute(egl_display_ptr dp, const EGLint* attri if (!found) { return false; } + if (verify && window) { + bool wide_color_support = true; + // Ordinarily we'd put a call to native_window_get_wide_color_support + // at the beginning of the function so that we'll have the + // result when needed elsewhere in the function. + // However, because eglCreateWindowSurface is called by SurfaceFlinger and + // SurfaceFlinger is required to answer the call below we would + // end up in a deadlock situation. By moving the call to only happen + // if the application has specifically asked for wide-color we avoid + // the deadlock with SurfaceFlinger since it will not ask for a + // wide-color surface. + int err = native_window_get_wide_color_support(window, &wide_color_support); + + if (err) { + ALOGE("getColorSpaceAttribute: invalid window (win=%p) " + "failed (%#x) (already connected to another API?)", + window, err); + return false; + } + if (!wide_color_support) { + // Application has asked for a wide-color colorspace but + // wide-color support isn't available on the display the window is on. + return false; + } + } // Only change the dataSpace from default if the application // has explicitly set the color space with a EGL_GL_COLORSPACE_KHR attribute. dataSpace = modifyBufferDataspace(dataSpace, colorSpace); @@ -573,6 +600,11 @@ static EGLBoolean getColorSpaceAttribute(egl_display_ptr dp, const EGLint* attri return true; } +static EGLBoolean getColorSpaceAttribute(egl_display_ptr dp, const EGLint* attrib_list, + EGLint& colorSpace, android_dataspace& dataSpace) { + return getColorSpaceAttribute(dp, NULL, attrib_list, colorSpace, dataSpace); +} + void getNativePixelFormat(EGLDisplay dpy, egl_connection_t* cnx, EGLConfig config, EGLint& format) { // Set the native window's buffers format to match what this config requests. // Whether to use sRGB gamma is not part of the EGLconfig, but is part @@ -667,7 +699,7 @@ EGLSurface eglCreateWindowSurface( EGLDisplay dpy, EGLConfig config, // now select correct colorspace and dataspace based on user's attribute list EGLint colorSpace; android_dataspace dataSpace; - if (!getColorSpaceAttribute(dp, attrib_list, colorSpace, dataSpace)) { + if (!getColorSpaceAttribute(dp, window, attrib_list, colorSpace, dataSpace)) { ALOGE("error invalid colorspace: %d", colorSpace); return setError(EGL_BAD_ATTRIBUTE, EGL_NO_SURFACE); } diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp index b696920023..4e5833ab12 100644 --- a/opengl/libs/EGL/egl_display.cpp +++ b/opengl/libs/EGL/egl_display.cpp @@ -30,6 +30,12 @@ #include "Loader.h" #include +#include +#include + +using namespace android::hardware::configstore; +using namespace android::hardware::configstore::V1_0; + // ---------------------------------------------------------------------------- namespace android { // ---------------------------------------------------------------------------- @@ -192,6 +198,18 @@ EGLBoolean egl_display_t::initialize(EGLint *major, EGLint *minor) { mClientApiString = sClientApiString; mExtensionString = gBuiltinExtensionString; + + bool wideColorBoardConfig = + getBool( + false); + + // Add wide-color extensions if device can support wide-color + if (wideColorBoardConfig) { + mExtensionString.append( + "EGL_EXT_gl_colorspace_scrgb EGL_EXT_gl_colorspace_scrgb_linear " + "EGL_EXT_gl_colorspace_display_p3_linear EGL_EXT_gl_colorspace_display_p3 "); + } + char const* start = gExtensionString; do { // length of the extension name