blob: 62e6bd3055c17cfc8b17ed2a8ef85edbe88e8d60 [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;
Jaesoo Lee3b746b32017-05-02 22:19:39 +090051using namespace android::hardware::configstore::V1_0;
Courtney Goeltzenleuchterf29f2872017-03-28 17:29:52 -060052
53static bool hasWideColorDisplay =
54 getBool<ISurfaceFlingerConfigs, &ISurfaceFlingerConfigs::hasWideColorDisplay>(false);
55
Mathias Agopian2f739f82011-07-07 14:54:30 -070056class EGLTest : public ::testing::Test {
57protected:
58 EGLDisplay mEglDisplay;
59
60protected:
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 Raita4cf36372017-01-13 10:18:36 -080080 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -070081 ASSERT_EQ(EGL_SUCCESS, eglGetError());
82 }
83};
84
85TEST_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 Raita4cf36372017-01-13 10:18:36 -080097 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -070098 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 Raita4cf36372017-01-13 10:18:36 -0800104 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700105 ASSERT_EQ(EGL_SUCCESS, eglGetError());
106 success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800107 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700108 ASSERT_EQ(EGL_SUCCESS, eglGetError());
109 success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800110 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700111 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 Lam1cbcb982012-04-16 22:21:02 -0700118TEST_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 Agopiana4e19522013-07-31 20:09:53 -0700132 struct DummyConsumer : public BnConsumerListener {
Brian Anderson5ea5e592016-12-01 16:54:33 -0800133 void onFrameAvailable(const BufferItem& /* item */) override {}
134 void onBuffersReleased() override {}
135 void onSidebandStreamChanged() override {}
Mathias Agopian595264f2013-07-16 22:56:09 -0700136 };
137
Daniel Lam1cbcb982012-04-16 22:21:02 -0700138 // Create a EGLSurface
Dan Stoza5603a2f2014-04-07 13:41:37 -0700139 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 Lam1cbcb982012-04-16 22:21:02 -0700144 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 Agopian2f739f82011-07-07 14:54:30 -0700155TEST_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 Raita4cf36372017-01-13 10:18:36 -0800171 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700172 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 Raita4cf36372017-01-13 10:18:36 -0800178 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700179 ASSERT_EQ(EGL_SUCCESS, eglGetError());
180 success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800181 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700182 ASSERT_EQ(EGL_SUCCESS, eglGetError());
183 success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800184 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700185 ASSERT_EQ(EGL_SUCCESS, eglGetError());
186 success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800187 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700188 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 Goeltzenleuchter2c325e22017-04-25 14:40:42 -0600196TEST_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
281TEST_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 Goeltzenleuchterf29f2872017-03-28 17:29:52 -0600366TEST_F(EGLTest, EGLConfigFP16) {
367 EGLint numConfigs;
368 EGLConfig config;
369 EGLBoolean success;
Mathias Agopian2f739f82011-07-07 14:54:30 -0700370
Courtney Goeltzenleuchterf29f2872017-03-28 17:29:52 -0600371 if (!hasWideColorDisplay) {
372 // skip this test if device does not have wide-color display
373 return;
374 }
375
Courtney Goeltzenleuchterd118ea92017-04-17 17:33:52 -0600376 ASSERT_TRUE(hasEglExtension(mEglDisplay, "EGL_EXT_pixel_format_float"));
Courtney Goeltzenleuchterf29f2872017-03-28 17:29:52 -0600377
Courtney Goeltzenleuchterd118ea92017-04-17 17:33:52 -0600378 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 Goeltzenleuchterf29f2872017-03-28 17:29:52 -0600390 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 Goeltzenleuchterd118ea92017-04-17 17:33:52 -0600420 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 Goeltzenleuchterf7ed1b42017-04-17 17:27:47 -0600434TEST_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 Goeltzenleuchterd118ea92017-04-17 17:33:52 -0600465// Emulate what a native application would do to create a
466// 10:10:10:2 surface.
467TEST_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 Goeltzenleuchterf29f2872017-03-28 17:29:52 -0600522 // 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 Agopian2f739f82011-07-07 14:54:30 -0700536}