Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_framebuffers.cc
blob8349ffaaa93d1a9d6b69b98e72f4582c0a209296
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/service/async_pixel_transfer_delegate_mock.h"
12 #include "gpu/command_buffer/service/async_pixel_transfer_manager.h"
13 #include "gpu/command_buffer/service/async_pixel_transfer_manager_mock.h"
14 #include "gpu/command_buffer/service/cmd_buffer_engine.h"
15 #include "gpu/command_buffer/service/context_group.h"
16 #include "gpu/command_buffer/service/context_state.h"
17 #include "gpu/command_buffer/service/gl_surface_mock.h"
18 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest.h"
20 #include "gpu/command_buffer/service/gpu_switches.h"
21 #include "gpu/command_buffer/service/image_manager.h"
22 #include "gpu/command_buffer/service/mailbox_manager.h"
23 #include "gpu/command_buffer/service/mocks.h"
24 #include "gpu/command_buffer/service/program_manager.h"
25 #include "gpu/command_buffer/service/test_helper.h"
26 #include "testing/gtest/include/gtest/gtest.h"
27 #include "ui/gl/gl_implementation.h"
28 #include "ui/gl/gl_mock.h"
29 #include "ui/gl/gl_surface_stub.h"
31 #if !defined(GL_DEPTH24_STENCIL8)
32 #define GL_DEPTH24_STENCIL8 0x88F0
33 #endif
35 using ::gfx::MockGLInterface;
36 using ::testing::_;
37 using ::testing::DoAll;
38 using ::testing::InSequence;
39 using ::testing::Invoke;
40 using ::testing::MatcherCast;
41 using ::testing::Mock;
42 using ::testing::Pointee;
43 using ::testing::Return;
44 using ::testing::SaveArg;
45 using ::testing::SetArrayArgument;
46 using ::testing::SetArgumentPointee;
47 using ::testing::SetArgPointee;
48 using ::testing::StrEq;
49 using ::testing::StrictMock;
51 namespace gpu {
52 namespace gles2 {
54 using namespace cmds;
56 class GLES2DecoderTestWithExtensionsOnGLES2 : public GLES2DecoderTest {
57 public:
58 GLES2DecoderTestWithExtensionsOnGLES2() {}
60 void SetUp() override {}
61 void Init(const char* extensions) {
62 InitState init;
63 init.extensions = extensions;
64 init.gl_version = "opengl es 2.0";
65 init.has_alpha = true;
66 init.has_depth = true;
67 init.request_alpha = true;
68 init.request_depth = true;
69 InitDecoder(init);
73 TEST_P(GLES2DecoderTest, CheckFramebufferStatusWithNoBoundTarget) {
74 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(_)).Times(0);
75 CheckFramebufferStatus::Result* result =
76 static_cast<CheckFramebufferStatus::Result*>(shared_memory_address_);
77 *result = 0;
78 CheckFramebufferStatus cmd;
79 cmd.Init(GL_FRAMEBUFFER, shared_memory_id_, shared_memory_offset_);
80 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
81 EXPECT_EQ(static_cast<GLenum>(GL_FRAMEBUFFER_COMPLETE), *result);
84 TEST_P(GLES2DecoderWithShaderTest, BindAndDeleteFramebuffer) {
85 SetupTexture();
86 AddExpectationsForSimulatedAttrib0(kNumVertices, 0);
87 SetupExpectationsForApplyingDefaultDirtyState();
88 DoBindFramebuffer(
89 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
90 DoDeleteFramebuffer(client_framebuffer_id_,
91 kServiceFramebufferId,
92 true,
93 GL_FRAMEBUFFER,
95 true,
96 GL_FRAMEBUFFER,
97 0);
98 EXPECT_CALL(*gl_, DrawArrays(GL_TRIANGLES, 0, kNumVertices))
99 .Times(1)
100 .RetiresOnSaturation();
101 DrawArrays cmd;
102 cmd.Init(GL_TRIANGLES, 0, kNumVertices);
103 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
104 EXPECT_EQ(GL_NO_ERROR, GetGLError());
107 TEST_P(GLES2DecoderTest, FramebufferRenderbufferWithNoBoundTarget) {
108 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(_, _, _, _)).Times(0);
109 FramebufferRenderbuffer cmd;
110 cmd.Init(GL_FRAMEBUFFER,
111 GL_COLOR_ATTACHMENT0,
112 GL_RENDERBUFFER,
113 client_renderbuffer_id_);
114 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
115 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
118 TEST_P(GLES2DecoderTest, FramebufferTexture2DWithNoBoundTarget) {
119 EXPECT_CALL(*gl_, FramebufferTexture2DEXT(_, _, _, _, _)).Times(0);
120 FramebufferTexture2D cmd;
121 cmd.Init(GL_FRAMEBUFFER,
122 GL_COLOR_ATTACHMENT0,
123 GL_TEXTURE_2D,
124 client_texture_id_);
125 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
126 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
129 TEST_P(GLES2DecoderTest, GetFramebufferAttachmentParameterivWithNoBoundTarget) {
130 EXPECT_CALL(*gl_, GetError())
131 .WillOnce(Return(GL_NO_ERROR))
132 .WillOnce(Return(GL_NO_ERROR))
133 .RetiresOnSaturation();
134 EXPECT_CALL(*gl_, GetFramebufferAttachmentParameterivEXT(_, _, _, _))
135 .Times(0);
136 GetFramebufferAttachmentParameteriv cmd;
137 cmd.Init(GL_FRAMEBUFFER,
138 GL_COLOR_ATTACHMENT0,
139 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE,
140 shared_memory_id_,
141 shared_memory_offset_);
142 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
143 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
146 TEST_P(GLES2DecoderTest, GetFramebufferAttachmentParameterivWithRenderbuffer) {
147 DoBindFramebuffer(
148 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
149 EXPECT_CALL(*gl_, GetError())
150 .WillOnce(Return(GL_NO_ERROR))
151 .RetiresOnSaturation();
152 EXPECT_CALL(*gl_,
153 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
154 GL_COLOR_ATTACHMENT0,
155 GL_RENDERBUFFER,
156 kServiceRenderbufferId))
157 .Times(1)
158 .RetiresOnSaturation();
159 EXPECT_CALL(*gl_, GetError())
160 .WillOnce(Return(GL_NO_ERROR))
161 .RetiresOnSaturation();
162 EXPECT_CALL(*gl_, GetError())
163 .WillOnce(Return(GL_NO_ERROR))
164 .WillOnce(Return(GL_NO_ERROR))
165 .RetiresOnSaturation();
166 GetFramebufferAttachmentParameteriv::Result* result =
167 static_cast<GetFramebufferAttachmentParameteriv::Result*>(
168 shared_memory_address_);
169 result->size = 0;
170 const GLint* result_value = result->GetData();
171 FramebufferRenderbuffer fbrb_cmd;
172 GetFramebufferAttachmentParameteriv cmd;
173 fbrb_cmd.Init(GL_FRAMEBUFFER,
174 GL_COLOR_ATTACHMENT0,
175 GL_RENDERBUFFER,
176 client_renderbuffer_id_);
177 cmd.Init(GL_FRAMEBUFFER,
178 GL_COLOR_ATTACHMENT0,
179 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
180 shared_memory_id_,
181 shared_memory_offset_);
182 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
183 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
184 EXPECT_EQ(GL_NO_ERROR, GetGLError());
185 EXPECT_EQ(static_cast<GLuint>(*result_value), client_renderbuffer_id_);
188 TEST_P(GLES2DecoderTest, GetFramebufferAttachmentParameterivWithTexture) {
189 DoBindFramebuffer(
190 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
191 EXPECT_CALL(*gl_, GetError())
192 .WillOnce(Return(GL_NO_ERROR))
193 .RetiresOnSaturation();
194 EXPECT_CALL(*gl_,
195 FramebufferTexture2DEXT(GL_FRAMEBUFFER,
196 GL_COLOR_ATTACHMENT0,
197 GL_TEXTURE_2D,
198 kServiceTextureId,
200 .Times(1)
201 .RetiresOnSaturation();
202 EXPECT_CALL(*gl_, GetError())
203 .WillOnce(Return(GL_NO_ERROR))
204 .RetiresOnSaturation();
205 EXPECT_CALL(*gl_, GetError())
206 .WillOnce(Return(GL_NO_ERROR))
207 .WillOnce(Return(GL_NO_ERROR))
208 .RetiresOnSaturation();
209 GetFramebufferAttachmentParameteriv::Result* result =
210 static_cast<GetFramebufferAttachmentParameteriv::Result*>(
211 shared_memory_address_);
212 result->SetNumResults(0);
213 const GLint* result_value = result->GetData();
214 FramebufferTexture2D fbtex_cmd;
215 GetFramebufferAttachmentParameteriv cmd;
216 fbtex_cmd.Init(GL_FRAMEBUFFER,
217 GL_COLOR_ATTACHMENT0,
218 GL_TEXTURE_2D,
219 client_texture_id_);
220 cmd.Init(GL_FRAMEBUFFER,
221 GL_COLOR_ATTACHMENT0,
222 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME,
223 shared_memory_id_,
224 shared_memory_offset_);
225 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd));
226 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
227 EXPECT_EQ(GL_NO_ERROR, GetGLError());
228 EXPECT_EQ(static_cast<GLuint>(*result_value), client_texture_id_);
231 TEST_P(GLES2DecoderWithShaderTest,
232 GetRenderbufferParameterivRebindRenderbuffer) {
233 SetupTexture();
234 DoBindRenderbuffer(
235 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
236 DoRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
238 GetRenderbufferParameteriv cmd;
239 cmd.Init(GL_RENDERBUFFER,
240 GL_RENDERBUFFER_RED_SIZE,
241 shared_memory_id_,
242 shared_memory_offset_);
244 RestoreRenderbufferBindings();
245 EnsureRenderbufferBound(true);
247 EXPECT_CALL(*gl_, GetError())
248 .WillOnce(Return(GL_NO_ERROR))
249 .WillOnce(Return(GL_NO_ERROR))
250 .RetiresOnSaturation();
251 EXPECT_CALL(*gl_,
252 GetRenderbufferParameterivEXT(
253 GL_RENDERBUFFER, GL_RENDERBUFFER_RED_SIZE, _));
254 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
255 EXPECT_EQ(GL_NO_ERROR, GetGLError());
258 TEST_P(GLES2DecoderTest, GetRenderbufferParameterivWithNoBoundTarget) {
259 EXPECT_CALL(*gl_, GetError())
260 .WillOnce(Return(GL_NO_ERROR))
261 .WillOnce(Return(GL_NO_ERROR))
262 .RetiresOnSaturation();
263 EXPECT_CALL(*gl_, GetRenderbufferParameterivEXT(_, _, _)).Times(0);
264 GetRenderbufferParameteriv cmd;
265 cmd.Init(GL_RENDERBUFFER,
266 GL_RENDERBUFFER_WIDTH,
267 shared_memory_id_,
268 shared_memory_offset_);
269 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
270 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
273 TEST_P(GLES2DecoderWithShaderTest, RenderbufferStorageRebindRenderbuffer) {
274 SetupTexture();
275 DoBindRenderbuffer(
276 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
277 RestoreRenderbufferBindings();
278 EnsureRenderbufferBound(true);
279 DoRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
282 TEST_P(GLES2DecoderTest, RenderbufferStorageWithNoBoundTarget) {
283 EXPECT_CALL(*gl_, RenderbufferStorageEXT(_, _, _, _)).Times(0);
284 RenderbufferStorage cmd;
285 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, 3, 4);
286 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
287 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
290 namespace {
292 // A class to emulate glReadPixels
293 class ReadPixelsEmulator {
294 public:
295 // pack_alignment is the alignment you want ReadPixels to use
296 // when copying. The actual data passed in pixels should be contiguous.
297 ReadPixelsEmulator(GLsizei width,
298 GLsizei height,
299 GLint bytes_per_pixel,
300 const void* src_pixels,
301 const void* expected_pixels,
302 GLint pack_alignment)
303 : width_(width),
304 height_(height),
305 pack_alignment_(pack_alignment),
306 bytes_per_pixel_(bytes_per_pixel),
307 src_pixels_(reinterpret_cast<const int8*>(src_pixels)),
308 expected_pixels_(reinterpret_cast<const int8*>(expected_pixels)) {}
310 void ReadPixels(GLint x,
311 GLint y,
312 GLsizei width,
313 GLsizei height,
314 GLenum format,
315 GLenum type,
316 void* pixels) const {
317 DCHECK_GE(x, 0);
318 DCHECK_GE(y, 0);
319 DCHECK_LE(x + width, width_);
320 DCHECK_LE(y + height, height_);
321 for (GLint yy = 0; yy < height; ++yy) {
322 const int8* src = GetPixelAddress(src_pixels_, x, y + yy);
323 const void* dst = ComputePackAlignmentAddress(0, yy, width, pixels);
324 memcpy(const_cast<void*>(dst), src, width * bytes_per_pixel_);
328 bool CompareRowSegment(GLint x,
329 GLint y,
330 GLsizei width,
331 const void* data) const {
332 DCHECK(x + width <= width_ || width == 0);
333 return memcmp(data,
334 GetPixelAddress(expected_pixels_, x, y),
335 width * bytes_per_pixel_) == 0;
338 // Helper to compute address of pixel in pack aligned data.
339 const void* ComputePackAlignmentAddress(GLint x,
340 GLint y,
341 GLsizei width,
342 const void* address) const {
343 GLint unpadded_row_size = ComputeImageDataSize(width, 1);
344 GLint two_rows_size = ComputeImageDataSize(width, 2);
345 GLsizei padded_row_size = two_rows_size - unpadded_row_size;
346 GLint offset = y * padded_row_size + x * bytes_per_pixel_;
347 return static_cast<const int8*>(address) + offset;
350 GLint ComputeImageDataSize(GLint width, GLint height) const {
351 GLint row_size = width * bytes_per_pixel_;
352 if (height > 1) {
353 GLint temp = row_size + pack_alignment_ - 1;
354 GLint padded_row_size = (temp / pack_alignment_) * pack_alignment_;
355 GLint size_of_all_but_last_row = (height - 1) * padded_row_size;
356 return size_of_all_but_last_row + row_size;
357 } else {
358 return height * row_size;
362 private:
363 const int8* GetPixelAddress(const int8* base, GLint x, GLint y) const {
364 return base + (width_ * y + x) * bytes_per_pixel_;
367 GLsizei width_;
368 GLsizei height_;
369 GLint pack_alignment_;
370 GLint bytes_per_pixel_;
371 const int8* src_pixels_;
372 const int8* expected_pixels_;
375 } // anonymous namespace
377 void GLES2DecoderTest::CheckReadPixelsOutOfRange(GLint in_read_x,
378 GLint in_read_y,
379 GLsizei in_read_width,
380 GLsizei in_read_height,
381 bool init) {
382 const GLsizei kWidth = 5;
383 const GLsizei kHeight = 3;
384 const GLint kBytesPerPixel = 4;
385 const GLint kPackAlignment = 4;
386 const GLenum kFormat = GL_RGBA;
387 static const uint8 kSrcPixels[kWidth * kHeight * kBytesPerPixel] = {
388 12, 13, 14, 255, 18, 19, 18, 255, 19, 12, 13, 255, 14, 18, 19, 255,
389 18, 19, 13, 255, 29, 28, 23, 255, 22, 21, 22, 255, 21, 29, 28, 255,
390 23, 22, 21, 255, 22, 21, 28, 255, 31, 34, 39, 255, 37, 32, 37, 255,
391 32, 31, 34, 255, 39, 37, 32, 255, 37, 32, 34, 255
394 ClearSharedMemory();
396 // We need to setup an FBO so we can know the max size that ReadPixels will
397 // access
398 if (init) {
399 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
400 DoTexImage2D(GL_TEXTURE_2D,
402 kFormat,
403 kWidth,
404 kHeight,
406 kFormat,
407 GL_UNSIGNED_BYTE,
408 kSharedMemoryId,
409 kSharedMemoryOffset);
410 DoBindFramebuffer(
411 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
412 DoFramebufferTexture2D(GL_FRAMEBUFFER,
413 GL_COLOR_ATTACHMENT0,
414 GL_TEXTURE_2D,
415 client_texture_id_,
416 kServiceTextureId,
418 GL_NO_ERROR);
419 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
420 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
421 .RetiresOnSaturation();
424 ReadPixelsEmulator emu(
425 kWidth, kHeight, kBytesPerPixel, kSrcPixels, kSrcPixels, kPackAlignment);
426 typedef ReadPixels::Result Result;
427 Result* result = GetSharedMemoryAs<Result*>();
428 uint32 result_shm_id = kSharedMemoryId;
429 uint32 result_shm_offset = kSharedMemoryOffset;
430 uint32 pixels_shm_id = kSharedMemoryId;
431 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result);
432 void* dest = &result[1];
433 EXPECT_CALL(*gl_, GetError())
434 .WillOnce(Return(GL_NO_ERROR))
435 .WillOnce(Return(GL_NO_ERROR))
436 .RetiresOnSaturation();
437 // ReadPixels will be called for valid size only even though the command
438 // is requesting a larger size.
439 GLint read_x = std::max(0, in_read_x);
440 GLint read_y = std::max(0, in_read_y);
441 GLint read_end_x = std::max(0, std::min(kWidth, in_read_x + in_read_width));
442 GLint read_end_y = std::max(0, std::min(kHeight, in_read_y + in_read_height));
443 GLint read_width = read_end_x - read_x;
444 GLint read_height = read_end_y - read_y;
445 if (read_width > 0 && read_height > 0) {
446 for (GLint yy = read_y; yy < read_end_y; ++yy) {
447 EXPECT_CALL(
448 *gl_,
449 ReadPixels(read_x, yy, read_width, 1, kFormat, GL_UNSIGNED_BYTE, _))
450 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels))
451 .RetiresOnSaturation();
454 ReadPixels cmd;
455 cmd.Init(in_read_x,
456 in_read_y,
457 in_read_width,
458 in_read_height,
459 kFormat,
460 GL_UNSIGNED_BYTE,
461 pixels_shm_id,
462 pixels_shm_offset,
463 result_shm_id,
464 result_shm_offset,
465 false);
466 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
468 GLint unpadded_row_size = emu.ComputeImageDataSize(in_read_width, 1);
469 scoped_ptr<int8[]> zero(new int8[unpadded_row_size]);
470 scoped_ptr<int8[]> pack(new int8[kPackAlignment]);
471 memset(zero.get(), 0, unpadded_row_size);
472 memset(pack.get(), kInitialMemoryValue, kPackAlignment);
473 for (GLint yy = 0; yy < in_read_height; ++yy) {
474 const int8* row = static_cast<const int8*>(
475 emu.ComputePackAlignmentAddress(0, yy, in_read_width, dest));
476 GLint y = in_read_y + yy;
477 if (y < 0 || y >= kHeight) {
478 EXPECT_EQ(0, memcmp(zero.get(), row, unpadded_row_size));
479 } else {
480 // check off left.
481 GLint num_left_pixels = std::max(-in_read_x, 0);
482 GLint num_left_bytes = num_left_pixels * kBytesPerPixel;
483 EXPECT_EQ(0, memcmp(zero.get(), row, num_left_bytes));
485 // check off right.
486 GLint num_right_pixels = std::max(in_read_x + in_read_width - kWidth, 0);
487 GLint num_right_bytes = num_right_pixels * kBytesPerPixel;
488 EXPECT_EQ(0,
489 memcmp(zero.get(),
490 row + unpadded_row_size - num_right_bytes,
491 num_right_bytes));
493 // check middle.
494 GLint x = std::max(in_read_x, 0);
495 GLint num_middle_pixels =
496 std::max(in_read_width - num_left_pixels - num_right_pixels, 0);
497 EXPECT_TRUE(
498 emu.CompareRowSegment(x, y, num_middle_pixels, row + num_left_bytes));
501 // check padding
502 if (yy != in_read_height - 1) {
503 GLint temp = unpadded_row_size + kPackAlignment - 1;
504 GLint padded_row_size = (temp / kPackAlignment ) * kPackAlignment;
505 GLint num_padding_bytes = padded_row_size - unpadded_row_size;
506 if (num_padding_bytes) {
507 EXPECT_EQ(0, memcmp(pack.get(),
508 row + unpadded_row_size, num_padding_bytes));
514 TEST_P(GLES2DecoderTest, ReadPixels) {
515 const GLsizei kWidth = 5;
516 const GLsizei kHeight = 3;
517 const GLint kBytesPerPixel = 4;
518 const GLint kPackAlignment = 4;
519 static const uint8 kSrcPixels[kWidth * kHeight * kBytesPerPixel] = {
520 12, 13, 14, 255, 18, 19, 18, 255, 19, 12, 13, 255, 14, 18, 19, 255,
521 18, 19, 13, 255, 29, 28, 23, 255, 22, 21, 22, 255, 21, 29, 28, 255,
522 23, 22, 21, 255, 22, 21, 28, 255, 31, 34, 39, 255, 37, 32, 37, 255,
523 32, 31, 34, 255, 39, 37, 32, 255, 37, 32, 34, 255
526 surface_->SetSize(gfx::Size(INT_MAX, INT_MAX));
528 ReadPixelsEmulator emu(
529 kWidth, kHeight, kBytesPerPixel, kSrcPixels, kSrcPixels, kPackAlignment);
530 typedef ReadPixels::Result Result;
531 Result* result = GetSharedMemoryAs<Result*>();
532 uint32 result_shm_id = kSharedMemoryId;
533 uint32 result_shm_offset = kSharedMemoryOffset;
534 uint32 pixels_shm_id = kSharedMemoryId;
535 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result);
536 void* dest = &result[1];
537 EXPECT_CALL(*gl_, GetError())
538 .WillOnce(Return(GL_NO_ERROR))
539 .WillOnce(Return(GL_NO_ERROR))
540 .RetiresOnSaturation();
541 EXPECT_CALL(*gl_,
542 ReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, _))
543 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels));
544 ReadPixels cmd;
545 cmd.Init(0,
547 kWidth,
548 kHeight,
549 GL_RGBA,
550 GL_UNSIGNED_BYTE,
551 pixels_shm_id,
552 pixels_shm_offset,
553 result_shm_id,
554 result_shm_offset,
555 false);
556 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
557 for (GLint yy = 0; yy < kHeight; ++yy) {
558 EXPECT_TRUE(emu.CompareRowSegment(
559 0, yy, kWidth, emu.ComputePackAlignmentAddress(0, yy, kWidth, dest)));
563 TEST_P(GLES2DecoderRGBBackbufferTest, ReadPixelsNoAlphaBackbuffer) {
564 const GLsizei kWidth = 3;
565 const GLsizei kHeight = 3;
566 const GLint kBytesPerPixel = 4;
567 const GLint kPackAlignment = 4;
568 static const uint8 kExpectedPixels[kWidth * kHeight * kBytesPerPixel] = {
569 12, 13, 14, 255, 19, 18, 19, 255, 13, 14, 18, 255,
570 29, 28, 23, 255, 21, 22, 21, 255, 28, 23, 22, 255,
571 31, 34, 39, 255, 32, 37, 32, 255, 34, 39, 37, 255,
573 static const uint8 kSrcPixels[kWidth * kHeight * kBytesPerPixel] = {
574 12, 13, 14, 18, 19, 18, 19, 12, 13, 14, 18, 19, 29, 28, 23, 22, 21, 22,
575 21, 29, 28, 23, 22, 21, 31, 34, 39, 37, 32, 37, 32, 31, 34, 39, 37, 32,
578 surface_->SetSize(gfx::Size(INT_MAX, INT_MAX));
580 ReadPixelsEmulator emu(kWidth,
581 kHeight,
582 kBytesPerPixel,
583 kSrcPixels,
584 kExpectedPixels,
585 kPackAlignment);
586 typedef ReadPixels::Result Result;
587 Result* result = GetSharedMemoryAs<Result*>();
588 uint32 result_shm_id = kSharedMemoryId;
589 uint32 result_shm_offset = kSharedMemoryOffset;
590 uint32 pixels_shm_id = kSharedMemoryId;
591 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result);
592 void* dest = &result[1];
593 EXPECT_CALL(*gl_, GetError())
594 .WillOnce(Return(GL_NO_ERROR))
595 .WillOnce(Return(GL_NO_ERROR))
596 .RetiresOnSaturation();
597 EXPECT_CALL(*gl_,
598 ReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, _))
599 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels));
600 ReadPixels cmd;
601 cmd.Init(0,
603 kWidth,
604 kHeight,
605 GL_RGBA,
606 GL_UNSIGNED_BYTE,
607 pixels_shm_id,
608 pixels_shm_offset,
609 result_shm_id,
610 result_shm_offset,
611 false);
612 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
613 for (GLint yy = 0; yy < kHeight; ++yy) {
614 EXPECT_TRUE(emu.CompareRowSegment(
615 0, yy, kWidth, emu.ComputePackAlignmentAddress(0, yy, kWidth, dest)));
619 TEST_P(GLES2DecoderTest, ReadPixelsOutOfRange) {
620 static GLint tests[][4] = {
622 -2, -1, 9, 5,
623 }, // out of range on all sides
625 2, 1, 9, 5,
626 }, // out of range on right, bottom
628 -7, -4, 9, 5,
629 }, // out of range on left, top
631 0, -5, 9, 5,
632 }, // completely off top
634 0, 3, 9, 5,
635 }, // completely off bottom
637 -9, 0, 9, 5,
638 }, // completely off left
640 5, 0, 9, 5,
641 }, // completely off right
644 for (size_t tt = 0; tt < arraysize(tests); ++tt) {
645 CheckReadPixelsOutOfRange(
646 tests[tt][0], tests[tt][1], tests[tt][2], tests[tt][3], tt == 0);
650 TEST_P(GLES2DecoderTest, ReadPixelsInvalidArgs) {
651 typedef ReadPixels::Result Result;
652 uint32 result_shm_id = kSharedMemoryId;
653 uint32 result_shm_offset = kSharedMemoryOffset;
654 uint32 pixels_shm_id = kSharedMemoryId;
655 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
656 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0);
657 ReadPixels cmd;
658 cmd.Init(0,
662 GL_RGB,
663 GL_UNSIGNED_BYTE,
664 pixels_shm_id,
665 pixels_shm_offset,
666 result_shm_id,
667 result_shm_offset,
668 false);
669 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
670 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
671 cmd.Init(0,
675 GL_RGB,
676 GL_UNSIGNED_BYTE,
677 pixels_shm_id,
678 pixels_shm_offset,
679 result_shm_id,
680 result_shm_offset,
681 false);
682 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
683 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
684 cmd.Init(0,
688 GL_RGB,
689 GL_INT,
690 pixels_shm_id,
691 pixels_shm_offset,
692 result_shm_id,
693 result_shm_offset,
694 false);
695 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
696 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
697 cmd.Init(0,
701 GL_RGB,
702 GL_UNSIGNED_BYTE,
703 kInvalidSharedMemoryId,
704 pixels_shm_offset,
705 result_shm_id,
706 result_shm_offset,
707 false);
708 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
709 cmd.Init(0,
713 GL_RGB,
714 GL_UNSIGNED_BYTE,
715 pixels_shm_id,
716 kInvalidSharedMemoryOffset,
717 result_shm_id,
718 result_shm_offset,
719 false);
720 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
721 cmd.Init(0,
725 GL_RGB,
726 GL_UNSIGNED_BYTE,
727 pixels_shm_id,
728 pixels_shm_offset,
729 kInvalidSharedMemoryId,
730 result_shm_offset,
731 false);
732 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
733 cmd.Init(0,
737 GL_RGB,
738 GL_UNSIGNED_BYTE,
739 pixels_shm_id,
740 pixels_shm_offset,
741 result_shm_id,
742 kInvalidSharedMemoryOffset,
743 false);
744 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
747 TEST_P(GLES2DecoderManualInitTest, ReadPixelsAsyncError) {
748 InitState init;
749 init.extensions = "GL_ARB_sync";
750 init.gl_version = "opengl es 3.0";
751 init.has_alpha = true;
752 init.request_alpha = true;
753 init.bind_generates_resource = true;
754 InitDecoder(init);
756 typedef ReadPixels::Result Result;
758 const GLsizei kWidth = 4;
759 const GLsizei kHeight = 4;
760 uint32 result_shm_id = kSharedMemoryId;
761 uint32 result_shm_offset = kSharedMemoryOffset;
762 uint32 pixels_shm_id = kSharedMemoryId;
763 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
765 EXPECT_CALL(*gl_, GetError())
766 // first error check must pass to get to the test
767 .WillOnce(Return(GL_NO_ERROR))
768 // second check is after BufferData, simulate fail here
769 .WillOnce(Return(GL_INVALID_OPERATION))
770 // third error check is fall-through call to sync ReadPixels
771 .WillOnce(Return(GL_NO_ERROR))
772 .RetiresOnSaturation();
774 EXPECT_CALL(*gl_,
775 ReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, _))
776 .Times(1);
777 EXPECT_CALL(*gl_, GenBuffersARB(1, _)).Times(1);
778 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _)).Times(1);
779 EXPECT_CALL(*gl_, BindBuffer(GL_PIXEL_PACK_BUFFER_ARB, _)).Times(2);
780 EXPECT_CALL(*gl_,
781 BufferData(GL_PIXEL_PACK_BUFFER_ARB, _, NULL, GL_STREAM_READ))
782 .Times(1);
784 ReadPixels cmd;
785 cmd.Init(0,
787 kWidth,
788 kHeight,
789 GL_RGBA,
790 GL_UNSIGNED_BYTE,
791 pixels_shm_id,
792 pixels_shm_offset,
793 result_shm_id,
794 result_shm_offset,
795 true);
796 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
799 // Check that if a renderbuffer is attached and GL returns
800 // GL_FRAMEBUFFER_COMPLETE that the buffer is cleared and state is restored.
801 TEST_P(GLES2DecoderTest, FramebufferRenderbufferClearColor) {
802 DoBindFramebuffer(
803 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
804 ClearColor color_cmd;
805 ColorMask color_mask_cmd;
806 Enable enable_cmd;
807 FramebufferRenderbuffer cmd;
808 color_cmd.Init(0.1f, 0.2f, 0.3f, 0.4f);
809 color_mask_cmd.Init(0, 1, 0, 1);
810 enable_cmd.Init(GL_SCISSOR_TEST);
811 cmd.Init(GL_FRAMEBUFFER,
812 GL_COLOR_ATTACHMENT0,
813 GL_RENDERBUFFER,
814 client_renderbuffer_id_);
815 InSequence sequence;
816 EXPECT_CALL(*gl_, ClearColor(0.1f, 0.2f, 0.3f, 0.4f))
817 .Times(1)
818 .RetiresOnSaturation();
819 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, true);
820 EXPECT_CALL(*gl_, GetError())
821 .WillOnce(Return(GL_NO_ERROR))
822 .RetiresOnSaturation();
823 EXPECT_CALL(*gl_,
824 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
825 GL_COLOR_ATTACHMENT0,
826 GL_RENDERBUFFER,
827 kServiceRenderbufferId))
828 .Times(1)
829 .RetiresOnSaturation();
830 EXPECT_CALL(*gl_, GetError())
831 .WillOnce(Return(GL_NO_ERROR))
832 .RetiresOnSaturation();
833 EXPECT_EQ(error::kNoError, ExecuteCmd(color_cmd));
834 EXPECT_EQ(error::kNoError, ExecuteCmd(color_mask_cmd));
835 EXPECT_EQ(error::kNoError, ExecuteCmd(enable_cmd));
836 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
839 TEST_P(GLES2DecoderTest, FramebufferRenderbufferClearDepth) {
840 DoBindFramebuffer(
841 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
842 ClearDepthf depth_cmd;
843 DepthMask depth_mask_cmd;
844 FramebufferRenderbuffer cmd;
845 depth_cmd.Init(0.5f);
846 depth_mask_cmd.Init(false);
847 cmd.Init(GL_FRAMEBUFFER,
848 GL_DEPTH_ATTACHMENT,
849 GL_RENDERBUFFER,
850 client_renderbuffer_id_);
851 InSequence sequence;
852 EXPECT_CALL(*gl_, ClearDepth(0.5f)).Times(1).RetiresOnSaturation();
853 EXPECT_CALL(*gl_, GetError())
854 .WillOnce(Return(GL_NO_ERROR))
855 .RetiresOnSaturation();
856 EXPECT_CALL(*gl_,
857 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
858 GL_DEPTH_ATTACHMENT,
859 GL_RENDERBUFFER,
860 kServiceRenderbufferId))
861 .Times(1)
862 .RetiresOnSaturation();
863 EXPECT_CALL(*gl_, GetError())
864 .WillOnce(Return(GL_NO_ERROR))
865 .RetiresOnSaturation();
866 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_cmd));
867 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_mask_cmd));
868 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
871 TEST_P(GLES2DecoderTest, FramebufferRenderbufferClearStencil) {
872 DoBindFramebuffer(
873 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
874 ClearStencil stencil_cmd;
875 StencilMaskSeparate stencil_mask_separate_cmd;
876 FramebufferRenderbuffer cmd;
877 stencil_cmd.Init(123);
878 stencil_mask_separate_cmd.Init(GL_BACK, 0x1234u);
879 cmd.Init(GL_FRAMEBUFFER,
880 GL_STENCIL_ATTACHMENT,
881 GL_RENDERBUFFER,
882 client_renderbuffer_id_);
883 InSequence sequence;
884 EXPECT_CALL(*gl_, ClearStencil(123)).Times(1).RetiresOnSaturation();
885 EXPECT_CALL(*gl_, GetError())
886 .WillOnce(Return(GL_NO_ERROR))
887 .RetiresOnSaturation();
888 EXPECT_CALL(*gl_,
889 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
890 GL_STENCIL_ATTACHMENT,
891 GL_RENDERBUFFER,
892 kServiceRenderbufferId))
893 .Times(1)
894 .RetiresOnSaturation();
895 EXPECT_CALL(*gl_, GetError())
896 .WillOnce(Return(GL_NO_ERROR))
897 .RetiresOnSaturation();
898 EXPECT_EQ(error::kNoError, ExecuteCmd(stencil_cmd));
899 EXPECT_EQ(error::kNoError, ExecuteCmd(stencil_mask_separate_cmd));
900 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
903 #if 0 // Turn this test on once we allow GL_DEPTH_STENCIL_ATTACHMENT
904 TEST_P(GLES2DecoderTest, FramebufferRenderbufferClearDepthStencil) {
905 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
906 kServiceFramebufferId);
907 ClearDepthf depth_cmd;
908 ClearStencil stencil_cmd;
909 FramebufferRenderbuffer cmd;
910 depth_cmd.Init(0.5f);
911 stencil_cmd.Init(123);
912 cmd.Init(
913 GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
914 client_renderbuffer_id_);
915 InSequence sequence;
916 EXPECT_CALL(*gl_, ClearDepth(0.5f))
917 .Times(1)
918 .RetiresOnSaturation();
919 EXPECT_CALL(*gl_, ClearStencil(123))
920 .Times(1)
921 .RetiresOnSaturation();
922 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
923 GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
924 kServiceRenderbufferId))
925 .Times(1)
926 .RetiresOnSaturation();
927 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_cmd));
928 EXPECT_EQ(error::kNoError, ExecuteCmd(stencil_cmd));
929 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
931 #endif
933 TEST_P(GLES2DecoderManualInitTest, ActualAlphaMatchesRequestedAlpha) {
934 InitState init;
935 init.has_alpha = true;
936 init.request_alpha = true;
937 init.bind_generates_resource = true;
938 InitDecoder(init);
940 EXPECT_CALL(*gl_, GetError())
941 .WillOnce(Return(GL_NO_ERROR))
942 .WillOnce(Return(GL_NO_ERROR))
943 .RetiresOnSaturation();
944 typedef GetIntegerv::Result Result;
945 Result* result = static_cast<Result*>(shared_memory_address_);
946 result->size = 0;
947 GetIntegerv cmd2;
948 cmd2.Init(GL_ALPHA_BITS, shared_memory_id_, shared_memory_offset_);
949 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
950 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_ALPHA_BITS),
951 result->GetNumResults());
952 EXPECT_EQ(GL_NO_ERROR, GetGLError());
953 EXPECT_EQ(8, result->GetData()[0]);
956 TEST_P(GLES2DecoderManualInitTest, ActualAlphaDoesNotMatchRequestedAlpha) {
957 InitState init;
958 init.has_alpha = true;
959 init.bind_generates_resource = true;
960 InitDecoder(init);
962 EXPECT_CALL(*gl_, GetError())
963 .WillOnce(Return(GL_NO_ERROR))
964 .WillOnce(Return(GL_NO_ERROR))
965 .RetiresOnSaturation();
966 typedef GetIntegerv::Result Result;
967 Result* result = static_cast<Result*>(shared_memory_address_);
968 result->size = 0;
969 GetIntegerv cmd2;
970 cmd2.Init(GL_ALPHA_BITS, shared_memory_id_, shared_memory_offset_);
971 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
972 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_ALPHA_BITS),
973 result->GetNumResults());
974 EXPECT_EQ(GL_NO_ERROR, GetGLError());
975 EXPECT_EQ(0, result->GetData()[0]);
978 TEST_P(GLES2DecoderManualInitTest, ActualDepthMatchesRequestedDepth) {
979 InitState init;
980 init.has_depth = true;
981 init.request_depth = true;
982 init.bind_generates_resource = true;
983 InitDecoder(init);
985 EXPECT_CALL(*gl_, GetError())
986 .WillOnce(Return(GL_NO_ERROR))
987 .WillOnce(Return(GL_NO_ERROR))
988 .RetiresOnSaturation();
989 typedef GetIntegerv::Result Result;
990 Result* result = static_cast<Result*>(shared_memory_address_);
991 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
992 .WillOnce(SetArgumentPointee<1>(24))
993 .RetiresOnSaturation();
994 result->size = 0;
995 GetIntegerv cmd2;
996 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
997 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
998 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
999 result->GetNumResults());
1000 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1001 EXPECT_EQ(24, result->GetData()[0]);
1004 TEST_P(GLES2DecoderManualInitTest, ActualDepthDoesNotMatchRequestedDepth) {
1005 InitState init;
1006 init.has_depth = true;
1007 init.bind_generates_resource = true;
1008 InitDecoder(init);
1010 EXPECT_CALL(*gl_, GetError())
1011 .WillOnce(Return(GL_NO_ERROR))
1012 .WillOnce(Return(GL_NO_ERROR))
1013 .RetiresOnSaturation();
1014 typedef GetIntegerv::Result Result;
1015 Result* result = static_cast<Result*>(shared_memory_address_);
1016 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
1017 .WillOnce(SetArgumentPointee<1>(24))
1018 .RetiresOnSaturation();
1019 result->size = 0;
1020 GetIntegerv cmd2;
1021 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
1022 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1023 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
1024 result->GetNumResults());
1025 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1026 EXPECT_EQ(0, result->GetData()[0]);
1029 TEST_P(GLES2DecoderManualInitTest, ActualStencilMatchesRequestedStencil) {
1030 InitState init;
1031 init.has_stencil = true;
1032 init.request_stencil = true;
1033 init.bind_generates_resource = true;
1034 InitDecoder(init);
1036 EXPECT_CALL(*gl_, GetError())
1037 .WillOnce(Return(GL_NO_ERROR))
1038 .WillOnce(Return(GL_NO_ERROR))
1039 .RetiresOnSaturation();
1040 typedef GetIntegerv::Result Result;
1041 Result* result = static_cast<Result*>(shared_memory_address_);
1042 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
1043 .WillOnce(SetArgumentPointee<1>(8))
1044 .RetiresOnSaturation();
1045 result->size = 0;
1046 GetIntegerv cmd2;
1047 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
1048 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1049 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
1050 result->GetNumResults());
1051 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1052 EXPECT_EQ(8, result->GetData()[0]);
1055 TEST_P(GLES2DecoderManualInitTest, ActualStencilDoesNotMatchRequestedStencil) {
1056 InitState init;
1057 init.has_stencil = true;
1058 init.bind_generates_resource = true;
1059 InitDecoder(init);
1061 EXPECT_CALL(*gl_, GetError())
1062 .WillOnce(Return(GL_NO_ERROR))
1063 .WillOnce(Return(GL_NO_ERROR))
1064 .RetiresOnSaturation();
1065 typedef GetIntegerv::Result Result;
1066 Result* result = static_cast<Result*>(shared_memory_address_);
1067 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
1068 .WillOnce(SetArgumentPointee<1>(8))
1069 .RetiresOnSaturation();
1070 result->size = 0;
1071 GetIntegerv cmd2;
1072 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
1073 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1074 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
1075 result->GetNumResults());
1076 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1077 EXPECT_EQ(0, result->GetData()[0]);
1080 TEST_P(GLES2DecoderManualInitTest, PackedDepthStencilReportsCorrectValues) {
1081 InitState init;
1082 init.extensions = "GL_OES_packed_depth_stencil";
1083 init.gl_version = "opengl es 2.0";
1084 init.has_depth = true;
1085 init.has_stencil = true;
1086 init.request_depth = true;
1087 init.request_stencil = true;
1088 init.bind_generates_resource = true;
1089 InitDecoder(init);
1091 EXPECT_CALL(*gl_, GetError())
1092 .WillOnce(Return(GL_NO_ERROR))
1093 .WillOnce(Return(GL_NO_ERROR))
1094 .WillOnce(Return(GL_NO_ERROR))
1095 .WillOnce(Return(GL_NO_ERROR))
1096 .RetiresOnSaturation();
1097 typedef GetIntegerv::Result Result;
1098 Result* result = static_cast<Result*>(shared_memory_address_);
1099 result->size = 0;
1100 GetIntegerv cmd2;
1101 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
1102 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
1103 .WillOnce(SetArgumentPointee<1>(8))
1104 .RetiresOnSaturation();
1105 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1106 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
1107 result->GetNumResults());
1108 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1109 EXPECT_EQ(8, result->GetData()[0]);
1110 result->size = 0;
1111 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
1112 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
1113 .WillOnce(SetArgumentPointee<1>(24))
1114 .RetiresOnSaturation();
1115 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1116 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
1117 result->GetNumResults());
1118 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1119 EXPECT_EQ(24, result->GetData()[0]);
1122 TEST_P(GLES2DecoderManualInitTest, PackedDepthStencilNoRequestedStencil) {
1123 InitState init;
1124 init.extensions = "GL_OES_packed_depth_stencil";
1125 init.gl_version = "opengl es 2.0";
1126 init.has_depth = true;
1127 init.has_stencil = true;
1128 init.request_depth = true;
1129 init.bind_generates_resource = true;
1130 InitDecoder(init);
1132 EXPECT_CALL(*gl_, GetError())
1133 .WillOnce(Return(GL_NO_ERROR))
1134 .WillOnce(Return(GL_NO_ERROR))
1135 .WillOnce(Return(GL_NO_ERROR))
1136 .WillOnce(Return(GL_NO_ERROR))
1137 .RetiresOnSaturation();
1138 typedef GetIntegerv::Result Result;
1139 Result* result = static_cast<Result*>(shared_memory_address_);
1140 result->size = 0;
1141 GetIntegerv cmd2;
1142 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
1143 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
1144 .WillOnce(SetArgumentPointee<1>(8))
1145 .RetiresOnSaturation();
1146 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1147 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
1148 result->GetNumResults());
1149 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1150 EXPECT_EQ(0, result->GetData()[0]);
1151 result->size = 0;
1152 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
1153 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
1154 .WillOnce(SetArgumentPointee<1>(24))
1155 .RetiresOnSaturation();
1156 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1157 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
1158 result->GetNumResults());
1159 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1160 EXPECT_EQ(24, result->GetData()[0]);
1163 TEST_P(GLES2DecoderManualInitTest, PackedDepthStencilRenderbufferDepth) {
1164 InitState init;
1165 init.extensions = "GL_OES_packed_depth_stencil";
1166 init.gl_version = "opengl es 2.0";
1167 init.bind_generates_resource = true;
1168 InitDecoder(init);
1169 DoBindRenderbuffer(
1170 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1171 DoBindFramebuffer(
1172 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1174 EnsureRenderbufferBound(false);
1175 EXPECT_CALL(*gl_, GetError())
1176 .WillOnce(Return(GL_NO_ERROR)) // for RenderbufferStoage
1177 .WillOnce(Return(GL_NO_ERROR))
1178 .WillOnce(Return(GL_NO_ERROR)) // for FramebufferRenderbuffer
1179 .WillOnce(Return(GL_NO_ERROR))
1180 .WillOnce(Return(GL_NO_ERROR)) // for GetIntegerv
1181 .WillOnce(Return(GL_NO_ERROR))
1182 .WillOnce(Return(GL_NO_ERROR)) // for GetIntegerv
1183 .WillOnce(Return(GL_NO_ERROR))
1184 .RetiresOnSaturation();
1186 EXPECT_CALL(
1187 *gl_,
1188 RenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 100, 50))
1189 .Times(1)
1190 .RetiresOnSaturation();
1191 RenderbufferStorage cmd;
1192 cmd.Init(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 100, 50);
1193 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1194 EXPECT_CALL(*gl_,
1195 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
1196 GL_DEPTH_ATTACHMENT,
1197 GL_RENDERBUFFER,
1198 kServiceRenderbufferId))
1199 .Times(1)
1200 .RetiresOnSaturation();
1201 FramebufferRenderbuffer fbrb_cmd;
1202 fbrb_cmd.Init(GL_FRAMEBUFFER,
1203 GL_DEPTH_ATTACHMENT,
1204 GL_RENDERBUFFER,
1205 client_renderbuffer_id_);
1206 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
1208 typedef GetIntegerv::Result Result;
1209 Result* result = static_cast<Result*>(shared_memory_address_);
1210 result->size = 0;
1211 GetIntegerv cmd2;
1212 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
1213 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
1214 .WillOnce(SetArgumentPointee<1>(8))
1215 .RetiresOnSaturation();
1216 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1217 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
1218 result->GetNumResults());
1219 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1220 EXPECT_EQ(0, result->GetData()[0]);
1221 result->size = 0;
1222 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
1223 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
1224 .WillOnce(SetArgumentPointee<1>(24))
1225 .RetiresOnSaturation();
1226 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1227 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
1228 result->GetNumResults());
1229 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1230 EXPECT_EQ(24, result->GetData()[0]);
1233 TEST_P(GLES2DecoderManualInitTest, PackedDepthStencilRenderbufferStencil) {
1234 InitState init;
1235 init.extensions = "GL_OES_packed_depth_stencil";
1236 init.gl_version = "opengl es 2.0";
1237 init.bind_generates_resource = true;
1238 InitDecoder(init);
1239 DoBindRenderbuffer(
1240 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1241 DoBindFramebuffer(
1242 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1244 EnsureRenderbufferBound(false);
1245 EXPECT_CALL(*gl_, GetError())
1246 .WillOnce(Return(GL_NO_ERROR)) // for RenderbufferStoage
1247 .WillOnce(Return(GL_NO_ERROR))
1248 .WillOnce(Return(GL_NO_ERROR)) // for FramebufferRenderbuffer
1249 .WillOnce(Return(GL_NO_ERROR))
1250 .WillOnce(Return(GL_NO_ERROR)) // for GetIntegerv
1251 .WillOnce(Return(GL_NO_ERROR))
1252 .WillOnce(Return(GL_NO_ERROR)) // for GetIntegerv
1253 .WillOnce(Return(GL_NO_ERROR))
1254 .RetiresOnSaturation();
1256 EXPECT_CALL(
1257 *gl_,
1258 RenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 100, 50))
1259 .Times(1)
1260 .RetiresOnSaturation();
1261 RenderbufferStorage cmd;
1262 cmd.Init(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 100, 50);
1263 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1264 EXPECT_CALL(*gl_,
1265 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
1266 GL_STENCIL_ATTACHMENT,
1267 GL_RENDERBUFFER,
1268 kServiceRenderbufferId))
1269 .Times(1)
1270 .RetiresOnSaturation();
1271 FramebufferRenderbuffer fbrb_cmd;
1272 fbrb_cmd.Init(GL_FRAMEBUFFER,
1273 GL_STENCIL_ATTACHMENT,
1274 GL_RENDERBUFFER,
1275 client_renderbuffer_id_);
1276 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
1278 typedef GetIntegerv::Result Result;
1279 Result* result = static_cast<Result*>(shared_memory_address_);
1280 result->size = 0;
1281 GetIntegerv cmd2;
1282 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
1283 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
1284 .WillOnce(SetArgumentPointee<1>(8))
1285 .RetiresOnSaturation();
1286 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1287 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
1288 result->GetNumResults());
1289 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1290 EXPECT_EQ(8, result->GetData()[0]);
1291 result->size = 0;
1292 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
1293 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
1294 .WillOnce(SetArgumentPointee<1>(24))
1295 .RetiresOnSaturation();
1296 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1297 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
1298 result->GetNumResults());
1299 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1300 EXPECT_EQ(0, result->GetData()[0]);
1303 TEST_P(GLES2DecoderTest, FramebufferRenderbufferGLError) {
1304 DoBindFramebuffer(
1305 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1306 EXPECT_CALL(*gl_, GetError())
1307 .WillOnce(Return(GL_NO_ERROR))
1308 .WillOnce(Return(GL_OUT_OF_MEMORY))
1309 .RetiresOnSaturation();
1310 EXPECT_CALL(*gl_,
1311 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
1312 GL_COLOR_ATTACHMENT0,
1313 GL_RENDERBUFFER,
1314 kServiceRenderbufferId))
1315 .Times(1)
1316 .RetiresOnSaturation();
1317 FramebufferRenderbuffer cmd;
1318 cmd.Init(GL_FRAMEBUFFER,
1319 GL_COLOR_ATTACHMENT0,
1320 GL_RENDERBUFFER,
1321 client_renderbuffer_id_);
1322 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1323 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
1326 TEST_P(GLES2DecoderTest, FramebufferTexture2DGLError) {
1327 const GLsizei kWidth = 5;
1328 const GLsizei kHeight = 3;
1329 const GLenum kFormat = GL_RGB;
1330 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1331 DoTexImage2D(GL_TEXTURE_2D,
1333 kFormat,
1334 kWidth,
1335 kHeight,
1337 kFormat,
1338 GL_UNSIGNED_BYTE,
1341 DoBindFramebuffer(
1342 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1343 EXPECT_CALL(*gl_, GetError())
1344 .WillOnce(Return(GL_NO_ERROR))
1345 .WillOnce(Return(GL_OUT_OF_MEMORY))
1346 .RetiresOnSaturation();
1347 EXPECT_CALL(*gl_,
1348 FramebufferTexture2DEXT(GL_FRAMEBUFFER,
1349 GL_COLOR_ATTACHMENT0,
1350 GL_TEXTURE_2D,
1351 kServiceTextureId,
1353 .Times(1)
1354 .RetiresOnSaturation();
1355 FramebufferTexture2D fbtex_cmd;
1356 fbtex_cmd.Init(GL_FRAMEBUFFER,
1357 GL_COLOR_ATTACHMENT0,
1358 GL_TEXTURE_2D,
1359 client_texture_id_);
1360 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd));
1361 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
1364 TEST_P(GLES2DecoderTest, RenderbufferStorageGLError) {
1365 DoBindRenderbuffer(
1366 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1367 EnsureRenderbufferBound(false);
1368 EXPECT_CALL(*gl_, GetError())
1369 .WillOnce(Return(GL_NO_ERROR))
1370 .WillOnce(Return(GL_OUT_OF_MEMORY))
1371 .RetiresOnSaturation();
1372 EXPECT_CALL(*gl_, RenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA, 100, 50))
1373 .Times(1)
1374 .RetiresOnSaturation();
1375 RenderbufferStorage cmd;
1376 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, 100, 50);
1377 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1378 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
1381 TEST_P(GLES2DecoderTest, RenderbufferStorageBadArgs) {
1382 DoBindRenderbuffer(
1383 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1384 EXPECT_CALL(*gl_, RenderbufferStorageEXT(_, _, _, _))
1385 .Times(0)
1386 .RetiresOnSaturation();
1387 RenderbufferStorage cmd;
1388 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, TestHelper::kMaxRenderbufferSize + 1, 1);
1389 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1390 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1391 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, 1, TestHelper::kMaxRenderbufferSize + 1);
1392 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1393 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1396 TEST_P(GLES2DecoderManualInitTest,
1397 RenderbufferStorageMultisampleCHROMIUMGLError) {
1398 InitState init;
1399 init.extensions = "GL_EXT_framebuffer_multisample";
1400 init.bind_generates_resource = true;
1401 InitDecoder(init);
1402 DoBindRenderbuffer(
1403 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1404 EnsureRenderbufferBound(false);
1405 EXPECT_CALL(*gl_, GetError())
1406 .WillOnce(Return(GL_NO_ERROR))
1407 .WillOnce(Return(GL_OUT_OF_MEMORY))
1408 .RetiresOnSaturation();
1409 EXPECT_CALL(
1410 *gl_,
1411 RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, 1, GL_RGBA, 100, 50))
1412 .Times(1)
1413 .RetiresOnSaturation();
1414 RenderbufferStorageMultisampleCHROMIUM cmd;
1415 cmd.Init(GL_RENDERBUFFER, 1, GL_RGBA4, 100, 50);
1416 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1417 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
1420 TEST_P(GLES2DecoderManualInitTest,
1421 RenderbufferStorageMultisampleCHROMIUMBadArgs) {
1422 InitState init;
1423 init.extensions = "GL_EXT_framebuffer_multisample";
1424 init.bind_generates_resource = true;
1425 InitDecoder(init);
1426 DoBindRenderbuffer(
1427 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1428 EXPECT_CALL(*gl_, RenderbufferStorageMultisampleEXT(_, _, _, _, _))
1429 .Times(0)
1430 .RetiresOnSaturation();
1431 RenderbufferStorageMultisampleCHROMIUM cmd;
1432 cmd.Init(GL_RENDERBUFFER,
1433 TestHelper::kMaxSamples + 1,
1434 GL_RGBA4,
1435 TestHelper::kMaxRenderbufferSize,
1437 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1438 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1439 cmd.Init(GL_RENDERBUFFER,
1440 TestHelper::kMaxSamples,
1441 GL_RGBA4,
1442 TestHelper::kMaxRenderbufferSize + 1,
1444 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1445 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1446 cmd.Init(GL_RENDERBUFFER,
1447 TestHelper::kMaxSamples,
1448 GL_RGBA4,
1450 TestHelper::kMaxRenderbufferSize + 1);
1451 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1452 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1455 TEST_P(GLES2DecoderManualInitTest, RenderbufferStorageMultisampleCHROMIUM) {
1456 InitState init;
1457 init.extensions = "GL_EXT_framebuffer_multisample";
1458 InitDecoder(init);
1459 DoBindRenderbuffer(
1460 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1461 InSequence sequence;
1462 EnsureRenderbufferBound(false);
1463 DoRenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER,
1464 TestHelper::kMaxSamples,
1465 GL_RGBA4,
1466 GL_RGBA,
1467 TestHelper::kMaxRenderbufferSize,
1471 TEST_P(GLES2DecoderManualInitTest,
1472 RenderbufferStorageMultisampleCHROMIUMRebindRenderbuffer) {
1473 InitState init;
1474 init.extensions = "GL_EXT_framebuffer_multisample";
1475 InitDecoder(init);
1476 DoBindRenderbuffer(
1477 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1478 RestoreRenderbufferBindings();
1479 InSequence sequence;
1480 EnsureRenderbufferBound(true);
1481 DoRenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER,
1482 TestHelper::kMaxSamples,
1483 GL_RGBA4,
1484 GL_RGBA,
1485 TestHelper::kMaxRenderbufferSize,
1489 TEST_P(GLES2DecoderManualInitTest,
1490 RenderbufferStorageMultisampleEXTNotSupported) {
1491 InitState init;
1492 init.extensions = "GL_EXT_framebuffer_multisample";
1493 init.bind_generates_resource = true;
1494 InitDecoder(init);
1495 DoBindRenderbuffer(
1496 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1497 InSequence sequence;
1498 // GL_EXT_framebuffer_multisample uses RenderbufferStorageMultisampleCHROMIUM.
1499 RenderbufferStorageMultisampleEXT cmd;
1500 cmd.Init(GL_RENDERBUFFER,
1501 TestHelper::kMaxSamples,
1502 GL_RGBA4,
1503 TestHelper::kMaxRenderbufferSize,
1505 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1506 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1509 class GLES2DecoderMultisampledRenderToTextureTest
1510 : public GLES2DecoderTestWithExtensionsOnGLES2 {
1511 public:
1512 void TestNotCompatibleWithRenderbufferStorageMultisampleCHROMIUM() {
1513 DoBindRenderbuffer(
1514 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1515 RenderbufferStorageMultisampleCHROMIUM cmd;
1516 cmd.Init(GL_RENDERBUFFER,
1517 TestHelper::kMaxSamples,
1518 GL_RGBA4,
1519 TestHelper::kMaxRenderbufferSize,
1521 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1522 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1525 void TestRenderbufferStorageMultisampleEXT(const char* extension,
1526 bool rb_rebind) {
1527 DoBindRenderbuffer(
1528 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1529 InSequence sequence;
1530 if (rb_rebind) {
1531 RestoreRenderbufferBindings();
1532 EnsureRenderbufferBound(true);
1533 } else {
1534 EnsureRenderbufferBound(false);
1537 EXPECT_CALL(*gl_, GetError())
1538 .WillOnce(Return(GL_NO_ERROR))
1539 .RetiresOnSaturation();
1540 if (strstr(extension, "GL_IMG_multisampled_render_to_texture")) {
1541 EXPECT_CALL(
1542 *gl_,
1543 RenderbufferStorageMultisampleIMG(GL_RENDERBUFFER,
1544 TestHelper::kMaxSamples,
1545 GL_RGBA4,
1546 TestHelper::kMaxRenderbufferSize,
1548 .Times(1)
1549 .RetiresOnSaturation();
1550 } else {
1551 EXPECT_CALL(
1552 *gl_,
1553 RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER,
1554 TestHelper::kMaxSamples,
1555 GL_RGBA4,
1556 TestHelper::kMaxRenderbufferSize,
1558 .Times(1)
1559 .RetiresOnSaturation();
1561 EXPECT_CALL(*gl_, GetError())
1562 .WillOnce(Return(GL_NO_ERROR))
1563 .RetiresOnSaturation();
1564 RenderbufferStorageMultisampleEXT cmd;
1565 cmd.Init(GL_RENDERBUFFER,
1566 TestHelper::kMaxSamples,
1567 GL_RGBA4,
1568 TestHelper::kMaxRenderbufferSize,
1570 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1571 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1575 INSTANTIATE_TEST_CASE_P(Service,
1576 GLES2DecoderMultisampledRenderToTextureTest,
1577 ::testing::Bool());
1579 TEST_P(GLES2DecoderMultisampledRenderToTextureTest,
1580 NotCompatibleWithRenderbufferStorageMultisampleCHROMIUM_EXT) {
1581 Init("GL_EXT_multisampled_render_to_texture");
1582 TestNotCompatibleWithRenderbufferStorageMultisampleCHROMIUM();
1585 TEST_P(GLES2DecoderMultisampledRenderToTextureTest,
1586 NotCompatibleWithRenderbufferStorageMultisampleCHROMIUM_IMG) {
1587 Init("GL_IMG_multisampled_render_to_texture");
1588 TestNotCompatibleWithRenderbufferStorageMultisampleCHROMIUM();
1591 TEST_P(GLES2DecoderMultisampledRenderToTextureTest,
1592 RenderbufferStorageMultisampleEXT_EXT) {
1593 Init("GL_EXT_multisampled_render_to_texture");
1594 TestRenderbufferStorageMultisampleEXT("GL_EXT_multisampled_render_to_texture",
1595 false);
1598 TEST_P(GLES2DecoderMultisampledRenderToTextureTest,
1599 RenderbufferStorageMultisampleEXT_IMG) {
1600 Init("GL_IMG_multisampled_render_to_texture");
1601 TestRenderbufferStorageMultisampleEXT("GL_IMG_multisampled_render_to_texture",
1602 false);
1605 TEST_P(GLES2DecoderMultisampledRenderToTextureTest,
1606 RenderbufferStorageMultisampleEXT_EXT_RebindRenderbuffer) {
1607 Init("GL_EXT_multisampled_render_to_texture");
1608 TestRenderbufferStorageMultisampleEXT("GL_EXT_multisampled_render_to_texture",
1609 true);
1612 TEST_P(GLES2DecoderMultisampledRenderToTextureTest,
1613 RenderbufferStorageMultisampleEXT_IMG_RebindRenderbuffer) {
1614 Init("GL_IMG_multisampled_render_to_texture");
1615 TestRenderbufferStorageMultisampleEXT("GL_IMG_multisampled_render_to_texture",
1616 true);
1619 TEST_P(GLES2DecoderTest, ReadPixelsGLError) {
1620 GLenum kFormat = GL_RGBA;
1621 GLint x = 0;
1622 GLint y = 0;
1623 GLsizei width = 2;
1624 GLsizei height = 4;
1625 typedef ReadPixels::Result Result;
1626 uint32 result_shm_id = kSharedMemoryId;
1627 uint32 result_shm_offset = kSharedMemoryOffset;
1628 uint32 pixels_shm_id = kSharedMemoryId;
1629 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
1630 EXPECT_CALL(*gl_, GetError())
1631 .WillOnce(Return(GL_NO_ERROR))
1632 .WillOnce(Return(GL_OUT_OF_MEMORY))
1633 .RetiresOnSaturation();
1634 EXPECT_CALL(*gl_,
1635 ReadPixels(x, y, width, height, kFormat, GL_UNSIGNED_BYTE, _))
1636 .Times(1)
1637 .RetiresOnSaturation();
1638 ReadPixels cmd;
1639 cmd.Init(x,
1641 width,
1642 height,
1643 kFormat,
1644 GL_UNSIGNED_BYTE,
1645 pixels_shm_id,
1646 pixels_shm_offset,
1647 result_shm_id,
1648 result_shm_offset,
1649 false);
1650 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1651 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
1654 TEST_P(GLES2DecoderWithShaderTest, UnClearedAttachmentsGetClearedOnClear) {
1655 const GLuint kFBOClientTextureId = 4100;
1656 const GLuint kFBOServiceTextureId = 4101;
1658 // Register a texture id.
1659 EXPECT_CALL(*gl_, GenTextures(_, _))
1660 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1661 .RetiresOnSaturation();
1662 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1664 // Setup "render to" texture.
1665 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1666 DoTexImage2D(
1667 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1668 DoBindFramebuffer(
1669 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1670 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1671 GL_COLOR_ATTACHMENT0,
1672 GL_TEXTURE_2D,
1673 kFBOClientTextureId,
1674 kFBOServiceTextureId,
1676 GL_NO_ERROR);
1677 // Set scissor rect and enable GL_SCISSOR_TEST to make sure we re-enable it
1678 // and restore the rect again after the clear.
1679 DoEnableDisable(GL_SCISSOR_TEST, true);
1680 DoScissor(0, 0, 64, 64);
1682 // Setup "render from" texture.
1683 SetupTexture();
1685 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
1686 GL_COLOR_BUFFER_BIT, // clear bits
1687 0, 0, 0,
1688 0, // color
1689 0, // stencil
1690 1.0f, // depth
1691 true, // scissor test
1692 0, 0, 64, 64);
1693 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1694 false, // Framebuffer has depth
1695 false, // Framebuffer has stencil
1696 0x1111, // color bits
1697 false, // depth mask
1698 false, // depth enabled
1699 0, // front stencil mask
1700 0, // back stencil mask
1701 false); // stencil enabled
1703 EXPECT_CALL(*gl_, Clear(GL_COLOR_BUFFER_BIT)).Times(1).RetiresOnSaturation();
1705 Clear cmd;
1706 cmd.Init(GL_COLOR_BUFFER_BIT);
1707 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1708 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1711 TEST_P(GLES2DecoderWithShaderTest, UnClearedAttachmentsGetClearedOnReadPixels) {
1712 const GLuint kFBOClientTextureId = 4100;
1713 const GLuint kFBOServiceTextureId = 4101;
1715 // Register a texture id.
1716 EXPECT_CALL(*gl_, GenTextures(_, _))
1717 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1718 .RetiresOnSaturation();
1719 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1721 // Setup "render to" texture.
1722 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1723 DoTexImage2D(
1724 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1725 DoBindFramebuffer(
1726 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1727 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1728 GL_COLOR_ATTACHMENT0,
1729 GL_TEXTURE_2D,
1730 kFBOClientTextureId,
1731 kFBOServiceTextureId,
1733 GL_NO_ERROR);
1734 DoEnableDisable(GL_SCISSOR_TEST, false);
1735 DoScissor(0, 0, 1, 1);
1737 // Setup "render from" texture.
1738 SetupTexture();
1740 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
1741 GL_COLOR_BUFFER_BIT, // clear bits
1742 0, 0, 0,
1743 0, // color
1744 0, // stencil
1745 1.0f, // depth
1746 false, // scissor test
1747 0, 0, 1, 1);
1749 EXPECT_CALL(*gl_, GetError())
1750 .WillOnce(Return(GL_NO_ERROR))
1751 .WillOnce(Return(GL_NO_ERROR))
1752 .RetiresOnSaturation();
1753 EXPECT_CALL(*gl_, ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, _))
1754 .Times(1)
1755 .RetiresOnSaturation();
1756 typedef ReadPixels::Result Result;
1757 uint32 result_shm_id = kSharedMemoryId;
1758 uint32 result_shm_offset = kSharedMemoryOffset;
1759 uint32 pixels_shm_id = kSharedMemoryId;
1760 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
1761 ReadPixels cmd;
1762 cmd.Init(0,
1766 GL_RGBA,
1767 GL_UNSIGNED_BYTE,
1768 pixels_shm_id,
1769 pixels_shm_offset,
1770 result_shm_id,
1771 result_shm_offset,
1772 false);
1773 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1774 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1777 TEST_P(GLES2DecoderManualInitTest,
1778 UnClearedAttachmentsGetClearedOnReadPixelsAndDrawBufferGetsRestored) {
1779 InitState init;
1780 init.extensions = "GL_EXT_framebuffer_multisample";
1781 init.bind_generates_resource = true;
1782 InitDecoder(init);
1783 const GLuint kFBOClientTextureId = 4100;
1784 const GLuint kFBOServiceTextureId = 4101;
1786 // Register a texture id.
1787 EXPECT_CALL(*gl_, GenTextures(_, _))
1788 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1789 .RetiresOnSaturation();
1790 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1792 // Setup "render from" texture.
1793 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1794 DoTexImage2D(
1795 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1796 DoBindFramebuffer(
1797 GL_READ_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1798 DoFramebufferTexture2D(GL_READ_FRAMEBUFFER,
1799 GL_COLOR_ATTACHMENT0,
1800 GL_TEXTURE_2D,
1801 kFBOClientTextureId,
1802 kFBOServiceTextureId,
1804 GL_NO_ERROR);
1806 // Set scissor rect and disable GL_SCISSOR_TEST to make sure we enable it in
1807 // the clear, then disable it and restore the rect again.
1808 DoScissor(0, 0, 32, 32);
1809 DoEnableDisable(GL_SCISSOR_TEST, false);
1811 SetupExpectationsForFramebufferClearingMulti(
1812 kServiceFramebufferId, // read framebuffer service id
1813 0, // backbuffer service id
1814 GL_READ_FRAMEBUFFER, // target
1815 GL_COLOR_BUFFER_BIT, // clear bits
1816 0, 0, 0,
1817 0, // color
1818 0, // stencil
1819 1.0f, // depth
1820 false, // scissor test
1821 0, 0, 32, 32);
1823 EXPECT_CALL(*gl_, GetError())
1824 .WillOnce(Return(GL_NO_ERROR))
1825 .WillOnce(Return(GL_NO_ERROR))
1826 .RetiresOnSaturation();
1827 EXPECT_CALL(*gl_, ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, _))
1828 .Times(1)
1829 .RetiresOnSaturation();
1830 typedef ReadPixels::Result Result;
1831 uint32 result_shm_id = kSharedMemoryId;
1832 uint32 result_shm_offset = kSharedMemoryOffset;
1833 uint32 pixels_shm_id = kSharedMemoryId;
1834 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
1835 ReadPixels cmd;
1836 cmd.Init(0,
1840 GL_RGBA,
1841 GL_UNSIGNED_BYTE,
1842 pixels_shm_id,
1843 pixels_shm_offset,
1844 result_shm_id,
1845 result_shm_offset,
1846 false);
1847 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1848 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1851 TEST_P(GLES2DecoderWithShaderTest, CopyTexImageWithInCompleteFBOFails) {
1852 GLenum target = GL_TEXTURE_2D;
1853 GLint level = 0;
1854 GLenum internal_format = GL_RGBA;
1855 GLsizei width = 2;
1856 GLsizei height = 4;
1857 SetupTexture();
1858 DoBindRenderbuffer(
1859 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1860 DoBindFramebuffer(
1861 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1862 DoRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 0, 0, GL_NO_ERROR);
1863 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
1864 GL_COLOR_ATTACHMENT0,
1865 GL_RENDERBUFFER,
1866 client_renderbuffer_id_,
1867 kServiceRenderbufferId,
1868 GL_NO_ERROR);
1870 EXPECT_CALL(*gl_, CopyTexImage2D(_, _, _, _, _, _, _, _))
1871 .Times(0)
1872 .RetiresOnSaturation();
1873 CopyTexImage2D cmd;
1874 cmd.Init(target, level, internal_format, 0, 0, width, height);
1875 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1876 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError());
1879 void GLES2DecoderWithShaderTest::CheckRenderbufferChangesMarkFBOAsNotComplete(
1880 bool bound_fbo) {
1881 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
1882 SetupTexture();
1883 DoBindRenderbuffer(
1884 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1885 DoBindFramebuffer(
1886 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1887 DoRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
1888 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
1889 GL_COLOR_ATTACHMENT0,
1890 GL_RENDERBUFFER,
1891 client_renderbuffer_id_,
1892 kServiceRenderbufferId,
1893 GL_NO_ERROR);
1895 if (!bound_fbo) {
1896 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
1899 Framebuffer* framebuffer =
1900 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
1901 ASSERT_TRUE(framebuffer != NULL);
1902 framebuffer_manager->MarkAsComplete(framebuffer);
1903 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1905 // Test that renderbufferStorage marks fbo as not complete.
1906 DoRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
1907 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
1908 framebuffer_manager->MarkAsComplete(framebuffer);
1909 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1911 // Test deleting renderbuffer marks fbo as not complete.
1912 DoDeleteRenderbuffer(client_renderbuffer_id_, kServiceRenderbufferId);
1913 if (bound_fbo) {
1914 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
1915 } else {
1916 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1918 // Cleanup
1919 DoDeleteFramebuffer(client_framebuffer_id_,
1920 kServiceFramebufferId,
1921 bound_fbo,
1922 GL_FRAMEBUFFER,
1924 bound_fbo,
1925 GL_FRAMEBUFFER,
1929 TEST_P(GLES2DecoderWithShaderTest,
1930 RenderbufferChangesMarkFBOAsNotCompleteBoundFBO) {
1931 CheckRenderbufferChangesMarkFBOAsNotComplete(true);
1934 TEST_P(GLES2DecoderWithShaderTest,
1935 RenderbufferChangesMarkFBOAsNotCompleteUnboundFBO) {
1936 CheckRenderbufferChangesMarkFBOAsNotComplete(false);
1939 void GLES2DecoderWithShaderTest::CheckTextureChangesMarkFBOAsNotComplete(
1940 bool bound_fbo) {
1941 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
1942 const GLuint kFBOClientTextureId = 4100;
1943 const GLuint kFBOServiceTextureId = 4101;
1945 // Register a texture id.
1946 EXPECT_CALL(*gl_, GenTextures(_, _))
1947 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1948 .RetiresOnSaturation();
1949 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1951 SetupTexture();
1953 // Setup "render to" texture.
1954 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1955 DoTexImage2D(
1956 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1957 DoBindFramebuffer(
1958 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1959 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1960 GL_COLOR_ATTACHMENT0,
1961 GL_TEXTURE_2D,
1962 kFBOClientTextureId,
1963 kFBOServiceTextureId,
1965 GL_NO_ERROR);
1967 DoBindRenderbuffer(
1968 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1969 DoBindFramebuffer(
1970 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1971 DoRenderbufferStorage(GL_RENDERBUFFER,
1972 GL_DEPTH_COMPONENT16,
1973 GL_DEPTH_COMPONENT,
1976 GL_NO_ERROR);
1977 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
1978 GL_DEPTH_ATTACHMENT,
1979 GL_RENDERBUFFER,
1980 client_renderbuffer_id_,
1981 kServiceRenderbufferId,
1982 GL_NO_ERROR);
1984 if (!bound_fbo) {
1985 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
1988 Framebuffer* framebuffer =
1989 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
1990 ASSERT_TRUE(framebuffer != NULL);
1991 framebuffer_manager->MarkAsComplete(framebuffer);
1992 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1994 // Test TexImage2D marks fbo as not complete.
1995 DoTexImage2D(
1996 GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, 0, 0);
1997 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
1998 framebuffer_manager->MarkAsComplete(framebuffer);
1999 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
2001 // Test CopyImage2D marks fbo as not complete.
2002 EXPECT_CALL(*gl_, GetError())
2003 .WillOnce(Return(GL_NO_ERROR))
2004 .RetiresOnSaturation();
2005 EXPECT_CALL(*gl_, CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 1, 1, 0))
2006 .Times(1)
2007 .RetiresOnSaturation();
2008 EXPECT_CALL(*gl_, GetError())
2009 .WillOnce(Return(GL_NO_ERROR))
2010 .RetiresOnSaturation();
2011 CopyTexImage2D cmd;
2012 cmd.Init(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 1, 1);
2013 // Unbind fbo and bind again after CopyTexImage2D tp avoid feedback loops.
2014 if (bound_fbo) {
2015 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
2017 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2018 if (bound_fbo) {
2019 DoBindFramebuffer(
2020 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2022 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
2024 // Test deleting texture marks fbo as not complete.
2025 framebuffer_manager->MarkAsComplete(framebuffer);
2026 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
2027 DoDeleteTexture(kFBOClientTextureId, kFBOServiceTextureId);
2029 if (bound_fbo) {
2030 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
2031 } else {
2032 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
2034 // Cleanup
2035 DoDeleteFramebuffer(client_framebuffer_id_,
2036 kServiceFramebufferId,
2037 bound_fbo,
2038 GL_FRAMEBUFFER,
2040 bound_fbo,
2041 GL_FRAMEBUFFER,
2045 TEST_P(GLES2DecoderWithShaderTest, TextureChangesMarkFBOAsNotCompleteBoundFBO) {
2046 CheckTextureChangesMarkFBOAsNotComplete(true);
2049 TEST_P(GLES2DecoderWithShaderTest,
2050 TextureChangesMarkFBOAsNotCompleteUnboundFBO) {
2051 CheckTextureChangesMarkFBOAsNotComplete(false);
2054 TEST_P(GLES2DecoderTest, CanChangeSurface) {
2055 scoped_refptr<GLSurfaceMock> other_surface(new GLSurfaceMock);
2056 EXPECT_CALL(*other_surface.get(), GetBackingFrameBufferObject())
2057 .WillOnce(Return(7));
2058 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 7));
2060 decoder_->SetSurface(other_surface);
2063 TEST_P(GLES2DecoderTest, DrawBuffersEXTImmediateSuccceeds) {
2064 const GLsizei count = 1;
2065 const GLenum bufs[] = {GL_COLOR_ATTACHMENT0};
2066 DrawBuffersEXTImmediate& cmd = *GetImmediateAs<DrawBuffersEXTImmediate>();
2067 cmd.Init(count, bufs);
2069 DoBindFramebuffer(
2070 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2071 EXPECT_CALL(*gl_, DrawBuffersARB(count, _)).Times(1).RetiresOnSaturation();
2072 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(bufs)));
2073 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2076 TEST_P(GLES2DecoderTest, DrawBuffersEXTImmediateFails) {
2077 const GLsizei count = 1;
2078 const GLenum bufs[] = {GL_COLOR_ATTACHMENT1_EXT};
2079 DrawBuffersEXTImmediate& cmd = *GetImmediateAs<DrawBuffersEXTImmediate>();
2080 cmd.Init(count, bufs);
2082 DoBindFramebuffer(
2083 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2084 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(bufs)));
2085 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2088 TEST_P(GLES2DecoderTest, DrawBuffersEXTImmediateBackbuffer) {
2089 const GLsizei count = 1;
2090 const GLenum bufs[] = {GL_BACK};
2091 DrawBuffersEXTImmediate& cmd = *GetImmediateAs<DrawBuffersEXTImmediate>();
2092 cmd.Init(count, bufs);
2094 DoBindFramebuffer(
2095 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2096 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(bufs)));
2097 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2099 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0); // unbind
2101 EXPECT_CALL(*gl_, DrawBuffersARB(count, _)).Times(1).RetiresOnSaturation();
2103 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(bufs)));
2104 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2107 TEST_P(GLES2DecoderManualInitTest, InvalidateFramebufferBinding) {
2108 InitState init;
2109 init.gl_version = "opengl es 3.0";
2110 InitDecoder(init);
2112 // EXPECT_EQ can't be used to compare function pointers
2113 EXPECT_TRUE(
2114 gfx::MockGLInterface::GetGLProcAddress("glInvalidateFramebuffer") !=
2115 gfx::g_driver_gl.fn.glDiscardFramebufferEXTFn);
2116 EXPECT_TRUE(
2117 gfx::MockGLInterface::GetGLProcAddress("glInvalidateFramebuffer") !=
2118 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT"));
2121 TEST_P(GLES2DecoderManualInitTest, DiscardFramebufferEXT) {
2122 InitState init;
2123 init.extensions = "GL_EXT_discard_framebuffer";
2124 init.gl_version = "opengl es 2.0";
2125 InitDecoder(init);
2127 // EXPECT_EQ can't be used to compare function pointers
2128 EXPECT_TRUE(
2129 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT") ==
2130 gfx::g_driver_gl.fn.glDiscardFramebufferEXTFn);
2132 const GLenum target = GL_FRAMEBUFFER;
2133 const GLsizei count = 1;
2134 const GLenum attachments[] = {GL_COLOR_ATTACHMENT0};
2136 SetupTexture();
2137 DoBindFramebuffer(
2138 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2139 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2140 GL_COLOR_ATTACHMENT0,
2141 GL_TEXTURE_2D,
2142 client_texture_id_,
2143 kServiceTextureId,
2145 GL_NO_ERROR);
2146 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
2147 Framebuffer* framebuffer =
2148 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
2149 EXPECT_TRUE(framebuffer->IsCleared());
2151 EXPECT_CALL(*gl_, DiscardFramebufferEXT(target, count, _))
2152 .Times(1)
2153 .RetiresOnSaturation();
2154 DiscardFramebufferEXTImmediate& cmd =
2155 *GetImmediateAs<DiscardFramebufferEXTImmediate>();
2156 cmd.Init(target, count, attachments);
2158 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(attachments)));
2159 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2160 EXPECT_FALSE(framebuffer->IsCleared());
2163 TEST_P(GLES2DecoderTest, DiscardFramebufferEXTUnsupported) {
2164 const GLenum target = GL_FRAMEBUFFER;
2165 const GLsizei count = 1;
2166 const GLenum attachments[] = {GL_COLOR_EXT};
2167 DiscardFramebufferEXTImmediate& cmd =
2168 *GetImmediateAs<DiscardFramebufferEXTImmediate>();
2169 cmd.Init(target, count, attachments);
2171 // Should not result into a call into GL.
2172 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(attachments)));
2173 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2176 TEST_P(GLES2DecoderManualInitTest,
2177 DiscardedAttachmentsEXTMarksFramebufferIncomplete) {
2178 InitState init;
2179 init.extensions = "GL_EXT_discard_framebuffer";
2180 init.gl_version = "opengl es 2.0";
2181 init.has_alpha = true;
2182 init.bind_generates_resource = true;
2183 InitDecoder(init);
2185 const GLuint kFBOClientTextureId = 4100;
2186 const GLuint kFBOServiceTextureId = 4101;
2188 // Register a texture id.
2189 EXPECT_CALL(*gl_, GenTextures(_, _))
2190 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2191 .RetiresOnSaturation();
2192 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2194 // Setup "render to" texture.
2195 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2196 DoTexImage2D(
2197 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2198 DoBindFramebuffer(
2199 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2200 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2201 GL_COLOR_ATTACHMENT0,
2202 GL_TEXTURE_2D,
2203 kFBOClientTextureId,
2204 kFBOServiceTextureId,
2206 GL_NO_ERROR);
2207 DoEnableDisable(GL_SCISSOR_TEST, false);
2208 DoScissor(0, 0, 1, 1);
2210 // Setup "render from" texture.
2211 SetupTexture();
2213 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
2214 GL_COLOR_BUFFER_BIT, // clear bits
2215 0, 0, 0,
2216 0, // color
2217 0, // stencil
2218 1.0f, // depth
2219 false, // scissor test
2220 0, 0, 1, 1);
2221 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2222 false, // Framebuffer has depth
2223 false, // Framebuffer has stencil
2224 0x1111, // color bits
2225 false, // depth mask
2226 false, // depth enabled
2227 0, // front stencil mask
2228 0, // back stencil mask
2229 false); // stencil enabled
2231 EXPECT_CALL(*gl_, Clear(GL_COLOR_BUFFER_BIT)).Times(1).RetiresOnSaturation();
2233 Clear clear_cmd;
2234 clear_cmd.Init(GL_COLOR_BUFFER_BIT);
2235 EXPECT_EQ(error::kNoError, ExecuteCmd(clear_cmd));
2236 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2238 // Check that framebuffer is cleared and complete.
2239 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
2240 Framebuffer* framebuffer =
2241 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
2242 EXPECT_TRUE(framebuffer->IsCleared());
2243 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
2245 // Check that Discard GL_COLOR_ATTACHMENT0, sets the attachment as uncleared
2246 // and the framebuffer as incomplete.
2247 EXPECT_TRUE(
2248 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT") ==
2249 gfx::g_driver_gl.fn.glDiscardFramebufferEXTFn);
2251 const GLenum target = GL_FRAMEBUFFER;
2252 const GLsizei count = 1;
2253 const GLenum attachments[] = {GL_COLOR_ATTACHMENT0};
2255 DiscardFramebufferEXTImmediate& discard_cmd =
2256 *GetImmediateAs<DiscardFramebufferEXTImmediate>();
2257 discard_cmd.Init(target, count, attachments);
2259 EXPECT_CALL(*gl_, DiscardFramebufferEXT(target, count, _))
2260 .Times(1)
2261 .RetiresOnSaturation();
2262 EXPECT_EQ(error::kNoError,
2263 ExecuteImmediateCmd(discard_cmd, sizeof(attachments)));
2264 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2265 EXPECT_FALSE(framebuffer->IsCleared());
2266 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
2269 TEST_P(GLES2DecoderManualInitTest, ReadFormatExtension) {
2270 InitState init;
2271 init.extensions = "GL_OES_read_format";
2272 init.bind_generates_resource = true;
2273 InitDecoder(init);
2275 EXPECT_CALL(*gl_, GetError())
2276 .WillOnce(Return(GL_NO_ERROR))
2277 .WillOnce(Return(GL_NO_ERROR))
2278 .WillOnce(Return(GL_NO_ERROR))
2279 .WillOnce(Return(GL_NO_ERROR))
2280 .RetiresOnSaturation();
2281 EXPECT_CALL(*gl_, GetError()).Times(6).RetiresOnSaturation();
2283 typedef GetIntegerv::Result Result;
2284 Result* result = static_cast<Result*>(shared_memory_address_);
2285 GetIntegerv cmd;
2286 const GLuint kFBOClientTextureId = 4100;
2287 const GLuint kFBOServiceTextureId = 4101;
2289 // Register a texture id.
2290 EXPECT_CALL(*gl_, GenTextures(_, _))
2291 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2292 .RetiresOnSaturation();
2293 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2295 // Setup "render to" texture.
2296 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2297 DoTexImage2D(
2298 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2299 DoBindFramebuffer(
2300 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2301 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2302 GL_COLOR_ATTACHMENT0,
2303 GL_TEXTURE_2D,
2304 kFBOClientTextureId,
2305 kFBOServiceTextureId,
2307 GL_NO_ERROR);
2309 result->size = 0;
2310 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(1).RetiresOnSaturation();
2311 cmd.Init(GL_IMPLEMENTATION_COLOR_READ_FORMAT,
2312 shared_memory_id_,
2313 shared_memory_offset_);
2314 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2315 EXPECT_EQ(1, result->GetNumResults());
2316 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2318 result->size = 0;
2319 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(1).RetiresOnSaturation();
2320 cmd.Init(GL_IMPLEMENTATION_COLOR_READ_TYPE,
2321 shared_memory_id_,
2322 shared_memory_offset_);
2323 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2324 EXPECT_EQ(1, result->GetNumResults());
2325 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2328 TEST_P(GLES2DecoderManualInitTest, NoReadFormatExtension) {
2329 InitState init;
2330 init.bind_generates_resource = true;
2331 InitDecoder(init);
2333 EXPECT_CALL(*gl_, GetError())
2334 .WillOnce(Return(GL_NO_ERROR))
2335 .WillOnce(Return(GL_NO_ERROR))
2336 .WillOnce(Return(GL_NO_ERROR))
2337 .WillOnce(Return(GL_NO_ERROR))
2338 .RetiresOnSaturation();
2340 typedef GetIntegerv::Result Result;
2341 Result* result = static_cast<Result*>(shared_memory_address_);
2342 GetIntegerv cmd;
2343 const GLuint kFBOClientTextureId = 4100;
2344 const GLuint kFBOServiceTextureId = 4101;
2346 // Register a texture id.
2347 EXPECT_CALL(*gl_, GenTextures(_, _))
2348 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2349 .RetiresOnSaturation();
2350 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2352 // Setup "render to" texture.
2353 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2354 DoTexImage2D(
2355 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2356 DoBindFramebuffer(
2357 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2358 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2359 GL_COLOR_ATTACHMENT0,
2360 GL_TEXTURE_2D,
2361 kFBOClientTextureId,
2362 kFBOServiceTextureId,
2364 GL_NO_ERROR);
2366 result->size = 0;
2367 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
2368 cmd.Init(GL_IMPLEMENTATION_COLOR_READ_FORMAT,
2369 shared_memory_id_,
2370 shared_memory_offset_);
2371 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2372 EXPECT_EQ(1, result->GetNumResults());
2373 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2375 result->size = 0;
2376 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
2377 cmd.Init(GL_IMPLEMENTATION_COLOR_READ_TYPE,
2378 shared_memory_id_,
2379 shared_memory_offset_);
2380 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2381 EXPECT_EQ(1, result->GetNumResults());
2382 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2385 // TODO(gman): PixelStorei
2387 // TODO(gman): SwapBuffers
2389 } // namespace gles2
2390 } // namespace gpu