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_implementation.h"
29 #include "ui/gl/gl_mock.h"
30 #include "ui/gl/gl_surface_stub.h"
32 #if !defined(GL_DEPTH24_STENCIL8)
33 #define GL_DEPTH24_STENCIL8 0x88F0
36 using ::gfx::MockGLInterface
;
38 using ::testing::DoAll
;
39 using ::testing::InSequence
;
40 using ::testing::Invoke
;
41 using ::testing::MatcherCast
;
42 using ::testing::Mock
;
43 using ::testing::Pointee
;
44 using ::testing::Return
;
45 using ::testing::SaveArg
;
46 using ::testing::SetArrayArgument
;
47 using ::testing::SetArgumentPointee
;
48 using ::testing::SetArgPointee
;
49 using ::testing::StrEq
;
50 using ::testing::StrictMock
;
57 TEST_P(GLES2DecoderTest
, GenerateMipmapWrongFormatsFails
) {
58 EXPECT_CALL(*gl_
, GenerateMipmapEXT(_
)).Times(0);
59 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
61 GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 17, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
63 cmd
.Init(GL_TEXTURE_2D
);
64 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
65 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
68 TEST_P(GLES2DecoderTest
, GenerateMipmapHandlesOutOfMemory
) {
69 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
70 TextureManager
* manager
= group().texture_manager();
71 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
72 ASSERT_TRUE(texture_ref
!= NULL
);
73 Texture
* texture
= texture_ref
->texture();
76 EXPECT_FALSE(texture
->GetLevelSize(GL_TEXTURE_2D
, 2, &width
, &height
));
77 DoTexImage2D(GL_TEXTURE_2D
,
87 EXPECT_CALL(*gl_
, GenerateMipmapEXT(GL_TEXTURE_2D
)).Times(1);
88 EXPECT_CALL(*gl_
, GetError())
89 .WillOnce(Return(GL_NO_ERROR
))
90 .WillOnce(Return(GL_OUT_OF_MEMORY
))
91 .RetiresOnSaturation();
93 cmd
.Init(GL_TEXTURE_2D
);
94 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
95 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
96 EXPECT_FALSE(texture
->GetLevelSize(GL_TEXTURE_2D
, 2, &width
, &height
));
99 TEST_P(GLES2DecoderTest
, GenerateMipmapClearsUnclearedTexture
) {
100 EXPECT_CALL(*gl_
, GenerateMipmapEXT(_
)).Times(0);
101 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
103 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
104 SetupClearTextureExpectations(kServiceTextureId
,
114 EXPECT_CALL(*gl_
, GenerateMipmapEXT(GL_TEXTURE_2D
));
115 EXPECT_CALL(*gl_
, GetError())
116 .WillOnce(Return(GL_NO_ERROR
))
117 .WillOnce(Return(GL_NO_ERROR
))
118 .RetiresOnSaturation();
120 cmd
.Init(GL_TEXTURE_2D
);
121 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
122 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
125 // Same as GenerateMipmapClearsUnclearedTexture, but with workaround
126 // |set_texture_filters_before_generating_mipmap|.
127 TEST_P(GLES2DecoderManualInitTest
, SetTextureFiltersBeforeGenerateMipmap
) {
128 CommandLine
command_line(0, NULL
);
129 command_line
.AppendSwitchASCII(
130 switches::kGpuDriverBugWorkarounds
,
131 base::IntToString(gpu::SET_TEXTURE_FILTER_BEFORE_GENERATING_MIPMAP
));
133 init
.gl_version
= "3.0";
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
.gl_version
= "3.0";
644 init
.bind_generates_resource
= true;
647 const uint32 kBadBucketId
= 123;
648 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
649 CompressedTexImage2DBucket cmd
;
650 cmd
.Init(GL_TEXTURE_2D
,
652 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
656 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
657 CompressedTexSubImage2DBucket cmd2
;
658 cmd2
.Init(GL_TEXTURE_2D
,
664 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
666 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
671 struct S3TCTestData
{
676 } // anonymous namespace.
678 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DS3TC
) {
680 init
.extensions
= "GL_EXT_texture_compression_s3tc";
681 init
.gl_version
= "3.0";
682 init
.bind_generates_resource
= true;
684 const uint32 kBucketId
= 123;
685 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
686 ASSERT_TRUE(bucket
!= NULL
);
688 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
690 static const S3TCTestData test_data
[] = {
692 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, 8,
695 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, 8,
698 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, 16,
701 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, 16,
705 for (size_t ii
= 0; ii
< arraysize(test_data
); ++ii
) {
706 const S3TCTestData
& test
= test_data
[ii
];
707 CompressedTexImage2DBucket cmd
;
709 DoCompressedTexImage2D(
710 GL_TEXTURE_2D
, 0, test
.format
, 2, 4, 0, test
.block_size
, kBucketId
);
711 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
714 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 5, 4, kBucketId
);
715 bucket
->SetSize(test
.block_size
* 2);
716 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
717 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
719 // test small height.
720 DoCompressedTexImage2D(
721 GL_TEXTURE_2D
, 0, test
.format
, 4, 2, 0, test
.block_size
, kBucketId
);
722 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
724 // test too bad height.
725 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 4, 5, kBucketId
);
726 bucket
->SetSize(test
.block_size
* 2);
727 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
728 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
730 // test small for level 0.
731 DoCompressedTexImage2D(
732 GL_TEXTURE_2D
, 0, test
.format
, 1, 1, 0, test
.block_size
, kBucketId
);
733 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
735 // test small for level 0.
736 DoCompressedTexImage2D(
737 GL_TEXTURE_2D
, 0, test
.format
, 2, 2, 0, test
.block_size
, kBucketId
);
738 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
740 // test size too large.
741 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 4, 4, kBucketId
);
742 bucket
->SetSize(test
.block_size
* 2);
743 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
744 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
746 // test size too small.
747 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 4, 4, kBucketId
);
748 bucket
->SetSize(test
.block_size
/ 2);
749 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
750 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
753 DoCompressedTexImage2D(
754 GL_TEXTURE_2D
, 0, test
.format
, 4, 4, 0, test
.block_size
, kBucketId
);
755 DoCompressedTexImage2D(
756 GL_TEXTURE_2D
, 1, test
.format
, 2, 2, 0, test
.block_size
, kBucketId
);
757 DoCompressedTexImage2D(
758 GL_TEXTURE_2D
, 2, test
.format
, 1, 1, 0, test
.block_size
, kBucketId
);
759 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
762 DoCompressedTexImage2D(GL_TEXTURE_2D
,
768 test
.block_size
* 4 * 4,
770 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
772 CompressedTexSubImage2DBucket sub_cmd
;
773 bucket
->SetSize(test
.block_size
);
774 // Test sub image bad xoffset
775 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 1, 0, 4, 4, test
.format
, kBucketId
);
776 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
777 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
779 // Test sub image bad yoffset
780 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 2, 4, 4, test
.format
, kBucketId
);
781 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
782 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
784 // Test sub image bad width
785 bucket
->SetSize(test
.block_size
* 2);
786 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 5, 4, test
.format
, kBucketId
);
787 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
788 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
790 // Test sub image bad height
791 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 4, 5, test
.format
, kBucketId
);
792 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
793 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
795 // Test sub image bad size
796 bucket
->SetSize(test
.block_size
+ 1);
797 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 4, 4, test
.format
, kBucketId
);
798 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
799 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
801 for (GLint yoffset
= 0; yoffset
<= 8; yoffset
+= 4) {
802 for (GLint xoffset
= 0; xoffset
<= 8; xoffset
+= 4) {
803 for (GLsizei height
= 4; height
<= 8; height
+= 4) {
804 for (GLsizei width
= 4; width
<= 8; width
+= 4) {
805 GLsizei size
= test
.block_size
* (width
/ 4) * (height
/ 4);
806 bucket
->SetSize(size
);
808 CompressedTexSubImage2D(GL_TEXTURE_2D
,
818 .RetiresOnSaturation();
819 sub_cmd
.Init(GL_TEXTURE_2D
,
827 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
828 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
836 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DETC1
) {
838 init
.extensions
= "GL_OES_compressed_ETC1_RGB8_texture";
839 init
.gl_version
= "opengl es 2.0";
840 init
.bind_generates_resource
= true;
842 const uint32 kBucketId
= 123;
843 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
844 ASSERT_TRUE(bucket
!= NULL
);
846 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
848 const GLenum kFormat
= GL_ETC1_RGB8_OES
;
849 const size_t kBlockSize
= 8;
851 CompressedTexImage2DBucket cmd
;
853 DoCompressedTexImage2D(GL_TEXTURE_2D
, 0, kFormat
, 4, 8, 0, 16, kBucketId
);
854 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
856 // test small height.
857 DoCompressedTexImage2D(GL_TEXTURE_2D
, 0, kFormat
, 8, 4, 0, 16, kBucketId
);
858 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
860 // test size too large.
861 cmd
.Init(GL_TEXTURE_2D
, 0, kFormat
, 4, 4, kBucketId
);
862 bucket
->SetSize(kBlockSize
* 2);
863 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
864 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
866 // test size too small.
867 cmd
.Init(GL_TEXTURE_2D
, 0, kFormat
, 4, 4, kBucketId
);
868 bucket
->SetSize(kBlockSize
/ 2);
869 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
870 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
873 DoCompressedTexImage2D(
874 GL_TEXTURE_2D
, 0, kFormat
, 16, 16, 0, kBlockSize
* 16, kBucketId
);
875 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
877 // Test CompressedTexSubImage not allowed
878 CompressedTexSubImage2DBucket sub_cmd
;
879 bucket
->SetSize(kBlockSize
);
880 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 4, 4, kFormat
, kBucketId
);
881 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
882 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
884 // Test TexSubImage not allowed for ETC1 compressed texture
885 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
886 ASSERT_TRUE(texture_ref
!= NULL
);
887 Texture
* texture
= texture_ref
->texture();
888 GLenum type
, internal_format
;
889 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
890 EXPECT_EQ(kFormat
, internal_format
);
891 TexSubImage2D texsub_cmd
;
892 texsub_cmd
.Init(GL_TEXTURE_2D
,
903 EXPECT_EQ(error::kNoError
, ExecuteCmd(texsub_cmd
));
904 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
906 // Test CopyTexSubImage not allowed for ETC1 compressed texture
907 CopyTexSubImage2D copy_cmd
;
908 copy_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 4, 4);
909 EXPECT_EQ(error::kNoError
, ExecuteCmd(copy_cmd
));
910 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
913 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalBindTexture
) {
915 init
.extensions
= "GL_OES_EGL_image_external";
916 init
.gl_version
= "opengl es 2.0";
917 init
.bind_generates_resource
= true;
919 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_EXTERNAL_OES
, kNewServiceId
));
920 EXPECT_CALL(*gl_
, GenTextures(1, _
))
921 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
));
923 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, kNewClientId
);
924 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
925 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
926 TextureRef
* texture_ref
= GetTexture(kNewClientId
);
927 EXPECT_TRUE(texture_ref
!= NULL
);
928 EXPECT_TRUE(texture_ref
->texture()->target() == GL_TEXTURE_EXTERNAL_OES
);
931 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalGetBinding
) {
933 init
.extensions
= "GL_OES_EGL_image_external";
934 init
.gl_version
= "opengl es 2.0";
935 init
.bind_generates_resource
= true;
937 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
939 EXPECT_CALL(*gl_
, GetError())
940 .WillOnce(Return(GL_NO_ERROR
))
941 .WillOnce(Return(GL_NO_ERROR
))
942 .RetiresOnSaturation();
943 typedef GetIntegerv::Result Result
;
944 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
946 GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES
, result
->GetData()))
950 cmd
.Init(GL_TEXTURE_BINDING_EXTERNAL_OES
,
952 shared_memory_offset_
);
953 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
954 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(
955 GL_TEXTURE_BINDING_EXTERNAL_OES
),
956 result
->GetNumResults());
957 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
958 EXPECT_EQ(client_texture_id_
, (uint32
)result
->GetData()[0]);
961 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTextureDefaults
) {
963 init
.extensions
= "GL_OES_EGL_image_external";
964 init
.gl_version
= "opengl es 2.0";
965 init
.bind_generates_resource
= true;
967 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
969 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
970 EXPECT_TRUE(texture_ref
!= NULL
);
971 Texture
* texture
= texture_ref
->texture();
972 EXPECT_TRUE(texture
->target() == GL_TEXTURE_EXTERNAL_OES
);
973 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
974 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
975 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
978 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTextureParam
) {
980 init
.extensions
= "GL_OES_EGL_image_external";
981 init
.gl_version
= "opengl es 2.0";
982 init
.bind_generates_resource
= true;
984 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
988 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
));
991 TexParameteri(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
));
995 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
));
999 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
));
1001 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1002 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1003 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1005 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
1006 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1007 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1009 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
1010 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1011 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1013 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
1014 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1015 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1017 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1018 EXPECT_TRUE(texture_ref
!= NULL
);
1019 Texture
* texture
= texture_ref
->texture();
1020 EXPECT_TRUE(texture
->target() == GL_TEXTURE_EXTERNAL_OES
);
1021 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1022 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1023 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1026 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTextureParamInvalid
) {
1028 init
.extensions
= "GL_OES_EGL_image_external";
1029 init
.gl_version
= "opengl es 2.0";
1030 init
.bind_generates_resource
= true;
1032 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1035 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
,
1036 GL_TEXTURE_MIN_FILTER
,
1037 GL_NEAREST_MIPMAP_NEAREST
);
1038 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1039 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1041 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
1042 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1043 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1045 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
1046 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1047 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1049 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1050 EXPECT_TRUE(texture_ref
!= NULL
);
1051 Texture
* texture
= texture_ref
->texture();
1052 EXPECT_TRUE(texture
->target() == GL_TEXTURE_EXTERNAL_OES
);
1053 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1054 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1055 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1058 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTexImage2DError
) {
1060 init
.extensions
= "GL_OES_EGL_image_external";
1061 init
.gl_version
= "opengl es 2.0";
1062 init
.bind_generates_resource
= true;
1065 GLenum target
= GL_TEXTURE_EXTERNAL_OES
;
1067 GLenum internal_format
= GL_RGBA
;
1070 GLenum format
= GL_RGBA
;
1071 GLenum type
= GL_UNSIGNED_BYTE
;
1072 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1073 ASSERT_TRUE(GetTexture(client_texture_id_
) != NULL
);
1083 kSharedMemoryOffset
);
1084 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1086 // TexImage2D is not allowed with GL_TEXTURE_EXTERNAL_OES targets.
1087 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1090 TEST_P(GLES2DecoderManualInitTest
, DefaultTextureZero
) {
1092 init
.gl_version
= "3.0";
1096 cmd1
.Init(GL_TEXTURE_2D
, 0);
1097 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1098 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1099 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1102 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1103 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1104 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1105 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1108 TEST_P(GLES2DecoderManualInitTest
, DefaultTextureBGR
) {
1110 init
.gl_version
= "3.0";
1111 init
.bind_generates_resource
= true;
1115 cmd1
.Init(GL_TEXTURE_2D
, 0);
1117 *gl_
, BindTexture(GL_TEXTURE_2D
, TestHelper::kServiceDefaultTexture2dId
));
1118 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1119 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1122 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1124 BindTexture(GL_TEXTURE_CUBE_MAP
,
1125 TestHelper::kServiceDefaultTextureCubemapId
));
1126 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1127 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1130 // Test that default texture 0 is immutable.
1131 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameterf
) {
1133 init
.gl_version
= "3.0";
1138 cmd1
.Init(GL_TEXTURE_2D
, 0);
1139 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1140 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1141 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1144 cmd2
.Init(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1145 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1146 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1151 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1152 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1153 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1154 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1157 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1158 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1159 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1163 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameteri
) {
1165 init
.gl_version
= "3.0";
1170 cmd1
.Init(GL_TEXTURE_2D
, 0);
1171 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1172 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1173 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1176 cmd2
.Init(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1177 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1178 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1183 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1184 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1185 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1186 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1189 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1190 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1191 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1195 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameterfv
) {
1197 init
.gl_version
= "3.0";
1202 cmd1
.Init(GL_TEXTURE_2D
, 0);
1203 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1204 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1205 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1207 GLfloat data
= GL_NEAREST
;
1208 TexParameterfvImmediate
& cmd2
=
1209 *GetImmediateAs
<TexParameterfvImmediate
>();
1210 cmd2
.Init(GL_TEXTURE_2D
,
1211 GL_TEXTURE_MAG_FILTER
,
1213 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1214 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1219 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1220 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1221 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1222 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1224 GLfloat data
= GL_NEAREST
;
1225 TexParameterfvImmediate
& cmd2
=
1226 *GetImmediateAs
<TexParameterfvImmediate
>();
1227 cmd2
.Init(GL_TEXTURE_CUBE_MAP
,
1228 GL_TEXTURE_MAG_FILTER
,
1230 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1231 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1235 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameteriv
) {
1237 init
.gl_version
= "3.0";
1242 cmd1
.Init(GL_TEXTURE_2D
, 0);
1243 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1244 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1245 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1247 GLfloat data
= GL_NEAREST
;
1248 TexParameterfvImmediate
& cmd2
=
1249 *GetImmediateAs
<TexParameterfvImmediate
>();
1250 cmd2
.Init(GL_TEXTURE_2D
,
1251 GL_TEXTURE_MAG_FILTER
,
1253 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1254 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1259 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1260 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1261 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1262 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1264 GLfloat data
= GL_NEAREST
;
1265 TexParameterfvImmediate
& cmd2
=
1266 *GetImmediateAs
<TexParameterfvImmediate
>();
1267 cmd2
.Init(GL_TEXTURE_CUBE_MAP
,
1268 GL_TEXTURE_MAG_FILTER
,
1270 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1271 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1275 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexImage2D
) {
1277 init
.gl_version
= "3.0";
1281 cmd1
.Init(GL_TEXTURE_2D
, 0);
1282 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1283 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1284 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1287 cmd2
.Init(GL_TEXTURE_2D
,
1295 kSharedMemoryOffset
);
1296 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1297 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1300 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexSubImage2D
) {
1302 init
.gl_version
= "3.0";
1306 cmd1
.Init(GL_TEXTURE_2D
, 0);
1307 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1308 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1309 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1312 cmd2
.Init(GL_TEXTURE_2D
,
1321 kSharedMemoryOffset
,
1323 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1324 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1327 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleBindTexture
) {
1329 init
.extensions
= "GL_ARB_texture_rectangle";
1330 init
.gl_version
= "3.0";
1331 init
.bind_generates_resource
= true;
1333 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_RECTANGLE_ARB
, kNewServiceId
));
1334 EXPECT_CALL(*gl_
, GenTextures(1, _
))
1335 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
));
1337 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, kNewClientId
);
1338 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1339 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1340 Texture
* texture
= GetTexture(kNewClientId
)->texture();
1341 EXPECT_TRUE(texture
!= NULL
);
1342 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1345 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleGetBinding
) {
1347 init
.extensions
= "GL_ARB_texture_rectangle";
1348 init
.gl_version
= "3.0";
1349 init
.bind_generates_resource
= true;
1352 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1354 EXPECT_CALL(*gl_
, GetError())
1355 .WillOnce(Return(GL_NO_ERROR
))
1356 .WillOnce(Return(GL_NO_ERROR
))
1357 .RetiresOnSaturation();
1358 typedef GetIntegerv::Result Result
;
1359 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1361 GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB
, result
->GetData()))
1365 cmd
.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB
,
1367 shared_memory_offset_
);
1368 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1369 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(
1370 GL_TEXTURE_BINDING_RECTANGLE_ARB
),
1371 result
->GetNumResults());
1372 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1373 EXPECT_EQ(client_texture_id_
, (uint32
)result
->GetData()[0]);
1376 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTextureDefaults
) {
1378 init
.extensions
= "GL_ARB_texture_rectangle";
1379 init
.gl_version
= "3.0";
1380 init
.bind_generates_resource
= true;
1383 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1385 Texture
* texture
= GetTexture(client_texture_id_
)->texture();
1386 EXPECT_TRUE(texture
!= NULL
);
1387 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1388 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1389 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1390 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1393 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTextureParam
) {
1395 init
.extensions
= "GL_ARB_texture_rectangle";
1396 init
.gl_version
= "3.0";
1397 init
.bind_generates_resource
= true;
1401 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1405 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
));
1408 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
));
1412 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
));
1416 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
));
1418 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1419 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1420 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1422 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
1423 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1424 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1426 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
1427 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1428 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1430 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
1431 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1432 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1434 Texture
* texture
= GetTexture(client_texture_id_
)->texture();
1435 EXPECT_TRUE(texture
!= NULL
);
1436 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1437 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1438 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1439 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1442 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTextureParamInvalid
) {
1444 init
.extensions
= "GL_ARB_texture_rectangle";
1445 init
.gl_version
= "3.0";
1446 init
.bind_generates_resource
= true;
1450 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1453 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
,
1454 GL_TEXTURE_MIN_FILTER
,
1455 GL_NEAREST_MIPMAP_NEAREST
);
1456 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1457 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1459 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
1460 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1461 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1463 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
1464 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1465 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1467 Texture
* texture
= GetTexture(client_texture_id_
)->texture();
1468 EXPECT_TRUE(texture
!= NULL
);
1469 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1470 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1471 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1472 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1475 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTexImage2DError
) {
1477 init
.extensions
= "GL_ARB_texture_rectangle";
1478 init
.gl_version
= "3.0";
1479 init
.bind_generates_resource
= true;
1482 GLenum target
= GL_TEXTURE_RECTANGLE_ARB
;
1484 GLenum internal_format
= GL_RGBA
;
1487 GLenum format
= GL_RGBA
;
1488 GLenum type
= GL_UNSIGNED_BYTE
;
1490 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1491 ASSERT_TRUE(GetTexture(client_texture_id_
) != NULL
);
1501 kSharedMemoryOffset
);
1502 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1504 // TexImage2D is not allowed with GL_TEXTURE_RECTANGLE_ARB targets.
1505 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1508 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DClearsAfterTexImage2DNULL
) {
1510 init
.gl_version
= "opengl es 2.0";
1511 init
.has_alpha
= true;
1512 init
.has_depth
= true;
1513 init
.request_alpha
= true;
1514 init
.request_depth
= true;
1517 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1519 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1520 SetupClearTextureExpectations(kServiceTextureId
,
1531 TexSubImage2D(GL_TEXTURE_2D
,
1539 shared_memory_address_
))
1541 .RetiresOnSaturation();
1543 cmd
.Init(GL_TEXTURE_2D
,
1552 kSharedMemoryOffset
,
1554 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1555 // Test if we call it again it does not clear.
1557 TexSubImage2D(GL_TEXTURE_2D
,
1565 shared_memory_address_
))
1567 .RetiresOnSaturation();
1568 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1571 TEST_P(GLES2DecoderTest
, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData
) {
1572 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1574 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1575 DoTexImage2D(GL_TEXTURE_2D
,
1584 kSharedMemoryOffset
);
1586 TexSubImage2D(GL_TEXTURE_2D
,
1594 shared_memory_address_
))
1596 .RetiresOnSaturation();
1598 cmd
.Init(GL_TEXTURE_2D
,
1607 kSharedMemoryOffset
,
1609 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1610 // Test if we call it again it does not clear.
1612 TexSubImage2D(GL_TEXTURE_2D
,
1620 shared_memory_address_
))
1622 .RetiresOnSaturation();
1623 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1627 GLES2DecoderManualInitTest
,
1628 TexSubImage2DDoesNotClearAfterTexImage2DNULLThenDataWithTexImage2DIsFaster
) {
1629 CommandLine
command_line(0, NULL
);
1630 command_line
.AppendSwitchASCII(
1631 switches::kGpuDriverBugWorkarounds
,
1632 base::IntToString(gpu::TEXSUBIMAGE2D_FASTER_THAN_TEXIMAGE2D
));
1634 init
.gl_version
= "3.0";
1635 init
.bind_generates_resource
= true;
1636 InitDecoderWithCommandLine(init
, &command_line
);
1637 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1639 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1642 // Uses texSubimage internally because the above workaround is active and
1643 // the update is for the full size of the texture.
1646 GL_TEXTURE_2D
, 0, 0, 0, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
1648 .RetiresOnSaturation();
1649 cmds::TexImage2D cmd
;
1650 cmd
.Init(GL_TEXTURE_2D
,
1658 kSharedMemoryOffset
);
1659 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1663 TexSubImage2D(GL_TEXTURE_2D
,
1671 shared_memory_address_
))
1673 .RetiresOnSaturation();
1675 cmd
.Init(GL_TEXTURE_2D
,
1684 kSharedMemoryOffset
,
1686 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1687 // Test if we call it again it does not clear.
1689 TexSubImage2D(GL_TEXTURE_2D
,
1697 shared_memory_address_
))
1699 .RetiresOnSaturation();
1700 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1703 TEST_P(GLES2DecoderTest
, TexSubImage2DClearsAfterTexImage2DWithDataThenNULL
) {
1704 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1705 // Put in data (so it should be marked as cleared)
1706 DoTexImage2D(GL_TEXTURE_2D
,
1715 kSharedMemoryOffset
);
1719 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1720 // It won't actually call TexImage2D, just mark it as uncleared.
1721 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
1722 // Next call to TexSubImage2d should clear.
1723 SetupClearTextureExpectations(kServiceTextureId
,
1734 TexSubImage2D(GL_TEXTURE_2D
,
1742 shared_memory_address_
))
1744 .RetiresOnSaturation();
1746 cmd
.Init(GL_TEXTURE_2D
,
1755 kSharedMemoryOffset
,
1757 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1760 TEST_P(GLES2DecoderTest
, CopyTexImage2DMarksTextureAsCleared
) {
1761 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1763 TextureManager
* manager
= group().texture_manager();
1764 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
1765 ASSERT_TRUE(texture_ref
!= NULL
);
1766 Texture
* texture
= texture_ref
->texture();
1768 EXPECT_CALL(*gl_
, GetError())
1769 .WillOnce(Return(GL_NO_ERROR
))
1770 .RetiresOnSaturation();
1771 EXPECT_CALL(*gl_
, CopyTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 0, 0, 1, 1, 0))
1773 .RetiresOnSaturation();
1774 EXPECT_CALL(*gl_
, GetError())
1775 .WillOnce(Return(GL_NO_ERROR
))
1776 .RetiresOnSaturation();
1778 cmd
.Init(GL_TEXTURE_2D
, 0, GL_RGBA
, 0, 0, 1, 1);
1779 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1781 EXPECT_TRUE(texture
->SafeToRenderFrom());
1784 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DClearsUnclearedTexture
) {
1785 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1787 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1789 SetupClearTextureExpectations(kServiceTextureId
,
1799 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 1, 1))
1801 .RetiresOnSaturation();
1802 CopyTexSubImage2D cmd
;
1803 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 1, 1);
1804 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1807 TEST_P(GLES2DecoderManualInitTest
, CompressedImage2DMarksTextureAsCleared
) {
1809 init
.extensions
= "GL_EXT_texture_compression_s3tc";
1810 init
.gl_version
= "3.0";
1811 init
.bind_generates_resource
= true;
1814 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1815 EXPECT_CALL(*gl_
, GetError())
1816 .WillOnce(Return(GL_NO_ERROR
))
1817 .RetiresOnSaturation();
1820 CompressedTexImage2D(
1821 GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, 4, 4, 0, 8, _
))
1823 .RetiresOnSaturation();
1824 EXPECT_CALL(*gl_
, GetError())
1825 .WillOnce(Return(GL_NO_ERROR
))
1826 .RetiresOnSaturation();
1827 CompressedTexImage2D cmd
;
1828 cmd
.Init(GL_TEXTURE_2D
,
1830 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
1835 kSharedMemoryOffset
);
1836 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1837 TextureManager
* manager
= group().texture_manager();
1838 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
1839 EXPECT_TRUE(texture_ref
->texture()->SafeToRenderFrom());
1842 TEST_P(GLES2DecoderTest
, TextureUsageAngleExtNotEnabledByDefault
) {
1843 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1847 GL_TEXTURE_2D
, GL_TEXTURE_USAGE_ANGLE
, GL_FRAMEBUFFER_ATTACHMENT_ANGLE
);
1848 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1849 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1852 TEST_P(GLES2DecoderTest
, ProduceAndConsumeTextureCHROMIUM
) {
1853 Mailbox mailbox
= Mailbox::Generate();
1855 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1857 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1859 GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 4, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1860 TextureRef
* texture_ref
=
1861 group().texture_manager()->GetTexture(client_texture_id_
);
1862 ASSERT_TRUE(texture_ref
!= NULL
);
1863 Texture
* texture
= texture_ref
->texture();
1864 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
1866 ProduceTextureCHROMIUMImmediate
& produce_cmd
=
1867 *GetImmediateAs
<ProduceTextureCHROMIUMImmediate
>();
1868 produce_cmd
.Init(GL_TEXTURE_2D
, mailbox
.name
);
1869 EXPECT_EQ(error::kNoError
,
1870 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
1871 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1873 // Texture didn't change.
1877 GLenum internal_format
;
1879 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
));
1880 EXPECT_EQ(3, width
);
1881 EXPECT_EQ(1, height
);
1882 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
1883 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
1884 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
1886 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
));
1887 EXPECT_EQ(2, width
);
1888 EXPECT_EQ(4, height
);
1889 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
1890 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
1891 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
1893 // Service ID has not changed.
1894 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
1896 // Create new texture for consume.
1897 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1898 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
1899 .RetiresOnSaturation();
1900 DoBindTexture(GL_TEXTURE_2D
, kNewClientId
, kNewServiceId
);
1902 // Assigns and binds original service size texture ID.
1903 EXPECT_CALL(*gl_
, DeleteTextures(1, _
)).Times(1).RetiresOnSaturation();
1904 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
1906 .RetiresOnSaturation();
1908 ConsumeTextureCHROMIUMImmediate
& consume_cmd
=
1909 *GetImmediateAs
<ConsumeTextureCHROMIUMImmediate
>();
1910 consume_cmd
.Init(GL_TEXTURE_2D
, mailbox
.name
);
1911 EXPECT_EQ(error::kNoError
,
1912 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
1913 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1915 // Texture is redefined.
1916 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
));
1917 EXPECT_EQ(3, width
);
1918 EXPECT_EQ(1, height
);
1919 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
1920 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
1921 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
1923 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
));
1924 EXPECT_EQ(2, width
);
1925 EXPECT_EQ(4, height
);
1926 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
1927 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
1928 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
1930 // Service ID is restored.
1931 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
1934 TEST_P(GLES2DecoderTest
, ProduceAndConsumeDirectTextureCHROMIUM
) {
1935 Mailbox mailbox
= Mailbox::Generate();
1937 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1939 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1941 GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 4, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1942 TextureRef
* texture_ref
=
1943 group().texture_manager()->GetTexture(client_texture_id_
);
1944 ASSERT_TRUE(texture_ref
!= NULL
);
1945 Texture
* texture
= texture_ref
->texture();
1946 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
1948 ProduceTextureDirectCHROMIUMImmediate
& produce_cmd
=
1949 *GetImmediateAs
<ProduceTextureDirectCHROMIUMImmediate
>();
1950 produce_cmd
.Init(client_texture_id_
, GL_TEXTURE_2D
, mailbox
.name
);
1951 EXPECT_EQ(error::kNoError
,
1952 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
1953 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1955 // Texture didn't change.
1959 GLenum internal_format
;
1961 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
));
1962 EXPECT_EQ(3, width
);
1963 EXPECT_EQ(1, height
);
1964 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
1965 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
1966 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
1968 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
));
1969 EXPECT_EQ(2, width
);
1970 EXPECT_EQ(4, height
);
1971 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
1972 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
1973 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
1975 // Service ID has not changed.
1976 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
1978 // Consume the texture into a new client ID.
1979 GLuint new_texture_id
= kNewClientId
;
1980 CreateAndConsumeTextureCHROMIUMImmediate
& consume_cmd
=
1981 *GetImmediateAs
<CreateAndConsumeTextureCHROMIUMImmediate
>();
1982 consume_cmd
.Init(GL_TEXTURE_2D
, new_texture_id
, mailbox
.name
);
1983 EXPECT_EQ(error::kNoError
,
1984 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
1985 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1987 // Make sure the new client ID is associated with the produced service ID.
1988 texture_ref
= group().texture_manager()->GetTexture(new_texture_id
);
1989 ASSERT_TRUE(texture_ref
!= NULL
);
1990 texture
= texture_ref
->texture();
1991 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
1993 DoBindTexture(GL_TEXTURE_2D
, kNewClientId
, kServiceTextureId
);
1995 // Texture is redefined.
1996 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
));
1997 EXPECT_EQ(3, width
);
1998 EXPECT_EQ(1, height
);
1999 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2000 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2001 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2003 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
));
2004 EXPECT_EQ(2, width
);
2005 EXPECT_EQ(4, height
);
2006 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2007 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2008 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2011 TEST_P(GLES2DecoderTest
, ProduceTextureCHROMIUMInvalidTarget
) {
2012 Mailbox mailbox
= Mailbox::Generate();
2014 DoBindTexture(GL_TEXTURE_CUBE_MAP
, client_texture_id_
, kServiceTextureId
);
2016 GL_TEXTURE_CUBE_MAP_POSITIVE_X
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
,
2017 GL_UNSIGNED_BYTE
, 0, 0);
2018 TextureRef
* texture_ref
=
2019 group().texture_manager()->GetTexture(client_texture_id_
);
2020 ASSERT_TRUE(texture_ref
!= NULL
);
2021 Texture
* texture
= texture_ref
->texture();
2022 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2024 ProduceTextureDirectCHROMIUMImmediate
& produce_cmd
=
2025 *GetImmediateAs
<ProduceTextureDirectCHROMIUMImmediate
>();
2026 produce_cmd
.Init(client_texture_id_
, GL_TEXTURE_2D
, mailbox
.name
);
2027 EXPECT_EQ(error::kNoError
,
2028 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2030 // ProduceTexture should fail it the texture and produce targets don't match.
2031 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2034 TEST_P(GLES2DecoderManualInitTest
, DepthTextureBadArgs
) {
2036 init
.extensions
= "GL_ANGLE_depth_texture";
2037 init
.gl_version
= "opengl es 2.0";
2038 init
.has_depth
= true;
2039 init
.has_stencil
= true;
2040 init
.request_depth
= true;
2041 init
.request_stencil
= true;
2042 init
.bind_generates_resource
= true;
2045 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2046 // Check trying to upload data fails.
2048 tex_cmd
.Init(GL_TEXTURE_2D
,
2056 kSharedMemoryOffset
);
2057 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
2058 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2060 tex_cmd
.Init(GL_TEXTURE_2D
,
2069 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
2070 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2071 // Make a 1 pixel depth texture.
2072 DoTexImage2D(GL_TEXTURE_2D
,
2082 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2084 // Check that trying to update it fails.
2085 TexSubImage2D tex_sub_cmd
;
2086 tex_sub_cmd
.Init(GL_TEXTURE_2D
,
2095 kSharedMemoryOffset
,
2097 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_sub_cmd
));
2098 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2100 // Check that trying to CopyTexImage2D fails
2101 CopyTexImage2D copy_tex_cmd
;
2102 copy_tex_cmd
.Init(GL_TEXTURE_2D
, 0, GL_DEPTH_COMPONENT
, 0, 0, 1, 1);
2103 EXPECT_EQ(error::kNoError
, ExecuteCmd(copy_tex_cmd
));
2104 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2106 // Check that trying to CopyTexSubImage2D fails
2107 CopyTexSubImage2D copy_sub_cmd
;
2108 copy_sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 1, 1);
2109 EXPECT_EQ(error::kNoError
, ExecuteCmd(copy_sub_cmd
));
2110 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2113 TEST_P(GLES2DecoderManualInitTest
, GenerateMipmapDepthTexture
) {
2115 init
.extensions
= "GL_ANGLE_depth_texture";
2116 init
.gl_version
= "opengl es 2.0";
2117 init
.has_depth
= true;
2118 init
.has_stencil
= true;
2119 init
.request_depth
= true;
2120 init
.request_stencil
= true;
2121 init
.bind_generates_resource
= true;
2123 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2124 DoTexImage2D(GL_TEXTURE_2D
,
2135 cmd
.Init(GL_TEXTURE_2D
);
2136 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2137 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2140 TEST_P(GLES2DecoderTest
, BindTexImage2DCHROMIUM
) {
2141 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2143 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2144 TextureRef
* texture_ref
=
2145 group().texture_manager()->GetTexture(client_texture_id_
);
2146 ASSERT_TRUE(texture_ref
!= NULL
);
2147 Texture
* texture
= texture_ref
->texture();
2148 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2150 group().image_manager()->AddImage(gfx::GLImage::CreateGLImage(0).get(), 1);
2151 EXPECT_FALSE(group().image_manager()->LookupImage(1) == NULL
);
2156 GLenum internal_format
;
2158 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
));
2159 EXPECT_EQ(3, width
);
2160 EXPECT_EQ(1, height
);
2161 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2162 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2163 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2164 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2166 // Bind image to texture.
2167 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2168 EXPECT_CALL(*gl_
, GetError())
2169 .WillOnce(Return(GL_NO_ERROR
))
2170 .WillOnce(Return(GL_NO_ERROR
))
2171 .RetiresOnSaturation();
2172 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd
;
2173 bind_tex_image_2d_cmd
.Init(GL_TEXTURE_2D
, 1);
2174 EXPECT_EQ(error::kNoError
, ExecuteCmd(bind_tex_image_2d_cmd
));
2175 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
));
2176 // Image should now be set.
2177 EXPECT_FALSE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2179 // Define new texture image.
2181 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2182 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
));
2183 // Image should no longer be set.
2184 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2187 TEST_P(GLES2DecoderTest
, BindTexImage2DCHROMIUMCubeMapNotAllowed
) {
2188 group().image_manager()->AddImage(gfx::GLImage::CreateGLImage(0).get(), 1);
2189 DoBindTexture(GL_TEXTURE_CUBE_MAP
, client_texture_id_
, kServiceTextureId
);
2191 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd
;
2192 bind_tex_image_2d_cmd
.Init(GL_TEXTURE_CUBE_MAP
, 1);
2193 EXPECT_EQ(error::kNoError
, ExecuteCmd(bind_tex_image_2d_cmd
));
2194 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
2197 TEST_P(GLES2DecoderTest
, OrphanGLImageWithTexImage2D
) {
2198 group().image_manager()->AddImage(gfx::GLImage::CreateGLImage(0).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 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2208 TextureRef
* texture_ref
=
2209 group().texture_manager()->GetTexture(client_texture_id_
);
2210 ASSERT_TRUE(texture_ref
!= NULL
);
2211 Texture
* texture
= texture_ref
->texture();
2212 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2215 TEST_P(GLES2DecoderTest
, ReleaseTexImage2DCHROMIUM
) {
2216 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
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_EQ(kServiceTextureId
, texture
->service_id());
2225 group().image_manager()->AddImage(gfx::GLImage::CreateGLImage(0).get(), 1);
2226 EXPECT_FALSE(group().image_manager()->LookupImage(1) == NULL
);
2231 GLenum internal_format
;
2233 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
));
2234 EXPECT_EQ(3, width
);
2235 EXPECT_EQ(1, height
);
2236 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2237 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2238 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2239 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2241 // Bind image to texture.
2242 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2243 EXPECT_CALL(*gl_
, GetError())
2244 .WillOnce(Return(GL_NO_ERROR
))
2245 .WillOnce(Return(GL_NO_ERROR
))
2246 .RetiresOnSaturation();
2247 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd
;
2248 bind_tex_image_2d_cmd
.Init(GL_TEXTURE_2D
, 1);
2249 EXPECT_EQ(error::kNoError
, ExecuteCmd(bind_tex_image_2d_cmd
));
2250 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
));
2251 // Image should now be set.
2252 EXPECT_FALSE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2254 // Release image from texture.
2255 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2256 EXPECT_CALL(*gl_
, GetError())
2257 .WillOnce(Return(GL_NO_ERROR
))
2258 .WillOnce(Return(GL_NO_ERROR
))
2259 .RetiresOnSaturation();
2260 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd
;
2261 release_tex_image_2d_cmd
.Init(GL_TEXTURE_2D
, 1);
2262 EXPECT_EQ(error::kNoError
, ExecuteCmd(release_tex_image_2d_cmd
));
2263 EXPECT_TRUE(texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
));
2264 // Image should no longer be set.
2265 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2268 class MockGLImage
: public gfx::GLImage
{
2272 // Overridden from gfx::GLImage:
2273 MOCK_METHOD0(Destroy
, void());
2274 MOCK_METHOD0(GetSize
, gfx::Size());
2275 MOCK_METHOD1(BindTexImage
, bool(unsigned));
2276 MOCK_METHOD1(ReleaseTexImage
, void(unsigned));
2277 MOCK_METHOD0(WillUseTexImage
, void());
2278 MOCK_METHOD0(DidUseTexImage
, void());
2279 MOCK_METHOD0(WillModifyTexImage
, void());
2280 MOCK_METHOD0(DidModifyTexImage
, void());
2283 virtual ~MockGLImage() {}
2286 TEST_P(GLES2DecoderWithShaderTest
, UseTexImage
) {
2287 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2288 DoTexImage2D(GL_TEXTURE_2D
,
2297 kSharedMemoryOffset
);
2299 TextureRef
* texture_ref
=
2300 group().texture_manager()->GetTexture(client_texture_id_
);
2301 ASSERT_TRUE(texture_ref
!= NULL
);
2302 Texture
* texture
= texture_ref
->texture();
2303 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2305 const int32 kImageId
= 1;
2306 scoped_refptr
<MockGLImage
> image(new MockGLImage
);
2307 group().image_manager()->AddImage(image
.get(), kImageId
);
2309 // Bind image to texture.
2310 EXPECT_CALL(*image
, BindTexImage(GL_TEXTURE_2D
))
2312 .WillOnce(Return(true))
2313 .RetiresOnSaturation();
2314 EXPECT_CALL(*image
, GetSize())
2316 .WillOnce(Return(gfx::Size(1, 1)))
2317 .RetiresOnSaturation();
2318 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2319 EXPECT_CALL(*gl_
, GetError())
2320 .WillOnce(Return(GL_NO_ERROR
))
2321 .WillOnce(Return(GL_NO_ERROR
))
2322 .RetiresOnSaturation();
2323 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd
;
2324 bind_tex_image_2d_cmd
.Init(GL_TEXTURE_2D
, kImageId
);
2325 EXPECT_EQ(error::kNoError
, ExecuteCmd(bind_tex_image_2d_cmd
));
2327 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2328 SetupExpectationsForApplyingDefaultDirtyState();
2330 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2331 EXPECT_CALL(*gl_
, GetError())
2332 .WillOnce(Return(GL_NO_ERROR
))
2333 .WillOnce(Return(GL_NO_ERROR
))
2334 .WillOnce(Return(GL_NO_ERROR
))
2335 .WillOnce(Return(GL_NO_ERROR
))
2336 .RetiresOnSaturation();
2337 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(3).RetiresOnSaturation();
2338 EXPECT_CALL(*image
, WillUseTexImage()).Times(1).RetiresOnSaturation();
2339 EXPECT_CALL(*image
, DidUseTexImage()).Times(1).RetiresOnSaturation();
2340 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2342 .RetiresOnSaturation();
2344 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2345 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2346 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2349 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2350 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2351 EXPECT_CALL(*gl_
, GetError())
2352 .WillOnce(Return(GL_NO_ERROR
))
2353 .WillOnce(Return(GL_NO_ERROR
))
2354 .RetiresOnSaturation();
2355 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2356 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2358 .RetiresOnSaturation();
2359 // Image will be 'in use' as long as bound to a framebuffer.
2360 EXPECT_CALL(*image
, WillUseTexImage()).Times(1).RetiresOnSaturation();
2362 FramebufferTexture2DEXT(GL_FRAMEBUFFER
,
2363 GL_COLOR_ATTACHMENT0
,
2368 .RetiresOnSaturation();
2369 EXPECT_CALL(*gl_
, GetError())
2370 .WillOnce(Return(GL_NO_ERROR
))
2371 .WillOnce(Return(GL_NO_ERROR
))
2372 .RetiresOnSaturation();
2373 FramebufferTexture2D fbtex_cmd
;
2374 fbtex_cmd
.Init(GL_FRAMEBUFFER
,
2375 GL_COLOR_ATTACHMENT0
,
2377 client_texture_id_
);
2378 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbtex_cmd
));
2379 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2381 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2382 EXPECT_CALL(*gl_
, GetError())
2383 .WillOnce(Return(GL_NO_ERROR
))
2384 .WillOnce(Return(GL_NO_ERROR
))
2385 .RetiresOnSaturation();
2387 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
2388 GL_COLOR_ATTACHMENT0
,
2390 kServiceRenderbufferId
))
2392 .RetiresOnSaturation();
2393 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2394 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2396 .RetiresOnSaturation();
2397 // Image should no longer be 'in use' after being unbound from framebuffer.
2398 EXPECT_CALL(*image
, DidUseTexImage()).Times(1).RetiresOnSaturation();
2399 EXPECT_CALL(*gl_
, GetError())
2400 .WillOnce(Return(GL_NO_ERROR
))
2401 .WillOnce(Return(GL_NO_ERROR
))
2402 .RetiresOnSaturation();
2403 FramebufferRenderbuffer fbrb_cmd
;
2404 fbrb_cmd
.Init(GL_FRAMEBUFFER
,
2405 GL_COLOR_ATTACHMENT0
,
2407 client_renderbuffer_id_
);
2408 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbrb_cmd
));
2411 TEST_P(GLES2DecoderManualInitTest
, DrawWithGLImageExternal
) {
2413 init
.extensions
= "GL_OES_EGL_image_external";
2414 init
.gl_version
= "opengl es 2.0";
2415 init
.has_alpha
= true;
2416 init
.has_depth
= true;
2417 init
.request_alpha
= true;
2418 init
.request_depth
= true;
2419 init
.bind_generates_resource
= true;
2422 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
2423 scoped_refptr
<MockGLImage
> image(new MockGLImage
);
2424 group().texture_manager()->SetTarget(texture_ref
, GL_TEXTURE_EXTERNAL_OES
);
2425 group().texture_manager()->SetLevelInfo(texture_ref
,
2426 GL_TEXTURE_EXTERNAL_OES
,
2436 group().texture_manager()->SetLevelImage(
2437 texture_ref
, GL_TEXTURE_EXTERNAL_OES
, 0, image
);
2439 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
2440 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2442 SetupSamplerExternalProgram();
2444 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
2445 SetupExpectationsForApplyingDefaultDirtyState();
2446 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref
));
2449 EXPECT_CALL(*gl_
, GetError())
2450 .WillOnce(Return(GL_NO_ERROR
))
2451 .RetiresOnSaturation();
2452 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2453 EXPECT_CALL(*image
, WillUseTexImage()).Times(1).RetiresOnSaturation();
2454 EXPECT_CALL(*gl_
, GetError())
2455 .WillOnce(Return(GL_NO_ERROR
))
2456 .RetiresOnSaturation();
2457 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(1);
2458 EXPECT_CALL(*gl_
, GetError())
2459 .WillOnce(Return(GL_NO_ERROR
))
2460 .RetiresOnSaturation();
2461 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2462 EXPECT_CALL(*image
, DidUseTexImage()).Times(1).RetiresOnSaturation();
2463 EXPECT_CALL(*gl_
, GetError())
2464 .WillOnce(Return(GL_NO_ERROR
))
2465 .RetiresOnSaturation();
2466 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2468 cmd
.Init(GL_TRIANGLES
,
2469 kValidIndexRangeCount
,
2471 kValidIndexRangeStart
* 2);
2472 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2473 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2476 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatOnGLES2
) {
2478 init
.extensions
= "GL_OES_texture_float";
2479 init
.gl_version
= "opengl es 2.0";
2481 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2482 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2483 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 16, 17, 0, GL_RGB
, GL_FLOAT
, 0, 0);
2485 GL_TEXTURE_2D
, 0, GL_LUMINANCE
, 16, 17, 0, GL_LUMINANCE
, GL_FLOAT
, 0, 0);
2486 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, 16, 17, 0, GL_ALPHA
, GL_FLOAT
, 0, 0);
2487 DoTexImage2D(GL_TEXTURE_2D
,
2499 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatOnGLES3
) {
2501 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
2502 init
.gl_version
= "opengl es 3.0";
2504 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2505 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2506 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 16, 17, 0, GL_RGB
, GL_FLOAT
, 0, 0);
2508 GL_TEXTURE_2D
, 0, GL_RGBA32F
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2510 GL_TEXTURE_2D
, 0, GL_LUMINANCE
, 16, 17, 0, GL_LUMINANCE
, GL_FLOAT
, 0, 0);
2511 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, 16, 17, 0, GL_ALPHA
, GL_FLOAT
, 0, 0);
2512 DoTexImage2D(GL_TEXTURE_2D
,
2524 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DFloatOnGLES3
) {
2526 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
2527 init
.gl_version
= "opengl es 3.0";
2529 const int kWidth
= 8;
2530 const int kHeight
= 4;
2531 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2532 DoTexImage2D(GL_TEXTURE_2D
,
2543 TexImage2D(GL_TEXTURE_2D
,
2551 shared_memory_address_
))
2553 .RetiresOnSaturation();
2555 cmd
.Init(GL_TEXTURE_2D
,
2564 kSharedMemoryOffset
,
2566 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2567 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2570 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DFloatDoesClearOnGLES3
) {
2572 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
2573 init
.gl_version
= "opengl es 3.0";
2575 const int kWidth
= 8;
2576 const int kHeight
= 4;
2577 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2578 DoTexImage2D(GL_TEXTURE_2D
,
2588 SetupClearTextureExpectations(kServiceTextureId
,
2599 TexSubImage2D(GL_TEXTURE_2D
,
2607 shared_memory_address_
))
2609 .RetiresOnSaturation();
2611 cmd
.Init(GL_TEXTURE_2D
,
2620 kSharedMemoryOffset
,
2622 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2623 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2626 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatConvertsFormatDesktop
) {
2628 init
.extensions
= "GL_ARB_texture_float";
2629 init
.gl_version
= "2.1";
2631 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2633 GL_TEXTURE_2D
, 0, GL_RGBA32F
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2634 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB32F
, 16, 17, 0, GL_RGB
, GL_FLOAT
, 0, 0);
2635 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2646 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2657 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2667 GL_LUMINANCE32F_ARB
);
2668 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2679 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
2689 GL_LUMINANCE_ALPHA32F_ARB
);
2692 class GLES2DecoderCompressedFormatsTest
: public GLES2DecoderManualInitTest
{
2694 GLES2DecoderCompressedFormatsTest() {}
2696 static bool ValueInArray(GLint value
, GLint
* array
, GLint count
) {
2697 for (GLint ii
= 0; ii
< count
; ++ii
) {
2698 if (array
[ii
] == value
) {
2705 void CheckFormats(const char* extension
, const GLenum
* formats
, int count
) {
2707 init
.extensions
= extension
;
2708 init
.gl_version
= "3.0";
2709 init
.bind_generates_resource
= true;
2712 EXPECT_CALL(*gl_
, GetError())
2713 .WillOnce(Return(GL_NO_ERROR
))
2714 .WillOnce(Return(GL_NO_ERROR
))
2715 .WillOnce(Return(GL_NO_ERROR
))
2716 .WillOnce(Return(GL_NO_ERROR
))
2717 .RetiresOnSaturation();
2719 typedef GetIntegerv::Result Result
;
2720 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
2723 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
2724 cmd
.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
2726 shared_memory_offset_
);
2727 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2728 EXPECT_EQ(1, result
->GetNumResults());
2729 GLint num_formats
= result
->GetData()[0];
2730 EXPECT_EQ(count
, num_formats
);
2731 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2734 cmd
.Init(GL_COMPRESSED_TEXTURE_FORMATS
,
2736 shared_memory_offset_
);
2737 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2738 EXPECT_EQ(num_formats
, result
->GetNumResults());
2740 for (int i
= 0; i
< count
; ++i
) {
2742 ValueInArray(formats
[i
], result
->GetData(), result
->GetNumResults()));
2745 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2749 INSTANTIATE_TEST_CASE_P(Service
,
2750 GLES2DecoderCompressedFormatsTest
,
2753 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsS3TC
) {
2754 const GLenum formats
[] = {
2755 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
,
2756 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
};
2757 CheckFormats("GL_EXT_texture_compression_s3tc", formats
, 4);
2760 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsATC
) {
2761 const GLenum formats
[] = {GL_ATC_RGB_AMD
, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD
,
2762 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
};
2763 CheckFormats("GL_AMD_compressed_ATC_texture", formats
, 3);
2766 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsPVRTC
) {
2767 const GLenum formats
[] = {
2768 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
,
2769 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
};
2770 CheckFormats("GL_IMG_texture_compression_pvrtc", formats
, 4);
2773 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsETC1
) {
2774 const GLenum formats
[] = {GL_ETC1_RGB8_OES
};
2775 CheckFormats("GL_OES_compressed_ETC1_RGB8_texture", formats
, 1);
2778 TEST_P(GLES2DecoderManualInitTest
, GetNoCompressedTextureFormats
) {
2780 init
.gl_version
= "3.0";
2781 init
.bind_generates_resource
= true;
2784 EXPECT_CALL(*gl_
, GetError())
2785 .WillOnce(Return(GL_NO_ERROR
))
2786 .WillOnce(Return(GL_NO_ERROR
))
2787 .WillOnce(Return(GL_NO_ERROR
))
2788 .WillOnce(Return(GL_NO_ERROR
))
2789 .RetiresOnSaturation();
2791 typedef GetIntegerv::Result Result
;
2792 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
2795 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
2796 cmd
.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
2798 shared_memory_offset_
);
2799 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2800 EXPECT_EQ(1, result
->GetNumResults());
2801 GLint num_formats
= result
->GetData()[0];
2802 EXPECT_EQ(0, num_formats
);
2803 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2807 GL_COMPRESSED_TEXTURE_FORMATS
, shared_memory_id_
, shared_memory_offset_
);
2808 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2809 EXPECT_EQ(num_formats
, result
->GetNumResults());
2811 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2814 // TODO(gman): Complete this test.
2815 // TEST_P(GLES2DecoderTest, CompressedTexImage2DGLError) {
2818 // TODO(gman): CompressedTexImage2D
2820 // TODO(gman): CompressedTexImage2DImmediate
2822 // TODO(gman): CompressedTexSubImage2DImmediate
2824 // TODO(gman): TexImage2D
2826 // TODO(gman): TexImage2DImmediate
2828 // TODO(gman): TexSubImage2DImmediate
2830 } // namespace gles2