| 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> | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 22 | #include <gui/Surface.h> | 
| Daniel Lam | 1cbcb98 | 2012-04-16 22:21:02 -0700 | [diff] [blame] | 23 |  | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 24 |  | 
|  | 25 | namespace android { | 
|  | 26 |  | 
| Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 27 | #define EGL_UNSIGNED_TRUE static_cast<EGLBoolean>(EGL_TRUE) | 
|  | 28 |  | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 29 | class EGLTest : public ::testing::Test { | 
|  | 30 | protected: | 
|  | 31 | EGLDisplay mEglDisplay; | 
|  | 32 |  | 
|  | 33 | protected: | 
|  | 34 | EGLTest() : | 
|  | 35 | mEglDisplay(EGL_NO_DISPLAY) { | 
|  | 36 | } | 
|  | 37 |  | 
|  | 38 | virtual void SetUp() { | 
|  | 39 | mEglDisplay = eglGetDisplay(EGL_DEFAULT_DISPLAY); | 
|  | 40 | ASSERT_NE(EGL_NO_DISPLAY, mEglDisplay); | 
|  | 41 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 42 |  | 
|  | 43 | EGLint majorVersion; | 
|  | 44 | EGLint minorVersion; | 
|  | 45 | EXPECT_TRUE(eglInitialize(mEglDisplay, &majorVersion, &minorVersion)); | 
|  | 46 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 47 | RecordProperty("EglVersionMajor", majorVersion); | 
|  | 48 | RecordProperty("EglVersionMajor", minorVersion); | 
|  | 49 | } | 
|  | 50 |  | 
|  | 51 | virtual void TearDown() { | 
|  | 52 | EGLBoolean success = eglTerminate(mEglDisplay); | 
| Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 53 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 54 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 55 | } | 
|  | 56 | }; | 
|  | 57 |  | 
|  | 58 | TEST_F(EGLTest, DISABLED_EGLConfigEightBitFirst) { | 
|  | 59 |  | 
|  | 60 | EGLint numConfigs; | 
|  | 61 | EGLConfig config; | 
|  | 62 | EGLBoolean success; | 
|  | 63 | EGLint attrs[] = { | 
|  | 64 | EGL_SURFACE_TYPE,       EGL_WINDOW_BIT, | 
|  | 65 | EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT, | 
|  | 66 | EGL_NONE | 
|  | 67 | }; | 
|  | 68 |  | 
|  | 69 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); | 
| Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 70 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 71 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 72 | ASSERT_GE(numConfigs, 1); | 
|  | 73 |  | 
|  | 74 | EGLint components[3]; | 
|  | 75 |  | 
|  | 76 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); | 
| Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 77 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 78 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 79 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); | 
| Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 80 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 81 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 82 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); | 
| Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 83 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 84 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 85 |  | 
|  | 86 | EXPECT_GE(components[0], 8); | 
|  | 87 | EXPECT_GE(components[1], 8); | 
|  | 88 | EXPECT_GE(components[2], 8); | 
|  | 89 | } | 
|  | 90 |  | 
| Daniel Lam | 1cbcb98 | 2012-04-16 22:21:02 -0700 | [diff] [blame] | 91 | TEST_F(EGLTest, EGLTerminateSucceedsWithRemainingObjects) { | 
|  | 92 | EGLint numConfigs; | 
|  | 93 | EGLConfig config; | 
|  | 94 | EGLint attrs[] = { | 
|  | 95 | EGL_SURFACE_TYPE,       EGL_WINDOW_BIT, | 
|  | 96 | EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT, | 
|  | 97 | EGL_RED_SIZE,           8, | 
|  | 98 | EGL_GREEN_SIZE,         8, | 
|  | 99 | EGL_BLUE_SIZE,          8, | 
|  | 100 | EGL_ALPHA_SIZE,         8, | 
|  | 101 | EGL_NONE | 
|  | 102 | }; | 
|  | 103 | EXPECT_TRUE(eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs)); | 
|  | 104 |  | 
| Mathias Agopian | a4e1952 | 2013-07-31 20:09:53 -0700 | [diff] [blame] | 105 | struct DummyConsumer : public BnConsumerListener { | 
| Dan Stoza | 8dc5539 | 2014-11-04 11:37:46 -0800 | [diff] [blame] | 106 | virtual void onFrameAvailable(const BufferItem& /* item */) {} | 
| Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 107 | virtual void onBuffersReleased() {} | 
| Jesse Hall | 85c0fee | 2014-03-13 14:34:28 -0700 | [diff] [blame] | 108 | virtual void onSidebandStreamChanged() {} | 
| Mathias Agopian | 595264f | 2013-07-16 22:56:09 -0700 | [diff] [blame] | 109 | }; | 
|  | 110 |  | 
| Daniel Lam | 1cbcb98 | 2012-04-16 22:21:02 -0700 | [diff] [blame] | 111 | // Create a EGLSurface | 
| Dan Stoza | 5603a2f | 2014-04-07 13:41:37 -0700 | [diff] [blame] | 112 | sp<IGraphicBufferProducer> producer; | 
|  | 113 | sp<IGraphicBufferConsumer> consumer; | 
|  | 114 | BufferQueue::createBufferQueue(&producer, &consumer); | 
|  | 115 | consumer->consumerConnect(new DummyConsumer, false); | 
|  | 116 | sp<Surface> mSTC = new Surface(producer); | 
| Daniel Lam | 1cbcb98 | 2012-04-16 22:21:02 -0700 | [diff] [blame] | 117 | sp<ANativeWindow> mANW = mSTC; | 
|  | 118 |  | 
|  | 119 | EGLSurface eglSurface = eglCreateWindowSurface(mEglDisplay, config, | 
|  | 120 | mANW.get(), NULL); | 
|  | 121 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 122 | ASSERT_NE(EGL_NO_SURFACE, eglSurface) ; | 
|  | 123 |  | 
|  | 124 | // do not destroy eglSurface | 
|  | 125 | // eglTerminate is called in the tear down and should destroy it for us | 
|  | 126 | } | 
|  | 127 |  | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 128 | TEST_F(EGLTest, EGLConfigRGBA8888First) { | 
|  | 129 |  | 
|  | 130 | EGLint numConfigs; | 
|  | 131 | EGLConfig config; | 
|  | 132 | EGLBoolean success; | 
|  | 133 | EGLint attrs[] = { | 
|  | 134 | EGL_SURFACE_TYPE,       EGL_WINDOW_BIT, | 
|  | 135 | EGL_RENDERABLE_TYPE,    EGL_OPENGL_ES2_BIT, | 
|  | 136 | EGL_RED_SIZE,           8, | 
|  | 137 | EGL_GREEN_SIZE,         8, | 
|  | 138 | EGL_BLUE_SIZE,          8, | 
|  | 139 | EGL_ALPHA_SIZE,         8, | 
|  | 140 | EGL_NONE | 
|  | 141 | }; | 
|  | 142 |  | 
|  | 143 | success = eglChooseConfig(mEglDisplay, attrs, &config, 1, &numConfigs); | 
| Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 144 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 145 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 146 | ASSERT_GE(numConfigs, 1); | 
|  | 147 |  | 
|  | 148 | EGLint components[4]; | 
|  | 149 |  | 
|  | 150 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_RED_SIZE, &components[0]); | 
| Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 151 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 152 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 153 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_GREEN_SIZE, &components[1]); | 
| Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 154 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 155 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 156 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_BLUE_SIZE, &components[2]); | 
| Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 157 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 158 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 159 | success = eglGetConfigAttrib(mEglDisplay, config, EGL_ALPHA_SIZE, &components[3]); | 
| Kalle Raita | 4cf3637 | 2017-01-13 10:18:36 -0800 | [diff] [blame] | 160 | ASSERT_EQ(EGL_UNSIGNED_TRUE, success); | 
| Mathias Agopian | 2f739f8 | 2011-07-07 14:54:30 -0700 | [diff] [blame] | 161 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); | 
|  | 162 |  | 
|  | 163 | EXPECT_GE(components[0], 8); | 
|  | 164 | EXPECT_GE(components[1], 8); | 
|  | 165 | EXPECT_GE(components[2], 8); | 
|  | 166 | EXPECT_GE(components[3], 8); | 
|  | 167 | } | 
|  | 168 |  | 
|  | 169 |  | 
|  | 170 | } |