2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include <gtest/gtest.h>
19 #include <utils/String8.h>
22 #include <gui/Surface.h>
27 class EGLTest : public ::testing::Test {
29 EGLDisplay mEglDisplay;
33 mEglDisplay(EGL_NO_DISPLAY) {
36 virtual void SetUp() {
37 mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
38 ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay);
39 ASSERT_EQ(EGL_SUCCESS, eglGetError());
43 EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion));
44 ASSERT_EQ(EGL_SUCCESS, eglGetError());
45 RecordProperty("EglVersionMajor", majorVersion);
46 RecordProperty("EglVersionMajor", minorVersion);
49 virtual void TearDown() {
50 EGLBoolean success = eglTerminate(mEglDisplay);
51 ASSERT_EQ(EGL_TRUE, success);
52 ASSERT_EQ(EGL_SUCCESS, eglGetError());
56 TEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) {
62 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
63 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
67 success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
68 ASSERT_EQ(EGL_TRUE, success);
69 ASSERT_EQ(EGL_SUCCESS, eglGetError());
70 ASSERT_GE(numConfigs, 1);
74 success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
75 ASSERT_EQ(EGL_TRUE, success);
76 ASSERT_EQ(EGL_SUCCESS, eglGetError());
77 success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
78 ASSERT_EQ(EGL_TRUE, success);
79 ASSERT_EQ(EGL_SUCCESS, eglGetError());
80 success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
81 ASSERT_EQ(EGL_TRUE, success);
82 ASSERT_EQ(EGL_SUCCESS, eglGetError());
84 EXPECT_GE(components[0], 8);
85 EXPECT_GE(components[1], 8);
86 EXPECT_GE(components[2], 8);
89 TEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) {
93 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
94 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
101 EXPECT_TRUE(eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs));
103 struct DummyConsumer : public BufferQueue::ConsumerListener {
104 virtual void onFrameAvailable() {}
105 virtual void onBuffersReleased() {}
108 // Create a EGLSurface
109 sp<BufferQueue> bq = new BufferQueue();
110 bq->consumerConnect(new DummyConsumer, false);
111 sp<Surface> mSTC = new Surface(static_cast<sp<IGraphicBufferProducer> >( bq));
112 sp<ANativeWindow> mANW = mSTC;
114 EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config,
116 ASSERT_EQ(EGL_SUCCESS, eglGetError());
117 ASSERT_NE(EGL_NO_SURFACE, eglSurface) ;
119 // do not destroy eglSurface
120 // eglTerminate is called in the tear down and should destroy it for us
123 TEST_F(EGLTest, EGLConfigRGBA8888First) {
129 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
130 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
138 success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
139 ASSERT_EQ(EGL_TRUE, success);
140 ASSERT_EQ(EGL_SUCCESS, eglGetError());
141 ASSERT_GE(numConfigs, 1);
143 EGLint components[4];
145 success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
146 ASSERT_EQ(EGL_TRUE, success);
147 ASSERT_EQ(EGL_SUCCESS, eglGetError());
148 success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
149 ASSERT_EQ(EGL_TRUE, success);
150 ASSERT_EQ(EGL_SUCCESS, eglGetError());
151 success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
152 ASSERT_EQ(EGL_TRUE, success);
153 ASSERT_EQ(EGL_SUCCESS, eglGetError());
154 success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]);
155 ASSERT_EQ(EGL_TRUE, success);
156 ASSERT_EQ(EGL_SUCCESS, eglGetError());
158 EXPECT_GE(components[0], 8);
159 EXPECT_GE(components[1], 8);
160 EXPECT_GE(components[2], 8);
161 EXPECT_GE(components[3], 8);