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