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/SurfaceTextureClient.h>
23 #include <gui/DummyConsumer.h>
28 class EGLTest : public ::testing::Test {
30 EGLDisplay mEglDisplay;
34 mEglDisplay(EGL_NO_DISPLAY) {
37 virtual void SetUp() {
38 mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
39 ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay);
40 ASSERT_EQ(EGL_SUCCESS, eglGetError());
44 EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion));
45 ASSERT_EQ(EGL_SUCCESS, eglGetError());
46 RecordProperty("EglVersionMajor", majorVersion);
47 RecordProperty("EglVersionMajor", minorVersion);
50 virtual void TearDown() {
51 EGLBoolean success = eglTerminate(mEglDisplay);
52 ASSERT_EQ(EGL_TRUE, success);
53 ASSERT_EQ(EGL_SUCCESS, eglGetError());
57 TEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) {
63 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
64 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
68 success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
69 ASSERT_EQ(EGL_TRUE, success);
70 ASSERT_EQ(EGL_SUCCESS, eglGetError());
71 ASSERT_GE(numConfigs, 1);
75 success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
76 ASSERT_EQ(EGL_TRUE, success);
77 ASSERT_EQ(EGL_SUCCESS, eglGetError());
78 success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
79 ASSERT_EQ(EGL_TRUE, success);
80 ASSERT_EQ(EGL_SUCCESS, eglGetError());
81 success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
82 ASSERT_EQ(EGL_TRUE, success);
83 ASSERT_EQ(EGL_SUCCESS, eglGetError());
85 EXPECT_GE(components[0], 8);
86 EXPECT_GE(components[1], 8);
87 EXPECT_GE(components[2], 8);
90 TEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) {
94 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
95 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
102 EXPECT_TRUE(eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs));
104 // Create a EGLSurface
105 sp<BufferQueue> bq = new BufferQueue();
106 bq->consumerConnect(new DummyConsumer());
107 sp<SurfaceTextureClient> mSTC = new SurfaceTextureClient(static_cast<sp<IGraphicBufferProducer> >( bq));
108 sp<ANativeWindow> mANW = mSTC;
110 EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config,
112 ASSERT_EQ(EGL_SUCCESS, eglGetError());
113 ASSERT_NE(EGL_NO_SURFACE, eglSurface) ;
115 // do not destroy eglSurface
116 // eglTerminate is called in the tear down and should destroy it for us
119 TEST_F(EGLTest, EGLConfigRGBA8888First) {
125 EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
126 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
134 success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
135 ASSERT_EQ(EGL_TRUE, success);
136 ASSERT_EQ(EGL_SUCCESS, eglGetError());
137 ASSERT_GE(numConfigs, 1);
139 EGLint components[4];
141 success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
142 ASSERT_EQ(EGL_TRUE, success);
143 ASSERT_EQ(EGL_SUCCESS, eglGetError());
144 success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
145 ASSERT_EQ(EGL_TRUE, success);
146 ASSERT_EQ(EGL_SUCCESS, eglGetError());
147 success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
148 ASSERT_EQ(EGL_TRUE, success);
149 ASSERT_EQ(EGL_SUCCESS, eglGetError());
150 success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]);
151 ASSERT_EQ(EGL_TRUE, success);
152 ASSERT_EQ(EGL_SUCCESS, eglGetError());
154 EXPECT_GE(components[0], 8);
155 EXPECT_GE(components[1], 8);
156 EXPECT_GE(components[2], 8);
157 EXPECT_GE(components[3], 8);