EGL_test.cpp revision 2f739f8f0442f9c1bb42c47ab43d365fd9020008
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>
222f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
232f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopiannamespace android {
242f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
252f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopianclass EGLTest : public ::testing::Test {
262f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopianprotected:
272f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EGLDisplay mEglDisplay;
282f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
292f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopianprotected:
302f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EGLTest() :
312f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian            mEglDisplay(EGL_NO_DISPLAY) {
322f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    }
332f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
342f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    virtual void SetUp() {
352f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian        mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY);
362f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian        ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay);
372f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian        ASSERT_EQ(EGL_SUCCESS, eglGetError());
382f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
392f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian        EGLint majorVersion;
402f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian        EGLint minorVersion;
412f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian        EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion));
422f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian        ASSERT_EQ(EGL_SUCCESS, eglGetError());
432f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian        RecordProperty("EglVersionMajor", majorVersion);
442f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian        RecordProperty("EglVersionMajor", minorVersion);
452f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    }
462f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
472f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    virtual void TearDown() {
482f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian        EGLBoolean success = eglTerminate(mEglDisplay);
492f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian        ASSERT_EQ(EGL_TRUE, success);
502f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian        ASSERT_EQ(EGL_SUCCESS, eglGetError());
512f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    }
522f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian};
532f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
542f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias AgopianTEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) {
552f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
562f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EGLint numConfigs;
572f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EGLConfig config;
582f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EGLBoolean success;
592f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EGLint attrs[] = {
602f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian            EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
612f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian            EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT,
622f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian            EGL_NONE
632f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    };
642f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
652f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
662f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_TRUE, success);
672f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_SUCCESS, eglGetError());
682f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_GE(numConfigs, 1);
692f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
702f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EGLint components[3];
712f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
722f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
732f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_TRUE, success);
742f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_SUCCESS, eglGetError());
752f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
762f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_TRUE, success);
772f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_SUCCESS, eglGetError());
782f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
792f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_TRUE, success);
802f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_SUCCESS, eglGetError());
812f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
822f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EXPECT_GE(components[0], 8);
832f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EXPECT_GE(components[1], 8);
842f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EXPECT_GE(components[2], 8);
852f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian}
862f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
872f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias AgopianTEST_F(EGLTest, EGLConfigRGBA8888First) {
882f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
892f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EGLint numConfigs;
902f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EGLConfig config;
912f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EGLBoolean success;
922f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EGLint attrs[] = {
932f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian            EGL_SURFACE_TYPE,       EGL_WINDOW_BIT,
942f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian            EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT,
952f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian            EGL_RED_SIZE,           8,
962f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian            EGL_GREEN_SIZE,         8,
972f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian            EGL_BLUE_SIZE,          8,
982f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian            EGL_ALPHA_SIZE,         8,
992f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian            EGL_NONE
1002f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    };
1012f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
1022f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs);
1032f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_TRUE, success);
1042f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_SUCCESS, eglGetError());
1052f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_GE(numConfigs, 1);
1062f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
1072f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EGLint components[4];
1082f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
1092f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]);
1102f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_TRUE, success);
1112f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_SUCCESS, eglGetError());
1122f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]);
1132f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_TRUE, success);
1142f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_SUCCESS, eglGetError());
1152f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]);
1162f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_TRUE, success);
1172f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_SUCCESS, eglGetError());
1182f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]);
1192f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_TRUE, success);
1202f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    ASSERT_EQ(EGL_SUCCESS, eglGetError());
1212f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
1222f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EXPECT_GE(components[0], 8);
1232f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EXPECT_GE(components[1], 8);
1242f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EXPECT_GE(components[2], 8);
1252f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian    EXPECT_GE(components[3], 8);
1262f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian}
1272f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
1282f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian
1292f739f8f0442f9c1bb42c47ab43d365fd9020008Mathias Agopian}
130