blob: 4c13dc87ef62e20d0dc89c8a9903f61e88dd407e [file] [log] [blame]
Mathias Agopian2f739f82011-07-07 14:54:30 -07001/*
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 Goeltzenleuchterf29f2872017-03-28 17:29:52 -060019#include <android/hardware/configstore/1.0/ISurfaceFlingerConfigs.h>
20
21#include <configstore/Utils.h>
Mathias Agopian2f739f82011-07-07 14:54:30 -070022#include <utils/String8.h>
23
24#include <EGL/egl.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080025#include <gui/Surface.h>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080026#include <gui/IConsumerListener.h>
27#include <gui/IProducerListener.h>
28#include <gui/IGraphicBufferConsumer.h>
29#include <gui/BufferQueue.h>
Mathias Agopian2f739f82011-07-07 14:54:30 -070030
Courtney Goeltzenleuchterd118ea92017-04-17 17:33:52 -060031bool hasEglExtension(EGLDisplay dpy, const char* extensionName) {
Courtney Goeltzenleuchterf29f2872017-03-28 17:29:52 -060032 const char* exts = eglQueryString(dpy, EGL_EXTENSIONS);
Courtney Goeltzenleuchterd118ea92017-04-17 17:33:52 -060033 size_t cropExtLen = strlen(extensionName);
Courtney Goeltzenleuchterf29f2872017-03-28 17:29:52 -060034 size_t extsLen = strlen(exts);
Courtney Goeltzenleuchterd118ea92017-04-17 17:33:52 -060035 bool equal = !strcmp(extensionName, exts);
36 android::String8 extString(extensionName);
37 android::String8 space(" ");
38 bool atStart = !strncmp(extString + space, exts, cropExtLen + 1);
Courtney Goeltzenleuchterf29f2872017-03-28 17:29:52 -060039 bool atEnd = (cropExtLen + 1) < extsLen &&
Courtney Goeltzenleuchterd118ea92017-04-17 17:33:52 -060040 !strcmp(space + extString, exts + extsLen - (cropExtLen + 1));
41 bool inMiddle = strstr(exts, space + extString + space);
Courtney Goeltzenleuchterf29f2872017-03-28 17:29:52 -060042 return equal || atStart || atEnd || inMiddle;
43}
44
Mathias Agopian2f739f82011-07-07 14:54:30 -070045namespace android {
46
Kalle Raita4cf36372017-01-13 10:18:36 -080047#define EGL_UNSIGNED_TRUE static_cast<EGLBoolean>(EGL_TRUE)
48
Courtney Goeltzenleuchterf29f2872017-03-28 17:29:52 -060049// retrieve wide-color setting from configstore
50using namespace android::hardware::configstore;
51
52static bool hasWideColorDisplay =
53 getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(false);
54
Mathias Agopian2f739f82011-07-07 14:54:30 -070055class EGLTest : public ::testing::Test {
56protected:
57 EGLDisplay mEglDisplay;
58
59protected:
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 Raita4cf36372017-01-13 10:18:36 -080079 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -070080 ASSERT_EQ(EGL_SUCCESS, eglGetError());
81 }
82};
83
84TEST_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 Raita4cf36372017-01-13 10:18:36 -080096 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -070097 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 Raita4cf36372017-01-13 10:18:36 -0800103 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700104 ASSERT_EQ(EGL_SUCCESS, eglGetError());
105 success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800106 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700107 ASSERT_EQ(EGL_SUCCESS, eglGetError());
108 success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800109 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700110 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 Lam1cbcb982012-04-16 22:21:02 -0700117TEST_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 Agopiana4e19522013-07-31 20:09:53 -0700131 struct DummyConsumer : public BnConsumerListener {
Brian Anderson5ea5e592016-12-01 16:54:33 -0800132 void onFrameAvailable(const BufferItem& /* item */) override {}
133 void onBuffersReleased() override {}
134 void onSidebandStreamChanged() override {}
Mathias Agopian595264f2013-07-16 22:56:09 -0700135 };
136
Daniel Lam1cbcb982012-04-16 22:21:02 -0700137 // Create a EGLSurface
Dan Stoza5603a2f2014-04-07 13:41:37 -0700138 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 Lam1cbcb982012-04-16 22:21:02 -0700143 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 Agopian2f739f82011-07-07 14:54:30 -0700154TEST_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 Raita4cf36372017-01-13 10:18:36 -0800170 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700171 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 Raita4cf36372017-01-13 10:18:36 -0800177 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700178 ASSERT_EQ(EGL_SUCCESS, eglGetError());
179 success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800180 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700181 ASSERT_EQ(EGL_SUCCESS, eglGetError());
182 success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800183 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700184 ASSERT_EQ(EGL_SUCCESS, eglGetError());
185 success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800186 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700187 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 Goeltzenleuchter2c325e22017-04-25 14:40:42 -0600195TEST_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
280TEST_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 Goeltzenleuchterf29f2872017-03-28 17:29:52 -0600365TEST_F(EGLTest, EGLConfigFP16) {
366 EGLint numConfigs;
367 EGLConfig config;
368 EGLBoolean success;
Mathias Agopian2f739f82011-07-07 14:54:30 -0700369
Courtney Goeltzenleuchterf29f2872017-03-28 17:29:52 -0600370 if (!hasWideColorDisplay) {
371 // skip this test if device does not have wide-color display
372 return;
373 }
374
Courtney Goeltzenleuchterd118ea92017-04-17 17:33:52 -0600375 ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_pixel_format_float"));
Courtney Goeltzenleuchterf29f2872017-03-28 17:29:52 -0600376
Courtney Goeltzenleuchterd118ea92017-04-17 17:33:52 -0600377 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 Goeltzenleuchterf29f2872017-03-28 17:29:52 -0600389 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 Goeltzenleuchterd118ea92017-04-17 17:33:52 -0600419 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 Goeltzenleuchterf7ed1b42017-04-17 17:27:47 -0600433TEST_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 Goeltzenleuchterd118ea92017-04-17 17:33:52 -0600464// Emulate what a native application would do to create a
465// 10:10:10:2 surface.
466TEST_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 Goeltzenleuchterf29f2872017-03-28 17:29:52 -0600521 // 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 Agopian2f739f82011-07-07 14:54:30 -0700535}