1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
7 #include "base/atomicops.h"
8 #include "gpu/command_buffer/common/gles2_cmd_format.h"
9 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
10 #include "gpu/command_buffer/common/id_allocator.h"
11 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
13 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
14 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
15 #include "gpu/command_buffer/service/context_group.h"
16 #include "gpu/command_buffer/service/gl_surface_mock.h"
17 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h"
18 #include "gpu/command_buffer/service/image_manager.h"
19 #include "gpu/command_buffer/service/mailbox_manager.h"
20 #include "gpu/command_buffer/service/mocks.h"
21 #include "gpu/command_buffer/service/program_manager.h"
22 #include "gpu/command_buffer/service/stream_texture_manager_mock.h"
23 #include "gpu/command_buffer/service/stream_texture_mock.h"
24 #include "gpu/command_buffer/service/test_helper.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/gl/gl_implementation.h"
27 #include "ui/gl/gl_mock.h"
28 #include "ui/gl/gl_surface_stub.h"
31 #if !defined(GL_DEPTH24_STENCIL8)
32 #define GL_DEPTH24_STENCIL8 0x88F0
35 using ::gfx::MockGLInterface;
37 using ::testing::DoAll;
38 using ::testing::InSequence;
39 using ::testing::Invoke;
40 using ::testing::MatcherCast;
41 using ::testing::Pointee;
42 using ::testing::Return;
43 using ::testing::SaveArg;
44 using ::testing::SetArrayArgument;
45 using ::testing::SetArgumentPointee;
46 using ::testing::SetArgPointee;
47 using ::testing::StrEq;
48 using ::testing::StrictMock;
55 class GLES2DecoderTest : public GLES2DecoderTestBase {
57 GLES2DecoderTest() { }
60 void CheckReadPixelsOutOfRange(
61 GLint in_read_x, GLint in_read_y,
62 GLsizei in_read_width, GLsizei in_read_height,
66 class GLES2DecoderANGLETest : public GLES2DecoderTestBase {
68 GLES2DecoderANGLETest()
69 : GLES2DecoderTestBase() {
70 GLES2Decoder::set_testing_force_is_angle(true);
73 virtual ~GLES2DecoderANGLETest() {
74 GLES2Decoder::set_testing_force_is_angle(false);
78 class GLES2DecoderWithShaderTest : public GLES2DecoderWithShaderTestBase {
80 GLES2DecoderWithShaderTest()
81 : GLES2DecoderWithShaderTestBase() {
84 void CheckTextureChangesMarkFBOAsNotComplete(bool bound_fbo);
85 void CheckRenderbufferChangesMarkFBOAsNotComplete(bool bound_fbo);
88 class GLES2DecoderGeometryInstancingTest : public GLES2DecoderWithShaderTest {
90 GLES2DecoderGeometryInstancingTest()
91 : GLES2DecoderWithShaderTest() {
94 virtual void SetUp() {
96 "GL_ANGLE_instanced_arrays", // extensions
100 true, // request alpha
101 true, // request depth
102 false, // request stencil
103 true); // bind generates resource
104 SetupDefaultProgram();
108 class GLES2DecoderRGBBackbufferTest : public GLES2DecoderWithShaderTest {
110 GLES2DecoderRGBBackbufferTest() { }
112 virtual void SetUp() {
117 false, // has stencil
118 false, // request alpha
119 false, // request depth
120 false, // request stencil
121 true); // bind generates resource
122 SetupDefaultProgram();
126 class GLES2DecoderManualInitTest : public GLES2DecoderWithShaderTest {
128 GLES2DecoderManualInitTest() { }
130 // Override default setup so nothing gets setup.
131 virtual void SetUp() {
135 class GLES2DecoderANGLEManualInitTest : public GLES2DecoderANGLETest {
137 // Override default setup so nothing gets setup.
138 virtual void SetUp() {
142 TEST_F(GLES2DecoderWithShaderTest, DrawArraysNoAttributesSucceeds) {
144 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
145 SetupExpectationsForApplyingDefaultDirtyState();
147 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
149 .RetiresOnSaturation();
151 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
152 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
153 EXPECT_EQ(GL_NO_ERROR, GetGLError());
156 // Tests when the math overflows (0x40000000 * sizeof GLfloat)
157 TEST_F(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0OverflowFails) {
158 const GLsizei kLargeCount = 0x40000000;
160 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
162 .RetiresOnSaturation();
164 cmd.Init(GL_TRIANGLES, 0, kLargeCount);
165 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
166 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
169 // Tests when the math overflows (0x7FFFFFFF + 1 = 0x8000000 verts)
170 TEST_F(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0PosToNegFails) {
171 const GLsizei kLargeCount = 0x7FFFFFFF;
173 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
175 .RetiresOnSaturation();
177 cmd.Init(GL_TRIANGLES, 0, kLargeCount);
178 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
179 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
182 // Tests when the driver returns an error
183 TEST_F(GLES2DecoderWithShaderTest, DrawArraysSimulatedAttrib0OOMFails) {
184 const GLsizei kFakeLargeCount = 0x1234;
186 AddExpectationsForSimulatedAttrib0WithError(
187 kFakeLargeCount, 0, GL_OUT_OF_MEMORY);
188 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
190 .RetiresOnSaturation();
192 cmd.Init(GL_TRIANGLES, 0, kFakeLargeCount);
193 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
194 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
197 TEST_F(GLES2DecoderWithShaderTest, DrawArraysBadTextureUsesBlack) {
198 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
199 // This is an NPOT texture. As the default filtering requires mips
200 // this should trigger replacing with black textures before rendering.
201 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
202 kSharedMemoryId, kSharedMemoryOffset);
203 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
206 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
208 .RetiresOnSaturation();
209 EXPECT_CALL(*gl_, BindTexture(
210 GL_TEXTURE_2D, TestHelper::kServiceBlackTexture2dId))
212 .RetiresOnSaturation();
213 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
215 .RetiresOnSaturation();
216 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
218 .RetiresOnSaturation();
219 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
221 .RetiresOnSaturation();
222 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
224 .RetiresOnSaturation();
226 SetupExpectationsForApplyingDefaultDirtyState();
228 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
229 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
230 EXPECT_EQ(GL_NO_ERROR, GetGLError());
233 TEST_F(GLES2DecoderWithShaderTest, DrawArraysMissingAttributesFails) {
234 DoEnableVertexAttribArray(1);
236 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
239 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
240 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
241 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
244 TEST_F(GLES2DecoderWithShaderTest,
245 DrawArraysMissingAttributesZeroCountSucceeds) {
246 DoEnableVertexAttribArray(1);
248 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
251 cmd.Init(GL_TRIANGLES, 0, 0);
252 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
253 EXPECT_EQ(GL_NO_ERROR, GetGLError());
256 TEST_F(GLES2DecoderWithShaderTest, DrawArraysValidAttributesSucceeds) {
259 DoEnableVertexAttribArray(1);
260 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
261 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
262 SetupExpectationsForApplyingDefaultDirtyState();
264 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
266 .RetiresOnSaturation();
268 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
269 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
270 EXPECT_EQ(GL_NO_ERROR, GetGLError());
273 TEST_F(GLES2DecoderWithShaderTest, DrawArraysDeletedBufferFails) {
275 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
276 DeleteVertexBuffer();
278 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
281 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
282 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
283 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
286 TEST_F(GLES2DecoderWithShaderTest, DrawArraysDeletedProgramSucceeds) {
288 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
289 SetupExpectationsForApplyingDefaultDirtyState();
290 DoDeleteProgram(client_program_id_, kServiceProgramId);
292 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
294 .RetiresOnSaturation();
295 EXPECT_CALL(*gl_, DeleteProgram(kServiceProgramId))
298 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
299 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
300 EXPECT_EQ(GL_NO_ERROR, GetGLError());
303 TEST_F(GLES2DecoderWithShaderTest, DrawArraysWithInvalidModeFails) {
305 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
307 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
310 cmd.Init(GL_QUADS, 0, 1);
311 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
312 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
313 cmd.Init(GL_POLYGON, 0, 1);
314 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
315 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
318 TEST_F(GLES2DecoderWithShaderTest, DrawArraysInvalidCountFails) {
320 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
323 EXPECT_CALL(*gl_, DrawArrays(_, _, _)).Times(0);
325 cmd.Init(GL_TRIANGLES, 1, kNumVertices);
326 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
327 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
328 EXPECT_EQ(GL_NO_ERROR, GetGLError());
330 // Try with count > size
331 cmd.Init(GL_TRIANGLES, 0, kNumVertices + 1);
332 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
333 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
334 EXPECT_EQ(GL_NO_ERROR, GetGLError());
336 // Try with attrib offset > 0
337 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
338 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 4);
339 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
340 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
341 EXPECT_EQ(GL_NO_ERROR, GetGLError());
343 // Try with size > 2 (ie, vec3 instead of vec2)
344 DoVertexAttribPointer(1, 3, GL_FLOAT, 0, 0);
345 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
346 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
347 EXPECT_EQ(GL_NO_ERROR, GetGLError());
349 // Try with stride > 8 (vec2 + vec2 byte)
350 DoVertexAttribPointer(1, 2, GL_FLOAT, sizeof(GLfloat) * 3, 0);
351 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
352 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
353 EXPECT_EQ(GL_NO_ERROR, GetGLError());
356 TEST_F(GLES2DecoderWithShaderTest, DrawArraysInstancedANGLEFails) {
359 DoEnableVertexAttribArray(1);
360 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
362 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
364 .RetiresOnSaturation();
365 DrawArraysInstancedANGLE cmd;
366 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
367 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
368 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
371 TEST_F(GLES2DecoderGeometryInstancingTest,
372 DrawArraysInstancedANGLENoAttributesFails) {
375 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
377 .RetiresOnSaturation();
378 DrawArraysInstancedANGLE cmd;
379 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
380 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
381 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
384 TEST_F(GLES2DecoderGeometryInstancingTest,
385 DrawArraysInstancedANGLESimulatedAttrib0) {
388 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
390 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
391 SetupExpectationsForApplyingDefaultDirtyState();
393 DoVertexAttribDivisorANGLE(0, 1);
394 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, 3))
396 .RetiresOnSaturation();
397 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 0))
399 .RetiresOnSaturation();
400 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 1))
402 .RetiresOnSaturation();
403 DrawArraysInstancedANGLE cmd;
404 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 3);
405 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
406 EXPECT_EQ(GL_NO_ERROR, GetGLError());
409 TEST_F(GLES2DecoderGeometryInstancingTest,
410 DrawArraysInstancedANGLEMissingAttributesFails) {
411 DoEnableVertexAttribArray(1);
413 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
415 DrawArraysInstancedANGLE cmd;
416 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
417 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
418 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
421 TEST_F(GLES2DecoderGeometryInstancingTest,
422 DrawArraysInstancedANGLEMissingAttributesZeroCountSucceeds) {
423 DoEnableVertexAttribArray(1);
425 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
427 DrawArraysInstancedANGLE cmd;
428 cmd.Init(GL_TRIANGLES, 0, 0, 1);
429 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
430 EXPECT_EQ(GL_NO_ERROR, GetGLError());
433 TEST_F(GLES2DecoderGeometryInstancingTest,
434 DrawArraysInstancedANGLEValidAttributesSucceeds) {
437 DoEnableVertexAttribArray(1);
438 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
439 AddExpectationsForSimulatedAttrib0(kNumVertices, kServiceBufferId);
440 SetupExpectationsForApplyingDefaultDirtyState();
442 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices, 1))
444 .RetiresOnSaturation();
445 DrawArraysInstancedANGLE cmd;
446 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
447 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
448 EXPECT_EQ(GL_NO_ERROR, GetGLError());
451 TEST_F(GLES2DecoderGeometryInstancingTest,
452 DrawArraysInstancedANGLEWithInvalidModeFails) {
454 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
456 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
458 DrawArraysInstancedANGLE cmd;
459 cmd.Init(GL_QUADS, 0, 1, 1);
460 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
461 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
462 cmd.Init(GL_POLYGON, 0, 1, 1);
463 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
464 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
467 TEST_F(GLES2DecoderGeometryInstancingTest,
468 DrawArraysInstancedANGLEInvalidPrimcountFails) {
470 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
472 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
474 DrawArraysInstancedANGLE cmd;
475 cmd.Init(GL_TRIANGLES, 0, 1, -1);
476 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
477 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
480 // Per-instance data is twice as large, but number of instances is half
481 TEST_F(GLES2DecoderGeometryInstancingTest,
482 DrawArraysInstancedANGLELargeInstanceSucceeds) {
485 SetupExpectationsForApplyingDefaultDirtyState();
486 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
488 DoEnableVertexAttribArray(0);
489 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
490 DoVertexAttribDivisorANGLE(0, 1);
491 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices,
494 .RetiresOnSaturation();
495 DrawArraysInstancedANGLE cmd;
496 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices / 2);
497 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
498 EXPECT_EQ(GL_NO_ERROR, GetGLError());
501 // Per-instance data is twice as large, but divisor is twice
502 TEST_F(GLES2DecoderGeometryInstancingTest,
503 DrawArraysInstancedANGLELargeDivisorSucceeds) {
506 SetupExpectationsForApplyingDefaultDirtyState();
507 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
509 DoEnableVertexAttribArray(0);
510 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
511 DoVertexAttribDivisorANGLE(0, 2);
512 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices,
515 .RetiresOnSaturation();
516 DrawArraysInstancedANGLE cmd;
517 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices);
518 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
519 EXPECT_EQ(GL_NO_ERROR, GetGLError());
522 TEST_F(GLES2DecoderGeometryInstancingTest, DrawArraysInstancedANGLELargeFails) {
525 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
527 DoEnableVertexAttribArray(0);
528 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
529 DoVertexAttribDivisorANGLE(0, 1);
530 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
532 .RetiresOnSaturation();
533 DrawArraysInstancedANGLE cmd;
534 cmd.Init(GL_TRIANGLES, 0, kNumVertices, kNumVertices + 1);
535 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
536 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
537 EXPECT_EQ(GL_NO_ERROR, GetGLError());
539 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
541 .RetiresOnSaturation();
542 cmd.Init(GL_TRIANGLES, 0, kNumVertices + 1, kNumVertices);
543 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
544 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
545 EXPECT_EQ(GL_NO_ERROR, GetGLError());
548 // Per-index data is twice as large, but number of indices is half
549 TEST_F(GLES2DecoderGeometryInstancingTest,
550 DrawArraysInstancedANGLELargeIndexSucceeds) {
553 SetupExpectationsForApplyingDefaultDirtyState();
554 DoVertexAttribPointer(1, 4, GL_FLOAT, 0, 0);
556 DoEnableVertexAttribArray(0);
557 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
558 DoVertexAttribDivisorANGLE(0, 1);
559 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(GL_TRIANGLES, 0, kNumVertices / 2,
562 .RetiresOnSaturation();
563 DrawArraysInstancedANGLE cmd;
564 cmd.Init(GL_TRIANGLES, 0, kNumVertices / 2, kNumVertices);
565 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
566 EXPECT_EQ(GL_NO_ERROR, GetGLError());
569 TEST_F(GLES2DecoderGeometryInstancingTest,
570 DrawArraysInstancedANGLENoDivisor0Fails) {
573 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
575 DoEnableVertexAttribArray(0);
576 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
577 DoVertexAttribDivisorANGLE(0, 1);
578 DoVertexAttribDivisorANGLE(1, 1);
579 EXPECT_CALL(*gl_, DrawArraysInstancedANGLE(_, _, _, _))
581 .RetiresOnSaturation();
582 DrawArraysInstancedANGLE cmd;
583 cmd.Init(GL_TRIANGLES, 0, kNumVertices, 1);
584 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
585 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
586 EXPECT_EQ(GL_NO_ERROR, GetGLError());
589 TEST_F(GLES2DecoderWithShaderTest, DrawElementsNoAttributesSucceeds) {
592 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
593 SetupExpectationsForApplyingDefaultDirtyState();
594 EXPECT_CALL(*gl_, DrawElements(GL_TRIANGLES, kValidIndexRangeCount,
596 BufferOffset(kValidIndexRangeStart * 2)))
598 .RetiresOnSaturation();
600 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
601 kValidIndexRangeStart * 2);
602 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
603 EXPECT_EQ(GL_NO_ERROR, GetGLError());
606 TEST_F(GLES2DecoderWithShaderTest, DrawElementsMissingAttributesFails) {
608 DoEnableVertexAttribArray(1);
610 EXPECT_CALL(*gl_, DrawElements(_, _, _, _))
613 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
614 kValidIndexRangeStart * 2);
615 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
616 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
619 TEST_F(GLES2DecoderWithShaderTest,
620 DrawElementsMissingAttributesZeroCountSucceeds) {
622 DoEnableVertexAttribArray(1);
624 EXPECT_CALL(*gl_, DrawElements(_, _, _, _))
627 cmd.Init(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT,
628 kValidIndexRangeStart * 2);
629 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
630 EXPECT_EQ(GL_NO_ERROR, GetGLError());
633 TEST_F(GLES2DecoderWithShaderTest, DrawElementsExtraAttributesFails) {
635 DoEnableVertexAttribArray(6);
637 EXPECT_CALL(*gl_, DrawElements(_, _, _, _))
640 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
641 kValidIndexRangeStart * 2);
642 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
643 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
646 TEST_F(GLES2DecoderWithShaderTest, DrawElementsValidAttributesSucceeds) {
650 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
651 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
652 SetupExpectationsForApplyingDefaultDirtyState();
654 EXPECT_CALL(*gl_, DrawElements(GL_TRIANGLES, kValidIndexRangeCount,
656 BufferOffset(kValidIndexRangeStart * 2)))
658 .RetiresOnSaturation();
660 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
661 kValidIndexRangeStart * 2);
662 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
663 EXPECT_EQ(GL_NO_ERROR, GetGLError());
666 TEST_F(GLES2DecoderWithShaderTest, DrawElementsDeletedBufferFails) {
669 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
672 EXPECT_CALL(*gl_, DrawElements(_, _, _, _))
675 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
676 kValidIndexRangeStart * 2);
677 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
678 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
681 TEST_F(GLES2DecoderWithShaderTest, DrawElementsDeletedProgramSucceeds) {
684 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
685 SetupExpectationsForApplyingDefaultDirtyState();
686 DoDeleteProgram(client_program_id_, kServiceProgramId);
688 EXPECT_CALL(*gl_, DrawElements(_, _, _, _))
690 EXPECT_CALL(*gl_, DeleteProgram(kServiceProgramId))
693 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
694 kValidIndexRangeStart * 2);
695 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
696 EXPECT_EQ(GL_NO_ERROR, GetGLError());
699 TEST_F(GLES2DecoderWithShaderTest, DrawElementsWithInvalidModeFails) {
702 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
704 EXPECT_CALL(*gl_, DrawElements(_, _, _, _))
707 cmd.Init(GL_QUADS, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
708 kValidIndexRangeStart * 2);
709 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
710 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
711 cmd.Init(GL_POLYGON, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
712 kValidIndexRangeStart);
713 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
714 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
717 TEST_F(GLES2DecoderWithShaderTest, DrawElementsInvalidCountFails) {
720 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
723 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
725 cmd.Init(GL_TRIANGLES, kNumIndices, GL_UNSIGNED_SHORT, 2);
726 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
727 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
728 EXPECT_EQ(GL_NO_ERROR, GetGLError());
730 // Try with count > size
731 cmd.Init(GL_TRIANGLES, kNumIndices + 1, GL_UNSIGNED_SHORT, 0);
732 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
733 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
734 EXPECT_EQ(GL_NO_ERROR, GetGLError());
737 TEST_F(GLES2DecoderWithShaderTest, DrawElementsOutOfRangeIndicesFails) {
740 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
742 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
744 cmd.Init(GL_TRIANGLES, kInvalidIndexRangeCount, GL_UNSIGNED_SHORT,
745 kInvalidIndexRangeStart * 2);
746 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
747 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
748 EXPECT_EQ(GL_NO_ERROR, GetGLError());
751 TEST_F(GLES2DecoderWithShaderTest, DrawElementsOddOffsetForUint16Fails) {
754 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
756 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(0);
758 cmd.Init(GL_TRIANGLES, kInvalidIndexRangeCount, GL_UNSIGNED_SHORT, 1);
759 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
760 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
761 EXPECT_EQ(GL_NO_ERROR, GetGLError());
764 TEST_F(GLES2DecoderWithShaderTest, DrawElementsInstancedANGLEFails) {
768 DoEnableVertexAttribArray(1);
769 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
771 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
773 .RetiresOnSaturation();
774 DrawElementsInstancedANGLE cmd;
775 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
776 kValidIndexRangeStart * 2, 1);
777 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
778 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
781 TEST_F(GLES2DecoderGeometryInstancingTest,
782 DrawElementsInstancedANGLENoAttributesFails) {
786 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
788 .RetiresOnSaturation();
789 DrawElementsInstancedANGLE cmd;
790 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
791 kValidIndexRangeStart * 2, 1);
792 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
793 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
796 TEST_F(GLES2DecoderGeometryInstancingTest,
797 DrawElementsInstancedANGLESimulatedAttrib0) {
801 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
803 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
804 SetupExpectationsForApplyingDefaultDirtyState();
806 DoVertexAttribDivisorANGLE(0, 1);
807 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(
809 kValidIndexRangeCount,
811 BufferOffset(kValidIndexRangeStart * 2),
814 .RetiresOnSaturation();
815 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 0))
817 .RetiresOnSaturation();
818 EXPECT_CALL(*gl_, VertexAttribDivisorANGLE(0, 1))
820 .RetiresOnSaturation();
821 DrawElementsInstancedANGLE cmd;
822 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
823 kValidIndexRangeStart * 2, 3);
824 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
825 EXPECT_EQ(GL_NO_ERROR, GetGLError());
828 TEST_F(GLES2DecoderGeometryInstancingTest,
829 DrawElementsInstancedANGLEMissingAttributesFails) {
831 DoEnableVertexAttribArray(1);
833 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
835 DrawElementsInstancedANGLE cmd;
836 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
837 kValidIndexRangeStart * 2, 1);
838 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
839 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
842 TEST_F(GLES2DecoderGeometryInstancingTest,
843 DrawElementsInstancedANGLEMissingAttributesZeroCountSucceeds) {
845 DoEnableVertexAttribArray(1);
847 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
849 DrawElementsInstancedANGLE cmd;
850 cmd.Init(GL_TRIANGLES, 0, GL_UNSIGNED_SHORT,
851 kValidIndexRangeStart * 2, 1);
852 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
853 EXPECT_EQ(GL_NO_ERROR, GetGLError());
856 TEST_F(GLES2DecoderGeometryInstancingTest,
857 DrawElementsInstancedANGLEValidAttributesSucceeds) {
861 DoEnableVertexAttribArray(1);
862 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
863 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, kServiceBufferId);
864 SetupExpectationsForApplyingDefaultDirtyState();
866 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(
868 kValidIndexRangeCount,
870 BufferOffset(kValidIndexRangeStart * 2),
873 .RetiresOnSaturation();
874 DrawElementsInstancedANGLE cmd;
875 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
876 kValidIndexRangeStart * 2, 1);
877 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
878 EXPECT_EQ(GL_NO_ERROR, GetGLError());
881 TEST_F(GLES2DecoderGeometryInstancingTest,
882 DrawElementsInstancedANGLEWithInvalidModeFails) {
885 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
887 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
889 DrawElementsInstancedANGLE cmd;
890 cmd.Init(GL_QUADS, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
891 kValidIndexRangeStart * 2, 1);
892 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
893 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
894 cmd.Init(GL_INVALID_ENUM, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
895 kValidIndexRangeStart * 2, 1);
896 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
897 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
900 // Per-instance data is twice as large, but number of instances is half
901 TEST_F(GLES2DecoderGeometryInstancingTest,
902 DrawElementsInstancedANGLELargeInstanceSucceeds) {
906 SetupExpectationsForApplyingDefaultDirtyState();
907 //Add offset so we're sure we're accessing data near the end of the buffer.
908 DoVertexAttribPointer(1, 2, GL_FLOAT, 0,
909 (kNumVertices - kMaxValidIndex - 1) * 2 *
912 DoEnableVertexAttribArray(0);
913 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
914 DoVertexAttribDivisorANGLE(0, 1);
915 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(
917 kValidIndexRangeCount,
919 BufferOffset(kValidIndexRangeStart * 2),
922 .RetiresOnSaturation();
923 DrawElementsInstancedANGLE cmd;
924 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
925 kValidIndexRangeStart * 2, kNumVertices / 2);
926 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
927 EXPECT_EQ(GL_NO_ERROR, GetGLError());
930 // Per-instance data is twice as large, but divisor is twice
931 TEST_F(GLES2DecoderGeometryInstancingTest,
932 DrawElementsInstancedANGLELargeDivisorSucceeds) {
936 SetupExpectationsForApplyingDefaultDirtyState();
937 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
939 DoEnableVertexAttribArray(0);
940 DoVertexAttribPointer(0, 4, GL_FLOAT, 0, 0);
941 DoVertexAttribDivisorANGLE(0, 2);
942 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(
944 kValidIndexRangeCount,
946 BufferOffset(kValidIndexRangeStart * 2),
949 .RetiresOnSaturation();
950 DrawElementsInstancedANGLE cmd;
951 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
952 kValidIndexRangeStart * 2, kNumVertices);
953 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
954 EXPECT_EQ(GL_NO_ERROR, GetGLError());
957 TEST_F(GLES2DecoderGeometryInstancingTest,
958 DrawElementsInstancedANGLELargeFails) {
962 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
964 DoEnableVertexAttribArray(0);
965 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
966 DoVertexAttribDivisorANGLE(0, 1);
967 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
969 .RetiresOnSaturation();
970 DrawElementsInstancedANGLE cmd;
971 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
972 kValidIndexRangeStart * 2, kNumVertices + 1);
973 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
974 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
975 EXPECT_EQ(GL_NO_ERROR, GetGLError());
977 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
979 .RetiresOnSaturation();
980 cmd.Init(GL_TRIANGLES, kInvalidIndexRangeCount, GL_UNSIGNED_SHORT,
981 kInvalidIndexRangeStart * 2, kNumVertices);
982 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
983 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
984 EXPECT_EQ(GL_NO_ERROR, GetGLError());
987 TEST_F(GLES2DecoderGeometryInstancingTest,
988 DrawElementsInstancedANGLEInvalidPrimcountFails) {
992 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
994 DoEnableVertexAttribArray(0);
995 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
996 DoVertexAttribDivisorANGLE(0, 1);
997 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
999 .RetiresOnSaturation();
1000 DrawElementsInstancedANGLE cmd;
1001 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
1002 kValidIndexRangeStart * 2, -1);
1003 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1004 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1005 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1008 // Per-index data is twice as large, but values of indices are smaller
1009 TEST_F(GLES2DecoderGeometryInstancingTest,
1010 DrawElementsInstancedANGLELargeIndexSucceeds) {
1013 SetupVertexBuffer();
1014 SetupExpectationsForApplyingDefaultDirtyState();
1015 DoVertexAttribPointer(1, 4, GL_FLOAT, 0, 0);
1017 DoEnableVertexAttribArray(0);
1018 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1019 DoVertexAttribDivisorANGLE(0, 1);
1020 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(
1022 kValidIndexRangeCount,
1024 BufferOffset(kValidIndexRangeStart * 2),
1027 .RetiresOnSaturation();
1028 DrawElementsInstancedANGLE cmd;
1029 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
1030 kValidIndexRangeStart * 2, kNumVertices);
1031 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1032 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1035 TEST_F(GLES2DecoderGeometryInstancingTest,
1036 DrawElementsInstancedANGLENoDivisor0Fails) {
1039 SetupVertexBuffer();
1040 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
1042 DoEnableVertexAttribArray(0);
1043 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
1044 DoVertexAttribDivisorANGLE(0, 1);
1045 DoVertexAttribDivisorANGLE(1, 1);
1046 EXPECT_CALL(*gl_, DrawElementsInstancedANGLE(_, _, _, _, _))
1048 .RetiresOnSaturation();
1049 DrawElementsInstancedANGLE cmd;
1050 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
1051 kValidIndexRangeStart * 2, kNumVertices);
1052 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1053 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1054 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1057 TEST_F(GLES2DecoderWithShaderTest, GetVertexAttribPointervSucceeds) {
1058 const float dummy = 0;
1059 const GLuint kOffsetToTestFor = sizeof(dummy) * 4;
1060 const GLuint kIndexToTest = 1;
1061 GetVertexAttribPointerv::Result* result =
1062 static_cast<GetVertexAttribPointerv::Result*>(shared_memory_address_);
1064 const GLuint* result_value = result->GetData();
1065 // Test that initial value is 0.
1066 GetVertexAttribPointerv cmd;
1067 cmd.Init(kIndexToTest, GL_VERTEX_ATTRIB_ARRAY_POINTER,
1068 shared_memory_id_, shared_memory_offset_);
1069 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1070 EXPECT_EQ(sizeof(*result_value), result->size);
1071 EXPECT_EQ(0u, *result_value);
1072 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1074 // Set the value and see that we get it.
1075 SetupVertexBuffer();
1076 DoVertexAttribPointer(kIndexToTest, 2, GL_FLOAT, 0, kOffsetToTestFor);
1078 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1079 EXPECT_EQ(sizeof(*result_value), result->size);
1080 EXPECT_EQ(kOffsetToTestFor, *result_value);
1081 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1084 TEST_F(GLES2DecoderWithShaderTest, GetVertexAttribPointervBadArgsFails) {
1085 const GLuint kIndexToTest = 1;
1086 GetVertexAttribPointerv::Result* result =
1087 static_cast<GetVertexAttribPointerv::Result*>(shared_memory_address_);
1089 const GLuint* result_value = result->GetData();
1090 // Test pname invalid fails.
1091 GetVertexAttribPointerv cmd;
1092 cmd.Init(kIndexToTest, GL_VERTEX_ATTRIB_ARRAY_POINTER + 1,
1093 shared_memory_id_, shared_memory_offset_);
1094 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1095 EXPECT_EQ(0u, result->size);
1096 EXPECT_EQ(kInitialResult, *result_value);
1097 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1099 // Test index out of range fails.
1101 cmd.Init(kNumVertexAttribs, GL_VERTEX_ATTRIB_ARRAY_POINTER,
1102 shared_memory_id_, shared_memory_offset_);
1103 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1104 EXPECT_EQ(0u, result->size);
1105 EXPECT_EQ(kInitialResult, *result_value);
1106 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1108 // Test memory id bad fails.
1109 cmd.Init(kIndexToTest, GL_VERTEX_ATTRIB_ARRAY_POINTER,
1110 kInvalidSharedMemoryId, shared_memory_offset_);
1111 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1113 // Test memory offset bad fails.
1114 cmd.Init(kIndexToTest, GL_VERTEX_ATTRIB_ARRAY_POINTER,
1115 shared_memory_id_, kInvalidSharedMemoryOffset);
1116 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1119 TEST_F(GLES2DecoderWithShaderTest, GetUniformivSucceeds) {
1120 GetUniformiv::Result* result =
1121 static_cast<GetUniformiv::Result*>(shared_memory_address_);
1124 cmd.Init(client_program_id_,
1125 kUniform2FakeLocation,
1126 kSharedMemoryId, kSharedMemoryOffset);
1127 EXPECT_CALL(*gl_, GetUniformiv(kServiceProgramId, kUniform2RealLocation, _))
1129 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1130 EXPECT_EQ(GLES2Util::GetGLDataTypeSizeForUniforms(kUniform2Type),
1134 TEST_F(GLES2DecoderWithShaderTest, GetUniformivArrayElementSucceeds) {
1135 GetUniformiv::Result* result =
1136 static_cast<GetUniformiv::Result*>(shared_memory_address_);
1139 cmd.Init(client_program_id_,
1140 kUniform2ElementFakeLocation,
1141 kSharedMemoryId, kSharedMemoryOffset);
1143 GetUniformiv(kServiceProgramId, kUniform2ElementRealLocation, _))
1145 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1146 EXPECT_EQ(GLES2Util::GetGLDataTypeSizeForUniforms(kUniform2Type),
1150 TEST_F(GLES2DecoderWithShaderTest, GetUniformivBadProgramFails) {
1151 GetUniformiv::Result* result =
1152 static_cast<GetUniformiv::Result*>(shared_memory_address_);
1155 // non-existant program
1156 cmd.Init(kInvalidClientId,
1157 kUniform2FakeLocation,
1158 kSharedMemoryId, kSharedMemoryOffset);
1159 EXPECT_CALL(*gl_, GetUniformiv(_, _, _))
1161 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1162 EXPECT_EQ(0U, result->size);
1163 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1164 // Valid id that is not a program. The GL spec requires a different error for
1166 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1167 result->size = kInitialResult;
1168 cmd.Init(client_shader_id_,
1169 kUniform2FakeLocation,
1170 kSharedMemoryId, kSharedMemoryOffset);
1171 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1172 EXPECT_EQ(0U, result->size);
1173 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1174 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1176 EXPECT_CALL(*gl_, CreateProgram())
1178 .WillOnce(Return(kNewServiceId))
1179 .RetiresOnSaturation();
1181 cmd2.Init(kNewClientId);
1182 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1183 result->size = kInitialResult;
1184 cmd.Init(kNewClientId,
1185 kUniform2FakeLocation,
1186 kSharedMemoryId, kSharedMemoryOffset);
1187 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1188 EXPECT_EQ(0U, result->size);
1189 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1192 TEST_F(GLES2DecoderWithShaderTest, GetUniformivBadLocationFails) {
1193 GetUniformiv::Result* result =
1194 static_cast<GetUniformiv::Result*>(shared_memory_address_);
1198 cmd.Init(client_program_id_, kInvalidUniformLocation,
1199 kSharedMemoryId, kSharedMemoryOffset);
1200 EXPECT_CALL(*gl_, GetUniformiv(_, _, _))
1202 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1203 EXPECT_EQ(0U, result->size);
1204 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1207 TEST_F(GLES2DecoderWithShaderTest, GetUniformivBadSharedMemoryFails) {
1209 cmd.Init(client_program_id_,
1210 kUniform2FakeLocation,
1211 kInvalidSharedMemoryId, kSharedMemoryOffset);
1212 EXPECT_CALL(*gl_, GetUniformiv(_, _, _))
1214 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1215 cmd.Init(client_program_id_, kUniform2FakeLocation,
1216 kSharedMemoryId, kInvalidSharedMemoryOffset);
1217 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1220 TEST_F(GLES2DecoderWithShaderTest, GetUniformfvSucceeds) {
1221 GetUniformfv::Result* result =
1222 static_cast<GetUniformfv::Result*>(shared_memory_address_);
1225 cmd.Init(client_program_id_,
1226 kUniform2FakeLocation,
1227 kSharedMemoryId, kSharedMemoryOffset);
1228 EXPECT_CALL(*gl_, GetUniformfv(kServiceProgramId, kUniform2RealLocation, _))
1230 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1231 EXPECT_EQ(GLES2Util::GetGLDataTypeSizeForUniforms(kUniform2Type),
1235 TEST_F(GLES2DecoderWithShaderTest, GetUniformfvArrayElementSucceeds) {
1236 GetUniformfv::Result* result =
1237 static_cast<GetUniformfv::Result*>(shared_memory_address_);
1240 cmd.Init(client_program_id_,
1241 kUniform2ElementFakeLocation,
1242 kSharedMemoryId, kSharedMemoryOffset);
1244 GetUniformfv(kServiceProgramId, kUniform2ElementRealLocation, _))
1246 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1247 EXPECT_EQ(GLES2Util::GetGLDataTypeSizeForUniforms(kUniform2Type),
1251 TEST_F(GLES2DecoderWithShaderTest, GetUniformfvBadProgramFails) {
1252 GetUniformfv::Result* result =
1253 static_cast<GetUniformfv::Result*>(shared_memory_address_);
1256 // non-existant program
1257 cmd.Init(kInvalidClientId,
1258 kUniform2FakeLocation,
1259 kSharedMemoryId, kSharedMemoryOffset);
1260 EXPECT_CALL(*gl_, GetUniformfv(_, _, _))
1262 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1263 EXPECT_EQ(0U, result->size);
1264 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1265 // Valid id that is not a program. The GL spec requires a different error for
1267 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1268 result->size = kInitialResult;
1269 cmd.Init(client_shader_id_,
1270 kUniform2FakeLocation,
1271 kSharedMemoryId, kSharedMemoryOffset);
1272 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1273 EXPECT_EQ(0U, result->size);
1274 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1275 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1277 EXPECT_CALL(*gl_, CreateProgram())
1279 .WillOnce(Return(kNewServiceId))
1280 .RetiresOnSaturation();
1282 cmd2.Init(kNewClientId);
1283 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1284 result->size = kInitialResult;
1285 cmd.Init(kNewClientId,
1286 kUniform2FakeLocation,
1287 kSharedMemoryId, kSharedMemoryOffset);
1288 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1289 EXPECT_EQ(0U, result->size);
1290 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1293 TEST_F(GLES2DecoderWithShaderTest, GetUniformfvBadLocationFails) {
1294 GetUniformfv::Result* result =
1295 static_cast<GetUniformfv::Result*>(shared_memory_address_);
1299 cmd.Init(client_program_id_, kInvalidUniformLocation,
1300 kSharedMemoryId, kSharedMemoryOffset);
1301 EXPECT_CALL(*gl_, GetUniformfv(_, _, _))
1303 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1304 EXPECT_EQ(0U, result->size);
1305 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1308 TEST_F(GLES2DecoderWithShaderTest, GetUniformfvBadSharedMemoryFails) {
1310 cmd.Init(client_program_id_,
1311 kUniform2FakeLocation,
1312 kInvalidSharedMemoryId, kSharedMemoryOffset);
1313 EXPECT_CALL(*gl_, GetUniformfv(_, _, _))
1315 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1316 cmd.Init(client_program_id_, kUniform2FakeLocation,
1317 kSharedMemoryId, kInvalidSharedMemoryOffset);
1318 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1321 TEST_F(GLES2DecoderWithShaderTest, GetAttachedShadersSucceeds) {
1322 GetAttachedShaders cmd;
1323 typedef GetAttachedShaders::Result Result;
1324 Result* result = static_cast<Result*>(shared_memory_address_);
1326 EXPECT_CALL(*gl_, GetAttachedShaders(kServiceProgramId, 1, _, _))
1327 .WillOnce(DoAll(SetArgumentPointee<2>(1),
1328 SetArgumentPointee<3>(kServiceShaderId)));
1329 cmd.Init(client_program_id_, shared_memory_id_, shared_memory_offset_,
1330 Result::ComputeSize(1));
1331 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1332 EXPECT_EQ(1, result->GetNumResults());
1333 EXPECT_EQ(client_shader_id_, result->GetData()[0]);
1334 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1337 TEST_F(GLES2DecoderWithShaderTest, GetAttachedShadersResultNotInitFail) {
1338 GetAttachedShaders cmd;
1339 typedef GetAttachedShaders::Result Result;
1340 Result* result = static_cast<Result*>(shared_memory_address_);
1342 EXPECT_CALL(*gl_, GetAttachedShaders(_, _, _, _))
1344 cmd.Init(client_program_id_, shared_memory_id_, shared_memory_offset_,
1345 Result::ComputeSize(1));
1346 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1349 TEST_F(GLES2DecoderWithShaderTest, GetAttachedShadersBadProgramFails) {
1350 GetAttachedShaders cmd;
1351 typedef GetAttachedShaders::Result Result;
1352 Result* result = static_cast<Result*>(shared_memory_address_);
1354 EXPECT_CALL(*gl_, GetAttachedShaders(_, _, _, _))
1356 cmd.Init(kInvalidClientId, shared_memory_id_, shared_memory_offset_,
1357 Result::ComputeSize(1));
1358 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1359 EXPECT_EQ(0U, result->size);
1360 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1363 TEST_F(GLES2DecoderWithShaderTest, GetAttachedShadersBadSharedMemoryFails) {
1364 GetAttachedShaders cmd;
1365 typedef GetAttachedShaders::Result Result;
1366 cmd.Init(client_program_id_, kInvalidSharedMemoryId, shared_memory_offset_,
1367 Result::ComputeSize(1));
1368 EXPECT_CALL(*gl_, GetAttachedShaders(_, _, _, _))
1370 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1371 cmd.Init(client_program_id_, shared_memory_id_, kInvalidSharedMemoryOffset,
1372 Result::ComputeSize(1));
1373 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1376 TEST_F(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatSucceeds) {
1377 ScopedGLImplementationSetter gl_impl(::gfx::kGLImplementationEGLGLES2);
1378 GetShaderPrecisionFormat cmd;
1379 typedef GetShaderPrecisionFormat::Result Result;
1380 Result* result = static_cast<Result*>(shared_memory_address_);
1381 result->success = 0;
1382 const GLint range[2] = { 62, 62 };
1383 const GLint precision = 16;
1384 EXPECT_CALL(*gl_,GetShaderPrecisionFormat(_, _, _, _))
1385 .WillOnce(DoAll(SetArrayArgument<2>(range,range+2),
1386 SetArgumentPointee<3>(precision)))
1387 .RetiresOnSaturation();
1388 cmd.Init(GL_VERTEX_SHADER, GL_HIGH_FLOAT,
1389 shared_memory_id_, shared_memory_offset_);
1390 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1391 EXPECT_NE(0, result->success);
1392 EXPECT_EQ(range[0], result->min_range);
1393 EXPECT_EQ(range[1], result->max_range);
1394 EXPECT_EQ(precision, result->precision);
1395 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1398 TEST_F(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatResultNotInitFails) {
1399 GetShaderPrecisionFormat cmd;
1400 typedef GetShaderPrecisionFormat::Result Result;
1401 Result* result = static_cast<Result*>(shared_memory_address_);
1402 result->success = 1;
1403 // NOTE: GL might not be called. There is no Desktop OpenGL equivalent
1404 cmd.Init(GL_VERTEX_SHADER, GL_HIGH_FLOAT,
1405 shared_memory_id_, shared_memory_offset_);
1406 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1409 TEST_F(GLES2DecoderWithShaderTest, GetShaderPrecisionFormatBadArgsFails) {
1410 typedef GetShaderPrecisionFormat::Result Result;
1411 Result* result = static_cast<Result*>(shared_memory_address_);
1412 result->success = 0;
1413 GetShaderPrecisionFormat cmd;
1414 cmd.Init(GL_TEXTURE_2D, GL_HIGH_FLOAT,
1415 shared_memory_id_, shared_memory_offset_);
1416 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1417 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1418 result->success = 0;
1419 cmd.Init(GL_VERTEX_SHADER, GL_TEXTURE_2D,
1420 shared_memory_id_, shared_memory_offset_);
1421 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1422 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1425 TEST_F(GLES2DecoderWithShaderTest,
1426 GetShaderPrecisionFormatBadSharedMemoryFails) {
1427 GetShaderPrecisionFormat cmd;
1428 cmd.Init(GL_VERTEX_SHADER, GL_HIGH_FLOAT,
1429 kInvalidSharedMemoryId, shared_memory_offset_);
1430 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1431 cmd.Init(GL_VERTEX_SHADER, GL_TEXTURE_2D,
1432 shared_memory_id_, kInvalidSharedMemoryOffset);
1433 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1436 TEST_F(GLES2DecoderWithShaderTest, GetActiveUniformSucceeds) {
1437 const GLuint kUniformIndex = 1;
1438 const uint32 kBucketId = 123;
1439 GetActiveUniform cmd;
1440 typedef GetActiveUniform::Result Result;
1441 Result* result = static_cast<Result*>(shared_memory_address_);
1442 result->success = 0;
1443 cmd.Init(client_program_id_, kUniformIndex, kBucketId,
1444 shared_memory_id_, shared_memory_offset_);
1445 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1446 EXPECT_NE(0, result->success);
1447 EXPECT_EQ(kUniform2Size, result->size);
1448 EXPECT_EQ(kUniform2Type, result->type);
1449 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1450 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1451 ASSERT_TRUE(bucket != NULL);
1452 EXPECT_EQ(0, memcmp(bucket->GetData(0, bucket->size()), kUniform2Name,
1456 TEST_F(GLES2DecoderWithShaderTest, GetActiveUniformResultNotInitFails) {
1457 const GLuint kUniformIndex = 1;
1458 const uint32 kBucketId = 123;
1459 GetActiveUniform cmd;
1460 typedef GetActiveUniform::Result Result;
1461 Result* result = static_cast<Result*>(shared_memory_address_);
1462 result->success = 1;
1463 cmd.Init(client_program_id_, kUniformIndex, kBucketId,
1464 shared_memory_id_, shared_memory_offset_);
1465 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1468 TEST_F(GLES2DecoderWithShaderTest, GetActiveUniformBadProgramFails) {
1469 const GLuint kUniformIndex = 1;
1470 const uint32 kBucketId = 123;
1471 GetActiveUniform cmd;
1472 typedef GetActiveUniform::Result Result;
1473 Result* result = static_cast<Result*>(shared_memory_address_);
1474 result->success = 0;
1475 cmd.Init(kInvalidClientId, kUniformIndex, kBucketId,
1476 shared_memory_id_, shared_memory_offset_);
1477 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1478 EXPECT_EQ(0, result->success);
1479 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1480 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1481 result->success = 0;
1482 cmd.Init(client_shader_id_, kUniformIndex, kBucketId,
1483 shared_memory_id_, shared_memory_offset_);
1484 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1485 EXPECT_EQ(0, result->success);
1486 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1487 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1490 TEST_F(GLES2DecoderWithShaderTest, GetActiveUniformBadIndexFails) {
1491 const uint32 kBucketId = 123;
1492 GetActiveUniform cmd;
1493 typedef GetActiveUniform::Result Result;
1494 Result* result = static_cast<Result*>(shared_memory_address_);
1495 result->success = 0;
1496 cmd.Init(client_program_id_, kBadUniformIndex, kBucketId,
1497 shared_memory_id_, shared_memory_offset_);
1498 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1499 EXPECT_EQ(0, result->success);
1500 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1503 TEST_F(GLES2DecoderWithShaderTest, GetActiveUniformBadSharedMemoryFails) {
1504 const GLuint kUniformIndex = 1;
1505 const uint32 kBucketId = 123;
1506 GetActiveUniform cmd;
1507 typedef GetActiveUniform::Result Result;
1508 cmd.Init(client_program_id_, kUniformIndex, kBucketId,
1509 kInvalidSharedMemoryId, shared_memory_offset_);
1510 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1511 cmd.Init(client_program_id_, kUniformIndex, kBucketId,
1512 shared_memory_id_, kInvalidSharedMemoryOffset);
1513 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1516 TEST_F(GLES2DecoderWithShaderTest, GetActiveAttribSucceeds) {
1517 const GLuint kAttribIndex = 1;
1518 const uint32 kBucketId = 123;
1519 GetActiveAttrib cmd;
1520 typedef GetActiveAttrib::Result Result;
1521 Result* result = static_cast<Result*>(shared_memory_address_);
1522 result->success = 0;
1523 cmd.Init(client_program_id_, kAttribIndex, kBucketId,
1524 shared_memory_id_, shared_memory_offset_);
1525 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1526 EXPECT_NE(0, result->success);
1527 EXPECT_EQ(kAttrib2Size, result->size);
1528 EXPECT_EQ(kAttrib2Type, result->type);
1529 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1530 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1531 ASSERT_TRUE(bucket != NULL);
1532 EXPECT_EQ(0, memcmp(bucket->GetData(0, bucket->size()), kAttrib2Name,
1536 TEST_F(GLES2DecoderWithShaderTest, GetActiveAttribResultNotInitFails) {
1537 const GLuint kAttribIndex = 1;
1538 const uint32 kBucketId = 123;
1539 GetActiveAttrib cmd;
1540 typedef GetActiveAttrib::Result Result;
1541 Result* result = static_cast<Result*>(shared_memory_address_);
1542 result->success = 1;
1543 cmd.Init(client_program_id_, kAttribIndex, kBucketId,
1544 shared_memory_id_, shared_memory_offset_);
1545 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1548 TEST_F(GLES2DecoderWithShaderTest, GetActiveAttribBadProgramFails) {
1549 const GLuint kAttribIndex = 1;
1550 const uint32 kBucketId = 123;
1551 GetActiveAttrib cmd;
1552 typedef GetActiveAttrib::Result Result;
1553 Result* result = static_cast<Result*>(shared_memory_address_);
1554 result->success = 0;
1555 cmd.Init(kInvalidClientId, kAttribIndex, kBucketId,
1556 shared_memory_id_, shared_memory_offset_);
1557 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1558 EXPECT_EQ(0, result->success);
1559 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1560 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1561 result->success = 0;
1562 cmd.Init(client_shader_id_, kAttribIndex, kBucketId,
1563 shared_memory_id_, shared_memory_offset_);
1564 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1565 EXPECT_EQ(0, result->success);
1566 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1567 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1570 TEST_F(GLES2DecoderWithShaderTest, GetActiveAttribBadIndexFails) {
1571 const uint32 kBucketId = 123;
1572 GetActiveAttrib cmd;
1573 typedef GetActiveAttrib::Result Result;
1574 Result* result = static_cast<Result*>(shared_memory_address_);
1575 result->success = 0;
1576 cmd.Init(client_program_id_, kBadAttribIndex, kBucketId,
1577 shared_memory_id_, shared_memory_offset_);
1578 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1579 EXPECT_EQ(0, result->success);
1580 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1583 TEST_F(GLES2DecoderWithShaderTest, GetActiveAttribBadSharedMemoryFails) {
1584 const GLuint kAttribIndex = 1;
1585 const uint32 kBucketId = 123;
1586 GetActiveAttrib cmd;
1587 typedef GetActiveAttrib::Result Result;
1588 cmd.Init(client_program_id_, kAttribIndex, kBucketId,
1589 kInvalidSharedMemoryId, shared_memory_offset_);
1590 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1591 cmd.Init(client_program_id_, kAttribIndex, kBucketId,
1592 shared_memory_id_, kInvalidSharedMemoryOffset);
1593 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1596 TEST_F(GLES2DecoderWithShaderTest, GetShaderInfoLogValidArgs) {
1597 const char* kInfo = "hello";
1598 const uint32 kBucketId = 123;
1599 CompileShader compile_cmd;
1600 GetShaderInfoLog cmd;
1601 EXPECT_CALL(*gl_, ShaderSource(kServiceShaderId, 1, _, _));
1602 EXPECT_CALL(*gl_, CompileShader(kServiceShaderId));
1603 EXPECT_CALL(*gl_, GetShaderiv(kServiceShaderId, GL_COMPILE_STATUS, _))
1604 .WillOnce(SetArgumentPointee<2>(GL_FALSE))
1605 .RetiresOnSaturation();
1606 EXPECT_CALL(*gl_, GetShaderiv(kServiceShaderId, GL_INFO_LOG_LENGTH, _))
1607 .WillOnce(SetArgumentPointee<2>(strlen(kInfo) + 1))
1608 .RetiresOnSaturation();
1610 *gl_, GetShaderInfoLog(kServiceShaderId, strlen(kInfo) + 1, _, _))
1611 .WillOnce(DoAll(SetArgumentPointee<2>(strlen(kInfo)),
1612 SetArrayArgument<3>(kInfo, kInfo + strlen(kInfo) + 1)));
1613 compile_cmd.Init(client_shader_id_);
1614 cmd.Init(client_shader_id_, kBucketId);
1615 EXPECT_EQ(error::kNoError, ExecuteCmd(compile_cmd));
1616 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1617 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1618 ASSERT_TRUE(bucket != NULL);
1619 EXPECT_EQ(strlen(kInfo) + 1, bucket->size());
1620 EXPECT_EQ(0, memcmp(bucket->GetData(0, bucket->size()), kInfo,
1622 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1625 TEST_F(GLES2DecoderWithShaderTest, GetShaderInfoLogInvalidArgs) {
1626 const uint32 kBucketId = 123;
1627 GetShaderInfoLog cmd;
1628 cmd.Init(kInvalidClientId, kBucketId);
1629 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1630 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1633 TEST_F(GLES2DecoderTest, GetIntegervCached) {
1638 TestInfo tests[] = {
1639 { GL_MAX_TEXTURE_SIZE, TestHelper::kMaxTextureSize, },
1640 { GL_MAX_CUBE_MAP_TEXTURE_SIZE, TestHelper::kMaxCubeMapTextureSize, },
1641 { GL_MAX_RENDERBUFFER_SIZE, TestHelper::kMaxRenderbufferSize, },
1643 typedef GetIntegerv::Result Result;
1644 for (size_t ii = 0; ii < sizeof(tests) / sizeof(tests[0]); ++ii) {
1645 const TestInfo& test = tests[ii];
1646 Result* result = static_cast<Result*>(shared_memory_address_);
1647 EXPECT_CALL(*gl_, GetError())
1648 .WillOnce(Return(GL_NO_ERROR))
1649 .WillOnce(Return(GL_NO_ERROR))
1650 .RetiresOnSaturation();
1651 EXPECT_CALL(*gl_, GetIntegerv(test.pname, _))
1655 cmd2.Init(test.pname, shared_memory_id_, shared_memory_offset_);
1656 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1658 decoder_->GetGLES2Util()->GLGetNumValuesReturned(test.pname),
1659 result->GetNumResults());
1660 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1661 EXPECT_EQ(test.expected, result->GetData()[0]);
1665 TEST_F(GLES2DecoderTest, CompileShaderValidArgs) {
1666 EXPECT_CALL(*gl_, ShaderSource(kServiceShaderId, 1, _, _));
1667 EXPECT_CALL(*gl_, CompileShader(kServiceShaderId));
1668 EXPECT_CALL(*gl_, GetShaderiv(kServiceShaderId, GL_COMPILE_STATUS, _))
1669 .WillOnce(SetArgumentPointee<2>(GL_TRUE))
1670 .RetiresOnSaturation();
1672 cmd.Init(client_shader_id_);
1673 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1676 TEST_F(GLES2DecoderTest, CompileShaderInvalidArgs) {
1678 cmd.Init(kInvalidClientId);
1679 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1680 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1681 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1682 cmd.Init(client_program_id_);
1683 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1684 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1685 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1688 TEST_F(GLES2DecoderTest, ShaderSourceAndGetShaderSourceValidArgs) {
1689 const uint32 kBucketId = 123;
1690 const char kSource[] = "hello";
1691 const uint32 kSourceSize = sizeof(kSource) - 1;
1692 memcpy(shared_memory_address_, kSource, kSourceSize);
1694 cmd.Init(client_shader_id_,
1695 kSharedMemoryId, kSharedMemoryOffset, kSourceSize);
1696 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1697 memset(shared_memory_address_, 0, kSourceSize);
1698 GetShaderSource get_cmd;
1699 get_cmd.Init(client_shader_id_, kBucketId);
1700 EXPECT_EQ(error::kNoError, ExecuteCmd(get_cmd));
1701 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
1702 ASSERT_TRUE(bucket != NULL);
1703 EXPECT_EQ(kSourceSize + 1, bucket->size());
1704 EXPECT_EQ(0, memcmp(bucket->GetData(0, bucket->size()), kSource,
1708 TEST_F(GLES2DecoderTest, ShaderSourceInvalidArgs) {
1709 const char kSource[] = "hello";
1710 const uint32 kSourceSize = sizeof(kSource) - 1;
1711 memcpy(shared_memory_address_, kSource, kSourceSize);
1713 cmd.Init(kInvalidClientId,
1714 kSharedMemoryId, kSharedMemoryOffset, kSourceSize);
1715 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1716 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1717 #if GLES2_TEST_SHADER_VS_PROGRAM_IDS
1718 cmd.Init(client_program_id_,
1719 kSharedMemoryId, kSharedMemoryOffset, kSourceSize);
1720 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1721 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1722 #endif // GLES2_TEST_SHADER_VS_PROGRAM_IDS
1723 cmd.Init(client_shader_id_,
1724 kInvalidSharedMemoryId, kSharedMemoryOffset, kSourceSize);
1725 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1726 cmd.Init(client_shader_id_,
1727 kSharedMemoryId, kInvalidSharedMemoryOffset, kSourceSize);
1728 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1729 cmd.Init(client_shader_id_,
1730 kSharedMemoryId, kSharedMemoryOffset, kSharedBufferSize);
1731 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1734 TEST_F(GLES2DecoderTest, ShaderSourceBucketAndGetShaderSourceValidArgs) {
1735 const uint32 kInBucketId = 123;
1736 const uint32 kOutBucketId = 125;
1737 const char kSource[] = "hello";
1738 const uint32 kSourceSize = sizeof(kSource) - 1;
1739 SetBucketAsCString(kInBucketId, kSource);
1740 ShaderSourceBucket cmd;
1741 cmd.Init(client_shader_id_, kInBucketId);
1742 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1743 ClearSharedMemory();
1744 GetShaderSource get_cmd;
1745 get_cmd.Init(client_shader_id_, kOutBucketId);
1746 EXPECT_EQ(error::kNoError, ExecuteCmd(get_cmd));
1747 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kOutBucketId);
1748 ASSERT_TRUE(bucket != NULL);
1749 EXPECT_EQ(kSourceSize + 1, bucket->size());
1750 EXPECT_EQ(0, memcmp(bucket->GetData(0, bucket->size()), kSource,
1754 TEST_F(GLES2DecoderTest, ShaderSourceBucketInvalidArgs) {
1755 const uint32 kBucketId = 123;
1756 const char kSource[] = "hello";
1757 const uint32 kSourceSize = sizeof(kSource) - 1;
1758 memcpy(shared_memory_address_, kSource, kSourceSize);
1759 ShaderSourceBucket cmd;
1761 cmd.Init(client_texture_id_, kBucketId);
1762 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
1763 // Test invalid client.
1764 SetBucketAsCString(kBucketId, kSource);
1765 cmd.Init(kInvalidClientId, kBucketId);
1766 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1767 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1770 TEST_F(GLES2DecoderTest, ShaderSourceStripComments) {
1771 const uint32 kInBucketId = 123;
1772 const char kSource[] = "hello/*te\ast*/world//a\ab";
1773 SetBucketAsCString(kInBucketId, kSource);
1774 ShaderSourceBucket cmd;
1775 cmd.Init(client_shader_id_, kInBucketId);
1776 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1777 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1780 TEST_F(GLES2DecoderTest, GenerateMipmapWrongFormatsFails) {
1781 EXPECT_CALL(*gl_, GenerateMipmapEXT(_))
1783 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1785 GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1788 cmd.Init(GL_TEXTURE_2D);
1789 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1790 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1793 TEST_F(GLES2DecoderTest, GenerateMipmapHandlesOutOfMemory) {
1794 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1795 TextureManager* manager = group().texture_manager();
1796 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
1797 ASSERT_TRUE(texture_ref != NULL);
1798 Texture* texture = texture_ref->texture();
1801 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height));
1803 GL_TEXTURE_2D, 0, GL_RGBA, 16, 16, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1804 kSharedMemoryId, kSharedMemoryOffset);
1805 EXPECT_CALL(*gl_, TexParameteri(
1806 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST))
1808 .RetiresOnSaturation();
1809 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D))
1811 EXPECT_CALL(*gl_, TexParameteri(
1812 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR))
1814 .RetiresOnSaturation();
1815 EXPECT_CALL(*gl_, GetError())
1816 .WillOnce(Return(GL_NO_ERROR))
1817 .WillOnce(Return(GL_OUT_OF_MEMORY))
1818 .RetiresOnSaturation();
1820 cmd.Init(GL_TEXTURE_2D);
1821 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1822 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
1823 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height));
1826 TEST_F(GLES2DecoderTest, GenerateMipmapClearsUnclearedTexture) {
1827 EXPECT_CALL(*gl_, GenerateMipmapEXT(_))
1829 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1830 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
1832 SetupClearTextureExpections(
1833 kServiceTextureId, kServiceTextureId, GL_TEXTURE_2D, GL_TEXTURE_2D,
1834 0, GL_RGBA, GL_UNSIGNED_BYTE, 2, 2);
1835 EXPECT_CALL(*gl_, TexParameteri(
1836 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST))
1838 .RetiresOnSaturation();
1839 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D));
1840 EXPECT_CALL(*gl_, TexParameteri(
1841 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR))
1843 .RetiresOnSaturation();
1844 EXPECT_CALL(*gl_, GetError())
1845 .WillOnce(Return(GL_NO_ERROR))
1846 .WillOnce(Return(GL_NO_ERROR))
1847 .RetiresOnSaturation();
1849 cmd.Init(GL_TEXTURE_2D);
1850 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1851 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1854 TEST_F(GLES2DecoderWithShaderTest, Uniform1iValidArgs) {
1855 EXPECT_CALL(*gl_, Uniform1i(kUniform1RealLocation, 2));
1857 cmd.Init(kUniform1FakeLocation, 2);
1858 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1861 TEST_F(GLES2DecoderWithShaderTest, Uniform1ivValidArgs) {
1863 *gl_, Uniform1iv(kUniform1RealLocation, 1,
1864 reinterpret_cast<const GLint*>(shared_memory_address_)));
1866 cmd.Init(kUniform1FakeLocation,
1867 1, shared_memory_id_, shared_memory_offset_);
1868 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1871 TEST_F(GLES2DecoderWithShaderTest, Uniform1ivInvalidArgs2_0) {
1872 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1874 cmd.Init(kUniform1FakeLocation,
1875 1, kInvalidSharedMemoryId, 0);
1876 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
1879 TEST_F(GLES2DecoderWithShaderTest, Uniform1ivInvalidArgs2_1) {
1880 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1882 cmd.Init(kUniform1FakeLocation,
1883 1, shared_memory_id_, kInvalidSharedMemoryOffset);
1884 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
1887 TEST_F(GLES2DecoderWithShaderTest, Uniform1ivImmediateValidArgs) {
1888 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1891 Uniform1iv(kUniform1RealLocation, 1,
1892 reinterpret_cast<GLint*>(ImmediateDataAddress(&cmd))));
1893 GLint temp[1 * 2] = { 0, };
1894 cmd.Init(kUniform1FakeLocation, 1,
1896 EXPECT_EQ(error::kNoError,
1897 ExecuteImmediateCmd(cmd, sizeof(temp)));
1900 TEST_F(GLES2DecoderWithShaderTest, Uniform1ivInvalidValidArgs) {
1901 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1903 cmd.Init(kUniform1FakeLocation,
1904 2, shared_memory_id_, shared_memory_offset_);
1905 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1906 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1909 TEST_F(GLES2DecoderWithShaderTest, Uniform1ivZeroCount) {
1910 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1912 cmd.Init(kUniform1FakeLocation,
1913 0, shared_memory_id_, shared_memory_offset_);
1914 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1915 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1918 TEST_F(GLES2DecoderWithShaderTest, Uniform1iSamplerIsLmited) {
1919 EXPECT_CALL(*gl_, Uniform1i(_, _)).Times(0);
1922 kUniform1FakeLocation,
1924 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1925 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1928 TEST_F(GLES2DecoderWithShaderTest, Uniform1ivSamplerIsLimited) {
1929 EXPECT_CALL(*gl_, Uniform1iv(_, _, _)).Times(0);
1930 Uniform1ivImmediate& cmd = *GetImmediateAs<Uniform1ivImmediate>();
1931 GLint temp[] = { kNumTextureUnits };
1932 cmd.Init(kUniform1FakeLocation, 1,
1934 EXPECT_EQ(error::kNoError,
1935 ExecuteImmediateCmd(cmd, sizeof(temp)));
1936 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1939 TEST_F(GLES2DecoderWithShaderTest, BindBufferToDifferentTargetFails) {
1940 // Bind the buffer to GL_ARRAY_BUFFER
1941 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
1942 // Attempt to rebind to GL_ELEMENT_ARRAY_BUFFER
1943 // NOTE: Real GLES2 does not have this restriction but WebGL and we do.
1944 // This can be restriction can be removed at runtime.
1945 EXPECT_CALL(*gl_, BindBuffer(_, _))
1948 cmd.Init(GL_ELEMENT_ARRAY_BUFFER, client_buffer_id_);
1949 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1950 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1953 TEST_F(GLES2DecoderTest, ActiveTextureValidArgs) {
1954 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
1955 SpecializedSetup<ActiveTexture, 0>(true);
1957 cmd.Init(GL_TEXTURE1);
1958 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1959 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1962 TEST_F(GLES2DecoderTest, ActiveTextureInvalidArgs) {
1963 EXPECT_CALL(*gl_, ActiveTexture(_)).Times(0);
1964 SpecializedSetup<ActiveTexture, 0>(false);
1966 cmd.Init(GL_TEXTURE0 - 1);
1967 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1968 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1969 cmd.Init(kNumTextureUnits);
1970 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1971 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1974 TEST_F(GLES2DecoderTest, CheckFramebufferStatusWithNoBoundTarget) {
1975 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(_))
1977 CheckFramebufferStatus::Result* result =
1978 static_cast<CheckFramebufferStatus::Result*>(shared_memory_address_);
1980 CheckFramebufferStatus cmd;
1981 cmd.Init(GL_FRAMEBUFFER, shared_memory_id_, shared_memory_offset_);
1982 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1983 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), *result);
1986 TEST_F(GLES2DecoderWithShaderTest, BindAndDeleteFramebuffer) {
1988 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
1989 SetupExpectationsForApplyingDefaultDirtyState();
1990 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
1991 kServiceFramebufferId);
1992 DoDeleteFramebuffer(
1993 client_framebuffer_id_, kServiceFramebufferId,
1994 true, GL_FRAMEBUFFER, 0,
1995 true, GL_FRAMEBUFFER, 0);
1996 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
1998 .RetiresOnSaturation();
2000 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2001 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2002 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2005 TEST_F(GLES2DecoderTest, FramebufferRenderbufferWithNoBoundTarget) {
2006 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(_, _, _, _))
2008 FramebufferRenderbuffer cmd;
2010 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
2011 client_renderbuffer_id_);
2012 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2013 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2016 TEST_F(GLES2DecoderTest, FramebufferTexture2DWithNoBoundTarget) {
2017 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(_, _, _, _, _))
2019 FramebufferTexture2D cmd;
2021 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, client_texture_id_,
2023 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2024 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2027 TEST_F(GLES2DecoderTest, GetFramebufferAttachmentParameterivWithNoBoundTarget) {
2028 EXPECT_CALL(*gl_, GetError())
2029 .WillOnce(Return(GL_NO_ERROR))
2030 .WillOnce(Return(GL_NO_ERROR))
2031 .RetiresOnSaturation();
2032 EXPECT_CALL(*gl_, GetFramebufferAttachmentParameterivEXT(_, _, _, _))
2034 GetFramebufferAttachmentParameteriv cmd;
2036 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2037 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, shared_memory_id_,
2038 shared_memory_offset_);
2039 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2040 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2043 TEST_F(GLES2DecoderTest, GetFramebufferAttachmentParameterivWithRenderbuffer) {
2044 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
2045 kServiceFramebufferId);
2046 EXPECT_CALL(*gl_, GetError())
2047 .WillOnce(Return(GL_NO_ERROR))
2048 .RetiresOnSaturation();
2049 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
2050 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
2051 kServiceRenderbufferId))
2053 .RetiresOnSaturation();
2054 EXPECT_CALL(*gl_, GetError())
2055 .WillOnce(Return(GL_NO_ERROR))
2056 .RetiresOnSaturation();
2057 EXPECT_CALL(*gl_, GetError())
2058 .WillOnce(Return(GL_NO_ERROR))
2059 .WillOnce(Return(GL_NO_ERROR))
2060 .RetiresOnSaturation();
2061 GetFramebufferAttachmentParameteriv::Result* result =
2062 static_cast<GetFramebufferAttachmentParameteriv::Result*>(
2063 shared_memory_address_);
2065 const GLint* result_value = result->GetData();
2066 FramebufferRenderbuffer fbrb_cmd;
2067 GetFramebufferAttachmentParameteriv cmd;
2069 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
2070 client_renderbuffer_id_);
2072 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2073 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, shared_memory_id_,
2074 shared_memory_offset_);
2075 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
2076 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2077 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2078 EXPECT_EQ(static_cast<GLuint>(*result_value), client_renderbuffer_id_);
2081 TEST_F(GLES2DecoderTest, GetFramebufferAttachmentParameterivWithTexture) {
2082 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
2083 kServiceFramebufferId);
2084 EXPECT_CALL(*gl_, GetError())
2085 .WillOnce(Return(GL_NO_ERROR))
2086 .RetiresOnSaturation();
2087 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(
2088 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
2089 kServiceTextureId, 0))
2091 .RetiresOnSaturation();
2092 EXPECT_CALL(*gl_, GetError())
2093 .WillOnce(Return(GL_NO_ERROR))
2094 .RetiresOnSaturation();
2095 EXPECT_CALL(*gl_, GetError())
2096 .WillOnce(Return(GL_NO_ERROR))
2097 .WillOnce(Return(GL_NO_ERROR))
2098 .RetiresOnSaturation();
2099 GetFramebufferAttachmentParameteriv::Result* result =
2100 static_cast<GetFramebufferAttachmentParameteriv::Result*>(
2101 shared_memory_address_);
2102 result->SetNumResults(0);
2103 const GLint* result_value = result->GetData();
2104 FramebufferTexture2D fbtex_cmd;
2105 GetFramebufferAttachmentParameteriv cmd;
2107 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, client_texture_id_,
2110 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
2111 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME, shared_memory_id_,
2112 shared_memory_offset_);
2113 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd));
2114 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2115 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2116 EXPECT_EQ(static_cast<GLuint>(*result_value), client_texture_id_);
2119 TEST_F(GLES2DecoderTest, GetRenderbufferParameterivWithNoBoundTarget) {
2120 EXPECT_CALL(*gl_, GetError())
2121 .WillOnce(Return(GL_NO_ERROR))
2122 .WillOnce(Return(GL_NO_ERROR))
2123 .RetiresOnSaturation();
2124 EXPECT_CALL(*gl_, GetRenderbufferParameterivEXT(_, _, _))
2126 GetRenderbufferParameteriv cmd;
2128 GL_RENDERBUFFER, GL_RENDERBUFFER_WIDTH, shared_memory_id_,
2129 shared_memory_offset_);
2130 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2131 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2134 TEST_F(GLES2DecoderTest, RenderbufferStorageWithNoBoundTarget) {
2135 EXPECT_CALL(*gl_, RenderbufferStorageEXT(_, _, _, _))
2137 RenderbufferStorage cmd;
2138 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, 3, 4);
2139 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2140 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2145 // A class to emulate glReadPixels
2146 class ReadPixelsEmulator {
2148 // pack_alignment is the alignment you want ReadPixels to use
2149 // when copying. The actual data passed in pixels should be contiguous.
2150 ReadPixelsEmulator(GLsizei width, GLsizei height, GLint bytes_per_pixel,
2151 const void* src_pixels, const void* expected_pixels,
2152 GLint pack_alignment)
2155 pack_alignment_(pack_alignment),
2156 bytes_per_pixel_(bytes_per_pixel),
2157 src_pixels_(reinterpret_cast<const int8*>(src_pixels)),
2158 expected_pixels_(reinterpret_cast<const int8*>(expected_pixels)) {
2162 GLint x, GLint y, GLsizei width, GLsizei height,
2163 GLenum format, GLenum type, void* pixels) const {
2166 DCHECK_LE(x + width, width_);
2167 DCHECK_LE(y + height, height_);
2168 for (GLint yy = 0; yy < height; ++yy) {
2169 const int8* src = GetPixelAddress(src_pixels_, x, y + yy);
2170 const void* dst = ComputePackAlignmentAddress(0, yy, width, pixels);
2171 memcpy(const_cast<void*>(dst), src, width * bytes_per_pixel_);
2175 bool CompareRowSegment(
2176 GLint x, GLint y, GLsizei width, const void* data) const {
2177 DCHECK(x + width <= width_ || width == 0);
2178 return memcmp(data, GetPixelAddress(expected_pixels_, x, y),
2179 width * bytes_per_pixel_) == 0;
2182 // Helper to compute address of pixel in pack aligned data.
2183 const void* ComputePackAlignmentAddress(
2184 GLint x, GLint y, GLsizei width, const void* address) const {
2185 GLint unpadded_row_size = ComputeImageDataSize(width, 1);
2186 GLint two_rows_size = ComputeImageDataSize(width, 2);
2187 GLsizei padded_row_size = two_rows_size - unpadded_row_size;
2188 GLint offset = y * padded_row_size + x * bytes_per_pixel_;
2189 return static_cast<const int8*>(address) + offset;
2192 GLint ComputeImageDataSize(GLint width, GLint height) const {
2193 GLint row_size = width * bytes_per_pixel_;
2195 GLint temp = row_size + pack_alignment_ - 1;
2196 GLint padded_row_size = (temp / pack_alignment_) * pack_alignment_;
2197 GLint size_of_all_but_last_row = (height - 1) * padded_row_size;
2198 return size_of_all_but_last_row + row_size;
2200 return height * row_size;
2205 const int8* GetPixelAddress(const int8* base, GLint x, GLint y) const {
2206 return base + (width_ * y + x) * bytes_per_pixel_;
2211 GLint pack_alignment_;
2212 GLint bytes_per_pixel_;
2213 const int8* src_pixels_;
2214 const int8* expected_pixels_;
2217 } // anonymous namespace
2219 void GLES2DecoderTest::CheckReadPixelsOutOfRange(
2220 GLint in_read_x, GLint in_read_y,
2221 GLsizei in_read_width, GLsizei in_read_height,
2223 const GLsizei kWidth = 5;
2224 const GLsizei kHeight = 3;
2225 const GLint kBytesPerPixel = 3;
2226 const GLint kPackAlignment = 4;
2227 const GLenum kFormat = GL_RGB;
2228 static const int8 kSrcPixels[kWidth * kHeight * kBytesPerPixel] = {
2229 12, 13, 14, 18, 19, 18, 19, 12, 13, 14, 18, 19, 18, 19, 13,
2230 29, 28, 23, 22, 21, 22, 21, 29, 28, 23, 22, 21, 22, 21, 28,
2231 31, 34, 39, 37, 32, 37, 32, 31, 34, 39, 37, 32, 37, 32, 34,
2234 ClearSharedMemory();
2236 // We need to setup an FBO so we can know the max size that ReadPixels will
2239 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2241 GL_TEXTURE_2D, 0, kFormat, kWidth, kHeight, 0,
2242 kFormat, GL_UNSIGNED_BYTE, kSharedMemoryId,
2243 kSharedMemoryOffset);
2245 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2246 DoFramebufferTexture2D(
2247 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
2248 client_texture_id_, kServiceTextureId, 0, GL_NO_ERROR);
2249 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
2250 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
2251 .RetiresOnSaturation();
2254 ReadPixelsEmulator emu(
2255 kWidth, kHeight, kBytesPerPixel, kSrcPixels, kSrcPixels, kPackAlignment);
2256 typedef ReadPixels::Result Result;
2257 Result* result = GetSharedMemoryAs<Result*>();
2258 uint32 result_shm_id = kSharedMemoryId;
2259 uint32 result_shm_offset = kSharedMemoryOffset;
2260 uint32 pixels_shm_id = kSharedMemoryId;
2261 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result);
2262 void* dest = &result[1];
2263 EXPECT_CALL(*gl_, GetError())
2264 .WillOnce(Return(GL_NO_ERROR))
2265 .WillOnce(Return(GL_NO_ERROR))
2266 .RetiresOnSaturation();
2267 // ReadPixels will be called for valid size only even though the command
2268 // is requesting a larger size.
2269 GLint read_x = std::max(0, in_read_x);
2270 GLint read_y = std::max(0, in_read_y);
2271 GLint read_end_x = std::max(0, std::min(kWidth, in_read_x + in_read_width));
2272 GLint read_end_y = std::max(0, std::min(kHeight, in_read_y + in_read_height));
2273 GLint read_width = read_end_x - read_x;
2274 GLint read_height = read_end_y - read_y;
2275 if (read_width > 0 && read_height > 0) {
2276 for (GLint yy = read_y; yy < read_end_y; ++yy) {
2278 *gl_, ReadPixels(read_x, yy, read_width, 1,
2279 kFormat, GL_UNSIGNED_BYTE, _))
2280 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels))
2281 .RetiresOnSaturation();
2285 cmd.Init(in_read_x, in_read_y, in_read_width, in_read_height,
2286 kFormat, GL_UNSIGNED_BYTE,
2287 pixels_shm_id, pixels_shm_offset,
2288 result_shm_id, result_shm_offset,
2290 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2292 GLint unpadded_row_size = emu.ComputeImageDataSize(in_read_width, 1);
2293 scoped_ptr<int8[]> zero(new int8[unpadded_row_size]);
2294 scoped_ptr<int8[]> pack(new int8[kPackAlignment]);
2295 memset(zero.get(), 0, unpadded_row_size);
2296 memset(pack.get(), kInitialMemoryValue, kPackAlignment);
2297 for (GLint yy = 0; yy < in_read_height; ++yy) {
2298 const int8* row = static_cast<const int8*>(
2299 emu.ComputePackAlignmentAddress(0, yy, in_read_width, dest));
2300 GLint y = in_read_y + yy;
2301 if (y < 0 || y >= kHeight) {
2302 EXPECT_EQ(0, memcmp(zero.get(), row, unpadded_row_size));
2305 GLint num_left_pixels = std::max(-in_read_x, 0);
2306 GLint num_left_bytes = num_left_pixels * kBytesPerPixel;
2307 EXPECT_EQ(0, memcmp(zero.get(), row, num_left_bytes));
2310 GLint num_right_pixels = std::max(in_read_x + in_read_width - kWidth, 0);
2311 GLint num_right_bytes = num_right_pixels * kBytesPerPixel;
2312 EXPECT_EQ(0, memcmp(zero.get(),
2313 row + unpadded_row_size - num_right_bytes,
2317 GLint x = std::max(in_read_x, 0);
2318 GLint num_middle_pixels =
2319 std::max(in_read_width - num_left_pixels - num_right_pixels, 0);
2320 EXPECT_TRUE(emu.CompareRowSegment(
2321 x, y, num_middle_pixels, row + num_left_bytes));
2325 if (yy != in_read_height - 1) {
2326 GLint num_padding_bytes =
2327 (kPackAlignment - 1) - (unpadded_row_size % kPackAlignment);
2329 memcmp(pack.get(), row + unpadded_row_size, num_padding_bytes));
2334 TEST_F(GLES2DecoderTest, ReadPixels) {
2335 const GLsizei kWidth = 5;
2336 const GLsizei kHeight = 3;
2337 const GLint kBytesPerPixel = 3;
2338 const GLint kPackAlignment = 4;
2339 static const int8 kSrcPixels[kWidth * kHeight * kBytesPerPixel] = {
2340 12, 13, 14, 18, 19, 18, 19, 12, 13, 14, 18, 19, 18, 19, 13,
2341 29, 28, 23, 22, 21, 22, 21, 29, 28, 23, 22, 21, 22, 21, 28,
2342 31, 34, 39, 37, 32, 37, 32, 31, 34, 39, 37, 32, 37, 32, 34,
2345 surface_->SetSize(gfx::Size(INT_MAX, INT_MAX));
2347 ReadPixelsEmulator emu(
2348 kWidth, kHeight, kBytesPerPixel, kSrcPixels, kSrcPixels, kPackAlignment);
2349 typedef ReadPixels::Result Result;
2350 Result* result = GetSharedMemoryAs<Result*>();
2351 uint32 result_shm_id = kSharedMemoryId;
2352 uint32 result_shm_offset = kSharedMemoryOffset;
2353 uint32 pixels_shm_id = kSharedMemoryId;
2354 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result);
2355 void* dest = &result[1];
2356 EXPECT_CALL(*gl_, GetError())
2357 .WillOnce(Return(GL_NO_ERROR))
2358 .WillOnce(Return(GL_NO_ERROR))
2359 .RetiresOnSaturation();
2361 *gl_, ReadPixels(0, 0, kWidth, kHeight, GL_RGB, GL_UNSIGNED_BYTE, _))
2362 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels));
2364 cmd.Init(0, 0, kWidth, kHeight, GL_RGB, GL_UNSIGNED_BYTE,
2365 pixels_shm_id, pixels_shm_offset,
2366 result_shm_id, result_shm_offset,
2368 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2369 for (GLint yy = 0; yy < kHeight; ++yy) {
2370 EXPECT_TRUE(emu.CompareRowSegment(
2372 emu.ComputePackAlignmentAddress(0, yy, kWidth, dest)));
2376 TEST_F(GLES2DecoderRGBBackbufferTest, ReadPixelsNoAlphaBackbuffer) {
2377 const GLsizei kWidth = 3;
2378 const GLsizei kHeight = 3;
2379 const GLint kBytesPerPixel = 4;
2380 const GLint kPackAlignment = 4;
2381 static const uint8 kExpectedPixels[kWidth * kHeight * kBytesPerPixel] = {
2382 12, 13, 14, 255, 19, 18, 19, 255, 13, 14, 18, 255,
2383 29, 28, 23, 255, 21, 22, 21, 255, 28, 23, 22, 255,
2384 31, 34, 39, 255, 32, 37, 32, 255, 34, 39, 37, 255,
2386 static const uint8 kSrcPixels[kWidth * kHeight * kBytesPerPixel] = {
2387 12, 13, 14, 18, 19, 18, 19, 12, 13, 14, 18, 19,
2388 29, 28, 23, 22, 21, 22, 21, 29, 28, 23, 22, 21,
2389 31, 34, 39, 37, 32, 37, 32, 31, 34, 39, 37, 32,
2392 surface_->SetSize(gfx::Size(INT_MAX, INT_MAX));
2394 ReadPixelsEmulator emu(
2395 kWidth, kHeight, kBytesPerPixel, kSrcPixels, kExpectedPixels,
2397 typedef ReadPixels::Result Result;
2398 Result* result = GetSharedMemoryAs<Result*>();
2399 uint32 result_shm_id = kSharedMemoryId;
2400 uint32 result_shm_offset = kSharedMemoryOffset;
2401 uint32 pixels_shm_id = kSharedMemoryId;
2402 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result);
2403 void* dest = &result[1];
2404 EXPECT_CALL(*gl_, GetError())
2405 .WillOnce(Return(GL_NO_ERROR))
2406 .WillOnce(Return(GL_NO_ERROR))
2407 .RetiresOnSaturation();
2409 *gl_, ReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, _))
2410 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels));
2412 cmd.Init(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
2413 pixels_shm_id, pixels_shm_offset,
2414 result_shm_id, result_shm_offset,
2416 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2417 for (GLint yy = 0; yy < kHeight; ++yy) {
2418 EXPECT_TRUE(emu.CompareRowSegment(
2420 emu.ComputePackAlignmentAddress(0, yy, kWidth, dest)));
2424 TEST_F(GLES2DecoderTest, ReadPixelsOutOfRange) {
2425 static GLint tests[][4] = {
2426 { -2, -1, 9, 5, }, // out of range on all sides
2427 { 2, 1, 9, 5, }, // out of range on right, bottom
2428 { -7, -4, 9, 5, }, // out of range on left, top
2429 { 0, -5, 9, 5, }, // completely off top
2430 { 0, 3, 9, 5, }, // completely off bottom
2431 { -9, 0, 9, 5, }, // completely off left
2432 { 5, 0, 9, 5, }, // completely off right
2435 for (size_t tt = 0; tt < arraysize(tests); ++tt) {
2436 CheckReadPixelsOutOfRange(
2437 tests[tt][0], tests[tt][1], tests[tt][2], tests[tt][3], tt == 0);
2441 TEST_F(GLES2DecoderTest, ReadPixelsInvalidArgs) {
2442 typedef ReadPixels::Result Result;
2443 Result* result = GetSharedMemoryAs<Result*>();
2444 uint32 result_shm_id = kSharedMemoryId;
2445 uint32 result_shm_offset = kSharedMemoryOffset;
2446 uint32 pixels_shm_id = kSharedMemoryId;
2447 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result);
2448 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0);
2450 cmd.Init(0, 0, -1, 1, GL_RGB, GL_UNSIGNED_BYTE,
2451 pixels_shm_id, pixels_shm_offset,
2452 result_shm_id, result_shm_offset,
2454 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2455 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2456 cmd.Init(0, 0, 1, -1, GL_RGB, GL_UNSIGNED_BYTE,
2457 pixels_shm_id, pixels_shm_offset,
2458 result_shm_id, result_shm_offset,
2460 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2461 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2462 cmd.Init(0, 0, 1, 1, GL_RGB, GL_INT,
2463 pixels_shm_id, pixels_shm_offset,
2464 result_shm_id, result_shm_offset,
2466 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2467 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
2468 cmd.Init(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE,
2469 kInvalidSharedMemoryId, pixels_shm_offset,
2470 result_shm_id, result_shm_offset,
2472 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2473 cmd.Init(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE,
2474 pixels_shm_id, kInvalidSharedMemoryOffset,
2475 result_shm_id, result_shm_offset,
2477 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2478 cmd.Init(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE,
2479 pixels_shm_id, pixels_shm_offset,
2480 kInvalidSharedMemoryId, result_shm_offset,
2482 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2483 cmd.Init(0, 0, 1, 1, GL_RGB, GL_UNSIGNED_BYTE,
2484 pixels_shm_id, pixels_shm_offset,
2485 result_shm_id, kInvalidSharedMemoryOffset,
2487 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2490 TEST_F(GLES2DecoderTest, BindAttribLocation) {
2491 const GLint kLocation = 2;
2492 const char* kName = "testing";
2493 const uint32 kNameSize = strlen(kName);
2495 *gl_, BindAttribLocation(kServiceProgramId, kLocation, StrEq(kName)))
2497 memcpy(shared_memory_address_, kName, kNameSize);
2498 BindAttribLocation cmd;
2499 cmd.Init(client_program_id_, kLocation, kSharedMemoryId, kSharedMemoryOffset,
2501 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2504 TEST_F(GLES2DecoderTest, BindAttribLocationInvalidArgs) {
2505 const GLint kLocation = 2;
2506 const char* kName = "testing";
2507 const char* kBadName = "test\aing";
2508 const uint32 kNameSize = strlen(kName);
2509 const uint32 kBadNameSize = strlen(kBadName);
2510 EXPECT_CALL(*gl_, BindAttribLocation(_, _, _)).Times(0);
2511 memcpy(shared_memory_address_, kName, kNameSize);
2512 BindAttribLocation cmd;
2513 cmd.Init(kInvalidClientId, kLocation,
2514 kSharedMemoryId, kSharedMemoryOffset, kNameSize);
2515 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2516 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2517 cmd.Init(client_program_id_, kLocation,
2518 kInvalidSharedMemoryId, kSharedMemoryOffset, kNameSize);
2519 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2520 cmd.Init(client_program_id_, kLocation,
2521 kSharedMemoryId, kInvalidSharedMemoryOffset, kNameSize);
2522 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2523 cmd.Init(client_program_id_, kLocation,
2524 kSharedMemoryId, kSharedMemoryOffset, kSharedBufferSize);
2525 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2526 memcpy(shared_memory_address_, kBadName, kBadNameSize);
2527 cmd.Init(client_program_id_, kLocation,
2528 kSharedMemoryId, kSharedMemoryOffset, kBadNameSize);
2529 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2530 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2533 TEST_F(GLES2DecoderTest, BindAttribLocationBucket) {
2534 const uint32 kBucketId = 123;
2535 const GLint kLocation = 2;
2536 const char* kName = "testing";
2538 *gl_, BindAttribLocation(kServiceProgramId, kLocation, StrEq(kName)))
2540 SetBucketAsCString(kBucketId, kName);
2541 BindAttribLocationBucket cmd;
2542 cmd.Init(client_program_id_, kLocation, kBucketId);
2543 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2546 TEST_F(GLES2DecoderTest, BindAttribLocationBucketInvalidArgs) {
2547 const uint32 kBucketId = 123;
2548 const GLint kLocation = 2;
2549 const char* kName = "testing";
2550 EXPECT_CALL(*gl_, BindAttribLocation(_, _, _)).Times(0);
2551 BindAttribLocationBucket cmd;
2552 // check bucket does not exist.
2553 cmd.Init(client_program_id_, kLocation, kBucketId);
2554 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2555 // check bucket is empty.
2556 SetBucketAsCString(kBucketId, NULL);
2557 cmd.Init(client_program_id_, kLocation, kBucketId);
2558 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2559 // Check bad program id
2560 SetBucketAsCString(kBucketId, kName);
2561 cmd.Init(kInvalidClientId, kLocation, kBucketId);
2562 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2563 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2566 TEST_F(GLES2DecoderWithShaderTest, GetAttribLocation) {
2567 const uint32 kNameSize = strlen(kAttrib2Name);
2568 const char* kNonExistentName = "foobar";
2569 const uint32 kNonExistentNameSize = strlen(kNonExistentName);
2570 typedef GetAttribLocation::Result Result;
2571 Result* result = GetSharedMemoryAs<Result*>();
2573 char* name = GetSharedMemoryAsWithOffset<char*>(sizeof(*result));
2574 const uint32 kNameOffset = kSharedMemoryOffset + sizeof(*result);
2575 memcpy(name, kAttrib2Name, kNameSize);
2576 GetAttribLocation cmd;
2577 cmd.Init(client_program_id_,
2578 kSharedMemoryId, kNameOffset,
2579 kSharedMemoryId, kSharedMemoryOffset,
2581 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2582 EXPECT_EQ(kAttrib2Location, *result);
2584 memcpy(name, kNonExistentName, kNonExistentNameSize);
2585 cmd.Init(client_program_id_,
2586 kSharedMemoryId, kNameOffset,
2587 kSharedMemoryId, kSharedMemoryOffset,
2588 kNonExistentNameSize);
2589 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2590 EXPECT_EQ(-1, *result);
2593 TEST_F(GLES2DecoderWithShaderTest, GetAttribLocationInvalidArgs) {
2594 const uint32 kNameSize = strlen(kAttrib2Name);
2595 const char* kBadName = "foo\abar";
2596 const uint32 kBadNameSize = strlen(kBadName);
2597 typedef GetAttribLocation::Result Result;
2598 Result* result = GetSharedMemoryAs<Result*>();
2600 char* name = GetSharedMemoryAsWithOffset<char*>(sizeof(*result));
2601 const uint32 kNameOffset = kSharedMemoryOffset + sizeof(*result);
2602 memcpy(name, kAttrib2Name, kNameSize);
2603 GetAttribLocation cmd;
2604 cmd.Init(kInvalidClientId,
2605 kSharedMemoryId, kNameOffset,
2606 kSharedMemoryId, kSharedMemoryOffset,
2608 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2609 EXPECT_EQ(-1, *result);
2610 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2612 cmd.Init(client_program_id_,
2613 kInvalidSharedMemoryId, kNameOffset,
2614 kSharedMemoryId, kSharedMemoryOffset,
2616 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2617 EXPECT_EQ(-1, *result);
2618 cmd.Init(client_program_id_,
2619 kSharedMemoryId, kInvalidSharedMemoryOffset,
2620 kSharedMemoryId, kSharedMemoryOffset,
2622 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2623 EXPECT_EQ(-1, *result);
2624 cmd.Init(client_program_id_,
2625 kSharedMemoryId, kNameOffset,
2626 kInvalidSharedMemoryId, kSharedMemoryOffset,
2628 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2629 EXPECT_EQ(-1, *result);
2630 cmd.Init(client_program_id_,
2631 kSharedMemoryId, kNameOffset,
2632 kSharedMemoryId, kInvalidSharedMemoryOffset,
2634 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2635 EXPECT_EQ(-1, *result);
2636 cmd.Init(client_program_id_,
2637 kSharedMemoryId, kNameOffset,
2638 kSharedMemoryId, kSharedMemoryOffset,
2640 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2641 EXPECT_EQ(-1, *result);
2642 memcpy(name, kBadName, kBadNameSize);
2643 cmd.Init(client_program_id_,
2644 kSharedMemoryId, kNameOffset,
2645 kSharedMemoryId, kSharedMemoryOffset,
2647 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2648 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2651 TEST_F(GLES2DecoderWithShaderTest, GetAttribLocationBucket) {
2652 const uint32 kBucketId = 123;
2653 const char* kNonExistentName = "foobar";
2654 typedef GetAttribLocationBucket::Result Result;
2655 Result* result = GetSharedMemoryAs<Result*>();
2656 SetBucketAsCString(kBucketId, kAttrib2Name);
2658 GetAttribLocationBucket cmd;
2659 cmd.Init(client_program_id_, kBucketId,
2660 kSharedMemoryId, kSharedMemoryOffset);
2661 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2662 EXPECT_EQ(kAttrib2Location, *result);
2663 SetBucketAsCString(kBucketId, kNonExistentName);
2665 cmd.Init(client_program_id_, kBucketId,
2666 kSharedMemoryId, kSharedMemoryOffset);
2667 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2668 EXPECT_EQ(-1, *result);
2671 TEST_F(GLES2DecoderWithShaderTest, GetAttribLocationBucketInvalidArgs) {
2672 const uint32 kBucketId = 123;
2673 typedef GetAttribLocationBucket::Result Result;
2674 Result* result = GetSharedMemoryAs<Result*>();
2676 GetAttribLocationBucket cmd;
2678 cmd.Init(client_program_id_, kBucketId,
2679 kSharedMemoryId, kSharedMemoryOffset);
2680 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2681 EXPECT_EQ(-1, *result);
2682 // Check bad program id.
2683 SetBucketAsCString(kBucketId, kAttrib2Name);
2684 cmd.Init(kInvalidClientId, kBucketId,
2685 kSharedMemoryId, kSharedMemoryOffset);
2687 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2688 EXPECT_EQ(-1, *result);
2689 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2691 cmd.Init(client_program_id_, kBucketId,
2692 kInvalidSharedMemoryId, kSharedMemoryOffset);
2693 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2694 cmd.Init(client_program_id_, kBucketId,
2695 kSharedMemoryId, kInvalidSharedMemoryOffset);
2696 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2699 TEST_F(GLES2DecoderWithShaderTest, GetUniformLocation) {
2700 const uint32 kNameSize = strlen(kUniform2Name);
2701 const char* kNonExistentName = "foobar";
2702 const uint32 kNonExistentNameSize = strlen(kNonExistentName);
2703 typedef GetUniformLocation::Result Result;
2704 Result* result = GetSharedMemoryAs<Result*>();
2706 char* name = GetSharedMemoryAsWithOffset<char*>(sizeof(*result));
2707 const uint32 kNameOffset = kSharedMemoryOffset + sizeof(*result);
2708 memcpy(name, kUniform2Name, kNameSize);
2709 GetUniformLocation cmd;
2710 cmd.Init(client_program_id_,
2711 kSharedMemoryId, kNameOffset,
2712 kSharedMemoryId, kSharedMemoryOffset,
2714 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2715 EXPECT_EQ(kUniform2FakeLocation, *result);
2716 memcpy(name, kNonExistentName, kNonExistentNameSize);
2718 cmd.Init(client_program_id_,
2719 kSharedMemoryId, kNameOffset,
2720 kSharedMemoryId, kSharedMemoryOffset,
2721 kNonExistentNameSize);
2722 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2723 EXPECT_EQ(-1, *result);
2726 TEST_F(GLES2DecoderWithShaderTest, GetUniformLocationInvalidArgs) {
2727 const uint32 kNameSize = strlen(kUniform2Name);
2728 const char* kBadName = "foo\abar";
2729 const uint32 kBadNameSize = strlen(kBadName);
2730 typedef GetUniformLocation::Result Result;
2731 Result* result = GetSharedMemoryAs<Result*>();
2733 char* name = GetSharedMemoryAsWithOffset<char*>(sizeof(*result));
2734 const uint32 kNameOffset = kSharedMemoryOffset + sizeof(*result);
2735 memcpy(name, kUniform2Name, kNameSize);
2736 GetUniformLocation cmd;
2737 cmd.Init(kInvalidClientId,
2738 kSharedMemoryId, kNameOffset,
2739 kSharedMemoryId, kSharedMemoryOffset,
2741 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2742 EXPECT_EQ(-1, *result);
2743 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2745 cmd.Init(client_program_id_,
2746 kInvalidSharedMemoryId, kNameOffset,
2747 kSharedMemoryId, kSharedMemoryOffset,
2749 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2750 EXPECT_EQ(-1, *result);
2751 cmd.Init(client_program_id_,
2752 kSharedMemoryId, kInvalidSharedMemoryOffset,
2753 kSharedMemoryId, kSharedMemoryOffset,
2755 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2756 EXPECT_EQ(-1, *result);
2757 cmd.Init(client_program_id_,
2758 kSharedMemoryId, kNameOffset,
2759 kInvalidSharedMemoryId, kSharedMemoryOffset,
2761 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2762 EXPECT_EQ(-1, *result);
2763 cmd.Init(client_program_id_,
2764 kSharedMemoryId, kNameOffset,
2765 kSharedMemoryId, kInvalidSharedMemoryOffset,
2767 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2768 EXPECT_EQ(-1, *result);
2769 cmd.Init(client_program_id_,
2770 kSharedMemoryId, kNameOffset,
2771 kSharedMemoryId, kSharedMemoryOffset,
2773 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2774 EXPECT_EQ(-1, *result);
2775 memcpy(name, kBadName, kBadNameSize);
2776 cmd.Init(client_program_id_,
2777 kSharedMemoryId, kNameOffset,
2778 kSharedMemoryId, kSharedMemoryOffset,
2780 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2781 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2784 TEST_F(GLES2DecoderWithShaderTest, GetUniformLocationBucket) {
2785 const uint32 kBucketId = 123;
2786 const char* kNonExistentName = "foobar";
2787 typedef GetUniformLocationBucket::Result Result;
2788 Result* result = GetSharedMemoryAs<Result*>();
2789 SetBucketAsCString(kBucketId, kUniform2Name);
2791 GetUniformLocationBucket cmd;
2792 cmd.Init(client_program_id_, kBucketId,
2793 kSharedMemoryId, kSharedMemoryOffset);
2794 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2795 EXPECT_EQ(kUniform2FakeLocation, *result);
2796 SetBucketAsCString(kBucketId, kNonExistentName);
2798 cmd.Init(client_program_id_, kBucketId,
2799 kSharedMemoryId, kSharedMemoryOffset);
2800 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2801 EXPECT_EQ(-1, *result);
2804 TEST_F(GLES2DecoderWithShaderTest, GetUniformLocationBucketInvalidArgs) {
2805 const uint32 kBucketId = 123;
2806 typedef GetUniformLocationBucket::Result Result;
2807 Result* result = GetSharedMemoryAs<Result*>();
2809 GetUniformLocationBucket cmd;
2811 cmd.Init(client_program_id_, kBucketId,
2812 kSharedMemoryId, kSharedMemoryOffset);
2813 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2814 EXPECT_EQ(-1, *result);
2815 // Check bad program id.
2816 SetBucketAsCString(kBucketId, kUniform2Name);
2817 cmd.Init(kInvalidClientId, kBucketId,
2818 kSharedMemoryId, kSharedMemoryOffset);
2820 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2821 EXPECT_EQ(-1, *result);
2822 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2824 cmd.Init(client_program_id_, kBucketId,
2825 kInvalidSharedMemoryId, kSharedMemoryOffset);
2826 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2827 cmd.Init(client_program_id_, kBucketId,
2828 kSharedMemoryId, kInvalidSharedMemoryOffset);
2829 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2832 TEST_F(GLES2DecoderWithShaderTest, GetMaxValueInBufferCHROMIUM) {
2834 GetMaxValueInBufferCHROMIUM::Result* result =
2835 static_cast<GetMaxValueInBufferCHROMIUM::Result*>(shared_memory_address_);
2838 GetMaxValueInBufferCHROMIUM cmd;
2839 cmd.Init(client_element_buffer_id_, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
2840 kValidIndexRangeStart * 2, kSharedMemoryId, kSharedMemoryOffset);
2841 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2842 EXPECT_EQ(7u, *result);
2843 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2844 cmd.Init(client_element_buffer_id_, kValidIndexRangeCount + 1,
2846 kValidIndexRangeStart * 2, kSharedMemoryId, kSharedMemoryOffset);
2847 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2848 EXPECT_EQ(100u, *result);
2849 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2851 cmd.Init(kInvalidClientId, kValidIndexRangeCount,
2853 kValidIndexRangeStart * 2, kSharedMemoryId, kSharedMemoryOffset);
2854 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2855 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2856 cmd.Init(client_element_buffer_id_, kOutOfRangeIndexRangeEnd,
2858 kValidIndexRangeStart * 2, kSharedMemoryId, kSharedMemoryOffset);
2859 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2860 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2861 cmd.Init(client_element_buffer_id_, kValidIndexRangeCount + 1,
2863 kOutOfRangeIndexRangeEnd * 2, kSharedMemoryId, kSharedMemoryOffset);
2864 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2865 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2866 cmd.Init(client_element_buffer_id_, kValidIndexRangeCount + 1,
2868 kValidIndexRangeStart * 2, kSharedMemoryId, kSharedMemoryOffset);
2869 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2870 cmd.Init(client_buffer_id_, kValidIndexRangeCount + 1,
2872 kValidIndexRangeStart * 2, kSharedMemoryId, kSharedMemoryOffset);
2873 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2874 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2875 cmd.Init(client_element_buffer_id_, kValidIndexRangeCount + 1,
2877 kValidIndexRangeStart * 2,
2878 kInvalidSharedMemoryId, kSharedMemoryOffset);
2879 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2880 cmd.Init(client_element_buffer_id_, kValidIndexRangeCount + 1,
2882 kValidIndexRangeStart * 2,
2883 kSharedMemoryId, kInvalidSharedMemoryOffset);
2884 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2887 TEST_F(GLES2DecoderTest, SharedIds) {
2888 GenSharedIdsCHROMIUM gen_cmd;
2889 RegisterSharedIdsCHROMIUM reg_cmd;
2890 DeleteSharedIdsCHROMIUM del_cmd;
2892 const GLuint kNamespaceId = id_namespaces::kTextures;
2893 const GLuint kExpectedId1 = 1;
2894 const GLuint kExpectedId2 = 2;
2895 const GLuint kExpectedId3 = 4;
2896 const GLuint kRegisterId = 3;
2897 GLuint* ids = GetSharedMemoryAs<GLuint*>();
2898 gen_cmd.Init(kNamespaceId, 0, 2, kSharedMemoryId, kSharedMemoryOffset);
2899 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
2900 IdAllocatorInterface* id_allocator = GetIdAllocator(kNamespaceId);
2901 ASSERT_TRUE(id_allocator != NULL);
2902 // This check is implementation dependant but it's kind of hard to check
2904 EXPECT_EQ(kExpectedId1, ids[0]);
2905 EXPECT_EQ(kExpectedId2, ids[1]);
2906 EXPECT_TRUE(id_allocator->InUse(kExpectedId1));
2907 EXPECT_TRUE(id_allocator->InUse(kExpectedId2));
2908 EXPECT_FALSE(id_allocator->InUse(kRegisterId));
2909 EXPECT_FALSE(id_allocator->InUse(kExpectedId3));
2911 ClearSharedMemory();
2912 ids[0] = kRegisterId;
2913 reg_cmd.Init(kNamespaceId, 1, kSharedMemoryId, kSharedMemoryOffset);
2914 EXPECT_EQ(error::kNoError, ExecuteCmd(reg_cmd));
2915 EXPECT_TRUE(id_allocator->InUse(kExpectedId1));
2916 EXPECT_TRUE(id_allocator->InUse(kExpectedId2));
2917 EXPECT_TRUE(id_allocator->InUse(kRegisterId));
2918 EXPECT_FALSE(id_allocator->InUse(kExpectedId3));
2920 ClearSharedMemory();
2921 gen_cmd.Init(kNamespaceId, 0, 1, kSharedMemoryId, kSharedMemoryOffset);
2922 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
2923 EXPECT_EQ(kExpectedId3, ids[0]);
2924 EXPECT_TRUE(id_allocator->InUse(kExpectedId1));
2925 EXPECT_TRUE(id_allocator->InUse(kExpectedId2));
2926 EXPECT_TRUE(id_allocator->InUse(kRegisterId));
2927 EXPECT_TRUE(id_allocator->InUse(kExpectedId3));
2929 ClearSharedMemory();
2930 ids[0] = kExpectedId1;
2931 ids[1] = kRegisterId;
2932 del_cmd.Init(kNamespaceId, 2, kSharedMemoryId, kSharedMemoryOffset);
2933 EXPECT_EQ(error::kNoError, ExecuteCmd(del_cmd));
2934 EXPECT_FALSE(id_allocator->InUse(kExpectedId1));
2935 EXPECT_TRUE(id_allocator->InUse(kExpectedId2));
2936 EXPECT_FALSE(id_allocator->InUse(kRegisterId));
2937 EXPECT_TRUE(id_allocator->InUse(kExpectedId3));
2939 ClearSharedMemory();
2940 ids[0] = kExpectedId3;
2941 ids[1] = kExpectedId2;
2942 del_cmd.Init(kNamespaceId, 2, kSharedMemoryId, kSharedMemoryOffset);
2943 EXPECT_EQ(error::kNoError, ExecuteCmd(del_cmd));
2944 EXPECT_FALSE(id_allocator->InUse(kExpectedId1));
2945 EXPECT_FALSE(id_allocator->InUse(kExpectedId2));
2946 EXPECT_FALSE(id_allocator->InUse(kRegisterId));
2947 EXPECT_FALSE(id_allocator->InUse(kExpectedId3));
2949 // Check passing in an id_offset.
2950 ClearSharedMemory();
2951 const GLuint kOffset = 0xABCDEF;
2952 gen_cmd.Init(kNamespaceId, kOffset, 2, kSharedMemoryId, kSharedMemoryOffset);
2953 EXPECT_EQ(error::kNoError, ExecuteCmd(gen_cmd));
2954 EXPECT_EQ(kOffset, ids[0]);
2955 EXPECT_EQ(kOffset + 1, ids[1]);
2958 TEST_F(GLES2DecoderTest, GenSharedIdsCHROMIUMBadArgs) {
2959 const GLuint kNamespaceId = id_namespaces::kTextures;
2960 GenSharedIdsCHROMIUM cmd;
2961 cmd.Init(kNamespaceId, 0, -1, kSharedMemoryId, kSharedMemoryOffset);
2962 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2963 cmd.Init(kNamespaceId, 0, 1, kInvalidSharedMemoryId, kSharedMemoryOffset);
2964 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2965 cmd.Init(kNamespaceId, 0, 1, kSharedMemoryId, kInvalidSharedMemoryOffset);
2966 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2969 TEST_F(GLES2DecoderTest, RegisterSharedIdsCHROMIUMBadArgs) {
2970 const GLuint kNamespaceId = id_namespaces::kTextures;
2971 RegisterSharedIdsCHROMIUM cmd;
2972 cmd.Init(kNamespaceId, -1, kSharedMemoryId, kSharedMemoryOffset);
2973 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2974 cmd.Init(kNamespaceId, 1, kInvalidSharedMemoryId, kSharedMemoryOffset);
2975 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2976 cmd.Init(kNamespaceId, 1, kSharedMemoryId, kInvalidSharedMemoryOffset);
2977 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2980 TEST_F(GLES2DecoderTest, RegisterSharedIdsCHROMIUMDuplicateIds) {
2981 const GLuint kNamespaceId = id_namespaces::kTextures;
2982 const GLuint kRegisterId = 3;
2983 RegisterSharedIdsCHROMIUM cmd;
2984 GLuint* ids = GetSharedMemoryAs<GLuint*>();
2985 ids[0] = kRegisterId;
2986 cmd.Init(kNamespaceId, 1, kSharedMemoryId, kSharedMemoryOffset);
2987 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2988 cmd.Init(kNamespaceId, 1, kSharedMemoryId, kSharedMemoryOffset);
2989 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2990 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
2993 TEST_F(GLES2DecoderTest, DeleteSharedIdsCHROMIUMBadArgs) {
2994 const GLuint kNamespaceId = id_namespaces::kTextures;
2995 DeleteSharedIdsCHROMIUM cmd;
2996 cmd.Init(kNamespaceId, -1, kSharedMemoryId, kSharedMemoryOffset);
2997 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
2998 cmd.Init(kNamespaceId, 1, kInvalidSharedMemoryId, kSharedMemoryOffset);
2999 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
3000 cmd.Init(kNamespaceId, 1, kSharedMemoryId, kInvalidSharedMemoryOffset);
3001 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
3004 TEST_F(GLES2DecoderTest, TexSubImage2DValidArgs) {
3005 const int kWidth = 16;
3006 const int kHeight = 8;
3007 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
3009 GL_TEXTURE_2D, 1, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3010 kSharedMemoryId, kSharedMemoryOffset);
3011 EXPECT_CALL(*gl_, TexSubImage2D(
3012 GL_TEXTURE_2D, 1, 1, 0, kWidth - 1, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
3013 shared_memory_address_))
3015 .RetiresOnSaturation();
3018 GL_TEXTURE_2D, 1, 1, 0, kWidth - 1, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
3019 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3020 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3021 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3024 TEST_F(GLES2DecoderTest, TexSubImage2DBadArgs) {
3025 const int kWidth = 16;
3026 const int kHeight = 8;
3027 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
3029 GL_TEXTURE_2D, 1, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3032 cmd.Init(GL_TEXTURE0, 1, 0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
3033 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3034 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3035 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
3036 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_TRUE, GL_UNSIGNED_BYTE,
3037 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3038 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3039 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
3040 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_INT,
3041 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3042 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3043 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
3044 cmd.Init(GL_TEXTURE_2D, 1, -1, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
3045 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3046 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3047 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3048 cmd.Init(GL_TEXTURE_2D, 1, 1, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
3049 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3050 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3051 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3052 cmd.Init(GL_TEXTURE_2D, 1, 0, -1, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
3053 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3054 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3055 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3056 cmd.Init(GL_TEXTURE_2D, 1, 0, 1, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
3057 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3058 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3059 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3060 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth + 1, kHeight, GL_RGBA,
3061 GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3062 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3063 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3064 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight + 1, GL_RGBA,
3065 GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3066 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3067 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3068 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_RGB, GL_UNSIGNED_BYTE,
3069 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3070 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3071 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
3072 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_RGBA,
3073 GL_UNSIGNED_SHORT_4_4_4_4, kSharedMemoryId, kSharedMemoryOffset,
3075 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3076 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
3077 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
3078 kInvalidSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3079 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
3080 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE,
3081 kSharedMemoryId, kInvalidSharedMemoryOffset, GL_FALSE);
3082 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
3085 TEST_F(GLES2DecoderTest, CopyTexSubImage2DValidArgs) {
3086 const int kWidth = 16;
3087 const int kHeight = 8;
3088 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
3090 GL_TEXTURE_2D, 1, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3091 kSharedMemoryId, kSharedMemoryOffset);
3092 EXPECT_CALL(*gl_, CopyTexSubImage2D(
3093 GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight))
3095 .RetiresOnSaturation();
3096 CopyTexSubImage2D cmd;
3097 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight);
3098 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3099 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3102 TEST_F(GLES2DecoderTest, CopyTexSubImage2DBadArgs) {
3103 const int kWidth = 16;
3104 const int kHeight = 8;
3105 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
3107 GL_TEXTURE_2D, 1, GL_RGBA, kWidth, kHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE,
3109 CopyTexSubImage2D cmd;
3110 cmd.Init(GL_TEXTURE0, 1, 0, 0, 0, 0, kWidth, kHeight);
3111 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3112 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
3113 cmd.Init(GL_TEXTURE_2D, 1, -1, 0, 0, 0, kWidth, kHeight);
3114 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3115 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3116 cmd.Init(GL_TEXTURE_2D, 1, 1, 0, 0, 0, kWidth, kHeight);
3117 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3118 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3119 cmd.Init(GL_TEXTURE_2D, 1, 0, -1, 0, 0, kWidth, kHeight);
3120 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3121 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3122 cmd.Init(GL_TEXTURE_2D, 1, 0, 1, 0, 0, kWidth, kHeight);
3123 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3124 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3125 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth + 1, kHeight);
3126 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3127 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3128 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight + 1);
3129 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3130 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3133 // Check that if a renderbuffer is attached and GL returns
3134 // GL_FRAMEBUFFER_COMPLETE that the buffer is cleared and state is restored.
3135 TEST_F(GLES2DecoderTest, FramebufferRenderbufferClearColor) {
3136 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
3137 kServiceFramebufferId);
3138 ClearColor color_cmd;
3139 ColorMask color_mask_cmd;
3141 FramebufferRenderbuffer cmd;
3142 color_cmd.Init(0.1f, 0.2f, 0.3f, 0.4f);
3143 color_mask_cmd.Init(0, 1, 0, 1);
3144 enable_cmd.Init(GL_SCISSOR_TEST);
3146 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3147 client_renderbuffer_id_);
3148 InSequence sequence;
3149 EXPECT_CALL(*gl_, ClearColor(0.1f, 0.2f, 0.3f, 0.4f))
3151 .RetiresOnSaturation();
3152 EXPECT_CALL(*gl_, GetError())
3153 .WillOnce(Return(GL_NO_ERROR))
3154 .RetiresOnSaturation();
3155 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
3156 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
3157 kServiceRenderbufferId))
3159 .RetiresOnSaturation();
3160 EXPECT_CALL(*gl_, GetError())
3161 .WillOnce(Return(GL_NO_ERROR))
3162 .RetiresOnSaturation();
3163 EXPECT_EQ(error::kNoError, ExecuteCmd(color_cmd));
3164 EXPECT_EQ(error::kNoError, ExecuteCmd(color_mask_cmd));
3165 EXPECT_EQ(error::kNoError, ExecuteCmd(enable_cmd));
3166 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3169 TEST_F(GLES2DecoderTest, FramebufferRenderbufferClearDepth) {
3170 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
3171 kServiceFramebufferId);
3172 ClearDepthf depth_cmd;
3173 DepthMask depth_mask_cmd;
3174 FramebufferRenderbuffer cmd;
3175 depth_cmd.Init(0.5f);
3176 depth_mask_cmd.Init(false);
3178 GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
3179 client_renderbuffer_id_);
3180 InSequence sequence;
3181 EXPECT_CALL(*gl_, ClearDepth(0.5f))
3183 .RetiresOnSaturation();
3184 EXPECT_CALL(*gl_, GetError())
3185 .WillOnce(Return(GL_NO_ERROR))
3186 .RetiresOnSaturation();
3187 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
3188 GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
3189 kServiceRenderbufferId))
3191 .RetiresOnSaturation();
3192 EXPECT_CALL(*gl_, GetError())
3193 .WillOnce(Return(GL_NO_ERROR))
3194 .RetiresOnSaturation();
3195 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_cmd));
3196 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_mask_cmd));
3197 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3200 TEST_F(GLES2DecoderTest, FramebufferRenderbufferClearStencil) {
3201 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
3202 kServiceFramebufferId);
3203 ClearStencil stencil_cmd;
3204 StencilMaskSeparate stencil_mask_separate_cmd;
3205 FramebufferRenderbuffer cmd;
3206 stencil_cmd.Init(123);
3207 stencil_mask_separate_cmd.Init(GL_BACK, 0x1234u);
3209 GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3210 client_renderbuffer_id_);
3211 InSequence sequence;
3212 EXPECT_CALL(*gl_, ClearStencil(123))
3214 .RetiresOnSaturation();
3215 EXPECT_CALL(*gl_, GetError())
3216 .WillOnce(Return(GL_NO_ERROR))
3217 .RetiresOnSaturation();
3218 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
3219 GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3220 kServiceRenderbufferId))
3222 .RetiresOnSaturation();
3223 EXPECT_CALL(*gl_, GetError())
3224 .WillOnce(Return(GL_NO_ERROR))
3225 .RetiresOnSaturation();
3226 EXPECT_EQ(error::kNoError, ExecuteCmd(stencil_cmd));
3227 EXPECT_EQ(error::kNoError, ExecuteCmd(stencil_mask_separate_cmd));
3228 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3231 TEST_F(GLES2DecoderTest, IsBuffer) {
3232 EXPECT_FALSE(DoIsBuffer(client_buffer_id_));
3233 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
3234 EXPECT_TRUE(DoIsBuffer(client_buffer_id_));
3235 DoDeleteBuffer(client_buffer_id_, kServiceBufferId);
3236 EXPECT_FALSE(DoIsBuffer(client_buffer_id_));
3239 TEST_F(GLES2DecoderTest, IsFramebuffer) {
3240 EXPECT_FALSE(DoIsFramebuffer(client_framebuffer_id_));
3241 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
3242 kServiceFramebufferId);
3243 EXPECT_TRUE(DoIsFramebuffer(client_framebuffer_id_));
3244 DoDeleteFramebuffer(
3245 client_framebuffer_id_, kServiceFramebufferId,
3246 true, GL_FRAMEBUFFER, 0,
3247 true, GL_FRAMEBUFFER, 0);
3248 EXPECT_FALSE(DoIsFramebuffer(client_framebuffer_id_));
3251 TEST_F(GLES2DecoderTest, IsProgram) {
3252 // IsProgram is true as soon as the program is created.
3253 EXPECT_TRUE(DoIsProgram(client_program_id_));
3254 EXPECT_CALL(*gl_, DeleteProgram(kServiceProgramId))
3256 .RetiresOnSaturation();
3257 DoDeleteProgram(client_program_id_, kServiceProgramId);
3258 EXPECT_FALSE(DoIsProgram(client_program_id_));
3262 TEST_F(GLES2DecoderTest, IsRenderbuffer) {
3263 EXPECT_FALSE(DoIsRenderbuffer(client_renderbuffer_id_));
3264 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
3265 kServiceRenderbufferId);
3266 EXPECT_TRUE(DoIsRenderbuffer(client_renderbuffer_id_));
3267 DoDeleteRenderbuffer(client_renderbuffer_id_, kServiceRenderbufferId);
3268 EXPECT_FALSE(DoIsRenderbuffer(client_renderbuffer_id_));
3271 TEST_F(GLES2DecoderTest, IsShader) {
3272 // IsShader is true as soon as the program is created.
3273 EXPECT_TRUE(DoIsShader(client_shader_id_));
3274 DoDeleteShader(client_shader_id_, kServiceShaderId);
3275 EXPECT_FALSE(DoIsShader(client_shader_id_));
3278 TEST_F(GLES2DecoderTest, IsTexture) {
3279 EXPECT_FALSE(DoIsTexture(client_texture_id_));
3280 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
3281 EXPECT_TRUE(DoIsTexture(client_texture_id_));
3282 DoDeleteTexture(client_texture_id_, kServiceTextureId);
3283 EXPECT_FALSE(DoIsTexture(client_texture_id_));
3286 #if 0 // Turn this test on once we allow GL_DEPTH_STENCIL_ATTACHMENT
3287 TEST_F(GLES2DecoderTest, FramebufferRenderbufferClearDepthStencil) {
3288 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
3289 kServiceFramebufferId);
3290 ClearDepthf depth_cmd;
3291 ClearStencil stencil_cmd;
3292 FramebufferRenderbuffer cmd;
3293 depth_cmd.Init(0.5f);
3294 stencil_cmd.Init(123);
3296 GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3297 client_renderbuffer_id_);
3298 InSequence sequence;
3299 EXPECT_CALL(*gl_, ClearDepth(0.5f))
3301 .RetiresOnSaturation();
3302 EXPECT_CALL(*gl_, ClearStencil(123))
3304 .RetiresOnSaturation();
3305 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
3306 GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
3307 kServiceRenderbufferId))
3309 .RetiresOnSaturation();
3310 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_cmd));
3311 EXPECT_EQ(error::kNoError, ExecuteCmd(stencil_cmd));
3312 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3316 TEST_F(GLES2DecoderWithShaderTest, VertexAttribPointer) {
3317 SetupVertexBuffer();
3318 static const GLenum types[] = {
3328 static const GLsizei sizes[] = {
3338 static const GLuint indices[] = {
3341 kNumVertexAttribs - 1,
3344 static const GLsizei offset_mult[] = {
3352 static const GLsizei offset_offset[] = {
3360 static const GLsizei stride_mult[] = {
3369 static const GLsizei stride_offset[] = {
3378 for (size_t tt = 0; tt < arraysize(types); ++tt) {
3379 GLenum type = types[tt];
3380 GLsizei num_bytes = sizes[tt];
3381 for (size_t ii = 0; ii < arraysize(indices); ++ii) {
3382 GLuint index = indices[ii];
3383 for (GLint size = 0; size < 5; ++size) {
3384 for (size_t oo = 0; oo < arraysize(offset_mult); ++oo) {
3385 GLuint offset = num_bytes * offset_mult[oo] + offset_offset[oo];
3386 for (size_t ss = 0; ss < arraysize(stride_mult); ++ss) {
3387 GLsizei stride = num_bytes * stride_mult[ss] + stride_offset[ss];
3388 for (int normalize = 0; normalize < 2; ++normalize) {
3389 bool index_good = index < static_cast<GLuint>(kNumVertexAttribs);
3390 bool size_good = (size > 0 && size < 5);
3391 bool offset_good = (offset % num_bytes == 0);
3392 bool stride_good = (stride % num_bytes == 0) && stride >= 0 &&
3394 bool type_good = (type != GL_INT && type != GL_UNSIGNED_INT &&
3396 bool good = size_good && offset_good && stride_good &&
3397 type_good && index_good;
3398 bool call = good && (type != GL_FIXED);
3400 EXPECT_CALL(*gl_, VertexAttribPointer(
3401 index, size, type, normalize, stride,
3402 BufferOffset(offset)));
3404 VertexAttribPointer cmd;
3405 cmd.Init(index, size, type, normalize, stride, offset);
3406 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3408 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3409 } else if (size_good &&
3414 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3415 } else if (size_good &&
3420 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
3421 } else if (size_good &&
3426 if (stride < 0 || stride > 255) {
3427 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3429 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
3431 } else if (size_good &&
3436 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
3437 } else if (!size_good &&
3442 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
3444 EXPECT_NE(GL_NO_ERROR, GetGLError());
3454 // Test that with an RGB backbuffer if we set the color mask to 1,1,1,1 it is
3455 // set to 1,1,1,0 at Draw time but is 1,1,1,1 at query time.
3456 TEST_F(GLES2DecoderRGBBackbufferTest, RGBBackbufferColorMask) {
3458 cmd.Init(true, true, true, true);
3459 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3460 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3463 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
3464 SetupExpectationsForApplyingDirtyState(
3465 true, // Framebuffer is RGB
3466 false, // Framebuffer has depth
3467 false, // Framebuffer has stencil
3468 0x1110, // color bits
3469 false, // depth mask
3470 false, // depth enabled
3471 0, // front stencil mask
3472 0, // back stencil mask
3473 false, // stencil enabled
3474 false, // cull_face_enabled
3475 false, // scissor_test_enabled
3476 false); // blend_enabled
3478 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
3480 .RetiresOnSaturation();
3481 DrawArrays draw_cmd;
3482 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
3483 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
3484 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3486 EXPECT_CALL(*gl_, GetError())
3487 .WillOnce(Return(GL_NO_ERROR))
3488 .WillOnce(Return(GL_NO_ERROR))
3489 .RetiresOnSaturation();
3490 typedef GetIntegerv::Result Result;
3491 Result* result = static_cast<Result*>(shared_memory_address_);
3492 EXPECT_CALL(*gl_, GetIntegerv(GL_COLOR_WRITEMASK, result->GetData()))
3496 cmd2.Init(GL_COLOR_WRITEMASK, shared_memory_id_, shared_memory_offset_);
3497 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
3499 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_COLOR_WRITEMASK),
3500 result->GetNumResults());
3501 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3502 EXPECT_EQ(1, result->GetData()[0]);
3503 EXPECT_EQ(1, result->GetData()[1]);
3504 EXPECT_EQ(1, result->GetData()[2]);
3505 EXPECT_EQ(1, result->GetData()[3]);
3508 // Test that with no depth if we set DepthMask true that it's set to false at
3509 // draw time but querying it returns true.
3510 TEST_F(GLES2DecoderRGBBackbufferTest, RGBBackbufferDepthMask) {
3511 EXPECT_CALL(*gl_, DepthMask(true))
3513 .RetiresOnSaturation();
3516 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3517 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3520 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
3521 SetupExpectationsForApplyingDirtyState(
3522 true, // Framebuffer is RGB
3523 false, // Framebuffer has depth
3524 false, // Framebuffer has stencil
3525 0x1110, // color bits
3526 false, // depth mask
3527 false, // depth enabled
3528 0, // front stencil mask
3529 0, // back stencil mask
3530 false, // stencil enabled
3531 false, // cull_face_enabled
3532 false, // scissor_test_enabled
3533 false); // blend_enabled
3535 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
3537 .RetiresOnSaturation();
3538 DrawArrays draw_cmd;
3539 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
3540 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
3541 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3543 EXPECT_CALL(*gl_, GetError())
3544 .WillOnce(Return(GL_NO_ERROR))
3545 .WillOnce(Return(GL_NO_ERROR))
3546 .RetiresOnSaturation();
3547 typedef GetIntegerv::Result Result;
3548 Result* result = static_cast<Result*>(shared_memory_address_);
3549 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_WRITEMASK, result->GetData()))
3553 cmd2.Init(GL_DEPTH_WRITEMASK, shared_memory_id_, shared_memory_offset_);
3554 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
3556 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_WRITEMASK),
3557 result->GetNumResults());
3558 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3559 EXPECT_EQ(1, result->GetData()[0]);
3562 // Test that with no stencil if we set the stencil mask it's still set to 0 at
3563 // draw time but gets our value if we query.
3564 TEST_F(GLES2DecoderRGBBackbufferTest, RGBBackbufferStencilMask) {
3565 const GLint kMask = 123;
3566 EXPECT_CALL(*gl_, StencilMask(kMask))
3568 .RetiresOnSaturation();
3571 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3572 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3575 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
3576 SetupExpectationsForApplyingDirtyState(
3577 true, // Framebuffer is RGB
3578 false, // Framebuffer has depth
3579 false, // Framebuffer has stencil
3580 0x1110, // color bits
3581 false, // depth mask
3582 false, // depth enabled
3583 0, // front stencil mask
3584 0, // back stencil mask
3585 false, // stencil enabled
3586 false, // cull_face_enabled
3587 false, // scissor_test_enabled
3588 false); // blend_enabled
3590 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
3592 .RetiresOnSaturation();
3593 DrawArrays draw_cmd;
3594 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
3595 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
3596 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3598 EXPECT_CALL(*gl_, GetError())
3599 .WillOnce(Return(GL_NO_ERROR))
3600 .WillOnce(Return(GL_NO_ERROR))
3601 .RetiresOnSaturation();
3602 typedef GetIntegerv::Result Result;
3603 Result* result = static_cast<Result*>(shared_memory_address_);
3604 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_WRITEMASK, result->GetData()))
3608 cmd2.Init(GL_STENCIL_WRITEMASK, shared_memory_id_, shared_memory_offset_);
3609 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
3611 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_WRITEMASK),
3612 result->GetNumResults());
3613 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3614 EXPECT_EQ(kMask, result->GetData()[0]);
3617 // Test that if an FBO is bound we get the correct masks.
3618 TEST_F(GLES2DecoderRGBBackbufferTest, RGBBackbufferColorMaskFBO) {
3620 cmd.Init(true, true, true, true);
3621 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3622 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3625 SetupVertexBuffer();
3626 DoEnableVertexAttribArray(0);
3627 DoVertexAttribPointer(0, 2, GL_FLOAT, 0, 0);
3628 DoEnableVertexAttribArray(1);
3629 DoVertexAttribPointer(1, 2, GL_FLOAT, 0, 0);
3630 DoEnableVertexAttribArray(2);
3631 DoVertexAttribPointer(2, 2, GL_FLOAT, 0, 0);
3632 SetupExpectationsForApplyingDirtyState(
3633 true, // Framebuffer is RGB
3634 false, // Framebuffer has depth
3635 false, // Framebuffer has stencil
3636 0x1110, // color bits
3637 false, // depth mask
3638 false, // depth enabled
3639 0, // front stencil mask
3640 0, // back stencil mask
3641 false, // stencil enabled
3642 false, // cull_face_enabled
3643 false, // scissor_test_enabled
3644 false); // blend_enabled
3646 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
3648 .RetiresOnSaturation();
3649 DrawArrays draw_cmd;
3650 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
3651 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
3652 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3654 // Check that no extra calls are made on the next draw.
3655 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
3657 .RetiresOnSaturation();
3658 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
3659 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3661 // Setup Frame buffer.
3662 // needs to be 1x1 or else it's not renderable.
3663 const GLsizei kWidth = 1;
3664 const GLsizei kHeight = 1;
3665 const GLenum kFormat = GL_RGB;
3666 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
3667 // Pass some data so the texture will be marked as cleared.
3669 GL_TEXTURE_2D, 0, kFormat, kWidth, kHeight, 0,
3670 kFormat, GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset);
3672 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
3673 DoFramebufferTexture2D(
3674 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
3675 client_texture_id_, kServiceTextureId, 0, GL_NO_ERROR);
3676 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
3677 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
3678 .RetiresOnSaturation();
3680 // This time state needs to be set.
3681 SetupExpectationsForApplyingDirtyState(
3682 false, // Framebuffer is RGB
3683 false, // Framebuffer has depth
3684 false, // Framebuffer has stencil
3685 0x1110, // color bits
3686 false, // depth mask
3687 false, // depth enabled
3688 0, // front stencil mask
3689 0, // back stencil mask
3690 false, // stencil enabled
3691 false, // cull_face_enabled
3692 false, // scissor_test_enabled
3693 false); // blend_enabled
3695 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
3697 .RetiresOnSaturation();
3698 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
3699 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3701 // Check that no extra calls are made on the next draw.
3702 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
3704 .RetiresOnSaturation();
3705 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
3706 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3709 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
3711 SetupExpectationsForApplyingDirtyState(
3712 true, // Framebuffer is RGB
3713 false, // Framebuffer has depth
3714 false, // Framebuffer has stencil
3715 0x1110, // color bits
3716 false, // depth mask
3717 false, // depth enabled
3718 0, // front stencil mask
3719 0, // back stencil mask
3720 false, // stencil enabled
3721 false, // cull_face_enabled
3722 false, // scissor_test_enabled
3723 false); // blend_enabled
3725 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
3727 .RetiresOnSaturation();
3728 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
3729 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3732 TEST_F(GLES2DecoderManualInitTest, ActualAlphaMatchesRequestedAlpha) {
3737 false, // has stencil
3738 true, // request alpha
3739 false, // request depth
3740 false, // request stencil
3741 true); // bind generates resource
3743 EXPECT_CALL(*gl_, GetError())
3744 .WillOnce(Return(GL_NO_ERROR))
3745 .WillOnce(Return(GL_NO_ERROR))
3746 .RetiresOnSaturation();
3747 typedef GetIntegerv::Result Result;
3748 Result* result = static_cast<Result*>(shared_memory_address_);
3749 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
3750 .WillOnce(SetArgumentPointee<1>(8))
3751 .RetiresOnSaturation();
3754 cmd2.Init(GL_ALPHA_BITS, shared_memory_id_, shared_memory_offset_);
3755 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
3757 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_ALPHA_BITS),
3758 result->GetNumResults());
3759 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3760 EXPECT_EQ(8, result->GetData()[0]);
3763 TEST_F(GLES2DecoderManualInitTest, ActualAlphaDoesNotMatchRequestedAlpha) {
3768 false, // has stencil
3769 false, // request alpha
3770 false, // request depth
3771 false, // request stencil
3772 true); // bind generates resource
3774 EXPECT_CALL(*gl_, GetError())
3775 .WillOnce(Return(GL_NO_ERROR))
3776 .WillOnce(Return(GL_NO_ERROR))
3777 .RetiresOnSaturation();
3778 typedef GetIntegerv::Result Result;
3779 Result* result = static_cast<Result*>(shared_memory_address_);
3780 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
3781 .WillOnce(SetArgumentPointee<1>(8))
3782 .RetiresOnSaturation();
3785 cmd2.Init(GL_ALPHA_BITS, shared_memory_id_, shared_memory_offset_);
3786 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
3788 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_ALPHA_BITS),
3789 result->GetNumResults());
3790 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3791 EXPECT_EQ(0, result->GetData()[0]);
3794 TEST_F(GLES2DecoderManualInitTest, ActualDepthMatchesRequestedDepth) {
3799 false, // has stencil
3800 false, // request alpha
3801 true, // request depth
3802 false, // request stencil
3803 true); // bind generates resource
3805 EXPECT_CALL(*gl_, GetError())
3806 .WillOnce(Return(GL_NO_ERROR))
3807 .WillOnce(Return(GL_NO_ERROR))
3808 .RetiresOnSaturation();
3809 typedef GetIntegerv::Result Result;
3810 Result* result = static_cast<Result*>(shared_memory_address_);
3811 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
3812 .WillOnce(SetArgumentPointee<1>(24))
3813 .RetiresOnSaturation();
3816 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
3817 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
3819 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
3820 result->GetNumResults());
3821 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3822 EXPECT_EQ(24, result->GetData()[0]);
3825 TEST_F(GLES2DecoderManualInitTest, ActualDepthDoesNotMatchRequestedDepth) {
3830 false, // has stencil
3831 false, // request alpha
3832 false, // request depth
3833 false, // request stencil
3834 true); // bind generates resource
3836 EXPECT_CALL(*gl_, GetError())
3837 .WillOnce(Return(GL_NO_ERROR))
3838 .WillOnce(Return(GL_NO_ERROR))
3839 .RetiresOnSaturation();
3840 typedef GetIntegerv::Result Result;
3841 Result* result = static_cast<Result*>(shared_memory_address_);
3842 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
3843 .WillOnce(SetArgumentPointee<1>(24))
3844 .RetiresOnSaturation();
3847 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
3848 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
3850 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
3851 result->GetNumResults());
3852 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3853 EXPECT_EQ(0, result->GetData()[0]);
3856 TEST_F(GLES2DecoderManualInitTest, ActualStencilMatchesRequestedStencil) {
3861 true, // has stencil
3862 false, // request alpha
3863 false, // request depth
3864 true, // request stencil
3865 true); // bind generates resource
3867 EXPECT_CALL(*gl_, GetError())
3868 .WillOnce(Return(GL_NO_ERROR))
3869 .WillOnce(Return(GL_NO_ERROR))
3870 .RetiresOnSaturation();
3871 typedef GetIntegerv::Result Result;
3872 Result* result = static_cast<Result*>(shared_memory_address_);
3873 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
3874 .WillOnce(SetArgumentPointee<1>(8))
3875 .RetiresOnSaturation();
3878 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
3879 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
3881 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
3882 result->GetNumResults());
3883 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3884 EXPECT_EQ(8, result->GetData()[0]);
3887 TEST_F(GLES2DecoderManualInitTest, ActualStencilDoesNotMatchRequestedStencil) {
3892 true, // has stencil
3893 false, // request alpha
3894 false, // request depth
3895 false, // request stencil
3896 true); // bind generates resource
3898 EXPECT_CALL(*gl_, GetError())
3899 .WillOnce(Return(GL_NO_ERROR))
3900 .WillOnce(Return(GL_NO_ERROR))
3901 .RetiresOnSaturation();
3902 typedef GetIntegerv::Result Result;
3903 Result* result = static_cast<Result*>(shared_memory_address_);
3904 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
3905 .WillOnce(SetArgumentPointee<1>(8))
3906 .RetiresOnSaturation();
3909 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
3910 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
3912 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
3913 result->GetNumResults());
3914 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3915 EXPECT_EQ(0, result->GetData()[0]);
3918 TEST_F(GLES2DecoderManualInitTest, DepthEnableWithDepth) {
3923 false, // has stencil
3924 false, // request alpha
3925 true, // request depth
3926 false, // request stencil
3927 true); // bind generates resource
3930 cmd.Init(GL_DEPTH_TEST);
3931 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3932 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3934 SetupDefaultProgram();
3936 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
3937 SetupExpectationsForApplyingDirtyState(
3938 true, // Framebuffer is RGB
3939 true, // Framebuffer has depth
3940 false, // Framebuffer has stencil
3941 0x1110, // color bits
3943 true, // depth enabled
3944 0, // front stencil mask
3945 0, // back stencil mask
3946 false, // stencil enabled
3947 false, // cull_face_enabled
3948 false, // scissor_test_enabled
3949 false); // blend_enabled
3952 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
3954 .RetiresOnSaturation();
3955 DrawArrays draw_cmd;
3956 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
3957 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
3958 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3960 EXPECT_CALL(*gl_, GetError())
3961 .WillOnce(Return(GL_NO_ERROR))
3962 .WillOnce(Return(GL_NO_ERROR))
3963 .RetiresOnSaturation();
3964 typedef GetIntegerv::Result Result;
3965 Result* result = static_cast<Result*>(shared_memory_address_);
3966 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_TEST, _))
3968 .RetiresOnSaturation();
3971 cmd2.Init(GL_DEPTH_TEST, shared_memory_id_, shared_memory_offset_);
3972 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
3974 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST),
3975 result->GetNumResults());
3976 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3977 EXPECT_EQ(1, result->GetData()[0]);
3980 TEST_F(GLES2DecoderManualInitTest, DepthEnableWithoutRequestedDepth) {
3985 false, // has stencil
3986 false, // request alpha
3987 false, // request depth
3988 false, // request stencil
3989 true); // bind generates resource
3992 cmd.Init(GL_DEPTH_TEST);
3993 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3994 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3996 SetupDefaultProgram();
3998 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
3999 SetupExpectationsForApplyingDirtyState(
4000 true, // Framebuffer is RGB
4001 false, // Framebuffer has depth
4002 false, // Framebuffer has stencil
4003 0x1110, // color bits
4004 false, // depth mask
4005 false, // depth enabled
4006 0, // front stencil mask
4007 0, // back stencil mask
4008 false, // stencil enabled
4009 false, // cull_face_enabled
4010 false, // scissor_test_enabled
4011 false); // blend_enabled
4013 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
4015 .RetiresOnSaturation();
4016 DrawArrays draw_cmd;
4017 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
4018 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
4019 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4021 EXPECT_CALL(*gl_, GetError())
4022 .WillOnce(Return(GL_NO_ERROR))
4023 .WillOnce(Return(GL_NO_ERROR))
4024 .RetiresOnSaturation();
4025 typedef GetIntegerv::Result Result;
4026 Result* result = static_cast<Result*>(shared_memory_address_);
4027 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_TEST, _))
4029 .RetiresOnSaturation();
4032 cmd2.Init(GL_DEPTH_TEST, shared_memory_id_, shared_memory_offset_);
4033 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
4035 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_TEST),
4036 result->GetNumResults());
4037 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4038 EXPECT_EQ(1, result->GetData()[0]);
4041 TEST_F(GLES2DecoderManualInitTest, StencilEnableWithStencil) {
4046 true, // has stencil
4047 false, // request alpha
4048 false, // request depth
4049 true, // request stencil
4050 true); // bind generates resource
4053 cmd.Init(GL_STENCIL_TEST);
4054 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4055 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4057 SetupDefaultProgram();
4059 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
4060 SetupExpectationsForApplyingDirtyState(
4061 true, // Framebuffer is RGB
4062 false, // Framebuffer has depth
4063 true, // Framebuffer has stencil
4064 0x1110, // color bits
4065 false, // depth mask
4066 false, // depth enabled
4067 -1, // front stencil mask
4068 -1, // back stencil mask
4069 true, // stencil enabled
4070 false, // cull_face_enabled
4071 false, // scissor_test_enabled
4072 false); // blend_enabled
4074 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
4076 .RetiresOnSaturation();
4077 DrawArrays draw_cmd;
4078 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
4079 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
4080 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4082 EXPECT_CALL(*gl_, GetError())
4083 .WillOnce(Return(GL_NO_ERROR))
4084 .WillOnce(Return(GL_NO_ERROR))
4085 .RetiresOnSaturation();
4086 typedef GetIntegerv::Result Result;
4087 Result* result = static_cast<Result*>(shared_memory_address_);
4088 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_TEST, _))
4090 .RetiresOnSaturation();
4093 cmd2.Init(GL_STENCIL_TEST, shared_memory_id_, shared_memory_offset_);
4094 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
4096 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST),
4097 result->GetNumResults());
4098 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4099 EXPECT_EQ(1, result->GetData()[0]);
4102 TEST_F(GLES2DecoderManualInitTest, StencilEnableWithoutRequestedStencil) {
4107 true, // has stencil
4108 false, // request alpha
4109 false, // request depth
4110 false, // request stencil
4111 true); // bind generates resource
4114 cmd.Init(GL_STENCIL_TEST);
4115 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4116 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4118 SetupDefaultProgram();
4120 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
4121 SetupExpectationsForApplyingDirtyState(
4122 true, // Framebuffer is RGB
4123 false, // Framebuffer has depth
4124 false, // Framebuffer has stencil
4125 0x1110, // color bits
4126 false, // depth mask
4127 false, // depth enabled
4128 0, // front stencil mask
4129 0, // back stencil mask
4130 false, // stencil enabled
4131 false, // cull_face_enabled
4132 false, // scissor_test_enabled
4133 false); // blend_enabled
4135 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
4137 .RetiresOnSaturation();
4138 DrawArrays draw_cmd;
4139 draw_cmd.Init(GL_TRIANGLES, 0, kNumVertices);
4140 EXPECT_EQ(error::kNoError, ExecuteCmd(draw_cmd));
4141 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4143 EXPECT_CALL(*gl_, GetError())
4144 .WillOnce(Return(GL_NO_ERROR))
4145 .WillOnce(Return(GL_NO_ERROR))
4146 .RetiresOnSaturation();
4147 typedef GetIntegerv::Result Result;
4148 Result* result = static_cast<Result*>(shared_memory_address_);
4149 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_TEST, _))
4151 .RetiresOnSaturation();
4154 cmd2.Init(GL_STENCIL_TEST, shared_memory_id_, shared_memory_offset_);
4155 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
4157 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_TEST),
4158 result->GetNumResults());
4159 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4160 EXPECT_EQ(1, result->GetData()[0]);
4163 TEST_F(GLES2DecoderManualInitTest, PackedDepthStencilReportsCorrectValues) {
4165 "GL_OES_packed_depth_stencil", // extensions
4168 true, // has stencil
4169 false, // request alpha
4170 true, // request depth
4171 true, // request stencil
4172 true); // bind generates resource
4174 EXPECT_CALL(*gl_, GetError())
4175 .WillOnce(Return(GL_NO_ERROR))
4176 .WillOnce(Return(GL_NO_ERROR))
4177 .WillOnce(Return(GL_NO_ERROR))
4178 .WillOnce(Return(GL_NO_ERROR))
4179 .RetiresOnSaturation();
4180 typedef GetIntegerv::Result Result;
4181 Result* result = static_cast<Result*>(shared_memory_address_);
4184 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
4185 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
4186 .WillOnce(SetArgumentPointee<1>(8))
4187 .RetiresOnSaturation();
4188 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
4190 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
4191 result->GetNumResults());
4192 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4193 EXPECT_EQ(8, result->GetData()[0]);
4195 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
4196 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
4197 .WillOnce(SetArgumentPointee<1>(24))
4198 .RetiresOnSaturation();
4199 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
4201 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
4202 result->GetNumResults());
4203 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4204 EXPECT_EQ(24, result->GetData()[0]);
4207 TEST_F(GLES2DecoderManualInitTest, PackedDepthStencilNoRequestedStencil) {
4209 "GL_OES_packed_depth_stencil", // extensions
4212 true, // has stencil
4213 false, // request alpha
4214 true, // request depth
4215 false, // request stencil
4216 true); // bind generates resource
4218 EXPECT_CALL(*gl_, GetError())
4219 .WillOnce(Return(GL_NO_ERROR))
4220 .WillOnce(Return(GL_NO_ERROR))
4221 .WillOnce(Return(GL_NO_ERROR))
4222 .WillOnce(Return(GL_NO_ERROR))
4223 .RetiresOnSaturation();
4224 typedef GetIntegerv::Result Result;
4225 Result* result = static_cast<Result*>(shared_memory_address_);
4228 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
4229 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
4230 .WillOnce(SetArgumentPointee<1>(8))
4231 .RetiresOnSaturation();
4232 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
4234 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
4235 result->GetNumResults());
4236 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4237 EXPECT_EQ(0, result->GetData()[0]);
4239 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
4240 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
4241 .WillOnce(SetArgumentPointee<1>(24))
4242 .RetiresOnSaturation();
4243 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
4245 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
4246 result->GetNumResults());
4247 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4248 EXPECT_EQ(24, result->GetData()[0]);
4251 TEST_F(GLES2DecoderManualInitTest, PackedDepthStencilRenderbufferDepth) {
4253 "GL_OES_packed_depth_stencil", // extensions
4256 false, // has stencil
4257 false, // request alpha
4258 false, // request depth
4259 false, // request stencil
4260 true); // bind generates resource
4261 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
4262 kServiceRenderbufferId);
4263 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
4264 kServiceFramebufferId);
4266 EXPECT_CALL(*gl_, GetError())
4267 .WillOnce(Return(GL_NO_ERROR)) // for RenderbufferStoage
4268 .WillOnce(Return(GL_NO_ERROR))
4269 .WillOnce(Return(GL_NO_ERROR)) // for FramebufferRenderbuffer
4270 .WillOnce(Return(GL_NO_ERROR))
4271 .WillOnce(Return(GL_NO_ERROR)) // for GetIntegerv
4272 .WillOnce(Return(GL_NO_ERROR))
4273 .WillOnce(Return(GL_NO_ERROR)) // for GetIntegerv
4274 .WillOnce(Return(GL_NO_ERROR))
4275 .RetiresOnSaturation();
4277 EXPECT_CALL(*gl_, RenderbufferStorageEXT(
4278 GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 100, 50))
4280 .RetiresOnSaturation();
4281 RenderbufferStorage cmd;
4282 cmd.Init(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 100, 50);
4283 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4284 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
4285 GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
4286 kServiceRenderbufferId))
4288 .RetiresOnSaturation();
4289 FramebufferRenderbuffer fbrb_cmd;
4291 GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
4292 client_renderbuffer_id_);
4293 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
4295 typedef GetIntegerv::Result Result;
4296 Result* result = static_cast<Result*>(shared_memory_address_);
4299 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
4300 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
4301 .WillOnce(SetArgumentPointee<1>(8))
4302 .RetiresOnSaturation();
4303 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
4305 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
4306 result->GetNumResults());
4307 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4308 EXPECT_EQ(0, result->GetData()[0]);
4310 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
4311 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
4312 .WillOnce(SetArgumentPointee<1>(24))
4313 .RetiresOnSaturation();
4314 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
4316 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
4317 result->GetNumResults());
4318 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4319 EXPECT_EQ(24, result->GetData()[0]);
4322 TEST_F(GLES2DecoderManualInitTest, PackedDepthStencilRenderbufferStencil) {
4324 "GL_OES_packed_depth_stencil", // extensions
4327 false, // has stencil
4328 false, // request alpha
4329 false, // request depth
4330 false, // request stencil
4331 true); // bind generates resource
4332 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
4333 kServiceRenderbufferId);
4334 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
4335 kServiceFramebufferId);
4337 EXPECT_CALL(*gl_, GetError())
4338 .WillOnce(Return(GL_NO_ERROR)) // for RenderbufferStoage
4339 .WillOnce(Return(GL_NO_ERROR))
4340 .WillOnce(Return(GL_NO_ERROR)) // for FramebufferRenderbuffer
4341 .WillOnce(Return(GL_NO_ERROR))
4342 .WillOnce(Return(GL_NO_ERROR)) // for GetIntegerv
4343 .WillOnce(Return(GL_NO_ERROR))
4344 .WillOnce(Return(GL_NO_ERROR)) // for GetIntegerv
4345 .WillOnce(Return(GL_NO_ERROR))
4346 .RetiresOnSaturation();
4348 EXPECT_CALL(*gl_, RenderbufferStorageEXT(
4349 GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 100, 50))
4351 .RetiresOnSaturation();
4352 RenderbufferStorage cmd;
4353 cmd.Init(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 100, 50);
4354 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4355 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
4356 GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
4357 kServiceRenderbufferId))
4359 .RetiresOnSaturation();
4360 FramebufferRenderbuffer fbrb_cmd;
4362 GL_FRAMEBUFFER, GL_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
4363 client_renderbuffer_id_);
4364 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
4366 typedef GetIntegerv::Result Result;
4367 Result* result = static_cast<Result*>(shared_memory_address_);
4370 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
4371 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
4372 .WillOnce(SetArgumentPointee<1>(8))
4373 .RetiresOnSaturation();
4374 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
4376 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
4377 result->GetNumResults());
4378 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4379 EXPECT_EQ(8, result->GetData()[0]);
4381 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
4382 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
4383 .WillOnce(SetArgumentPointee<1>(24))
4384 .RetiresOnSaturation();
4385 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
4387 decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
4388 result->GetNumResults());
4389 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4390 EXPECT_EQ(0, result->GetData()[0]);
4393 TEST_F(GLES2DecoderTest, GetMultipleIntegervCHROMIUMValidArgs) {
4394 const GLsizei kCount = 3;
4395 GLenum* pnames = GetSharedMemoryAs<GLenum*>();
4396 pnames[0] = GL_DEPTH_WRITEMASK;
4397 pnames[1] = GL_COLOR_WRITEMASK;
4398 pnames[2] = GL_STENCIL_WRITEMASK;
4400 GetSharedMemoryAsWithOffset<GLint*>(sizeof(*pnames) * kCount);
4402 GLsizei num_results = 0;
4403 for (GLsizei ii = 0; ii < kCount; ++ii) {
4404 num_results += decoder_->GetGLES2Util()->GLGetNumValuesReturned(pnames[ii]);
4406 const GLsizei result_size = num_results * sizeof(*results);
4407 memset(results, 0, result_size);
4409 const GLint kSentinel = 0x12345678;
4410 results[num_results] = kSentinel;
4412 GetMultipleIntegervCHROMIUM cmd;
4414 kSharedMemoryId, kSharedMemoryOffset, kCount,
4415 kSharedMemoryId, kSharedMemoryOffset + sizeof(*pnames) * kCount,
4418 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4419 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4420 EXPECT_EQ(1, results[0]); // Depth writemask
4421 EXPECT_EQ(1, results[1]); // color writemask red
4422 EXPECT_EQ(1, results[2]); // color writemask green
4423 EXPECT_EQ(1, results[3]); // color writemask blue
4424 EXPECT_EQ(1, results[4]); // color writemask alpha
4425 EXPECT_EQ(-1, results[5]); // stencil writemask alpha
4426 EXPECT_EQ(kSentinel, results[num_results]); // End of results
4429 TEST_F(GLES2DecoderTest, GetMultipleIntegervCHROMIUMInvalidArgs) {
4430 const GLsizei kCount = 3;
4431 // Offset the pnames because GLGetError will use the first uint32.
4432 const uint32 kPnameOffset = sizeof(uint32);
4433 const uint32 kResultsOffset = kPnameOffset + sizeof(GLint) * kCount;
4434 GLenum* pnames = GetSharedMemoryAsWithOffset<GLenum*>(kPnameOffset);
4435 pnames[0] = GL_DEPTH_WRITEMASK;
4436 pnames[1] = GL_COLOR_WRITEMASK;
4437 pnames[2] = GL_STENCIL_WRITEMASK;
4438 GLint* results = GetSharedMemoryAsWithOffset<GLint*>(kResultsOffset);
4440 GLsizei num_results = 0;
4441 for (GLsizei ii = 0; ii < kCount; ++ii) {
4442 num_results += decoder_->GetGLES2Util()->GLGetNumValuesReturned(pnames[ii]);
4444 const GLsizei result_size = num_results * sizeof(*results);
4445 memset(results, 0, result_size);
4447 const GLint kSentinel = 0x12345678;
4448 results[num_results] = kSentinel;
4450 GetMultipleIntegervCHROMIUM cmd;
4451 // Check bad pnames pointer.
4453 kInvalidSharedMemoryId, kSharedMemoryOffset + kPnameOffset, kCount,
4454 kSharedMemoryId, kSharedMemoryOffset + kResultsOffset,
4456 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
4457 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4458 // Check bad pnames pointer.
4460 kSharedMemoryId, kInvalidSharedMemoryOffset, kCount,
4461 kSharedMemoryId, kSharedMemoryOffset + kResultsOffset,
4463 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
4464 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4467 kSharedMemoryId, kSharedMemoryOffset + kPnameOffset, -1,
4468 kSharedMemoryId, kSharedMemoryOffset + kResultsOffset,
4470 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
4471 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4472 // Check bad results pointer.
4474 kSharedMemoryId, kSharedMemoryOffset + kPnameOffset, kCount,
4475 kInvalidSharedMemoryId, kSharedMemoryOffset + kResultsOffset,
4477 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
4478 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4479 // Check bad results pointer.
4481 kSharedMemoryId, kSharedMemoryOffset + kPnameOffset, kCount,
4482 kSharedMemoryId, kInvalidSharedMemoryOffset,
4484 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
4485 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4488 kSharedMemoryId, kSharedMemoryOffset + kPnameOffset, kCount,
4489 kSharedMemoryId, kSharedMemoryOffset + kResultsOffset,
4491 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4492 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
4495 kSharedMemoryId, kSharedMemoryOffset + kPnameOffset, kCount,
4496 kSharedMemoryId, kSharedMemoryOffset + kResultsOffset,
4498 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4499 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
4502 kSharedMemoryId, kSharedMemoryOffset + kPnameOffset, kCount,
4503 kSharedMemoryId, kSharedMemoryOffset + kResultsOffset,
4505 GLenum temp = pnames[2];
4506 pnames[2] = GL_TRUE;
4507 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4508 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
4510 // Check results area has not been cleared by client.
4512 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(cmd));
4513 // Check buffer is what we expect
4514 EXPECT_EQ(0, results[0]);
4515 EXPECT_EQ(1, results[1]);
4516 EXPECT_EQ(0, results[2]);
4517 EXPECT_EQ(0, results[3]);
4518 EXPECT_EQ(0, results[4]);
4519 EXPECT_EQ(0, results[5]);
4520 EXPECT_EQ(kSentinel, results[num_results]); // End of results
4523 TEST_F(GLES2DecoderTest, TexImage2DRedefinitionSucceeds) {
4524 const int kWidth = 16;
4525 const int kHeight = 8;
4526 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
4527 EXPECT_CALL(*gl_, GetError())
4528 .WillRepeatedly(Return(GL_NO_ERROR));
4529 for (int ii = 0; ii < 2; ++ii) {
4532 EXPECT_CALL(*gl_, TexImage2D(
4533 GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA,
4534 GL_UNSIGNED_BYTE, _))
4536 .RetiresOnSaturation();
4538 GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA,
4539 GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset);
4541 SetupClearTextureExpections(
4542 kServiceTextureId, kServiceTextureId, GL_TEXTURE_2D, GL_TEXTURE_2D,
4543 0, GL_RGBA, GL_UNSIGNED_BYTE, kWidth, kHeight);
4545 GL_TEXTURE_2D, 0, GL_RGBA, kWidth, kHeight, 0, GL_RGBA,
4546 GL_UNSIGNED_BYTE, 0, 0);
4548 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4549 EXPECT_CALL(*gl_, TexSubImage2D(
4550 GL_TEXTURE_2D, 0, 0, 0, kWidth, kHeight - 1, GL_RGBA, GL_UNSIGNED_BYTE,
4551 shared_memory_address_))
4553 .RetiresOnSaturation();
4554 // Consider this TexSubImage2D command part of the previous TexImage2D
4555 // (last GL_TRUE argument). It will be skipped if there are bugs in the
4556 // redefinition case.
4559 GL_TEXTURE_2D, 0, 0, 0, kWidth, kHeight - 1, GL_RGBA, GL_UNSIGNED_BYTE,
4560 kSharedMemoryId, kSharedMemoryOffset, GL_TRUE);
4561 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
4565 TEST_F(GLES2DecoderTest, TexImage2DGLError) {
4566 GLenum target = GL_TEXTURE_2D;
4568 GLenum internal_format = GL_RGBA;
4572 GLenum format = GL_RGBA;
4573 GLenum type = GL_UNSIGNED_BYTE;
4574 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
4575 TextureManager* manager = group().texture_manager();
4576 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
4577 ASSERT_TRUE(texture_ref != NULL);
4578 Texture* texture = texture_ref->texture();
4579 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
4580 EXPECT_CALL(*gl_, GetError())
4581 .WillOnce(Return(GL_NO_ERROR))
4582 .WillOnce(Return(GL_OUT_OF_MEMORY))
4583 .RetiresOnSaturation();
4584 EXPECT_CALL(*gl_, TexImage2D(target, level, internal_format,
4585 width, height, border, format, type, _))
4587 .RetiresOnSaturation();
4589 cmd.Init(target, level, internal_format, width, height, border, format,
4590 type, kSharedMemoryId, kSharedMemoryOffset);
4591 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4592 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
4593 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
4596 TEST_F(GLES2DecoderTest, BufferDataGLError) {
4597 GLenum target = GL_ARRAY_BUFFER;
4598 GLsizeiptr size = 4;
4599 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
4600 BufferManager* manager = group().buffer_manager();
4601 Buffer* buffer = manager->GetBuffer(client_buffer_id_);
4602 ASSERT_TRUE(buffer != NULL);
4603 EXPECT_EQ(0, buffer->size());
4604 EXPECT_CALL(*gl_, GetError())
4605 .WillOnce(Return(GL_NO_ERROR))
4606 .WillOnce(Return(GL_OUT_OF_MEMORY))
4607 .RetiresOnSaturation();
4608 EXPECT_CALL(*gl_, BufferData(target, size, _, GL_STREAM_DRAW))
4610 .RetiresOnSaturation();
4612 cmd.Init(target, size, 0, 0, GL_STREAM_DRAW);
4613 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4614 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
4615 EXPECT_EQ(0, buffer->size());
4618 TEST_F(GLES2DecoderTest, CopyTexImage2DGLError) {
4619 GLenum target = GL_TEXTURE_2D;
4621 GLenum internal_format = GL_RGBA;
4625 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
4626 TextureManager* manager = group().texture_manager();
4627 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
4628 ASSERT_TRUE(texture_ref != NULL);
4629 Texture* texture = texture_ref->texture();
4630 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
4631 EXPECT_CALL(*gl_, GetError())
4632 .WillOnce(Return(GL_NO_ERROR))
4633 .WillOnce(Return(GL_OUT_OF_MEMORY))
4634 .RetiresOnSaturation();
4635 EXPECT_CALL(*gl_, CopyTexImage2D(
4636 target, level, internal_format, 0, 0, width, height, border))
4638 .RetiresOnSaturation();
4640 cmd.Init(target, level, internal_format, 0, 0, width, height, border);
4641 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4642 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
4643 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
4646 TEST_F(GLES2DecoderTest, FramebufferRenderbufferGLError) {
4647 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
4648 kServiceFramebufferId);
4649 EXPECT_CALL(*gl_, GetError())
4650 .WillOnce(Return(GL_NO_ERROR))
4651 .WillOnce(Return(GL_OUT_OF_MEMORY))
4652 .RetiresOnSaturation();
4653 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
4654 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
4655 kServiceRenderbufferId))
4657 .RetiresOnSaturation();
4658 FramebufferRenderbuffer cmd;
4660 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
4661 client_renderbuffer_id_);
4662 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4663 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
4666 TEST_F(GLES2DecoderTest, FramebufferTexture2DGLError) {
4667 const GLsizei kWidth = 5;
4668 const GLsizei kHeight = 3;
4669 const GLenum kFormat = GL_RGB;
4670 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
4671 DoTexImage2D(GL_TEXTURE_2D, 0, kFormat, kWidth, kHeight, 0,
4672 kFormat, GL_UNSIGNED_BYTE, 0, 0);
4673 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
4674 kServiceFramebufferId);
4675 EXPECT_CALL(*gl_, GetError())
4676 .WillOnce(Return(GL_NO_ERROR))
4677 .WillOnce(Return(GL_OUT_OF_MEMORY))
4678 .RetiresOnSaturation();
4679 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(
4680 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
4681 kServiceTextureId, 0))
4683 .RetiresOnSaturation();
4684 FramebufferTexture2D fbtex_cmd;
4686 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, client_texture_id_,
4688 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd));
4689 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
4692 TEST_F(GLES2DecoderTest, RenderbufferStorageGLError) {
4693 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
4694 kServiceRenderbufferId);
4695 EXPECT_CALL(*gl_, GetError())
4696 .WillOnce(Return(GL_NO_ERROR))
4697 .WillOnce(Return(GL_OUT_OF_MEMORY))
4698 .RetiresOnSaturation();
4699 EXPECT_CALL(*gl_, RenderbufferStorageEXT(
4700 GL_RENDERBUFFER, GL_RGBA, 100, 50))
4702 .RetiresOnSaturation();
4703 RenderbufferStorage cmd;
4704 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, 100, 50);
4705 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4706 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
4709 TEST_F(GLES2DecoderTest, RenderbufferStorageBadArgs) {
4710 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
4711 kServiceRenderbufferId);
4712 EXPECT_CALL(*gl_, RenderbufferStorageEXT(_, _, _, _))
4714 .RetiresOnSaturation();
4715 RenderbufferStorage cmd;
4716 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, TestHelper::kMaxRenderbufferSize + 1, 1);
4717 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4718 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
4719 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, 1, TestHelper::kMaxRenderbufferSize + 1);
4720 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4721 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
4724 TEST_F(GLES2DecoderManualInitTest, RenderbufferStorageMultisampleGLError) {
4726 "GL_EXT_framebuffer_multisample", // extensions
4729 false, // has stencil
4730 false, // request alpha
4731 false, // request depth
4732 false, // request stencil
4733 true); // bind generates resource
4734 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
4735 kServiceRenderbufferId);
4736 EXPECT_CALL(*gl_, GetError())
4737 .WillOnce(Return(GL_NO_ERROR))
4738 .WillOnce(Return(GL_OUT_OF_MEMORY))
4739 .RetiresOnSaturation();
4740 EXPECT_CALL(*gl_, RenderbufferStorageMultisampleEXT(
4741 GL_RENDERBUFFER, 1, GL_RGBA, 100, 50))
4743 .RetiresOnSaturation();
4744 RenderbufferStorageMultisampleEXT cmd;
4745 cmd.Init(GL_RENDERBUFFER, 1, GL_RGBA4, 100, 50);
4746 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4747 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
4750 TEST_F(GLES2DecoderManualInitTest, RenderbufferStorageMultisampleBadArgs) {
4752 "GL_EXT_framebuffer_multisample", // extensions
4755 false, // has stencil
4756 false, // request alpha
4757 false, // request depth
4758 false, // request stencil
4759 true); // bind generates resource
4760 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
4761 kServiceRenderbufferId);
4762 EXPECT_CALL(*gl_, RenderbufferStorageMultisampleEXT(_, _, _, _, _))
4764 .RetiresOnSaturation();
4765 RenderbufferStorageMultisampleEXT cmd;
4766 cmd.Init(GL_RENDERBUFFER, TestHelper::kMaxSamples + 1,
4767 GL_RGBA4, TestHelper::kMaxRenderbufferSize, 1);
4768 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4769 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
4770 cmd.Init(GL_RENDERBUFFER, TestHelper::kMaxSamples,
4771 GL_RGBA4, TestHelper::kMaxRenderbufferSize + 1, 1);
4772 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4773 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
4774 cmd.Init(GL_RENDERBUFFER, TestHelper::kMaxSamples,
4775 GL_RGBA4, 1, TestHelper::kMaxRenderbufferSize + 1);
4776 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4777 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
4780 TEST_F(GLES2DecoderTest, ReadPixelsGLError) {
4781 GLenum kFormat = GL_RGBA;
4786 typedef ReadPixels::Result Result;
4787 Result* result = GetSharedMemoryAs<Result*>();
4788 uint32 result_shm_id = kSharedMemoryId;
4789 uint32 result_shm_offset = kSharedMemoryOffset;
4790 uint32 pixels_shm_id = kSharedMemoryId;
4791 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result);
4792 EXPECT_CALL(*gl_, GetError())
4793 .WillOnce(Return(GL_NO_ERROR))
4794 .WillOnce(Return(GL_OUT_OF_MEMORY))
4795 .RetiresOnSaturation();
4797 *gl_, ReadPixels(x, y, width, height, kFormat, GL_UNSIGNED_BYTE, _))
4799 .RetiresOnSaturation();
4801 cmd.Init(x, y, width, height, kFormat, GL_UNSIGNED_BYTE,
4802 pixels_shm_id, pixels_shm_offset,
4803 result_shm_id, result_shm_offset,
4805 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4806 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
4809 static bool ValueInArray(GLint value, GLint* array, GLint count) {
4810 for (GLint ii = 0; ii < count; ++ii) {
4811 if (array[ii] == value) {
4818 TEST_F(GLES2DecoderManualInitTest, GetCompressedTextureFormats) {
4820 "GL_EXT_texture_compression_s3tc", // extensions
4823 false, // has stencil
4824 false, // request alpha
4825 false, // request depth
4826 false, // request stencil
4827 true); // bind generates resource
4829 EXPECT_CALL(*gl_, GetError())
4830 .WillOnce(Return(GL_NO_ERROR))
4831 .WillOnce(Return(GL_NO_ERROR))
4832 .WillOnce(Return(GL_NO_ERROR))
4833 .WillOnce(Return(GL_NO_ERROR))
4834 .RetiresOnSaturation();
4836 typedef GetIntegerv::Result Result;
4837 Result* result = static_cast<Result*>(shared_memory_address_);
4840 EXPECT_CALL(*gl_, GetIntegerv(_, _))
4842 .RetiresOnSaturation();
4844 GL_NUM_COMPRESSED_TEXTURE_FORMATS,
4845 shared_memory_id_, shared_memory_offset_);
4846 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4847 EXPECT_EQ(1, result->GetNumResults());
4848 GLint num_formats = result->GetData()[0];
4849 EXPECT_EQ(4, num_formats);
4850 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4854 GL_COMPRESSED_TEXTURE_FORMATS,
4855 shared_memory_id_, shared_memory_offset_);
4856 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4857 EXPECT_EQ(num_formats, result->GetNumResults());
4859 EXPECT_TRUE(ValueInArray(
4860 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
4861 result->GetData(), result->GetNumResults()));
4862 EXPECT_TRUE(ValueInArray(
4863 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
4864 result->GetData(), result->GetNumResults()));
4865 EXPECT_TRUE(ValueInArray(
4866 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT,
4867 result->GetData(), result->GetNumResults()));
4868 EXPECT_TRUE(ValueInArray(
4869 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
4870 result->GetData(), result->GetNumResults()));
4872 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4875 TEST_F(GLES2DecoderManualInitTest, GetNoCompressedTextureFormats) {
4880 false, // has stencil
4881 false, // request alpha
4882 false, // request depth
4883 false, // request stencil
4884 true); // bind generates resource
4886 EXPECT_CALL(*gl_, GetError())
4887 .WillOnce(Return(GL_NO_ERROR))
4888 .WillOnce(Return(GL_NO_ERROR))
4889 .WillOnce(Return(GL_NO_ERROR))
4890 .WillOnce(Return(GL_NO_ERROR))
4891 .RetiresOnSaturation();
4893 typedef GetIntegerv::Result Result;
4894 Result* result = static_cast<Result*>(shared_memory_address_);
4897 EXPECT_CALL(*gl_, GetIntegerv(_, _))
4899 .RetiresOnSaturation();
4901 GL_NUM_COMPRESSED_TEXTURE_FORMATS,
4902 shared_memory_id_, shared_memory_offset_);
4903 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4904 EXPECT_EQ(1, result->GetNumResults());
4905 GLint num_formats = result->GetData()[0];
4906 EXPECT_EQ(0, num_formats);
4907 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4911 GL_COMPRESSED_TEXTURE_FORMATS,
4912 shared_memory_id_, shared_memory_offset_);
4913 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4914 EXPECT_EQ(num_formats, result->GetNumResults());
4916 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4919 TEST_F(GLES2DecoderManualInitTest, CompressedTexImage2DBucketBadBucket) {
4921 "GL_EXT_texture_compression_s3tc", // extensions
4924 false, // has stencil
4925 false, // request alpha
4926 false, // request depth
4927 false, // request stencil
4928 true); // bind generates resource
4930 const uint32 kBadBucketId = 123;
4931 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
4932 CompressedTexImage2DBucket cmd;
4934 GL_TEXTURE_2D, 0, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 4, 4, 0,
4936 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
4937 CompressedTexSubImage2DBucket cmd2;
4939 GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
4941 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
4946 struct S3TCTestData {
4951 } // anonymous namespace.
4953 TEST_F(GLES2DecoderManualInitTest, CompressedTexImage2DS3TC) {
4955 "GL_EXT_texture_compression_s3tc", // extensions
4958 false, // has stencil
4959 false, // request alpha
4960 false, // request depth
4961 false, // request stencil
4962 true); // bind generates resource
4963 const uint32 kBucketId = 123;
4964 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
4965 ASSERT_TRUE(bucket != NULL);
4967 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
4969 static const S3TCTestData test_data[] = {
4970 { GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 8, },
4971 { GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 8, },
4972 { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 16, },
4973 { GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16, },
4976 for (size_t ii = 0; ii < arraysize(test_data); ++ii) {
4977 const S3TCTestData& test = test_data[ii];
4978 CompressedTexImage2DBucket cmd;
4979 // test small width.
4980 DoCompressedTexImage2D(
4981 GL_TEXTURE_2D, 0, test.format, 2, 4, 0, test.block_size,
4983 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4987 GL_TEXTURE_2D, 0, test.format, 5, 4, 0,
4989 bucket->SetSize(test.block_size * 2);
4990 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
4991 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
4993 // test small height.
4994 DoCompressedTexImage2D(
4995 GL_TEXTURE_2D, 0, test.format, 4, 2, 0, test.block_size,
4997 EXPECT_EQ(GL_NO_ERROR, GetGLError());
4999 // test too bad height.
5001 GL_TEXTURE_2D, 0, test.format, 4, 5, 0,
5003 bucket->SetSize(test.block_size * 2);
5004 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5005 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
5007 // test small for level 0.
5008 DoCompressedTexImage2D(
5009 GL_TEXTURE_2D, 0, test.format, 1, 1, 0, test.block_size,
5011 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5013 // test small for level 0.
5014 DoCompressedTexImage2D(
5015 GL_TEXTURE_2D, 0, test.format, 2, 2, 0, test.block_size,
5017 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5019 // test size too large.
5021 GL_TEXTURE_2D, 0, test.format, 4, 4, 0,
5023 bucket->SetSize(test.block_size * 2);
5024 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5025 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
5027 // test size too small.
5029 GL_TEXTURE_2D, 0, test.format, 4, 4, 0,
5031 bucket->SetSize(test.block_size / 2);
5032 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5033 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
5035 // test with 3 mips.
5036 DoCompressedTexImage2D(
5037 GL_TEXTURE_2D, 0, test.format, 4, 4, 0, test.block_size, kBucketId);
5038 DoCompressedTexImage2D(
5039 GL_TEXTURE_2D, 1, test.format, 2, 2, 0, test.block_size, kBucketId);
5040 DoCompressedTexImage2D(
5041 GL_TEXTURE_2D, 2, test.format, 1, 1, 0, test.block_size, kBucketId);
5042 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5045 DoCompressedTexImage2D(
5046 GL_TEXTURE_2D, 0, test.format, 16, 16, 0, test.block_size * 4 * 4,
5048 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5050 CompressedTexSubImage2DBucket sub_cmd;
5051 bucket->SetSize(test.block_size);
5052 // Test sub image bad xoffset
5054 GL_TEXTURE_2D, 0, 1, 0, 4, 4, test.format, kBucketId);
5055 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
5056 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
5058 // Test sub image bad yoffset
5060 GL_TEXTURE_2D, 0, 0, 2, 4, 4, test.format, kBucketId);
5061 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
5062 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
5064 // Test sub image bad width
5065 bucket->SetSize(test.block_size * 2);
5067 GL_TEXTURE_2D, 0, 0, 0, 5, 4, test.format, kBucketId);
5068 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
5069 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
5071 // Test sub image bad height
5073 GL_TEXTURE_2D, 0, 0, 0, 4, 5, test.format, kBucketId);
5074 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
5075 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
5077 // Test sub image bad size
5078 bucket->SetSize(test.block_size + 1);
5080 GL_TEXTURE_2D, 0, 0, 0, 4, 4, test.format, kBucketId);
5081 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
5082 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
5084 for (GLint yoffset = 0; yoffset <= 8; yoffset += 4) {
5085 for (GLint xoffset = 0; xoffset <= 8; xoffset += 4) {
5086 for (GLsizei height = 4; height <= 8; height +=4 ) {
5087 for (GLsizei width = 4; width <= 8; width += 4) {
5088 GLsizei size = test.block_size * (width / 4) * (height / 4);
5089 bucket->SetSize(size);
5090 EXPECT_CALL(*gl_, CompressedTexSubImage2D(
5091 GL_TEXTURE_2D, 0, xoffset, yoffset, width, height, test.format,
5094 .RetiresOnSaturation();
5096 GL_TEXTURE_2D, 0, xoffset, yoffset, width, height, test.format,
5098 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
5099 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5107 TEST_F(GLES2DecoderManualInitTest, CompressedTexImage2DETC1) {
5109 "GL_OES_compressed_ETC1_RGB8_texture", // extensions
5112 false, // has stencil
5113 false, // request alpha
5114 false, // request depth
5115 false, // request stencil
5116 true); // bind generates resource
5117 const uint32 kBucketId = 123;
5118 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
5119 ASSERT_TRUE(bucket != NULL);
5121 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
5123 const GLenum kFormat = GL_ETC1_RGB8_OES;
5124 const size_t kBlockSize = 8;
5126 CompressedTexImage2DBucket cmd;
5127 // test small width.
5128 DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 4, 8, 0, 16, kBucketId);
5129 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5131 // test small height.
5132 DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 8, 4, 0, 16, kBucketId);
5133 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5135 // test size too large.
5136 cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, 0, kBucketId);
5137 bucket->SetSize(kBlockSize * 2);
5138 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5139 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
5141 // test size too small.
5142 cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, 0, kBucketId);
5143 bucket->SetSize(kBlockSize / 2);
5144 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5145 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
5148 DoCompressedTexImage2D(
5149 GL_TEXTURE_2D, 0, kFormat, 16, 16, 0, kBlockSize * 16, kBucketId);
5150 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5152 // Test CompressedTexSubImage not allowed
5153 CompressedTexSubImage2DBucket sub_cmd;
5154 bucket->SetSize(kBlockSize);
5155 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, kFormat, kBucketId);
5156 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
5157 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
5159 // Test TexSubImage not allowed for ETC1 compressed texture
5160 TextureRef* texture_ref = GetTexture(client_texture_id_);
5161 ASSERT_TRUE(texture_ref != NULL);
5162 Texture* texture = texture_ref->texture();
5163 GLenum type, internal_format;
5164 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
5165 EXPECT_EQ(kFormat, internal_format);
5166 TexSubImage2D texsub_cmd;
5167 texsub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, GL_RGBA, GL_UNSIGNED_BYTE,
5168 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
5169 EXPECT_EQ(error::kNoError, ExecuteCmd(texsub_cmd));
5170 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
5172 // Test CopyTexSubImage not allowed for ETC1 compressed texture
5173 CopyTexSubImage2D copy_cmd;
5174 copy_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 4, 4);
5175 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_cmd));
5176 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
5179 TEST_F(GLES2DecoderManualInitTest, GetCompressedTextureFormatsETC1) {
5181 "GL_OES_compressed_ETC1_RGB8_texture", // extensions
5184 false, // has stencil
5185 false, // request alpha
5186 false, // request depth
5187 false, // request stencil
5188 true); // bind generates resource
5190 EXPECT_CALL(*gl_, GetError())
5191 .WillOnce(Return(GL_NO_ERROR))
5192 .WillOnce(Return(GL_NO_ERROR))
5193 .WillOnce(Return(GL_NO_ERROR))
5194 .WillOnce(Return(GL_NO_ERROR))
5195 .RetiresOnSaturation();
5197 typedef GetIntegerv::Result Result;
5198 Result* result = static_cast<Result*>(shared_memory_address_);
5201 EXPECT_CALL(*gl_, GetIntegerv(_, _))
5203 .RetiresOnSaturation();
5205 GL_NUM_COMPRESSED_TEXTURE_FORMATS,
5206 shared_memory_id_, shared_memory_offset_);
5207 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5208 EXPECT_EQ(1, result->GetNumResults());
5209 GLint num_formats = result->GetData()[0];
5210 EXPECT_EQ(1, num_formats);
5211 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5215 GL_COMPRESSED_TEXTURE_FORMATS,
5216 shared_memory_id_, shared_memory_offset_);
5217 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5218 EXPECT_EQ(num_formats, result->GetNumResults());
5220 EXPECT_TRUE(ValueInArray(
5222 result->GetData(), result->GetNumResults()));
5223 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5226 TEST_F(GLES2DecoderWithShaderTest, GetProgramInfoCHROMIUMValidArgs) {
5227 const uint32 kBucketId = 123;
5228 GetProgramInfoCHROMIUM cmd;
5229 cmd.Init(client_program_id_, kBucketId);
5230 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5231 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
5232 EXPECT_GT(bucket->size(), 0u);
5235 TEST_F(GLES2DecoderWithShaderTest, GetProgramInfoCHROMIUMInvalidArgs) {
5236 const uint32 kBucketId = 123;
5237 CommonDecoder::Bucket* bucket = decoder_->GetBucket(kBucketId);
5238 EXPECT_TRUE(bucket == NULL);
5239 GetProgramInfoCHROMIUM cmd;
5240 cmd.Init(kInvalidClientId, kBucketId);
5241 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5242 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5243 bucket = decoder_->GetBucket(kBucketId);
5244 ASSERT_TRUE(bucket != NULL);
5245 EXPECT_EQ(sizeof(ProgramInfoHeader), bucket->size());
5246 ProgramInfoHeader* info = bucket->GetDataAs<ProgramInfoHeader*>(
5247 0, sizeof(ProgramInfoHeader));
5248 ASSERT_TRUE(info != 0);
5249 EXPECT_EQ(0u, info->link_status);
5250 EXPECT_EQ(0u, info->num_attribs);
5251 EXPECT_EQ(0u, info->num_uniforms);
5254 TEST_F(GLES2DecoderManualInitTest, EGLImageExternalBindTexture) {
5256 "GL_OES_EGL_image_external", // extensions
5259 false, // has stencil
5260 false, // request alpha
5261 false, // request depth
5262 false, // request stencil
5263 true); // bind generates resource
5264 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_EXTERNAL_OES, kNewServiceId));
5265 EXPECT_CALL(*gl_, GenTextures(1, _))
5266 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
5268 cmd.Init(GL_TEXTURE_EXTERNAL_OES, kNewClientId);
5269 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5270 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5271 TextureRef* texture_ref = GetTexture(kNewClientId);
5272 EXPECT_TRUE(texture_ref != NULL);
5273 EXPECT_TRUE(texture_ref->texture()->target() == GL_TEXTURE_EXTERNAL_OES);
5276 TEST_F(GLES2DecoderManualInitTest, EGLImageExternalGetBinding) {
5278 "GL_OES_EGL_image_external", // extensions
5281 false, // has stencil
5282 false, // request alpha
5283 false, // request depth
5284 false, // request stencil
5285 true); // bind generates resource
5286 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
5288 EXPECT_CALL(*gl_, GetError())
5289 .WillOnce(Return(GL_NO_ERROR))
5290 .WillOnce(Return(GL_NO_ERROR))
5291 .RetiresOnSaturation();
5292 typedef GetIntegerv::Result Result;
5293 Result* result = static_cast<Result*>(shared_memory_address_);
5294 EXPECT_CALL(*gl_, GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES,
5299 cmd.Init(GL_TEXTURE_BINDING_EXTERNAL_OES,
5301 shared_memory_offset_);
5302 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5303 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(
5304 GL_TEXTURE_BINDING_EXTERNAL_OES), result->GetNumResults());
5305 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5306 EXPECT_EQ(client_texture_id_, (uint32)result->GetData()[0]);
5309 TEST_F(GLES2DecoderManualInitTest, EGLImageExternalTextureDefaults) {
5311 "GL_OES_EGL_image_external", // extensions
5314 false, // has stencil
5315 false, // request alpha
5316 false, // request depth
5317 false, // request stencil
5318 true); // bind generates resource
5319 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
5321 TextureRef* texture_ref = GetTexture(client_texture_id_);
5322 EXPECT_TRUE(texture_ref != NULL);
5323 Texture* texture = texture_ref->texture();
5324 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
5325 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
5326 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
5327 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
5330 TEST_F(GLES2DecoderManualInitTest, EGLImageExternalTextureParam) {
5332 "GL_OES_EGL_image_external", // extensions
5335 false, // has stencil
5336 false, // request alpha
5337 false, // request depth
5338 false, // request stencil
5339 true); // bind generates resource
5341 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
5343 EXPECT_CALL(*gl_, TexParameteri(GL_TEXTURE_EXTERNAL_OES,
5344 GL_TEXTURE_MIN_FILTER,
5346 EXPECT_CALL(*gl_, TexParameteri(GL_TEXTURE_EXTERNAL_OES,
5347 GL_TEXTURE_MIN_FILTER,
5349 EXPECT_CALL(*gl_, TexParameteri(GL_TEXTURE_EXTERNAL_OES,
5352 EXPECT_CALL(*gl_, TexParameteri(GL_TEXTURE_EXTERNAL_OES,
5356 cmd.Init(GL_TEXTURE_EXTERNAL_OES,
5357 GL_TEXTURE_MIN_FILTER,
5359 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5360 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5362 cmd.Init(GL_TEXTURE_EXTERNAL_OES,
5363 GL_TEXTURE_MIN_FILTER,
5365 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5366 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5368 cmd.Init(GL_TEXTURE_EXTERNAL_OES,
5371 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5372 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5374 cmd.Init(GL_TEXTURE_EXTERNAL_OES,
5377 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5378 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5380 TextureRef* texture_ref = GetTexture(client_texture_id_);
5381 EXPECT_TRUE(texture_ref != NULL);
5382 Texture* texture = texture_ref->texture();
5383 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
5384 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
5385 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
5386 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
5389 TEST_F(GLES2DecoderManualInitTest, EGLImageExternalTextureParamInvalid) {
5391 "GL_OES_EGL_image_external", // extensions
5394 false, // has stencil
5395 false, // request alpha
5396 false, // request depth
5397 false, // request stencil
5398 true); // bind generates resource
5400 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
5403 cmd.Init(GL_TEXTURE_EXTERNAL_OES,
5404 GL_TEXTURE_MIN_FILTER,
5405 GL_NEAREST_MIPMAP_NEAREST);
5406 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5407 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
5409 cmd.Init(GL_TEXTURE_EXTERNAL_OES,
5412 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5413 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
5415 cmd.Init(GL_TEXTURE_EXTERNAL_OES,
5418 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5419 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
5421 TextureRef* texture_ref = GetTexture(client_texture_id_);
5422 EXPECT_TRUE(texture_ref != NULL);
5423 Texture* texture = texture_ref->texture();
5424 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
5425 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
5426 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
5427 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
5430 TEST_F(GLES2DecoderManualInitTest, EGLImageExternalTexImage2DError) {
5432 "GL_OES_EGL_image_external", // extensions
5435 false, // has stencil
5436 false, // request alpha
5437 false, // request depth
5438 false, // request stencil
5439 true); // bind generates resource
5441 GLenum target = GL_TEXTURE_EXTERNAL_OES;
5443 GLenum internal_format = GL_RGBA;
5447 GLenum format = GL_RGBA;
5448 GLenum type = GL_UNSIGNED_BYTE;
5449 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
5450 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL);
5452 cmd.Init(target, level, internal_format, width, height, border, format,
5453 type, kSharedMemoryId, kSharedMemoryOffset);
5454 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5456 // TexImage2D is not allowed with GL_TEXTURE_EXTERNAL_OES targets.
5457 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
5460 TEST_F(GLES2DecoderManualInitTest, BindGeneratesResourceFalse) {
5465 false, // has stencil
5466 false, // request alpha
5467 false, // request depth
5468 false, // request stencil
5469 false); // bind generates resource
5472 cmd1.Init(GL_TEXTURE_2D, kInvalidClientId);
5473 EXPECT_NE(error::kNoError, ExecuteCmd(cmd1));
5476 cmd2.Init(GL_ARRAY_BUFFER, kInvalidClientId);
5477 EXPECT_NE(error::kNoError, ExecuteCmd(cmd2));
5479 BindFramebuffer cmd3;
5480 cmd3.Init(GL_FRAMEBUFFER, kInvalidClientId);
5481 EXPECT_NE(error::kNoError, ExecuteCmd(cmd3));
5483 BindRenderbuffer cmd4;
5484 cmd4.Init(GL_RENDERBUFFER, kInvalidClientId);
5485 EXPECT_NE(error::kNoError, ExecuteCmd(cmd4));
5488 TEST_F(GLES2DecoderManualInitTest, CreateStreamTextureCHROMIUM) {
5489 const GLuint kObjectId = 123;
5491 "GL_CHROMIUM_stream_texture", // extensions
5494 false, // has stencil
5495 false, // request alpha
5496 false, // request depth
5497 false, // request stencil
5498 true); // bind generates resource
5500 EXPECT_CALL(*stream_texture_manager(), CreateStreamTexture(
5501 kServiceTextureId, client_texture_id_))
5502 .WillOnce(Return(kObjectId))
5503 .RetiresOnSaturation();
5505 CreateStreamTextureCHROMIUM cmd;
5506 CreateStreamTextureCHROMIUM::Result* result =
5507 static_cast<CreateStreamTextureCHROMIUM::Result*>(shared_memory_address_);
5508 cmd.Init(client_texture_id_, shared_memory_id_, shared_memory_offset_);
5509 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5510 EXPECT_EQ(kObjectId, *result);
5511 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5512 TextureRef* texture_ref = GetTexture(client_texture_id_);
5513 EXPECT_TRUE(texture_ref != NULL);
5514 EXPECT_TRUE(texture_ref->texture()->IsStreamTexture());
5515 EXPECT_CALL(*stream_texture_manager(),
5516 DestroyStreamTexture(kServiceTextureId))
5518 .RetiresOnSaturation();
5521 TEST_F(GLES2DecoderManualInitTest, CreateStreamTextureCHROMIUMBadId) {
5523 "GL_CHROMIUM_stream_texture", // extensions
5526 false, // has stencil
5527 false, // request alpha
5528 false, // request depth
5529 false, // request stencil
5530 true); // bind generates resource
5532 CreateStreamTextureCHROMIUM cmd;
5533 CreateStreamTextureCHROMIUM::Result* result =
5534 static_cast<CreateStreamTextureCHROMIUM::Result*>(shared_memory_address_);
5535 cmd.Init(kNewClientId, shared_memory_id_, shared_memory_offset_);
5536 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5537 EXPECT_EQ(static_cast<GLuint>(GL_ZERO), *result);
5538 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
5541 TEST_F(GLES2DecoderManualInitTest, CreateStreamTextureCHROMIUMAlreadyBound) {
5543 "GL_CHROMIUM_stream_texture", // extensions
5546 false, // has stencil
5547 false, // request alpha
5548 false, // request depth
5549 false, // request stencil
5550 true); // bind generates resource
5551 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
5553 CreateStreamTextureCHROMIUM cmd;
5554 CreateStreamTextureCHROMIUM::Result* result =
5555 static_cast<CreateStreamTextureCHROMIUM::Result*>(shared_memory_address_);
5556 cmd.Init(client_texture_id_, shared_memory_id_, shared_memory_offset_);
5557 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5558 EXPECT_EQ(static_cast<GLuint>(GL_ZERO), *result);
5559 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
5562 TEST_F(GLES2DecoderManualInitTest, CreateStreamTextureCHROMIUMAlreadySet) {
5564 "GL_CHROMIUM_stream_texture", // extensions
5567 false, // has stencil
5568 false, // request alpha
5569 false, // request depth
5570 false, // request stencil
5571 true); // bind generates resource
5573 TextureRef* texture_ref = GetTexture(client_texture_id_);
5574 group().texture_manager()->SetStreamTexture(texture_ref, true);
5576 CreateStreamTextureCHROMIUM cmd;
5577 cmd.Init(client_texture_id_, shared_memory_id_, shared_memory_offset_);
5578 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5579 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
5581 EXPECT_CALL(*stream_texture_manager(),
5582 DestroyStreamTexture(kServiceTextureId))
5584 .RetiresOnSaturation();
5587 TEST_F(GLES2DecoderManualInitTest, DrawStreamTextureCHROMIUM) {
5589 "GL_CHROMIUM_stream_texture GL_OES_EGL_image_external", // extensions
5592 false, // has stencil
5593 true, // request alpha
5594 true, // request depth
5595 false, // request stencil
5596 true); // bind generates resource
5598 StrictMock<MockStreamTexture> stream_texture;
5600 TextureRef* texture_ref = GetTexture(client_texture_id_);
5601 group().texture_manager()->SetStreamTexture(texture_ref, true);
5603 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
5604 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5606 SetupSamplerExternalProgram();
5608 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
5609 SetupExpectationsForApplyingDefaultDirtyState();
5610 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref));
5613 EXPECT_CALL(*stream_texture_manager(), LookupStreamTexture(kServiceTextureId))
5614 .WillOnce(Return(&stream_texture))
5615 .RetiresOnSaturation();
5616 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
5618 .RetiresOnSaturation();
5619 EXPECT_CALL(stream_texture, Update())
5621 .RetiresOnSaturation();
5622 EXPECT_CALL(*gl_, DrawElements(_, _, _, _))
5625 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
5626 kValidIndexRangeStart * 2);
5627 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5628 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5630 EXPECT_CALL(*stream_texture_manager(),
5631 DestroyStreamTexture(kServiceTextureId))
5633 .RetiresOnSaturation();
5636 TEST_F(GLES2DecoderManualInitTest, BindStreamTextureCHROMIUMInvalid) {
5638 "GL_CHROMIUM_stream_texture", // extensions
5641 false, // has stencil
5642 false, // request alpha
5643 false, // request depth
5644 false, // request stencil
5645 true); // bind generates resource
5647 TextureRef* texture_ref = GetTexture(client_texture_id_);
5648 group().texture_manager()->SetStreamTexture(texture_ref, true);
5651 cmd.Init(GL_TEXTURE_2D, client_texture_id_);
5652 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5653 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
5656 cmd2.Init(GL_TEXTURE_CUBE_MAP, client_texture_id_);
5657 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
5658 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
5660 EXPECT_CALL(*stream_texture_manager(),
5661 DestroyStreamTexture(kServiceTextureId))
5663 .RetiresOnSaturation();
5666 TEST_F(GLES2DecoderManualInitTest, DestroyStreamTextureCHROMIUM) {
5668 "GL_CHROMIUM_stream_texture", // extensions
5671 false, // has stencil
5672 false, // request alpha
5673 false, // request depth
5674 false, // request stencil
5675 true); // bind generates resource
5677 TextureRef* texture_ref = GetTexture(client_texture_id_);
5678 group().texture_manager()->SetStreamTexture(texture_ref, true);
5680 EXPECT_CALL(*stream_texture_manager(),
5681 DestroyStreamTexture(kServiceTextureId))
5683 .RetiresOnSaturation();
5685 DestroyStreamTextureCHROMIUM cmd;
5686 cmd.Init(client_texture_id_);
5687 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5688 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5689 EXPECT_FALSE(texture_ref->texture()->IsStreamTexture());
5690 EXPECT_EQ(0U, texture_ref->texture()->target());
5693 TEST_F(GLES2DecoderManualInitTest, DestroyStreamTextureCHROMIUMInvalid) {
5695 "GL_CHROMIUM_stream_texture", // extensions
5698 false, // has stencil
5699 false, // request alpha
5700 false, // request depth
5701 false, // request stencil
5702 true); // bind generates resource
5704 DestroyStreamTextureCHROMIUM cmd;
5705 cmd.Init(client_texture_id_);
5706 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5707 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
5710 TEST_F(GLES2DecoderManualInitTest, DestroyStreamTextureCHROMIUMBadId) {
5712 "GL_CHROMIUM_stream_texture", // extensions
5715 false, // has stencil
5716 false, // request alpha
5717 false, // request depth
5718 false, // request stencil
5719 true); // bind generates resource
5721 DestroyStreamTextureCHROMIUM cmd;
5723 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5724 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
5727 TEST_F(GLES2DecoderManualInitTest, StreamTextureCHROMIUMNullMgr) {
5732 false, // has stencil
5733 false, // request alpha
5734 false, // request depth
5735 false, // request stencil
5736 true); // bind generates resource
5738 CreateStreamTextureCHROMIUM cmd;
5739 cmd.Init(client_texture_id_, shared_memory_id_, shared_memory_offset_);
5740 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(cmd));
5741 GetGLError(); // ignore internal error
5743 TextureRef* texture_ref = GetTexture(client_texture_id_);
5744 group().texture_manager()->SetStreamTexture(texture_ref, true);
5746 DestroyStreamTextureCHROMIUM cmd2;
5747 cmd2.Init(client_texture_id_);
5748 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(cmd2));
5749 GetGLError(); // ignore internal error
5752 TEST_F(GLES2DecoderManualInitTest, ReCreateStreamTextureCHROMIUM) {
5753 const GLuint kObjectId = 123;
5755 "GL_CHROMIUM_stream_texture GL_OES_EGL_image_external", // extensions
5758 false, // has stencil
5759 false, // request alpha
5760 false, // request depth
5761 false, // request stencil
5762 true); // bind generates resource
5764 EXPECT_CALL(*stream_texture_manager(),
5765 DestroyStreamTexture(kServiceTextureId))
5767 .RetiresOnSaturation();
5768 EXPECT_CALL(*stream_texture_manager(),
5769 CreateStreamTexture(kServiceTextureId, client_texture_id_))
5770 .WillOnce(Return(kObjectId))
5771 .RetiresOnSaturation();
5773 TextureRef* texture_ref = GetTexture(client_texture_id_);
5774 group().texture_manager()->SetStreamTexture(texture_ref, true);
5776 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
5777 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5779 DestroyStreamTextureCHROMIUM cmd;
5780 cmd.Init(client_texture_id_);
5781 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5782 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5783 EXPECT_FALSE(texture_ref->texture()->IsStreamTexture());
5785 CreateStreamTextureCHROMIUM cmd2;
5786 cmd2.Init(client_texture_id_, shared_memory_id_, shared_memory_offset_);
5787 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
5788 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5789 EXPECT_TRUE(texture_ref->texture()->IsStreamTexture());
5791 EXPECT_CALL(*stream_texture_manager(),
5792 DestroyStreamTexture(kServiceTextureId))
5794 .RetiresOnSaturation();
5797 TEST_F(GLES2DecoderManualInitTest, ProduceAndConsumeStreamTextureCHROMIUM) {
5799 "GL_CHROMIUM_stream_texture GL_OES_EGL_image_external", // extensions
5802 false, // has stencil
5803 false, // request alpha
5804 false, // request depth
5805 false, // request stencil
5806 true); // bind generates resource
5808 TextureRef* texture_ref = GetTexture(client_texture_id_);
5809 group().texture_manager()->SetStreamTexture(texture_ref, true);
5811 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
5813 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM];
5814 group().mailbox_manager()->GenerateMailboxName(
5815 reinterpret_cast<MailboxName*>(mailbox));
5817 memcpy(shared_memory_address_, mailbox, sizeof(mailbox));
5819 EXPECT_EQ(kServiceTextureId, texture_ref->service_id());
5821 ProduceTextureCHROMIUM produce_cmd;
5823 GL_TEXTURE_EXTERNAL_OES, kSharedMemoryId, kSharedMemoryOffset);
5824 EXPECT_EQ(error::kNoError, ExecuteCmd(produce_cmd));
5825 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5827 // Create new texture for consume.
5828 EXPECT_CALL(*gl_, GenTextures(_, _))
5829 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
5830 .RetiresOnSaturation();
5831 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, kNewClientId, kNewServiceId);
5833 // Assigns and binds original service size texture ID.
5834 EXPECT_CALL(*gl_, DeleteTextures(1, _))
5836 .RetiresOnSaturation();
5837 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_EXTERNAL_OES, kServiceTextureId))
5839 .RetiresOnSaturation();
5841 // Shared mem got clobbered from GetError() above.
5842 memcpy(shared_memory_address_, mailbox, sizeof(mailbox));
5843 ConsumeTextureCHROMIUM consume_cmd;
5845 GL_TEXTURE_EXTERNAL_OES, kSharedMemoryId, kSharedMemoryOffset);
5846 EXPECT_EQ(error::kNoError, ExecuteCmd(consume_cmd));
5847 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5849 // Service ID is restored.
5850 EXPECT_EQ(kServiceTextureId, texture_ref->service_id());
5852 EXPECT_CALL(*stream_texture_manager(),
5853 DestroyStreamTexture(kServiceTextureId))
5855 .RetiresOnSaturation();
5858 TEST_F(GLES2DecoderManualInitTest, ARBTextureRectangleBindTexture) {
5860 "GL_ARB_texture_rectangle", // extensions
5863 false, // has stencil
5864 false, // request alpha
5865 false, // request depth
5866 false, // request stencil
5867 true); // bind generates resource
5868 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_RECTANGLE_ARB, kNewServiceId));
5869 EXPECT_CALL(*gl_, GenTextures(1, _))
5870 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
5872 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, kNewClientId);
5873 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5874 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5875 Texture* texture = GetTexture(kNewClientId)->texture();
5876 EXPECT_TRUE(texture != NULL);
5877 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
5880 TEST_F(GLES2DecoderManualInitTest, ARBTextureRectangleGetBinding) {
5882 "GL_ARB_texture_rectangle", // extensions
5885 false, // has stencil
5886 false, // request alpha
5887 false, // request depth
5888 false, // request stencil
5889 true); // bind generates resource
5891 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
5893 EXPECT_CALL(*gl_, GetError())
5894 .WillOnce(Return(GL_NO_ERROR))
5895 .WillOnce(Return(GL_NO_ERROR))
5896 .RetiresOnSaturation();
5897 typedef GetIntegerv::Result Result;
5898 Result* result = static_cast<Result*>(shared_memory_address_);
5899 EXPECT_CALL(*gl_, GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB,
5904 cmd.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB,
5906 shared_memory_offset_);
5907 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5908 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(
5909 GL_TEXTURE_BINDING_RECTANGLE_ARB), result->GetNumResults());
5910 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5911 EXPECT_EQ(client_texture_id_, (uint32)result->GetData()[0]);
5914 TEST_F(GLES2DecoderManualInitTest, ARBTextureRectangleTextureDefaults) {
5916 "GL_ARB_texture_rectangle", // extensions
5919 false, // has stencil
5920 false, // request alpha
5921 false, // request depth
5922 false, // request stencil
5923 true); // bind generates resource
5925 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
5927 Texture* texture = GetTexture(client_texture_id_)->texture();
5928 EXPECT_TRUE(texture != NULL);
5929 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
5930 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
5931 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
5932 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
5935 TEST_F(GLES2DecoderManualInitTest, ARBTextureRectangleTextureParam) {
5937 "GL_ARB_texture_rectangle", // extensions
5940 false, // has stencil
5941 false, // request alpha
5942 false, // request depth
5943 false, // request stencil
5944 true); // bind generates resource
5947 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
5949 EXPECT_CALL(*gl_, TexParameteri(GL_TEXTURE_RECTANGLE_ARB,
5950 GL_TEXTURE_MIN_FILTER,
5952 EXPECT_CALL(*gl_, TexParameteri(GL_TEXTURE_RECTANGLE_ARB,
5953 GL_TEXTURE_MIN_FILTER,
5955 EXPECT_CALL(*gl_, TexParameteri(GL_TEXTURE_RECTANGLE_ARB,
5958 EXPECT_CALL(*gl_, TexParameteri(GL_TEXTURE_RECTANGLE_ARB,
5962 cmd.Init(GL_TEXTURE_RECTANGLE_ARB,
5963 GL_TEXTURE_MIN_FILTER,
5965 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5966 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5968 cmd.Init(GL_TEXTURE_RECTANGLE_ARB,
5969 GL_TEXTURE_MIN_FILTER,
5971 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5972 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5974 cmd.Init(GL_TEXTURE_RECTANGLE_ARB,
5977 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5978 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5980 cmd.Init(GL_TEXTURE_RECTANGLE_ARB,
5983 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
5984 EXPECT_EQ(GL_NO_ERROR, GetGLError());
5986 Texture* texture = GetTexture(client_texture_id_)->texture();
5987 EXPECT_TRUE(texture != NULL);
5988 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
5989 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
5990 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
5991 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
5994 TEST_F(GLES2DecoderManualInitTest, ARBTextureRectangleTextureParamInvalid) {
5996 "GL_ARB_texture_rectangle", // extensions
5999 false, // has stencil
6000 false, // request alpha
6001 false, // request depth
6002 false, // request stencil
6003 true); // bind generates resource
6006 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
6009 cmd.Init(GL_TEXTURE_RECTANGLE_ARB,
6010 GL_TEXTURE_MIN_FILTER,
6011 GL_NEAREST_MIPMAP_NEAREST);
6012 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6013 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
6015 cmd.Init(GL_TEXTURE_RECTANGLE_ARB,
6018 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6019 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
6021 cmd.Init(GL_TEXTURE_RECTANGLE_ARB,
6024 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6025 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
6027 Texture* texture = GetTexture(client_texture_id_)->texture();
6028 EXPECT_TRUE(texture != NULL);
6029 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
6030 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
6031 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
6032 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
6035 TEST_F(GLES2DecoderManualInitTest, ARBTextureRectangleTexImage2DError) {
6037 "GL_ARB_texture_rectangle", // extensions
6040 false, // has stencil
6041 false, // request alpha
6042 false, // request depth
6043 false, // request stencil
6044 true); // bind generates resource
6046 GLenum target = GL_TEXTURE_RECTANGLE_ARB;
6048 GLenum internal_format = GL_RGBA;
6052 GLenum format = GL_RGBA;
6053 GLenum type = GL_UNSIGNED_BYTE;
6055 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
6056 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL);
6058 cmd.Init(target, level, internal_format, width, height, border, format,
6059 type, kSharedMemoryId, kSharedMemoryOffset);
6060 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6062 // TexImage2D is not allowed with GL_TEXTURE_RECTANGLE_ARB targets.
6063 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
6066 TEST_F(GLES2DecoderTest, EnableFeatureCHROMIUMBadBucket) {
6067 const uint32 kBadBucketId = 123;
6068 EnableFeatureCHROMIUM cmd;
6069 cmd.Init(kBadBucketId, shared_memory_id_, shared_memory_offset_);
6070 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
6073 TEST_F(GLES2DecoderTest, RequestExtensionCHROMIUMBadBucket) {
6074 const uint32 kBadBucketId = 123;
6075 RequestExtensionCHROMIUM cmd;
6076 cmd.Init(kBadBucketId);
6077 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
6080 TEST_F(GLES2DecoderTest, TexSubImage2DClearsAfterTexImage2DNULL) {
6081 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
6082 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
6084 SetupClearTextureExpections(
6085 kServiceTextureId, kServiceTextureId, GL_TEXTURE_2D, GL_TEXTURE_2D,
6086 0, GL_RGBA, GL_UNSIGNED_BYTE, 2, 2);
6087 EXPECT_CALL(*gl_, TexSubImage2D(
6088 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6089 shared_memory_address_))
6091 .RetiresOnSaturation();
6094 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6095 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
6096 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6097 // Test if we call it again it does not clear.
6098 EXPECT_CALL(*gl_, TexSubImage2D(
6099 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6100 shared_memory_address_))
6102 .RetiresOnSaturation();
6103 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6106 TEST_F(GLES2DecoderTest, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData) {
6107 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
6108 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
6110 DoTexImage2DSameSize(
6111 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
6112 kSharedMemoryId, kSharedMemoryOffset);
6113 EXPECT_CALL(*gl_, TexSubImage2D(
6114 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6115 shared_memory_address_))
6117 .RetiresOnSaturation();
6120 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6121 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
6122 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6123 // Test if we call it again it does not clear.
6124 EXPECT_CALL(*gl_, TexSubImage2D(
6125 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6126 shared_memory_address_))
6128 .RetiresOnSaturation();
6129 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6132 TEST_F(GLES2DecoderANGLETest,
6133 TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData) {
6134 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
6135 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
6137 DoTexImage2DSameSize(
6138 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
6139 kSharedMemoryId, kSharedMemoryOffset);
6140 EXPECT_CALL(*gl_, TexSubImage2D(
6141 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6142 shared_memory_address_))
6144 .RetiresOnSaturation();
6147 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6148 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
6149 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6150 // Test if we call it again it does not clear.
6151 EXPECT_CALL(*gl_, TexSubImage2D(
6152 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6153 shared_memory_address_))
6155 .RetiresOnSaturation();
6156 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6159 TEST_F(GLES2DecoderTest, TexSubImage2DClearsAfterTexImage2DWithDataThenNULL) {
6160 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
6161 // Put in data (so it should be marked as cleared)
6162 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
6163 kSharedMemoryId, kSharedMemoryOffset);
6167 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
6168 // It won't actually call TexImage2D, just mark it as uncleared.
6169 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
6170 // Next call to TexSubImage2d should clear.
6171 SetupClearTextureExpections(
6172 kServiceTextureId, kServiceTextureId, GL_TEXTURE_2D, GL_TEXTURE_2D,
6173 0, GL_RGBA, GL_UNSIGNED_BYTE, 2, 2);
6174 EXPECT_CALL(*gl_, TexSubImage2D(
6175 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6176 shared_memory_address_))
6178 .RetiresOnSaturation();
6181 GL_TEXTURE_2D, 0, 1, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6182 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
6183 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6186 TEST_F(GLES2DecoderWithShaderTest, DrawArraysClearsAfterTexImage2DNULL) {
6187 SetupAllNeededVertexBuffers();
6188 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
6189 // Create an uncleared texture with 2 levels.
6190 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
6192 DoTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
6194 // Expect 2 levels will be cleared.
6195 SetupClearTextureExpections(
6196 kServiceTextureId, kServiceTextureId, GL_TEXTURE_2D, GL_TEXTURE_2D,
6197 0, GL_RGBA, GL_UNSIGNED_BYTE, 2, 2);
6198 SetupClearTextureExpections(
6199 kServiceTextureId, kServiceTextureId, GL_TEXTURE_2D, GL_TEXTURE_2D,
6200 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, 1);
6201 SetupExpectationsForApplyingDefaultDirtyState();
6202 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
6204 .RetiresOnSaturation();
6206 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
6207 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6208 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6211 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
6213 .RetiresOnSaturation();
6214 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6215 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6218 TEST_F(GLES2DecoderWithShaderTest, DrawElementsClearsAfterTexImage2DNULL) {
6219 SetupAllNeededVertexBuffers();
6221 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
6222 // Create an uncleared texture with 2 levels.
6223 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE,
6225 DoTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
6227 // Expect 2 levels will be cleared.
6228 SetupClearTextureExpections(
6229 kServiceTextureId, kServiceTextureId, GL_TEXTURE_2D, GL_TEXTURE_2D,
6230 0, GL_RGBA, GL_UNSIGNED_BYTE, 2, 2);
6231 SetupClearTextureExpections(
6232 kServiceTextureId, kServiceTextureId, GL_TEXTURE_2D, GL_TEXTURE_2D,
6233 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, 1);
6234 SetupExpectationsForApplyingDefaultDirtyState();
6236 EXPECT_CALL(*gl_, DrawElements(GL_TRIANGLES, kValidIndexRangeCount,
6238 BufferOffset(kValidIndexRangeStart * 2)))
6240 .RetiresOnSaturation();
6242 cmd.Init(GL_TRIANGLES, kValidIndexRangeCount, GL_UNSIGNED_SHORT,
6243 kValidIndexRangeStart * 2);
6244 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6245 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6248 EXPECT_CALL(*gl_, DrawElements(GL_TRIANGLES, kValidIndexRangeCount,
6250 BufferOffset(kValidIndexRangeStart * 2)))
6252 .RetiresOnSaturation();
6253 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6254 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6257 TEST_F(GLES2DecoderWithShaderTest, DrawClearsAfterTexImage2DNULLInFBO) {
6258 const GLuint kFBOClientTextureId = 4100;
6259 const GLuint kFBOServiceTextureId = 4101;
6261 SetupAllNeededVertexBuffers();
6262 // Register a texture id.
6263 EXPECT_CALL(*gl_, GenTextures(_, _))
6264 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
6265 .RetiresOnSaturation();
6266 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
6268 // Setup "render to" texture.
6269 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
6271 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
6273 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
6274 DoFramebufferTexture2D(
6275 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
6276 kFBOClientTextureId, kFBOServiceTextureId, 0, GL_NO_ERROR);
6278 // Setup "render from" texture.
6281 SetupExpectationsForFramebufferClearing(
6282 GL_FRAMEBUFFER, // target
6283 GL_COLOR_BUFFER_BIT, // clear bits
6284 0, 0, 0, 0, // color
6287 false); // scissor test
6289 SetupExpectationsForApplyingDirtyState(
6290 false, // Framebuffer is RGB
6291 false, // Framebuffer has depth
6292 false, // Framebuffer has stencil
6293 0x1111, // color bits
6294 false, // depth mask
6295 false, // depth enabled
6296 0, // front stencil mask
6297 0, // back stencil mask
6298 false, // stencil enabled
6299 false, // cull_face_enabled
6300 false, // scissor_test_enabled
6301 false); // blend_enabled
6303 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
6305 .RetiresOnSaturation();
6307 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
6308 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6309 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6312 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
6314 .RetiresOnSaturation();
6315 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6316 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6319 TEST_F(GLES2DecoderWithShaderTest, DrawWitFBOThatCantClearDoesNotDraw) {
6320 const GLuint kFBOClientTextureId = 4100;
6321 const GLuint kFBOServiceTextureId = 4101;
6323 // Register a texture id.
6324 EXPECT_CALL(*gl_, GenTextures(_, _))
6325 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
6326 .RetiresOnSaturation();
6327 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
6329 // Setup "render to" texture.
6330 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
6332 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
6334 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
6335 DoFramebufferTexture2D(
6336 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
6337 kFBOClientTextureId, kFBOServiceTextureId, 0, GL_NO_ERROR);
6339 // Setup "render from" texture.
6342 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
6343 .WillOnce(Return(GL_FRAMEBUFFER_UNSUPPORTED))
6344 .RetiresOnSaturation();
6345 EXPECT_CALL(*gl_, DrawArrays(_, _, _))
6347 .RetiresOnSaturation();
6349 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
6350 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6351 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError());
6354 TEST_F(GLES2DecoderTest, CopyTexImage2DMarksTextureAsCleared) {
6355 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
6357 TextureManager* manager = group().texture_manager();
6358 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
6359 ASSERT_TRUE(texture_ref != NULL);
6360 Texture* texture = texture_ref->texture();
6362 EXPECT_CALL(*gl_, GetError())
6363 .WillOnce(Return(GL_NO_ERROR))
6364 .RetiresOnSaturation();
6365 EXPECT_CALL(*gl_, CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1, 0))
6367 .RetiresOnSaturation();
6368 EXPECT_CALL(*gl_, GetError())
6369 .WillOnce(Return(GL_NO_ERROR))
6370 .RetiresOnSaturation();
6372 cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1, 0);
6373 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6375 EXPECT_TRUE(texture->SafeToRenderFrom());
6378 TEST_F(GLES2DecoderTest, CopyTexSubImage2DClearsUnclearedTexture) {
6379 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
6381 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
6383 SetupClearTextureExpections(
6384 kServiceTextureId, kServiceTextureId, GL_TEXTURE_2D, GL_TEXTURE_2D,
6385 0, GL_RGBA, GL_UNSIGNED_BYTE, 2, 2);
6386 EXPECT_CALL(*gl_, CopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1))
6388 .RetiresOnSaturation();
6389 CopyTexSubImage2D cmd;
6390 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
6391 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6394 TEST_F(GLES2DecoderManualInitTest, CompressedImage2DMarksTextureAsCleared) {
6396 "GL_EXT_texture_compression_s3tc", // extensions
6399 false, // has stencil
6400 false, // request alpha
6401 false, // request depth
6402 false, // request stencil
6403 true); // bind generates resource
6405 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
6406 EXPECT_CALL(*gl_, GetError())
6407 .WillOnce(Return(GL_NO_ERROR))
6408 .RetiresOnSaturation();
6409 EXPECT_CALL(*gl_, CompressedTexImage2D(
6410 GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 8, _))
6412 .RetiresOnSaturation();
6413 EXPECT_CALL(*gl_, GetError())
6414 .WillOnce(Return(GL_NO_ERROR))
6415 .RetiresOnSaturation();
6416 CompressedTexImage2D cmd;
6417 cmd.Init(GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0,
6418 8, kSharedMemoryId, kSharedMemoryOffset);
6419 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6420 TextureManager* manager = group().texture_manager();
6421 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
6422 EXPECT_TRUE(texture_ref->texture()->SafeToRenderFrom());
6425 TEST_F(GLES2DecoderWithShaderTest, UnClearedAttachmentsGetClearedOnClear) {
6426 const GLuint kFBOClientTextureId = 4100;
6427 const GLuint kFBOServiceTextureId = 4101;
6429 // Register a texture id.
6430 EXPECT_CALL(*gl_, GenTextures(_, _))
6431 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
6432 .RetiresOnSaturation();
6433 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
6435 // Setup "render to" texture.
6436 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
6438 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
6440 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
6441 DoFramebufferTexture2D(
6442 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
6443 kFBOClientTextureId, kFBOServiceTextureId, 0, GL_NO_ERROR);
6445 // Setup "render from" texture.
6448 SetupExpectationsForFramebufferClearing(
6449 GL_FRAMEBUFFER, // target
6450 GL_COLOR_BUFFER_BIT, // clear bits
6451 0, 0, 0, 0, // color
6454 false); // scissor test
6455 SetupExpectationsForApplyingDirtyState(
6456 false, // Framebuffer is RGB
6457 false, // Framebuffer has depth
6458 false, // Framebuffer has stencil
6459 0x1111, // color bits
6460 false, // depth mask
6461 false, // depth enabled
6462 0, // front stencil mask
6463 0, // back stencil mask
6464 false, // stencil enabled
6465 false, // cull_face_enabled
6466 false, // scissor_test_enabled
6467 false); // blend_enabled
6469 EXPECT_CALL(*gl_, Clear(GL_COLOR_BUFFER_BIT))
6471 .RetiresOnSaturation();
6474 cmd.Init(GL_COLOR_BUFFER_BIT);
6475 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6476 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6479 TEST_F(GLES2DecoderWithShaderTest, UnClearedAttachmentsGetClearedOnReadPixels) {
6480 const GLuint kFBOClientTextureId = 4100;
6481 const GLuint kFBOServiceTextureId = 4101;
6483 // Register a texture id.
6484 EXPECT_CALL(*gl_, GenTextures(_, _))
6485 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
6486 .RetiresOnSaturation();
6487 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
6489 // Setup "render to" texture.
6490 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
6492 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
6494 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
6495 DoFramebufferTexture2D(
6496 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
6497 kFBOClientTextureId, kFBOServiceTextureId, 0, GL_NO_ERROR);
6499 // Setup "render from" texture.
6502 SetupExpectationsForFramebufferClearing(
6503 GL_FRAMEBUFFER, // target
6504 GL_COLOR_BUFFER_BIT, // clear bits
6505 0, 0, 0, 0, // color
6508 false); // scissor test
6510 EXPECT_CALL(*gl_, GetError())
6511 .WillOnce(Return(GL_NO_ERROR))
6512 .WillOnce(Return(GL_NO_ERROR))
6513 .RetiresOnSaturation();
6514 EXPECT_CALL(*gl_, ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, _))
6516 .RetiresOnSaturation();
6517 typedef ReadPixels::Result Result;
6518 Result* result = GetSharedMemoryAs<Result*>();
6519 uint32 result_shm_id = kSharedMemoryId;
6520 uint32 result_shm_offset = kSharedMemoryOffset;
6521 uint32 pixels_shm_id = kSharedMemoryId;
6522 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result);
6524 cmd.Init(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6525 pixels_shm_id, pixels_shm_offset,
6526 result_shm_id, result_shm_offset,
6528 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6529 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6532 TEST_F(GLES2DecoderManualInitTest,
6533 UnClearedAttachmentsGetClearedOnReadPixelsAndDrawBufferGetsRestored) {
6535 "GL_EXT_framebuffer_multisample", // extensions
6538 false, // has stencil
6539 false, // request alpha
6540 false, // request depth
6541 false, // request stencil
6542 true); // bind generates resource
6543 const GLuint kFBOClientTextureId = 4100;
6544 const GLuint kFBOServiceTextureId = 4101;
6546 // Register a texture id.
6547 EXPECT_CALL(*gl_, GenTextures(_, _))
6548 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
6549 .RetiresOnSaturation();
6550 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
6552 // Setup "render from" texture.
6553 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
6555 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
6557 GL_READ_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
6558 DoFramebufferTexture2D(
6559 GL_READ_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
6560 kFBOClientTextureId, kFBOServiceTextureId, 0, GL_NO_ERROR);
6562 SetupExpectationsForFramebufferClearingMulti(
6563 kServiceFramebufferId, // read framebuffer service id
6564 0, // backbuffer service id
6565 GL_READ_FRAMEBUFFER, // target
6566 GL_COLOR_BUFFER_BIT, // clear bits
6567 0, 0, 0, 0, // color
6570 false); // scissor test
6572 EXPECT_CALL(*gl_, GetError())
6573 .WillOnce(Return(GL_NO_ERROR))
6574 .WillOnce(Return(GL_NO_ERROR))
6575 .RetiresOnSaturation();
6576 EXPECT_CALL(*gl_, ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, _))
6578 .RetiresOnSaturation();
6579 typedef ReadPixels::Result Result;
6580 uint32 result_shm_id = kSharedMemoryId;
6581 uint32 result_shm_offset = kSharedMemoryOffset;
6582 uint32 pixels_shm_id = kSharedMemoryId;
6583 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
6585 cmd.Init(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
6586 pixels_shm_id, pixels_shm_offset,
6587 result_shm_id, result_shm_offset,
6589 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6590 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6593 TEST_F(GLES2DecoderWithShaderTest, DrawClearsAfterRenderbufferStorageInFBO) {
6595 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
6596 kServiceRenderbufferId);
6597 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
6598 kServiceFramebufferId);
6599 DoRenderbufferStorage(
6600 GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 100, 50, GL_NO_ERROR);
6601 DoFramebufferRenderbuffer(
6602 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
6603 client_renderbuffer_id_, kServiceRenderbufferId, GL_NO_ERROR);
6605 SetupExpectationsForFramebufferClearing(
6606 GL_FRAMEBUFFER, // target
6607 GL_COLOR_BUFFER_BIT, // clear bits
6608 0, 0, 0, 0, // color
6611 false); // scissor test
6613 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
6614 SetupExpectationsForApplyingDirtyState(
6615 false, // Framebuffer is RGB
6616 false, // Framebuffer has depth
6617 false, // Framebuffer has stencil
6618 0x1111, // color bits
6619 false, // depth mask
6620 false, // depth enabled
6621 0, // front stencil mask
6622 0, // back stencil mask
6623 false, // stencil enabled
6624 false, // cull_face_enabled
6625 false, // scissor_test_enabled
6626 false); // blend_enabled
6628 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
6630 .RetiresOnSaturation();
6632 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
6633 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6634 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6637 TEST_F(GLES2DecoderTest, DrawArraysClearsAfterTexImage2DNULLCubemap) {
6638 static const GLenum faces[] = {
6639 GL_TEXTURE_CUBE_MAP_POSITIVE_X,
6640 GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
6641 GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
6642 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
6643 GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
6644 GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
6646 SetupCubemapProgram();
6647 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
6648 // Fill out all the faces for 2 levels, leave 2 uncleared.
6649 for (int ii = 0; ii < 6; ++ii) {
6650 GLenum face = faces[ii];
6652 (face == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) ? 0 : kSharedMemoryId;
6654 (face == GL_TEXTURE_CUBE_MAP_NEGATIVE_Y) ? 0 : kSharedMemoryOffset;
6655 DoTexImage2D(face, 0, GL_RGBA, 2, 2, 0, GL_RGBA,
6656 GL_UNSIGNED_BYTE, shm_id, shm_offset);
6657 DoTexImage2D(face, 1, GL_RGBA, 1, 1, 0, GL_RGBA,
6658 GL_UNSIGNED_BYTE, shm_id, shm_offset);
6660 // Expect 2 levels will be cleared.
6661 SetupClearTextureExpections(
6662 kServiceTextureId, kServiceTextureId, GL_TEXTURE_CUBE_MAP,
6663 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, GL_UNSIGNED_BYTE, 2, 2);
6664 SetupClearTextureExpections(
6665 kServiceTextureId, kServiceTextureId, GL_TEXTURE_CUBE_MAP,
6666 GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 1, GL_RGBA, GL_UNSIGNED_BYTE, 1, 1);
6667 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
6668 SetupExpectationsForApplyingDefaultDirtyState();
6669 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
6671 .RetiresOnSaturation();
6673 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
6674 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6677 TEST_F(GLES2DecoderTest, TextureUsageAngleExtNotEnabledByDefault) {
6678 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
6681 cmd.Init(GL_TEXTURE_2D,
6682 GL_TEXTURE_USAGE_ANGLE,
6683 GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
6684 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6685 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
6688 TEST_F(GLES2DecoderWithShaderTest,
6689 DrawClearsAfterRenderbuffersWithMultipleAttachments) {
6690 const GLuint kFBOClientTextureId = 4100;
6691 const GLuint kFBOServiceTextureId = 4101;
6693 // Register a texture id.
6694 EXPECT_CALL(*gl_, GenTextures(_, _))
6695 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
6696 .RetiresOnSaturation();
6697 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
6699 // Setup "render to" texture.
6700 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
6702 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
6704 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
6705 DoFramebufferTexture2D(
6706 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
6707 kFBOClientTextureId, kFBOServiceTextureId, 0, GL_NO_ERROR);
6709 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
6710 kServiceRenderbufferId);
6711 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
6712 kServiceFramebufferId);
6713 DoRenderbufferStorage(
6714 GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
6716 DoFramebufferRenderbuffer(
6717 GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
6718 client_renderbuffer_id_, kServiceRenderbufferId, GL_NO_ERROR);
6721 SetupExpectationsForFramebufferClearing(
6722 GL_FRAMEBUFFER, // target
6723 GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, // clear bits
6724 0, 0, 0, 0, // color
6727 false); // scissor test
6729 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
6730 SetupExpectationsForApplyingDirtyState(
6731 false, // Framebuffer is RGB
6732 true, // Framebuffer has depth
6733 false, // Framebuffer has stencil
6734 0x1111, // color bits
6736 false, // depth enabled
6737 0, // front stencil mask
6738 0, // back stencil mask
6739 false, // stencil enabled
6740 false, // cull_face_enabled
6741 false, // scissor_test_enabled
6742 false); // blend_enabled
6744 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
6746 .RetiresOnSaturation();
6748 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
6749 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6750 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6753 TEST_F(GLES2DecoderWithShaderTest, CopyTexImageWithInCompleteFBOFails) {
6754 GLenum target = GL_TEXTURE_2D;
6756 GLenum internal_format = GL_RGBA;
6761 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
6762 kServiceRenderbufferId);
6763 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
6764 kServiceFramebufferId);
6765 DoRenderbufferStorage(
6766 GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 0, 0, GL_NO_ERROR);
6767 DoFramebufferRenderbuffer(
6768 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
6769 client_renderbuffer_id_, kServiceRenderbufferId, GL_NO_ERROR);
6771 EXPECT_CALL(*gl_, CopyTexImage2D(_, _, _, _, _, _, _, _))
6773 .RetiresOnSaturation();
6775 cmd.Init(target, level, internal_format, 0, 0, width, height, border);
6776 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6777 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError());
6780 void GLES2DecoderWithShaderTest::CheckRenderbufferChangesMarkFBOAsNotComplete(
6782 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
6784 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
6785 kServiceRenderbufferId);
6786 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
6787 kServiceFramebufferId);
6788 DoRenderbufferStorage(
6789 GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
6790 DoFramebufferRenderbuffer(
6791 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
6792 client_renderbuffer_id_, kServiceRenderbufferId, GL_NO_ERROR);
6796 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
6799 Framebuffer* framebuffer =
6800 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
6801 ASSERT_TRUE(framebuffer != NULL);
6802 framebuffer_manager->MarkAsComplete(framebuffer);
6803 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
6805 // Test that renderbufferStorage marks fbo as not complete.
6806 DoRenderbufferStorage(
6807 GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
6808 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
6809 framebuffer_manager->MarkAsComplete(framebuffer);
6810 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
6812 // Test deleting renderbuffer marks fbo as not complete.
6813 DoDeleteRenderbuffer(client_renderbuffer_id_, kServiceRenderbufferId);
6815 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
6817 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
6821 TEST_F(GLES2DecoderWithShaderTest,
6822 RenderbufferChangesMarkFBOAsNotCompleteBoundFBO) {
6823 CheckRenderbufferChangesMarkFBOAsNotComplete(true);
6826 TEST_F(GLES2DecoderWithShaderTest,
6827 RenderbufferChangesMarkFBOAsNotCompleteUnboundFBO) {
6828 CheckRenderbufferChangesMarkFBOAsNotComplete(false);
6831 void GLES2DecoderWithShaderTest::CheckTextureChangesMarkFBOAsNotComplete(
6833 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
6834 const GLuint kFBOClientTextureId = 4100;
6835 const GLuint kFBOServiceTextureId = 4101;
6837 // Register a texture id.
6838 EXPECT_CALL(*gl_, GenTextures(_, _))
6839 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
6840 .RetiresOnSaturation();
6841 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
6845 // Setup "render to" texture.
6846 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
6848 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
6850 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
6851 DoFramebufferTexture2D(
6852 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
6853 kFBOClientTextureId, kFBOServiceTextureId, 0, GL_NO_ERROR);
6855 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
6856 kServiceRenderbufferId);
6857 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
6858 kServiceFramebufferId);
6859 DoRenderbufferStorage(
6860 GL_RENDERBUFFER, GL_DEPTH_COMPONENT16, GL_DEPTH_COMPONENT,
6862 DoFramebufferRenderbuffer(
6863 GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER,
6864 client_renderbuffer_id_, kServiceRenderbufferId, GL_NO_ERROR);
6867 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
6870 Framebuffer* framebuffer =
6871 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
6872 ASSERT_TRUE(framebuffer != NULL);
6873 framebuffer_manager->MarkAsComplete(framebuffer);
6874 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
6876 // Test TexImage2D marks fbo as not complete.
6878 GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, 0, 0);
6879 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
6880 framebuffer_manager->MarkAsComplete(framebuffer);
6881 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
6883 // Test CopyImage2D marks fbo as not complete.
6884 EXPECT_CALL(*gl_, GetError())
6885 .WillOnce(Return(GL_NO_ERROR))
6886 .RetiresOnSaturation();
6887 EXPECT_CALL(*gl_, CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 1, 1, 0))
6889 .RetiresOnSaturation();
6890 EXPECT_CALL(*gl_, GetError())
6891 .WillOnce(Return(GL_NO_ERROR))
6892 .RetiresOnSaturation();
6894 cmd.Init(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 1, 1, 0);
6895 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6896 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
6898 // Test deleting texture marks fbo as not complete.
6899 framebuffer_manager->MarkAsComplete(framebuffer);
6900 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
6901 DoDeleteTexture(kFBOClientTextureId, kFBOServiceTextureId);
6904 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
6906 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
6910 TEST_F(GLES2DecoderWithShaderTest, TextureChangesMarkFBOAsNotCompleteBoundFBO) {
6911 CheckTextureChangesMarkFBOAsNotComplete(true);
6914 TEST_F(GLES2DecoderWithShaderTest,
6915 TextureChangesMarkFBOAsNotCompleteUnboundFBO) {
6916 CheckTextureChangesMarkFBOAsNotComplete(false);
6919 TEST_F(GLES2DecoderWithShaderTest,
6920 DrawingWithFBOTwiceChecksForFBOCompleteOnce) {
6921 const GLuint kFBOClientTextureId = 4100;
6922 const GLuint kFBOServiceTextureId = 4101;
6924 SetupAllNeededVertexBuffers();
6926 // Register a texture id.
6927 EXPECT_CALL(*gl_, GenTextures(_, _))
6928 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
6929 .RetiresOnSaturation();
6930 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
6932 // Setup "render to" texture that is cleared.
6933 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
6935 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
6936 kSharedMemoryId, kSharedMemoryOffset);
6938 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
6939 DoFramebufferTexture2D(
6940 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
6941 kFBOClientTextureId, kFBOServiceTextureId, 0, GL_NO_ERROR);
6943 // Setup "render from" texture.
6946 // Make sure we check for framebuffer complete.
6947 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
6948 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
6949 .RetiresOnSaturation();
6951 SetupExpectationsForApplyingDirtyState(
6952 false, // Framebuffer is RGB
6953 false, // Framebuffer has depth
6954 false, // Framebuffer has stencil
6955 0x1111, // color bits
6956 false, // depth mask
6957 false, // depth enabled
6958 0, // front stencil mask
6959 0, // back stencil mask
6960 false, // stencil enabled
6961 false, // cull_face_enabled
6962 false, // scissor_test_enabled
6963 false); // blend_enabled
6965 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
6967 .RetiresOnSaturation();
6969 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
6970 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6971 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6974 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
6976 .RetiresOnSaturation();
6977 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
6978 EXPECT_EQ(GL_NO_ERROR, GetGLError());
6981 TEST_F(GLES2DecoderTest, BeginQueryEXTDisabled) {
6982 // Test something fails if off.
6985 TEST_F(GLES2DecoderManualInitTest, BeginEndQueryEXT) {
6987 "GL_EXT_occlusion_query_boolean", // extensions
6990 false, // has stencil
6991 true, // request alpha
6992 false, // request depth
6993 false, // request stencil
6994 true); // bind generates resource
6996 // Test end fails if no begin.
6997 EndQueryEXT end_cmd;
6998 end_cmd.Init(GL_ANY_SAMPLES_PASSED_EXT, 1);
6999 EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
7000 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
7002 BeginQueryEXT begin_cmd;
7004 // Test id = 0 fails.
7006 GL_ANY_SAMPLES_PASSED_EXT, 0, kSharedMemoryId, kSharedMemoryOffset);
7007 EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
7008 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
7010 GenHelper<GenQueriesEXTImmediate>(kNewClientId);
7012 // Test valid parameters work.
7013 EXPECT_CALL(*gl_, GenQueriesARB(1, _))
7014 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
7015 .RetiresOnSaturation();
7016 EXPECT_CALL(*gl_, BeginQueryARB(GL_ANY_SAMPLES_PASSED_EXT, kNewServiceId))
7018 .RetiresOnSaturation();
7020 GL_ANY_SAMPLES_PASSED_EXT, kNewClientId,
7021 kSharedMemoryId, kSharedMemoryOffset);
7022 EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
7023 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7025 QueryManager* query_manager = decoder_->GetQueryManager();
7026 ASSERT_TRUE(query_manager != NULL);
7027 QueryManager::Query* query = query_manager->GetQuery(kNewClientId);
7028 ASSERT_TRUE(query != NULL);
7029 EXPECT_FALSE(query->pending());
7031 // Test trying begin again fails
7032 EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
7033 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
7035 // Test end fails with different target
7036 end_cmd.Init(GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, 1);
7037 EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
7038 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
7040 // Test end succeeds
7041 EXPECT_CALL(*gl_, EndQueryARB(GL_ANY_SAMPLES_PASSED_EXT))
7043 .RetiresOnSaturation();
7044 end_cmd.Init(GL_ANY_SAMPLES_PASSED_EXT, 1);
7045 EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
7046 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7047 EXPECT_TRUE(query->pending());
7049 EXPECT_CALL(*gl_, DeleteQueriesARB(1, _))
7051 .RetiresOnSaturation();
7054 static void CheckBeginEndQueryBadMemoryFails(
7055 GLES2DecoderTestBase* test,
7059 uint32 shm_offset) {
7060 ::testing::StrictMock< ::gfx::MockGLInterface>* gl = test->GetGLMock();
7062 BeginQueryEXT begin_cmd;
7064 test->GenHelper<GenQueriesEXTImmediate>(client_id);
7066 EXPECT_CALL(*gl, GenQueriesARB(1, _))
7067 .WillOnce(SetArgumentPointee<1>(service_id))
7068 .RetiresOnSaturation();
7069 EXPECT_CALL(*gl, BeginQueryARB(GL_ANY_SAMPLES_PASSED_EXT, service_id))
7071 .RetiresOnSaturation();
7073 // Test bad shared memory fails
7074 begin_cmd.Init(GL_ANY_SAMPLES_PASSED_EXT, client_id, shm_id, shm_offset);
7075 error::Error error1 = test->ExecuteCmd(begin_cmd);
7077 EXPECT_CALL(*gl, EndQueryARB(GL_ANY_SAMPLES_PASSED_EXT))
7079 .RetiresOnSaturation();
7081 EndQueryEXT end_cmd;
7082 end_cmd.Init(GL_ANY_SAMPLES_PASSED_EXT, 1);
7083 error::Error error2 = test->ExecuteCmd(end_cmd);
7086 GetQueryObjectuivARB(service_id, GL_QUERY_RESULT_AVAILABLE_EXT, _))
7087 .WillOnce(SetArgumentPointee<2>(1))
7088 .RetiresOnSaturation();
7090 GetQueryObjectuivARB(service_id, GL_QUERY_RESULT_EXT, _))
7091 .WillOnce(SetArgumentPointee<2>(1))
7092 .RetiresOnSaturation();
7094 QueryManager* query_manager = test->GetDecoder()->GetQueryManager();
7095 ASSERT_TRUE(query_manager != NULL);
7096 bool process_success = query_manager->ProcessPendingQueries();
7098 EXPECT_TRUE(error1 != error::kNoError ||
7099 error2 != error::kNoError ||
7102 EXPECT_CALL(*gl, DeleteQueriesARB(1, _))
7104 .RetiresOnSaturation();
7107 TEST_F(GLES2DecoderManualInitTest, BeginEndQueryEXTBadMemoryIdFails) {
7109 "GL_EXT_occlusion_query_boolean", // extensions
7112 false, // has stencil
7113 true, // request alpha
7114 false, // request depth
7115 false, // request stencil
7116 true); // bind generates resource
7118 CheckBeginEndQueryBadMemoryFails(
7119 this, kNewClientId, kNewServiceId,
7120 kInvalidSharedMemoryId, kSharedMemoryOffset);
7123 TEST_F(GLES2DecoderManualInitTest, BeginEndQueryEXTBadMemoryOffsetFails) {
7125 "GL_EXT_occlusion_query_boolean", // extensions
7128 false, // has stencil
7129 true, // request alpha
7130 false, // request depth
7131 false, // request stencil
7132 true); // bind generates resource
7134 CheckBeginEndQueryBadMemoryFails(
7135 this, kNewClientId, kNewServiceId,
7136 kSharedMemoryId, kInvalidSharedMemoryOffset);
7139 TEST_F(GLES2DecoderTest, BeginEndQueryEXTCommandsIssuedCHROMIUM) {
7140 BeginQueryEXT begin_cmd;
7142 GenHelper<GenQueriesEXTImmediate>(kNewClientId);
7144 // Test valid parameters work.
7146 GL_COMMANDS_ISSUED_CHROMIUM, kNewClientId,
7147 kSharedMemoryId, kSharedMemoryOffset);
7148 EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
7149 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7151 QueryManager* query_manager = decoder_->GetQueryManager();
7152 ASSERT_TRUE(query_manager != NULL);
7153 QueryManager::Query* query = query_manager->GetQuery(kNewClientId);
7154 ASSERT_TRUE(query != NULL);
7155 EXPECT_FALSE(query->pending());
7157 // Test end succeeds
7158 EndQueryEXT end_cmd;
7159 end_cmd.Init(GL_COMMANDS_ISSUED_CHROMIUM, 1);
7160 EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
7161 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7162 EXPECT_FALSE(query->pending());
7165 TEST_F(GLES2DecoderTest, BeginEndQueryEXTGetErrorQueryCHROMIUM) {
7166 BeginQueryEXT begin_cmd;
7168 GenHelper<GenQueriesEXTImmediate>(kNewClientId);
7170 // Test valid parameters work.
7172 GL_GET_ERROR_QUERY_CHROMIUM, kNewClientId,
7173 kSharedMemoryId, kSharedMemoryOffset);
7174 EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
7175 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7177 QueryManager* query_manager = decoder_->GetQueryManager();
7178 ASSERT_TRUE(query_manager != NULL);
7179 QueryManager::Query* query = query_manager->GetQuery(kNewClientId);
7180 ASSERT_TRUE(query != NULL);
7181 EXPECT_FALSE(query->pending());
7183 // Test end succeeds
7184 QuerySync* sync = static_cast<QuerySync*>(shared_memory_address_);
7186 EXPECT_CALL(*gl_, GetError())
7187 .WillOnce(Return(GL_INVALID_VALUE))
7188 .RetiresOnSaturation();
7190 EndQueryEXT end_cmd;
7191 end_cmd.Init(GL_GET_ERROR_QUERY_CHROMIUM, 1);
7192 EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
7193 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7194 EXPECT_FALSE(query->pending());
7195 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE),
7196 static_cast<GLenum>(sync->result));
7199 TEST_F(GLES2DecoderTest, ProduceAndConsumeTextureCHROMIUM) {
7200 GLbyte mailbox[GL_MAILBOX_SIZE_CHROMIUM];
7201 group().mailbox_manager()->GenerateMailboxName(
7202 reinterpret_cast<MailboxName*>(mailbox));
7204 memcpy(shared_memory_address_, mailbox, sizeof(mailbox));
7206 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
7207 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
7209 DoTexImage2D(GL_TEXTURE_2D, 1, GL_RGBA, 2, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
7211 TextureRef* texture_ref = group().texture_manager()->GetTexture(
7212 client_texture_id_);
7213 ASSERT_TRUE(texture_ref != NULL);
7214 Texture* texture = texture_ref->texture();
7215 EXPECT_EQ(kServiceTextureId, texture->service_id());
7217 ProduceTextureCHROMIUM produce_cmd;
7218 produce_cmd.Init(GL_TEXTURE_2D, kSharedMemoryId, kSharedMemoryOffset);
7219 EXPECT_EQ(error::kNoError, ExecuteCmd(produce_cmd));
7220 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7222 // Texture didn't change.
7226 GLenum internal_format;
7228 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
7229 EXPECT_EQ(3, width);
7230 EXPECT_EQ(1, height);
7231 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
7232 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
7233 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
7235 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
7236 EXPECT_EQ(2, width);
7237 EXPECT_EQ(4, height);
7238 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
7239 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
7240 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
7242 // Service ID has not changed.
7243 EXPECT_EQ(kServiceTextureId, texture->service_id());
7245 // Create new texture for consume.
7246 EXPECT_CALL(*gl_, GenTextures(_, _))
7247 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
7248 .RetiresOnSaturation();
7249 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kNewServiceId);
7251 // Assigns and binds original service size texture ID.
7252 EXPECT_CALL(*gl_, DeleteTextures(1, _))
7254 .RetiresOnSaturation();
7255 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
7257 .RetiresOnSaturation();
7259 memcpy(shared_memory_address_, mailbox, sizeof(mailbox));
7260 ConsumeTextureCHROMIUM consume_cmd;
7261 consume_cmd.Init(GL_TEXTURE_2D, kSharedMemoryId, kSharedMemoryOffset);
7262 EXPECT_EQ(error::kNoError, ExecuteCmd(consume_cmd));
7263 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7265 // Texture is redefined.
7266 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
7267 EXPECT_EQ(3, width);
7268 EXPECT_EQ(1, height);
7269 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
7270 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
7271 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
7273 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
7274 EXPECT_EQ(2, width);
7275 EXPECT_EQ(4, height);
7276 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
7277 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
7278 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
7280 // Service ID is restored.
7281 EXPECT_EQ(kServiceTextureId, texture->service_id());
7285 TEST_F(GLES2DecoderTest, CanChangeSurface) {
7286 scoped_refptr<GLSurfaceMock> other_surface(new GLSurfaceMock);
7287 EXPECT_CALL(*other_surface.get(), GetBackingFrameBufferObject()).
7288 WillOnce(Return(7));
7289 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 7));
7291 decoder_->SetSurface(other_surface);
7294 TEST_F(GLES2DecoderTest, IsEnabledReturnsCachedValue) {
7295 // NOTE: There are no expectations because no GL functions should be
7296 // called for DEPTH_TEST or STENCIL_TEST
7297 static const GLenum kStates[] = {
7301 for (size_t ii = 0; ii < arraysize(kStates); ++ii) {
7303 GLenum state = kStates[ii];
7304 enable_cmd.Init(state);
7305 EXPECT_EQ(error::kNoError, ExecuteCmd(enable_cmd));
7306 IsEnabled::Result* result =
7307 static_cast<IsEnabled::Result*>(shared_memory_address_);
7308 IsEnabled is_enabled_cmd;
7309 is_enabled_cmd.Init(state, shared_memory_id_, shared_memory_offset_);
7310 EXPECT_EQ(error::kNoError, ExecuteCmd(is_enabled_cmd));
7311 EXPECT_NE(0u, *result);
7312 Disable disable_cmd;
7313 disable_cmd.Init(state);
7314 EXPECT_EQ(error::kNoError, ExecuteCmd(disable_cmd));
7315 EXPECT_EQ(error::kNoError, ExecuteCmd(is_enabled_cmd));
7316 EXPECT_EQ(0u, *result);
7320 TEST_F(GLES2DecoderManualInitTest, DepthTextureBadArgs) {
7322 "GL_ANGLE_depth_texture", // extensions
7325 true, // has stencil
7326 false, // request alpha
7327 true, // request depth
7328 true, // request stencil
7329 true); // bind generates resource
7331 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
7332 // Check trying to upload data fails.
7335 GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
7336 1, 1, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,
7337 kSharedMemoryId, kSharedMemoryOffset);
7338 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
7339 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
7342 GL_TEXTURE_2D, 1, GL_DEPTH_COMPONENT,
7343 1, 1, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0, 0);
7344 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
7345 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
7346 // Make a 1 pixel depth texture.
7347 DoTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
7348 1, 1, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0, 0);
7349 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7351 // Check that trying to update it fails.
7352 TexSubImage2D tex_sub_cmd;
7354 GL_TEXTURE_2D, 0, 0, 0, 1, 1, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,
7355 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
7356 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_sub_cmd));
7357 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
7359 // Check that trying to CopyTexImage2D fails
7360 CopyTexImage2D copy_tex_cmd;
7361 copy_tex_cmd.Init(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 1, 1, 0);
7362 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_tex_cmd));
7363 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
7365 // Check that trying to CopyTexSubImage2D fails
7366 CopyTexSubImage2D copy_sub_cmd;
7367 copy_sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
7368 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_sub_cmd));
7369 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
7372 TEST_F(GLES2DecoderManualInitTest, GenerateMipmapDepthTexture) {
7374 "GL_ANGLE_depth_texture", // extensions
7377 true, // has stencil
7378 false, // request alpha
7379 true, // request depth
7380 true, // request stencil
7381 true); // bind generates resource
7382 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
7383 DoTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT,
7384 2, 2, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT,
7387 cmd.Init(GL_TEXTURE_2D);
7388 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7389 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
7392 TEST_F(GLES2DecoderANGLEManualInitTest, DrawClearsDepthTexture) {
7394 "GL_ANGLE_depth_texture", // extensions
7397 false, // has stencil
7398 true, // request alpha
7399 true, // request depth
7400 false, // request stencil
7401 true); // bind generates resource
7403 SetupDefaultProgram();
7404 SetupAllNeededVertexBuffers();
7405 const GLenum attachment = GL_DEPTH_ATTACHMENT;
7406 const GLenum target = GL_TEXTURE_2D;
7407 const GLint level = 0;
7408 DoBindTexture(target, client_texture_id_, kServiceTextureId);
7410 // Create a depth texture.
7411 DoTexImage2D(target, level, GL_DEPTH_COMPONENT, 1, 1, 0,
7412 GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0, 0);
7414 EXPECT_CALL(*gl_, GenFramebuffersEXT(1, _))
7416 .RetiresOnSaturation();
7417 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, _))
7419 .RetiresOnSaturation();
7421 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(
7422 GL_DRAW_FRAMEBUFFER_EXT, attachment, target, kServiceTextureId, level))
7424 .RetiresOnSaturation();
7425 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT))
7426 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
7427 .RetiresOnSaturation();
7429 EXPECT_CALL(*gl_, ClearStencil(0))
7431 .RetiresOnSaturation();
7432 EXPECT_CALL(*gl_, StencilMask(-1))
7434 .RetiresOnSaturation();
7435 EXPECT_CALL(*gl_, ClearDepth(1.0f))
7437 .RetiresOnSaturation();
7438 EXPECT_CALL(*gl_, DepthMask(true))
7440 .RetiresOnSaturation();
7441 EXPECT_CALL(*gl_, Disable(GL_SCISSOR_TEST))
7443 .RetiresOnSaturation();
7445 EXPECT_CALL(*gl_, Clear(GL_DEPTH_BUFFER_BIT))
7447 .RetiresOnSaturation();
7449 SetupExpectationsForRestoreClearState(
7450 0.0f, 0.0f, 0.0f, 0.0f, 0, 1.0f, false);
7452 EXPECT_CALL(*gl_, DeleteFramebuffersEXT(1, _))
7454 .RetiresOnSaturation();
7455 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0))
7457 .RetiresOnSaturation();
7459 SetupExpectationsForApplyingDefaultDirtyState();
7460 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
7462 .RetiresOnSaturation();
7464 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
7465 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7466 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7469 TEST_F(GLES2DecoderWithShaderTest, BindUniformLocationCHROMIUM) {
7470 const GLint kLocation = 2;
7471 const char* kName = "testing";
7472 const uint32 kNameSize = strlen(kName);
7473 const char* kBadName1 = "gl_testing";
7474 const uint32 kBadName1Size = strlen(kBadName1);
7475 const char* kBadName2 = "testing[1]";
7476 const uint32 kBadName2Size = strlen(kBadName2);
7477 memcpy(shared_memory_address_, kName, kNameSize);
7478 BindUniformLocationCHROMIUM cmd;
7479 cmd.Init(client_program_id_, kLocation, kSharedMemoryId, kSharedMemoryOffset,
7481 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7482 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7483 // check negative location
7484 memcpy(shared_memory_address_, kName, kNameSize);
7485 cmd.Init(client_program_id_, -1, kSharedMemoryId, kSharedMemoryOffset,
7487 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7488 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
7489 // check highest location
7490 memcpy(shared_memory_address_, kName, kNameSize);
7491 GLint kMaxLocation =
7492 (kMaxFragmentUniformVectors + kMaxVertexUniformVectors) * 4 - 1;
7493 cmd.Init(client_program_id_, kMaxLocation, kSharedMemoryId,
7494 kSharedMemoryOffset, kNameSize);
7495 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7496 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7497 // check too high location
7498 memcpy(shared_memory_address_, kName, kNameSize);
7499 cmd.Init(client_program_id_, kMaxLocation + 1, kSharedMemoryId,
7500 kSharedMemoryOffset, kNameSize);
7501 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7502 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
7503 // check bad name "gl_..."
7504 memcpy(shared_memory_address_, kBadName1, kBadName1Size);
7505 cmd.Init(client_program_id_, kLocation, kSharedMemoryId, kSharedMemoryOffset,
7507 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7508 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
7509 // check bad name "name[1]" non zero
7510 memcpy(shared_memory_address_, kBadName2, kBadName2Size);
7511 cmd.Init(client_program_id_, kLocation, kSharedMemoryId, kSharedMemoryOffset,
7513 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7514 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
7517 class GLES2DecoderVertexArraysOESTest : public GLES2DecoderWithShaderTest {
7519 GLES2DecoderVertexArraysOESTest() { }
7521 bool vertex_array_deleted_manually_;
7523 virtual void SetUp() {
7525 "GL_OES_vertex_array_object", // extensions
7528 false, // has stencil
7529 false, // request alpha
7530 false, // request depth
7531 false, // request stencil
7532 true); // bind generates resource
7533 SetupDefaultProgram();
7535 AddExpectationsForGenVertexArraysOES();
7536 GenHelper<GenVertexArraysOESImmediate>(client_vertexarray_id_);
7538 vertex_array_deleted_manually_ = false;
7541 virtual void TearDown() {
7542 // This should only be set if the test handled deletion of the vertex array
7543 // itself. Necessary because vertex_array_objects are not sharable, and thus
7544 // not managed in the ContextGroup, meaning they will be destroyed during
7546 if (!vertex_array_deleted_manually_) {
7547 AddExpectationsForDeleteVertexArraysOES();
7550 GLES2DecoderWithShaderTest::TearDown();
7553 void GenVertexArraysOESValidArgs() {
7554 AddExpectationsForGenVertexArraysOES();
7555 GetSharedMemoryAs<GLuint*>()[0] = kNewClientId;
7556 GenVertexArraysOES cmd;
7557 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
7558 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7559 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7560 EXPECT_TRUE(GetVertexArrayInfo(kNewClientId) != NULL);
7561 AddExpectationsForDeleteVertexArraysOES();
7564 void GenVertexArraysOESInvalidArgs() {
7565 EXPECT_CALL(*gl_, GenVertexArraysOES(_, _)).Times(0);
7566 GetSharedMemoryAs<GLuint*>()[0] = client_vertexarray_id_;
7567 GenVertexArraysOES cmd;
7568 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
7569 EXPECT_EQ(error::kInvalidArguments, ExecuteCmd(cmd));
7572 void GenVertexArraysOESImmediateValidArgs() {
7573 AddExpectationsForGenVertexArraysOES();
7574 GenVertexArraysOESImmediate* cmd =
7575 GetImmediateAs<GenVertexArraysOESImmediate>();
7576 GLuint temp = kNewClientId;
7577 cmd->Init(1, &temp);
7578 EXPECT_EQ(error::kNoError,
7579 ExecuteImmediateCmd(*cmd, sizeof(temp)));
7580 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7581 EXPECT_TRUE(GetVertexArrayInfo(kNewClientId) != NULL);
7582 AddExpectationsForDeleteVertexArraysOES();
7585 void GenVertexArraysOESImmediateInvalidArgs() {
7586 EXPECT_CALL(*gl_, GenVertexArraysOES(_, _)).Times(0);
7587 GenVertexArraysOESImmediate* cmd =
7588 GetImmediateAs<GenVertexArraysOESImmediate>();
7589 cmd->Init(1, &client_vertexarray_id_);
7590 EXPECT_EQ(error::kInvalidArguments,
7591 ExecuteImmediateCmd(*cmd, sizeof(&client_vertexarray_id_)));
7594 void DeleteVertexArraysOESValidArgs() {
7595 AddExpectationsForDeleteVertexArraysOES();
7596 GetSharedMemoryAs<GLuint*>()[0] = client_vertexarray_id_;
7597 DeleteVertexArraysOES cmd;
7598 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
7599 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7600 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7602 GetVertexArrayInfo(client_vertexarray_id_) == NULL);
7603 vertex_array_deleted_manually_ = true;
7606 void DeleteVertexArraysOESInvalidArgs() {
7607 GetSharedMemoryAs<GLuint*>()[0] = kInvalidClientId;
7608 DeleteVertexArraysOES cmd;
7609 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
7610 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7613 void DeleteVertexArraysOESImmediateValidArgs() {
7614 AddExpectationsForDeleteVertexArraysOES();
7615 DeleteVertexArraysOESImmediate& cmd =
7616 *GetImmediateAs<DeleteVertexArraysOESImmediate>();
7617 cmd.Init(1, &client_vertexarray_id_);
7618 EXPECT_EQ(error::kNoError,
7619 ExecuteImmediateCmd(cmd, sizeof(client_vertexarray_id_)));
7620 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7622 GetVertexArrayInfo(client_vertexarray_id_) == NULL);
7623 vertex_array_deleted_manually_ = true;
7626 void DeleteVertexArraysOESImmediateInvalidArgs() {
7627 DeleteVertexArraysOESImmediate& cmd =
7628 *GetImmediateAs<DeleteVertexArraysOESImmediate>();
7629 GLuint temp = kInvalidClientId;
7631 EXPECT_EQ(error::kNoError,
7632 ExecuteImmediateCmd(cmd, sizeof(temp)));
7635 void IsVertexArrayOESValidArgs() {
7636 IsVertexArrayOES cmd;
7637 cmd.Init(client_vertexarray_id_, shared_memory_id_, shared_memory_offset_);
7638 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7639 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7642 void IsVertexArrayOESInvalidArgsBadSharedMemoryId() {
7643 IsVertexArrayOES cmd;
7645 client_vertexarray_id_, kInvalidSharedMemoryId, shared_memory_offset_);
7646 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
7648 client_vertexarray_id_, shared_memory_id_, kInvalidSharedMemoryOffset);
7649 EXPECT_EQ(error::kOutOfBounds, ExecuteCmd(cmd));
7652 void BindVertexArrayOESValidArgs() {
7653 AddExpectationsForBindVertexArrayOES();
7654 BindVertexArrayOES cmd;
7655 cmd.Init(client_vertexarray_id_);
7656 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7657 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7660 void BindVertexArrayOESValidArgsNewId() {
7661 BindVertexArrayOES cmd;
7662 cmd.Init(kNewClientId);
7663 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7664 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
7668 class GLES2DecoderEmulatedVertexArraysOESTest
7669 : public GLES2DecoderVertexArraysOESTest {
7671 GLES2DecoderEmulatedVertexArraysOESTest() { }
7673 virtual void SetUp() {
7678 false, // has stencil
7679 false, // request alpha
7680 false, // request depth
7681 false, // request stencil
7682 true); // bind generates resource
7683 SetupDefaultProgram();
7685 AddExpectationsForGenVertexArraysOES();
7686 GenHelper<GenVertexArraysOESImmediate>(client_vertexarray_id_);
7688 vertex_array_deleted_manually_ = false;
7692 // Test vertex array objects with native support
7693 TEST_F(GLES2DecoderVertexArraysOESTest, GenVertexArraysOESValidArgs) {
7694 GenVertexArraysOESValidArgs();
7696 TEST_F(GLES2DecoderEmulatedVertexArraysOESTest, GenVertexArraysOESValidArgs) {
7697 GenVertexArraysOESValidArgs();
7700 TEST_F(GLES2DecoderVertexArraysOESTest, GenVertexArraysOESInvalidArgs) {
7701 GenVertexArraysOESInvalidArgs();
7703 TEST_F(GLES2DecoderEmulatedVertexArraysOESTest, ) {
7704 GenVertexArraysOESInvalidArgs();
7707 TEST_F(GLES2DecoderVertexArraysOESTest, GenVertexArraysOESImmediateValidArgs) {
7708 GenVertexArraysOESImmediateValidArgs();
7710 TEST_F(GLES2DecoderEmulatedVertexArraysOESTest,
7711 GenVertexArraysOESImmediateValidArgs) {
7712 GenVertexArraysOESImmediateValidArgs();
7715 TEST_F(GLES2DecoderVertexArraysOESTest,
7716 GenVertexArraysOESImmediateInvalidArgs) {
7717 GenVertexArraysOESImmediateInvalidArgs();
7719 TEST_F(GLES2DecoderEmulatedVertexArraysOESTest,
7720 GenVertexArraysOESImmediateInvalidArgs) {
7721 GenVertexArraysOESImmediateInvalidArgs();
7724 TEST_F(GLES2DecoderVertexArraysOESTest, DeleteVertexArraysOESValidArgs) {
7725 DeleteVertexArraysOESValidArgs();
7727 TEST_F(GLES2DecoderEmulatedVertexArraysOESTest,
7728 DeleteVertexArraysOESValidArgs) {
7729 DeleteVertexArraysOESValidArgs();
7732 TEST_F(GLES2DecoderVertexArraysOESTest, DeleteVertexArraysOESInvalidArgs) {
7733 DeleteVertexArraysOESInvalidArgs();
7735 TEST_F(GLES2DecoderEmulatedVertexArraysOESTest,
7736 DeleteVertexArraysOESInvalidArgs) {
7737 DeleteVertexArraysOESInvalidArgs();
7740 TEST_F(GLES2DecoderVertexArraysOESTest,
7741 DeleteVertexArraysOESImmediateValidArgs) {
7742 DeleteVertexArraysOESImmediateValidArgs();
7744 TEST_F(GLES2DecoderEmulatedVertexArraysOESTest,
7745 DeleteVertexArraysOESImmediateValidArgs) {
7746 DeleteVertexArraysOESImmediateValidArgs();
7749 TEST_F(GLES2DecoderVertexArraysOESTest,
7750 DeleteVertexArraysOESImmediateInvalidArgs) {
7751 DeleteVertexArraysOESImmediateInvalidArgs();
7753 TEST_F(GLES2DecoderEmulatedVertexArraysOESTest,
7754 DeleteVertexArraysOESImmediateInvalidArgs) {
7755 DeleteVertexArraysOESImmediateInvalidArgs();
7758 TEST_F(GLES2DecoderVertexArraysOESTest, IsVertexArrayOESValidArgs) {
7759 IsVertexArrayOESValidArgs();
7761 TEST_F(GLES2DecoderEmulatedVertexArraysOESTest, IsVertexArrayOESValidArgs) {
7762 IsVertexArrayOESValidArgs();
7765 TEST_F(GLES2DecoderVertexArraysOESTest,
7766 IsVertexArrayOESInvalidArgsBadSharedMemoryId) {
7767 IsVertexArrayOESInvalidArgsBadSharedMemoryId();
7769 TEST_F(GLES2DecoderEmulatedVertexArraysOESTest,
7770 IsVertexArrayOESInvalidArgsBadSharedMemoryId) {
7771 IsVertexArrayOESInvalidArgsBadSharedMemoryId();
7774 TEST_F(GLES2DecoderVertexArraysOESTest, BindVertexArrayOESValidArgs) {
7775 BindVertexArrayOESValidArgs();
7777 TEST_F(GLES2DecoderEmulatedVertexArraysOESTest, BindVertexArrayOESValidArgs) {
7778 BindVertexArrayOESValidArgs();
7781 TEST_F(GLES2DecoderVertexArraysOESTest, BindVertexArrayOESValidArgsNewId) {
7782 BindVertexArrayOESValidArgsNewId();
7784 TEST_F(GLES2DecoderEmulatedVertexArraysOESTest,
7785 BindVertexArrayOESValidArgsNewId) {
7786 BindVertexArrayOESValidArgsNewId();
7789 TEST_F(GLES2DecoderTest, BindTexImage2DCHROMIUM) {
7790 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
7791 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
7793 TextureRef* texture_ref = group().texture_manager()->GetTexture(
7794 client_texture_id_);
7795 ASSERT_TRUE(texture_ref != NULL);
7796 Texture* texture = texture_ref->texture();
7797 EXPECT_EQ(kServiceTextureId, texture->service_id());
7799 group().image_manager()->AddImage(gfx::GLImage::CreateGLImage(0).get(), 1);
7800 EXPECT_FALSE(group().image_manager()->LookupImage(1) == NULL);
7805 GLenum internal_format;
7807 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
7808 EXPECT_EQ(3, width);
7809 EXPECT_EQ(1, height);
7810 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
7811 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
7812 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
7813 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
7815 // Bind image to texture.
7816 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
7817 EXPECT_CALL(*gl_, GetError())
7818 .WillOnce(Return(GL_NO_ERROR))
7819 .WillOnce(Return(GL_NO_ERROR))
7820 .RetiresOnSaturation();
7821 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
7822 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
7823 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
7824 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
7825 // Image should now be set.
7826 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
7828 // Define new texture image.
7829 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
7831 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
7832 // Image should no longer be set.
7833 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
7836 TEST_F(GLES2DecoderTest, ReleaseTexImage2DCHROMIUM) {
7837 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
7838 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
7840 TextureRef* texture_ref = group().texture_manager()->GetTexture(
7841 client_texture_id_);
7842 ASSERT_TRUE(texture_ref != NULL);
7843 Texture* texture = texture_ref->texture();
7844 EXPECT_EQ(kServiceTextureId, texture->service_id());
7846 group().image_manager()->AddImage(gfx::GLImage::CreateGLImage(0).get(), 1);
7847 EXPECT_FALSE(group().image_manager()->LookupImage(1) == NULL);
7852 GLenum internal_format;
7854 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
7855 EXPECT_EQ(3, width);
7856 EXPECT_EQ(1, height);
7857 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
7858 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
7859 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
7860 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
7862 // Bind image to texture.
7863 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
7864 EXPECT_CALL(*gl_, GetError())
7865 .WillOnce(Return(GL_NO_ERROR))
7866 .WillOnce(Return(GL_NO_ERROR))
7867 .RetiresOnSaturation();
7868 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
7869 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
7870 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
7871 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
7872 // Image should now be set.
7873 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
7875 // Release image from texture.
7876 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
7877 EXPECT_CALL(*gl_, GetError())
7878 .WillOnce(Return(GL_NO_ERROR))
7879 .WillOnce(Return(GL_NO_ERROR))
7880 .RetiresOnSaturation();
7881 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd;
7882 release_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
7883 EXPECT_EQ(error::kNoError, ExecuteCmd(release_tex_image_2d_cmd));
7884 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
7885 // Image should no longer be set.
7886 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
7889 class MockGLImage : public gfx::GLImage {
7893 // Overridden from gfx::GLImage:
7894 MOCK_METHOD0(Destroy, void());
7895 MOCK_METHOD0(GetSize, gfx::Size());
7896 MOCK_METHOD0(BindTexImage, bool());
7897 MOCK_METHOD0(ReleaseTexImage, void());
7898 MOCK_METHOD0(WillUseTexImage, void());
7899 MOCK_METHOD0(DidUseTexImage, void());
7902 virtual ~MockGLImage() {}
7905 TEST_F(GLES2DecoderWithShaderTest, UseTexImage) {
7906 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
7907 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE,
7908 kSharedMemoryId, kSharedMemoryOffset);
7910 TextureRef* texture_ref = group().texture_manager()->GetTexture(
7911 client_texture_id_);
7912 ASSERT_TRUE(texture_ref != NULL);
7913 Texture* texture = texture_ref->texture();
7914 EXPECT_EQ(kServiceTextureId, texture->service_id());
7916 const int32 kImageId = 1;
7917 scoped_refptr<MockGLImage> image(new MockGLImage);
7918 group().image_manager()->AddImage(image.get(), kImageId);
7920 // Bind image to texture.
7921 EXPECT_CALL(*image, BindTexImage())
7923 .WillOnce(Return(true))
7924 .RetiresOnSaturation();
7925 EXPECT_CALL(*image, GetSize())
7927 .WillOnce(Return(gfx::Size(1, 1)))
7928 .RetiresOnSaturation();
7929 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
7930 EXPECT_CALL(*gl_, GetError())
7931 .WillOnce(Return(GL_NO_ERROR))
7932 .WillOnce(Return(GL_NO_ERROR))
7933 .RetiresOnSaturation();
7934 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
7935 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, kImageId);
7936 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
7938 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
7939 SetupExpectationsForApplyingDefaultDirtyState();
7941 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
7942 EXPECT_CALL(*gl_, GetError())
7943 .WillOnce(Return(GL_NO_ERROR))
7944 .WillOnce(Return(GL_NO_ERROR))
7945 .WillOnce(Return(GL_NO_ERROR))
7946 .WillOnce(Return(GL_NO_ERROR))
7947 .RetiresOnSaturation();
7948 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
7950 .RetiresOnSaturation();
7951 EXPECT_CALL(*image, WillUseTexImage())
7953 .RetiresOnSaturation();
7954 EXPECT_CALL(*image, DidUseTexImage())
7956 .RetiresOnSaturation();
7957 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
7959 .RetiresOnSaturation();
7961 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
7962 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
7963 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7965 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
7966 kServiceFramebufferId);
7967 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
7968 EXPECT_CALL(*gl_, GetError())
7969 .WillOnce(Return(GL_NO_ERROR))
7970 .WillOnce(Return(GL_NO_ERROR))
7971 .RetiresOnSaturation();
7972 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
7974 .RetiresOnSaturation();
7975 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
7977 .RetiresOnSaturation();
7978 // Image will be 'in use' as long as bound to a framebuffer.
7979 EXPECT_CALL(*image, WillUseTexImage())
7981 .RetiresOnSaturation();
7982 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(
7983 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
7984 kServiceTextureId, 0))
7986 .RetiresOnSaturation();
7987 EXPECT_CALL(*gl_, GetError())
7988 .WillOnce(Return(GL_NO_ERROR))
7989 .WillOnce(Return(GL_NO_ERROR))
7990 .RetiresOnSaturation();
7991 FramebufferTexture2D fbtex_cmd;
7993 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, client_texture_id_,
7995 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd));
7996 EXPECT_EQ(GL_NO_ERROR, GetGLError());
7998 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
7999 EXPECT_CALL(*gl_, GetError())
8000 .WillOnce(Return(GL_NO_ERROR))
8001 .WillOnce(Return(GL_NO_ERROR))
8002 .RetiresOnSaturation();
8003 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
8004 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
8005 kServiceRenderbufferId))
8007 .RetiresOnSaturation();
8008 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
8010 .RetiresOnSaturation();
8011 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
8013 .RetiresOnSaturation();
8014 // Image should no longer be 'in use' after being unbound from framebuffer.
8015 EXPECT_CALL(*image, DidUseTexImage())
8017 .RetiresOnSaturation();
8018 EXPECT_CALL(*gl_, GetError())
8019 .WillOnce(Return(GL_NO_ERROR))
8020 .WillOnce(Return(GL_NO_ERROR))
8021 .RetiresOnSaturation();
8022 FramebufferRenderbuffer fbrb_cmd;
8024 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER,
8025 client_renderbuffer_id_);
8026 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
8029 TEST_F(GLES2DecoderManualInitTest, GpuMemoryManagerCHROMIUM) {
8031 "GL_ARB_texture_rectangle", // extensions
8034 false, // has stencil
8035 false, // request alpha
8036 false, // request depth
8037 false, // request stencil
8038 true); // bind generates resource
8040 Texture* texture = GetTexture(client_texture_id_)->texture();
8041 EXPECT_TRUE(texture != NULL);
8042 EXPECT_TRUE(texture->pool() == GL_TEXTURE_POOL_UNMANAGED_CHROMIUM);
8045 GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
8048 cmd.Init(GL_TEXTURE_2D,
8049 GL_TEXTURE_POOL_CHROMIUM,
8050 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM);
8051 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8052 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8054 cmd.Init(GL_TEXTURE_2D,
8055 GL_TEXTURE_POOL_CHROMIUM,
8056 GL_TEXTURE_POOL_MANAGED_CHROMIUM);
8057 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8058 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8060 EXPECT_TRUE(texture->pool() == GL_TEXTURE_POOL_MANAGED_CHROMIUM);
8062 cmd.Init(GL_TEXTURE_2D,
8063 GL_TEXTURE_POOL_CHROMIUM,
8065 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8066 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
8069 TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransfers) {
8071 "GL_CHROMIUM_async_pixel_transfers", // extensions
8072 false, false, false, // has alpha/depth/stencil
8073 false, false, false, // request alpha/depth/stencil
8074 true); // bind generates resource
8076 // Set up the texture.
8077 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
8078 TextureRef* texture_ref = GetTexture(client_texture_id_);
8079 Texture* texture = texture_ref->texture();
8081 // Set a mock Async delegate
8082 StrictMock<gpu::MockAsyncPixelTransferManager>* manager =
8083 new StrictMock<gpu::MockAsyncPixelTransferManager>;
8084 manager->Initialize(group().texture_manager());
8085 decoder_->SetAsyncPixelTransferManagerForTest(manager);
8086 StrictMock<gpu::MockAsyncPixelTransferDelegate>* delegate = NULL;
8088 // Tex(Sub)Image2D upload commands.
8089 AsyncTexImage2DCHROMIUM teximage_cmd;
8090 teximage_cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA,
8091 GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset);
8092 AsyncTexSubImage2DCHROMIUM texsubimage_cmd;
8093 texsubimage_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 8, 8, GL_RGBA,
8094 GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset);
8095 WaitAsyncTexImage2DCHROMIUM wait_cmd;
8096 wait_cmd.Init(GL_TEXTURE_2D);
8098 // No transfer state exists initially.
8100 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
8103 base::Closure bind_callback;
8107 // Create transfer state since it doesn't exist.
8108 EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
8110 delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
8111 .RetiresOnSaturation();
8112 EXPECT_CALL(*delegate, AsyncTexImage2D(_, _, _))
8113 .WillOnce(SaveArg<2>(&bind_callback))
8114 .RetiresOnSaturation();
8115 // Command succeeds.
8116 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
8117 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8120 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
8122 EXPECT_TRUE(texture->IsImmutable());
8123 // The texture is safe but the level has not been defined yet.
8124 EXPECT_TRUE(texture->SafeToRenderFrom());
8125 GLsizei width, height;
8126 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
8129 // Async redefinitions are not allowed!
8131 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
8132 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
8135 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
8137 EXPECT_TRUE(texture->IsImmutable());
8138 EXPECT_TRUE(texture->SafeToRenderFrom());
8141 // Binding/defining of the async transfer
8143 // TODO(epenner): We should check that the manager gets the
8144 // BindCompletedAsyncTransfers() call, which is required to
8145 // guarantee the delegate calls the bind callback.
8147 // Simulate the bind callback from the delegate.
8148 bind_callback.Run();
8150 // After the bind callback is run, the texture is safe,
8151 // and has the right size etc.
8152 EXPECT_TRUE(texture->SafeToRenderFrom());
8153 GLsizei width, height;
8154 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
8155 EXPECT_EQ(width, 8);
8156 EXPECT_EQ(height, 8);
8159 // AsyncTexSubImage2D
8160 decoder_->GetAsyncPixelTransferManager()
8161 ->ClearPixelTransferDelegateForTest(texture_ref);
8162 texture->SetImmutable(false);
8164 // Create transfer state since it doesn't exist.
8165 EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
8167 delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
8168 .RetiresOnSaturation();
8169 EXPECT_CALL(*delegate, AsyncTexSubImage2D(_, _))
8170 .RetiresOnSaturation();
8171 // Command succeeds.
8172 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd));
8173 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8176 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
8178 EXPECT_TRUE(texture->IsImmutable());
8179 EXPECT_TRUE(texture->SafeToRenderFrom());
8182 // No transfer is in progress.
8183 EXPECT_CALL(*delegate, TransferIsInProgress())
8184 .WillOnce(Return(false)) // texSubImage validation
8185 .WillOnce(Return(false)) // async validation
8186 .RetiresOnSaturation();
8187 EXPECT_CALL(*delegate, AsyncTexSubImage2D(_, _))
8188 .RetiresOnSaturation();
8189 // Command succeeds.
8190 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd));
8191 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8194 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
8196 EXPECT_TRUE(texture->IsImmutable());
8197 EXPECT_TRUE(texture->SafeToRenderFrom());
8200 // A transfer is still in progress!
8201 EXPECT_CALL(*delegate, TransferIsInProgress())
8202 .WillOnce(Return(true))
8203 .RetiresOnSaturation();
8204 // No async call, command fails.
8205 EXPECT_EQ(error::kNoError, ExecuteCmd(texsubimage_cmd));
8206 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
8209 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
8211 EXPECT_TRUE(texture->IsImmutable());
8212 EXPECT_TRUE(texture->SafeToRenderFrom());
8215 // Delete delegate on DeleteTexture.
8217 EXPECT_CALL(*delegate, Destroy()).RetiresOnSaturation();
8218 DoDeleteTexture(client_texture_id_, kServiceTextureId);
8220 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
8225 // WaitAsyncTexImage2D
8227 // Get a fresh texture since the existing texture cannot be respecified
8228 // asynchronously and AsyncTexSubImage2D does not involved binding.
8229 EXPECT_CALL(*gl_, GenTextures(1, _))
8230 .WillOnce(SetArgumentPointee<1>(kServiceTextureId));
8231 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
8232 texture_ref = GetTexture(client_texture_id_);
8233 texture = texture_ref->texture();
8234 texture->SetImmutable(false);
8235 // Create transfer state since it doesn't exist.
8236 EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
8238 delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
8239 .RetiresOnSaturation();
8240 EXPECT_CALL(*delegate, AsyncTexImage2D(_, _, _))
8241 .RetiresOnSaturation();
8242 // Start async transfer.
8243 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
8244 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8247 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
8250 EXPECT_TRUE(texture->IsImmutable());
8251 // Wait for completion.
8252 EXPECT_CALL(*delegate, WaitForTransferCompletion());
8253 EXPECT_CALL(*manager, BindCompletedAsyncTransfers());
8254 EXPECT_EQ(error::kNoError, ExecuteCmd(wait_cmd));
8255 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8259 TEST_F(GLES2DecoderManualInitTest, AsyncPixelTransferManager) {
8261 "GL_CHROMIUM_async_pixel_transfers", // extensions
8262 false, false, false, // has alpha/depth/stencil
8263 false, false, false, // request alpha/depth/stencil
8264 true); // bind generates resource
8266 // Set up the texture.
8267 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
8268 TextureRef* texture_ref = GetTexture(client_texture_id_);
8270 // Set a mock Async delegate.
8271 StrictMock<gpu::MockAsyncPixelTransferManager>* manager =
8272 new StrictMock<gpu::MockAsyncPixelTransferManager>;
8273 manager->Initialize(group().texture_manager());
8274 decoder_->SetAsyncPixelTransferManagerForTest(manager);
8275 StrictMock<gpu::MockAsyncPixelTransferDelegate>* delegate = NULL;
8277 AsyncTexImage2DCHROMIUM teximage_cmd;
8278 teximage_cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 8, 8, 0, GL_RGBA,
8279 GL_UNSIGNED_BYTE, kSharedMemoryId, kSharedMemoryOffset);
8281 // No transfer delegate exists initially.
8283 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
8286 // Create delegate on AsyncTexImage2D.
8288 EXPECT_CALL(*manager, CreatePixelTransferDelegateImpl(texture_ref, _))
8290 delegate = new StrictMock<gpu::MockAsyncPixelTransferDelegate>))
8291 .RetiresOnSaturation();
8292 EXPECT_CALL(*delegate, AsyncTexImage2D(_, _, _)).RetiresOnSaturation();
8294 // Command succeeds.
8295 EXPECT_EQ(error::kNoError, ExecuteCmd(teximage_cmd));
8296 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8299 // Delegate is cached.
8301 decoder_->GetAsyncPixelTransferManager()->GetPixelTransferDelegate(
8304 // Delete delegate on manager teardown.
8306 EXPECT_CALL(*delegate, Destroy()).RetiresOnSaturation();
8307 decoder_->ResetAsyncPixelTransferManagerForTest();
8309 // Texture ref still valid.
8310 EXPECT_EQ(texture_ref, GetTexture(client_texture_id_));
8316 class SizeOnlyMemoryTracker : public MemoryTracker {
8318 SizeOnlyMemoryTracker() {
8319 // These are the default textures. 1 for TEXTURE_2D and 6 faces for
8320 // TEXTURE_CUBE_MAP.
8321 const size_t kInitialUnmanagedPoolSize = 7 * 4;
8322 const size_t kInitialManagedPoolSize = 0;
8323 pool_infos_[MemoryTracker::kUnmanaged].initial_size =
8324 kInitialUnmanagedPoolSize;
8325 pool_infos_[MemoryTracker::kManaged].initial_size =
8326 kInitialManagedPoolSize;
8329 // Ensure a certain amount of GPU memory is free. Returns true on success.
8330 MOCK_METHOD1(EnsureGPUMemoryAvailable, bool(size_t size_needed));
8332 virtual void TrackMemoryAllocatedChange(
8333 size_t old_size, size_t new_size, Pool pool) {
8334 PoolInfo& info = pool_infos_[pool];
8335 info.size += new_size - old_size;
8338 size_t GetPoolSize(Pool pool) {
8339 const PoolInfo& info = pool_infos_[pool];
8340 return info.size - info.initial_size;
8344 virtual ~SizeOnlyMemoryTracker() {
8351 size_t initial_size;
8354 std::map<Pool, PoolInfo> pool_infos_;
8357 } // anonymous namespace.
8359 TEST_F(GLES2DecoderManualInitTest, MemoryTrackerInitialSize) {
8360 scoped_refptr<SizeOnlyMemoryTracker> memory_tracker =
8361 new SizeOnlyMemoryTracker();
8362 set_memory_tracker(memory_tracker.get());
8367 false, // has stencil
8368 false, // request alpha
8369 false, // request depth
8370 false, // request stencil
8371 true); // bind generates resource
8372 // Expect that initial size - size is 0.
8373 EXPECT_EQ(0u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
8374 EXPECT_EQ(0u, memory_tracker->GetPoolSize(MemoryTracker::kManaged));
8377 TEST_F(GLES2DecoderManualInitTest, MemoryTrackerTexImage2D) {
8378 scoped_refptr<SizeOnlyMemoryTracker> memory_tracker =
8379 new SizeOnlyMemoryTracker();
8380 set_memory_tracker(memory_tracker.get());
8385 false, // has stencil
8386 false, // request alpha
8387 false, // request depth
8388 false, // request stencil
8389 true); // bind generates resource
8390 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
8391 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
8392 .WillOnce(Return(true)).RetiresOnSaturation();
8393 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 8, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
8394 kSharedMemoryId, kSharedMemoryOffset);
8395 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
8396 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(64))
8397 .WillOnce(Return(true)).RetiresOnSaturation();
8398 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
8399 kSharedMemoryId, kSharedMemoryOffset);
8400 EXPECT_EQ(64u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
8401 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8402 // Check we get out of memory and no call to glTexImage2D if Ensure fails.
8403 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(64))
8404 .WillOnce(Return(false)).RetiresOnSaturation();
8406 cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE,
8407 kSharedMemoryId, kSharedMemoryOffset);
8408 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8409 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
8410 EXPECT_EQ(64u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
8413 TEST_F(GLES2DecoderManualInitTest, MemoryTrackerTexStorage2DEXT) {
8414 scoped_refptr<SizeOnlyMemoryTracker> memory_tracker =
8415 new SizeOnlyMemoryTracker();
8416 set_memory_tracker(memory_tracker.get());
8421 false, // has stencil
8422 false, // request alpha
8423 false, // request depth
8424 false, // request stencil
8425 true); // bind generates resource
8426 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
8427 // Check we get out of memory and no call to glTexStorage2DEXT
8429 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
8430 .WillOnce(Return(false)).RetiresOnSaturation();
8431 TexStorage2DEXT cmd;
8432 cmd.Init(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 4);
8433 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8434 EXPECT_EQ(0u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
8435 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
8438 TEST_F(GLES2DecoderManualInitTest, MemoryTrackerCopyTexImage2D) {
8439 GLenum target = GL_TEXTURE_2D;
8441 GLenum internal_format = GL_RGBA;
8445 scoped_refptr<SizeOnlyMemoryTracker> memory_tracker =
8446 new SizeOnlyMemoryTracker();
8447 set_memory_tracker(memory_tracker.get());
8452 false, // has stencil
8453 true, // request alpha
8454 false, // request depth
8455 false, // request stencil
8456 true); // bind generates resource
8457 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
8458 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
8459 .WillOnce(Return(true)).RetiresOnSaturation();
8460 EXPECT_CALL(*gl_, GetError())
8461 .WillOnce(Return(GL_NO_ERROR))
8462 .WillOnce(Return(GL_NO_ERROR))
8463 .RetiresOnSaturation();
8464 EXPECT_CALL(*gl_, CopyTexImage2D(
8465 target, level, internal_format, 0, 0, width, height, border))
8467 .RetiresOnSaturation();
8469 cmd.Init(target, level, internal_format, 0, 0, width, height, border);
8470 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8471 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
8472 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8473 // Check we get out of memory and no call to glCopyTexImage2D if Ensure fails.
8474 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
8475 .WillOnce(Return(false)).RetiresOnSaturation();
8476 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8477 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
8478 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
8481 TEST_F(GLES2DecoderManualInitTest, MemoryTrackerRenderbufferStorage) {
8482 scoped_refptr<SizeOnlyMemoryTracker> memory_tracker =
8483 new SizeOnlyMemoryTracker();
8484 set_memory_tracker(memory_tracker.get());
8489 false, // has stencil
8490 false, // request alpha
8491 false, // request depth
8492 false, // request stencil
8493 true); // bind generates resource
8494 DoBindRenderbuffer(GL_RENDERBUFFER, client_renderbuffer_id_,
8495 kServiceRenderbufferId);
8496 EXPECT_CALL(*gl_, GetError())
8497 .WillOnce(Return(GL_NO_ERROR))
8498 .WillOnce(Return(GL_NO_ERROR))
8499 .RetiresOnSaturation();
8500 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
8501 .WillOnce(Return(true)).RetiresOnSaturation();
8502 EXPECT_CALL(*gl_, RenderbufferStorageEXT(
8503 GL_RENDERBUFFER, GL_RGBA, 8, 4))
8505 .RetiresOnSaturation();
8506 RenderbufferStorage cmd;
8507 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, 8, 4);
8508 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8509 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8510 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
8511 // Check we get out of memory and no call to glRenderbufferStorage if Ensure
8513 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
8514 .WillOnce(Return(false)).RetiresOnSaturation();
8515 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8516 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
8517 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
8520 TEST_F(GLES2DecoderManualInitTest, MemoryTrackerBufferData) {
8521 scoped_refptr<SizeOnlyMemoryTracker> memory_tracker =
8522 new SizeOnlyMemoryTracker();
8523 set_memory_tracker(memory_tracker.get());
8528 false, // has stencil
8529 false, // request alpha
8530 false, // request depth
8531 false, // request stencil
8532 true); // bind generates resource
8533 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_,
8535 EXPECT_CALL(*gl_, GetError())
8536 .WillOnce(Return(GL_NO_ERROR))
8537 .WillOnce(Return(GL_NO_ERROR))
8538 .RetiresOnSaturation();
8539 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
8540 .WillOnce(Return(true)).RetiresOnSaturation();
8541 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER, 128, _, GL_STREAM_DRAW))
8543 .RetiresOnSaturation();
8545 cmd.Init(GL_ARRAY_BUFFER, 128, 0, 0, GL_STREAM_DRAW);
8546 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8547 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8548 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kManaged));
8549 // Check we get out of memory and no call to glBufferData if Ensure
8551 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
8552 .WillOnce(Return(false)).RetiresOnSaturation();
8553 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
8554 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
8555 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kManaged));
8558 TEST_F(GLES2DecoderTest, DrawBuffersEXTImmediateSuccceeds) {
8559 const GLsizei count = 1;
8560 const GLenum bufs[] = { GL_COLOR_ATTACHMENT0 };
8561 DrawBuffersEXTImmediate& cmd =
8562 *GetImmediateAs<DrawBuffersEXTImmediate>();
8563 cmd.Init(count, bufs);
8565 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
8566 kServiceFramebufferId);
8567 EXPECT_CALL(*gl_, DrawBuffersARB(count, _))
8569 .RetiresOnSaturation();
8570 EXPECT_EQ(error::kNoError,
8571 ExecuteImmediateCmd(cmd, sizeof(bufs)));
8572 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8575 TEST_F(GLES2DecoderTest, DrawBuffersEXTImmediateFails) {
8576 const GLsizei count = 1;
8577 const GLenum bufs[] = { GL_COLOR_ATTACHMENT1_EXT };
8578 DrawBuffersEXTImmediate& cmd =
8579 *GetImmediateAs<DrawBuffersEXTImmediate>();
8580 cmd.Init(count, bufs);
8582 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
8583 kServiceFramebufferId);
8584 EXPECT_EQ(error::kNoError,
8585 ExecuteImmediateCmd(cmd, sizeof(bufs)));
8586 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
8589 TEST_F(GLES2DecoderTest, DrawBuffersEXTImmediateBackbuffer) {
8590 const GLsizei count = 1;
8591 const GLenum bufs[] = { GL_BACK };
8592 DrawBuffersEXTImmediate& cmd =
8593 *GetImmediateAs<DrawBuffersEXTImmediate>();
8594 cmd.Init(count, bufs);
8596 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
8597 kServiceFramebufferId);
8598 EXPECT_EQ(error::kNoError,
8599 ExecuteImmediateCmd(cmd, sizeof(bufs)));
8600 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
8602 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0); // unbind
8604 EXPECT_CALL(*gl_, DrawBuffersARB(count, _))
8606 .RetiresOnSaturation();
8608 EXPECT_EQ(error::kNoError,
8609 ExecuteImmediateCmd(cmd, sizeof(bufs)));
8610 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8613 TEST_F(GLES2DecoderManualInitTest, DiscardFramebufferEXT) {
8614 InitDecoder("GL_EXT_discard_framebuffer", // extensions
8617 false, // has stencil
8618 false, // request alpha
8619 false, // request depth
8620 false, // request stencil
8621 false); // bind generates resource
8623 const GLenum target = GL_FRAMEBUFFER;
8624 const GLsizei count = 1;
8625 const GLenum attachments[] = { GL_COLOR_ATTACHMENT0 };
8629 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
8630 DoFramebufferTexture2D(GL_FRAMEBUFFER,
8631 GL_COLOR_ATTACHMENT0,
8637 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
8638 Framebuffer* framebuffer =
8639 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
8640 EXPECT_TRUE(framebuffer->IsCleared());
8642 EXPECT_CALL(*gl_, DiscardFramebufferEXT(target, count, _))
8644 .RetiresOnSaturation();
8645 DiscardFramebufferEXTImmediate& cmd =
8646 *GetImmediateAs<DiscardFramebufferEXTImmediate>();
8647 cmd.Init(target, count, attachments);
8649 EXPECT_EQ(error::kNoError,
8650 ExecuteImmediateCmd(cmd, sizeof(attachments)));
8651 EXPECT_EQ(GL_NO_ERROR, GetGLError());
8652 EXPECT_FALSE(framebuffer->IsCleared());
8655 TEST_F(GLES2DecoderTest, DiscardFramebufferEXTUnsupported) {
8656 const GLenum target = GL_FRAMEBUFFER;
8657 const GLsizei count = 1;
8658 const GLenum attachments[] = { GL_COLOR_EXT };
8659 DiscardFramebufferEXTImmediate& cmd =
8660 *GetImmediateAs<DiscardFramebufferEXTImmediate>();
8661 cmd.Init(target, count, attachments);
8663 // Should not result into a call into GL.
8664 EXPECT_EQ(error::kNoError,
8665 ExecuteImmediateCmd(cmd, sizeof(attachments)));
8666 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
8669 // TODO(gman): Complete this test.
8670 // TEST_F(GLES2DecoderTest, CompressedTexImage2DGLError) {
8673 // TODO(gman): BufferData
8675 // TODO(gman): BufferDataImmediate
8677 // TODO(gman): BufferSubData
8679 // TODO(gman): BufferSubDataImmediate
8681 // TODO(gman): CompressedTexImage2D
8683 // TODO(gman): CompressedTexImage2DImmediate
8685 // TODO(gman): CompressedTexSubImage2DImmediate
8687 // TODO(gman): DeleteProgram
8689 // TODO(gman): DeleteShader
8691 // TODO(gman): PixelStorei
8693 // TODO(gman): TexImage2D
8695 // TODO(gman): TexImage2DImmediate
8697 // TODO(gman): TexSubImage2DImmediate
8699 // TODO(gman): UseProgram
8701 // TODO(gman): SwapBuffers
8703 } // namespace gles2