Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_textures.cc
blobd688bc3ac690d2c35676124a0d177ddf05cb9c74
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "gpu/command_buffer/service/gles2_cmd_decoder.h"
7 #include "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
9 #include "gpu/command_buffer/common/gles2_cmd_format.h"
10 #include "gpu/command_buffer/common/gles2_cmd_utils.h"
11 #include "gpu/command_buffer/common/id_allocator.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_delegate_mock.h"
13 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
14 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
15 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
16 #include "gpu/command_buffer/service/context_group.h"
17 #include "gpu/command_buffer/service/context_state.h"
18 #include "gpu/command_buffer/service/gl_surface_mock.h"
19 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
20 #include "gpu/command_buffer/service/image_manager.h"
21 #include "gpu/command_buffer/service/mailbox_manager.h"
22 #include "gpu/command_buffer/service/mocks.h"
23 #include "gpu/command_buffer/service/program_manager.h"
24 #include "gpu/command_buffer/service/test_helper.h"
25 #include "gpu/config/gpu_switches.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/gl/gl_image_stub.h"
28 #include "ui/gl/gl_implementation.h"
29 #include "ui/gl/gl_mock.h"
30 #include "ui/gl/gl_surface_stub.h"
32 #if !defined(GL_DEPTH24_STENCIL8)
33 #define GL_DEPTH24_STENCIL8 0x88F0
34 #endif
36 using ::gfx::MockGLInterface;
37 using ::testing::_;
38 using ::testing::DoAll;
39 using ::testing::InSequence;
40 using ::testing::Invoke;
41 using ::testing::MatcherCast;
42 using ::testing::Mock;
43 using ::testing::Pointee;
44 using ::testing::Return;
45 using ::testing::SaveArg;
46 using ::testing::SetArrayArgument;
47 using ::testing::SetArgumentPointee;
48 using ::testing::SetArgPointee;
49 using ::testing::StrEq;
50 using ::testing::StrictMock;
52 namespace gpu {
53 namespace gles2 {
55 using namespace cmds;
57 TEST_P(GLES2DecoderTest, GenerateMipmapWrongFormatsFails) {
58 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
59 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
60 DoTexImage2D(
61 GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
62 GenerateMipmap cmd;
63 cmd.Init(GL_TEXTURE_2D);
64 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
65 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
68 TEST_P(GLES2DecoderTest, GenerateMipmapHandlesOutOfMemory) {
69 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
70 TextureManager* manager = group().texture_manager();
71 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
72 ASSERT_TRUE(texture_ref != NULL);
73 Texture* texture = texture_ref->texture();
74 GLint width = 0;
75 GLint height = 0;
76 EXPECT_FALSE(
77 texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height, nullptr));
78 DoTexImage2D(GL_TEXTURE_2D,
80 GL_RGBA,
81 16,
82 16,
84 GL_RGBA,
85 GL_UNSIGNED_BYTE,
86 kSharedMemoryId,
87 kSharedMemoryOffset);
88 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D)).Times(1);
89 EXPECT_CALL(*gl_, GetError())
90 .WillOnce(Return(GL_NO_ERROR))
91 .WillOnce(Return(GL_OUT_OF_MEMORY))
92 .RetiresOnSaturation();
93 GenerateMipmap cmd;
94 cmd.Init(GL_TEXTURE_2D);
95 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
96 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
97 EXPECT_FALSE(
98 texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height, nullptr));
101 TEST_P(GLES2DecoderTest, GenerateMipmapClearsUnclearedTexture) {
102 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
103 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
104 DoTexImage2D(
105 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
106 SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
107 GL_TEXTURE_2D, GL_TEXTURE_2D, 0, GL_RGBA,
108 GL_RGBA, GL_UNSIGNED_BYTE, 0, 0, 2, 2);
109 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D));
110 EXPECT_CALL(*gl_, GetError())
111 .WillOnce(Return(GL_NO_ERROR))
112 .WillOnce(Return(GL_NO_ERROR))
113 .RetiresOnSaturation();
114 GenerateMipmap cmd;
115 cmd.Init(GL_TEXTURE_2D);
116 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
117 EXPECT_EQ(GL_NO_ERROR, GetGLError());
120 // Same as GenerateMipmapClearsUnclearedTexture, but with workaround
121 // |set_texture_filters_before_generating_mipmap|.
122 TEST_P(GLES2DecoderManualInitTest, SetTextureFiltersBeforeGenerateMipmap) {
123 base::CommandLine command_line(0, NULL);
124 command_line.AppendSwitchASCII(
125 switches::kGpuDriverBugWorkarounds,
126 base::IntToString(gpu::SET_TEXTURE_FILTER_BEFORE_GENERATING_MIPMAP));
127 InitState init;
128 init.bind_generates_resource = true;
129 InitDecoderWithCommandLine(init, &command_line);
131 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
132 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
133 DoTexImage2D(
134 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
135 SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
136 GL_TEXTURE_2D, GL_TEXTURE_2D, 0, GL_RGBA,
137 GL_RGBA, GL_UNSIGNED_BYTE, 0, 0, 2, 2);
138 EXPECT_CALL(
139 *gl_,
140 TexParameteri(
141 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST))
142 .Times(1)
143 .RetiresOnSaturation();
144 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D));
145 EXPECT_CALL(
146 *gl_,
147 TexParameteri(
148 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR))
149 .Times(1)
150 .RetiresOnSaturation();
151 EXPECT_CALL(*gl_, GetError())
152 .WillOnce(Return(GL_NO_ERROR))
153 .WillOnce(Return(GL_NO_ERROR))
154 .RetiresOnSaturation();
155 GenerateMipmap cmd;
156 cmd.Init(GL_TEXTURE_2D);
157 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
158 EXPECT_EQ(GL_NO_ERROR, GetGLError());
161 TEST_P(GLES2DecoderTest, ActiveTextureValidArgs) {
162 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
163 SpecializedSetup<ActiveTexture, 0>(true);
164 ActiveTexture cmd;
165 cmd.Init(GL_TEXTURE1);
166 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
167 EXPECT_EQ(GL_NO_ERROR, GetGLError());
170 TEST_P(GLES2DecoderTest, ActiveTextureInvalidArgs) {
171 EXPECT_CALL(*gl_, ActiveTexture(_)).Times(0);
172 SpecializedSetup<ActiveTexture, 0>(false);
173 ActiveTexture cmd;
174 cmd.Init(GL_TEXTURE0 - 1);
175 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
176 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
177 cmd.Init(kNumTextureUnits);
178 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
179 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
182 TEST_P(GLES2DecoderTest, TexSubImage2DValidArgs) {
183 const int kWidth = 16;
184 const int kHeight = 8;
185 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
186 DoTexImage2D(GL_TEXTURE_2D,
188 GL_RGBA,
189 kWidth,
190 kHeight,
192 GL_RGBA,
193 GL_UNSIGNED_BYTE,
194 kSharedMemoryId,
195 kSharedMemoryOffset);
196 EXPECT_CALL(*gl_,
197 TexSubImage2D(GL_TEXTURE_2D,
201 kWidth - 1,
202 kHeight,
203 GL_RGBA,
204 GL_UNSIGNED_BYTE,
205 shared_memory_address_))
206 .Times(1)
207 .RetiresOnSaturation();
208 TexSubImage2D cmd;
209 cmd.Init(GL_TEXTURE_2D,
213 kWidth - 1,
214 kHeight,
215 GL_RGBA,
216 GL_UNSIGNED_BYTE,
217 kSharedMemoryId,
218 kSharedMemoryOffset,
219 GL_FALSE);
220 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
221 EXPECT_EQ(GL_NO_ERROR, GetGLError());
224 TEST_P(GLES2DecoderTest, TexSubImage2DBadArgs) {
225 const int kWidth = 16;
226 const int kHeight = 8;
227 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
228 DoTexImage2D(GL_TEXTURE_2D,
230 GL_RGBA,
231 kWidth,
232 kHeight,
234 GL_RGBA,
235 GL_UNSIGNED_BYTE,
238 TexSubImage2D cmd;
239 cmd.Init(GL_TEXTURE0,
243 kWidth,
244 kHeight,
245 GL_RGBA,
246 GL_UNSIGNED_BYTE,
247 kSharedMemoryId,
248 kSharedMemoryOffset,
249 GL_FALSE);
250 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
251 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
252 cmd.Init(GL_TEXTURE_2D,
256 kWidth,
257 kHeight,
258 GL_TRUE,
259 GL_UNSIGNED_BYTE,
260 kSharedMemoryId,
261 kSharedMemoryOffset,
262 GL_FALSE);
263 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
264 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
265 cmd.Init(GL_TEXTURE_2D,
269 kWidth,
270 kHeight,
271 GL_RGBA,
272 GL_UNSIGNED_INT,
273 kSharedMemoryId,
274 kSharedMemoryOffset,
275 GL_FALSE);
276 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
277 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
278 cmd.Init(GL_TEXTURE_2D,
282 kWidth,
283 kHeight,
284 GL_RGBA,
285 GL_UNSIGNED_BYTE,
286 kSharedMemoryId,
287 kSharedMemoryOffset,
288 GL_FALSE);
289 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
290 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
291 cmd.Init(GL_TEXTURE_2D,
295 kWidth,
296 kHeight,
297 GL_RGBA,
298 GL_UNSIGNED_BYTE,
299 kSharedMemoryId,
300 kSharedMemoryOffset,
301 GL_FALSE);
302 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
303 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
304 cmd.Init(GL_TEXTURE_2D,
308 kWidth,
309 kHeight,
310 GL_RGBA,
311 GL_UNSIGNED_BYTE,
312 kSharedMemoryId,
313 kSharedMemoryOffset,
314 GL_FALSE);
315 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
316 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
317 cmd.Init(GL_TEXTURE_2D,
321 kWidth,
322 kHeight,
323 GL_RGBA,
324 GL_UNSIGNED_BYTE,
325 kSharedMemoryId,
326 kSharedMemoryOffset,
327 GL_FALSE);
328 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
329 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
330 cmd.Init(GL_TEXTURE_2D,
334 kWidth + 1,
335 kHeight,
336 GL_RGBA,
337 GL_UNSIGNED_BYTE,
338 kSharedMemoryId,
339 kSharedMemoryOffset,
340 GL_FALSE);
341 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
342 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
343 cmd.Init(GL_TEXTURE_2D,
347 kWidth,
348 kHeight + 1,
349 GL_RGBA,
350 GL_UNSIGNED_BYTE,
351 kSharedMemoryId,
352 kSharedMemoryOffset,
353 GL_FALSE);
354 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
355 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
356 cmd.Init(GL_TEXTURE_2D,
360 kWidth,
361 kHeight,
362 GL_RGB,
363 GL_UNSIGNED_BYTE,
364 kSharedMemoryId,
365 kSharedMemoryOffset,
366 GL_FALSE);
367 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
368 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
369 cmd.Init(GL_TEXTURE_2D,
373 kWidth,
374 kHeight,
375 GL_RGBA,
376 GL_UNSIGNED_SHORT_4_4_4_4,
377 kSharedMemoryId,
378 kSharedMemoryOffset,
379 GL_FALSE);
380 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
381 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
382 cmd.Init(GL_TEXTURE_2D,
386 kWidth,
387 kHeight,
388 GL_RGBA,
389 GL_UNSIGNED_BYTE,
390 kInvalidSharedMemoryId,
391 kSharedMemoryOffset,
392 GL_FALSE);
393 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
394 cmd.Init(GL_TEXTURE_2D,
398 kWidth,
399 kHeight,
400 GL_RGBA,
401 GL_UNSIGNED_BYTE,
402 kSharedMemoryId,
403 kInvalidSharedMemoryOffset,
404 GL_FALSE);
405 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
408 TEST_P(GLES2DecoderTest, CopyTexSubImage2DValidArgs) {
409 const int kWidth = 16;
410 const int kHeight = 8;
411 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
412 DoTexImage2D(GL_TEXTURE_2D,
414 GL_RGBA,
415 kWidth,
416 kHeight,
418 GL_RGBA,
419 GL_UNSIGNED_BYTE,
420 kSharedMemoryId,
421 kSharedMemoryOffset);
422 EXPECT_CALL(*gl_,
423 CopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight))
424 .Times(1)
425 .RetiresOnSaturation();
426 CopyTexSubImage2D cmd;
427 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight);
428 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
429 EXPECT_EQ(GL_NO_ERROR, GetGLError());
432 TEST_P(GLES2DecoderTest, CopyTexSubImage2DBadArgs) {
433 const int kWidth = 16;
434 const int kHeight = 8;
435 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
436 DoTexImage2D(GL_TEXTURE_2D,
438 GL_RGBA,
439 kWidth,
440 kHeight,
442 GL_RGBA,
443 GL_UNSIGNED_BYTE,
446 CopyTexSubImage2D cmd;
447 cmd.Init(GL_TEXTURE0, 1, 0, 0, 0, 0, kWidth, kHeight);
448 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
449 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
450 cmd.Init(GL_TEXTURE_2D, 1, -1, 0, 0, 0, kWidth, kHeight);
451 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
452 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
453 cmd.Init(GL_TEXTURE_2D, 1, 1, 0, 0, 0, kWidth, kHeight);
454 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
455 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
456 cmd.Init(GL_TEXTURE_2D, 1, 0, -1, 0, 0, kWidth, kHeight);
457 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
458 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
459 cmd.Init(GL_TEXTURE_2D, 1, 0, 1, 0, 0, kWidth, kHeight);
460 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
461 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
462 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth + 1, kHeight);
463 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
464 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
465 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight + 1);
466 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
467 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
470 TEST_P(GLES2DecoderTest, TexImage2DRedefinitionSucceeds) {
471 const int kWidth = 16;
472 const int kHeight = 8;
473 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
474 EXPECT_CALL(*gl_, GetError()).WillRepeatedly(Return(GL_NO_ERROR));
475 for (int ii = 0; ii < 2; ++ii) {
476 TexImage2D cmd;
477 if (ii == 0) {
478 EXPECT_CALL(*gl_,
479 TexImage2D(GL_TEXTURE_2D,
481 GL_RGBA,
482 kWidth,
483 kHeight,
485 GL_RGBA,
486 GL_UNSIGNED_BYTE,
488 .Times(1)
489 .RetiresOnSaturation();
490 cmd.Init(GL_TEXTURE_2D,
492 GL_RGBA,
493 kWidth,
494 kHeight,
495 GL_RGBA,
496 GL_UNSIGNED_BYTE,
497 kSharedMemoryId,
498 kSharedMemoryOffset);
499 } else {
500 cmd.Init(GL_TEXTURE_2D,
502 GL_RGBA,
503 kWidth,
504 kHeight,
505 GL_RGBA,
506 GL_UNSIGNED_BYTE,
510 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
511 EXPECT_CALL(*gl_,
512 TexSubImage2D(GL_TEXTURE_2D,
516 kWidth,
517 kHeight - 1,
518 GL_RGBA,
519 GL_UNSIGNED_BYTE,
520 shared_memory_address_))
521 .Times(1)
522 .RetiresOnSaturation();
523 // Consider this TexSubImage2D command part of the previous TexImage2D
524 // (last GL_TRUE argument). It will be skipped if there are bugs in the
525 // redefinition case.
526 TexSubImage2D cmd2;
527 cmd2.Init(GL_TEXTURE_2D,
531 kWidth,
532 kHeight - 1,
533 GL_RGBA,
534 GL_UNSIGNED_BYTE,
535 kSharedMemoryId,
536 kSharedMemoryOffset,
537 GL_TRUE);
538 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
542 TEST_P(GLES2DecoderTest, TexImage2DGLError) {
543 GLenum target = GL_TEXTURE_2D;
544 GLint level = 0;
545 GLenum internal_format = GL_RGBA;
546 GLsizei width = 2;
547 GLsizei height = 4;
548 GLint border = 0;
549 GLenum format = GL_RGBA;
550 GLenum type = GL_UNSIGNED_BYTE;
551 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
552 TextureManager* manager = group().texture_manager();
553 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
554 ASSERT_TRUE(texture_ref != NULL);
555 Texture* texture = texture_ref->texture();
556 EXPECT_FALSE(
557 texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height, nullptr));
558 EXPECT_CALL(*gl_, GetError())
559 .WillOnce(Return(GL_NO_ERROR))
560 .WillOnce(Return(GL_OUT_OF_MEMORY))
561 .RetiresOnSaturation();
562 EXPECT_CALL(*gl_,
563 TexImage2D(target,
564 level,
565 internal_format,
566 width,
567 height,
568 border,
569 format,
570 type,
572 .Times(1)
573 .RetiresOnSaturation();
574 TexImage2D cmd;
575 cmd.Init(target,
576 level,
577 internal_format,
578 width,
579 height,
580 format,
581 type,
582 kSharedMemoryId,
583 kSharedMemoryOffset);
584 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
585 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
586 EXPECT_FALSE(
587 texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height, nullptr));
590 TEST_P(GLES2DecoderTest, CopyTexImage2DGLError) {
591 GLenum target = GL_TEXTURE_2D;
592 GLint level = 0;
593 GLenum internal_format = GL_RGBA;
594 GLsizei width = 2;
595 GLsizei height = 4;
596 GLint border = 0;
597 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
598 TextureManager* manager = group().texture_manager();
599 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
600 ASSERT_TRUE(texture_ref != NULL);
601 Texture* texture = texture_ref->texture();
602 EXPECT_FALSE(
603 texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height, nullptr));
604 EXPECT_CALL(*gl_, GetError())
605 .WillOnce(Return(GL_NO_ERROR))
606 .WillOnce(Return(GL_OUT_OF_MEMORY))
607 .RetiresOnSaturation();
608 EXPECT_CALL(*gl_,
609 CopyTexImage2D(
610 target, level, internal_format, 0, 0, width, height, border))
611 .Times(1)
612 .RetiresOnSaturation();
613 CopyTexImage2D cmd;
614 cmd.Init(target, level, internal_format, 0, 0, width, height);
615 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
616 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
617 EXPECT_FALSE(
618 texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height, nullptr));
621 TEST_P(GLES3DecoderTest, CompressedTexImage3DBucket) {
622 const uint32 kBucketId = 123;
623 const uint32 kBadBucketId = 99;
624 const GLenum kTarget = GL_TEXTURE_2D_ARRAY;
625 const GLint kLevel = 0;
626 const GLenum kInternalFormat = GL_COMPRESSED_R11_EAC;
627 const GLsizei kWidth = 4;
628 const GLsizei kHeight = 4;
629 const GLsizei kDepth = 4;
630 const GLint kBorder = 0;
631 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
632 ASSERT_TRUE(bucket != NULL);
633 const GLsizei kImageSize = 32;
634 bucket->SetSize(kImageSize);
636 DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
638 CompressedTexImage3DBucket cmd;
639 cmd.Init(kTarget,
640 kLevel,
641 kInternalFormat,
642 kWidth,
643 kHeight,
644 kDepth,
645 kBadBucketId);
646 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
648 cmd.Init(kTarget,
649 kLevel,
650 kInternalFormat,
651 kWidth,
652 kHeight,
653 kDepth,
654 kBucketId);
655 EXPECT_CALL(*gl_,
656 CompressedTexImage3D(kTarget, kLevel, kInternalFormat, kWidth,
657 kHeight, kDepth, kBorder, kImageSize, _))
658 .Times(1)
659 .RetiresOnSaturation();
660 EXPECT_CALL(*gl_, GetError())
661 .WillOnce(Return(GL_NO_ERROR))
662 .WillOnce(Return(GL_NO_ERROR))
663 .RetiresOnSaturation();
664 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
665 EXPECT_EQ(GL_NO_ERROR, GetGLError());
668 TEST_P(GLES2DecoderTest, CompressedTexImage3DFailsOnES2) {
669 const uint32 kBucketId = 123;
670 const GLenum kTarget = GL_TEXTURE_2D_ARRAY;
671 const GLint kLevel = 0;
672 const GLenum kInternalFormat = GL_COMPRESSED_R11_EAC;
673 const GLsizei kWidth = 4;
674 const GLsizei kHeight = 4;
675 const GLsizei kDepth = 4;
676 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
677 ASSERT_TRUE(bucket != NULL);
678 const GLsizei kImageSize = 32;
679 bucket->SetSize(kImageSize);
682 CompressedTexImage3DBucket cmd;
683 cmd.Init(kTarget,
684 kLevel,
685 kInternalFormat,
686 kWidth,
687 kHeight,
688 kDepth,
689 kBucketId);
690 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
694 CompressedTexSubImage3DBucket cmd;
695 cmd.Init(kTarget,
696 kLevel,
697 0, 0, 0,
698 kWidth,
699 kHeight,
700 kDepth,
701 kInternalFormat,
702 kBucketId);
703 EXPECT_EQ(error::kUnknownCommand, ExecuteCmd(cmd));
707 TEST_P(GLES3DecoderTest, CompressedTexImage3DFailsWithBadImageSize) {
708 const uint32 kBucketId = 123;
709 const GLenum kTarget = GL_TEXTURE_2D_ARRAY;
710 const GLint kLevel = 0;
711 const GLenum kInternalFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
712 const GLsizei kWidth = 4;
713 const GLsizei kHeight = 8;
714 const GLsizei kDepth = 4;
715 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
716 ASSERT_TRUE(bucket != NULL);
717 const GLsizei kBadImageSize = 64;
718 bucket->SetSize(kBadImageSize);
720 DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
722 CompressedTexImage3DBucket cmd;
723 cmd.Init(kTarget,
724 kLevel,
725 kInternalFormat,
726 kWidth,
727 kHeight,
728 kDepth,
729 kBucketId);
730 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
731 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
734 TEST_P(GLES3DecoderTest, CompressedTexSubImage3DFails) {
735 const uint32 kBucketId = 123;
736 const GLenum kTarget = GL_TEXTURE_2D_ARRAY;
737 const GLint kLevel = 0;
738 const GLenum kInternalFormat = GL_COMPRESSED_RGBA8_ETC2_EAC;
739 const GLsizei kWidth = 4;
740 const GLsizei kHeight = 8;
741 const GLsizei kDepth = 4;
742 const GLint kBorder = 0;
743 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
744 ASSERT_TRUE(bucket != NULL);
745 const GLsizei kImageSize = 128;
746 bucket->SetSize(kImageSize);
748 DoBindTexture(kTarget, client_texture_id_, kServiceTextureId);
750 CompressedTexImage3DBucket tex_cmd;
751 tex_cmd.Init(kTarget,
752 kLevel,
753 kInternalFormat,
754 kWidth,
755 kHeight,
756 kDepth,
757 kBucketId);
758 EXPECT_CALL(*gl_,
759 CompressedTexImage3D(kTarget, kLevel, kInternalFormat, kWidth,
760 kHeight, kDepth, kBorder, kImageSize, _))
761 .Times(1)
762 .RetiresOnSaturation();
763 EXPECT_CALL(*gl_, GetError())
764 .WillOnce(Return(GL_NO_ERROR))
765 .WillOnce(Return(GL_NO_ERROR))
766 .RetiresOnSaturation();
767 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
768 EXPECT_EQ(GL_NO_ERROR, GetGLError());
770 const GLint kXOffset = 0;
771 const GLint kYOffset = 0;
772 const GLint kZOffset = 0;
773 const GLint kSubWidth = 4;
774 const GLint kSubHeight = 4;
775 const GLint kSubDepth = 4;
776 const GLenum kFormat = kInternalFormat;
777 CompressedTexSubImage3DBucket cmd;
779 // Incorrect image size.
780 cmd.Init(kTarget,
781 kLevel,
782 kXOffset,
783 kYOffset,
784 kZOffset,
785 kSubWidth,
786 kSubHeight,
787 kSubDepth,
788 kFormat,
789 kBucketId);
790 const GLsizei kBadSubImageSize = 32;
791 const GLsizei kSubImageSize = 64;
792 bucket->SetSize(kBadSubImageSize);
793 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
794 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
796 // Incorrect format.
797 const GLenum kBadFormat = GL_COMPRESSED_R11_EAC;
798 cmd.Init(kTarget,
799 kLevel,
800 kXOffset,
801 kYOffset,
802 kZOffset,
803 kSubWidth,
804 kSubHeight,
805 kSubDepth,
806 kBadFormat,
807 kBucketId);
808 bucket->SetSize(kSubImageSize);
809 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
810 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
812 // Negative offset.
813 cmd.Init(kTarget,
814 kLevel,
815 kXOffset,
817 kZOffset,
818 kSubWidth,
819 kSubHeight,
820 kSubDepth,
821 kFormat,
822 kBucketId);
823 bucket->SetSize(kSubImageSize);
824 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
825 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
827 // offset + size > texture size
828 cmd.Init(kTarget,
829 kLevel,
830 kXOffset,
831 kYOffset + 8,
832 kZOffset,
833 kSubWidth,
834 kSubHeight,
835 kSubDepth,
836 kFormat,
837 kBucketId);
838 bucket->SetSize(kSubImageSize);
839 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
840 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
842 // offset not a multiple of 4.
843 cmd.Init(kTarget,
844 kLevel,
845 kXOffset,
846 kYOffset + 1,
847 kZOffset,
848 kSubWidth,
849 kSubHeight,
850 kSubDepth,
851 kFormat,
852 kBucketId);
853 bucket->SetSize(kSubImageSize);
854 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
855 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
857 // offset + width not a multlple of 4 .
858 cmd.Init(kTarget,
859 kLevel,
860 kXOffset,
861 kYOffset,
862 kZOffset,
863 kSubWidth,
864 kSubHeight + 3,
865 kSubDepth,
866 kFormat,
867 kBucketId);
868 const GLsizei kSubImageSize2 = 128;
869 bucket->SetSize(kSubImageSize2);
870 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
871 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
873 // Bad bucket id.
874 const uint32 kBadBucketId = 444;
875 cmd.Init(kTarget,
876 kLevel,
877 kXOffset,
878 kYOffset,
879 kZOffset,
880 kSubWidth,
881 kSubHeight,
882 kSubDepth,
883 kFormat,
884 kBadBucketId);
885 bucket->SetSize(kSubImageSize);
886 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
889 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DBucketBadBucket) {
890 InitState init;
891 init.extensions = "GL_EXT_texture_compression_s3tc";
892 init.bind_generates_resource = true;
893 InitDecoder(init);
895 const uint32 kBadBucketId = 123;
896 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
897 CompressedTexImage2DBucket cmd;
898 cmd.Init(GL_TEXTURE_2D,
900 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
903 kBadBucketId);
904 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
905 CompressedTexSubImage2DBucket cmd2;
906 cmd2.Init(GL_TEXTURE_2D,
912 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
913 kBadBucketId);
914 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
917 namespace {
919 struct S3TCTestData {
920 GLenum format;
921 size_t block_size;
924 } // anonymous namespace.
926 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DS3TC) {
927 InitState init;
928 init.extensions = "GL_EXT_texture_compression_s3tc";
929 init.bind_generates_resource = true;
930 InitDecoder(init);
931 const uint32 kBucketId = 123;
932 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
933 ASSERT_TRUE(bucket != NULL);
935 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
937 static const S3TCTestData test_data[] = {
939 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 8,
942 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 8,
945 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 16,
948 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16,
952 for (size_t ii = 0; ii < arraysize(test_data); ++ii) {
953 const S3TCTestData& test = test_data[ii];
954 CompressedTexImage2DBucket cmd;
955 // test small width.
956 DoCompressedTexImage2D(
957 GL_TEXTURE_2D, 0, test.format, 2, 4, 0, test.block_size, kBucketId);
958 EXPECT_EQ(GL_NO_ERROR, GetGLError());
960 // test bad width.
961 cmd.Init(GL_TEXTURE_2D, 0, test.format, 5, 4, kBucketId);
962 bucket->SetSize(test.block_size * 2);
963 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
964 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
966 // test small height.
967 DoCompressedTexImage2D(
968 GL_TEXTURE_2D, 0, test.format, 4, 2, 0, test.block_size, kBucketId);
969 EXPECT_EQ(GL_NO_ERROR, GetGLError());
971 // test too bad height.
972 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 5, kBucketId);
973 bucket->SetSize(test.block_size * 2);
974 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
975 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
977 // test small for level 0.
978 DoCompressedTexImage2D(
979 GL_TEXTURE_2D, 0, test.format, 1, 1, 0, test.block_size, kBucketId);
980 EXPECT_EQ(GL_NO_ERROR, GetGLError());
982 // test small for level 0.
983 DoCompressedTexImage2D(
984 GL_TEXTURE_2D, 0, test.format, 2, 2, 0, test.block_size, kBucketId);
985 EXPECT_EQ(GL_NO_ERROR, GetGLError());
987 // test size too large.
988 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId);
989 bucket->SetSize(test.block_size * 2);
990 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
991 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
993 // test size too small.
994 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId);
995 bucket->SetSize(test.block_size / 2);
996 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
997 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
999 // test with 3 mips.
1000 DoCompressedTexImage2D(
1001 GL_TEXTURE_2D, 0, test.format, 4, 4, 0, test.block_size, kBucketId);
1002 DoCompressedTexImage2D(
1003 GL_TEXTURE_2D, 1, test.format, 2, 2, 0, test.block_size, kBucketId);
1004 DoCompressedTexImage2D(
1005 GL_TEXTURE_2D, 2, test.format, 1, 1, 0, test.block_size, kBucketId);
1006 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1008 // Test a 16x16
1009 DoCompressedTexImage2D(GL_TEXTURE_2D,
1011 test.format,
1015 test.block_size * 4 * 4,
1016 kBucketId);
1017 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1019 CompressedTexSubImage2DBucket sub_cmd;
1020 bucket->SetSize(test.block_size);
1021 // Test sub image bad xoffset
1022 sub_cmd.Init(GL_TEXTURE_2D, 0, 1, 0, 4, 4, test.format, kBucketId);
1023 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
1024 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1026 // Test sub image bad yoffset
1027 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 2, 4, 4, test.format, kBucketId);
1028 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
1029 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1031 // Test sub image bad width
1032 bucket->SetSize(test.block_size * 2);
1033 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 5, 4, test.format, kBucketId);
1034 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
1035 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1037 // Test sub image bad height
1038 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 5, test.format, kBucketId);
1039 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
1040 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1042 // Test sub image bad size
1043 bucket->SetSize(test.block_size + 1);
1044 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, test.format, kBucketId);
1045 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
1046 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1048 for (GLint yoffset = 0; yoffset <= 8; yoffset += 4) {
1049 for (GLint xoffset = 0; xoffset <= 8; xoffset += 4) {
1050 for (GLsizei height = 4; height <= 8; height += 4) {
1051 for (GLsizei width = 4; width <= 8; width += 4) {
1052 GLsizei size = test.block_size * (width / 4) * (height / 4);
1053 bucket->SetSize(size);
1054 EXPECT_CALL(*gl_,
1055 CompressedTexSubImage2D(GL_TEXTURE_2D,
1057 xoffset,
1058 yoffset,
1059 width,
1060 height,
1061 test.format,
1062 size,
1064 .Times(1)
1065 .RetiresOnSaturation();
1066 sub_cmd.Init(GL_TEXTURE_2D,
1068 xoffset,
1069 yoffset,
1070 width,
1071 height,
1072 test.format,
1073 kBucketId);
1074 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
1075 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1083 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DETC1) {
1084 InitState init;
1085 init.extensions = "GL_OES_compressed_ETC1_RGB8_texture";
1086 init.gl_version = "opengl es 2.0";
1087 init.bind_generates_resource = true;
1088 InitDecoder(init);
1089 const uint32 kBucketId = 123;
1090 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
1091 ASSERT_TRUE(bucket != NULL);
1093 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1095 const GLenum kFormat = GL_ETC1_RGB8_OES;
1096 const size_t kBlockSize = 8;
1098 CompressedTexImage2DBucket cmd;
1099 // test small width.
1100 DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 4, 8, 0, 16, kBucketId);
1101 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1103 // test small height.
1104 DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 8, 4, 0, 16, kBucketId);
1105 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1107 // test size too large.
1108 cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, kBucketId);
1109 bucket->SetSize(kBlockSize * 2);
1110 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1111 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1113 // test size too small.
1114 cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, kBucketId);
1115 bucket->SetSize(kBlockSize / 2);
1116 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1117 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1119 // Test a 16x16
1120 DoCompressedTexImage2D(
1121 GL_TEXTURE_2D, 0, kFormat, 16, 16, 0, kBlockSize * 16, kBucketId);
1122 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1124 // Test CompressedTexSubImage not allowed
1125 CompressedTexSubImage2DBucket sub_cmd;
1126 bucket->SetSize(kBlockSize);
1127 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, kFormat, kBucketId);
1128 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
1129 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1131 // Test TexSubImage not allowed for ETC1 compressed texture
1132 TextureRef* texture_ref = GetTexture(client_texture_id_);
1133 ASSERT_TRUE(texture_ref != NULL);
1134 Texture* texture = texture_ref->texture();
1135 GLenum type, internal_format;
1136 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
1137 EXPECT_EQ(kFormat, internal_format);
1138 TexSubImage2D texsub_cmd;
1139 texsub_cmd.Init(GL_TEXTURE_2D,
1145 GL_RGBA,
1146 GL_UNSIGNED_BYTE,
1147 kSharedMemoryId,
1148 kSharedMemoryOffset,
1149 GL_FALSE);
1150 EXPECT_EQ(error::kNoError, ExecuteCmd(texsub_cmd));
1151 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1153 // Test CopyTexSubImage not allowed for ETC1 compressed texture
1154 CopyTexSubImage2D copy_cmd;
1155 copy_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 4, 4);
1156 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_cmd));
1157 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1162 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalBindTexture) {
1163 InitState init;
1164 init.extensions = "GL_OES_EGL_image_external";
1165 init.gl_version = "opengl es 2.0";
1166 init.bind_generates_resource = true;
1167 InitDecoder(init);
1168 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_EXTERNAL_OES, kNewServiceId));
1169 EXPECT_CALL(*gl_, GenTextures(1, _))
1170 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
1171 BindTexture cmd;
1172 cmd.Init(GL_TEXTURE_EXTERNAL_OES, kNewClientId);
1173 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1174 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1175 TextureRef* texture_ref = GetTexture(kNewClientId);
1176 EXPECT_TRUE(texture_ref != NULL);
1177 EXPECT_TRUE(texture_ref->texture()->target() == GL_TEXTURE_EXTERNAL_OES);
1180 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalGetBinding) {
1181 InitState init;
1182 init.extensions = "GL_OES_EGL_image_external";
1183 init.gl_version = "opengl es 2.0";
1184 init.bind_generates_resource = true;
1185 InitDecoder(init);
1186 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1188 EXPECT_CALL(*gl_, GetError())
1189 .WillOnce(Return(GL_NO_ERROR))
1190 .WillOnce(Return(GL_NO_ERROR))
1191 .RetiresOnSaturation();
1192 typedef GetIntegerv::Result Result;
1193 Result* result = static_cast<Result*>(shared_memory_address_);
1194 EXPECT_CALL(*gl_,
1195 GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, result->GetData()))
1196 .Times(0);
1197 result->size = 0;
1198 GetIntegerv cmd;
1199 cmd.Init(GL_TEXTURE_BINDING_EXTERNAL_OES,
1200 shared_memory_id_,
1201 shared_memory_offset_);
1202 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1203 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(
1204 GL_TEXTURE_BINDING_EXTERNAL_OES),
1205 result->GetNumResults());
1206 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1207 EXPECT_EQ(client_texture_id_, (uint32)result->GetData()[0]);
1210 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureDefaults) {
1211 InitState init;
1212 init.extensions = "GL_OES_EGL_image_external";
1213 init.gl_version = "opengl es 2.0";
1214 init.bind_generates_resource = true;
1215 InitDecoder(init);
1216 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1218 TextureRef* texture_ref = GetTexture(client_texture_id_);
1219 EXPECT_TRUE(texture_ref != NULL);
1220 Texture* texture = texture_ref->texture();
1221 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
1222 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1223 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1224 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1227 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureParam) {
1228 InitState init;
1229 init.extensions = "GL_OES_EGL_image_external";
1230 init.gl_version = "opengl es 2.0";
1231 init.bind_generates_resource = true;
1232 InitDecoder(init);
1233 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1235 EXPECT_CALL(*gl_,
1236 TexParameteri(
1237 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
1238 EXPECT_CALL(
1239 *gl_,
1240 TexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1241 EXPECT_CALL(
1242 *gl_,
1243 TexParameteri(
1244 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1245 EXPECT_CALL(
1246 *gl_,
1247 TexParameteri(
1248 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1249 TexParameteri cmd;
1250 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1251 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1252 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1254 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1255 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1256 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1258 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1259 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1260 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1262 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1263 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1264 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1266 TextureRef* texture_ref = GetTexture(client_texture_id_);
1267 EXPECT_TRUE(texture_ref != NULL);
1268 Texture* texture = texture_ref->texture();
1269 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
1270 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1271 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1272 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1275 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureParamInvalid) {
1276 InitState init;
1277 init.extensions = "GL_OES_EGL_image_external";
1278 init.gl_version = "opengl es 2.0";
1279 init.bind_generates_resource = true;
1280 InitDecoder(init);
1281 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1283 TexParameteri cmd;
1284 cmd.Init(GL_TEXTURE_EXTERNAL_OES,
1285 GL_TEXTURE_MIN_FILTER,
1286 GL_NEAREST_MIPMAP_NEAREST);
1287 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1288 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1290 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_REPEAT);
1291 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1292 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1294 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_REPEAT);
1295 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1296 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1298 TextureRef* texture_ref = GetTexture(client_texture_id_);
1299 EXPECT_TRUE(texture_ref != NULL);
1300 Texture* texture = texture_ref->texture();
1301 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
1302 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1303 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1304 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1307 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTexImage2DError) {
1308 InitState init;
1309 init.extensions = "GL_OES_EGL_image_external";
1310 init.gl_version = "opengl es 2.0";
1311 init.bind_generates_resource = true;
1312 InitDecoder(init);
1314 GLenum target = GL_TEXTURE_EXTERNAL_OES;
1315 GLint level = 0;
1316 GLenum internal_format = GL_RGBA;
1317 GLsizei width = 2;
1318 GLsizei height = 4;
1319 GLenum format = GL_RGBA;
1320 GLenum type = GL_UNSIGNED_BYTE;
1321 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1322 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL);
1323 TexImage2D cmd;
1324 cmd.Init(target,
1325 level,
1326 internal_format,
1327 width,
1328 height,
1329 format,
1330 type,
1331 kSharedMemoryId,
1332 kSharedMemoryOffset);
1333 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1335 // TexImage2D is not allowed with GL_TEXTURE_EXTERNAL_OES targets.
1336 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1339 TEST_P(GLES2DecoderManualInitTest, DefaultTextureZero) {
1340 InitState init;
1341 InitDecoder(init);
1343 BindTexture cmd1;
1344 cmd1.Init(GL_TEXTURE_2D, 0);
1345 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1346 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1347 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1349 BindTexture cmd2;
1350 cmd2.Init(GL_TEXTURE_CUBE_MAP, 0);
1351 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1352 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1353 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1356 TEST_P(GLES2DecoderManualInitTest, DefaultTextureBGR) {
1357 InitState init;
1358 init.bind_generates_resource = true;
1359 InitDecoder(init);
1361 BindTexture cmd1;
1362 cmd1.Init(GL_TEXTURE_2D, 0);
1363 EXPECT_CALL(
1364 *gl_, BindTexture(GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId));
1365 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1366 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1368 BindTexture cmd2;
1369 cmd2.Init(GL_TEXTURE_CUBE_MAP, 0);
1370 EXPECT_CALL(*gl_,
1371 BindTexture(GL_TEXTURE_CUBE_MAP,
1372 TestHelper::kServiceDefaultTextureCubemapId));
1373 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1374 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1377 // Test that default texture 0 is immutable.
1378 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameterf) {
1379 InitState init;
1380 InitDecoder(init);
1383 BindTexture cmd1;
1384 cmd1.Init(GL_TEXTURE_2D, 0);
1385 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1386 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1387 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1389 TexParameterf cmd2;
1390 cmd2.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1391 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1392 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1396 BindTexture cmd1;
1397 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1398 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1399 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1400 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1402 TexParameterf cmd2;
1403 cmd2.Init(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1404 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1405 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1409 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameteri) {
1410 InitState init;
1411 InitDecoder(init);
1414 BindTexture cmd1;
1415 cmd1.Init(GL_TEXTURE_2D, 0);
1416 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1417 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1418 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1420 TexParameteri cmd2;
1421 cmd2.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1422 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1423 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1427 BindTexture cmd1;
1428 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1429 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1430 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1431 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1433 TexParameteri cmd2;
1434 cmd2.Init(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1435 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1436 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1440 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameterfv) {
1441 InitState init;
1442 InitDecoder(init);
1445 BindTexture cmd1;
1446 cmd1.Init(GL_TEXTURE_2D, 0);
1447 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1448 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1449 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1451 GLfloat data = GL_NEAREST;
1452 TexParameterfvImmediate& cmd2 =
1453 *GetImmediateAs<TexParameterfvImmediate>();
1454 cmd2.Init(GL_TEXTURE_2D,
1455 GL_TEXTURE_MAG_FILTER,
1456 &data);
1457 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1458 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1462 BindTexture cmd1;
1463 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1464 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1465 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1466 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1468 GLfloat data = GL_NEAREST;
1469 TexParameterfvImmediate& cmd2 =
1470 *GetImmediateAs<TexParameterfvImmediate>();
1471 cmd2.Init(GL_TEXTURE_CUBE_MAP,
1472 GL_TEXTURE_MAG_FILTER,
1473 &data);
1474 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1475 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1479 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameteriv) {
1480 InitState init;
1481 InitDecoder(init);
1484 BindTexture cmd1;
1485 cmd1.Init(GL_TEXTURE_2D, 0);
1486 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1487 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1488 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1490 GLfloat data = GL_NEAREST;
1491 TexParameterfvImmediate& cmd2 =
1492 *GetImmediateAs<TexParameterfvImmediate>();
1493 cmd2.Init(GL_TEXTURE_2D,
1494 GL_TEXTURE_MAG_FILTER,
1495 &data);
1496 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1497 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1501 BindTexture cmd1;
1502 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1503 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1504 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1505 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1507 GLfloat data = GL_NEAREST;
1508 TexParameterfvImmediate& cmd2 =
1509 *GetImmediateAs<TexParameterfvImmediate>();
1510 cmd2.Init(GL_TEXTURE_CUBE_MAP,
1511 GL_TEXTURE_MAG_FILTER,
1512 &data);
1513 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1514 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1518 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexImage2D) {
1519 InitState init;
1520 InitDecoder(init);
1522 BindTexture cmd1;
1523 cmd1.Init(GL_TEXTURE_2D, 0);
1524 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1525 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1526 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1528 TexImage2D cmd2;
1529 cmd2.Init(GL_TEXTURE_2D,
1531 GL_RGBA,
1534 GL_RGBA,
1535 GL_UNSIGNED_BYTE,
1536 kSharedMemoryId,
1537 kSharedMemoryOffset);
1538 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1539 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1542 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexSubImage2D) {
1543 InitState init;
1544 InitDecoder(init);
1546 BindTexture cmd1;
1547 cmd1.Init(GL_TEXTURE_2D, 0);
1548 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1549 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1550 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1552 TexSubImage2D cmd2;
1553 cmd2.Init(GL_TEXTURE_2D,
1559 GL_RGBA,
1560 GL_UNSIGNED_BYTE,
1561 kSharedMemoryId,
1562 kSharedMemoryOffset,
1563 GL_FALSE);
1564 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1565 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1568 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleBindTexture) {
1569 InitState init;
1570 init.extensions = "GL_ARB_texture_rectangle";
1571 init.bind_generates_resource = true;
1572 InitDecoder(init);
1573 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_RECTANGLE_ARB, kNewServiceId));
1574 EXPECT_CALL(*gl_, GenTextures(1, _))
1575 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
1576 BindTexture cmd;
1577 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, kNewClientId);
1578 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1579 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1580 Texture* texture = GetTexture(kNewClientId)->texture();
1581 EXPECT_TRUE(texture != NULL);
1582 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1585 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleGetBinding) {
1586 InitState init;
1587 init.extensions = "GL_ARB_texture_rectangle";
1588 init.bind_generates_resource = true;
1589 InitDecoder(init);
1590 DoBindTexture(
1591 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1593 EXPECT_CALL(*gl_, GetError())
1594 .WillOnce(Return(GL_NO_ERROR))
1595 .WillOnce(Return(GL_NO_ERROR))
1596 .RetiresOnSaturation();
1597 typedef GetIntegerv::Result Result;
1598 Result* result = static_cast<Result*>(shared_memory_address_);
1599 EXPECT_CALL(*gl_,
1600 GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, result->GetData()))
1601 .Times(0);
1602 result->size = 0;
1603 GetIntegerv cmd;
1604 cmd.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB,
1605 shared_memory_id_,
1606 shared_memory_offset_);
1607 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1608 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(
1609 GL_TEXTURE_BINDING_RECTANGLE_ARB),
1610 result->GetNumResults());
1611 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1612 EXPECT_EQ(client_texture_id_, (uint32)result->GetData()[0]);
1615 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureDefaults) {
1616 InitState init;
1617 init.extensions = "GL_ARB_texture_rectangle";
1618 init.bind_generates_resource = true;
1619 InitDecoder(init);
1620 DoBindTexture(
1621 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1623 Texture* texture = GetTexture(client_texture_id_)->texture();
1624 EXPECT_TRUE(texture != NULL);
1625 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1626 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1627 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1628 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1631 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureParam) {
1632 InitState init;
1633 init.extensions = "GL_ARB_texture_rectangle";
1634 init.bind_generates_resource = true;
1635 InitDecoder(init);
1637 DoBindTexture(
1638 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1640 EXPECT_CALL(*gl_,
1641 TexParameteri(
1642 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
1643 EXPECT_CALL(*gl_,
1644 TexParameteri(
1645 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1646 EXPECT_CALL(
1647 *gl_,
1648 TexParameteri(
1649 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1650 EXPECT_CALL(
1651 *gl_,
1652 TexParameteri(
1653 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1654 TexParameteri cmd;
1655 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1656 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1657 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1659 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1660 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1661 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1663 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1664 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1665 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1667 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1668 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1669 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1671 Texture* texture = GetTexture(client_texture_id_)->texture();
1672 EXPECT_TRUE(texture != NULL);
1673 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1674 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1675 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1676 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1679 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureParamInvalid) {
1680 InitState init;
1681 init.extensions = "GL_ARB_texture_rectangle";
1682 init.bind_generates_resource = true;
1683 InitDecoder(init);
1685 DoBindTexture(
1686 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1688 TexParameteri cmd;
1689 cmd.Init(GL_TEXTURE_RECTANGLE_ARB,
1690 GL_TEXTURE_MIN_FILTER,
1691 GL_NEAREST_MIPMAP_NEAREST);
1692 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1693 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1695 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_REPEAT);
1696 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1697 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1699 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_REPEAT);
1700 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1701 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1703 Texture* texture = GetTexture(client_texture_id_)->texture();
1704 EXPECT_TRUE(texture != NULL);
1705 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1706 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1707 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1708 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1711 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTexImage2D) {
1712 InitState init;
1713 init.extensions = "GL_ARB_texture_rectangle";
1714 init.bind_generates_resource = true;
1715 InitDecoder(init);
1717 GLenum target = GL_TEXTURE_RECTANGLE_ARB;
1718 GLint level = 0;
1719 GLenum internal_format = GL_RGBA;
1720 GLsizei width = 2;
1721 GLsizei height = 4;
1722 GLenum format = GL_RGBA;
1723 GLenum type = GL_UNSIGNED_BYTE;
1725 DoBindTexture(
1726 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1727 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL);
1729 EXPECT_CALL(*gl_, GetError())
1730 .WillOnce(Return(GL_NO_ERROR))
1731 .WillOnce(Return(GL_NO_ERROR))
1732 .RetiresOnSaturation();
1733 EXPECT_CALL(*gl_,
1734 TexImage2D(target,
1735 level,
1736 internal_format,
1737 width,
1738 height,
1740 format,
1741 type,
1743 .Times(1)
1744 .RetiresOnSaturation();
1745 TexImage2D cmd;
1746 cmd.Init(target,
1747 level,
1748 internal_format,
1749 width,
1750 height,
1751 format,
1752 type,
1753 kSharedMemoryId,
1754 kSharedMemoryOffset);
1755 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1757 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1760 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTexImage2DInvalid) {
1761 InitState init;
1762 init.extensions = "GL_ARB_texture_rectangle";
1763 init.bind_generates_resource = true;
1764 InitDecoder(init);
1766 GLenum target = GL_TEXTURE_RECTANGLE_ARB;
1767 GLint level = 1;
1768 GLenum internal_format = GL_RGBA;
1769 GLsizei width = 2;
1770 GLsizei height = 4;
1771 GLenum format = GL_RGBA;
1772 GLenum type = GL_UNSIGNED_BYTE;
1774 DoBindTexture(
1775 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1776 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL);
1778 TexImage2D cmd;
1779 cmd.Init(target,
1780 level,
1781 internal_format,
1782 width,
1783 height,
1784 format,
1785 type,
1786 kSharedMemoryId,
1787 kSharedMemoryOffset);
1788 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1790 // TexImage2D may only be used with level 0 on GL_TEXTURE_RECTANGLE_ARB
1791 // targets.
1792 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1795 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DClearsAfterTexImage2DNULL) {
1796 InitState init;
1797 init.gl_version = "opengl es 2.0";
1798 init.has_alpha = true;
1799 init.has_depth = true;
1800 init.request_alpha = true;
1801 init.request_depth = true;
1802 InitDecoder(init);
1804 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1805 DoTexImage2D(
1806 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1807 SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
1808 GL_TEXTURE_2D, GL_TEXTURE_2D, 0, GL_RGBA,
1809 GL_RGBA, GL_UNSIGNED_BYTE, 0, 1, 2, 1);
1810 EXPECT_CALL(*gl_, TexSubImage2D(GL_TEXTURE_2D, 0, 0, _, _, 1, GL_RGBA,
1811 GL_UNSIGNED_BYTE, shared_memory_address_))
1812 .Times(2)
1813 .RetiresOnSaturation();
1814 TexSubImage2D cmd;
1815 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 2, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1816 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
1817 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1818 cmd.Init(GL_TEXTURE_2D, 0, 0, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1819 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
1820 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1821 // Test if we call it again it does not clear.
1822 EXPECT_CALL(*gl_, TexSubImage2D(GL_TEXTURE_2D, 0, 0, 1, 1, 1, GL_RGBA,
1823 GL_UNSIGNED_BYTE, shared_memory_address_))
1824 .Times(1)
1825 .RetiresOnSaturation();
1826 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1829 TEST_P(GLES2DecoderTest, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData) {
1830 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1831 DoTexImage2D(
1832 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1833 DoTexImage2D(GL_TEXTURE_2D,
1835 GL_RGBA,
1839 GL_RGBA,
1840 GL_UNSIGNED_BYTE,
1841 kSharedMemoryId,
1842 kSharedMemoryOffset);
1843 EXPECT_CALL(*gl_,
1844 TexSubImage2D(GL_TEXTURE_2D,
1850 GL_RGBA,
1851 GL_UNSIGNED_BYTE,
1852 shared_memory_address_))
1853 .Times(1)
1854 .RetiresOnSaturation();
1855 TexSubImage2D cmd;
1856 cmd.Init(GL_TEXTURE_2D,
1862 GL_RGBA,
1863 GL_UNSIGNED_BYTE,
1864 kSharedMemoryId,
1865 kSharedMemoryOffset,
1866 GL_FALSE);
1867 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1868 // Test if we call it again it does not clear.
1869 EXPECT_CALL(*gl_,
1870 TexSubImage2D(GL_TEXTURE_2D,
1876 GL_RGBA,
1877 GL_UNSIGNED_BYTE,
1878 shared_memory_address_))
1879 .Times(1)
1880 .RetiresOnSaturation();
1881 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1884 TEST_P(
1885 GLES2DecoderManualInitTest,
1886 TexSubImage2DDoesNotClearAfterTexImage2DNULLThenDataWithTexImage2DIsFaster) {
1887 base::CommandLine command_line(0, NULL);
1888 command_line.AppendSwitchASCII(
1889 switches::kGpuDriverBugWorkarounds,
1890 base::IntToString(gpu::TEXSUBIMAGE_FASTER_THAN_TEXIMAGE));
1891 InitState init;
1892 init.bind_generates_resource = true;
1893 InitDecoderWithCommandLine(init, &command_line);
1894 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1895 DoTexImage2D(
1896 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1899 // Uses texSubimage internally because the above workaround is active and
1900 // the update is for the full size of the texture.
1901 EXPECT_CALL(*gl_,
1902 TexSubImage2D(
1903 GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, _))
1904 .Times(1)
1905 .RetiresOnSaturation();
1906 cmds::TexImage2D cmd;
1907 cmd.Init(GL_TEXTURE_2D,
1909 GL_RGBA,
1912 GL_RGBA,
1913 GL_UNSIGNED_BYTE,
1914 kSharedMemoryId,
1915 kSharedMemoryOffset);
1916 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1919 EXPECT_CALL(*gl_,
1920 TexSubImage2D(GL_TEXTURE_2D,
1926 GL_RGBA,
1927 GL_UNSIGNED_BYTE,
1928 shared_memory_address_))
1929 .Times(1)
1930 .RetiresOnSaturation();
1931 TexSubImage2D cmd;
1932 cmd.Init(GL_TEXTURE_2D,
1938 GL_RGBA,
1939 GL_UNSIGNED_BYTE,
1940 kSharedMemoryId,
1941 kSharedMemoryOffset,
1942 GL_FALSE);
1943 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1944 // Test if we call it again it does not clear.
1945 EXPECT_CALL(*gl_,
1946 TexSubImage2D(GL_TEXTURE_2D,
1952 GL_RGBA,
1953 GL_UNSIGNED_BYTE,
1954 shared_memory_address_))
1955 .Times(1)
1956 .RetiresOnSaturation();
1957 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1960 TEST_P(GLES2DecoderTest, TexSubImage2DClearsAfterTexImage2DWithDataThenNULL) {
1961 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1962 // Put in data (so it should be marked as cleared)
1963 DoTexImage2D(GL_TEXTURE_2D,
1965 GL_RGBA,
1969 GL_RGBA,
1970 GL_UNSIGNED_BYTE,
1971 kSharedMemoryId,
1972 kSharedMemoryOffset);
1973 // Put in no data.
1974 TexImage2D tex_cmd;
1975 tex_cmd.Init(
1976 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1977 // It won't actually call TexImage2D, just mark it as uncleared.
1978 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
1979 // Next call to TexSubImage2d should clear.
1980 SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
1981 GL_TEXTURE_2D, GL_TEXTURE_2D, 0, GL_RGBA,
1982 GL_RGBA, GL_UNSIGNED_BYTE, 0, 1, 2, 1);
1983 EXPECT_CALL(*gl_, TexSubImage2D(GL_TEXTURE_2D, 0, 0, _, _, 1, GL_RGBA,
1984 GL_UNSIGNED_BYTE, shared_memory_address_))
1985 .Times(2)
1986 .RetiresOnSaturation();
1987 TexSubImage2D cmd;
1988 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 2, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1989 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
1990 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1991 cmd.Init(GL_TEXTURE_2D, 0, 0, 1, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE,
1992 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
1993 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1996 TEST_P(GLES2DecoderTest, CopyTexImage2DMarksTextureAsCleared) {
1997 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1999 TextureManager* manager = group().texture_manager();
2000 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
2001 ASSERT_TRUE(texture_ref != NULL);
2002 Texture* texture = texture_ref->texture();
2004 EXPECT_CALL(*gl_, GetError())
2005 .WillOnce(Return(GL_NO_ERROR))
2006 .RetiresOnSaturation();
2007 EXPECT_CALL(*gl_, CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1, 0))
2008 .Times(1)
2009 .RetiresOnSaturation();
2010 EXPECT_CALL(*gl_, GetError())
2011 .WillOnce(Return(GL_NO_ERROR))
2012 .RetiresOnSaturation();
2013 CopyTexImage2D cmd;
2014 cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1);
2015 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2017 EXPECT_TRUE(texture->SafeToRenderFrom());
2020 TEST_P(GLES2DecoderTest, CopyTexSubImage2DTwiceMarksTextureAsCleared) {
2021 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2022 DoTexImage2D(
2023 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2025 // This will initialize the top part.
2027 EXPECT_CALL(*gl_, CopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 1))
2028 .Times(1)
2029 .RetiresOnSaturation();
2030 CopyTexSubImage2D cmd;
2031 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 1);
2032 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2035 // This will initialize the bottom part.
2037 EXPECT_CALL(*gl_, CopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 1, 0, 0, 2, 1))
2038 .Times(1)
2039 .RetiresOnSaturation();
2040 CopyTexSubImage2D cmd;
2041 cmd.Init(GL_TEXTURE_2D, 0, 0, 1, 0, 0, 2, 1);
2042 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2045 TextureManager* manager = group().texture_manager();
2046 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
2047 ASSERT_TRUE(texture_ref != NULL);
2048 Texture* texture = texture_ref->texture();
2049 EXPECT_TRUE(texture->SafeToRenderFrom());
2052 TEST_P(GLES2DecoderTest, CopyTexSubImage2DTwiceClearsUnclearedTexture) {
2053 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2054 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0,
2057 // This will initialize the top part.
2059 EXPECT_CALL(*gl_, CopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 1))
2060 .Times(1)
2061 .RetiresOnSaturation();
2062 CopyTexSubImage2D cmd;
2063 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 2, 1);
2064 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2067 SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
2068 GL_TEXTURE_2D, GL_TEXTURE_2D, 0, GL_RGBA,
2069 GL_RGBA, GL_UNSIGNED_BYTE, 0, 1, 2, 1);
2071 // This will clear the bottom part as a rectangle is not sufficient to keep
2072 // track of the initialized area.
2074 EXPECT_CALL(*gl_, CopyTexSubImage2D(GL_TEXTURE_2D, 0, 1, 1, 0, 0, 1, 1))
2075 .Times(1)
2076 .RetiresOnSaturation();
2077 CopyTexSubImage2D cmd;
2078 cmd.Init(GL_TEXTURE_2D, 0, 1, 1, 0, 0, 1, 1);
2079 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2082 TextureManager* manager = group().texture_manager();
2083 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
2084 ASSERT_TRUE(texture_ref != NULL);
2085 Texture* texture = texture_ref->texture();
2086 EXPECT_TRUE(texture->SafeToRenderFrom());
2089 TEST_P(GLES2DecoderTest, CopyTexSubImage2DClearsUnclearedBackBufferSizedTexture) {
2090 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2091 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kBackBufferWidth, kBackBufferHeight,
2092 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2094 EXPECT_CALL(*gl_, CopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0,
2095 kBackBufferWidth, kBackBufferHeight))
2096 .Times(1)
2097 .RetiresOnSaturation();
2098 CopyTexSubImage2D cmd;
2099 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, kBackBufferWidth, kBackBufferHeight);
2100 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2102 TextureManager* manager = group().texture_manager();
2103 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
2104 ASSERT_TRUE(texture_ref != NULL);
2105 Texture* texture = texture_ref->texture();
2106 EXPECT_TRUE(texture->SafeToRenderFrom());
2109 TEST_P(GLES2DecoderManualInitTest, CompressedImage2DMarksTextureAsCleared) {
2110 InitState init;
2111 init.extensions = "GL_EXT_texture_compression_s3tc";
2112 init.bind_generates_resource = true;
2113 InitDecoder(init);
2115 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2116 EXPECT_CALL(*gl_, GetError())
2117 .WillOnce(Return(GL_NO_ERROR))
2118 .RetiresOnSaturation();
2119 EXPECT_CALL(
2120 *gl_,
2121 CompressedTexImage2D(
2122 GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 8, _))
2123 .Times(1)
2124 .RetiresOnSaturation();
2125 EXPECT_CALL(*gl_, GetError())
2126 .WillOnce(Return(GL_NO_ERROR))
2127 .RetiresOnSaturation();
2128 CompressedTexImage2D cmd;
2129 cmd.Init(GL_TEXTURE_2D,
2131 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
2135 kSharedMemoryId,
2136 kSharedMemoryOffset);
2137 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2138 TextureManager* manager = group().texture_manager();
2139 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
2140 EXPECT_TRUE(texture_ref->texture()->SafeToRenderFrom());
2143 TEST_P(GLES2DecoderTest, TextureUsageAngleExtNotEnabledByDefault) {
2144 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2146 TexParameteri cmd;
2147 cmd.Init(
2148 GL_TEXTURE_2D, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
2149 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2150 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
2153 TEST_P(GLES2DecoderTest, ProduceAndConsumeTextureCHROMIUM) {
2154 Mailbox mailbox = Mailbox::Generate();
2156 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2157 DoTexImage2D(
2158 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2159 DoTexImage2D(
2160 GL_TEXTURE_2D, 1, GL_RGBA, 2, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2161 TextureRef* texture_ref =
2162 group().texture_manager()->GetTexture(client_texture_id_);
2163 ASSERT_TRUE(texture_ref != NULL);
2164 Texture* texture = texture_ref->texture();
2165 EXPECT_EQ(kServiceTextureId, texture->service_id());
2167 ProduceTextureCHROMIUMImmediate& produce_cmd =
2168 *GetImmediateAs<ProduceTextureCHROMIUMImmediate>();
2169 produce_cmd.Init(GL_TEXTURE_2D, mailbox.name);
2170 EXPECT_EQ(error::kNoError,
2171 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
2172 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2174 // Texture didn't change.
2175 GLsizei width;
2176 GLsizei height;
2177 GLenum type;
2178 GLenum internal_format;
2180 EXPECT_TRUE(
2181 texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr));
2182 EXPECT_EQ(3, width);
2183 EXPECT_EQ(1, height);
2184 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2185 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2186 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2188 EXPECT_TRUE(
2189 texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height, nullptr));
2190 EXPECT_EQ(2, width);
2191 EXPECT_EQ(4, height);
2192 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
2193 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2194 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2196 // Service ID has not changed.
2197 EXPECT_EQ(kServiceTextureId, texture->service_id());
2199 // Create new texture for consume.
2200 EXPECT_CALL(*gl_, GenTextures(_, _))
2201 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
2202 .RetiresOnSaturation();
2203 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kNewServiceId);
2205 // Assigns and binds original service size texture ID.
2206 EXPECT_CALL(*gl_, DeleteTextures(1, _)).Times(1).RetiresOnSaturation();
2207 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2208 .Times(1)
2209 .RetiresOnSaturation();
2211 ConsumeTextureCHROMIUMImmediate& consume_cmd =
2212 *GetImmediateAs<ConsumeTextureCHROMIUMImmediate>();
2213 consume_cmd.Init(GL_TEXTURE_2D, mailbox.name);
2214 EXPECT_EQ(error::kNoError,
2215 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name)));
2216 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2218 // Texture is redefined.
2219 EXPECT_TRUE(
2220 texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr));
2221 EXPECT_EQ(3, width);
2222 EXPECT_EQ(1, height);
2223 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2224 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2225 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2227 EXPECT_TRUE(
2228 texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height, nullptr));
2229 EXPECT_EQ(2, width);
2230 EXPECT_EQ(4, height);
2231 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
2232 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2233 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2235 // Service ID is restored.
2236 EXPECT_EQ(kServiceTextureId, texture->service_id());
2239 TEST_P(GLES2DecoderTest, ProduceAndConsumeDirectTextureCHROMIUM) {
2240 Mailbox mailbox = Mailbox::Generate();
2242 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2243 DoTexImage2D(
2244 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2245 DoTexImage2D(
2246 GL_TEXTURE_2D, 1, GL_RGBA, 2, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2247 TextureRef* texture_ref =
2248 group().texture_manager()->GetTexture(client_texture_id_);
2249 ASSERT_TRUE(texture_ref != NULL);
2250 Texture* texture = texture_ref->texture();
2251 EXPECT_EQ(kServiceTextureId, texture->service_id());
2253 ProduceTextureDirectCHROMIUMImmediate& produce_cmd =
2254 *GetImmediateAs<ProduceTextureDirectCHROMIUMImmediate>();
2255 produce_cmd.Init(client_texture_id_, GL_TEXTURE_2D, mailbox.name);
2256 EXPECT_EQ(error::kNoError,
2257 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
2258 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2260 // Texture didn't change.
2261 GLsizei width;
2262 GLsizei height;
2263 GLenum type;
2264 GLenum internal_format;
2266 EXPECT_TRUE(
2267 texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr));
2268 EXPECT_EQ(3, width);
2269 EXPECT_EQ(1, height);
2270 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2271 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2272 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2274 EXPECT_TRUE(
2275 texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height, nullptr));
2276 EXPECT_EQ(2, width);
2277 EXPECT_EQ(4, height);
2278 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
2279 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2280 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2282 // Service ID has not changed.
2283 EXPECT_EQ(kServiceTextureId, texture->service_id());
2285 // Consume the texture into a new client ID.
2286 GLuint new_texture_id = kNewClientId;
2287 CreateAndConsumeTextureCHROMIUMImmediate& consume_cmd =
2288 *GetImmediateAs<CreateAndConsumeTextureCHROMIUMImmediate>();
2289 consume_cmd.Init(GL_TEXTURE_2D, new_texture_id, mailbox.name);
2290 EXPECT_EQ(error::kNoError,
2291 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name)));
2292 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2294 // Make sure the new client ID is associated with the produced service ID.
2295 texture_ref = group().texture_manager()->GetTexture(new_texture_id);
2296 ASSERT_TRUE(texture_ref != NULL);
2297 texture = texture_ref->texture();
2298 EXPECT_EQ(kServiceTextureId, texture->service_id());
2300 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kServiceTextureId);
2302 // Texture is redefined.
2303 EXPECT_TRUE(
2304 texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr));
2305 EXPECT_EQ(3, width);
2306 EXPECT_EQ(1, height);
2307 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2308 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2309 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2311 EXPECT_TRUE(
2312 texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height, nullptr));
2313 EXPECT_EQ(2, width);
2314 EXPECT_EQ(4, height);
2315 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
2316 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2317 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2320 TEST_P(GLES2DecoderTest, ProduceTextureCHROMIUMInvalidTarget) {
2321 Mailbox mailbox = Mailbox::Generate();
2323 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2324 DoTexImage2D(
2325 GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 3, 1, 0, GL_RGBA,
2326 GL_UNSIGNED_BYTE, 0, 0);
2327 TextureRef* texture_ref =
2328 group().texture_manager()->GetTexture(client_texture_id_);
2329 ASSERT_TRUE(texture_ref != NULL);
2330 Texture* texture = texture_ref->texture();
2331 EXPECT_EQ(kServiceTextureId, texture->service_id());
2333 ProduceTextureDirectCHROMIUMImmediate& produce_cmd =
2334 *GetImmediateAs<ProduceTextureDirectCHROMIUMImmediate>();
2335 produce_cmd.Init(client_texture_id_, GL_TEXTURE_2D, mailbox.name);
2336 EXPECT_EQ(error::kNoError,
2337 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
2339 // ProduceTexture should fail it the texture and produce targets don't match.
2340 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2343 TEST_P(GLES2DecoderTest, CreateAndConsumeTextureCHROMIUMInvalidMailbox) {
2344 // Attempt to consume the mailbox when no texture has been produced with it.
2345 Mailbox mailbox = Mailbox::Generate();
2346 GLuint new_texture_id = kNewClientId;
2348 EXPECT_CALL(*gl_, GenTextures(1, _))
2349 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
2350 .RetiresOnSaturation();
2351 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, _))
2352 .Times(2)
2353 .RetiresOnSaturation();
2354 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
2355 .Times(1)
2356 .RetiresOnSaturation();
2358 CreateAndConsumeTextureCHROMIUMImmediate& consume_cmd =
2359 *GetImmediateAs<CreateAndConsumeTextureCHROMIUMImmediate>();
2360 consume_cmd.Init(GL_TEXTURE_2D, new_texture_id, mailbox.name);
2361 EXPECT_EQ(error::kNoError,
2362 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name)));
2364 // CreateAndConsumeTexture should fail if the mailbox isn't associated with a
2365 // texture.
2366 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2368 // Make sure the new client_id is associated with a texture ref even though
2369 // CreateAndConsumeTexture failed.
2370 TextureRef* texture_ref =
2371 group().texture_manager()->GetTexture(new_texture_id);
2372 ASSERT_TRUE(texture_ref != NULL);
2373 Texture* texture = texture_ref->texture();
2374 // New texture should have the correct target type.
2375 EXPECT_TRUE(texture->target() == GL_TEXTURE_2D);
2376 // New texture should have a valid service_id.
2377 EXPECT_EQ(kNewServiceId, texture->service_id());
2380 TEST_P(GLES2DecoderTest, CreateAndConsumeTextureCHROMIUMInvalidTarget) {
2381 Mailbox mailbox = Mailbox::Generate();
2383 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2384 TextureRef* texture_ref =
2385 group().texture_manager()->GetTexture(client_texture_id_);
2386 ASSERT_TRUE(texture_ref != NULL);
2388 ProduceTextureDirectCHROMIUMImmediate& produce_cmd =
2389 *GetImmediateAs<ProduceTextureDirectCHROMIUMImmediate>();
2390 produce_cmd.Init(client_texture_id_, GL_TEXTURE_2D, mailbox.name);
2391 EXPECT_EQ(error::kNoError,
2392 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
2393 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2395 EXPECT_CALL(*gl_, GenTextures(1, _))
2396 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
2397 .RetiresOnSaturation();
2398 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, _))
2399 .Times(2)
2400 .RetiresOnSaturation();
2401 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
2402 .Times(1)
2403 .RetiresOnSaturation();
2405 // Attempt to consume the mailbox with a different target.
2406 GLuint new_texture_id = kNewClientId;
2407 CreateAndConsumeTextureCHROMIUMImmediate& consume_cmd =
2408 *GetImmediateAs<CreateAndConsumeTextureCHROMIUMImmediate>();
2409 consume_cmd.Init(GL_TEXTURE_CUBE_MAP, new_texture_id, mailbox.name);
2410 EXPECT_EQ(error::kNoError,
2411 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name)));
2413 // CreateAndConsumeTexture should fail if the produced texture had a different
2414 // target.
2415 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2417 // Make sure the new client_id is associated with a texture ref even though
2418 // CreateAndConsumeTexture failed.
2419 texture_ref = group().texture_manager()->GetTexture(new_texture_id);
2420 ASSERT_TRUE(texture_ref != NULL);
2421 Texture* texture = texture_ref->texture();
2422 // New texture should have the correct target type.
2423 EXPECT_TRUE(texture->target() == GL_TEXTURE_CUBE_MAP);
2424 // New texture should have a valid service_id.
2425 EXPECT_EQ(kNewServiceId, texture->service_id());
2427 // Make sure the client_id did not become associated with the produced texture
2428 // service_id.
2429 EXPECT_NE(kServiceTextureId, texture->service_id());
2432 TEST_P(GLES2DecoderManualInitTest, DepthTextureBadArgs) {
2433 InitState init;
2434 init.extensions = "GL_ANGLE_depth_texture";
2435 init.gl_version = "opengl es 2.0";
2436 init.has_depth = true;
2437 init.has_stencil = true;
2438 init.request_depth = true;
2439 init.request_stencil = true;
2440 init.bind_generates_resource = true;
2441 InitDecoder(init);
2443 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2444 // Check trying to upload data fails.
2445 TexImage2D tex_cmd;
2446 tex_cmd.Init(GL_TEXTURE_2D,
2448 GL_DEPTH_COMPONENT,
2451 GL_DEPTH_COMPONENT,
2452 GL_UNSIGNED_INT,
2453 kSharedMemoryId,
2454 kSharedMemoryOffset);
2455 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
2456 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2457 // Try level > 0.
2458 tex_cmd.Init(GL_TEXTURE_2D,
2460 GL_DEPTH_COMPONENT,
2463 GL_DEPTH_COMPONENT,
2464 GL_UNSIGNED_INT,
2467 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
2468 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2469 // Make a 1 pixel depth texture.
2470 DoTexImage2D(GL_TEXTURE_2D,
2472 GL_DEPTH_COMPONENT,
2476 GL_DEPTH_COMPONENT,
2477 GL_UNSIGNED_INT,
2480 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2482 // Check that trying to update it fails.
2483 TexSubImage2D tex_sub_cmd;
2484 tex_sub_cmd.Init(GL_TEXTURE_2D,
2490 GL_DEPTH_COMPONENT,
2491 GL_UNSIGNED_INT,
2492 kSharedMemoryId,
2493 kSharedMemoryOffset,
2494 GL_FALSE);
2495 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_sub_cmd));
2496 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2498 // Check that trying to CopyTexImage2D fails
2499 CopyTexImage2D copy_tex_cmd;
2500 copy_tex_cmd.Init(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 1, 1);
2501 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_tex_cmd));
2502 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2504 // Check that trying to CopyTexSubImage2D fails
2505 CopyTexSubImage2D copy_sub_cmd;
2506 copy_sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
2507 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_sub_cmd));
2508 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2511 TEST_P(GLES2DecoderManualInitTest, GenerateMipmapDepthTexture) {
2512 InitState init;
2513 init.extensions = "GL_ANGLE_depth_texture";
2514 init.gl_version = "opengl es 2.0";
2515 init.has_depth = true;
2516 init.has_stencil = true;
2517 init.request_depth = true;
2518 init.request_stencil = true;
2519 init.bind_generates_resource = true;
2520 InitDecoder(init);
2521 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2522 DoTexImage2D(GL_TEXTURE_2D,
2524 GL_DEPTH_COMPONENT,
2528 GL_DEPTH_COMPONENT,
2529 GL_UNSIGNED_INT,
2532 GenerateMipmap cmd;
2533 cmd.Init(GL_TEXTURE_2D);
2534 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2535 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2538 TEST_P(GLES2DecoderTest, BindTexImage2DCHROMIUM) {
2539 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2540 DoTexImage2D(
2541 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2542 TextureRef* texture_ref =
2543 group().texture_manager()->GetTexture(client_texture_id_);
2544 ASSERT_TRUE(texture_ref != NULL);
2545 Texture* texture = texture_ref->texture();
2546 EXPECT_EQ(kServiceTextureId, texture->service_id());
2548 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2549 GetImageManager()->AddImage(image.get(), 1);
2550 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL);
2552 GLsizei width;
2553 GLsizei height;
2554 GLenum type;
2555 GLenum internal_format;
2557 EXPECT_TRUE(
2558 texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr));
2559 EXPECT_EQ(3, width);
2560 EXPECT_EQ(1, height);
2561 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2562 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2563 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2564 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2566 // Bind image to texture.
2567 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2568 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2569 EXPECT_TRUE(
2570 texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr));
2571 // Image should now be set.
2572 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2574 // Define new texture image.
2575 DoTexImage2D(
2576 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2577 EXPECT_TRUE(
2578 texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr));
2579 // Image should no longer be set.
2580 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2583 TEST_P(GLES2DecoderTest, BindTexImage2DCHROMIUMCubeMapNotAllowed) {
2584 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2585 GetImageManager()->AddImage(image.get(), 1);
2586 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2588 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2589 bind_tex_image_2d_cmd.Init(GL_TEXTURE_CUBE_MAP, 1);
2590 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2591 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
2594 TEST_P(GLES2DecoderTest, OrphanGLImageWithTexImage2D) {
2595 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2596 GetImageManager()->AddImage(image.get(), 1);
2597 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2599 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2601 TextureRef* texture_ref =
2602 group().texture_manager()->GetTexture(client_texture_id_);
2603 ASSERT_TRUE(texture_ref != NULL);
2604 Texture* texture = texture_ref->texture();
2606 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2607 DoTexImage2D(
2608 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2609 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2612 TEST_P(GLES2DecoderTest, GLImageAttachedAfterSubTexImage2D) {
2613 // Specifically tests that TexSubImage2D is not optimized to TexImage2D
2614 // in the presence of image attachments.
2615 ASSERT_FALSE(
2616 feature_info()->workarounds().texsubimage_faster_than_teximage);
2618 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2619 GetImageManager()->AddImage(image.get(), 1);
2620 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2622 GLenum target = GL_TEXTURE_2D;
2623 GLint level = 0;
2624 GLint xoffset = 0;
2625 GLint yoffset = 0;
2626 GLsizei width = 1;
2627 GLsizei height = 1;
2628 GLint border = 0;
2629 GLenum format = GL_RGBA;
2630 GLenum type = GL_UNSIGNED_BYTE;
2631 uint32_t pixels_shm_id = kSharedMemoryId;
2632 uint32_t pixels_shm_offset = kSharedMemoryOffset;
2633 GLboolean internal = 0;
2635 // Define texture first.
2636 DoTexImage2D(target, level, format, width, height, border, format, type,
2637 pixels_shm_id, pixels_shm_offset);
2639 // Bind texture to GLImage.
2640 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2642 // Check binding.
2643 TextureRef* texture_ref =
2644 group().texture_manager()->GetTexture(client_texture_id_);
2645 ASSERT_TRUE(texture_ref != NULL);
2646 Texture* texture = texture_ref->texture();
2647 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2649 // TexSubImage2D should not unbind GLImage.
2650 EXPECT_CALL(*gl_, TexSubImage2D(target, level, xoffset, yoffset, width,
2651 height, format, type, _))
2652 .Times(1)
2653 .RetiresOnSaturation();
2654 cmds::TexSubImage2D tex_sub_image_2d_cmd;
2655 tex_sub_image_2d_cmd.Init(target, level, xoffset, yoffset, width, height,
2656 format, type, pixels_shm_id, pixels_shm_offset,
2657 internal);
2658 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_sub_image_2d_cmd));
2659 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2662 TEST_P(GLES2DecoderTest, GLImageAttachedAfterClearLevel) {
2663 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2664 GetImageManager()->AddImage(image.get(), 1);
2665 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2667 GLenum target = GL_TEXTURE_2D;
2668 GLint level = 0;
2669 GLint xoffset = 0;
2670 GLint yoffset = 0;
2671 GLsizei width = 1;
2672 GLsizei height = 1;
2673 GLint border = 0;
2674 GLenum format = GL_RGBA;
2675 GLenum type = GL_UNSIGNED_BYTE;
2676 uint32_t pixels_shm_id = kSharedMemoryId;
2677 uint32_t pixels_shm_offset = kSharedMemoryOffset;
2679 // Define texture first.
2680 DoTexImage2D(target, level, format, width, height, border, format, type,
2681 pixels_shm_id, pixels_shm_offset);
2683 // Bind texture to GLImage.
2684 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2686 // Check binding.
2687 TextureRef* texture_ref =
2688 group().texture_manager()->GetTexture(client_texture_id_);
2689 ASSERT_TRUE(texture_ref != NULL);
2690 Texture* texture = texture_ref->texture();
2691 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2693 // ClearLevel should use glTexSubImage2D to avoid unbinding GLImage.
2694 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2695 .Times(2)
2696 .RetiresOnSaturation();
2697 EXPECT_CALL(*gl_, TexSubImage2D(target, level, xoffset, yoffset, width,
2698 height, format, type, _))
2699 .Times(1)
2700 .RetiresOnSaturation();
2701 GetDecoder()->ClearLevel(texture, target, level, format, type, 0, 0, width,
2702 height);
2703 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2706 TEST_P(GLES2DecoderTest, ReleaseTexImage2DCHROMIUM) {
2707 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2708 DoTexImage2D(
2709 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2710 TextureRef* texture_ref =
2711 group().texture_manager()->GetTexture(client_texture_id_);
2712 ASSERT_TRUE(texture_ref != NULL);
2713 Texture* texture = texture_ref->texture();
2714 EXPECT_EQ(kServiceTextureId, texture->service_id());
2716 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2717 GetImageManager()->AddImage(image.get(), 1);
2718 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL);
2720 GLsizei width;
2721 GLsizei height;
2722 GLenum type;
2723 GLenum internal_format;
2725 EXPECT_TRUE(
2726 texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr));
2727 EXPECT_EQ(3, width);
2728 EXPECT_EQ(1, height);
2729 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2730 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2731 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2732 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2734 // Bind image to texture.
2735 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2736 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2737 EXPECT_TRUE(
2738 texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr));
2739 // Image should now be set.
2740 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2742 // Release image from texture.
2743 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2744 EXPECT_CALL(*gl_, GetError())
2745 .WillOnce(Return(GL_NO_ERROR))
2746 .WillOnce(Return(GL_NO_ERROR))
2747 .RetiresOnSaturation();
2748 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd;
2749 release_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
2750 EXPECT_EQ(error::kNoError, ExecuteCmd(release_tex_image_2d_cmd));
2751 EXPECT_TRUE(
2752 texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height, nullptr));
2753 // Image should no longer be set.
2754 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2757 class MockGLImage : public gfx::GLImage {
2758 public:
2759 MockGLImage() {}
2761 // Overridden from gfx::GLImage:
2762 MOCK_METHOD0(GetSize, gfx::Size());
2763 MOCK_METHOD0(GetInternalFormat, unsigned());
2764 MOCK_METHOD1(Destroy, void(bool));
2765 MOCK_METHOD1(BindTexImage, bool(unsigned));
2766 MOCK_METHOD1(ReleaseTexImage, void(unsigned));
2767 MOCK_METHOD3(CopyTexSubImage,
2768 bool(unsigned, const gfx::Point&, const gfx::Rect&));
2769 MOCK_METHOD0(WillUseTexImage, void());
2770 MOCK_METHOD0(DidUseTexImage, void());
2771 MOCK_METHOD0(WillModifyTexImage, void());
2772 MOCK_METHOD0(DidModifyTexImage, void());
2773 MOCK_METHOD5(ScheduleOverlayPlane, bool(gfx::AcceleratedWidget,
2774 int,
2775 gfx::OverlayTransform,
2776 const gfx::Rect&,
2777 const gfx::RectF&));
2778 MOCK_METHOD3(OnMemoryDump,
2779 void(base::trace_event::ProcessMemoryDump*,
2780 uint64_t,
2781 const std::string&));
2783 protected:
2784 virtual ~MockGLImage() {}
2787 TEST_P(GLES2DecoderWithShaderTest, UseTexImage) {
2788 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2789 DoTexImage2D(GL_TEXTURE_2D,
2791 GL_RGBA,
2795 GL_RGBA,
2796 GL_UNSIGNED_BYTE,
2797 kSharedMemoryId,
2798 kSharedMemoryOffset);
2800 TextureRef* texture_ref =
2801 group().texture_manager()->GetTexture(client_texture_id_);
2802 ASSERT_TRUE(texture_ref != NULL);
2803 Texture* texture = texture_ref->texture();
2804 EXPECT_EQ(kServiceTextureId, texture->service_id());
2806 const int32 kImageId = 1;
2807 scoped_refptr<MockGLImage> image(new MockGLImage);
2808 GetImageManager()->AddImage(image.get(), kImageId);
2810 // Bind image to texture.
2811 EXPECT_CALL(*image.get(), BindTexImage(GL_TEXTURE_2D))
2812 .Times(1)
2813 .WillOnce(Return(true))
2814 .RetiresOnSaturation();
2815 EXPECT_CALL(*image.get(), GetSize())
2816 .Times(1)
2817 .WillOnce(Return(gfx::Size(1, 1)))
2818 .RetiresOnSaturation();
2819 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2820 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId);
2822 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2823 SetupExpectationsForApplyingDefaultDirtyState();
2825 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2826 EXPECT_CALL(*gl_, GetError())
2827 .WillOnce(Return(GL_NO_ERROR))
2828 .WillOnce(Return(GL_NO_ERROR))
2829 .WillOnce(Return(GL_NO_ERROR))
2830 .WillOnce(Return(GL_NO_ERROR))
2831 .RetiresOnSaturation();
2832 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(3).RetiresOnSaturation();
2833 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2834 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2835 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2836 .Times(1)
2837 .RetiresOnSaturation();
2838 DrawArrays cmd;
2839 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2840 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2841 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2843 DoBindFramebuffer(
2844 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2845 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2846 EXPECT_CALL(*gl_, GetError())
2847 .WillOnce(Return(GL_NO_ERROR))
2848 .WillOnce(Return(GL_NO_ERROR))
2849 .RetiresOnSaturation();
2850 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2851 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2852 .Times(2)
2853 .RetiresOnSaturation();
2854 // Image will be 'in use' as long as bound to a framebuffer.
2855 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2856 EXPECT_CALL(*gl_,
2857 FramebufferTexture2DEXT(GL_FRAMEBUFFER,
2858 GL_COLOR_ATTACHMENT0,
2859 GL_TEXTURE_2D,
2860 kServiceTextureId,
2862 .Times(1)
2863 .RetiresOnSaturation();
2864 EXPECT_CALL(*gl_, GetError())
2865 .WillOnce(Return(GL_NO_ERROR))
2866 .WillOnce(Return(GL_NO_ERROR))
2867 .RetiresOnSaturation();
2868 FramebufferTexture2D fbtex_cmd;
2869 fbtex_cmd.Init(GL_FRAMEBUFFER,
2870 GL_COLOR_ATTACHMENT0,
2871 GL_TEXTURE_2D,
2872 client_texture_id_);
2873 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd));
2874 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2876 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2877 EXPECT_CALL(*gl_, GetError())
2878 .WillOnce(Return(GL_NO_ERROR))
2879 .WillOnce(Return(GL_NO_ERROR))
2880 .RetiresOnSaturation();
2881 EXPECT_CALL(*gl_,
2882 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
2883 GL_COLOR_ATTACHMENT0,
2884 GL_RENDERBUFFER,
2885 kServiceRenderbufferId))
2886 .Times(1)
2887 .RetiresOnSaturation();
2888 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2889 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2890 .Times(2)
2891 .RetiresOnSaturation();
2892 // Image should no longer be 'in use' after being unbound from framebuffer.
2893 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2894 EXPECT_CALL(*gl_, GetError())
2895 .WillOnce(Return(GL_NO_ERROR))
2896 .WillOnce(Return(GL_NO_ERROR))
2897 .RetiresOnSaturation();
2898 FramebufferRenderbuffer fbrb_cmd;
2899 fbrb_cmd.Init(GL_FRAMEBUFFER,
2900 GL_COLOR_ATTACHMENT0,
2901 GL_RENDERBUFFER,
2902 client_renderbuffer_id_);
2903 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
2906 TEST_P(GLES2DecoderManualInitTest, DrawWithGLImageExternal) {
2907 InitState init;
2908 init.extensions = "GL_OES_EGL_image_external";
2909 init.gl_version = "opengl es 2.0";
2910 init.has_alpha = true;
2911 init.has_depth = true;
2912 init.request_alpha = true;
2913 init.request_depth = true;
2914 init.bind_generates_resource = true;
2915 InitDecoder(init);
2917 TextureRef* texture_ref = GetTexture(client_texture_id_);
2918 scoped_refptr<MockGLImage> image(new MockGLImage);
2919 group().texture_manager()->SetTarget(texture_ref, GL_TEXTURE_EXTERNAL_OES);
2920 group().texture_manager()->SetLevelInfo(texture_ref, GL_TEXTURE_EXTERNAL_OES,
2921 0, GL_RGBA, 0, 0, 1, 0, GL_RGBA,
2922 GL_UNSIGNED_BYTE, gfx::Rect());
2923 group().texture_manager()->SetLevelImage(
2924 texture_ref, GL_TEXTURE_EXTERNAL_OES, 0, image.get());
2926 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
2927 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2929 SetupSamplerExternalProgram();
2930 SetupIndexBuffer();
2931 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
2932 SetupExpectationsForApplyingDefaultDirtyState();
2933 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref));
2935 InSequence s;
2936 EXPECT_CALL(*gl_, GetError())
2937 .WillOnce(Return(GL_NO_ERROR))
2938 .RetiresOnSaturation();
2939 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2940 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2941 EXPECT_CALL(*gl_, GetError())
2942 .WillOnce(Return(GL_NO_ERROR))
2943 .RetiresOnSaturation();
2944 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(1);
2945 EXPECT_CALL(*gl_, GetError())
2946 .WillOnce(Return(GL_NO_ERROR))
2947 .RetiresOnSaturation();
2948 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2949 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2950 EXPECT_CALL(*gl_, GetError())
2951 .WillOnce(Return(GL_NO_ERROR))
2952 .RetiresOnSaturation();
2953 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2954 DrawElements cmd;
2955 cmd.Init(GL_TRIANGLES,
2956 kValidIndexRangeCount,
2957 GL_UNSIGNED_SHORT,
2958 kValidIndexRangeStart * 2);
2959 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2960 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2963 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES2) {
2964 InitState init;
2965 init.extensions = "GL_OES_texture_float";
2966 init.gl_version = "opengl es 2.0";
2967 InitDecoder(init);
2968 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2969 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2970 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0);
2971 DoTexImage2D(
2972 GL_TEXTURE_2D, 0, GL_LUMINANCE, 16, 17, 0, GL_LUMINANCE, GL_FLOAT, 0, 0);
2973 DoTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 16, 17, 0, GL_ALPHA, GL_FLOAT, 0, 0);
2974 DoTexImage2D(GL_TEXTURE_2D,
2976 GL_LUMINANCE_ALPHA,
2980 GL_LUMINANCE_ALPHA,
2981 GL_FLOAT,
2986 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES3) {
2987 InitState init;
2988 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
2989 init.gl_version = "opengl es 3.0";
2990 InitDecoder(init);
2991 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2992 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2993 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0);
2994 DoTexImage2D(
2995 GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2996 DoTexImage2D(
2997 GL_TEXTURE_2D, 0, GL_LUMINANCE, 16, 17, 0, GL_LUMINANCE, GL_FLOAT, 0, 0);
2998 DoTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 16, 17, 0, GL_ALPHA, GL_FLOAT, 0, 0);
2999 DoTexImage2D(GL_TEXTURE_2D,
3001 GL_LUMINANCE_ALPHA,
3005 GL_LUMINANCE_ALPHA,
3006 GL_FLOAT,
3011 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DFloatOnGLES3) {
3012 InitState init;
3013 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
3014 init.gl_version = "opengl es 3.0";
3015 InitDecoder(init);
3016 const int kWidth = 8;
3017 const int kHeight = 4;
3018 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
3019 DoTexImage2D(GL_TEXTURE_2D,
3021 GL_RGBA32F,
3022 kWidth,
3023 kHeight,
3025 GL_RGBA,
3026 GL_FLOAT,
3029 EXPECT_CALL(*gl_,
3030 TexImage2D(GL_TEXTURE_2D,
3032 GL_RGBA32F,
3033 kWidth,
3034 kHeight,
3036 GL_RGBA,
3037 GL_FLOAT,
3038 shared_memory_address_))
3039 .Times(1)
3040 .RetiresOnSaturation();
3041 TexSubImage2D cmd;
3042 cmd.Init(GL_TEXTURE_2D,
3046 kWidth,
3047 kHeight,
3048 GL_RGBA,
3049 GL_FLOAT,
3050 kSharedMemoryId,
3051 kSharedMemoryOffset,
3052 GL_FALSE);
3053 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3054 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3057 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DFloatDoesClearOnGLES3) {
3058 InitState init;
3059 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
3060 init.gl_version = "opengl es 3.0";
3061 InitDecoder(init);
3062 const int kWidth = 8;
3063 const int kHeight = 4;
3064 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
3065 DoTexImage2D(GL_TEXTURE_2D,
3067 GL_RGBA32F,
3068 kWidth,
3069 kHeight,
3071 GL_RGBA,
3072 GL_FLOAT,
3075 SetupClearTextureExpectations(kServiceTextureId, kServiceTextureId,
3076 GL_TEXTURE_2D, GL_TEXTURE_2D, 0, GL_RGBA32F,
3077 GL_RGBA, GL_FLOAT, 0, kHeight - 1, kWidth, 1);
3078 EXPECT_CALL(*gl_, TexSubImage2D(GL_TEXTURE_2D, 0, 0, _, _, _, GL_RGBA,
3079 GL_FLOAT, shared_memory_address_))
3080 .Times(2)
3081 .RetiresOnSaturation();
3082 TexSubImage2D cmd;
3083 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, kWidth, kHeight - 1, GL_RGBA, GL_FLOAT,
3084 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3085 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3086 cmd.Init(GL_TEXTURE_2D, 0, 0, kHeight - 1, kWidth - 1, 1, GL_RGBA, GL_FLOAT,
3087 kSharedMemoryId, kSharedMemoryOffset, GL_FALSE);
3088 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3089 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3092 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatConvertsFormatDesktop) {
3093 InitState init;
3094 init.extensions = "GL_ARB_texture_float";
3095 InitDecoder(init);
3096 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
3097 DoTexImage2D(
3098 GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
3099 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0);
3100 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
3102 GL_RGBA,
3106 GL_RGBA,
3107 GL_FLOAT,
3110 GL_RGBA32F_ARB);
3111 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
3113 GL_RGB,
3117 GL_RGB,
3118 GL_FLOAT,
3121 GL_RGB32F_ARB);
3122 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
3124 GL_LUMINANCE,
3128 GL_LUMINANCE,
3129 GL_FLOAT,
3132 GL_LUMINANCE32F_ARB);
3133 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
3135 GL_ALPHA,
3139 GL_ALPHA,
3140 GL_FLOAT,
3143 GL_ALPHA32F_ARB);
3144 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
3146 GL_LUMINANCE_ALPHA,
3150 GL_LUMINANCE_ALPHA,
3151 GL_FLOAT,
3154 GL_LUMINANCE_ALPHA32F_ARB);
3157 class GLES2DecoderCompressedFormatsTest : public GLES2DecoderManualInitTest {
3158 public:
3159 GLES2DecoderCompressedFormatsTest() {}
3161 static bool ValueInArray(GLint value, GLint* array, GLint count) {
3162 for (GLint ii = 0; ii < count; ++ii) {
3163 if (array[ii] == value) {
3164 return true;
3167 return false;
3170 void CheckFormats(const char* extension, const GLenum* formats, int count) {
3171 InitState init;
3172 init.extensions = extension;
3173 init.bind_generates_resource = true;
3174 InitDecoder(init);
3176 EXPECT_CALL(*gl_, GetError())
3177 .WillOnce(Return(GL_NO_ERROR))
3178 .WillOnce(Return(GL_NO_ERROR))
3179 .WillOnce(Return(GL_NO_ERROR))
3180 .WillOnce(Return(GL_NO_ERROR))
3181 .RetiresOnSaturation();
3183 typedef GetIntegerv::Result Result;
3184 Result* result = static_cast<Result*>(shared_memory_address_);
3185 GetIntegerv cmd;
3186 result->size = 0;
3187 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
3188 cmd.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS,
3189 shared_memory_id_,
3190 shared_memory_offset_);
3191 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3192 EXPECT_EQ(1, result->GetNumResults());
3193 GLint num_formats = result->GetData()[0];
3194 EXPECT_EQ(count, num_formats);
3195 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3197 result->size = 0;
3198 cmd.Init(GL_COMPRESSED_TEXTURE_FORMATS,
3199 shared_memory_id_,
3200 shared_memory_offset_);
3201 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3202 EXPECT_EQ(num_formats, result->GetNumResults());
3204 for (int i = 0; i < count; ++i) {
3205 EXPECT_TRUE(
3206 ValueInArray(formats[i], result->GetData(), result->GetNumResults()));
3209 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3213 INSTANTIATE_TEST_CASE_P(Service,
3214 GLES2DecoderCompressedFormatsTest,
3215 ::testing::Bool());
3217 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsS3TC) {
3218 const GLenum formats[] = {
3219 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
3220 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT};
3221 CheckFormats("GL_EXT_texture_compression_s3tc", formats, 4);
3224 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsATC) {
3225 const GLenum formats[] = {GL_ATC_RGB_AMD, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD,
3226 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD};
3227 CheckFormats("GL_AMD_compressed_ATC_texture", formats, 3);
3230 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsPVRTC) {
3231 const GLenum formats[] = {
3232 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG,
3233 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG};
3234 CheckFormats("GL_IMG_texture_compression_pvrtc", formats, 4);
3237 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsETC1) {
3238 const GLenum formats[] = {GL_ETC1_RGB8_OES};
3239 CheckFormats("GL_OES_compressed_ETC1_RGB8_texture", formats, 1);
3242 TEST_P(GLES2DecoderManualInitTest, GetNoCompressedTextureFormats) {
3243 InitState init;
3244 init.bind_generates_resource = true;
3245 InitDecoder(init);
3247 EXPECT_CALL(*gl_, GetError())
3248 .WillOnce(Return(GL_NO_ERROR))
3249 .WillOnce(Return(GL_NO_ERROR))
3250 .WillOnce(Return(GL_NO_ERROR))
3251 .WillOnce(Return(GL_NO_ERROR))
3252 .RetiresOnSaturation();
3254 typedef GetIntegerv::Result Result;
3255 Result* result = static_cast<Result*>(shared_memory_address_);
3256 GetIntegerv cmd;
3257 result->size = 0;
3258 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
3259 cmd.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS,
3260 shared_memory_id_,
3261 shared_memory_offset_);
3262 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3263 EXPECT_EQ(1, result->GetNumResults());
3264 GLint num_formats = result->GetData()[0];
3265 EXPECT_EQ(0, num_formats);
3266 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3268 result->size = 0;
3269 cmd.Init(
3270 GL_COMPRESSED_TEXTURE_FORMATS, shared_memory_id_, shared_memory_offset_);
3271 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
3272 EXPECT_EQ(num_formats, result->GetNumResults());
3274 EXPECT_EQ(GL_NO_ERROR, GetGLError());
3277 // TODO(gman): Complete this test.
3278 // TEST_P(GLES2DecoderTest, CompressedTexImage2DGLError) {
3279 // }
3281 // TODO(gman): CompressedTexImage2D
3283 // TODO(gman): CompressedTexImage2DImmediate
3285 // TODO(gman): CompressedTexSubImage2DImmediate
3287 // TODO(gman): TexImage2D
3289 // TODO(gman): TexImage2DImmediate
3291 // TODO(gman): TexSubImage2DImmediate
3293 } // namespace gles2
3294 } // namespace gpu