1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
11 #include "gpu/command_buffer/common/id_allocator.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h"
13 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
14 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
15 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
16 #include "gpu/command_buffer/service/context_group.h"
17 #include "gpu/command_buffer/service/context_state.h"
18 #include "gpu/command_buffer/service/gl_surface_mock.h"
19 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
20 #include "gpu/command_buffer/service/image_manager.h"
21 #include "gpu/command_buffer/service/mailbox_manager.h"
22 #include "gpu/command_buffer/service/mocks.h"
23 #include "gpu/command_buffer/service/program_manager.h"
24 #include "gpu/command_buffer/service/test_helper.h"
25 #include "gpu/config/gpu_switches.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/gl/gl_image_stub.h"
28 #include "ui/gl/gl_implementation.h"
29 #include "ui/gl/gl_mock.h"
30 #include "ui/gl/gl_surface_stub.h"
32 #if !defined(GL_DEPTH24_STENCIL8)
33 #define GL_DEPTH24_STENCIL8 0x88F0
36 using ::gfx::MockGLInterface
;
38 using ::testing::DoAll
;
39 using ::testing::InSequence
;
40 using ::testing::Invoke
;
41 using ::testing::MatcherCast
;
42 using ::testing::Mock
;
43 using ::testing::Pointee
;
44 using ::testing::Return
;
45 using ::testing::SaveArg
;
46 using ::testing::SetArrayArgument
;
47 using ::testing::SetArgumentPointee
;
48 using ::testing::SetArgPointee
;
49 using ::testing::StrEq
;
50 using ::testing::StrictMock
;
57 TEST_P(GLES2DecoderTest
, GenerateMipmapWrongFormatsFails
) {
58 EXPECT_CALL(*gl_
, GenerateMipmapEXT(_
)).Times(0);
59 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
61 GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 17, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
63 cmd
.Init(GL_TEXTURE_2D
);
64 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
65 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
68 TEST_P(GLES2DecoderTest
, GenerateMipmapHandlesOutOfMemory
) {
69 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
70 TextureManager
* manager
= group().texture_manager();
71 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
72 ASSERT_TRUE(texture_ref
!= NULL
);
73 Texture
* texture
= texture_ref
->texture();
77 texture
->GetLevelSize(GL_TEXTURE_2D
, 2, &width
, &height
, nullptr));
78 DoTexImage2D(GL_TEXTURE_2D
,
88 EXPECT_CALL(*gl_
, GenerateMipmapEXT(GL_TEXTURE_2D
)).Times(1);
89 EXPECT_CALL(*gl_
, GetError())
90 .WillOnce(Return(GL_NO_ERROR
))
91 .WillOnce(Return(GL_OUT_OF_MEMORY
))
92 .RetiresOnSaturation();
94 cmd
.Init(GL_TEXTURE_2D
);
95 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
96 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
98 texture
->GetLevelSize(GL_TEXTURE_2D
, 2, &width
, &height
, nullptr));
101 TEST_P(GLES2DecoderTest
, GenerateMipmapClearsUnclearedTexture
) {
102 EXPECT_CALL(*gl_
, GenerateMipmapEXT(_
)).Times(0);
103 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
105 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
106 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
107 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA
,
108 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0, 2, 2);
109 EXPECT_CALL(*gl_
, GenerateMipmapEXT(GL_TEXTURE_2D
));
110 EXPECT_CALL(*gl_
, GetError())
111 .WillOnce(Return(GL_NO_ERROR
))
112 .WillOnce(Return(GL_NO_ERROR
))
113 .RetiresOnSaturation();
115 cmd
.Init(GL_TEXTURE_2D
);
116 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
117 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
120 // Same as GenerateMipmapClearsUnclearedTexture, but with workaround
121 // |set_texture_filters_before_generating_mipmap|.
122 TEST_P(GLES2DecoderManualInitTest
, SetTextureFiltersBeforeGenerateMipmap
) {
123 base::CommandLine
command_line(0, NULL
);
124 command_line
.AppendSwitchASCII(
125 switches::kGpuDriverBugWorkarounds
,
126 base::IntToString(gpu::SET_TEXTURE_FILTER_BEFORE_GENERATING_MIPMAP
));
128 init
.bind_generates_resource
= true;
129 InitDecoderWithCommandLine(init
, &command_line
);
131 EXPECT_CALL(*gl_
, GenerateMipmapEXT(_
)).Times(0);
132 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
134 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
135 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
136 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA
,
137 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0, 2, 2);
141 GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_NEAREST
))
143 .RetiresOnSaturation();
144 EXPECT_CALL(*gl_
, GenerateMipmapEXT(GL_TEXTURE_2D
));
148 GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST_MIPMAP_LINEAR
))
150 .RetiresOnSaturation();
151 EXPECT_CALL(*gl_
, GetError())
152 .WillOnce(Return(GL_NO_ERROR
))
153 .WillOnce(Return(GL_NO_ERROR
))
154 .RetiresOnSaturation();
156 cmd
.Init(GL_TEXTURE_2D
);
157 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
158 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
161 TEST_P(GLES2DecoderTest
, ActiveTextureValidArgs
) {
162 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE1
));
163 SpecializedSetup
<ActiveTexture
, 0>(true);
165 cmd
.Init(GL_TEXTURE1
);
166 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
167 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
170 TEST_P(GLES2DecoderTest
, ActiveTextureInvalidArgs
) {
171 EXPECT_CALL(*gl_
, ActiveTexture(_
)).Times(0);
172 SpecializedSetup
<ActiveTexture
, 0>(false);
174 cmd
.Init(GL_TEXTURE0
- 1);
175 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
176 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
177 cmd
.Init(kNumTextureUnits
);
178 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
179 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
182 TEST_P(GLES2DecoderTest
, TexSubImage2DValidArgs
) {
183 const int kWidth
= 16;
184 const int kHeight
= 8;
185 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
186 DoTexImage2D(GL_TEXTURE_2D
,
195 kSharedMemoryOffset
);
197 TexSubImage2D(GL_TEXTURE_2D
,
205 shared_memory_address_
))
207 .RetiresOnSaturation();
209 cmd
.Init(GL_TEXTURE_2D
,
220 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
221 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
224 TEST_P(GLES2DecoderTest
, TexSubImage2DBadArgs
) {
225 const int kWidth
= 16;
226 const int kHeight
= 8;
227 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
228 DoTexImage2D(GL_TEXTURE_2D
,
239 cmd
.Init(GL_TEXTURE0
,
250 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
251 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
252 cmd
.Init(GL_TEXTURE_2D
,
263 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
264 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
265 cmd
.Init(GL_TEXTURE_2D
,
276 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
277 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
278 cmd
.Init(GL_TEXTURE_2D
,
289 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
290 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
291 cmd
.Init(GL_TEXTURE_2D
,
302 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
303 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
304 cmd
.Init(GL_TEXTURE_2D
,
315 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
316 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
317 cmd
.Init(GL_TEXTURE_2D
,
328 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
329 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
330 cmd
.Init(GL_TEXTURE_2D
,
341 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
342 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
343 cmd
.Init(GL_TEXTURE_2D
,
354 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
355 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
356 cmd
.Init(GL_TEXTURE_2D
,
367 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
368 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
369 cmd
.Init(GL_TEXTURE_2D
,
376 GL_UNSIGNED_SHORT_4_4_4_4
,
380 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
381 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
382 cmd
.Init(GL_TEXTURE_2D
,
390 kInvalidSharedMemoryId
,
393 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
394 cmd
.Init(GL_TEXTURE_2D
,
403 kInvalidSharedMemoryOffset
,
405 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
408 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DValidArgs
) {
409 const int kWidth
= 16;
410 const int kHeight
= 8;
411 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
412 DoTexImage2D(GL_TEXTURE_2D
,
421 kSharedMemoryOffset
);
423 CopyTexSubImage2D(GL_TEXTURE_2D
, 1, 0, 0, 0, 0, kWidth
, kHeight
))
425 .RetiresOnSaturation();
426 CopyTexSubImage2D cmd
;
427 cmd
.Init(GL_TEXTURE_2D
, 1, 0, 0, 0, 0, kWidth
, kHeight
);
428 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
429 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
432 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DBadArgs
) {
433 const int kWidth
= 16;
434 const int kHeight
= 8;
435 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
436 DoTexImage2D(GL_TEXTURE_2D
,
446 CopyTexSubImage2D cmd
;
447 cmd
.Init(GL_TEXTURE0
, 1, 0, 0, 0, 0, kWidth
, kHeight
);
448 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
449 EXPECT_EQ(GL_INVALID_ENUM
, 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, 1, 0, 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, 1, 0, 0, kWidth
, 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
+ 1, kHeight
);
463 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
464 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
465 cmd
.Init(GL_TEXTURE_2D
, 1, 0, 0, 0, 0, kWidth
, kHeight
+ 1);
466 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
467 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
470 TEST_P(GLES2DecoderTest
, TexImage2DRedefinitionSucceeds
) {
471 const int kWidth
= 16;
472 const int kHeight
= 8;
473 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
474 EXPECT_CALL(*gl_
, GetError()).WillRepeatedly(Return(GL_NO_ERROR
));
475 for (int ii
= 0; ii
< 2; ++ii
) {
479 TexImage2D(GL_TEXTURE_2D
,
489 .RetiresOnSaturation();
490 cmd
.Init(GL_TEXTURE_2D
,
498 kSharedMemoryOffset
);
500 cmd
.Init(GL_TEXTURE_2D
,
510 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
512 TexSubImage2D(GL_TEXTURE_2D
,
520 shared_memory_address_
))
522 .RetiresOnSaturation();
523 // Consider this TexSubImage2D command part of the previous TexImage2D
524 // (last GL_TRUE argument). It will be skipped if there are bugs in the
525 // redefinition case.
527 cmd2
.Init(GL_TEXTURE_2D
,
538 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
542 TEST_P(GLES2DecoderTest
, TexImage2DGLError
) {
543 GLenum target
= GL_TEXTURE_2D
;
545 GLenum internal_format
= GL_RGBA
;
549 GLenum format
= GL_RGBA
;
550 GLenum type
= GL_UNSIGNED_BYTE
;
551 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
552 TextureManager
* manager
= group().texture_manager();
553 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
554 ASSERT_TRUE(texture_ref
!= NULL
);
555 Texture
* texture
= texture_ref
->texture();
557 texture
->GetLevelSize(GL_TEXTURE_2D
, level
, &width
, &height
, nullptr));
558 EXPECT_CALL(*gl_
, GetError())
559 .WillOnce(Return(GL_NO_ERROR
))
560 .WillOnce(Return(GL_OUT_OF_MEMORY
))
561 .RetiresOnSaturation();
573 .RetiresOnSaturation();
583 kSharedMemoryOffset
);
584 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
585 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
587 texture
->GetLevelSize(GL_TEXTURE_2D
, level
, &width
, &height
, nullptr));
590 TEST_P(GLES2DecoderTest
, CopyTexImage2DGLError
) {
591 GLenum target
= GL_TEXTURE_2D
;
593 GLenum internal_format
= GL_RGBA
;
597 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
598 TextureManager
* manager
= group().texture_manager();
599 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
600 ASSERT_TRUE(texture_ref
!= NULL
);
601 Texture
* texture
= texture_ref
->texture();
603 texture
->GetLevelSize(GL_TEXTURE_2D
, level
, &width
, &height
, nullptr));
604 EXPECT_CALL(*gl_
, GetError())
605 .WillOnce(Return(GL_NO_ERROR
))
606 .WillOnce(Return(GL_OUT_OF_MEMORY
))
607 .RetiresOnSaturation();
610 target
, level
, internal_format
, 0, 0, width
, height
, border
))
612 .RetiresOnSaturation();
614 cmd
.Init(target
, level
, internal_format
, 0, 0, width
, height
);
615 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
616 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
618 texture
->GetLevelSize(GL_TEXTURE_2D
, level
, &width
, &height
, nullptr));
621 TEST_P(GLES3DecoderTest
, CompressedTexImage3DBucket
) {
622 const uint32 kBucketId
= 123;
623 const uint32 kBadBucketId
= 99;
624 const GLenum kTarget
= GL_TEXTURE_2D_ARRAY
;
625 const GLint kLevel
= 0;
626 const GLenum kInternalFormat
= GL_COMPRESSED_R11_EAC
;
627 const GLsizei kWidth
= 4;
628 const GLsizei kHeight
= 4;
629 const GLsizei kDepth
= 4;
630 const GLint kBorder
= 0;
631 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
632 ASSERT_TRUE(bucket
!= NULL
);
633 const GLsizei kImageSize
= 32;
634 bucket
->SetSize(kImageSize
);
636 DoBindTexture(kTarget
, client_texture_id_
, kServiceTextureId
);
638 CompressedTexImage3DBucket cmd
;
646 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
656 CompressedTexImage3D(kTarget
, kLevel
, kInternalFormat
, kWidth
,
657 kHeight
, kDepth
, kBorder
, kImageSize
, _
))
659 .RetiresOnSaturation();
660 EXPECT_CALL(*gl_
, GetError())
661 .WillOnce(Return(GL_NO_ERROR
))
662 .WillOnce(Return(GL_NO_ERROR
))
663 .RetiresOnSaturation();
664 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
665 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
668 TEST_P(GLES2DecoderTest
, CompressedTexImage3DFailsOnES2
) {
669 const uint32 kBucketId
= 123;
670 const GLenum kTarget
= GL_TEXTURE_2D_ARRAY
;
671 const GLint kLevel
= 0;
672 const GLenum kInternalFormat
= GL_COMPRESSED_R11_EAC
;
673 const GLsizei kWidth
= 4;
674 const GLsizei kHeight
= 4;
675 const GLsizei kDepth
= 4;
676 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
677 ASSERT_TRUE(bucket
!= NULL
);
678 const GLsizei kImageSize
= 32;
679 bucket
->SetSize(kImageSize
);
682 CompressedTexImage3DBucket cmd
;
690 EXPECT_EQ(error::kUnknownCommand
, ExecuteCmd(cmd
));
694 CompressedTexSubImage3DBucket cmd
;
703 EXPECT_EQ(error::kUnknownCommand
, ExecuteCmd(cmd
));
707 TEST_P(GLES3DecoderTest
, CompressedTexImage3DFailsWithBadImageSize
) {
708 const uint32 kBucketId
= 123;
709 const GLenum kTarget
= GL_TEXTURE_2D_ARRAY
;
710 const GLint kLevel
= 0;
711 const GLenum kInternalFormat
= GL_COMPRESSED_RGBA8_ETC2_EAC
;
712 const GLsizei kWidth
= 4;
713 const GLsizei kHeight
= 8;
714 const GLsizei kDepth
= 4;
715 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
716 ASSERT_TRUE(bucket
!= NULL
);
717 const GLsizei kBadImageSize
= 64;
718 bucket
->SetSize(kBadImageSize
);
720 DoBindTexture(kTarget
, client_texture_id_
, kServiceTextureId
);
722 CompressedTexImage3DBucket cmd
;
730 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
731 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
734 TEST_P(GLES3DecoderTest
, CompressedTexSubImage3DFails
) {
735 const uint32 kBucketId
= 123;
736 const GLenum kTarget
= GL_TEXTURE_2D_ARRAY
;
737 const GLint kLevel
= 0;
738 const GLenum kInternalFormat
= GL_COMPRESSED_RGBA8_ETC2_EAC
;
739 const GLsizei kWidth
= 4;
740 const GLsizei kHeight
= 8;
741 const GLsizei kDepth
= 4;
742 const GLint kBorder
= 0;
743 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
744 ASSERT_TRUE(bucket
!= NULL
);
745 const GLsizei kImageSize
= 128;
746 bucket
->SetSize(kImageSize
);
748 DoBindTexture(kTarget
, client_texture_id_
, kServiceTextureId
);
750 CompressedTexImage3DBucket tex_cmd
;
751 tex_cmd
.Init(kTarget
,
759 CompressedTexImage3D(kTarget
, kLevel
, kInternalFormat
, kWidth
,
760 kHeight
, kDepth
, kBorder
, kImageSize
, _
))
762 .RetiresOnSaturation();
763 EXPECT_CALL(*gl_
, GetError())
764 .WillOnce(Return(GL_NO_ERROR
))
765 .WillOnce(Return(GL_NO_ERROR
))
766 .RetiresOnSaturation();
767 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
768 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
770 const GLint kXOffset
= 0;
771 const GLint kYOffset
= 0;
772 const GLint kZOffset
= 0;
773 const GLint kSubWidth
= 4;
774 const GLint kSubHeight
= 4;
775 const GLint kSubDepth
= 4;
776 const GLenum kFormat
= kInternalFormat
;
777 CompressedTexSubImage3DBucket cmd
;
779 // Incorrect image size.
790 const GLsizei kBadSubImageSize
= 32;
791 const GLsizei kSubImageSize
= 64;
792 bucket
->SetSize(kBadSubImageSize
);
793 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
794 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
797 const GLenum kBadFormat
= GL_COMPRESSED_R11_EAC
;
808 bucket
->SetSize(kSubImageSize
);
809 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
810 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
823 bucket
->SetSize(kSubImageSize
);
824 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
825 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
827 // offset + size > texture size
838 bucket
->SetSize(kSubImageSize
);
839 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
840 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
842 // offset not a multiple of 4.
853 bucket
->SetSize(kSubImageSize
);
854 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
855 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
857 // offset + width not a multlple of 4 .
868 const GLsizei kSubImageSize2
= 128;
869 bucket
->SetSize(kSubImageSize2
);
870 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
871 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
874 const uint32 kBadBucketId
= 444;
885 bucket
->SetSize(kSubImageSize
);
886 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
889 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DBucketBadBucket
) {
891 init
.extensions
= "GL_EXT_texture_compression_s3tc";
892 init
.bind_generates_resource
= true;
895 const uint32 kBadBucketId
= 123;
896 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
897 CompressedTexImage2DBucket cmd
;
898 cmd
.Init(GL_TEXTURE_2D
,
900 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
904 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
905 CompressedTexSubImage2DBucket cmd2
;
906 cmd2
.Init(GL_TEXTURE_2D
,
912 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
,
914 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
919 struct S3TCTestData
{
924 } // anonymous namespace.
926 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DS3TC
) {
928 init
.extensions
= "GL_EXT_texture_compression_s3tc";
929 init
.bind_generates_resource
= true;
931 const uint32 kBucketId
= 123;
932 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
933 ASSERT_TRUE(bucket
!= NULL
);
935 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
937 static const S3TCTestData test_data
[] = {
939 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, 8,
942 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
, 8,
945 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, 16,
948 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
, 16,
952 for (size_t ii
= 0; ii
< arraysize(test_data
); ++ii
) {
953 const S3TCTestData
& test
= test_data
[ii
];
954 CompressedTexImage2DBucket cmd
;
956 DoCompressedTexImage2D(
957 GL_TEXTURE_2D
, 0, test
.format
, 2, 4, 0, test
.block_size
, kBucketId
);
958 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
961 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 5, 4, kBucketId
);
962 bucket
->SetSize(test
.block_size
* 2);
963 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
964 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
966 // test small height.
967 DoCompressedTexImage2D(
968 GL_TEXTURE_2D
, 0, test
.format
, 4, 2, 0, test
.block_size
, kBucketId
);
969 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
971 // test too bad height.
972 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 4, 5, kBucketId
);
973 bucket
->SetSize(test
.block_size
* 2);
974 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
975 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
977 // test small for level 0.
978 DoCompressedTexImage2D(
979 GL_TEXTURE_2D
, 0, test
.format
, 1, 1, 0, test
.block_size
, kBucketId
);
980 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
982 // test small for level 0.
983 DoCompressedTexImage2D(
984 GL_TEXTURE_2D
, 0, test
.format
, 2, 2, 0, test
.block_size
, kBucketId
);
985 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
987 // test size too large.
988 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 4, 4, kBucketId
);
989 bucket
->SetSize(test
.block_size
* 2);
990 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
991 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
993 // test size too small.
994 cmd
.Init(GL_TEXTURE_2D
, 0, test
.format
, 4, 4, kBucketId
);
995 bucket
->SetSize(test
.block_size
/ 2);
996 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
997 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1000 DoCompressedTexImage2D(
1001 GL_TEXTURE_2D
, 0, test
.format
, 4, 4, 0, test
.block_size
, kBucketId
);
1002 DoCompressedTexImage2D(
1003 GL_TEXTURE_2D
, 1, test
.format
, 2, 2, 0, test
.block_size
, kBucketId
);
1004 DoCompressedTexImage2D(
1005 GL_TEXTURE_2D
, 2, test
.format
, 1, 1, 0, test
.block_size
, kBucketId
);
1006 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1009 DoCompressedTexImage2D(GL_TEXTURE_2D
,
1015 test
.block_size
* 4 * 4,
1017 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1019 CompressedTexSubImage2DBucket sub_cmd
;
1020 bucket
->SetSize(test
.block_size
);
1021 // Test sub image bad xoffset
1022 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 1, 0, 4, 4, test
.format
, kBucketId
);
1023 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1024 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1026 // Test sub image bad yoffset
1027 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 2, 4, 4, test
.format
, kBucketId
);
1028 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1029 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1031 // Test sub image bad width
1032 bucket
->SetSize(test
.block_size
* 2);
1033 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 5, 4, test
.format
, kBucketId
);
1034 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1035 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1037 // Test sub image bad height
1038 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 4, 5, test
.format
, kBucketId
);
1039 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1040 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1042 // Test sub image bad size
1043 bucket
->SetSize(test
.block_size
+ 1);
1044 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 4, 4, test
.format
, kBucketId
);
1045 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1046 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1048 for (GLint yoffset
= 0; yoffset
<= 8; yoffset
+= 4) {
1049 for (GLint xoffset
= 0; xoffset
<= 8; xoffset
+= 4) {
1050 for (GLsizei height
= 4; height
<= 8; height
+= 4) {
1051 for (GLsizei width
= 4; width
<= 8; width
+= 4) {
1052 GLsizei size
= test
.block_size
* (width
/ 4) * (height
/ 4);
1053 bucket
->SetSize(size
);
1055 CompressedTexSubImage2D(GL_TEXTURE_2D
,
1065 .RetiresOnSaturation();
1066 sub_cmd
.Init(GL_TEXTURE_2D
,
1074 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1075 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1083 TEST_P(GLES2DecoderManualInitTest
, CompressedTexImage2DETC1
) {
1085 init
.extensions
= "GL_OES_compressed_ETC1_RGB8_texture";
1086 init
.gl_version
= "opengl es 2.0";
1087 init
.bind_generates_resource
= true;
1089 const uint32 kBucketId
= 123;
1090 CommonDecoder::Bucket
* bucket
= decoder_
->CreateBucket(kBucketId
);
1091 ASSERT_TRUE(bucket
!= NULL
);
1093 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1095 const GLenum kFormat
= GL_ETC1_RGB8_OES
;
1096 const size_t kBlockSize
= 8;
1098 CompressedTexImage2DBucket cmd
;
1099 // test small width.
1100 DoCompressedTexImage2D(GL_TEXTURE_2D
, 0, kFormat
, 4, 8, 0, 16, kBucketId
);
1101 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1103 // test small height.
1104 DoCompressedTexImage2D(GL_TEXTURE_2D
, 0, kFormat
, 8, 4, 0, 16, kBucketId
);
1105 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1107 // test size too large.
1108 cmd
.Init(GL_TEXTURE_2D
, 0, kFormat
, 4, 4, kBucketId
);
1109 bucket
->SetSize(kBlockSize
* 2);
1110 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1111 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1113 // test size too small.
1114 cmd
.Init(GL_TEXTURE_2D
, 0, kFormat
, 4, 4, kBucketId
);
1115 bucket
->SetSize(kBlockSize
/ 2);
1116 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1117 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1120 DoCompressedTexImage2D(
1121 GL_TEXTURE_2D
, 0, kFormat
, 16, 16, 0, kBlockSize
* 16, kBucketId
);
1122 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1124 // Test CompressedTexSubImage not allowed
1125 CompressedTexSubImage2DBucket sub_cmd
;
1126 bucket
->SetSize(kBlockSize
);
1127 sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 4, 4, kFormat
, kBucketId
);
1128 EXPECT_EQ(error::kNoError
, ExecuteCmd(sub_cmd
));
1129 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1131 // Test TexSubImage not allowed for ETC1 compressed texture
1132 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1133 ASSERT_TRUE(texture_ref
!= NULL
);
1134 Texture
* texture
= texture_ref
->texture();
1135 GLenum type
, internal_format
;
1136 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
1137 EXPECT_EQ(kFormat
, internal_format
);
1138 TexSubImage2D texsub_cmd
;
1139 texsub_cmd
.Init(GL_TEXTURE_2D
,
1148 kSharedMemoryOffset
,
1150 EXPECT_EQ(error::kNoError
, ExecuteCmd(texsub_cmd
));
1151 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1153 // Test CopyTexSubImage not allowed for ETC1 compressed texture
1154 CopyTexSubImage2D copy_cmd
;
1155 copy_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 4, 4);
1156 EXPECT_EQ(error::kNoError
, ExecuteCmd(copy_cmd
));
1157 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1162 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalBindTexture
) {
1164 init
.extensions
= "GL_OES_EGL_image_external";
1165 init
.gl_version
= "opengl es 2.0";
1166 init
.bind_generates_resource
= true;
1168 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_EXTERNAL_OES
, kNewServiceId
));
1169 EXPECT_CALL(*gl_
, GenTextures(1, _
))
1170 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
));
1172 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, kNewClientId
);
1173 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1174 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1175 TextureRef
* texture_ref
= GetTexture(kNewClientId
);
1176 EXPECT_TRUE(texture_ref
!= NULL
);
1177 EXPECT_TRUE(texture_ref
->texture()->target() == GL_TEXTURE_EXTERNAL_OES
);
1180 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalGetBinding
) {
1182 init
.extensions
= "GL_OES_EGL_image_external";
1183 init
.gl_version
= "opengl es 2.0";
1184 init
.bind_generates_resource
= true;
1186 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1188 EXPECT_CALL(*gl_
, GetError())
1189 .WillOnce(Return(GL_NO_ERROR
))
1190 .WillOnce(Return(GL_NO_ERROR
))
1191 .RetiresOnSaturation();
1192 typedef GetIntegerv::Result Result
;
1193 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1195 GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES
, result
->GetData()))
1199 cmd
.Init(GL_TEXTURE_BINDING_EXTERNAL_OES
,
1201 shared_memory_offset_
);
1202 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1203 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(
1204 GL_TEXTURE_BINDING_EXTERNAL_OES
),
1205 result
->GetNumResults());
1206 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1207 EXPECT_EQ(client_texture_id_
, (uint32
)result
->GetData()[0]);
1210 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTextureDefaults
) {
1212 init
.extensions
= "GL_OES_EGL_image_external";
1213 init
.gl_version
= "opengl es 2.0";
1214 init
.bind_generates_resource
= true;
1216 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1218 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1219 EXPECT_TRUE(texture_ref
!= NULL
);
1220 Texture
* texture
= texture_ref
->texture();
1221 EXPECT_TRUE(texture
->target() == GL_TEXTURE_EXTERNAL_OES
);
1222 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1223 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1224 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1227 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTextureParam
) {
1229 init
.extensions
= "GL_OES_EGL_image_external";
1230 init
.gl_version
= "opengl es 2.0";
1231 init
.bind_generates_resource
= true;
1233 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1237 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
));
1240 TexParameteri(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
));
1244 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
));
1248 GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
));
1250 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1251 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1252 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1254 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
1255 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1256 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1258 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
1259 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1260 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1262 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
1263 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1264 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1266 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1267 EXPECT_TRUE(texture_ref
!= NULL
);
1268 Texture
* texture
= texture_ref
->texture();
1269 EXPECT_TRUE(texture
->target() == GL_TEXTURE_EXTERNAL_OES
);
1270 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1271 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1272 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1275 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTextureParamInvalid
) {
1277 init
.extensions
= "GL_OES_EGL_image_external";
1278 init
.gl_version
= "opengl es 2.0";
1279 init
.bind_generates_resource
= true;
1281 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1284 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
,
1285 GL_TEXTURE_MIN_FILTER
,
1286 GL_NEAREST_MIPMAP_NEAREST
);
1287 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1288 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1290 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
1291 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1292 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1294 cmd
.Init(GL_TEXTURE_EXTERNAL_OES
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
1295 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1296 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1298 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
1299 EXPECT_TRUE(texture_ref
!= NULL
);
1300 Texture
* texture
= texture_ref
->texture();
1301 EXPECT_TRUE(texture
->target() == GL_TEXTURE_EXTERNAL_OES
);
1302 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1303 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1304 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1307 TEST_P(GLES2DecoderManualInitTest
, EGLImageExternalTexImage2DError
) {
1309 init
.extensions
= "GL_OES_EGL_image_external";
1310 init
.gl_version
= "opengl es 2.0";
1311 init
.bind_generates_resource
= true;
1314 GLenum target
= GL_TEXTURE_EXTERNAL_OES
;
1316 GLenum internal_format
= GL_RGBA
;
1319 GLenum format
= GL_RGBA
;
1320 GLenum type
= GL_UNSIGNED_BYTE
;
1321 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
1322 ASSERT_TRUE(GetTexture(client_texture_id_
) != NULL
);
1332 kSharedMemoryOffset
);
1333 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1335 // TexImage2D is not allowed with GL_TEXTURE_EXTERNAL_OES targets.
1336 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1339 TEST_P(GLES2DecoderManualInitTest
, DefaultTextureZero
) {
1344 cmd1
.Init(GL_TEXTURE_2D
, 0);
1345 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1346 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1347 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1350 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1351 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1352 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1353 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1356 TEST_P(GLES2DecoderManualInitTest
, DefaultTextureBGR
) {
1358 init
.bind_generates_resource
= true;
1362 cmd1
.Init(GL_TEXTURE_2D
, 0);
1364 *gl_
, BindTexture(GL_TEXTURE_2D
, TestHelper::kServiceDefaultTexture2dId
));
1365 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1366 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1369 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1371 BindTexture(GL_TEXTURE_CUBE_MAP
,
1372 TestHelper::kServiceDefaultTextureCubemapId
));
1373 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1374 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1377 // Test that default texture 0 is immutable.
1378 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameterf
) {
1384 cmd1
.Init(GL_TEXTURE_2D
, 0);
1385 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1386 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1387 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1390 cmd2
.Init(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1391 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1392 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1397 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1398 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1399 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1400 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1403 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1404 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1405 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1409 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameteri
) {
1415 cmd1
.Init(GL_TEXTURE_2D
, 0);
1416 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1417 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1418 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1421 cmd2
.Init(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1422 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1423 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1428 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1429 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1430 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1431 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1434 cmd2
.Init(GL_TEXTURE_CUBE_MAP
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
1435 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1436 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1440 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameterfv
) {
1446 cmd1
.Init(GL_TEXTURE_2D
, 0);
1447 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1448 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1449 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1451 GLfloat data
= GL_NEAREST
;
1452 TexParameterfvImmediate
& cmd2
=
1453 *GetImmediateAs
<TexParameterfvImmediate
>();
1454 cmd2
.Init(GL_TEXTURE_2D
,
1455 GL_TEXTURE_MAG_FILTER
,
1457 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1458 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1463 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1464 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1465 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1466 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1468 GLfloat data
= GL_NEAREST
;
1469 TexParameterfvImmediate
& cmd2
=
1470 *GetImmediateAs
<TexParameterfvImmediate
>();
1471 cmd2
.Init(GL_TEXTURE_CUBE_MAP
,
1472 GL_TEXTURE_MAG_FILTER
,
1474 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1475 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1479 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexParameteriv
) {
1485 cmd1
.Init(GL_TEXTURE_2D
, 0);
1486 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1487 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1488 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1490 GLfloat data
= GL_NEAREST
;
1491 TexParameterfvImmediate
& cmd2
=
1492 *GetImmediateAs
<TexParameterfvImmediate
>();
1493 cmd2
.Init(GL_TEXTURE_2D
,
1494 GL_TEXTURE_MAG_FILTER
,
1496 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1497 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1502 cmd1
.Init(GL_TEXTURE_CUBE_MAP
, 0);
1503 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, 0));
1504 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1505 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1507 GLfloat data
= GL_NEAREST
;
1508 TexParameterfvImmediate
& cmd2
=
1509 *GetImmediateAs
<TexParameterfvImmediate
>();
1510 cmd2
.Init(GL_TEXTURE_CUBE_MAP
,
1511 GL_TEXTURE_MAG_FILTER
,
1513 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd2
, sizeof(data
)));
1514 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1518 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexImage2D
) {
1523 cmd1
.Init(GL_TEXTURE_2D
, 0);
1524 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1525 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1526 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1529 cmd2
.Init(GL_TEXTURE_2D
,
1537 kSharedMemoryOffset
);
1538 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1539 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1542 TEST_P(GLES2DecoderManualInitTest
, NoDefaultTexSubImage2D
) {
1547 cmd1
.Init(GL_TEXTURE_2D
, 0);
1548 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, 0));
1549 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd1
));
1550 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1553 cmd2
.Init(GL_TEXTURE_2D
,
1562 kSharedMemoryOffset
,
1564 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1565 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1568 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleBindTexture
) {
1570 init
.extensions
= "GL_ARB_texture_rectangle";
1571 init
.bind_generates_resource
= true;
1573 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_RECTANGLE_ARB
, kNewServiceId
));
1574 EXPECT_CALL(*gl_
, GenTextures(1, _
))
1575 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
));
1577 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, kNewClientId
);
1578 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1579 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1580 Texture
* texture
= GetTexture(kNewClientId
)->texture();
1581 EXPECT_TRUE(texture
!= NULL
);
1582 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1585 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleGetBinding
) {
1587 init
.extensions
= "GL_ARB_texture_rectangle";
1588 init
.bind_generates_resource
= true;
1591 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1593 EXPECT_CALL(*gl_
, GetError())
1594 .WillOnce(Return(GL_NO_ERROR
))
1595 .WillOnce(Return(GL_NO_ERROR
))
1596 .RetiresOnSaturation();
1597 typedef GetIntegerv::Result Result
;
1598 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1600 GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB
, result
->GetData()))
1604 cmd
.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB
,
1606 shared_memory_offset_
);
1607 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1608 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(
1609 GL_TEXTURE_BINDING_RECTANGLE_ARB
),
1610 result
->GetNumResults());
1611 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1612 EXPECT_EQ(client_texture_id_
, (uint32
)result
->GetData()[0]);
1615 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTextureDefaults
) {
1617 init
.extensions
= "GL_ARB_texture_rectangle";
1618 init
.bind_generates_resource
= true;
1621 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1623 Texture
* texture
= GetTexture(client_texture_id_
)->texture();
1624 EXPECT_TRUE(texture
!= NULL
);
1625 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1626 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1627 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1628 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1631 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTextureParam
) {
1633 init
.extensions
= "GL_ARB_texture_rectangle";
1634 init
.bind_generates_resource
= true;
1638 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1642 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
));
1645 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
));
1649 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
));
1653 GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
));
1655 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
1656 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1657 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1659 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_MIN_FILTER
, GL_LINEAR
);
1660 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1661 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1663 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
1664 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1665 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1667 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
1668 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1669 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1671 Texture
* texture
= GetTexture(client_texture_id_
)->texture();
1672 EXPECT_TRUE(texture
!= NULL
);
1673 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1674 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1675 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1676 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1679 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTextureParamInvalid
) {
1681 init
.extensions
= "GL_ARB_texture_rectangle";
1682 init
.bind_generates_resource
= true;
1686 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1689 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
,
1690 GL_TEXTURE_MIN_FILTER
,
1691 GL_NEAREST_MIPMAP_NEAREST
);
1692 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1693 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1695 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_S
, GL_REPEAT
);
1696 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1697 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1699 cmd
.Init(GL_TEXTURE_RECTANGLE_ARB
, GL_TEXTURE_WRAP_T
, GL_REPEAT
);
1700 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1701 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
1703 Texture
* texture
= GetTexture(client_texture_id_
)->texture();
1704 EXPECT_TRUE(texture
!= NULL
);
1705 EXPECT_TRUE(texture
->target() == GL_TEXTURE_RECTANGLE_ARB
);
1706 EXPECT_TRUE(texture
->min_filter() == GL_LINEAR
);
1707 EXPECT_TRUE(texture
->wrap_s() == GL_CLAMP_TO_EDGE
);
1708 EXPECT_TRUE(texture
->wrap_t() == GL_CLAMP_TO_EDGE
);
1711 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTexImage2D
) {
1713 init
.extensions
= "GL_ARB_texture_rectangle";
1714 init
.bind_generates_resource
= true;
1717 GLenum target
= GL_TEXTURE_RECTANGLE_ARB
;
1719 GLenum internal_format
= GL_RGBA
;
1722 GLenum format
= GL_RGBA
;
1723 GLenum type
= GL_UNSIGNED_BYTE
;
1726 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1727 ASSERT_TRUE(GetTexture(client_texture_id_
) != NULL
);
1729 EXPECT_CALL(*gl_
, GetError())
1730 .WillOnce(Return(GL_NO_ERROR
))
1731 .WillOnce(Return(GL_NO_ERROR
))
1732 .RetiresOnSaturation();
1744 .RetiresOnSaturation();
1754 kSharedMemoryOffset
);
1755 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1757 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1760 TEST_P(GLES2DecoderManualInitTest
, ARBTextureRectangleTexImage2DInvalid
) {
1762 init
.extensions
= "GL_ARB_texture_rectangle";
1763 init
.bind_generates_resource
= true;
1766 GLenum target
= GL_TEXTURE_RECTANGLE_ARB
;
1768 GLenum internal_format
= GL_RGBA
;
1771 GLenum format
= GL_RGBA
;
1772 GLenum type
= GL_UNSIGNED_BYTE
;
1775 GL_TEXTURE_RECTANGLE_ARB
, client_texture_id_
, kServiceTextureId
);
1776 ASSERT_TRUE(GetTexture(client_texture_id_
) != NULL
);
1787 kSharedMemoryOffset
);
1788 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1790 // TexImage2D may only be used with level 0 on GL_TEXTURE_RECTANGLE_ARB
1792 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1795 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DClearsAfterTexImage2DNULL
) {
1797 init
.gl_version
= "opengl es 2.0";
1798 init
.has_alpha
= true;
1799 init
.has_depth
= true;
1800 init
.request_alpha
= true;
1801 init
.request_depth
= true;
1804 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1806 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1807 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
1808 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA
,
1809 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 1, 2, 1);
1810 EXPECT_CALL(*gl_
, TexSubImage2D(GL_TEXTURE_2D
, 0, 0, _
, _
, 1, GL_RGBA
,
1811 GL_UNSIGNED_BYTE
, shared_memory_address_
))
1813 .RetiresOnSaturation();
1815 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 2, 1, GL_RGBA
, GL_UNSIGNED_BYTE
,
1816 kSharedMemoryId
, kSharedMemoryOffset
, GL_FALSE
);
1817 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1818 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 1, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
,
1819 kSharedMemoryId
, kSharedMemoryOffset
, GL_FALSE
);
1820 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1821 // Test if we call it again it does not clear.
1822 EXPECT_CALL(*gl_
, TexSubImage2D(GL_TEXTURE_2D
, 0, 0, 1, 1, 1, GL_RGBA
,
1823 GL_UNSIGNED_BYTE
, shared_memory_address_
))
1825 .RetiresOnSaturation();
1826 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1829 TEST_P(GLES2DecoderTest
, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData
) {
1830 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1832 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1833 DoTexImage2D(GL_TEXTURE_2D
,
1842 kSharedMemoryOffset
);
1844 TexSubImage2D(GL_TEXTURE_2D
,
1852 shared_memory_address_
))
1854 .RetiresOnSaturation();
1856 cmd
.Init(GL_TEXTURE_2D
,
1865 kSharedMemoryOffset
,
1867 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1868 // Test if we call it again it does not clear.
1870 TexSubImage2D(GL_TEXTURE_2D
,
1878 shared_memory_address_
))
1880 .RetiresOnSaturation();
1881 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1885 GLES2DecoderManualInitTest
,
1886 TexSubImage2DDoesNotClearAfterTexImage2DNULLThenDataWithTexImage2DIsFaster
) {
1887 base::CommandLine
command_line(0, NULL
);
1888 command_line
.AppendSwitchASCII(
1889 switches::kGpuDriverBugWorkarounds
,
1890 base::IntToString(gpu::TEXSUBIMAGE_FASTER_THAN_TEXIMAGE
));
1892 init
.bind_generates_resource
= true;
1893 InitDecoderWithCommandLine(init
, &command_line
);
1894 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1896 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1899 // Uses texSubimage internally because the above workaround is active and
1900 // the update is for the full size of the texture.
1903 GL_TEXTURE_2D
, 0, 0, 0, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
1905 .RetiresOnSaturation();
1906 cmds::TexImage2D cmd
;
1907 cmd
.Init(GL_TEXTURE_2D
,
1915 kSharedMemoryOffset
);
1916 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1920 TexSubImage2D(GL_TEXTURE_2D
,
1928 shared_memory_address_
))
1930 .RetiresOnSaturation();
1932 cmd
.Init(GL_TEXTURE_2D
,
1941 kSharedMemoryOffset
,
1943 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1944 // Test if we call it again it does not clear.
1946 TexSubImage2D(GL_TEXTURE_2D
,
1954 shared_memory_address_
))
1956 .RetiresOnSaturation();
1957 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1960 TEST_P(GLES2DecoderTest
, TexSubImage2DClearsAfterTexImage2DWithDataThenNULL
) {
1961 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1962 // Put in data (so it should be marked as cleared)
1963 DoTexImage2D(GL_TEXTURE_2D
,
1972 kSharedMemoryOffset
);
1976 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1977 // It won't actually call TexImage2D, just mark it as uncleared.
1978 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
1979 // Next call to TexSubImage2d should clear.
1980 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
1981 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA
,
1982 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 1, 2, 1);
1983 EXPECT_CALL(*gl_
, TexSubImage2D(GL_TEXTURE_2D
, 0, 0, _
, _
, 1, GL_RGBA
,
1984 GL_UNSIGNED_BYTE
, shared_memory_address_
))
1986 .RetiresOnSaturation();
1988 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 2, 1, GL_RGBA
, GL_UNSIGNED_BYTE
,
1989 kSharedMemoryId
, kSharedMemoryOffset
, GL_FALSE
);
1990 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1991 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 1, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
,
1992 kSharedMemoryId
, kSharedMemoryOffset
, GL_FALSE
);
1993 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1996 TEST_P(GLES2DecoderTest
, CopyTexImage2DMarksTextureAsCleared
) {
1997 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1999 TextureManager
* manager
= group().texture_manager();
2000 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2001 ASSERT_TRUE(texture_ref
!= NULL
);
2002 Texture
* texture
= texture_ref
->texture();
2004 EXPECT_CALL(*gl_
, GetError())
2005 .WillOnce(Return(GL_NO_ERROR
))
2006 .RetiresOnSaturation();
2007 EXPECT_CALL(*gl_
, CopyTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 0, 0, 1, 1, 0))
2009 .RetiresOnSaturation();
2010 EXPECT_CALL(*gl_
, GetError())
2011 .WillOnce(Return(GL_NO_ERROR
))
2012 .RetiresOnSaturation();
2014 cmd
.Init(GL_TEXTURE_2D
, 0, GL_RGBA
, 0, 0, 1, 1);
2015 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2017 EXPECT_TRUE(texture
->SafeToRenderFrom());
2020 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DTwiceMarksTextureAsCleared
) {
2021 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2023 GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2025 // This will initialize the top part.
2027 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 2, 1))
2029 .RetiresOnSaturation();
2030 CopyTexSubImage2D cmd
;
2031 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 2, 1);
2032 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2035 // This will initialize the bottom part.
2037 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 1, 0, 0, 2, 1))
2039 .RetiresOnSaturation();
2040 CopyTexSubImage2D cmd
;
2041 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 1, 0, 0, 2, 1);
2042 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2045 TextureManager
* manager
= group().texture_manager();
2046 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2047 ASSERT_TRUE(texture_ref
!= NULL
);
2048 Texture
* texture
= texture_ref
->texture();
2049 EXPECT_TRUE(texture
->SafeToRenderFrom());
2052 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DTwiceClearsUnclearedTexture
) {
2053 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2054 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 2, 2, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0,
2057 // This will initialize the top part.
2059 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 2, 1))
2061 .RetiresOnSaturation();
2062 CopyTexSubImage2D cmd
;
2063 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 2, 1);
2064 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2067 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
2068 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA
,
2069 GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 1, 2, 1);
2071 // This will clear the bottom part as a rectangle is not sufficient to keep
2072 // track of the initialized area.
2074 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 1, 1, 0, 0, 1, 1))
2076 .RetiresOnSaturation();
2077 CopyTexSubImage2D cmd
;
2078 cmd
.Init(GL_TEXTURE_2D
, 0, 1, 1, 0, 0, 1, 1);
2079 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2082 TextureManager
* manager
= group().texture_manager();
2083 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2084 ASSERT_TRUE(texture_ref
!= NULL
);
2085 Texture
* texture
= texture_ref
->texture();
2086 EXPECT_TRUE(texture
->SafeToRenderFrom());
2089 TEST_P(GLES2DecoderTest
, CopyTexSubImage2DClearsUnclearedBackBufferSizedTexture
) {
2090 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2091 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, kBackBufferWidth
, kBackBufferHeight
,
2092 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2094 EXPECT_CALL(*gl_
, CopyTexSubImage2D(GL_TEXTURE_2D
, 0, 0, 0, 0, 0,
2095 kBackBufferWidth
, kBackBufferHeight
))
2097 .RetiresOnSaturation();
2098 CopyTexSubImage2D cmd
;
2099 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, kBackBufferWidth
, kBackBufferHeight
);
2100 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2102 TextureManager
* manager
= group().texture_manager();
2103 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2104 ASSERT_TRUE(texture_ref
!= NULL
);
2105 Texture
* texture
= texture_ref
->texture();
2106 EXPECT_TRUE(texture
->SafeToRenderFrom());
2109 TEST_P(GLES2DecoderManualInitTest
, CompressedImage2DMarksTextureAsCleared
) {
2111 init
.extensions
= "GL_EXT_texture_compression_s3tc";
2112 init
.bind_generates_resource
= true;
2115 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2116 EXPECT_CALL(*gl_
, GetError())
2117 .WillOnce(Return(GL_NO_ERROR
))
2118 .RetiresOnSaturation();
2121 CompressedTexImage2D(
2122 GL_TEXTURE_2D
, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, 4, 4, 0, 8, _
))
2124 .RetiresOnSaturation();
2125 EXPECT_CALL(*gl_
, GetError())
2126 .WillOnce(Return(GL_NO_ERROR
))
2127 .RetiresOnSaturation();
2128 CompressedTexImage2D cmd
;
2129 cmd
.Init(GL_TEXTURE_2D
,
2131 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
,
2136 kSharedMemoryOffset
);
2137 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2138 TextureManager
* manager
= group().texture_manager();
2139 TextureRef
* texture_ref
= manager
->GetTexture(client_texture_id_
);
2140 EXPECT_TRUE(texture_ref
->texture()->SafeToRenderFrom());
2143 TEST_P(GLES2DecoderTest
, TextureUsageAngleExtNotEnabledByDefault
) {
2144 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2148 GL_TEXTURE_2D
, GL_TEXTURE_USAGE_ANGLE
, GL_FRAMEBUFFER_ATTACHMENT_ANGLE
);
2149 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2150 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
2153 TEST_P(GLES2DecoderTest
, ProduceAndConsumeTextureCHROMIUM
) {
2154 Mailbox mailbox
= Mailbox::Generate();
2156 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2158 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2160 GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 4, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2161 TextureRef
* texture_ref
=
2162 group().texture_manager()->GetTexture(client_texture_id_
);
2163 ASSERT_TRUE(texture_ref
!= NULL
);
2164 Texture
* texture
= texture_ref
->texture();
2165 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2167 ProduceTextureCHROMIUMImmediate
& produce_cmd
=
2168 *GetImmediateAs
<ProduceTextureCHROMIUMImmediate
>();
2169 produce_cmd
.Init(GL_TEXTURE_2D
, mailbox
.name
);
2170 EXPECT_EQ(error::kNoError
,
2171 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2172 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2174 // Texture didn't change.
2178 GLenum internal_format
;
2181 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2182 EXPECT_EQ(3, width
);
2183 EXPECT_EQ(1, height
);
2184 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2185 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2186 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2189 texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
, nullptr));
2190 EXPECT_EQ(2, width
);
2191 EXPECT_EQ(4, height
);
2192 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2193 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2194 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2196 // Service ID has not changed.
2197 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2199 // Create new texture for consume.
2200 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2201 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
2202 .RetiresOnSaturation();
2203 DoBindTexture(GL_TEXTURE_2D
, kNewClientId
, kNewServiceId
);
2205 // Assigns and binds original service size texture ID.
2206 EXPECT_CALL(*gl_
, DeleteTextures(1, _
)).Times(1).RetiresOnSaturation();
2207 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2209 .RetiresOnSaturation();
2211 ConsumeTextureCHROMIUMImmediate
& consume_cmd
=
2212 *GetImmediateAs
<ConsumeTextureCHROMIUMImmediate
>();
2213 consume_cmd
.Init(GL_TEXTURE_2D
, mailbox
.name
);
2214 EXPECT_EQ(error::kNoError
,
2215 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
2216 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2218 // Texture is redefined.
2220 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2221 EXPECT_EQ(3, width
);
2222 EXPECT_EQ(1, height
);
2223 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2224 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2225 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2228 texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
, nullptr));
2229 EXPECT_EQ(2, width
);
2230 EXPECT_EQ(4, height
);
2231 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2232 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2233 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2235 // Service ID is restored.
2236 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2239 TEST_P(GLES2DecoderTest
, ProduceAndConsumeDirectTextureCHROMIUM
) {
2240 Mailbox mailbox
= Mailbox::Generate();
2242 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2244 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2246 GL_TEXTURE_2D
, 1, GL_RGBA
, 2, 4, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2247 TextureRef
* texture_ref
=
2248 group().texture_manager()->GetTexture(client_texture_id_
);
2249 ASSERT_TRUE(texture_ref
!= NULL
);
2250 Texture
* texture
= texture_ref
->texture();
2251 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2253 ProduceTextureDirectCHROMIUMImmediate
& produce_cmd
=
2254 *GetImmediateAs
<ProduceTextureDirectCHROMIUMImmediate
>();
2255 produce_cmd
.Init(client_texture_id_
, GL_TEXTURE_2D
, mailbox
.name
);
2256 EXPECT_EQ(error::kNoError
,
2257 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2258 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2260 // Texture didn't change.
2264 GLenum internal_format
;
2267 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2268 EXPECT_EQ(3, width
);
2269 EXPECT_EQ(1, height
);
2270 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2271 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2272 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2275 texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
, nullptr));
2276 EXPECT_EQ(2, width
);
2277 EXPECT_EQ(4, height
);
2278 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2279 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2280 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2282 // Service ID has not changed.
2283 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2285 // Consume the texture into a new client ID.
2286 GLuint new_texture_id
= kNewClientId
;
2287 CreateAndConsumeTextureCHROMIUMImmediate
& consume_cmd
=
2288 *GetImmediateAs
<CreateAndConsumeTextureCHROMIUMImmediate
>();
2289 consume_cmd
.Init(GL_TEXTURE_2D
, new_texture_id
, mailbox
.name
);
2290 EXPECT_EQ(error::kNoError
,
2291 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
2292 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2294 // Make sure the new client ID is associated with the produced service ID.
2295 texture_ref
= group().texture_manager()->GetTexture(new_texture_id
);
2296 ASSERT_TRUE(texture_ref
!= NULL
);
2297 texture
= texture_ref
->texture();
2298 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2300 DoBindTexture(GL_TEXTURE_2D
, kNewClientId
, kServiceTextureId
);
2302 // Texture is redefined.
2304 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2305 EXPECT_EQ(3, width
);
2306 EXPECT_EQ(1, height
);
2307 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2308 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2309 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2312 texture
->GetLevelSize(GL_TEXTURE_2D
, 1, &width
, &height
, nullptr));
2313 EXPECT_EQ(2, width
);
2314 EXPECT_EQ(4, height
);
2315 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 1, &type
, &internal_format
));
2316 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2317 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2320 TEST_P(GLES2DecoderTest
, ProduceTextureCHROMIUMInvalidTarget
) {
2321 Mailbox mailbox
= Mailbox::Generate();
2323 DoBindTexture(GL_TEXTURE_CUBE_MAP
, client_texture_id_
, kServiceTextureId
);
2325 GL_TEXTURE_CUBE_MAP_POSITIVE_X
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
,
2326 GL_UNSIGNED_BYTE
, 0, 0);
2327 TextureRef
* texture_ref
=
2328 group().texture_manager()->GetTexture(client_texture_id_
);
2329 ASSERT_TRUE(texture_ref
!= NULL
);
2330 Texture
* texture
= texture_ref
->texture();
2331 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2333 ProduceTextureDirectCHROMIUMImmediate
& produce_cmd
=
2334 *GetImmediateAs
<ProduceTextureDirectCHROMIUMImmediate
>();
2335 produce_cmd
.Init(client_texture_id_
, GL_TEXTURE_2D
, mailbox
.name
);
2336 EXPECT_EQ(error::kNoError
,
2337 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2339 // ProduceTexture should fail it the texture and produce targets don't match.
2340 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2343 TEST_P(GLES2DecoderTest
, CreateAndConsumeTextureCHROMIUMInvalidMailbox
) {
2344 // Attempt to consume the mailbox when no texture has been produced with it.
2345 Mailbox mailbox
= Mailbox::Generate();
2346 GLuint new_texture_id
= kNewClientId
;
2348 EXPECT_CALL(*gl_
, GenTextures(1, _
))
2349 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
2350 .RetiresOnSaturation();
2351 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, _
))
2353 .RetiresOnSaturation();
2354 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
2356 .RetiresOnSaturation();
2358 CreateAndConsumeTextureCHROMIUMImmediate
& consume_cmd
=
2359 *GetImmediateAs
<CreateAndConsumeTextureCHROMIUMImmediate
>();
2360 consume_cmd
.Init(GL_TEXTURE_2D
, new_texture_id
, mailbox
.name
);
2361 EXPECT_EQ(error::kNoError
,
2362 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
2364 // CreateAndConsumeTexture should fail if the mailbox isn't associated with a
2366 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2368 // Make sure the new client_id is associated with a texture ref even though
2369 // CreateAndConsumeTexture failed.
2370 TextureRef
* texture_ref
=
2371 group().texture_manager()->GetTexture(new_texture_id
);
2372 ASSERT_TRUE(texture_ref
!= NULL
);
2373 Texture
* texture
= texture_ref
->texture();
2374 // New texture should have the correct target type.
2375 EXPECT_TRUE(texture
->target() == GL_TEXTURE_2D
);
2376 // New texture should have a valid service_id.
2377 EXPECT_EQ(kNewServiceId
, texture
->service_id());
2380 TEST_P(GLES2DecoderTest
, CreateAndConsumeTextureCHROMIUMInvalidTarget
) {
2381 Mailbox mailbox
= Mailbox::Generate();
2383 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2384 TextureRef
* texture_ref
=
2385 group().texture_manager()->GetTexture(client_texture_id_
);
2386 ASSERT_TRUE(texture_ref
!= NULL
);
2388 ProduceTextureDirectCHROMIUMImmediate
& produce_cmd
=
2389 *GetImmediateAs
<ProduceTextureDirectCHROMIUMImmediate
>();
2390 produce_cmd
.Init(client_texture_id_
, GL_TEXTURE_2D
, mailbox
.name
);
2391 EXPECT_EQ(error::kNoError
,
2392 ExecuteImmediateCmd(produce_cmd
, sizeof(mailbox
.name
)));
2393 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2395 EXPECT_CALL(*gl_
, GenTextures(1, _
))
2396 .WillOnce(SetArgumentPointee
<1>(kNewServiceId
))
2397 .RetiresOnSaturation();
2398 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_CUBE_MAP
, _
))
2400 .RetiresOnSaturation();
2401 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
))
2403 .RetiresOnSaturation();
2405 // Attempt to consume the mailbox with a different target.
2406 GLuint new_texture_id
= kNewClientId
;
2407 CreateAndConsumeTextureCHROMIUMImmediate
& consume_cmd
=
2408 *GetImmediateAs
<CreateAndConsumeTextureCHROMIUMImmediate
>();
2409 consume_cmd
.Init(GL_TEXTURE_CUBE_MAP
, new_texture_id
, mailbox
.name
);
2410 EXPECT_EQ(error::kNoError
,
2411 ExecuteImmediateCmd(consume_cmd
, sizeof(mailbox
.name
)));
2413 // CreateAndConsumeTexture should fail if the produced texture had a different
2415 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2417 // Make sure the new client_id is associated with a texture ref even though
2418 // CreateAndConsumeTexture failed.
2419 texture_ref
= group().texture_manager()->GetTexture(new_texture_id
);
2420 ASSERT_TRUE(texture_ref
!= NULL
);
2421 Texture
* texture
= texture_ref
->texture();
2422 // New texture should have the correct target type.
2423 EXPECT_TRUE(texture
->target() == GL_TEXTURE_CUBE_MAP
);
2424 // New texture should have a valid service_id.
2425 EXPECT_EQ(kNewServiceId
, texture
->service_id());
2427 // Make sure the client_id did not become associated with the produced texture
2429 EXPECT_NE(kServiceTextureId
, texture
->service_id());
2432 TEST_P(GLES2DecoderManualInitTest
, DepthTextureBadArgs
) {
2434 init
.extensions
= "GL_ANGLE_depth_texture";
2435 init
.gl_version
= "opengl es 2.0";
2436 init
.has_depth
= true;
2437 init
.has_stencil
= true;
2438 init
.request_depth
= true;
2439 init
.request_stencil
= true;
2440 init
.bind_generates_resource
= true;
2443 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2444 // Check trying to upload data fails.
2446 tex_cmd
.Init(GL_TEXTURE_2D
,
2454 kSharedMemoryOffset
);
2455 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
2456 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2458 tex_cmd
.Init(GL_TEXTURE_2D
,
2467 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_cmd
));
2468 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2469 // Make a 1 pixel depth texture.
2470 DoTexImage2D(GL_TEXTURE_2D
,
2480 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2482 // Check that trying to update it fails.
2483 TexSubImage2D tex_sub_cmd
;
2484 tex_sub_cmd
.Init(GL_TEXTURE_2D
,
2493 kSharedMemoryOffset
,
2495 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_sub_cmd
));
2496 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2498 // Check that trying to CopyTexImage2D fails
2499 CopyTexImage2D copy_tex_cmd
;
2500 copy_tex_cmd
.Init(GL_TEXTURE_2D
, 0, GL_DEPTH_COMPONENT
, 0, 0, 1, 1);
2501 EXPECT_EQ(error::kNoError
, ExecuteCmd(copy_tex_cmd
));
2502 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2504 // Check that trying to CopyTexSubImage2D fails
2505 CopyTexSubImage2D copy_sub_cmd
;
2506 copy_sub_cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, 0, 0, 1, 1);
2507 EXPECT_EQ(error::kNoError
, ExecuteCmd(copy_sub_cmd
));
2508 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2511 TEST_P(GLES2DecoderManualInitTest
, GenerateMipmapDepthTexture
) {
2513 init
.extensions
= "GL_ANGLE_depth_texture";
2514 init
.gl_version
= "opengl es 2.0";
2515 init
.has_depth
= true;
2516 init
.has_stencil
= true;
2517 init
.request_depth
= true;
2518 init
.request_stencil
= true;
2519 init
.bind_generates_resource
= true;
2521 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2522 DoTexImage2D(GL_TEXTURE_2D
,
2533 cmd
.Init(GL_TEXTURE_2D
);
2534 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2535 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2538 TEST_P(GLES2DecoderTest
, BindTexImage2DCHROMIUM
) {
2539 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2541 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2542 TextureRef
* texture_ref
=
2543 group().texture_manager()->GetTexture(client_texture_id_
);
2544 ASSERT_TRUE(texture_ref
!= NULL
);
2545 Texture
* texture
= texture_ref
->texture();
2546 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2548 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2549 GetImageManager()->AddImage(image
.get(), 1);
2550 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL
);
2555 GLenum internal_format
;
2558 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2559 EXPECT_EQ(3, width
);
2560 EXPECT_EQ(1, height
);
2561 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2562 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2563 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2564 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2566 // Bind image to texture.
2567 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2568 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2570 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2571 // Image should now be set.
2572 EXPECT_FALSE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2574 // Define new texture image.
2576 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2578 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2579 // Image should no longer be set.
2580 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2583 TEST_P(GLES2DecoderTest
, BindTexImage2DCHROMIUMCubeMapNotAllowed
) {
2584 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2585 GetImageManager()->AddImage(image
.get(), 1);
2586 DoBindTexture(GL_TEXTURE_CUBE_MAP
, client_texture_id_
, kServiceTextureId
);
2588 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd
;
2589 bind_tex_image_2d_cmd
.Init(GL_TEXTURE_CUBE_MAP
, 1);
2590 EXPECT_EQ(error::kNoError
, ExecuteCmd(bind_tex_image_2d_cmd
));
2591 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
2594 TEST_P(GLES2DecoderTest
, OrphanGLImageWithTexImage2D
) {
2595 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2596 GetImageManager()->AddImage(image
.get(), 1);
2597 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2599 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2601 TextureRef
* texture_ref
=
2602 group().texture_manager()->GetTexture(client_texture_id_
);
2603 ASSERT_TRUE(texture_ref
!= NULL
);
2604 Texture
* texture
= texture_ref
->texture();
2606 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2608 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2609 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2612 TEST_P(GLES2DecoderTest
, GLImageAttachedAfterSubTexImage2D
) {
2613 // Specifically tests that TexSubImage2D is not optimized to TexImage2D
2614 // in the presence of image attachments.
2616 feature_info()->workarounds().texsubimage_faster_than_teximage
);
2618 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2619 GetImageManager()->AddImage(image
.get(), 1);
2620 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2622 GLenum target
= GL_TEXTURE_2D
;
2629 GLenum format
= GL_RGBA
;
2630 GLenum type
= GL_UNSIGNED_BYTE
;
2631 uint32_t pixels_shm_id
= kSharedMemoryId
;
2632 uint32_t pixels_shm_offset
= kSharedMemoryOffset
;
2633 GLboolean internal
= 0;
2635 // Define texture first.
2636 DoTexImage2D(target
, level
, format
, width
, height
, border
, format
, type
,
2637 pixels_shm_id
, pixels_shm_offset
);
2639 // Bind texture to GLImage.
2640 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2643 TextureRef
* texture_ref
=
2644 group().texture_manager()->GetTexture(client_texture_id_
);
2645 ASSERT_TRUE(texture_ref
!= NULL
);
2646 Texture
* texture
= texture_ref
->texture();
2647 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2649 // TexSubImage2D should not unbind GLImage.
2650 EXPECT_CALL(*gl_
, TexSubImage2D(target
, level
, xoffset
, yoffset
, width
,
2651 height
, format
, type
, _
))
2653 .RetiresOnSaturation();
2654 cmds::TexSubImage2D tex_sub_image_2d_cmd
;
2655 tex_sub_image_2d_cmd
.Init(target
, level
, xoffset
, yoffset
, width
, height
,
2656 format
, type
, pixels_shm_id
, pixels_shm_offset
,
2658 EXPECT_EQ(error::kNoError
, ExecuteCmd(tex_sub_image_2d_cmd
));
2659 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2662 TEST_P(GLES2DecoderTest
, GLImageAttachedAfterClearLevel
) {
2663 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2664 GetImageManager()->AddImage(image
.get(), 1);
2665 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2667 GLenum target
= GL_TEXTURE_2D
;
2674 GLenum format
= GL_RGBA
;
2675 GLenum type
= GL_UNSIGNED_BYTE
;
2676 uint32_t pixels_shm_id
= kSharedMemoryId
;
2677 uint32_t pixels_shm_offset
= kSharedMemoryOffset
;
2679 // Define texture first.
2680 DoTexImage2D(target
, level
, format
, width
, height
, border
, format
, type
,
2681 pixels_shm_id
, pixels_shm_offset
);
2683 // Bind texture to GLImage.
2684 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2687 TextureRef
* texture_ref
=
2688 group().texture_manager()->GetTexture(client_texture_id_
);
2689 ASSERT_TRUE(texture_ref
!= NULL
);
2690 Texture
* texture
= texture_ref
->texture();
2691 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2693 // ClearLevel should use glTexSubImage2D to avoid unbinding GLImage.
2694 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2696 .RetiresOnSaturation();
2697 EXPECT_CALL(*gl_
, TexSubImage2D(target
, level
, xoffset
, yoffset
, width
,
2698 height
, format
, type
, _
))
2700 .RetiresOnSaturation();
2701 GetDecoder()->ClearLevel(texture
, target
, level
, format
, type
, 0, 0, width
,
2703 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == image
.get());
2706 TEST_P(GLES2DecoderTest
, ReleaseTexImage2DCHROMIUM
) {
2707 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2709 GL_TEXTURE_2D
, 0, GL_RGBA
, 3, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2710 TextureRef
* texture_ref
=
2711 group().texture_manager()->GetTexture(client_texture_id_
);
2712 ASSERT_TRUE(texture_ref
!= NULL
);
2713 Texture
* texture
= texture_ref
->texture();
2714 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2716 scoped_refptr
<gfx::GLImage
> image(new gfx::GLImageStub
);
2717 GetImageManager()->AddImage(image
.get(), 1);
2718 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL
);
2723 GLenum internal_format
;
2726 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2727 EXPECT_EQ(3, width
);
2728 EXPECT_EQ(1, height
);
2729 EXPECT_TRUE(texture
->GetLevelType(GL_TEXTURE_2D
, 0, &type
, &internal_format
));
2730 EXPECT_EQ(static_cast<GLenum
>(GL_RGBA
), internal_format
);
2731 EXPECT_EQ(static_cast<GLenum
>(GL_UNSIGNED_BYTE
), type
);
2732 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2734 // Bind image to texture.
2735 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2736 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, 1);
2738 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2739 // Image should now be set.
2740 EXPECT_FALSE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2742 // Release image from texture.
2743 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2744 EXPECT_CALL(*gl_
, GetError())
2745 .WillOnce(Return(GL_NO_ERROR
))
2746 .WillOnce(Return(GL_NO_ERROR
))
2747 .RetiresOnSaturation();
2748 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd
;
2749 release_tex_image_2d_cmd
.Init(GL_TEXTURE_2D
, 1);
2750 EXPECT_EQ(error::kNoError
, ExecuteCmd(release_tex_image_2d_cmd
));
2752 texture
->GetLevelSize(GL_TEXTURE_2D
, 0, &width
, &height
, nullptr));
2753 // Image should no longer be set.
2754 EXPECT_TRUE(texture
->GetLevelImage(GL_TEXTURE_2D
, 0) == NULL
);
2757 class MockGLImage
: public gfx::GLImage
{
2761 // Overridden from gfx::GLImage:
2762 MOCK_METHOD0(GetSize
, gfx::Size());
2763 MOCK_METHOD0(GetInternalFormat
, unsigned());
2764 MOCK_METHOD1(Destroy
, void(bool));
2765 MOCK_METHOD1(BindTexImage
, bool(unsigned));
2766 MOCK_METHOD1(ReleaseTexImage
, void(unsigned));
2767 MOCK_METHOD3(CopyTexSubImage
,
2768 bool(unsigned, const gfx::Point
&, const gfx::Rect
&));
2769 MOCK_METHOD0(WillUseTexImage
, void());
2770 MOCK_METHOD0(DidUseTexImage
, void());
2771 MOCK_METHOD0(WillModifyTexImage
, void());
2772 MOCK_METHOD0(DidModifyTexImage
, void());
2773 MOCK_METHOD5(ScheduleOverlayPlane
, bool(gfx::AcceleratedWidget
,
2775 gfx::OverlayTransform
,
2777 const gfx::RectF
&));
2778 MOCK_METHOD3(OnMemoryDump
,
2779 void(base::trace_event::ProcessMemoryDump
*,
2781 const std::string
&));
2784 virtual ~MockGLImage() {}
2787 TEST_P(GLES2DecoderWithShaderTest
, UseTexImage
) {
2788 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2789 DoTexImage2D(GL_TEXTURE_2D
,
2798 kSharedMemoryOffset
);
2800 TextureRef
* texture_ref
=
2801 group().texture_manager()->GetTexture(client_texture_id_
);
2802 ASSERT_TRUE(texture_ref
!= NULL
);
2803 Texture
* texture
= texture_ref
->texture();
2804 EXPECT_EQ(kServiceTextureId
, texture
->service_id());
2806 const int32 kImageId
= 1;
2807 scoped_refptr
<MockGLImage
> image(new MockGLImage
);
2808 GetImageManager()->AddImage(image
.get(), kImageId
);
2810 // Bind image to texture.
2811 EXPECT_CALL(*image
.get(), BindTexImage(GL_TEXTURE_2D
))
2813 .WillOnce(Return(true))
2814 .RetiresOnSaturation();
2815 EXPECT_CALL(*image
.get(), GetSize())
2817 .WillOnce(Return(gfx::Size(1, 1)))
2818 .RetiresOnSaturation();
2819 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2820 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D
, kImageId
);
2822 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
2823 SetupExpectationsForApplyingDefaultDirtyState();
2825 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2826 EXPECT_CALL(*gl_
, GetError())
2827 .WillOnce(Return(GL_NO_ERROR
))
2828 .WillOnce(Return(GL_NO_ERROR
))
2829 .WillOnce(Return(GL_NO_ERROR
))
2830 .WillOnce(Return(GL_NO_ERROR
))
2831 .RetiresOnSaturation();
2832 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(3).RetiresOnSaturation();
2833 EXPECT_CALL(*image
.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2834 EXPECT_CALL(*image
.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2835 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
2837 .RetiresOnSaturation();
2839 cmd
.Init(GL_TRIANGLES
, 0, kNumVertices
);
2840 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2841 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2844 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2845 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2846 EXPECT_CALL(*gl_
, GetError())
2847 .WillOnce(Return(GL_NO_ERROR
))
2848 .WillOnce(Return(GL_NO_ERROR
))
2849 .RetiresOnSaturation();
2850 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2851 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2853 .RetiresOnSaturation();
2854 // Image will be 'in use' as long as bound to a framebuffer.
2855 EXPECT_CALL(*image
.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2857 FramebufferTexture2DEXT(GL_FRAMEBUFFER
,
2858 GL_COLOR_ATTACHMENT0
,
2863 .RetiresOnSaturation();
2864 EXPECT_CALL(*gl_
, GetError())
2865 .WillOnce(Return(GL_NO_ERROR
))
2866 .WillOnce(Return(GL_NO_ERROR
))
2867 .RetiresOnSaturation();
2868 FramebufferTexture2D fbtex_cmd
;
2869 fbtex_cmd
.Init(GL_FRAMEBUFFER
,
2870 GL_COLOR_ATTACHMENT0
,
2872 client_texture_id_
);
2873 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbtex_cmd
));
2874 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2876 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2877 EXPECT_CALL(*gl_
, GetError())
2878 .WillOnce(Return(GL_NO_ERROR
))
2879 .WillOnce(Return(GL_NO_ERROR
))
2880 .RetiresOnSaturation();
2882 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
2883 GL_COLOR_ATTACHMENT0
,
2885 kServiceRenderbufferId
))
2887 .RetiresOnSaturation();
2888 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2889 EXPECT_CALL(*gl_
, BindTexture(GL_TEXTURE_2D
, kServiceTextureId
))
2891 .RetiresOnSaturation();
2892 // Image should no longer be 'in use' after being unbound from framebuffer.
2893 EXPECT_CALL(*image
.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2894 EXPECT_CALL(*gl_
, GetError())
2895 .WillOnce(Return(GL_NO_ERROR
))
2896 .WillOnce(Return(GL_NO_ERROR
))
2897 .RetiresOnSaturation();
2898 FramebufferRenderbuffer fbrb_cmd
;
2899 fbrb_cmd
.Init(GL_FRAMEBUFFER
,
2900 GL_COLOR_ATTACHMENT0
,
2902 client_renderbuffer_id_
);
2903 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbrb_cmd
));
2906 TEST_P(GLES2DecoderManualInitTest
, DrawWithGLImageExternal
) {
2908 init
.extensions
= "GL_OES_EGL_image_external";
2909 init
.gl_version
= "opengl es 2.0";
2910 init
.has_alpha
= true;
2911 init
.has_depth
= true;
2912 init
.request_alpha
= true;
2913 init
.request_depth
= true;
2914 init
.bind_generates_resource
= true;
2917 TextureRef
* texture_ref
= GetTexture(client_texture_id_
);
2918 scoped_refptr
<MockGLImage
> image(new MockGLImage
);
2919 group().texture_manager()->SetTarget(texture_ref
, GL_TEXTURE_EXTERNAL_OES
);
2920 group().texture_manager()->SetLevelInfo(texture_ref
, GL_TEXTURE_EXTERNAL_OES
,
2921 0, GL_RGBA
, 0, 0, 1, 0, GL_RGBA
,
2922 GL_UNSIGNED_BYTE
, gfx::Rect());
2923 group().texture_manager()->SetLevelImage(
2924 texture_ref
, GL_TEXTURE_EXTERNAL_OES
, 0, image
.get());
2926 DoBindTexture(GL_TEXTURE_EXTERNAL_OES
, client_texture_id_
, kServiceTextureId
);
2927 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2929 SetupSamplerExternalProgram();
2931 AddExpectationsForSimulatedAttrib0(kMaxValidIndex
+ 1, 0);
2932 SetupExpectationsForApplyingDefaultDirtyState();
2933 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref
));
2936 EXPECT_CALL(*gl_
, GetError())
2937 .WillOnce(Return(GL_NO_ERROR
))
2938 .RetiresOnSaturation();
2939 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2940 EXPECT_CALL(*image
.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2941 EXPECT_CALL(*gl_
, GetError())
2942 .WillOnce(Return(GL_NO_ERROR
))
2943 .RetiresOnSaturation();
2944 EXPECT_CALL(*gl_
, DrawElements(_
, _
, _
, _
)).Times(1);
2945 EXPECT_CALL(*gl_
, GetError())
2946 .WillOnce(Return(GL_NO_ERROR
))
2947 .RetiresOnSaturation();
2948 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2949 EXPECT_CALL(*image
.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2950 EXPECT_CALL(*gl_
, GetError())
2951 .WillOnce(Return(GL_NO_ERROR
))
2952 .RetiresOnSaturation();
2953 EXPECT_CALL(*gl_
, ActiveTexture(GL_TEXTURE0
)).Times(1).RetiresOnSaturation();
2955 cmd
.Init(GL_TRIANGLES
,
2956 kValidIndexRangeCount
,
2958 kValidIndexRangeStart
* 2);
2959 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2960 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2963 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatOnGLES2
) {
2965 init
.extensions
= "GL_OES_texture_float";
2966 init
.gl_version
= "opengl es 2.0";
2968 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2969 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2970 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 16, 17, 0, GL_RGB
, GL_FLOAT
, 0, 0);
2972 GL_TEXTURE_2D
, 0, GL_LUMINANCE
, 16, 17, 0, GL_LUMINANCE
, GL_FLOAT
, 0, 0);
2973 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, 16, 17, 0, GL_ALPHA
, GL_FLOAT
, 0, 0);
2974 DoTexImage2D(GL_TEXTURE_2D
,
2986 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatOnGLES3
) {
2988 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
2989 init
.gl_version
= "opengl es 3.0";
2991 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
2992 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGBA
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2993 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 16, 17, 0, GL_RGB
, GL_FLOAT
, 0, 0);
2995 GL_TEXTURE_2D
, 0, GL_RGBA32F
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
2997 GL_TEXTURE_2D
, 0, GL_LUMINANCE
, 16, 17, 0, GL_LUMINANCE
, GL_FLOAT
, 0, 0);
2998 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_ALPHA
, 16, 17, 0, GL_ALPHA
, GL_FLOAT
, 0, 0);
2999 DoTexImage2D(GL_TEXTURE_2D
,
3011 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DFloatOnGLES3
) {
3013 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
3014 init
.gl_version
= "opengl es 3.0";
3016 const int kWidth
= 8;
3017 const int kHeight
= 4;
3018 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
3019 DoTexImage2D(GL_TEXTURE_2D
,
3030 TexImage2D(GL_TEXTURE_2D
,
3038 shared_memory_address_
))
3040 .RetiresOnSaturation();
3042 cmd
.Init(GL_TEXTURE_2D
,
3051 kSharedMemoryOffset
,
3053 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3054 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3057 TEST_P(GLES2DecoderManualInitTest
, TexSubImage2DFloatDoesClearOnGLES3
) {
3059 init
.extensions
= "GL_OES_texture_float GL_EXT_color_buffer_float";
3060 init
.gl_version
= "opengl es 3.0";
3062 const int kWidth
= 8;
3063 const int kHeight
= 4;
3064 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
3065 DoTexImage2D(GL_TEXTURE_2D
,
3075 SetupClearTextureExpectations(kServiceTextureId
, kServiceTextureId
,
3076 GL_TEXTURE_2D
, GL_TEXTURE_2D
, 0, GL_RGBA32F
,
3077 GL_RGBA
, GL_FLOAT
, 0, kHeight
- 1, kWidth
, 1);
3078 EXPECT_CALL(*gl_
, TexSubImage2D(GL_TEXTURE_2D
, 0, 0, _
, _
, _
, GL_RGBA
,
3079 GL_FLOAT
, shared_memory_address_
))
3081 .RetiresOnSaturation();
3083 cmd
.Init(GL_TEXTURE_2D
, 0, 0, 0, kWidth
, kHeight
- 1, GL_RGBA
, GL_FLOAT
,
3084 kSharedMemoryId
, kSharedMemoryOffset
, GL_FALSE
);
3085 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3086 cmd
.Init(GL_TEXTURE_2D
, 0, 0, kHeight
- 1, kWidth
- 1, 1, GL_RGBA
, GL_FLOAT
,
3087 kSharedMemoryId
, kSharedMemoryOffset
, GL_FALSE
);
3088 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3089 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3092 TEST_P(GLES2DecoderManualInitTest
, TexImage2DFloatConvertsFormatDesktop
) {
3094 init
.extensions
= "GL_ARB_texture_float";
3096 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
3098 GL_TEXTURE_2D
, 0, GL_RGBA32F
, 16, 17, 0, GL_RGBA
, GL_FLOAT
, 0, 0);
3099 DoTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB32F
, 16, 17, 0, GL_RGB
, GL_FLOAT
, 0, 0);
3100 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3111 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3122 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3132 GL_LUMINANCE32F_ARB
);
3133 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3144 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D
,
3154 GL_LUMINANCE_ALPHA32F_ARB
);
3157 class GLES2DecoderCompressedFormatsTest
: public GLES2DecoderManualInitTest
{
3159 GLES2DecoderCompressedFormatsTest() {}
3161 static bool ValueInArray(GLint value
, GLint
* array
, GLint count
) {
3162 for (GLint ii
= 0; ii
< count
; ++ii
) {
3163 if (array
[ii
] == value
) {
3170 void CheckFormats(const char* extension
, const GLenum
* formats
, int count
) {
3172 init
.extensions
= extension
;
3173 init
.bind_generates_resource
= true;
3176 EXPECT_CALL(*gl_
, GetError())
3177 .WillOnce(Return(GL_NO_ERROR
))
3178 .WillOnce(Return(GL_NO_ERROR
))
3179 .WillOnce(Return(GL_NO_ERROR
))
3180 .WillOnce(Return(GL_NO_ERROR
))
3181 .RetiresOnSaturation();
3183 typedef GetIntegerv::Result Result
;
3184 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
3187 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
3188 cmd
.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
3190 shared_memory_offset_
);
3191 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3192 EXPECT_EQ(1, result
->GetNumResults());
3193 GLint num_formats
= result
->GetData()[0];
3194 EXPECT_EQ(count
, num_formats
);
3195 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3198 cmd
.Init(GL_COMPRESSED_TEXTURE_FORMATS
,
3200 shared_memory_offset_
);
3201 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3202 EXPECT_EQ(num_formats
, result
->GetNumResults());
3204 for (int i
= 0; i
< count
; ++i
) {
3206 ValueInArray(formats
[i
], result
->GetData(), result
->GetNumResults()));
3209 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3213 INSTANTIATE_TEST_CASE_P(Service
,
3214 GLES2DecoderCompressedFormatsTest
,
3217 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsS3TC
) {
3218 const GLenum formats
[] = {
3219 GL_COMPRESSED_RGB_S3TC_DXT1_EXT
, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT
,
3220 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
};
3221 CheckFormats("GL_EXT_texture_compression_s3tc", formats
, 4);
3224 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsATC
) {
3225 const GLenum formats
[] = {GL_ATC_RGB_AMD
, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD
,
3226 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD
};
3227 CheckFormats("GL_AMD_compressed_ATC_texture", formats
, 3);
3230 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsPVRTC
) {
3231 const GLenum formats
[] = {
3232 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG
, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG
,
3233 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG
, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG
};
3234 CheckFormats("GL_IMG_texture_compression_pvrtc", formats
, 4);
3237 TEST_P(GLES2DecoderCompressedFormatsTest
, GetCompressedTextureFormatsETC1
) {
3238 const GLenum formats
[] = {GL_ETC1_RGB8_OES
};
3239 CheckFormats("GL_OES_compressed_ETC1_RGB8_texture", formats
, 1);
3242 TEST_P(GLES2DecoderManualInitTest
, GetNoCompressedTextureFormats
) {
3244 init
.bind_generates_resource
= true;
3247 EXPECT_CALL(*gl_
, GetError())
3248 .WillOnce(Return(GL_NO_ERROR
))
3249 .WillOnce(Return(GL_NO_ERROR
))
3250 .WillOnce(Return(GL_NO_ERROR
))
3251 .WillOnce(Return(GL_NO_ERROR
))
3252 .RetiresOnSaturation();
3254 typedef GetIntegerv::Result Result
;
3255 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
3258 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
3259 cmd
.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS
,
3261 shared_memory_offset_
);
3262 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3263 EXPECT_EQ(1, result
->GetNumResults());
3264 GLint num_formats
= result
->GetData()[0];
3265 EXPECT_EQ(0, num_formats
);
3266 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3270 GL_COMPRESSED_TEXTURE_FORMATS
, shared_memory_id_
, shared_memory_offset_
);
3271 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
3272 EXPECT_EQ(num_formats
, result
->GetNumResults());
3274 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
3277 // TODO(gman): Complete this test.
3278 // TEST_P(GLES2DecoderTest, CompressedTexImage2DGLError) {
3281 // TODO(gman): CompressedTexImage2D
3283 // TODO(gman): CompressedTexImage2DImmediate
3285 // TODO(gman): CompressedTexSubImage2DImmediate
3287 // TODO(gman): TexImage2D
3289 // TODO(gman): TexImage2DImmediate
3291 // TODO(gman): TexSubImage2DImmediate
3293 } // namespace gles2