12f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian/* 22f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * Copyright (C) 2011 The Android Open Source Project 32f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * 42f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License"); 52f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * you may not use this file except in compliance with the License. 62f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * You may obtain a copy of the License at 72f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * 82f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * http://www.apache.org/licenses/LICENSE-2.0 92f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * 102f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * Unless required by applicable law or agreed to in writing, software 112f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS, 122f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 132f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * See the License for the specific language governing permissions and 142f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian * limitations under the License. 152f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian */ 162f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 172f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian#include <gtest/gtest.h> 182f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 192f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian#include <utils/String8.h> 202f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 212f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian#include <EGL/egl.h> 221cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam#include <gui/SurfaceTextureClient.h> 231cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam#include <gui/DummyConsumer.h> 241cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam 252f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 262f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopiannamespace android { 272f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 282f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopianclass EGLTest : public ::testing::Test { 292f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopianprotected: 302f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLDisplay mEglDisplay; 312f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 322f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopianprotected: 332f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLTest() : 342f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian mEglDisplay(EGL_NO_DISPLAY) { 352f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian } 362f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 372f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian virtual void SetUp() { 382f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); 392f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay); 402f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_SUCCESS, eglGetError()); 412f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 422f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLint majorVersion; 432f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLint minorVersion; 442f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion)); 452f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_SUCCESS, eglGetError()); 462f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian RecordProperty("EglVersionMajor", majorVersion); 472f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian RecordProperty("EglVersionMajor", minorVersion); 482f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian } 492f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 502f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian virtual void TearDown() { 512f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLBoolean success = eglTerminate(mEglDisplay); 522f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_TRUE, success); 532f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_SUCCESS, eglGetError()); 542f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian } 552f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian}; 562f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 572f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias AgopianTEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) { 582f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 592f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLint numConfigs; 602f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLConfig config; 612f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLBoolean success; 622f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLint attrs[] = { 632f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 642f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 652f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGL_NONE 662f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian }; 672f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 682f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); 692f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_TRUE, success); 702f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_SUCCESS, eglGetError()); 712f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_GE(numConfigs, 1); 722f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 732f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLint components[3]; 742f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 752f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); 762f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_TRUE, success); 772f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_SUCCESS, eglGetError()); 782f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); 792f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_TRUE, success); 802f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_SUCCESS, eglGetError()); 812f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); 822f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_TRUE, success); 832f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_SUCCESS, eglGetError()); 842f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 852f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EXPECT_GE(components[0], 8); 862f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EXPECT_GE(components[1], 8); 872f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EXPECT_GE(components[2], 8); 882f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian} 892f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 901cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel LamTEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) { 911cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam EGLint numConfigs; 921cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam EGLConfig config; 931cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam EGLint attrs[] = { 941cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 951cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 961cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam EGL_RED_SIZE, 8, 971cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam EGL_GREEN_SIZE, 8, 981cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam EGL_BLUE_SIZE, 8, 991cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam EGL_ALPHA_SIZE, 8, 1001cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam EGL_NONE 1011cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam }; 1021cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam EXPECT_TRUE(eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs)); 1031cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam 1041cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam // Create a EGLSurface 1051cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam sp<BufferQueue> bq = new BufferQueue(); 1061cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam bq->consumerConnect(new DummyConsumer()); 1071cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam sp<SurfaceTextureClient> mSTC = new SurfaceTextureClient(static_cast<sp<ISurfaceTexture> >( bq)); 1081cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam sp<ANativeWindow> mANW = mSTC; 1091cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam 1101cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, 1111cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam mANW.get(), NULL); 1121cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam ASSERT_EQ(EGL_SUCCESS, eglGetError()); 1131cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam ASSERT_NE(EGL_NO_SURFACE, eglSurface) ; 1141cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam 1151cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam // do not destroy eglSurface 1161cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam // eglTerminate is called in the tear down and should destroy it for us 1171cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam} 1181cbcb98a2528ea0d8ce34dc35513859c7ef957f3Daniel Lam 1192f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias AgopianTEST_F(EGLTest, EGLConfigRGBA8888First) { 1202f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 1212f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLint numConfigs; 1222f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLConfig config; 1232f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLBoolean success; 1242f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLint attrs[] = { 1252f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 1262f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 1272f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGL_RED_SIZE, 8, 1282f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGL_GREEN_SIZE, 8, 1292f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGL_BLUE_SIZE, 8, 1302f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGL_ALPHA_SIZE, 8, 1312f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGL_NONE 1322f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian }; 1332f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 1342f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); 1352f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_TRUE, success); 1362f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_SUCCESS, eglGetError()); 1372f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_GE(numConfigs, 1); 1382f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 1392f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EGLint components[4]; 1402f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 1412f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); 1422f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_TRUE, success); 1432f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_SUCCESS, eglGetError()); 1442f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); 1452f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_TRUE, success); 1462f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_SUCCESS, eglGetError()); 1472f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); 1482f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_TRUE, success); 1492f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_SUCCESS, eglGetError()); 1502f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); 1512f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_TRUE, success); 1522f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian ASSERT_EQ(EGL_SUCCESS, eglGetError()); 1532f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 1542f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EXPECT_GE(components[0], 8); 1552f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EXPECT_GE(components[1], 8); 1562f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EXPECT_GE(components[2], 8); 1572f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian EXPECT_GE(components[3], 8); 1582f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian} 1592f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 1602f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian 1612f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian} 162