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