Don't add an aura tooltip to bubble close buttons on Windows.
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest_framebuffers.cc
blob4255ffaa180a6253fd70b8143dd1860f83e1c619
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);
1679 // Setup "render from" texture.
1680 SetupTexture();
1682 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
1683 GL_COLOR_BUFFER_BIT, // clear bits
1687 0, // color
1688 0, // stencil
1689 1.0f, // depth
1690 false); // scissor test
1691 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1692 false, // Framebuffer has depth
1693 false, // Framebuffer has stencil
1694 0x1111, // color bits
1695 false, // depth mask
1696 false, // depth enabled
1697 0, // front stencil mask
1698 0, // back stencil mask
1699 false); // stencil enabled
1701 EXPECT_CALL(*gl_, Clear(GL_COLOR_BUFFER_BIT)).Times(1).RetiresOnSaturation();
1703 Clear cmd;
1704 cmd.Init(GL_COLOR_BUFFER_BIT);
1705 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1706 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1709 TEST_P(GLES2DecoderWithShaderTest, UnClearedAttachmentsGetClearedOnReadPixels) {
1710 const GLuint kFBOClientTextureId = 4100;
1711 const GLuint kFBOServiceTextureId = 4101;
1713 // Register a texture id.
1714 EXPECT_CALL(*gl_, GenTextures(_, _))
1715 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1716 .RetiresOnSaturation();
1717 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1719 // Setup "render to" texture.
1720 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1721 DoTexImage2D(
1722 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1723 DoBindFramebuffer(
1724 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1725 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1726 GL_COLOR_ATTACHMENT0,
1727 GL_TEXTURE_2D,
1728 kFBOClientTextureId,
1729 kFBOServiceTextureId,
1731 GL_NO_ERROR);
1733 // Setup "render from" texture.
1734 SetupTexture();
1736 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
1737 GL_COLOR_BUFFER_BIT, // clear bits
1741 0, // color
1742 0, // stencil
1743 1.0f, // depth
1744 false); // scissor test
1746 EXPECT_CALL(*gl_, GetError())
1747 .WillOnce(Return(GL_NO_ERROR))
1748 .WillOnce(Return(GL_NO_ERROR))
1749 .RetiresOnSaturation();
1750 EXPECT_CALL(*gl_, ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, _))
1751 .Times(1)
1752 .RetiresOnSaturation();
1753 typedef ReadPixels::Result Result;
1754 uint32 result_shm_id = kSharedMemoryId;
1755 uint32 result_shm_offset = kSharedMemoryOffset;
1756 uint32 pixels_shm_id = kSharedMemoryId;
1757 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
1758 ReadPixels cmd;
1759 cmd.Init(0,
1763 GL_RGBA,
1764 GL_UNSIGNED_BYTE,
1765 pixels_shm_id,
1766 pixels_shm_offset,
1767 result_shm_id,
1768 result_shm_offset,
1769 false);
1770 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1771 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1774 TEST_P(GLES2DecoderManualInitTest,
1775 UnClearedAttachmentsGetClearedOnReadPixelsAndDrawBufferGetsRestored) {
1776 InitState init;
1777 init.extensions = "GL_EXT_framebuffer_multisample";
1778 init.bind_generates_resource = true;
1779 InitDecoder(init);
1780 const GLuint kFBOClientTextureId = 4100;
1781 const GLuint kFBOServiceTextureId = 4101;
1783 // Register a texture id.
1784 EXPECT_CALL(*gl_, GenTextures(_, _))
1785 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1786 .RetiresOnSaturation();
1787 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1789 // Setup "render from" texture.
1790 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1791 DoTexImage2D(
1792 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1793 DoBindFramebuffer(
1794 GL_READ_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1795 DoFramebufferTexture2D(GL_READ_FRAMEBUFFER,
1796 GL_COLOR_ATTACHMENT0,
1797 GL_TEXTURE_2D,
1798 kFBOClientTextureId,
1799 kFBOServiceTextureId,
1801 GL_NO_ERROR);
1803 // Enable GL_SCISSOR_TEST to make sure we disable it in the clear,
1804 // then re-enable after.
1805 DoEnableDisable(GL_SCISSOR_TEST, true);
1807 SetupExpectationsForFramebufferClearingMulti(
1808 kServiceFramebufferId, // read framebuffer service id
1809 0, // backbuffer service id
1810 GL_READ_FRAMEBUFFER, // target
1811 GL_COLOR_BUFFER_BIT, // clear bits
1815 0, // color
1816 0, // stencil
1817 1.0f, // depth
1818 true); // scissor test
1820 EXPECT_CALL(*gl_, GetError())
1821 .WillOnce(Return(GL_NO_ERROR))
1822 .WillOnce(Return(GL_NO_ERROR))
1823 .RetiresOnSaturation();
1824 EXPECT_CALL(*gl_, ReadPixels(0, 0, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, _))
1825 .Times(1)
1826 .RetiresOnSaturation();
1827 typedef ReadPixels::Result Result;
1828 uint32 result_shm_id = kSharedMemoryId;
1829 uint32 result_shm_offset = kSharedMemoryOffset;
1830 uint32 pixels_shm_id = kSharedMemoryId;
1831 uint32 pixels_shm_offset = kSharedMemoryOffset + sizeof(Result);
1832 ReadPixels cmd;
1833 cmd.Init(0,
1837 GL_RGBA,
1838 GL_UNSIGNED_BYTE,
1839 pixels_shm_id,
1840 pixels_shm_offset,
1841 result_shm_id,
1842 result_shm_offset,
1843 false);
1844 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1845 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1848 TEST_P(GLES2DecoderWithShaderTest, CopyTexImageWithInCompleteFBOFails) {
1849 GLenum target = GL_TEXTURE_2D;
1850 GLint level = 0;
1851 GLenum internal_format = GL_RGBA;
1852 GLsizei width = 2;
1853 GLsizei height = 4;
1854 SetupTexture();
1855 DoBindRenderbuffer(
1856 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1857 DoBindFramebuffer(
1858 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1859 DoRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 0, 0, GL_NO_ERROR);
1860 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
1861 GL_COLOR_ATTACHMENT0,
1862 GL_RENDERBUFFER,
1863 client_renderbuffer_id_,
1864 kServiceRenderbufferId,
1865 GL_NO_ERROR);
1867 EXPECT_CALL(*gl_, CopyTexImage2D(_, _, _, _, _, _, _, _))
1868 .Times(0)
1869 .RetiresOnSaturation();
1870 CopyTexImage2D cmd;
1871 cmd.Init(target, level, internal_format, 0, 0, width, height);
1872 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1873 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION, GetGLError());
1876 void GLES2DecoderWithShaderTest::CheckRenderbufferChangesMarkFBOAsNotComplete(
1877 bool bound_fbo) {
1878 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
1879 SetupTexture();
1880 DoBindRenderbuffer(
1881 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1882 DoBindFramebuffer(
1883 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1884 DoRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
1885 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
1886 GL_COLOR_ATTACHMENT0,
1887 GL_RENDERBUFFER,
1888 client_renderbuffer_id_,
1889 kServiceRenderbufferId,
1890 GL_NO_ERROR);
1892 if (!bound_fbo) {
1893 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
1896 Framebuffer* framebuffer =
1897 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
1898 ASSERT_TRUE(framebuffer != NULL);
1899 framebuffer_manager->MarkAsComplete(framebuffer);
1900 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1902 // Test that renderbufferStorage marks fbo as not complete.
1903 DoRenderbufferStorage(GL_RENDERBUFFER, GL_RGBA4, GL_RGBA, 1, 1, GL_NO_ERROR);
1904 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
1905 framebuffer_manager->MarkAsComplete(framebuffer);
1906 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1908 // Test deleting renderbuffer marks fbo as not complete.
1909 DoDeleteRenderbuffer(client_renderbuffer_id_, kServiceRenderbufferId);
1910 if (bound_fbo) {
1911 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
1912 } else {
1913 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1915 // Cleanup
1916 DoDeleteFramebuffer(client_framebuffer_id_,
1917 kServiceFramebufferId,
1918 bound_fbo,
1919 GL_FRAMEBUFFER,
1921 bound_fbo,
1922 GL_FRAMEBUFFER,
1926 TEST_P(GLES2DecoderWithShaderTest,
1927 RenderbufferChangesMarkFBOAsNotCompleteBoundFBO) {
1928 CheckRenderbufferChangesMarkFBOAsNotComplete(true);
1931 TEST_P(GLES2DecoderWithShaderTest,
1932 RenderbufferChangesMarkFBOAsNotCompleteUnboundFBO) {
1933 CheckRenderbufferChangesMarkFBOAsNotComplete(false);
1936 void GLES2DecoderWithShaderTest::CheckTextureChangesMarkFBOAsNotComplete(
1937 bool bound_fbo) {
1938 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
1939 const GLuint kFBOClientTextureId = 4100;
1940 const GLuint kFBOServiceTextureId = 4101;
1942 // Register a texture id.
1943 EXPECT_CALL(*gl_, GenTextures(_, _))
1944 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
1945 .RetiresOnSaturation();
1946 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
1948 SetupTexture();
1950 // Setup "render to" texture.
1951 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
1952 DoTexImage2D(
1953 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
1954 DoBindFramebuffer(
1955 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1956 DoFramebufferTexture2D(GL_FRAMEBUFFER,
1957 GL_COLOR_ATTACHMENT0,
1958 GL_TEXTURE_2D,
1959 kFBOClientTextureId,
1960 kFBOServiceTextureId,
1962 GL_NO_ERROR);
1964 DoBindRenderbuffer(
1965 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
1966 DoBindFramebuffer(
1967 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
1968 DoRenderbufferStorage(GL_RENDERBUFFER,
1969 GL_DEPTH_COMPONENT16,
1970 GL_DEPTH_COMPONENT,
1973 GL_NO_ERROR);
1974 DoFramebufferRenderbuffer(GL_FRAMEBUFFER,
1975 GL_DEPTH_ATTACHMENT,
1976 GL_RENDERBUFFER,
1977 client_renderbuffer_id_,
1978 kServiceRenderbufferId,
1979 GL_NO_ERROR);
1981 if (!bound_fbo) {
1982 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
1985 Framebuffer* framebuffer =
1986 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
1987 ASSERT_TRUE(framebuffer != NULL);
1988 framebuffer_manager->MarkAsComplete(framebuffer);
1989 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1991 // Test TexImage2D marks fbo as not complete.
1992 DoTexImage2D(
1993 GL_TEXTURE_2D, 0, GL_RGB, 1, 1, 0, GL_RGB, GL_UNSIGNED_BYTE, 0, 0);
1994 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
1995 framebuffer_manager->MarkAsComplete(framebuffer);
1996 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
1998 // Test CopyImage2D marks fbo as not complete.
1999 EXPECT_CALL(*gl_, GetError())
2000 .WillOnce(Return(GL_NO_ERROR))
2001 .RetiresOnSaturation();
2002 EXPECT_CALL(*gl_, CopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 1, 1, 0))
2003 .Times(1)
2004 .RetiresOnSaturation();
2005 EXPECT_CALL(*gl_, GetError())
2006 .WillOnce(Return(GL_NO_ERROR))
2007 .RetiresOnSaturation();
2008 CopyTexImage2D cmd;
2009 cmd.Init(GL_TEXTURE_2D, 0, GL_RGB, 0, 0, 1, 1);
2010 // Unbind fbo and bind again after CopyTexImage2D tp avoid feedback loops.
2011 if (bound_fbo) {
2012 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0);
2014 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2015 if (bound_fbo) {
2016 DoBindFramebuffer(
2017 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2019 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
2021 // Test deleting texture marks fbo as not complete.
2022 framebuffer_manager->MarkAsComplete(framebuffer);
2023 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
2024 DoDeleteTexture(kFBOClientTextureId, kFBOServiceTextureId);
2026 if (bound_fbo) {
2027 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
2028 } else {
2029 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
2031 // Cleanup
2032 DoDeleteFramebuffer(client_framebuffer_id_,
2033 kServiceFramebufferId,
2034 bound_fbo,
2035 GL_FRAMEBUFFER,
2037 bound_fbo,
2038 GL_FRAMEBUFFER,
2042 TEST_P(GLES2DecoderWithShaderTest, TextureChangesMarkFBOAsNotCompleteBoundFBO) {
2043 CheckTextureChangesMarkFBOAsNotComplete(true);
2046 TEST_P(GLES2DecoderWithShaderTest,
2047 TextureChangesMarkFBOAsNotCompleteUnboundFBO) {
2048 CheckTextureChangesMarkFBOAsNotComplete(false);
2051 TEST_P(GLES2DecoderTest, CanChangeSurface) {
2052 scoped_refptr<GLSurfaceMock> other_surface(new GLSurfaceMock);
2053 EXPECT_CALL(*other_surface.get(), GetBackingFrameBufferObject())
2054 .WillOnce(Return(7));
2055 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER_EXT, 7));
2057 decoder_->SetSurface(other_surface);
2060 TEST_P(GLES2DecoderTest, DrawBuffersEXTImmediateSuccceeds) {
2061 const GLsizei count = 1;
2062 const GLenum bufs[] = {GL_COLOR_ATTACHMENT0};
2063 DrawBuffersEXTImmediate& cmd = *GetImmediateAs<DrawBuffersEXTImmediate>();
2064 cmd.Init(count, bufs);
2066 DoBindFramebuffer(
2067 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2068 EXPECT_CALL(*gl_, DrawBuffersARB(count, _)).Times(1).RetiresOnSaturation();
2069 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(bufs)));
2070 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2073 TEST_P(GLES2DecoderTest, DrawBuffersEXTImmediateFails) {
2074 const GLsizei count = 1;
2075 const GLenum bufs[] = {GL_COLOR_ATTACHMENT1_EXT};
2076 DrawBuffersEXTImmediate& cmd = *GetImmediateAs<DrawBuffersEXTImmediate>();
2077 cmd.Init(count, bufs);
2079 DoBindFramebuffer(
2080 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2081 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(bufs)));
2082 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2085 TEST_P(GLES2DecoderTest, DrawBuffersEXTImmediateBackbuffer) {
2086 const GLsizei count = 1;
2087 const GLenum bufs[] = {GL_BACK};
2088 DrawBuffersEXTImmediate& cmd = *GetImmediateAs<DrawBuffersEXTImmediate>();
2089 cmd.Init(count, bufs);
2091 DoBindFramebuffer(
2092 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2093 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(bufs)));
2094 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2096 DoBindFramebuffer(GL_FRAMEBUFFER, 0, 0); // unbind
2098 EXPECT_CALL(*gl_, DrawBuffersARB(count, _)).Times(1).RetiresOnSaturation();
2100 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(bufs)));
2101 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2104 TEST_P(GLES2DecoderManualInitTest, InvalidateFramebufferBinding) {
2105 InitState init;
2106 init.gl_version = "opengl es 3.0";
2107 InitDecoder(init);
2109 // EXPECT_EQ can't be used to compare function pointers
2110 EXPECT_TRUE(
2111 gfx::MockGLInterface::GetGLProcAddress("glInvalidateFramebuffer") !=
2112 gfx::g_driver_gl.fn.glDiscardFramebufferEXTFn);
2113 EXPECT_TRUE(
2114 gfx::MockGLInterface::GetGLProcAddress("glInvalidateFramebuffer") !=
2115 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT"));
2118 TEST_P(GLES2DecoderManualInitTest, DiscardFramebufferEXT) {
2119 InitState init;
2120 init.extensions = "GL_EXT_discard_framebuffer";
2121 init.gl_version = "opengl es 2.0";
2122 InitDecoder(init);
2124 // EXPECT_EQ can't be used to compare function pointers
2125 EXPECT_TRUE(
2126 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT") ==
2127 gfx::g_driver_gl.fn.glDiscardFramebufferEXTFn);
2129 const GLenum target = GL_FRAMEBUFFER;
2130 const GLsizei count = 1;
2131 const GLenum attachments[] = {GL_COLOR_ATTACHMENT0};
2133 SetupTexture();
2134 DoBindFramebuffer(
2135 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2136 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2137 GL_COLOR_ATTACHMENT0,
2138 GL_TEXTURE_2D,
2139 client_texture_id_,
2140 kServiceTextureId,
2142 GL_NO_ERROR);
2143 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
2144 Framebuffer* framebuffer =
2145 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
2146 EXPECT_TRUE(framebuffer->IsCleared());
2148 EXPECT_CALL(*gl_, DiscardFramebufferEXT(target, count, _))
2149 .Times(1)
2150 .RetiresOnSaturation();
2151 DiscardFramebufferEXTImmediate& cmd =
2152 *GetImmediateAs<DiscardFramebufferEXTImmediate>();
2153 cmd.Init(target, count, attachments);
2155 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(attachments)));
2156 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2157 EXPECT_FALSE(framebuffer->IsCleared());
2160 TEST_P(GLES2DecoderTest, DiscardFramebufferEXTUnsupported) {
2161 const GLenum target = GL_FRAMEBUFFER;
2162 const GLsizei count = 1;
2163 const GLenum attachments[] = {GL_COLOR_EXT};
2164 DiscardFramebufferEXTImmediate& cmd =
2165 *GetImmediateAs<DiscardFramebufferEXTImmediate>();
2166 cmd.Init(target, count, attachments);
2168 // Should not result into a call into GL.
2169 EXPECT_EQ(error::kNoError, ExecuteImmediateCmd(cmd, sizeof(attachments)));
2170 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
2173 TEST_P(GLES2DecoderManualInitTest,
2174 DiscardedAttachmentsEXTMarksFramebufferIncomplete) {
2175 InitState init;
2176 init.extensions = "GL_EXT_discard_framebuffer";
2177 init.gl_version = "opengl es 2.0";
2178 init.has_alpha = true;
2179 init.bind_generates_resource = true;
2180 InitDecoder(init);
2182 const GLuint kFBOClientTextureId = 4100;
2183 const GLuint kFBOServiceTextureId = 4101;
2185 // Register a texture id.
2186 EXPECT_CALL(*gl_, GenTextures(_, _))
2187 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2188 .RetiresOnSaturation();
2189 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2191 // Setup "render to" texture.
2192 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2193 DoTexImage2D(
2194 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2195 DoBindFramebuffer(
2196 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2197 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2198 GL_COLOR_ATTACHMENT0,
2199 GL_TEXTURE_2D,
2200 kFBOClientTextureId,
2201 kFBOServiceTextureId,
2203 GL_NO_ERROR);
2205 // Setup "render from" texture.
2206 SetupTexture();
2208 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER, // target
2209 GL_COLOR_BUFFER_BIT, // clear bits
2213 0, // color
2214 0, // stencil
2215 1.0f, // depth
2216 false); // scissor test
2217 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2218 false, // Framebuffer has depth
2219 false, // Framebuffer has stencil
2220 0x1111, // color bits
2221 false, // depth mask
2222 false, // depth enabled
2223 0, // front stencil mask
2224 0, // back stencil mask
2225 false); // stencil enabled
2227 EXPECT_CALL(*gl_, Clear(GL_COLOR_BUFFER_BIT)).Times(1).RetiresOnSaturation();
2229 Clear clear_cmd;
2230 clear_cmd.Init(GL_COLOR_BUFFER_BIT);
2231 EXPECT_EQ(error::kNoError, ExecuteCmd(clear_cmd));
2232 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2234 // Check that framebuffer is cleared and complete.
2235 FramebufferManager* framebuffer_manager = group().framebuffer_manager();
2236 Framebuffer* framebuffer =
2237 framebuffer_manager->GetFramebuffer(client_framebuffer_id_);
2238 EXPECT_TRUE(framebuffer->IsCleared());
2239 EXPECT_TRUE(framebuffer_manager->IsComplete(framebuffer));
2241 // Check that Discard GL_COLOR_ATTACHMENT0, sets the attachment as uncleared
2242 // and the framebuffer as incomplete.
2243 EXPECT_TRUE(
2244 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT") ==
2245 gfx::g_driver_gl.fn.glDiscardFramebufferEXTFn);
2247 const GLenum target = GL_FRAMEBUFFER;
2248 const GLsizei count = 1;
2249 const GLenum attachments[] = {GL_COLOR_ATTACHMENT0};
2251 DiscardFramebufferEXTImmediate& discard_cmd =
2252 *GetImmediateAs<DiscardFramebufferEXTImmediate>();
2253 discard_cmd.Init(target, count, attachments);
2255 EXPECT_CALL(*gl_, DiscardFramebufferEXT(target, count, _))
2256 .Times(1)
2257 .RetiresOnSaturation();
2258 EXPECT_EQ(error::kNoError,
2259 ExecuteImmediateCmd(discard_cmd, sizeof(attachments)));
2260 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2261 EXPECT_FALSE(framebuffer->IsCleared());
2262 EXPECT_FALSE(framebuffer_manager->IsComplete(framebuffer));
2265 TEST_P(GLES2DecoderManualInitTest, ReadFormatExtension) {
2266 InitState init;
2267 init.extensions = "GL_OES_read_format";
2268 init.bind_generates_resource = true;
2269 InitDecoder(init);
2271 EXPECT_CALL(*gl_, GetError())
2272 .WillOnce(Return(GL_NO_ERROR))
2273 .WillOnce(Return(GL_NO_ERROR))
2274 .WillOnce(Return(GL_NO_ERROR))
2275 .WillOnce(Return(GL_NO_ERROR))
2276 .RetiresOnSaturation();
2277 EXPECT_CALL(*gl_, GetError()).Times(6).RetiresOnSaturation();
2279 typedef GetIntegerv::Result Result;
2280 Result* result = static_cast<Result*>(shared_memory_address_);
2281 GetIntegerv cmd;
2282 const GLuint kFBOClientTextureId = 4100;
2283 const GLuint kFBOServiceTextureId = 4101;
2285 // Register a texture id.
2286 EXPECT_CALL(*gl_, GenTextures(_, _))
2287 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2288 .RetiresOnSaturation();
2289 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2291 // Setup "render to" texture.
2292 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2293 DoTexImage2D(
2294 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2295 DoBindFramebuffer(
2296 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2297 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2298 GL_COLOR_ATTACHMENT0,
2299 GL_TEXTURE_2D,
2300 kFBOClientTextureId,
2301 kFBOServiceTextureId,
2303 GL_NO_ERROR);
2305 result->size = 0;
2306 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(1).RetiresOnSaturation();
2307 cmd.Init(GL_IMPLEMENTATION_COLOR_READ_FORMAT,
2308 shared_memory_id_,
2309 shared_memory_offset_);
2310 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2311 EXPECT_EQ(1, result->GetNumResults());
2312 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2314 result->size = 0;
2315 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(1).RetiresOnSaturation();
2316 cmd.Init(GL_IMPLEMENTATION_COLOR_READ_TYPE,
2317 shared_memory_id_,
2318 shared_memory_offset_);
2319 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2320 EXPECT_EQ(1, result->GetNumResults());
2321 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2324 TEST_P(GLES2DecoderManualInitTest, NoReadFormatExtension) {
2325 InitState init;
2326 init.bind_generates_resource = true;
2327 InitDecoder(init);
2329 EXPECT_CALL(*gl_, GetError())
2330 .WillOnce(Return(GL_NO_ERROR))
2331 .WillOnce(Return(GL_NO_ERROR))
2332 .WillOnce(Return(GL_NO_ERROR))
2333 .WillOnce(Return(GL_NO_ERROR))
2334 .RetiresOnSaturation();
2336 typedef GetIntegerv::Result Result;
2337 Result* result = static_cast<Result*>(shared_memory_address_);
2338 GetIntegerv cmd;
2339 const GLuint kFBOClientTextureId = 4100;
2340 const GLuint kFBOServiceTextureId = 4101;
2342 // Register a texture id.
2343 EXPECT_CALL(*gl_, GenTextures(_, _))
2344 .WillOnce(SetArgumentPointee<1>(kFBOServiceTextureId))
2345 .RetiresOnSaturation();
2346 GenHelper<GenTexturesImmediate>(kFBOClientTextureId);
2348 // Setup "render to" texture.
2349 DoBindTexture(GL_TEXTURE_2D, kFBOClientTextureId, kFBOServiceTextureId);
2350 DoTexImage2D(
2351 GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0, 0);
2352 DoBindFramebuffer(
2353 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
2354 DoFramebufferTexture2D(GL_FRAMEBUFFER,
2355 GL_COLOR_ATTACHMENT0,
2356 GL_TEXTURE_2D,
2357 kFBOClientTextureId,
2358 kFBOServiceTextureId,
2360 GL_NO_ERROR);
2362 result->size = 0;
2363 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
2364 cmd.Init(GL_IMPLEMENTATION_COLOR_READ_FORMAT,
2365 shared_memory_id_,
2366 shared_memory_offset_);
2367 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2368 EXPECT_EQ(1, result->GetNumResults());
2369 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2371 result->size = 0;
2372 EXPECT_CALL(*gl_, GetIntegerv(_, _)).Times(0).RetiresOnSaturation();
2373 cmd.Init(GL_IMPLEMENTATION_COLOR_READ_TYPE,
2374 shared_memory_id_,
2375 shared_memory_offset_);
2376 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
2377 EXPECT_EQ(1, result->GetNumResults());
2378 EXPECT_EQ(GL_NO_ERROR, GetGLError());
2381 // TODO(gman): PixelStorei
2383 // TODO(gman): SwapBuffers
2385 } // namespace gles2
2386 } // namespace gpu