Infobar material design refresh: bg color
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_textures.cc
blobfe5c3d4666de9976fd48a78cebf113f1717a389c
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
31 #endif
33 using ::gfx::MockGLInterface;
34 using ::testing::_;
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;
49 namespace gpu {
50 namespace gles2 {
52 using namespace cmds;
54 TEST_P(GLES2DecoderTest, GenerateMipmapWrongFormatsFails) {
55 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
56 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
57 DoTexImage2D(
58 GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
59 GenerateMipmap cmd;
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();
71 GLint width = 0;
72 GLint height = 0;
73 EXPECT_FALSE(
74 texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height, nullptr));
75 DoTexImage2D(GL_TEXTURE_2D,
77 GL_RGBA,
78 16,
79 16,
81 GL_RGBA,
82 GL_UNSIGNED_BYTE,
83 kSharedMemoryId,
84 kSharedMemoryOffset);
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();
90 GenerateMipmap cmd;
91 cmd.Init(GL_TEXTURE_2D);
92 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
93 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
94 EXPECT_FALSE(
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);
101 DoTexImage2D(
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();
111 GenerateMipmap cmd;
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));
124 InitState init;
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);
130 DoTexImage2D(
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);
135 EXPECT_CALL(
136 *gl_,
137 TexParameteri(
138 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST))
139 .Times(1)
140 .RetiresOnSaturation();
141 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D));
142 EXPECT_CALL(
143 *gl_,
144 TexParameteri(
145 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR))
146 .Times(1)
147 .RetiresOnSaturation();
148 EXPECT_CALL(*gl_, GetError())
149 .WillOnce(Return(GL_NO_ERROR))
150 .WillOnce(Return(GL_NO_ERROR))
151 .RetiresOnSaturation();
152 GenerateMipmap cmd;
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);
161 ActiveTexture cmd;
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);
170 ActiveTexture cmd;
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,
185 GL_RGBA,
186 kWidth,
187 kHeight,
189 GL_RGBA,
190 GL_UNSIGNED_BYTE,
191 kSharedMemoryId,
192 kSharedMemoryOffset);
193 EXPECT_CALL(*gl_,
194 TexSubImage2D(GL_TEXTURE_2D,
198 kWidth - 1,
199 kHeight,
200 GL_RGBA,
201 GL_UNSIGNED_BYTE,
202 shared_memory_address_))
203 .Times(1)
204 .RetiresOnSaturation();
205 TexSubImage2D cmd;
206 cmd.Init(GL_TEXTURE_2D,
210 kWidth - 1,
211 kHeight,
212 GL_RGBA,
213 GL_UNSIGNED_BYTE,
214 kSharedMemoryId,
215 kSharedMemoryOffset,
216 GL_FALSE);
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,
227 GL_RGBA,
228 kWidth,
229 kHeight,
231 GL_RGBA,
232 GL_UNSIGNED_BYTE,
235 TexSubImage2D cmd;
236 cmd.Init(GL_TEXTURE0,
240 kWidth,
241 kHeight,
242 GL_RGBA,
243 GL_UNSIGNED_BYTE,
244 kSharedMemoryId,
245 kSharedMemoryOffset,
246 GL_FALSE);
247 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
248 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
249 cmd.Init(GL_TEXTURE_2D,
253 kWidth,
254 kHeight,
255 GL_TRUE,
256 GL_UNSIGNED_BYTE,
257 kSharedMemoryId,
258 kSharedMemoryOffset,
259 GL_FALSE);
260 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
261 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
262 cmd.Init(GL_TEXTURE_2D,
266 kWidth,
267 kHeight,
268 GL_RGBA,
269 GL_UNSIGNED_INT,
270 kSharedMemoryId,
271 kSharedMemoryOffset,
272 GL_FALSE);
273 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
274 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
275 cmd.Init(GL_TEXTURE_2D,
279 kWidth,
280 kHeight,
281 GL_RGBA,
282 GL_UNSIGNED_BYTE,
283 kSharedMemoryId,
284 kSharedMemoryOffset,
285 GL_FALSE);
286 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
287 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
288 cmd.Init(GL_TEXTURE_2D,
292 kWidth,
293 kHeight,
294 GL_RGBA,
295 GL_UNSIGNED_BYTE,
296 kSharedMemoryId,
297 kSharedMemoryOffset,
298 GL_FALSE);
299 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
300 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
301 cmd.Init(GL_TEXTURE_2D,
305 kWidth,
306 kHeight,
307 GL_RGBA,
308 GL_UNSIGNED_BYTE,
309 kSharedMemoryId,
310 kSharedMemoryOffset,
311 GL_FALSE);
312 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
313 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
314 cmd.Init(GL_TEXTURE_2D,
318 kWidth,
319 kHeight,
320 GL_RGBA,
321 GL_UNSIGNED_BYTE,
322 kSharedMemoryId,
323 kSharedMemoryOffset,
324 GL_FALSE);
325 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
326 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
327 cmd.Init(GL_TEXTURE_2D,
331 kWidth + 1,
332 kHeight,
333 GL_RGBA,
334 GL_UNSIGNED_BYTE,
335 kSharedMemoryId,
336 kSharedMemoryOffset,
337 GL_FALSE);
338 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
339 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
340 cmd.Init(GL_TEXTURE_2D,
344 kWidth,
345 kHeight + 1,
346 GL_RGBA,
347 GL_UNSIGNED_BYTE,
348 kSharedMemoryId,
349 kSharedMemoryOffset,
350 GL_FALSE);
351 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
352 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
353 cmd.Init(GL_TEXTURE_2D,
357 kWidth,
358 kHeight,
359 GL_RGB,
360 GL_UNSIGNED_BYTE,
361 kSharedMemoryId,
362 kSharedMemoryOffset,
363 GL_FALSE);
364 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
365 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
366 cmd.Init(GL_TEXTURE_2D,
370 kWidth,
371 kHeight,
372 GL_RGBA,
373 GL_UNSIGNED_SHORT_4_4_4_4,
374 kSharedMemoryId,
375 kSharedMemoryOffset,
376 GL_FALSE);
377 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
378 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
379 cmd.Init(GL_TEXTURE_2D,
383 kWidth,
384 kHeight,
385 GL_RGBA,
386 GL_UNSIGNED_BYTE,
387 kInvalidSharedMemoryId,
388 kSharedMemoryOffset,
389 GL_FALSE);
390 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
391 cmd.Init(GL_TEXTURE_2D,
395 kWidth,
396 kHeight,
397 GL_RGBA,
398 GL_UNSIGNED_BYTE,
399 kSharedMemoryId,
400 kInvalidSharedMemoryOffset,
401 GL_FALSE);
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,
411 GL_RGBA,
412 kWidth,
413 kHeight,
415 GL_RGBA,
416 GL_UNSIGNED_BYTE,
417 kSharedMemoryId,
418 kSharedMemoryOffset);
419 EXPECT_CALL(*gl_,
420 CopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight))
421 .Times(1)
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,
435 GL_RGBA,
436 kWidth,
437 kHeight,
439 GL_RGBA,
440 GL_UNSIGNED_BYTE,
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) {
473 TexImage2D cmd;
474 if (ii == 0) {
475 EXPECT_CALL(*gl_,
476 TexImage2D(GL_TEXTURE_2D,
478 GL_RGBA,
479 kWidth,
480 kHeight,
482 GL_RGBA,
483 GL_UNSIGNED_BYTE,
485 .Times(1)
486 .RetiresOnSaturation();
487 cmd.Init(GL_TEXTURE_2D,
489 GL_RGBA,
490 kWidth,
491 kHeight,
492 GL_RGBA,
493 GL_UNSIGNED_BYTE,
494 kSharedMemoryId,
495 kSharedMemoryOffset);
496 } else {
497 cmd.Init(GL_TEXTURE_2D,
499 GL_RGBA,
500 kWidth,
501 kHeight,
502 GL_RGBA,
503 GL_UNSIGNED_BYTE,
507 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
508 EXPECT_CALL(*gl_,
509 TexSubImage2D(GL_TEXTURE_2D,
513 kWidth,
514 kHeight - 1,
515 GL_RGBA,
516 GL_UNSIGNED_BYTE,
517 shared_memory_address_))
518 .Times(1)
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.
523 TexSubImage2D cmd2;
524 cmd2.Init(GL_TEXTURE_2D,
528 kWidth,
529 kHeight - 1,
530 GL_RGBA,
531 GL_UNSIGNED_BYTE,
532 kSharedMemoryId,
533 kSharedMemoryOffset,
534 GL_TRUE);
535 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
539 TEST_P(GLES2DecoderTest, TexImage2DGLError) {
540 GLenum target = GL_TEXTURE_2D;
541 GLint level = 0;
542 GLenum internal_format = GL_RGBA;
543 GLsizei width = 2;
544 GLsizei height = 4;
545 GLint border = 0;
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();
553 EXPECT_FALSE(
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();
559 EXPECT_CALL(*gl_,
560 TexImage2D(target,
561 level,
562 internal_format,
563 width,
564 height,
565 border,
566 format,
567 type,
569 .Times(1)
570 .RetiresOnSaturation();
571 TexImage2D cmd;
572 cmd.Init(target,
573 level,
574 internal_format,
575 width,
576 height,
577 format,
578 type,
579 kSharedMemoryId,
580 kSharedMemoryOffset);
581 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
582 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
583 EXPECT_FALSE(
584 texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height, nullptr));
587 TEST_P(GLES2DecoderTest, CopyTexImage2DGLError) {
588 GLenum target = GL_TEXTURE_2D;
589 GLint level = 0;
590 GLenum internal_format = GL_RGBA;
591 GLsizei width = 2;
592 GLsizei height = 4;
593 GLint border = 0;
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();
599 EXPECT_FALSE(
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();
605 EXPECT_CALL(*gl_,
606 CopyTexImage2D(
607 target, level, internal_format, 0, 0, width, height, border))
608 .Times(1)
609 .RetiresOnSaturation();
610 CopyTexImage2D cmd;
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());
614 EXPECT_FALSE(
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;
636 cmd.Init(kTarget,
637 kLevel,
638 kInternalFormat,
639 kWidth,
640 kHeight,
641 kDepth,
642 kBadBucketId);
643 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
645 cmd.Init(kTarget,
646 kLevel,
647 kInternalFormat,
648 kWidth,
649 kHeight,
650 kDepth,
651 kBucketId);
652 EXPECT_CALL(*gl_,
653 CompressedTexImage3D(kTarget, kLevel, kInternalFormat, kWidth,
654 kHeight, kDepth, kBorder, kImageSize, _))
655 .Times(1)
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;
680 cmd.Init(kTarget,
681 kLevel,
682 kInternalFormat,
683 kWidth,
684 kHeight,
685 kDepth,
686 kBucketId);
687 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
691 CompressedTexSubImage3DBucket cmd;
692 cmd.Init(kTarget,
693 kLevel,
694 0, 0, 0,
695 kWidth,
696 kHeight,
697 kDepth,
698 kInternalFormat,
699 kBucketId);
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;
720 cmd.Init(kTarget,
721 kLevel,
722 kInternalFormat,
723 kWidth,
724 kHeight,
725 kDepth,
726 kBucketId);
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,
749 kLevel,
750 kInternalFormat,
751 kWidth,
752 kHeight,
753 kDepth,
754 kBucketId);
755 EXPECT_CALL(*gl_,
756 CompressedTexImage3D(kTarget, kLevel, kInternalFormat, kWidth,
757 kHeight, kDepth, kBorder, kImageSize, _))
758 .Times(1)
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.
777 cmd.Init(kTarget,
778 kLevel,
779 kXOffset,
780 kYOffset,
781 kZOffset,
782 kSubWidth,
783 kSubHeight,
784 kSubDepth,
785 kFormat,
786 kBucketId);
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());
793 // Incorrect format.
794 const GLenum kBadFormat = GL_COMPRESSED_R11_EAC;
795 cmd.Init(kTarget,
796 kLevel,
797 kXOffset,
798 kYOffset,
799 kZOffset,
800 kSubWidth,
801 kSubHeight,
802 kSubDepth,
803 kBadFormat,
804 kBucketId);
805 bucket->SetSize(kSubImageSize);
806 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
807 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
809 // Negative offset.
810 cmd.Init(kTarget,
811 kLevel,
812 kXOffset,
814 kZOffset,
815 kSubWidth,
816 kSubHeight,
817 kSubDepth,
818 kFormat,
819 kBucketId);
820 bucket->SetSize(kSubImageSize);
821 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
822 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
824 // offset + size > texture size
825 cmd.Init(kTarget,
826 kLevel,
827 kXOffset,
828 kYOffset + 8,
829 kZOffset,
830 kSubWidth,
831 kSubHeight,
832 kSubDepth,
833 kFormat,
834 kBucketId);
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.
840 cmd.Init(kTarget,
841 kLevel,
842 kXOffset,
843 kYOffset + 1,
844 kZOffset,
845 kSubWidth,
846 kSubHeight,
847 kSubDepth,
848 kFormat,
849 kBucketId);
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 .
855 cmd.Init(kTarget,
856 kLevel,
857 kXOffset,
858 kYOffset,
859 kZOffset,
860 kSubWidth,
861 kSubHeight + 3,
862 kSubDepth,
863 kFormat,
864 kBucketId);
865 const GLsizei kSubImageSize2 = 128;
866 bucket->SetSize(kSubImageSize2);
867 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
868 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
870 // Bad bucket id.
871 const uint32 kBadBucketId = 444;
872 cmd.Init(kTarget,
873 kLevel,
874 kXOffset,
875 kYOffset,
876 kZOffset,
877 kSubWidth,
878 kSubHeight,
879 kSubDepth,
880 kFormat,
881 kBadBucketId);
882 bucket->SetSize(kSubImageSize);
883 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
886 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DBucketBadBucket) {
887 InitState init;
888 init.extensions = "GL_EXT_texture_compression_s3tc";
889 init.bind_generates_resource = true;
890 InitDecoder(init);
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,
900 kBadBucketId);
901 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
902 CompressedTexSubImage2DBucket cmd2;
903 cmd2.Init(GL_TEXTURE_2D,
909 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
910 kBadBucketId);
911 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
914 namespace {
916 struct S3TCTestData {
917 GLenum format;
918 size_t block_size;
921 } // anonymous namespace.
923 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DS3TC) {
924 InitState init;
925 init.extensions = "GL_EXT_texture_compression_s3tc";
926 init.bind_generates_resource = true;
927 InitDecoder(init);
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;
952 // test small width.
953 DoCompressedTexImage2D(
954 GL_TEXTURE_2D, 0, test.format, 2, 4, 0, test.block_size, kBucketId);
955 EXPECT_EQ(GL_NO_ERROR, GetGLError());
957 // test bad width.
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());
996 // test with 3 mips.
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());
1005 // Test a 16x16
1006 DoCompressedTexImage2D(GL_TEXTURE_2D,
1008 test.format,
1012 test.block_size * 4 * 4,
1013 kBucketId);
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);
1051 EXPECT_CALL(*gl_,
1052 CompressedTexSubImage2D(GL_TEXTURE_2D,
1054 xoffset,
1055 yoffset,
1056 width,
1057 height,
1058 test.format,
1059 size,
1061 .Times(1)
1062 .RetiresOnSaturation();
1063 sub_cmd.Init(GL_TEXTURE_2D,
1065 xoffset,
1066 yoffset,
1067 width,
1068 height,
1069 test.format,
1070 kBucketId);
1071 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
1072 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1080 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DETC1) {
1081 InitState init;
1082 init.extensions = "GL_OES_compressed_ETC1_RGB8_texture";
1083 init.gl_version = "opengl es 2.0";
1084 init.bind_generates_resource = true;
1085 InitDecoder(init);
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());
1116 // Test a 16x16
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,
1142 GL_RGBA,
1143 GL_UNSIGNED_BYTE,
1144 kSharedMemoryId,
1145 kSharedMemoryOffset,
1146 GL_FALSE);
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) {
1160 InitState init;
1161 init.extensions = "GL_OES_EGL_image_external";
1162 init.gl_version = "opengl es 2.0";
1163 init.bind_generates_resource = true;
1164 InitDecoder(init);
1165 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_EXTERNAL_OES, kNewServiceId));
1166 EXPECT_CALL(*gl_, GenTextures(1, _))
1167 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
1168 BindTexture cmd;
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) {
1178 InitState init;
1179 init.extensions = "GL_OES_EGL_image_external";
1180 init.gl_version = "opengl es 2.0";
1181 init.bind_generates_resource = true;
1182 InitDecoder(init);
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_);
1191 EXPECT_CALL(*gl_,
1192 GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, result->GetData()))
1193 .Times(0);
1194 result->size = 0;
1195 GetIntegerv cmd;
1196 cmd.Init(GL_TEXTURE_BINDING_EXTERNAL_OES,
1197 shared_memory_id_,
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) {
1208 InitState init;
1209 init.extensions = "GL_OES_EGL_image_external";
1210 init.gl_version = "opengl es 2.0";
1211 init.bind_generates_resource = true;
1212 InitDecoder(init);
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) {
1225 InitState init;
1226 init.extensions = "GL_OES_EGL_image_external";
1227 init.gl_version = "opengl es 2.0";
1228 init.bind_generates_resource = true;
1229 InitDecoder(init);
1230 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1232 EXPECT_CALL(*gl_,
1233 TexParameteri(
1234 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
1235 EXPECT_CALL(
1236 *gl_,
1237 TexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1238 EXPECT_CALL(
1239 *gl_,
1240 TexParameteri(
1241 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1242 EXPECT_CALL(
1243 *gl_,
1244 TexParameteri(
1245 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1246 TexParameteri cmd;
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) {
1273 InitState init;
1274 init.extensions = "GL_OES_EGL_image_external";
1275 init.gl_version = "opengl es 2.0";
1276 init.bind_generates_resource = true;
1277 InitDecoder(init);
1278 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1280 TexParameteri cmd;
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) {
1305 InitState init;
1306 init.extensions = "GL_OES_EGL_image_external";
1307 init.gl_version = "opengl es 2.0";
1308 init.bind_generates_resource = true;
1309 InitDecoder(init);
1311 GLenum target = GL_TEXTURE_EXTERNAL_OES;
1312 GLint level = 0;
1313 GLenum internal_format = GL_RGBA;
1314 GLsizei width = 2;
1315 GLsizei height = 4;
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);
1320 TexImage2D cmd;
1321 cmd.Init(target,
1322 level,
1323 internal_format,
1324 width,
1325 height,
1326 format,
1327 type,
1328 kSharedMemoryId,
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) {
1337 InitState init;
1338 InitDecoder(init);
1340 BindTexture cmd1;
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());
1346 BindTexture cmd2;
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) {
1354 InitState init;
1355 init.bind_generates_resource = true;
1356 InitDecoder(init);
1358 BindTexture cmd1;
1359 cmd1.Init(GL_TEXTURE_2D, 0);
1360 EXPECT_CALL(
1361 *gl_, BindTexture(GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId));
1362 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1363 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1365 BindTexture cmd2;
1366 cmd2.Init(GL_TEXTURE_CUBE_MAP, 0);
1367 EXPECT_CALL(*gl_,
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) {
1376 InitState init;
1377 InitDecoder(init);
1380 BindTexture cmd1;
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());
1386 TexParameterf cmd2;
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());
1393 BindTexture cmd1;
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());
1399 TexParameterf cmd2;
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) {
1407 InitState init;
1408 InitDecoder(init);
1411 BindTexture cmd1;
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());
1417 TexParameteri cmd2;
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());
1424 BindTexture cmd1;
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());
1430 TexParameteri cmd2;
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) {
1438 InitState init;
1439 InitDecoder(init);
1442 BindTexture cmd1;
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,
1453 &data);
1454 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1455 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1459 BindTexture cmd1;
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,
1470 &data);
1471 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1472 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1476 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameteriv) {
1477 InitState init;
1478 InitDecoder(init);
1481 BindTexture cmd1;
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,
1492 &data);
1493 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1494 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1498 BindTexture cmd1;
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,
1509 &data);
1510 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1511 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1515 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexImage2D) {
1516 InitState init;
1517 InitDecoder(init);
1519 BindTexture cmd1;
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());
1525 TexImage2D cmd2;
1526 cmd2.Init(GL_TEXTURE_2D,
1528 GL_RGBA,
1531 GL_RGBA,
1532 GL_UNSIGNED_BYTE,
1533 kSharedMemoryId,
1534 kSharedMemoryOffset);
1535 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1536 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1539 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexSubImage2D) {
1540 InitState init;
1541 InitDecoder(init);
1543 BindTexture cmd1;
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());
1549 TexSubImage2D cmd2;
1550 cmd2.Init(GL_TEXTURE_2D,
1556 GL_RGBA,
1557 GL_UNSIGNED_BYTE,
1558 kSharedMemoryId,
1559 kSharedMemoryOffset,
1560 GL_FALSE);
1561 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1562 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1565 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleBindTexture) {
1566 InitState init;
1567 init.extensions = "GL_ARB_texture_rectangle";
1568 init.bind_generates_resource = true;
1569 InitDecoder(init);
1570 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_RECTANGLE_ARB, kNewServiceId));
1571 EXPECT_CALL(*gl_, GenTextures(1, _))
1572 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
1573 BindTexture cmd;
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) {
1583 InitState init;
1584 init.extensions = "GL_ARB_texture_rectangle";
1585 init.bind_generates_resource = true;
1586 InitDecoder(init);
1587 DoBindTexture(
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_);
1596 EXPECT_CALL(*gl_,
1597 GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, result->GetData()))
1598 .Times(0);
1599 result->size = 0;
1600 GetIntegerv cmd;
1601 cmd.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB,
1602 shared_memory_id_,
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) {
1613 InitState init;
1614 init.extensions = "GL_ARB_texture_rectangle";
1615 init.bind_generates_resource = true;
1616 InitDecoder(init);
1617 DoBindTexture(
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) {
1629 InitState init;
1630 init.extensions = "GL_ARB_texture_rectangle";
1631 init.bind_generates_resource = true;
1632 InitDecoder(init);
1634 DoBindTexture(
1635 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1637 EXPECT_CALL(*gl_,
1638 TexParameteri(
1639 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
1640 EXPECT_CALL(*gl_,
1641 TexParameteri(
1642 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1643 EXPECT_CALL(
1644 *gl_,
1645 TexParameteri(
1646 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1647 EXPECT_CALL(
1648 *gl_,
1649 TexParameteri(
1650 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1651 TexParameteri cmd;
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) {
1677 InitState init;
1678 init.extensions = "GL_ARB_texture_rectangle";
1679 init.bind_generates_resource = true;
1680 InitDecoder(init);
1682 DoBindTexture(
1683 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1685 TexParameteri cmd;
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) {
1709 InitState init;
1710 init.extensions = "GL_ARB_texture_rectangle";
1711 init.bind_generates_resource = true;
1712 InitDecoder(init);
1714 GLenum target = GL_TEXTURE_RECTANGLE_ARB;
1715 GLint level = 0;
1716 GLenum internal_format = GL_RGBA;
1717 GLsizei width = 2;
1718 GLsizei height = 4;
1719 GLenum format = GL_RGBA;
1720 GLenum type = GL_UNSIGNED_BYTE;
1722 DoBindTexture(
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();
1730 EXPECT_CALL(*gl_,
1731 TexImage2D(target,
1732 level,
1733 internal_format,
1734 width,
1735 height,
1737 format,
1738 type,
1740 .Times(1)
1741 .RetiresOnSaturation();
1742 TexImage2D cmd;
1743 cmd.Init(target,
1744 level,
1745 internal_format,
1746 width,
1747 height,
1748 format,
1749 type,
1750 kSharedMemoryId,
1751 kSharedMemoryOffset);
1752 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1754 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1757 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTexImage2DInvalid) {
1758 InitState init;
1759 init.extensions = "GL_ARB_texture_rectangle";
1760 init.bind_generates_resource = true;
1761 InitDecoder(init);
1763 GLenum target = GL_TEXTURE_RECTANGLE_ARB;
1764 GLint level = 1;
1765 GLenum internal_format = GL_RGBA;
1766 GLsizei width = 2;
1767 GLsizei height = 4;
1768 GLenum format = GL_RGBA;
1769 GLenum type = GL_UNSIGNED_BYTE;
1771 DoBindTexture(
1772 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1773 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL);
1775 TexImage2D cmd;
1776 cmd.Init(target,
1777 level,
1778 internal_format,
1779 width,
1780 height,
1781 format,
1782 type,
1783 kSharedMemoryId,
1784 kSharedMemoryOffset);
1785 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1787 // TexImage2D may only be used with level 0 on GL_TEXTURE_RECTANGLE_ARB
1788 // targets.
1789 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1792 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DClearsAfterTexImage2DNULL) {
1793 InitState init;
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;
1799 InitDecoder(init);
1801 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1802 DoTexImage2D(
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_))
1809 .Times(2)
1810 .RetiresOnSaturation();
1811 TexSubImage2D cmd;
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_))
1821 .Times(1)
1822 .RetiresOnSaturation();
1823 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1826 TEST_P(GLES2DecoderTest, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData) {
1827 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1828 DoTexImage2D(
1829 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1830 DoTexImage2D(GL_TEXTURE_2D,
1832 GL_RGBA,
1836 GL_RGBA,
1837 GL_UNSIGNED_BYTE,
1838 kSharedMemoryId,
1839 kSharedMemoryOffset);
1840 EXPECT_CALL(*gl_,
1841 TexSubImage2D(GL_TEXTURE_2D,
1847 GL_RGBA,
1848 GL_UNSIGNED_BYTE,
1849 shared_memory_address_))
1850 .Times(1)
1851 .RetiresOnSaturation();
1852 TexSubImage2D cmd;
1853 cmd.Init(GL_TEXTURE_2D,
1859 GL_RGBA,
1860 GL_UNSIGNED_BYTE,
1861 kSharedMemoryId,
1862 kSharedMemoryOffset,
1863 GL_FALSE);
1864 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1865 // Test if we call it again it does not clear.
1866 EXPECT_CALL(*gl_,
1867 TexSubImage2D(GL_TEXTURE_2D,
1873 GL_RGBA,
1874 GL_UNSIGNED_BYTE,
1875 shared_memory_address_))
1876 .Times(1)
1877 .RetiresOnSaturation();
1878 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1881 TEST_P(
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));
1888 InitState init;
1889 init.bind_generates_resource = true;
1890 InitDecoderWithCommandLine(init, &command_line);
1891 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1892 DoTexImage2D(
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.
1898 EXPECT_CALL(*gl_,
1899 TexSubImage2D(
1900 GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, _))
1901 .Times(1)
1902 .RetiresOnSaturation();
1903 cmds::TexImage2D cmd;
1904 cmd.Init(GL_TEXTURE_2D,
1906 GL_RGBA,
1909 GL_RGBA,
1910 GL_UNSIGNED_BYTE,
1911 kSharedMemoryId,
1912 kSharedMemoryOffset);
1913 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1916 EXPECT_CALL(*gl_,
1917 TexSubImage2D(GL_TEXTURE_2D,
1923 GL_RGBA,
1924 GL_UNSIGNED_BYTE,
1925 shared_memory_address_))
1926 .Times(1)
1927 .RetiresOnSaturation();
1928 TexSubImage2D cmd;
1929 cmd.Init(GL_TEXTURE_2D,
1935 GL_RGBA,
1936 GL_UNSIGNED_BYTE,
1937 kSharedMemoryId,
1938 kSharedMemoryOffset,
1939 GL_FALSE);
1940 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1941 // Test if we call it again it does not clear.
1942 EXPECT_CALL(*gl_,
1943 TexSubImage2D(GL_TEXTURE_2D,
1949 GL_RGBA,
1950 GL_UNSIGNED_BYTE,
1951 shared_memory_address_))
1952 .Times(1)
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,
1962 GL_RGBA,
1966 GL_RGBA,
1967 GL_UNSIGNED_BYTE,
1968 kSharedMemoryId,
1969 kSharedMemoryOffset);
1970 // Put in no data.
1971 TexImage2D tex_cmd;
1972 tex_cmd.Init(
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_))
1982 .Times(2)
1983 .RetiresOnSaturation();
1984 TexSubImage2D cmd;
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))
2005 .Times(1)
2006 .RetiresOnSaturation();
2007 EXPECT_CALL(*gl_, GetError())
2008 .WillOnce(Return(GL_NO_ERROR))
2009 .RetiresOnSaturation();
2010 CopyTexImage2D cmd;
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);
2019 DoTexImage2D(
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))
2025 .Times(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))
2035 .Times(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))
2057 .Times(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))
2072 .Times(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))
2093 .Times(1)
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) {
2107 InitState init;
2108 init.extensions = "GL_EXT_texture_compression_s3tc";
2109 init.bind_generates_resource = true;
2110 InitDecoder(init);
2112 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2113 EXPECT_CALL(*gl_, GetError())
2114 .WillOnce(Return(GL_NO_ERROR))
2115 .RetiresOnSaturation();
2116 EXPECT_CALL(
2117 *gl_,
2118 CompressedTexImage2D(
2119 GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 8, _))
2120 .Times(1)
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,
2132 kSharedMemoryId,
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);
2143 TexParameteri cmd;
2144 cmd.Init(
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);
2154 DoTexImage2D(
2155 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2156 DoTexImage2D(
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.
2172 GLsizei width;
2173 GLsizei height;
2174 GLenum type;
2175 GLenum internal_format;
2177 EXPECT_TRUE(
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);
2185 EXPECT_TRUE(
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))
2205 .Times(1)
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.
2216 EXPECT_TRUE(
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);
2224 EXPECT_TRUE(
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);
2240 DoTexImage2D(
2241 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2242 DoTexImage2D(
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.
2258 GLsizei width;
2259 GLsizei height;
2260 GLenum type;
2261 GLenum internal_format;
2263 EXPECT_TRUE(
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);
2271 EXPECT_TRUE(
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.
2300 EXPECT_TRUE(
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);
2308 EXPECT_TRUE(
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);
2321 DoTexImage2D(
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, _))
2349 .Times(2)
2350 .RetiresOnSaturation();
2351 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
2352 .Times(1)
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
2362 // texture.
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, _))
2396 .Times(2)
2397 .RetiresOnSaturation();
2398 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
2399 .Times(1)
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
2411 // target.
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
2425 // service_id.
2426 EXPECT_NE(kServiceTextureId, texture->service_id());
2429 TEST_P(GLES2DecoderManualInitTest, DepthTextureBadArgs) {
2430 InitState init;
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;
2438 InitDecoder(init);
2440 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2441 // Check trying to upload data fails.
2442 TexImage2D tex_cmd;
2443 tex_cmd.Init(GL_TEXTURE_2D,
2445 GL_DEPTH_COMPONENT,
2448 GL_DEPTH_COMPONENT,
2449 GL_UNSIGNED_INT,
2450 kSharedMemoryId,
2451 kSharedMemoryOffset);
2452 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
2453 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2454 // Try level > 0.
2455 tex_cmd.Init(GL_TEXTURE_2D,
2457 GL_DEPTH_COMPONENT,
2460 GL_DEPTH_COMPONENT,
2461 GL_UNSIGNED_INT,
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,
2469 GL_DEPTH_COMPONENT,
2473 GL_DEPTH_COMPONENT,
2474 GL_UNSIGNED_INT,
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,
2487 GL_DEPTH_COMPONENT,
2488 GL_UNSIGNED_INT,
2489 kSharedMemoryId,
2490 kSharedMemoryOffset,
2491 GL_FALSE);
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) {
2509 InitState init;
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;
2517 InitDecoder(init);
2518 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2519 DoTexImage2D(GL_TEXTURE_2D,
2521 GL_DEPTH_COMPONENT,
2525 GL_DEPTH_COMPONENT,
2526 GL_UNSIGNED_INT,
2529 GenerateMipmap cmd;
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);
2537 DoTexImage2D(
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);
2549 GLsizei width;
2550 GLsizei height;
2551 GLenum type;
2552 GLenum internal_format;
2554 EXPECT_TRUE(
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);
2566 EXPECT_TRUE(
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.
2572 DoTexImage2D(
2573 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2574 EXPECT_TRUE(
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());
2604 DoTexImage2D(
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.
2612 ASSERT_FALSE(
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;
2620 GLint level = 0;
2621 GLint xoffset = 0;
2622 GLint yoffset = 0;
2623 GLsizei width = 1;
2624 GLsizei height = 1;
2625 GLint border = 0;
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);
2639 // Check binding.
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, _))
2649 .Times(1)
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,
2654 internal);
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;
2665 GLint level = 0;
2666 GLint xoffset = 0;
2667 GLint yoffset = 0;
2668 GLsizei width = 1;
2669 GLsizei height = 1;
2670 GLint border = 0;
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);
2683 // Check binding.
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))
2692 .Times(2)
2693 .RetiresOnSaturation();
2694 EXPECT_CALL(*gl_, TexSubImage2D(target, level, xoffset, yoffset, width,
2695 height, format, type, _))
2696 .Times(1)
2697 .RetiresOnSaturation();
2698 GetDecoder()->ClearLevel(texture, target, level, format, type, 0, 0, width,
2699 height);
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);
2705 DoTexImage2D(
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);
2717 GLsizei width;
2718 GLsizei height;
2719 GLenum type;
2720 GLenum internal_format;
2722 EXPECT_TRUE(
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);
2734 EXPECT_TRUE(
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));
2748 EXPECT_TRUE(
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 {
2755 public:
2756 MockGLImage() {}
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,
2771 int,
2772 gfx::OverlayTransform,
2773 const gfx::Rect&,
2774 const gfx::RectF&));
2775 MOCK_METHOD3(OnMemoryDump,
2776 void(base::trace_event::ProcessMemoryDump*,
2777 uint64_t,
2778 const std::string&));
2780 protected:
2781 virtual ~MockGLImage() {}
2784 TEST_P(GLES2DecoderWithShaderTest, UseTexImage) {
2785 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2786 DoTexImage2D(GL_TEXTURE_2D,
2788 GL_RGBA,
2792 GL_RGBA,
2793 GL_UNSIGNED_BYTE,
2794 kSharedMemoryId,
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))
2809 .Times(1)
2810 .WillOnce(Return(true))
2811 .RetiresOnSaturation();
2812 EXPECT_CALL(*image.get(), GetSize())
2813 .Times(1)
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))
2833 .Times(1)
2834 .RetiresOnSaturation();
2835 DrawArrays cmd;
2836 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2837 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2838 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2840 DoBindFramebuffer(
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))
2849 .Times(2)
2850 .RetiresOnSaturation();
2851 // Image will be 'in use' as long as bound to a framebuffer.
2852 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2853 EXPECT_CALL(*gl_,
2854 FramebufferTexture2DEXT(GL_FRAMEBUFFER,
2855 GL_COLOR_ATTACHMENT0,
2856 GL_TEXTURE_2D,
2857 kServiceTextureId,
2859 .Times(1)
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,
2868 GL_TEXTURE_2D,
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();
2878 EXPECT_CALL(*gl_,
2879 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
2880 GL_COLOR_ATTACHMENT0,
2881 GL_RENDERBUFFER,
2882 kServiceRenderbufferId))
2883 .Times(1)
2884 .RetiresOnSaturation();
2885 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2886 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2887 .Times(2)
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,
2898 GL_RENDERBUFFER,
2899 client_renderbuffer_id_);
2900 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
2903 TEST_P(GLES2DecoderManualInitTest, DrawWithGLImageExternal) {
2904 InitState init;
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;
2912 InitDecoder(init);
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();
2927 SetupIndexBuffer();
2928 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
2929 SetupExpectationsForApplyingDefaultDirtyState();
2930 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref));
2932 InSequence s;
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();
2951 DrawElements cmd;
2952 cmd.Init(GL_TRIANGLES,
2953 kValidIndexRangeCount,
2954 GL_UNSIGNED_SHORT,
2955 kValidIndexRangeStart * 2);
2956 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2957 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2960 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES2) {
2961 InitState init;
2962 init.extensions = "GL_OES_texture_float";
2963 init.gl_version = "opengl es 2.0";
2964 InitDecoder(init);
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);
2968 DoTexImage2D(
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,
2973 GL_LUMINANCE_ALPHA,
2977 GL_LUMINANCE_ALPHA,
2978 GL_FLOAT,
2983 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES3) {
2984 InitState init;
2985 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
2986 init.gl_version = "opengl es 3.0";
2987 InitDecoder(init);
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);
2991 DoTexImage2D(
2992 GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2993 DoTexImage2D(
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,
2998 GL_LUMINANCE_ALPHA,
3002 GL_LUMINANCE_ALPHA,
3003 GL_FLOAT,
3008 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DFloatOnGLES3) {
3009 InitState init;
3010 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
3011 init.gl_version = "opengl es 3.0";
3012 InitDecoder(init);
3013 const int kWidth = 8;
3014 const int kHeight = 4;
3015 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
3016 DoTexImage2D(GL_TEXTURE_2D,
3018 GL_RGBA32F,
3019 kWidth,
3020 kHeight,
3022 GL_RGBA,
3023 GL_FLOAT,
3026 EXPECT_CALL(*gl_,
3027 TexImage2D(GL_TEXTURE_2D,
3029 GL_RGBA32F,
3030 kWidth,
3031 kHeight,
3033 GL_RGBA,
3034 GL_FLOAT,
3035 shared_memory_address_))
3036 .Times(1)
3037 .RetiresOnSaturation();
3038 TexSubImage2D cmd;
3039 cmd.Init(GL_TEXTURE_2D,
3043 kWidth,
3044 kHeight,
3045 GL_RGBA,
3046 GL_FLOAT,
3047 kSharedMemoryId,
3048 kSharedMemoryOffset,
3049 GL_FALSE);
3050 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3051 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3054 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DFloatDoesClearOnGLES3) {
3055 InitState init;
3056 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
3057 init.gl_version = "opengl es 3.0";
3058 InitDecoder(init);
3059 const int kWidth = 8;
3060 const int kHeight = 4;
3061 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
3062 DoTexImage2D(GL_TEXTURE_2D,
3064 GL_RGBA32F,
3065 kWidth,
3066 kHeight,
3068 GL_RGBA,
3069 GL_FLOAT,
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_))
3077 .Times(2)
3078 .RetiresOnSaturation();
3079 TexSubImage2D cmd;
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) {
3090 InitState init;
3091 init.extensions = "GL_ARB_texture_float";
3092 InitDecoder(init);
3093 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
3094 DoTexImage2D(
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,
3099 GL_RGBA,
3103 GL_RGBA,
3104 GL_FLOAT,
3107 GL_RGBA32F_ARB);
3108 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
3110 GL_RGB,
3114 GL_RGB,
3115 GL_FLOAT,
3118 GL_RGB32F_ARB);
3119 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
3121 GL_LUMINANCE,
3125 GL_LUMINANCE,
3126 GL_FLOAT,
3129 GL_LUMINANCE32F_ARB);
3130 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
3132 GL_ALPHA,
3136 GL_ALPHA,
3137 GL_FLOAT,
3140 GL_ALPHA32F_ARB);
3141 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
3143 GL_LUMINANCE_ALPHA,
3147 GL_LUMINANCE_ALPHA,
3148 GL_FLOAT,
3151 GL_LUMINANCE_ALPHA32F_ARB);
3154 class GLES2DecoderCompressedFormatsTest : public GLES2DecoderManualInitTest {
3155 public:
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) {
3161 return true;
3164 return false;
3167 void CheckFormats(const char* extension, const GLenum* formats, int count) {
3168 InitState init;
3169 init.extensions = extension;
3170 init.bind_generates_resource = true;
3171 InitDecoder(init);
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_);
3182 GetIntegerv cmd;
3183 result->size = 0;
3184 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
3185 cmd.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS,
3186 shared_memory_id_,
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());
3194 result->size = 0;
3195 cmd.Init(GL_COMPRESSED_TEXTURE_FORMATS,
3196 shared_memory_id_,
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) {
3202 EXPECT_TRUE(
3203 ValueInArray(formats[i], result->GetData(), result->GetNumResults()));
3206 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3210 INSTANTIATE_TEST_CASE_P(Service,
3211 GLES2DecoderCompressedFormatsTest,
3212 ::testing::Bool());
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) {
3273 InitState init;
3274 init.bind_generates_resource = true;
3275 InitDecoder(init);
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_);
3286 GetIntegerv cmd;
3287 result->size = 0;
3288 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
3289 cmd.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS,
3290 shared_memory_id_,
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());
3298 result->size = 0;
3299 cmd.Init(
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) {
3309 // }
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
3324 } // namespace gpu