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; |
| 51 | |
| 52 | static bool hasWideColorDisplay = |
| 53 | getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(false); |
| 54 | |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 55 | class EGLTest : public ::testing::Test { |
| 56 | protected: |
| 57 | EGLDisplay mEglDisplay; |
| 58 | |
| 59 | protected: |
| 60 | EGLTest() : |
| 61 | mEglDisplay(EGL_NO_DISPLAY) { |
| 62 | } |
| 63 | |
| 64 | virtual void SetUp() { |
| 65 | mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 66 | ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay); |
| 67 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 68 | |
| 69 | EGLint majorVersion; |
| 70 | EGLint minorVersion; |
| 71 | EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion)); |
| 72 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 73 | RecordProperty("EglVersionMajor", majorVersion); |
| 74 | RecordProperty("EglVersionMajor", minorVersion); |
| 75 | } |
| 76 | |
| 77 | virtual void TearDown() { |
| 78 | EGLBoolean success = eglTerminate(mEglDisplay); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 79 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 80 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 81 | } |
| 82 | }; |
| 83 | |
| 84 | TEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) { |
| 85 | |
| 86 | EGLint numConfigs; |
| 87 | EGLConfig config; |
| 88 | EGLBoolean success; |
| 89 | EGLint attrs[] = { |
| 90 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 91 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 92 | EGL_NONE |
| 93 | }; |
| 94 | |
| 95 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 96 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 97 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 98 | ASSERT_GE(numConfigs, 1); |
| 99 | |
| 100 | EGLint components[3]; |
| 101 | |
| 102 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 103 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 104 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 105 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 106 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 107 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 108 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 109 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 110 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 111 | |
| 112 | EXPECT_GE(components[0], 8); |
| 113 | EXPECT_GE(components[1], 8); |
| 114 | EXPECT_GE(components[2], 8); |
| 115 | } |
| 116 | |
Daniel Lam | 1cbcb98 | 2012-04-16 22:21:02 -0700 | [diff] [blame] | 117 | TEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) { |
| 118 | EGLint numConfigs; |
| 119 | EGLConfig config; |
| 120 | EGLint attrs[] = { |
| 121 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 122 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 123 | EGL_RED_SIZE, 8, |
| 124 | EGL_GREEN_SIZE, 8, |
| 125 | EGL_BLUE_SIZE, 8, |
| 126 | EGL_ALPHA_SIZE, 8, |
| 127 | EGL_NONE |
| 128 | }; |
| 129 | EXPECT_TRUE(eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs)); |
| 130 | |
Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 131 | struct DummyConsumer : public BnConsumerListener { |
Brian Anderson | 5ea5e59 | 2016-12-01 16:54:33 -0800 | [diff] [blame] | 132 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 133 | void onBuffersReleased() override {} |
| 134 | void onSidebandStreamChanged() override {} |
Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
Daniel Lam | 1cbcb98 | 2012-04-16 22:21:02 -0700 | [diff] [blame] | 137 | // Create a EGLSurface |
Dan Stoza | 5603a2f | 2014-04-07 13:41:37 -0700 | [diff] [blame] | 138 | sp<IGraphicBufferProducer> producer; |
| 139 | sp<IGraphicBufferConsumer> consumer; |
| 140 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 141 | consumer->consumerConnect(new DummyConsumer, false); |
| 142 | sp<Surface> mSTC = new Surface(producer); |
Daniel Lam | 1cbcb98 | 2012-04-16 22:21:02 -0700 | [diff] [blame] | 143 | sp<ANativeWindow> mANW = mSTC; |
| 144 | |
| 145 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, |
| 146 | mANW.get(), NULL); |
| 147 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 148 | ASSERT_NE(EGL_NO_SURFACE, eglSurface) ; |
| 149 | |
| 150 | // do not destroy eglSurface |
| 151 | // eglTerminate is called in the tear down and should destroy it for us |
| 152 | } |
| 153 | |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 154 | TEST_F(EGLTest, EGLConfigRGBA8888First) { |
| 155 | |
| 156 | EGLint numConfigs; |
| 157 | EGLConfig config; |
| 158 | EGLBoolean success; |
| 159 | EGLint attrs[] = { |
| 160 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 161 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 162 | EGL_RED_SIZE, 8, |
| 163 | EGL_GREEN_SIZE, 8, |
| 164 | EGL_BLUE_SIZE, 8, |
| 165 | EGL_ALPHA_SIZE, 8, |
| 166 | EGL_NONE |
| 167 | }; |
| 168 | |
| 169 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 170 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 171 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 172 | ASSERT_GE(numConfigs, 1); |
| 173 | |
| 174 | EGLint components[4]; |
| 175 | |
| 176 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 177 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 178 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 179 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 180 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 181 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 182 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 183 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 184 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 185 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); |
Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 186 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 187 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 188 | |
| 189 | EXPECT_GE(components[0], 8); |
| 190 | EXPECT_GE(components[1], 8); |
| 191 | EXPECT_GE(components[2], 8); |
| 192 | EXPECT_GE(components[3], 8); |
| 193 | } |
| 194 | |
Courtney Goeltzenleuchter | 2c325e2 | 2017-04-25 14:40:42 -0600 | [diff] [blame] | 195 | TEST_F(EGLTest, EGLDisplayP3) { |
| 196 | EGLint numConfigs; |
| 197 | EGLConfig config; |
| 198 | EGLBoolean success; |
| 199 | |
| 200 | if (!hasWideColorDisplay) { |
| 201 | // skip this test if device does not have wide-color display |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | // Test that display-p3 extensions exist |
| 206 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_gl_colorspace_display_p3")); |
| 207 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_gl_colorspace_display_p3_linear")); |
| 208 | |
| 209 | // Use 8-bit to keep forcus on Display-P3 aspect |
| 210 | EGLint attrs[] = { |
| 211 | // clang-format off |
| 212 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 213 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 214 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, |
| 215 | EGL_RED_SIZE, 8, |
| 216 | EGL_GREEN_SIZE, 8, |
| 217 | EGL_BLUE_SIZE, 8, |
| 218 | EGL_ALPHA_SIZE, 8, |
| 219 | EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT, |
| 220 | EGL_NONE, EGL_NONE |
| 221 | // clang-format on |
| 222 | }; |
| 223 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
| 224 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 225 | ASSERT_EQ(1, numConfigs); |
| 226 | |
| 227 | EGLint components[4]; |
| 228 | EGLint value; |
| 229 | eglGetConfigAttrib(mEglDisplay, config, EGL_CONFIG_ID, &value); |
| 230 | |
| 231 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
| 232 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 233 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 234 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
| 235 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 236 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 237 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
| 238 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 239 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 240 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); |
| 241 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 242 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 243 | |
| 244 | EXPECT_EQ(components[0], 8); |
| 245 | EXPECT_EQ(components[1], 8); |
| 246 | EXPECT_EQ(components[2], 8); |
| 247 | EXPECT_EQ(components[3], 8); |
| 248 | |
| 249 | struct DummyConsumer : public BnConsumerListener { |
| 250 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 251 | void onBuffersReleased() override {} |
| 252 | void onSidebandStreamChanged() override {} |
| 253 | }; |
| 254 | |
| 255 | // Create a EGLSurface |
| 256 | sp<IGraphicBufferProducer> producer; |
| 257 | sp<IGraphicBufferConsumer> consumer; |
| 258 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 259 | consumer->consumerConnect(new DummyConsumer, false); |
| 260 | sp<Surface> mSTC = new Surface(producer); |
| 261 | sp<ANativeWindow> mANW = mSTC; |
| 262 | EGLint winAttrs[] = { |
| 263 | // clang-format off |
| 264 | EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, |
| 265 | EGL_NONE, EGL_NONE |
| 266 | // clang-format on |
| 267 | }; |
| 268 | |
| 269 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, mANW.get(), winAttrs); |
| 270 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 271 | ASSERT_NE(EGL_NO_SURFACE, eglSurface); |
| 272 | |
| 273 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_GL_COLORSPACE_KHR, &value); |
| 274 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 275 | ASSERT_EQ(EGL_GL_COLORSPACE_DISPLAY_P3_EXT, value); |
| 276 | |
| 277 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, eglSurface)); |
| 278 | } |
| 279 | |
| 280 | TEST_F(EGLTest, EGLDisplayP31010102) { |
| 281 | EGLint numConfigs; |
| 282 | EGLConfig config; |
| 283 | EGLBoolean success; |
| 284 | |
| 285 | if (!hasWideColorDisplay) { |
| 286 | // skip this test if device does not have wide-color display |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | // Test that display-p3 extensions exist |
| 291 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_gl_colorspace_display_p3")); |
| 292 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_gl_colorspace_display_p3_linear")); |
| 293 | |
| 294 | // Use 8-bit to keep forcus on Display-P3 aspect |
| 295 | EGLint attrs[] = { |
| 296 | // clang-format off |
| 297 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 298 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 299 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, |
| 300 | EGL_RED_SIZE, 10, |
| 301 | EGL_GREEN_SIZE, 10, |
| 302 | EGL_BLUE_SIZE, 10, |
| 303 | EGL_ALPHA_SIZE, 2, |
| 304 | EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT, |
| 305 | EGL_NONE, EGL_NONE |
| 306 | // clang-format on |
| 307 | }; |
| 308 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
| 309 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 310 | ASSERT_EQ(1, numConfigs); |
| 311 | |
| 312 | EGLint components[4]; |
| 313 | EGLint value; |
| 314 | eglGetConfigAttrib(mEglDisplay, config, EGL_CONFIG_ID, &value); |
| 315 | |
| 316 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
| 317 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 318 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 319 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
| 320 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 321 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 322 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
| 323 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 324 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 325 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); |
| 326 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 327 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 328 | |
| 329 | EXPECT_EQ(components[0], 10); |
| 330 | EXPECT_EQ(components[1], 10); |
| 331 | EXPECT_EQ(components[2], 10); |
| 332 | EXPECT_EQ(components[3], 2); |
| 333 | |
| 334 | struct DummyConsumer : public BnConsumerListener { |
| 335 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 336 | void onBuffersReleased() override {} |
| 337 | void onSidebandStreamChanged() override {} |
| 338 | }; |
| 339 | |
| 340 | // Create a EGLSurface |
| 341 | sp<IGraphicBufferProducer> producer; |
| 342 | sp<IGraphicBufferConsumer> consumer; |
| 343 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 344 | consumer->consumerConnect(new DummyConsumer, false); |
| 345 | sp<Surface> mSTC = new Surface(producer); |
| 346 | sp<ANativeWindow> mANW = mSTC; |
| 347 | EGLint winAttrs[] = { |
| 348 | // clang-format off |
| 349 | EGL_GL_COLORSPACE_KHR, EGL_GL_COLORSPACE_DISPLAY_P3_EXT, |
| 350 | EGL_NONE, EGL_NONE |
| 351 | // clang-format on |
| 352 | }; |
| 353 | |
| 354 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, mANW.get(), winAttrs); |
| 355 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 356 | ASSERT_NE(EGL_NO_SURFACE, eglSurface); |
| 357 | |
| 358 | success = eglQuerySurface(mEglDisplay, eglSurface, EGL_GL_COLORSPACE_KHR, &value); |
| 359 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 360 | ASSERT_EQ(EGL_GL_COLORSPACE_DISPLAY_P3_EXT, value); |
| 361 | |
| 362 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, eglSurface)); |
| 363 | } |
| 364 | |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 365 | TEST_F(EGLTest, EGLConfigFP16) { |
| 366 | EGLint numConfigs; |
| 367 | EGLConfig config; |
| 368 | EGLBoolean success; |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 369 | |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 370 | if (!hasWideColorDisplay) { |
| 371 | // skip this test if device does not have wide-color display |
| 372 | return; |
| 373 | } |
| 374 | |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 375 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_pixel_format_float")); |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 376 | |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 377 | EGLint attrs[] = { |
| 378 | // clang-format off |
| 379 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 380 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 381 | EGL_RED_SIZE, 16, |
| 382 | EGL_GREEN_SIZE, 16, |
| 383 | EGL_BLUE_SIZE, 16, |
| 384 | EGL_ALPHA_SIZE, 16, |
| 385 | EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FLOAT_EXT, |
| 386 | EGL_NONE, EGL_NONE |
| 387 | // clang-format on |
| 388 | }; |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 389 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
| 390 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 391 | ASSERT_EQ(1, numConfigs); |
| 392 | |
| 393 | EGLint components[4]; |
| 394 | |
| 395 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
| 396 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 397 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 398 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
| 399 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 400 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 401 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
| 402 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 403 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 404 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); |
| 405 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 406 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 407 | |
| 408 | EXPECT_GE(components[0], 16); |
| 409 | EXPECT_GE(components[1], 16); |
| 410 | EXPECT_GE(components[2], 16); |
| 411 | EXPECT_GE(components[3], 16); |
| 412 | |
| 413 | struct DummyConsumer : public BnConsumerListener { |
| 414 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 415 | void onBuffersReleased() override {} |
| 416 | void onSidebandStreamChanged() override {} |
| 417 | }; |
| 418 | |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 419 | sp<IGraphicBufferProducer> producer; |
| 420 | sp<IGraphicBufferConsumer> consumer; |
| 421 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 422 | consumer->consumerConnect(new DummyConsumer, false); |
| 423 | sp<Surface> mSTC = new Surface(producer); |
| 424 | sp<ANativeWindow> mANW = mSTC; |
| 425 | |
| 426 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, mANW.get(), NULL); |
| 427 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 428 | ASSERT_NE(EGL_NO_SURFACE, eglSurface); |
| 429 | |
| 430 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, eglSurface)); |
| 431 | } |
| 432 | |
Courtney Goeltzenleuchter | f7ed1b4 | 2017-04-17 17:27:47 -0600 | [diff] [blame] | 433 | TEST_F(EGLTest, EGL_KHR_no_config_context) { |
| 434 | if (!hasWideColorDisplay) { |
| 435 | // skip this test if device does not have wide-color display |
| 436 | return; |
| 437 | } |
| 438 | |
| 439 | ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_KHR_no_config_context")); |
| 440 | |
| 441 | struct DummyConsumer : public BnConsumerListener { |
| 442 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 443 | void onBuffersReleased() override {} |
| 444 | void onSidebandStreamChanged() override {} |
| 445 | }; |
| 446 | |
| 447 | std::vector<EGLint> contextAttributes; |
| 448 | contextAttributes.reserve(4); |
| 449 | contextAttributes.push_back(EGL_CONTEXT_CLIENT_VERSION); |
| 450 | contextAttributes.push_back(2); |
| 451 | contextAttributes.push_back(EGL_NONE); |
| 452 | contextAttributes.push_back(EGL_NONE); |
| 453 | |
| 454 | EGLContext eglContext = eglCreateContext(mEglDisplay, EGL_NO_CONFIG_KHR, EGL_NO_CONTEXT, |
| 455 | contextAttributes.data()); |
| 456 | EXPECT_NE(EGL_NO_CONTEXT, eglContext); |
| 457 | EXPECT_EQ(EGL_SUCCESS, eglGetError()); |
| 458 | |
| 459 | if (eglContext != EGL_NO_CONTEXT) { |
| 460 | eglDestroyContext(mEglDisplay, eglContext); |
| 461 | } |
| 462 | } |
| 463 | |
Courtney Goeltzenleuchter | d118ea9 | 2017-04-17 17:33:52 -0600 | [diff] [blame] | 464 | // Emulate what a native application would do to create a |
| 465 | // 10:10:10:2 surface. |
| 466 | TEST_F(EGLTest, EGLConfig1010102) { |
| 467 | EGLint numConfigs; |
| 468 | EGLConfig config; |
| 469 | EGLBoolean success; |
| 470 | |
| 471 | if (!hasWideColorDisplay) { |
| 472 | // skip this test if device does not have wide-color display |
| 473 | return; |
| 474 | } |
| 475 | |
| 476 | EGLint attrs[] = { |
| 477 | // clang-format off |
| 478 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 479 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 480 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, |
| 481 | EGL_RED_SIZE, 10, |
| 482 | EGL_GREEN_SIZE, 10, |
| 483 | EGL_BLUE_SIZE, 10, |
| 484 | EGL_ALPHA_SIZE, 2, |
| 485 | EGL_COLOR_COMPONENT_TYPE_EXT, EGL_COLOR_COMPONENT_TYPE_FIXED_EXT, |
| 486 | EGL_NONE, EGL_NONE |
| 487 | // clang-format on |
| 488 | }; |
| 489 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
| 490 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 491 | ASSERT_EQ(1, numConfigs); |
| 492 | |
| 493 | EGLint components[4]; |
| 494 | EGLint value; |
| 495 | eglGetConfigAttrib(mEglDisplay, config, EGL_CONFIG_ID, &value); |
| 496 | |
| 497 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
| 498 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 499 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 500 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
| 501 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 502 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 503 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
| 504 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 505 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 506 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); |
| 507 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); |
| 508 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 509 | |
| 510 | EXPECT_EQ(components[0], 10); |
| 511 | EXPECT_EQ(components[1], 10); |
| 512 | EXPECT_EQ(components[2], 10); |
| 513 | EXPECT_EQ(components[3], 2); |
| 514 | |
| 515 | struct DummyConsumer : public BnConsumerListener { |
| 516 | void onFrameAvailable(const BufferItem& /* item */) override {} |
| 517 | void onBuffersReleased() override {} |
| 518 | void onSidebandStreamChanged() override {} |
| 519 | }; |
| 520 | |
Courtney Goeltzenleuchter | f29f287 | 2017-03-28 17:29:52 -0600 | [diff] [blame] | 521 | // Create a EGLSurface |
| 522 | sp<IGraphicBufferProducer> producer; |
| 523 | sp<IGraphicBufferConsumer> consumer; |
| 524 | BufferQueue::createBufferQueue(&producer, &consumer); |
| 525 | consumer->consumerConnect(new DummyConsumer, false); |
| 526 | sp<Surface> mSTC = new Surface(producer); |
| 527 | sp<ANativeWindow> mANW = mSTC; |
| 528 | |
| 529 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, mANW.get(), NULL); |
| 530 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 531 | ASSERT_NE(EGL_NO_SURFACE, eglSurface); |
| 532 | |
| 533 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, eglSurface)); |
| 534 | } |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 535 | } |