EGL_test.cpp revision 85c0fee024384a7756a5eeb31592b6a0d7bacd91
1/* 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> 22#include <gui/Surface.h> 23 24 25namespace android { 26 27class EGLTest : public ::testing::Test { 28protected: 29 EGLDisplay mEglDisplay; 30 31protected: 32 EGLTest() : 33 mEglDisplay(EGL_NO_DISPLAY) { 34 } 35 36 virtual void SetUp() { 37 mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); 38 ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay); 39 ASSERT_EQ(EGL_SUCCESS, eglGetError()); 40 41 EGLint majorVersion; 42 EGLint minorVersion; 43 EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion)); 44 ASSERT_EQ(EGL_SUCCESS, eglGetError()); 45 RecordProperty("EglVersionMajor", majorVersion); 46 RecordProperty("EglVersionMajor", minorVersion); 47 } 48 49 virtual void TearDown() { 50 EGLBoolean success = eglTerminate(mEglDisplay); 51 ASSERT_EQ(EGL_TRUE, success); 52 ASSERT_EQ(EGL_SUCCESS, eglGetError()); 53 } 54}; 55 56TEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) { 57 58 EGLint numConfigs; 59 EGLConfig config; 60 EGLBoolean success; 61 EGLint attrs[] = { 62 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 63 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 64 EGL_NONE 65 }; 66 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); 71 72 EGLint components[3]; 73 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()); 83 84 EXPECT_GE(components[0], 8); 85 EXPECT_GE(components[1], 8); 86 EXPECT_GE(components[2], 8); 87} 88 89TEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) { 90 EGLint numConfigs; 91 EGLConfig config; 92 EGLint attrs[] = { 93 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 94 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 95 EGL_RED_SIZE, 8, 96 EGL_GREEN_SIZE, 8, 97 EGL_BLUE_SIZE, 8, 98 EGL_ALPHA_SIZE, 8, 99 EGL_NONE 100 }; 101 EXPECT_TRUE(eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs)); 102 103 struct DummyConsumer : public BnConsumerListener { 104 virtual void onFrameAvailable() {} 105 virtual void onBuffersReleased() {} 106 virtual void onSidebandStreamChanged() {} 107 }; 108 109 // Create a EGLSurface 110 sp<BufferQueue> bq = new BufferQueue(); 111 bq->consumerConnect(new DummyConsumer, false); 112 sp<Surface> mSTC = new Surface(static_cast<sp<IGraphicBufferProducer> >( bq)); 113 sp<ANativeWindow> mANW = mSTC; 114 115 EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, 116 mANW.get(), NULL); 117 ASSERT_EQ(EGL_SUCCESS, eglGetError()); 118 ASSERT_NE(EGL_NO_SURFACE, eglSurface) ; 119 120 // do not destroy eglSurface 121 // eglTerminate is called in the tear down and should destroy it for us 122} 123 124TEST_F(EGLTest, EGLConfigRGBA8888First) { 125 126 EGLint numConfigs; 127 EGLConfig config; 128 EGLBoolean success; 129 EGLint attrs[] = { 130 EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 131 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 132 EGL_RED_SIZE, 8, 133 EGL_GREEN_SIZE, 8, 134 EGL_BLUE_SIZE, 8, 135 EGL_ALPHA_SIZE, 8, 136 EGL_NONE 137 }; 138 139 success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); 140 ASSERT_EQ(EGL_TRUE, success); 141 ASSERT_EQ(EGL_SUCCESS, eglGetError()); 142 ASSERT_GE(numConfigs, 1); 143 144 EGLint components[4]; 145 146 success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); 147 ASSERT_EQ(EGL_TRUE, success); 148 ASSERT_EQ(EGL_SUCCESS, eglGetError()); 149 success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); 150 ASSERT_EQ(EGL_TRUE, success); 151 ASSERT_EQ(EGL_SUCCESS, eglGetError()); 152 success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); 153 ASSERT_EQ(EGL_TRUE, success); 154 ASSERT_EQ(EGL_SUCCESS, eglGetError()); 155 success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); 156 ASSERT_EQ(EGL_TRUE, success); 157 ASSERT_EQ(EGL_SUCCESS, eglGetError()); 158 159 EXPECT_GE(components[0], 8); 160 EXPECT_GE(components[1], 8); 161 EXPECT_GE(components[2], 8); 162 EXPECT_GE(components[3], 8); 163} 164 165 166} 167