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> |
Daniel Lam | 1cbcb98 | 2012-04-16 22:21:02 -0700 | [diff] [blame^] | 22 | #include <gui/SurfaceTextureClient.h> |
| 23 | #include <gui/DummyConsumer.h> |
| 24 | |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | |
| 28 | class EGLTest : public ::testing::Test { |
| 29 | protected: |
| 30 | EGLDisplay mEglDisplay; |
| 31 | |
| 32 | protected: |
| 33 | EGLTest() : |
| 34 | mEglDisplay(EGL_NO_DISPLAY) { |
| 35 | } |
| 36 | |
| 37 | virtual void SetUp() { |
| 38 | mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 39 | ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay); |
| 40 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 41 | |
| 42 | EGLint majorVersion; |
| 43 | EGLint minorVersion; |
| 44 | EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion)); |
| 45 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 46 | RecordProperty("EglVersionMajor", majorVersion); |
| 47 | RecordProperty("EglVersionMajor", minorVersion); |
| 48 | } |
| 49 | |
| 50 | virtual void TearDown() { |
| 51 | EGLBoolean success = eglTerminate(mEglDisplay); |
| 52 | ASSERT_EQ(EGL_TRUE, success); |
| 53 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | TEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) { |
| 58 | |
| 59 | EGLint numConfigs; |
| 60 | EGLConfig config; |
| 61 | EGLBoolean success; |
| 62 | EGLint attrs[] = { |
| 63 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 64 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 65 | EGL_NONE |
| 66 | }; |
| 67 | |
| 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); |
| 72 | |
| 73 | EGLint components[3]; |
| 74 | |
| 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()); |
| 84 | |
| 85 | EXPECT_GE(components[0], 8); |
| 86 | EXPECT_GE(components[1], 8); |
| 87 | EXPECT_GE(components[2], 8); |
| 88 | } |
| 89 | |
Daniel Lam | 1cbcb98 | 2012-04-16 22:21:02 -0700 | [diff] [blame^] | 90 | TEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) { |
| 91 | EGLint numConfigs; |
| 92 | EGLConfig config; |
| 93 | EGLint attrs[] = { |
| 94 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 95 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 96 | EGL_RED_SIZE, 8, |
| 97 | EGL_GREEN_SIZE, 8, |
| 98 | EGL_BLUE_SIZE, 8, |
| 99 | EGL_ALPHA_SIZE, 8, |
| 100 | EGL_NONE |
| 101 | }; |
| 102 | EXPECT_TRUE(eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs)); |
| 103 | |
| 104 | // Create a EGLSurface |
| 105 | sp<BufferQueue> bq = new BufferQueue(); |
| 106 | bq->consumerConnect(new DummyConsumer()); |
| 107 | sp<SurfaceTextureClient> mSTC = new SurfaceTextureClient(static_cast<sp<ISurfaceTexture> >( bq)); |
| 108 | sp<ANativeWindow> mANW = mSTC; |
| 109 | |
| 110 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, |
| 111 | mANW.get(), NULL); |
| 112 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 113 | ASSERT_NE(EGL_NO_SURFACE, eglSurface) ; |
| 114 | |
| 115 | // do not destroy eglSurface |
| 116 | // eglTerminate is called in the tear down and should destroy it for us |
| 117 | } |
| 118 | |
Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 119 | TEST_F(EGLTest, EGLConfigRGBA8888First) { |
| 120 | |
| 121 | EGLint numConfigs; |
| 122 | EGLConfig config; |
| 123 | EGLBoolean success; |
| 124 | EGLint attrs[] = { |
| 125 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 126 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 127 | EGL_RED_SIZE, 8, |
| 128 | EGL_GREEN_SIZE, 8, |
| 129 | EGL_BLUE_SIZE, 8, |
| 130 | EGL_ALPHA_SIZE, 8, |
| 131 | EGL_NONE |
| 132 | }; |
| 133 | |
| 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); |
| 138 | |
| 139 | EGLint components[4]; |
| 140 | |
| 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()); |
| 153 | |
| 154 | EXPECT_GE(components[0], 8); |
| 155 | EXPECT_GE(components[1], 8); |
| 156 | EXPECT_GE(components[2], 8); |
| 157 | EXPECT_GE(components[3], 8); |
| 158 | } |
| 159 | |
| 160 | |
| 161 | } |