blob: 1b3086be698e40e1ff58179fe1706d7c6efe30b7 [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>
Mathias Agopian2b5dd402017-02-07 17:36:19 -080023#include <gui/IConsumerListener.h>
24#include <gui/IProducerListener.h>
25#include <gui/IGraphicBufferConsumer.h>
26#include <gui/BufferQueue.h>
Mathias Agopian2f739f82011-07-07 14:54:30 -070027
28namespace android {
29
Kalle Raita4cf36372017-01-13 10:18:36 -080030#define EGL_UNSIGNED_TRUE static_cast<EGLBoolean>(EGL_TRUE)
31
Mathias Agopian2f739f82011-07-07 14:54:30 -070032class EGLTest : public ::testing::Test {
33protected:
34 EGLDisplay mEglDisplay;
35
36protected:
37 EGLTest() :
38 mEglDisplay(EGL_NO_DISPLAY) {
39 }
40
41 virtual void SetUp() {
42 mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
43 ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay);
44 ASSERT_EQ(EGL_SUCCESS, eglGetError());
45
46 EGLint majorVersion;
47 EGLint minorVersion;
48 EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion));
49 ASSERT_EQ(EGL_SUCCESS, eglGetError());
50 RecordProperty("EglVersionMajor", majorVersion);
51 RecordProperty("EglVersionMajor", minorVersion);
52 }
53
54 virtual void TearDown() {
55 EGLBoolean success = eglTerminate(mEglDisplay);
Kalle Raita4cf36372017-01-13 10:18:36 -080056 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -070057 ASSERT_EQ(EGL_SUCCESS, eglGetError());
58 }
59};
60
61TEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) {
62
63 EGLint numConfigs;
64 EGLConfig config;
65 EGLBoolean success;
66 EGLint attrs[] = {
67 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
68 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
69 EGL_NONE
70 };
71
72 success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
Kalle Raita4cf36372017-01-13 10:18:36 -080073 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -070074 ASSERT_EQ(EGL_SUCCESS, eglGetError());
75 ASSERT_GE(numConfigs, 1);
76
77 EGLint components[3];
78
79 success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
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_GREEN_SIZE, &components[1]);
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 success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
Kalle Raita4cf36372017-01-13 10:18:36 -080086 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -070087 ASSERT_EQ(EGL_SUCCESS, eglGetError());
88
89 EXPECT_GE(components[0], 8);
90 EXPECT_GE(components[1], 8);
91 EXPECT_GE(components[2], 8);
92}
93
Daniel Lam1cbcb982012-04-16 22:21:02 -070094TEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) {
95 EGLint numConfigs;
96 EGLConfig config;
97 EGLint attrs[] = {
98 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
99 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
100 EGL_RED_SIZE, 8,
101 EGL_GREEN_SIZE, 8,
102 EGL_BLUE_SIZE, 8,
103 EGL_ALPHA_SIZE, 8,
104 EGL_NONE
105 };
106 EXPECT_TRUE(eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs));
107
Mathias Agopiana4e19522013-07-31 20:09:53 -0700108 struct DummyConsumer : public BnConsumerListener {
Brian Anderson5ea5e592016-12-01 16:54:33 -0800109 void onFrameAvailable(const BufferItem& /* item */) override {}
110 void onBuffersReleased() override {}
111 void onSidebandStreamChanged() override {}
Mathias Agopian595264f2013-07-16 22:56:09 -0700112 };
113
Daniel Lam1cbcb982012-04-16 22:21:02 -0700114 // Create a EGLSurface
Dan Stoza5603a2f2014-04-07 13:41:37 -0700115 sp<IGraphicBufferProducer> producer;
116 sp<IGraphicBufferConsumer> consumer;
117 BufferQueue::createBufferQueue(&producer, &consumer);
118 consumer->consumerConnect(new DummyConsumer, false);
119 sp<Surface> mSTC = new Surface(producer);
Daniel Lam1cbcb982012-04-16 22:21:02 -0700120 sp<ANativeWindow> mANW = mSTC;
121
122 EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config,
123 mANW.get(), NULL);
124 ASSERT_EQ(EGL_SUCCESS, eglGetError());
125 ASSERT_NE(EGL_NO_SURFACE, eglSurface) ;
126
127 // do not destroy eglSurface
128 // eglTerminate is called in the tear down and should destroy it for us
129}
130
Mathias Agopian2f739f82011-07-07 14:54:30 -0700131TEST_F(EGLTest, EGLConfigRGBA8888First) {
132
133 EGLint numConfigs;
134 EGLConfig config;
135 EGLBoolean success;
136 EGLint attrs[] = {
137 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
138 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
139 EGL_RED_SIZE, 8,
140 EGL_GREEN_SIZE, 8,
141 EGL_BLUE_SIZE, 8,
142 EGL_ALPHA_SIZE, 8,
143 EGL_NONE
144 };
145
146 success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
Kalle Raita4cf36372017-01-13 10:18:36 -0800147 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700148 ASSERT_EQ(EGL_SUCCESS, eglGetError());
149 ASSERT_GE(numConfigs, 1);
150
151 EGLint components[4];
152
153 success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
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_GREEN_SIZE, &components[1]);
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_BLUE_SIZE, &components[2]);
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 success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]);
Kalle Raita4cf36372017-01-13 10:18:36 -0800163 ASSERT_EQ(EGL_UNSIGNED_TRUE, success);
Mathias Agopian2f739f82011-07-07 14:54:30 -0700164 ASSERT_EQ(EGL_SUCCESS, eglGetError());
165
166 EXPECT_GE(components[0], 8);
167 EXPECT_GE(components[1], 8);
168 EXPECT_GE(components[2], 8);
169 EXPECT_GE(components[3], 8);
170}
171
172
173}