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 CommandLine
command_line(0, NULL
);
130 command_line
.AppendSwitchASCII(
131 switches::kGpuDriverBugWorkarounds
,
132 base::IntToString(gpu::SET_TEXTURE_FILTER_BEFORE_GENERATING_MIPMAP
));
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
);
141 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
142 SetupClearTextureExpectations(kServiceTextureId
,
155 GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_NEAREST
))
157 .RetiresOnSaturation();
158 EXPECT_CALL(*gl_
, GenerateMipmapEXT(GL_TEXTURE_2D
));
162 GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_LINEAR
))
164 .RetiresOnSaturation();
165 EXPECT_CALL(*gl_
, GetError())
166 .WillOnce(Return(GL_NO_ERROR
))
167 .WillOnce(Return(GL_NO_ERROR
))
168 .RetiresOnSaturation();
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);
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);
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
,
209 kSharedMemoryOffset
);
211 TexSubImage2D(GL_TEXTURE_2D
,
219 shared_memory_address_
))
221 .RetiresOnSaturation();
223 cmd
.Init(GL_TEXTURE_2D
,
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
,
253 cmd
.Init(GL_TEXTURE0
,
264 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
265 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
266 cmd
.Init(GL_TEXTURE_2D
,
277 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
278 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
279 cmd
.Init(GL_TEXTURE_2D
,
290 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
291 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
292 cmd
.Init(GL_TEXTURE_2D
,
303 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
304 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
305 cmd
.Init(GL_TEXTURE_2D
,
316 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
317 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
318 cmd
.Init(GL_TEXTURE_2D
,
329 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
330 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
331 cmd
.Init(GL_TEXTURE_2D
,
342 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
343 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
344 cmd
.Init(GL_TEXTURE_2D
,
355 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
356 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
357 cmd
.Init(GL_TEXTURE_2D
,
368 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
369 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
370 cmd
.Init(GL_TEXTURE_2D
,
381 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
382 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
383 cmd
.Init(GL_TEXTURE_2D
,
390 GL_UNSIGNED_SHORT_4_4_4_4
,
394 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
395 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
396 cmd
.Init(GL_TEXTURE_2D
,
404 kInvalidSharedMemoryId
,
407 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
408 cmd
.Init(GL_TEXTURE_2D
,
417 kInvalidSharedMemoryOffset
,
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
,
435 kSharedMemoryOffset
);
437 CopyTexSubImage2D(GL_TEXTURE_2D
, 1, 0, 0, 0, 0, kWidth
, kHeight
))
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
,
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
) {
493 TexImage2D(GL_TEXTURE_2D
,
503 .RetiresOnSaturation();
504 cmd
.Init(GL_TEXTURE_2D
,
512 kSharedMemoryOffset
);
514 SetupClearTextureExpectations(kServiceTextureId
,
524 cmd
.Init(GL_TEXTURE_2D
,
534 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
536 TexSubImage2D(GL_TEXTURE_2D
,
544 shared_memory_address_
))
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.
551 cmd2
.Init(GL_TEXTURE_2D
,
562 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
566 TEST_P(GLES2DecoderTest
, TexImage2DGLError
) {
567 GLenum target
= GL_TEXTURE_2D
;
569 GLenum internal_format
= GL_RGBA
;
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();
596 .RetiresOnSaturation();
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
;
615 GLenum internal_format
= GL_RGBA
;
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();
631 target
, level
, internal_format
, 0, 0, width
, height
, border
))
633 .RetiresOnSaturation();
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
) {
643 init
.extensions
= "GL_EXT_texture_compression_s3tc";
644 init
.gl_version
= "3.0";
645 init
.bind_generates_resource
= true;
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
,
657 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
658 CompressedTexSubImage2DBucket cmd2
;
659 cmd2
.Init(GL_TEXTURE_2D
,
665 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
667 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
672 struct S3TCTestData
{
677 } // anonymous namespace.
679 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DS3TC
) {
681 init
.extensions
= "GL_EXT_texture_compression_s3tc";
682 init
.gl_version
= "3.0";
683 init
.bind_generates_resource
= true;
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
;
710 DoCompressedTexImage2D(
711 GL_TEXTURE_2D
, 0, test
.format
, 2, 4, 0, test
.block_size
, kBucketId
);
712 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
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());
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());
763 DoCompressedTexImage2D(GL_TEXTURE_2D
,
769 test
.block_size
* 4 * 4,
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
);
809 CompressedTexSubImage2D(GL_TEXTURE_2D
,
819 .RetiresOnSaturation();
820 sub_cmd
.Init(GL_TEXTURE_2D
,
828 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
829 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
837 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DETC1
) {
839 init
.extensions
= "GL_OES_compressed_ETC1_RGB8_texture";
840 init
.gl_version
= "opengl es 2.0";
841 init
.bind_generates_resource
= true;
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
;
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());
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
,
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
) {
916 init
.extensions
= "GL_OES_EGL_image_external";
917 init
.gl_version
= "opengl es 2.0";
918 init
.bind_generates_resource
= true;
920 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_EXTERNAL_OES
, kNewServiceId
));
921 EXPECT_CALL(*gl_
, GenTextures(1, _
))
922 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
));
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
) {
934 init
.extensions
= "GL_OES_EGL_image_external";
935 init
.gl_version
= "opengl es 2.0";
936 init
.bind_generates_resource
= true;
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_
);
947 GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES
, result
->GetData()))
951 cmd
.Init(GL_TEXTURE_BINDING_EXTERNAL_OES
,
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
) {
964 init
.extensions
= "GL_OES_EGL_image_external";
965 init
.gl_version
= "opengl es 2.0";
966 init
.bind_generates_resource
= true;
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
) {
981 init
.extensions
= "GL_OES_EGL_image_external";
982 init
.gl_version
= "opengl es 2.0";
983 init
.bind_generates_resource
= true;
985 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
989 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
));
992 TexParameteri(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
));
996 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
));
1000 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
));
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
) {
1029 init
.extensions
= "GL_OES_EGL_image_external";
1030 init
.gl_version
= "opengl es 2.0";
1031 init
.bind_generates_resource
= true;
1033 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
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
) {
1061 init
.extensions
= "GL_OES_EGL_image_external";
1062 init
.gl_version
= "opengl es 2.0";
1063 init
.bind_generates_resource
= true;
1066 GLenum target
= GL_TEXTURE_EXTERNAL_OES
;
1068 GLenum internal_format
= GL_RGBA
;
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
);
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
) {
1093 init
.gl_version
= "3.0";
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());
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
) {
1111 init
.gl_version
= "3.0";
1112 init
.bind_generates_resource
= true;
1116 cmd1
.Init(GL_TEXTURE_2D
, 0);
1118 *gl_
, BindTexture(GL_TEXTURE_2D
, TestHelper::kServiceDefaultTexture2dId
));
1119 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1120 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1123 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, 0);
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
) {
1134 init
.gl_version
= "3.0";
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());
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());
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());
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
) {
1166 init
.gl_version
= "3.0";
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());
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());
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());
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
) {
1198 init
.gl_version
= "3.0";
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
,
1214 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1215 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
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
,
1231 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1232 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1236 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameteriv
) {
1238 init
.gl_version
= "3.0";
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
,
1254 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1255 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
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
,
1271 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1272 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1276 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexImage2D
) {
1278 init
.gl_version
= "3.0";
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());
1288 cmd2
.Init(GL_TEXTURE_2D
,
1296 kSharedMemoryOffset
);
1297 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1298 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1301 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexSubImage2D
) {
1303 init
.gl_version
= "3.0";
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());
1313 cmd2
.Init(GL_TEXTURE_2D
,
1322 kSharedMemoryOffset
,
1324 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1325 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1328 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleBindTexture
) {
1330 init
.extensions
= "GL_ARB_texture_rectangle";
1331 init
.gl_version
= "3.0";
1332 init
.bind_generates_resource
= true;
1334 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_RECTANGLE_ARB
, kNewServiceId
));
1335 EXPECT_CALL(*gl_
, GenTextures(1, _
))
1336 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
));
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
) {
1348 init
.extensions
= "GL_ARB_texture_rectangle";
1349 init
.gl_version
= "3.0";
1350 init
.bind_generates_resource
= true;
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_
);
1362 GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB
, result
->GetData()))
1366 cmd
.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB
,
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
) {
1379 init
.extensions
= "GL_ARB_texture_rectangle";
1380 init
.gl_version
= "3.0";
1381 init
.bind_generates_resource
= true;
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
) {
1396 init
.extensions
= "GL_ARB_texture_rectangle";
1397 init
.gl_version
= "3.0";
1398 init
.bind_generates_resource
= true;
1402 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1406 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
));
1409 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
));
1413 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
));
1417 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
));
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
) {
1445 init
.extensions
= "GL_ARB_texture_rectangle";
1446 init
.gl_version
= "3.0";
1447 init
.bind_generates_resource
= true;
1451 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
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
) {
1478 init
.extensions
= "GL_ARB_texture_rectangle";
1479 init
.gl_version
= "3.0";
1480 init
.bind_generates_resource
= true;
1483 GLenum target
= GL_TEXTURE_RECTANGLE_ARB
;
1485 GLenum internal_format
= GL_RGBA
;
1488 GLenum format
= GL_RGBA
;
1489 GLenum type
= GL_UNSIGNED_BYTE
;
1491 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1492 ASSERT_TRUE(GetTexture(client_texture_id_
) != NULL
);
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
) {
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;
1518 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1520 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1521 SetupClearTextureExpectations(kServiceTextureId
,
1532 TexSubImage2D(GL_TEXTURE_2D
,
1540 shared_memory_address_
))
1542 .RetiresOnSaturation();
1544 cmd
.Init(GL_TEXTURE_2D
,
1553 kSharedMemoryOffset
,
1555 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1556 // Test if we call it again it does not clear.
1558 TexSubImage2D(GL_TEXTURE_2D
,
1566 shared_memory_address_
))
1568 .RetiresOnSaturation();
1569 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1572 TEST_P(GLES2DecoderTest
, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData
) {
1573 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1575 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1576 DoTexImage2D(GL_TEXTURE_2D
,
1585 kSharedMemoryOffset
);
1587 TexSubImage2D(GL_TEXTURE_2D
,
1595 shared_memory_address_
))
1597 .RetiresOnSaturation();
1599 cmd
.Init(GL_TEXTURE_2D
,
1608 kSharedMemoryOffset
,
1610 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1611 // Test if we call it again it does not clear.
1613 TexSubImage2D(GL_TEXTURE_2D
,
1621 shared_memory_address_
))
1623 .RetiresOnSaturation();
1624 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
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
));
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
);
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.
1647 GL_TEXTURE_2D
, 0, 0, 0, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
1649 .RetiresOnSaturation();
1650 cmds::TexImage2D cmd
;
1651 cmd
.Init(GL_TEXTURE_2D
,
1659 kSharedMemoryOffset
);
1660 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1664 TexSubImage2D(GL_TEXTURE_2D
,
1672 shared_memory_address_
))
1674 .RetiresOnSaturation();
1676 cmd
.Init(GL_TEXTURE_2D
,
1685 kSharedMemoryOffset
,
1687 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1688 // Test if we call it again it does not clear.
1690 TexSubImage2D(GL_TEXTURE_2D
,
1698 shared_memory_address_
))
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
,
1716 kSharedMemoryOffset
);
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
,
1735 TexSubImage2D(GL_TEXTURE_2D
,
1743 shared_memory_address_
))
1745 .RetiresOnSaturation();
1747 cmd
.Init(GL_TEXTURE_2D
,
1756 kSharedMemoryOffset
,
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))
1774 .RetiresOnSaturation();
1775 EXPECT_CALL(*gl_
, GetError())
1776 .WillOnce(Return(GL_NO_ERROR
))
1777 .RetiresOnSaturation();
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
);
1788 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1790 SetupClearTextureExpectations(kServiceTextureId
,
1800 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 1, 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
) {
1810 init
.extensions
= "GL_EXT_texture_compression_s3tc";
1811 init
.gl_version
= "3.0";
1812 init
.bind_generates_resource
= true;
1815 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1816 EXPECT_CALL(*gl_
, GetError())
1817 .WillOnce(Return(GL_NO_ERROR
))
1818 .RetiresOnSaturation();
1821 CompressedTexImage2D(
1822 GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, 4, 4, 0, 8, _
))
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
,
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
);
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
);
1858 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
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.
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
))
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
);
1940 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
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.
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
);
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
) {
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;
2046 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2047 // Check trying to upload data fails.
2049 tex_cmd
.Init(GL_TEXTURE_2D
,
2057 kSharedMemoryOffset
);
2058 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
2059 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2061 tex_cmd
.Init(GL_TEXTURE_2D
,
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
,
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
,
2096 kSharedMemoryOffset
,
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
) {
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;
2124 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2125 DoTexImage2D(GL_TEXTURE_2D
,
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
);
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
);
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.
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());
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
);
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
);
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
{
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
,
2288 gfx::OverlayTransform
,
2290 const gfx::RectF
&));
2293 virtual ~MockGLImage() {}
2296 TEST_P(GLES2DecoderWithShaderTest
, UseTexImage
) {
2297 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2298 DoTexImage2D(GL_TEXTURE_2D
,
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
))
2322 .WillOnce(Return(true))
2323 .RetiresOnSaturation();
2324 EXPECT_CALL(*image
.get(), GetSize())
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
))
2352 .RetiresOnSaturation();
2354 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2355 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2356 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
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
))
2368 .RetiresOnSaturation();
2369 // Image will be 'in use' as long as bound to a framebuffer.
2370 EXPECT_CALL(*image
.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2372 FramebufferTexture2DEXT(GL_FRAMEBUFFER
,
2373 GL_COLOR_ATTACHMENT0
,
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
,
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();
2397 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
2398 GL_COLOR_ATTACHMENT0
,
2400 kServiceRenderbufferId
))
2402 .RetiresOnSaturation();
2403 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2404 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
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
,
2417 client_renderbuffer_id_
);
2418 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbrb_cmd
));
2421 TEST_P(GLES2DecoderManualInitTest
, DrawWithGLImageExternal
) {
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;
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
,
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();
2454 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
2455 SetupExpectationsForApplyingDefaultDirtyState();
2456 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref
));
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();
2478 cmd
.Init(GL_TRIANGLES
,
2479 kValidIndexRangeCount
,
2481 kValidIndexRangeStart
* 2);
2482 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2483 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2486 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatOnGLES2
) {
2488 init
.extensions
= "GL_OES_texture_float";
2489 init
.gl_version
= "opengl es 2.0";
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);
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
,
2509 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatOnGLES3
) {
2511 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
2512 init
.gl_version
= "opengl es 3.0";
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);
2518 GL_TEXTURE_2D
, 0, GL_RGBA32F
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
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
,
2534 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DFloatOnGLES3
) {
2536 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
2537 init
.gl_version
= "opengl es 3.0";
2539 const int kWidth
= 8;
2540 const int kHeight
= 4;
2541 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2542 DoTexImage2D(GL_TEXTURE_2D
,
2553 TexImage2D(GL_TEXTURE_2D
,
2561 shared_memory_address_
))
2563 .RetiresOnSaturation();
2565 cmd
.Init(GL_TEXTURE_2D
,
2574 kSharedMemoryOffset
,
2576 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2577 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2580 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DFloatDoesClearOnGLES3
) {
2582 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
2583 init
.gl_version
= "opengl es 3.0";
2585 const int kWidth
= 8;
2586 const int kHeight
= 4;
2587 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2588 DoTexImage2D(GL_TEXTURE_2D
,
2598 SetupClearTextureExpectations(kServiceTextureId
,
2609 TexSubImage2D(GL_TEXTURE_2D
,
2617 shared_memory_address_
))
2619 .RetiresOnSaturation();
2621 cmd
.Init(GL_TEXTURE_2D
,
2630 kSharedMemoryOffset
,
2632 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2633 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2636 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatConvertsFormatDesktop
) {
2638 init
.extensions
= "GL_ARB_texture_float";
2639 init
.gl_version
= "2.1";
2641 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
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
,
2656 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2667 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2677 GL_LUMINANCE32F_ARB
);
2678 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2689 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2699 GL_LUMINANCE_ALPHA32F_ARB
);
2702 class GLES2DecoderCompressedFormatsTest
: public GLES2DecoderManualInitTest
{
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
) {
2715 void CheckFormats(const char* extension
, const GLenum
* formats
, int count
) {
2717 init
.extensions
= extension
;
2718 init
.gl_version
= "3.0";
2719 init
.bind_generates_resource
= true;
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_
);
2733 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
2734 cmd
.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
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());
2744 cmd
.Init(GL_COMPRESSED_TEXTURE_FORMATS
,
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
) {
2752 ValueInArray(formats
[i
], result
->GetData(), result
->GetNumResults()));
2755 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2759 INSTANTIATE_TEST_CASE_P(Service
,
2760 GLES2DecoderCompressedFormatsTest
,
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
) {
2790 init
.gl_version
= "3.0";
2791 init
.bind_generates_resource
= true;
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_
);
2805 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
2806 cmd
.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
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());
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) {
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