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
TEST_F(SurfaceTextureGLToGLTest,TransformHintGetsRespected)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
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));
35
36 SetUpWindowAndContext();
37
38 // 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
TEST_F(SurfaceTextureGLToGLTest,TexturingFromGLFilledRGBABufferPow2)80 TEST_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.
87 // Set max dequeued to 2, and max acquired already defaults to 1.
88 ASSERT_EQ(OK, mSTC->setMaxDequeuedBufferCount(2));
89
90 SetUpWindowAndContext();
91
92 // 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
TEST_F(SurfaceTextureGLToGLTest,EglDestroySurfaceUnrefsBuffers)158 TEST_F(SurfaceTextureGLToGLTest, EglDestroySurfaceUnrefsBuffers) {
159 SetUpWindowAndContext();
160 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
195 // This test should have the only reference to buffer 0.
196 EXPECT_EQ(1, buffers[0]->getStrongCount());
197
198 // The GLConsumer should hold one reference to buffer 1 in its
199 // mCurrentTextureImage member and another reference in mEglSlots. The third
200 // reference is in this test.
201 EXPECT_EQ(3, buffers[1]->getStrongCount());
202 }
203
TEST_F(SurfaceTextureGLToGLTest,EglDestroySurfaceAfterAbandonUnrefsBuffers)204 TEST_F(SurfaceTextureGLToGLTest, EglDestroySurfaceAfterAbandonUnrefsBuffers) {
205 SetUpWindowAndContext();
206 sp<GraphicBuffer> buffers[3];
207
208 // This test requires async mode to run on a single thread.
209 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
210 mProducerEglSurface, mProducerEglContext));
211 ASSERT_EQ(EGL_SUCCESS, eglGetError());
212 EXPECT_TRUE(eglSwapInterval(mEglDisplay, 0));
213 ASSERT_EQ(EGL_SUCCESS, eglGetError());
214
215 for (int i = 0; i < 3; i++) {
216 // Produce a frame
217 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
218 mProducerEglSurface, mProducerEglContext));
219 ASSERT_EQ(EGL_SUCCESS, eglGetError());
220 glClear(GL_COLOR_BUFFER_BIT);
221 EXPECT_TRUE(eglSwapBuffers(mEglDisplay, mProducerEglSurface));
222 ASSERT_EQ(EGL_SUCCESS, eglGetError());
223
224 // Consume a frame
225 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
226 mEglContext));
227 ASSERT_EQ(EGL_SUCCESS, eglGetError());
228 mFW->waitForFrame();
229 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
230 buffers[i] = mST->getCurrentBuffer();
231 }
232
233 // Abandon the GLConsumer, releasing the ref that the GLConsumer has
234 // on buffers[2].
235 mST->abandon();
236
237 // Destroy the GL texture object to release its ref on buffers[2].
238 GLuint texID = TEX_ID;
239 glDeleteTextures(1, &texID);
240
241 // Destroy the EGLSurface.
242 EXPECT_TRUE(eglDestroySurface(mEglDisplay, mProducerEglSurface));
243 ASSERT_EQ(EGL_SUCCESS, eglGetError());
244 mProducerEglSurface = EGL_NO_SURFACE;
245
246 EXPECT_EQ(1, buffers[1]->getStrongCount());
247
248 // Depending on how lazily the GL driver dequeues buffers, we may end up
249 // with either two or three total buffers. If there are three, each entry
250 // of the buffers array will be unique and there should only be one
251 // reference (the one in this test). If there are two the first and last
252 // element in the array will be equal meaning that buffer representing both
253 // 0 and 2 will have two references (one for 0 and one for 2).
254 if (buffers[2] != buffers[0]) {
255 EXPECT_EQ(1, buffers[0]->getStrongCount());
256 EXPECT_EQ(1, buffers[2]->getStrongCount());
257 } else {
258 EXPECT_EQ(2, buffers[0]->getStrongCount());
259 }
260 }
261
TEST_F(SurfaceTextureGLToGLTest,EglMakeCurrentBeforeConsumerDeathUnrefsBuffers)262 TEST_F(SurfaceTextureGLToGLTest, EglMakeCurrentBeforeConsumerDeathUnrefsBuffers) {
263 SetUpWindowAndContext();
264 sp<GraphicBuffer> buffer;
265
266 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
267 mProducerEglSurface, mProducerEglContext));
268
269 // Produce a frame
270 glClear(GL_COLOR_BUFFER_BIT);
271 EXPECT_TRUE(eglSwapBuffers(mEglDisplay, mProducerEglSurface));
272 ASSERT_EQ(EGL_SUCCESS, eglGetError());
273
274 // Destroy the EGLSurface.
275 EXPECT_TRUE(eglDestroySurface(mEglDisplay, mProducerEglSurface));
276 ASSERT_EQ(EGL_SUCCESS, eglGetError());
277 mProducerEglSurface = EGL_NO_SURFACE;
278 mSTC.clear();
279 mANW.clear();
280 mTextureRenderer.clear();
281
282 // Consume a frame
283 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
284 buffer = mST->getCurrentBuffer();
285
286 // Destroy the GL texture object to release its ref
287 GLuint texID = TEX_ID;
288 glDeleteTextures(1, &texID);
289
290 // make un-current, all references to buffer should be gone
291 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE,
292 EGL_NO_SURFACE, EGL_NO_CONTEXT));
293
294 // Destroy consumer
295 mST.clear();
296
297 EXPECT_EQ(1, buffer->getStrongCount());
298 }
299
TEST_F(SurfaceTextureGLToGLTest,EglMakeCurrentAfterConsumerDeathUnrefsBuffers)300 TEST_F(SurfaceTextureGLToGLTest, EglMakeCurrentAfterConsumerDeathUnrefsBuffers) {
301 SetUpWindowAndContext();
302 sp<GraphicBuffer> buffer;
303
304 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
305 mProducerEglSurface, mProducerEglContext));
306
307 // Produce a frame
308 glClear(GL_COLOR_BUFFER_BIT);
309 EXPECT_TRUE(eglSwapBuffers(mEglDisplay, mProducerEglSurface));
310 ASSERT_EQ(EGL_SUCCESS, eglGetError());
311
312 // Destroy the EGLSurface.
313 EXPECT_TRUE(eglDestroySurface(mEglDisplay, mProducerEglSurface));
314 ASSERT_EQ(EGL_SUCCESS, eglGetError());
315 mProducerEglSurface = EGL_NO_SURFACE;
316 mSTC.clear();
317 mANW.clear();
318 mTextureRenderer.clear();
319
320 // Consume a frame
321 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
322 buffer = mST->getCurrentBuffer();
323
324 // Destroy the GL texture object to release its ref
325 GLuint texID = TEX_ID;
326 glDeleteTextures(1, &texID);
327
328 // Destroy consumer
329 mST.clear();
330
331 // make un-current, all references to buffer should be gone
332 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, EGL_NO_SURFACE,
333 EGL_NO_SURFACE, EGL_NO_CONTEXT));
334
335 EXPECT_EQ(1, buffer->getStrongCount());
336 }
337
TEST_F(SurfaceTextureGLToGLTest,TexturingFromUserSizedGLFilledBuffer)338 TEST_F(SurfaceTextureGLToGLTest, TexturingFromUserSizedGLFilledBuffer) {
339 enum { texWidth = 64 };
340 enum { texHeight = 64 };
341
342 // This test requires 3 buffers to complete run on a single thread.
343 // Set max dequeued to 2, and max acquired already defaults to 1.
344 ASSERT_EQ(OK, mSTC->setMaxDequeuedBufferCount(2));
345
346 SetUpWindowAndContext();
347
348 // Set the user buffer size.
349 native_window_set_buffers_user_dimensions(mANW.get(), texWidth, texHeight);
350
351 // Do the producer side of things
352 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
353 mProducerEglSurface, mProducerEglContext));
354 ASSERT_EQ(EGL_SUCCESS, eglGetError());
355
356 // This is needed to ensure we pick up a buffer of the correct size.
357 eglSwapBuffers(mEglDisplay, mProducerEglSurface);
358
359 glClearColor(0.6, 0.6, 0.6, 0.6);
360 glClear(GL_COLOR_BUFFER_BIT);
361
362 glEnable(GL_SCISSOR_TEST);
363 glScissor(4, 4, 1, 1);
364 glClearColor(1.0, 0.0, 0.0, 1.0);
365 glClear(GL_COLOR_BUFFER_BIT);
366
367 eglSwapBuffers(mEglDisplay, mProducerEglSurface);
368
369 // Do the consumer side of things
370 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
371 mEglContext));
372 ASSERT_EQ(EGL_SUCCESS, eglGetError());
373
374 glDisable(GL_SCISSOR_TEST);
375
376 // Skip the first frame, which was empty
377 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
378 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
379
380 glClearColor(0.2, 0.2, 0.2, 0.2);
381 glClear(GL_COLOR_BUFFER_BIT);
382
383 glViewport(0, 0, texWidth, texHeight);
384 drawTexture();
385
386 EXPECT_TRUE(checkPixel( 0, 0, 153, 153, 153, 153));
387 EXPECT_TRUE(checkPixel(63, 0, 153, 153, 153, 153));
388 EXPECT_TRUE(checkPixel(63, 63, 153, 153, 153, 153));
389 EXPECT_TRUE(checkPixel( 0, 63, 153, 153, 153, 153));
390
391 EXPECT_TRUE(checkPixel( 4, 4, 255, 0, 0, 255));
392 EXPECT_TRUE(checkPixel( 5, 5, 153, 153, 153, 153));
393 EXPECT_TRUE(checkPixel( 3, 3, 153, 153, 153, 153));
394 EXPECT_TRUE(checkPixel(45, 52, 153, 153, 153, 153));
395 EXPECT_TRUE(checkPixel(12, 36, 153, 153, 153, 153));
396 }
397
TEST_F(SurfaceTextureGLToGLTest,TexturingFromPreRotatedUserSizedGLFilledBuffer)398 TEST_F(SurfaceTextureGLToGLTest, TexturingFromPreRotatedUserSizedGLFilledBuffer) {
399 enum { texWidth = 64 };
400 enum { texHeight = 16 };
401
402 // This test requires 3 buffers to complete run on a single thread.
403 // Set max dequeued to 2, and max acquired already defaults to 1.
404 ASSERT_EQ(OK, mSTC->setMaxDequeuedBufferCount(2));
405
406 SetUpWindowAndContext();
407
408 // Set the transform hint.
409 mST->setTransformHint(NATIVE_WINDOW_TRANSFORM_ROT_90);
410
411 // Set the user buffer size.
412 native_window_set_buffers_user_dimensions(mANW.get(), texWidth, texHeight);
413
414 // Do the producer side of things
415 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
416 mProducerEglSurface, mProducerEglContext));
417 ASSERT_EQ(EGL_SUCCESS, eglGetError());
418
419 // This is needed to ensure we pick up a buffer of the correct size and the
420 // new rotation hint.
421 eglSwapBuffers(mEglDisplay, mProducerEglSurface);
422
423 glClearColor(0.6, 0.6, 0.6, 0.6);
424 glClear(GL_COLOR_BUFFER_BIT);
425
426 glEnable(GL_SCISSOR_TEST);
427 glScissor(24, 4, 1, 1);
428 glClearColor(1.0, 0.0, 0.0, 1.0);
429 glClear(GL_COLOR_BUFFER_BIT);
430
431 eglSwapBuffers(mEglDisplay, mProducerEglSurface);
432
433 // Do the consumer side of things
434 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
435 mEglContext));
436 ASSERT_EQ(EGL_SUCCESS, eglGetError());
437
438 glDisable(GL_SCISSOR_TEST);
439
440 // Skip the first frame, which was empty
441 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
442 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
443
444 glClearColor(0.2, 0.2, 0.2, 0.2);
445 glClear(GL_COLOR_BUFFER_BIT);
446
447 glViewport(0, 0, texWidth, texHeight);
448 drawTexture();
449
450 EXPECT_TRUE(checkPixel( 0, 0, 153, 153, 153, 153));
451 EXPECT_TRUE(checkPixel(63, 0, 153, 153, 153, 153));
452 EXPECT_TRUE(checkPixel(63, 15, 153, 153, 153, 153));
453 EXPECT_TRUE(checkPixel( 0, 15, 153, 153, 153, 153));
454
455 EXPECT_TRUE(checkPixel(24, 4, 255, 0, 0, 255));
456 EXPECT_TRUE(checkPixel(25, 5, 153, 153, 153, 153));
457 EXPECT_TRUE(checkPixel(23, 3, 153, 153, 153, 153));
458 EXPECT_TRUE(checkPixel(45, 13, 153, 153, 153, 153));
459 EXPECT_TRUE(checkPixel(12, 8, 153, 153, 153, 153));
460 }
461
TEST_F(SurfaceTextureGLToGLTest,TexturingFromPreRotatedGLFilledBuffer)462 TEST_F(SurfaceTextureGLToGLTest, TexturingFromPreRotatedGLFilledBuffer) {
463 enum { texWidth = 64 };
464 enum { texHeight = 16 };
465
466 // This test requires 3 buffers to complete run on a single thread.
467 // Set max dequeued to 2, and max acquired already defaults to 1.
468 ASSERT_EQ(OK, mSTC->setMaxDequeuedBufferCount(2));
469
470 SetUpWindowAndContext();
471
472 // Set the transform hint.
473 mST->setTransformHint(NATIVE_WINDOW_TRANSFORM_ROT_90);
474
475 // Set the default buffer size.
476 mST->setDefaultBufferSize(texWidth, texHeight);
477
478 // Do the producer side of things
479 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mProducerEglSurface,
480 mProducerEglSurface, mProducerEglContext));
481 ASSERT_EQ(EGL_SUCCESS, eglGetError());
482
483 // This is needed to ensure we pick up a buffer of the correct size and the
484 // new rotation hint.
485 eglSwapBuffers(mEglDisplay, mProducerEglSurface);
486
487 glClearColor(0.6, 0.6, 0.6, 0.6);
488 glClear(GL_COLOR_BUFFER_BIT);
489
490 glEnable(GL_SCISSOR_TEST);
491 glScissor(24, 4, 1, 1);
492 glClearColor(1.0, 0.0, 0.0, 1.0);
493 glClear(GL_COLOR_BUFFER_BIT);
494
495 eglSwapBuffers(mEglDisplay, mProducerEglSurface);
496
497 // Do the consumer side of things
498 EXPECT_TRUE(eglMakeCurrent(mEglDisplay, mEglSurface, mEglSurface,
499 mEglContext));
500 ASSERT_EQ(EGL_SUCCESS, eglGetError());
501
502 glDisable(GL_SCISSOR_TEST);
503
504 // Skip the first frame, which was empty
505 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
506 ASSERT_EQ(NO_ERROR, mST->updateTexImage());
507
508 glClearColor(0.2, 0.2, 0.2, 0.2);
509 glClear(GL_COLOR_BUFFER_BIT);
510
511 glViewport(0, 0, texWidth, texHeight);
512 drawTexture();
513
514 EXPECT_TRUE(checkPixel( 0, 0, 153, 153, 153, 153));
515 EXPECT_TRUE(checkPixel(63, 0, 153, 153, 153, 153));
516 EXPECT_TRUE(checkPixel(63, 15, 153, 153, 153, 153));
517 EXPECT_TRUE(checkPixel( 0, 15, 153, 153, 153, 153));
518
519 EXPECT_TRUE(checkPixel(24, 4, 255, 0, 0, 255));
520 EXPECT_TRUE(checkPixel(25, 5, 153, 153, 153, 153));
521 EXPECT_TRUE(checkPixel(23, 3, 153, 153, 153, 153));
522 EXPECT_TRUE(checkPixel(45, 13, 153, 153, 153, 153));
523 EXPECT_TRUE(checkPixel(12, 8, 153, 153, 153, 153));
524 }
525
526 } // namespace android
527