Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame^] | 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 | |
| 23 | namespace android { |
| 24 | |
| 25 | class EGLTest : public ::testing::Test { |
| 26 | protected: |
| 27 | EGLDisplay mEglDisplay; |
| 28 | |
| 29 | protected: |
| 30 | EGLTest() : |
| 31 | mEglDisplay(EGL_NO_DISPLAY) { |
| 32 | } |
| 33 | |
| 34 | virtual void SetUp() { |
| 35 | mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 36 | ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay); |
| 37 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 38 | |
| 39 | EGLint majorVersion; |
| 40 | EGLint minorVersion; |
| 41 | EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion)); |
| 42 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 43 | RecordProperty("EglVersionMajor", majorVersion); |
| 44 | RecordProperty("EglVersionMajor", minorVersion); |
| 45 | } |
| 46 | |
| 47 | virtual void TearDown() { |
| 48 | EGLBoolean success = eglTerminate(mEglDisplay); |
| 49 | ASSERT_EQ(EGL_TRUE, success); |
| 50 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 51 | } |
| 52 | }; |
| 53 | |
| 54 | TEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) { |
| 55 | |
| 56 | EGLint numConfigs; |
| 57 | EGLConfig config; |
| 58 | EGLBoolean success; |
| 59 | EGLint attrs[] = { |
| 60 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 61 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 62 | EGL_NONE |
| 63 | }; |
| 64 | |
| 65 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
| 66 | ASSERT_EQ(EGL_TRUE, success); |
| 67 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 68 | ASSERT_GE(numConfigs, 1); |
| 69 | |
| 70 | EGLint components[3]; |
| 71 | |
| 72 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
| 73 | ASSERT_EQ(EGL_TRUE, success); |
| 74 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 75 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
| 76 | ASSERT_EQ(EGL_TRUE, success); |
| 77 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 78 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
| 79 | ASSERT_EQ(EGL_TRUE, success); |
| 80 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 81 | |
| 82 | EXPECT_GE(components[0], 8); |
| 83 | EXPECT_GE(components[1], 8); |
| 84 | EXPECT_GE(components[2], 8); |
| 85 | } |
| 86 | |
| 87 | TEST_F(EGLTest, EGLConfigRGBA8888First) { |
| 88 | |
| 89 | EGLint numConfigs; |
| 90 | EGLConfig config; |
| 91 | EGLBoolean success; |
| 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 | |
| 102 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); |
| 103 | ASSERT_EQ(EGL_TRUE, success); |
| 104 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 105 | ASSERT_GE(numConfigs, 1); |
| 106 | |
| 107 | EGLint components[4]; |
| 108 | |
| 109 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); |
| 110 | ASSERT_EQ(EGL_TRUE, success); |
| 111 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 112 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); |
| 113 | ASSERT_EQ(EGL_TRUE, success); |
| 114 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 115 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); |
| 116 | ASSERT_EQ(EGL_TRUE, success); |
| 117 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 118 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); |
| 119 | ASSERT_EQ(EGL_TRUE, success); |
| 120 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 121 | |
| 122 | EXPECT_GE(components[0], 8); |
| 123 | EXPECT_GE(components[1], 8); |
| 124 | EXPECT_GE(components[2], 8); |
| 125 | EXPECT_GE(components[3], 8); |
| 126 | } |
| 127 | |
| 128 | |
| 129 | } |