Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_textures.cc
blob7a4bf66d6f3b6c3b1d4f897f819c8c7c87ac0dff
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 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.gl_version = "3.0";
135 init.bind_generates_resource = true;
136 InitDecoderWithCommandLine(init, &command_line);
138 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
139 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
140 DoTexImage2D(
141 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
142 SetupClearTextureExpectations(kServiceTextureId,
143 kServiceTextureId,
144 GL_TEXTURE_2D,
145 GL_TEXTURE_2D,
147 GL_RGBA,
148 GL_RGBA,
149 GL_UNSIGNED_BYTE,
152 EXPECT_CALL(
153 *gl_,
154 TexParameteri(
155 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST))
156 .Times(1)
157 .RetiresOnSaturation();
158 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D));
159 EXPECT_CALL(
160 *gl_,
161 TexParameteri(
162 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR))
163 .Times(1)
164 .RetiresOnSaturation();
165 EXPECT_CALL(*gl_, GetError())
166 .WillOnce(Return(GL_NO_ERROR))
167 .WillOnce(Return(GL_NO_ERROR))
168 .RetiresOnSaturation();
169 GenerateMipmap cmd;
170 cmd.Init(GL_TEXTURE_2D);
171 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
172 EXPECT_EQ(GL_NO_ERROR, GetGLError());
175 TEST_P(GLES2DecoderTest, ActiveTextureValidArgs) {
176 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
177 SpecializedSetup<ActiveTexture, 0>(true);
178 ActiveTexture cmd;
179 cmd.Init(GL_TEXTURE1);
180 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
181 EXPECT_EQ(GL_NO_ERROR, GetGLError());
184 TEST_P(GLES2DecoderTest, ActiveTextureInvalidArgs) {
185 EXPECT_CALL(*gl_, ActiveTexture(_)).Times(0);
186 SpecializedSetup<ActiveTexture, 0>(false);
187 ActiveTexture cmd;
188 cmd.Init(GL_TEXTURE0 - 1);
189 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
190 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
191 cmd.Init(kNumTextureUnits);
192 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
193 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
196 TEST_P(GLES2DecoderTest, TexSubImage2DValidArgs) {
197 const int kWidth = 16;
198 const int kHeight = 8;
199 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
200 DoTexImage2D(GL_TEXTURE_2D,
202 GL_RGBA,
203 kWidth,
204 kHeight,
206 GL_RGBA,
207 GL_UNSIGNED_BYTE,
208 kSharedMemoryId,
209 kSharedMemoryOffset);
210 EXPECT_CALL(*gl_,
211 TexSubImage2D(GL_TEXTURE_2D,
215 kWidth - 1,
216 kHeight,
217 GL_RGBA,
218 GL_UNSIGNED_BYTE,
219 shared_memory_address_))
220 .Times(1)
221 .RetiresOnSaturation();
222 TexSubImage2D cmd;
223 cmd.Init(GL_TEXTURE_2D,
227 kWidth - 1,
228 kHeight,
229 GL_RGBA,
230 GL_UNSIGNED_BYTE,
231 kSharedMemoryId,
232 kSharedMemoryOffset,
233 GL_FALSE);
234 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
235 EXPECT_EQ(GL_NO_ERROR, GetGLError());
238 TEST_P(GLES2DecoderTest, TexSubImage2DBadArgs) {
239 const int kWidth = 16;
240 const int kHeight = 8;
241 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
242 DoTexImage2D(GL_TEXTURE_2D,
244 GL_RGBA,
245 kWidth,
246 kHeight,
248 GL_RGBA,
249 GL_UNSIGNED_BYTE,
252 TexSubImage2D cmd;
253 cmd.Init(GL_TEXTURE0,
257 kWidth,
258 kHeight,
259 GL_RGBA,
260 GL_UNSIGNED_BYTE,
261 kSharedMemoryId,
262 kSharedMemoryOffset,
263 GL_FALSE);
264 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
265 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
266 cmd.Init(GL_TEXTURE_2D,
270 kWidth,
271 kHeight,
272 GL_TRUE,
273 GL_UNSIGNED_BYTE,
274 kSharedMemoryId,
275 kSharedMemoryOffset,
276 GL_FALSE);
277 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
278 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
279 cmd.Init(GL_TEXTURE_2D,
283 kWidth,
284 kHeight,
285 GL_RGBA,
286 GL_UNSIGNED_INT,
287 kSharedMemoryId,
288 kSharedMemoryOffset,
289 GL_FALSE);
290 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
291 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
292 cmd.Init(GL_TEXTURE_2D,
296 kWidth,
297 kHeight,
298 GL_RGBA,
299 GL_UNSIGNED_BYTE,
300 kSharedMemoryId,
301 kSharedMemoryOffset,
302 GL_FALSE);
303 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
304 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
305 cmd.Init(GL_TEXTURE_2D,
309 kWidth,
310 kHeight,
311 GL_RGBA,
312 GL_UNSIGNED_BYTE,
313 kSharedMemoryId,
314 kSharedMemoryOffset,
315 GL_FALSE);
316 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
317 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
318 cmd.Init(GL_TEXTURE_2D,
322 kWidth,
323 kHeight,
324 GL_RGBA,
325 GL_UNSIGNED_BYTE,
326 kSharedMemoryId,
327 kSharedMemoryOffset,
328 GL_FALSE);
329 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
330 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
331 cmd.Init(GL_TEXTURE_2D,
335 kWidth,
336 kHeight,
337 GL_RGBA,
338 GL_UNSIGNED_BYTE,
339 kSharedMemoryId,
340 kSharedMemoryOffset,
341 GL_FALSE);
342 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
343 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
344 cmd.Init(GL_TEXTURE_2D,
348 kWidth + 1,
349 kHeight,
350 GL_RGBA,
351 GL_UNSIGNED_BYTE,
352 kSharedMemoryId,
353 kSharedMemoryOffset,
354 GL_FALSE);
355 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
356 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
357 cmd.Init(GL_TEXTURE_2D,
361 kWidth,
362 kHeight + 1,
363 GL_RGBA,
364 GL_UNSIGNED_BYTE,
365 kSharedMemoryId,
366 kSharedMemoryOffset,
367 GL_FALSE);
368 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
369 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
370 cmd.Init(GL_TEXTURE_2D,
374 kWidth,
375 kHeight,
376 GL_RGB,
377 GL_UNSIGNED_BYTE,
378 kSharedMemoryId,
379 kSharedMemoryOffset,
380 GL_FALSE);
381 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
382 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
383 cmd.Init(GL_TEXTURE_2D,
387 kWidth,
388 kHeight,
389 GL_RGBA,
390 GL_UNSIGNED_SHORT_4_4_4_4,
391 kSharedMemoryId,
392 kSharedMemoryOffset,
393 GL_FALSE);
394 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
395 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
396 cmd.Init(GL_TEXTURE_2D,
400 kWidth,
401 kHeight,
402 GL_RGBA,
403 GL_UNSIGNED_BYTE,
404 kInvalidSharedMemoryId,
405 kSharedMemoryOffset,
406 GL_FALSE);
407 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
408 cmd.Init(GL_TEXTURE_2D,
412 kWidth,
413 kHeight,
414 GL_RGBA,
415 GL_UNSIGNED_BYTE,
416 kSharedMemoryId,
417 kInvalidSharedMemoryOffset,
418 GL_FALSE);
419 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
422 TEST_P(GLES2DecoderTest, CopyTexSubImage2DValidArgs) {
423 const int kWidth = 16;
424 const int kHeight = 8;
425 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
426 DoTexImage2D(GL_TEXTURE_2D,
428 GL_RGBA,
429 kWidth,
430 kHeight,
432 GL_RGBA,
433 GL_UNSIGNED_BYTE,
434 kSharedMemoryId,
435 kSharedMemoryOffset);
436 EXPECT_CALL(*gl_,
437 CopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight))
438 .Times(1)
439 .RetiresOnSaturation();
440 CopyTexSubImage2D cmd;
441 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight);
442 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
443 EXPECT_EQ(GL_NO_ERROR, GetGLError());
446 TEST_P(GLES2DecoderTest, CopyTexSubImage2DBadArgs) {
447 const int kWidth = 16;
448 const int kHeight = 8;
449 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
450 DoTexImage2D(GL_TEXTURE_2D,
452 GL_RGBA,
453 kWidth,
454 kHeight,
456 GL_RGBA,
457 GL_UNSIGNED_BYTE,
460 CopyTexSubImage2D cmd;
461 cmd.Init(GL_TEXTURE0, 1, 0, 0, 0, 0, kWidth, kHeight);
462 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
463 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
464 cmd.Init(GL_TEXTURE_2D, 1, -1, 0, 0, 0, kWidth, kHeight);
465 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
466 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
467 cmd.Init(GL_TEXTURE_2D, 1, 1, 0, 0, 0, kWidth, kHeight);
468 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
469 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
470 cmd.Init(GL_TEXTURE_2D, 1, 0, -1, 0, 0, kWidth, kHeight);
471 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
472 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
473 cmd.Init(GL_TEXTURE_2D, 1, 0, 1, 0, 0, kWidth, kHeight);
474 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
475 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
476 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth + 1, kHeight);
477 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
478 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
479 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight + 1);
480 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
481 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
484 TEST_P(GLES2DecoderTest, TexImage2DRedefinitionSucceeds) {
485 const int kWidth = 16;
486 const int kHeight = 8;
487 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
488 EXPECT_CALL(*gl_, GetError()).WillRepeatedly(Return(GL_NO_ERROR));
489 for (int ii = 0; ii < 2; ++ii) {
490 TexImage2D cmd;
491 if (ii == 0) {
492 EXPECT_CALL(*gl_,
493 TexImage2D(GL_TEXTURE_2D,
495 GL_RGBA,
496 kWidth,
497 kHeight,
499 GL_RGBA,
500 GL_UNSIGNED_BYTE,
502 .Times(1)
503 .RetiresOnSaturation();
504 cmd.Init(GL_TEXTURE_2D,
506 GL_RGBA,
507 kWidth,
508 kHeight,
509 GL_RGBA,
510 GL_UNSIGNED_BYTE,
511 kSharedMemoryId,
512 kSharedMemoryOffset);
513 } else {
514 SetupClearTextureExpectations(kServiceTextureId,
515 kServiceTextureId,
516 GL_TEXTURE_2D,
517 GL_TEXTURE_2D,
519 GL_RGBA,
520 GL_RGBA,
521 GL_UNSIGNED_BYTE,
522 kWidth,
523 kHeight);
524 cmd.Init(GL_TEXTURE_2D,
526 GL_RGBA,
527 kWidth,
528 kHeight,
529 GL_RGBA,
530 GL_UNSIGNED_BYTE,
534 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
535 EXPECT_CALL(*gl_,
536 TexSubImage2D(GL_TEXTURE_2D,
540 kWidth,
541 kHeight - 1,
542 GL_RGBA,
543 GL_UNSIGNED_BYTE,
544 shared_memory_address_))
545 .Times(1)
546 .RetiresOnSaturation();
547 // Consider this TexSubImage2D command part of the previous TexImage2D
548 // (last GL_TRUE argument). It will be skipped if there are bugs in the
549 // redefinition case.
550 TexSubImage2D cmd2;
551 cmd2.Init(GL_TEXTURE_2D,
555 kWidth,
556 kHeight - 1,
557 GL_RGBA,
558 GL_UNSIGNED_BYTE,
559 kSharedMemoryId,
560 kSharedMemoryOffset,
561 GL_TRUE);
562 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
566 TEST_P(GLES2DecoderTest, TexImage2DGLError) {
567 GLenum target = GL_TEXTURE_2D;
568 GLint level = 0;
569 GLenum internal_format = GL_RGBA;
570 GLsizei width = 2;
571 GLsizei height = 4;
572 GLint border = 0;
573 GLenum format = GL_RGBA;
574 GLenum type = GL_UNSIGNED_BYTE;
575 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
576 TextureManager* manager = group().texture_manager();
577 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
578 ASSERT_TRUE(texture_ref != NULL);
579 Texture* texture = texture_ref->texture();
580 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
581 EXPECT_CALL(*gl_, GetError())
582 .WillOnce(Return(GL_NO_ERROR))
583 .WillOnce(Return(GL_OUT_OF_MEMORY))
584 .RetiresOnSaturation();
585 EXPECT_CALL(*gl_,
586 TexImage2D(target,
587 level,
588 internal_format,
589 width,
590 height,
591 border,
592 format,
593 type,
595 .Times(1)
596 .RetiresOnSaturation();
597 TexImage2D cmd;
598 cmd.Init(target,
599 level,
600 internal_format,
601 width,
602 height,
603 format,
604 type,
605 kSharedMemoryId,
606 kSharedMemoryOffset);
607 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
608 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
609 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
612 TEST_P(GLES2DecoderTest, CopyTexImage2DGLError) {
613 GLenum target = GL_TEXTURE_2D;
614 GLint level = 0;
615 GLenum internal_format = GL_RGBA;
616 GLsizei width = 2;
617 GLsizei height = 4;
618 GLint border = 0;
619 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
620 TextureManager* manager = group().texture_manager();
621 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
622 ASSERT_TRUE(texture_ref != NULL);
623 Texture* texture = texture_ref->texture();
624 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
625 EXPECT_CALL(*gl_, GetError())
626 .WillOnce(Return(GL_NO_ERROR))
627 .WillOnce(Return(GL_OUT_OF_MEMORY))
628 .RetiresOnSaturation();
629 EXPECT_CALL(*gl_,
630 CopyTexImage2D(
631 target, level, internal_format, 0, 0, width, height, border))
632 .Times(1)
633 .RetiresOnSaturation();
634 CopyTexImage2D cmd;
635 cmd.Init(target, level, internal_format, 0, 0, width, height);
636 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
637 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
638 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
641 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DBucketBadBucket) {
642 InitState init;
643 init.extensions = "GL_EXT_texture_compression_s3tc";
644 init.gl_version = "3.0";
645 init.bind_generates_resource = true;
646 InitDecoder(init);
648 const uint32 kBadBucketId = 123;
649 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
650 CompressedTexImage2DBucket cmd;
651 cmd.Init(GL_TEXTURE_2D,
653 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
656 kBadBucketId);
657 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
658 CompressedTexSubImage2DBucket cmd2;
659 cmd2.Init(GL_TEXTURE_2D,
665 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
666 kBadBucketId);
667 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
670 namespace {
672 struct S3TCTestData {
673 GLenum format;
674 size_t block_size;
677 } // anonymous namespace.
679 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DS3TC) {
680 InitState init;
681 init.extensions = "GL_EXT_texture_compression_s3tc";
682 init.gl_version = "3.0";
683 init.bind_generates_resource = true;
684 InitDecoder(init);
685 const uint32 kBucketId = 123;
686 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
687 ASSERT_TRUE(bucket != NULL);
689 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
691 static const S3TCTestData test_data[] = {
693 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 8,
696 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 8,
699 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 16,
702 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16,
706 for (size_t ii = 0; ii < arraysize(test_data); ++ii) {
707 const S3TCTestData& test = test_data[ii];
708 CompressedTexImage2DBucket cmd;
709 // test small width.
710 DoCompressedTexImage2D(
711 GL_TEXTURE_2D, 0, test.format, 2, 4, 0, test.block_size, kBucketId);
712 EXPECT_EQ(GL_NO_ERROR, GetGLError());
714 // test bad width.
715 cmd.Init(GL_TEXTURE_2D, 0, test.format, 5, 4, kBucketId);
716 bucket->SetSize(test.block_size * 2);
717 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
718 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
720 // test small height.
721 DoCompressedTexImage2D(
722 GL_TEXTURE_2D, 0, test.format, 4, 2, 0, test.block_size, kBucketId);
723 EXPECT_EQ(GL_NO_ERROR, GetGLError());
725 // test too bad height.
726 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 5, kBucketId);
727 bucket->SetSize(test.block_size * 2);
728 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
729 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
731 // test small for level 0.
732 DoCompressedTexImage2D(
733 GL_TEXTURE_2D, 0, test.format, 1, 1, 0, test.block_size, kBucketId);
734 EXPECT_EQ(GL_NO_ERROR, GetGLError());
736 // test small for level 0.
737 DoCompressedTexImage2D(
738 GL_TEXTURE_2D, 0, test.format, 2, 2, 0, test.block_size, kBucketId);
739 EXPECT_EQ(GL_NO_ERROR, GetGLError());
741 // test size too large.
742 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId);
743 bucket->SetSize(test.block_size * 2);
744 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
745 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
747 // test size too small.
748 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId);
749 bucket->SetSize(test.block_size / 2);
750 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
751 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
753 // test with 3 mips.
754 DoCompressedTexImage2D(
755 GL_TEXTURE_2D, 0, test.format, 4, 4, 0, test.block_size, kBucketId);
756 DoCompressedTexImage2D(
757 GL_TEXTURE_2D, 1, test.format, 2, 2, 0, test.block_size, kBucketId);
758 DoCompressedTexImage2D(
759 GL_TEXTURE_2D, 2, test.format, 1, 1, 0, test.block_size, kBucketId);
760 EXPECT_EQ(GL_NO_ERROR, GetGLError());
762 // Test a 16x16
763 DoCompressedTexImage2D(GL_TEXTURE_2D,
765 test.format,
769 test.block_size * 4 * 4,
770 kBucketId);
771 EXPECT_EQ(GL_NO_ERROR, GetGLError());
773 CompressedTexSubImage2DBucket sub_cmd;
774 bucket->SetSize(test.block_size);
775 // Test sub image bad xoffset
776 sub_cmd.Init(GL_TEXTURE_2D, 0, 1, 0, 4, 4, test.format, kBucketId);
777 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
778 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
780 // Test sub image bad yoffset
781 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 2, 4, 4, test.format, kBucketId);
782 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
783 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
785 // Test sub image bad width
786 bucket->SetSize(test.block_size * 2);
787 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 5, 4, test.format, kBucketId);
788 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
789 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
791 // Test sub image bad height
792 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 5, test.format, kBucketId);
793 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
794 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
796 // Test sub image bad size
797 bucket->SetSize(test.block_size + 1);
798 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, test.format, kBucketId);
799 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
800 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
802 for (GLint yoffset = 0; yoffset <= 8; yoffset += 4) {
803 for (GLint xoffset = 0; xoffset <= 8; xoffset += 4) {
804 for (GLsizei height = 4; height <= 8; height += 4) {
805 for (GLsizei width = 4; width <= 8; width += 4) {
806 GLsizei size = test.block_size * (width / 4) * (height / 4);
807 bucket->SetSize(size);
808 EXPECT_CALL(*gl_,
809 CompressedTexSubImage2D(GL_TEXTURE_2D,
811 xoffset,
812 yoffset,
813 width,
814 height,
815 test.format,
816 size,
818 .Times(1)
819 .RetiresOnSaturation();
820 sub_cmd.Init(GL_TEXTURE_2D,
822 xoffset,
823 yoffset,
824 width,
825 height,
826 test.format,
827 kBucketId);
828 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
829 EXPECT_EQ(GL_NO_ERROR, GetGLError());
837 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DETC1) {
838 InitState init;
839 init.extensions = "GL_OES_compressed_ETC1_RGB8_texture";
840 init.gl_version = "opengl es 2.0";
841 init.bind_generates_resource = true;
842 InitDecoder(init);
843 const uint32 kBucketId = 123;
844 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
845 ASSERT_TRUE(bucket != NULL);
847 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
849 const GLenum kFormat = GL_ETC1_RGB8_OES;
850 const size_t kBlockSize = 8;
852 CompressedTexImage2DBucket cmd;
853 // test small width.
854 DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 4, 8, 0, 16, kBucketId);
855 EXPECT_EQ(GL_NO_ERROR, GetGLError());
857 // test small height.
858 DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 8, 4, 0, 16, kBucketId);
859 EXPECT_EQ(GL_NO_ERROR, GetGLError());
861 // test size too large.
862 cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, kBucketId);
863 bucket->SetSize(kBlockSize * 2);
864 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
865 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
867 // test size too small.
868 cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, kBucketId);
869 bucket->SetSize(kBlockSize / 2);
870 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
871 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
873 // Test a 16x16
874 DoCompressedTexImage2D(
875 GL_TEXTURE_2D, 0, kFormat, 16, 16, 0, kBlockSize * 16, kBucketId);
876 EXPECT_EQ(GL_NO_ERROR, GetGLError());
878 // Test CompressedTexSubImage not allowed
879 CompressedTexSubImage2DBucket sub_cmd;
880 bucket->SetSize(kBlockSize);
881 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, kFormat, kBucketId);
882 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
883 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
885 // Test TexSubImage not allowed for ETC1 compressed texture
886 TextureRef* texture_ref = GetTexture(client_texture_id_);
887 ASSERT_TRUE(texture_ref != NULL);
888 Texture* texture = texture_ref->texture();
889 GLenum type, internal_format;
890 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
891 EXPECT_EQ(kFormat, internal_format);
892 TexSubImage2D texsub_cmd;
893 texsub_cmd.Init(GL_TEXTURE_2D,
899 GL_RGBA,
900 GL_UNSIGNED_BYTE,
901 kSharedMemoryId,
902 kSharedMemoryOffset,
903 GL_FALSE);
904 EXPECT_EQ(error::kNoError, ExecuteCmd(texsub_cmd));
905 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
907 // Test CopyTexSubImage not allowed for ETC1 compressed texture
908 CopyTexSubImage2D copy_cmd;
909 copy_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 4, 4);
910 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_cmd));
911 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
914 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalBindTexture) {
915 InitState init;
916 init.extensions = "GL_OES_EGL_image_external";
917 init.gl_version = "opengl es 2.0";
918 init.bind_generates_resource = true;
919 InitDecoder(init);
920 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_EXTERNAL_OES, kNewServiceId));
921 EXPECT_CALL(*gl_, GenTextures(1, _))
922 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
923 BindTexture cmd;
924 cmd.Init(GL_TEXTURE_EXTERNAL_OES, kNewClientId);
925 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
926 EXPECT_EQ(GL_NO_ERROR, GetGLError());
927 TextureRef* texture_ref = GetTexture(kNewClientId);
928 EXPECT_TRUE(texture_ref != NULL);
929 EXPECT_TRUE(texture_ref->texture()->target() == GL_TEXTURE_EXTERNAL_OES);
932 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalGetBinding) {
933 InitState init;
934 init.extensions = "GL_OES_EGL_image_external";
935 init.gl_version = "opengl es 2.0";
936 init.bind_generates_resource = true;
937 InitDecoder(init);
938 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
940 EXPECT_CALL(*gl_, GetError())
941 .WillOnce(Return(GL_NO_ERROR))
942 .WillOnce(Return(GL_NO_ERROR))
943 .RetiresOnSaturation();
944 typedef GetIntegerv::Result Result;
945 Result* result = static_cast<Result*>(shared_memory_address_);
946 EXPECT_CALL(*gl_,
947 GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, result->GetData()))
948 .Times(0);
949 result->size = 0;
950 GetIntegerv cmd;
951 cmd.Init(GL_TEXTURE_BINDING_EXTERNAL_OES,
952 shared_memory_id_,
953 shared_memory_offset_);
954 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
955 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(
956 GL_TEXTURE_BINDING_EXTERNAL_OES),
957 result->GetNumResults());
958 EXPECT_EQ(GL_NO_ERROR, GetGLError());
959 EXPECT_EQ(client_texture_id_, (uint32)result->GetData()[0]);
962 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureDefaults) {
963 InitState init;
964 init.extensions = "GL_OES_EGL_image_external";
965 init.gl_version = "opengl es 2.0";
966 init.bind_generates_resource = true;
967 InitDecoder(init);
968 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
970 TextureRef* texture_ref = GetTexture(client_texture_id_);
971 EXPECT_TRUE(texture_ref != NULL);
972 Texture* texture = texture_ref->texture();
973 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
974 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
975 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
976 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
979 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureParam) {
980 InitState init;
981 init.extensions = "GL_OES_EGL_image_external";
982 init.gl_version = "opengl es 2.0";
983 init.bind_generates_resource = true;
984 InitDecoder(init);
985 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
987 EXPECT_CALL(*gl_,
988 TexParameteri(
989 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
990 EXPECT_CALL(
991 *gl_,
992 TexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
993 EXPECT_CALL(
994 *gl_,
995 TexParameteri(
996 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
997 EXPECT_CALL(
998 *gl_,
999 TexParameteri(
1000 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1001 TexParameteri cmd;
1002 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1003 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1004 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1006 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1007 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1008 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1010 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1011 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1012 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1014 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1015 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1016 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1018 TextureRef* texture_ref = GetTexture(client_texture_id_);
1019 EXPECT_TRUE(texture_ref != NULL);
1020 Texture* texture = texture_ref->texture();
1021 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
1022 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1023 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1024 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1027 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureParamInvalid) {
1028 InitState init;
1029 init.extensions = "GL_OES_EGL_image_external";
1030 init.gl_version = "opengl es 2.0";
1031 init.bind_generates_resource = true;
1032 InitDecoder(init);
1033 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1035 TexParameteri cmd;
1036 cmd.Init(GL_TEXTURE_EXTERNAL_OES,
1037 GL_TEXTURE_MIN_FILTER,
1038 GL_NEAREST_MIPMAP_NEAREST);
1039 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1040 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1042 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_REPEAT);
1043 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1044 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1046 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_REPEAT);
1047 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1048 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1050 TextureRef* texture_ref = GetTexture(client_texture_id_);
1051 EXPECT_TRUE(texture_ref != NULL);
1052 Texture* texture = texture_ref->texture();
1053 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
1054 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1055 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1056 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1059 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTexImage2DError) {
1060 InitState init;
1061 init.extensions = "GL_OES_EGL_image_external";
1062 init.gl_version = "opengl es 2.0";
1063 init.bind_generates_resource = true;
1064 InitDecoder(init);
1066 GLenum target = GL_TEXTURE_EXTERNAL_OES;
1067 GLint level = 0;
1068 GLenum internal_format = GL_RGBA;
1069 GLsizei width = 2;
1070 GLsizei height = 4;
1071 GLenum format = GL_RGBA;
1072 GLenum type = GL_UNSIGNED_BYTE;
1073 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1074 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL);
1075 TexImage2D cmd;
1076 cmd.Init(target,
1077 level,
1078 internal_format,
1079 width,
1080 height,
1081 format,
1082 type,
1083 kSharedMemoryId,
1084 kSharedMemoryOffset);
1085 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1087 // TexImage2D is not allowed with GL_TEXTURE_EXTERNAL_OES targets.
1088 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1091 TEST_P(GLES2DecoderManualInitTest, DefaultTextureZero) {
1092 InitState init;
1093 init.gl_version = "3.0";
1094 InitDecoder(init);
1096 BindTexture cmd1;
1097 cmd1.Init(GL_TEXTURE_2D, 0);
1098 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1099 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1100 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1102 BindTexture cmd2;
1103 cmd2.Init(GL_TEXTURE_CUBE_MAP, 0);
1104 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1105 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1106 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1109 TEST_P(GLES2DecoderManualInitTest, DefaultTextureBGR) {
1110 InitState init;
1111 init.gl_version = "3.0";
1112 init.bind_generates_resource = true;
1113 InitDecoder(init);
1115 BindTexture cmd1;
1116 cmd1.Init(GL_TEXTURE_2D, 0);
1117 EXPECT_CALL(
1118 *gl_, BindTexture(GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId));
1119 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1120 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1122 BindTexture cmd2;
1123 cmd2.Init(GL_TEXTURE_CUBE_MAP, 0);
1124 EXPECT_CALL(*gl_,
1125 BindTexture(GL_TEXTURE_CUBE_MAP,
1126 TestHelper::kServiceDefaultTextureCubemapId));
1127 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1128 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1131 // Test that default texture 0 is immutable.
1132 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameterf) {
1133 InitState init;
1134 init.gl_version = "3.0";
1135 InitDecoder(init);
1138 BindTexture cmd1;
1139 cmd1.Init(GL_TEXTURE_2D, 0);
1140 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1141 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1142 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1144 TexParameterf cmd2;
1145 cmd2.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1146 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1147 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1151 BindTexture cmd1;
1152 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1153 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1154 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1155 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1157 TexParameterf cmd2;
1158 cmd2.Init(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1159 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1160 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1164 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameteri) {
1165 InitState init;
1166 init.gl_version = "3.0";
1167 InitDecoder(init);
1170 BindTexture cmd1;
1171 cmd1.Init(GL_TEXTURE_2D, 0);
1172 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1173 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1174 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1176 TexParameteri cmd2;
1177 cmd2.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1178 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1179 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1183 BindTexture cmd1;
1184 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1185 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1186 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1187 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1189 TexParameteri cmd2;
1190 cmd2.Init(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1191 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1192 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1196 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameterfv) {
1197 InitState init;
1198 init.gl_version = "3.0";
1199 InitDecoder(init);
1202 BindTexture cmd1;
1203 cmd1.Init(GL_TEXTURE_2D, 0);
1204 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1205 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1206 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1208 GLfloat data = GL_NEAREST;
1209 TexParameterfvImmediate& cmd2 =
1210 *GetImmediateAs<TexParameterfvImmediate>();
1211 cmd2.Init(GL_TEXTURE_2D,
1212 GL_TEXTURE_MAG_FILTER,
1213 &data);
1214 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1215 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1219 BindTexture cmd1;
1220 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1221 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1222 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1223 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1225 GLfloat data = GL_NEAREST;
1226 TexParameterfvImmediate& cmd2 =
1227 *GetImmediateAs<TexParameterfvImmediate>();
1228 cmd2.Init(GL_TEXTURE_CUBE_MAP,
1229 GL_TEXTURE_MAG_FILTER,
1230 &data);
1231 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1232 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1236 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameteriv) {
1237 InitState init;
1238 init.gl_version = "3.0";
1239 InitDecoder(init);
1242 BindTexture cmd1;
1243 cmd1.Init(GL_TEXTURE_2D, 0);
1244 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1245 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1246 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1248 GLfloat data = GL_NEAREST;
1249 TexParameterfvImmediate& cmd2 =
1250 *GetImmediateAs<TexParameterfvImmediate>();
1251 cmd2.Init(GL_TEXTURE_2D,
1252 GL_TEXTURE_MAG_FILTER,
1253 &data);
1254 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1255 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1259 BindTexture cmd1;
1260 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1261 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1262 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1263 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1265 GLfloat data = GL_NEAREST;
1266 TexParameterfvImmediate& cmd2 =
1267 *GetImmediateAs<TexParameterfvImmediate>();
1268 cmd2.Init(GL_TEXTURE_CUBE_MAP,
1269 GL_TEXTURE_MAG_FILTER,
1270 &data);
1271 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1272 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1276 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexImage2D) {
1277 InitState init;
1278 init.gl_version = "3.0";
1279 InitDecoder(init);
1281 BindTexture cmd1;
1282 cmd1.Init(GL_TEXTURE_2D, 0);
1283 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1284 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1285 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1287 TexImage2D cmd2;
1288 cmd2.Init(GL_TEXTURE_2D,
1290 GL_RGBA,
1293 GL_RGBA,
1294 GL_UNSIGNED_BYTE,
1295 kSharedMemoryId,
1296 kSharedMemoryOffset);
1297 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1298 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1301 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexSubImage2D) {
1302 InitState init;
1303 init.gl_version = "3.0";
1304 InitDecoder(init);
1306 BindTexture cmd1;
1307 cmd1.Init(GL_TEXTURE_2D, 0);
1308 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1309 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1310 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1312 TexSubImage2D cmd2;
1313 cmd2.Init(GL_TEXTURE_2D,
1319 GL_RGBA,
1320 GL_UNSIGNED_BYTE,
1321 kSharedMemoryId,
1322 kSharedMemoryOffset,
1323 GL_FALSE);
1324 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1325 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1328 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleBindTexture) {
1329 InitState init;
1330 init.extensions = "GL_ARB_texture_rectangle";
1331 init.gl_version = "3.0";
1332 init.bind_generates_resource = true;
1333 InitDecoder(init);
1334 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_RECTANGLE_ARB, kNewServiceId));
1335 EXPECT_CALL(*gl_, GenTextures(1, _))
1336 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
1337 BindTexture cmd;
1338 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, kNewClientId);
1339 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1340 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1341 Texture* texture = GetTexture(kNewClientId)->texture();
1342 EXPECT_TRUE(texture != NULL);
1343 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1346 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleGetBinding) {
1347 InitState init;
1348 init.extensions = "GL_ARB_texture_rectangle";
1349 init.gl_version = "3.0";
1350 init.bind_generates_resource = true;
1351 InitDecoder(init);
1352 DoBindTexture(
1353 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1355 EXPECT_CALL(*gl_, GetError())
1356 .WillOnce(Return(GL_NO_ERROR))
1357 .WillOnce(Return(GL_NO_ERROR))
1358 .RetiresOnSaturation();
1359 typedef GetIntegerv::Result Result;
1360 Result* result = static_cast<Result*>(shared_memory_address_);
1361 EXPECT_CALL(*gl_,
1362 GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, result->GetData()))
1363 .Times(0);
1364 result->size = 0;
1365 GetIntegerv cmd;
1366 cmd.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB,
1367 shared_memory_id_,
1368 shared_memory_offset_);
1369 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1370 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(
1371 GL_TEXTURE_BINDING_RECTANGLE_ARB),
1372 result->GetNumResults());
1373 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1374 EXPECT_EQ(client_texture_id_, (uint32)result->GetData()[0]);
1377 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureDefaults) {
1378 InitState init;
1379 init.extensions = "GL_ARB_texture_rectangle";
1380 init.gl_version = "3.0";
1381 init.bind_generates_resource = true;
1382 InitDecoder(init);
1383 DoBindTexture(
1384 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1386 Texture* texture = GetTexture(client_texture_id_)->texture();
1387 EXPECT_TRUE(texture != NULL);
1388 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1389 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1390 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1391 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1394 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureParam) {
1395 InitState init;
1396 init.extensions = "GL_ARB_texture_rectangle";
1397 init.gl_version = "3.0";
1398 init.bind_generates_resource = true;
1399 InitDecoder(init);
1401 DoBindTexture(
1402 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1404 EXPECT_CALL(*gl_,
1405 TexParameteri(
1406 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
1407 EXPECT_CALL(*gl_,
1408 TexParameteri(
1409 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1410 EXPECT_CALL(
1411 *gl_,
1412 TexParameteri(
1413 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1414 EXPECT_CALL(
1415 *gl_,
1416 TexParameteri(
1417 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1418 TexParameteri cmd;
1419 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1420 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1421 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1423 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1424 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1425 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1427 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1428 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1429 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1431 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1432 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1433 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1435 Texture* texture = GetTexture(client_texture_id_)->texture();
1436 EXPECT_TRUE(texture != NULL);
1437 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1438 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1439 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1440 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1443 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureParamInvalid) {
1444 InitState init;
1445 init.extensions = "GL_ARB_texture_rectangle";
1446 init.gl_version = "3.0";
1447 init.bind_generates_resource = true;
1448 InitDecoder(init);
1450 DoBindTexture(
1451 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1453 TexParameteri cmd;
1454 cmd.Init(GL_TEXTURE_RECTANGLE_ARB,
1455 GL_TEXTURE_MIN_FILTER,
1456 GL_NEAREST_MIPMAP_NEAREST);
1457 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1458 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1460 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_REPEAT);
1461 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1462 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1464 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_REPEAT);
1465 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1466 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1468 Texture* texture = GetTexture(client_texture_id_)->texture();
1469 EXPECT_TRUE(texture != NULL);
1470 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1471 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1472 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1473 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1476 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTexImage2DError) {
1477 InitState init;
1478 init.extensions = "GL_ARB_texture_rectangle";
1479 init.gl_version = "3.0";
1480 init.bind_generates_resource = true;
1481 InitDecoder(init);
1483 GLenum target = GL_TEXTURE_RECTANGLE_ARB;
1484 GLint level = 0;
1485 GLenum internal_format = GL_RGBA;
1486 GLsizei width = 2;
1487 GLsizei height = 4;
1488 GLenum format = GL_RGBA;
1489 GLenum type = GL_UNSIGNED_BYTE;
1490 DoBindTexture(
1491 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1492 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL);
1493 TexImage2D cmd;
1494 cmd.Init(target,
1495 level,
1496 internal_format,
1497 width,
1498 height,
1499 format,
1500 type,
1501 kSharedMemoryId,
1502 kSharedMemoryOffset);
1503 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1505 // TexImage2D is not allowed with GL_TEXTURE_RECTANGLE_ARB targets.
1506 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1509 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DClearsAfterTexImage2DNULL) {
1510 InitState init;
1511 init.gl_version = "opengl es 2.0";
1512 init.has_alpha = true;
1513 init.has_depth = true;
1514 init.request_alpha = true;
1515 init.request_depth = true;
1516 InitDecoder(init);
1518 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1519 DoTexImage2D(
1520 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1521 SetupClearTextureExpectations(kServiceTextureId,
1522 kServiceTextureId,
1523 GL_TEXTURE_2D,
1524 GL_TEXTURE_2D,
1526 GL_RGBA,
1527 GL_RGBA,
1528 GL_UNSIGNED_BYTE,
1531 EXPECT_CALL(*gl_,
1532 TexSubImage2D(GL_TEXTURE_2D,
1538 GL_RGBA,
1539 GL_UNSIGNED_BYTE,
1540 shared_memory_address_))
1541 .Times(1)
1542 .RetiresOnSaturation();
1543 TexSubImage2D cmd;
1544 cmd.Init(GL_TEXTURE_2D,
1550 GL_RGBA,
1551 GL_UNSIGNED_BYTE,
1552 kSharedMemoryId,
1553 kSharedMemoryOffset,
1554 GL_FALSE);
1555 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1556 // Test if we call it again it does not clear.
1557 EXPECT_CALL(*gl_,
1558 TexSubImage2D(GL_TEXTURE_2D,
1564 GL_RGBA,
1565 GL_UNSIGNED_BYTE,
1566 shared_memory_address_))
1567 .Times(1)
1568 .RetiresOnSaturation();
1569 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1572 TEST_P(GLES2DecoderTest, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData) {
1573 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1574 DoTexImage2D(
1575 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1576 DoTexImage2D(GL_TEXTURE_2D,
1578 GL_RGBA,
1582 GL_RGBA,
1583 GL_UNSIGNED_BYTE,
1584 kSharedMemoryId,
1585 kSharedMemoryOffset);
1586 EXPECT_CALL(*gl_,
1587 TexSubImage2D(GL_TEXTURE_2D,
1593 GL_RGBA,
1594 GL_UNSIGNED_BYTE,
1595 shared_memory_address_))
1596 .Times(1)
1597 .RetiresOnSaturation();
1598 TexSubImage2D cmd;
1599 cmd.Init(GL_TEXTURE_2D,
1605 GL_RGBA,
1606 GL_UNSIGNED_BYTE,
1607 kSharedMemoryId,
1608 kSharedMemoryOffset,
1609 GL_FALSE);
1610 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1611 // Test if we call it again it does not clear.
1612 EXPECT_CALL(*gl_,
1613 TexSubImage2D(GL_TEXTURE_2D,
1619 GL_RGBA,
1620 GL_UNSIGNED_BYTE,
1621 shared_memory_address_))
1622 .Times(1)
1623 .RetiresOnSaturation();
1624 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1627 TEST_P(
1628 GLES2DecoderManualInitTest,
1629 TexSubImage2DDoesNotClearAfterTexImage2DNULLThenDataWithTexImage2DIsFaster) {
1630 CommandLine command_line(0, NULL);
1631 command_line.AppendSwitchASCII(
1632 switches::kGpuDriverBugWorkarounds,
1633 base::IntToString(gpu::TEXSUBIMAGE2D_FASTER_THAN_TEXIMAGE2D));
1634 InitState init;
1635 init.gl_version = "3.0";
1636 init.bind_generates_resource = true;
1637 InitDecoderWithCommandLine(init, &command_line);
1638 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1639 DoTexImage2D(
1640 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1643 // Uses texSubimage internally because the above workaround is active and
1644 // the update is for the full size of the texture.
1645 EXPECT_CALL(*gl_,
1646 TexSubImage2D(
1647 GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, _))
1648 .Times(1)
1649 .RetiresOnSaturation();
1650 cmds::TexImage2D cmd;
1651 cmd.Init(GL_TEXTURE_2D,
1653 GL_RGBA,
1656 GL_RGBA,
1657 GL_UNSIGNED_BYTE,
1658 kSharedMemoryId,
1659 kSharedMemoryOffset);
1660 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1663 EXPECT_CALL(*gl_,
1664 TexSubImage2D(GL_TEXTURE_2D,
1670 GL_RGBA,
1671 GL_UNSIGNED_BYTE,
1672 shared_memory_address_))
1673 .Times(1)
1674 .RetiresOnSaturation();
1675 TexSubImage2D cmd;
1676 cmd.Init(GL_TEXTURE_2D,
1682 GL_RGBA,
1683 GL_UNSIGNED_BYTE,
1684 kSharedMemoryId,
1685 kSharedMemoryOffset,
1686 GL_FALSE);
1687 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1688 // Test if we call it again it does not clear.
1689 EXPECT_CALL(*gl_,
1690 TexSubImage2D(GL_TEXTURE_2D,
1696 GL_RGBA,
1697 GL_UNSIGNED_BYTE,
1698 shared_memory_address_))
1699 .Times(1)
1700 .RetiresOnSaturation();
1701 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1704 TEST_P(GLES2DecoderTest, TexSubImage2DClearsAfterTexImage2DWithDataThenNULL) {
1705 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1706 // Put in data (so it should be marked as cleared)
1707 DoTexImage2D(GL_TEXTURE_2D,
1709 GL_RGBA,
1713 GL_RGBA,
1714 GL_UNSIGNED_BYTE,
1715 kSharedMemoryId,
1716 kSharedMemoryOffset);
1717 // Put in no data.
1718 TexImage2D tex_cmd;
1719 tex_cmd.Init(
1720 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1721 // It won't actually call TexImage2D, just mark it as uncleared.
1722 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
1723 // Next call to TexSubImage2d should clear.
1724 SetupClearTextureExpectations(kServiceTextureId,
1725 kServiceTextureId,
1726 GL_TEXTURE_2D,
1727 GL_TEXTURE_2D,
1729 GL_RGBA,
1730 GL_RGBA,
1731 GL_UNSIGNED_BYTE,
1734 EXPECT_CALL(*gl_,
1735 TexSubImage2D(GL_TEXTURE_2D,
1741 GL_RGBA,
1742 GL_UNSIGNED_BYTE,
1743 shared_memory_address_))
1744 .Times(1)
1745 .RetiresOnSaturation();
1746 TexSubImage2D cmd;
1747 cmd.Init(GL_TEXTURE_2D,
1753 GL_RGBA,
1754 GL_UNSIGNED_BYTE,
1755 kSharedMemoryId,
1756 kSharedMemoryOffset,
1757 GL_FALSE);
1758 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1761 TEST_P(GLES2DecoderTest, CopyTexImage2DMarksTextureAsCleared) {
1762 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1764 TextureManager* manager = group().texture_manager();
1765 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
1766 ASSERT_TRUE(texture_ref != NULL);
1767 Texture* texture = texture_ref->texture();
1769 EXPECT_CALL(*gl_, GetError())
1770 .WillOnce(Return(GL_NO_ERROR))
1771 .RetiresOnSaturation();
1772 EXPECT_CALL(*gl_, CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1, 0))
1773 .Times(1)
1774 .RetiresOnSaturation();
1775 EXPECT_CALL(*gl_, GetError())
1776 .WillOnce(Return(GL_NO_ERROR))
1777 .RetiresOnSaturation();
1778 CopyTexImage2D cmd;
1779 cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1);
1780 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1782 EXPECT_TRUE(texture->SafeToRenderFrom());
1785 TEST_P(GLES2DecoderTest, CopyTexSubImage2DClearsUnclearedTexture) {
1786 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1787 DoTexImage2D(
1788 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1790 SetupClearTextureExpectations(kServiceTextureId,
1791 kServiceTextureId,
1792 GL_TEXTURE_2D,
1793 GL_TEXTURE_2D,
1795 GL_RGBA,
1796 GL_RGBA,
1797 GL_UNSIGNED_BYTE,
1800 EXPECT_CALL(*gl_, CopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1))
1801 .Times(1)
1802 .RetiresOnSaturation();
1803 CopyTexSubImage2D cmd;
1804 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1805 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1808 TEST_P(GLES2DecoderManualInitTest, CompressedImage2DMarksTextureAsCleared) {
1809 InitState init;
1810 init.extensions = "GL_EXT_texture_compression_s3tc";
1811 init.gl_version = "3.0";
1812 init.bind_generates_resource = true;
1813 InitDecoder(init);
1815 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1816 EXPECT_CALL(*gl_, GetError())
1817 .WillOnce(Return(GL_NO_ERROR))
1818 .RetiresOnSaturation();
1819 EXPECT_CALL(
1820 *gl_,
1821 CompressedTexImage2D(
1822 GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 8, _))
1823 .Times(1)
1824 .RetiresOnSaturation();
1825 EXPECT_CALL(*gl_, GetError())
1826 .WillOnce(Return(GL_NO_ERROR))
1827 .RetiresOnSaturation();
1828 CompressedTexImage2D cmd;
1829 cmd.Init(GL_TEXTURE_2D,
1831 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1835 kSharedMemoryId,
1836 kSharedMemoryOffset);
1837 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1838 TextureManager* manager = group().texture_manager();
1839 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
1840 EXPECT_TRUE(texture_ref->texture()->SafeToRenderFrom());
1843 TEST_P(GLES2DecoderTest, TextureUsageAngleExtNotEnabledByDefault) {
1844 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1846 TexParameteri cmd;
1847 cmd.Init(
1848 GL_TEXTURE_2D, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
1849 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1850 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1853 TEST_P(GLES2DecoderTest, ProduceAndConsumeTextureCHROMIUM) {
1854 Mailbox mailbox = Mailbox::Generate();
1856 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1857 DoTexImage2D(
1858 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1859 DoTexImage2D(
1860 GL_TEXTURE_2D, 1, GL_RGBA, 2, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1861 TextureRef* texture_ref =
1862 group().texture_manager()->GetTexture(client_texture_id_);
1863 ASSERT_TRUE(texture_ref != NULL);
1864 Texture* texture = texture_ref->texture();
1865 EXPECT_EQ(kServiceTextureId, texture->service_id());
1867 ProduceTextureCHROMIUMImmediate& produce_cmd =
1868 *GetImmediateAs<ProduceTextureCHROMIUMImmediate>();
1869 produce_cmd.Init(GL_TEXTURE_2D, mailbox.name);
1870 EXPECT_EQ(error::kNoError,
1871 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
1872 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1874 // Texture didn't change.
1875 GLsizei width;
1876 GLsizei height;
1877 GLenum type;
1878 GLenum internal_format;
1880 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
1881 EXPECT_EQ(3, width);
1882 EXPECT_EQ(1, height);
1883 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
1884 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1885 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1887 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
1888 EXPECT_EQ(2, width);
1889 EXPECT_EQ(4, height);
1890 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
1891 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1892 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1894 // Service ID has not changed.
1895 EXPECT_EQ(kServiceTextureId, texture->service_id());
1897 // Create new texture for consume.
1898 EXPECT_CALL(*gl_, GenTextures(_, _))
1899 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
1900 .RetiresOnSaturation();
1901 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kNewServiceId);
1903 // Assigns and binds original service size texture ID.
1904 EXPECT_CALL(*gl_, DeleteTextures(1, _)).Times(1).RetiresOnSaturation();
1905 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
1906 .Times(1)
1907 .RetiresOnSaturation();
1909 ConsumeTextureCHROMIUMImmediate& consume_cmd =
1910 *GetImmediateAs<ConsumeTextureCHROMIUMImmediate>();
1911 consume_cmd.Init(GL_TEXTURE_2D, mailbox.name);
1912 EXPECT_EQ(error::kNoError,
1913 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name)));
1914 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1916 // Texture is redefined.
1917 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
1918 EXPECT_EQ(3, width);
1919 EXPECT_EQ(1, height);
1920 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
1921 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1922 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1924 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
1925 EXPECT_EQ(2, width);
1926 EXPECT_EQ(4, height);
1927 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
1928 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1929 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1931 // Service ID is restored.
1932 EXPECT_EQ(kServiceTextureId, texture->service_id());
1935 TEST_P(GLES2DecoderTest, ProduceAndConsumeDirectTextureCHROMIUM) {
1936 Mailbox mailbox = Mailbox::Generate();
1938 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1939 DoTexImage2D(
1940 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1941 DoTexImage2D(
1942 GL_TEXTURE_2D, 1, GL_RGBA, 2, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1943 TextureRef* texture_ref =
1944 group().texture_manager()->GetTexture(client_texture_id_);
1945 ASSERT_TRUE(texture_ref != NULL);
1946 Texture* texture = texture_ref->texture();
1947 EXPECT_EQ(kServiceTextureId, texture->service_id());
1949 ProduceTextureDirectCHROMIUMImmediate& produce_cmd =
1950 *GetImmediateAs<ProduceTextureDirectCHROMIUMImmediate>();
1951 produce_cmd.Init(client_texture_id_, GL_TEXTURE_2D, mailbox.name);
1952 EXPECT_EQ(error::kNoError,
1953 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
1954 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1956 // Texture didn't change.
1957 GLsizei width;
1958 GLsizei height;
1959 GLenum type;
1960 GLenum internal_format;
1962 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
1963 EXPECT_EQ(3, width);
1964 EXPECT_EQ(1, height);
1965 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
1966 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1967 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1969 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
1970 EXPECT_EQ(2, width);
1971 EXPECT_EQ(4, height);
1972 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
1973 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1974 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1976 // Service ID has not changed.
1977 EXPECT_EQ(kServiceTextureId, texture->service_id());
1979 // Consume the texture into a new client ID.
1980 GLuint new_texture_id = kNewClientId;
1981 CreateAndConsumeTextureCHROMIUMImmediate& consume_cmd =
1982 *GetImmediateAs<CreateAndConsumeTextureCHROMIUMImmediate>();
1983 consume_cmd.Init(GL_TEXTURE_2D, new_texture_id, mailbox.name);
1984 EXPECT_EQ(error::kNoError,
1985 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name)));
1986 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1988 // Make sure the new client ID is associated with the produced service ID.
1989 texture_ref = group().texture_manager()->GetTexture(new_texture_id);
1990 ASSERT_TRUE(texture_ref != NULL);
1991 texture = texture_ref->texture();
1992 EXPECT_EQ(kServiceTextureId, texture->service_id());
1994 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kServiceTextureId);
1996 // Texture is redefined.
1997 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
1998 EXPECT_EQ(3, width);
1999 EXPECT_EQ(1, height);
2000 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2001 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2002 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2004 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
2005 EXPECT_EQ(2, width);
2006 EXPECT_EQ(4, height);
2007 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
2008 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2009 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2012 TEST_P(GLES2DecoderTest, ProduceTextureCHROMIUMInvalidTarget) {
2013 Mailbox mailbox = Mailbox::Generate();
2015 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2016 DoTexImage2D(
2017 GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 3, 1, 0, GL_RGBA,
2018 GL_UNSIGNED_BYTE, 0, 0);
2019 TextureRef* texture_ref =
2020 group().texture_manager()->GetTexture(client_texture_id_);
2021 ASSERT_TRUE(texture_ref != NULL);
2022 Texture* texture = texture_ref->texture();
2023 EXPECT_EQ(kServiceTextureId, texture->service_id());
2025 ProduceTextureDirectCHROMIUMImmediate& produce_cmd =
2026 *GetImmediateAs<ProduceTextureDirectCHROMIUMImmediate>();
2027 produce_cmd.Init(client_texture_id_, GL_TEXTURE_2D, mailbox.name);
2028 EXPECT_EQ(error::kNoError,
2029 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
2031 // ProduceTexture should fail it the texture and produce targets don't match.
2032 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2035 TEST_P(GLES2DecoderManualInitTest, DepthTextureBadArgs) {
2036 InitState init;
2037 init.extensions = "GL_ANGLE_depth_texture";
2038 init.gl_version = "opengl es 2.0";
2039 init.has_depth = true;
2040 init.has_stencil = true;
2041 init.request_depth = true;
2042 init.request_stencil = true;
2043 init.bind_generates_resource = true;
2044 InitDecoder(init);
2046 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2047 // Check trying to upload data fails.
2048 TexImage2D tex_cmd;
2049 tex_cmd.Init(GL_TEXTURE_2D,
2051 GL_DEPTH_COMPONENT,
2054 GL_DEPTH_COMPONENT,
2055 GL_UNSIGNED_INT,
2056 kSharedMemoryId,
2057 kSharedMemoryOffset);
2058 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
2059 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2060 // Try level > 0.
2061 tex_cmd.Init(GL_TEXTURE_2D,
2063 GL_DEPTH_COMPONENT,
2066 GL_DEPTH_COMPONENT,
2067 GL_UNSIGNED_INT,
2070 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
2071 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2072 // Make a 1 pixel depth texture.
2073 DoTexImage2D(GL_TEXTURE_2D,
2075 GL_DEPTH_COMPONENT,
2079 GL_DEPTH_COMPONENT,
2080 GL_UNSIGNED_INT,
2083 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2085 // Check that trying to update it fails.
2086 TexSubImage2D tex_sub_cmd;
2087 tex_sub_cmd.Init(GL_TEXTURE_2D,
2093 GL_DEPTH_COMPONENT,
2094 GL_UNSIGNED_INT,
2095 kSharedMemoryId,
2096 kSharedMemoryOffset,
2097 GL_FALSE);
2098 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_sub_cmd));
2099 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2101 // Check that trying to CopyTexImage2D fails
2102 CopyTexImage2D copy_tex_cmd;
2103 copy_tex_cmd.Init(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 1, 1);
2104 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_tex_cmd));
2105 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2107 // Check that trying to CopyTexSubImage2D fails
2108 CopyTexSubImage2D copy_sub_cmd;
2109 copy_sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
2110 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_sub_cmd));
2111 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2114 TEST_P(GLES2DecoderManualInitTest, GenerateMipmapDepthTexture) {
2115 InitState init;
2116 init.extensions = "GL_ANGLE_depth_texture";
2117 init.gl_version = "opengl es 2.0";
2118 init.has_depth = true;
2119 init.has_stencil = true;
2120 init.request_depth = true;
2121 init.request_stencil = true;
2122 init.bind_generates_resource = true;
2123 InitDecoder(init);
2124 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2125 DoTexImage2D(GL_TEXTURE_2D,
2127 GL_DEPTH_COMPONENT,
2131 GL_DEPTH_COMPONENT,
2132 GL_UNSIGNED_INT,
2135 GenerateMipmap cmd;
2136 cmd.Init(GL_TEXTURE_2D);
2137 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2138 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2141 TEST_P(GLES2DecoderTest, BindTexImage2DCHROMIUM) {
2142 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2143 DoTexImage2D(
2144 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2145 TextureRef* texture_ref =
2146 group().texture_manager()->GetTexture(client_texture_id_);
2147 ASSERT_TRUE(texture_ref != NULL);
2148 Texture* texture = texture_ref->texture();
2149 EXPECT_EQ(kServiceTextureId, texture->service_id());
2151 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2152 GetImageManager()->AddImage(image.get(), 1);
2153 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL);
2155 GLsizei width;
2156 GLsizei height;
2157 GLenum type;
2158 GLenum internal_format;
2160 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2161 EXPECT_EQ(3, width);
2162 EXPECT_EQ(1, height);
2163 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2164 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2165 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2166 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2168 // Bind image to texture.
2169 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2170 EXPECT_CALL(*gl_, GetError())
2171 .WillOnce(Return(GL_NO_ERROR))
2172 .WillOnce(Return(GL_NO_ERROR))
2173 .RetiresOnSaturation();
2174 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2175 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
2176 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2177 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2178 // Image should now be set.
2179 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2181 // Define new texture image.
2182 DoTexImage2D(
2183 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2184 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2185 // Image should no longer be set.
2186 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2189 TEST_P(GLES2DecoderTest, BindTexImage2DCHROMIUMCubeMapNotAllowed) {
2190 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2191 GetImageManager()->AddImage(image.get(), 1);
2192 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2194 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2195 bind_tex_image_2d_cmd.Init(GL_TEXTURE_CUBE_MAP, 1);
2196 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2197 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
2200 TEST_P(GLES2DecoderTest, OrphanGLImageWithTexImage2D) {
2201 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2202 GetImageManager()->AddImage(image.get(), 1);
2203 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2205 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2206 bind_tex_image_2d_cmd.Init(GL_TEXTURE_CUBE_MAP, 1);
2207 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2208 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
2210 DoTexImage2D(
2211 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2212 TextureRef* texture_ref =
2213 group().texture_manager()->GetTexture(client_texture_id_);
2214 ASSERT_TRUE(texture_ref != NULL);
2215 Texture* texture = texture_ref->texture();
2216 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2219 TEST_P(GLES2DecoderTest, ReleaseTexImage2DCHROMIUM) {
2220 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2221 DoTexImage2D(
2222 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2223 TextureRef* texture_ref =
2224 group().texture_manager()->GetTexture(client_texture_id_);
2225 ASSERT_TRUE(texture_ref != NULL);
2226 Texture* texture = texture_ref->texture();
2227 EXPECT_EQ(kServiceTextureId, texture->service_id());
2229 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2230 GetImageManager()->AddImage(image.get(), 1);
2231 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL);
2233 GLsizei width;
2234 GLsizei height;
2235 GLenum type;
2236 GLenum internal_format;
2238 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2239 EXPECT_EQ(3, width);
2240 EXPECT_EQ(1, height);
2241 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2242 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2243 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2244 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2246 // Bind image to texture.
2247 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2248 EXPECT_CALL(*gl_, GetError())
2249 .WillOnce(Return(GL_NO_ERROR))
2250 .WillOnce(Return(GL_NO_ERROR))
2251 .RetiresOnSaturation();
2252 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2253 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
2254 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2255 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2256 // Image should now be set.
2257 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2259 // Release image from texture.
2260 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2261 EXPECT_CALL(*gl_, GetError())
2262 .WillOnce(Return(GL_NO_ERROR))
2263 .WillOnce(Return(GL_NO_ERROR))
2264 .RetiresOnSaturation();
2265 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd;
2266 release_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
2267 EXPECT_EQ(error::kNoError, ExecuteCmd(release_tex_image_2d_cmd));
2268 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2269 // Image should no longer be set.
2270 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2273 class MockGLImage : public gfx::GLImage {
2274 public:
2275 MockGLImage() {}
2277 // Overridden from gfx::GLImage:
2278 MOCK_METHOD0(GetSize, gfx::Size());
2279 MOCK_METHOD1(Destroy, void(bool));
2280 MOCK_METHOD1(BindTexImage, bool(unsigned));
2281 MOCK_METHOD1(ReleaseTexImage, void(unsigned));
2282 MOCK_METHOD0(WillUseTexImage, void());
2283 MOCK_METHOD0(DidUseTexImage, void());
2284 MOCK_METHOD0(WillModifyTexImage, void());
2285 MOCK_METHOD0(DidModifyTexImage, void());
2286 MOCK_METHOD5(ScheduleOverlayPlane, bool(gfx::AcceleratedWidget,
2287 int,
2288 gfx::OverlayTransform,
2289 const gfx::Rect&,
2290 const gfx::RectF&));
2292 protected:
2293 virtual ~MockGLImage() {}
2296 TEST_P(GLES2DecoderWithShaderTest, UseTexImage) {
2297 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2298 DoTexImage2D(GL_TEXTURE_2D,
2300 GL_RGBA,
2304 GL_RGBA,
2305 GL_UNSIGNED_BYTE,
2306 kSharedMemoryId,
2307 kSharedMemoryOffset);
2309 TextureRef* texture_ref =
2310 group().texture_manager()->GetTexture(client_texture_id_);
2311 ASSERT_TRUE(texture_ref != NULL);
2312 Texture* texture = texture_ref->texture();
2313 EXPECT_EQ(kServiceTextureId, texture->service_id());
2315 const int32 kImageId = 1;
2316 scoped_refptr<MockGLImage> image(new MockGLImage);
2317 GetImageManager()->AddImage(image.get(), kImageId);
2319 // Bind image to texture.
2320 EXPECT_CALL(*image.get(), BindTexImage(GL_TEXTURE_2D))
2321 .Times(1)
2322 .WillOnce(Return(true))
2323 .RetiresOnSaturation();
2324 EXPECT_CALL(*image.get(), GetSize())
2325 .Times(1)
2326 .WillOnce(Return(gfx::Size(1, 1)))
2327 .RetiresOnSaturation();
2328 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2329 EXPECT_CALL(*gl_, GetError())
2330 .WillOnce(Return(GL_NO_ERROR))
2331 .WillOnce(Return(GL_NO_ERROR))
2332 .RetiresOnSaturation();
2333 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2334 bind_tex_image_2d_cmd.Init(GL_TEXTURE_2D, kImageId);
2335 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2337 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2338 SetupExpectationsForApplyingDefaultDirtyState();
2340 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2341 EXPECT_CALL(*gl_, GetError())
2342 .WillOnce(Return(GL_NO_ERROR))
2343 .WillOnce(Return(GL_NO_ERROR))
2344 .WillOnce(Return(GL_NO_ERROR))
2345 .WillOnce(Return(GL_NO_ERROR))
2346 .RetiresOnSaturation();
2347 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(3).RetiresOnSaturation();
2348 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2349 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2350 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2351 .Times(1)
2352 .RetiresOnSaturation();
2353 DrawArrays cmd;
2354 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2355 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2356 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2358 DoBindFramebuffer(
2359 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2360 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2361 EXPECT_CALL(*gl_, GetError())
2362 .WillOnce(Return(GL_NO_ERROR))
2363 .WillOnce(Return(GL_NO_ERROR))
2364 .RetiresOnSaturation();
2365 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2366 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2367 .Times(2)
2368 .RetiresOnSaturation();
2369 // Image will be 'in use' as long as bound to a framebuffer.
2370 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2371 EXPECT_CALL(*gl_,
2372 FramebufferTexture2DEXT(GL_FRAMEBUFFER,
2373 GL_COLOR_ATTACHMENT0,
2374 GL_TEXTURE_2D,
2375 kServiceTextureId,
2377 .Times(1)
2378 .RetiresOnSaturation();
2379 EXPECT_CALL(*gl_, GetError())
2380 .WillOnce(Return(GL_NO_ERROR))
2381 .WillOnce(Return(GL_NO_ERROR))
2382 .RetiresOnSaturation();
2383 FramebufferTexture2D fbtex_cmd;
2384 fbtex_cmd.Init(GL_FRAMEBUFFER,
2385 GL_COLOR_ATTACHMENT0,
2386 GL_TEXTURE_2D,
2387 client_texture_id_);
2388 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd));
2389 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2391 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2392 EXPECT_CALL(*gl_, GetError())
2393 .WillOnce(Return(GL_NO_ERROR))
2394 .WillOnce(Return(GL_NO_ERROR))
2395 .RetiresOnSaturation();
2396 EXPECT_CALL(*gl_,
2397 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
2398 GL_COLOR_ATTACHMENT0,
2399 GL_RENDERBUFFER,
2400 kServiceRenderbufferId))
2401 .Times(1)
2402 .RetiresOnSaturation();
2403 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2404 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2405 .Times(2)
2406 .RetiresOnSaturation();
2407 // Image should no longer be 'in use' after being unbound from framebuffer.
2408 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2409 EXPECT_CALL(*gl_, GetError())
2410 .WillOnce(Return(GL_NO_ERROR))
2411 .WillOnce(Return(GL_NO_ERROR))
2412 .RetiresOnSaturation();
2413 FramebufferRenderbuffer fbrb_cmd;
2414 fbrb_cmd.Init(GL_FRAMEBUFFER,
2415 GL_COLOR_ATTACHMENT0,
2416 GL_RENDERBUFFER,
2417 client_renderbuffer_id_);
2418 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
2421 TEST_P(GLES2DecoderManualInitTest, DrawWithGLImageExternal) {
2422 InitState init;
2423 init.extensions = "GL_OES_EGL_image_external";
2424 init.gl_version = "opengl es 2.0";
2425 init.has_alpha = true;
2426 init.has_depth = true;
2427 init.request_alpha = true;
2428 init.request_depth = true;
2429 init.bind_generates_resource = true;
2430 InitDecoder(init);
2432 TextureRef* texture_ref = GetTexture(client_texture_id_);
2433 scoped_refptr<MockGLImage> image(new MockGLImage);
2434 group().texture_manager()->SetTarget(texture_ref, GL_TEXTURE_EXTERNAL_OES);
2435 group().texture_manager()->SetLevelInfo(texture_ref,
2436 GL_TEXTURE_EXTERNAL_OES,
2438 GL_RGBA,
2443 GL_RGBA,
2444 GL_UNSIGNED_BYTE,
2445 true);
2446 group().texture_manager()->SetLevelImage(
2447 texture_ref, GL_TEXTURE_EXTERNAL_OES, 0, image.get());
2449 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
2450 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2452 SetupSamplerExternalProgram();
2453 SetupIndexBuffer();
2454 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
2455 SetupExpectationsForApplyingDefaultDirtyState();
2456 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref));
2458 InSequence s;
2459 EXPECT_CALL(*gl_, GetError())
2460 .WillOnce(Return(GL_NO_ERROR))
2461 .RetiresOnSaturation();
2462 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2463 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2464 EXPECT_CALL(*gl_, GetError())
2465 .WillOnce(Return(GL_NO_ERROR))
2466 .RetiresOnSaturation();
2467 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(1);
2468 EXPECT_CALL(*gl_, GetError())
2469 .WillOnce(Return(GL_NO_ERROR))
2470 .RetiresOnSaturation();
2471 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2472 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2473 EXPECT_CALL(*gl_, GetError())
2474 .WillOnce(Return(GL_NO_ERROR))
2475 .RetiresOnSaturation();
2476 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2477 DrawElements cmd;
2478 cmd.Init(GL_TRIANGLES,
2479 kValidIndexRangeCount,
2480 GL_UNSIGNED_SHORT,
2481 kValidIndexRangeStart * 2);
2482 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2483 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2486 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES2) {
2487 InitState init;
2488 init.extensions = "GL_OES_texture_float";
2489 init.gl_version = "opengl es 2.0";
2490 InitDecoder(init);
2491 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2492 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2493 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0);
2494 DoTexImage2D(
2495 GL_TEXTURE_2D, 0, GL_LUMINANCE, 16, 17, 0, GL_LUMINANCE, GL_FLOAT, 0, 0);
2496 DoTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 16, 17, 0, GL_ALPHA, GL_FLOAT, 0, 0);
2497 DoTexImage2D(GL_TEXTURE_2D,
2499 GL_LUMINANCE_ALPHA,
2503 GL_LUMINANCE_ALPHA,
2504 GL_FLOAT,
2509 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES3) {
2510 InitState init;
2511 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
2512 init.gl_version = "opengl es 3.0";
2513 InitDecoder(init);
2514 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2515 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2516 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0);
2517 DoTexImage2D(
2518 GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2519 DoTexImage2D(
2520 GL_TEXTURE_2D, 0, GL_LUMINANCE, 16, 17, 0, GL_LUMINANCE, GL_FLOAT, 0, 0);
2521 DoTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 16, 17, 0, GL_ALPHA, GL_FLOAT, 0, 0);
2522 DoTexImage2D(GL_TEXTURE_2D,
2524 GL_LUMINANCE_ALPHA,
2528 GL_LUMINANCE_ALPHA,
2529 GL_FLOAT,
2534 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DFloatOnGLES3) {
2535 InitState init;
2536 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
2537 init.gl_version = "opengl es 3.0";
2538 InitDecoder(init);
2539 const int kWidth = 8;
2540 const int kHeight = 4;
2541 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2542 DoTexImage2D(GL_TEXTURE_2D,
2544 GL_RGBA32F,
2545 kWidth,
2546 kHeight,
2548 GL_RGBA,
2549 GL_FLOAT,
2552 EXPECT_CALL(*gl_,
2553 TexImage2D(GL_TEXTURE_2D,
2555 GL_RGBA32F,
2556 kWidth,
2557 kHeight,
2559 GL_RGBA,
2560 GL_FLOAT,
2561 shared_memory_address_))
2562 .Times(1)
2563 .RetiresOnSaturation();
2564 TexSubImage2D cmd;
2565 cmd.Init(GL_TEXTURE_2D,
2569 kWidth,
2570 kHeight,
2571 GL_RGBA,
2572 GL_FLOAT,
2573 kSharedMemoryId,
2574 kSharedMemoryOffset,
2575 GL_FALSE);
2576 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2577 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2580 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DFloatDoesClearOnGLES3) {
2581 InitState init;
2582 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
2583 init.gl_version = "opengl es 3.0";
2584 InitDecoder(init);
2585 const int kWidth = 8;
2586 const int kHeight = 4;
2587 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2588 DoTexImage2D(GL_TEXTURE_2D,
2590 GL_RGBA32F,
2591 kWidth,
2592 kHeight,
2594 GL_RGBA,
2595 GL_FLOAT,
2598 SetupClearTextureExpectations(kServiceTextureId,
2599 kServiceTextureId,
2600 GL_TEXTURE_2D,
2601 GL_TEXTURE_2D,
2603 GL_RGBA32F,
2604 GL_RGBA,
2605 GL_FLOAT,
2606 kWidth,
2607 kHeight);
2608 EXPECT_CALL(*gl_,
2609 TexSubImage2D(GL_TEXTURE_2D,
2613 kWidth - 1,
2614 kHeight,
2615 GL_RGBA,
2616 GL_FLOAT,
2617 shared_memory_address_))
2618 .Times(1)
2619 .RetiresOnSaturation();
2620 TexSubImage2D cmd;
2621 cmd.Init(GL_TEXTURE_2D,
2625 kWidth - 1,
2626 kHeight,
2627 GL_RGBA,
2628 GL_FLOAT,
2629 kSharedMemoryId,
2630 kSharedMemoryOffset,
2631 GL_FALSE);
2632 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2633 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2636 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatConvertsFormatDesktop) {
2637 InitState init;
2638 init.extensions = "GL_ARB_texture_float";
2639 init.gl_version = "2.1";
2640 InitDecoder(init);
2641 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2642 DoTexImage2D(
2643 GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2644 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0);
2645 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2647 GL_RGBA,
2651 GL_RGBA,
2652 GL_FLOAT,
2655 GL_RGBA32F_ARB);
2656 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2658 GL_RGB,
2662 GL_RGB,
2663 GL_FLOAT,
2666 GL_RGB32F_ARB);
2667 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2669 GL_LUMINANCE,
2673 GL_LUMINANCE,
2674 GL_FLOAT,
2677 GL_LUMINANCE32F_ARB);
2678 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2680 GL_ALPHA,
2684 GL_ALPHA,
2685 GL_FLOAT,
2688 GL_ALPHA32F_ARB);
2689 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2691 GL_LUMINANCE_ALPHA,
2695 GL_LUMINANCE_ALPHA,
2696 GL_FLOAT,
2699 GL_LUMINANCE_ALPHA32F_ARB);
2702 class GLES2DecoderCompressedFormatsTest : public GLES2DecoderManualInitTest {
2703 public:
2704 GLES2DecoderCompressedFormatsTest() {}
2706 static bool ValueInArray(GLint value, GLint* array, GLint count) {
2707 for (GLint ii = 0; ii < count; ++ii) {
2708 if (array[ii] == value) {
2709 return true;
2712 return false;
2715 void CheckFormats(const char* extension, const GLenum* formats, int count) {
2716 InitState init;
2717 init.extensions = extension;
2718 init.gl_version = "3.0";
2719 init.bind_generates_resource = true;
2720 InitDecoder(init);
2722 EXPECT_CALL(*gl_, GetError())
2723 .WillOnce(Return(GL_NO_ERROR))
2724 .WillOnce(Return(GL_NO_ERROR))
2725 .WillOnce(Return(GL_NO_ERROR))
2726 .WillOnce(Return(GL_NO_ERROR))
2727 .RetiresOnSaturation();
2729 typedef GetIntegerv::Result Result;
2730 Result* result = static_cast<Result*>(shared_memory_address_);
2731 GetIntegerv cmd;
2732 result->size = 0;
2733 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
2734 cmd.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS,
2735 shared_memory_id_,
2736 shared_memory_offset_);
2737 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2738 EXPECT_EQ(1, result->GetNumResults());
2739 GLint num_formats = result->GetData()[0];
2740 EXPECT_EQ(count, num_formats);
2741 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2743 result->size = 0;
2744 cmd.Init(GL_COMPRESSED_TEXTURE_FORMATS,
2745 shared_memory_id_,
2746 shared_memory_offset_);
2747 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2748 EXPECT_EQ(num_formats, result->GetNumResults());
2750 for (int i = 0; i < count; ++i) {
2751 EXPECT_TRUE(
2752 ValueInArray(formats[i], result->GetData(), result->GetNumResults()));
2755 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2759 INSTANTIATE_TEST_CASE_P(Service,
2760 GLES2DecoderCompressedFormatsTest,
2761 ::testing::Bool());
2763 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsS3TC) {
2764 const GLenum formats[] = {
2765 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
2766 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT};
2767 CheckFormats("GL_EXT_texture_compression_s3tc", formats, 4);
2770 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsATC) {
2771 const GLenum formats[] = {GL_ATC_RGB_AMD, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD,
2772 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD};
2773 CheckFormats("GL_AMD_compressed_ATC_texture", formats, 3);
2776 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsPVRTC) {
2777 const GLenum formats[] = {
2778 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG,
2779 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG};
2780 CheckFormats("GL_IMG_texture_compression_pvrtc", formats, 4);
2783 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsETC1) {
2784 const GLenum formats[] = {GL_ETC1_RGB8_OES};
2785 CheckFormats("GL_OES_compressed_ETC1_RGB8_texture", formats, 1);
2788 TEST_P(GLES2DecoderManualInitTest, GetNoCompressedTextureFormats) {
2789 InitState init;
2790 init.gl_version = "3.0";
2791 init.bind_generates_resource = true;
2792 InitDecoder(init);
2794 EXPECT_CALL(*gl_, GetError())
2795 .WillOnce(Return(GL_NO_ERROR))
2796 .WillOnce(Return(GL_NO_ERROR))
2797 .WillOnce(Return(GL_NO_ERROR))
2798 .WillOnce(Return(GL_NO_ERROR))
2799 .RetiresOnSaturation();
2801 typedef GetIntegerv::Result Result;
2802 Result* result = static_cast<Result*>(shared_memory_address_);
2803 GetIntegerv cmd;
2804 result->size = 0;
2805 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
2806 cmd.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS,
2807 shared_memory_id_,
2808 shared_memory_offset_);
2809 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2810 EXPECT_EQ(1, result->GetNumResults());
2811 GLint num_formats = result->GetData()[0];
2812 EXPECT_EQ(0, num_formats);
2813 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2815 result->size = 0;
2816 cmd.Init(
2817 GL_COMPRESSED_TEXTURE_FORMATS, shared_memory_id_, shared_memory_offset_);
2818 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2819 EXPECT_EQ(num_formats, result->GetNumResults());
2821 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2824 // TODO(gman): Complete this test.
2825 // TEST_P(GLES2DecoderTest, CompressedTexImage2DGLError) {
2826 // }
2828 // TODO(gman): CompressedTexImage2D
2830 // TODO(gman): CompressedTexImage2DImmediate
2832 // TODO(gman): CompressedTexSubImage2DImmediate
2834 // TODO(gman): TexImage2D
2836 // TODO(gman): TexImage2DImmediate
2838 // TODO(gman): TexSubImage2DImmediate
2840 } // namespace gles2
2841 } // namespace gpu