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
37 using ::gfx::MockGLInterface
;
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
;
58 TEST_P(GLES2DecoderTest
, GenerateMipmapWrongFormatsFails
) {
59 EXPECT_CALL(*gl_
, GenerateMipmapEXT(_
)).Times(0);
60 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
62 GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 17, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
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();
77 EXPECT_FALSE(texture
->GetLevelSize(GL_TEXTURE_2D
, 2, &width
, &height
));
78 DoTexImage2D(GL_TEXTURE_2D
,
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();
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
);
104 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
105 SetupClearTextureExpectations(kServiceTextureId
,
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();
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
));
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
);
140 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
141 SetupClearTextureExpectations(kServiceTextureId
,
154 GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_NEAREST
))
156 .RetiresOnSaturation();
157 EXPECT_CALL(*gl_
, GenerateMipmapEXT(GL_TEXTURE_2D
));
161 GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_LINEAR
))
163 .RetiresOnSaturation();
164 EXPECT_CALL(*gl_
, GetError())
165 .WillOnce(Return(GL_NO_ERROR
))
166 .WillOnce(Return(GL_NO_ERROR
))
167 .RetiresOnSaturation();
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);
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);
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
,
208 kSharedMemoryOffset
);
210 TexSubImage2D(GL_TEXTURE_2D
,
218 shared_memory_address_
))
220 .RetiresOnSaturation();
222 cmd
.Init(GL_TEXTURE_2D
,
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
,
252 cmd
.Init(GL_TEXTURE0
,
263 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
264 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
265 cmd
.Init(GL_TEXTURE_2D
,
276 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
277 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
278 cmd
.Init(GL_TEXTURE_2D
,
289 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
290 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
291 cmd
.Init(GL_TEXTURE_2D
,
302 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
303 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
304 cmd
.Init(GL_TEXTURE_2D
,
315 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
316 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
317 cmd
.Init(GL_TEXTURE_2D
,
328 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
329 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
330 cmd
.Init(GL_TEXTURE_2D
,
341 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
342 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
343 cmd
.Init(GL_TEXTURE_2D
,
354 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
355 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
356 cmd
.Init(GL_TEXTURE_2D
,
367 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
368 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
369 cmd
.Init(GL_TEXTURE_2D
,
380 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
381 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
382 cmd
.Init(GL_TEXTURE_2D
,
389 GL_UNSIGNED_SHORT_4_4_4_4
,
393 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
394 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
395 cmd
.Init(GL_TEXTURE_2D
,
403 kInvalidSharedMemoryId
,
406 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
407 cmd
.Init(GL_TEXTURE_2D
,
416 kInvalidSharedMemoryOffset
,
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
,
434 kSharedMemoryOffset
);
436 CopyTexSubImage2D(GL_TEXTURE_2D
, 1, 0, 0, 0, 0, kWidth
, kHeight
))
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
,
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
) {
492 TexImage2D(GL_TEXTURE_2D
,
502 .RetiresOnSaturation();
503 cmd
.Init(GL_TEXTURE_2D
,
511 kSharedMemoryOffset
);
513 SetupClearTextureExpectations(kServiceTextureId
,
523 cmd
.Init(GL_TEXTURE_2D
,
533 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
535 TexSubImage2D(GL_TEXTURE_2D
,
543 shared_memory_address_
))
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.
550 cmd2
.Init(GL_TEXTURE_2D
,
561 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
565 TEST_P(GLES2DecoderTest
, TexImage2DGLError
) {
566 GLenum target
= GL_TEXTURE_2D
;
568 GLenum internal_format
= GL_RGBA
;
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();
595 .RetiresOnSaturation();
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
;
614 GLenum internal_format
= GL_RGBA
;
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();
630 target
, level
, internal_format
, 0, 0, width
, height
, border
))
632 .RetiresOnSaturation();
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
) {
642 init
.extensions
= "GL_EXT_texture_compression_s3tc";
643 init
.bind_generates_resource
= true;
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
,
655 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
656 CompressedTexSubImage2DBucket cmd2
;
657 cmd2
.Init(GL_TEXTURE_2D
,
663 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
665 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
670 struct S3TCTestData
{
675 } // anonymous namespace.
677 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DS3TC
) {
679 init
.extensions
= "GL_EXT_texture_compression_s3tc";
680 init
.bind_generates_resource
= true;
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
;
707 DoCompressedTexImage2D(
708 GL_TEXTURE_2D
, 0, test
.format
, 2, 4, 0, test
.block_size
, kBucketId
);
709 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
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());
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());
760 DoCompressedTexImage2D(GL_TEXTURE_2D
,
766 test
.block_size
* 4 * 4,
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
);
806 CompressedTexSubImage2D(GL_TEXTURE_2D
,
816 .RetiresOnSaturation();
817 sub_cmd
.Init(GL_TEXTURE_2D
,
825 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
826 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
834 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DETC1
) {
836 init
.extensions
= "GL_OES_compressed_ETC1_RGB8_texture";
837 init
.gl_version
= "opengl es 2.0";
838 init
.bind_generates_resource
= true;
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
;
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());
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
,
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
) {
913 init
.extensions
= "GL_OES_EGL_image_external";
914 init
.gl_version
= "opengl es 2.0";
915 init
.bind_generates_resource
= true;
917 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_EXTERNAL_OES
, kNewServiceId
));
918 EXPECT_CALL(*gl_
, GenTextures(1, _
))
919 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
));
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
) {
931 init
.extensions
= "GL_OES_EGL_image_external";
932 init
.gl_version
= "opengl es 2.0";
933 init
.bind_generates_resource
= true;
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_
);
944 GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES
, result
->GetData()))
948 cmd
.Init(GL_TEXTURE_BINDING_EXTERNAL_OES
,
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
) {
961 init
.extensions
= "GL_OES_EGL_image_external";
962 init
.gl_version
= "opengl es 2.0";
963 init
.bind_generates_resource
= true;
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
) {
978 init
.extensions
= "GL_OES_EGL_image_external";
979 init
.gl_version
= "opengl es 2.0";
980 init
.bind_generates_resource
= true;
982 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
986 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
));
989 TexParameteri(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
));
993 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
));
997 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
));
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
) {
1026 init
.extensions
= "GL_OES_EGL_image_external";
1027 init
.gl_version
= "opengl es 2.0";
1028 init
.bind_generates_resource
= true;
1030 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
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
) {
1058 init
.extensions
= "GL_OES_EGL_image_external";
1059 init
.gl_version
= "opengl es 2.0";
1060 init
.bind_generates_resource
= true;
1063 GLenum target
= GL_TEXTURE_EXTERNAL_OES
;
1065 GLenum internal_format
= GL_RGBA
;
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
);
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
) {
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());
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
) {
1107 init
.bind_generates_resource
= true;
1111 cmd1
.Init(GL_TEXTURE_2D
, 0);
1113 *gl_
, BindTexture(GL_TEXTURE_2D
, TestHelper::kServiceDefaultTexture2dId
));
1114 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1115 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1118 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, 0);
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
) {
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());
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());
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());
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
) {
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());
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());
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());
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
) {
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
,
1206 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1207 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
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
,
1223 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1224 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1228 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameteriv
) {
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
,
1245 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1246 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
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
,
1262 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1263 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1267 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexImage2D
) {
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());
1278 cmd2
.Init(GL_TEXTURE_2D
,
1286 kSharedMemoryOffset
);
1287 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1288 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1291 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexSubImage2D
) {
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());
1302 cmd2
.Init(GL_TEXTURE_2D
,
1311 kSharedMemoryOffset
,
1313 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1314 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1317 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleBindTexture
) {
1319 init
.extensions
= "GL_ARB_texture_rectangle";
1320 init
.bind_generates_resource
= true;
1322 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_RECTANGLE_ARB
, kNewServiceId
));
1323 EXPECT_CALL(*gl_
, GenTextures(1, _
))
1324 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
));
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
) {
1336 init
.extensions
= "GL_ARB_texture_rectangle";
1337 init
.bind_generates_resource
= true;
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_
);
1349 GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB
, result
->GetData()))
1353 cmd
.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB
,
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
) {
1366 init
.extensions
= "GL_ARB_texture_rectangle";
1367 init
.bind_generates_resource
= true;
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
) {
1382 init
.extensions
= "GL_ARB_texture_rectangle";
1383 init
.bind_generates_resource
= true;
1387 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1391 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
));
1394 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
));
1398 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
));
1402 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
));
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
) {
1430 init
.extensions
= "GL_ARB_texture_rectangle";
1431 init
.bind_generates_resource
= true;
1435 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
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
) {
1462 init
.extensions
= "GL_ARB_texture_rectangle";
1463 init
.bind_generates_resource
= true;
1466 GLenum target
= GL_TEXTURE_RECTANGLE_ARB
;
1468 GLenum internal_format
= GL_RGBA
;
1471 GLenum format
= GL_RGBA
;
1472 GLenum type
= GL_UNSIGNED_BYTE
;
1474 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1475 ASSERT_TRUE(GetTexture(client_texture_id_
) != NULL
);
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
) {
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;
1501 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1503 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1504 SetupClearTextureExpectations(kServiceTextureId
,
1515 TexSubImage2D(GL_TEXTURE_2D
,
1523 shared_memory_address_
))
1525 .RetiresOnSaturation();
1527 cmd
.Init(GL_TEXTURE_2D
,
1536 kSharedMemoryOffset
,
1538 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1539 // Test if we call it again it does not clear.
1541 TexSubImage2D(GL_TEXTURE_2D
,
1549 shared_memory_address_
))
1551 .RetiresOnSaturation();
1552 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1555 TEST_P(GLES2DecoderTest
, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData
) {
1556 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1558 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1559 DoTexImage2D(GL_TEXTURE_2D
,
1568 kSharedMemoryOffset
);
1570 TexSubImage2D(GL_TEXTURE_2D
,
1578 shared_memory_address_
))
1580 .RetiresOnSaturation();
1582 cmd
.Init(GL_TEXTURE_2D
,
1591 kSharedMemoryOffset
,
1593 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1594 // Test if we call it again it does not clear.
1596 TexSubImage2D(GL_TEXTURE_2D
,
1604 shared_memory_address_
))
1606 .RetiresOnSaturation();
1607 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
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
));
1618 init
.bind_generates_resource
= true;
1619 InitDecoderWithCommandLine(init
, &command_line
);
1620 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
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.
1629 GL_TEXTURE_2D
, 0, 0, 0, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
1631 .RetiresOnSaturation();
1632 cmds::TexImage2D cmd
;
1633 cmd
.Init(GL_TEXTURE_2D
,
1641 kSharedMemoryOffset
);
1642 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1646 TexSubImage2D(GL_TEXTURE_2D
,
1654 shared_memory_address_
))
1656 .RetiresOnSaturation();
1658 cmd
.Init(GL_TEXTURE_2D
,
1667 kSharedMemoryOffset
,
1669 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1670 // Test if we call it again it does not clear.
1672 TexSubImage2D(GL_TEXTURE_2D
,
1680 shared_memory_address_
))
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
,
1698 kSharedMemoryOffset
);
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
,
1717 TexSubImage2D(GL_TEXTURE_2D
,
1725 shared_memory_address_
))
1727 .RetiresOnSaturation();
1729 cmd
.Init(GL_TEXTURE_2D
,
1738 kSharedMemoryOffset
,
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))
1756 .RetiresOnSaturation();
1757 EXPECT_CALL(*gl_
, GetError())
1758 .WillOnce(Return(GL_NO_ERROR
))
1759 .RetiresOnSaturation();
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
);
1770 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1772 SetupClearTextureExpectations(kServiceTextureId
,
1782 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 1, 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
))
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
) {
1818 init
.extensions
= "GL_EXT_texture_compression_s3tc";
1819 init
.bind_generates_resource
= true;
1822 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1823 EXPECT_CALL(*gl_
, GetError())
1824 .WillOnce(Return(GL_NO_ERROR
))
1825 .RetiresOnSaturation();
1828 CompressedTexImage2D(
1829 GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, 4, 4, 0, 8, _
))
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
,
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
);
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
);
1865 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
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.
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
))
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
);
1947 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
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.
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
);
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
) {
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;
2053 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2054 // Check trying to upload data fails.
2056 tex_cmd
.Init(GL_TEXTURE_2D
,
2064 kSharedMemoryOffset
);
2065 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
2066 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2068 tex_cmd
.Init(GL_TEXTURE_2D
,
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
,
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
,
2103 kSharedMemoryOffset
,
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
) {
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;
2131 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2132 DoTexImage2D(GL_TEXTURE_2D
,
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
);
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
);
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.
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());
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
);
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
);
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
{
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
,
2296 gfx::OverlayTransform
,
2298 const gfx::RectF
&));
2301 virtual ~MockGLImage() {}
2304 TEST_P(GLES2DecoderWithShaderTest
, UseTexImage
) {
2305 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2306 DoTexImage2D(GL_TEXTURE_2D
,
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
))
2330 .WillOnce(Return(true))
2331 .RetiresOnSaturation();
2332 EXPECT_CALL(*image
.get(), GetSize())
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
))
2360 .RetiresOnSaturation();
2362 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2363 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2364 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
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
))
2376 .RetiresOnSaturation();
2377 // Image will be 'in use' as long as bound to a framebuffer.
2378 EXPECT_CALL(*image
.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2380 FramebufferTexture2DEXT(GL_FRAMEBUFFER
,
2381 GL_COLOR_ATTACHMENT0
,
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
,
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();
2405 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
2406 GL_COLOR_ATTACHMENT0
,
2408 kServiceRenderbufferId
))
2410 .RetiresOnSaturation();
2411 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2412 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
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
,
2425 client_renderbuffer_id_
);
2426 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbrb_cmd
));
2429 TEST_P(GLES2DecoderManualInitTest
, DrawWithGLImageExternal
) {
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;
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
,
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();
2462 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
2463 SetupExpectationsForApplyingDefaultDirtyState();
2464 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref
));
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();
2486 cmd
.Init(GL_TRIANGLES
,
2487 kValidIndexRangeCount
,
2489 kValidIndexRangeStart
* 2);
2490 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2491 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2494 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatOnGLES2
) {
2496 init
.extensions
= "GL_OES_texture_float";
2497 init
.gl_version
= "opengl es 2.0";
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);
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
,
2517 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatOnGLES3
) {
2519 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
2520 init
.gl_version
= "opengl es 3.0";
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);
2526 GL_TEXTURE_2D
, 0, GL_RGBA32F
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
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
,
2542 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DFloatOnGLES3
) {
2544 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
2545 init
.gl_version
= "opengl es 3.0";
2547 const int kWidth
= 8;
2548 const int kHeight
= 4;
2549 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2550 DoTexImage2D(GL_TEXTURE_2D
,
2561 TexImage2D(GL_TEXTURE_2D
,
2569 shared_memory_address_
))
2571 .RetiresOnSaturation();
2573 cmd
.Init(GL_TEXTURE_2D
,
2582 kSharedMemoryOffset
,
2584 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2585 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2588 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DFloatDoesClearOnGLES3
) {
2590 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
2591 init
.gl_version
= "opengl es 3.0";
2593 const int kWidth
= 8;
2594 const int kHeight
= 4;
2595 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2596 DoTexImage2D(GL_TEXTURE_2D
,
2606 SetupClearTextureExpectations(kServiceTextureId
,
2617 TexSubImage2D(GL_TEXTURE_2D
,
2625 shared_memory_address_
))
2627 .RetiresOnSaturation();
2629 cmd
.Init(GL_TEXTURE_2D
,
2638 kSharedMemoryOffset
,
2640 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2641 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2644 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatConvertsFormatDesktop
) {
2646 init
.extensions
= "GL_ARB_texture_float";
2648 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
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
,
2663 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2674 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2684 GL_LUMINANCE32F_ARB
);
2685 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2696 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2706 GL_LUMINANCE_ALPHA32F_ARB
);
2709 class GLES2DecoderCompressedFormatsTest
: public GLES2DecoderManualInitTest
{
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
) {
2722 void CheckFormats(const char* extension
, const GLenum
* formats
, int count
) {
2724 init
.extensions
= extension
;
2725 init
.bind_generates_resource
= true;
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_
);
2739 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
2740 cmd
.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
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());
2750 cmd
.Init(GL_COMPRESSED_TEXTURE_FORMATS
,
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
) {
2758 ValueInArray(formats
[i
], result
->GetData(), result
->GetNumResults()));
2761 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2765 INSTANTIATE_TEST_CASE_P(Service
,
2766 GLES2DecoderCompressedFormatsTest
,
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
) {
2796 init
.bind_generates_resource
= true;
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_
);
2810 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
2811 cmd
.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
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());
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) {
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