Pin Chrome's shortcut to the Win10 Start menu on install and OS upgrade.
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_framebuffers.cc
blob6e47194f472ae0c0b514d894db97bba77cd878b4
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 = 3;
385 const GLint kPackAlignment = 4;
386 const GLenum kFormat = GL_RGB;
387 static const int8 kSrcPixels[kWidth * kHeight * kBytesPerPixel] = {
388 12, 13, 14, 18, 19, 18, 19, 12, 13, 14, 18, 19, 18, 19, 13,
389 29, 28, 23, 22, 21, 22, 21, 29, 28, 23, 22, 21, 22, 21, 28,
390 31, 34, 39, 37, 32, 37, 32, 31, 34, 39, 37, 32, 37, 32, 34,
393 ClearSharedMemory();
395 // We need to setup an FBO so we can know the max size that ReadPixels will
396 // access
397 if (init) {
398 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
399 DoTexImage2D(GL_TEXTURE_2D,
401 kFormat,
402 kWidth,
403 kHeight,
405 kFormat,
406 GL_UNSIGNED_BYTE,
407 kSharedMemoryId,
408 kSharedMemoryOffset);
409 DoBindFramebuffer(
410 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
411 DoFramebufferTexture2D(GL_FRAMEBUFFER,
412 GL_COLOR_ATTACHMENT0,
413 GL_TEXTURE_2D,
414 client_texture_id_,
415 kServiceTextureId,
417 GL_NO_ERROR);
418 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
419 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
420 .RetiresOnSaturation();
423 ReadPixelsEmulator emu(
424 kWidth, kHeight, kBytesPerPixel, kSrcPixels, kSrcPixels, kPackAlignment);
425 typedef ReadPixels::Result Result;
426 Result* result = GetSharedMemoryAs<Result*>();
427 uint32 result_shm_id = kSharedMemoryId;
428 uint32 result_shm_offset = kSharedMemoryOffset;
429 uint32 pixels_shm_id = kSharedMemoryId;
430 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result);
431 void* dest = &result[1];
432 EXPECT_CALL(*gl_, GetError())
433 .WillOnce(Return(GL_NO_ERROR))
434 .WillOnce(Return(GL_NO_ERROR))
435 .RetiresOnSaturation();
436 // ReadPixels will be called for valid size only even though the command
437 // is requesting a larger size.
438 GLint read_x = std::max(0, in_read_x);
439 GLint read_y = std::max(0, in_read_y);
440 GLint read_end_x = std::max(0, std::min(kWidth, in_read_x + in_read_width));
441 GLint read_end_y = std::max(0, std::min(kHeight, in_read_y + in_read_height));
442 GLint read_width = read_end_x - read_x;
443 GLint read_height = read_end_y - read_y;
444 if (read_width > 0 && read_height > 0) {
445 for (GLint yy = read_y; yy < read_end_y; ++yy) {
446 EXPECT_CALL(
447 *gl_,
448 ReadPixels(read_x, yy, read_width, 1, kFormat, GL_UNSIGNED_BYTE, _))
449 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels))
450 .RetiresOnSaturation();
453 ReadPixels cmd;
454 cmd.Init(in_read_x,
455 in_read_y,
456 in_read_width,
457 in_read_height,
458 kFormat,
459 GL_UNSIGNED_BYTE,
460 pixels_shm_id,
461 pixels_shm_offset,
462 result_shm_id,
463 result_shm_offset,
464 false);
465 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
467 GLint unpadded_row_size = emu.ComputeImageDataSize(in_read_width, 1);
468 scoped_ptr<int8[]> zero(new int8[unpadded_row_size]);
469 scoped_ptr<int8[]> pack(new int8[kPackAlignment]);
470 memset(zero.get(), 0, unpadded_row_size);
471 memset(pack.get(), kInitialMemoryValue, kPackAlignment);
472 for (GLint yy = 0; yy < in_read_height; ++yy) {
473 const int8* row = static_cast<const int8*>(
474 emu.ComputePackAlignmentAddress(0, yy, in_read_width, dest));
475 GLint y = in_read_y + yy;
476 if (y < 0 || y >= kHeight) {
477 EXPECT_EQ(0, memcmp(zero.get(), row, unpadded_row_size));
478 } else {
479 // check off left.
480 GLint num_left_pixels = std::max(-in_read_x, 0);
481 GLint num_left_bytes = num_left_pixels * kBytesPerPixel;
482 EXPECT_EQ(0, memcmp(zero.get(), row, num_left_bytes));
484 // check off right.
485 GLint num_right_pixels = std::max(in_read_x + in_read_width - kWidth, 0);
486 GLint num_right_bytes = num_right_pixels * kBytesPerPixel;
487 EXPECT_EQ(0,
488 memcmp(zero.get(),
489 row + unpadded_row_size - num_right_bytes,
490 num_right_bytes));
492 // check middle.
493 GLint x = std::max(in_read_x, 0);
494 GLint num_middle_pixels =
495 std::max(in_read_width - num_left_pixels - num_right_pixels, 0);
496 EXPECT_TRUE(
497 emu.CompareRowSegment(x, y, num_middle_pixels, row + num_left_bytes));
500 // check padding
501 if (yy != in_read_height - 1) {
502 GLint num_padding_bytes =
503 (kPackAlignment - 1) - (unpadded_row_size % kPackAlignment);
504 EXPECT_EQ(0,
505 memcmp(pack.get(), row + unpadded_row_size, num_padding_bytes));
510 TEST_P(GLES2DecoderTest, ReadPixels) {
511 const GLsizei kWidth = 5;
512 const GLsizei kHeight = 3;
513 const GLint kBytesPerPixel = 3;
514 const GLint kPackAlignment = 4;
515 static const int8 kSrcPixels[kWidth * kHeight * kBytesPerPixel] = {
516 12, 13, 14, 18, 19, 18, 19, 12, 13, 14, 18, 19, 18, 19, 13,
517 29, 28, 23, 22, 21, 22, 21, 29, 28, 23, 22, 21, 22, 21, 28,
518 31, 34, 39, 37, 32, 37, 32, 31, 34, 39, 37, 32, 37, 32, 34,
521 surface_->SetSize(gfx::Size(INT_MAX, INT_MAX));
523 ReadPixelsEmulator emu(
524 kWidth, kHeight, kBytesPerPixel, kSrcPixels, kSrcPixels, kPackAlignment);
525 typedef ReadPixels::Result Result;
526 Result* result = GetSharedMemoryAs<Result*>();
527 uint32 result_shm_id = kSharedMemoryId;
528 uint32 result_shm_offset = kSharedMemoryOffset;
529 uint32 pixels_shm_id = kSharedMemoryId;
530 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result);
531 void* dest = &result[1];
532 EXPECT_CALL(*gl_, GetError())
533 .WillOnce(Return(GL_NO_ERROR))
534 .WillOnce(Return(GL_NO_ERROR))
535 .RetiresOnSaturation();
536 EXPECT_CALL(*gl_,
537 ReadPixels(0, 0, kWidth, kHeight, GL_RGB, GL_UNSIGNED_BYTE, _))
538 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels));
539 ReadPixels cmd;
540 cmd.Init(0,
542 kWidth,
543 kHeight,
544 GL_RGB,
545 GL_UNSIGNED_BYTE,
546 pixels_shm_id,
547 pixels_shm_offset,
548 result_shm_id,
549 result_shm_offset,
550 false);
551 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
552 for (GLint yy = 0; yy < kHeight; ++yy) {
553 EXPECT_TRUE(emu.CompareRowSegment(
554 0, yy, kWidth, emu.ComputePackAlignmentAddress(0, yy, kWidth, dest)));
558 TEST_P(GLES2DecoderRGBBackbufferTest, ReadPixelsNoAlphaBackbuffer) {
559 const GLsizei kWidth = 3;
560 const GLsizei kHeight = 3;
561 const GLint kBytesPerPixel = 4;
562 const GLint kPackAlignment = 4;
563 static const uint8 kExpectedPixels[kWidth * kHeight * kBytesPerPixel] = {
564 12, 13, 14, 255, 19, 18, 19, 255, 13, 14, 18, 255,
565 29, 28, 23, 255, 21, 22, 21, 255, 28, 23, 22, 255,
566 31, 34, 39, 255, 32, 37, 32, 255, 34, 39, 37, 255,
568 static const uint8 kSrcPixels[kWidth * kHeight * kBytesPerPixel] = {
569 12, 13, 14, 18, 19, 18, 19, 12, 13, 14, 18, 19, 29, 28, 23, 22, 21, 22,
570 21, 29, 28, 23, 22, 21, 31, 34, 39, 37, 32, 37, 32, 31, 34, 39, 37, 32,
573 surface_->SetSize(gfx::Size(INT_MAX, INT_MAX));
575 ReadPixelsEmulator emu(kWidth,
576 kHeight,
577 kBytesPerPixel,
578 kSrcPixels,
579 kExpectedPixels,
580 kPackAlignment);
581 typedef ReadPixels::Result Result;
582 Result* result = GetSharedMemoryAs<Result*>();
583 uint32 result_shm_id = kSharedMemoryId;
584 uint32 result_shm_offset = kSharedMemoryOffset;
585 uint32 pixels_shm_id = kSharedMemoryId;
586 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(*result);
587 void* dest = &result[1];
588 EXPECT_CALL(*gl_, GetError())
589 .WillOnce(Return(GL_NO_ERROR))
590 .WillOnce(Return(GL_NO_ERROR))
591 .RetiresOnSaturation();
592 EXPECT_CALL(*gl_,
593 ReadPixels(0, 0, kWidth, kHeight, GL_RGBA, GL_UNSIGNED_BYTE, _))
594 .WillOnce(Invoke(&emu, &ReadPixelsEmulator::ReadPixels));
595 ReadPixels cmd;
596 cmd.Init(0,
598 kWidth,
599 kHeight,
600 GL_RGBA,
601 GL_UNSIGNED_BYTE,
602 pixels_shm_id,
603 pixels_shm_offset,
604 result_shm_id,
605 result_shm_offset,
606 false);
607 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
608 for (GLint yy = 0; yy < kHeight; ++yy) {
609 EXPECT_TRUE(emu.CompareRowSegment(
610 0, yy, kWidth, emu.ComputePackAlignmentAddress(0, yy, kWidth, dest)));
614 TEST_P(GLES2DecoderTest, ReadPixelsOutOfRange) {
615 static GLint tests[][4] = {
617 -2, -1, 9, 5,
618 }, // out of range on all sides
620 2, 1, 9, 5,
621 }, // out of range on right, bottom
623 -7, -4, 9, 5,
624 }, // out of range on left, top
626 0, -5, 9, 5,
627 }, // completely off top
629 0, 3, 9, 5,
630 }, // completely off bottom
632 -9, 0, 9, 5,
633 }, // completely off left
635 5, 0, 9, 5,
636 }, // completely off right
639 for (size_t tt = 0; tt < arraysize(tests); ++tt) {
640 CheckReadPixelsOutOfRange(
641 tests[tt][0], tests[tt][1], tests[tt][2], tests[tt][3], tt == 0);
645 TEST_P(GLES2DecoderTest, ReadPixelsInvalidArgs) {
646 typedef ReadPixels::Result Result;
647 uint32 result_shm_id = kSharedMemoryId;
648 uint32 result_shm_offset = kSharedMemoryOffset;
649 uint32 pixels_shm_id = kSharedMemoryId;
650 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
651 EXPECT_CALL(*gl_, ReadPixels(_, _, _, _, _, _, _)).Times(0);
652 ReadPixels cmd;
653 cmd.Init(0,
657 GL_RGB,
658 GL_UNSIGNED_BYTE,
659 pixels_shm_id,
660 pixels_shm_offset,
661 result_shm_id,
662 result_shm_offset,
663 false);
664 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
665 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
666 cmd.Init(0,
670 GL_RGB,
671 GL_UNSIGNED_BYTE,
672 pixels_shm_id,
673 pixels_shm_offset,
674 result_shm_id,
675 result_shm_offset,
676 false);
677 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
678 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
679 cmd.Init(0,
683 GL_RGB,
684 GL_INT,
685 pixels_shm_id,
686 pixels_shm_offset,
687 result_shm_id,
688 result_shm_offset,
689 false);
690 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
691 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
692 cmd.Init(0,
696 GL_RGB,
697 GL_UNSIGNED_BYTE,
698 kInvalidSharedMemoryId,
699 pixels_shm_offset,
700 result_shm_id,
701 result_shm_offset,
702 false);
703 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
704 cmd.Init(0,
708 GL_RGB,
709 GL_UNSIGNED_BYTE,
710 pixels_shm_id,
711 kInvalidSharedMemoryOffset,
712 result_shm_id,
713 result_shm_offset,
714 false);
715 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
716 cmd.Init(0,
720 GL_RGB,
721 GL_UNSIGNED_BYTE,
722 pixels_shm_id,
723 pixels_shm_offset,
724 kInvalidSharedMemoryId,
725 result_shm_offset,
726 false);
727 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
728 cmd.Init(0,
732 GL_RGB,
733 GL_UNSIGNED_BYTE,
734 pixels_shm_id,
735 pixels_shm_offset,
736 result_shm_id,
737 kInvalidSharedMemoryOffset,
738 false);
739 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
742 TEST_P(GLES2DecoderManualInitTest, ReadPixelsAsyncError) {
743 InitState init;
744 init.extensions = "GL_ARB_sync";
745 init.gl_version = "opengl es 3.0";
746 init.has_alpha = true;
747 init.request_alpha = true;
748 init.bind_generates_resource = true;
749 InitDecoder(init);
751 typedef ReadPixels::Result Result;
753 const GLsizei kWidth = 4;
754 const GLsizei kHeight = 4;
755 uint32 result_shm_id = kSharedMemoryId;
756 uint32 result_shm_offset = kSharedMemoryOffset;
757 uint32 pixels_shm_id = kSharedMemoryId;
758 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
760 EXPECT_CALL(*gl_, GetError())
761 // first error check must pass to get to the test
762 .WillOnce(Return(GL_NO_ERROR))
763 // second check is after BufferData, simulate fail here
764 .WillOnce(Return(GL_INVALID_OPERATION))
765 // third error check is fall-through call to sync ReadPixels
766 .WillOnce(Return(GL_NO_ERROR))
767 .RetiresOnSaturation();
769 EXPECT_CALL(*gl_,
770 ReadPixels(0, 0, kWidth, kHeight, GL_RGB, GL_UNSIGNED_BYTE, _))
771 .Times(1);
772 EXPECT_CALL(*gl_, GenBuffersARB(1, _)).Times(1);
773 EXPECT_CALL(*gl_, DeleteBuffersARB(1, _)).Times(1);
774 EXPECT_CALL(*gl_, BindBuffer(GL_PIXEL_PACK_BUFFER_ARB, _)).Times(2);
775 EXPECT_CALL(*gl_,
776 BufferData(GL_PIXEL_PACK_BUFFER_ARB, _, NULL, GL_STREAM_READ))
777 .Times(1);
779 ReadPixels cmd;
780 cmd.Init(0,
782 kWidth,
783 kHeight,
784 GL_RGB,
785 GL_UNSIGNED_BYTE,
786 pixels_shm_id,
787 pixels_shm_offset,
788 result_shm_id,
789 result_shm_offset,
790 true);
791 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
794 // Check that if a renderbuffer is attached and GL returns
795 // GL_FRAMEBUFFER_COMPLETE that the buffer is cleared and state is restored.
796 TEST_P(GLES2DecoderTest, FramebufferRenderbufferClearColor) {
797 DoBindFramebuffer(
798 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
799 ClearColor color_cmd;
800 ColorMask color_mask_cmd;
801 Enable enable_cmd;
802 FramebufferRenderbuffer cmd;
803 color_cmd.Init(0.1f, 0.2f, 0.3f, 0.4f);
804 color_mask_cmd.Init(0, 1, 0, 1);
805 enable_cmd.Init(GL_SCISSOR_TEST);
806 cmd.Init(GL_FRAMEBUFFER,
807 GL_COLOR_ATTACHMENT0,
808 GL_RENDERBUFFER,
809 client_renderbuffer_id_);
810 InSequence sequence;
811 EXPECT_CALL(*gl_, ClearColor(0.1f, 0.2f, 0.3f, 0.4f))
812 .Times(1)
813 .RetiresOnSaturation();
814 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST, true);
815 EXPECT_CALL(*gl_, GetError())
816 .WillOnce(Return(GL_NO_ERROR))
817 .RetiresOnSaturation();
818 EXPECT_CALL(*gl_,
819 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
820 GL_COLOR_ATTACHMENT0,
821 GL_RENDERBUFFER,
822 kServiceRenderbufferId))
823 .Times(1)
824 .RetiresOnSaturation();
825 EXPECT_CALL(*gl_, GetError())
826 .WillOnce(Return(GL_NO_ERROR))
827 .RetiresOnSaturation();
828 EXPECT_EQ(error::kNoError, ExecuteCmd(color_cmd));
829 EXPECT_EQ(error::kNoError, ExecuteCmd(color_mask_cmd));
830 EXPECT_EQ(error::kNoError, ExecuteCmd(enable_cmd));
831 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
834 TEST_P(GLES2DecoderTest, FramebufferRenderbufferClearDepth) {
835 DoBindFramebuffer(
836 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
837 ClearDepthf depth_cmd;
838 DepthMask depth_mask_cmd;
839 FramebufferRenderbuffer cmd;
840 depth_cmd.Init(0.5f);
841 depth_mask_cmd.Init(false);
842 cmd.Init(GL_FRAMEBUFFER,
843 GL_DEPTH_ATTACHMENT,
844 GL_RENDERBUFFER,
845 client_renderbuffer_id_);
846 InSequence sequence;
847 EXPECT_CALL(*gl_, ClearDepth(0.5f)).Times(1).RetiresOnSaturation();
848 EXPECT_CALL(*gl_, GetError())
849 .WillOnce(Return(GL_NO_ERROR))
850 .RetiresOnSaturation();
851 EXPECT_CALL(*gl_,
852 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
853 GL_DEPTH_ATTACHMENT,
854 GL_RENDERBUFFER,
855 kServiceRenderbufferId))
856 .Times(1)
857 .RetiresOnSaturation();
858 EXPECT_CALL(*gl_, GetError())
859 .WillOnce(Return(GL_NO_ERROR))
860 .RetiresOnSaturation();
861 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_cmd));
862 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_mask_cmd));
863 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
866 TEST_P(GLES2DecoderTest, FramebufferRenderbufferClearStencil) {
867 DoBindFramebuffer(
868 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
869 ClearStencil stencil_cmd;
870 StencilMaskSeparate stencil_mask_separate_cmd;
871 FramebufferRenderbuffer cmd;
872 stencil_cmd.Init(123);
873 stencil_mask_separate_cmd.Init(GL_BACK, 0x1234u);
874 cmd.Init(GL_FRAMEBUFFER,
875 GL_STENCIL_ATTACHMENT,
876 GL_RENDERBUFFER,
877 client_renderbuffer_id_);
878 InSequence sequence;
879 EXPECT_CALL(*gl_, ClearStencil(123)).Times(1).RetiresOnSaturation();
880 EXPECT_CALL(*gl_, GetError())
881 .WillOnce(Return(GL_NO_ERROR))
882 .RetiresOnSaturation();
883 EXPECT_CALL(*gl_,
884 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
885 GL_STENCIL_ATTACHMENT,
886 GL_RENDERBUFFER,
887 kServiceRenderbufferId))
888 .Times(1)
889 .RetiresOnSaturation();
890 EXPECT_CALL(*gl_, GetError())
891 .WillOnce(Return(GL_NO_ERROR))
892 .RetiresOnSaturation();
893 EXPECT_EQ(error::kNoError, ExecuteCmd(stencil_cmd));
894 EXPECT_EQ(error::kNoError, ExecuteCmd(stencil_mask_separate_cmd));
895 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
898 #if 0 // Turn this test on once we allow GL_DEPTH_STENCIL_ATTACHMENT
899 TEST_P(GLES2DecoderTest, FramebufferRenderbufferClearDepthStencil) {
900 DoBindFramebuffer(GL_FRAMEBUFFER, client_framebuffer_id_,
901 kServiceFramebufferId);
902 ClearDepthf depth_cmd;
903 ClearStencil stencil_cmd;
904 FramebufferRenderbuffer cmd;
905 depth_cmd.Init(0.5f);
906 stencil_cmd.Init(123);
907 cmd.Init(
908 GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
909 client_renderbuffer_id_);
910 InSequence sequence;
911 EXPECT_CALL(*gl_, ClearDepth(0.5f))
912 .Times(1)
913 .RetiresOnSaturation();
914 EXPECT_CALL(*gl_, ClearStencil(123))
915 .Times(1)
916 .RetiresOnSaturation();
917 EXPECT_CALL(*gl_, FramebufferRenderbufferEXT(
918 GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER,
919 kServiceRenderbufferId))
920 .Times(1)
921 .RetiresOnSaturation();
922 EXPECT_EQ(error::kNoError, ExecuteCmd(depth_cmd));
923 EXPECT_EQ(error::kNoError, ExecuteCmd(stencil_cmd));
924 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
926 #endif
928 TEST_P(GLES2DecoderManualInitTest, ActualAlphaMatchesRequestedAlpha) {
929 InitState init;
930 init.has_alpha = true;
931 init.request_alpha = true;
932 init.bind_generates_resource = true;
933 InitDecoder(init);
935 EXPECT_CALL(*gl_, GetError())
936 .WillOnce(Return(GL_NO_ERROR))
937 .WillOnce(Return(GL_NO_ERROR))
938 .RetiresOnSaturation();
939 typedef GetIntegerv::Result Result;
940 Result* result = static_cast<Result*>(shared_memory_address_);
941 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
942 .WillOnce(SetArgumentPointee<1>(8))
943 .RetiresOnSaturation();
944 result->size = 0;
945 GetIntegerv cmd2;
946 cmd2.Init(GL_ALPHA_BITS, shared_memory_id_, shared_memory_offset_);
947 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
948 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_ALPHA_BITS),
949 result->GetNumResults());
950 EXPECT_EQ(GL_NO_ERROR, GetGLError());
951 EXPECT_EQ(8, result->GetData()[0]);
954 TEST_P(GLES2DecoderManualInitTest, ActualAlphaDoesNotMatchRequestedAlpha) {
955 InitState init;
956 init.has_alpha = true;
957 init.bind_generates_resource = true;
958 InitDecoder(init);
960 EXPECT_CALL(*gl_, GetError())
961 .WillOnce(Return(GL_NO_ERROR))
962 .WillOnce(Return(GL_NO_ERROR))
963 .RetiresOnSaturation();
964 typedef GetIntegerv::Result Result;
965 Result* result = static_cast<Result*>(shared_memory_address_);
966 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
967 .WillOnce(SetArgumentPointee<1>(8))
968 .RetiresOnSaturation();
969 result->size = 0;
970 GetIntegerv cmd2;
971 cmd2.Init(GL_ALPHA_BITS, shared_memory_id_, shared_memory_offset_);
972 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
973 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_ALPHA_BITS),
974 result->GetNumResults());
975 EXPECT_EQ(GL_NO_ERROR, GetGLError());
976 EXPECT_EQ(0, result->GetData()[0]);
979 TEST_P(GLES2DecoderManualInitTest, ActualDepthMatchesRequestedDepth) {
980 InitState init;
981 init.has_depth = true;
982 init.request_depth = true;
983 init.bind_generates_resource = true;
984 InitDecoder(init);
986 EXPECT_CALL(*gl_, GetError())
987 .WillOnce(Return(GL_NO_ERROR))
988 .WillOnce(Return(GL_NO_ERROR))
989 .RetiresOnSaturation();
990 typedef GetIntegerv::Result Result;
991 Result* result = static_cast<Result*>(shared_memory_address_);
992 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
993 .WillOnce(SetArgumentPointee<1>(24))
994 .RetiresOnSaturation();
995 result->size = 0;
996 GetIntegerv cmd2;
997 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
998 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
999 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
1000 result->GetNumResults());
1001 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1002 EXPECT_EQ(24, result->GetData()[0]);
1005 TEST_P(GLES2DecoderManualInitTest, ActualDepthDoesNotMatchRequestedDepth) {
1006 InitState init;
1007 init.has_depth = true;
1008 init.bind_generates_resource = true;
1009 InitDecoder(init);
1011 EXPECT_CALL(*gl_, GetError())
1012 .WillOnce(Return(GL_NO_ERROR))
1013 .WillOnce(Return(GL_NO_ERROR))
1014 .RetiresOnSaturation();
1015 typedef GetIntegerv::Result Result;
1016 Result* result = static_cast<Result*>(shared_memory_address_);
1017 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
1018 .WillOnce(SetArgumentPointee<1>(24))
1019 .RetiresOnSaturation();
1020 result->size = 0;
1021 GetIntegerv cmd2;
1022 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
1023 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1024 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
1025 result->GetNumResults());
1026 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1027 EXPECT_EQ(0, result->GetData()[0]);
1030 TEST_P(GLES2DecoderManualInitTest, ActualStencilMatchesRequestedStencil) {
1031 InitState init;
1032 init.has_stencil = true;
1033 init.request_stencil = true;
1034 init.bind_generates_resource = true;
1035 InitDecoder(init);
1037 EXPECT_CALL(*gl_, GetError())
1038 .WillOnce(Return(GL_NO_ERROR))
1039 .WillOnce(Return(GL_NO_ERROR))
1040 .RetiresOnSaturation();
1041 typedef GetIntegerv::Result Result;
1042 Result* result = static_cast<Result*>(shared_memory_address_);
1043 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
1044 .WillOnce(SetArgumentPointee<1>(8))
1045 .RetiresOnSaturation();
1046 result->size = 0;
1047 GetIntegerv cmd2;
1048 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
1049 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1050 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
1051 result->GetNumResults());
1052 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1053 EXPECT_EQ(8, result->GetData()[0]);
1056 TEST_P(GLES2DecoderManualInitTest, ActualStencilDoesNotMatchRequestedStencil) {
1057 InitState init;
1058 init.has_stencil = true;
1059 init.bind_generates_resource = true;
1060 InitDecoder(init);
1062 EXPECT_CALL(*gl_, GetError())
1063 .WillOnce(Return(GL_NO_ERROR))
1064 .WillOnce(Return(GL_NO_ERROR))
1065 .RetiresOnSaturation();
1066 typedef GetIntegerv::Result Result;
1067 Result* result = static_cast<Result*>(shared_memory_address_);
1068 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
1069 .WillOnce(SetArgumentPointee<1>(8))
1070 .RetiresOnSaturation();
1071 result->size = 0;
1072 GetIntegerv cmd2;
1073 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
1074 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1075 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
1076 result->GetNumResults());
1077 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1078 EXPECT_EQ(0, result->GetData()[0]);
1081 TEST_P(GLES2DecoderManualInitTest, PackedDepthStencilReportsCorrectValues) {
1082 InitState init;
1083 init.extensions = "GL_OES_packed_depth_stencil";
1084 init.gl_version = "opengl es 2.0";
1085 init.has_depth = true;
1086 init.has_stencil = true;
1087 init.request_depth = true;
1088 init.request_stencil = true;
1089 init.bind_generates_resource = true;
1090 InitDecoder(init);
1092 EXPECT_CALL(*gl_, GetError())
1093 .WillOnce(Return(GL_NO_ERROR))
1094 .WillOnce(Return(GL_NO_ERROR))
1095 .WillOnce(Return(GL_NO_ERROR))
1096 .WillOnce(Return(GL_NO_ERROR))
1097 .RetiresOnSaturation();
1098 typedef GetIntegerv::Result Result;
1099 Result* result = static_cast<Result*>(shared_memory_address_);
1100 result->size = 0;
1101 GetIntegerv cmd2;
1102 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
1103 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
1104 .WillOnce(SetArgumentPointee<1>(8))
1105 .RetiresOnSaturation();
1106 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1107 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
1108 result->GetNumResults());
1109 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1110 EXPECT_EQ(8, result->GetData()[0]);
1111 result->size = 0;
1112 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
1113 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
1114 .WillOnce(SetArgumentPointee<1>(24))
1115 .RetiresOnSaturation();
1116 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1117 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
1118 result->GetNumResults());
1119 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1120 EXPECT_EQ(24, result->GetData()[0]);
1123 TEST_P(GLES2DecoderManualInitTest, PackedDepthStencilNoRequestedStencil) {
1124 InitState init;
1125 init.extensions = "GL_OES_packed_depth_stencil";
1126 init.gl_version = "opengl es 2.0";
1127 init.has_depth = true;
1128 init.has_stencil = true;
1129 init.request_depth = true;
1130 init.bind_generates_resource = true;
1131 InitDecoder(init);
1133 EXPECT_CALL(*gl_, GetError())
1134 .WillOnce(Return(GL_NO_ERROR))
1135 .WillOnce(Return(GL_NO_ERROR))
1136 .WillOnce(Return(GL_NO_ERROR))
1137 .WillOnce(Return(GL_NO_ERROR))
1138 .RetiresOnSaturation();
1139 typedef GetIntegerv::Result Result;
1140 Result* result = static_cast<Result*>(shared_memory_address_);
1141 result->size = 0;
1142 GetIntegerv cmd2;
1143 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
1144 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
1145 .WillOnce(SetArgumentPointee<1>(8))
1146 .RetiresOnSaturation();
1147 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1148 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
1149 result->GetNumResults());
1150 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1151 EXPECT_EQ(0, result->GetData()[0]);
1152 result->size = 0;
1153 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
1154 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
1155 .WillOnce(SetArgumentPointee<1>(24))
1156 .RetiresOnSaturation();
1157 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1158 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
1159 result->GetNumResults());
1160 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1161 EXPECT_EQ(24, result->GetData()[0]);
1164 TEST_P(GLES2DecoderManualInitTest, PackedDepthStencilRenderbufferDepth) {
1165 InitState init;
1166 init.extensions = "GL_OES_packed_depth_stencil";
1167 init.gl_version = "opengl es 2.0";
1168 init.bind_generates_resource = true;
1169 InitDecoder(init);
1170 DoBindRenderbuffer(
1171 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1172 DoBindFramebuffer(
1173 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1175 EnsureRenderbufferBound(false);
1176 EXPECT_CALL(*gl_, GetError())
1177 .WillOnce(Return(GL_NO_ERROR)) // for RenderbufferStoage
1178 .WillOnce(Return(GL_NO_ERROR))
1179 .WillOnce(Return(GL_NO_ERROR)) // for FramebufferRenderbuffer
1180 .WillOnce(Return(GL_NO_ERROR))
1181 .WillOnce(Return(GL_NO_ERROR)) // for GetIntegerv
1182 .WillOnce(Return(GL_NO_ERROR))
1183 .WillOnce(Return(GL_NO_ERROR)) // for GetIntegerv
1184 .WillOnce(Return(GL_NO_ERROR))
1185 .RetiresOnSaturation();
1187 EXPECT_CALL(
1188 *gl_,
1189 RenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 100, 50))
1190 .Times(1)
1191 .RetiresOnSaturation();
1192 RenderbufferStorage cmd;
1193 cmd.Init(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 100, 50);
1194 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1195 EXPECT_CALL(*gl_,
1196 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
1197 GL_DEPTH_ATTACHMENT,
1198 GL_RENDERBUFFER,
1199 kServiceRenderbufferId))
1200 .Times(1)
1201 .RetiresOnSaturation();
1202 FramebufferRenderbuffer fbrb_cmd;
1203 fbrb_cmd.Init(GL_FRAMEBUFFER,
1204 GL_DEPTH_ATTACHMENT,
1205 GL_RENDERBUFFER,
1206 client_renderbuffer_id_);
1207 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
1209 typedef GetIntegerv::Result Result;
1210 Result* result = static_cast<Result*>(shared_memory_address_);
1211 result->size = 0;
1212 GetIntegerv cmd2;
1213 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
1214 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
1215 .WillOnce(SetArgumentPointee<1>(8))
1216 .RetiresOnSaturation();
1217 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1218 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
1219 result->GetNumResults());
1220 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1221 EXPECT_EQ(0, result->GetData()[0]);
1222 result->size = 0;
1223 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
1224 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
1225 .WillOnce(SetArgumentPointee<1>(24))
1226 .RetiresOnSaturation();
1227 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1228 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
1229 result->GetNumResults());
1230 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1231 EXPECT_EQ(24, result->GetData()[0]);
1234 TEST_P(GLES2DecoderManualInitTest, PackedDepthStencilRenderbufferStencil) {
1235 InitState init;
1236 init.extensions = "GL_OES_packed_depth_stencil";
1237 init.gl_version = "opengl es 2.0";
1238 init.bind_generates_resource = true;
1239 InitDecoder(init);
1240 DoBindRenderbuffer(
1241 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1242 DoBindFramebuffer(
1243 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1245 EnsureRenderbufferBound(false);
1246 EXPECT_CALL(*gl_, GetError())
1247 .WillOnce(Return(GL_NO_ERROR)) // for RenderbufferStoage
1248 .WillOnce(Return(GL_NO_ERROR))
1249 .WillOnce(Return(GL_NO_ERROR)) // for FramebufferRenderbuffer
1250 .WillOnce(Return(GL_NO_ERROR))
1251 .WillOnce(Return(GL_NO_ERROR)) // for GetIntegerv
1252 .WillOnce(Return(GL_NO_ERROR))
1253 .WillOnce(Return(GL_NO_ERROR)) // for GetIntegerv
1254 .WillOnce(Return(GL_NO_ERROR))
1255 .RetiresOnSaturation();
1257 EXPECT_CALL(
1258 *gl_,
1259 RenderbufferStorageEXT(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 100, 50))
1260 .Times(1)
1261 .RetiresOnSaturation();
1262 RenderbufferStorage cmd;
1263 cmd.Init(GL_RENDERBUFFER, GL_DEPTH24_STENCIL8, 100, 50);
1264 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1265 EXPECT_CALL(*gl_,
1266 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
1267 GL_STENCIL_ATTACHMENT,
1268 GL_RENDERBUFFER,
1269 kServiceRenderbufferId))
1270 .Times(1)
1271 .RetiresOnSaturation();
1272 FramebufferRenderbuffer fbrb_cmd;
1273 fbrb_cmd.Init(GL_FRAMEBUFFER,
1274 GL_STENCIL_ATTACHMENT,
1275 GL_RENDERBUFFER,
1276 client_renderbuffer_id_);
1277 EXPECT_EQ(error::kNoError, ExecuteCmd(fbrb_cmd));
1279 typedef GetIntegerv::Result Result;
1280 Result* result = static_cast<Result*>(shared_memory_address_);
1281 result->size = 0;
1282 GetIntegerv cmd2;
1283 cmd2.Init(GL_STENCIL_BITS, shared_memory_id_, shared_memory_offset_);
1284 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
1285 .WillOnce(SetArgumentPointee<1>(8))
1286 .RetiresOnSaturation();
1287 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1288 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS),
1289 result->GetNumResults());
1290 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1291 EXPECT_EQ(8, result->GetData()[0]);
1292 result->size = 0;
1293 cmd2.Init(GL_DEPTH_BITS, shared_memory_id_, shared_memory_offset_);
1294 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
1295 .WillOnce(SetArgumentPointee<1>(24))
1296 .RetiresOnSaturation();
1297 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
1298 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS),
1299 result->GetNumResults());
1300 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1301 EXPECT_EQ(0, result->GetData()[0]);
1304 TEST_P(GLES2DecoderTest, FramebufferRenderbufferGLError) {
1305 DoBindFramebuffer(
1306 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1307 EXPECT_CALL(*gl_, GetError())
1308 .WillOnce(Return(GL_NO_ERROR))
1309 .WillOnce(Return(GL_OUT_OF_MEMORY))
1310 .RetiresOnSaturation();
1311 EXPECT_CALL(*gl_,
1312 FramebufferRenderbufferEXT(GL_FRAMEBUFFER,
1313 GL_COLOR_ATTACHMENT0,
1314 GL_RENDERBUFFER,
1315 kServiceRenderbufferId))
1316 .Times(1)
1317 .RetiresOnSaturation();
1318 FramebufferRenderbuffer cmd;
1319 cmd.Init(GL_FRAMEBUFFER,
1320 GL_COLOR_ATTACHMENT0,
1321 GL_RENDERBUFFER,
1322 client_renderbuffer_id_);
1323 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1324 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
1327 TEST_P(GLES2DecoderTest, FramebufferTexture2DGLError) {
1328 const GLsizei kWidth = 5;
1329 const GLsizei kHeight = 3;
1330 const GLenum kFormat = GL_RGB;
1331 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
1332 DoTexImage2D(GL_TEXTURE_2D,
1334 kFormat,
1335 kWidth,
1336 kHeight,
1338 kFormat,
1339 GL_UNSIGNED_BYTE,
1342 DoBindFramebuffer(
1343 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1344 EXPECT_CALL(*gl_, GetError())
1345 .WillOnce(Return(GL_NO_ERROR))
1346 .WillOnce(Return(GL_OUT_OF_MEMORY))
1347 .RetiresOnSaturation();
1348 EXPECT_CALL(*gl_,
1349 FramebufferTexture2DEXT(GL_FRAMEBUFFER,
1350 GL_COLOR_ATTACHMENT0,
1351 GL_TEXTURE_2D,
1352 kServiceTextureId,
1354 .Times(1)
1355 .RetiresOnSaturation();
1356 FramebufferTexture2D fbtex_cmd;
1357 fbtex_cmd.Init(GL_FRAMEBUFFER,
1358 GL_COLOR_ATTACHMENT0,
1359 GL_TEXTURE_2D,
1360 client_texture_id_);
1361 EXPECT_EQ(error::kNoError, ExecuteCmd(fbtex_cmd));
1362 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
1365 TEST_P(GLES2DecoderTest, RenderbufferStorageGLError) {
1366 DoBindRenderbuffer(
1367 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1368 EnsureRenderbufferBound(false);
1369 EXPECT_CALL(*gl_, GetError())
1370 .WillOnce(Return(GL_NO_ERROR))
1371 .WillOnce(Return(GL_OUT_OF_MEMORY))
1372 .RetiresOnSaturation();
1373 EXPECT_CALL(*gl_, RenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA, 100, 50))
1374 .Times(1)
1375 .RetiresOnSaturation();
1376 RenderbufferStorage cmd;
1377 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, 100, 50);
1378 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1379 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
1382 TEST_P(GLES2DecoderTest, RenderbufferStorageBadArgs) {
1383 DoBindRenderbuffer(
1384 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1385 EXPECT_CALL(*gl_, RenderbufferStorageEXT(_, _, _, _))
1386 .Times(0)
1387 .RetiresOnSaturation();
1388 RenderbufferStorage cmd;
1389 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, TestHelper::kMaxRenderbufferSize + 1, 1);
1390 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1391 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1392 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, 1, TestHelper::kMaxRenderbufferSize + 1);
1393 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1394 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1397 TEST_P(GLES2DecoderManualInitTest,
1398 RenderbufferStorageMultisampleCHROMIUMGLError) {
1399 InitState init;
1400 init.extensions = "GL_EXT_framebuffer_multisample";
1401 init.bind_generates_resource = true;
1402 InitDecoder(init);
1403 DoBindRenderbuffer(
1404 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1405 EnsureRenderbufferBound(false);
1406 EXPECT_CALL(*gl_, GetError())
1407 .WillOnce(Return(GL_NO_ERROR))
1408 .WillOnce(Return(GL_OUT_OF_MEMORY))
1409 .RetiresOnSaturation();
1410 EXPECT_CALL(
1411 *gl_,
1412 RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, 1, GL_RGBA, 100, 50))
1413 .Times(1)
1414 .RetiresOnSaturation();
1415 RenderbufferStorageMultisampleCHROMIUM cmd;
1416 cmd.Init(GL_RENDERBUFFER, 1, GL_RGBA4, 100, 50);
1417 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1418 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
1421 TEST_P(GLES2DecoderManualInitTest,
1422 RenderbufferStorageMultisampleCHROMIUMBadArgs) {
1423 InitState init;
1424 init.extensions = "GL_EXT_framebuffer_multisample";
1425 init.bind_generates_resource = true;
1426 InitDecoder(init);
1427 DoBindRenderbuffer(
1428 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1429 EXPECT_CALL(*gl_, RenderbufferStorageMultisampleEXT(_, _, _, _, _))
1430 .Times(0)
1431 .RetiresOnSaturation();
1432 RenderbufferStorageMultisampleCHROMIUM cmd;
1433 cmd.Init(GL_RENDERBUFFER,
1434 TestHelper::kMaxSamples + 1,
1435 GL_RGBA4,
1436 TestHelper::kMaxRenderbufferSize,
1438 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1439 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1440 cmd.Init(GL_RENDERBUFFER,
1441 TestHelper::kMaxSamples,
1442 GL_RGBA4,
1443 TestHelper::kMaxRenderbufferSize + 1,
1445 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1446 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1447 cmd.Init(GL_RENDERBUFFER,
1448 TestHelper::kMaxSamples,
1449 GL_RGBA4,
1451 TestHelper::kMaxRenderbufferSize + 1);
1452 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1453 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
1456 TEST_P(GLES2DecoderManualInitTest, RenderbufferStorageMultisampleCHROMIUM) {
1457 InitState init;
1458 init.extensions = "GL_EXT_framebuffer_multisample";
1459 InitDecoder(init);
1460 DoBindRenderbuffer(
1461 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1462 InSequence sequence;
1463 EnsureRenderbufferBound(false);
1464 DoRenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER,
1465 TestHelper::kMaxSamples,
1466 GL_RGBA4,
1467 GL_RGBA,
1468 TestHelper::kMaxRenderbufferSize,
1472 TEST_P(GLES2DecoderManualInitTest,
1473 RenderbufferStorageMultisampleCHROMIUMRebindRenderbuffer) {
1474 InitState init;
1475 init.extensions = "GL_EXT_framebuffer_multisample";
1476 InitDecoder(init);
1477 DoBindRenderbuffer(
1478 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1479 RestoreRenderbufferBindings();
1480 InSequence sequence;
1481 EnsureRenderbufferBound(true);
1482 DoRenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER,
1483 TestHelper::kMaxSamples,
1484 GL_RGBA4,
1485 GL_RGBA,
1486 TestHelper::kMaxRenderbufferSize,
1490 TEST_P(GLES2DecoderManualInitTest,
1491 RenderbufferStorageMultisampleEXTNotSupported) {
1492 InitState init;
1493 init.extensions = "GL_EXT_framebuffer_multisample";
1494 init.bind_generates_resource = true;
1495 InitDecoder(init);
1496 DoBindRenderbuffer(
1497 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1498 InSequence sequence;
1499 // GL_EXT_framebuffer_multisample uses RenderbufferStorageMultisampleCHROMIUM.
1500 RenderbufferStorageMultisampleEXT cmd;
1501 cmd.Init(GL_RENDERBUFFER,
1502 TestHelper::kMaxSamples,
1503 GL_RGBA4,
1504 TestHelper::kMaxRenderbufferSize,
1506 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1507 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1510 class GLES2DecoderMultisampledRenderToTextureTest
1511 : public GLES2DecoderTestWithExtensionsOnGLES2 {
1512 public:
1513 void TestNotCompatibleWithRenderbufferStorageMultisampleCHROMIUM() {
1514 DoBindRenderbuffer(
1515 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1516 RenderbufferStorageMultisampleCHROMIUM cmd;
1517 cmd.Init(GL_RENDERBUFFER,
1518 TestHelper::kMaxSamples,
1519 GL_RGBA4,
1520 TestHelper::kMaxRenderbufferSize,
1522 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1523 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1526 void TestRenderbufferStorageMultisampleEXT(const char* extension,
1527 bool rb_rebind) {
1528 DoBindRenderbuffer(
1529 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1530 InSequence sequence;
1531 if (rb_rebind) {
1532 RestoreRenderbufferBindings();
1533 EnsureRenderbufferBound(true);
1534 } else {
1535 EnsureRenderbufferBound(false);
1538 EXPECT_CALL(*gl_, GetError())
1539 .WillOnce(Return(GL_NO_ERROR))
1540 .RetiresOnSaturation();
1541 if (strstr(extension, "GL_IMG_multisampled_render_to_texture")) {
1542 EXPECT_CALL(
1543 *gl_,
1544 RenderbufferStorageMultisampleIMG(GL_RENDERBUFFER,
1545 TestHelper::kMaxSamples,
1546 GL_RGBA4,
1547 TestHelper::kMaxRenderbufferSize,
1549 .Times(1)
1550 .RetiresOnSaturation();
1551 } else {
1552 EXPECT_CALL(
1553 *gl_,
1554 RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER,
1555 TestHelper::kMaxSamples,
1556 GL_RGBA4,
1557 TestHelper::kMaxRenderbufferSize,
1559 .Times(1)
1560 .RetiresOnSaturation();
1562 EXPECT_CALL(*gl_, GetError())
1563 .WillOnce(Return(GL_NO_ERROR))
1564 .RetiresOnSaturation();
1565 RenderbufferStorageMultisampleEXT cmd;
1566 cmd.Init(GL_RENDERBUFFER,
1567 TestHelper::kMaxSamples,
1568 GL_RGBA4,
1569 TestHelper::kMaxRenderbufferSize,
1571 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1572 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1576 INSTANTIATE_TEST_CASE_P(Service,
1577 GLES2DecoderMultisampledRenderToTextureTest,
1578 ::testing::Bool());
1580 TEST_P(GLES2DecoderMultisampledRenderToTextureTest,
1581 NotCompatibleWithRenderbufferStorageMultisampleCHROMIUM_EXT) {
1582 Init("GL_EXT_multisampled_render_to_texture");
1583 TestNotCompatibleWithRenderbufferStorageMultisampleCHROMIUM();
1586 TEST_P(GLES2DecoderMultisampledRenderToTextureTest,
1587 NotCompatibleWithRenderbufferStorageMultisampleCHROMIUM_IMG) {
1588 Init("GL_IMG_multisampled_render_to_texture");
1589 TestNotCompatibleWithRenderbufferStorageMultisampleCHROMIUM();
1592 TEST_P(GLES2DecoderMultisampledRenderToTextureTest,
1593 RenderbufferStorageMultisampleEXT_EXT) {
1594 Init("GL_EXT_multisampled_render_to_texture");
1595 TestRenderbufferStorageMultisampleEXT("GL_EXT_multisampled_render_to_texture",
1596 false);
1599 TEST_P(GLES2DecoderMultisampledRenderToTextureTest,
1600 RenderbufferStorageMultisampleEXT_IMG) {
1601 Init("GL_IMG_multisampled_render_to_texture");
1602 TestRenderbufferStorageMultisampleEXT("GL_IMG_multisampled_render_to_texture",
1603 false);
1606 TEST_P(GLES2DecoderMultisampledRenderToTextureTest,
1607 RenderbufferStorageMultisampleEXT_EXT_RebindRenderbuffer) {
1608 Init("GL_EXT_multisampled_render_to_texture");
1609 TestRenderbufferStorageMultisampleEXT("GL_EXT_multisampled_render_to_texture",
1610 true);
1613 TEST_P(GLES2DecoderMultisampledRenderToTextureTest,
1614 RenderbufferStorageMultisampleEXT_IMG_RebindRenderbuffer) {
1615 Init("GL_IMG_multisampled_render_to_texture");
1616 TestRenderbufferStorageMultisampleEXT("GL_IMG_multisampled_render_to_texture",
1617 true);
1620 TEST_P(GLES2DecoderTest, ReadPixelsGLError) {
1621 GLenum kFormat = GL_RGBA;
1622 GLint x = 0;
1623 GLint y = 0;
1624 GLsizei width = 2;
1625 GLsizei height = 4;
1626 typedef ReadPixels::Result Result;
1627 uint32 result_shm_id = kSharedMemoryId;
1628 uint32 result_shm_offset = kSharedMemoryOffset;
1629 uint32 pixels_shm_id = kSharedMemoryId;
1630 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
1631 EXPECT_CALL(*gl_, GetError())
1632 .WillOnce(Return(GL_NO_ERROR))
1633 .WillOnce(Return(GL_OUT_OF_MEMORY))
1634 .RetiresOnSaturation();
1635 EXPECT_CALL(*gl_,
1636 ReadPixels(x, y, width, height, kFormat, GL_UNSIGNED_BYTE, _))
1637 .Times(1)
1638 .RetiresOnSaturation();
1639 ReadPixels cmd;
1640 cmd.Init(x,
1642 width,
1643 height,
1644 kFormat,
1645 GL_UNSIGNED_BYTE,
1646 pixels_shm_id,
1647 pixels_shm_offset,
1648 result_shm_id,
1649 result_shm_offset,
1650 false);
1651 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1652 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
1655 TEST_P(GLES2DecoderWithShaderTest, UnClearedAttachmentsGetClearedOnClear) {
1656 const GLuint kFBOClientTextureId = 4100;
1657 const GLuint kFBOServiceTextureId = 4101;
1659 // Register a texture id.
1660 EXPECT_CALL(*gl_, GenTextures(_, _))
1661 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1662 .RetiresOnSaturation();
1663 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1665 // Setup "render to" texture.
1666 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1667 DoTexImage2D(
1668 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1669 DoBindFramebuffer(
1670 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1671 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1672 GL_COLOR_ATTACHMENT0,
1673 GL_TEXTURE_2D,
1674 kFBOClientTextureId,
1675 kFBOServiceTextureId,
1677 GL_NO_ERROR);
1678 // Set scissor rect and enable GL_SCISSOR_TEST to make sure we re-enable it
1679 // and restore the rect again after the clear.
1680 DoEnableDisable(GL_SCISSOR_TEST, true);
1681 DoScissor(0, 0, 64, 64);
1683 // Setup "render from" texture.
1684 SetupTexture();
1686 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
1687 GL_COLOR_BUFFER_BIT, // clear bits
1688 0, 0, 0,
1689 0, // color
1690 0, // stencil
1691 1.0f, // depth
1692 true, // scissor test
1693 0, 0, 64, 64);
1694 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1695 false, // Framebuffer has depth
1696 false, // Framebuffer has stencil
1697 0x1111, // color bits
1698 false, // depth mask
1699 false, // depth enabled
1700 0, // front stencil mask
1701 0, // back stencil mask
1702 false); // stencil enabled
1704 EXPECT_CALL(*gl_, Clear(GL_COLOR_BUFFER_BIT)).Times(1).RetiresOnSaturation();
1706 Clear cmd;
1707 cmd.Init(GL_COLOR_BUFFER_BIT);
1708 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1709 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1712 TEST_P(GLES2DecoderWithShaderTest, UnClearedAttachmentsGetClearedOnReadPixels) {
1713 const GLuint kFBOClientTextureId = 4100;
1714 const GLuint kFBOServiceTextureId = 4101;
1716 // Register a texture id.
1717 EXPECT_CALL(*gl_, GenTextures(_, _))
1718 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1719 .RetiresOnSaturation();
1720 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1722 // Setup "render to" texture.
1723 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1724 DoTexImage2D(
1725 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1726 DoBindFramebuffer(
1727 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1728 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1729 GL_COLOR_ATTACHMENT0,
1730 GL_TEXTURE_2D,
1731 kFBOClientTextureId,
1732 kFBOServiceTextureId,
1734 GL_NO_ERROR);
1735 DoEnableDisable(GL_SCISSOR_TEST, false);
1736 DoScissor(0, 0, 1, 1);
1738 // Setup "render from" texture.
1739 SetupTexture();
1741 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
1742 GL_COLOR_BUFFER_BIT, // clear bits
1743 0, 0, 0,
1744 0, // color
1745 0, // stencil
1746 1.0f, // depth
1747 false, // scissor test
1748 0, 0, 1, 1);
1750 EXPECT_CALL(*gl_, GetError())
1751 .WillOnce(Return(GL_NO_ERROR))
1752 .WillOnce(Return(GL_NO_ERROR))
1753 .RetiresOnSaturation();
1754 EXPECT_CALL(*gl_, ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, _))
1755 .Times(1)
1756 .RetiresOnSaturation();
1757 typedef ReadPixels::Result Result;
1758 uint32 result_shm_id = kSharedMemoryId;
1759 uint32 result_shm_offset = kSharedMemoryOffset;
1760 uint32 pixels_shm_id = kSharedMemoryId;
1761 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
1762 ReadPixels cmd;
1763 cmd.Init(0,
1767 GL_RGBA,
1768 GL_UNSIGNED_BYTE,
1769 pixels_shm_id,
1770 pixels_shm_offset,
1771 result_shm_id,
1772 result_shm_offset,
1773 false);
1774 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1775 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1778 TEST_P(GLES2DecoderManualInitTest,
1779 UnClearedAttachmentsGetClearedOnReadPixelsAndDrawBufferGetsRestored) {
1780 InitState init;
1781 init.extensions = "GL_EXT_framebuffer_multisample";
1782 init.bind_generates_resource = true;
1783 InitDecoder(init);
1784 const GLuint kFBOClientTextureId = 4100;
1785 const GLuint kFBOServiceTextureId = 4101;
1787 // Register a texture id.
1788 EXPECT_CALL(*gl_, GenTextures(_, _))
1789 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1790 .RetiresOnSaturation();
1791 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1793 // Setup "render from" texture.
1794 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1795 DoTexImage2D(
1796 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1797 DoBindFramebuffer(
1798 GL_READ_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1799 DoFramebufferTexture2D(GL_READ_FRAMEBUFFER,
1800 GL_COLOR_ATTACHMENT0,
1801 GL_TEXTURE_2D,
1802 kFBOClientTextureId,
1803 kFBOServiceTextureId,
1805 GL_NO_ERROR);
1807 // Set scissor rect and disable GL_SCISSOR_TEST to make sure we enable it in
1808 // the clear, then disable it and restore the rect again.
1809 DoScissor(0, 0, 32, 32);
1810 DoEnableDisable(GL_SCISSOR_TEST, false);
1812 SetupExpectationsForFramebufferClearingMulti(
1813 kServiceFramebufferId, // read framebuffer service id
1814 0, // backbuffer service id
1815 GL_READ_FRAMEBUFFER, // target
1816 GL_COLOR_BUFFER_BIT, // clear bits
1817 0, 0, 0,
1818 0, // color
1819 0, // stencil
1820 1.0f, // depth
1821 false, // scissor test
1822 0, 0, 32, 32);
1824 EXPECT_CALL(*gl_, GetError())
1825 .WillOnce(Return(GL_NO_ERROR))
1826 .WillOnce(Return(GL_NO_ERROR))
1827 .RetiresOnSaturation();
1828 EXPECT_CALL(*gl_, ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, _))
1829 .Times(1)
1830 .RetiresOnSaturation();
1831 typedef ReadPixels::Result Result;
1832 uint32 result_shm_id = kSharedMemoryId;
1833 uint32 result_shm_offset = kSharedMemoryOffset;
1834 uint32 pixels_shm_id = kSharedMemoryId;
1835 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
1836 ReadPixels cmd;
1837 cmd.Init(0,
1841 GL_RGBA,
1842 GL_UNSIGNED_BYTE,
1843 pixels_shm_id,
1844 pixels_shm_offset,
1845 result_shm_id,
1846 result_shm_offset,
1847 false);
1848 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1849 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1852 TEST_P(GLES2DecoderWithShaderTest, CopyTexImageWithInCompleteFBOFails) {
1853 GLenum target = GL_TEXTURE_2D;
1854 GLint level = 0;
1855 GLenum internal_format = GL_RGBA;
1856 GLsizei width = 2;
1857 GLsizei height = 4;
1858 SetupTexture();
1859 DoBindRenderbuffer(
1860 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1861 DoBindFramebuffer(
1862 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1863 DoRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 0, 0, GL_NO_ERROR);
1864 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
1865 GL_COLOR_ATTACHMENT0,
1866 GL_RENDERBUFFER,
1867 client_renderbuffer_id_,
1868 kServiceRenderbufferId,
1869 GL_NO_ERROR);
1871 EXPECT_CALL(*gl_, CopyTexImage2D(_, _, _, _, _, _, _, _))
1872 .Times(0)
1873 .RetiresOnSaturation();
1874 CopyTexImage2D cmd;
1875 cmd.Init(target, level, internal_format, 0, 0, width, height);
1876 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1877 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError());
1880 void GLES2DecoderWithShaderTest::CheckRenderbufferChangesMarkFBOAsNotComplete(
1881 bool bound_fbo) {
1882 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
1883 SetupTexture();
1884 DoBindRenderbuffer(
1885 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1886 DoBindFramebuffer(
1887 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1888 DoRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
1889 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
1890 GL_COLOR_ATTACHMENT0,
1891 GL_RENDERBUFFER,
1892 client_renderbuffer_id_,
1893 kServiceRenderbufferId,
1894 GL_NO_ERROR);
1896 if (!bound_fbo) {
1897 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
1900 Framebuffer* framebuffer =
1901 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
1902 ASSERT_TRUE(framebuffer != NULL);
1903 framebuffer_manager->MarkAsComplete(framebuffer);
1904 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1906 // Test that renderbufferStorage marks fbo as not complete.
1907 DoRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
1908 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
1909 framebuffer_manager->MarkAsComplete(framebuffer);
1910 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1912 // Test deleting renderbuffer marks fbo as not complete.
1913 DoDeleteRenderbuffer(client_renderbuffer_id_, kServiceRenderbufferId);
1914 if (bound_fbo) {
1915 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
1916 } else {
1917 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1919 // Cleanup
1920 DoDeleteFramebuffer(client_framebuffer_id_,
1921 kServiceFramebufferId,
1922 bound_fbo,
1923 GL_FRAMEBUFFER,
1925 bound_fbo,
1926 GL_FRAMEBUFFER,
1930 TEST_P(GLES2DecoderWithShaderTest,
1931 RenderbufferChangesMarkFBOAsNotCompleteBoundFBO) {
1932 CheckRenderbufferChangesMarkFBOAsNotComplete(true);
1935 TEST_P(GLES2DecoderWithShaderTest,
1936 RenderbufferChangesMarkFBOAsNotCompleteUnboundFBO) {
1937 CheckRenderbufferChangesMarkFBOAsNotComplete(false);
1940 void GLES2DecoderWithShaderTest::CheckTextureChangesMarkFBOAsNotComplete(
1941 bool bound_fbo) {
1942 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
1943 const GLuint kFBOClientTextureId = 4100;
1944 const GLuint kFBOServiceTextureId = 4101;
1946 // Register a texture id.
1947 EXPECT_CALL(*gl_, GenTextures(_, _))
1948 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1949 .RetiresOnSaturation();
1950 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1952 SetupTexture();
1954 // Setup "render to" texture.
1955 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1956 DoTexImage2D(
1957 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1958 DoBindFramebuffer(
1959 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1960 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1961 GL_COLOR_ATTACHMENT0,
1962 GL_TEXTURE_2D,
1963 kFBOClientTextureId,
1964 kFBOServiceTextureId,
1966 GL_NO_ERROR);
1968 DoBindRenderbuffer(
1969 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1970 DoBindFramebuffer(
1971 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1972 DoRenderbufferStorage(GL_RENDERBUFFER,
1973 GL_DEPTH_COMPONENT16,
1974 GL_DEPTH_COMPONENT,
1977 GL_NO_ERROR);
1978 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
1979 GL_DEPTH_ATTACHMENT,
1980 GL_RENDERBUFFER,
1981 client_renderbuffer_id_,
1982 kServiceRenderbufferId,
1983 GL_NO_ERROR);
1985 if (!bound_fbo) {
1986 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
1989 Framebuffer* framebuffer =
1990 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
1991 ASSERT_TRUE(framebuffer != NULL);
1992 framebuffer_manager->MarkAsComplete(framebuffer);
1993 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1995 // Test TexImage2D marks fbo as not complete.
1996 DoTexImage2D(
1997 GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, 0, 0);
1998 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
1999 framebuffer_manager->MarkAsComplete(framebuffer);
2000 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
2002 // Test CopyImage2D marks fbo as not complete.
2003 EXPECT_CALL(*gl_, GetError())
2004 .WillOnce(Return(GL_NO_ERROR))
2005 .RetiresOnSaturation();
2006 EXPECT_CALL(*gl_, CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 1, 1, 0))
2007 .Times(1)
2008 .RetiresOnSaturation();
2009 EXPECT_CALL(*gl_, GetError())
2010 .WillOnce(Return(GL_NO_ERROR))
2011 .RetiresOnSaturation();
2012 CopyTexImage2D cmd;
2013 cmd.Init(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 1, 1);
2014 // Unbind fbo and bind again after CopyTexImage2D tp avoid feedback loops.
2015 if (bound_fbo) {
2016 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
2018 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2019 if (bound_fbo) {
2020 DoBindFramebuffer(
2021 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2023 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
2025 // Test deleting texture marks fbo as not complete.
2026 framebuffer_manager->MarkAsComplete(framebuffer);
2027 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
2028 DoDeleteTexture(kFBOClientTextureId, kFBOServiceTextureId);
2030 if (bound_fbo) {
2031 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
2032 } else {
2033 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
2035 // Cleanup
2036 DoDeleteFramebuffer(client_framebuffer_id_,
2037 kServiceFramebufferId,
2038 bound_fbo,
2039 GL_FRAMEBUFFER,
2041 bound_fbo,
2042 GL_FRAMEBUFFER,
2046 TEST_P(GLES2DecoderWithShaderTest, TextureChangesMarkFBOAsNotCompleteBoundFBO) {
2047 CheckTextureChangesMarkFBOAsNotComplete(true);
2050 TEST_P(GLES2DecoderWithShaderTest,
2051 TextureChangesMarkFBOAsNotCompleteUnboundFBO) {
2052 CheckTextureChangesMarkFBOAsNotComplete(false);
2055 TEST_P(GLES2DecoderTest, CanChangeSurface) {
2056 scoped_refptr<GLSurfaceMock> other_surface(new GLSurfaceMock);
2057 EXPECT_CALL(*other_surface.get(), GetBackingFrameBufferObject())
2058 .WillOnce(Return(7));
2059 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 7));
2061 decoder_->SetSurface(other_surface);
2064 TEST_P(GLES2DecoderTest, DrawBuffersEXTImmediateSuccceeds) {
2065 const GLsizei count = 1;
2066 const GLenum bufs[] = {GL_COLOR_ATTACHMENT0};
2067 DrawBuffersEXTImmediate& cmd = *GetImmediateAs<DrawBuffersEXTImmediate>();
2068 cmd.Init(count, bufs);
2070 DoBindFramebuffer(
2071 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2072 EXPECT_CALL(*gl_, DrawBuffersARB(count, _)).Times(1).RetiresOnSaturation();
2073 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(bufs)));
2074 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2077 TEST_P(GLES2DecoderTest, DrawBuffersEXTImmediateFails) {
2078 const GLsizei count = 1;
2079 const GLenum bufs[] = {GL_COLOR_ATTACHMENT1_EXT};
2080 DrawBuffersEXTImmediate& cmd = *GetImmediateAs<DrawBuffersEXTImmediate>();
2081 cmd.Init(count, bufs);
2083 DoBindFramebuffer(
2084 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2085 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(bufs)));
2086 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2089 TEST_P(GLES2DecoderTest, DrawBuffersEXTImmediateBackbuffer) {
2090 const GLsizei count = 1;
2091 const GLenum bufs[] = {GL_BACK};
2092 DrawBuffersEXTImmediate& cmd = *GetImmediateAs<DrawBuffersEXTImmediate>();
2093 cmd.Init(count, bufs);
2095 DoBindFramebuffer(
2096 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2097 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(bufs)));
2098 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2100 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0); // unbind
2102 EXPECT_CALL(*gl_, DrawBuffersARB(count, _)).Times(1).RetiresOnSaturation();
2104 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(bufs)));
2105 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2108 TEST_P(GLES2DecoderManualInitTest, InvalidateFramebufferBinding) {
2109 InitState init;
2110 init.gl_version = "opengl es 3.0";
2111 InitDecoder(init);
2113 // EXPECT_EQ can't be used to compare function pointers
2114 EXPECT_TRUE(
2115 gfx::MockGLInterface::GetGLProcAddress("glInvalidateFramebuffer") !=
2116 gfx::g_driver_gl.fn.glDiscardFramebufferEXTFn);
2117 EXPECT_TRUE(
2118 gfx::MockGLInterface::GetGLProcAddress("glInvalidateFramebuffer") !=
2119 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT"));
2122 TEST_P(GLES2DecoderManualInitTest, DiscardFramebufferEXT) {
2123 InitState init;
2124 init.extensions = "GL_EXT_discard_framebuffer";
2125 init.gl_version = "opengl es 2.0";
2126 InitDecoder(init);
2128 // EXPECT_EQ can't be used to compare function pointers
2129 EXPECT_TRUE(
2130 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT") ==
2131 gfx::g_driver_gl.fn.glDiscardFramebufferEXTFn);
2133 const GLenum target = GL_FRAMEBUFFER;
2134 const GLsizei count = 1;
2135 const GLenum attachments[] = {GL_COLOR_ATTACHMENT0};
2137 SetupTexture();
2138 DoBindFramebuffer(
2139 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2140 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2141 GL_COLOR_ATTACHMENT0,
2142 GL_TEXTURE_2D,
2143 client_texture_id_,
2144 kServiceTextureId,
2146 GL_NO_ERROR);
2147 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
2148 Framebuffer* framebuffer =
2149 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
2150 EXPECT_TRUE(framebuffer->IsCleared());
2152 EXPECT_CALL(*gl_, DiscardFramebufferEXT(target, count, _))
2153 .Times(1)
2154 .RetiresOnSaturation();
2155 DiscardFramebufferEXTImmediate& cmd =
2156 *GetImmediateAs<DiscardFramebufferEXTImmediate>();
2157 cmd.Init(target, count, attachments);
2159 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(attachments)));
2160 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2161 EXPECT_FALSE(framebuffer->IsCleared());
2164 TEST_P(GLES2DecoderTest, DiscardFramebufferEXTUnsupported) {
2165 const GLenum target = GL_FRAMEBUFFER;
2166 const GLsizei count = 1;
2167 const GLenum attachments[] = {GL_COLOR_EXT};
2168 DiscardFramebufferEXTImmediate& cmd =
2169 *GetImmediateAs<DiscardFramebufferEXTImmediate>();
2170 cmd.Init(target, count, attachments);
2172 // Should not result into a call into GL.
2173 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(attachments)));
2174 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2177 TEST_P(GLES2DecoderManualInitTest,
2178 DiscardedAttachmentsEXTMarksFramebufferIncomplete) {
2179 InitState init;
2180 init.extensions = "GL_EXT_discard_framebuffer";
2181 init.gl_version = "opengl es 2.0";
2182 init.has_alpha = true;
2183 init.bind_generates_resource = true;
2184 InitDecoder(init);
2186 const GLuint kFBOClientTextureId = 4100;
2187 const GLuint kFBOServiceTextureId = 4101;
2189 // Register a texture id.
2190 EXPECT_CALL(*gl_, GenTextures(_, _))
2191 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2192 .RetiresOnSaturation();
2193 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2195 // Setup "render to" texture.
2196 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2197 DoTexImage2D(
2198 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2199 DoBindFramebuffer(
2200 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2201 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2202 GL_COLOR_ATTACHMENT0,
2203 GL_TEXTURE_2D,
2204 kFBOClientTextureId,
2205 kFBOServiceTextureId,
2207 GL_NO_ERROR);
2208 DoEnableDisable(GL_SCISSOR_TEST, false);
2209 DoScissor(0, 0, 1, 1);
2211 // Setup "render from" texture.
2212 SetupTexture();
2214 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
2215 GL_COLOR_BUFFER_BIT, // clear bits
2216 0, 0, 0,
2217 0, // color
2218 0, // stencil
2219 1.0f, // depth
2220 false, // scissor test
2221 0, 0, 1, 1);
2222 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2223 false, // Framebuffer has depth
2224 false, // Framebuffer has stencil
2225 0x1111, // color bits
2226 false, // depth mask
2227 false, // depth enabled
2228 0, // front stencil mask
2229 0, // back stencil mask
2230 false); // stencil enabled
2232 EXPECT_CALL(*gl_, Clear(GL_COLOR_BUFFER_BIT)).Times(1).RetiresOnSaturation();
2234 Clear clear_cmd;
2235 clear_cmd.Init(GL_COLOR_BUFFER_BIT);
2236 EXPECT_EQ(error::kNoError, ExecuteCmd(clear_cmd));
2237 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2239 // Check that framebuffer is cleared and complete.
2240 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
2241 Framebuffer* framebuffer =
2242 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
2243 EXPECT_TRUE(framebuffer->IsCleared());
2244 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
2246 // Check that Discard GL_COLOR_ATTACHMENT0, sets the attachment as uncleared
2247 // and the framebuffer as incomplete.
2248 EXPECT_TRUE(
2249 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT") ==
2250 gfx::g_driver_gl.fn.glDiscardFramebufferEXTFn);
2252 const GLenum target = GL_FRAMEBUFFER;
2253 const GLsizei count = 1;
2254 const GLenum attachments[] = {GL_COLOR_ATTACHMENT0};
2256 DiscardFramebufferEXTImmediate& discard_cmd =
2257 *GetImmediateAs<DiscardFramebufferEXTImmediate>();
2258 discard_cmd.Init(target, count, attachments);
2260 EXPECT_CALL(*gl_, DiscardFramebufferEXT(target, count, _))
2261 .Times(1)
2262 .RetiresOnSaturation();
2263 EXPECT_EQ(error::kNoError,
2264 ExecuteImmediateCmd(discard_cmd, sizeof(attachments)));
2265 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2266 EXPECT_FALSE(framebuffer->IsCleared());
2267 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
2270 TEST_P(GLES2DecoderManualInitTest, ReadFormatExtension) {
2271 InitState init;
2272 init.extensions = "GL_OES_read_format";
2273 init.bind_generates_resource = true;
2274 InitDecoder(init);
2276 EXPECT_CALL(*gl_, GetError())
2277 .WillOnce(Return(GL_NO_ERROR))
2278 .WillOnce(Return(GL_NO_ERROR))
2279 .WillOnce(Return(GL_NO_ERROR))
2280 .WillOnce(Return(GL_NO_ERROR))
2281 .RetiresOnSaturation();
2282 EXPECT_CALL(*gl_, GetError()).Times(6).RetiresOnSaturation();
2284 typedef GetIntegerv::Result Result;
2285 Result* result = static_cast<Result*>(shared_memory_address_);
2286 GetIntegerv cmd;
2287 const GLuint kFBOClientTextureId = 4100;
2288 const GLuint kFBOServiceTextureId = 4101;
2290 // Register a texture id.
2291 EXPECT_CALL(*gl_, GenTextures(_, _))
2292 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2293 .RetiresOnSaturation();
2294 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2296 // Setup "render to" texture.
2297 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2298 DoTexImage2D(
2299 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2300 DoBindFramebuffer(
2301 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2302 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2303 GL_COLOR_ATTACHMENT0,
2304 GL_TEXTURE_2D,
2305 kFBOClientTextureId,
2306 kFBOServiceTextureId,
2308 GL_NO_ERROR);
2310 result->size = 0;
2311 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(1).RetiresOnSaturation();
2312 cmd.Init(GL_IMPLEMENTATION_COLOR_READ_FORMAT,
2313 shared_memory_id_,
2314 shared_memory_offset_);
2315 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2316 EXPECT_EQ(1, result->GetNumResults());
2317 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2319 result->size = 0;
2320 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(1).RetiresOnSaturation();
2321 cmd.Init(GL_IMPLEMENTATION_COLOR_READ_TYPE,
2322 shared_memory_id_,
2323 shared_memory_offset_);
2324 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2325 EXPECT_EQ(1, result->GetNumResults());
2326 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2329 TEST_P(GLES2DecoderManualInitTest, NoReadFormatExtension) {
2330 InitState init;
2331 init.bind_generates_resource = true;
2332 InitDecoder(init);
2334 EXPECT_CALL(*gl_, GetError())
2335 .WillOnce(Return(GL_NO_ERROR))
2336 .WillOnce(Return(GL_NO_ERROR))
2337 .WillOnce(Return(GL_NO_ERROR))
2338 .WillOnce(Return(GL_NO_ERROR))
2339 .RetiresOnSaturation();
2341 typedef GetIntegerv::Result Result;
2342 Result* result = static_cast<Result*>(shared_memory_address_);
2343 GetIntegerv cmd;
2344 const GLuint kFBOClientTextureId = 4100;
2345 const GLuint kFBOServiceTextureId = 4101;
2347 // Register a texture id.
2348 EXPECT_CALL(*gl_, GenTextures(_, _))
2349 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2350 .RetiresOnSaturation();
2351 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2353 // Setup "render to" texture.
2354 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2355 DoTexImage2D(
2356 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2357 DoBindFramebuffer(
2358 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2359 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2360 GL_COLOR_ATTACHMENT0,
2361 GL_TEXTURE_2D,
2362 kFBOClientTextureId,
2363 kFBOServiceTextureId,
2365 GL_NO_ERROR);
2367 result->size = 0;
2368 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
2369 cmd.Init(GL_IMPLEMENTATION_COLOR_READ_FORMAT,
2370 shared_memory_id_,
2371 shared_memory_offset_);
2372 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2373 EXPECT_EQ(1, result->GetNumResults());
2374 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2376 result->size = 0;
2377 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
2378 cmd.Init(GL_IMPLEMENTATION_COLOR_READ_TYPE,
2379 shared_memory_id_,
2380 shared_memory_offset_);
2381 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2382 EXPECT_EQ(1, result->GetNumResults());
2383 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2386 // TODO(gman): PixelStorei
2388 // TODO(gman): SwapBuffers
2390 } // namespace gles2
2391 } // namespace gpu