Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include <gtest/gtest.h> |
| 18 | |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 19 | #include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h> |
| 20 | |
| 21 | #include <configstore/Utils.h> |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 22 | #include <utils/String8.h> |
| 23 | |
| 24 | #include <EGL/egl.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 25 | #include <gui/Surface.h> |
Mathias Agopian | 2b5dd40 | 2017-02-07 17:36:19 -0800 | [diff] [blame] | 26 | #include <gui/IConsumerListener.h> |
| 27 | #include <gui/IProducerListener.h> |
| 28 | #include <gui/IGraphicBufferConsumer.h> |
| 29 | #include <gui/BufferQueue.h> |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 30 | |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 31 | bool hasEglExtension(EGLDisplay dpy, const char* extensionName) { |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 32 | const char* exts = eglQueryString(dpy, EGL_EXTENSIONS); |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 33 | size_t cropExtLen = strlen(extensionName); |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 34 | size_t extsLen = strlen(exts); |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 35 | bool equal = !strcmp(extensionName, exts); |
| 36 | android::String8 extString(extensionName); |
| 37 | android::String8 space(" "); |
| 38 | bool atStart = !strncmp(extString + space, exts, cropExtLen + 1); |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 39 | bool atEnd = (cropExtLen + 1) < extsLen && |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 40 | !strcmp(space + extString, exts + extsLen - (cropExtLen + 1)); |
| 41 | bool inMiddle = strstr(exts, space + extString + space); |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 42 | return equal || atStart || atEnd || inMiddle; |
| 43 | } |
| 44 | |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 45 | namespace android { |
| 46 | |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 47 | #define EGL_UNSIGNED_TRUE static_cast<EGLBoolean>(EGL_TRUE) |
| 48 | |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 49 | // retrieve wide-color setting from configstore |
| 50 | using namespace android::hardware::configstore; |
Jaesoo Lee | 3b746b3 | 2017-05-02 22:19:39 +0900 | [diff] [blame] | 51 | using namespace android::hardware::configstore::V1_0; |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 52 | |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 53 | #define METADATA_SCALE(x) (static_cast<EGLint>(x * EGL_METADATA_SCALING_EXT)) |
| 54 | |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 55 | static bool hasWideColorDisplay = |
| 56 | getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(false); |
| 57 | |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 58 | static bool hasHdrDisplay = |
| 59 | getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasHDRDisplay>(false); |
| 60 | |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 61 | class EGLTest : public ::testing::Test { |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 62 | public: |
| 63 | void get8BitConfig(EGLConfig& config); |
| 64 | void addOptionalWindowMetadata(std::vector<EGLint>& attrs); |
| 65 | void checkOptionalWindowMetadata(EGLSurface eglSurface); |
| 66 | |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 67 | protected: |
| 68 | EGLDisplay mEglDisplay; |
| 69 | |
| 70 | protected: |
| 71 | EGLTest() : |
| 72 | mEglDisplay(EGL_NO_DISPLAY) { |
| 73 | } |
| 74 | |
| 75 | virtual void SetUp() { |
| 76 | mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 77 | ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay); |
| 78 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 79 | |
| 80 | EGLint majorVersion; |
| 81 | EGLint minorVersion; |
| 82 | EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion)); |
| 83 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 84 | RecordProperty("EglVersionMajor", majorVersion); |
| 85 | RecordProperty("EglVersionMajor", minorVersion); |
| 86 | } |
| 87 | |
| 88 | virtual void TearDown() { |
| 89 | EGLBoolean success = eglTerminate(mEglDisplay); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 90 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 91 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 92 | } |
| 93 | }; |
| 94 | |
| 95 | TEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) { |
| 96 | |
| 97 | EGLint numConfigs; |
| 98 | EGLConfig config; |
| 99 | EGLBoolean success; |
| 100 | EGLint attrs[] = { |
| 101 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 102 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 103 | EGL_NONE |
| 104 | }; |
| 105 | |
| 106 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 107 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 108 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 109 | ASSERT_GE(numConfigs, 1); |
| 110 | |
| 111 | EGLint components[3]; |
| 112 | |
| 113 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 114 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 115 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 116 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 117 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 118 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 119 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 120 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 121 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 122 | |
| 123 | EXPECT_GE(components[0], 8); |
| 124 | EXPECT_GE(components[1], 8); |
| 125 | EXPECT_GE(components[2], 8); |
| 126 | } |
| 127 | |
Daniel Lam | 1cbcb98 | 2012-04-16 22:21:02 -0700 | [diff] [blame] | 128 | TEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) { |
| 129 | EGLint numConfigs; |
| 130 | EGLConfig config; |
| 131 | EGLint attrs[] = { |
| 132 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 133 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 134 | EGL_RED_SIZE, 8, |
| 135 | EGL_GREEN_SIZE, 8, |
| 136 | EGL_BLUE_SIZE, 8, |
| 137 | EGL_ALPHA_SIZE, 8, |
| 138 | EGL_NONE |
| 139 | }; |
| 140 | EXPECT_TRUE(eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs)); |
| 141 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 142 | struct DummyConsumer : public BnConsumerListener { |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 143 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 144 | void onBuffersReleased() override {} |
| 145 | void onSidebandStreamChanged() override {} |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
Daniel Lam | 1cbcb98 | 2012-04-16 22:21:02 -0700 | [diff] [blame] | 148 | // Create a EGLSurface |
Dan Stoza | 5603a2f | 2014-04-07 13:41:37 -0700 | [diff] [blame] | 149 | sp<IGraphicBufferProducer> producer; |
| 150 | sp<IGraphicBufferConsumer> consumer; |
| 151 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 152 | consumer->consumerConnect(new DummyConsumer, false); |
| 153 | sp<Surface> mSTC = new Surface(producer); |
Daniel Lam | 1cbcb98 | 2012-04-16 22:21:02 -0700 | [diff] [blame] | 154 | sp<ANativeWindow> mANW = mSTC; |
| 155 | |
| 156 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, |
| 157 | mANW.get(), NULL); |
| 158 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 159 | ASSERT_NE(EGL_NO_SURFACE, eglSurface) ; |
| 160 | |
| 161 | // do not destroy eglSurface |
| 162 | // eglTerminate is called in the tear down and should destroy it for us |
| 163 | } |
| 164 | |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 165 | TEST_F(EGLTest, EGLConfigRGBA8888First) { |
| 166 | |
| 167 | EGLint numConfigs; |
| 168 | EGLConfig config; |
| 169 | EGLBoolean success; |
| 170 | EGLint attrs[] = { |
| 171 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 172 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 173 | EGL_RED_SIZE, 8, |
| 174 | EGL_GREEN_SIZE, 8, |
| 175 | EGL_BLUE_SIZE, 8, |
| 176 | EGL_ALPHA_SIZE, 8, |
| 177 | EGL_NONE |
| 178 | }; |
| 179 | |
| 180 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 181 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 182 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 183 | ASSERT_GE(numConfigs, 1); |
| 184 | |
| 185 | EGLint components[4]; |
| 186 | |
| 187 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 188 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 189 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 190 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 191 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 192 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 193 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 194 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 195 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 196 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 197 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 198 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 199 | |
| 200 | EXPECT_GE(components[0], 8); |
| 201 | EXPECT_GE(components[1], 8); |
| 202 | EXPECT_GE(components[2], 8); |
| 203 | EXPECT_GE(components[3], 8); |
| 204 | } |
| 205 | |
Courtney Goeltzenleuchter | 2c325e2 | 2017-04-25 14:40:42 -0600 | [diff] [blame] | 206 | TEST_F(EGLTest, EGLDisplayP3) { |
| 207 | EGLint numConfigs; |
| 208 | EGLConfig config; |
| 209 | EGLBoolean success; |
| 210 | |
| 211 | if (!hasWideColorDisplay) { |
| 212 | // skip this test if device does not have wide-color display |
Courtney Goeltzenleuchter | e417726 | 2017-07-10 16:34:25 -0600 | [diff] [blame] | 213 | std::cerr << "[ ] Device does not support wide-color, test skipped" << std::endl; |
Courtney Goeltzenleuchter | 2c325e2 | 2017-04-25 14:40:42 -0600 | [diff] [blame] | 214 | return; |
| 215 | } |
| 216 | |
| 217 | // Test that display-p3 extensions exist |
| 218 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_gl_colorspace_display_p3")); |
| 219 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_gl_colorspace_display_p3_linear")); |
| 220 | |
| 221 | // Use 8-bit to keep forcus on Display-P3 aspect |
| 222 | EGLint attrs[] = { |
| 223 | // clang-format off |
| 224 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 225 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 226 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, |
| 227 | EGL_RED_SIZE, 8, |
| 228 | EGL_GREEN_SIZE, 8, |
| 229 | EGL_BLUE_SIZE, 8, |
| 230 | EGL_ALPHA_SIZE, 8, |
| 231 | EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT, |
| 232 | EGL_NONE, EGL_NONE |
| 233 | // clang-format on |
| 234 | }; |
| 235 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
| 236 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 237 | ASSERT_EQ(1, numConfigs); |
| 238 | |
| 239 | EGLint components[4]; |
| 240 | EGLint value; |
| 241 | eglGetConfigAttrib(mEglDisplay, config, EGL_CONFIG_ID, &value); |
| 242 | |
| 243 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
| 244 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 245 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 246 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
| 247 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 248 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 249 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
| 250 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 251 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 252 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); |
| 253 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 254 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 255 | |
| 256 | EXPECT_EQ(components[0], 8); |
| 257 | EXPECT_EQ(components[1], 8); |
| 258 | EXPECT_EQ(components[2], 8); |
| 259 | EXPECT_EQ(components[3], 8); |
| 260 | |
| 261 | struct DummyConsumer : public BnConsumerListener { |
| 262 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 263 | void onBuffersReleased() override {} |
| 264 | void onSidebandStreamChanged() override {} |
| 265 | }; |
| 266 | |
| 267 | // Create a EGLSurface |
| 268 | sp<IGraphicBufferProducer> producer; |
| 269 | sp<IGraphicBufferConsumer> consumer; |
| 270 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 271 | consumer->consumerConnect(new DummyConsumer, false); |
| 272 | sp<Surface> mSTC = new Surface(producer); |
| 273 | sp<ANativeWindow> mANW = mSTC; |
| 274 | EGLint winAttrs[] = { |
| 275 | // clang-format off |
| 276 | EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, |
| 277 | EGL_NONE, EGL_NONE |
| 278 | // clang-format on |
| 279 | }; |
| 280 | |
| 281 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, mANW.get(), winAttrs); |
| 282 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 283 | ASSERT_NE(EGL_NO_SURFACE, eglSurface); |
| 284 | |
| 285 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_GL_COLORSPACE_KHR, &value); |
| 286 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 287 | ASSERT_EQ(EGL_GL_COLORSPACE_DISPLAY_P3_EXT, value); |
| 288 | |
| 289 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, eglSurface)); |
| 290 | } |
| 291 | |
| 292 | TEST_F(EGLTest, EGLDisplayP31010102) { |
| 293 | EGLint numConfigs; |
| 294 | EGLConfig config; |
| 295 | EGLBoolean success; |
| 296 | |
| 297 | if (!hasWideColorDisplay) { |
| 298 | // skip this test if device does not have wide-color display |
Courtney Goeltzenleuchter | e417726 | 2017-07-10 16:34:25 -0600 | [diff] [blame] | 299 | std::cerr << "[ ] Device does not support wide-color, test skipped" << std::endl; |
Courtney Goeltzenleuchter | 2c325e2 | 2017-04-25 14:40:42 -0600 | [diff] [blame] | 300 | return; |
| 301 | } |
| 302 | |
| 303 | // Test that display-p3 extensions exist |
| 304 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_gl_colorspace_display_p3")); |
| 305 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_gl_colorspace_display_p3_linear")); |
| 306 | |
| 307 | // Use 8-bit to keep forcus on Display-P3 aspect |
| 308 | EGLint attrs[] = { |
| 309 | // clang-format off |
| 310 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 311 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 312 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, |
| 313 | EGL_RED_SIZE, 10, |
| 314 | EGL_GREEN_SIZE, 10, |
| 315 | EGL_BLUE_SIZE, 10, |
| 316 | EGL_ALPHA_SIZE, 2, |
| 317 | EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT, |
| 318 | EGL_NONE, EGL_NONE |
| 319 | // clang-format on |
| 320 | }; |
| 321 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
| 322 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 323 | ASSERT_EQ(1, numConfigs); |
| 324 | |
| 325 | EGLint components[4]; |
| 326 | EGLint value; |
| 327 | eglGetConfigAttrib(mEglDisplay, config, EGL_CONFIG_ID, &value); |
| 328 | |
| 329 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
| 330 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 331 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 332 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
| 333 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 334 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 335 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
| 336 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 337 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 338 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); |
| 339 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 340 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 341 | |
| 342 | EXPECT_EQ(components[0], 10); |
| 343 | EXPECT_EQ(components[1], 10); |
| 344 | EXPECT_EQ(components[2], 10); |
| 345 | EXPECT_EQ(components[3], 2); |
| 346 | |
| 347 | struct DummyConsumer : public BnConsumerListener { |
| 348 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 349 | void onBuffersReleased() override {} |
| 350 | void onSidebandStreamChanged() override {} |
| 351 | }; |
| 352 | |
| 353 | // Create a EGLSurface |
| 354 | sp<IGraphicBufferProducer> producer; |
| 355 | sp<IGraphicBufferConsumer> consumer; |
| 356 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 357 | consumer->consumerConnect(new DummyConsumer, false); |
| 358 | sp<Surface> mSTC = new Surface(producer); |
| 359 | sp<ANativeWindow> mANW = mSTC; |
| 360 | EGLint winAttrs[] = { |
| 361 | // clang-format off |
| 362 | EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, |
| 363 | EGL_NONE, EGL_NONE |
| 364 | // clang-format on |
| 365 | }; |
| 366 | |
| 367 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, mANW.get(), winAttrs); |
| 368 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 369 | ASSERT_NE(EGL_NO_SURFACE, eglSurface); |
| 370 | |
| 371 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_GL_COLORSPACE_KHR, &value); |
| 372 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 373 | ASSERT_EQ(EGL_GL_COLORSPACE_DISPLAY_P3_EXT, value); |
| 374 | |
| 375 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, eglSurface)); |
| 376 | } |
| 377 | |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 378 | void EGLTest::get8BitConfig(EGLConfig& config) { |
| 379 | EGLint numConfigs; |
| 380 | EGLBoolean success; |
| 381 | |
| 382 | // Use 8-bit to keep focus on colorspace aspect |
| 383 | const EGLint attrs[] = { |
| 384 | // clang-format off |
| 385 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 386 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 387 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, |
| 388 | EGL_RED_SIZE, 8, |
| 389 | EGL_GREEN_SIZE, 8, |
| 390 | EGL_BLUE_SIZE, 8, |
| 391 | EGL_ALPHA_SIZE, 8, |
| 392 | EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT, |
| 393 | EGL_NONE, |
| 394 | // clang-format on |
| 395 | }; |
| 396 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
| 397 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 398 | ASSERT_EQ(1, numConfigs); |
| 399 | |
| 400 | EGLint components[4]; |
| 401 | EGLint value; |
| 402 | eglGetConfigAttrib(mEglDisplay, config, EGL_CONFIG_ID, &value); |
| 403 | |
| 404 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
| 405 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 406 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 407 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
| 408 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 409 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 410 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
| 411 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 412 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 413 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); |
| 414 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 415 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 416 | |
| 417 | // Verify component sizes on config match what was asked for. |
| 418 | EXPECT_EQ(components[0], 8); |
| 419 | EXPECT_EQ(components[1], 8); |
| 420 | EXPECT_EQ(components[2], 8); |
| 421 | EXPECT_EQ(components[3], 8); |
| 422 | } |
| 423 | |
| 424 | void EGLTest::addOptionalWindowMetadata(std::vector<EGLint>& attrs) { |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 425 | if (hasEglExtension(mEglDisplay, "EGL_EXT_surface_SMPTE2086_metadata")) { |
| 426 | attrs.push_back(EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 427 | attrs.push_back(METADATA_SCALE(0.640)); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 428 | attrs.push_back(EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 429 | attrs.push_back(METADATA_SCALE(0.330)); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 430 | attrs.push_back(EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 431 | attrs.push_back(METADATA_SCALE(0.290)); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 432 | attrs.push_back(EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 433 | attrs.push_back(METADATA_SCALE(0.600)); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 434 | attrs.push_back(EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 435 | attrs.push_back(METADATA_SCALE(0.150)); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 436 | attrs.push_back(EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 437 | attrs.push_back(METADATA_SCALE(0.060)); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 438 | attrs.push_back(EGL_SMPTE2086_WHITE_POINT_X_EXT); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 439 | attrs.push_back(METADATA_SCALE(0.3127)); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 440 | attrs.push_back(EGL_SMPTE2086_WHITE_POINT_Y_EXT); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 441 | attrs.push_back(METADATA_SCALE(0.3290)); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 442 | attrs.push_back(EGL_SMPTE2086_MAX_LUMINANCE_EXT); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 443 | attrs.push_back(METADATA_SCALE(300)); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 444 | attrs.push_back(EGL_SMPTE2086_MIN_LUMINANCE_EXT); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 445 | attrs.push_back(METADATA_SCALE(0.7)); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | if (hasEglExtension(mEglDisplay, "EGL_EXT_surface_CTA861_3_metadata")) { |
| 449 | attrs.push_back(EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 450 | attrs.push_back(METADATA_SCALE(300)); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 451 | attrs.push_back(EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 452 | attrs.push_back(METADATA_SCALE(75)); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | |
| 456 | void EGLTest::checkOptionalWindowMetadata(EGLSurface eglSurface) { |
| 457 | EGLBoolean success; |
| 458 | EGLint value; |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 459 | |
| 460 | if (hasEglExtension(mEglDisplay, "EGL_EXT_surface_SMPTE2086_metadata")) { |
| 461 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_SMPTE2086_DISPLAY_PRIMARY_RX_EXT, &value); |
| 462 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 463 | ASSERT_EQ(METADATA_SCALE(0.640), value); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 464 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_SMPTE2086_DISPLAY_PRIMARY_RY_EXT, &value); |
| 465 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 466 | ASSERT_EQ(METADATA_SCALE(0.330), value); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 467 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_SMPTE2086_DISPLAY_PRIMARY_GX_EXT, &value); |
| 468 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 469 | ASSERT_EQ(METADATA_SCALE(0.290), value); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 470 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_SMPTE2086_DISPLAY_PRIMARY_GY_EXT, &value); |
| 471 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 472 | ASSERT_EQ(METADATA_SCALE(0.600), value); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 473 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_SMPTE2086_DISPLAY_PRIMARY_BX_EXT, &value); |
| 474 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 475 | ASSERT_EQ(METADATA_SCALE(0.150), value); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 476 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_SMPTE2086_DISPLAY_PRIMARY_BY_EXT, &value); |
| 477 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 478 | ASSERT_EQ(METADATA_SCALE(0.060), value); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 479 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_SMPTE2086_WHITE_POINT_X_EXT, &value); |
| 480 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 481 | ASSERT_EQ(METADATA_SCALE(0.3127), value); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 482 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_SMPTE2086_WHITE_POINT_Y_EXT, &value); |
| 483 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 484 | ASSERT_EQ(METADATA_SCALE(0.3290), value); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 485 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_SMPTE2086_MAX_LUMINANCE_EXT, &value); |
| 486 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 487 | ASSERT_EQ(METADATA_SCALE(300.0), value); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 488 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_SMPTE2086_MIN_LUMINANCE_EXT, &value); |
| 489 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 490 | ASSERT_EQ(METADATA_SCALE(0.7), value); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 491 | } |
| 492 | |
| 493 | if (hasEglExtension(mEglDisplay, "EGL_EXT_surface_CTA861_3_metadata")) { |
| 494 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_CTA861_3_MAX_CONTENT_LIGHT_LEVEL_EXT, &value); |
| 495 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 496 | ASSERT_EQ(METADATA_SCALE(300.0), value); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 497 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_CTA861_3_MAX_FRAME_AVERAGE_LEVEL_EXT, &value); |
| 498 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Courtney Goeltzenleuchter | 786ab88 | 2018-01-26 13:37:33 -0800 | [diff] [blame^] | 499 | ASSERT_EQ(METADATA_SCALE(75.0), value); |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 500 | } |
| 501 | } |
| 502 | |
| 503 | TEST_F(EGLTest, EGLBT2020Linear) { |
| 504 | EGLConfig config; |
| 505 | EGLBoolean success; |
| 506 | |
| 507 | if (!hasHdrDisplay) { |
| 508 | // skip this test if device does not have HDR display |
| 509 | RecordProperty("hasHdrDisplay", false); |
| 510 | return; |
| 511 | } |
| 512 | |
| 513 | // Test that bt2020 linear extension exists |
| 514 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_gl_colorspace_bt2020_linear")) |
| 515 | << "EGL_EXT_gl_colorspace_bt2020_linear extension not available"; |
| 516 | |
| 517 | ASSERT_NO_FATAL_FAILURE(get8BitConfig(config)); |
| 518 | |
| 519 | struct DummyConsumer : public BnConsumerListener { |
| 520 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 521 | void onBuffersReleased() override {} |
| 522 | void onSidebandStreamChanged() override {} |
| 523 | }; |
| 524 | |
| 525 | // Create a EGLSurface |
| 526 | sp<IGraphicBufferProducer> producer; |
| 527 | sp<IGraphicBufferConsumer> consumer; |
| 528 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 529 | consumer->consumerConnect(new DummyConsumer, false); |
| 530 | sp<Surface> mSTC = new Surface(producer); |
| 531 | sp<ANativeWindow> mANW = mSTC; |
| 532 | |
| 533 | std::vector<EGLint> winAttrs; |
| 534 | winAttrs.push_back(EGL_GL_COLORSPACE_KHR); |
| 535 | winAttrs.push_back(EGL_GL_COLORSPACE_BT2020_PQ_EXT); |
| 536 | |
| 537 | ASSERT_NO_FATAL_FAILURE(addOptionalWindowMetadata(winAttrs)); |
| 538 | |
| 539 | winAttrs.push_back(EGL_NONE); |
| 540 | |
| 541 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, mANW.get(), winAttrs.data()); |
| 542 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 543 | ASSERT_NE(EGL_NO_SURFACE, eglSurface); |
| 544 | |
| 545 | EGLint value; |
| 546 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_GL_COLORSPACE_KHR, &value); |
| 547 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 548 | ASSERT_EQ(EGL_GL_COLORSPACE_BT2020_PQ_EXT, value); |
| 549 | |
| 550 | ASSERT_NO_FATAL_FAILURE(checkOptionalWindowMetadata(eglSurface)); |
| 551 | |
| 552 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, eglSurface)); |
| 553 | } |
| 554 | |
| 555 | TEST_F(EGLTest, EGLBT2020PQ) { |
| 556 | EGLConfig config; |
| 557 | EGLBoolean success; |
| 558 | |
| 559 | if (!hasHdrDisplay) { |
| 560 | // skip this test if device does not have HDR display |
| 561 | RecordProperty("hasHdrDisplay", false); |
| 562 | return; |
| 563 | } |
| 564 | |
| 565 | // Test that bt2020-pq extension exists |
| 566 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_gl_colorspace_bt2020_pq")) |
| 567 | << "EGL_EXT_gl_colorspace_bt2020_pq extension not available"; |
| 568 | |
| 569 | ASSERT_NO_FATAL_FAILURE(get8BitConfig(config)); |
| 570 | |
| 571 | struct DummyConsumer : public BnConsumerListener { |
| 572 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 573 | void onBuffersReleased() override {} |
| 574 | void onSidebandStreamChanged() override {} |
| 575 | }; |
| 576 | |
| 577 | // Create a EGLSurface |
| 578 | sp<IGraphicBufferProducer> producer; |
| 579 | sp<IGraphicBufferConsumer> consumer; |
| 580 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 581 | consumer->consumerConnect(new DummyConsumer, false); |
| 582 | sp<Surface> mSTC = new Surface(producer); |
| 583 | sp<ANativeWindow> mANW = mSTC; |
| 584 | std::vector<EGLint> winAttrs; |
| 585 | winAttrs.push_back(EGL_GL_COLORSPACE_KHR); |
| 586 | winAttrs.push_back(EGL_GL_COLORSPACE_BT2020_PQ_EXT); |
| 587 | |
| 588 | ASSERT_NO_FATAL_FAILURE(addOptionalWindowMetadata(winAttrs)); |
| 589 | |
| 590 | winAttrs.push_back(EGL_NONE); |
| 591 | |
| 592 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, mANW.get(), winAttrs.data()); |
| 593 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 594 | ASSERT_NE(EGL_NO_SURFACE, eglSurface); |
| 595 | |
| 596 | EGLint value; |
| 597 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_GL_COLORSPACE_KHR, &value); |
| 598 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 599 | ASSERT_EQ(EGL_GL_COLORSPACE_BT2020_PQ_EXT, value); |
| 600 | |
| 601 | ASSERT_NO_FATAL_FAILURE(checkOptionalWindowMetadata(eglSurface)); |
| 602 | |
| 603 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, eglSurface)); |
| 604 | } |
| 605 | |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 606 | TEST_F(EGLTest, EGLConfigFP16) { |
| 607 | EGLint numConfigs; |
| 608 | EGLConfig config; |
| 609 | EGLBoolean success; |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 610 | |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 611 | if (!hasWideColorDisplay) { |
| 612 | // skip this test if device does not have wide-color display |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 613 | RecordProperty("hasWideColorDisplay", false); |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 614 | return; |
| 615 | } |
| 616 | |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 617 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_pixel_format_float")); |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 618 | |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 619 | const EGLint attrs[] = { |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 620 | // clang-format off |
| 621 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 622 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 623 | EGL_RED_SIZE, 16, |
| 624 | EGL_GREEN_SIZE, 16, |
| 625 | EGL_BLUE_SIZE, 16, |
| 626 | EGL_ALPHA_SIZE, 16, |
| 627 | EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT, |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 628 | EGL_NONE, |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 629 | // clang-format on |
| 630 | }; |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 631 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
| 632 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 633 | ASSERT_EQ(1, numConfigs); |
| 634 | |
| 635 | EGLint components[4]; |
| 636 | |
| 637 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
| 638 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 639 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 640 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
| 641 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 642 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 643 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
| 644 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 645 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 646 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); |
| 647 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 648 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 649 | |
| 650 | EXPECT_GE(components[0], 16); |
| 651 | EXPECT_GE(components[1], 16); |
| 652 | EXPECT_GE(components[2], 16); |
| 653 | EXPECT_GE(components[3], 16); |
| 654 | |
| 655 | struct DummyConsumer : public BnConsumerListener { |
| 656 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 657 | void onBuffersReleased() override {} |
| 658 | void onSidebandStreamChanged() override {} |
| 659 | }; |
| 660 | |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 661 | sp<IGraphicBufferProducer> producer; |
| 662 | sp<IGraphicBufferConsumer> consumer; |
| 663 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 664 | consumer->consumerConnect(new DummyConsumer, false); |
| 665 | sp<Surface> mSTC = new Surface(producer); |
| 666 | sp<ANativeWindow> mANW = mSTC; |
| 667 | |
| 668 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, mANW.get(), NULL); |
| 669 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 670 | ASSERT_NE(EGL_NO_SURFACE, eglSurface); |
| 671 | |
| 672 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, eglSurface)); |
| 673 | } |
| 674 | |
Courtney Goeltzenleuchter | d99694b | 2017-07-10 16:30:42 -0600 | [diff] [blame] | 675 | TEST_F(EGLTest, EGLNoConfigContext) { |
Courtney Goeltzenleuchter | f7ed1b4 | 2017-04-17 17:27:47 -0600 | [diff] [blame] | 676 | if (!hasWideColorDisplay) { |
| 677 | // skip this test if device does not have wide-color display |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 678 | RecordProperty("hasWideColorDisplay", false); |
Courtney Goeltzenleuchter | f7ed1b4 | 2017-04-17 17:27:47 -0600 | [diff] [blame] | 679 | return; |
| 680 | } |
| 681 | |
| 682 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_KHR_no_config_context")); |
| 683 | |
| 684 | struct DummyConsumer : public BnConsumerListener { |
| 685 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 686 | void onBuffersReleased() override {} |
| 687 | void onSidebandStreamChanged() override {} |
| 688 | }; |
| 689 | |
| 690 | std::vector<EGLint> contextAttributes; |
| 691 | contextAttributes.reserve(4); |
| 692 | contextAttributes.push_back(EGL_CONTEXT_CLIENT_VERSION); |
| 693 | contextAttributes.push_back(2); |
| 694 | contextAttributes.push_back(EGL_NONE); |
| 695 | contextAttributes.push_back(EGL_NONE); |
| 696 | |
| 697 | EGLContext eglContext = eglCreateContext(mEglDisplay, EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, |
| 698 | contextAttributes.data()); |
| 699 | EXPECT_NE(EGL_NO_CONTEXT, eglContext); |
| 700 | EXPECT_EQ(EGL_SUCCESS, eglGetError()); |
| 701 | |
| 702 | if (eglContext != EGL_NO_CONTEXT) { |
| 703 | eglDestroyContext(mEglDisplay, eglContext); |
| 704 | } |
| 705 | } |
| 706 | |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 707 | // Emulate what a native application would do to create a |
| 708 | // 10:10:10:2 surface. |
| 709 | TEST_F(EGLTest, EGLConfig1010102) { |
| 710 | EGLint numConfigs; |
| 711 | EGLConfig config; |
| 712 | EGLBoolean success; |
| 713 | |
| 714 | if (!hasWideColorDisplay) { |
| 715 | // skip this test if device does not have wide-color display |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 716 | RecordProperty("hasWideColorDisplay", false); |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 717 | return; |
| 718 | } |
| 719 | |
Courtney Goeltzenleuchter | 12ffe09 | 2017-11-16 14:27:48 -0700 | [diff] [blame] | 720 | const EGLint attrs[] = { |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 721 | // clang-format off |
| 722 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 723 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 724 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, |
| 725 | EGL_RED_SIZE, 10, |
| 726 | EGL_GREEN_SIZE, 10, |
| 727 | EGL_BLUE_SIZE, 10, |
| 728 | EGL_ALPHA_SIZE, 2, |
| 729 | EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT, |
| 730 | EGL_NONE, EGL_NONE |
| 731 | // clang-format on |
| 732 | }; |
| 733 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
| 734 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 735 | ASSERT_EQ(1, numConfigs); |
| 736 | |
| 737 | EGLint components[4]; |
| 738 | EGLint value; |
| 739 | eglGetConfigAttrib(mEglDisplay, config, EGL_CONFIG_ID, &value); |
| 740 | |
| 741 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
| 742 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 743 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 744 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
| 745 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 746 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 747 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
| 748 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 749 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 750 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); |
| 751 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 752 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 753 | |
| 754 | EXPECT_EQ(components[0], 10); |
| 755 | EXPECT_EQ(components[1], 10); |
| 756 | EXPECT_EQ(components[2], 10); |
| 757 | EXPECT_EQ(components[3], 2); |
| 758 | |
| 759 | struct DummyConsumer : public BnConsumerListener { |
| 760 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 761 | void onBuffersReleased() override {} |
| 762 | void onSidebandStreamChanged() override {} |
| 763 | }; |
| 764 | |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 765 | // Create a EGLSurface |
| 766 | sp<IGraphicBufferProducer> producer; |
| 767 | sp<IGraphicBufferConsumer> consumer; |
| 768 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 769 | consumer->consumerConnect(new DummyConsumer, false); |
| 770 | sp<Surface> mSTC = new Surface(producer); |
| 771 | sp<ANativeWindow> mANW = mSTC; |
| 772 | |
| 773 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, mANW.get(), NULL); |
| 774 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 775 | ASSERT_NE(EGL_NO_SURFACE, eglSurface); |
| 776 | |
| 777 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, eglSurface)); |
| 778 | } |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 779 | } |