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"
20 #include "gpu/command_buffer/service/image_manager.h"
21 #include "gpu/command_buffer/service/mailbox_manager.h"
22 #include "gpu/command_buffer/service/mocks.h"
23 #include "gpu/command_buffer/service/program_manager.h"
24 #include "gpu/command_buffer/service/test_helper.h"
25 #include "gpu/config/gpu_switches.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/gl/gl_image_stub.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();
77 texture
->GetLevelSize(GL_TEXTURE_2D
, 2, &width
, &height
, nullptr));
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());
98 texture
->GetLevelSize(GL_TEXTURE_2D
, 2, &width
, &height
, nullptr));
101 TEST_P(GLES2DecoderTest
, GenerateMipmapClearsUnclearedTexture
) {
102 EXPECT_CALL(*gl_
, GenerateMipmapEXT(_
)).Times(0);
103 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
105 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
106 SetupClearTextureExpectations(kServiceTextureId
,
116 EXPECT_CALL(*gl_
, GenerateMipmapEXT(GL_TEXTURE_2D
));
117 EXPECT_CALL(*gl_
, GetError())
118 .WillOnce(Return(GL_NO_ERROR
))
119 .WillOnce(Return(GL_NO_ERROR
))
120 .RetiresOnSaturation();
122 cmd
.Init(GL_TEXTURE_2D
);
123 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
124 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
127 // Same as GenerateMipmapClearsUnclearedTexture, but with workaround
128 // |set_texture_filters_before_generating_mipmap|.
129 TEST_P(GLES2DecoderManualInitTest
, SetTextureFiltersBeforeGenerateMipmap
) {
130 base::CommandLine
command_line(0, NULL
);
131 command_line
.AppendSwitchASCII(
132 switches::kGpuDriverBugWorkarounds
,
133 base::IntToString(gpu::SET_TEXTURE_FILTER_BEFORE_GENERATING_MIPMAP
));
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();
581 texture
->GetLevelSize(GL_TEXTURE_2D
, level
, &width
, &height
, nullptr));
582 EXPECT_CALL(*gl_
, GetError())
583 .WillOnce(Return(GL_NO_ERROR
))
584 .WillOnce(Return(GL_OUT_OF_MEMORY
))
585 .RetiresOnSaturation();
597 .RetiresOnSaturation();
607 kSharedMemoryOffset
);
608 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
609 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
611 texture
->GetLevelSize(GL_TEXTURE_2D
, level
, &width
, &height
, nullptr));
614 TEST_P(GLES2DecoderTest
, CopyTexImage2DGLError
) {
615 GLenum target
= GL_TEXTURE_2D
;
617 GLenum internal_format
= GL_RGBA
;
621 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
622 TextureManager
* manager
= group().texture_manager();
623 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
624 ASSERT_TRUE(texture_ref
!= NULL
);
625 Texture
* texture
= texture_ref
->texture();
627 texture
->GetLevelSize(GL_TEXTURE_2D
, level
, &width
, &height
, nullptr));
628 EXPECT_CALL(*gl_
, GetError())
629 .WillOnce(Return(GL_NO_ERROR
))
630 .WillOnce(Return(GL_OUT_OF_MEMORY
))
631 .RetiresOnSaturation();
634 target
, level
, internal_format
, 0, 0, width
, height
, border
))
636 .RetiresOnSaturation();
638 cmd
.Init(target
, level
, internal_format
, 0, 0, width
, height
);
639 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
640 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
642 texture
->GetLevelSize(GL_TEXTURE_2D
, level
, &width
, &height
, nullptr));
645 TEST_P(GLES3DecoderTest
, CompressedTexImage3DBucket
) {
646 const uint32 kBucketId
= 123;
647 const uint32 kBadBucketId
= 99;
648 const GLenum kTarget
= GL_TEXTURE_2D_ARRAY
;
649 const GLint kLevel
= 0;
650 const GLenum kInternalFormat
= GL_COMPRESSED_R11_EAC
;
651 const GLsizei kWidth
= 4;
652 const GLsizei kHeight
= 4;
653 const GLsizei kDepth
= 4;
654 const GLint kBorder
= 0;
655 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
656 ASSERT_TRUE(bucket
!= NULL
);
657 const GLsizei kImageSize
= 32;
658 bucket
->SetSize(kImageSize
);
660 DoBindTexture(kTarget
, client_texture_id_
, kServiceTextureId
);
662 CompressedTexImage3DBucket cmd
;
670 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
680 CompressedTexImage3D(kTarget
, kLevel
, kInternalFormat
, kWidth
,
681 kHeight
, kDepth
, kBorder
, kImageSize
, _
))
683 .RetiresOnSaturation();
684 EXPECT_CALL(*gl_
, GetError())
685 .WillOnce(Return(GL_NO_ERROR
))
686 .WillOnce(Return(GL_NO_ERROR
))
687 .RetiresOnSaturation();
688 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
689 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
692 TEST_P(GLES2DecoderTest
, CompressedTexImage3DFailsOnES2
) {
693 const uint32 kBucketId
= 123;
694 const GLenum kTarget
= GL_TEXTURE_2D_ARRAY
;
695 const GLint kLevel
= 0;
696 const GLenum kInternalFormat
= GL_COMPRESSED_R11_EAC
;
697 const GLsizei kWidth
= 4;
698 const GLsizei kHeight
= 4;
699 const GLsizei kDepth
= 4;
700 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
701 ASSERT_TRUE(bucket
!= NULL
);
702 const GLsizei kImageSize
= 32;
703 bucket
->SetSize(kImageSize
);
706 CompressedTexImage3DBucket cmd
;
714 EXPECT_EQ(error::kUnknownCommand
, ExecuteCmd(cmd
));
718 CompressedTexSubImage3DBucket cmd
;
727 EXPECT_EQ(error::kUnknownCommand
, ExecuteCmd(cmd
));
731 TEST_P(GLES3DecoderTest
, CompressedTexImage3DFailsWithBadImageSize
) {
732 const uint32 kBucketId
= 123;
733 const GLenum kTarget
= GL_TEXTURE_2D_ARRAY
;
734 const GLint kLevel
= 0;
735 const GLenum kInternalFormat
= GL_COMPRESSED_RGBA8_ETC2_EAC
;
736 const GLsizei kWidth
= 4;
737 const GLsizei kHeight
= 8;
738 const GLsizei kDepth
= 4;
739 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
740 ASSERT_TRUE(bucket
!= NULL
);
741 const GLsizei kBadImageSize
= 64;
742 bucket
->SetSize(kBadImageSize
);
744 DoBindTexture(kTarget
, client_texture_id_
, kServiceTextureId
);
746 CompressedTexImage3DBucket cmd
;
754 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
755 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
758 TEST_P(GLES3DecoderTest
, CompressedTexSubImage3DFails
) {
759 const uint32 kBucketId
= 123;
760 const GLenum kTarget
= GL_TEXTURE_2D_ARRAY
;
761 const GLint kLevel
= 0;
762 const GLenum kInternalFormat
= GL_COMPRESSED_RGBA8_ETC2_EAC
;
763 const GLsizei kWidth
= 4;
764 const GLsizei kHeight
= 8;
765 const GLsizei kDepth
= 4;
766 const GLint kBorder
= 0;
767 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
768 ASSERT_TRUE(bucket
!= NULL
);
769 const GLsizei kImageSize
= 128;
770 bucket
->SetSize(kImageSize
);
772 DoBindTexture(kTarget
, client_texture_id_
, kServiceTextureId
);
774 CompressedTexImage3DBucket tex_cmd
;
775 tex_cmd
.Init(kTarget
,
783 CompressedTexImage3D(kTarget
, kLevel
, kInternalFormat
, kWidth
,
784 kHeight
, kDepth
, kBorder
, kImageSize
, _
))
786 .RetiresOnSaturation();
787 EXPECT_CALL(*gl_
, GetError())
788 .WillOnce(Return(GL_NO_ERROR
))
789 .WillOnce(Return(GL_NO_ERROR
))
790 .RetiresOnSaturation();
791 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
792 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
794 const GLint kXOffset
= 0;
795 const GLint kYOffset
= 0;
796 const GLint kZOffset
= 0;
797 const GLint kSubWidth
= 4;
798 const GLint kSubHeight
= 4;
799 const GLint kSubDepth
= 4;
800 const GLenum kFormat
= kInternalFormat
;
801 CompressedTexSubImage3DBucket cmd
;
803 // Incorrect image size.
814 const GLsizei kBadSubImageSize
= 32;
815 const GLsizei kSubImageSize
= 64;
816 bucket
->SetSize(kBadSubImageSize
);
817 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
818 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
821 const GLenum kBadFormat
= GL_COMPRESSED_R11_EAC
;
832 bucket
->SetSize(kSubImageSize
);
833 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
834 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
847 bucket
->SetSize(kSubImageSize
);
848 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
849 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
851 // offset + size > texture size
862 bucket
->SetSize(kSubImageSize
);
863 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
864 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
866 // offset not a multiple of 4.
877 bucket
->SetSize(kSubImageSize
);
878 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
879 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
881 // offset + width not a multlple of 4 .
892 const GLsizei kSubImageSize2
= 128;
893 bucket
->SetSize(kSubImageSize2
);
894 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
895 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
898 const uint32 kBadBucketId
= 444;
909 bucket
->SetSize(kSubImageSize
);
910 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
913 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DBucketBadBucket
) {
915 init
.extensions
= "GL_EXT_texture_compression_s3tc";
916 init
.bind_generates_resource
= true;
919 const uint32 kBadBucketId
= 123;
920 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
921 CompressedTexImage2DBucket cmd
;
922 cmd
.Init(GL_TEXTURE_2D
,
924 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
928 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
929 CompressedTexSubImage2DBucket cmd2
;
930 cmd2
.Init(GL_TEXTURE_2D
,
936 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
938 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
943 struct S3TCTestData
{
948 } // anonymous namespace.
950 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DS3TC
) {
952 init
.extensions
= "GL_EXT_texture_compression_s3tc";
953 init
.bind_generates_resource
= true;
955 const uint32 kBucketId
= 123;
956 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
957 ASSERT_TRUE(bucket
!= NULL
);
959 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
961 static const S3TCTestData test_data
[] = {
963 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, 8,
966 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, 8,
969 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, 16,
972 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, 16,
976 for (size_t ii
= 0; ii
< arraysize(test_data
); ++ii
) {
977 const S3TCTestData
& test
= test_data
[ii
];
978 CompressedTexImage2DBucket cmd
;
980 DoCompressedTexImage2D(
981 GL_TEXTURE_2D
, 0, test
.format
, 2, 4, 0, test
.block_size
, kBucketId
);
982 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
985 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 5, 4, kBucketId
);
986 bucket
->SetSize(test
.block_size
* 2);
987 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
988 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
990 // test small height.
991 DoCompressedTexImage2D(
992 GL_TEXTURE_2D
, 0, test
.format
, 4, 2, 0, test
.block_size
, kBucketId
);
993 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
995 // test too bad height.
996 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 4, 5, kBucketId
);
997 bucket
->SetSize(test
.block_size
* 2);
998 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
999 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1001 // test small for level 0.
1002 DoCompressedTexImage2D(
1003 GL_TEXTURE_2D
, 0, test
.format
, 1, 1, 0, test
.block_size
, kBucketId
);
1004 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1006 // test small for level 0.
1007 DoCompressedTexImage2D(
1008 GL_TEXTURE_2D
, 0, test
.format
, 2, 2, 0, test
.block_size
, kBucketId
);
1009 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1011 // test size too large.
1012 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 4, 4, kBucketId
);
1013 bucket
->SetSize(test
.block_size
* 2);
1014 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1015 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1017 // test size too small.
1018 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 4, 4, kBucketId
);
1019 bucket
->SetSize(test
.block_size
/ 2);
1020 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1021 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1023 // test with 3 mips.
1024 DoCompressedTexImage2D(
1025 GL_TEXTURE_2D
, 0, test
.format
, 4, 4, 0, test
.block_size
, kBucketId
);
1026 DoCompressedTexImage2D(
1027 GL_TEXTURE_2D
, 1, test
.format
, 2, 2, 0, test
.block_size
, kBucketId
);
1028 DoCompressedTexImage2D(
1029 GL_TEXTURE_2D
, 2, test
.format
, 1, 1, 0, test
.block_size
, kBucketId
);
1030 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1033 DoCompressedTexImage2D(GL_TEXTURE_2D
,
1039 test
.block_size
* 4 * 4,
1041 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1043 CompressedTexSubImage2DBucket sub_cmd
;
1044 bucket
->SetSize(test
.block_size
);
1045 // Test sub image bad xoffset
1046 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 1, 0, 4, 4, test
.format
, kBucketId
);
1047 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1048 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1050 // Test sub image bad yoffset
1051 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 2, 4, 4, test
.format
, kBucketId
);
1052 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1053 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1055 // Test sub image bad width
1056 bucket
->SetSize(test
.block_size
* 2);
1057 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 5, 4, test
.format
, kBucketId
);
1058 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1059 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1061 // Test sub image bad height
1062 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 4, 5, test
.format
, kBucketId
);
1063 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1064 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1066 // Test sub image bad size
1067 bucket
->SetSize(test
.block_size
+ 1);
1068 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 4, 4, test
.format
, kBucketId
);
1069 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1070 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1072 for (GLint yoffset
= 0; yoffset
<= 8; yoffset
+= 4) {
1073 for (GLint xoffset
= 0; xoffset
<= 8; xoffset
+= 4) {
1074 for (GLsizei height
= 4; height
<= 8; height
+= 4) {
1075 for (GLsizei width
= 4; width
<= 8; width
+= 4) {
1076 GLsizei size
= test
.block_size
* (width
/ 4) * (height
/ 4);
1077 bucket
->SetSize(size
);
1079 CompressedTexSubImage2D(GL_TEXTURE_2D
,
1089 .RetiresOnSaturation();
1090 sub_cmd
.Init(GL_TEXTURE_2D
,
1098 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1099 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1107 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DETC1
) {
1109 init
.extensions
= "GL_OES_compressed_ETC1_RGB8_texture";
1110 init
.gl_version
= "opengl es 2.0";
1111 init
.bind_generates_resource
= true;
1113 const uint32 kBucketId
= 123;
1114 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
1115 ASSERT_TRUE(bucket
!= NULL
);
1117 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1119 const GLenum kFormat
= GL_ETC1_RGB8_OES
;
1120 const size_t kBlockSize
= 8;
1122 CompressedTexImage2DBucket cmd
;
1123 // test small width.
1124 DoCompressedTexImage2D(GL_TEXTURE_2D
, 0, kFormat
, 4, 8, 0, 16, kBucketId
);
1125 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1127 // test small height.
1128 DoCompressedTexImage2D(GL_TEXTURE_2D
, 0, kFormat
, 8, 4, 0, 16, kBucketId
);
1129 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1131 // test size too large.
1132 cmd
.Init(GL_TEXTURE_2D
, 0, kFormat
, 4, 4, kBucketId
);
1133 bucket
->SetSize(kBlockSize
* 2);
1134 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1135 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1137 // test size too small.
1138 cmd
.Init(GL_TEXTURE_2D
, 0, kFormat
, 4, 4, kBucketId
);
1139 bucket
->SetSize(kBlockSize
/ 2);
1140 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1141 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1144 DoCompressedTexImage2D(
1145 GL_TEXTURE_2D
, 0, kFormat
, 16, 16, 0, kBlockSize
* 16, kBucketId
);
1146 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1148 // Test CompressedTexSubImage not allowed
1149 CompressedTexSubImage2DBucket sub_cmd
;
1150 bucket
->SetSize(kBlockSize
);
1151 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 4, 4, kFormat
, kBucketId
);
1152 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1153 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1155 // Test TexSubImage not allowed for ETC1 compressed texture
1156 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1157 ASSERT_TRUE(texture_ref
!= NULL
);
1158 Texture
* texture
= texture_ref
->texture();
1159 GLenum type
, internal_format
;
1160 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
1161 EXPECT_EQ(kFormat
, internal_format
);
1162 TexSubImage2D texsub_cmd
;
1163 texsub_cmd
.Init(GL_TEXTURE_2D
,
1172 kSharedMemoryOffset
,
1174 EXPECT_EQ(error::kNoError
, ExecuteCmd(texsub_cmd
));
1175 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1177 // Test CopyTexSubImage not allowed for ETC1 compressed texture
1178 CopyTexSubImage2D copy_cmd
;
1179 copy_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 4, 4);
1180 EXPECT_EQ(error::kNoError
, ExecuteCmd(copy_cmd
));
1181 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1186 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalBindTexture
) {
1188 init
.extensions
= "GL_OES_EGL_image_external";
1189 init
.gl_version
= "opengl es 2.0";
1190 init
.bind_generates_resource
= true;
1192 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_EXTERNAL_OES
, kNewServiceId
));
1193 EXPECT_CALL(*gl_
, GenTextures(1, _
))
1194 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
));
1196 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, kNewClientId
);
1197 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1198 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1199 TextureRef
* texture_ref
= GetTexture(kNewClientId
);
1200 EXPECT_TRUE(texture_ref
!= NULL
);
1201 EXPECT_TRUE(texture_ref
->texture()->target() == GL_TEXTURE_EXTERNAL_OES
);
1204 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalGetBinding
) {
1206 init
.extensions
= "GL_OES_EGL_image_external";
1207 init
.gl_version
= "opengl es 2.0";
1208 init
.bind_generates_resource
= true;
1210 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1212 EXPECT_CALL(*gl_
, GetError())
1213 .WillOnce(Return(GL_NO_ERROR
))
1214 .WillOnce(Return(GL_NO_ERROR
))
1215 .RetiresOnSaturation();
1216 typedef GetIntegerv::Result Result
;
1217 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1219 GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES
, result
->GetData()))
1223 cmd
.Init(GL_TEXTURE_BINDING_EXTERNAL_OES
,
1225 shared_memory_offset_
);
1226 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1227 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(
1228 GL_TEXTURE_BINDING_EXTERNAL_OES
),
1229 result
->GetNumResults());
1230 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1231 EXPECT_EQ(client_texture_id_
, (uint32
)result
->GetData()[0]);
1234 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTextureDefaults
) {
1236 init
.extensions
= "GL_OES_EGL_image_external";
1237 init
.gl_version
= "opengl es 2.0";
1238 init
.bind_generates_resource
= true;
1240 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1242 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1243 EXPECT_TRUE(texture_ref
!= NULL
);
1244 Texture
* texture
= texture_ref
->texture();
1245 EXPECT_TRUE(texture
->target() == GL_TEXTURE_EXTERNAL_OES
);
1246 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1247 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1248 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1251 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTextureParam
) {
1253 init
.extensions
= "GL_OES_EGL_image_external";
1254 init
.gl_version
= "opengl es 2.0";
1255 init
.bind_generates_resource
= true;
1257 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1261 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
));
1264 TexParameteri(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
));
1268 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
));
1272 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
));
1274 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1275 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1276 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1278 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
1279 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1280 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1282 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
1283 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1284 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1286 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
1287 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1288 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1290 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1291 EXPECT_TRUE(texture_ref
!= NULL
);
1292 Texture
* texture
= texture_ref
->texture();
1293 EXPECT_TRUE(texture
->target() == GL_TEXTURE_EXTERNAL_OES
);
1294 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1295 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1296 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1299 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTextureParamInvalid
) {
1301 init
.extensions
= "GL_OES_EGL_image_external";
1302 init
.gl_version
= "opengl es 2.0";
1303 init
.bind_generates_resource
= true;
1305 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1308 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
,
1309 GL_TEXTURE_MIN_FILTER
,
1310 GL_NEAREST_MIPMAP_NEAREST
);
1311 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1312 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1314 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
1315 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1316 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1318 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
1319 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1320 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1322 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1323 EXPECT_TRUE(texture_ref
!= NULL
);
1324 Texture
* texture
= texture_ref
->texture();
1325 EXPECT_TRUE(texture
->target() == GL_TEXTURE_EXTERNAL_OES
);
1326 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1327 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1328 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1331 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTexImage2DError
) {
1333 init
.extensions
= "GL_OES_EGL_image_external";
1334 init
.gl_version
= "opengl es 2.0";
1335 init
.bind_generates_resource
= true;
1338 GLenum target
= GL_TEXTURE_EXTERNAL_OES
;
1340 GLenum internal_format
= GL_RGBA
;
1343 GLenum format
= GL_RGBA
;
1344 GLenum type
= GL_UNSIGNED_BYTE
;
1345 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1346 ASSERT_TRUE(GetTexture(client_texture_id_
) != NULL
);
1356 kSharedMemoryOffset
);
1357 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1359 // TexImage2D is not allowed with GL_TEXTURE_EXTERNAL_OES targets.
1360 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1363 TEST_P(GLES2DecoderManualInitTest
, DefaultTextureZero
) {
1368 cmd1
.Init(GL_TEXTURE_2D
, 0);
1369 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1370 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1371 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1374 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1375 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1376 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1377 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1380 TEST_P(GLES2DecoderManualInitTest
, DefaultTextureBGR
) {
1382 init
.bind_generates_resource
= true;
1386 cmd1
.Init(GL_TEXTURE_2D
, 0);
1388 *gl_
, BindTexture(GL_TEXTURE_2D
, TestHelper::kServiceDefaultTexture2dId
));
1389 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1390 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1393 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1395 BindTexture(GL_TEXTURE_CUBE_MAP
,
1396 TestHelper::kServiceDefaultTextureCubemapId
));
1397 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1398 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1401 // Test that default texture 0 is immutable.
1402 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameterf
) {
1408 cmd1
.Init(GL_TEXTURE_2D
, 0);
1409 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1410 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1411 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1414 cmd2
.Init(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1415 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1416 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1421 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1422 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1423 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1424 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1427 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1428 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1429 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1433 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameteri
) {
1439 cmd1
.Init(GL_TEXTURE_2D
, 0);
1440 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1441 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1442 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1445 cmd2
.Init(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1446 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1447 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1452 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1453 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1454 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1455 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1458 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1459 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1460 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1464 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameterfv
) {
1470 cmd1
.Init(GL_TEXTURE_2D
, 0);
1471 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1472 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1473 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1475 GLfloat data
= GL_NEAREST
;
1476 TexParameterfvImmediate
& cmd2
=
1477 *GetImmediateAs
<TexParameterfvImmediate
>();
1478 cmd2
.Init(GL_TEXTURE_2D
,
1479 GL_TEXTURE_MAG_FILTER
,
1481 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1482 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1487 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1488 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1489 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1490 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1492 GLfloat data
= GL_NEAREST
;
1493 TexParameterfvImmediate
& cmd2
=
1494 *GetImmediateAs
<TexParameterfvImmediate
>();
1495 cmd2
.Init(GL_TEXTURE_CUBE_MAP
,
1496 GL_TEXTURE_MAG_FILTER
,
1498 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1499 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1503 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameteriv
) {
1509 cmd1
.Init(GL_TEXTURE_2D
, 0);
1510 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1511 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1512 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1514 GLfloat data
= GL_NEAREST
;
1515 TexParameterfvImmediate
& cmd2
=
1516 *GetImmediateAs
<TexParameterfvImmediate
>();
1517 cmd2
.Init(GL_TEXTURE_2D
,
1518 GL_TEXTURE_MAG_FILTER
,
1520 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1521 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1526 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1527 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1528 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1529 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1531 GLfloat data
= GL_NEAREST
;
1532 TexParameterfvImmediate
& cmd2
=
1533 *GetImmediateAs
<TexParameterfvImmediate
>();
1534 cmd2
.Init(GL_TEXTURE_CUBE_MAP
,
1535 GL_TEXTURE_MAG_FILTER
,
1537 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1538 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1542 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexImage2D
) {
1547 cmd1
.Init(GL_TEXTURE_2D
, 0);
1548 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1549 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1550 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1553 cmd2
.Init(GL_TEXTURE_2D
,
1561 kSharedMemoryOffset
);
1562 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1563 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1566 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexSubImage2D
) {
1571 cmd1
.Init(GL_TEXTURE_2D
, 0);
1572 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1573 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1574 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1577 cmd2
.Init(GL_TEXTURE_2D
,
1586 kSharedMemoryOffset
,
1588 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1589 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1592 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleBindTexture
) {
1594 init
.extensions
= "GL_ARB_texture_rectangle";
1595 init
.bind_generates_resource
= true;
1597 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_RECTANGLE_ARB
, kNewServiceId
));
1598 EXPECT_CALL(*gl_
, GenTextures(1, _
))
1599 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
));
1601 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, kNewClientId
);
1602 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1603 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1604 Texture
* texture
= GetTexture(kNewClientId
)->texture();
1605 EXPECT_TRUE(texture
!= NULL
);
1606 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1609 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleGetBinding
) {
1611 init
.extensions
= "GL_ARB_texture_rectangle";
1612 init
.bind_generates_resource
= true;
1615 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1617 EXPECT_CALL(*gl_
, GetError())
1618 .WillOnce(Return(GL_NO_ERROR
))
1619 .WillOnce(Return(GL_NO_ERROR
))
1620 .RetiresOnSaturation();
1621 typedef GetIntegerv::Result Result
;
1622 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1624 GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB
, result
->GetData()))
1628 cmd
.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB
,
1630 shared_memory_offset_
);
1631 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1632 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(
1633 GL_TEXTURE_BINDING_RECTANGLE_ARB
),
1634 result
->GetNumResults());
1635 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1636 EXPECT_EQ(client_texture_id_
, (uint32
)result
->GetData()[0]);
1639 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTextureDefaults
) {
1641 init
.extensions
= "GL_ARB_texture_rectangle";
1642 init
.bind_generates_resource
= true;
1645 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1647 Texture
* texture
= GetTexture(client_texture_id_
)->texture();
1648 EXPECT_TRUE(texture
!= NULL
);
1649 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1650 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1651 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1652 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1655 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTextureParam
) {
1657 init
.extensions
= "GL_ARB_texture_rectangle";
1658 init
.bind_generates_resource
= true;
1662 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1666 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
));
1669 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
));
1673 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
));
1677 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
));
1679 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1680 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1681 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1683 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
1684 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1685 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1687 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
1688 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1689 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1691 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
1692 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1693 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1695 Texture
* texture
= GetTexture(client_texture_id_
)->texture();
1696 EXPECT_TRUE(texture
!= NULL
);
1697 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1698 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1699 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1700 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1703 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTextureParamInvalid
) {
1705 init
.extensions
= "GL_ARB_texture_rectangle";
1706 init
.bind_generates_resource
= true;
1710 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1713 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
,
1714 GL_TEXTURE_MIN_FILTER
,
1715 GL_NEAREST_MIPMAP_NEAREST
);
1716 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1717 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1719 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
1720 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1721 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1723 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
1724 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1725 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1727 Texture
* texture
= GetTexture(client_texture_id_
)->texture();
1728 EXPECT_TRUE(texture
!= NULL
);
1729 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1730 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1731 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1732 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1735 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTexImage2DError
) {
1737 init
.extensions
= "GL_ARB_texture_rectangle";
1738 init
.bind_generates_resource
= true;
1741 GLenum target
= GL_TEXTURE_RECTANGLE_ARB
;
1743 GLenum internal_format
= GL_RGBA
;
1746 GLenum format
= GL_RGBA
;
1747 GLenum type
= GL_UNSIGNED_BYTE
;
1749 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1750 ASSERT_TRUE(GetTexture(client_texture_id_
) != NULL
);
1760 kSharedMemoryOffset
);
1761 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1763 // TexImage2D is not allowed with GL_TEXTURE_RECTANGLE_ARB targets.
1764 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1767 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DClearsAfterTexImage2DNULL
) {
1769 init
.gl_version
= "opengl es 2.0";
1770 init
.has_alpha
= true;
1771 init
.has_depth
= true;
1772 init
.request_alpha
= true;
1773 init
.request_depth
= true;
1776 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1778 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1779 SetupClearTextureExpectations(kServiceTextureId
,
1790 TexSubImage2D(GL_TEXTURE_2D
,
1798 shared_memory_address_
))
1800 .RetiresOnSaturation();
1802 cmd
.Init(GL_TEXTURE_2D
,
1811 kSharedMemoryOffset
,
1813 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1814 // Test if we call it again it does not clear.
1816 TexSubImage2D(GL_TEXTURE_2D
,
1824 shared_memory_address_
))
1826 .RetiresOnSaturation();
1827 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1830 TEST_P(GLES2DecoderTest
, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData
) {
1831 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1833 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1834 DoTexImage2D(GL_TEXTURE_2D
,
1843 kSharedMemoryOffset
);
1845 TexSubImage2D(GL_TEXTURE_2D
,
1853 shared_memory_address_
))
1855 .RetiresOnSaturation();
1857 cmd
.Init(GL_TEXTURE_2D
,
1866 kSharedMemoryOffset
,
1868 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1869 // Test if we call it again it does not clear.
1871 TexSubImage2D(GL_TEXTURE_2D
,
1879 shared_memory_address_
))
1881 .RetiresOnSaturation();
1882 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1886 GLES2DecoderManualInitTest
,
1887 TexSubImage2DDoesNotClearAfterTexImage2DNULLThenDataWithTexImage2DIsFaster
) {
1888 base::CommandLine
command_line(0, NULL
);
1889 command_line
.AppendSwitchASCII(
1890 switches::kGpuDriverBugWorkarounds
,
1891 base::IntToString(gpu::TEXSUBIMAGE_FASTER_THAN_TEXIMAGE
));
1893 init
.bind_generates_resource
= true;
1894 InitDecoderWithCommandLine(init
, &command_line
);
1895 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1897 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1900 // Uses texSubimage internally because the above workaround is active and
1901 // the update is for the full size of the texture.
1904 GL_TEXTURE_2D
, 0, 0, 0, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
1906 .RetiresOnSaturation();
1907 cmds::TexImage2D cmd
;
1908 cmd
.Init(GL_TEXTURE_2D
,
1916 kSharedMemoryOffset
);
1917 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1921 TexSubImage2D(GL_TEXTURE_2D
,
1929 shared_memory_address_
))
1931 .RetiresOnSaturation();
1933 cmd
.Init(GL_TEXTURE_2D
,
1942 kSharedMemoryOffset
,
1944 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1945 // Test if we call it again it does not clear.
1947 TexSubImage2D(GL_TEXTURE_2D
,
1955 shared_memory_address_
))
1957 .RetiresOnSaturation();
1958 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1961 TEST_P(GLES2DecoderTest
, TexSubImage2DClearsAfterTexImage2DWithDataThenNULL
) {
1962 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1963 // Put in data (so it should be marked as cleared)
1964 DoTexImage2D(GL_TEXTURE_2D
,
1973 kSharedMemoryOffset
);
1977 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1978 // It won't actually call TexImage2D, just mark it as uncleared.
1979 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
1980 // Next call to TexSubImage2d should clear.
1981 SetupClearTextureExpectations(kServiceTextureId
,
1992 TexSubImage2D(GL_TEXTURE_2D
,
2000 shared_memory_address_
))
2002 .RetiresOnSaturation();
2004 cmd
.Init(GL_TEXTURE_2D
,
2013 kSharedMemoryOffset
,
2015 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2018 TEST_P(GLES2DecoderTest
, CopyTexImage2DMarksTextureAsCleared
) {
2019 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2021 TextureManager
* manager
= group().texture_manager();
2022 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2023 ASSERT_TRUE(texture_ref
!= NULL
);
2024 Texture
* texture
= texture_ref
->texture();
2026 EXPECT_CALL(*gl_
, GetError())
2027 .WillOnce(Return(GL_NO_ERROR
))
2028 .RetiresOnSaturation();
2029 EXPECT_CALL(*gl_
, CopyTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 0, 0, 1, 1, 0))
2031 .RetiresOnSaturation();
2032 EXPECT_CALL(*gl_
, GetError())
2033 .WillOnce(Return(GL_NO_ERROR
))
2034 .RetiresOnSaturation();
2036 cmd
.Init(GL_TEXTURE_2D
, 0, GL_RGBA
, 0, 0, 1, 1);
2037 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2039 EXPECT_TRUE(texture
->SafeToRenderFrom());
2042 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DClearsUnclearedTexture
) {
2043 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2045 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2047 SetupClearTextureExpectations(kServiceTextureId
,
2057 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 1, 1))
2059 .RetiresOnSaturation();
2060 CopyTexSubImage2D cmd
;
2061 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 1, 1);
2062 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2064 TextureManager
* manager
= group().texture_manager();
2065 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2066 ASSERT_TRUE(texture_ref
!= NULL
);
2067 Texture
* texture
= texture_ref
->texture();
2068 EXPECT_TRUE(texture
->SafeToRenderFrom());
2071 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DClearsUnclearedBackBufferSizedTexture
) {
2072 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2073 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, kBackBufferWidth
, kBackBufferHeight
,
2074 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2076 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0,
2077 kBackBufferWidth
, kBackBufferHeight
))
2079 .RetiresOnSaturation();
2080 CopyTexSubImage2D cmd
;
2081 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, kBackBufferWidth
, kBackBufferHeight
);
2082 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2084 TextureManager
* manager
= group().texture_manager();
2085 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2086 ASSERT_TRUE(texture_ref
!= NULL
);
2087 Texture
* texture
= texture_ref
->texture();
2088 EXPECT_TRUE(texture
->SafeToRenderFrom());
2091 TEST_P(GLES2DecoderManualInitTest
, CompressedImage2DMarksTextureAsCleared
) {
2093 init
.extensions
= "GL_EXT_texture_compression_s3tc";
2094 init
.bind_generates_resource
= true;
2097 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2098 EXPECT_CALL(*gl_
, GetError())
2099 .WillOnce(Return(GL_NO_ERROR
))
2100 .RetiresOnSaturation();
2103 CompressedTexImage2D(
2104 GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, 4, 4, 0, 8, _
))
2106 .RetiresOnSaturation();
2107 EXPECT_CALL(*gl_
, GetError())
2108 .WillOnce(Return(GL_NO_ERROR
))
2109 .RetiresOnSaturation();
2110 CompressedTexImage2D cmd
;
2111 cmd
.Init(GL_TEXTURE_2D
,
2113 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
2118 kSharedMemoryOffset
);
2119 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2120 TextureManager
* manager
= group().texture_manager();
2121 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2122 EXPECT_TRUE(texture_ref
->texture()->SafeToRenderFrom());
2125 TEST_P(GLES2DecoderTest
, TextureUsageAngleExtNotEnabledByDefault
) {
2126 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2130 GL_TEXTURE_2D
, GL_TEXTURE_USAGE_ANGLE
, GL_FRAMEBUFFER_ATTACHMENT_ANGLE
);
2131 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2132 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
2135 TEST_P(GLES2DecoderTest
, ProduceAndConsumeTextureCHROMIUM
) {
2136 Mailbox mailbox
= Mailbox::Generate();
2138 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2140 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2142 GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 4, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2143 TextureRef
* texture_ref
=
2144 group().texture_manager()->GetTexture(client_texture_id_
);
2145 ASSERT_TRUE(texture_ref
!= NULL
);
2146 Texture
* texture
= texture_ref
->texture();
2147 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2149 ProduceTextureCHROMIUMImmediate
& produce_cmd
=
2150 *GetImmediateAs
<ProduceTextureCHROMIUMImmediate
>();
2151 produce_cmd
.Init(GL_TEXTURE_2D
, mailbox
.name
);
2152 EXPECT_EQ(error::kNoError
,
2153 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2154 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2156 // Texture didn't change.
2160 GLenum internal_format
;
2163 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2164 EXPECT_EQ(3, width
);
2165 EXPECT_EQ(1, height
);
2166 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2167 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2168 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2171 texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
, nullptr));
2172 EXPECT_EQ(2, width
);
2173 EXPECT_EQ(4, height
);
2174 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2175 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2176 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2178 // Service ID has not changed.
2179 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2181 // Create new texture for consume.
2182 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2183 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
2184 .RetiresOnSaturation();
2185 DoBindTexture(GL_TEXTURE_2D
, kNewClientId
, kNewServiceId
);
2187 // Assigns and binds original service size texture ID.
2188 EXPECT_CALL(*gl_
, DeleteTextures(1, _
)).Times(1).RetiresOnSaturation();
2189 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2191 .RetiresOnSaturation();
2193 ConsumeTextureCHROMIUMImmediate
& consume_cmd
=
2194 *GetImmediateAs
<ConsumeTextureCHROMIUMImmediate
>();
2195 consume_cmd
.Init(GL_TEXTURE_2D
, mailbox
.name
);
2196 EXPECT_EQ(error::kNoError
,
2197 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
2198 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2200 // Texture is redefined.
2202 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2203 EXPECT_EQ(3, width
);
2204 EXPECT_EQ(1, height
);
2205 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2206 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2207 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2210 texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
, nullptr));
2211 EXPECT_EQ(2, width
);
2212 EXPECT_EQ(4, height
);
2213 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2214 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2215 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2217 // Service ID is restored.
2218 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2221 TEST_P(GLES2DecoderTest
, ProduceAndConsumeDirectTextureCHROMIUM
) {
2222 Mailbox mailbox
= Mailbox::Generate();
2224 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2226 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2228 GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 4, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2229 TextureRef
* texture_ref
=
2230 group().texture_manager()->GetTexture(client_texture_id_
);
2231 ASSERT_TRUE(texture_ref
!= NULL
);
2232 Texture
* texture
= texture_ref
->texture();
2233 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2235 ProduceTextureDirectCHROMIUMImmediate
& produce_cmd
=
2236 *GetImmediateAs
<ProduceTextureDirectCHROMIUMImmediate
>();
2237 produce_cmd
.Init(client_texture_id_
, GL_TEXTURE_2D
, mailbox
.name
);
2238 EXPECT_EQ(error::kNoError
,
2239 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2240 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2242 // Texture didn't change.
2246 GLenum internal_format
;
2249 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2250 EXPECT_EQ(3, width
);
2251 EXPECT_EQ(1, height
);
2252 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2253 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2254 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2257 texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
, nullptr));
2258 EXPECT_EQ(2, width
);
2259 EXPECT_EQ(4, height
);
2260 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2261 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2262 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2264 // Service ID has not changed.
2265 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2267 // Consume the texture into a new client ID.
2268 GLuint new_texture_id
= kNewClientId
;
2269 CreateAndConsumeTextureCHROMIUMImmediate
& consume_cmd
=
2270 *GetImmediateAs
<CreateAndConsumeTextureCHROMIUMImmediate
>();
2271 consume_cmd
.Init(GL_TEXTURE_2D
, new_texture_id
, mailbox
.name
);
2272 EXPECT_EQ(error::kNoError
,
2273 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
2274 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2276 // Make sure the new client ID is associated with the produced service ID.
2277 texture_ref
= group().texture_manager()->GetTexture(new_texture_id
);
2278 ASSERT_TRUE(texture_ref
!= NULL
);
2279 texture
= texture_ref
->texture();
2280 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2282 DoBindTexture(GL_TEXTURE_2D
, kNewClientId
, kServiceTextureId
);
2284 // Texture is redefined.
2286 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2287 EXPECT_EQ(3, width
);
2288 EXPECT_EQ(1, height
);
2289 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2290 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2291 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2294 texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
, nullptr));
2295 EXPECT_EQ(2, width
);
2296 EXPECT_EQ(4, height
);
2297 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2298 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2299 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2302 TEST_P(GLES2DecoderTest
, ProduceTextureCHROMIUMInvalidTarget
) {
2303 Mailbox mailbox
= Mailbox::Generate();
2305 DoBindTexture(GL_TEXTURE_CUBE_MAP
, client_texture_id_
, kServiceTextureId
);
2307 GL_TEXTURE_CUBE_MAP_POSITIVE_X
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
,
2308 GL_UNSIGNED_BYTE
, 0, 0);
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 ProduceTextureDirectCHROMIUMImmediate
& produce_cmd
=
2316 *GetImmediateAs
<ProduceTextureDirectCHROMIUMImmediate
>();
2317 produce_cmd
.Init(client_texture_id_
, GL_TEXTURE_2D
, mailbox
.name
);
2318 EXPECT_EQ(error::kNoError
,
2319 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2321 // ProduceTexture should fail it the texture and produce targets don't match.
2322 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2325 TEST_P(GLES2DecoderTest
, CreateAndConsumeTextureCHROMIUMInvalidMailbox
) {
2326 // Attempt to consume the mailbox when no texture has been produced with it.
2327 Mailbox mailbox
= Mailbox::Generate();
2328 GLuint new_texture_id
= kNewClientId
;
2330 EXPECT_CALL(*gl_
, GenTextures(1, _
))
2331 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
2332 .RetiresOnSaturation();
2333 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, _
))
2335 .RetiresOnSaturation();
2336 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
2338 .RetiresOnSaturation();
2340 CreateAndConsumeTextureCHROMIUMImmediate
& consume_cmd
=
2341 *GetImmediateAs
<CreateAndConsumeTextureCHROMIUMImmediate
>();
2342 consume_cmd
.Init(GL_TEXTURE_2D
, new_texture_id
, mailbox
.name
);
2343 EXPECT_EQ(error::kNoError
,
2344 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
2346 // CreateAndConsumeTexture should fail if the mailbox isn't associated with a
2348 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2350 // Make sure the new client_id is associated with a texture ref even though
2351 // CreateAndConsumeTexture failed.
2352 TextureRef
* texture_ref
=
2353 group().texture_manager()->GetTexture(new_texture_id
);
2354 ASSERT_TRUE(texture_ref
!= NULL
);
2355 Texture
* texture
= texture_ref
->texture();
2356 // New texture should have the correct target type.
2357 EXPECT_TRUE(texture
->target() == GL_TEXTURE_2D
);
2358 // New texture should have a valid service_id.
2359 EXPECT_EQ(kNewServiceId
, texture
->service_id());
2362 TEST_P(GLES2DecoderTest
, CreateAndConsumeTextureCHROMIUMInvalidTarget
) {
2363 Mailbox mailbox
= Mailbox::Generate();
2365 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2366 TextureRef
* texture_ref
=
2367 group().texture_manager()->GetTexture(client_texture_id_
);
2368 ASSERT_TRUE(texture_ref
!= NULL
);
2370 ProduceTextureDirectCHROMIUMImmediate
& produce_cmd
=
2371 *GetImmediateAs
<ProduceTextureDirectCHROMIUMImmediate
>();
2372 produce_cmd
.Init(client_texture_id_
, GL_TEXTURE_2D
, mailbox
.name
);
2373 EXPECT_EQ(error::kNoError
,
2374 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2375 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2377 EXPECT_CALL(*gl_
, GenTextures(1, _
))
2378 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
2379 .RetiresOnSaturation();
2380 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, _
))
2382 .RetiresOnSaturation();
2383 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
2385 .RetiresOnSaturation();
2387 // Attempt to consume the mailbox with a different target.
2388 GLuint new_texture_id
= kNewClientId
;
2389 CreateAndConsumeTextureCHROMIUMImmediate
& consume_cmd
=
2390 *GetImmediateAs
<CreateAndConsumeTextureCHROMIUMImmediate
>();
2391 consume_cmd
.Init(GL_TEXTURE_CUBE_MAP
, new_texture_id
, mailbox
.name
);
2392 EXPECT_EQ(error::kNoError
,
2393 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
2395 // CreateAndConsumeTexture should fail if the produced texture had a different
2397 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2399 // Make sure the new client_id is associated with a texture ref even though
2400 // CreateAndConsumeTexture failed.
2401 texture_ref
= group().texture_manager()->GetTexture(new_texture_id
);
2402 ASSERT_TRUE(texture_ref
!= NULL
);
2403 Texture
* texture
= texture_ref
->texture();
2404 // New texture should have the correct target type.
2405 EXPECT_TRUE(texture
->target() == GL_TEXTURE_CUBE_MAP
);
2406 // New texture should have a valid service_id.
2407 EXPECT_EQ(kNewServiceId
, texture
->service_id());
2409 // Make sure the client_id did not become associated with the produced texture
2411 EXPECT_NE(kServiceTextureId
, texture
->service_id());
2414 TEST_P(GLES2DecoderManualInitTest
, DepthTextureBadArgs
) {
2416 init
.extensions
= "GL_ANGLE_depth_texture";
2417 init
.gl_version
= "opengl es 2.0";
2418 init
.has_depth
= true;
2419 init
.has_stencil
= true;
2420 init
.request_depth
= true;
2421 init
.request_stencil
= true;
2422 init
.bind_generates_resource
= true;
2425 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2426 // Check trying to upload data fails.
2428 tex_cmd
.Init(GL_TEXTURE_2D
,
2436 kSharedMemoryOffset
);
2437 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
2438 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2440 tex_cmd
.Init(GL_TEXTURE_2D
,
2449 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
2450 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2451 // Make a 1 pixel depth texture.
2452 DoTexImage2D(GL_TEXTURE_2D
,
2462 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2464 // Check that trying to update it fails.
2465 TexSubImage2D tex_sub_cmd
;
2466 tex_sub_cmd
.Init(GL_TEXTURE_2D
,
2475 kSharedMemoryOffset
,
2477 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_sub_cmd
));
2478 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2480 // Check that trying to CopyTexImage2D fails
2481 CopyTexImage2D copy_tex_cmd
;
2482 copy_tex_cmd
.Init(GL_TEXTURE_2D
, 0, GL_DEPTH_COMPONENT
, 0, 0, 1, 1);
2483 EXPECT_EQ(error::kNoError
, ExecuteCmd(copy_tex_cmd
));
2484 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2486 // Check that trying to CopyTexSubImage2D fails
2487 CopyTexSubImage2D copy_sub_cmd
;
2488 copy_sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 1, 1);
2489 EXPECT_EQ(error::kNoError
, ExecuteCmd(copy_sub_cmd
));
2490 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2493 TEST_P(GLES2DecoderManualInitTest
, GenerateMipmapDepthTexture
) {
2495 init
.extensions
= "GL_ANGLE_depth_texture";
2496 init
.gl_version
= "opengl es 2.0";
2497 init
.has_depth
= true;
2498 init
.has_stencil
= true;
2499 init
.request_depth
= true;
2500 init
.request_stencil
= true;
2501 init
.bind_generates_resource
= true;
2503 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2504 DoTexImage2D(GL_TEXTURE_2D
,
2515 cmd
.Init(GL_TEXTURE_2D
);
2516 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2517 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2520 TEST_P(GLES2DecoderTest
, BindTexImage2DCHROMIUM
) {
2521 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2523 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2524 TextureRef
* texture_ref
=
2525 group().texture_manager()->GetTexture(client_texture_id_
);
2526 ASSERT_TRUE(texture_ref
!= NULL
);
2527 Texture
* texture
= texture_ref
->texture();
2528 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2530 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2531 GetImageManager()->AddImage(image
.get(), 1);
2532 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL
);
2537 GLenum internal_format
;
2540 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2541 EXPECT_EQ(3, width
);
2542 EXPECT_EQ(1, height
);
2543 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2544 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2545 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2546 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2548 // Bind image to texture.
2549 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2550 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2552 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2553 // Image should now be set.
2554 EXPECT_FALSE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2556 // Define new texture image.
2558 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2560 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2561 // Image should no longer be set.
2562 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2565 TEST_P(GLES2DecoderTest
, BindTexImage2DCHROMIUMCubeMapNotAllowed
) {
2566 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2567 GetImageManager()->AddImage(image
.get(), 1);
2568 DoBindTexture(GL_TEXTURE_CUBE_MAP
, client_texture_id_
, kServiceTextureId
);
2570 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd
;
2571 bind_tex_image_2d_cmd
.Init(GL_TEXTURE_CUBE_MAP
, 1);
2572 EXPECT_EQ(error::kNoError
, ExecuteCmd(bind_tex_image_2d_cmd
));
2573 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
2576 TEST_P(GLES2DecoderTest
, OrphanGLImageWithTexImage2D
) {
2577 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2578 GetImageManager()->AddImage(image
.get(), 1);
2579 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2581 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2583 TextureRef
* texture_ref
=
2584 group().texture_manager()->GetTexture(client_texture_id_
);
2585 ASSERT_TRUE(texture_ref
!= NULL
);
2586 Texture
* texture
= texture_ref
->texture();
2588 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2590 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2591 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2594 TEST_P(GLES2DecoderTest
, GLImageAttachedAfterSubTexImage2D
) {
2595 // Specifically tests that TexSubImage2D is not optimized to TexImage2D
2596 // in the presence of image attachments.
2598 feature_info()->workarounds().texsubimage_faster_than_teximage
);
2600 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2601 GetImageManager()->AddImage(image
.get(), 1);
2602 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2604 GLenum target
= GL_TEXTURE_2D
;
2611 GLenum format
= GL_RGBA
;
2612 GLenum type
= GL_UNSIGNED_BYTE
;
2613 uint32_t pixels_shm_id
= kSharedMemoryId
;
2614 uint32_t pixels_shm_offset
= kSharedMemoryOffset
;
2615 GLboolean internal
= 0;
2617 // Define texture first.
2618 DoTexImage2D(target
, level
, format
, width
, height
, border
, format
, type
,
2619 pixels_shm_id
, pixels_shm_offset
);
2621 // Bind texture to GLImage.
2622 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2625 TextureRef
* texture_ref
=
2626 group().texture_manager()->GetTexture(client_texture_id_
);
2627 ASSERT_TRUE(texture_ref
!= NULL
);
2628 Texture
* texture
= texture_ref
->texture();
2629 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2631 // TexSubImage2D should not unbind GLImage.
2632 EXPECT_CALL(*gl_
, TexSubImage2D(target
, level
, xoffset
, yoffset
, width
,
2633 height
, format
, type
, _
))
2635 .RetiresOnSaturation();
2636 cmds::TexSubImage2D tex_sub_image_2d_cmd
;
2637 tex_sub_image_2d_cmd
.Init(target
, level
, xoffset
, yoffset
, width
, height
,
2638 format
, type
, pixels_shm_id
, pixels_shm_offset
,
2640 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_sub_image_2d_cmd
));
2641 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2644 TEST_P(GLES2DecoderTest
, GLImageAttachedAfterClearLevel
) {
2645 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2646 GetImageManager()->AddImage(image
.get(), 1);
2647 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2649 GLenum target
= GL_TEXTURE_2D
;
2656 GLenum format
= GL_RGBA
;
2657 GLenum type
= GL_UNSIGNED_BYTE
;
2658 uint32_t pixels_shm_id
= kSharedMemoryId
;
2659 uint32_t pixels_shm_offset
= kSharedMemoryOffset
;
2661 // Define texture first.
2662 DoTexImage2D(target
, level
, format
, width
, height
, border
, format
, type
,
2663 pixels_shm_id
, pixels_shm_offset
);
2665 // Bind texture to GLImage.
2666 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2669 TextureRef
* texture_ref
=
2670 group().texture_manager()->GetTexture(client_texture_id_
);
2671 ASSERT_TRUE(texture_ref
!= NULL
);
2672 Texture
* texture
= texture_ref
->texture();
2673 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2675 // ClearLevel should use glTexSubImage2D to avoid unbinding GLImage.
2676 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2678 .RetiresOnSaturation();
2679 EXPECT_CALL(*gl_
, TexSubImage2D(target
, level
, xoffset
, yoffset
, width
,
2680 height
, format
, type
, _
))
2682 .RetiresOnSaturation();
2683 GetDecoder()->ClearLevel(texture
, target
, level
, format
, format
, type
, width
,
2685 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2688 TEST_P(GLES2DecoderTest
, ReleaseTexImage2DCHROMIUM
) {
2689 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2691 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2692 TextureRef
* texture_ref
=
2693 group().texture_manager()->GetTexture(client_texture_id_
);
2694 ASSERT_TRUE(texture_ref
!= NULL
);
2695 Texture
* texture
= texture_ref
->texture();
2696 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2698 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2699 GetImageManager()->AddImage(image
.get(), 1);
2700 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL
);
2705 GLenum internal_format
;
2708 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2709 EXPECT_EQ(3, width
);
2710 EXPECT_EQ(1, height
);
2711 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2712 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2713 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2714 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2716 // Bind image to texture.
2717 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2718 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2720 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2721 // Image should now be set.
2722 EXPECT_FALSE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2724 // Release image from texture.
2725 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2726 EXPECT_CALL(*gl_
, GetError())
2727 .WillOnce(Return(GL_NO_ERROR
))
2728 .WillOnce(Return(GL_NO_ERROR
))
2729 .RetiresOnSaturation();
2730 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd
;
2731 release_tex_image_2d_cmd
.Init(GL_TEXTURE_2D
, 1);
2732 EXPECT_EQ(error::kNoError
, ExecuteCmd(release_tex_image_2d_cmd
));
2734 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2735 // Image should no longer be set.
2736 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2739 class MockGLImage
: public gfx::GLImage
{
2743 // Overridden from gfx::GLImage:
2744 MOCK_METHOD0(GetSize
, gfx::Size());
2745 MOCK_METHOD0(GetInternalFormat
, unsigned());
2746 MOCK_METHOD1(Destroy
, void(bool));
2747 MOCK_METHOD1(BindTexImage
, bool(unsigned));
2748 MOCK_METHOD1(ReleaseTexImage
, void(unsigned));
2749 MOCK_METHOD3(CopyTexSubImage
,
2750 bool(unsigned, const gfx::Point
&, const gfx::Rect
&));
2751 MOCK_METHOD0(WillUseTexImage
, void());
2752 MOCK_METHOD0(DidUseTexImage
, void());
2753 MOCK_METHOD0(WillModifyTexImage
, void());
2754 MOCK_METHOD0(DidModifyTexImage
, void());
2755 MOCK_METHOD5(ScheduleOverlayPlane
, bool(gfx::AcceleratedWidget
,
2757 gfx::OverlayTransform
,
2759 const gfx::RectF
&));
2762 virtual ~MockGLImage() {}
2765 TEST_P(GLES2DecoderWithShaderTest
, UseTexImage
) {
2766 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2767 DoTexImage2D(GL_TEXTURE_2D
,
2776 kSharedMemoryOffset
);
2778 TextureRef
* texture_ref
=
2779 group().texture_manager()->GetTexture(client_texture_id_
);
2780 ASSERT_TRUE(texture_ref
!= NULL
);
2781 Texture
* texture
= texture_ref
->texture();
2782 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2784 const int32 kImageId
= 1;
2785 scoped_refptr
<MockGLImage
> image(new MockGLImage
);
2786 GetImageManager()->AddImage(image
.get(), kImageId
);
2788 // Bind image to texture.
2789 EXPECT_CALL(*image
.get(), BindTexImage(GL_TEXTURE_2D
))
2791 .WillOnce(Return(true))
2792 .RetiresOnSaturation();
2793 EXPECT_CALL(*image
.get(), GetSize())
2795 .WillOnce(Return(gfx::Size(1, 1)))
2796 .RetiresOnSaturation();
2797 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2798 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, kImageId
);
2800 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2801 SetupExpectationsForApplyingDefaultDirtyState();
2803 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2804 EXPECT_CALL(*gl_
, GetError())
2805 .WillOnce(Return(GL_NO_ERROR
))
2806 .WillOnce(Return(GL_NO_ERROR
))
2807 .WillOnce(Return(GL_NO_ERROR
))
2808 .WillOnce(Return(GL_NO_ERROR
))
2809 .RetiresOnSaturation();
2810 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(3).RetiresOnSaturation();
2811 EXPECT_CALL(*image
.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2812 EXPECT_CALL(*image
.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2813 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2815 .RetiresOnSaturation();
2817 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2818 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2819 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2822 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2823 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2824 EXPECT_CALL(*gl_
, GetError())
2825 .WillOnce(Return(GL_NO_ERROR
))
2826 .WillOnce(Return(GL_NO_ERROR
))
2827 .RetiresOnSaturation();
2828 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2829 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2831 .RetiresOnSaturation();
2832 // Image will be 'in use' as long as bound to a framebuffer.
2833 EXPECT_CALL(*image
.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2835 FramebufferTexture2DEXT(GL_FRAMEBUFFER
,
2836 GL_COLOR_ATTACHMENT0
,
2841 .RetiresOnSaturation();
2842 EXPECT_CALL(*gl_
, GetError())
2843 .WillOnce(Return(GL_NO_ERROR
))
2844 .WillOnce(Return(GL_NO_ERROR
))
2845 .RetiresOnSaturation();
2846 FramebufferTexture2D fbtex_cmd
;
2847 fbtex_cmd
.Init(GL_FRAMEBUFFER
,
2848 GL_COLOR_ATTACHMENT0
,
2850 client_texture_id_
);
2851 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbtex_cmd
));
2852 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2854 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2855 EXPECT_CALL(*gl_
, GetError())
2856 .WillOnce(Return(GL_NO_ERROR
))
2857 .WillOnce(Return(GL_NO_ERROR
))
2858 .RetiresOnSaturation();
2860 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
2861 GL_COLOR_ATTACHMENT0
,
2863 kServiceRenderbufferId
))
2865 .RetiresOnSaturation();
2866 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2867 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2869 .RetiresOnSaturation();
2870 // Image should no longer be 'in use' after being unbound from framebuffer.
2871 EXPECT_CALL(*image
.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2872 EXPECT_CALL(*gl_
, GetError())
2873 .WillOnce(Return(GL_NO_ERROR
))
2874 .WillOnce(Return(GL_NO_ERROR
))
2875 .RetiresOnSaturation();
2876 FramebufferRenderbuffer fbrb_cmd
;
2877 fbrb_cmd
.Init(GL_FRAMEBUFFER
,
2878 GL_COLOR_ATTACHMENT0
,
2880 client_renderbuffer_id_
);
2881 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbrb_cmd
));
2884 TEST_P(GLES2DecoderManualInitTest
, DrawWithGLImageExternal
) {
2886 init
.extensions
= "GL_OES_EGL_image_external";
2887 init
.gl_version
= "opengl es 2.0";
2888 init
.has_alpha
= true;
2889 init
.has_depth
= true;
2890 init
.request_alpha
= true;
2891 init
.request_depth
= true;
2892 init
.bind_generates_resource
= true;
2895 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
2896 scoped_refptr
<MockGLImage
> image(new MockGLImage
);
2897 group().texture_manager()->SetTarget(texture_ref
, GL_TEXTURE_EXTERNAL_OES
);
2898 group().texture_manager()->SetLevelInfo(texture_ref
,
2899 GL_TEXTURE_EXTERNAL_OES
,
2909 group().texture_manager()->SetLevelImage(
2910 texture_ref
, GL_TEXTURE_EXTERNAL_OES
, 0, image
.get());
2912 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
2913 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2915 SetupSamplerExternalProgram();
2917 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
2918 SetupExpectationsForApplyingDefaultDirtyState();
2919 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref
));
2922 EXPECT_CALL(*gl_
, GetError())
2923 .WillOnce(Return(GL_NO_ERROR
))
2924 .RetiresOnSaturation();
2925 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2926 EXPECT_CALL(*image
.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2927 EXPECT_CALL(*gl_
, GetError())
2928 .WillOnce(Return(GL_NO_ERROR
))
2929 .RetiresOnSaturation();
2930 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(1);
2931 EXPECT_CALL(*gl_
, GetError())
2932 .WillOnce(Return(GL_NO_ERROR
))
2933 .RetiresOnSaturation();
2934 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2935 EXPECT_CALL(*image
.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2936 EXPECT_CALL(*gl_
, GetError())
2937 .WillOnce(Return(GL_NO_ERROR
))
2938 .RetiresOnSaturation();
2939 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2941 cmd
.Init(GL_TRIANGLES
,
2942 kValidIndexRangeCount
,
2944 kValidIndexRangeStart
* 2);
2945 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2946 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2949 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatOnGLES2
) {
2951 init
.extensions
= "GL_OES_texture_float";
2952 init
.gl_version
= "opengl es 2.0";
2954 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2955 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2956 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 16, 17, 0, GL_RGB
, GL_FLOAT
, 0, 0);
2958 GL_TEXTURE_2D
, 0, GL_LUMINANCE
, 16, 17, 0, GL_LUMINANCE
, GL_FLOAT
, 0, 0);
2959 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, 16, 17, 0, GL_ALPHA
, GL_FLOAT
, 0, 0);
2960 DoTexImage2D(GL_TEXTURE_2D
,
2972 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatOnGLES3
) {
2974 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
2975 init
.gl_version
= "opengl es 3.0";
2977 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2978 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2979 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 16, 17, 0, GL_RGB
, GL_FLOAT
, 0, 0);
2981 GL_TEXTURE_2D
, 0, GL_RGBA32F
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2983 GL_TEXTURE_2D
, 0, GL_LUMINANCE
, 16, 17, 0, GL_LUMINANCE
, GL_FLOAT
, 0, 0);
2984 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, 16, 17, 0, GL_ALPHA
, GL_FLOAT
, 0, 0);
2985 DoTexImage2D(GL_TEXTURE_2D
,
2997 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DFloatOnGLES3
) {
2999 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
3000 init
.gl_version
= "opengl es 3.0";
3002 const int kWidth
= 8;
3003 const int kHeight
= 4;
3004 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
3005 DoTexImage2D(GL_TEXTURE_2D
,
3016 TexImage2D(GL_TEXTURE_2D
,
3024 shared_memory_address_
))
3026 .RetiresOnSaturation();
3028 cmd
.Init(GL_TEXTURE_2D
,
3037 kSharedMemoryOffset
,
3039 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3040 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3043 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DFloatDoesClearOnGLES3
) {
3045 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
3046 init
.gl_version
= "opengl es 3.0";
3048 const int kWidth
= 8;
3049 const int kHeight
= 4;
3050 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
3051 DoTexImage2D(GL_TEXTURE_2D
,
3061 SetupClearTextureExpectations(kServiceTextureId
,
3072 TexSubImage2D(GL_TEXTURE_2D
,
3080 shared_memory_address_
))
3082 .RetiresOnSaturation();
3084 cmd
.Init(GL_TEXTURE_2D
,
3093 kSharedMemoryOffset
,
3095 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3096 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3099 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatConvertsFormatDesktop
) {
3101 init
.extensions
= "GL_ARB_texture_float";
3103 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
3105 GL_TEXTURE_2D
, 0, GL_RGBA32F
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
3106 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB32F
, 16, 17, 0, GL_RGB
, GL_FLOAT
, 0, 0);
3107 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3118 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3129 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3139 GL_LUMINANCE32F_ARB
);
3140 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3151 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3161 GL_LUMINANCE_ALPHA32F_ARB
);
3164 class GLES2DecoderCompressedFormatsTest
: public GLES2DecoderManualInitTest
{
3166 GLES2DecoderCompressedFormatsTest() {}
3168 static bool ValueInArray(GLint value
, GLint
* array
, GLint count
) {
3169 for (GLint ii
= 0; ii
< count
; ++ii
) {
3170 if (array
[ii
] == value
) {
3177 void CheckFormats(const char* extension
, const GLenum
* formats
, int count
) {
3179 init
.extensions
= extension
;
3180 init
.bind_generates_resource
= true;
3183 EXPECT_CALL(*gl_
, GetError())
3184 .WillOnce(Return(GL_NO_ERROR
))
3185 .WillOnce(Return(GL_NO_ERROR
))
3186 .WillOnce(Return(GL_NO_ERROR
))
3187 .WillOnce(Return(GL_NO_ERROR
))
3188 .RetiresOnSaturation();
3190 typedef GetIntegerv::Result Result
;
3191 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
3194 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
3195 cmd
.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
3197 shared_memory_offset_
);
3198 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3199 EXPECT_EQ(1, result
->GetNumResults());
3200 GLint num_formats
= result
->GetData()[0];
3201 EXPECT_EQ(count
, num_formats
);
3202 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3205 cmd
.Init(GL_COMPRESSED_TEXTURE_FORMATS
,
3207 shared_memory_offset_
);
3208 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3209 EXPECT_EQ(num_formats
, result
->GetNumResults());
3211 for (int i
= 0; i
< count
; ++i
) {
3213 ValueInArray(formats
[i
], result
->GetData(), result
->GetNumResults()));
3216 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3220 INSTANTIATE_TEST_CASE_P(Service
,
3221 GLES2DecoderCompressedFormatsTest
,
3224 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsS3TC
) {
3225 const GLenum formats
[] = {
3226 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
,
3227 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
};
3228 CheckFormats("GL_EXT_texture_compression_s3tc", formats
, 4);
3231 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsATC
) {
3232 const GLenum formats
[] = {GL_ATC_RGB_AMD
, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD
,
3233 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
};
3234 CheckFormats("GL_AMD_compressed_ATC_texture", formats
, 3);
3237 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsPVRTC
) {
3238 const GLenum formats
[] = {
3239 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
,
3240 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
};
3241 CheckFormats("GL_IMG_texture_compression_pvrtc", formats
, 4);
3244 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsETC1
) {
3245 const GLenum formats
[] = {GL_ETC1_RGB8_OES
};
3246 CheckFormats("GL_OES_compressed_ETC1_RGB8_texture", formats
, 1);
3249 TEST_P(GLES2DecoderManualInitTest
, GetNoCompressedTextureFormats
) {
3251 init
.bind_generates_resource
= true;
3254 EXPECT_CALL(*gl_
, GetError())
3255 .WillOnce(Return(GL_NO_ERROR
))
3256 .WillOnce(Return(GL_NO_ERROR
))
3257 .WillOnce(Return(GL_NO_ERROR
))
3258 .WillOnce(Return(GL_NO_ERROR
))
3259 .RetiresOnSaturation();
3261 typedef GetIntegerv::Result Result
;
3262 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
3265 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
3266 cmd
.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
3268 shared_memory_offset_
);
3269 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3270 EXPECT_EQ(1, result
->GetNumResults());
3271 GLint num_formats
= result
->GetData()[0];
3272 EXPECT_EQ(0, num_formats
);
3273 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3277 GL_COMPRESSED_TEXTURE_FORMATS
, shared_memory_id_
, shared_memory_offset_
);
3278 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3279 EXPECT_EQ(num_formats
, result
->GetNumResults());
3281 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3284 // TODO(gman): Complete this test.
3285 // TEST_P(GLES2DecoderTest, CompressedTexImage2DGLError) {
3288 // TODO(gman): CompressedTexImage2D
3290 // TODO(gman): CompressedTexImage2DImmediate
3292 // TODO(gman): CompressedTexSubImage2DImmediate
3294 // TODO(gman): TexImage2D
3296 // TODO(gman): TexImage2DImmediate
3298 // TODO(gman): TexSubImage2DImmediate
3300 } // namespace gles2