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/cmd_buffer_engine.h"
13 #include "gpu/command_buffer/service/context_group.h"
14 #include "gpu/command_buffer/service/context_state.h"
15 #include "gpu/command_buffer/service/gl_surface_mock.h"
16 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
17 #include "gpu/command_buffer/service/image_manager.h"
18 #include "gpu/command_buffer/service/mailbox_manager.h"
19 #include "gpu/command_buffer/service/mocks.h"
20 #include "gpu/command_buffer/service/program_manager.h"
21 #include "gpu/command_buffer/service/test_helper.h"
22 #include "gpu/config/gpu_switches.h"
23 #include "testing/gtest/include/gtest/gtest.h"
24 #include "ui/gl/gl_image_stub.h"
25 #include "ui/gl/gl_implementation.h"
26 #include "ui/gl/gl_mock.h"
27 #include "ui/gl/gl_surface_stub.h"
29 #if !defined(GL_DEPTH24_STENCIL8)
30 #define GL_DEPTH24_STENCIL8 0x88F0
33 using ::gfx::MockGLInterface
;
35 using ::testing::DoAll
;
36 using ::testing::InSequence
;
37 using ::testing::Invoke
;
38 using ::testing::MatcherCast
;
39 using ::testing::Mock
;
40 using ::testing::Pointee
;
41 using ::testing::Return
;
42 using ::testing::SaveArg
;
43 using ::testing::SetArrayArgument
;
44 using ::testing::SetArgumentPointee
;
45 using ::testing::SetArgPointee
;
46 using ::testing::StrEq
;
47 using ::testing::StrictMock
;
54 TEST_P(GLES2DecoderTest
, GenerateMipmapWrongFormatsFails
) {
55 EXPECT_CALL(*gl_
, GenerateMipmapEXT(_
)).Times(0);
56 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
58 GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 17, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
60 cmd
.Init(GL_TEXTURE_2D
);
61 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
62 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
65 TEST_P(GLES2DecoderTest
, GenerateMipmapHandlesOutOfMemory
) {
66 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
67 TextureManager
* manager
= group().texture_manager();
68 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
69 ASSERT_TRUE(texture_ref
!= NULL
);
70 Texture
* texture
= texture_ref
->texture();
74 texture
->GetLevelSize(GL_TEXTURE_2D
, 2, &width
, &height
, nullptr));
75 DoTexImage2D(GL_TEXTURE_2D
,
85 EXPECT_CALL(*gl_
, GenerateMipmapEXT(GL_TEXTURE_2D
)).Times(1);
86 EXPECT_CALL(*gl_
, GetError())
87 .WillOnce(Return(GL_NO_ERROR
))
88 .WillOnce(Return(GL_OUT_OF_MEMORY
))
89 .RetiresOnSaturation();
91 cmd
.Init(GL_TEXTURE_2D
);
92 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
93 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
95 texture
->GetLevelSize(GL_TEXTURE_2D
, 2, &width
, &height
, nullptr));
98 TEST_P(GLES2DecoderTest
, GenerateMipmapClearsUnclearedTexture
) {
99 EXPECT_CALL(*gl_
, GenerateMipmapEXT(_
)).Times(0);
100 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
102 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
103 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
104 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA
,
105 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0, 2, 2);
106 EXPECT_CALL(*gl_
, GenerateMipmapEXT(GL_TEXTURE_2D
));
107 EXPECT_CALL(*gl_
, GetError())
108 .WillOnce(Return(GL_NO_ERROR
))
109 .WillOnce(Return(GL_NO_ERROR
))
110 .RetiresOnSaturation();
112 cmd
.Init(GL_TEXTURE_2D
);
113 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
114 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
117 // Same as GenerateMipmapClearsUnclearedTexture, but with workaround
118 // |set_texture_filters_before_generating_mipmap|.
119 TEST_P(GLES2DecoderManualInitTest
, SetTextureFiltersBeforeGenerateMipmap
) {
120 base::CommandLine
command_line(0, NULL
);
121 command_line
.AppendSwitchASCII(
122 switches::kGpuDriverBugWorkarounds
,
123 base::IntToString(gpu::SET_TEXTURE_FILTER_BEFORE_GENERATING_MIPMAP
));
125 init
.bind_generates_resource
= true;
126 InitDecoderWithCommandLine(init
, &command_line
);
128 EXPECT_CALL(*gl_
, GenerateMipmapEXT(_
)).Times(0);
129 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
131 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
132 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
133 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA
,
134 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0, 2, 2);
138 GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_NEAREST
))
140 .RetiresOnSaturation();
141 EXPECT_CALL(*gl_
, GenerateMipmapEXT(GL_TEXTURE_2D
));
145 GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_LINEAR
))
147 .RetiresOnSaturation();
148 EXPECT_CALL(*gl_
, GetError())
149 .WillOnce(Return(GL_NO_ERROR
))
150 .WillOnce(Return(GL_NO_ERROR
))
151 .RetiresOnSaturation();
153 cmd
.Init(GL_TEXTURE_2D
);
154 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
155 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
158 TEST_P(GLES2DecoderTest
, ActiveTextureValidArgs
) {
159 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE1
));
160 SpecializedSetup
<ActiveTexture
, 0>(true);
162 cmd
.Init(GL_TEXTURE1
);
163 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
164 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
167 TEST_P(GLES2DecoderTest
, ActiveTextureInvalidArgs
) {
168 EXPECT_CALL(*gl_
, ActiveTexture(_
)).Times(0);
169 SpecializedSetup
<ActiveTexture
, 0>(false);
171 cmd
.Init(GL_TEXTURE0
- 1);
172 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
173 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
174 cmd
.Init(kNumTextureUnits
);
175 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
176 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
179 TEST_P(GLES2DecoderTest
, TexSubImage2DValidArgs
) {
180 const int kWidth
= 16;
181 const int kHeight
= 8;
182 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
183 DoTexImage2D(GL_TEXTURE_2D
,
192 kSharedMemoryOffset
);
194 TexSubImage2D(GL_TEXTURE_2D
,
202 shared_memory_address_
))
204 .RetiresOnSaturation();
206 cmd
.Init(GL_TEXTURE_2D
,
217 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
218 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
221 TEST_P(GLES2DecoderTest
, TexSubImage2DBadArgs
) {
222 const int kWidth
= 16;
223 const int kHeight
= 8;
224 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
225 DoTexImage2D(GL_TEXTURE_2D
,
236 cmd
.Init(GL_TEXTURE0
,
247 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
248 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
249 cmd
.Init(GL_TEXTURE_2D
,
260 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
261 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
262 cmd
.Init(GL_TEXTURE_2D
,
273 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
274 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
275 cmd
.Init(GL_TEXTURE_2D
,
286 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
287 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
288 cmd
.Init(GL_TEXTURE_2D
,
299 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
300 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
301 cmd
.Init(GL_TEXTURE_2D
,
312 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
313 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
314 cmd
.Init(GL_TEXTURE_2D
,
325 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
326 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
327 cmd
.Init(GL_TEXTURE_2D
,
338 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
339 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
340 cmd
.Init(GL_TEXTURE_2D
,
351 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
352 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
353 cmd
.Init(GL_TEXTURE_2D
,
364 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
365 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
366 cmd
.Init(GL_TEXTURE_2D
,
373 GL_UNSIGNED_SHORT_4_4_4_4
,
377 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
378 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
379 cmd
.Init(GL_TEXTURE_2D
,
387 kInvalidSharedMemoryId
,
390 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
391 cmd
.Init(GL_TEXTURE_2D
,
400 kInvalidSharedMemoryOffset
,
402 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
405 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DValidArgs
) {
406 const int kWidth
= 16;
407 const int kHeight
= 8;
408 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
409 DoTexImage2D(GL_TEXTURE_2D
,
418 kSharedMemoryOffset
);
420 CopyTexSubImage2D(GL_TEXTURE_2D
, 1, 0, 0, 0, 0, kWidth
, kHeight
))
422 .RetiresOnSaturation();
423 CopyTexSubImage2D cmd
;
424 cmd
.Init(GL_TEXTURE_2D
, 1, 0, 0, 0, 0, kWidth
, kHeight
);
425 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
426 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
429 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DBadArgs
) {
430 const int kWidth
= 16;
431 const int kHeight
= 8;
432 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
433 DoTexImage2D(GL_TEXTURE_2D
,
443 CopyTexSubImage2D cmd
;
444 cmd
.Init(GL_TEXTURE0
, 1, 0, 0, 0, 0, kWidth
, kHeight
);
445 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
446 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
447 cmd
.Init(GL_TEXTURE_2D
, 1, -1, 0, 0, 0, kWidth
, kHeight
);
448 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
449 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
450 cmd
.Init(GL_TEXTURE_2D
, 1, 1, 0, 0, 0, kWidth
, kHeight
);
451 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
452 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
453 cmd
.Init(GL_TEXTURE_2D
, 1, 0, -1, 0, 0, kWidth
, kHeight
);
454 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
455 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
456 cmd
.Init(GL_TEXTURE_2D
, 1, 0, 1, 0, 0, kWidth
, kHeight
);
457 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
458 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
459 cmd
.Init(GL_TEXTURE_2D
, 1, 0, 0, 0, 0, kWidth
+ 1, kHeight
);
460 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
461 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
462 cmd
.Init(GL_TEXTURE_2D
, 1, 0, 0, 0, 0, kWidth
, kHeight
+ 1);
463 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
464 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
467 TEST_P(GLES2DecoderTest
, TexImage2DRedefinitionSucceeds
) {
468 const int kWidth
= 16;
469 const int kHeight
= 8;
470 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
471 EXPECT_CALL(*gl_
, GetError()).WillRepeatedly(Return(GL_NO_ERROR
));
472 for (int ii
= 0; ii
< 2; ++ii
) {
476 TexImage2D(GL_TEXTURE_2D
,
486 .RetiresOnSaturation();
487 cmd
.Init(GL_TEXTURE_2D
,
495 kSharedMemoryOffset
);
497 cmd
.Init(GL_TEXTURE_2D
,
507 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
509 TexSubImage2D(GL_TEXTURE_2D
,
517 shared_memory_address_
))
519 .RetiresOnSaturation();
520 // Consider this TexSubImage2D command part of the previous TexImage2D
521 // (last GL_TRUE argument). It will be skipped if there are bugs in the
522 // redefinition case.
524 cmd2
.Init(GL_TEXTURE_2D
,
535 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
539 TEST_P(GLES2DecoderTest
, TexImage2DGLError
) {
540 GLenum target
= GL_TEXTURE_2D
;
542 GLenum internal_format
= GL_RGBA
;
546 GLenum format
= GL_RGBA
;
547 GLenum type
= GL_UNSIGNED_BYTE
;
548 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
549 TextureManager
* manager
= group().texture_manager();
550 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
551 ASSERT_TRUE(texture_ref
!= NULL
);
552 Texture
* texture
= texture_ref
->texture();
554 texture
->GetLevelSize(GL_TEXTURE_2D
, level
, &width
, &height
, nullptr));
555 EXPECT_CALL(*gl_
, GetError())
556 .WillOnce(Return(GL_NO_ERROR
))
557 .WillOnce(Return(GL_OUT_OF_MEMORY
))
558 .RetiresOnSaturation();
570 .RetiresOnSaturation();
580 kSharedMemoryOffset
);
581 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
582 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
584 texture
->GetLevelSize(GL_TEXTURE_2D
, level
, &width
, &height
, nullptr));
587 TEST_P(GLES2DecoderTest
, CopyTexImage2DGLError
) {
588 GLenum target
= GL_TEXTURE_2D
;
590 GLenum internal_format
= GL_RGBA
;
594 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
595 TextureManager
* manager
= group().texture_manager();
596 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
597 ASSERT_TRUE(texture_ref
!= NULL
);
598 Texture
* texture
= texture_ref
->texture();
600 texture
->GetLevelSize(GL_TEXTURE_2D
, level
, &width
, &height
, nullptr));
601 EXPECT_CALL(*gl_
, GetError())
602 .WillOnce(Return(GL_NO_ERROR
))
603 .WillOnce(Return(GL_OUT_OF_MEMORY
))
604 .RetiresOnSaturation();
607 target
, level
, internal_format
, 0, 0, width
, height
, border
))
609 .RetiresOnSaturation();
611 cmd
.Init(target
, level
, internal_format
, 0, 0, width
, height
);
612 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
613 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
615 texture
->GetLevelSize(GL_TEXTURE_2D
, level
, &width
, &height
, nullptr));
618 TEST_P(GLES3DecoderTest
, CompressedTexImage3DBucket
) {
619 const uint32 kBucketId
= 123;
620 const uint32 kBadBucketId
= 99;
621 const GLenum kTarget
= GL_TEXTURE_2D_ARRAY
;
622 const GLint kLevel
= 0;
623 const GLenum kInternalFormat
= GL_COMPRESSED_R11_EAC
;
624 const GLsizei kWidth
= 4;
625 const GLsizei kHeight
= 4;
626 const GLsizei kDepth
= 4;
627 const GLint kBorder
= 0;
628 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
629 ASSERT_TRUE(bucket
!= NULL
);
630 const GLsizei kImageSize
= 32;
631 bucket
->SetSize(kImageSize
);
633 DoBindTexture(kTarget
, client_texture_id_
, kServiceTextureId
);
635 CompressedTexImage3DBucket cmd
;
643 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
653 CompressedTexImage3D(kTarget
, kLevel
, kInternalFormat
, kWidth
,
654 kHeight
, kDepth
, kBorder
, kImageSize
, _
))
656 .RetiresOnSaturation();
657 EXPECT_CALL(*gl_
, GetError())
658 .WillOnce(Return(GL_NO_ERROR
))
659 .WillOnce(Return(GL_NO_ERROR
))
660 .RetiresOnSaturation();
661 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
662 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
665 TEST_P(GLES2DecoderTest
, CompressedTexImage3DFailsOnES2
) {
666 const uint32 kBucketId
= 123;
667 const GLenum kTarget
= GL_TEXTURE_2D_ARRAY
;
668 const GLint kLevel
= 0;
669 const GLenum kInternalFormat
= GL_COMPRESSED_R11_EAC
;
670 const GLsizei kWidth
= 4;
671 const GLsizei kHeight
= 4;
672 const GLsizei kDepth
= 4;
673 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
674 ASSERT_TRUE(bucket
!= NULL
);
675 const GLsizei kImageSize
= 32;
676 bucket
->SetSize(kImageSize
);
679 CompressedTexImage3DBucket cmd
;
687 EXPECT_EQ(error::kUnknownCommand
, ExecuteCmd(cmd
));
691 CompressedTexSubImage3DBucket cmd
;
700 EXPECT_EQ(error::kUnknownCommand
, ExecuteCmd(cmd
));
704 TEST_P(GLES3DecoderTest
, CompressedTexImage3DFailsWithBadImageSize
) {
705 const uint32 kBucketId
= 123;
706 const GLenum kTarget
= GL_TEXTURE_2D_ARRAY
;
707 const GLint kLevel
= 0;
708 const GLenum kInternalFormat
= GL_COMPRESSED_RGBA8_ETC2_EAC
;
709 const GLsizei kWidth
= 4;
710 const GLsizei kHeight
= 8;
711 const GLsizei kDepth
= 4;
712 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
713 ASSERT_TRUE(bucket
!= NULL
);
714 const GLsizei kBadImageSize
= 64;
715 bucket
->SetSize(kBadImageSize
);
717 DoBindTexture(kTarget
, client_texture_id_
, kServiceTextureId
);
719 CompressedTexImage3DBucket cmd
;
727 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
728 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
731 TEST_P(GLES3DecoderTest
, CompressedTexSubImage3DFails
) {
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 const GLint kBorder
= 0;
740 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
741 ASSERT_TRUE(bucket
!= NULL
);
742 const GLsizei kImageSize
= 128;
743 bucket
->SetSize(kImageSize
);
745 DoBindTexture(kTarget
, client_texture_id_
, kServiceTextureId
);
747 CompressedTexImage3DBucket tex_cmd
;
748 tex_cmd
.Init(kTarget
,
756 CompressedTexImage3D(kTarget
, kLevel
, kInternalFormat
, kWidth
,
757 kHeight
, kDepth
, kBorder
, kImageSize
, _
))
759 .RetiresOnSaturation();
760 EXPECT_CALL(*gl_
, GetError())
761 .WillOnce(Return(GL_NO_ERROR
))
762 .WillOnce(Return(GL_NO_ERROR
))
763 .RetiresOnSaturation();
764 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
765 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
767 const GLint kXOffset
= 0;
768 const GLint kYOffset
= 0;
769 const GLint kZOffset
= 0;
770 const GLint kSubWidth
= 4;
771 const GLint kSubHeight
= 4;
772 const GLint kSubDepth
= 4;
773 const GLenum kFormat
= kInternalFormat
;
774 CompressedTexSubImage3DBucket cmd
;
776 // Incorrect image size.
787 const GLsizei kBadSubImageSize
= 32;
788 const GLsizei kSubImageSize
= 64;
789 bucket
->SetSize(kBadSubImageSize
);
790 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
791 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
794 const GLenum kBadFormat
= GL_COMPRESSED_R11_EAC
;
805 bucket
->SetSize(kSubImageSize
);
806 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
807 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
820 bucket
->SetSize(kSubImageSize
);
821 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
822 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
824 // offset + size > texture size
835 bucket
->SetSize(kSubImageSize
);
836 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
837 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
839 // offset not a multiple of 4.
850 bucket
->SetSize(kSubImageSize
);
851 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
852 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
854 // offset + width not a multlple of 4 .
865 const GLsizei kSubImageSize2
= 128;
866 bucket
->SetSize(kSubImageSize2
);
867 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
868 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
871 const uint32 kBadBucketId
= 444;
882 bucket
->SetSize(kSubImageSize
);
883 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
886 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DBucketBadBucket
) {
888 init
.extensions
= "GL_EXT_texture_compression_s3tc";
889 init
.bind_generates_resource
= true;
892 const uint32 kBadBucketId
= 123;
893 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
894 CompressedTexImage2DBucket cmd
;
895 cmd
.Init(GL_TEXTURE_2D
,
897 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
901 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
902 CompressedTexSubImage2DBucket cmd2
;
903 cmd2
.Init(GL_TEXTURE_2D
,
909 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
911 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
916 struct S3TCTestData
{
921 } // anonymous namespace.
923 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DS3TC
) {
925 init
.extensions
= "GL_EXT_texture_compression_s3tc";
926 init
.bind_generates_resource
= true;
928 const uint32 kBucketId
= 123;
929 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
930 ASSERT_TRUE(bucket
!= NULL
);
932 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
934 static const S3TCTestData test_data
[] = {
936 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, 8,
939 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, 8,
942 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, 16,
945 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, 16,
949 for (size_t ii
= 0; ii
< arraysize(test_data
); ++ii
) {
950 const S3TCTestData
& test
= test_data
[ii
];
951 CompressedTexImage2DBucket cmd
;
953 DoCompressedTexImage2D(
954 GL_TEXTURE_2D
, 0, test
.format
, 2, 4, 0, test
.block_size
, kBucketId
);
955 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
958 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 5, 4, kBucketId
);
959 bucket
->SetSize(test
.block_size
* 2);
960 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
961 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
963 // test small height.
964 DoCompressedTexImage2D(
965 GL_TEXTURE_2D
, 0, test
.format
, 4, 2, 0, test
.block_size
, kBucketId
);
966 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
968 // test too bad height.
969 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 4, 5, kBucketId
);
970 bucket
->SetSize(test
.block_size
* 2);
971 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
972 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
974 // test small for level 0.
975 DoCompressedTexImage2D(
976 GL_TEXTURE_2D
, 0, test
.format
, 1, 1, 0, test
.block_size
, kBucketId
);
977 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
979 // test small for level 0.
980 DoCompressedTexImage2D(
981 GL_TEXTURE_2D
, 0, test
.format
, 2, 2, 0, test
.block_size
, kBucketId
);
982 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
984 // test size too large.
985 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 4, 4, kBucketId
);
986 bucket
->SetSize(test
.block_size
* 2);
987 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
988 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
990 // test size too small.
991 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 4, 4, kBucketId
);
992 bucket
->SetSize(test
.block_size
/ 2);
993 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
994 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
997 DoCompressedTexImage2D(
998 GL_TEXTURE_2D
, 0, test
.format
, 4, 4, 0, test
.block_size
, kBucketId
);
999 DoCompressedTexImage2D(
1000 GL_TEXTURE_2D
, 1, test
.format
, 2, 2, 0, test
.block_size
, kBucketId
);
1001 DoCompressedTexImage2D(
1002 GL_TEXTURE_2D
, 2, test
.format
, 1, 1, 0, test
.block_size
, kBucketId
);
1003 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1006 DoCompressedTexImage2D(GL_TEXTURE_2D
,
1012 test
.block_size
* 4 * 4,
1014 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1016 CompressedTexSubImage2DBucket sub_cmd
;
1017 bucket
->SetSize(test
.block_size
);
1018 // Test sub image bad xoffset
1019 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 1, 0, 4, 4, test
.format
, kBucketId
);
1020 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1021 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1023 // Test sub image bad yoffset
1024 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 2, 4, 4, test
.format
, kBucketId
);
1025 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1026 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1028 // Test sub image bad width
1029 bucket
->SetSize(test
.block_size
* 2);
1030 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 5, 4, test
.format
, kBucketId
);
1031 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1032 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1034 // Test sub image bad height
1035 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 4, 5, test
.format
, kBucketId
);
1036 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1037 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1039 // Test sub image bad size
1040 bucket
->SetSize(test
.block_size
+ 1);
1041 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 4, 4, test
.format
, kBucketId
);
1042 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1043 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1045 for (GLint yoffset
= 0; yoffset
<= 8; yoffset
+= 4) {
1046 for (GLint xoffset
= 0; xoffset
<= 8; xoffset
+= 4) {
1047 for (GLsizei height
= 4; height
<= 8; height
+= 4) {
1048 for (GLsizei width
= 4; width
<= 8; width
+= 4) {
1049 GLsizei size
= test
.block_size
* (width
/ 4) * (height
/ 4);
1050 bucket
->SetSize(size
);
1052 CompressedTexSubImage2D(GL_TEXTURE_2D
,
1062 .RetiresOnSaturation();
1063 sub_cmd
.Init(GL_TEXTURE_2D
,
1071 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1072 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1080 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DETC1
) {
1082 init
.extensions
= "GL_OES_compressed_ETC1_RGB8_texture";
1083 init
.gl_version
= "opengl es 2.0";
1084 init
.bind_generates_resource
= true;
1086 const uint32 kBucketId
= 123;
1087 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
1088 ASSERT_TRUE(bucket
!= NULL
);
1090 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1092 const GLenum kFormat
= GL_ETC1_RGB8_OES
;
1093 const size_t kBlockSize
= 8;
1095 CompressedTexImage2DBucket cmd
;
1096 // test small width.
1097 DoCompressedTexImage2D(GL_TEXTURE_2D
, 0, kFormat
, 4, 8, 0, 16, kBucketId
);
1098 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1100 // test small height.
1101 DoCompressedTexImage2D(GL_TEXTURE_2D
, 0, kFormat
, 8, 4, 0, 16, kBucketId
);
1102 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1104 // test size too large.
1105 cmd
.Init(GL_TEXTURE_2D
, 0, kFormat
, 4, 4, kBucketId
);
1106 bucket
->SetSize(kBlockSize
* 2);
1107 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1108 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1110 // test size too small.
1111 cmd
.Init(GL_TEXTURE_2D
, 0, kFormat
, 4, 4, kBucketId
);
1112 bucket
->SetSize(kBlockSize
/ 2);
1113 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1114 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1117 DoCompressedTexImage2D(
1118 GL_TEXTURE_2D
, 0, kFormat
, 16, 16, 0, kBlockSize
* 16, kBucketId
);
1119 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1121 // Test CompressedTexSubImage not allowed
1122 CompressedTexSubImage2DBucket sub_cmd
;
1123 bucket
->SetSize(kBlockSize
);
1124 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 4, 4, kFormat
, kBucketId
);
1125 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1126 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1128 // Test TexSubImage not allowed for ETC1 compressed texture
1129 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1130 ASSERT_TRUE(texture_ref
!= NULL
);
1131 Texture
* texture
= texture_ref
->texture();
1132 GLenum type
, internal_format
;
1133 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
1134 EXPECT_EQ(kFormat
, internal_format
);
1135 TexSubImage2D texsub_cmd
;
1136 texsub_cmd
.Init(GL_TEXTURE_2D
,
1145 kSharedMemoryOffset
,
1147 EXPECT_EQ(error::kNoError
, ExecuteCmd(texsub_cmd
));
1148 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1150 // Test CopyTexSubImage not allowed for ETC1 compressed texture
1151 CopyTexSubImage2D copy_cmd
;
1152 copy_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 4, 4);
1153 EXPECT_EQ(error::kNoError
, ExecuteCmd(copy_cmd
));
1154 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1159 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalBindTexture
) {
1161 init
.extensions
= "GL_OES_EGL_image_external";
1162 init
.gl_version
= "opengl es 2.0";
1163 init
.bind_generates_resource
= true;
1165 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_EXTERNAL_OES
, kNewServiceId
));
1166 EXPECT_CALL(*gl_
, GenTextures(1, _
))
1167 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
));
1169 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, kNewClientId
);
1170 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1171 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1172 TextureRef
* texture_ref
= GetTexture(kNewClientId
);
1173 EXPECT_TRUE(texture_ref
!= NULL
);
1174 EXPECT_TRUE(texture_ref
->texture()->target() == GL_TEXTURE_EXTERNAL_OES
);
1177 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalGetBinding
) {
1179 init
.extensions
= "GL_OES_EGL_image_external";
1180 init
.gl_version
= "opengl es 2.0";
1181 init
.bind_generates_resource
= true;
1183 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1185 EXPECT_CALL(*gl_
, GetError())
1186 .WillOnce(Return(GL_NO_ERROR
))
1187 .WillOnce(Return(GL_NO_ERROR
))
1188 .RetiresOnSaturation();
1189 typedef GetIntegerv::Result Result
;
1190 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1192 GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES
, result
->GetData()))
1196 cmd
.Init(GL_TEXTURE_BINDING_EXTERNAL_OES
,
1198 shared_memory_offset_
);
1199 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1200 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(
1201 GL_TEXTURE_BINDING_EXTERNAL_OES
),
1202 result
->GetNumResults());
1203 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1204 EXPECT_EQ(client_texture_id_
, (uint32
)result
->GetData()[0]);
1207 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTextureDefaults
) {
1209 init
.extensions
= "GL_OES_EGL_image_external";
1210 init
.gl_version
= "opengl es 2.0";
1211 init
.bind_generates_resource
= true;
1213 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1215 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1216 EXPECT_TRUE(texture_ref
!= NULL
);
1217 Texture
* texture
= texture_ref
->texture();
1218 EXPECT_TRUE(texture
->target() == GL_TEXTURE_EXTERNAL_OES
);
1219 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1220 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1221 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1224 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTextureParam
) {
1226 init
.extensions
= "GL_OES_EGL_image_external";
1227 init
.gl_version
= "opengl es 2.0";
1228 init
.bind_generates_resource
= true;
1230 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1234 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
));
1237 TexParameteri(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
));
1241 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
));
1245 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
));
1247 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1248 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1249 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1251 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
1252 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1253 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1255 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
1256 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1257 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1259 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
1260 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1261 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1263 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1264 EXPECT_TRUE(texture_ref
!= NULL
);
1265 Texture
* texture
= texture_ref
->texture();
1266 EXPECT_TRUE(texture
->target() == GL_TEXTURE_EXTERNAL_OES
);
1267 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1268 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1269 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1272 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTextureParamInvalid
) {
1274 init
.extensions
= "GL_OES_EGL_image_external";
1275 init
.gl_version
= "opengl es 2.0";
1276 init
.bind_generates_resource
= true;
1278 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1281 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
,
1282 GL_TEXTURE_MIN_FILTER
,
1283 GL_NEAREST_MIPMAP_NEAREST
);
1284 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1285 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1287 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
1288 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1289 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1291 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
1292 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1293 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1295 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1296 EXPECT_TRUE(texture_ref
!= NULL
);
1297 Texture
* texture
= texture_ref
->texture();
1298 EXPECT_TRUE(texture
->target() == GL_TEXTURE_EXTERNAL_OES
);
1299 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1300 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1301 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1304 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTexImage2DError
) {
1306 init
.extensions
= "GL_OES_EGL_image_external";
1307 init
.gl_version
= "opengl es 2.0";
1308 init
.bind_generates_resource
= true;
1311 GLenum target
= GL_TEXTURE_EXTERNAL_OES
;
1313 GLenum internal_format
= GL_RGBA
;
1316 GLenum format
= GL_RGBA
;
1317 GLenum type
= GL_UNSIGNED_BYTE
;
1318 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1319 ASSERT_TRUE(GetTexture(client_texture_id_
) != NULL
);
1329 kSharedMemoryOffset
);
1330 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1332 // TexImage2D is not allowed with GL_TEXTURE_EXTERNAL_OES targets.
1333 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1336 TEST_P(GLES2DecoderManualInitTest
, DefaultTextureZero
) {
1341 cmd1
.Init(GL_TEXTURE_2D
, 0);
1342 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1343 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1344 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1347 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1348 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1349 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1350 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1353 TEST_P(GLES2DecoderManualInitTest
, DefaultTextureBGR
) {
1355 init
.bind_generates_resource
= true;
1359 cmd1
.Init(GL_TEXTURE_2D
, 0);
1361 *gl_
, BindTexture(GL_TEXTURE_2D
, TestHelper::kServiceDefaultTexture2dId
));
1362 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1363 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1366 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1368 BindTexture(GL_TEXTURE_CUBE_MAP
,
1369 TestHelper::kServiceDefaultTextureCubemapId
));
1370 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1371 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1374 // Test that default texture 0 is immutable.
1375 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameterf
) {
1381 cmd1
.Init(GL_TEXTURE_2D
, 0);
1382 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1383 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1384 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1387 cmd2
.Init(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1388 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1389 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1394 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1395 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1396 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1397 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1400 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1401 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1402 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1406 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameteri
) {
1412 cmd1
.Init(GL_TEXTURE_2D
, 0);
1413 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1414 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1415 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1418 cmd2
.Init(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1419 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1420 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1425 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1426 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1427 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1428 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1431 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1432 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1433 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1437 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameterfv
) {
1443 cmd1
.Init(GL_TEXTURE_2D
, 0);
1444 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1445 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1446 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1448 GLfloat data
= GL_NEAREST
;
1449 TexParameterfvImmediate
& cmd2
=
1450 *GetImmediateAs
<TexParameterfvImmediate
>();
1451 cmd2
.Init(GL_TEXTURE_2D
,
1452 GL_TEXTURE_MAG_FILTER
,
1454 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1455 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1460 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1461 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1462 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1463 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1465 GLfloat data
= GL_NEAREST
;
1466 TexParameterfvImmediate
& cmd2
=
1467 *GetImmediateAs
<TexParameterfvImmediate
>();
1468 cmd2
.Init(GL_TEXTURE_CUBE_MAP
,
1469 GL_TEXTURE_MAG_FILTER
,
1471 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1472 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1476 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameteriv
) {
1482 cmd1
.Init(GL_TEXTURE_2D
, 0);
1483 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1484 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1485 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1487 GLfloat data
= GL_NEAREST
;
1488 TexParameterfvImmediate
& cmd2
=
1489 *GetImmediateAs
<TexParameterfvImmediate
>();
1490 cmd2
.Init(GL_TEXTURE_2D
,
1491 GL_TEXTURE_MAG_FILTER
,
1493 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1494 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1499 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1500 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1501 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1502 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1504 GLfloat data
= GL_NEAREST
;
1505 TexParameterfvImmediate
& cmd2
=
1506 *GetImmediateAs
<TexParameterfvImmediate
>();
1507 cmd2
.Init(GL_TEXTURE_CUBE_MAP
,
1508 GL_TEXTURE_MAG_FILTER
,
1510 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1511 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1515 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexImage2D
) {
1520 cmd1
.Init(GL_TEXTURE_2D
, 0);
1521 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1522 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1523 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1526 cmd2
.Init(GL_TEXTURE_2D
,
1534 kSharedMemoryOffset
);
1535 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1536 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1539 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexSubImage2D
) {
1544 cmd1
.Init(GL_TEXTURE_2D
, 0);
1545 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1546 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1547 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1550 cmd2
.Init(GL_TEXTURE_2D
,
1559 kSharedMemoryOffset
,
1561 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1562 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1565 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleBindTexture
) {
1567 init
.extensions
= "GL_ARB_texture_rectangle";
1568 init
.bind_generates_resource
= true;
1570 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_RECTANGLE_ARB
, kNewServiceId
));
1571 EXPECT_CALL(*gl_
, GenTextures(1, _
))
1572 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
));
1574 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, kNewClientId
);
1575 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1576 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1577 Texture
* texture
= GetTexture(kNewClientId
)->texture();
1578 EXPECT_TRUE(texture
!= NULL
);
1579 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1582 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleGetBinding
) {
1584 init
.extensions
= "GL_ARB_texture_rectangle";
1585 init
.bind_generates_resource
= true;
1588 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1590 EXPECT_CALL(*gl_
, GetError())
1591 .WillOnce(Return(GL_NO_ERROR
))
1592 .WillOnce(Return(GL_NO_ERROR
))
1593 .RetiresOnSaturation();
1594 typedef GetIntegerv::Result Result
;
1595 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1597 GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB
, result
->GetData()))
1601 cmd
.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB
,
1603 shared_memory_offset_
);
1604 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1605 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(
1606 GL_TEXTURE_BINDING_RECTANGLE_ARB
),
1607 result
->GetNumResults());
1608 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1609 EXPECT_EQ(client_texture_id_
, (uint32
)result
->GetData()[0]);
1612 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTextureDefaults
) {
1614 init
.extensions
= "GL_ARB_texture_rectangle";
1615 init
.bind_generates_resource
= true;
1618 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1620 Texture
* texture
= GetTexture(client_texture_id_
)->texture();
1621 EXPECT_TRUE(texture
!= NULL
);
1622 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1623 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1624 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1625 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1628 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTextureParam
) {
1630 init
.extensions
= "GL_ARB_texture_rectangle";
1631 init
.bind_generates_resource
= true;
1635 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1639 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
));
1642 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
));
1646 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
));
1650 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
));
1652 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1653 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1654 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1656 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
1657 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1658 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1660 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
1661 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1662 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1664 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
1665 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1666 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1668 Texture
* texture
= GetTexture(client_texture_id_
)->texture();
1669 EXPECT_TRUE(texture
!= NULL
);
1670 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1671 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1672 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1673 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1676 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTextureParamInvalid
) {
1678 init
.extensions
= "GL_ARB_texture_rectangle";
1679 init
.bind_generates_resource
= true;
1683 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1686 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
,
1687 GL_TEXTURE_MIN_FILTER
,
1688 GL_NEAREST_MIPMAP_NEAREST
);
1689 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1690 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1692 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
1693 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1694 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1696 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
1697 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1698 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1700 Texture
* texture
= GetTexture(client_texture_id_
)->texture();
1701 EXPECT_TRUE(texture
!= NULL
);
1702 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1703 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1704 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1705 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1708 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTexImage2D
) {
1710 init
.extensions
= "GL_ARB_texture_rectangle";
1711 init
.bind_generates_resource
= true;
1714 GLenum target
= GL_TEXTURE_RECTANGLE_ARB
;
1716 GLenum internal_format
= GL_RGBA
;
1719 GLenum format
= GL_RGBA
;
1720 GLenum type
= GL_UNSIGNED_BYTE
;
1723 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1724 ASSERT_TRUE(GetTexture(client_texture_id_
) != NULL
);
1726 EXPECT_CALL(*gl_
, GetError())
1727 .WillOnce(Return(GL_NO_ERROR
))
1728 .WillOnce(Return(GL_NO_ERROR
))
1729 .RetiresOnSaturation();
1741 .RetiresOnSaturation();
1751 kSharedMemoryOffset
);
1752 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1754 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1757 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTexImage2DInvalid
) {
1759 init
.extensions
= "GL_ARB_texture_rectangle";
1760 init
.bind_generates_resource
= true;
1763 GLenum target
= GL_TEXTURE_RECTANGLE_ARB
;
1765 GLenum internal_format
= GL_RGBA
;
1768 GLenum format
= GL_RGBA
;
1769 GLenum type
= GL_UNSIGNED_BYTE
;
1772 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1773 ASSERT_TRUE(GetTexture(client_texture_id_
) != NULL
);
1784 kSharedMemoryOffset
);
1785 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1787 // TexImage2D may only be used with level 0 on GL_TEXTURE_RECTANGLE_ARB
1789 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1792 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DClearsAfterTexImage2DNULL
) {
1794 init
.gl_version
= "opengl es 2.0";
1795 init
.has_alpha
= true;
1796 init
.has_depth
= true;
1797 init
.request_alpha
= true;
1798 init
.request_depth
= true;
1801 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1803 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1804 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
1805 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA
,
1806 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 1, 2, 1);
1807 EXPECT_CALL(*gl_
, TexSubImage2D(GL_TEXTURE_2D
, 0, 0, _
, _
, 1, GL_RGBA
,
1808 GL_UNSIGNED_BYTE
, shared_memory_address_
))
1810 .RetiresOnSaturation();
1812 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 2, 1, GL_RGBA
, GL_UNSIGNED_BYTE
,
1813 kSharedMemoryId
, kSharedMemoryOffset
, GL_FALSE
);
1814 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1815 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 1, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
,
1816 kSharedMemoryId
, kSharedMemoryOffset
, GL_FALSE
);
1817 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1818 // Test if we call it again it does not clear.
1819 EXPECT_CALL(*gl_
, TexSubImage2D(GL_TEXTURE_2D
, 0, 0, 1, 1, 1, GL_RGBA
,
1820 GL_UNSIGNED_BYTE
, shared_memory_address_
))
1822 .RetiresOnSaturation();
1823 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1826 TEST_P(GLES2DecoderTest
, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData
) {
1827 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1829 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1830 DoTexImage2D(GL_TEXTURE_2D
,
1839 kSharedMemoryOffset
);
1841 TexSubImage2D(GL_TEXTURE_2D
,
1849 shared_memory_address_
))
1851 .RetiresOnSaturation();
1853 cmd
.Init(GL_TEXTURE_2D
,
1862 kSharedMemoryOffset
,
1864 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1865 // Test if we call it again it does not clear.
1867 TexSubImage2D(GL_TEXTURE_2D
,
1875 shared_memory_address_
))
1877 .RetiresOnSaturation();
1878 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1882 GLES2DecoderManualInitTest
,
1883 TexSubImage2DDoesNotClearAfterTexImage2DNULLThenDataWithTexImage2DIsFaster
) {
1884 base::CommandLine
command_line(0, NULL
);
1885 command_line
.AppendSwitchASCII(
1886 switches::kGpuDriverBugWorkarounds
,
1887 base::IntToString(gpu::TEXSUBIMAGE_FASTER_THAN_TEXIMAGE
));
1889 init
.bind_generates_resource
= true;
1890 InitDecoderWithCommandLine(init
, &command_line
);
1891 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1893 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1896 // Uses texSubimage internally because the above workaround is active and
1897 // the update is for the full size of the texture.
1900 GL_TEXTURE_2D
, 0, 0, 0, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
1902 .RetiresOnSaturation();
1903 cmds::TexImage2D cmd
;
1904 cmd
.Init(GL_TEXTURE_2D
,
1912 kSharedMemoryOffset
);
1913 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1917 TexSubImage2D(GL_TEXTURE_2D
,
1925 shared_memory_address_
))
1927 .RetiresOnSaturation();
1929 cmd
.Init(GL_TEXTURE_2D
,
1938 kSharedMemoryOffset
,
1940 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1941 // Test if we call it again it does not clear.
1943 TexSubImage2D(GL_TEXTURE_2D
,
1951 shared_memory_address_
))
1953 .RetiresOnSaturation();
1954 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1957 TEST_P(GLES2DecoderTest
, TexSubImage2DClearsAfterTexImage2DWithDataThenNULL
) {
1958 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1959 // Put in data (so it should be marked as cleared)
1960 DoTexImage2D(GL_TEXTURE_2D
,
1969 kSharedMemoryOffset
);
1973 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1974 // It won't actually call TexImage2D, just mark it as uncleared.
1975 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
1976 // Next call to TexSubImage2d should clear.
1977 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
1978 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA
,
1979 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 1, 2, 1);
1980 EXPECT_CALL(*gl_
, TexSubImage2D(GL_TEXTURE_2D
, 0, 0, _
, _
, 1, GL_RGBA
,
1981 GL_UNSIGNED_BYTE
, shared_memory_address_
))
1983 .RetiresOnSaturation();
1985 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 2, 1, GL_RGBA
, GL_UNSIGNED_BYTE
,
1986 kSharedMemoryId
, kSharedMemoryOffset
, GL_FALSE
);
1987 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1988 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 1, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
,
1989 kSharedMemoryId
, kSharedMemoryOffset
, GL_FALSE
);
1990 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1993 TEST_P(GLES2DecoderTest
, CopyTexImage2DMarksTextureAsCleared
) {
1994 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1996 TextureManager
* manager
= group().texture_manager();
1997 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
1998 ASSERT_TRUE(texture_ref
!= NULL
);
1999 Texture
* texture
= texture_ref
->texture();
2001 EXPECT_CALL(*gl_
, GetError())
2002 .WillOnce(Return(GL_NO_ERROR
))
2003 .RetiresOnSaturation();
2004 EXPECT_CALL(*gl_
, CopyTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 0, 0, 1, 1, 0))
2006 .RetiresOnSaturation();
2007 EXPECT_CALL(*gl_
, GetError())
2008 .WillOnce(Return(GL_NO_ERROR
))
2009 .RetiresOnSaturation();
2011 cmd
.Init(GL_TEXTURE_2D
, 0, GL_RGBA
, 0, 0, 1, 1);
2012 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2014 EXPECT_TRUE(texture
->SafeToRenderFrom());
2017 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DTwiceMarksTextureAsCleared
) {
2018 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2020 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2022 // This will initialize the top part.
2024 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 2, 1))
2026 .RetiresOnSaturation();
2027 CopyTexSubImage2D cmd
;
2028 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 2, 1);
2029 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2032 // This will initialize the bottom part.
2034 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 1, 0, 0, 2, 1))
2036 .RetiresOnSaturation();
2037 CopyTexSubImage2D cmd
;
2038 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 1, 0, 0, 2, 1);
2039 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2042 TextureManager
* manager
= group().texture_manager();
2043 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2044 ASSERT_TRUE(texture_ref
!= NULL
);
2045 Texture
* texture
= texture_ref
->texture();
2046 EXPECT_TRUE(texture
->SafeToRenderFrom());
2049 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DTwiceClearsUnclearedTexture
) {
2050 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2051 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
2054 // This will initialize the top part.
2056 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 2, 1))
2058 .RetiresOnSaturation();
2059 CopyTexSubImage2D cmd
;
2060 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 2, 1);
2061 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2064 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
2065 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA
,
2066 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 1, 2, 1);
2068 // This will clear the bottom part as a rectangle is not sufficient to keep
2069 // track of the initialized area.
2071 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 1, 1, 0, 0, 1, 1))
2073 .RetiresOnSaturation();
2074 CopyTexSubImage2D cmd
;
2075 cmd
.Init(GL_TEXTURE_2D
, 0, 1, 1, 0, 0, 1, 1);
2076 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2079 TextureManager
* manager
= group().texture_manager();
2080 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2081 ASSERT_TRUE(texture_ref
!= NULL
);
2082 Texture
* texture
= texture_ref
->texture();
2083 EXPECT_TRUE(texture
->SafeToRenderFrom());
2086 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DClearsUnclearedBackBufferSizedTexture
) {
2087 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2088 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, kBackBufferWidth
, kBackBufferHeight
,
2089 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2091 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0,
2092 kBackBufferWidth
, kBackBufferHeight
))
2094 .RetiresOnSaturation();
2095 CopyTexSubImage2D cmd
;
2096 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, kBackBufferWidth
, kBackBufferHeight
);
2097 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2099 TextureManager
* manager
= group().texture_manager();
2100 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2101 ASSERT_TRUE(texture_ref
!= NULL
);
2102 Texture
* texture
= texture_ref
->texture();
2103 EXPECT_TRUE(texture
->SafeToRenderFrom());
2106 TEST_P(GLES2DecoderManualInitTest
, CompressedImage2DMarksTextureAsCleared
) {
2108 init
.extensions
= "GL_EXT_texture_compression_s3tc";
2109 init
.bind_generates_resource
= true;
2112 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2113 EXPECT_CALL(*gl_
, GetError())
2114 .WillOnce(Return(GL_NO_ERROR
))
2115 .RetiresOnSaturation();
2118 CompressedTexImage2D(
2119 GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, 4, 4, 0, 8, _
))
2121 .RetiresOnSaturation();
2122 EXPECT_CALL(*gl_
, GetError())
2123 .WillOnce(Return(GL_NO_ERROR
))
2124 .RetiresOnSaturation();
2125 CompressedTexImage2D cmd
;
2126 cmd
.Init(GL_TEXTURE_2D
,
2128 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
2133 kSharedMemoryOffset
);
2134 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2135 TextureManager
* manager
= group().texture_manager();
2136 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2137 EXPECT_TRUE(texture_ref
->texture()->SafeToRenderFrom());
2140 TEST_P(GLES2DecoderTest
, TextureUsageAngleExtNotEnabledByDefault
) {
2141 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2145 GL_TEXTURE_2D
, GL_TEXTURE_USAGE_ANGLE
, GL_FRAMEBUFFER_ATTACHMENT_ANGLE
);
2146 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2147 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
2150 TEST_P(GLES2DecoderTest
, ProduceAndConsumeTextureCHROMIUM
) {
2151 Mailbox mailbox
= Mailbox::Generate();
2153 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2155 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2157 GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 4, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2158 TextureRef
* texture_ref
=
2159 group().texture_manager()->GetTexture(client_texture_id_
);
2160 ASSERT_TRUE(texture_ref
!= NULL
);
2161 Texture
* texture
= texture_ref
->texture();
2162 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2164 ProduceTextureCHROMIUMImmediate
& produce_cmd
=
2165 *GetImmediateAs
<ProduceTextureCHROMIUMImmediate
>();
2166 produce_cmd
.Init(GL_TEXTURE_2D
, mailbox
.name
);
2167 EXPECT_EQ(error::kNoError
,
2168 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2169 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2171 // Texture didn't change.
2175 GLenum internal_format
;
2178 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2179 EXPECT_EQ(3, width
);
2180 EXPECT_EQ(1, height
);
2181 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2182 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2183 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2186 texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
, nullptr));
2187 EXPECT_EQ(2, width
);
2188 EXPECT_EQ(4, height
);
2189 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2190 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2191 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2193 // Service ID has not changed.
2194 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2196 // Create new texture for consume.
2197 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2198 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
2199 .RetiresOnSaturation();
2200 DoBindTexture(GL_TEXTURE_2D
, kNewClientId
, kNewServiceId
);
2202 // Assigns and binds original service size texture ID.
2203 EXPECT_CALL(*gl_
, DeleteTextures(1, _
)).Times(1).RetiresOnSaturation();
2204 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2206 .RetiresOnSaturation();
2208 ConsumeTextureCHROMIUMImmediate
& consume_cmd
=
2209 *GetImmediateAs
<ConsumeTextureCHROMIUMImmediate
>();
2210 consume_cmd
.Init(GL_TEXTURE_2D
, mailbox
.name
);
2211 EXPECT_EQ(error::kNoError
,
2212 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
2213 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2215 // Texture is redefined.
2217 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2218 EXPECT_EQ(3, width
);
2219 EXPECT_EQ(1, height
);
2220 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2221 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2222 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2225 texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
, nullptr));
2226 EXPECT_EQ(2, width
);
2227 EXPECT_EQ(4, height
);
2228 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2229 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2230 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2232 // Service ID is restored.
2233 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2236 TEST_P(GLES2DecoderTest
, ProduceAndConsumeDirectTextureCHROMIUM
) {
2237 Mailbox mailbox
= Mailbox::Generate();
2239 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2241 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2243 GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 4, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2244 TextureRef
* texture_ref
=
2245 group().texture_manager()->GetTexture(client_texture_id_
);
2246 ASSERT_TRUE(texture_ref
!= NULL
);
2247 Texture
* texture
= texture_ref
->texture();
2248 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2250 ProduceTextureDirectCHROMIUMImmediate
& produce_cmd
=
2251 *GetImmediateAs
<ProduceTextureDirectCHROMIUMImmediate
>();
2252 produce_cmd
.Init(client_texture_id_
, GL_TEXTURE_2D
, mailbox
.name
);
2253 EXPECT_EQ(error::kNoError
,
2254 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2255 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2257 // Texture didn't change.
2261 GLenum internal_format
;
2264 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2265 EXPECT_EQ(3, width
);
2266 EXPECT_EQ(1, height
);
2267 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2268 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2269 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2272 texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
, nullptr));
2273 EXPECT_EQ(2, width
);
2274 EXPECT_EQ(4, height
);
2275 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2276 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2277 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2279 // Service ID has not changed.
2280 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2282 // Consume the texture into a new client ID.
2283 GLuint new_texture_id
= kNewClientId
;
2284 CreateAndConsumeTextureCHROMIUMImmediate
& consume_cmd
=
2285 *GetImmediateAs
<CreateAndConsumeTextureCHROMIUMImmediate
>();
2286 consume_cmd
.Init(GL_TEXTURE_2D
, new_texture_id
, mailbox
.name
);
2287 EXPECT_EQ(error::kNoError
,
2288 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
2289 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2291 // Make sure the new client ID is associated with the produced service ID.
2292 texture_ref
= group().texture_manager()->GetTexture(new_texture_id
);
2293 ASSERT_TRUE(texture_ref
!= NULL
);
2294 texture
= texture_ref
->texture();
2295 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2297 DoBindTexture(GL_TEXTURE_2D
, kNewClientId
, kServiceTextureId
);
2299 // Texture is redefined.
2301 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2302 EXPECT_EQ(3, width
);
2303 EXPECT_EQ(1, height
);
2304 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2305 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2306 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2309 texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
, nullptr));
2310 EXPECT_EQ(2, width
);
2311 EXPECT_EQ(4, height
);
2312 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2313 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2314 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2317 TEST_P(GLES2DecoderTest
, ProduceTextureCHROMIUMInvalidTarget
) {
2318 Mailbox mailbox
= Mailbox::Generate();
2320 DoBindTexture(GL_TEXTURE_CUBE_MAP
, client_texture_id_
, kServiceTextureId
);
2322 GL_TEXTURE_CUBE_MAP_POSITIVE_X
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
,
2323 GL_UNSIGNED_BYTE
, 0, 0);
2324 TextureRef
* texture_ref
=
2325 group().texture_manager()->GetTexture(client_texture_id_
);
2326 ASSERT_TRUE(texture_ref
!= NULL
);
2327 Texture
* texture
= texture_ref
->texture();
2328 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2330 ProduceTextureDirectCHROMIUMImmediate
& produce_cmd
=
2331 *GetImmediateAs
<ProduceTextureDirectCHROMIUMImmediate
>();
2332 produce_cmd
.Init(client_texture_id_
, GL_TEXTURE_2D
, mailbox
.name
);
2333 EXPECT_EQ(error::kNoError
,
2334 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2336 // ProduceTexture should fail it the texture and produce targets don't match.
2337 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2340 TEST_P(GLES2DecoderTest
, CreateAndConsumeTextureCHROMIUMInvalidMailbox
) {
2341 // Attempt to consume the mailbox when no texture has been produced with it.
2342 Mailbox mailbox
= Mailbox::Generate();
2343 GLuint new_texture_id
= kNewClientId
;
2345 EXPECT_CALL(*gl_
, GenTextures(1, _
))
2346 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
2347 .RetiresOnSaturation();
2348 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, _
))
2350 .RetiresOnSaturation();
2351 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
2353 .RetiresOnSaturation();
2355 CreateAndConsumeTextureCHROMIUMImmediate
& consume_cmd
=
2356 *GetImmediateAs
<CreateAndConsumeTextureCHROMIUMImmediate
>();
2357 consume_cmd
.Init(GL_TEXTURE_2D
, new_texture_id
, mailbox
.name
);
2358 EXPECT_EQ(error::kNoError
,
2359 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
2361 // CreateAndConsumeTexture should fail if the mailbox isn't associated with a
2363 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2365 // Make sure the new client_id is associated with a texture ref even though
2366 // CreateAndConsumeTexture failed.
2367 TextureRef
* texture_ref
=
2368 group().texture_manager()->GetTexture(new_texture_id
);
2369 ASSERT_TRUE(texture_ref
!= NULL
);
2370 Texture
* texture
= texture_ref
->texture();
2371 // New texture should have the correct target type.
2372 EXPECT_TRUE(texture
->target() == GL_TEXTURE_2D
);
2373 // New texture should have a valid service_id.
2374 EXPECT_EQ(kNewServiceId
, texture
->service_id());
2377 TEST_P(GLES2DecoderTest
, CreateAndConsumeTextureCHROMIUMInvalidTarget
) {
2378 Mailbox mailbox
= Mailbox::Generate();
2380 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2381 TextureRef
* texture_ref
=
2382 group().texture_manager()->GetTexture(client_texture_id_
);
2383 ASSERT_TRUE(texture_ref
!= NULL
);
2385 ProduceTextureDirectCHROMIUMImmediate
& produce_cmd
=
2386 *GetImmediateAs
<ProduceTextureDirectCHROMIUMImmediate
>();
2387 produce_cmd
.Init(client_texture_id_
, GL_TEXTURE_2D
, mailbox
.name
);
2388 EXPECT_EQ(error::kNoError
,
2389 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2390 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2392 EXPECT_CALL(*gl_
, GenTextures(1, _
))
2393 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
2394 .RetiresOnSaturation();
2395 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, _
))
2397 .RetiresOnSaturation();
2398 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
2400 .RetiresOnSaturation();
2402 // Attempt to consume the mailbox with a different target.
2403 GLuint new_texture_id
= kNewClientId
;
2404 CreateAndConsumeTextureCHROMIUMImmediate
& consume_cmd
=
2405 *GetImmediateAs
<CreateAndConsumeTextureCHROMIUMImmediate
>();
2406 consume_cmd
.Init(GL_TEXTURE_CUBE_MAP
, new_texture_id
, mailbox
.name
);
2407 EXPECT_EQ(error::kNoError
,
2408 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
2410 // CreateAndConsumeTexture should fail if the produced texture had a different
2412 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2414 // Make sure the new client_id is associated with a texture ref even though
2415 // CreateAndConsumeTexture failed.
2416 texture_ref
= group().texture_manager()->GetTexture(new_texture_id
);
2417 ASSERT_TRUE(texture_ref
!= NULL
);
2418 Texture
* texture
= texture_ref
->texture();
2419 // New texture should have the correct target type.
2420 EXPECT_TRUE(texture
->target() == GL_TEXTURE_CUBE_MAP
);
2421 // New texture should have a valid service_id.
2422 EXPECT_EQ(kNewServiceId
, texture
->service_id());
2424 // Make sure the client_id did not become associated with the produced texture
2426 EXPECT_NE(kServiceTextureId
, texture
->service_id());
2429 TEST_P(GLES2DecoderManualInitTest
, DepthTextureBadArgs
) {
2431 init
.extensions
= "GL_ANGLE_depth_texture";
2432 init
.gl_version
= "opengl es 2.0";
2433 init
.has_depth
= true;
2434 init
.has_stencil
= true;
2435 init
.request_depth
= true;
2436 init
.request_stencil
= true;
2437 init
.bind_generates_resource
= true;
2440 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2441 // Check trying to upload data fails.
2443 tex_cmd
.Init(GL_TEXTURE_2D
,
2451 kSharedMemoryOffset
);
2452 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
2453 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2455 tex_cmd
.Init(GL_TEXTURE_2D
,
2464 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
2465 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2466 // Make a 1 pixel depth texture.
2467 DoTexImage2D(GL_TEXTURE_2D
,
2477 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2479 // Check that trying to update it fails.
2480 TexSubImage2D tex_sub_cmd
;
2481 tex_sub_cmd
.Init(GL_TEXTURE_2D
,
2490 kSharedMemoryOffset
,
2492 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_sub_cmd
));
2493 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2495 // Check that trying to CopyTexImage2D fails
2496 CopyTexImage2D copy_tex_cmd
;
2497 copy_tex_cmd
.Init(GL_TEXTURE_2D
, 0, GL_DEPTH_COMPONENT
, 0, 0, 1, 1);
2498 EXPECT_EQ(error::kNoError
, ExecuteCmd(copy_tex_cmd
));
2499 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2501 // Check that trying to CopyTexSubImage2D fails
2502 CopyTexSubImage2D copy_sub_cmd
;
2503 copy_sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 1, 1);
2504 EXPECT_EQ(error::kNoError
, ExecuteCmd(copy_sub_cmd
));
2505 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2508 TEST_P(GLES2DecoderManualInitTest
, GenerateMipmapDepthTexture
) {
2510 init
.extensions
= "GL_ANGLE_depth_texture";
2511 init
.gl_version
= "opengl es 2.0";
2512 init
.has_depth
= true;
2513 init
.has_stencil
= true;
2514 init
.request_depth
= true;
2515 init
.request_stencil
= true;
2516 init
.bind_generates_resource
= true;
2518 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2519 DoTexImage2D(GL_TEXTURE_2D
,
2530 cmd
.Init(GL_TEXTURE_2D
);
2531 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2532 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2535 TEST_P(GLES2DecoderTest
, BindTexImage2DCHROMIUM
) {
2536 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2538 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2539 TextureRef
* texture_ref
=
2540 group().texture_manager()->GetTexture(client_texture_id_
);
2541 ASSERT_TRUE(texture_ref
!= NULL
);
2542 Texture
* texture
= texture_ref
->texture();
2543 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2545 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2546 GetImageManager()->AddImage(image
.get(), 1);
2547 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL
);
2552 GLenum internal_format
;
2555 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2556 EXPECT_EQ(3, width
);
2557 EXPECT_EQ(1, height
);
2558 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2559 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2560 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2561 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2563 // Bind image to texture.
2564 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2565 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2567 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2568 // Image should now be set.
2569 EXPECT_FALSE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2571 // Define new texture image.
2573 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2575 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2576 // Image should no longer be set.
2577 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2580 TEST_P(GLES2DecoderTest
, BindTexImage2DCHROMIUMCubeMapNotAllowed
) {
2581 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2582 GetImageManager()->AddImage(image
.get(), 1);
2583 DoBindTexture(GL_TEXTURE_CUBE_MAP
, client_texture_id_
, kServiceTextureId
);
2585 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd
;
2586 bind_tex_image_2d_cmd
.Init(GL_TEXTURE_CUBE_MAP
, 1);
2587 EXPECT_EQ(error::kNoError
, ExecuteCmd(bind_tex_image_2d_cmd
));
2588 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
2591 TEST_P(GLES2DecoderTest
, OrphanGLImageWithTexImage2D
) {
2592 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2593 GetImageManager()->AddImage(image
.get(), 1);
2594 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2596 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2598 TextureRef
* texture_ref
=
2599 group().texture_manager()->GetTexture(client_texture_id_
);
2600 ASSERT_TRUE(texture_ref
!= NULL
);
2601 Texture
* texture
= texture_ref
->texture();
2603 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2605 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2606 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2609 TEST_P(GLES2DecoderTest
, GLImageAttachedAfterSubTexImage2D
) {
2610 // Specifically tests that TexSubImage2D is not optimized to TexImage2D
2611 // in the presence of image attachments.
2613 feature_info()->workarounds().texsubimage_faster_than_teximage
);
2615 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2616 GetImageManager()->AddImage(image
.get(), 1);
2617 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2619 GLenum target
= GL_TEXTURE_2D
;
2626 GLenum format
= GL_RGBA
;
2627 GLenum type
= GL_UNSIGNED_BYTE
;
2628 uint32_t pixels_shm_id
= kSharedMemoryId
;
2629 uint32_t pixels_shm_offset
= kSharedMemoryOffset
;
2630 GLboolean internal
= 0;
2632 // Define texture first.
2633 DoTexImage2D(target
, level
, format
, width
, height
, border
, format
, type
,
2634 pixels_shm_id
, pixels_shm_offset
);
2636 // Bind texture to GLImage.
2637 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2640 TextureRef
* texture_ref
=
2641 group().texture_manager()->GetTexture(client_texture_id_
);
2642 ASSERT_TRUE(texture_ref
!= NULL
);
2643 Texture
* texture
= texture_ref
->texture();
2644 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2646 // TexSubImage2D should not unbind GLImage.
2647 EXPECT_CALL(*gl_
, TexSubImage2D(target
, level
, xoffset
, yoffset
, width
,
2648 height
, format
, type
, _
))
2650 .RetiresOnSaturation();
2651 cmds::TexSubImage2D tex_sub_image_2d_cmd
;
2652 tex_sub_image_2d_cmd
.Init(target
, level
, xoffset
, yoffset
, width
, height
,
2653 format
, type
, pixels_shm_id
, pixels_shm_offset
,
2655 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_sub_image_2d_cmd
));
2656 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2659 TEST_P(GLES2DecoderTest
, GLImageAttachedAfterClearLevel
) {
2660 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2661 GetImageManager()->AddImage(image
.get(), 1);
2662 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2664 GLenum target
= GL_TEXTURE_2D
;
2671 GLenum format
= GL_RGBA
;
2672 GLenum type
= GL_UNSIGNED_BYTE
;
2673 uint32_t pixels_shm_id
= kSharedMemoryId
;
2674 uint32_t pixels_shm_offset
= kSharedMemoryOffset
;
2676 // Define texture first.
2677 DoTexImage2D(target
, level
, format
, width
, height
, border
, format
, type
,
2678 pixels_shm_id
, pixels_shm_offset
);
2680 // Bind texture to GLImage.
2681 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2684 TextureRef
* texture_ref
=
2685 group().texture_manager()->GetTexture(client_texture_id_
);
2686 ASSERT_TRUE(texture_ref
!= NULL
);
2687 Texture
* texture
= texture_ref
->texture();
2688 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2690 // ClearLevel should use glTexSubImage2D to avoid unbinding GLImage.
2691 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2693 .RetiresOnSaturation();
2694 EXPECT_CALL(*gl_
, TexSubImage2D(target
, level
, xoffset
, yoffset
, width
,
2695 height
, format
, type
, _
))
2697 .RetiresOnSaturation();
2698 GetDecoder()->ClearLevel(texture
, target
, level
, format
, type
, 0, 0, width
,
2700 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2703 TEST_P(GLES2DecoderTest
, ReleaseTexImage2DCHROMIUM
) {
2704 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2706 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2707 TextureRef
* texture_ref
=
2708 group().texture_manager()->GetTexture(client_texture_id_
);
2709 ASSERT_TRUE(texture_ref
!= NULL
);
2710 Texture
* texture
= texture_ref
->texture();
2711 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2713 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2714 GetImageManager()->AddImage(image
.get(), 1);
2715 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL
);
2720 GLenum internal_format
;
2723 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2724 EXPECT_EQ(3, width
);
2725 EXPECT_EQ(1, height
);
2726 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2727 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2728 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2729 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2731 // Bind image to texture.
2732 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2733 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2735 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2736 // Image should now be set.
2737 EXPECT_FALSE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2739 // Release image from texture.
2740 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2741 EXPECT_CALL(*gl_
, GetError())
2742 .WillOnce(Return(GL_NO_ERROR
))
2743 .WillOnce(Return(GL_NO_ERROR
))
2744 .RetiresOnSaturation();
2745 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd
;
2746 release_tex_image_2d_cmd
.Init(GL_TEXTURE_2D
, 1);
2747 EXPECT_EQ(error::kNoError
, ExecuteCmd(release_tex_image_2d_cmd
));
2749 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2750 // Image should no longer be set.
2751 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2754 class MockGLImage
: public gfx::GLImage
{
2758 // Overridden from gfx::GLImage:
2759 MOCK_METHOD0(GetSize
, gfx::Size());
2760 MOCK_METHOD0(GetInternalFormat
, unsigned());
2761 MOCK_METHOD1(Destroy
, void(bool));
2762 MOCK_METHOD1(BindTexImage
, bool(unsigned));
2763 MOCK_METHOD1(ReleaseTexImage
, void(unsigned));
2764 MOCK_METHOD3(CopyTexSubImage
,
2765 bool(unsigned, const gfx::Point
&, const gfx::Rect
&));
2766 MOCK_METHOD0(WillUseTexImage
, void());
2767 MOCK_METHOD0(DidUseTexImage
, void());
2768 MOCK_METHOD0(WillModifyTexImage
, void());
2769 MOCK_METHOD0(DidModifyTexImage
, void());
2770 MOCK_METHOD5(ScheduleOverlayPlane
, bool(gfx::AcceleratedWidget
,
2772 gfx::OverlayTransform
,
2774 const gfx::RectF
&));
2775 MOCK_METHOD3(OnMemoryDump
,
2776 void(base::trace_event::ProcessMemoryDump
*,
2778 const std::string
&));
2781 virtual ~MockGLImage() {}
2784 TEST_P(GLES2DecoderWithShaderTest
, UseTexImage
) {
2785 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2786 DoTexImage2D(GL_TEXTURE_2D
,
2795 kSharedMemoryOffset
);
2797 TextureRef
* texture_ref
=
2798 group().texture_manager()->GetTexture(client_texture_id_
);
2799 ASSERT_TRUE(texture_ref
!= NULL
);
2800 Texture
* texture
= texture_ref
->texture();
2801 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2803 const int32 kImageId
= 1;
2804 scoped_refptr
<MockGLImage
> image(new MockGLImage
);
2805 GetImageManager()->AddImage(image
.get(), kImageId
);
2807 // Bind image to texture.
2808 EXPECT_CALL(*image
.get(), BindTexImage(GL_TEXTURE_2D
))
2810 .WillOnce(Return(true))
2811 .RetiresOnSaturation();
2812 EXPECT_CALL(*image
.get(), GetSize())
2814 .WillOnce(Return(gfx::Size(1, 1)))
2815 .RetiresOnSaturation();
2816 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2817 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, kImageId
);
2819 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2820 SetupExpectationsForApplyingDefaultDirtyState();
2822 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2823 EXPECT_CALL(*gl_
, GetError())
2824 .WillOnce(Return(GL_NO_ERROR
))
2825 .WillOnce(Return(GL_NO_ERROR
))
2826 .WillOnce(Return(GL_NO_ERROR
))
2827 .WillOnce(Return(GL_NO_ERROR
))
2828 .RetiresOnSaturation();
2829 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(3).RetiresOnSaturation();
2830 EXPECT_CALL(*image
.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2831 EXPECT_CALL(*image
.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2832 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2834 .RetiresOnSaturation();
2836 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2837 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2838 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2841 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2842 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2843 EXPECT_CALL(*gl_
, GetError())
2844 .WillOnce(Return(GL_NO_ERROR
))
2845 .WillOnce(Return(GL_NO_ERROR
))
2846 .RetiresOnSaturation();
2847 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2848 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2850 .RetiresOnSaturation();
2851 // Image will be 'in use' as long as bound to a framebuffer.
2852 EXPECT_CALL(*image
.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2854 FramebufferTexture2DEXT(GL_FRAMEBUFFER
,
2855 GL_COLOR_ATTACHMENT0
,
2860 .RetiresOnSaturation();
2861 EXPECT_CALL(*gl_
, GetError())
2862 .WillOnce(Return(GL_NO_ERROR
))
2863 .WillOnce(Return(GL_NO_ERROR
))
2864 .RetiresOnSaturation();
2865 FramebufferTexture2D fbtex_cmd
;
2866 fbtex_cmd
.Init(GL_FRAMEBUFFER
,
2867 GL_COLOR_ATTACHMENT0
,
2869 client_texture_id_
);
2870 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbtex_cmd
));
2871 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2873 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2874 EXPECT_CALL(*gl_
, GetError())
2875 .WillOnce(Return(GL_NO_ERROR
))
2876 .WillOnce(Return(GL_NO_ERROR
))
2877 .RetiresOnSaturation();
2879 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
2880 GL_COLOR_ATTACHMENT0
,
2882 kServiceRenderbufferId
))
2884 .RetiresOnSaturation();
2885 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2886 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2888 .RetiresOnSaturation();
2889 // Image should no longer be 'in use' after being unbound from framebuffer.
2890 EXPECT_CALL(*image
.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2891 EXPECT_CALL(*gl_
, GetError())
2892 .WillOnce(Return(GL_NO_ERROR
))
2893 .WillOnce(Return(GL_NO_ERROR
))
2894 .RetiresOnSaturation();
2895 FramebufferRenderbuffer fbrb_cmd
;
2896 fbrb_cmd
.Init(GL_FRAMEBUFFER
,
2897 GL_COLOR_ATTACHMENT0
,
2899 client_renderbuffer_id_
);
2900 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbrb_cmd
));
2903 TEST_P(GLES2DecoderManualInitTest
, DrawWithGLImageExternal
) {
2905 init
.extensions
= "GL_OES_EGL_image_external";
2906 init
.gl_version
= "opengl es 2.0";
2907 init
.has_alpha
= true;
2908 init
.has_depth
= true;
2909 init
.request_alpha
= true;
2910 init
.request_depth
= true;
2911 init
.bind_generates_resource
= true;
2914 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
2915 scoped_refptr
<MockGLImage
> image(new MockGLImage
);
2916 group().texture_manager()->SetTarget(texture_ref
, GL_TEXTURE_EXTERNAL_OES
);
2917 group().texture_manager()->SetLevelInfo(texture_ref
, GL_TEXTURE_EXTERNAL_OES
,
2918 0, GL_RGBA
, 0, 0, 1, 0, GL_RGBA
,
2919 GL_UNSIGNED_BYTE
, gfx::Rect());
2920 group().texture_manager()->SetLevelImage(
2921 texture_ref
, GL_TEXTURE_EXTERNAL_OES
, 0, image
.get());
2923 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
2924 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2926 SetupSamplerExternalProgram();
2928 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
2929 SetupExpectationsForApplyingDefaultDirtyState();
2930 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref
));
2933 EXPECT_CALL(*gl_
, GetError())
2934 .WillOnce(Return(GL_NO_ERROR
))
2935 .RetiresOnSaturation();
2936 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2937 EXPECT_CALL(*image
.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2938 EXPECT_CALL(*gl_
, GetError())
2939 .WillOnce(Return(GL_NO_ERROR
))
2940 .RetiresOnSaturation();
2941 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(1);
2942 EXPECT_CALL(*gl_
, GetError())
2943 .WillOnce(Return(GL_NO_ERROR
))
2944 .RetiresOnSaturation();
2945 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2946 EXPECT_CALL(*image
.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2947 EXPECT_CALL(*gl_
, GetError())
2948 .WillOnce(Return(GL_NO_ERROR
))
2949 .RetiresOnSaturation();
2950 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2952 cmd
.Init(GL_TRIANGLES
,
2953 kValidIndexRangeCount
,
2955 kValidIndexRangeStart
* 2);
2956 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2957 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2960 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatOnGLES2
) {
2962 init
.extensions
= "GL_OES_texture_float";
2963 init
.gl_version
= "opengl es 2.0";
2965 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2966 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2967 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 16, 17, 0, GL_RGB
, GL_FLOAT
, 0, 0);
2969 GL_TEXTURE_2D
, 0, GL_LUMINANCE
, 16, 17, 0, GL_LUMINANCE
, GL_FLOAT
, 0, 0);
2970 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, 16, 17, 0, GL_ALPHA
, GL_FLOAT
, 0, 0);
2971 DoTexImage2D(GL_TEXTURE_2D
,
2983 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatOnGLES3
) {
2985 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
2986 init
.gl_version
= "opengl es 3.0";
2988 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2989 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2990 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 16, 17, 0, GL_RGB
, GL_FLOAT
, 0, 0);
2992 GL_TEXTURE_2D
, 0, GL_RGBA32F
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2994 GL_TEXTURE_2D
, 0, GL_LUMINANCE
, 16, 17, 0, GL_LUMINANCE
, GL_FLOAT
, 0, 0);
2995 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, 16, 17, 0, GL_ALPHA
, GL_FLOAT
, 0, 0);
2996 DoTexImage2D(GL_TEXTURE_2D
,
3008 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DFloatOnGLES3
) {
3010 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
3011 init
.gl_version
= "opengl es 3.0";
3013 const int kWidth
= 8;
3014 const int kHeight
= 4;
3015 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
3016 DoTexImage2D(GL_TEXTURE_2D
,
3027 TexImage2D(GL_TEXTURE_2D
,
3035 shared_memory_address_
))
3037 .RetiresOnSaturation();
3039 cmd
.Init(GL_TEXTURE_2D
,
3048 kSharedMemoryOffset
,
3050 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3051 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3054 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DFloatDoesClearOnGLES3
) {
3056 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
3057 init
.gl_version
= "opengl es 3.0";
3059 const int kWidth
= 8;
3060 const int kHeight
= 4;
3061 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
3062 DoTexImage2D(GL_TEXTURE_2D
,
3072 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
3073 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA32F
,
3074 GL_RGBA
, GL_FLOAT
, 0, kHeight
- 1, kWidth
, 1);
3075 EXPECT_CALL(*gl_
, TexSubImage2D(GL_TEXTURE_2D
, 0, 0, _
, _
, _
, GL_RGBA
,
3076 GL_FLOAT
, shared_memory_address_
))
3078 .RetiresOnSaturation();
3080 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, kWidth
, kHeight
- 1, GL_RGBA
, GL_FLOAT
,
3081 kSharedMemoryId
, kSharedMemoryOffset
, GL_FALSE
);
3082 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3083 cmd
.Init(GL_TEXTURE_2D
, 0, 0, kHeight
- 1, kWidth
- 1, 1, GL_RGBA
, GL_FLOAT
,
3084 kSharedMemoryId
, kSharedMemoryOffset
, GL_FALSE
);
3085 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3086 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3089 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatConvertsFormatDesktop
) {
3091 init
.extensions
= "GL_ARB_texture_float";
3093 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
3095 GL_TEXTURE_2D
, 0, GL_RGBA32F
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
3096 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB32F
, 16, 17, 0, GL_RGB
, GL_FLOAT
, 0, 0);
3097 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3108 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3119 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3129 GL_LUMINANCE32F_ARB
);
3130 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3141 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3151 GL_LUMINANCE_ALPHA32F_ARB
);
3154 class GLES2DecoderCompressedFormatsTest
: public GLES2DecoderManualInitTest
{
3156 GLES2DecoderCompressedFormatsTest() {}
3158 static bool ValueInArray(GLint value
, GLint
* array
, GLint count
) {
3159 for (GLint ii
= 0; ii
< count
; ++ii
) {
3160 if (array
[ii
] == value
) {
3167 void CheckFormats(const char* extension
, const GLenum
* formats
, int count
) {
3169 init
.extensions
= extension
;
3170 init
.bind_generates_resource
= true;
3173 EXPECT_CALL(*gl_
, GetError())
3174 .WillOnce(Return(GL_NO_ERROR
))
3175 .WillOnce(Return(GL_NO_ERROR
))
3176 .WillOnce(Return(GL_NO_ERROR
))
3177 .WillOnce(Return(GL_NO_ERROR
))
3178 .RetiresOnSaturation();
3180 typedef GetIntegerv::Result Result
;
3181 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
3184 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
3185 cmd
.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
3187 shared_memory_offset_
);
3188 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3189 EXPECT_EQ(1, result
->GetNumResults());
3190 GLint num_formats
= result
->GetData()[0];
3191 EXPECT_EQ(count
, num_formats
);
3192 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3195 cmd
.Init(GL_COMPRESSED_TEXTURE_FORMATS
,
3197 shared_memory_offset_
);
3198 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3199 EXPECT_EQ(num_formats
, result
->GetNumResults());
3201 for (int i
= 0; i
< count
; ++i
) {
3203 ValueInArray(formats
[i
], result
->GetData(), result
->GetNumResults()));
3206 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3210 INSTANTIATE_TEST_CASE_P(Service
,
3211 GLES2DecoderCompressedFormatsTest
,
3214 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsS3TC
) {
3215 const GLenum formats
[] = {
3216 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
,
3217 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
};
3218 CheckFormats("GL_EXT_texture_compression_s3tc", formats
, 4);
3221 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsATC
) {
3222 const GLenum formats
[] = {GL_ATC_RGB_AMD
, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD
,
3223 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
};
3224 CheckFormats("GL_AMD_compressed_ATC_texture", formats
, 3);
3227 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsPVRTC
) {
3228 const GLenum formats
[] = {
3229 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
,
3230 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
};
3231 CheckFormats("GL_IMG_texture_compression_pvrtc", formats
, 4);
3234 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsETC1
) {
3235 const GLenum formats
[] = {GL_ETC1_RGB8_OES
};
3236 CheckFormats("GL_OES_compressed_ETC1_RGB8_texture", formats
, 1);
3239 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsASTC
) {
3240 const GLenum formats
[] = {
3241 GL_COMPRESSED_RGBA_ASTC_4x4_KHR
,
3242 GL_COMPRESSED_RGBA_ASTC_5x4_KHR
,
3243 GL_COMPRESSED_RGBA_ASTC_5x5_KHR
,
3244 GL_COMPRESSED_RGBA_ASTC_6x5_KHR
,
3245 GL_COMPRESSED_RGBA_ASTC_6x6_KHR
,
3246 GL_COMPRESSED_RGBA_ASTC_8x5_KHR
,
3247 GL_COMPRESSED_RGBA_ASTC_8x6_KHR
,
3248 GL_COMPRESSED_RGBA_ASTC_8x8_KHR
,
3249 GL_COMPRESSED_RGBA_ASTC_10x5_KHR
,
3250 GL_COMPRESSED_RGBA_ASTC_10x6_KHR
,
3251 GL_COMPRESSED_RGBA_ASTC_10x8_KHR
,
3252 GL_COMPRESSED_RGBA_ASTC_10x10_KHR
,
3253 GL_COMPRESSED_RGBA_ASTC_12x10_KHR
,
3254 GL_COMPRESSED_RGBA_ASTC_12x12_KHR
,
3255 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR
,
3256 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR
,
3257 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR
,
3258 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR
,
3259 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR
,
3260 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR
,
3261 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR
,
3262 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR
,
3263 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR
,
3264 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR
,
3265 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR
,
3266 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR
,
3267 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR
,
3268 GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR
};
3269 CheckFormats("GL_KHR_texture_compression_astc_ldr", formats
, 28);
3272 TEST_P(GLES2DecoderManualInitTest
, GetNoCompressedTextureFormats
) {
3274 init
.bind_generates_resource
= true;
3277 EXPECT_CALL(*gl_
, GetError())
3278 .WillOnce(Return(GL_NO_ERROR
))
3279 .WillOnce(Return(GL_NO_ERROR
))
3280 .WillOnce(Return(GL_NO_ERROR
))
3281 .WillOnce(Return(GL_NO_ERROR
))
3282 .RetiresOnSaturation();
3284 typedef GetIntegerv::Result Result
;
3285 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
3288 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
3289 cmd
.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
3291 shared_memory_offset_
);
3292 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3293 EXPECT_EQ(1, result
->GetNumResults());
3294 GLint num_formats
= result
->GetData()[0];
3295 EXPECT_EQ(0, num_formats
);
3296 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3300 GL_COMPRESSED_TEXTURE_FORMATS
, shared_memory_id_
, shared_memory_offset_
);
3301 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3302 EXPECT_EQ(num_formats
, result
->GetNumResults());
3304 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3307 // TODO(gman): Complete this test.
3308 // TEST_P(GLES2DecoderTest, CompressedTexImage2DGLError) {
3311 // TODO(gman): CompressedTexImage2D
3313 // TODO(gman): CompressedTexImage2DImmediate
3315 // TODO(gman): CompressedTexSubImage2DImmediate
3317 // TODO(gman): TexImage2D
3319 // TODO(gman): TexImage2DImmediate
3321 // TODO(gman): TexSubImage2DImmediate
3323 } // namespace gles2