Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_textures.cc
blob259072fbaf9e1254f3eb8df35dbb21ea754a9560
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"
21 #include "gpu/command_buffer/service/gpu_switches.h"
22 #include "gpu/command_buffer/service/image_manager.h"
23 #include "gpu/command_buffer/service/mailbox_manager.h"
24 #include "gpu/command_buffer/service/mocks.h"
25 #include "gpu/command_buffer/service/program_manager.h"
26 #include "gpu/command_buffer/service/test_helper.h"
27 #include "testing/gtest/include/gtest/gtest.h"
28 #include "ui/gl/gl_image_stub.h"
29 #include "ui/gl/gl_implementation.h"
30 #include "ui/gl/gl_mock.h"
31 #include "ui/gl/gl_surface_stub.h"
33 #if !defined(GL_DEPTH24_STENCIL8)
34 #define GL_DEPTH24_STENCIL8 0x88F0
35 #endif
37 using ::gfx::MockGLInterface;
38 using ::testing::_;
39 using ::testing::DoAll;
40 using ::testing::InSequence;
41 using ::testing::Invoke;
42 using ::testing::MatcherCast;
43 using ::testing::Mock;
44 using ::testing::Pointee;
45 using ::testing::Return;
46 using ::testing::SaveArg;
47 using ::testing::SetArrayArgument;
48 using ::testing::SetArgumentPointee;
49 using ::testing::SetArgPointee;
50 using ::testing::StrEq;
51 using ::testing::StrictMock;
53 namespace gpu {
54 namespace gles2 {
56 using namespace cmds;
58 TEST_P(GLES2DecoderTest, GenerateMipmapWrongFormatsFails) {
59 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
60 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
61 DoTexImage2D(
62 GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
63 GenerateMipmap cmd;
64 cmd.Init(GL_TEXTURE_2D);
65 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
66 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
69 TEST_P(GLES2DecoderTest, GenerateMipmapHandlesOutOfMemory) {
70 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
71 TextureManager* manager = group().texture_manager();
72 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
73 ASSERT_TRUE(texture_ref != NULL);
74 Texture* texture = texture_ref->texture();
75 GLint width = 0;
76 GLint height = 0;
77 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height));
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(texture->GetLevelSize(GL_TEXTURE_2D, 2, &width, &height));
100 TEST_P(GLES2DecoderTest, GenerateMipmapClearsUnclearedTexture) {
101 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
102 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
103 DoTexImage2D(
104 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
105 SetupClearTextureExpectations(kServiceTextureId,
106 kServiceTextureId,
107 GL_TEXTURE_2D,
108 GL_TEXTURE_2D,
110 GL_RGBA,
111 GL_RGBA,
112 GL_UNSIGNED_BYTE,
115 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D));
116 EXPECT_CALL(*gl_, GetError())
117 .WillOnce(Return(GL_NO_ERROR))
118 .WillOnce(Return(GL_NO_ERROR))
119 .RetiresOnSaturation();
120 GenerateMipmap cmd;
121 cmd.Init(GL_TEXTURE_2D);
122 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
123 EXPECT_EQ(GL_NO_ERROR, GetGLError());
126 // Same as GenerateMipmapClearsUnclearedTexture, but with workaround
127 // |set_texture_filters_before_generating_mipmap|.
128 TEST_P(GLES2DecoderManualInitTest, SetTextureFiltersBeforeGenerateMipmap) {
129 base::CommandLine command_line(0, NULL);
130 command_line.AppendSwitchASCII(
131 switches::kGpuDriverBugWorkarounds,
132 base::IntToString(gpu::SET_TEXTURE_FILTER_BEFORE_GENERATING_MIPMAP));
133 InitState init;
134 init.bind_generates_resource = true;
135 InitDecoderWithCommandLine(init, &command_line);
137 EXPECT_CALL(*gl_, GenerateMipmapEXT(_)).Times(0);
138 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
139 DoTexImage2D(
140 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
141 SetupClearTextureExpectations(kServiceTextureId,
142 kServiceTextureId,
143 GL_TEXTURE_2D,
144 GL_TEXTURE_2D,
146 GL_RGBA,
147 GL_RGBA,
148 GL_UNSIGNED_BYTE,
151 EXPECT_CALL(
152 *gl_,
153 TexParameteri(
154 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST))
155 .Times(1)
156 .RetiresOnSaturation();
157 EXPECT_CALL(*gl_, GenerateMipmapEXT(GL_TEXTURE_2D));
158 EXPECT_CALL(
159 *gl_,
160 TexParameteri(
161 GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_LINEAR))
162 .Times(1)
163 .RetiresOnSaturation();
164 EXPECT_CALL(*gl_, GetError())
165 .WillOnce(Return(GL_NO_ERROR))
166 .WillOnce(Return(GL_NO_ERROR))
167 .RetiresOnSaturation();
168 GenerateMipmap cmd;
169 cmd.Init(GL_TEXTURE_2D);
170 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
171 EXPECT_EQ(GL_NO_ERROR, GetGLError());
174 TEST_P(GLES2DecoderTest, ActiveTextureValidArgs) {
175 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE1));
176 SpecializedSetup<ActiveTexture, 0>(true);
177 ActiveTexture cmd;
178 cmd.Init(GL_TEXTURE1);
179 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
180 EXPECT_EQ(GL_NO_ERROR, GetGLError());
183 TEST_P(GLES2DecoderTest, ActiveTextureInvalidArgs) {
184 EXPECT_CALL(*gl_, ActiveTexture(_)).Times(0);
185 SpecializedSetup<ActiveTexture, 0>(false);
186 ActiveTexture cmd;
187 cmd.Init(GL_TEXTURE0 - 1);
188 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
189 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
190 cmd.Init(kNumTextureUnits);
191 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
192 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
195 TEST_P(GLES2DecoderTest, TexSubImage2DValidArgs) {
196 const int kWidth = 16;
197 const int kHeight = 8;
198 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
199 DoTexImage2D(GL_TEXTURE_2D,
201 GL_RGBA,
202 kWidth,
203 kHeight,
205 GL_RGBA,
206 GL_UNSIGNED_BYTE,
207 kSharedMemoryId,
208 kSharedMemoryOffset);
209 EXPECT_CALL(*gl_,
210 TexSubImage2D(GL_TEXTURE_2D,
214 kWidth - 1,
215 kHeight,
216 GL_RGBA,
217 GL_UNSIGNED_BYTE,
218 shared_memory_address_))
219 .Times(1)
220 .RetiresOnSaturation();
221 TexSubImage2D cmd;
222 cmd.Init(GL_TEXTURE_2D,
226 kWidth - 1,
227 kHeight,
228 GL_RGBA,
229 GL_UNSIGNED_BYTE,
230 kSharedMemoryId,
231 kSharedMemoryOffset,
232 GL_FALSE);
233 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
234 EXPECT_EQ(GL_NO_ERROR, GetGLError());
237 TEST_P(GLES2DecoderTest, TexSubImage2DBadArgs) {
238 const int kWidth = 16;
239 const int kHeight = 8;
240 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
241 DoTexImage2D(GL_TEXTURE_2D,
243 GL_RGBA,
244 kWidth,
245 kHeight,
247 GL_RGBA,
248 GL_UNSIGNED_BYTE,
251 TexSubImage2D cmd;
252 cmd.Init(GL_TEXTURE0,
256 kWidth,
257 kHeight,
258 GL_RGBA,
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_TRUE,
272 GL_UNSIGNED_BYTE,
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_INT,
286 kSharedMemoryId,
287 kSharedMemoryOffset,
288 GL_FALSE);
289 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
290 EXPECT_EQ(GL_INVALID_ENUM, 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,
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 + 1,
348 kHeight,
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 + 1,
362 GL_RGBA,
363 GL_UNSIGNED_BYTE,
364 kSharedMemoryId,
365 kSharedMemoryOffset,
366 GL_FALSE);
367 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
368 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
369 cmd.Init(GL_TEXTURE_2D,
373 kWidth,
374 kHeight,
375 GL_RGB,
376 GL_UNSIGNED_BYTE,
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_SHORT_4_4_4_4,
390 kSharedMemoryId,
391 kSharedMemoryOffset,
392 GL_FALSE);
393 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
394 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
395 cmd.Init(GL_TEXTURE_2D,
399 kWidth,
400 kHeight,
401 GL_RGBA,
402 GL_UNSIGNED_BYTE,
403 kInvalidSharedMemoryId,
404 kSharedMemoryOffset,
405 GL_FALSE);
406 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
407 cmd.Init(GL_TEXTURE_2D,
411 kWidth,
412 kHeight,
413 GL_RGBA,
414 GL_UNSIGNED_BYTE,
415 kSharedMemoryId,
416 kInvalidSharedMemoryOffset,
417 GL_FALSE);
418 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
421 TEST_P(GLES2DecoderTest, CopyTexSubImage2DValidArgs) {
422 const int kWidth = 16;
423 const int kHeight = 8;
424 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
425 DoTexImage2D(GL_TEXTURE_2D,
427 GL_RGBA,
428 kWidth,
429 kHeight,
431 GL_RGBA,
432 GL_UNSIGNED_BYTE,
433 kSharedMemoryId,
434 kSharedMemoryOffset);
435 EXPECT_CALL(*gl_,
436 CopyTexSubImage2D(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight))
437 .Times(1)
438 .RetiresOnSaturation();
439 CopyTexSubImage2D cmd;
440 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight);
441 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
442 EXPECT_EQ(GL_NO_ERROR, GetGLError());
445 TEST_P(GLES2DecoderTest, CopyTexSubImage2DBadArgs) {
446 const int kWidth = 16;
447 const int kHeight = 8;
448 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
449 DoTexImage2D(GL_TEXTURE_2D,
451 GL_RGBA,
452 kWidth,
453 kHeight,
455 GL_RGBA,
456 GL_UNSIGNED_BYTE,
459 CopyTexSubImage2D cmd;
460 cmd.Init(GL_TEXTURE0, 1, 0, 0, 0, 0, kWidth, kHeight);
461 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
462 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
463 cmd.Init(GL_TEXTURE_2D, 1, -1, 0, 0, 0, kWidth, kHeight);
464 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
465 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
466 cmd.Init(GL_TEXTURE_2D, 1, 1, 0, 0, 0, kWidth, kHeight);
467 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
468 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
469 cmd.Init(GL_TEXTURE_2D, 1, 0, -1, 0, 0, kWidth, kHeight);
470 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
471 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
472 cmd.Init(GL_TEXTURE_2D, 1, 0, 1, 0, 0, kWidth, kHeight);
473 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
474 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
475 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth + 1, kHeight);
476 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
477 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
478 cmd.Init(GL_TEXTURE_2D, 1, 0, 0, 0, 0, kWidth, kHeight + 1);
479 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
480 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
483 TEST_P(GLES2DecoderTest, TexImage2DRedefinitionSucceeds) {
484 const int kWidth = 16;
485 const int kHeight = 8;
486 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
487 EXPECT_CALL(*gl_, GetError()).WillRepeatedly(Return(GL_NO_ERROR));
488 for (int ii = 0; ii < 2; ++ii) {
489 TexImage2D cmd;
490 if (ii == 0) {
491 EXPECT_CALL(*gl_,
492 TexImage2D(GL_TEXTURE_2D,
494 GL_RGBA,
495 kWidth,
496 kHeight,
498 GL_RGBA,
499 GL_UNSIGNED_BYTE,
501 .Times(1)
502 .RetiresOnSaturation();
503 cmd.Init(GL_TEXTURE_2D,
505 GL_RGBA,
506 kWidth,
507 kHeight,
508 GL_RGBA,
509 GL_UNSIGNED_BYTE,
510 kSharedMemoryId,
511 kSharedMemoryOffset);
512 } else {
513 SetupClearTextureExpectations(kServiceTextureId,
514 kServiceTextureId,
515 GL_TEXTURE_2D,
516 GL_TEXTURE_2D,
518 GL_RGBA,
519 GL_RGBA,
520 GL_UNSIGNED_BYTE,
521 kWidth,
522 kHeight);
523 cmd.Init(GL_TEXTURE_2D,
525 GL_RGBA,
526 kWidth,
527 kHeight,
528 GL_RGBA,
529 GL_UNSIGNED_BYTE,
533 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
534 EXPECT_CALL(*gl_,
535 TexSubImage2D(GL_TEXTURE_2D,
539 kWidth,
540 kHeight - 1,
541 GL_RGBA,
542 GL_UNSIGNED_BYTE,
543 shared_memory_address_))
544 .Times(1)
545 .RetiresOnSaturation();
546 // Consider this TexSubImage2D command part of the previous TexImage2D
547 // (last GL_TRUE argument). It will be skipped if there are bugs in the
548 // redefinition case.
549 TexSubImage2D cmd2;
550 cmd2.Init(GL_TEXTURE_2D,
554 kWidth,
555 kHeight - 1,
556 GL_RGBA,
557 GL_UNSIGNED_BYTE,
558 kSharedMemoryId,
559 kSharedMemoryOffset,
560 GL_TRUE);
561 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
565 TEST_P(GLES2DecoderTest, TexImage2DGLError) {
566 GLenum target = GL_TEXTURE_2D;
567 GLint level = 0;
568 GLenum internal_format = GL_RGBA;
569 GLsizei width = 2;
570 GLsizei height = 4;
571 GLint border = 0;
572 GLenum format = GL_RGBA;
573 GLenum type = GL_UNSIGNED_BYTE;
574 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
575 TextureManager* manager = group().texture_manager();
576 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
577 ASSERT_TRUE(texture_ref != NULL);
578 Texture* texture = texture_ref->texture();
579 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
580 EXPECT_CALL(*gl_, GetError())
581 .WillOnce(Return(GL_NO_ERROR))
582 .WillOnce(Return(GL_OUT_OF_MEMORY))
583 .RetiresOnSaturation();
584 EXPECT_CALL(*gl_,
585 TexImage2D(target,
586 level,
587 internal_format,
588 width,
589 height,
590 border,
591 format,
592 type,
594 .Times(1)
595 .RetiresOnSaturation();
596 TexImage2D cmd;
597 cmd.Init(target,
598 level,
599 internal_format,
600 width,
601 height,
602 format,
603 type,
604 kSharedMemoryId,
605 kSharedMemoryOffset);
606 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
607 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
608 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
611 TEST_P(GLES2DecoderTest, CopyTexImage2DGLError) {
612 GLenum target = GL_TEXTURE_2D;
613 GLint level = 0;
614 GLenum internal_format = GL_RGBA;
615 GLsizei width = 2;
616 GLsizei height = 4;
617 GLint border = 0;
618 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
619 TextureManager* manager = group().texture_manager();
620 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
621 ASSERT_TRUE(texture_ref != NULL);
622 Texture* texture = texture_ref->texture();
623 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
624 EXPECT_CALL(*gl_, GetError())
625 .WillOnce(Return(GL_NO_ERROR))
626 .WillOnce(Return(GL_OUT_OF_MEMORY))
627 .RetiresOnSaturation();
628 EXPECT_CALL(*gl_,
629 CopyTexImage2D(
630 target, level, internal_format, 0, 0, width, height, border))
631 .Times(1)
632 .RetiresOnSaturation();
633 CopyTexImage2D cmd;
634 cmd.Init(target, level, internal_format, 0, 0, width, height);
635 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
636 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
637 EXPECT_FALSE(texture->GetLevelSize(GL_TEXTURE_2D, level, &width, &height));
640 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DBucketBadBucket) {
641 InitState init;
642 init.extensions = "GL_EXT_texture_compression_s3tc";
643 init.bind_generates_resource = true;
644 InitDecoder(init);
646 const uint32 kBadBucketId = 123;
647 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
648 CompressedTexImage2DBucket cmd;
649 cmd.Init(GL_TEXTURE_2D,
651 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
654 kBadBucketId);
655 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
656 CompressedTexSubImage2DBucket cmd2;
657 cmd2.Init(GL_TEXTURE_2D,
663 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT,
664 kBadBucketId);
665 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
668 namespace {
670 struct S3TCTestData {
671 GLenum format;
672 size_t block_size;
675 } // anonymous namespace.
677 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DS3TC) {
678 InitState init;
679 init.extensions = "GL_EXT_texture_compression_s3tc";
680 init.bind_generates_resource = true;
681 InitDecoder(init);
682 const uint32 kBucketId = 123;
683 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
684 ASSERT_TRUE(bucket != NULL);
686 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
688 static const S3TCTestData test_data[] = {
690 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 8,
693 GL_COMPRESSED_RGBA_S3TC_DXT1_EXT, 8,
696 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, 16,
699 GL_COMPRESSED_RGBA_S3TC_DXT5_EXT, 16,
703 for (size_t ii = 0; ii < arraysize(test_data); ++ii) {
704 const S3TCTestData& test = test_data[ii];
705 CompressedTexImage2DBucket cmd;
706 // test small width.
707 DoCompressedTexImage2D(
708 GL_TEXTURE_2D, 0, test.format, 2, 4, 0, test.block_size, kBucketId);
709 EXPECT_EQ(GL_NO_ERROR, GetGLError());
711 // test bad width.
712 cmd.Init(GL_TEXTURE_2D, 0, test.format, 5, 4, kBucketId);
713 bucket->SetSize(test.block_size * 2);
714 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
715 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
717 // test small height.
718 DoCompressedTexImage2D(
719 GL_TEXTURE_2D, 0, test.format, 4, 2, 0, test.block_size, kBucketId);
720 EXPECT_EQ(GL_NO_ERROR, GetGLError());
722 // test too bad height.
723 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 5, kBucketId);
724 bucket->SetSize(test.block_size * 2);
725 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
726 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
728 // test small for level 0.
729 DoCompressedTexImage2D(
730 GL_TEXTURE_2D, 0, test.format, 1, 1, 0, test.block_size, kBucketId);
731 EXPECT_EQ(GL_NO_ERROR, GetGLError());
733 // test small for level 0.
734 DoCompressedTexImage2D(
735 GL_TEXTURE_2D, 0, test.format, 2, 2, 0, test.block_size, kBucketId);
736 EXPECT_EQ(GL_NO_ERROR, GetGLError());
738 // test size too large.
739 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId);
740 bucket->SetSize(test.block_size * 2);
741 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
742 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
744 // test size too small.
745 cmd.Init(GL_TEXTURE_2D, 0, test.format, 4, 4, kBucketId);
746 bucket->SetSize(test.block_size / 2);
747 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
748 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
750 // test with 3 mips.
751 DoCompressedTexImage2D(
752 GL_TEXTURE_2D, 0, test.format, 4, 4, 0, test.block_size, kBucketId);
753 DoCompressedTexImage2D(
754 GL_TEXTURE_2D, 1, test.format, 2, 2, 0, test.block_size, kBucketId);
755 DoCompressedTexImage2D(
756 GL_TEXTURE_2D, 2, test.format, 1, 1, 0, test.block_size, kBucketId);
757 EXPECT_EQ(GL_NO_ERROR, GetGLError());
759 // Test a 16x16
760 DoCompressedTexImage2D(GL_TEXTURE_2D,
762 test.format,
766 test.block_size * 4 * 4,
767 kBucketId);
768 EXPECT_EQ(GL_NO_ERROR, GetGLError());
770 CompressedTexSubImage2DBucket sub_cmd;
771 bucket->SetSize(test.block_size);
772 // Test sub image bad xoffset
773 sub_cmd.Init(GL_TEXTURE_2D, 0, 1, 0, 4, 4, test.format, kBucketId);
774 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
775 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
777 // Test sub image bad yoffset
778 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 2, 4, 4, test.format, kBucketId);
779 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
780 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
782 // Test sub image bad width
783 bucket->SetSize(test.block_size * 2);
784 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 5, 4, test.format, kBucketId);
785 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
786 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
788 // Test sub image bad height
789 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 5, test.format, kBucketId);
790 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
791 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
793 // Test sub image bad size
794 bucket->SetSize(test.block_size + 1);
795 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, test.format, kBucketId);
796 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
797 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
799 for (GLint yoffset = 0; yoffset <= 8; yoffset += 4) {
800 for (GLint xoffset = 0; xoffset <= 8; xoffset += 4) {
801 for (GLsizei height = 4; height <= 8; height += 4) {
802 for (GLsizei width = 4; width <= 8; width += 4) {
803 GLsizei size = test.block_size * (width / 4) * (height / 4);
804 bucket->SetSize(size);
805 EXPECT_CALL(*gl_,
806 CompressedTexSubImage2D(GL_TEXTURE_2D,
808 xoffset,
809 yoffset,
810 width,
811 height,
812 test.format,
813 size,
815 .Times(1)
816 .RetiresOnSaturation();
817 sub_cmd.Init(GL_TEXTURE_2D,
819 xoffset,
820 yoffset,
821 width,
822 height,
823 test.format,
824 kBucketId);
825 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
826 EXPECT_EQ(GL_NO_ERROR, GetGLError());
834 TEST_P(GLES2DecoderManualInitTest, CompressedTexImage2DETC1) {
835 InitState init;
836 init.extensions = "GL_OES_compressed_ETC1_RGB8_texture";
837 init.gl_version = "opengl es 2.0";
838 init.bind_generates_resource = true;
839 InitDecoder(init);
840 const uint32 kBucketId = 123;
841 CommonDecoder::Bucket* bucket = decoder_->CreateBucket(kBucketId);
842 ASSERT_TRUE(bucket != NULL);
844 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
846 const GLenum kFormat = GL_ETC1_RGB8_OES;
847 const size_t kBlockSize = 8;
849 CompressedTexImage2DBucket cmd;
850 // test small width.
851 DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 4, 8, 0, 16, kBucketId);
852 EXPECT_EQ(GL_NO_ERROR, GetGLError());
854 // test small height.
855 DoCompressedTexImage2D(GL_TEXTURE_2D, 0, kFormat, 8, 4, 0, 16, kBucketId);
856 EXPECT_EQ(GL_NO_ERROR, GetGLError());
858 // test size too large.
859 cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, kBucketId);
860 bucket->SetSize(kBlockSize * 2);
861 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
862 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
864 // test size too small.
865 cmd.Init(GL_TEXTURE_2D, 0, kFormat, 4, 4, kBucketId);
866 bucket->SetSize(kBlockSize / 2);
867 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
868 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
870 // Test a 16x16
871 DoCompressedTexImage2D(
872 GL_TEXTURE_2D, 0, kFormat, 16, 16, 0, kBlockSize * 16, kBucketId);
873 EXPECT_EQ(GL_NO_ERROR, GetGLError());
875 // Test CompressedTexSubImage not allowed
876 CompressedTexSubImage2DBucket sub_cmd;
877 bucket->SetSize(kBlockSize);
878 sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 4, 4, kFormat, kBucketId);
879 EXPECT_EQ(error::kNoError, ExecuteCmd(sub_cmd));
880 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
882 // Test TexSubImage not allowed for ETC1 compressed texture
883 TextureRef* texture_ref = GetTexture(client_texture_id_);
884 ASSERT_TRUE(texture_ref != NULL);
885 Texture* texture = texture_ref->texture();
886 GLenum type, internal_format;
887 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
888 EXPECT_EQ(kFormat, internal_format);
889 TexSubImage2D texsub_cmd;
890 texsub_cmd.Init(GL_TEXTURE_2D,
896 GL_RGBA,
897 GL_UNSIGNED_BYTE,
898 kSharedMemoryId,
899 kSharedMemoryOffset,
900 GL_FALSE);
901 EXPECT_EQ(error::kNoError, ExecuteCmd(texsub_cmd));
902 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
904 // Test CopyTexSubImage not allowed for ETC1 compressed texture
905 CopyTexSubImage2D copy_cmd;
906 copy_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 4, 4);
907 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_cmd));
908 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
911 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalBindTexture) {
912 InitState init;
913 init.extensions = "GL_OES_EGL_image_external";
914 init.gl_version = "opengl es 2.0";
915 init.bind_generates_resource = true;
916 InitDecoder(init);
917 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_EXTERNAL_OES, kNewServiceId));
918 EXPECT_CALL(*gl_, GenTextures(1, _))
919 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
920 BindTexture cmd;
921 cmd.Init(GL_TEXTURE_EXTERNAL_OES, kNewClientId);
922 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
923 EXPECT_EQ(GL_NO_ERROR, GetGLError());
924 TextureRef* texture_ref = GetTexture(kNewClientId);
925 EXPECT_TRUE(texture_ref != NULL);
926 EXPECT_TRUE(texture_ref->texture()->target() == GL_TEXTURE_EXTERNAL_OES);
929 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalGetBinding) {
930 InitState init;
931 init.extensions = "GL_OES_EGL_image_external";
932 init.gl_version = "opengl es 2.0";
933 init.bind_generates_resource = true;
934 InitDecoder(init);
935 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
937 EXPECT_CALL(*gl_, GetError())
938 .WillOnce(Return(GL_NO_ERROR))
939 .WillOnce(Return(GL_NO_ERROR))
940 .RetiresOnSaturation();
941 typedef GetIntegerv::Result Result;
942 Result* result = static_cast<Result*>(shared_memory_address_);
943 EXPECT_CALL(*gl_,
944 GetIntegerv(GL_TEXTURE_BINDING_EXTERNAL_OES, result->GetData()))
945 .Times(0);
946 result->size = 0;
947 GetIntegerv cmd;
948 cmd.Init(GL_TEXTURE_BINDING_EXTERNAL_OES,
949 shared_memory_id_,
950 shared_memory_offset_);
951 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
952 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(
953 GL_TEXTURE_BINDING_EXTERNAL_OES),
954 result->GetNumResults());
955 EXPECT_EQ(GL_NO_ERROR, GetGLError());
956 EXPECT_EQ(client_texture_id_, (uint32)result->GetData()[0]);
959 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureDefaults) {
960 InitState init;
961 init.extensions = "GL_OES_EGL_image_external";
962 init.gl_version = "opengl es 2.0";
963 init.bind_generates_resource = true;
964 InitDecoder(init);
965 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
967 TextureRef* texture_ref = GetTexture(client_texture_id_);
968 EXPECT_TRUE(texture_ref != NULL);
969 Texture* texture = texture_ref->texture();
970 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
971 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
972 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
973 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
976 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureParam) {
977 InitState init;
978 init.extensions = "GL_OES_EGL_image_external";
979 init.gl_version = "opengl es 2.0";
980 init.bind_generates_resource = true;
981 InitDecoder(init);
982 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
984 EXPECT_CALL(*gl_,
985 TexParameteri(
986 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
987 EXPECT_CALL(
988 *gl_,
989 TexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
990 EXPECT_CALL(
991 *gl_,
992 TexParameteri(
993 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
994 EXPECT_CALL(
995 *gl_,
996 TexParameteri(
997 GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
998 TexParameteri cmd;
999 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1000 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1001 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1003 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1004 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1005 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1007 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1008 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1009 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1011 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1012 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1013 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1015 TextureRef* texture_ref = GetTexture(client_texture_id_);
1016 EXPECT_TRUE(texture_ref != NULL);
1017 Texture* texture = texture_ref->texture();
1018 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
1019 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1020 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1021 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1024 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTextureParamInvalid) {
1025 InitState init;
1026 init.extensions = "GL_OES_EGL_image_external";
1027 init.gl_version = "opengl es 2.0";
1028 init.bind_generates_resource = true;
1029 InitDecoder(init);
1030 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1032 TexParameteri cmd;
1033 cmd.Init(GL_TEXTURE_EXTERNAL_OES,
1034 GL_TEXTURE_MIN_FILTER,
1035 GL_NEAREST_MIPMAP_NEAREST);
1036 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1037 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1039 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_REPEAT);
1040 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1041 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1043 cmd.Init(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_REPEAT);
1044 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1045 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1047 TextureRef* texture_ref = GetTexture(client_texture_id_);
1048 EXPECT_TRUE(texture_ref != NULL);
1049 Texture* texture = texture_ref->texture();
1050 EXPECT_TRUE(texture->target() == GL_TEXTURE_EXTERNAL_OES);
1051 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1052 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1053 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1056 TEST_P(GLES2DecoderManualInitTest, EGLImageExternalTexImage2DError) {
1057 InitState init;
1058 init.extensions = "GL_OES_EGL_image_external";
1059 init.gl_version = "opengl es 2.0";
1060 init.bind_generates_resource = true;
1061 InitDecoder(init);
1063 GLenum target = GL_TEXTURE_EXTERNAL_OES;
1064 GLint level = 0;
1065 GLenum internal_format = GL_RGBA;
1066 GLsizei width = 2;
1067 GLsizei height = 4;
1068 GLenum format = GL_RGBA;
1069 GLenum type = GL_UNSIGNED_BYTE;
1070 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
1071 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL);
1072 TexImage2D cmd;
1073 cmd.Init(target,
1074 level,
1075 internal_format,
1076 width,
1077 height,
1078 format,
1079 type,
1080 kSharedMemoryId,
1081 kSharedMemoryOffset);
1082 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1084 // TexImage2D is not allowed with GL_TEXTURE_EXTERNAL_OES targets.
1085 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1088 TEST_P(GLES2DecoderManualInitTest, DefaultTextureZero) {
1089 InitState init;
1090 InitDecoder(init);
1092 BindTexture cmd1;
1093 cmd1.Init(GL_TEXTURE_2D, 0);
1094 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1095 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1096 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1098 BindTexture cmd2;
1099 cmd2.Init(GL_TEXTURE_CUBE_MAP, 0);
1100 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1101 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1102 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1105 TEST_P(GLES2DecoderManualInitTest, DefaultTextureBGR) {
1106 InitState init;
1107 init.bind_generates_resource = true;
1108 InitDecoder(init);
1110 BindTexture cmd1;
1111 cmd1.Init(GL_TEXTURE_2D, 0);
1112 EXPECT_CALL(
1113 *gl_, BindTexture(GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId));
1114 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1115 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1117 BindTexture cmd2;
1118 cmd2.Init(GL_TEXTURE_CUBE_MAP, 0);
1119 EXPECT_CALL(*gl_,
1120 BindTexture(GL_TEXTURE_CUBE_MAP,
1121 TestHelper::kServiceDefaultTextureCubemapId));
1122 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1123 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1126 // Test that default texture 0 is immutable.
1127 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameterf) {
1128 InitState init;
1129 InitDecoder(init);
1132 BindTexture cmd1;
1133 cmd1.Init(GL_TEXTURE_2D, 0);
1134 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1135 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1136 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1138 TexParameterf cmd2;
1139 cmd2.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1140 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1141 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1145 BindTexture cmd1;
1146 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1147 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1148 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1149 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1151 TexParameterf cmd2;
1152 cmd2.Init(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1153 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1154 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1158 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameteri) {
1159 InitState init;
1160 InitDecoder(init);
1163 BindTexture cmd1;
1164 cmd1.Init(GL_TEXTURE_2D, 0);
1165 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1166 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1167 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1169 TexParameteri cmd2;
1170 cmd2.Init(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1171 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1172 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1176 BindTexture cmd1;
1177 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1178 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1179 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1180 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1182 TexParameteri cmd2;
1183 cmd2.Init(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
1184 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1185 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1189 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameterfv) {
1190 InitState init;
1191 InitDecoder(init);
1194 BindTexture cmd1;
1195 cmd1.Init(GL_TEXTURE_2D, 0);
1196 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1197 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1198 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1200 GLfloat data = GL_NEAREST;
1201 TexParameterfvImmediate& cmd2 =
1202 *GetImmediateAs<TexParameterfvImmediate>();
1203 cmd2.Init(GL_TEXTURE_2D,
1204 GL_TEXTURE_MAG_FILTER,
1205 &data);
1206 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1207 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1211 BindTexture cmd1;
1212 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1213 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1214 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1215 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1217 GLfloat data = GL_NEAREST;
1218 TexParameterfvImmediate& cmd2 =
1219 *GetImmediateAs<TexParameterfvImmediate>();
1220 cmd2.Init(GL_TEXTURE_CUBE_MAP,
1221 GL_TEXTURE_MAG_FILTER,
1222 &data);
1223 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1224 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1228 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexParameteriv) {
1229 InitState init;
1230 InitDecoder(init);
1233 BindTexture cmd1;
1234 cmd1.Init(GL_TEXTURE_2D, 0);
1235 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1236 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1237 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1239 GLfloat data = GL_NEAREST;
1240 TexParameterfvImmediate& cmd2 =
1241 *GetImmediateAs<TexParameterfvImmediate>();
1242 cmd2.Init(GL_TEXTURE_2D,
1243 GL_TEXTURE_MAG_FILTER,
1244 &data);
1245 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1246 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1250 BindTexture cmd1;
1251 cmd1.Init(GL_TEXTURE_CUBE_MAP, 0);
1252 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, 0));
1253 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1254 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1256 GLfloat data = GL_NEAREST;
1257 TexParameterfvImmediate& cmd2 =
1258 *GetImmediateAs<TexParameterfvImmediate>();
1259 cmd2.Init(GL_TEXTURE_CUBE_MAP,
1260 GL_TEXTURE_MAG_FILTER,
1261 &data);
1262 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd2, sizeof(data)));
1263 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1267 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexImage2D) {
1268 InitState init;
1269 InitDecoder(init);
1271 BindTexture cmd1;
1272 cmd1.Init(GL_TEXTURE_2D, 0);
1273 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1274 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1275 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1277 TexImage2D cmd2;
1278 cmd2.Init(GL_TEXTURE_2D,
1280 GL_RGBA,
1283 GL_RGBA,
1284 GL_UNSIGNED_BYTE,
1285 kSharedMemoryId,
1286 kSharedMemoryOffset);
1287 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1288 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1291 TEST_P(GLES2DecoderManualInitTest, NoDefaultTexSubImage2D) {
1292 InitState init;
1293 InitDecoder(init);
1295 BindTexture cmd1;
1296 cmd1.Init(GL_TEXTURE_2D, 0);
1297 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, 0));
1298 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
1299 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1301 TexSubImage2D cmd2;
1302 cmd2.Init(GL_TEXTURE_2D,
1308 GL_RGBA,
1309 GL_UNSIGNED_BYTE,
1310 kSharedMemoryId,
1311 kSharedMemoryOffset,
1312 GL_FALSE);
1313 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1314 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1317 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleBindTexture) {
1318 InitState init;
1319 init.extensions = "GL_ARB_texture_rectangle";
1320 init.bind_generates_resource = true;
1321 InitDecoder(init);
1322 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_RECTANGLE_ARB, kNewServiceId));
1323 EXPECT_CALL(*gl_, GenTextures(1, _))
1324 .WillOnce(SetArgumentPointee<1>(kNewServiceId));
1325 BindTexture cmd;
1326 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, kNewClientId);
1327 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1328 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1329 Texture* texture = GetTexture(kNewClientId)->texture();
1330 EXPECT_TRUE(texture != NULL);
1331 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1334 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleGetBinding) {
1335 InitState init;
1336 init.extensions = "GL_ARB_texture_rectangle";
1337 init.bind_generates_resource = true;
1338 InitDecoder(init);
1339 DoBindTexture(
1340 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1342 EXPECT_CALL(*gl_, GetError())
1343 .WillOnce(Return(GL_NO_ERROR))
1344 .WillOnce(Return(GL_NO_ERROR))
1345 .RetiresOnSaturation();
1346 typedef GetIntegerv::Result Result;
1347 Result* result = static_cast<Result*>(shared_memory_address_);
1348 EXPECT_CALL(*gl_,
1349 GetIntegerv(GL_TEXTURE_BINDING_RECTANGLE_ARB, result->GetData()))
1350 .Times(0);
1351 result->size = 0;
1352 GetIntegerv cmd;
1353 cmd.Init(GL_TEXTURE_BINDING_RECTANGLE_ARB,
1354 shared_memory_id_,
1355 shared_memory_offset_);
1356 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1357 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(
1358 GL_TEXTURE_BINDING_RECTANGLE_ARB),
1359 result->GetNumResults());
1360 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1361 EXPECT_EQ(client_texture_id_, (uint32)result->GetData()[0]);
1364 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureDefaults) {
1365 InitState init;
1366 init.extensions = "GL_ARB_texture_rectangle";
1367 init.bind_generates_resource = true;
1368 InitDecoder(init);
1369 DoBindTexture(
1370 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1372 Texture* texture = GetTexture(client_texture_id_)->texture();
1373 EXPECT_TRUE(texture != NULL);
1374 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1375 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1376 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1377 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1380 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureParam) {
1381 InitState init;
1382 init.extensions = "GL_ARB_texture_rectangle";
1383 init.bind_generates_resource = true;
1384 InitDecoder(init);
1386 DoBindTexture(
1387 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1389 EXPECT_CALL(*gl_,
1390 TexParameteri(
1391 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST));
1392 EXPECT_CALL(*gl_,
1393 TexParameteri(
1394 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR));
1395 EXPECT_CALL(
1396 *gl_,
1397 TexParameteri(
1398 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE));
1399 EXPECT_CALL(
1400 *gl_,
1401 TexParameteri(
1402 GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE));
1403 TexParameteri cmd;
1404 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
1405 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1406 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1408 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
1409 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1410 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1412 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
1413 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1414 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1416 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
1417 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1418 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1420 Texture* texture = GetTexture(client_texture_id_)->texture();
1421 EXPECT_TRUE(texture != NULL);
1422 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1423 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1424 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1425 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1428 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTextureParamInvalid) {
1429 InitState init;
1430 init.extensions = "GL_ARB_texture_rectangle";
1431 init.bind_generates_resource = true;
1432 InitDecoder(init);
1434 DoBindTexture(
1435 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1437 TexParameteri cmd;
1438 cmd.Init(GL_TEXTURE_RECTANGLE_ARB,
1439 GL_TEXTURE_MIN_FILTER,
1440 GL_NEAREST_MIPMAP_NEAREST);
1441 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1442 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1444 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_S, GL_REPEAT);
1445 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1446 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1448 cmd.Init(GL_TEXTURE_RECTANGLE_ARB, GL_TEXTURE_WRAP_T, GL_REPEAT);
1449 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1450 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1452 Texture* texture = GetTexture(client_texture_id_)->texture();
1453 EXPECT_TRUE(texture != NULL);
1454 EXPECT_TRUE(texture->target() == GL_TEXTURE_RECTANGLE_ARB);
1455 EXPECT_TRUE(texture->min_filter() == GL_LINEAR);
1456 EXPECT_TRUE(texture->wrap_s() == GL_CLAMP_TO_EDGE);
1457 EXPECT_TRUE(texture->wrap_t() == GL_CLAMP_TO_EDGE);
1460 TEST_P(GLES2DecoderManualInitTest, ARBTextureRectangleTexImage2DError) {
1461 InitState init;
1462 init.extensions = "GL_ARB_texture_rectangle";
1463 init.bind_generates_resource = true;
1464 InitDecoder(init);
1466 GLenum target = GL_TEXTURE_RECTANGLE_ARB;
1467 GLint level = 0;
1468 GLenum internal_format = GL_RGBA;
1469 GLsizei width = 2;
1470 GLsizei height = 4;
1471 GLenum format = GL_RGBA;
1472 GLenum type = GL_UNSIGNED_BYTE;
1473 DoBindTexture(
1474 GL_TEXTURE_RECTANGLE_ARB, client_texture_id_, kServiceTextureId);
1475 ASSERT_TRUE(GetTexture(client_texture_id_) != NULL);
1476 TexImage2D cmd;
1477 cmd.Init(target,
1478 level,
1479 internal_format,
1480 width,
1481 height,
1482 format,
1483 type,
1484 kSharedMemoryId,
1485 kSharedMemoryOffset);
1486 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1488 // TexImage2D is not allowed with GL_TEXTURE_RECTANGLE_ARB targets.
1489 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1492 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DClearsAfterTexImage2DNULL) {
1493 InitState init;
1494 init.gl_version = "opengl es 2.0";
1495 init.has_alpha = true;
1496 init.has_depth = true;
1497 init.request_alpha = true;
1498 init.request_depth = true;
1499 InitDecoder(init);
1501 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1502 DoTexImage2D(
1503 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1504 SetupClearTextureExpectations(kServiceTextureId,
1505 kServiceTextureId,
1506 GL_TEXTURE_2D,
1507 GL_TEXTURE_2D,
1509 GL_RGBA,
1510 GL_RGBA,
1511 GL_UNSIGNED_BYTE,
1514 EXPECT_CALL(*gl_,
1515 TexSubImage2D(GL_TEXTURE_2D,
1521 GL_RGBA,
1522 GL_UNSIGNED_BYTE,
1523 shared_memory_address_))
1524 .Times(1)
1525 .RetiresOnSaturation();
1526 TexSubImage2D cmd;
1527 cmd.Init(GL_TEXTURE_2D,
1533 GL_RGBA,
1534 GL_UNSIGNED_BYTE,
1535 kSharedMemoryId,
1536 kSharedMemoryOffset,
1537 GL_FALSE);
1538 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1539 // Test if we call it again it does not clear.
1540 EXPECT_CALL(*gl_,
1541 TexSubImage2D(GL_TEXTURE_2D,
1547 GL_RGBA,
1548 GL_UNSIGNED_BYTE,
1549 shared_memory_address_))
1550 .Times(1)
1551 .RetiresOnSaturation();
1552 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1555 TEST_P(GLES2DecoderTest, TexSubImage2DDoesNotClearAfterTexImage2DNULLThenData) {
1556 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1557 DoTexImage2D(
1558 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1559 DoTexImage2D(GL_TEXTURE_2D,
1561 GL_RGBA,
1565 GL_RGBA,
1566 GL_UNSIGNED_BYTE,
1567 kSharedMemoryId,
1568 kSharedMemoryOffset);
1569 EXPECT_CALL(*gl_,
1570 TexSubImage2D(GL_TEXTURE_2D,
1576 GL_RGBA,
1577 GL_UNSIGNED_BYTE,
1578 shared_memory_address_))
1579 .Times(1)
1580 .RetiresOnSaturation();
1581 TexSubImage2D cmd;
1582 cmd.Init(GL_TEXTURE_2D,
1588 GL_RGBA,
1589 GL_UNSIGNED_BYTE,
1590 kSharedMemoryId,
1591 kSharedMemoryOffset,
1592 GL_FALSE);
1593 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1594 // Test if we call it again it does not clear.
1595 EXPECT_CALL(*gl_,
1596 TexSubImage2D(GL_TEXTURE_2D,
1602 GL_RGBA,
1603 GL_UNSIGNED_BYTE,
1604 shared_memory_address_))
1605 .Times(1)
1606 .RetiresOnSaturation();
1607 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1610 TEST_P(
1611 GLES2DecoderManualInitTest,
1612 TexSubImage2DDoesNotClearAfterTexImage2DNULLThenDataWithTexImage2DIsFaster) {
1613 base::CommandLine command_line(0, NULL);
1614 command_line.AppendSwitchASCII(
1615 switches::kGpuDriverBugWorkarounds,
1616 base::IntToString(gpu::TEXSUBIMAGE2D_FASTER_THAN_TEXIMAGE2D));
1617 InitState init;
1618 init.bind_generates_resource = true;
1619 InitDecoderWithCommandLine(init, &command_line);
1620 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1621 DoTexImage2D(
1622 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1625 // Uses texSubimage internally because the above workaround is active and
1626 // the update is for the full size of the texture.
1627 EXPECT_CALL(*gl_,
1628 TexSubImage2D(
1629 GL_TEXTURE_2D, 0, 0, 0, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, _))
1630 .Times(1)
1631 .RetiresOnSaturation();
1632 cmds::TexImage2D cmd;
1633 cmd.Init(GL_TEXTURE_2D,
1635 GL_RGBA,
1638 GL_RGBA,
1639 GL_UNSIGNED_BYTE,
1640 kSharedMemoryId,
1641 kSharedMemoryOffset);
1642 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1645 EXPECT_CALL(*gl_,
1646 TexSubImage2D(GL_TEXTURE_2D,
1652 GL_RGBA,
1653 GL_UNSIGNED_BYTE,
1654 shared_memory_address_))
1655 .Times(1)
1656 .RetiresOnSaturation();
1657 TexSubImage2D cmd;
1658 cmd.Init(GL_TEXTURE_2D,
1664 GL_RGBA,
1665 GL_UNSIGNED_BYTE,
1666 kSharedMemoryId,
1667 kSharedMemoryOffset,
1668 GL_FALSE);
1669 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1670 // Test if we call it again it does not clear.
1671 EXPECT_CALL(*gl_,
1672 TexSubImage2D(GL_TEXTURE_2D,
1678 GL_RGBA,
1679 GL_UNSIGNED_BYTE,
1680 shared_memory_address_))
1681 .Times(1)
1682 .RetiresOnSaturation();
1683 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1686 TEST_P(GLES2DecoderTest, TexSubImage2DClearsAfterTexImage2DWithDataThenNULL) {
1687 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1688 // Put in data (so it should be marked as cleared)
1689 DoTexImage2D(GL_TEXTURE_2D,
1691 GL_RGBA,
1695 GL_RGBA,
1696 GL_UNSIGNED_BYTE,
1697 kSharedMemoryId,
1698 kSharedMemoryOffset);
1699 // Put in no data.
1700 TexImage2D tex_cmd;
1701 tex_cmd.Init(
1702 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1703 // It won't actually call TexImage2D, just mark it as uncleared.
1704 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
1705 // Next call to TexSubImage2d should clear.
1706 SetupClearTextureExpectations(kServiceTextureId,
1707 kServiceTextureId,
1708 GL_TEXTURE_2D,
1709 GL_TEXTURE_2D,
1711 GL_RGBA,
1712 GL_RGBA,
1713 GL_UNSIGNED_BYTE,
1716 EXPECT_CALL(*gl_,
1717 TexSubImage2D(GL_TEXTURE_2D,
1723 GL_RGBA,
1724 GL_UNSIGNED_BYTE,
1725 shared_memory_address_))
1726 .Times(1)
1727 .RetiresOnSaturation();
1728 TexSubImage2D cmd;
1729 cmd.Init(GL_TEXTURE_2D,
1735 GL_RGBA,
1736 GL_UNSIGNED_BYTE,
1737 kSharedMemoryId,
1738 kSharedMemoryOffset,
1739 GL_FALSE);
1740 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1743 TEST_P(GLES2DecoderTest, CopyTexImage2DMarksTextureAsCleared) {
1744 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1746 TextureManager* manager = group().texture_manager();
1747 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
1748 ASSERT_TRUE(texture_ref != NULL);
1749 Texture* texture = texture_ref->texture();
1751 EXPECT_CALL(*gl_, GetError())
1752 .WillOnce(Return(GL_NO_ERROR))
1753 .RetiresOnSaturation();
1754 EXPECT_CALL(*gl_, CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1, 0))
1755 .Times(1)
1756 .RetiresOnSaturation();
1757 EXPECT_CALL(*gl_, GetError())
1758 .WillOnce(Return(GL_NO_ERROR))
1759 .RetiresOnSaturation();
1760 CopyTexImage2D cmd;
1761 cmd.Init(GL_TEXTURE_2D, 0, GL_RGBA, 0, 0, 1, 1);
1762 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1764 EXPECT_TRUE(texture->SafeToRenderFrom());
1767 TEST_P(GLES2DecoderTest, CopyTexSubImage2DClearsUnclearedTexture) {
1768 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1769 DoTexImage2D(
1770 GL_TEXTURE_2D, 0, GL_RGBA, 2, 2, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1772 SetupClearTextureExpectations(kServiceTextureId,
1773 kServiceTextureId,
1774 GL_TEXTURE_2D,
1775 GL_TEXTURE_2D,
1777 GL_RGBA,
1778 GL_RGBA,
1779 GL_UNSIGNED_BYTE,
1782 EXPECT_CALL(*gl_, CopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1))
1783 .Times(1)
1784 .RetiresOnSaturation();
1785 CopyTexSubImage2D cmd;
1786 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
1787 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1789 TextureManager* manager = group().texture_manager();
1790 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
1791 ASSERT_TRUE(texture_ref != NULL);
1792 Texture* texture = texture_ref->texture();
1793 EXPECT_TRUE(texture->SafeToRenderFrom());
1796 TEST_P(GLES2DecoderTest, CopyTexSubImage2DClearsUnclearedBackBufferSizedTexture) {
1797 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1798 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, kBackBufferWidth, kBackBufferHeight,
1799 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1801 EXPECT_CALL(*gl_, CopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0,
1802 kBackBufferWidth, kBackBufferHeight))
1803 .Times(1)
1804 .RetiresOnSaturation();
1805 CopyTexSubImage2D cmd;
1806 cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, kBackBufferWidth, kBackBufferHeight);
1807 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1809 TextureManager* manager = group().texture_manager();
1810 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
1811 ASSERT_TRUE(texture_ref != NULL);
1812 Texture* texture = texture_ref->texture();
1813 EXPECT_TRUE(texture->SafeToRenderFrom());
1816 TEST_P(GLES2DecoderManualInitTest, CompressedImage2DMarksTextureAsCleared) {
1817 InitState init;
1818 init.extensions = "GL_EXT_texture_compression_s3tc";
1819 init.bind_generates_resource = true;
1820 InitDecoder(init);
1822 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1823 EXPECT_CALL(*gl_, GetError())
1824 .WillOnce(Return(GL_NO_ERROR))
1825 .RetiresOnSaturation();
1826 EXPECT_CALL(
1827 *gl_,
1828 CompressedTexImage2D(
1829 GL_TEXTURE_2D, 0, GL_COMPRESSED_RGB_S3TC_DXT1_EXT, 4, 4, 0, 8, _))
1830 .Times(1)
1831 .RetiresOnSaturation();
1832 EXPECT_CALL(*gl_, GetError())
1833 .WillOnce(Return(GL_NO_ERROR))
1834 .RetiresOnSaturation();
1835 CompressedTexImage2D cmd;
1836 cmd.Init(GL_TEXTURE_2D,
1838 GL_COMPRESSED_RGB_S3TC_DXT1_EXT,
1842 kSharedMemoryId,
1843 kSharedMemoryOffset);
1844 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1845 TextureManager* manager = group().texture_manager();
1846 TextureRef* texture_ref = manager->GetTexture(client_texture_id_);
1847 EXPECT_TRUE(texture_ref->texture()->SafeToRenderFrom());
1850 TEST_P(GLES2DecoderTest, TextureUsageAngleExtNotEnabledByDefault) {
1851 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1853 TexParameteri cmd;
1854 cmd.Init(
1855 GL_TEXTURE_2D, GL_TEXTURE_USAGE_ANGLE, GL_FRAMEBUFFER_ATTACHMENT_ANGLE);
1856 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1857 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1860 TEST_P(GLES2DecoderTest, ProduceAndConsumeTextureCHROMIUM) {
1861 Mailbox mailbox = Mailbox::Generate();
1863 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1864 DoTexImage2D(
1865 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1866 DoTexImage2D(
1867 GL_TEXTURE_2D, 1, GL_RGBA, 2, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1868 TextureRef* texture_ref =
1869 group().texture_manager()->GetTexture(client_texture_id_);
1870 ASSERT_TRUE(texture_ref != NULL);
1871 Texture* texture = texture_ref->texture();
1872 EXPECT_EQ(kServiceTextureId, texture->service_id());
1874 ProduceTextureCHROMIUMImmediate& produce_cmd =
1875 *GetImmediateAs<ProduceTextureCHROMIUMImmediate>();
1876 produce_cmd.Init(GL_TEXTURE_2D, mailbox.name);
1877 EXPECT_EQ(error::kNoError,
1878 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
1879 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1881 // Texture didn't change.
1882 GLsizei width;
1883 GLsizei height;
1884 GLenum type;
1885 GLenum internal_format;
1887 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
1888 EXPECT_EQ(3, width);
1889 EXPECT_EQ(1, height);
1890 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
1891 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1892 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1894 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
1895 EXPECT_EQ(2, width);
1896 EXPECT_EQ(4, height);
1897 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
1898 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1899 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1901 // Service ID has not changed.
1902 EXPECT_EQ(kServiceTextureId, texture->service_id());
1904 // Create new texture for consume.
1905 EXPECT_CALL(*gl_, GenTextures(_, _))
1906 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
1907 .RetiresOnSaturation();
1908 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kNewServiceId);
1910 // Assigns and binds original service size texture ID.
1911 EXPECT_CALL(*gl_, DeleteTextures(1, _)).Times(1).RetiresOnSaturation();
1912 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
1913 .Times(1)
1914 .RetiresOnSaturation();
1916 ConsumeTextureCHROMIUMImmediate& consume_cmd =
1917 *GetImmediateAs<ConsumeTextureCHROMIUMImmediate>();
1918 consume_cmd.Init(GL_TEXTURE_2D, mailbox.name);
1919 EXPECT_EQ(error::kNoError,
1920 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name)));
1921 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1923 // Texture is redefined.
1924 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
1925 EXPECT_EQ(3, width);
1926 EXPECT_EQ(1, height);
1927 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
1928 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1929 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1931 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
1932 EXPECT_EQ(2, width);
1933 EXPECT_EQ(4, height);
1934 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
1935 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1936 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1938 // Service ID is restored.
1939 EXPECT_EQ(kServiceTextureId, texture->service_id());
1942 TEST_P(GLES2DecoderTest, ProduceAndConsumeDirectTextureCHROMIUM) {
1943 Mailbox mailbox = Mailbox::Generate();
1945 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1946 DoTexImage2D(
1947 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1948 DoTexImage2D(
1949 GL_TEXTURE_2D, 1, GL_RGBA, 2, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1950 TextureRef* texture_ref =
1951 group().texture_manager()->GetTexture(client_texture_id_);
1952 ASSERT_TRUE(texture_ref != NULL);
1953 Texture* texture = texture_ref->texture();
1954 EXPECT_EQ(kServiceTextureId, texture->service_id());
1956 ProduceTextureDirectCHROMIUMImmediate& produce_cmd =
1957 *GetImmediateAs<ProduceTextureDirectCHROMIUMImmediate>();
1958 produce_cmd.Init(client_texture_id_, GL_TEXTURE_2D, mailbox.name);
1959 EXPECT_EQ(error::kNoError,
1960 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
1961 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1963 // Texture didn't change.
1964 GLsizei width;
1965 GLsizei height;
1966 GLenum type;
1967 GLenum internal_format;
1969 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
1970 EXPECT_EQ(3, width);
1971 EXPECT_EQ(1, height);
1972 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
1973 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1974 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1976 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
1977 EXPECT_EQ(2, width);
1978 EXPECT_EQ(4, height);
1979 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
1980 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
1981 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
1983 // Service ID has not changed.
1984 EXPECT_EQ(kServiceTextureId, texture->service_id());
1986 // Consume the texture into a new client ID.
1987 GLuint new_texture_id = kNewClientId;
1988 CreateAndConsumeTextureCHROMIUMImmediate& consume_cmd =
1989 *GetImmediateAs<CreateAndConsumeTextureCHROMIUMImmediate>();
1990 consume_cmd.Init(GL_TEXTURE_2D, new_texture_id, mailbox.name);
1991 EXPECT_EQ(error::kNoError,
1992 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name)));
1993 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1995 // Make sure the new client ID is associated with the produced service ID.
1996 texture_ref = group().texture_manager()->GetTexture(new_texture_id);
1997 ASSERT_TRUE(texture_ref != NULL);
1998 texture = texture_ref->texture();
1999 EXPECT_EQ(kServiceTextureId, texture->service_id());
2001 DoBindTexture(GL_TEXTURE_2D, kNewClientId, kServiceTextureId);
2003 // Texture is redefined.
2004 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2005 EXPECT_EQ(3, width);
2006 EXPECT_EQ(1, height);
2007 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2008 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2009 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2011 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 1, &width, &height));
2012 EXPECT_EQ(2, width);
2013 EXPECT_EQ(4, height);
2014 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 1, &type, &internal_format));
2015 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2016 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2019 TEST_P(GLES2DecoderTest, ProduceTextureCHROMIUMInvalidTarget) {
2020 Mailbox mailbox = Mailbox::Generate();
2022 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2023 DoTexImage2D(
2024 GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, 3, 1, 0, GL_RGBA,
2025 GL_UNSIGNED_BYTE, 0, 0);
2026 TextureRef* texture_ref =
2027 group().texture_manager()->GetTexture(client_texture_id_);
2028 ASSERT_TRUE(texture_ref != NULL);
2029 Texture* texture = texture_ref->texture();
2030 EXPECT_EQ(kServiceTextureId, texture->service_id());
2032 ProduceTextureDirectCHROMIUMImmediate& produce_cmd =
2033 *GetImmediateAs<ProduceTextureDirectCHROMIUMImmediate>();
2034 produce_cmd.Init(client_texture_id_, GL_TEXTURE_2D, mailbox.name);
2035 EXPECT_EQ(error::kNoError,
2036 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
2038 // ProduceTexture should fail it the texture and produce targets don't match.
2039 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2042 TEST_P(GLES2DecoderTest, CreateAndConsumeTextureCHROMIUMInvalidMailbox) {
2043 // Attempt to consume the mailbox when no texture has been produced with it.
2044 Mailbox mailbox = Mailbox::Generate();
2045 GLuint new_texture_id = kNewClientId;
2047 EXPECT_CALL(*gl_, GenTextures(1, _))
2048 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
2049 .RetiresOnSaturation();
2050 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, _))
2051 .Times(2)
2052 .RetiresOnSaturation();
2053 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
2054 .Times(1)
2055 .RetiresOnSaturation();
2057 CreateAndConsumeTextureCHROMIUMImmediate& consume_cmd =
2058 *GetImmediateAs<CreateAndConsumeTextureCHROMIUMImmediate>();
2059 consume_cmd.Init(GL_TEXTURE_2D, new_texture_id, mailbox.name);
2060 EXPECT_EQ(error::kNoError,
2061 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name)));
2063 // CreateAndConsumeTexture should fail if the mailbox isn't associated with a
2064 // texture.
2065 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2067 // Make sure the new client_id is associated with a texture ref even though
2068 // CreateAndConsumeTexture failed.
2069 TextureRef* texture_ref =
2070 group().texture_manager()->GetTexture(new_texture_id);
2071 ASSERT_TRUE(texture_ref != NULL);
2072 Texture* texture = texture_ref->texture();
2073 // New texture should have the correct target type.
2074 EXPECT_TRUE(texture->target() == GL_TEXTURE_2D);
2075 // New texture should have a valid service_id.
2076 EXPECT_EQ(kNewServiceId, texture->service_id());
2079 TEST_P(GLES2DecoderTest, CreateAndConsumeTextureCHROMIUMInvalidTarget) {
2080 Mailbox mailbox = Mailbox::Generate();
2082 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2083 TextureRef* texture_ref =
2084 group().texture_manager()->GetTexture(client_texture_id_);
2085 ASSERT_TRUE(texture_ref != NULL);
2087 ProduceTextureDirectCHROMIUMImmediate& produce_cmd =
2088 *GetImmediateAs<ProduceTextureDirectCHROMIUMImmediate>();
2089 produce_cmd.Init(client_texture_id_, GL_TEXTURE_2D, mailbox.name);
2090 EXPECT_EQ(error::kNoError,
2091 ExecuteImmediateCmd(produce_cmd, sizeof(mailbox.name)));
2092 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2094 EXPECT_CALL(*gl_, GenTextures(1, _))
2095 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
2096 .RetiresOnSaturation();
2097 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_CUBE_MAP, _))
2098 .Times(2)
2099 .RetiresOnSaturation();
2100 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
2101 .Times(1)
2102 .RetiresOnSaturation();
2104 // Attempt to consume the mailbox with a different target.
2105 GLuint new_texture_id = kNewClientId;
2106 CreateAndConsumeTextureCHROMIUMImmediate& consume_cmd =
2107 *GetImmediateAs<CreateAndConsumeTextureCHROMIUMImmediate>();
2108 consume_cmd.Init(GL_TEXTURE_CUBE_MAP, new_texture_id, mailbox.name);
2109 EXPECT_EQ(error::kNoError,
2110 ExecuteImmediateCmd(consume_cmd, sizeof(mailbox.name)));
2112 // CreateAndConsumeTexture should fail if the produced texture had a different
2113 // target.
2114 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2116 // Make sure the new client_id is associated with a texture ref even though
2117 // CreateAndConsumeTexture failed.
2118 texture_ref = group().texture_manager()->GetTexture(new_texture_id);
2119 ASSERT_TRUE(texture_ref != NULL);
2120 Texture* texture = texture_ref->texture();
2121 // New texture should have the correct target type.
2122 EXPECT_TRUE(texture->target() == GL_TEXTURE_CUBE_MAP);
2123 // New texture should have a valid service_id.
2124 EXPECT_EQ(kNewServiceId, texture->service_id());
2126 // Make sure the client_id did not become associated with the produced texture
2127 // service_id.
2128 EXPECT_NE(kServiceTextureId, texture->service_id());
2131 TEST_P(GLES2DecoderManualInitTest, DepthTextureBadArgs) {
2132 InitState init;
2133 init.extensions = "GL_ANGLE_depth_texture";
2134 init.gl_version = "opengl es 2.0";
2135 init.has_depth = true;
2136 init.has_stencil = true;
2137 init.request_depth = true;
2138 init.request_stencil = true;
2139 init.bind_generates_resource = true;
2140 InitDecoder(init);
2142 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2143 // Check trying to upload data fails.
2144 TexImage2D tex_cmd;
2145 tex_cmd.Init(GL_TEXTURE_2D,
2147 GL_DEPTH_COMPONENT,
2150 GL_DEPTH_COMPONENT,
2151 GL_UNSIGNED_INT,
2152 kSharedMemoryId,
2153 kSharedMemoryOffset);
2154 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
2155 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2156 // Try level > 0.
2157 tex_cmd.Init(GL_TEXTURE_2D,
2159 GL_DEPTH_COMPONENT,
2162 GL_DEPTH_COMPONENT,
2163 GL_UNSIGNED_INT,
2166 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_cmd));
2167 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2168 // Make a 1 pixel depth texture.
2169 DoTexImage2D(GL_TEXTURE_2D,
2171 GL_DEPTH_COMPONENT,
2175 GL_DEPTH_COMPONENT,
2176 GL_UNSIGNED_INT,
2179 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2181 // Check that trying to update it fails.
2182 TexSubImage2D tex_sub_cmd;
2183 tex_sub_cmd.Init(GL_TEXTURE_2D,
2189 GL_DEPTH_COMPONENT,
2190 GL_UNSIGNED_INT,
2191 kSharedMemoryId,
2192 kSharedMemoryOffset,
2193 GL_FALSE);
2194 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_sub_cmd));
2195 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2197 // Check that trying to CopyTexImage2D fails
2198 CopyTexImage2D copy_tex_cmd;
2199 copy_tex_cmd.Init(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 0, 0, 1, 1);
2200 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_tex_cmd));
2201 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2203 // Check that trying to CopyTexSubImage2D fails
2204 CopyTexSubImage2D copy_sub_cmd;
2205 copy_sub_cmd.Init(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 1, 1);
2206 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_sub_cmd));
2207 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2210 TEST_P(GLES2DecoderManualInitTest, GenerateMipmapDepthTexture) {
2211 InitState init;
2212 init.extensions = "GL_ANGLE_depth_texture";
2213 init.gl_version = "opengl es 2.0";
2214 init.has_depth = true;
2215 init.has_stencil = true;
2216 init.request_depth = true;
2217 init.request_stencil = true;
2218 init.bind_generates_resource = true;
2219 InitDecoder(init);
2220 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2221 DoTexImage2D(GL_TEXTURE_2D,
2223 GL_DEPTH_COMPONENT,
2227 GL_DEPTH_COMPONENT,
2228 GL_UNSIGNED_INT,
2231 GenerateMipmap cmd;
2232 cmd.Init(GL_TEXTURE_2D);
2233 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2234 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2237 TEST_P(GLES2DecoderTest, BindTexImage2DCHROMIUM) {
2238 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2239 DoTexImage2D(
2240 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2241 TextureRef* texture_ref =
2242 group().texture_manager()->GetTexture(client_texture_id_);
2243 ASSERT_TRUE(texture_ref != NULL);
2244 Texture* texture = texture_ref->texture();
2245 EXPECT_EQ(kServiceTextureId, texture->service_id());
2247 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2248 GetImageManager()->AddImage(image.get(), 1);
2249 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL);
2251 GLsizei width;
2252 GLsizei height;
2253 GLenum type;
2254 GLenum internal_format;
2256 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2257 EXPECT_EQ(3, width);
2258 EXPECT_EQ(1, height);
2259 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2260 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2261 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2262 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2264 // Bind image to texture.
2265 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2266 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2267 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2268 // Image should now be set.
2269 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2271 // Define new texture image.
2272 DoTexImage2D(
2273 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2274 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2275 // Image should no longer be set.
2276 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2279 TEST_P(GLES2DecoderTest, BindTexImage2DCHROMIUMCubeMapNotAllowed) {
2280 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2281 GetImageManager()->AddImage(image.get(), 1);
2282 DoBindTexture(GL_TEXTURE_CUBE_MAP, client_texture_id_, kServiceTextureId);
2284 BindTexImage2DCHROMIUM bind_tex_image_2d_cmd;
2285 bind_tex_image_2d_cmd.Init(GL_TEXTURE_CUBE_MAP, 1);
2286 EXPECT_EQ(error::kNoError, ExecuteCmd(bind_tex_image_2d_cmd));
2287 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
2290 TEST_P(GLES2DecoderTest, OrphanGLImageWithTexImage2D) {
2291 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2292 GetImageManager()->AddImage(image.get(), 1);
2293 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2295 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2297 TextureRef* texture_ref =
2298 group().texture_manager()->GetTexture(client_texture_id_);
2299 ASSERT_TRUE(texture_ref != NULL);
2300 Texture* texture = texture_ref->texture();
2302 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2303 DoTexImage2D(
2304 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2305 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2308 TEST_P(GLES2DecoderTest, GLImageAttachedAfterSubTexImage2D) {
2309 // Specifically tests that TexSubImage2D is not optimized to TexImage2D
2310 // in the presence of image attachments.
2311 ASSERT_FALSE(
2312 feature_info()->workarounds().texsubimage2d_faster_than_teximage2d);
2314 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2315 GetImageManager()->AddImage(image.get(), 1);
2316 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2318 GLenum target = GL_TEXTURE_2D;
2319 GLint level = 0;
2320 GLint xoffset = 0;
2321 GLint yoffset = 0;
2322 GLsizei width = 1;
2323 GLsizei height = 1;
2324 GLint border = 0;
2325 GLenum format = GL_RGBA;
2326 GLenum type = GL_UNSIGNED_BYTE;
2327 uint32_t pixels_shm_id = kSharedMemoryId;
2328 uint32_t pixels_shm_offset = kSharedMemoryOffset;
2329 GLboolean internal = 0;
2331 // Define texture first.
2332 DoTexImage2D(target, level, format, width, height, border, format, type,
2333 pixels_shm_id, pixels_shm_offset);
2335 // Bind texture to GLImage.
2336 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2338 // Check binding.
2339 TextureRef* texture_ref =
2340 group().texture_manager()->GetTexture(client_texture_id_);
2341 ASSERT_TRUE(texture_ref != NULL);
2342 Texture* texture = texture_ref->texture();
2343 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2345 // TexSubImage2D should not unbind GLImage.
2346 EXPECT_CALL(*gl_, TexSubImage2D(target, level, xoffset, yoffset, width,
2347 height, format, type, _))
2348 .Times(1)
2349 .RetiresOnSaturation();
2350 cmds::TexSubImage2D tex_sub_image_2d_cmd;
2351 tex_sub_image_2d_cmd.Init(target, level, xoffset, yoffset, width, height,
2352 format, type, pixels_shm_id, pixels_shm_offset,
2353 internal);
2354 EXPECT_EQ(error::kNoError, ExecuteCmd(tex_sub_image_2d_cmd));
2355 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2358 TEST_P(GLES2DecoderTest, GLImageAttachedAfterClearLevel) {
2359 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2360 GetImageManager()->AddImage(image.get(), 1);
2361 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2363 GLenum target = GL_TEXTURE_2D;
2364 GLint level = 0;
2365 GLint xoffset = 0;
2366 GLint yoffset = 0;
2367 GLsizei width = 1;
2368 GLsizei height = 1;
2369 GLint border = 0;
2370 GLenum format = GL_RGBA;
2371 GLenum type = GL_UNSIGNED_BYTE;
2372 uint32_t pixels_shm_id = kSharedMemoryId;
2373 uint32_t pixels_shm_offset = kSharedMemoryOffset;
2375 // Define texture first.
2376 DoTexImage2D(target, level, format, width, height, border, format, type,
2377 pixels_shm_id, pixels_shm_offset);
2379 // Bind texture to GLImage.
2380 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2382 // Check binding.
2383 TextureRef* texture_ref =
2384 group().texture_manager()->GetTexture(client_texture_id_);
2385 ASSERT_TRUE(texture_ref != NULL);
2386 Texture* texture = texture_ref->texture();
2387 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2389 // ClearLevel should use glTexSubImage2D to avoid unbinding GLImage.
2390 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2391 .Times(2)
2392 .RetiresOnSaturation();
2393 EXPECT_CALL(*gl_, TexSubImage2D(target, level, xoffset, yoffset, width,
2394 height, format, type, _))
2395 .Times(1)
2396 .RetiresOnSaturation();
2397 GetDecoder()->ClearLevel(texture, target, level, format, format, type, width,
2398 height, false);
2399 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == image.get());
2402 TEST_P(GLES2DecoderTest, ReleaseTexImage2DCHROMIUM) {
2403 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2404 DoTexImage2D(
2405 GL_TEXTURE_2D, 0, GL_RGBA, 3, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2406 TextureRef* texture_ref =
2407 group().texture_manager()->GetTexture(client_texture_id_);
2408 ASSERT_TRUE(texture_ref != NULL);
2409 Texture* texture = texture_ref->texture();
2410 EXPECT_EQ(kServiceTextureId, texture->service_id());
2412 scoped_refptr<gfx::GLImage> image(new gfx::GLImageStub);
2413 GetImageManager()->AddImage(image.get(), 1);
2414 EXPECT_FALSE(GetImageManager()->LookupImage(1) == NULL);
2416 GLsizei width;
2417 GLsizei height;
2418 GLenum type;
2419 GLenum internal_format;
2421 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2422 EXPECT_EQ(3, width);
2423 EXPECT_EQ(1, height);
2424 EXPECT_TRUE(texture->GetLevelType(GL_TEXTURE_2D, 0, &type, &internal_format));
2425 EXPECT_EQ(static_cast<GLenum>(GL_RGBA), internal_format);
2426 EXPECT_EQ(static_cast<GLenum>(GL_UNSIGNED_BYTE), type);
2427 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2429 // Bind image to texture.
2430 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2431 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, 1);
2432 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2433 // Image should now be set.
2434 EXPECT_FALSE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2436 // Release image from texture.
2437 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2438 EXPECT_CALL(*gl_, GetError())
2439 .WillOnce(Return(GL_NO_ERROR))
2440 .WillOnce(Return(GL_NO_ERROR))
2441 .RetiresOnSaturation();
2442 ReleaseTexImage2DCHROMIUM release_tex_image_2d_cmd;
2443 release_tex_image_2d_cmd.Init(GL_TEXTURE_2D, 1);
2444 EXPECT_EQ(error::kNoError, ExecuteCmd(release_tex_image_2d_cmd));
2445 EXPECT_TRUE(texture->GetLevelSize(GL_TEXTURE_2D, 0, &width, &height));
2446 // Image should no longer be set.
2447 EXPECT_TRUE(texture->GetLevelImage(GL_TEXTURE_2D, 0) == NULL);
2450 class MockGLImage : public gfx::GLImage {
2451 public:
2452 MockGLImage() {}
2454 // Overridden from gfx::GLImage:
2455 MOCK_METHOD0(GetSize, gfx::Size());
2456 MOCK_METHOD1(Destroy, void(bool));
2457 MOCK_METHOD1(BindTexImage, bool(unsigned));
2458 MOCK_METHOD1(ReleaseTexImage, void(unsigned));
2459 MOCK_METHOD1(CopyTexImage, bool(unsigned));
2460 MOCK_METHOD0(WillUseTexImage, void());
2461 MOCK_METHOD0(DidUseTexImage, void());
2462 MOCK_METHOD0(WillModifyTexImage, void());
2463 MOCK_METHOD0(DidModifyTexImage, void());
2464 MOCK_METHOD5(ScheduleOverlayPlane, bool(gfx::AcceleratedWidget,
2465 int,
2466 gfx::OverlayTransform,
2467 const gfx::Rect&,
2468 const gfx::RectF&));
2470 protected:
2471 virtual ~MockGLImage() {}
2474 TEST_P(GLES2DecoderWithShaderTest, UseTexImage) {
2475 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2476 DoTexImage2D(GL_TEXTURE_2D,
2478 GL_RGBA,
2482 GL_RGBA,
2483 GL_UNSIGNED_BYTE,
2484 kSharedMemoryId,
2485 kSharedMemoryOffset);
2487 TextureRef* texture_ref =
2488 group().texture_manager()->GetTexture(client_texture_id_);
2489 ASSERT_TRUE(texture_ref != NULL);
2490 Texture* texture = texture_ref->texture();
2491 EXPECT_EQ(kServiceTextureId, texture->service_id());
2493 const int32 kImageId = 1;
2494 scoped_refptr<MockGLImage> image(new MockGLImage);
2495 GetImageManager()->AddImage(image.get(), kImageId);
2497 // Bind image to texture.
2498 EXPECT_CALL(*image.get(), BindTexImage(GL_TEXTURE_2D))
2499 .Times(1)
2500 .WillOnce(Return(true))
2501 .RetiresOnSaturation();
2502 EXPECT_CALL(*image.get(), GetSize())
2503 .Times(1)
2504 .WillOnce(Return(gfx::Size(1, 1)))
2505 .RetiresOnSaturation();
2506 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2507 DoBindTexImage2DCHROMIUM(GL_TEXTURE_2D, kImageId);
2509 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
2510 SetupExpectationsForApplyingDefaultDirtyState();
2512 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2513 EXPECT_CALL(*gl_, GetError())
2514 .WillOnce(Return(GL_NO_ERROR))
2515 .WillOnce(Return(GL_NO_ERROR))
2516 .WillOnce(Return(GL_NO_ERROR))
2517 .WillOnce(Return(GL_NO_ERROR))
2518 .RetiresOnSaturation();
2519 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(3).RetiresOnSaturation();
2520 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2521 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2522 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
2523 .Times(1)
2524 .RetiresOnSaturation();
2525 DrawArrays cmd;
2526 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
2527 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2528 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2530 DoBindFramebuffer(
2531 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2532 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2533 EXPECT_CALL(*gl_, GetError())
2534 .WillOnce(Return(GL_NO_ERROR))
2535 .WillOnce(Return(GL_NO_ERROR))
2536 .RetiresOnSaturation();
2537 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2538 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2539 .Times(2)
2540 .RetiresOnSaturation();
2541 // Image will be 'in use' as long as bound to a framebuffer.
2542 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2543 EXPECT_CALL(*gl_,
2544 FramebufferTexture2DEXT(GL_FRAMEBUFFER,
2545 GL_COLOR_ATTACHMENT0,
2546 GL_TEXTURE_2D,
2547 kServiceTextureId,
2549 .Times(1)
2550 .RetiresOnSaturation();
2551 EXPECT_CALL(*gl_, GetError())
2552 .WillOnce(Return(GL_NO_ERROR))
2553 .WillOnce(Return(GL_NO_ERROR))
2554 .RetiresOnSaturation();
2555 FramebufferTexture2D fbtex_cmd;
2556 fbtex_cmd.Init(GL_FRAMEBUFFER,
2557 GL_COLOR_ATTACHMENT0,
2558 GL_TEXTURE_2D,
2559 client_texture_id_);
2560 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd));
2561 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2563 // ScopedGLErrorSuppressor calls GetError on its constructor and destructor.
2564 EXPECT_CALL(*gl_, GetError())
2565 .WillOnce(Return(GL_NO_ERROR))
2566 .WillOnce(Return(GL_NO_ERROR))
2567 .RetiresOnSaturation();
2568 EXPECT_CALL(*gl_,
2569 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
2570 GL_COLOR_ATTACHMENT0,
2571 GL_RENDERBUFFER,
2572 kServiceRenderbufferId))
2573 .Times(1)
2574 .RetiresOnSaturation();
2575 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2576 EXPECT_CALL(*gl_, BindTexture(GL_TEXTURE_2D, kServiceTextureId))
2577 .Times(2)
2578 .RetiresOnSaturation();
2579 // Image should no longer be 'in use' after being unbound from framebuffer.
2580 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2581 EXPECT_CALL(*gl_, GetError())
2582 .WillOnce(Return(GL_NO_ERROR))
2583 .WillOnce(Return(GL_NO_ERROR))
2584 .RetiresOnSaturation();
2585 FramebufferRenderbuffer fbrb_cmd;
2586 fbrb_cmd.Init(GL_FRAMEBUFFER,
2587 GL_COLOR_ATTACHMENT0,
2588 GL_RENDERBUFFER,
2589 client_renderbuffer_id_);
2590 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
2593 TEST_P(GLES2DecoderManualInitTest, DrawWithGLImageExternal) {
2594 InitState init;
2595 init.extensions = "GL_OES_EGL_image_external";
2596 init.gl_version = "opengl es 2.0";
2597 init.has_alpha = true;
2598 init.has_depth = true;
2599 init.request_alpha = true;
2600 init.request_depth = true;
2601 init.bind_generates_resource = true;
2602 InitDecoder(init);
2604 TextureRef* texture_ref = GetTexture(client_texture_id_);
2605 scoped_refptr<MockGLImage> image(new MockGLImage);
2606 group().texture_manager()->SetTarget(texture_ref, GL_TEXTURE_EXTERNAL_OES);
2607 group().texture_manager()->SetLevelInfo(texture_ref,
2608 GL_TEXTURE_EXTERNAL_OES,
2610 GL_RGBA,
2615 GL_RGBA,
2616 GL_UNSIGNED_BYTE,
2617 true);
2618 group().texture_manager()->SetLevelImage(
2619 texture_ref, GL_TEXTURE_EXTERNAL_OES, 0, image.get());
2621 DoBindTexture(GL_TEXTURE_EXTERNAL_OES, client_texture_id_, kServiceTextureId);
2622 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2624 SetupSamplerExternalProgram();
2625 SetupIndexBuffer();
2626 AddExpectationsForSimulatedAttrib0(kMaxValidIndex + 1, 0);
2627 SetupExpectationsForApplyingDefaultDirtyState();
2628 EXPECT_TRUE(group().texture_manager()->CanRender(texture_ref));
2630 InSequence s;
2631 EXPECT_CALL(*gl_, GetError())
2632 .WillOnce(Return(GL_NO_ERROR))
2633 .RetiresOnSaturation();
2634 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2635 EXPECT_CALL(*image.get(), WillUseTexImage()).Times(1).RetiresOnSaturation();
2636 EXPECT_CALL(*gl_, GetError())
2637 .WillOnce(Return(GL_NO_ERROR))
2638 .RetiresOnSaturation();
2639 EXPECT_CALL(*gl_, DrawElements(_, _, _, _)).Times(1);
2640 EXPECT_CALL(*gl_, GetError())
2641 .WillOnce(Return(GL_NO_ERROR))
2642 .RetiresOnSaturation();
2643 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2644 EXPECT_CALL(*image.get(), DidUseTexImage()).Times(1).RetiresOnSaturation();
2645 EXPECT_CALL(*gl_, GetError())
2646 .WillOnce(Return(GL_NO_ERROR))
2647 .RetiresOnSaturation();
2648 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)).Times(1).RetiresOnSaturation();
2649 DrawElements cmd;
2650 cmd.Init(GL_TRIANGLES,
2651 kValidIndexRangeCount,
2652 GL_UNSIGNED_SHORT,
2653 kValidIndexRangeStart * 2);
2654 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2655 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2658 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES2) {
2659 InitState init;
2660 init.extensions = "GL_OES_texture_float";
2661 init.gl_version = "opengl es 2.0";
2662 InitDecoder(init);
2663 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2664 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2665 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0);
2666 DoTexImage2D(
2667 GL_TEXTURE_2D, 0, GL_LUMINANCE, 16, 17, 0, GL_LUMINANCE, GL_FLOAT, 0, 0);
2668 DoTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 16, 17, 0, GL_ALPHA, GL_FLOAT, 0, 0);
2669 DoTexImage2D(GL_TEXTURE_2D,
2671 GL_LUMINANCE_ALPHA,
2675 GL_LUMINANCE_ALPHA,
2676 GL_FLOAT,
2681 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatOnGLES3) {
2682 InitState init;
2683 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
2684 init.gl_version = "opengl es 3.0";
2685 InitDecoder(init);
2686 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2687 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2688 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0);
2689 DoTexImage2D(
2690 GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2691 DoTexImage2D(
2692 GL_TEXTURE_2D, 0, GL_LUMINANCE, 16, 17, 0, GL_LUMINANCE, GL_FLOAT, 0, 0);
2693 DoTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA, 16, 17, 0, GL_ALPHA, GL_FLOAT, 0, 0);
2694 DoTexImage2D(GL_TEXTURE_2D,
2696 GL_LUMINANCE_ALPHA,
2700 GL_LUMINANCE_ALPHA,
2701 GL_FLOAT,
2706 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DFloatOnGLES3) {
2707 InitState init;
2708 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
2709 init.gl_version = "opengl es 3.0";
2710 InitDecoder(init);
2711 const int kWidth = 8;
2712 const int kHeight = 4;
2713 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2714 DoTexImage2D(GL_TEXTURE_2D,
2716 GL_RGBA32F,
2717 kWidth,
2718 kHeight,
2720 GL_RGBA,
2721 GL_FLOAT,
2724 EXPECT_CALL(*gl_,
2725 TexImage2D(GL_TEXTURE_2D,
2727 GL_RGBA32F,
2728 kWidth,
2729 kHeight,
2731 GL_RGBA,
2732 GL_FLOAT,
2733 shared_memory_address_))
2734 .Times(1)
2735 .RetiresOnSaturation();
2736 TexSubImage2D cmd;
2737 cmd.Init(GL_TEXTURE_2D,
2741 kWidth,
2742 kHeight,
2743 GL_RGBA,
2744 GL_FLOAT,
2745 kSharedMemoryId,
2746 kSharedMemoryOffset,
2747 GL_FALSE);
2748 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2749 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2752 TEST_P(GLES2DecoderManualInitTest, TexSubImage2DFloatDoesClearOnGLES3) {
2753 InitState init;
2754 init.extensions = "GL_OES_texture_float GL_EXT_color_buffer_float";
2755 init.gl_version = "opengl es 3.0";
2756 InitDecoder(init);
2757 const int kWidth = 8;
2758 const int kHeight = 4;
2759 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2760 DoTexImage2D(GL_TEXTURE_2D,
2762 GL_RGBA32F,
2763 kWidth,
2764 kHeight,
2766 GL_RGBA,
2767 GL_FLOAT,
2770 SetupClearTextureExpectations(kServiceTextureId,
2771 kServiceTextureId,
2772 GL_TEXTURE_2D,
2773 GL_TEXTURE_2D,
2775 GL_RGBA32F,
2776 GL_RGBA,
2777 GL_FLOAT,
2778 kWidth,
2779 kHeight);
2780 EXPECT_CALL(*gl_,
2781 TexSubImage2D(GL_TEXTURE_2D,
2785 kWidth - 1,
2786 kHeight,
2787 GL_RGBA,
2788 GL_FLOAT,
2789 shared_memory_address_))
2790 .Times(1)
2791 .RetiresOnSaturation();
2792 TexSubImage2D cmd;
2793 cmd.Init(GL_TEXTURE_2D,
2797 kWidth - 1,
2798 kHeight,
2799 GL_RGBA,
2800 GL_FLOAT,
2801 kSharedMemoryId,
2802 kSharedMemoryOffset,
2803 GL_FALSE);
2804 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2805 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2808 TEST_P(GLES2DecoderManualInitTest, TexImage2DFloatConvertsFormatDesktop) {
2809 InitState init;
2810 init.extensions = "GL_ARB_texture_float";
2811 InitDecoder(init);
2812 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
2813 DoTexImage2D(
2814 GL_TEXTURE_2D, 0, GL_RGBA32F, 16, 17, 0, GL_RGBA, GL_FLOAT, 0, 0);
2815 DoTexImage2D(GL_TEXTURE_2D, 0, GL_RGB32F, 16, 17, 0, GL_RGB, GL_FLOAT, 0, 0);
2816 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2818 GL_RGBA,
2822 GL_RGBA,
2823 GL_FLOAT,
2826 GL_RGBA32F_ARB);
2827 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2829 GL_RGB,
2833 GL_RGB,
2834 GL_FLOAT,
2837 GL_RGB32F_ARB);
2838 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2840 GL_LUMINANCE,
2844 GL_LUMINANCE,
2845 GL_FLOAT,
2848 GL_LUMINANCE32F_ARB);
2849 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2851 GL_ALPHA,
2855 GL_ALPHA,
2856 GL_FLOAT,
2859 GL_ALPHA32F_ARB);
2860 DoTexImage2DConvertInternalFormat(GL_TEXTURE_2D,
2862 GL_LUMINANCE_ALPHA,
2866 GL_LUMINANCE_ALPHA,
2867 GL_FLOAT,
2870 GL_LUMINANCE_ALPHA32F_ARB);
2873 class GLES2DecoderCompressedFormatsTest : public GLES2DecoderManualInitTest {
2874 public:
2875 GLES2DecoderCompressedFormatsTest() {}
2877 static bool ValueInArray(GLint value, GLint* array, GLint count) {
2878 for (GLint ii = 0; ii < count; ++ii) {
2879 if (array[ii] == value) {
2880 return true;
2883 return false;
2886 void CheckFormats(const char* extension, const GLenum* formats, int count) {
2887 InitState init;
2888 init.extensions = extension;
2889 init.bind_generates_resource = true;
2890 InitDecoder(init);
2892 EXPECT_CALL(*gl_, GetError())
2893 .WillOnce(Return(GL_NO_ERROR))
2894 .WillOnce(Return(GL_NO_ERROR))
2895 .WillOnce(Return(GL_NO_ERROR))
2896 .WillOnce(Return(GL_NO_ERROR))
2897 .RetiresOnSaturation();
2899 typedef GetIntegerv::Result Result;
2900 Result* result = static_cast<Result*>(shared_memory_address_);
2901 GetIntegerv cmd;
2902 result->size = 0;
2903 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
2904 cmd.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS,
2905 shared_memory_id_,
2906 shared_memory_offset_);
2907 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2908 EXPECT_EQ(1, result->GetNumResults());
2909 GLint num_formats = result->GetData()[0];
2910 EXPECT_EQ(count, num_formats);
2911 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2913 result->size = 0;
2914 cmd.Init(GL_COMPRESSED_TEXTURE_FORMATS,
2915 shared_memory_id_,
2916 shared_memory_offset_);
2917 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2918 EXPECT_EQ(num_formats, result->GetNumResults());
2920 for (int i = 0; i < count; ++i) {
2921 EXPECT_TRUE(
2922 ValueInArray(formats[i], result->GetData(), result->GetNumResults()));
2925 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2929 INSTANTIATE_TEST_CASE_P(Service,
2930 GLES2DecoderCompressedFormatsTest,
2931 ::testing::Bool());
2933 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsS3TC) {
2934 const GLenum formats[] = {
2935 GL_COMPRESSED_RGB_S3TC_DXT1_EXT, GL_COMPRESSED_RGBA_S3TC_DXT1_EXT,
2936 GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, GL_COMPRESSED_RGBA_S3TC_DXT5_EXT};
2937 CheckFormats("GL_EXT_texture_compression_s3tc", formats, 4);
2940 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsATC) {
2941 const GLenum formats[] = {GL_ATC_RGB_AMD, GL_ATC_RGBA_EXPLICIT_ALPHA_AMD,
2942 GL_ATC_RGBA_INTERPOLATED_ALPHA_AMD};
2943 CheckFormats("GL_AMD_compressed_ATC_texture", formats, 3);
2946 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsPVRTC) {
2947 const GLenum formats[] = {
2948 GL_COMPRESSED_RGB_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGB_PVRTC_2BPPV1_IMG,
2949 GL_COMPRESSED_RGBA_PVRTC_4BPPV1_IMG, GL_COMPRESSED_RGBA_PVRTC_2BPPV1_IMG};
2950 CheckFormats("GL_IMG_texture_compression_pvrtc", formats, 4);
2953 TEST_P(GLES2DecoderCompressedFormatsTest, GetCompressedTextureFormatsETC1) {
2954 const GLenum formats[] = {GL_ETC1_RGB8_OES};
2955 CheckFormats("GL_OES_compressed_ETC1_RGB8_texture", formats, 1);
2958 TEST_P(GLES2DecoderManualInitTest, GetNoCompressedTextureFormats) {
2959 InitState init;
2960 init.bind_generates_resource = true;
2961 InitDecoder(init);
2963 EXPECT_CALL(*gl_, GetError())
2964 .WillOnce(Return(GL_NO_ERROR))
2965 .WillOnce(Return(GL_NO_ERROR))
2966 .WillOnce(Return(GL_NO_ERROR))
2967 .WillOnce(Return(GL_NO_ERROR))
2968 .RetiresOnSaturation();
2970 typedef GetIntegerv::Result Result;
2971 Result* result = static_cast<Result*>(shared_memory_address_);
2972 GetIntegerv cmd;
2973 result->size = 0;
2974 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
2975 cmd.Init(GL_NUM_COMPRESSED_TEXTURE_FORMATS,
2976 shared_memory_id_,
2977 shared_memory_offset_);
2978 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2979 EXPECT_EQ(1, result->GetNumResults());
2980 GLint num_formats = result->GetData()[0];
2981 EXPECT_EQ(0, num_formats);
2982 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2984 result->size = 0;
2985 cmd.Init(
2986 GL_COMPRESSED_TEXTURE_FORMATS, shared_memory_id_, shared_memory_offset_);
2987 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2988 EXPECT_EQ(num_formats, result->GetNumResults());
2990 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2993 // TODO(gman): Complete this test.
2994 // TEST_P(GLES2DecoderTest, CompressedTexImage2DGLError) {
2995 // }
2997 // TODO(gman): CompressedTexImage2D
2999 // TODO(gman): CompressedTexImage2DImmediate
3001 // TODO(gman): CompressedTexSubImage2DImmediate
3003 // TODO(gman): TexImage2D
3005 // TODO(gman): TexImage2DImmediate
3007 // TODO(gman): TexSubImage2DImmediate
3009 } // namespace gles2
3010 } // namespace gpu