Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 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 | #define LOG_TAG "SurfaceTextureGLToGL_test" |
| 18 | //#define LOG_NDEBUG 0 |
| 19 | |
| 20 | #include "SurfaceTextureGLToGL.h" |
| 21 | |
| 22 | namespace android { |
| 23 | |
| 24 | TEST_F(SurfaceTextureGLToGLTest, TransformHintGetsRespected) { |
| 25 | const uint32_t texWidth = 32; |
| 26 | const uint32_t texHeight = 64; |
| 27 | |
| 28 | mST->setDefaultBufferSize(texWidth, texHeight); |
| 29 | mST->setTransformHint(NATIVE_WINDOW_TRANSFORM_ROT_90); |
| 30 | |
| 31 | // This test requires 3 buffers to avoid deadlock because we're |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 32 | // both producer and consumer, and only using one thread. Set max dequeued |
| 33 | // to 2, and max acquired already defaults to 1. |
| 34 | ASSERT_EQ(OK, mSTC->setMaxDequeuedBufferCount(2)); |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 35 | |
| 36 | // Do the producer side of things |
| 37 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface, |
| 38 | mProducerEglSurface, mProducerEglContext)); |
| 39 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 40 | |
| 41 | // Start a buffer with our chosen size and transform hint moving |
| 42 | // through the system. |
| 43 | glClear(GL_COLOR_BUFFER_BIT); // give the driver something to do |
| 44 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 45 | mST->updateTexImage(); // consume it |
| 46 | // Swap again. |
| 47 | glClear(GL_COLOR_BUFFER_BIT); |
| 48 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 49 | mST->updateTexImage(); |
| 50 | |
| 51 | // The current buffer should either show the effects of the transform |
| 52 | // hint (in the form of an inverse transform), or show that the |
| 53 | // transform hint has been ignored. |
| 54 | sp<GraphicBuffer> buf = mST->getCurrentBuffer(); |
| 55 | if (mST->getCurrentTransform() == NATIVE_WINDOW_TRANSFORM_ROT_270) { |
| 56 | ASSERT_EQ(texWidth, buf->getHeight()); |
| 57 | ASSERT_EQ(texHeight, buf->getWidth()); |
| 58 | } else { |
| 59 | ASSERT_EQ(texWidth, buf->getWidth()); |
| 60 | ASSERT_EQ(texHeight, buf->getHeight()); |
| 61 | } |
| 62 | |
| 63 | // Reset the transform hint and confirm that it takes. |
| 64 | mST->setTransformHint(0); |
| 65 | glClear(GL_COLOR_BUFFER_BIT); |
| 66 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 67 | mST->updateTexImage(); |
| 68 | glClear(GL_COLOR_BUFFER_BIT); |
| 69 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 70 | mST->updateTexImage(); |
| 71 | |
| 72 | buf = mST->getCurrentBuffer(); |
| 73 | ASSERT_EQ((uint32_t) 0, mST->getCurrentTransform()); |
| 74 | ASSERT_EQ(texWidth, buf->getWidth()); |
| 75 | ASSERT_EQ(texHeight, buf->getHeight()); |
| 76 | } |
| 77 | |
| 78 | TEST_F(SurfaceTextureGLToGLTest, TexturingFromGLFilledRGBABufferPow2) { |
| 79 | const int texWidth = 64; |
| 80 | const int texHeight = 64; |
| 81 | |
| 82 | mST->setDefaultBufferSize(texWidth, texHeight); |
| 83 | |
| 84 | // This test requires 3 buffers to complete run on a single thread. |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 85 | // Set max dequeued to 2, and max acquired already defaults to 1. |
| 86 | ASSERT_EQ(OK, mSTC->setMaxDequeuedBufferCount(2)); |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 87 | |
| 88 | // Do the producer side of things |
| 89 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface, |
| 90 | mProducerEglSurface, mProducerEglContext)); |
| 91 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 92 | |
| 93 | // This is needed to ensure we pick up a buffer of the correct size. |
| 94 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 95 | |
| 96 | glClearColor(0.6, 0.6, 0.6, 0.6); |
| 97 | glClear(GL_COLOR_BUFFER_BIT); |
| 98 | |
| 99 | glEnable(GL_SCISSOR_TEST); |
| 100 | glScissor(4, 4, 4, 4); |
| 101 | glClearColor(1.0, 0.0, 0.0, 1.0); |
| 102 | glClear(GL_COLOR_BUFFER_BIT); |
| 103 | |
| 104 | glScissor(24, 48, 4, 4); |
| 105 | glClearColor(0.0, 1.0, 0.0, 1.0); |
| 106 | glClear(GL_COLOR_BUFFER_BIT); |
| 107 | |
| 108 | glScissor(37, 17, 4, 4); |
| 109 | glClearColor(0.0, 0.0, 1.0, 1.0); |
| 110 | glClear(GL_COLOR_BUFFER_BIT); |
| 111 | |
| 112 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 113 | |
| 114 | // Do the consumer side of things |
| 115 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, |
| 116 | mEglContext)); |
| 117 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 118 | |
| 119 | glDisable(GL_SCISSOR_TEST); |
| 120 | |
| 121 | // Skip the first frame, which was empty |
| 122 | ASSERT_EQ(NO_ERROR, mST->updateTexImage()); |
| 123 | ASSERT_EQ(NO_ERROR, mST->updateTexImage()); |
| 124 | |
| 125 | glClearColor(0.2, 0.2, 0.2, 0.2); |
| 126 | glClear(GL_COLOR_BUFFER_BIT); |
| 127 | |
| 128 | glViewport(0, 0, texWidth, texHeight); |
| 129 | drawTexture(); |
| 130 | |
| 131 | EXPECT_TRUE(checkPixel( 0, 0, 153, 153, 153, 153)); |
| 132 | EXPECT_TRUE(checkPixel(63, 0, 153, 153, 153, 153)); |
| 133 | EXPECT_TRUE(checkPixel(63, 63, 153, 153, 153, 153)); |
| 134 | EXPECT_TRUE(checkPixel( 0, 63, 153, 153, 153, 153)); |
| 135 | |
| 136 | EXPECT_TRUE(checkPixel( 4, 7, 255, 0, 0, 255)); |
| 137 | EXPECT_TRUE(checkPixel(25, 51, 0, 255, 0, 255)); |
| 138 | EXPECT_TRUE(checkPixel(40, 19, 0, 0, 255, 255)); |
| 139 | EXPECT_TRUE(checkPixel(29, 51, 153, 153, 153, 153)); |
| 140 | EXPECT_TRUE(checkPixel( 5, 32, 153, 153, 153, 153)); |
| 141 | EXPECT_TRUE(checkPixel(13, 8, 153, 153, 153, 153)); |
| 142 | EXPECT_TRUE(checkPixel(46, 3, 153, 153, 153, 153)); |
| 143 | EXPECT_TRUE(checkPixel(30, 33, 153, 153, 153, 153)); |
| 144 | EXPECT_TRUE(checkPixel( 6, 52, 153, 153, 153, 153)); |
| 145 | EXPECT_TRUE(checkPixel(55, 33, 153, 153, 153, 153)); |
| 146 | EXPECT_TRUE(checkPixel(16, 29, 153, 153, 153, 153)); |
| 147 | EXPECT_TRUE(checkPixel( 1, 30, 153, 153, 153, 153)); |
| 148 | EXPECT_TRUE(checkPixel(41, 37, 153, 153, 153, 153)); |
| 149 | EXPECT_TRUE(checkPixel(46, 29, 153, 153, 153, 153)); |
| 150 | EXPECT_TRUE(checkPixel(15, 25, 153, 153, 153, 153)); |
| 151 | EXPECT_TRUE(checkPixel( 3, 52, 153, 153, 153, 153)); |
| 152 | } |
| 153 | |
| 154 | TEST_F(SurfaceTextureGLToGLTest, EglDestroySurfaceUnrefsBuffers) { |
| 155 | sp<GraphicBuffer> buffers[2]; |
| 156 | |
| 157 | // This test requires async mode to run on a single thread. |
| 158 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface, |
| 159 | mProducerEglSurface, mProducerEglContext)); |
| 160 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 161 | EXPECT_TRUE(eglSwapInterval(mEglDisplay, 0)); |
| 162 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 163 | |
| 164 | for (int i = 0; i < 2; i++) { |
| 165 | // Produce a frame |
| 166 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface, |
| 167 | mProducerEglSurface, mProducerEglContext)); |
| 168 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 169 | glClear(GL_COLOR_BUFFER_BIT); |
| 170 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 171 | |
| 172 | // Consume a frame |
| 173 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, |
| 174 | mEglContext)); |
| 175 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 176 | mFW->waitForFrame(); |
| 177 | ASSERT_EQ(NO_ERROR, mST->updateTexImage()); |
| 178 | buffers[i] = mST->getCurrentBuffer(); |
| 179 | } |
| 180 | |
| 181 | // Destroy the GL texture object to release its ref on buffers[2]. |
| 182 | GLuint texID = TEX_ID; |
| 183 | glDeleteTextures(1, &texID); |
| 184 | |
| 185 | // Destroy the EGLSurface |
| 186 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, mProducerEglSurface)); |
| 187 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 188 | mProducerEglSurface = EGL_NO_SURFACE; |
| 189 | |
| 190 | // This test should have the only reference to buffer 0. |
| 191 | EXPECT_EQ(1, buffers[0]->getStrongCount()); |
| 192 | |
Michael Lentine | d8ead0c | 2015-05-19 15:23:43 -0700 | [diff] [blame] | 193 | // The GLConsumer should hold one reference to buffer 1 in its |
| 194 | // mCurrentTextureImage member and another reference in mEglSlots. The third |
| 195 | // reference is in this test. |
| 196 | EXPECT_EQ(3, buffers[1]->getStrongCount()); |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | TEST_F(SurfaceTextureGLToGLTest, EglDestroySurfaceAfterAbandonUnrefsBuffers) { |
| 200 | sp<GraphicBuffer> buffers[3]; |
| 201 | |
| 202 | // This test requires async mode to run on a single thread. |
| 203 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface, |
| 204 | mProducerEglSurface, mProducerEglContext)); |
| 205 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 206 | EXPECT_TRUE(eglSwapInterval(mEglDisplay, 0)); |
| 207 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 208 | |
| 209 | for (int i = 0; i < 3; i++) { |
| 210 | // Produce a frame |
| 211 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface, |
| 212 | mProducerEglSurface, mProducerEglContext)); |
| 213 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 214 | glClear(GL_COLOR_BUFFER_BIT); |
| 215 | EXPECT_TRUE(eglSwapBuffers(mEglDisplay, mProducerEglSurface)); |
| 216 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 217 | |
| 218 | // Consume a frame |
| 219 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, |
| 220 | mEglContext)); |
| 221 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 222 | mFW->waitForFrame(); |
| 223 | ASSERT_EQ(NO_ERROR, mST->updateTexImage()); |
| 224 | buffers[i] = mST->getCurrentBuffer(); |
| 225 | } |
| 226 | |
| 227 | // Abandon the GLConsumer, releasing the ref that the GLConsumer has |
| 228 | // on buffers[2]. |
| 229 | mST->abandon(); |
| 230 | |
| 231 | // Destroy the GL texture object to release its ref on buffers[2]. |
| 232 | GLuint texID = TEX_ID; |
| 233 | glDeleteTextures(1, &texID); |
| 234 | |
| 235 | // Destroy the EGLSurface. |
| 236 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, mProducerEglSurface)); |
| 237 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 238 | mProducerEglSurface = EGL_NO_SURFACE; |
| 239 | |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 240 | EXPECT_EQ(1, buffers[1]->getStrongCount()); |
| 241 | |
| 242 | // Depending on how lazily the GL driver dequeues buffers, we may end up |
Michael Lentine | d8ead0c | 2015-05-19 15:23:43 -0700 | [diff] [blame] | 243 | // with either two or three total buffers. If there are three, each entry |
| 244 | // of the buffers array will be unique and there should only be one |
| 245 | // reference (the one in this test). If there are two the first and last |
| 246 | // element in the array will be equal meaning that buffer representing both |
| 247 | // 0 and 2 will have two references (one for 0 and one for 2). |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 248 | if (buffers[2] != buffers[0]) { |
Michael Lentine | d8ead0c | 2015-05-19 15:23:43 -0700 | [diff] [blame] | 249 | EXPECT_EQ(1, buffers[0]->getStrongCount()); |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 250 | EXPECT_EQ(1, buffers[2]->getStrongCount()); |
Michael Lentine | d8ead0c | 2015-05-19 15:23:43 -0700 | [diff] [blame] | 251 | } else { |
| 252 | EXPECT_EQ(2, buffers[0]->getStrongCount()); |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 253 | } |
| 254 | } |
| 255 | |
| 256 | TEST_F(SurfaceTextureGLToGLTest, EglMakeCurrentBeforeConsumerDeathUnrefsBuffers) { |
| 257 | sp<GraphicBuffer> buffer; |
| 258 | |
| 259 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface, |
| 260 | mProducerEglSurface, mProducerEglContext)); |
| 261 | |
| 262 | // Produce a frame |
| 263 | glClear(GL_COLOR_BUFFER_BIT); |
| 264 | EXPECT_TRUE(eglSwapBuffers(mEglDisplay, mProducerEglSurface)); |
| 265 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 266 | |
| 267 | // Destroy the EGLSurface. |
| 268 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, mProducerEglSurface)); |
| 269 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 270 | mProducerEglSurface = EGL_NO_SURFACE; |
| 271 | mSTC.clear(); |
| 272 | mANW.clear(); |
| 273 | mTextureRenderer.clear(); |
| 274 | |
| 275 | // Consume a frame |
| 276 | ASSERT_EQ(NO_ERROR, mST->updateTexImage()); |
| 277 | buffer = mST->getCurrentBuffer(); |
| 278 | |
| 279 | // Destroy the GL texture object to release its ref |
| 280 | GLuint texID = TEX_ID; |
| 281 | glDeleteTextures(1, &texID); |
| 282 | |
| 283 | // make un-current, all references to buffer should be gone |
| 284 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, |
| 285 | EGL_NO_SURFACE, EGL_NO_CONTEXT)); |
| 286 | |
| 287 | // Destroy consumer |
| 288 | mST.clear(); |
| 289 | |
| 290 | EXPECT_EQ(1, buffer->getStrongCount()); |
| 291 | } |
| 292 | |
| 293 | TEST_F(SurfaceTextureGLToGLTest, EglMakeCurrentAfterConsumerDeathUnrefsBuffers) { |
| 294 | sp<GraphicBuffer> buffer; |
| 295 | |
| 296 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface, |
| 297 | mProducerEglSurface, mProducerEglContext)); |
| 298 | |
| 299 | // Produce a frame |
| 300 | glClear(GL_COLOR_BUFFER_BIT); |
| 301 | EXPECT_TRUE(eglSwapBuffers(mEglDisplay, mProducerEglSurface)); |
| 302 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 303 | |
| 304 | // Destroy the EGLSurface. |
| 305 | EXPECT_TRUE(eglDestroySurface(mEglDisplay, mProducerEglSurface)); |
| 306 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 307 | mProducerEglSurface = EGL_NO_SURFACE; |
| 308 | mSTC.clear(); |
| 309 | mANW.clear(); |
| 310 | mTextureRenderer.clear(); |
| 311 | |
| 312 | // Consume a frame |
| 313 | ASSERT_EQ(NO_ERROR, mST->updateTexImage()); |
| 314 | buffer = mST->getCurrentBuffer(); |
| 315 | |
| 316 | // Destroy the GL texture object to release its ref |
| 317 | GLuint texID = TEX_ID; |
| 318 | glDeleteTextures(1, &texID); |
| 319 | |
| 320 | // Destroy consumer |
| 321 | mST.clear(); |
| 322 | |
| 323 | // make un-current, all references to buffer should be gone |
| 324 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE, |
| 325 | EGL_NO_SURFACE, EGL_NO_CONTEXT)); |
| 326 | |
| 327 | EXPECT_EQ(1, buffer->getStrongCount()); |
| 328 | } |
| 329 | |
| 330 | TEST_F(SurfaceTextureGLToGLTest, TexturingFromUserSizedGLFilledBuffer) { |
| 331 | enum { texWidth = 64 }; |
| 332 | enum { texHeight = 64 }; |
| 333 | |
| 334 | // This test requires 3 buffers to complete run on a single thread. |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 335 | // Set max dequeued to 2, and max acquired already defaults to 1. |
| 336 | ASSERT_EQ(OK, mSTC->setMaxDequeuedBufferCount(2)); |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 337 | |
| 338 | // Set the user buffer size. |
| 339 | native_window_set_buffers_user_dimensions(mANW.get(), texWidth, texHeight); |
| 340 | |
| 341 | // Do the producer side of things |
| 342 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface, |
| 343 | mProducerEglSurface, mProducerEglContext)); |
| 344 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 345 | |
| 346 | // This is needed to ensure we pick up a buffer of the correct size. |
| 347 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 348 | |
| 349 | glClearColor(0.6, 0.6, 0.6, 0.6); |
| 350 | glClear(GL_COLOR_BUFFER_BIT); |
| 351 | |
| 352 | glEnable(GL_SCISSOR_TEST); |
| 353 | glScissor(4, 4, 1, 1); |
| 354 | glClearColor(1.0, 0.0, 0.0, 1.0); |
| 355 | glClear(GL_COLOR_BUFFER_BIT); |
| 356 | |
| 357 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 358 | |
| 359 | // Do the consumer side of things |
| 360 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, |
| 361 | mEglContext)); |
| 362 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 363 | |
| 364 | glDisable(GL_SCISSOR_TEST); |
| 365 | |
| 366 | // Skip the first frame, which was empty |
| 367 | ASSERT_EQ(NO_ERROR, mST->updateTexImage()); |
| 368 | ASSERT_EQ(NO_ERROR, mST->updateTexImage()); |
| 369 | |
| 370 | glClearColor(0.2, 0.2, 0.2, 0.2); |
| 371 | glClear(GL_COLOR_BUFFER_BIT); |
| 372 | |
| 373 | glViewport(0, 0, texWidth, texHeight); |
| 374 | drawTexture(); |
| 375 | |
| 376 | EXPECT_TRUE(checkPixel( 0, 0, 153, 153, 153, 153)); |
| 377 | EXPECT_TRUE(checkPixel(63, 0, 153, 153, 153, 153)); |
| 378 | EXPECT_TRUE(checkPixel(63, 63, 153, 153, 153, 153)); |
| 379 | EXPECT_TRUE(checkPixel( 0, 63, 153, 153, 153, 153)); |
| 380 | |
| 381 | EXPECT_TRUE(checkPixel( 4, 4, 255, 0, 0, 255)); |
| 382 | EXPECT_TRUE(checkPixel( 5, 5, 153, 153, 153, 153)); |
| 383 | EXPECT_TRUE(checkPixel( 3, 3, 153, 153, 153, 153)); |
| 384 | EXPECT_TRUE(checkPixel(45, 52, 153, 153, 153, 153)); |
| 385 | EXPECT_TRUE(checkPixel(12, 36, 153, 153, 153, 153)); |
| 386 | } |
| 387 | |
| 388 | TEST_F(SurfaceTextureGLToGLTest, TexturingFromPreRotatedUserSizedGLFilledBuffer) { |
| 389 | enum { texWidth = 64 }; |
| 390 | enum { texHeight = 16 }; |
| 391 | |
| 392 | // This test requires 3 buffers to complete run on a single thread. |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 393 | // Set max dequeued to 2, and max acquired already defaults to 1. |
| 394 | ASSERT_EQ(OK, mSTC->setMaxDequeuedBufferCount(2)); |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 395 | |
| 396 | // Set the transform hint. |
| 397 | mST->setTransformHint(NATIVE_WINDOW_TRANSFORM_ROT_90); |
| 398 | |
| 399 | // Set the user buffer size. |
| 400 | native_window_set_buffers_user_dimensions(mANW.get(), texWidth, texHeight); |
| 401 | |
| 402 | // Do the producer side of things |
| 403 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface, |
| 404 | mProducerEglSurface, mProducerEglContext)); |
| 405 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 406 | |
| 407 | // This is needed to ensure we pick up a buffer of the correct size and the |
| 408 | // new rotation hint. |
| 409 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 410 | |
| 411 | glClearColor(0.6, 0.6, 0.6, 0.6); |
| 412 | glClear(GL_COLOR_BUFFER_BIT); |
| 413 | |
| 414 | glEnable(GL_SCISSOR_TEST); |
| 415 | glScissor(24, 4, 1, 1); |
| 416 | glClearColor(1.0, 0.0, 0.0, 1.0); |
| 417 | glClear(GL_COLOR_BUFFER_BIT); |
| 418 | |
| 419 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 420 | |
| 421 | // Do the consumer side of things |
| 422 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, |
| 423 | mEglContext)); |
| 424 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 425 | |
| 426 | glDisable(GL_SCISSOR_TEST); |
| 427 | |
| 428 | // Skip the first frame, which was empty |
| 429 | ASSERT_EQ(NO_ERROR, mST->updateTexImage()); |
| 430 | ASSERT_EQ(NO_ERROR, mST->updateTexImage()); |
| 431 | |
| 432 | glClearColor(0.2, 0.2, 0.2, 0.2); |
| 433 | glClear(GL_COLOR_BUFFER_BIT); |
| 434 | |
| 435 | glViewport(0, 0, texWidth, texHeight); |
| 436 | drawTexture(); |
| 437 | |
| 438 | EXPECT_TRUE(checkPixel( 0, 0, 153, 153, 153, 153)); |
| 439 | EXPECT_TRUE(checkPixel(63, 0, 153, 153, 153, 153)); |
| 440 | EXPECT_TRUE(checkPixel(63, 15, 153, 153, 153, 153)); |
| 441 | EXPECT_TRUE(checkPixel( 0, 15, 153, 153, 153, 153)); |
| 442 | |
| 443 | EXPECT_TRUE(checkPixel(24, 4, 255, 0, 0, 255)); |
| 444 | EXPECT_TRUE(checkPixel(25, 5, 153, 153, 153, 153)); |
| 445 | EXPECT_TRUE(checkPixel(23, 3, 153, 153, 153, 153)); |
| 446 | EXPECT_TRUE(checkPixel(45, 13, 153, 153, 153, 153)); |
| 447 | EXPECT_TRUE(checkPixel(12, 8, 153, 153, 153, 153)); |
| 448 | } |
| 449 | |
| 450 | TEST_F(SurfaceTextureGLToGLTest, TexturingFromPreRotatedGLFilledBuffer) { |
| 451 | enum { texWidth = 64 }; |
| 452 | enum { texHeight = 16 }; |
| 453 | |
| 454 | // This test requires 3 buffers to complete run on a single thread. |
Pablo Ceballos | 19e3e06 | 2015-08-19 16:16:06 -0700 | [diff] [blame] | 455 | // Set max dequeued to 2, and max acquired already defaults to 1. |
| 456 | ASSERT_EQ(OK, mSTC->setMaxDequeuedBufferCount(2)); |
Dan Stoza | cb1fcde | 2013-12-03 12:37:36 -0800 | [diff] [blame] | 457 | |
| 458 | // Set the transform hint. |
| 459 | mST->setTransformHint(NATIVE_WINDOW_TRANSFORM_ROT_90); |
| 460 | |
| 461 | // Set the default buffer size. |
| 462 | mST->setDefaultBufferSize(texWidth, texHeight); |
| 463 | |
| 464 | // Do the producer side of things |
| 465 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface, |
| 466 | mProducerEglSurface, mProducerEglContext)); |
| 467 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 468 | |
| 469 | // This is needed to ensure we pick up a buffer of the correct size and the |
| 470 | // new rotation hint. |
| 471 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 472 | |
| 473 | glClearColor(0.6, 0.6, 0.6, 0.6); |
| 474 | glClear(GL_COLOR_BUFFER_BIT); |
| 475 | |
| 476 | glEnable(GL_SCISSOR_TEST); |
| 477 | glScissor(24, 4, 1, 1); |
| 478 | glClearColor(1.0, 0.0, 0.0, 1.0); |
| 479 | glClear(GL_COLOR_BUFFER_BIT); |
| 480 | |
| 481 | eglSwapBuffers(mEglDisplay, mProducerEglSurface); |
| 482 | |
| 483 | // Do the consumer side of things |
| 484 | EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface, |
| 485 | mEglContext)); |
| 486 | ASSERT_EQ(EGL_SUCCESS, eglGetError()); |
| 487 | |
| 488 | glDisable(GL_SCISSOR_TEST); |
| 489 | |
| 490 | // Skip the first frame, which was empty |
| 491 | ASSERT_EQ(NO_ERROR, mST->updateTexImage()); |
| 492 | ASSERT_EQ(NO_ERROR, mST->updateTexImage()); |
| 493 | |
| 494 | glClearColor(0.2, 0.2, 0.2, 0.2); |
| 495 | glClear(GL_COLOR_BUFFER_BIT); |
| 496 | |
| 497 | glViewport(0, 0, texWidth, texHeight); |
| 498 | drawTexture(); |
| 499 | |
| 500 | EXPECT_TRUE(checkPixel( 0, 0, 153, 153, 153, 153)); |
| 501 | EXPECT_TRUE(checkPixel(63, 0, 153, 153, 153, 153)); |
| 502 | EXPECT_TRUE(checkPixel(63, 15, 153, 153, 153, 153)); |
| 503 | EXPECT_TRUE(checkPixel( 0, 15, 153, 153, 153, 153)); |
| 504 | |
| 505 | EXPECT_TRUE(checkPixel(24, 4, 255, 0, 0, 255)); |
| 506 | EXPECT_TRUE(checkPixel(25, 5, 153, 153, 153, 153)); |
| 507 | EXPECT_TRUE(checkPixel(23, 3, 153, 153, 153, 153)); |
| 508 | EXPECT_TRUE(checkPixel(45, 13, 153, 153, 153, 153)); |
| 509 | EXPECT_TRUE(checkPixel(12, 8, 153, 153, 153, 153)); |
| 510 | } |
| 511 | |
| 512 | } // namespace android |