Jamie Gennis | 134f042 | 2011-03-08 12:18:54 -0800 | [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 | |
Jamie Gennis | 5c0c93a | 2011-03-14 15:34:04 -0700 | [diff] [blame] | 17 | #include <EGL/egl.h> |
Jamie Gennis | 134f042 | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 18 | #include <gtest/gtest.h> |
Jamie Gennis | 5c0c93a | 2011-03-14 15:34:04 -0700 | [diff] [blame] | 19 | #include <gui/SurfaceTextureClient.h> |
Jamie Gennis | 134f042 | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 20 | |
| 21 | namespace android { |
| 22 | |
| 23 | class SurfaceTextureClientTest : public ::testing::Test { |
| 24 | protected: |
| 25 | virtual void SetUp() { |
| 26 | mST = new SurfaceTexture(123); |
| 27 | mSTC = new SurfaceTextureClient(mST); |
| 28 | } |
| 29 | |
| 30 | virtual void TearDown() { |
| 31 | mST.clear(); |
| 32 | mSTC.clear(); |
| 33 | } |
| 34 | |
| 35 | sp<SurfaceTexture> mST; |
| 36 | sp<SurfaceTextureClient> mSTC; |
| 37 | }; |
| 38 | |
Jamie Gennis | bae774e | 2011-03-14 15:08:53 -0700 | [diff] [blame] | 39 | TEST_F(SurfaceTextureClientTest, GetISurfaceTextureIsNotNull) { |
| 40 | sp<ISurfaceTexture> ist(mSTC->getISurfaceTexture()); |
| 41 | ASSERT_TRUE(ist != NULL); |
| 42 | } |
| 43 | |
Jamie Gennis | 134f042 | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 44 | TEST_F(SurfaceTextureClientTest, QueuesToWindowCompositorIsFalse) { |
| 45 | sp<ANativeWindow> anw(mSTC); |
| 46 | int result = -123; |
| 47 | int err = anw->query(anw.get(), NATIVE_WINDOW_QUEUES_TO_WINDOW_COMPOSER, |
| 48 | &result); |
| 49 | EXPECT_EQ(NO_ERROR, err); |
| 50 | EXPECT_EQ(0, result); |
| 51 | } |
| 52 | |
Jamie Gennis | 391bbe2 | 2011-03-14 15:00:06 -0700 | [diff] [blame] | 53 | TEST_F(SurfaceTextureClientTest, ConcreteTypeIsSurfaceTextureClient) { |
| 54 | sp<ANativeWindow> anw(mSTC); |
| 55 | int result = -123; |
| 56 | int err = anw->query(anw.get(), NATIVE_WINDOW_CONCRETE_TYPE, &result); |
| 57 | EXPECT_EQ(NO_ERROR, err); |
| 58 | EXPECT_EQ(NATIVE_WINDOW_SURFACE_TEXTURE_CLIENT, result); |
| 59 | } |
| 60 | |
Jamie Gennis | 5c0c93a | 2011-03-14 15:34:04 -0700 | [diff] [blame] | 61 | TEST_F(SurfaceTextureClientTest, ANativeWindowLockFails) { |
| 62 | sp<ANativeWindow> anw(mSTC); |
| 63 | ANativeWindow_Buffer buf; |
| 64 | ASSERT_EQ(BAD_VALUE, ANativeWindow_lock(anw.get(), &buf, NULL)); |
| 65 | } |
| 66 | |
| 67 | TEST_F(SurfaceTextureClientTest, EglCreateWindowSurfaceFails) { |
| 68 | sp<ANativeWindow> anw(mSTC); |
| 69 | |
| 70 | EGLDisplay dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); |
| 71 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 72 | ASSERT_NE(EGL_NO_DISPLAY, dpy); |
| 73 | |
| 74 | EGLint majorVersion; |
| 75 | EGLint minorVersion; |
| 76 | EXPECT_TRUE(eglInitialize(dpy, &majorVersion, &minorVersion)); |
| 77 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 78 | |
| 79 | EGLConfig myConfig = {0}; |
| 80 | EGLint numConfigs = 0; |
| 81 | EGLint configAttribs[] = { |
| 82 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, |
| 83 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
| 84 | EGL_RED_SIZE, 8, |
| 85 | EGL_GREEN_SIZE, 8, |
| 86 | EGL_BLUE_SIZE, 8, |
| 87 | EGL_ALPHA_SIZE, 8, |
| 88 | EGL_DEPTH_SIZE, 16, |
| 89 | EGL_STENCIL_SIZE, 8, |
| 90 | EGL_NONE }; |
| 91 | EXPECT_TRUE(eglChooseConfig(dpy, configAttribs, &myConfig, 1, |
| 92 | &numConfigs)); |
| 93 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 94 | |
| 95 | EGLSurface eglSurface = eglCreateWindowSurface(dpy, myConfig, anw.get(), |
| 96 | NULL); |
| 97 | ASSERT_EQ(EGL_NO_SURFACE, eglSurface); |
| 98 | ASSERT_EQ(EGL_BAD_NATIVE_WINDOW, eglGetError()); |
| 99 | |
| 100 | eglTerminate(dpy); |
| 101 | } |
| 102 | |
Mathias Agopian | a5c75c0 | 2011-03-31 19:10:24 -0700 | [diff] [blame^] | 103 | TEST_F(SurfaceTextureClientTest, BufferGeometryInvalidSizesFail) { |
| 104 | sp<ANativeWindow> anw(mSTC); |
| 105 | |
| 106 | EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), -1, 0, 0)); |
| 107 | EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), 0, -1, 0)); |
| 108 | EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, -1)); |
| 109 | EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), -1, -1, 0)); |
| 110 | EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), 0, 8, 0)); |
| 111 | EXPECT_GT(OK, native_window_set_buffers_geometry(anw.get(), 8, 0, 0)); |
| 112 | } |
| 113 | |
| 114 | TEST_F(SurfaceTextureClientTest, DefaultGeometryValues) { |
| 115 | sp<ANativeWindow> anw(mSTC); |
| 116 | android_native_buffer_t* buf; |
| 117 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf)); |
| 118 | EXPECT_EQ(1, buf->width); |
| 119 | EXPECT_EQ(1, buf->height); |
| 120 | EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format); |
| 121 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf)); |
| 122 | } |
| 123 | |
| 124 | TEST_F(SurfaceTextureClientTest, BufferGeometryCanBeSet) { |
| 125 | sp<ANativeWindow> anw(mSTC); |
| 126 | android_native_buffer_t* buf; |
| 127 | EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, PIXEL_FORMAT_RGB_565)); |
| 128 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf)); |
| 129 | EXPECT_EQ(16, buf->width); |
| 130 | EXPECT_EQ(8, buf->height); |
| 131 | EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format); |
| 132 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf)); |
| 133 | } |
| 134 | |
| 135 | TEST_F(SurfaceTextureClientTest, BufferGeometryDefaultSizeSetFormat) { |
| 136 | sp<ANativeWindow> anw(mSTC); |
| 137 | android_native_buffer_t* buf; |
| 138 | EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, PIXEL_FORMAT_RGB_565)); |
| 139 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf)); |
| 140 | EXPECT_EQ(1, buf->width); |
| 141 | EXPECT_EQ(1, buf->height); |
| 142 | EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format); |
| 143 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf)); |
| 144 | } |
| 145 | |
| 146 | TEST_F(SurfaceTextureClientTest, BufferGeometrySetSizeDefaultFormat) { |
| 147 | sp<ANativeWindow> anw(mSTC); |
| 148 | android_native_buffer_t* buf; |
| 149 | EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, 0)); |
| 150 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf)); |
| 151 | EXPECT_EQ(16, buf->width); |
| 152 | EXPECT_EQ(8, buf->height); |
| 153 | EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format); |
| 154 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf)); |
| 155 | } |
| 156 | |
| 157 | TEST_F(SurfaceTextureClientTest, BufferGeometrySizeCanBeUnset) { |
| 158 | sp<ANativeWindow> anw(mSTC); |
| 159 | android_native_buffer_t* buf; |
| 160 | EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, 0)); |
| 161 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf)); |
| 162 | EXPECT_EQ(16, buf->width); |
| 163 | EXPECT_EQ(8, buf->height); |
| 164 | EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format); |
| 165 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf)); |
| 166 | EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, 0)); |
| 167 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf)); |
| 168 | EXPECT_EQ(1, buf->width); |
| 169 | EXPECT_EQ(1, buf->height); |
| 170 | EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format); |
| 171 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf)); |
| 172 | } |
| 173 | |
| 174 | TEST_F(SurfaceTextureClientTest, BufferGeometrySizeCanBeChangedWithoutFormat) { |
| 175 | sp<ANativeWindow> anw(mSTC); |
| 176 | android_native_buffer_t* buf; |
| 177 | EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 0, 0, PIXEL_FORMAT_RGB_565)); |
| 178 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf)); |
| 179 | EXPECT_EQ(1, buf->width); |
| 180 | EXPECT_EQ(1, buf->height); |
| 181 | EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format); |
| 182 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf)); |
| 183 | EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 16, 8, 0)); |
| 184 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf)); |
| 185 | EXPECT_EQ(16, buf->width); |
| 186 | EXPECT_EQ(8, buf->height); |
| 187 | EXPECT_EQ(PIXEL_FORMAT_RGB_565, buf->format); |
| 188 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf)); |
| 189 | } |
| 190 | |
| 191 | TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSize) { |
| 192 | sp<ANativeWindow> anw(mSTC); |
| 193 | sp<SurfaceTexture> st(mST); |
| 194 | android_native_buffer_t* buf; |
| 195 | EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8)); |
| 196 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf)); |
| 197 | EXPECT_EQ(16, buf->width); |
| 198 | EXPECT_EQ(8, buf->height); |
| 199 | EXPECT_EQ(PIXEL_FORMAT_RGBA_8888, buf->format); |
| 200 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf)); |
| 201 | } |
| 202 | |
| 203 | TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSizeAfterDequeue) { |
| 204 | sp<ANativeWindow> anw(mSTC); |
| 205 | sp<SurfaceTexture> st(mST); |
| 206 | android_native_buffer_t* buf[2]; |
| 207 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0])); |
| 208 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1])); |
| 209 | EXPECT_NE(buf[0], buf[1]); |
| 210 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0])); |
| 211 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1])); |
| 212 | EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8)); |
| 213 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0])); |
| 214 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1])); |
| 215 | EXPECT_NE(buf[0], buf[1]); |
| 216 | EXPECT_EQ(16, buf[0]->width); |
| 217 | EXPECT_EQ(16, buf[1]->width); |
| 218 | EXPECT_EQ(8, buf[0]->height); |
| 219 | EXPECT_EQ(8, buf[1]->height); |
| 220 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0])); |
| 221 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1])); |
| 222 | } |
| 223 | |
| 224 | TEST_F(SurfaceTextureClientTest, SurfaceTextureSetDefaultSizeVsGeometry) { |
| 225 | sp<ANativeWindow> anw(mSTC); |
| 226 | sp<SurfaceTexture> st(mST); |
| 227 | android_native_buffer_t* buf[2]; |
| 228 | EXPECT_EQ(OK, st->setDefaultBufferSize(16, 8)); |
| 229 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0])); |
| 230 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1])); |
| 231 | EXPECT_NE(buf[0], buf[1]); |
| 232 | EXPECT_EQ(16, buf[0]->width); |
| 233 | EXPECT_EQ(16, buf[1]->width); |
| 234 | EXPECT_EQ(8, buf[0]->height); |
| 235 | EXPECT_EQ(8, buf[1]->height); |
| 236 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0])); |
| 237 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1])); |
| 238 | EXPECT_EQ(OK, native_window_set_buffers_geometry(anw.get(), 12, 24, 0)); |
| 239 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[0])); |
| 240 | ASSERT_EQ(OK, anw->dequeueBuffer(anw.get(), &buf[1])); |
| 241 | EXPECT_NE(buf[0], buf[1]); |
| 242 | EXPECT_EQ(12, buf[0]->width); |
| 243 | EXPECT_EQ(12, buf[1]->width); |
| 244 | EXPECT_EQ(24, buf[0]->height); |
| 245 | EXPECT_EQ(24, buf[1]->height); |
| 246 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[0])); |
| 247 | ASSERT_EQ(OK, anw->cancelBuffer(anw.get(), buf[1])); |
| 248 | } |
| 249 | |
Jamie Gennis | 134f042 | 2011-03-08 12:18:54 -0800 | [diff] [blame] | 250 | } |