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
35 using ::gfx::MockGLInterface
;
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
;
56 class GLES2DecoderTestWithExtensionsOnGLES2
: public GLES2DecoderTest
{
58 GLES2DecoderTestWithExtensionsOnGLES2() {}
60 void SetUp() override
{}
61 void Init(const char* extensions
) {
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;
73 TEST_P(GLES2DecoderTest
, CheckFramebufferStatusWithNoBoundTarget
) {
74 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(_
)).Times(0);
75 CheckFramebufferStatus::Result
* result
=
76 static_cast<CheckFramebufferStatus::Result
*>(shared_memory_address_
);
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
) {
86 AddExpectationsForSimulatedAttrib0(kNumVertices
, 0);
87 SetupExpectationsForApplyingDefaultDirtyState();
89 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
90 DoDeleteFramebuffer(client_framebuffer_id_
,
91 kServiceFramebufferId
,
98 EXPECT_CALL(*gl_
, DrawArrays(GL_TRIANGLES
, 0, kNumVertices
))
100 .RetiresOnSaturation();
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
,
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
,
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(_
, _
, _
, _
))
136 GetFramebufferAttachmentParameteriv cmd
;
137 cmd
.Init(GL_FRAMEBUFFER
,
138 GL_COLOR_ATTACHMENT0
,
139 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE
,
141 shared_memory_offset_
);
142 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
143 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
146 TEST_P(GLES2DecoderTest
, GetFramebufferAttachmentParameterivWithRenderbuffer
) {
148 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
149 EXPECT_CALL(*gl_
, GetError())
150 .WillOnce(Return(GL_NO_ERROR
))
151 .RetiresOnSaturation();
153 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
154 GL_COLOR_ATTACHMENT0
,
156 kServiceRenderbufferId
))
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_
);
170 const GLint
* result_value
= result
->GetData();
171 FramebufferRenderbuffer fbrb_cmd
;
172 GetFramebufferAttachmentParameteriv cmd
;
173 fbrb_cmd
.Init(GL_FRAMEBUFFER
,
174 GL_COLOR_ATTACHMENT0
,
176 client_renderbuffer_id_
);
177 cmd
.Init(GL_FRAMEBUFFER
,
178 GL_COLOR_ATTACHMENT0
,
179 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
,
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
) {
190 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
191 EXPECT_CALL(*gl_
, GetError())
192 .WillOnce(Return(GL_NO_ERROR
))
193 .RetiresOnSaturation();
195 FramebufferTexture2DEXT(GL_FRAMEBUFFER
,
196 GL_COLOR_ATTACHMENT0
,
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
,
220 cmd
.Init(GL_FRAMEBUFFER
,
221 GL_COLOR_ATTACHMENT0
,
222 GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME
,
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
) {
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
,
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();
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
,
268 shared_memory_offset_
);
269 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
270 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
273 TEST_P(GLES2DecoderWithShaderTest
, RenderbufferStorageRebindRenderbuffer
) {
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());
292 // A class to emulate glReadPixels
293 class ReadPixelsEmulator
{
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
,
299 GLint bytes_per_pixel
,
300 const void* src_pixels
,
301 const void* expected_pixels
,
302 GLint pack_alignment
)
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
,
316 void* pixels
) const {
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
,
331 const void* data
) const {
332 DCHECK(x
+ width
<= width_
|| width
== 0);
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
,
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_
;
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
;
358 return height
* row_size
;
363 const int8
* GetPixelAddress(const int8
* base
, GLint x
, GLint y
) const {
364 return base
+ (width_
* y
+ x
) * bytes_per_pixel_
;
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
,
379 GLsizei in_read_width
,
380 GLsizei in_read_height
,
382 const GLsizei kWidth
= 5;
383 const GLsizei kHeight
= 3;
384 const GLint kBytesPerPixel
= 4;
385 const GLint kPackAlignment
= 4;
386 const GLenum kFormat
= GL_RGBA
;
387 static const uint8 kSrcPixels
[kWidth
* kHeight
* kBytesPerPixel
] = {
388 12, 13, 14, 255, 18, 19, 18, 255, 19, 12, 13, 255, 14, 18, 19, 255,
389 18, 19, 13, 255, 29, 28, 23, 255, 22, 21, 22, 255, 21, 29, 28, 255,
390 23, 22, 21, 255, 22, 21, 28, 255, 31, 34, 39, 255, 37, 32, 37, 255,
391 32, 31, 34, 255, 39, 37, 32, 255, 37, 32, 34, 255
396 // We need to setup an FBO so we can know the max size that ReadPixels will
399 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
400 DoTexImage2D(GL_TEXTURE_2D
,
409 kSharedMemoryOffset
);
411 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
412 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
413 GL_COLOR_ATTACHMENT0
,
419 EXPECT_CALL(*gl_
, CheckFramebufferStatusEXT(GL_FRAMEBUFFER
))
420 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE
))
421 .RetiresOnSaturation();
424 ReadPixelsEmulator
emu(
425 kWidth
, kHeight
, kBytesPerPixel
, kSrcPixels
, kSrcPixels
, kPackAlignment
);
426 typedef ReadPixels::Result Result
;
427 Result
* result
= GetSharedMemoryAs
<Result
*>();
428 uint32 result_shm_id
= kSharedMemoryId
;
429 uint32 result_shm_offset
= kSharedMemoryOffset
;
430 uint32 pixels_shm_id
= kSharedMemoryId
;
431 uint32 pixels_shm_offset
= kSharedMemoryOffset
+ sizeof(*result
);
432 void* dest
= &result
[1];
433 EXPECT_CALL(*gl_
, GetError())
434 .WillOnce(Return(GL_NO_ERROR
))
435 .WillOnce(Return(GL_NO_ERROR
))
436 .RetiresOnSaturation();
437 // ReadPixels will be called for valid size only even though the command
438 // is requesting a larger size.
439 GLint read_x
= std::max(0, in_read_x
);
440 GLint read_y
= std::max(0, in_read_y
);
441 GLint read_end_x
= std::max(0, std::min(kWidth
, in_read_x
+ in_read_width
));
442 GLint read_end_y
= std::max(0, std::min(kHeight
, in_read_y
+ in_read_height
));
443 GLint read_width
= read_end_x
- read_x
;
444 GLint read_height
= read_end_y
- read_y
;
445 if (read_width
> 0 && read_height
> 0) {
446 for (GLint yy
= read_y
; yy
< read_end_y
; ++yy
) {
449 ReadPixels(read_x
, yy
, read_width
, 1, kFormat
, GL_UNSIGNED_BYTE
, _
))
450 .WillOnce(Invoke(&emu
, &ReadPixelsEmulator::ReadPixels
))
451 .RetiresOnSaturation();
466 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
468 GLint unpadded_row_size
= emu
.ComputeImageDataSize(in_read_width
, 1);
469 scoped_ptr
<int8
[]> zero(new int8
[unpadded_row_size
]);
470 scoped_ptr
<int8
[]> pack(new int8
[kPackAlignment
]);
471 memset(zero
.get(), 0, unpadded_row_size
);
472 memset(pack
.get(), kInitialMemoryValue
, kPackAlignment
);
473 for (GLint yy
= 0; yy
< in_read_height
; ++yy
) {
474 const int8
* row
= static_cast<const int8
*>(
475 emu
.ComputePackAlignmentAddress(0, yy
, in_read_width
, dest
));
476 GLint y
= in_read_y
+ yy
;
477 if (y
< 0 || y
>= kHeight
) {
478 EXPECT_EQ(0, memcmp(zero
.get(), row
, unpadded_row_size
));
481 GLint num_left_pixels
= std::max(-in_read_x
, 0);
482 GLint num_left_bytes
= num_left_pixels
* kBytesPerPixel
;
483 EXPECT_EQ(0, memcmp(zero
.get(), row
, num_left_bytes
));
486 GLint num_right_pixels
= std::max(in_read_x
+ in_read_width
- kWidth
, 0);
487 GLint num_right_bytes
= num_right_pixels
* kBytesPerPixel
;
490 row
+ unpadded_row_size
- num_right_bytes
,
494 GLint x
= std::max(in_read_x
, 0);
495 GLint num_middle_pixels
=
496 std::max(in_read_width
- num_left_pixels
- num_right_pixels
, 0);
498 emu
.CompareRowSegment(x
, y
, num_middle_pixels
, row
+ num_left_bytes
));
502 if (yy
!= in_read_height
- 1) {
503 GLint temp
= unpadded_row_size
+ kPackAlignment
- 1;
504 GLint padded_row_size
= (temp
/ kPackAlignment
) * kPackAlignment
;
505 GLint num_padding_bytes
= padded_row_size
- unpadded_row_size
;
506 if (num_padding_bytes
) {
507 EXPECT_EQ(0, memcmp(pack
.get(),
508 row
+ unpadded_row_size
, num_padding_bytes
));
514 TEST_P(GLES2DecoderTest
, ReadPixels
) {
515 const GLsizei kWidth
= 5;
516 const GLsizei kHeight
= 3;
517 const GLint kBytesPerPixel
= 4;
518 const GLint kPackAlignment
= 4;
519 static const uint8 kSrcPixels
[kWidth
* kHeight
* kBytesPerPixel
] = {
520 12, 13, 14, 255, 18, 19, 18, 255, 19, 12, 13, 255, 14, 18, 19, 255,
521 18, 19, 13, 255, 29, 28, 23, 255, 22, 21, 22, 255, 21, 29, 28, 255,
522 23, 22, 21, 255, 22, 21, 28, 255, 31, 34, 39, 255, 37, 32, 37, 255,
523 32, 31, 34, 255, 39, 37, 32, 255, 37, 32, 34, 255
526 surface_
->SetSize(gfx::Size(INT_MAX
, INT_MAX
));
528 ReadPixelsEmulator
emu(
529 kWidth
, kHeight
, kBytesPerPixel
, kSrcPixels
, kSrcPixels
, kPackAlignment
);
530 typedef ReadPixels::Result Result
;
531 Result
* result
= GetSharedMemoryAs
<Result
*>();
532 uint32 result_shm_id
= kSharedMemoryId
;
533 uint32 result_shm_offset
= kSharedMemoryOffset
;
534 uint32 pixels_shm_id
= kSharedMemoryId
;
535 uint32 pixels_shm_offset
= kSharedMemoryOffset
+ sizeof(*result
);
536 void* dest
= &result
[1];
537 EXPECT_CALL(*gl_
, GetError())
538 .WillOnce(Return(GL_NO_ERROR
))
539 .WillOnce(Return(GL_NO_ERROR
))
540 .RetiresOnSaturation();
542 ReadPixels(0, 0, kWidth
, kHeight
, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
543 .WillOnce(Invoke(&emu
, &ReadPixelsEmulator::ReadPixels
));
556 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
557 for (GLint yy
= 0; yy
< kHeight
; ++yy
) {
558 EXPECT_TRUE(emu
.CompareRowSegment(
559 0, yy
, kWidth
, emu
.ComputePackAlignmentAddress(0, yy
, kWidth
, dest
)));
563 TEST_P(GLES2DecoderRGBBackbufferTest
, ReadPixelsNoAlphaBackbuffer
) {
564 const GLsizei kWidth
= 3;
565 const GLsizei kHeight
= 3;
566 const GLint kBytesPerPixel
= 4;
567 const GLint kPackAlignment
= 4;
568 static const uint8 kExpectedPixels
[kWidth
* kHeight
* kBytesPerPixel
] = {
569 12, 13, 14, 255, 19, 18, 19, 255, 13, 14, 18, 255,
570 29, 28, 23, 255, 21, 22, 21, 255, 28, 23, 22, 255,
571 31, 34, 39, 255, 32, 37, 32, 255, 34, 39, 37, 255,
573 static const uint8 kSrcPixels
[kWidth
* kHeight
* kBytesPerPixel
] = {
574 12, 13, 14, 18, 19, 18, 19, 12, 13, 14, 18, 19, 29, 28, 23, 22, 21, 22,
575 21, 29, 28, 23, 22, 21, 31, 34, 39, 37, 32, 37, 32, 31, 34, 39, 37, 32,
578 surface_
->SetSize(gfx::Size(INT_MAX
, INT_MAX
));
580 ReadPixelsEmulator
emu(kWidth
,
586 typedef ReadPixels::Result Result
;
587 Result
* result
= GetSharedMemoryAs
<Result
*>();
588 uint32 result_shm_id
= kSharedMemoryId
;
589 uint32 result_shm_offset
= kSharedMemoryOffset
;
590 uint32 pixels_shm_id
= kSharedMemoryId
;
591 uint32 pixels_shm_offset
= kSharedMemoryOffset
+ sizeof(*result
);
592 void* dest
= &result
[1];
593 EXPECT_CALL(*gl_
, GetError())
594 .WillOnce(Return(GL_NO_ERROR
))
595 .WillOnce(Return(GL_NO_ERROR
))
596 .RetiresOnSaturation();
598 ReadPixels(0, 0, kWidth
, kHeight
, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
599 .WillOnce(Invoke(&emu
, &ReadPixelsEmulator::ReadPixels
));
612 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
613 for (GLint yy
= 0; yy
< kHeight
; ++yy
) {
614 EXPECT_TRUE(emu
.CompareRowSegment(
615 0, yy
, kWidth
, emu
.ComputePackAlignmentAddress(0, yy
, kWidth
, dest
)));
619 TEST_P(GLES2DecoderTest
, ReadPixelsOutOfRange
) {
620 static GLint tests
[][4] = {
623 }, // out of range on all sides
626 }, // out of range on right, bottom
629 }, // out of range on left, top
632 }, // completely off top
635 }, // completely off bottom
638 }, // completely off left
641 }, // completely off right
644 for (size_t tt
= 0; tt
< arraysize(tests
); ++tt
) {
645 CheckReadPixelsOutOfRange(
646 tests
[tt
][0], tests
[tt
][1], tests
[tt
][2], tests
[tt
][3], tt
== 0);
650 TEST_P(GLES2DecoderTest
, ReadPixelsInvalidArgs
) {
651 typedef ReadPixels::Result Result
;
652 uint32 result_shm_id
= kSharedMemoryId
;
653 uint32 result_shm_offset
= kSharedMemoryOffset
;
654 uint32 pixels_shm_id
= kSharedMemoryId
;
655 uint32 pixels_shm_offset
= kSharedMemoryOffset
+ sizeof(Result
);
656 EXPECT_CALL(*gl_
, ReadPixels(_
, _
, _
, _
, _
, _
, _
)).Times(0);
669 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
670 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
682 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
683 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
695 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
696 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
703 kInvalidSharedMemoryId
,
708 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
716 kInvalidSharedMemoryOffset
,
720 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
729 kInvalidSharedMemoryId
,
732 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
742 kInvalidSharedMemoryOffset
,
744 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
747 TEST_P(GLES2DecoderManualInitTest
, ReadPixelsAsyncError
) {
749 init
.extensions
= "GL_ARB_sync";
750 init
.gl_version
= "opengl es 3.0";
751 init
.has_alpha
= true;
752 init
.request_alpha
= true;
753 init
.bind_generates_resource
= true;
756 typedef ReadPixels::Result Result
;
758 const GLsizei kWidth
= 4;
759 const GLsizei kHeight
= 4;
760 uint32 result_shm_id
= kSharedMemoryId
;
761 uint32 result_shm_offset
= kSharedMemoryOffset
;
762 uint32 pixels_shm_id
= kSharedMemoryId
;
763 uint32 pixels_shm_offset
= kSharedMemoryOffset
+ sizeof(Result
);
765 EXPECT_CALL(*gl_
, GetError())
766 // first error check must pass to get to the test
767 .WillOnce(Return(GL_NO_ERROR
))
768 // second check is after BufferData, simulate fail here
769 .WillOnce(Return(GL_INVALID_OPERATION
))
770 // third error check is fall-through call to sync ReadPixels
771 .WillOnce(Return(GL_NO_ERROR
))
772 .RetiresOnSaturation();
775 ReadPixels(0, 0, kWidth
, kHeight
, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
777 EXPECT_CALL(*gl_
, GenBuffersARB(1, _
)).Times(1);
778 EXPECT_CALL(*gl_
, DeleteBuffersARB(1, _
)).Times(1);
779 EXPECT_CALL(*gl_
, BindBuffer(GL_PIXEL_PACK_BUFFER_ARB
, _
)).Times(2);
781 BufferData(GL_PIXEL_PACK_BUFFER_ARB
, _
, NULL
, GL_STREAM_READ
))
796 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
799 // Check that if a renderbuffer is attached and GL returns
800 // GL_FRAMEBUFFER_COMPLETE that the buffer is cleared and state is restored.
801 TEST_P(GLES2DecoderTest
, FramebufferRenderbufferClearColor
) {
803 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
804 ClearColor color_cmd
;
805 ColorMask color_mask_cmd
;
807 FramebufferRenderbuffer cmd
;
808 color_cmd
.Init(0.1f
, 0.2f
, 0.3f
, 0.4f
);
809 color_mask_cmd
.Init(0, 1, 0, 1);
810 enable_cmd
.Init(GL_SCISSOR_TEST
);
811 cmd
.Init(GL_FRAMEBUFFER
,
812 GL_COLOR_ATTACHMENT0
,
814 client_renderbuffer_id_
);
816 EXPECT_CALL(*gl_
, ClearColor(0.1f
, 0.2f
, 0.3f
, 0.4f
))
818 .RetiresOnSaturation();
819 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST
, true);
820 EXPECT_CALL(*gl_
, GetError())
821 .WillOnce(Return(GL_NO_ERROR
))
822 .RetiresOnSaturation();
824 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
825 GL_COLOR_ATTACHMENT0
,
827 kServiceRenderbufferId
))
829 .RetiresOnSaturation();
830 EXPECT_CALL(*gl_
, GetError())
831 .WillOnce(Return(GL_NO_ERROR
))
832 .RetiresOnSaturation();
833 EXPECT_EQ(error::kNoError
, ExecuteCmd(color_cmd
));
834 EXPECT_EQ(error::kNoError
, ExecuteCmd(color_mask_cmd
));
835 EXPECT_EQ(error::kNoError
, ExecuteCmd(enable_cmd
));
836 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
839 TEST_P(GLES2DecoderTest
, FramebufferRenderbufferClearDepth
) {
841 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
842 ClearDepthf depth_cmd
;
843 DepthMask depth_mask_cmd
;
844 FramebufferRenderbuffer cmd
;
845 depth_cmd
.Init(0.5f
);
846 depth_mask_cmd
.Init(false);
847 cmd
.Init(GL_FRAMEBUFFER
,
850 client_renderbuffer_id_
);
852 EXPECT_CALL(*gl_
, ClearDepth(0.5f
)).Times(1).RetiresOnSaturation();
853 EXPECT_CALL(*gl_
, GetError())
854 .WillOnce(Return(GL_NO_ERROR
))
855 .RetiresOnSaturation();
857 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
860 kServiceRenderbufferId
))
862 .RetiresOnSaturation();
863 EXPECT_CALL(*gl_
, GetError())
864 .WillOnce(Return(GL_NO_ERROR
))
865 .RetiresOnSaturation();
866 EXPECT_EQ(error::kNoError
, ExecuteCmd(depth_cmd
));
867 EXPECT_EQ(error::kNoError
, ExecuteCmd(depth_mask_cmd
));
868 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
871 TEST_P(GLES2DecoderTest
, FramebufferRenderbufferClearStencil
) {
873 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
874 ClearStencil stencil_cmd
;
875 StencilMaskSeparate stencil_mask_separate_cmd
;
876 FramebufferRenderbuffer cmd
;
877 stencil_cmd
.Init(123);
878 stencil_mask_separate_cmd
.Init(GL_BACK
, 0x1234u
);
879 cmd
.Init(GL_FRAMEBUFFER
,
880 GL_STENCIL_ATTACHMENT
,
882 client_renderbuffer_id_
);
884 EXPECT_CALL(*gl_
, ClearStencil(123)).Times(1).RetiresOnSaturation();
885 EXPECT_CALL(*gl_
, GetError())
886 .WillOnce(Return(GL_NO_ERROR
))
887 .RetiresOnSaturation();
889 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
890 GL_STENCIL_ATTACHMENT
,
892 kServiceRenderbufferId
))
894 .RetiresOnSaturation();
895 EXPECT_CALL(*gl_
, GetError())
896 .WillOnce(Return(GL_NO_ERROR
))
897 .RetiresOnSaturation();
898 EXPECT_EQ(error::kNoError
, ExecuteCmd(stencil_cmd
));
899 EXPECT_EQ(error::kNoError
, ExecuteCmd(stencil_mask_separate_cmd
));
900 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
903 #if 0 // Turn this test on once we allow GL_DEPTH_STENCIL_ATTACHMENT
904 TEST_P(GLES2DecoderTest
, FramebufferRenderbufferClearDepthStencil
) {
905 DoBindFramebuffer(GL_FRAMEBUFFER
, client_framebuffer_id_
,
906 kServiceFramebufferId
);
907 ClearDepthf depth_cmd
;
908 ClearStencil stencil_cmd
;
909 FramebufferRenderbuffer cmd
;
910 depth_cmd
.Init(0.5f
);
911 stencil_cmd
.Init(123);
913 GL_FRAMEBUFFER
, GL_DEPTH_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
,
914 client_renderbuffer_id_
);
916 EXPECT_CALL(*gl_
, ClearDepth(0.5f
))
918 .RetiresOnSaturation();
919 EXPECT_CALL(*gl_
, ClearStencil(123))
921 .RetiresOnSaturation();
922 EXPECT_CALL(*gl_
, FramebufferRenderbufferEXT(
923 GL_FRAMEBUFFER
, GL_DEPTH_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
,
924 kServiceRenderbufferId
))
926 .RetiresOnSaturation();
927 EXPECT_EQ(error::kNoError
, ExecuteCmd(depth_cmd
));
928 EXPECT_EQ(error::kNoError
, ExecuteCmd(stencil_cmd
));
929 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
933 TEST_P(GLES2DecoderManualInitTest
, ActualAlphaMatchesRequestedAlpha
) {
935 init
.has_alpha
= true;
936 init
.request_alpha
= true;
937 init
.bind_generates_resource
= true;
940 EXPECT_CALL(*gl_
, GetError())
941 .WillOnce(Return(GL_NO_ERROR
))
942 .WillOnce(Return(GL_NO_ERROR
))
943 .RetiresOnSaturation();
944 typedef GetIntegerv::Result Result
;
945 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
948 cmd2
.Init(GL_ALPHA_BITS
, shared_memory_id_
, shared_memory_offset_
);
949 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
950 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_ALPHA_BITS
),
951 result
->GetNumResults());
952 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
953 EXPECT_EQ(8, result
->GetData()[0]);
956 TEST_P(GLES2DecoderManualInitTest
, ActualAlphaDoesNotMatchRequestedAlpha
) {
958 init
.has_alpha
= true;
959 init
.bind_generates_resource
= true;
962 EXPECT_CALL(*gl_
, GetError())
963 .WillOnce(Return(GL_NO_ERROR
))
964 .WillOnce(Return(GL_NO_ERROR
))
965 .RetiresOnSaturation();
966 typedef GetIntegerv::Result Result
;
967 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
970 cmd2
.Init(GL_ALPHA_BITS
, shared_memory_id_
, shared_memory_offset_
);
971 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
972 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_ALPHA_BITS
),
973 result
->GetNumResults());
974 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
975 EXPECT_EQ(0, result
->GetData()[0]);
978 TEST_P(GLES2DecoderManualInitTest
, ActualDepthMatchesRequestedDepth
) {
980 init
.has_depth
= true;
981 init
.request_depth
= true;
982 init
.bind_generates_resource
= true;
985 EXPECT_CALL(*gl_
, GetError())
986 .WillOnce(Return(GL_NO_ERROR
))
987 .WillOnce(Return(GL_NO_ERROR
))
988 .RetiresOnSaturation();
989 typedef GetIntegerv::Result Result
;
990 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
991 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_BITS
, _
))
992 .WillOnce(SetArgumentPointee
<1>(24))
993 .RetiresOnSaturation();
996 cmd2
.Init(GL_DEPTH_BITS
, shared_memory_id_
, shared_memory_offset_
);
997 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
998 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS
),
999 result
->GetNumResults());
1000 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1001 EXPECT_EQ(24, result
->GetData()[0]);
1004 TEST_P(GLES2DecoderManualInitTest
, ActualDepthDoesNotMatchRequestedDepth
) {
1006 init
.has_depth
= true;
1007 init
.bind_generates_resource
= true;
1010 EXPECT_CALL(*gl_
, GetError())
1011 .WillOnce(Return(GL_NO_ERROR
))
1012 .WillOnce(Return(GL_NO_ERROR
))
1013 .RetiresOnSaturation();
1014 typedef GetIntegerv::Result Result
;
1015 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1016 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_BITS
, _
))
1017 .WillOnce(SetArgumentPointee
<1>(24))
1018 .RetiresOnSaturation();
1021 cmd2
.Init(GL_DEPTH_BITS
, shared_memory_id_
, shared_memory_offset_
);
1022 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1023 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS
),
1024 result
->GetNumResults());
1025 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1026 EXPECT_EQ(0, result
->GetData()[0]);
1029 TEST_P(GLES2DecoderManualInitTest
, ActualStencilMatchesRequestedStencil
) {
1031 init
.has_stencil
= true;
1032 init
.request_stencil
= true;
1033 init
.bind_generates_resource
= true;
1036 EXPECT_CALL(*gl_
, GetError())
1037 .WillOnce(Return(GL_NO_ERROR
))
1038 .WillOnce(Return(GL_NO_ERROR
))
1039 .RetiresOnSaturation();
1040 typedef GetIntegerv::Result Result
;
1041 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1042 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_BITS
, _
))
1043 .WillOnce(SetArgumentPointee
<1>(8))
1044 .RetiresOnSaturation();
1047 cmd2
.Init(GL_STENCIL_BITS
, shared_memory_id_
, shared_memory_offset_
);
1048 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1049 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS
),
1050 result
->GetNumResults());
1051 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1052 EXPECT_EQ(8, result
->GetData()[0]);
1055 TEST_P(GLES2DecoderManualInitTest
, ActualStencilDoesNotMatchRequestedStencil
) {
1057 init
.has_stencil
= true;
1058 init
.bind_generates_resource
= true;
1061 EXPECT_CALL(*gl_
, GetError())
1062 .WillOnce(Return(GL_NO_ERROR
))
1063 .WillOnce(Return(GL_NO_ERROR
))
1064 .RetiresOnSaturation();
1065 typedef GetIntegerv::Result Result
;
1066 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1067 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_BITS
, _
))
1068 .WillOnce(SetArgumentPointee
<1>(8))
1069 .RetiresOnSaturation();
1072 cmd2
.Init(GL_STENCIL_BITS
, shared_memory_id_
, shared_memory_offset_
);
1073 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1074 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS
),
1075 result
->GetNumResults());
1076 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1077 EXPECT_EQ(0, result
->GetData()[0]);
1080 TEST_P(GLES2DecoderManualInitTest
, PackedDepthStencilReportsCorrectValues
) {
1082 init
.extensions
= "GL_OES_packed_depth_stencil";
1083 init
.gl_version
= "opengl es 2.0";
1084 init
.has_depth
= true;
1085 init
.has_stencil
= true;
1086 init
.request_depth
= true;
1087 init
.request_stencil
= true;
1088 init
.bind_generates_resource
= true;
1091 EXPECT_CALL(*gl_
, GetError())
1092 .WillOnce(Return(GL_NO_ERROR
))
1093 .WillOnce(Return(GL_NO_ERROR
))
1094 .WillOnce(Return(GL_NO_ERROR
))
1095 .WillOnce(Return(GL_NO_ERROR
))
1096 .RetiresOnSaturation();
1097 typedef GetIntegerv::Result Result
;
1098 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1101 cmd2
.Init(GL_STENCIL_BITS
, shared_memory_id_
, shared_memory_offset_
);
1102 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_BITS
, _
))
1103 .WillOnce(SetArgumentPointee
<1>(8))
1104 .RetiresOnSaturation();
1105 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1106 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS
),
1107 result
->GetNumResults());
1108 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1109 EXPECT_EQ(8, result
->GetData()[0]);
1111 cmd2
.Init(GL_DEPTH_BITS
, shared_memory_id_
, shared_memory_offset_
);
1112 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_BITS
, _
))
1113 .WillOnce(SetArgumentPointee
<1>(24))
1114 .RetiresOnSaturation();
1115 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1116 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS
),
1117 result
->GetNumResults());
1118 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1119 EXPECT_EQ(24, result
->GetData()[0]);
1122 TEST_P(GLES2DecoderManualInitTest
, PackedDepthStencilNoRequestedStencil
) {
1124 init
.extensions
= "GL_OES_packed_depth_stencil";
1125 init
.gl_version
= "opengl es 2.0";
1126 init
.has_depth
= true;
1127 init
.has_stencil
= true;
1128 init
.request_depth
= true;
1129 init
.bind_generates_resource
= true;
1132 EXPECT_CALL(*gl_
, GetError())
1133 .WillOnce(Return(GL_NO_ERROR
))
1134 .WillOnce(Return(GL_NO_ERROR
))
1135 .WillOnce(Return(GL_NO_ERROR
))
1136 .WillOnce(Return(GL_NO_ERROR
))
1137 .RetiresOnSaturation();
1138 typedef GetIntegerv::Result Result
;
1139 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1142 cmd2
.Init(GL_STENCIL_BITS
, shared_memory_id_
, shared_memory_offset_
);
1143 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_BITS
, _
))
1144 .WillOnce(SetArgumentPointee
<1>(8))
1145 .RetiresOnSaturation();
1146 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1147 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS
),
1148 result
->GetNumResults());
1149 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1150 EXPECT_EQ(0, result
->GetData()[0]);
1152 cmd2
.Init(GL_DEPTH_BITS
, shared_memory_id_
, shared_memory_offset_
);
1153 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_BITS
, _
))
1154 .WillOnce(SetArgumentPointee
<1>(24))
1155 .RetiresOnSaturation();
1156 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1157 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS
),
1158 result
->GetNumResults());
1159 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1160 EXPECT_EQ(24, result
->GetData()[0]);
1163 TEST_P(GLES2DecoderManualInitTest
, PackedDepthStencilRenderbufferDepth
) {
1165 init
.extensions
= "GL_OES_packed_depth_stencil";
1166 init
.gl_version
= "opengl es 2.0";
1167 init
.bind_generates_resource
= true;
1170 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1172 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1174 EnsureRenderbufferBound(false);
1175 EXPECT_CALL(*gl_
, GetError())
1176 .WillOnce(Return(GL_NO_ERROR
)) // for RenderbufferStoage
1177 .WillOnce(Return(GL_NO_ERROR
))
1178 .WillOnce(Return(GL_NO_ERROR
)) // for FramebufferRenderbuffer
1179 .WillOnce(Return(GL_NO_ERROR
))
1180 .WillOnce(Return(GL_NO_ERROR
)) // for GetIntegerv
1181 .WillOnce(Return(GL_NO_ERROR
))
1182 .WillOnce(Return(GL_NO_ERROR
)) // for GetIntegerv
1183 .WillOnce(Return(GL_NO_ERROR
))
1184 .RetiresOnSaturation();
1188 RenderbufferStorageEXT(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 100, 50))
1190 .RetiresOnSaturation();
1191 RenderbufferStorage cmd
;
1192 cmd
.Init(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 100, 50);
1193 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1195 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
1196 GL_DEPTH_ATTACHMENT
,
1198 kServiceRenderbufferId
))
1200 .RetiresOnSaturation();
1201 FramebufferRenderbuffer fbrb_cmd
;
1202 fbrb_cmd
.Init(GL_FRAMEBUFFER
,
1203 GL_DEPTH_ATTACHMENT
,
1205 client_renderbuffer_id_
);
1206 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbrb_cmd
));
1208 typedef GetIntegerv::Result Result
;
1209 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1212 cmd2
.Init(GL_STENCIL_BITS
, shared_memory_id_
, shared_memory_offset_
);
1213 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_BITS
, _
))
1214 .WillOnce(SetArgumentPointee
<1>(8))
1215 .RetiresOnSaturation();
1216 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1217 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS
),
1218 result
->GetNumResults());
1219 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1220 EXPECT_EQ(0, result
->GetData()[0]);
1222 cmd2
.Init(GL_DEPTH_BITS
, shared_memory_id_
, shared_memory_offset_
);
1223 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_BITS
, _
))
1224 .WillOnce(SetArgumentPointee
<1>(24))
1225 .RetiresOnSaturation();
1226 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1227 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS
),
1228 result
->GetNumResults());
1229 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1230 EXPECT_EQ(24, result
->GetData()[0]);
1233 TEST_P(GLES2DecoderManualInitTest
, PackedDepthStencilRenderbufferStencil
) {
1235 init
.extensions
= "GL_OES_packed_depth_stencil";
1236 init
.gl_version
= "opengl es 2.0";
1237 init
.bind_generates_resource
= true;
1240 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1242 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1244 EnsureRenderbufferBound(false);
1245 EXPECT_CALL(*gl_
, GetError())
1246 .WillOnce(Return(GL_NO_ERROR
)) // for RenderbufferStoage
1247 .WillOnce(Return(GL_NO_ERROR
))
1248 .WillOnce(Return(GL_NO_ERROR
)) // for FramebufferRenderbuffer
1249 .WillOnce(Return(GL_NO_ERROR
))
1250 .WillOnce(Return(GL_NO_ERROR
)) // for GetIntegerv
1251 .WillOnce(Return(GL_NO_ERROR
))
1252 .WillOnce(Return(GL_NO_ERROR
)) // for GetIntegerv
1253 .WillOnce(Return(GL_NO_ERROR
))
1254 .RetiresOnSaturation();
1258 RenderbufferStorageEXT(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 100, 50))
1260 .RetiresOnSaturation();
1261 RenderbufferStorage cmd
;
1262 cmd
.Init(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 100, 50);
1263 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1265 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
1266 GL_STENCIL_ATTACHMENT
,
1268 kServiceRenderbufferId
))
1270 .RetiresOnSaturation();
1271 FramebufferRenderbuffer fbrb_cmd
;
1272 fbrb_cmd
.Init(GL_FRAMEBUFFER
,
1273 GL_STENCIL_ATTACHMENT
,
1275 client_renderbuffer_id_
);
1276 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbrb_cmd
));
1278 typedef GetIntegerv::Result Result
;
1279 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
1282 cmd2
.Init(GL_STENCIL_BITS
, shared_memory_id_
, shared_memory_offset_
);
1283 EXPECT_CALL(*gl_
, GetIntegerv(GL_STENCIL_BITS
, _
))
1284 .WillOnce(SetArgumentPointee
<1>(8))
1285 .RetiresOnSaturation();
1286 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1287 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_STENCIL_BITS
),
1288 result
->GetNumResults());
1289 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1290 EXPECT_EQ(8, result
->GetData()[0]);
1292 cmd2
.Init(GL_DEPTH_BITS
, shared_memory_id_
, shared_memory_offset_
);
1293 EXPECT_CALL(*gl_
, GetIntegerv(GL_DEPTH_BITS
, _
))
1294 .WillOnce(SetArgumentPointee
<1>(24))
1295 .RetiresOnSaturation();
1296 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd2
));
1297 EXPECT_EQ(decoder_
->GetGLES2Util()->GLGetNumValuesReturned(GL_DEPTH_BITS
),
1298 result
->GetNumResults());
1299 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1300 EXPECT_EQ(0, result
->GetData()[0]);
1303 TEST_P(GLES2DecoderTest
, FramebufferRenderbufferGLError
) {
1305 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1306 EXPECT_CALL(*gl_
, GetError())
1307 .WillOnce(Return(GL_NO_ERROR
))
1308 .WillOnce(Return(GL_OUT_OF_MEMORY
))
1309 .RetiresOnSaturation();
1311 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
1312 GL_COLOR_ATTACHMENT0
,
1314 kServiceRenderbufferId
))
1316 .RetiresOnSaturation();
1317 FramebufferRenderbuffer cmd
;
1318 cmd
.Init(GL_FRAMEBUFFER
,
1319 GL_COLOR_ATTACHMENT0
,
1321 client_renderbuffer_id_
);
1322 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1323 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
1326 TEST_P(GLES2DecoderTest
, FramebufferTexture2DGLError
) {
1327 const GLsizei kWidth
= 5;
1328 const GLsizei kHeight
= 3;
1329 const GLenum kFormat
= GL_RGB
;
1330 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
1331 DoTexImage2D(GL_TEXTURE_2D
,
1342 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1343 EXPECT_CALL(*gl_
, GetError())
1344 .WillOnce(Return(GL_NO_ERROR
))
1345 .WillOnce(Return(GL_OUT_OF_MEMORY
))
1346 .RetiresOnSaturation();
1348 FramebufferTexture2DEXT(GL_FRAMEBUFFER
,
1349 GL_COLOR_ATTACHMENT0
,
1354 .RetiresOnSaturation();
1355 FramebufferTexture2D fbtex_cmd
;
1356 fbtex_cmd
.Init(GL_FRAMEBUFFER
,
1357 GL_COLOR_ATTACHMENT0
,
1359 client_texture_id_
);
1360 EXPECT_EQ(error::kNoError
, ExecuteCmd(fbtex_cmd
));
1361 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
1364 TEST_P(GLES2DecoderTest
, RenderbufferStorageGLError
) {
1366 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1367 EnsureRenderbufferBound(false);
1368 EXPECT_CALL(*gl_
, GetError())
1369 .WillOnce(Return(GL_NO_ERROR
))
1370 .WillOnce(Return(GL_OUT_OF_MEMORY
))
1371 .RetiresOnSaturation();
1372 EXPECT_CALL(*gl_
, RenderbufferStorageEXT(GL_RENDERBUFFER
, GL_RGBA
, 100, 50))
1374 .RetiresOnSaturation();
1375 RenderbufferStorage cmd
;
1376 cmd
.Init(GL_RENDERBUFFER
, GL_RGBA4
, 100, 50);
1377 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1378 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
1381 TEST_P(GLES2DecoderTest
, RenderbufferStorageBadArgs
) {
1383 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1384 EXPECT_CALL(*gl_
, RenderbufferStorageEXT(_
, _
, _
, _
))
1386 .RetiresOnSaturation();
1387 RenderbufferStorage cmd
;
1388 cmd
.Init(GL_RENDERBUFFER
, GL_RGBA4
, TestHelper::kMaxRenderbufferSize
+ 1, 1);
1389 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1390 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1391 cmd
.Init(GL_RENDERBUFFER
, GL_RGBA4
, 1, TestHelper::kMaxRenderbufferSize
+ 1);
1392 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1393 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1396 TEST_P(GLES2DecoderManualInitTest
,
1397 RenderbufferStorageMultisampleCHROMIUMGLError
) {
1399 init
.extensions
= "GL_EXT_framebuffer_multisample";
1400 init
.bind_generates_resource
= true;
1403 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1404 EnsureRenderbufferBound(false);
1405 EXPECT_CALL(*gl_
, GetError())
1406 .WillOnce(Return(GL_NO_ERROR
))
1407 .WillOnce(Return(GL_OUT_OF_MEMORY
))
1408 .RetiresOnSaturation();
1411 RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER
, 1, GL_RGBA
, 100, 50))
1413 .RetiresOnSaturation();
1414 RenderbufferStorageMultisampleCHROMIUM cmd
;
1415 cmd
.Init(GL_RENDERBUFFER
, 1, GL_RGBA4
, 100, 50);
1416 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1417 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
1420 TEST_P(GLES2DecoderManualInitTest
,
1421 RenderbufferStorageMultisampleCHROMIUMBadArgs
) {
1423 init
.extensions
= "GL_EXT_framebuffer_multisample";
1424 init
.bind_generates_resource
= true;
1427 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1428 EXPECT_CALL(*gl_
, RenderbufferStorageMultisampleEXT(_
, _
, _
, _
, _
))
1430 .RetiresOnSaturation();
1431 RenderbufferStorageMultisampleCHROMIUM cmd
;
1432 cmd
.Init(GL_RENDERBUFFER
,
1433 TestHelper::kMaxSamples
+ 1,
1435 TestHelper::kMaxRenderbufferSize
,
1437 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1438 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1439 cmd
.Init(GL_RENDERBUFFER
,
1440 TestHelper::kMaxSamples
,
1442 TestHelper::kMaxRenderbufferSize
+ 1,
1444 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1445 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1446 cmd
.Init(GL_RENDERBUFFER
,
1447 TestHelper::kMaxSamples
,
1450 TestHelper::kMaxRenderbufferSize
+ 1);
1451 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1452 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1455 TEST_P(GLES2DecoderManualInitTest
, RenderbufferStorageMultisampleCHROMIUM
) {
1457 init
.extensions
= "GL_EXT_framebuffer_multisample";
1460 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1461 InSequence sequence
;
1462 EnsureRenderbufferBound(false);
1463 DoRenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER
,
1464 TestHelper::kMaxSamples
,
1467 TestHelper::kMaxRenderbufferSize
,
1471 TEST_P(GLES2DecoderManualInitTest
,
1472 RenderbufferStorageMultisampleCHROMIUMRebindRenderbuffer
) {
1474 init
.extensions
= "GL_EXT_framebuffer_multisample";
1477 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1478 RestoreRenderbufferBindings();
1479 InSequence sequence
;
1480 EnsureRenderbufferBound(true);
1481 DoRenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER
,
1482 TestHelper::kMaxSamples
,
1485 TestHelper::kMaxRenderbufferSize
,
1489 TEST_P(GLES2DecoderManualInitTest
,
1490 RenderbufferStorageMultisampleEXTNotSupported
) {
1492 init
.extensions
= "GL_EXT_framebuffer_multisample";
1493 init
.bind_generates_resource
= true;
1496 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1497 InSequence sequence
;
1498 // GL_EXT_framebuffer_multisample uses RenderbufferStorageMultisampleCHROMIUM.
1499 RenderbufferStorageMultisampleEXT cmd
;
1500 cmd
.Init(GL_RENDERBUFFER
,
1501 TestHelper::kMaxSamples
,
1503 TestHelper::kMaxRenderbufferSize
,
1505 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1506 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1509 class GLES2DecoderMultisampledRenderToTextureTest
1510 : public GLES2DecoderTestWithExtensionsOnGLES2
{
1512 void TestNotCompatibleWithRenderbufferStorageMultisampleCHROMIUM() {
1514 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1515 RenderbufferStorageMultisampleCHROMIUM cmd
;
1516 cmd
.Init(GL_RENDERBUFFER
,
1517 TestHelper::kMaxSamples
,
1519 TestHelper::kMaxRenderbufferSize
,
1521 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1522 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1525 void TestRenderbufferStorageMultisampleEXT(const char* extension
,
1528 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1529 InSequence sequence
;
1531 RestoreRenderbufferBindings();
1532 EnsureRenderbufferBound(true);
1534 EnsureRenderbufferBound(false);
1537 EXPECT_CALL(*gl_
, GetError())
1538 .WillOnce(Return(GL_NO_ERROR
))
1539 .RetiresOnSaturation();
1540 if (strstr(extension
, "GL_IMG_multisampled_render_to_texture")) {
1543 RenderbufferStorageMultisampleIMG(GL_RENDERBUFFER
,
1544 TestHelper::kMaxSamples
,
1546 TestHelper::kMaxRenderbufferSize
,
1549 .RetiresOnSaturation();
1553 RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER
,
1554 TestHelper::kMaxSamples
,
1556 TestHelper::kMaxRenderbufferSize
,
1559 .RetiresOnSaturation();
1561 EXPECT_CALL(*gl_
, GetError())
1562 .WillOnce(Return(GL_NO_ERROR
))
1563 .RetiresOnSaturation();
1564 RenderbufferStorageMultisampleEXT cmd
;
1565 cmd
.Init(GL_RENDERBUFFER
,
1566 TestHelper::kMaxSamples
,
1568 TestHelper::kMaxRenderbufferSize
,
1570 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1571 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1575 INSTANTIATE_TEST_CASE_P(Service
,
1576 GLES2DecoderMultisampledRenderToTextureTest
,
1579 TEST_P(GLES2DecoderMultisampledRenderToTextureTest
,
1580 NotCompatibleWithRenderbufferStorageMultisampleCHROMIUM_EXT
) {
1581 Init("GL_EXT_multisampled_render_to_texture");
1582 TestNotCompatibleWithRenderbufferStorageMultisampleCHROMIUM();
1585 TEST_P(GLES2DecoderMultisampledRenderToTextureTest
,
1586 NotCompatibleWithRenderbufferStorageMultisampleCHROMIUM_IMG
) {
1587 Init("GL_IMG_multisampled_render_to_texture");
1588 TestNotCompatibleWithRenderbufferStorageMultisampleCHROMIUM();
1591 TEST_P(GLES2DecoderMultisampledRenderToTextureTest
,
1592 RenderbufferStorageMultisampleEXT_EXT
) {
1593 Init("GL_EXT_multisampled_render_to_texture");
1594 TestRenderbufferStorageMultisampleEXT("GL_EXT_multisampled_render_to_texture",
1598 TEST_P(GLES2DecoderMultisampledRenderToTextureTest
,
1599 RenderbufferStorageMultisampleEXT_IMG
) {
1600 Init("GL_IMG_multisampled_render_to_texture");
1601 TestRenderbufferStorageMultisampleEXT("GL_IMG_multisampled_render_to_texture",
1605 TEST_P(GLES2DecoderMultisampledRenderToTextureTest
,
1606 RenderbufferStorageMultisampleEXT_EXT_RebindRenderbuffer
) {
1607 Init("GL_EXT_multisampled_render_to_texture");
1608 TestRenderbufferStorageMultisampleEXT("GL_EXT_multisampled_render_to_texture",
1612 TEST_P(GLES2DecoderMultisampledRenderToTextureTest
,
1613 RenderbufferStorageMultisampleEXT_IMG_RebindRenderbuffer
) {
1614 Init("GL_IMG_multisampled_render_to_texture");
1615 TestRenderbufferStorageMultisampleEXT("GL_IMG_multisampled_render_to_texture",
1619 TEST_P(GLES2DecoderTest
, ReadPixelsGLError
) {
1620 GLenum kFormat
= GL_RGBA
;
1625 typedef ReadPixels::Result Result
;
1626 uint32 result_shm_id
= kSharedMemoryId
;
1627 uint32 result_shm_offset
= kSharedMemoryOffset
;
1628 uint32 pixels_shm_id
= kSharedMemoryId
;
1629 uint32 pixels_shm_offset
= kSharedMemoryOffset
+ sizeof(Result
);
1630 EXPECT_CALL(*gl_
, GetError())
1631 .WillOnce(Return(GL_NO_ERROR
))
1632 .WillOnce(Return(GL_OUT_OF_MEMORY
))
1633 .RetiresOnSaturation();
1635 ReadPixels(x
, y
, width
, height
, kFormat
, GL_UNSIGNED_BYTE
, _
))
1637 .RetiresOnSaturation();
1650 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1651 EXPECT_EQ(GL_OUT_OF_MEMORY
, GetGLError());
1654 TEST_P(GLES2DecoderWithShaderTest
, UnClearedAttachmentsGetClearedOnClear
) {
1655 const GLuint kFBOClientTextureId
= 4100;
1656 const GLuint kFBOServiceTextureId
= 4101;
1658 // Register a texture id.
1659 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1660 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
1661 .RetiresOnSaturation();
1662 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
1664 // Setup "render to" texture.
1665 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
1667 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1669 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1670 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1671 GL_COLOR_ATTACHMENT0
,
1673 kFBOClientTextureId
,
1674 kFBOServiceTextureId
,
1677 // Set scissor rect and enable GL_SCISSOR_TEST to make sure we re-enable it
1678 // and restore the rect again after the clear.
1679 DoEnableDisable(GL_SCISSOR_TEST
, true);
1680 DoScissor(0, 0, 64, 64);
1682 // Setup "render from" texture.
1685 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
1686 GL_COLOR_BUFFER_BIT
, // clear bits
1691 true, // scissor test
1693 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1694 false, // Framebuffer has depth
1695 false, // Framebuffer has stencil
1696 0x1111, // color bits
1697 false, // depth mask
1698 false, // depth enabled
1699 0, // front stencil mask
1700 0, // back stencil mask
1701 false); // stencil enabled
1703 EXPECT_CALL(*gl_
, Clear(GL_COLOR_BUFFER_BIT
)).Times(1).RetiresOnSaturation();
1706 cmd
.Init(GL_COLOR_BUFFER_BIT
);
1707 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1708 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1711 TEST_P(GLES2DecoderWithShaderTest
, UnClearedAttachmentsGetClearedOnReadPixels
) {
1712 const GLuint kFBOClientTextureId
= 4100;
1713 const GLuint kFBOServiceTextureId
= 4101;
1715 // Register a texture id.
1716 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1717 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
1718 .RetiresOnSaturation();
1719 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
1721 // Setup "render to" texture.
1722 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
1724 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1726 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1727 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1728 GL_COLOR_ATTACHMENT0
,
1730 kFBOClientTextureId
,
1731 kFBOServiceTextureId
,
1734 DoEnableDisable(GL_SCISSOR_TEST
, false);
1735 DoScissor(0, 0, 1, 1);
1737 // Setup "render from" texture.
1740 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
1741 GL_COLOR_BUFFER_BIT
, // clear bits
1746 false, // scissor test
1749 EXPECT_CALL(*gl_
, GetError())
1750 .WillOnce(Return(GL_NO_ERROR
))
1751 .WillOnce(Return(GL_NO_ERROR
))
1752 .RetiresOnSaturation();
1753 EXPECT_CALL(*gl_
, ReadPixels(0, 0, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
1755 .RetiresOnSaturation();
1756 typedef ReadPixels::Result Result
;
1757 uint32 result_shm_id
= kSharedMemoryId
;
1758 uint32 result_shm_offset
= kSharedMemoryOffset
;
1759 uint32 pixels_shm_id
= kSharedMemoryId
;
1760 uint32 pixels_shm_offset
= kSharedMemoryOffset
+ sizeof(Result
);
1773 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1774 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1777 TEST_P(GLES2DecoderManualInitTest
,
1778 UnClearedAttachmentsGetClearedOnReadPixelsAndDrawBufferGetsRestored
) {
1780 init
.extensions
= "GL_EXT_framebuffer_multisample";
1781 init
.bind_generates_resource
= true;
1783 const GLuint kFBOClientTextureId
= 4100;
1784 const GLuint kFBOServiceTextureId
= 4101;
1786 // Register a texture id.
1787 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1788 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
1789 .RetiresOnSaturation();
1790 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
1792 // Setup "render from" texture.
1793 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
1795 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1797 GL_READ_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1798 DoFramebufferTexture2D(GL_READ_FRAMEBUFFER
,
1799 GL_COLOR_ATTACHMENT0
,
1801 kFBOClientTextureId
,
1802 kFBOServiceTextureId
,
1806 // Set scissor rect and disable GL_SCISSOR_TEST to make sure we enable it in
1807 // the clear, then disable it and restore the rect again.
1808 DoScissor(0, 0, 32, 32);
1809 DoEnableDisable(GL_SCISSOR_TEST
, false);
1811 SetupExpectationsForFramebufferClearingMulti(
1812 kServiceFramebufferId
, // read framebuffer service id
1813 0, // backbuffer service id
1814 GL_READ_FRAMEBUFFER
, // target
1815 GL_COLOR_BUFFER_BIT
, // clear bits
1820 false, // scissor test
1823 EXPECT_CALL(*gl_
, GetError())
1824 .WillOnce(Return(GL_NO_ERROR
))
1825 .WillOnce(Return(GL_NO_ERROR
))
1826 .RetiresOnSaturation();
1827 EXPECT_CALL(*gl_
, ReadPixels(0, 0, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
1829 .RetiresOnSaturation();
1830 typedef ReadPixels::Result Result
;
1831 uint32 result_shm_id
= kSharedMemoryId
;
1832 uint32 result_shm_offset
= kSharedMemoryOffset
;
1833 uint32 pixels_shm_id
= kSharedMemoryId
;
1834 uint32 pixels_shm_offset
= kSharedMemoryOffset
+ sizeof(Result
);
1847 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1848 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1851 TEST_P(GLES2DecoderWithShaderTest
, CopyTexImageWithInCompleteFBOFails
) {
1852 GLenum target
= GL_TEXTURE_2D
;
1854 GLenum internal_format
= GL_RGBA
;
1859 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1861 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1862 DoRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA4
, GL_RGBA
, 0, 0, GL_NO_ERROR
);
1863 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
1864 GL_COLOR_ATTACHMENT0
,
1866 client_renderbuffer_id_
,
1867 kServiceRenderbufferId
,
1870 EXPECT_CALL(*gl_
, CopyTexImage2D(_
, _
, _
, _
, _
, _
, _
, _
))
1872 .RetiresOnSaturation();
1874 cmd
.Init(target
, level
, internal_format
, 0, 0, width
, height
);
1875 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1876 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION
, GetGLError());
1879 void GLES2DecoderWithShaderTest::CheckRenderbufferChangesMarkFBOAsNotComplete(
1881 FramebufferManager
* framebuffer_manager
= group().framebuffer_manager();
1884 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1886 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1887 DoRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA4
, GL_RGBA
, 1, 1, GL_NO_ERROR
);
1888 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
1889 GL_COLOR_ATTACHMENT0
,
1891 client_renderbuffer_id_
,
1892 kServiceRenderbufferId
,
1896 DoBindFramebuffer(GL_FRAMEBUFFER
, 0, 0);
1899 Framebuffer
* framebuffer
=
1900 framebuffer_manager
->GetFramebuffer(client_framebuffer_id_
);
1901 ASSERT_TRUE(framebuffer
!= NULL
);
1902 framebuffer_manager
->MarkAsComplete(framebuffer
);
1903 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
1905 // Test that renderbufferStorage marks fbo as not complete.
1906 DoRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA4
, GL_RGBA
, 1, 1, GL_NO_ERROR
);
1907 EXPECT_FALSE(framebuffer_manager
->IsComplete(framebuffer
));
1908 framebuffer_manager
->MarkAsComplete(framebuffer
);
1909 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
1911 // Test deleting renderbuffer marks fbo as not complete.
1912 DoDeleteRenderbuffer(client_renderbuffer_id_
, kServiceRenderbufferId
);
1914 EXPECT_FALSE(framebuffer_manager
->IsComplete(framebuffer
));
1916 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
1919 DoDeleteFramebuffer(client_framebuffer_id_
,
1920 kServiceFramebufferId
,
1929 TEST_P(GLES2DecoderWithShaderTest
,
1930 RenderbufferChangesMarkFBOAsNotCompleteBoundFBO
) {
1931 CheckRenderbufferChangesMarkFBOAsNotComplete(true);
1934 TEST_P(GLES2DecoderWithShaderTest
,
1935 RenderbufferChangesMarkFBOAsNotCompleteUnboundFBO
) {
1936 CheckRenderbufferChangesMarkFBOAsNotComplete(false);
1939 void GLES2DecoderWithShaderTest::CheckTextureChangesMarkFBOAsNotComplete(
1941 FramebufferManager
* framebuffer_manager
= group().framebuffer_manager();
1942 const GLuint kFBOClientTextureId
= 4100;
1943 const GLuint kFBOServiceTextureId
= 4101;
1945 // Register a texture id.
1946 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1947 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
1948 .RetiresOnSaturation();
1949 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
1953 // Setup "render to" texture.
1954 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
1956 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1958 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1959 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1960 GL_COLOR_ATTACHMENT0
,
1962 kFBOClientTextureId
,
1963 kFBOServiceTextureId
,
1968 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1970 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1971 DoRenderbufferStorage(GL_RENDERBUFFER
,
1972 GL_DEPTH_COMPONENT16
,
1977 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
1978 GL_DEPTH_ATTACHMENT
,
1980 client_renderbuffer_id_
,
1981 kServiceRenderbufferId
,
1985 DoBindFramebuffer(GL_FRAMEBUFFER
, 0, 0);
1988 Framebuffer
* framebuffer
=
1989 framebuffer_manager
->GetFramebuffer(client_framebuffer_id_
);
1990 ASSERT_TRUE(framebuffer
!= NULL
);
1991 framebuffer_manager
->MarkAsComplete(framebuffer
);
1992 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
1994 // Test TexImage2D marks fbo as not complete.
1996 GL_TEXTURE_2D
, 0, GL_RGB
, 1, 1, 0, GL_RGB
, GL_UNSIGNED_BYTE
, 0, 0);
1997 EXPECT_FALSE(framebuffer_manager
->IsComplete(framebuffer
));
1998 framebuffer_manager
->MarkAsComplete(framebuffer
);
1999 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
2001 // Test CopyImage2D marks fbo as not complete.
2002 EXPECT_CALL(*gl_
, GetError())
2003 .WillOnce(Return(GL_NO_ERROR
))
2004 .RetiresOnSaturation();
2005 EXPECT_CALL(*gl_
, CopyTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 0, 0, 1, 1, 0))
2007 .RetiresOnSaturation();
2008 EXPECT_CALL(*gl_
, GetError())
2009 .WillOnce(Return(GL_NO_ERROR
))
2010 .RetiresOnSaturation();
2012 cmd
.Init(GL_TEXTURE_2D
, 0, GL_RGB
, 0, 0, 1, 1);
2013 // Unbind fbo and bind again after CopyTexImage2D tp avoid feedback loops.
2015 DoBindFramebuffer(GL_FRAMEBUFFER
, 0, 0);
2017 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2020 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2022 EXPECT_FALSE(framebuffer_manager
->IsComplete(framebuffer
));
2024 // Test deleting texture marks fbo as not complete.
2025 framebuffer_manager
->MarkAsComplete(framebuffer
);
2026 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
2027 DoDeleteTexture(kFBOClientTextureId
, kFBOServiceTextureId
);
2030 EXPECT_FALSE(framebuffer_manager
->IsComplete(framebuffer
));
2032 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
2035 DoDeleteFramebuffer(client_framebuffer_id_
,
2036 kServiceFramebufferId
,
2045 TEST_P(GLES2DecoderWithShaderTest
, TextureChangesMarkFBOAsNotCompleteBoundFBO
) {
2046 CheckTextureChangesMarkFBOAsNotComplete(true);
2049 TEST_P(GLES2DecoderWithShaderTest
,
2050 TextureChangesMarkFBOAsNotCompleteUnboundFBO
) {
2051 CheckTextureChangesMarkFBOAsNotComplete(false);
2054 TEST_P(GLES2DecoderTest
, CanChangeSurface
) {
2055 scoped_refptr
<GLSurfaceMock
> other_surface(new GLSurfaceMock
);
2056 EXPECT_CALL(*other_surface
.get(), GetBackingFrameBufferObject())
2057 .WillOnce(Return(7));
2058 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 7));
2060 decoder_
->SetSurface(other_surface
);
2063 TEST_P(GLES2DecoderTest
, DrawBuffersEXTImmediateSuccceeds
) {
2064 const GLsizei count
= 1;
2065 const GLenum bufs
[] = {GL_COLOR_ATTACHMENT0
};
2066 DrawBuffersEXTImmediate
& cmd
= *GetImmediateAs
<DrawBuffersEXTImmediate
>();
2067 cmd
.Init(count
, bufs
);
2070 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2071 EXPECT_CALL(*gl_
, DrawBuffersARB(count
, _
)).Times(1).RetiresOnSaturation();
2072 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(bufs
)));
2073 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2076 TEST_P(GLES2DecoderTest
, DrawBuffersEXTImmediateFails
) {
2077 const GLsizei count
= 1;
2078 const GLenum bufs
[] = {GL_COLOR_ATTACHMENT1_EXT
};
2079 DrawBuffersEXTImmediate
& cmd
= *GetImmediateAs
<DrawBuffersEXTImmediate
>();
2080 cmd
.Init(count
, bufs
);
2083 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2084 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(bufs
)));
2085 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2088 TEST_P(GLES2DecoderTest
, DrawBuffersEXTImmediateBackbuffer
) {
2089 const GLsizei count
= 1;
2090 const GLenum bufs
[] = {GL_BACK
};
2091 DrawBuffersEXTImmediate
& cmd
= *GetImmediateAs
<DrawBuffersEXTImmediate
>();
2092 cmd
.Init(count
, bufs
);
2095 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2096 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(bufs
)));
2097 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2099 DoBindFramebuffer(GL_FRAMEBUFFER
, 0, 0); // unbind
2101 EXPECT_CALL(*gl_
, DrawBuffersARB(count
, _
)).Times(1).RetiresOnSaturation();
2103 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(bufs
)));
2104 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2107 TEST_P(GLES2DecoderManualInitTest
, InvalidateFramebufferBinding
) {
2109 init
.gl_version
= "opengl es 3.0";
2112 // EXPECT_EQ can't be used to compare function pointers
2114 gfx::MockGLInterface::GetGLProcAddress("glInvalidateFramebuffer") !=
2115 gfx::g_driver_gl
.fn
.glDiscardFramebufferEXTFn
);
2117 gfx::MockGLInterface::GetGLProcAddress("glInvalidateFramebuffer") !=
2118 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT"));
2121 TEST_P(GLES2DecoderManualInitTest
, DiscardFramebufferEXT
) {
2123 init
.extensions
= "GL_EXT_discard_framebuffer";
2124 init
.gl_version
= "opengl es 2.0";
2127 // EXPECT_EQ can't be used to compare function pointers
2129 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT") ==
2130 gfx::g_driver_gl
.fn
.glDiscardFramebufferEXTFn
);
2132 const GLenum target
= GL_FRAMEBUFFER
;
2133 const GLsizei count
= 1;
2134 const GLenum attachments
[] = {GL_COLOR_ATTACHMENT0
};
2138 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2139 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2140 GL_COLOR_ATTACHMENT0
,
2146 FramebufferManager
* framebuffer_manager
= group().framebuffer_manager();
2147 Framebuffer
* framebuffer
=
2148 framebuffer_manager
->GetFramebuffer(client_framebuffer_id_
);
2149 EXPECT_TRUE(framebuffer
->IsCleared());
2151 EXPECT_CALL(*gl_
, DiscardFramebufferEXT(target
, count
, _
))
2153 .RetiresOnSaturation();
2154 DiscardFramebufferEXTImmediate
& cmd
=
2155 *GetImmediateAs
<DiscardFramebufferEXTImmediate
>();
2156 cmd
.Init(target
, count
, attachments
);
2158 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(attachments
)));
2159 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2160 EXPECT_FALSE(framebuffer
->IsCleared());
2163 TEST_P(GLES2DecoderTest
, DiscardFramebufferEXTUnsupported
) {
2164 const GLenum target
= GL_FRAMEBUFFER
;
2165 const GLsizei count
= 1;
2166 const GLenum attachments
[] = {GL_COLOR_EXT
};
2167 DiscardFramebufferEXTImmediate
& cmd
=
2168 *GetImmediateAs
<DiscardFramebufferEXTImmediate
>();
2169 cmd
.Init(target
, count
, attachments
);
2171 // Should not result into a call into GL.
2172 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(attachments
)));
2173 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2176 TEST_P(GLES2DecoderManualInitTest
,
2177 DiscardedAttachmentsEXTMarksFramebufferIncomplete
) {
2179 init
.extensions
= "GL_EXT_discard_framebuffer";
2180 init
.gl_version
= "opengl es 2.0";
2181 init
.has_alpha
= true;
2182 init
.bind_generates_resource
= true;
2185 const GLuint kFBOClientTextureId
= 4100;
2186 const GLuint kFBOServiceTextureId
= 4101;
2188 // Register a texture id.
2189 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2190 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2191 .RetiresOnSaturation();
2192 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2194 // Setup "render to" texture.
2195 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2197 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2199 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2200 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2201 GL_COLOR_ATTACHMENT0
,
2203 kFBOClientTextureId
,
2204 kFBOServiceTextureId
,
2207 DoEnableDisable(GL_SCISSOR_TEST
, false);
2208 DoScissor(0, 0, 1, 1);
2210 // Setup "render from" texture.
2213 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
2214 GL_COLOR_BUFFER_BIT
, // clear bits
2219 false, // scissor test
2221 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2222 false, // Framebuffer has depth
2223 false, // Framebuffer has stencil
2224 0x1111, // color bits
2225 false, // depth mask
2226 false, // depth enabled
2227 0, // front stencil mask
2228 0, // back stencil mask
2229 false); // stencil enabled
2231 EXPECT_CALL(*gl_
, Clear(GL_COLOR_BUFFER_BIT
)).Times(1).RetiresOnSaturation();
2234 clear_cmd
.Init(GL_COLOR_BUFFER_BIT
);
2235 EXPECT_EQ(error::kNoError
, ExecuteCmd(clear_cmd
));
2236 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2238 // Check that framebuffer is cleared and complete.
2239 FramebufferManager
* framebuffer_manager
= group().framebuffer_manager();
2240 Framebuffer
* framebuffer
=
2241 framebuffer_manager
->GetFramebuffer(client_framebuffer_id_
);
2242 EXPECT_TRUE(framebuffer
->IsCleared());
2243 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
2245 // Check that Discard GL_COLOR_ATTACHMENT0, sets the attachment as uncleared
2246 // and the framebuffer as incomplete.
2248 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT") ==
2249 gfx::g_driver_gl
.fn
.glDiscardFramebufferEXTFn
);
2251 const GLenum target
= GL_FRAMEBUFFER
;
2252 const GLsizei count
= 1;
2253 const GLenum attachments
[] = {GL_COLOR_ATTACHMENT0
};
2255 DiscardFramebufferEXTImmediate
& discard_cmd
=
2256 *GetImmediateAs
<DiscardFramebufferEXTImmediate
>();
2257 discard_cmd
.Init(target
, count
, attachments
);
2259 EXPECT_CALL(*gl_
, DiscardFramebufferEXT(target
, count
, _
))
2261 .RetiresOnSaturation();
2262 EXPECT_EQ(error::kNoError
,
2263 ExecuteImmediateCmd(discard_cmd
, sizeof(attachments
)));
2264 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2265 EXPECT_FALSE(framebuffer
->IsCleared());
2266 EXPECT_FALSE(framebuffer_manager
->IsComplete(framebuffer
));
2269 TEST_P(GLES2DecoderManualInitTest
, ReadFormatExtension
) {
2271 init
.extensions
= "GL_OES_read_format";
2272 init
.bind_generates_resource
= true;
2275 EXPECT_CALL(*gl_
, GetError())
2276 .WillOnce(Return(GL_NO_ERROR
))
2277 .WillOnce(Return(GL_NO_ERROR
))
2278 .WillOnce(Return(GL_NO_ERROR
))
2279 .WillOnce(Return(GL_NO_ERROR
))
2280 .RetiresOnSaturation();
2281 EXPECT_CALL(*gl_
, GetError()).Times(6).RetiresOnSaturation();
2283 typedef GetIntegerv::Result Result
;
2284 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
2286 const GLuint kFBOClientTextureId
= 4100;
2287 const GLuint kFBOServiceTextureId
= 4101;
2289 // Register a texture id.
2290 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2291 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2292 .RetiresOnSaturation();
2293 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2295 // Setup "render to" texture.
2296 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2298 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2300 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2301 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2302 GL_COLOR_ATTACHMENT0
,
2304 kFBOClientTextureId
,
2305 kFBOServiceTextureId
,
2310 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(1).RetiresOnSaturation();
2311 cmd
.Init(GL_IMPLEMENTATION_COLOR_READ_FORMAT
,
2313 shared_memory_offset_
);
2314 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2315 EXPECT_EQ(1, result
->GetNumResults());
2316 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2319 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(1).RetiresOnSaturation();
2320 cmd
.Init(GL_IMPLEMENTATION_COLOR_READ_TYPE
,
2322 shared_memory_offset_
);
2323 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2324 EXPECT_EQ(1, result
->GetNumResults());
2325 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2328 TEST_P(GLES2DecoderManualInitTest
, NoReadFormatExtension
) {
2330 init
.bind_generates_resource
= true;
2333 EXPECT_CALL(*gl_
, GetError())
2334 .WillOnce(Return(GL_NO_ERROR
))
2335 .WillOnce(Return(GL_NO_ERROR
))
2336 .WillOnce(Return(GL_NO_ERROR
))
2337 .WillOnce(Return(GL_NO_ERROR
))
2338 .RetiresOnSaturation();
2340 typedef GetIntegerv::Result Result
;
2341 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
2343 const GLuint kFBOClientTextureId
= 4100;
2344 const GLuint kFBOServiceTextureId
= 4101;
2346 // Register a texture id.
2347 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2348 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2349 .RetiresOnSaturation();
2350 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2352 // Setup "render to" texture.
2353 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2355 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2357 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2358 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2359 GL_COLOR_ATTACHMENT0
,
2361 kFBOClientTextureId
,
2362 kFBOServiceTextureId
,
2367 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
2368 cmd
.Init(GL_IMPLEMENTATION_COLOR_READ_FORMAT
,
2370 shared_memory_offset_
);
2371 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2372 EXPECT_EQ(1, result
->GetNumResults());
2373 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2376 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
2377 cmd
.Init(GL_IMPLEMENTATION_COLOR_READ_TYPE
,
2379 shared_memory_offset_
);
2380 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2381 EXPECT_EQ(1, result
->GetNumResults());
2382 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2385 // TODO(gman): PixelStorei
2387 // TODO(gman): SwapBuffers
2389 } // namespace gles2