Make GL bindings conditional
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_textures.cc
blob05b44afeecfd5cafb1e9c844f7cd0c26a4a74dae
1 // Copyright 2014 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/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
11 #include "gpu/command_buffer/common/id_allocator.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h"
13 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
14 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
15 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
16 #include "gpu/command_buffer/service/context_group.h"
17 #include "gpu/command_buffer/service/context_state.h"
18 #include "gpu/command_buffer/service/gl_surface_mock.h"
19 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
21 #include "gpu/command_buffer/service/gpu_switches.h"
22 #include "gpu/command_buffer/service/image_manager.h"
23 #include "gpu/command_buffer/service/mailbox_manager.h"
24 #include "gpu/command_buffer/service/mocks.h"
25 #include "gpu/command_buffer/service/program_manager.h"
26 #include "gpu/command_buffer/service/test_helper.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gl/gl_image_stub.h"
29 #include "ui/gl/gl_implementation.h"
30 #include "ui/gl/gl_mock.h"
31 #include "ui/gl/gl_surface_stub.h"
33 #if !defined(GL_DEPTH24_STENCIL8)
34 #define GL_DEPTH24_STENCIL8 0x88F0
35 #endif
37 using ::gfx::MockGLInterface;
38 using ::testing::_;
39 using ::testing::DoAll;
40 using ::testing::InSequence;
41 using ::testing::Invoke;
42 using ::testing::MatcherCast;
43 using ::testing::Mock;
44 using ::testing::Pointee;
45 using ::testing::Return;
46 using ::testing::SaveArg;
47 using ::testing::SetArrayArgument;
48 using ::testing::SetArgumentPointee;
49 using ::testing::SetArgPointee;
50 using ::testing::StrEq;
51 using ::testing::StrictMock;
53 namespace gpu {
54 namespace gles2 {
56 using namespace cmds;
58 TEST_P(GLES2DecoderTest, GenerateMipmapWrongFormatsFails) {
59 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
60 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
61 DoTexImage2D(
62 GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
63 GenerateMipmap cmd;
64 cmd.Init(GL_TEXTURE_2D);
65 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
66 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
69 TEST_P(GLES2DecoderTest, GenerateMipmapHandlesOutOfMemory) {
70 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
71 TextureManager* manager = group().texture_manager();
72 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
73 ASSERT_TRUE(texture_ref != NULL);
74 Texture* texture = texture_ref->texture();
75 GLint width = 0;
76 GLint height = 0;
77 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height));
78 DoTexImage2D(GL_TEXTURE_2D,
80 GL_RGBA,
81 16,
82 16,
84 GL_RGBA,
85 GL_UNSIGNED_BYTE,
86 kSharedMemoryId,
87 kSharedMemoryOffset);
88 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D)).Times(1);
89 EXPECT_CALL(*gl_, GetError())
90 .WillOnce(Return(GL_NO_ERROR))
91 .WillOnce(Return(GL_OUT_OF_MEMORY))
92 .RetiresOnSaturation();
93 GenerateMipmap cmd;
94 cmd.Init(GL_TEXTURE_2D);
95 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
96 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
97 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height));
100 TEST_P(GLES2DecoderTest, GenerateMipmapClearsUnclearedTexture) {
101 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
102 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
103 DoTexImage2D(
104 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
105 SetupClearTextureExpectations(kServiceTextureId,
106 kServiceTextureId,
107 GL_TEXTURE_2D,
108 GL_TEXTURE_2D,
110 GL_RGBA,
111 GL_RGBA,
112 GL_UNSIGNED_BYTE,
115 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D));
116 EXPECT_CALL(*gl_, GetError())
117 .WillOnce(Return(GL_NO_ERROR))
118 .WillOnce(Return(GL_NO_ERROR))
119 .RetiresOnSaturation();
120 GenerateMipmap cmd;
121 cmd.Init(GL_TEXTURE_2D);
122 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
123 EXPECT_EQ(GL_NO_ERROR, GetGLError());
126 // Same as GenerateMipmapClearsUnclearedTexture, but with workaround
127 // |set_texture_filters_before_generating_mipmap|.
128 TEST_P(GLES2DecoderManualInitTest, SetTextureFiltersBeforeGenerateMipmap) {
129 base::CommandLine command_line(0, NULL);
130 command_line.AppendSwitchASCII(
131 switches::kGpuDriverBugWorkarounds,
132 base::IntToString(gpu::SET_TEXTURE_FILTER_BEFORE_GENERATING_MIPMAP));
133 InitState init;
134 init.bind_generates_resource = true;
135 InitDecoderWithCommandLine(init, &command_line);
137 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
138 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
139 DoTexImage2D(
140 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
141 SetupClearTextureExpectations(kServiceTextureId,
142 kServiceTextureId,
143 GL_TEXTURE_2D,
144 GL_TEXTURE_2D,
146 GL_RGBA,
147 GL_RGBA,
148 GL_UNSIGNED_BYTE,
151 EXPECT_CALL(
152 *gl_,
153 TexParameteri(
154 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST))
155 .Times(1)
156 .RetiresOnSaturation();
157 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D));
158 EXPECT_CALL(
159 *gl_,
160 TexParameteri(
161 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR))
162 .Times(1)
163 .RetiresOnSaturation();
164 EXPECT_CALL(*gl_, GetError())
165 .WillOnce(Return(GL_NO_ERROR))
166 .WillOnce(Return(GL_NO_ERROR))
167 .RetiresOnSaturation();
168 GenerateMipmap cmd;
169 cmd.Init(GL_TEXTURE_2D);
170 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
171 EXPECT_EQ(GL_NO_ERROR, GetGLError());
174 TEST_P(GLES2DecoderTest, ActiveTextureValidArgs) {
175 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
176 SpecializedSetup<ActiveTexture, 0>(true);
177 ActiveTexture cmd;
178 cmd.Init(GL_TEXTURE1);
179 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
180 EXPECT_EQ(GL_NO_ERROR, GetGLError());
183 TEST_P(GLES2DecoderTest, ActiveTextureInvalidArgs) {
184 EXPECT_CALL(*gl_, ActiveTexture(_)).Times(0);
185 SpecializedSetup<ActiveTexture, 0>(false);
186 ActiveTexture cmd;
187 cmd.Init(GL_TEXTURE0 - 1);
188 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
189 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
190 cmd.Init(kNumTextureUnits);
191 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
192 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
195 TEST_P(GLES2DecoderTest, TexSubImage2DValidArgs) {
196 const int kWidth = 16;
197 const int kHeight = 8;
198 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
199 DoTexImage2D(GL_TEXTURE_2D,
201 GL_RGBA,
202 kWidth,
203 kHeight,
205 GL_RGBA,
206 GL_UNSIGNED_BYTE,
207 kSharedMemoryId,
208 kSharedMemoryOffset);
209 EXPECT_CALL(*gl_,
210 TexSubImage2D(GL_TEXTURE_2D,
214 kWidth - 1,
215 kHeight,
216 GL_RGBA,
217 GL_UNSIGNED_BYTE,
218 shared_memory_address_))
219 .Times(1)
220 .RetiresOnSaturation();
221 TexSubImage2D cmd;
222 cmd.Init(GL_TEXTURE_2D,
226 kWidth - 1,
227 kHeight,
228 GL_RGBA,
229 GL_UNSIGNED_BYTE,
230 kSharedMemoryId,
231 kSharedMemoryOffset,
232 GL_FALSE);
233 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
234 EXPECT_EQ(GL_NO_ERROR, GetGLError());
237 TEST_P(GLES2DecoderTest, TexSubImage2DBadArgs) {
238 const int kWidth = 16;
239 const int kHeight = 8;
240 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
241 DoTexImage2D(GL_TEXTURE_2D,
243 GL_RGBA,
244 kWidth,
245 kHeight,
247 GL_RGBA,
248 GL_UNSIGNED_BYTE,
251 TexSubImage2D cmd;
252 cmd.Init(GL_TEXTURE0,
256 kWidth,
257 kHeight,
258 GL_RGBA,
259 GL_UNSIGNED_BYTE,
260 kSharedMemoryId,
261 kSharedMemoryOffset,
262 GL_FALSE);
263 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
264 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
265 cmd.Init(GL_TEXTURE_2D,
269 kWidth,
270 kHeight,
271 GL_TRUE,
272 GL_UNSIGNED_BYTE,
273 kSharedMemoryId,
274 kSharedMemoryOffset,
275 GL_FALSE);
276 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
277 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
278 cmd.Init(GL_TEXTURE_2D,
282 kWidth,
283 kHeight,
284 GL_RGBA,
285 GL_UNSIGNED_INT,
286 kSharedMemoryId,
287 kSharedMemoryOffset,
288 GL_FALSE);
289 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
290 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
291 cmd.Init(GL_TEXTURE_2D,
295 kWidth,
296 kHeight,
297 GL_RGBA,
298 GL_UNSIGNED_BYTE,
299 kSharedMemoryId,
300 kSharedMemoryOffset,
301 GL_FALSE);
302 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
303 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
304 cmd.Init(GL_TEXTURE_2D,
308 kWidth,
309 kHeight,
310 GL_RGBA,
311 GL_UNSIGNED_BYTE,
312 kSharedMemoryId,
313 kSharedMemoryOffset,
314 GL_FALSE);
315 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
316 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
317 cmd.Init(GL_TEXTURE_2D,
321 kWidth,
322 kHeight,
323 GL_RGBA,
324 GL_UNSIGNED_BYTE,
325 kSharedMemoryId,
326 kSharedMemoryOffset,
327 GL_FALSE);
328 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
329 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
330 cmd.Init(GL_TEXTURE_2D,
334 kWidth,
335 kHeight,
336 GL_RGBA,
337 GL_UNSIGNED_BYTE,
338 kSharedMemoryId,
339 kSharedMemoryOffset,
340 GL_FALSE);
341 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
342 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
343 cmd.Init(GL_TEXTURE_2D,
347 kWidth + 1,
348 kHeight,
349 GL_RGBA,
350 GL_UNSIGNED_BYTE,
351 kSharedMemoryId,
352 kSharedMemoryOffset,
353 GL_FALSE);
354 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
355 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
356 cmd.Init(GL_TEXTURE_2D,
360 kWidth,
361 kHeight + 1,
362 GL_RGBA,
363 GL_UNSIGNED_BYTE,
364 kSharedMemoryId,
365 kSharedMemoryOffset,
366 GL_FALSE);
367 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
368 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
369 cmd.Init(GL_TEXTURE_2D,
373 kWidth,
374 kHeight,
375 GL_RGB,
376 GL_UNSIGNED_BYTE,
377 kSharedMemoryId,
378 kSharedMemoryOffset,
379 GL_FALSE);
380 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
381 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
382 cmd.Init(GL_TEXTURE_2D,
386 kWidth,
387 kHeight,
388 GL_RGBA,
389 GL_UNSIGNED_SHORT_4_4_4_4,
390 kSharedMemoryId,
391 kSharedMemoryOffset,
392 GL_FALSE);
393 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
394 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
395 cmd.Init(GL_TEXTURE_2D,
399 kWidth,
400 kHeight,
401 GL_RGBA,
402 GL_UNSIGNED_BYTE,
403 kInvalidSharedMemoryId,
404 kSharedMemoryOffset,
405 GL_FALSE);
406 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
407 cmd.Init(GL_TEXTURE_2D,
411 kWidth,
412 kHeight,
413 GL_RGBA,
414 GL_UNSIGNED_BYTE,
415 kSharedMemoryId,
416 kInvalidSharedMemoryOffset,
417 GL_FALSE);
418 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
421 TEST_P(GLES2DecoderTest, CopyTexSubImage2DValidArgs) {
422 const int kWidth = 16;
423 const int kHeight = 8;
424 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
425 DoTexImage2D(GL_TEXTURE_2D,
427 GL_RGBA,
428 kWidth,
429 kHeight,
431 GL_RGBA,
432 GL_UNSIGNED_BYTE,
433 kSharedMemoryId,
434 kSharedMemoryOffset);
435 EXPECT_CALL(*gl_,
436 CopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight))
437 .Times(1)
438 .RetiresOnSaturation();
439 CopyTexSubImage2D cmd;
440 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight);
441 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
442 EXPECT_EQ(GL_NO_ERROR, GetGLError());
445 TEST_P(GLES2DecoderTest, CopyTexSubImage2DBadArgs) {
446 const int kWidth = 16;
447 const int kHeight = 8;
448 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
449 DoTexImage2D(GL_TEXTURE_2D,
451 GL_RGBA,
452 kWidth,
453 kHeight,
455 GL_RGBA,
456 GL_UNSIGNED_BYTE,
459 CopyTexSubImage2D cmd;
460 cmd.Init(GL_TEXTURE0, 1, 0, 0, 0, 0, kWidth, kHeight);
461 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
462 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
463 cmd.Init(GL_TEXTURE_2D, 1, -1, 0, 0, 0, kWidth, kHeight);
464 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
465 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
466 cmd.Init(GL_TEXTURE_2D, 1, 1, 0, 0, 0, kWidth, kHeight);
467 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
468 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
469 cmd.Init(GL_TEXTURE_2D, 1, 0, -1, 0, 0, kWidth, kHeight);
470 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
471 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
472 cmd.Init(GL_TEXTURE_2D, 1, 0, 1, 0, 0, kWidth, kHeight);
473 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
474 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
475 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth + 1, kHeight);
476 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
477 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
478 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight + 1);
479 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
480 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
483 TEST_P(GLES2DecoderTest, TexImage2DRedefinitionSucceeds) {
484 const int kWidth = 16;
485 const int kHeight = 8;
486 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
487 EXPECT_CALL(*gl_, GetError()).WillRepeatedly(Return(GL_NO_ERROR));
488 for (int ii = 0; ii < 2; ++ii) {
489 TexImage2D cmd;
490 if (ii == 0) {
491 EXPECT_CALL(*gl_,
492 TexImage2D(GL_TEXTURE_2D,
494 GL_RGBA,
495 kWidth,
496 kHeight,
498 GL_RGBA,
499 GL_UNSIGNED_BYTE,
501 .Times(1)
502 .RetiresOnSaturation();
503 cmd.Init(GL_TEXTURE_2D,
505 GL_RGBA,
506 kWidth,
507 kHeight,
508 GL_RGBA,
509 GL_UNSIGNED_BYTE,
510 kSharedMemoryId,
511 kSharedMemoryOffset);
512 } else {
513 SetupClearTextureExpectations(kServiceTextureId,
514 kServiceTextureId,
515 GL_TEXTURE_2D,
516 GL_TEXTURE_2D,
518 GL_RGBA,
519 GL_RGBA,
520 GL_UNSIGNED_BYTE,
521 kWidth,
522 kHeight);
523 cmd.Init(GL_TEXTURE_2D,
525 GL_RGBA,
526 kWidth,
527 kHeight,
528 GL_RGBA,
529 GL_UNSIGNED_BYTE,
533 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
534 EXPECT_CALL(*gl_,
535 TexSubImage2D(GL_TEXTURE_2D,
539 kWidth,
540 kHeight - 1,
541 GL_RGBA,
542 GL_UNSIGNED_BYTE,
543 shared_memory_address_))
544 .Times(1)
545 .RetiresOnSaturation();
546 // Consider this TexSubImage2D command part of the previous TexImage2D
547 // (last GL_TRUE argument). It will be skipped if there are bugs in the
548 // redefinition case.
549 TexSubImage2D cmd2;
550 cmd2.Init(GL_TEXTURE_2D,
554 kWidth,
555 kHeight - 1,
556 GL_RGBA,
557 GL_UNSIGNED_BYTE,
558 kSharedMemoryId,
559 kSharedMemoryOffset,
560 GL_TRUE);
561 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
565 TEST_P(GLES2DecoderTest, TexImage2DGLError) {
566 GLenum target = GL_TEXTURE_2D;
567 GLint level = 0;
568 GLenum internal_format = GL_RGBA;
569 GLsizei width = 2;
570 GLsizei height = 4;
571 GLint border = 0;
572 GLenum format = GL_RGBA;
573 GLenum type = GL_UNSIGNED_BYTE;
574 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
575 TextureManager* manager = group().texture_manager();
576 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
577 ASSERT_TRUE(texture_ref != NULL);
578 Texture* texture = texture_ref->texture();
579 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
580 EXPECT_CALL(*gl_, GetError())
581 .WillOnce(Return(GL_NO_ERROR))
582 .WillOnce(Return(GL_OUT_OF_MEMORY))
583 .RetiresOnSaturation();
584 EXPECT_CALL(*gl_,
585 TexImage2D(target,
586 level,
587 internal_format,
588 width,
589 height,
590 border,
591 format,
592 type,
594 .Times(1)
595 .RetiresOnSaturation();
596 TexImage2D cmd;
597 cmd.Init(target,
598 level,
599 internal_format,
600 width,
601 height,
602 format,
603 type,
604 kSharedMemoryId,
605 kSharedMemoryOffset);
606 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
607 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
608 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
611 TEST_P(GLES2DecoderTest, CopyTexImage2DGLError) {
612 GLenum target = GL_TEXTURE_2D;
613 GLint level = 0;
614 GLenum internal_format = GL_RGBA;
615 GLsizei width = 2;
616 GLsizei height = 4;
617 GLint border = 0;
618 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
619 TextureManager* manager = group().texture_manager();
620 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
621 ASSERT_TRUE(texture_ref != NULL);
622 Texture* texture = texture_ref->texture();
623 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
624 EXPECT_CALL(*gl_, GetError())
625 .WillOnce(Return(GL_NO_ERROR))
626 .WillOnce(Return(GL_OUT_OF_MEMORY))
627 .RetiresOnSaturation();
628 EXPECT_CALL(*gl_,
629 CopyTexImage2D(
630 target, level, internal_format, 0, 0, width, height, border))
631 .Times(1)
632 .RetiresOnSaturation();
633 CopyTexImage2D cmd;
634 cmd.Init(target, level, internal_format, 0, 0, width, height);
635 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
636 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
637 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
640 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DBucketBadBucket) {
641 InitState init;
642 init.extensions = "GL_EXT_texture_compression_s3tc";
643 init.bind_generates_resource = true;
644 InitDecoder(init);
646 const uint32 kBadBucketId = 123;
647 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
648 CompressedTexImage2DBucket cmd;
649 cmd.Init(GL_TEXTURE_2D,
651 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
654 kBadBucketId);
655 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
656 CompressedTexSubImage2DBucket cmd2;
657 cmd2.Init(GL_TEXTURE_2D,
663 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
664 kBadBucketId);
665 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
668 namespace {
670 struct S3TCTestData {
671 GLenum format;
672 size_t block_size;
675 } // anonymous namespace.
677 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DS3TC) {
678 InitState init;
679 init.extensions = "GL_EXT_texture_compression_s3tc";
680 init.bind_generates_resource = true;
681 InitDecoder(init);
682 const uint32 kBucketId = 123;
683 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
684 ASSERT_TRUE(bucket != NULL);
686 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
688 static const S3TCTestData test_data[] = {
690 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 8,
693 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 8,
696 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 16,
699 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16,
703 for (size_t ii = 0; ii < arraysize(test_data); ++ii) {
704 const S3TCTestData& test = test_data[ii];
705 CompressedTexImage2DBucket cmd;
706 // test small width.
707 DoCompressedTexImage2D(
708 GL_TEXTURE_2D, 0, test.format, 2, 4, 0, test.block_size, kBucketId);
709 EXPECT_EQ(GL_NO_ERROR, GetGLError());
711 // test bad width.
712 cmd.Init(GL_TEXTURE_2D, 0, test.format, 5, 4, kBucketId);
713 bucket->SetSize(test.block_size * 2);
714 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
715 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
717 // test small height.
718 DoCompressedTexImage2D(
719 GL_TEXTURE_2D, 0, test.format, 4, 2, 0, test.block_size, kBucketId);
720 EXPECT_EQ(GL_NO_ERROR, GetGLError());
722 // test too bad height.
723 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 5, kBucketId);
724 bucket->SetSize(test.block_size * 2);
725 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
726 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
728 // test small for level 0.
729 DoCompressedTexImage2D(
730 GL_TEXTURE_2D, 0, test.format, 1, 1, 0, test.block_size, kBucketId);
731 EXPECT_EQ(GL_NO_ERROR, GetGLError());
733 // test small for level 0.
734 DoCompressedTexImage2D(
735 GL_TEXTURE_2D, 0, test.format, 2, 2, 0, test.block_size, kBucketId);
736 EXPECT_EQ(GL_NO_ERROR, GetGLError());
738 // test size too large.
739 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId);
740 bucket->SetSize(test.block_size * 2);
741 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
742 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
744 // test size too small.
745 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId);
746 bucket->SetSize(test.block_size / 2);
747 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
748 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
750 // test with 3 mips.
751 DoCompressedTexImage2D(
752 GL_TEXTURE_2D, 0, test.format, 4, 4, 0, test.block_size, kBucketId);
753 DoCompressedTexImage2D(
754 GL_TEXTURE_2D, 1, test.format, 2, 2, 0, test.block_size, kBucketId);
755 DoCompressedTexImage2D(
756 GL_TEXTURE_2D, 2, test.format, 1, 1, 0, test.block_size, kBucketId);
757 EXPECT_EQ(GL_NO_ERROR, GetGLError());
759 // Test a 16x16
760 DoCompressedTexImage2D(GL_TEXTURE_2D,
762 test.format,
766 test.block_size * 4 * 4,
767 kBucketId);
768 EXPECT_EQ(GL_NO_ERROR, GetGLError());
770 CompressedTexSubImage2DBucket sub_cmd;
771 bucket->SetSize(test.block_size);
772 // Test sub image bad xoffset
773 sub_cmd.Init(GL_TEXTURE_2D, 0, 1, 0, 4, 4, test.format, kBucketId);
774 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
775 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
777 // Test sub image bad yoffset
778 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 2, 4, 4, test.format, kBucketId);
779 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
780 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
782 // Test sub image bad width
783 bucket->SetSize(test.block_size * 2);
784 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 5, 4, test.format, kBucketId);
785 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
786 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
788 // Test sub image bad height
789 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 5, test.format, kBucketId);
790 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
791 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
793 // Test sub image bad size
794 bucket->SetSize(test.block_size + 1);
795 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, test.format, kBucketId);
796 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
797 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
799 for (GLint yoffset = 0; yoffset <= 8; yoffset += 4) {
800 for (GLint xoffset = 0; xoffset <= 8; xoffset += 4) {
801 for (GLsizei height = 4; height <= 8; height += 4) {
802 for (GLsizei width = 4; width <= 8; width += 4) {
803 GLsizei size = test.block_size * (width / 4) * (height / 4);
804 bucket->SetSize(size);
805 EXPECT_CALL(*gl_,
806 CompressedTexSubImage2D(GL_TEXTURE_2D,
808 xoffset,
809 yoffset,
810 width,
811 height,
812 test.format,
813 size,
815 .Times(1)
816 .RetiresOnSaturation();
817 sub_cmd.Init(GL_TEXTURE_2D,
819 xoffset,
820 yoffset,
821 width,
822 height,
823 test.format,
824 kBucketId);
825 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
826 EXPECT_EQ(GL_NO_ERROR, GetGLError());
834 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DETC1) {
835 InitState init;
836 init.extensions = "GL_OES_compressed_ETC1_RGB8_texture";
837 init.gl_version = "opengl es 2.0";
838 init.bind_generates_resource = true;
839 InitDecoder(init);
840 const uint32 kBucketId = 123;
841 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
842 ASSERT_TRUE(bucket != NULL);
844 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
846 const GLenum kFormat = GL_ETC1_RGB8_OES;
847 const size_t kBlockSize = 8;
849 CompressedTexImage2DBucket cmd;
850 // test small width.
851 DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 4, 8, 0, 16, kBucketId);
852 EXPECT_EQ(GL_NO_ERROR, GetGLError());
854 // test small height.
855 DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 8, 4, 0, 16, kBucketId);
856 EXPECT_EQ(GL_NO_ERROR, GetGLError());
858 // test size too large.
859 cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, kBucketId);
860 bucket->SetSize(kBlockSize * 2);
861 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
862 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
864 // test size too small.
865 cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, kBucketId);
866 bucket->SetSize(kBlockSize / 2);
867 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
868 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
870 // Test a 16x16
871 DoCompressedTexImage2D(
872 GL_TEXTURE_2D, 0, kFormat, 16, 16, 0, kBlockSize * 16, kBucketId);
873 EXPECT_EQ(GL_NO_ERROR, GetGLError());
875 // Test CompressedTexSubImage not allowed
876 CompressedTexSubImage2DBucket sub_cmd;
877 bucket->SetSize(kBlockSize);
878 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, kFormat, kBucketId);
879 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
880 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
882 // Test TexSubImage not allowed for ETC1 compressed texture
883 TextureRef* texture_ref = GetTexture(client_texture_id_);
884 ASSERT_TRUE(texture_ref != NULL);
885 Texture* texture = texture_ref->texture();
886 GLenum type, internal_format;
887 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
888 EXPECT_EQ(kFormat, internal_format);
889 TexSubImage2D texsub_cmd;
890 texsub_cmd.Init(GL_TEXTURE_2D,
896 GL_RGBA,
897 GL_UNSIGNED_BYTE,
898 kSharedMemoryId,
899 kSharedMemoryOffset,
900 GL_FALSE);
901 EXPECT_EQ(error::kNoError, ExecuteCmd(texsub_cmd));
902 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
904 // Test CopyTexSubImage not allowed for ETC1 compressed texture
905 CopyTexSubImage2D copy_cmd;
906 copy_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 4, 4);
907 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_cmd));
908 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
911 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalBindTexture) {
912 InitState init;
913 init.extensions = "GL_OES_EGL_image_external";
914 init.gl_version = "opengl es 2.0";
915 init.bind_generates_resource = true;
916 InitDecoder(init);
917 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_EXTERNAL_OES, kNewServiceId));
918 EXPECT_CALL(*gl_, GenTextures(1, _))
919 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
920 BindTexture cmd;
921 cmd.Init(GL_TEXTURE_EXTERNAL_OES, kNewClientId);
922 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
923 EXPECT_EQ(GL_NO_ERROR, GetGLError());
924 TextureRef* texture_ref = GetTexture(kNewClientId);
925 EXPECT_TRUE(texture_ref != NULL);
926 EXPECT_TRUE(texture_ref->texture()->target() == GL_TEXTURE_EXTERNAL_OES);
929 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalGetBinding) {
930 InitState init;
931 init.extensions = "GL_OES_EGL_image_external";
932 init.gl_version = "opengl es 2.0";
933 init.bind_generates_resource = true;
934 InitDecoder(init);
935 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
937 EXPECT_CALL(*gl_, GetError())
938 .WillOnce(Return(GL_NO_ERROR))
939 .WillOnce(Return(GL_NO_ERROR))
940 .RetiresOnSaturation();
941 typedef GetIntegerv::Result Result;
942 Result* result = static_cast<Result*>(shared_memory_address_);
943 EXPECT_CALL(*gl_,
944 GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, result->GetData()))
945 .Times(0);
946 result->size = 0;
947 GetIntegerv cmd;
948 cmd.Init(GL_TEXTURE_BINDING_EXTERNAL_OES,
949 shared_memory_id_,
950 shared_memory_offset_);
951 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
952 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(
953 GL_TEXTURE_BINDING_EXTERNAL_OES),
954 result->GetNumResults());
955 EXPECT_EQ(GL_NO_ERROR, GetGLError());
956 EXPECT_EQ(client_texture_id_, (uint32)result->GetData()[0]);
959 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureDefaults) {
960 InitState init;
961 init.extensions = "GL_OES_EGL_image_external";
962 init.gl_version = "opengl es 2.0";
963 init.bind_generates_resource = true;
964 InitDecoder(init);
965 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
967 TextureRef* texture_ref = GetTexture(client_texture_id_);
968 EXPECT_TRUE(texture_ref != NULL);
969 Texture* texture = texture_ref->texture();
970 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
971 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
972 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
973 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
976 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureParam) {
977 InitState init;
978 init.extensions = "GL_OES_EGL_image_external";
979 init.gl_version = "opengl es 2.0";
980 init.bind_generates_resource = true;
981 InitDecoder(init);
982 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
984 EXPECT_CALL(*gl_,
985 TexParameteri(
986 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
987 EXPECT_CALL(
988 *gl_,
989 TexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
990 EXPECT_CALL(
991 *gl_,
992 TexParameteri(
993 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
994 EXPECT_CALL(
995 *gl_,
996 TexParameteri(
997 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
998 TexParameteri cmd;
999 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1000 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1001 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1003 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1004 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1005 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1007 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1008 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1009 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1011 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1012 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1013 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1015 TextureRef* texture_ref = GetTexture(client_texture_id_);
1016 EXPECT_TRUE(texture_ref != NULL);
1017 Texture* texture = texture_ref->texture();
1018 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
1019 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1020 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1021 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1024 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureParamInvalid) {
1025 InitState init;
1026 init.extensions = "GL_OES_EGL_image_external";
1027 init.gl_version = "opengl es 2.0";
1028 init.bind_generates_resource = true;
1029 InitDecoder(init);
1030 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1032 TexParameteri cmd;
1033 cmd.Init(GL_TEXTURE_EXTERNAL_OES,
1034 GL_TEXTURE_MIN_FILTER,
1035 GL_NEAREST_MIPMAP_NEAREST);
1036 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1037 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1039 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_REPEAT);
1040 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1041 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1043 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_REPEAT);
1044 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1045 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1047 TextureRef* texture_ref = GetTexture(client_texture_id_);
1048 EXPECT_TRUE(texture_ref != NULL);
1049 Texture* texture = texture_ref->texture();
1050 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
1051 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1052 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1053 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1056 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTexImage2DError) {
1057 InitState init;
1058 init.extensions = "GL_OES_EGL_image_external";
1059 init.gl_version = "opengl es 2.0";
1060 init.bind_generates_resource = true;
1061 InitDecoder(init);
1063 GLenum target = GL_TEXTURE_EXTERNAL_OES;
1064 GLint level = 0;
1065 GLenum internal_format = GL_RGBA;
1066 GLsizei width = 2;
1067 GLsizei height = 4;
1068 GLenum format = GL_RGBA;
1069 GLenum type = GL_UNSIGNED_BYTE;
1070 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1071 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL);
1072 TexImage2D cmd;
1073 cmd.Init(target,
1074 level,
1075 internal_format,
1076 width,
1077 height,
1078 format,
1079 type,
1080 kSharedMemoryId,
1081 kSharedMemoryOffset);
1082 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1084 // TexImage2D is not allowed with GL_TEXTURE_EXTERNAL_OES targets.
1085 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1088 TEST_P(GLES2DecoderManualInitTest, DefaultTextureZero) {
1089 InitState init;
1090 InitDecoder(init);
1092 BindTexture cmd1;
1093 cmd1.Init(GL_TEXTURE_2D, 0);
1094 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1095 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1096 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1098 BindTexture cmd2;
1099 cmd2.Init(GL_TEXTURE_CUBE_MAP, 0);
1100 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1101 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1102 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1105 TEST_P(GLES2DecoderManualInitTest, DefaultTextureBGR) {
1106 InitState init;
1107 init.bind_generates_resource = true;
1108 InitDecoder(init);
1110 BindTexture cmd1;
1111 cmd1.Init(GL_TEXTURE_2D, 0);
1112 EXPECT_CALL(
1113 *gl_, BindTexture(GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId));
1114 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1115 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1117 BindTexture cmd2;
1118 cmd2.Init(GL_TEXTURE_CUBE_MAP, 0);
1119 EXPECT_CALL(*gl_,
1120 BindTexture(GL_TEXTURE_CUBE_MAP,
1121 TestHelper::kServiceDefaultTextureCubemapId));
1122 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1123 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1126 // Test that default texture 0 is immutable.
1127 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameterf) {
1128 InitState init;
1129 InitDecoder(init);
1132 BindTexture cmd1;
1133 cmd1.Init(GL_TEXTURE_2D, 0);
1134 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1135 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1136 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1138 TexParameterf cmd2;
1139 cmd2.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1140 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1141 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1145 BindTexture cmd1;
1146 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1147 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1148 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1149 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1151 TexParameterf cmd2;
1152 cmd2.Init(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1153 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1154 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1158 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameteri) {
1159 InitState init;
1160 InitDecoder(init);
1163 BindTexture cmd1;
1164 cmd1.Init(GL_TEXTURE_2D, 0);
1165 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1166 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1167 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1169 TexParameteri cmd2;
1170 cmd2.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1171 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1172 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1176 BindTexture cmd1;
1177 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1178 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1179 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1180 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1182 TexParameteri cmd2;
1183 cmd2.Init(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1184 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1185 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1189 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameterfv) {
1190 InitState init;
1191 InitDecoder(init);
1194 BindTexture cmd1;
1195 cmd1.Init(GL_TEXTURE_2D, 0);
1196 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1197 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1198 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1200 GLfloat data = GL_NEAREST;
1201 TexParameterfvImmediate& cmd2 =
1202 *GetImmediateAs<TexParameterfvImmediate>();
1203 cmd2.Init(GL_TEXTURE_2D,
1204 GL_TEXTURE_MAG_FILTER,
1205 &data);
1206 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1207 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1211 BindTexture cmd1;
1212 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1213 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1214 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1215 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1217 GLfloat data = GL_NEAREST;
1218 TexParameterfvImmediate& cmd2 =
1219 *GetImmediateAs<TexParameterfvImmediate>();
1220 cmd2.Init(GL_TEXTURE_CUBE_MAP,
1221 GL_TEXTURE_MAG_FILTER,
1222 &data);
1223 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1224 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1228 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameteriv) {
1229 InitState init;
1230 InitDecoder(init);
1233 BindTexture cmd1;
1234 cmd1.Init(GL_TEXTURE_2D, 0);
1235 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1236 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1237 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1239 GLfloat data = GL_NEAREST;
1240 TexParameterfvImmediate& cmd2 =
1241 *GetImmediateAs<TexParameterfvImmediate>();
1242 cmd2.Init(GL_TEXTURE_2D,
1243 GL_TEXTURE_MAG_FILTER,
1244 &data);
1245 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1246 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1250 BindTexture cmd1;
1251 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1252 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1253 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1254 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1256 GLfloat data = GL_NEAREST;
1257 TexParameterfvImmediate& cmd2 =
1258 *GetImmediateAs<TexParameterfvImmediate>();
1259 cmd2.Init(GL_TEXTURE_CUBE_MAP,
1260 GL_TEXTURE_MAG_FILTER,
1261 &data);
1262 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1263 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1267 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexImage2D) {
1268 InitState init;
1269 InitDecoder(init);
1271 BindTexture cmd1;
1272 cmd1.Init(GL_TEXTURE_2D, 0);
1273 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1274 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1275 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1277 TexImage2D cmd2;
1278 cmd2.Init(GL_TEXTURE_2D,
1280 GL_RGBA,
1283 GL_RGBA,
1284 GL_UNSIGNED_BYTE,
1285 kSharedMemoryId,
1286 kSharedMemoryOffset);
1287 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1288 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1291 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexSubImage2D) {
1292 InitState init;
1293 InitDecoder(init);
1295 BindTexture cmd1;
1296 cmd1.Init(GL_TEXTURE_2D, 0);
1297 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1298 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1299 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1301 TexSubImage2D cmd2;
1302 cmd2.Init(GL_TEXTURE_2D,
1308 GL_RGBA,
1309 GL_UNSIGNED_BYTE,
1310 kSharedMemoryId,
1311 kSharedMemoryOffset,
1312 GL_FALSE);
1313 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1314 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1317 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleBindTexture) {
1318 InitState init;
1319 init.extensions = "GL_ARB_texture_rectangle";
1320 init.bind_generates_resource = true;
1321 InitDecoder(init);
1322 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_RECTANGLE_ARB, kNewServiceId));
1323 EXPECT_CALL(*gl_, GenTextures(1, _))
1324 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
1325 BindTexture cmd;
1326 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, kNewClientId);
1327 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1328 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1329 Texture* texture = GetTexture(kNewClientId)->texture();
1330 EXPECT_TRUE(texture != NULL);
1331 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1334 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleGetBinding) {
1335 InitState init;
1336 init.extensions = "GL_ARB_texture_rectangle";
1337 init.bind_generates_resource = true;
1338 InitDecoder(init);
1339 DoBindTexture(
1340 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1342 EXPECT_CALL(*gl_, GetError())
1343 .WillOnce(Return(GL_NO_ERROR))
1344 .WillOnce(Return(GL_NO_ERROR))
1345 .RetiresOnSaturation();
1346 typedef GetIntegerv::Result Result;
1347 Result* result = static_cast<Result*>(shared_memory_address_);
1348 EXPECT_CALL(*gl_,
1349 GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, result->GetData()))
1350 .Times(0);
1351 result->size = 0;
1352 GetIntegerv cmd;
1353 cmd.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB,
1354 shared_memory_id_,
1355 shared_memory_offset_);
1356 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1357 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(
1358 GL_TEXTURE_BINDING_RECTANGLE_ARB),
1359 result->GetNumResults());
1360 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1361 EXPECT_EQ(client_texture_id_, (uint32)result->GetData()[0]);
1364 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureDefaults) {
1365 InitState init;
1366 init.extensions = "GL_ARB_texture_rectangle";
1367 init.bind_generates_resource = true;
1368 InitDecoder(init);
1369 DoBindTexture(
1370 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1372 Texture* texture = GetTexture(client_texture_id_)->texture();
1373 EXPECT_TRUE(texture != NULL);
1374 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1375 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1376 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1377 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1380 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureParam) {
1381 InitState init;
1382 init.extensions = "GL_ARB_texture_rectangle";
1383 init.bind_generates_resource = true;
1384 InitDecoder(init);
1386 DoBindTexture(
1387 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1389 EXPECT_CALL(*gl_,
1390 TexParameteri(
1391 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
1392 EXPECT_CALL(*gl_,
1393 TexParameteri(
1394 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1395 EXPECT_CALL(
1396 *gl_,
1397 TexParameteri(
1398 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1399 EXPECT_CALL(
1400 *gl_,
1401 TexParameteri(
1402 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1403 TexParameteri cmd;
1404 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1405 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1406 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1408 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1409 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1410 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1412 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1413 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1414 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1416 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1417 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1418 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1420 Texture* texture = GetTexture(client_texture_id_)->texture();
1421 EXPECT_TRUE(texture != NULL);
1422 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1423 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1424 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1425 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1428 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureParamInvalid) {
1429 InitState init;
1430 init.extensions = "GL_ARB_texture_rectangle";
1431 init.bind_generates_resource = true;
1432 InitDecoder(init);
1434 DoBindTexture(
1435 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1437 TexParameteri cmd;
1438 cmd.Init(GL_TEXTURE_RECTANGLE_ARB,
1439 GL_TEXTURE_MIN_FILTER,
1440 GL_NEAREST_MIPMAP_NEAREST);
1441 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1442 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1444 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_REPEAT);
1445 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1446 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1448 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_REPEAT);
1449 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1450 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1452 Texture* texture = GetTexture(client_texture_id_)->texture();
1453 EXPECT_TRUE(texture != NULL);
1454 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1455 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1456 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1457 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1460 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTexImage2DError) {
1461 InitState init;
1462 init.extensions = "GL_ARB_texture_rectangle";
1463 init.bind_generates_resource = true;
1464 InitDecoder(init);
1466 GLenum target = GL_TEXTURE_RECTANGLE_ARB;
1467 GLint level = 0;
1468 GLenum internal_format = GL_RGBA;
1469 GLsizei width = 2;
1470 GLsizei height = 4;
1471 GLenum format = GL_RGBA;
1472 GLenum type = GL_UNSIGNED_BYTE;
1473 DoBindTexture(
1474 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1475 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL);
1476 TexImage2D cmd;
1477 cmd.Init(target,
1478 level,
1479 internal_format,
1480 width,
1481 height,
1482 format,
1483 type,
1484 kSharedMemoryId,
1485 kSharedMemoryOffset);
1486 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1488 // TexImage2D is not allowed with GL_TEXTURE_RECTANGLE_ARB targets.
1489 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1492 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DClearsAfterTexImage2DNULL) {
1493 InitState init;
1494 init.gl_version = "opengl es 2.0";
1495 init.has_alpha = true;
1496 init.has_depth = true;
1497 init.request_alpha = true;
1498 init.request_depth = true;
1499 InitDecoder(init);
1501 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1502 DoTexImage2D(
1503 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1504 SetupClearTextureExpectations(kServiceTextureId,
1505 kServiceTextureId,
1506 GL_TEXTURE_2D,
1507 GL_TEXTURE_2D,
1509 GL_RGBA,
1510 GL_RGBA,
1511 GL_UNSIGNED_BYTE,
1514 EXPECT_CALL(*gl_,
1515 TexSubImage2D(GL_TEXTURE_2D,
1521 GL_RGBA,
1522 GL_UNSIGNED_BYTE,
1523 shared_memory_address_))
1524 .Times(1)
1525 .RetiresOnSaturation();
1526 TexSubImage2D cmd;
1527 cmd.Init(GL_TEXTURE_2D,
1533 GL_RGBA,
1534 GL_UNSIGNED_BYTE,
1535 kSharedMemoryId,
1536 kSharedMemoryOffset,
1537 GL_FALSE);
1538 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1539 // Test if we call it again it does not clear.
1540 EXPECT_CALL(*gl_,
1541 TexSubImage2D(GL_TEXTURE_2D,
1547 GL_RGBA,
1548 GL_UNSIGNED_BYTE,
1549 shared_memory_address_))
1550 .Times(1)
1551 .RetiresOnSaturation();
1552 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1555 TEST_P(GLES2DecoderTest, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData) {
1556 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1557 DoTexImage2D(
1558 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1559 DoTexImage2D(GL_TEXTURE_2D,
1561 GL_RGBA,
1565 GL_RGBA,
1566 GL_UNSIGNED_BYTE,
1567 kSharedMemoryId,
1568 kSharedMemoryOffset);
1569 EXPECT_CALL(*gl_,
1570 TexSubImage2D(GL_TEXTURE_2D,
1576 GL_RGBA,
1577 GL_UNSIGNED_BYTE,
1578 shared_memory_address_))
1579 .Times(1)
1580 .RetiresOnSaturation();
1581 TexSubImage2D cmd;
1582 cmd.Init(GL_TEXTURE_2D,
1588 GL_RGBA,
1589 GL_UNSIGNED_BYTE,
1590 kSharedMemoryId,
1591 kSharedMemoryOffset,
1592 GL_FALSE);
1593 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1594 // Test if we call it again it does not clear.
1595 EXPECT_CALL(*gl_,
1596 TexSubImage2D(GL_TEXTURE_2D,
1602 GL_RGBA,
1603 GL_UNSIGNED_BYTE,
1604 shared_memory_address_))
1605 .Times(1)
1606 .RetiresOnSaturation();
1607 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1610 TEST_P(
1611 GLES2DecoderManualInitTest,
1612 TexSubImage2DDoesNotClearAfterTexImage2DNULLThenDataWithTexImage2DIsFaster) {
1613 base::CommandLine command_line(0, NULL);
1614 command_line.AppendSwitchASCII(
1615 switches::kGpuDriverBugWorkarounds,
1616 base::IntToString(gpu::TEXSUBIMAGE2D_FASTER_THAN_TEXIMAGE2D));
1617 InitState init;
1618 init.bind_generates_resource = true;
1619 InitDecoderWithCommandLine(init, &command_line);
1620 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1621 DoTexImage2D(
1622 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1625 // Uses texSubimage internally because the above workaround is active and
1626 // the update is for the full size of the texture.
1627 EXPECT_CALL(*gl_,
1628 TexSubImage2D(
1629 GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, _))
1630 .Times(1)
1631 .RetiresOnSaturation();
1632 cmds::TexImage2D cmd;
1633 cmd.Init(GL_TEXTURE_2D,
1635 GL_RGBA,
1638 GL_RGBA,
1639 GL_UNSIGNED_BYTE,
1640 kSharedMemoryId,
1641 kSharedMemoryOffset);
1642 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1645 EXPECT_CALL(*gl_,
1646 TexSubImage2D(GL_TEXTURE_2D,
1652 GL_RGBA,
1653 GL_UNSIGNED_BYTE,
1654 shared_memory_address_))
1655 .Times(1)
1656 .RetiresOnSaturation();
1657 TexSubImage2D cmd;
1658 cmd.Init(GL_TEXTURE_2D,
1664 GL_RGBA,
1665 GL_UNSIGNED_BYTE,
1666 kSharedMemoryId,
1667 kSharedMemoryOffset,
1668 GL_FALSE);
1669 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1670 // Test if we call it again it does not clear.
1671 EXPECT_CALL(*gl_,
1672 TexSubImage2D(GL_TEXTURE_2D,
1678 GL_RGBA,
1679 GL_UNSIGNED_BYTE,
1680 shared_memory_address_))
1681 .Times(1)
1682 .RetiresOnSaturation();
1683 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1686 TEST_P(GLES2DecoderTest, TexSubImage2DClearsAfterTexImage2DWithDataThenNULL) {
1687 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1688 // Put in data (so it should be marked as cleared)
1689 DoTexImage2D(GL_TEXTURE_2D,
1691 GL_RGBA,
1695 GL_RGBA,
1696 GL_UNSIGNED_BYTE,
1697 kSharedMemoryId,
1698 kSharedMemoryOffset);
1699 // Put in no data.
1700 TexImage2D tex_cmd;
1701 tex_cmd.Init(
1702 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1703 // It won't actually call TexImage2D, just mark it as uncleared.
1704 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
1705 // Next call to TexSubImage2d should clear.
1706 SetupClearTextureExpectations(kServiceTextureId,
1707 kServiceTextureId,
1708 GL_TEXTURE_2D,
1709 GL_TEXTURE_2D,
1711 GL_RGBA,
1712 GL_RGBA,
1713 GL_UNSIGNED_BYTE,
1716 EXPECT_CALL(*gl_,
1717 TexSubImage2D(GL_TEXTURE_2D,
1723 GL_RGBA,
1724 GL_UNSIGNED_BYTE,
1725 shared_memory_address_))
1726 .Times(1)
1727 .RetiresOnSaturation();
1728 TexSubImage2D cmd;
1729 cmd.Init(GL_TEXTURE_2D,
1735 GL_RGBA,
1736 GL_UNSIGNED_BYTE,
1737 kSharedMemoryId,
1738 kSharedMemoryOffset,
1739 GL_FALSE);
1740 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1743 TEST_P(GLES2DecoderTest, CopyTexImage2DMarksTextureAsCleared) {
1744 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1746 TextureManager* manager = group().texture_manager();
1747 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
1748 ASSERT_TRUE(texture_ref != NULL);
1749 Texture* texture = texture_ref->texture();
1751 EXPECT_CALL(*gl_, GetError())
1752 .WillOnce(Return(GL_NO_ERROR))
1753 .RetiresOnSaturation();
1754 EXPECT_CALL(*gl_, CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1, 0))
1755 .Times(1)
1756 .RetiresOnSaturation();
1757 EXPECT_CALL(*gl_, GetError())
1758 .WillOnce(Return(GL_NO_ERROR))
1759 .RetiresOnSaturation();
1760 CopyTexImage2D cmd;
1761 cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1);
1762 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1764 EXPECT_TRUE(texture->SafeToRenderFrom());
1767 TEST_P(GLES2DecoderTest, CopyTexSubImage2DClearsUnclearedTexture) {
1768 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1769 DoTexImage2D(
1770 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1772 SetupClearTextureExpectations(kServiceTextureId,
1773 kServiceTextureId,
1774 GL_TEXTURE_2D,
1775 GL_TEXTURE_2D,
1777 GL_RGBA,
1778 GL_RGBA,
1779 GL_UNSIGNED_BYTE,
1782 EXPECT_CALL(*gl_, CopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1))
1783 .Times(1)
1784 .RetiresOnSaturation();
1785 CopyTexSubImage2D cmd;
1786 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1787 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1789 TextureManager* manager = group().texture_manager();
1790 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
1791 ASSERT_TRUE(texture_ref != NULL);
1792 Texture* texture = texture_ref->texture();
1793 EXPECT_TRUE(texture->SafeToRenderFrom());
1796 TEST_P(GLES2DecoderTest, CopyTexSubImage2DClearsUnclearedBackBufferSizedTexture) {
1797 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1798 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kBackBufferWidth, kBackBufferHeight,
1799 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1801 EXPECT_CALL(*gl_, CopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0,
1802 kBackBufferWidth, kBackBufferHeight))
1803 .Times(1)
1804 .RetiresOnSaturation();
1805 CopyTexSubImage2D cmd;
1806 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, kBackBufferWidth, kBackBufferHeight);
1807 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1809 TextureManager* manager = group().texture_manager();
1810 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
1811 ASSERT_TRUE(texture_ref != NULL);
1812 Texture* texture = texture_ref->texture();
1813 EXPECT_TRUE(texture->SafeToRenderFrom());
1816 TEST_P(GLES2DecoderManualInitTest, CompressedImage2DMarksTextureAsCleared) {
1817 InitState init;
1818 init.extensions = "GL_EXT_texture_compression_s3tc";
1819 init.bind_generates_resource = true;
1820 InitDecoder(init);
1822 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1823 EXPECT_CALL(*gl_, GetError())
1824 .WillOnce(Return(GL_NO_ERROR))
1825 .RetiresOnSaturation();
1826 EXPECT_CALL(
1827 *gl_,
1828 CompressedTexImage2D(
1829 GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 8, _))
1830 .Times(1)
1831 .RetiresOnSaturation();
1832 EXPECT_CALL(*gl_, GetError())
1833 .WillOnce(Return(GL_NO_ERROR))
1834 .RetiresOnSaturation();
1835 CompressedTexImage2D cmd;
1836 cmd.Init(GL_TEXTURE_2D,
1838 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1842 kSharedMemoryId,
1843 kSharedMemoryOffset);
1844 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1845 TextureManager* manager = group().texture_manager();
1846 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
1847 EXPECT_TRUE(texture_ref->texture()->SafeToRenderFrom());
1850 TEST_P(GLES2DecoderTest, TextureUsageAngleExtNotEnabledByDefault) {
1851 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1853 TexParameteri cmd;
1854 cmd.Init(
1855 GL_TEXTURE_2D, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
1856 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1857 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1860 TEST_P(GLES2DecoderTest, ProduceAndConsumeTextureCHROMIUM) {
1861 Mailbox mailbox = Mailbox::Generate();
1863 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1864 DoTexImage2D(
1865 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1866 DoTexImage2D(
1867 GL_TEXTURE_2D, 1, GL_RGBA, 2, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1868 TextureRef* texture_ref =
1869 group().texture_manager()->GetTexture(client_texture_id_);
1870 ASSERT_TRUE(texture_ref != NULL);
1871 Texture* texture = texture_ref->texture();
1872 EXPECT_EQ(kServiceTextureId, texture->service_id());
1874 ProduceTextureCHROMIUMImmediate& produce_cmd =
1875 *GetImmediateAs<ProduceTextureCHROMIUMImmediate>();
1876 produce_cmd.Init(GL_TEXTURE_2D, mailbox.name);
1877 EXPECT_EQ(error::kNoError,
1878 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
1879 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1881 // Texture didn't change.
1882 GLsizei width;
1883 GLsizei height;
1884 GLenum type;
1885 GLenum internal_format;
1887 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
1888 EXPECT_EQ(3, width);
1889 EXPECT_EQ(1, height);
1890 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
1891 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1892 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1894 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
1895 EXPECT_EQ(2, width);
1896 EXPECT_EQ(4, height);
1897 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
1898 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1899 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1901 // Service ID has not changed.
1902 EXPECT_EQ(kServiceTextureId, texture->service_id());
1904 // Create new texture for consume.
1905 EXPECT_CALL(*gl_, GenTextures(_, _))
1906 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
1907 .RetiresOnSaturation();
1908 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kNewServiceId);
1910 // Assigns and binds original service size texture ID.
1911 EXPECT_CALL(*gl_, DeleteTextures(1, _)).Times(1).RetiresOnSaturation();
1912 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
1913 .Times(1)
1914 .RetiresOnSaturation();
1916 ConsumeTextureCHROMIUMImmediate& consume_cmd =
1917 *GetImmediateAs<ConsumeTextureCHROMIUMImmediate>();
1918 consume_cmd.Init(GL_TEXTURE_2D, mailbox.name);
1919 EXPECT_EQ(error::kNoError,
1920 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name)));
1921 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1923 // Texture is redefined.
1924 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
1925 EXPECT_EQ(3, width);
1926 EXPECT_EQ(1, height);
1927 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
1928 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1929 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1931 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
1932 EXPECT_EQ(2, width);
1933 EXPECT_EQ(4, height);
1934 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
1935 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1936 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1938 // Service ID is restored.
1939 EXPECT_EQ(kServiceTextureId, texture->service_id());
1942 TEST_P(GLES2DecoderTest, ProduceAndConsumeDirectTextureCHROMIUM) {
1943 Mailbox mailbox = Mailbox::Generate();
1945 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1946 DoTexImage2D(
1947 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1948 DoTexImage2D(
1949 GL_TEXTURE_2D, 1, GL_RGBA, 2, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1950 TextureRef* texture_ref =
1951 group().texture_manager()->GetTexture(client_texture_id_);
1952 ASSERT_TRUE(texture_ref != NULL);
1953 Texture* texture = texture_ref->texture();
1954 EXPECT_EQ(kServiceTextureId, texture->service_id());
1956 ProduceTextureDirectCHROMIUMImmediate& produce_cmd =
1957 *GetImmediateAs<ProduceTextureDirectCHROMIUMImmediate>();
1958 produce_cmd.Init(client_texture_id_, GL_TEXTURE_2D, mailbox.name);
1959 EXPECT_EQ(error::kNoError,
1960 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
1961 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1963 // Texture didn't change.
1964 GLsizei width;
1965 GLsizei height;
1966 GLenum type;
1967 GLenum internal_format;
1969 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
1970 EXPECT_EQ(3, width);
1971 EXPECT_EQ(1, height);
1972 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
1973 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1974 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1976 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
1977 EXPECT_EQ(2, width);
1978 EXPECT_EQ(4, height);
1979 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
1980 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1981 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1983 // Service ID has not changed.
1984 EXPECT_EQ(kServiceTextureId, texture->service_id());
1986 // Consume the texture into a new client ID.
1987 GLuint new_texture_id = kNewClientId;
1988 CreateAndConsumeTextureCHROMIUMImmediate& consume_cmd =
1989 *GetImmediateAs<CreateAndConsumeTextureCHROMIUMImmediate>();
1990 consume_cmd.Init(GL_TEXTURE_2D, new_texture_id, mailbox.name);
1991 EXPECT_EQ(error::kNoError,
1992 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name)));
1993 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1995 // Make sure the new client ID is associated with the produced service ID.
1996 texture_ref = group().texture_manager()->GetTexture(new_texture_id);
1997 ASSERT_TRUE(texture_ref != NULL);
1998 texture = texture_ref->texture();
1999 EXPECT_EQ(kServiceTextureId, texture->service_id());
2001 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kServiceTextureId);
2003 // Texture is redefined.
2004 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2005 EXPECT_EQ(3, width);
2006 EXPECT_EQ(1, height);
2007 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2008 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2009 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2011 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
2012 EXPECT_EQ(2, width);
2013 EXPECT_EQ(4, height);
2014 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
2015 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2016 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2019 TEST_P(GLES2DecoderTest, ProduceTextureCHROMIUMInvalidTarget) {
2020 Mailbox mailbox = Mailbox::Generate();
2022 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2023 DoTexImage2D(
2024 GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 3, 1, 0, GL_RGBA,
2025 GL_UNSIGNED_BYTE, 0, 0);
2026 TextureRef* texture_ref =
2027 group().texture_manager()->GetTexture(client_texture_id_);
2028 ASSERT_TRUE(texture_ref != NULL);
2029 Texture* texture = texture_ref->texture();
2030 EXPECT_EQ(kServiceTextureId, texture->service_id());
2032 ProduceTextureDirectCHROMIUMImmediate& produce_cmd =
2033 *GetImmediateAs<ProduceTextureDirectCHROMIUMImmediate>();
2034 produce_cmd.Init(client_texture_id_, GL_TEXTURE_2D, mailbox.name);
2035 EXPECT_EQ(error::kNoError,
2036 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
2038 // ProduceTexture should fail it the texture and produce targets don't match.
2039 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2042 TEST_P(GLES2DecoderManualInitTest, DepthTextureBadArgs) {
2043 InitState init;
2044 init.extensions = "GL_ANGLE_depth_texture";
2045 init.gl_version = "opengl es 2.0";
2046 init.has_depth = true;
2047 init.has_stencil = true;
2048 init.request_depth = true;
2049 init.request_stencil = true;
2050 init.bind_generates_resource = true;
2051 InitDecoder(init);
2053 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2054 // Check trying to upload data fails.
2055 TexImage2D tex_cmd;
2056 tex_cmd.Init(GL_TEXTURE_2D,
2058 GL_DEPTH_COMPONENT,
2061 GL_DEPTH_COMPONENT,
2062 GL_UNSIGNED_INT,
2063 kSharedMemoryId,
2064 kSharedMemoryOffset);
2065 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
2066 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2067 // Try level > 0.
2068 tex_cmd.Init(GL_TEXTURE_2D,
2070 GL_DEPTH_COMPONENT,
2073 GL_DEPTH_COMPONENT,
2074 GL_UNSIGNED_INT,
2077 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
2078 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2079 // Make a 1 pixel depth texture.
2080 DoTexImage2D(GL_TEXTURE_2D,
2082 GL_DEPTH_COMPONENT,
2086 GL_DEPTH_COMPONENT,
2087 GL_UNSIGNED_INT,
2090 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2092 // Check that trying to update it fails.
2093 TexSubImage2D tex_sub_cmd;
2094 tex_sub_cmd.Init(GL_TEXTURE_2D,
2100 GL_DEPTH_COMPONENT,
2101 GL_UNSIGNED_INT,
2102 kSharedMemoryId,
2103 kSharedMemoryOffset,
2104 GL_FALSE);
2105 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_sub_cmd));
2106 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2108 // Check that trying to CopyTexImage2D fails
2109 CopyTexImage2D copy_tex_cmd;
2110 copy_tex_cmd.Init(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 1, 1);
2111 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_tex_cmd));
2112 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2114 // Check that trying to CopyTexSubImage2D fails
2115 CopyTexSubImage2D copy_sub_cmd;
2116 copy_sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
2117 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_sub_cmd));
2118 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2121 TEST_P(GLES2DecoderManualInitTest, GenerateMipmapDepthTexture) {
2122 InitState init;
2123 init.extensions = "GL_ANGLE_depth_texture";
2124 init.gl_version = "opengl es 2.0";
2125 init.has_depth = true;
2126 init.has_stencil = true;
2127 init.request_depth = true;
2128 init.request_stencil = true;
2129 init.bind_generates_resource = true;
2130 InitDecoder(init);
2131 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2132 DoTexImage2D(GL_TEXTURE_2D,
2134 GL_DEPTH_COMPONENT,
2138 GL_DEPTH_COMPONENT,
2139 GL_UNSIGNED_INT,
2142 GenerateMipmap cmd;
2143 cmd.Init(GL_TEXTURE_2D);
2144 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2145 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2148 TEST_P(GLES2DecoderTest, BindTexImage2DCHROMIUM) {
2149 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2150 DoTexImage2D(
2151 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2152 TextureRef* texture_ref =
2153 group().texture_manager()->GetTexture(client_texture_id_);
2154 ASSERT_TRUE(texture_ref != NULL);
2155 Texture* texture = texture_ref->texture();
2156 EXPECT_EQ(kServiceTextureId, texture->service_id());
2158 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2159 GetImageManager()->AddImage(image.get(), 1);
2160 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL);
2162 GLsizei width;
2163 GLsizei height;
2164 GLenum type;
2165 GLenum internal_format;
2167 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2168 EXPECT_EQ(3, width);
2169 EXPECT_EQ(1, height);
2170 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2171 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2172 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2173 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2175 // Bind image to texture.
2176 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2177 EXPECT_CALL(*gl_, GetError())
2178 .WillOnce(Return(GL_NO_ERROR))
2179 .WillOnce(Return(GL_NO_ERROR))
2180 .RetiresOnSaturation();
2181 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2182 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
2183 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2184 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2185 // Image should now be set.
2186 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2188 // Define new texture image.
2189 DoTexImage2D(
2190 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2191 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2192 // Image should no longer be set.
2193 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2196 TEST_P(GLES2DecoderTest, BindTexImage2DCHROMIUMCubeMapNotAllowed) {
2197 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2198 GetImageManager()->AddImage(image.get(), 1);
2199 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2201 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2202 bind_tex_image_2d_cmd.Init(GL_TEXTURE_CUBE_MAP, 1);
2203 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2204 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
2207 TEST_P(GLES2DecoderTest, OrphanGLImageWithTexImage2D) {
2208 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2209 GetImageManager()->AddImage(image.get(), 1);
2210 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2212 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2213 bind_tex_image_2d_cmd.Init(GL_TEXTURE_CUBE_MAP, 1);
2214 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2215 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
2217 DoTexImage2D(
2218 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2219 TextureRef* texture_ref =
2220 group().texture_manager()->GetTexture(client_texture_id_);
2221 ASSERT_TRUE(texture_ref != NULL);
2222 Texture* texture = texture_ref->texture();
2223 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2226 TEST_P(GLES2DecoderTest, ReleaseTexImage2DCHROMIUM) {
2227 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2228 DoTexImage2D(
2229 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2230 TextureRef* texture_ref =
2231 group().texture_manager()->GetTexture(client_texture_id_);
2232 ASSERT_TRUE(texture_ref != NULL);
2233 Texture* texture = texture_ref->texture();
2234 EXPECT_EQ(kServiceTextureId, texture->service_id());
2236 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2237 GetImageManager()->AddImage(image.get(), 1);
2238 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL);
2240 GLsizei width;
2241 GLsizei height;
2242 GLenum type;
2243 GLenum internal_format;
2245 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2246 EXPECT_EQ(3, width);
2247 EXPECT_EQ(1, height);
2248 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2249 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2250 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2251 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2253 // Bind image to texture.
2254 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2255 EXPECT_CALL(*gl_, GetError())
2256 .WillOnce(Return(GL_NO_ERROR))
2257 .WillOnce(Return(GL_NO_ERROR))
2258 .RetiresOnSaturation();
2259 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2260 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
2261 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2262 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2263 // Image should now be set.
2264 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2266 // Release image from texture.
2267 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2268 EXPECT_CALL(*gl_, GetError())
2269 .WillOnce(Return(GL_NO_ERROR))
2270 .WillOnce(Return(GL_NO_ERROR))
2271 .RetiresOnSaturation();
2272 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd;
2273 release_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
2274 EXPECT_EQ(error::kNoError, ExecuteCmd(release_tex_image_2d_cmd));
2275 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2276 // Image should no longer be set.
2277 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2280 class MockGLImage : public gfx::GLImage {
2281 public:
2282 MockGLImage() {}
2284 // Overridden from gfx::GLImage:
2285 MOCK_METHOD0(GetSize, gfx::Size());
2286 MOCK_METHOD1(Destroy, void(bool));
2287 MOCK_METHOD1(BindTexImage, bool(unsigned));
2288 MOCK_METHOD1(ReleaseTexImage, void(unsigned));
2289 MOCK_METHOD1(CopyTexImage, bool(unsigned));
2290 MOCK_METHOD0(WillUseTexImage, void());
2291 MOCK_METHOD0(DidUseTexImage, void());
2292 MOCK_METHOD0(WillModifyTexImage, void());
2293 MOCK_METHOD0(DidModifyTexImage, void());
2294 MOCK_METHOD5(ScheduleOverlayPlane, bool(gfx::AcceleratedWidget,
2295 int,
2296 gfx::OverlayTransform,
2297 const gfx::Rect&,
2298 const gfx::RectF&));
2300 protected:
2301 virtual ~MockGLImage() {}
2304 TEST_P(GLES2DecoderWithShaderTest, UseTexImage) {
2305 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2306 DoTexImage2D(GL_TEXTURE_2D,
2308 GL_RGBA,
2312 GL_RGBA,
2313 GL_UNSIGNED_BYTE,
2314 kSharedMemoryId,
2315 kSharedMemoryOffset);
2317 TextureRef* texture_ref =
2318 group().texture_manager()->GetTexture(client_texture_id_);
2319 ASSERT_TRUE(texture_ref != NULL);
2320 Texture* texture = texture_ref->texture();
2321 EXPECT_EQ(kServiceTextureId, texture->service_id());
2323 const int32 kImageId = 1;
2324 scoped_refptr<MockGLImage> image(new MockGLImage);
2325 GetImageManager()->AddImage(image.get(), kImageId);
2327 // Bind image to texture.
2328 EXPECT_CALL(*image.get(), BindTexImage(GL_TEXTURE_2D))
2329 .Times(1)
2330 .WillOnce(Return(true))
2331 .RetiresOnSaturation();
2332 EXPECT_CALL(*image.get(), GetSize())
2333 .Times(1)
2334 .WillOnce(Return(gfx::Size(1, 1)))
2335 .RetiresOnSaturation();
2336 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2337 EXPECT_CALL(*gl_, GetError())
2338 .WillOnce(Return(GL_NO_ERROR))
2339 .WillOnce(Return(GL_NO_ERROR))
2340 .RetiresOnSaturation();
2341 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2342 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, kImageId);
2343 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2345 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2346 SetupExpectationsForApplyingDefaultDirtyState();
2348 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2349 EXPECT_CALL(*gl_, GetError())
2350 .WillOnce(Return(GL_NO_ERROR))
2351 .WillOnce(Return(GL_NO_ERROR))
2352 .WillOnce(Return(GL_NO_ERROR))
2353 .WillOnce(Return(GL_NO_ERROR))
2354 .RetiresOnSaturation();
2355 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(3).RetiresOnSaturation();
2356 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2357 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2358 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2359 .Times(1)
2360 .RetiresOnSaturation();
2361 DrawArrays cmd;
2362 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2363 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2364 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2366 DoBindFramebuffer(
2367 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2368 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2369 EXPECT_CALL(*gl_, GetError())
2370 .WillOnce(Return(GL_NO_ERROR))
2371 .WillOnce(Return(GL_NO_ERROR))
2372 .RetiresOnSaturation();
2373 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2374 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2375 .Times(2)
2376 .RetiresOnSaturation();
2377 // Image will be 'in use' as long as bound to a framebuffer.
2378 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2379 EXPECT_CALL(*gl_,
2380 FramebufferTexture2DEXT(GL_FRAMEBUFFER,
2381 GL_COLOR_ATTACHMENT0,
2382 GL_TEXTURE_2D,
2383 kServiceTextureId,
2385 .Times(1)
2386 .RetiresOnSaturation();
2387 EXPECT_CALL(*gl_, GetError())
2388 .WillOnce(Return(GL_NO_ERROR))
2389 .WillOnce(Return(GL_NO_ERROR))
2390 .RetiresOnSaturation();
2391 FramebufferTexture2D fbtex_cmd;
2392 fbtex_cmd.Init(GL_FRAMEBUFFER,
2393 GL_COLOR_ATTACHMENT0,
2394 GL_TEXTURE_2D,
2395 client_texture_id_);
2396 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd));
2397 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2399 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2400 EXPECT_CALL(*gl_, GetError())
2401 .WillOnce(Return(GL_NO_ERROR))
2402 .WillOnce(Return(GL_NO_ERROR))
2403 .RetiresOnSaturation();
2404 EXPECT_CALL(*gl_,
2405 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
2406 GL_COLOR_ATTACHMENT0,
2407 GL_RENDERBUFFER,
2408 kServiceRenderbufferId))
2409 .Times(1)
2410 .RetiresOnSaturation();
2411 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2412 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2413 .Times(2)
2414 .RetiresOnSaturation();
2415 // Image should no longer be 'in use' after being unbound from framebuffer.
2416 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2417 EXPECT_CALL(*gl_, GetError())
2418 .WillOnce(Return(GL_NO_ERROR))
2419 .WillOnce(Return(GL_NO_ERROR))
2420 .RetiresOnSaturation();
2421 FramebufferRenderbuffer fbrb_cmd;
2422 fbrb_cmd.Init(GL_FRAMEBUFFER,
2423 GL_COLOR_ATTACHMENT0,
2424 GL_RENDERBUFFER,
2425 client_renderbuffer_id_);
2426 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
2429 TEST_P(GLES2DecoderManualInitTest, DrawWithGLImageExternal) {
2430 InitState init;
2431 init.extensions = "GL_OES_EGL_image_external";
2432 init.gl_version = "opengl es 2.0";
2433 init.has_alpha = true;
2434 init.has_depth = true;
2435 init.request_alpha = true;
2436 init.request_depth = true;
2437 init.bind_generates_resource = true;
2438 InitDecoder(init);
2440 TextureRef* texture_ref = GetTexture(client_texture_id_);
2441 scoped_refptr<MockGLImage> image(new MockGLImage);
2442 group().texture_manager()->SetTarget(texture_ref, GL_TEXTURE_EXTERNAL_OES);
2443 group().texture_manager()->SetLevelInfo(texture_ref,
2444 GL_TEXTURE_EXTERNAL_OES,
2446 GL_RGBA,
2451 GL_RGBA,
2452 GL_UNSIGNED_BYTE,
2453 true);
2454 group().texture_manager()->SetLevelImage(
2455 texture_ref, GL_TEXTURE_EXTERNAL_OES, 0, image.get());
2457 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
2458 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2460 SetupSamplerExternalProgram();
2461 SetupIndexBuffer();
2462 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
2463 SetupExpectationsForApplyingDefaultDirtyState();
2464 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref));
2466 InSequence s;
2467 EXPECT_CALL(*gl_, GetError())
2468 .WillOnce(Return(GL_NO_ERROR))
2469 .RetiresOnSaturation();
2470 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2471 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2472 EXPECT_CALL(*gl_, GetError())
2473 .WillOnce(Return(GL_NO_ERROR))
2474 .RetiresOnSaturation();
2475 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(1);
2476 EXPECT_CALL(*gl_, GetError())
2477 .WillOnce(Return(GL_NO_ERROR))
2478 .RetiresOnSaturation();
2479 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2480 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2481 EXPECT_CALL(*gl_, GetError())
2482 .WillOnce(Return(GL_NO_ERROR))
2483 .RetiresOnSaturation();
2484 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2485 DrawElements cmd;
2486 cmd.Init(GL_TRIANGLES,
2487 kValidIndexRangeCount,
2488 GL_UNSIGNED_SHORT,
2489 kValidIndexRangeStart * 2);
2490 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2491 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2494 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES2) {
2495 InitState init;
2496 init.extensions = "GL_OES_texture_float";
2497 init.gl_version = "opengl es 2.0";
2498 InitDecoder(init);
2499 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2500 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2501 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0);
2502 DoTexImage2D(
2503 GL_TEXTURE_2D, 0, GL_LUMINANCE, 16, 17, 0, GL_LUMINANCE, GL_FLOAT, 0, 0);
2504 DoTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 16, 17, 0, GL_ALPHA, GL_FLOAT, 0, 0);
2505 DoTexImage2D(GL_TEXTURE_2D,
2507 GL_LUMINANCE_ALPHA,
2511 GL_LUMINANCE_ALPHA,
2512 GL_FLOAT,
2517 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES3) {
2518 InitState init;
2519 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
2520 init.gl_version = "opengl es 3.0";
2521 InitDecoder(init);
2522 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2523 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2524 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0);
2525 DoTexImage2D(
2526 GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2527 DoTexImage2D(
2528 GL_TEXTURE_2D, 0, GL_LUMINANCE, 16, 17, 0, GL_LUMINANCE, GL_FLOAT, 0, 0);
2529 DoTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 16, 17, 0, GL_ALPHA, GL_FLOAT, 0, 0);
2530 DoTexImage2D(GL_TEXTURE_2D,
2532 GL_LUMINANCE_ALPHA,
2536 GL_LUMINANCE_ALPHA,
2537 GL_FLOAT,
2542 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DFloatOnGLES3) {
2543 InitState init;
2544 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
2545 init.gl_version = "opengl es 3.0";
2546 InitDecoder(init);
2547 const int kWidth = 8;
2548 const int kHeight = 4;
2549 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2550 DoTexImage2D(GL_TEXTURE_2D,
2552 GL_RGBA32F,
2553 kWidth,
2554 kHeight,
2556 GL_RGBA,
2557 GL_FLOAT,
2560 EXPECT_CALL(*gl_,
2561 TexImage2D(GL_TEXTURE_2D,
2563 GL_RGBA32F,
2564 kWidth,
2565 kHeight,
2567 GL_RGBA,
2568 GL_FLOAT,
2569 shared_memory_address_))
2570 .Times(1)
2571 .RetiresOnSaturation();
2572 TexSubImage2D cmd;
2573 cmd.Init(GL_TEXTURE_2D,
2577 kWidth,
2578 kHeight,
2579 GL_RGBA,
2580 GL_FLOAT,
2581 kSharedMemoryId,
2582 kSharedMemoryOffset,
2583 GL_FALSE);
2584 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2585 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2588 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DFloatDoesClearOnGLES3) {
2589 InitState init;
2590 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
2591 init.gl_version = "opengl es 3.0";
2592 InitDecoder(init);
2593 const int kWidth = 8;
2594 const int kHeight = 4;
2595 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2596 DoTexImage2D(GL_TEXTURE_2D,
2598 GL_RGBA32F,
2599 kWidth,
2600 kHeight,
2602 GL_RGBA,
2603 GL_FLOAT,
2606 SetupClearTextureExpectations(kServiceTextureId,
2607 kServiceTextureId,
2608 GL_TEXTURE_2D,
2609 GL_TEXTURE_2D,
2611 GL_RGBA32F,
2612 GL_RGBA,
2613 GL_FLOAT,
2614 kWidth,
2615 kHeight);
2616 EXPECT_CALL(*gl_,
2617 TexSubImage2D(GL_TEXTURE_2D,
2621 kWidth - 1,
2622 kHeight,
2623 GL_RGBA,
2624 GL_FLOAT,
2625 shared_memory_address_))
2626 .Times(1)
2627 .RetiresOnSaturation();
2628 TexSubImage2D cmd;
2629 cmd.Init(GL_TEXTURE_2D,
2633 kWidth - 1,
2634 kHeight,
2635 GL_RGBA,
2636 GL_FLOAT,
2637 kSharedMemoryId,
2638 kSharedMemoryOffset,
2639 GL_FALSE);
2640 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2641 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2644 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatConvertsFormatDesktop) {
2645 InitState init;
2646 init.extensions = "GL_ARB_texture_float";
2647 InitDecoder(init);
2648 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2649 DoTexImage2D(
2650 GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2651 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0);
2652 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2654 GL_RGBA,
2658 GL_RGBA,
2659 GL_FLOAT,
2662 GL_RGBA32F_ARB);
2663 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2665 GL_RGB,
2669 GL_RGB,
2670 GL_FLOAT,
2673 GL_RGB32F_ARB);
2674 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2676 GL_LUMINANCE,
2680 GL_LUMINANCE,
2681 GL_FLOAT,
2684 GL_LUMINANCE32F_ARB);
2685 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2687 GL_ALPHA,
2691 GL_ALPHA,
2692 GL_FLOAT,
2695 GL_ALPHA32F_ARB);
2696 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2698 GL_LUMINANCE_ALPHA,
2702 GL_LUMINANCE_ALPHA,
2703 GL_FLOAT,
2706 GL_LUMINANCE_ALPHA32F_ARB);
2709 class GLES2DecoderCompressedFormatsTest : public GLES2DecoderManualInitTest {
2710 public:
2711 GLES2DecoderCompressedFormatsTest() {}
2713 static bool ValueInArray(GLint value, GLint* array, GLint count) {
2714 for (GLint ii = 0; ii < count; ++ii) {
2715 if (array[ii] == value) {
2716 return true;
2719 return false;
2722 void CheckFormats(const char* extension, const GLenum* formats, int count) {
2723 InitState init;
2724 init.extensions = extension;
2725 init.bind_generates_resource = true;
2726 InitDecoder(init);
2728 EXPECT_CALL(*gl_, GetError())
2729 .WillOnce(Return(GL_NO_ERROR))
2730 .WillOnce(Return(GL_NO_ERROR))
2731 .WillOnce(Return(GL_NO_ERROR))
2732 .WillOnce(Return(GL_NO_ERROR))
2733 .RetiresOnSaturation();
2735 typedef GetIntegerv::Result Result;
2736 Result* result = static_cast<Result*>(shared_memory_address_);
2737 GetIntegerv cmd;
2738 result->size = 0;
2739 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
2740 cmd.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS,
2741 shared_memory_id_,
2742 shared_memory_offset_);
2743 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2744 EXPECT_EQ(1, result->GetNumResults());
2745 GLint num_formats = result->GetData()[0];
2746 EXPECT_EQ(count, num_formats);
2747 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2749 result->size = 0;
2750 cmd.Init(GL_COMPRESSED_TEXTURE_FORMATS,
2751 shared_memory_id_,
2752 shared_memory_offset_);
2753 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2754 EXPECT_EQ(num_formats, result->GetNumResults());
2756 for (int i = 0; i < count; ++i) {
2757 EXPECT_TRUE(
2758 ValueInArray(formats[i], result->GetData(), result->GetNumResults()));
2761 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2765 INSTANTIATE_TEST_CASE_P(Service,
2766 GLES2DecoderCompressedFormatsTest,
2767 ::testing::Bool());
2769 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsS3TC) {
2770 const GLenum formats[] = {
2771 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
2772 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT};
2773 CheckFormats("GL_EXT_texture_compression_s3tc", formats, 4);
2776 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsATC) {
2777 const GLenum formats[] = {GL_ATC_RGB_AMD, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD,
2778 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD};
2779 CheckFormats("GL_AMD_compressed_ATC_texture", formats, 3);
2782 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsPVRTC) {
2783 const GLenum formats[] = {
2784 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG,
2785 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG};
2786 CheckFormats("GL_IMG_texture_compression_pvrtc", formats, 4);
2789 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsETC1) {
2790 const GLenum formats[] = {GL_ETC1_RGB8_OES};
2791 CheckFormats("GL_OES_compressed_ETC1_RGB8_texture", formats, 1);
2794 TEST_P(GLES2DecoderManualInitTest, GetNoCompressedTextureFormats) {
2795 InitState init;
2796 init.bind_generates_resource = true;
2797 InitDecoder(init);
2799 EXPECT_CALL(*gl_, GetError())
2800 .WillOnce(Return(GL_NO_ERROR))
2801 .WillOnce(Return(GL_NO_ERROR))
2802 .WillOnce(Return(GL_NO_ERROR))
2803 .WillOnce(Return(GL_NO_ERROR))
2804 .RetiresOnSaturation();
2806 typedef GetIntegerv::Result Result;
2807 Result* result = static_cast<Result*>(shared_memory_address_);
2808 GetIntegerv cmd;
2809 result->size = 0;
2810 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
2811 cmd.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS,
2812 shared_memory_id_,
2813 shared_memory_offset_);
2814 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2815 EXPECT_EQ(1, result->GetNumResults());
2816 GLint num_formats = result->GetData()[0];
2817 EXPECT_EQ(0, num_formats);
2818 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2820 result->size = 0;
2821 cmd.Init(
2822 GL_COMPRESSED_TEXTURE_FORMATS, shared_memory_id_, shared_memory_offset_);
2823 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2824 EXPECT_EQ(num_formats, result->GetNumResults());
2826 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2829 // TODO(gman): Complete this test.
2830 // TEST_P(GLES2DecoderTest, CompressedTexImage2DGLError) {
2831 // }
2833 // TODO(gman): CompressedTexImage2D
2835 // TODO(gman): CompressedTexImage2DImmediate
2837 // TODO(gman): CompressedTexSubImage2DImmediate
2839 // TODO(gman): TexImage2D
2841 // TODO(gman): TexImage2DImmediate
2843 // TODO(gman): TexSubImage2DImmediate
2845 } // namespace gles2
2846 } // namespace gpu