blob: 2b9c38ea7c8caff6f9d75c2b9b2b194d18a36a07 [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
19#include <utils/String8.h>
20
21#include <EGL/egl.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080022#include <gui/Surface.h>
Daniel Lam1cbcb982012-04-16 22:21:02 -070023
Mathias Agopian2f739f82011-07-07 14:54:30 -070024
25namespace android {
26
Kalle Raita4cf36372017-01-13 10:18:36 -080027#define EGL_UNSIGNED_TRUE static_cast<EGLBoolean>(EGL_TRUE)
28
Mathias Agopian2f739f82011-07-07 14:54:30 -070029class EGLTest : public ::testing::Test {
30protected:
31 EGLDisplay mEglDisplay;
32
33protected:
34 EGLTest() :
35 mEglDisplay(EGL_NO_DISPLAY) {
36 }
37
38 virtual void SetUp() {
39 mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
40 ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay);
41 ASSERT_EQ(EGL_SUCCESS, eglGetError());
42
43 EGLint majorVersion;
44 EGLint minorVersion;
45 EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion));
46 ASSERT_EQ(EGL_SUCCESS, eglGetError());
47 RecordProperty("EglVersionMajor", majorVersion);
48 RecordProperty("EglVersionMajor", minorVersion);
49 }
50
51 virtual void TearDown() {
52 EGLBoolean success = eglTerminate(mEglDisplay);
Kalle Raita4cf36372017-01-13 10:18:36 -080053 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -070054 ASSERT_EQ(EGL_SUCCESS, eglGetError());
55 }
56};
57
58TEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) {
59
60 EGLint numConfigs;
61 EGLConfig config;
62 EGLBoolean success;
63 EGLint attrs[] = {
64 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
65 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
66 EGL_NONE
67 };
68
69 success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
Kalle Raita4cf36372017-01-13 10:18:36 -080070 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -070071 ASSERT_EQ(EGL_SUCCESS, eglGetError());
72 ASSERT_GE(numConfigs, 1);
73
74 EGLint components[3];
75
76 success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
Kalle Raita4cf36372017-01-13 10:18:36 -080077 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -070078 ASSERT_EQ(EGL_SUCCESS, eglGetError());
79 success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
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 success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
Kalle Raita4cf36372017-01-13 10:18:36 -080083 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -070084 ASSERT_EQ(EGL_SUCCESS, eglGetError());
85
86 EXPECT_GE(components[0], 8);
87 EXPECT_GE(components[1], 8);
88 EXPECT_GE(components[2], 8);
89}
90
Daniel Lam1cbcb982012-04-16 22:21:02 -070091TEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) {
92 EGLint numConfigs;
93 EGLConfig config;
94 EGLint attrs[] = {
95 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
96 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
97 EGL_RED_SIZE, 8,
98 EGL_GREEN_SIZE, 8,
99 EGL_BLUE_SIZE, 8,
100 EGL_ALPHA_SIZE, 8,
101 EGL_NONE
102 };
103 EXPECT_TRUE(eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs));
104
Mathias Agopiana4e19522013-07-31 20:09:53 -0700105 struct DummyConsumer : public BnConsumerListener {
Dan Stoza8dc55392014-11-04 11:37:46 -0800106 virtual void onFrameAvailable(const BufferItem& /* item */) {}
Mathias Agopian595264f2013-07-16 22:56:09 -0700107 virtual void onBuffersReleased() {}
Jesse Hall85c0fee2014-03-13 14:34:28 -0700108 virtual void onSidebandStreamChanged() {}
Mathias Agopian595264f2013-07-16 22:56:09 -0700109 };
110
Daniel Lam1cbcb982012-04-16 22:21:02 -0700111 // Create a EGLSurface
Dan Stoza5603a2f2014-04-07 13:41:37 -0700112 sp<IGraphicBufferProducer> producer;
113 sp<IGraphicBufferConsumer> consumer;
114 BufferQueue::createBufferQueue(&producer, &consumer);
115 consumer->consumerConnect(new DummyConsumer, false);
116 sp<Surface> mSTC = new Surface(producer);
Daniel Lam1cbcb982012-04-16 22:21:02 -0700117 sp<ANativeWindow> mANW = mSTC;
118
119 EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config,
120 mANW.get(), NULL);
121 ASSERT_EQ(EGL_SUCCESS, eglGetError());
122 ASSERT_NE(EGL_NO_SURFACE, eglSurface) ;
123
124 // do not destroy eglSurface
125 // eglTerminate is called in the tear down and should destroy it for us
126}
127
Mathias Agopian2f739f82011-07-07 14:54:30 -0700128TEST_F(EGLTest, EGLConfigRGBA8888First) {
129
130 EGLint numConfigs;
131 EGLConfig config;
132 EGLBoolean success;
133 EGLint attrs[] = {
134 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
135 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
136 EGL_RED_SIZE, 8,
137 EGL_GREEN_SIZE, 8,
138 EGL_BLUE_SIZE, 8,
139 EGL_ALPHA_SIZE, 8,
140 EGL_NONE
141 };
142
143 success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
Kalle Raita4cf36372017-01-13 10:18:36 -0800144 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700145 ASSERT_EQ(EGL_SUCCESS, eglGetError());
146 ASSERT_GE(numConfigs, 1);
147
148 EGLint components[4];
149
150 success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800151 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700152 ASSERT_EQ(EGL_SUCCESS, eglGetError());
153 success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800154 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700155 ASSERT_EQ(EGL_SUCCESS, eglGetError());
156 success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800157 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700158 ASSERT_EQ(EGL_SUCCESS, eglGetError());
159 success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800160 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700161 ASSERT_EQ(EGL_SUCCESS, eglGetError());
162
163 EXPECT_GE(components[0], 8);
164 EXPECT_GE(components[1], 8);
165 EXPECT_GE(components[2], 8);
166 EXPECT_GE(components[3], 8);
167}
168
169
170}