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