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
= 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,
395 // We need to setup an FBO so we can know the max size that ReadPixels will
398 DoBindTexture(GL_TEXTURE_2D
, client_texture_id_
, kServiceTextureId
);
399 DoTexImage2D(GL_TEXTURE_2D
,
408 kSharedMemoryOffset
);
410 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
411 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
412 GL_COLOR_ATTACHMENT0
,
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
) {
448 ReadPixels(read_x
, yy
, read_width
, 1, kFormat
, GL_UNSIGNED_BYTE
, _
))
449 .WillOnce(Invoke(&emu
, &ReadPixelsEmulator::ReadPixels
))
450 .RetiresOnSaturation();
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
));
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
));
485 GLint num_right_pixels
= std::max(in_read_x
+ in_read_width
- kWidth
, 0);
486 GLint num_right_bytes
= num_right_pixels
* kBytesPerPixel
;
489 row
+ unpadded_row_size
- num_right_bytes
,
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);
497 emu
.CompareRowSegment(x
, y
, num_middle_pixels
, row
+ num_left_bytes
));
501 if (yy
!= in_read_height
- 1) {
502 GLint num_padding_bytes
=
503 (kPackAlignment
- 1) - (unpadded_row_size
% kPackAlignment
);
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();
537 ReadPixels(0, 0, kWidth
, kHeight
, GL_RGB
, GL_UNSIGNED_BYTE
, _
))
538 .WillOnce(Invoke(&emu
, &ReadPixelsEmulator::ReadPixels
));
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
,
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();
593 ReadPixels(0, 0, kWidth
, kHeight
, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
594 .WillOnce(Invoke(&emu
, &ReadPixelsEmulator::ReadPixels
));
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] = {
618 }, // out of range on all sides
621 }, // out of range on right, bottom
624 }, // out of range on left, top
627 }, // completely off top
630 }, // completely off bottom
633 }, // completely off left
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);
664 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
665 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
677 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
678 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
690 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
691 EXPECT_EQ(GL_INVALID_ENUM
, GetGLError());
698 kInvalidSharedMemoryId
,
703 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
711 kInvalidSharedMemoryOffset
,
715 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
724 kInvalidSharedMemoryId
,
727 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
737 kInvalidSharedMemoryOffset
,
739 EXPECT_NE(error::kNoError
, ExecuteCmd(cmd
));
742 TEST_P(GLES2DecoderManualInitTest
, ReadPixelsAsyncError
) {
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;
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();
770 ReadPixels(0, 0, kWidth
, kHeight
, GL_RGB
, GL_UNSIGNED_BYTE
, _
))
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);
776 BufferData(GL_PIXEL_PACK_BUFFER_ARB
, _
, NULL
, GL_STREAM_READ
))
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
) {
798 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
799 ClearColor color_cmd
;
800 ColorMask color_mask_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
,
809 client_renderbuffer_id_
);
811 EXPECT_CALL(*gl_
, ClearColor(0.1f
, 0.2f
, 0.3f
, 0.4f
))
813 .RetiresOnSaturation();
814 SetupExpectationsForEnableDisable(GL_SCISSOR_TEST
, true);
815 EXPECT_CALL(*gl_
, GetError())
816 .WillOnce(Return(GL_NO_ERROR
))
817 .RetiresOnSaturation();
819 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
820 GL_COLOR_ATTACHMENT0
,
822 kServiceRenderbufferId
))
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
) {
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
,
845 client_renderbuffer_id_
);
847 EXPECT_CALL(*gl_
, ClearDepth(0.5f
)).Times(1).RetiresOnSaturation();
848 EXPECT_CALL(*gl_
, GetError())
849 .WillOnce(Return(GL_NO_ERROR
))
850 .RetiresOnSaturation();
852 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
855 kServiceRenderbufferId
))
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
) {
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
,
877 client_renderbuffer_id_
);
879 EXPECT_CALL(*gl_
, ClearStencil(123)).Times(1).RetiresOnSaturation();
880 EXPECT_CALL(*gl_
, GetError())
881 .WillOnce(Return(GL_NO_ERROR
))
882 .RetiresOnSaturation();
884 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
885 GL_STENCIL_ATTACHMENT
,
887 kServiceRenderbufferId
))
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);
908 GL_FRAMEBUFFER
, GL_DEPTH_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
,
909 client_renderbuffer_id_
);
911 EXPECT_CALL(*gl_
, ClearDepth(0.5f
))
913 .RetiresOnSaturation();
914 EXPECT_CALL(*gl_
, ClearStencil(123))
916 .RetiresOnSaturation();
917 EXPECT_CALL(*gl_
, FramebufferRenderbufferEXT(
918 GL_FRAMEBUFFER
, GL_DEPTH_STENCIL_ATTACHMENT
, GL_RENDERBUFFER
,
919 kServiceRenderbufferId
))
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
));
928 TEST_P(GLES2DecoderManualInitTest
, ActualAlphaMatchesRequestedAlpha
) {
930 init
.has_alpha
= true;
931 init
.request_alpha
= true;
932 init
.bind_generates_resource
= true;
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();
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
) {
956 init
.has_alpha
= true;
957 init
.bind_generates_resource
= true;
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();
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
) {
981 init
.has_depth
= true;
982 init
.request_depth
= true;
983 init
.bind_generates_resource
= true;
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();
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
) {
1007 init
.has_depth
= true;
1008 init
.bind_generates_resource
= true;
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();
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
) {
1032 init
.has_stencil
= true;
1033 init
.request_stencil
= true;
1034 init
.bind_generates_resource
= true;
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();
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
) {
1058 init
.has_stencil
= true;
1059 init
.bind_generates_resource
= true;
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();
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
) {
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;
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_
);
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]);
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
) {
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;
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_
);
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]);
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
) {
1166 init
.extensions
= "GL_OES_packed_depth_stencil";
1167 init
.gl_version
= "opengl es 2.0";
1168 init
.bind_generates_resource
= true;
1171 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
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();
1189 RenderbufferStorageEXT(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 100, 50))
1191 .RetiresOnSaturation();
1192 RenderbufferStorage cmd
;
1193 cmd
.Init(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 100, 50);
1194 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1196 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
1197 GL_DEPTH_ATTACHMENT
,
1199 kServiceRenderbufferId
))
1201 .RetiresOnSaturation();
1202 FramebufferRenderbuffer fbrb_cmd
;
1203 fbrb_cmd
.Init(GL_FRAMEBUFFER
,
1204 GL_DEPTH_ATTACHMENT
,
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_
);
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]);
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
) {
1236 init
.extensions
= "GL_OES_packed_depth_stencil";
1237 init
.gl_version
= "opengl es 2.0";
1238 init
.bind_generates_resource
= true;
1241 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
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();
1259 RenderbufferStorageEXT(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 100, 50))
1261 .RetiresOnSaturation();
1262 RenderbufferStorage cmd
;
1263 cmd
.Init(GL_RENDERBUFFER
, GL_DEPTH24_STENCIL8
, 100, 50);
1264 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1266 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
1267 GL_STENCIL_ATTACHMENT
,
1269 kServiceRenderbufferId
))
1271 .RetiresOnSaturation();
1272 FramebufferRenderbuffer fbrb_cmd
;
1273 fbrb_cmd
.Init(GL_FRAMEBUFFER
,
1274 GL_STENCIL_ATTACHMENT
,
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_
);
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]);
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
) {
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();
1312 FramebufferRenderbufferEXT(GL_FRAMEBUFFER
,
1313 GL_COLOR_ATTACHMENT0
,
1315 kServiceRenderbufferId
))
1317 .RetiresOnSaturation();
1318 FramebufferRenderbuffer cmd
;
1319 cmd
.Init(GL_FRAMEBUFFER
,
1320 GL_COLOR_ATTACHMENT0
,
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
,
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();
1349 FramebufferTexture2DEXT(GL_FRAMEBUFFER
,
1350 GL_COLOR_ATTACHMENT0
,
1355 .RetiresOnSaturation();
1356 FramebufferTexture2D fbtex_cmd
;
1357 fbtex_cmd
.Init(GL_FRAMEBUFFER
,
1358 GL_COLOR_ATTACHMENT0
,
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
) {
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))
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
) {
1384 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1385 EXPECT_CALL(*gl_
, RenderbufferStorageEXT(_
, _
, _
, _
))
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
) {
1400 init
.extensions
= "GL_EXT_framebuffer_multisample";
1401 init
.bind_generates_resource
= true;
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();
1412 RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER
, 1, GL_RGBA
, 100, 50))
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
) {
1424 init
.extensions
= "GL_EXT_framebuffer_multisample";
1425 init
.bind_generates_resource
= true;
1428 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1429 EXPECT_CALL(*gl_
, RenderbufferStorageMultisampleEXT(_
, _
, _
, _
, _
))
1431 .RetiresOnSaturation();
1432 RenderbufferStorageMultisampleCHROMIUM cmd
;
1433 cmd
.Init(GL_RENDERBUFFER
,
1434 TestHelper::kMaxSamples
+ 1,
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
,
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
,
1451 TestHelper::kMaxRenderbufferSize
+ 1);
1452 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1453 EXPECT_EQ(GL_INVALID_VALUE
, GetGLError());
1456 TEST_P(GLES2DecoderManualInitTest
, RenderbufferStorageMultisampleCHROMIUM
) {
1458 init
.extensions
= "GL_EXT_framebuffer_multisample";
1461 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1462 InSequence sequence
;
1463 EnsureRenderbufferBound(false);
1464 DoRenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER
,
1465 TestHelper::kMaxSamples
,
1468 TestHelper::kMaxRenderbufferSize
,
1472 TEST_P(GLES2DecoderManualInitTest
,
1473 RenderbufferStorageMultisampleCHROMIUMRebindRenderbuffer
) {
1475 init
.extensions
= "GL_EXT_framebuffer_multisample";
1478 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1479 RestoreRenderbufferBindings();
1480 InSequence sequence
;
1481 EnsureRenderbufferBound(true);
1482 DoRenderbufferStorageMultisampleCHROMIUM(GL_RENDERBUFFER
,
1483 TestHelper::kMaxSamples
,
1486 TestHelper::kMaxRenderbufferSize
,
1490 TEST_P(GLES2DecoderManualInitTest
,
1491 RenderbufferStorageMultisampleEXTNotSupported
) {
1493 init
.extensions
= "GL_EXT_framebuffer_multisample";
1494 init
.bind_generates_resource
= true;
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
,
1504 TestHelper::kMaxRenderbufferSize
,
1506 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1507 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1510 class GLES2DecoderMultisampledRenderToTextureTest
1511 : public GLES2DecoderTestWithExtensionsOnGLES2
{
1513 void TestNotCompatibleWithRenderbufferStorageMultisampleCHROMIUM() {
1515 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1516 RenderbufferStorageMultisampleCHROMIUM cmd
;
1517 cmd
.Init(GL_RENDERBUFFER
,
1518 TestHelper::kMaxSamples
,
1520 TestHelper::kMaxRenderbufferSize
,
1522 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1523 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
1526 void TestRenderbufferStorageMultisampleEXT(const char* extension
,
1529 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1530 InSequence sequence
;
1532 RestoreRenderbufferBindings();
1533 EnsureRenderbufferBound(true);
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")) {
1544 RenderbufferStorageMultisampleIMG(GL_RENDERBUFFER
,
1545 TestHelper::kMaxSamples
,
1547 TestHelper::kMaxRenderbufferSize
,
1550 .RetiresOnSaturation();
1554 RenderbufferStorageMultisampleEXT(GL_RENDERBUFFER
,
1555 TestHelper::kMaxSamples
,
1557 TestHelper::kMaxRenderbufferSize
,
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
,
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
,
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",
1599 TEST_P(GLES2DecoderMultisampledRenderToTextureTest
,
1600 RenderbufferStorageMultisampleEXT_IMG
) {
1601 Init("GL_IMG_multisampled_render_to_texture");
1602 TestRenderbufferStorageMultisampleEXT("GL_IMG_multisampled_render_to_texture",
1606 TEST_P(GLES2DecoderMultisampledRenderToTextureTest
,
1607 RenderbufferStorageMultisampleEXT_EXT_RebindRenderbuffer
) {
1608 Init("GL_EXT_multisampled_render_to_texture");
1609 TestRenderbufferStorageMultisampleEXT("GL_EXT_multisampled_render_to_texture",
1613 TEST_P(GLES2DecoderMultisampledRenderToTextureTest
,
1614 RenderbufferStorageMultisampleEXT_IMG_RebindRenderbuffer
) {
1615 Init("GL_IMG_multisampled_render_to_texture");
1616 TestRenderbufferStorageMultisampleEXT("GL_IMG_multisampled_render_to_texture",
1620 TEST_P(GLES2DecoderTest
, ReadPixelsGLError
) {
1621 GLenum kFormat
= GL_RGBA
;
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();
1636 ReadPixels(x
, y
, width
, height
, kFormat
, GL_UNSIGNED_BYTE
, _
))
1638 .RetiresOnSaturation();
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
);
1668 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1670 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1671 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1672 GL_COLOR_ATTACHMENT0
,
1674 kFBOClientTextureId
,
1675 kFBOServiceTextureId
,
1678 // Set scissor rect and enable GL_SCISSOR_TEST to make sure we re-enable it
1679 // and restore the rect again after the clear.
1680 DoEnableDisable(GL_SCISSOR_TEST
, true);
1681 DoScissor(0, 0, 64, 64);
1683 // Setup "render from" texture.
1686 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
1687 GL_COLOR_BUFFER_BIT
, // clear bits
1692 true, // scissor test
1694 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
1695 false, // Framebuffer has depth
1696 false, // Framebuffer has stencil
1697 0x1111, // color bits
1698 false, // depth mask
1699 false, // depth enabled
1700 0, // front stencil mask
1701 0, // back stencil mask
1702 false); // stencil enabled
1704 EXPECT_CALL(*gl_
, Clear(GL_COLOR_BUFFER_BIT
)).Times(1).RetiresOnSaturation();
1707 cmd
.Init(GL_COLOR_BUFFER_BIT
);
1708 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1709 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1712 TEST_P(GLES2DecoderWithShaderTest
, UnClearedAttachmentsGetClearedOnReadPixels
) {
1713 const GLuint kFBOClientTextureId
= 4100;
1714 const GLuint kFBOServiceTextureId
= 4101;
1716 // Register a texture id.
1717 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1718 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
1719 .RetiresOnSaturation();
1720 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
1722 // Setup "render to" texture.
1723 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
1725 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1727 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1728 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1729 GL_COLOR_ATTACHMENT0
,
1731 kFBOClientTextureId
,
1732 kFBOServiceTextureId
,
1735 DoEnableDisable(GL_SCISSOR_TEST
, false);
1736 DoScissor(0, 0, 1, 1);
1738 // Setup "render from" texture.
1741 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
1742 GL_COLOR_BUFFER_BIT
, // clear bits
1747 false, // scissor test
1750 EXPECT_CALL(*gl_
, GetError())
1751 .WillOnce(Return(GL_NO_ERROR
))
1752 .WillOnce(Return(GL_NO_ERROR
))
1753 .RetiresOnSaturation();
1754 EXPECT_CALL(*gl_
, ReadPixels(0, 0, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
1756 .RetiresOnSaturation();
1757 typedef ReadPixels::Result Result
;
1758 uint32 result_shm_id
= kSharedMemoryId
;
1759 uint32 result_shm_offset
= kSharedMemoryOffset
;
1760 uint32 pixels_shm_id
= kSharedMemoryId
;
1761 uint32 pixels_shm_offset
= kSharedMemoryOffset
+ sizeof(Result
);
1774 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1775 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1778 TEST_P(GLES2DecoderManualInitTest
,
1779 UnClearedAttachmentsGetClearedOnReadPixelsAndDrawBufferGetsRestored
) {
1781 init
.extensions
= "GL_EXT_framebuffer_multisample";
1782 init
.bind_generates_resource
= true;
1784 const GLuint kFBOClientTextureId
= 4100;
1785 const GLuint kFBOServiceTextureId
= 4101;
1787 // Register a texture id.
1788 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1789 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
1790 .RetiresOnSaturation();
1791 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
1793 // Setup "render from" texture.
1794 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
1796 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1798 GL_READ_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1799 DoFramebufferTexture2D(GL_READ_FRAMEBUFFER
,
1800 GL_COLOR_ATTACHMENT0
,
1802 kFBOClientTextureId
,
1803 kFBOServiceTextureId
,
1807 // Set scissor rect and disable GL_SCISSOR_TEST to make sure we enable it in
1808 // the clear, then disable it and restore the rect again.
1809 DoScissor(0, 0, 32, 32);
1810 DoEnableDisable(GL_SCISSOR_TEST
, false);
1812 SetupExpectationsForFramebufferClearingMulti(
1813 kServiceFramebufferId
, // read framebuffer service id
1814 0, // backbuffer service id
1815 GL_READ_FRAMEBUFFER
, // target
1816 GL_COLOR_BUFFER_BIT
, // clear bits
1821 false, // scissor test
1824 EXPECT_CALL(*gl_
, GetError())
1825 .WillOnce(Return(GL_NO_ERROR
))
1826 .WillOnce(Return(GL_NO_ERROR
))
1827 .RetiresOnSaturation();
1828 EXPECT_CALL(*gl_
, ReadPixels(0, 0, 1, 1, GL_RGBA
, GL_UNSIGNED_BYTE
, _
))
1830 .RetiresOnSaturation();
1831 typedef ReadPixels::Result Result
;
1832 uint32 result_shm_id
= kSharedMemoryId
;
1833 uint32 result_shm_offset
= kSharedMemoryOffset
;
1834 uint32 pixels_shm_id
= kSharedMemoryId
;
1835 uint32 pixels_shm_offset
= kSharedMemoryOffset
+ sizeof(Result
);
1848 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1849 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
1852 TEST_P(GLES2DecoderWithShaderTest
, CopyTexImageWithInCompleteFBOFails
) {
1853 GLenum target
= GL_TEXTURE_2D
;
1855 GLenum internal_format
= GL_RGBA
;
1860 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1862 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1863 DoRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA4
, GL_RGBA
, 0, 0, GL_NO_ERROR
);
1864 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
1865 GL_COLOR_ATTACHMENT0
,
1867 client_renderbuffer_id_
,
1868 kServiceRenderbufferId
,
1871 EXPECT_CALL(*gl_
, CopyTexImage2D(_
, _
, _
, _
, _
, _
, _
, _
))
1873 .RetiresOnSaturation();
1875 cmd
.Init(target
, level
, internal_format
, 0, 0, width
, height
);
1876 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
1877 EXPECT_EQ(GL_INVALID_FRAMEBUFFER_OPERATION
, GetGLError());
1880 void GLES2DecoderWithShaderTest::CheckRenderbufferChangesMarkFBOAsNotComplete(
1882 FramebufferManager
* framebuffer_manager
= group().framebuffer_manager();
1885 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1887 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1888 DoRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA4
, GL_RGBA
, 1, 1, GL_NO_ERROR
);
1889 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
1890 GL_COLOR_ATTACHMENT0
,
1892 client_renderbuffer_id_
,
1893 kServiceRenderbufferId
,
1897 DoBindFramebuffer(GL_FRAMEBUFFER
, 0, 0);
1900 Framebuffer
* framebuffer
=
1901 framebuffer_manager
->GetFramebuffer(client_framebuffer_id_
);
1902 ASSERT_TRUE(framebuffer
!= NULL
);
1903 framebuffer_manager
->MarkAsComplete(framebuffer
);
1904 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
1906 // Test that renderbufferStorage marks fbo as not complete.
1907 DoRenderbufferStorage(GL_RENDERBUFFER
, GL_RGBA4
, GL_RGBA
, 1, 1, GL_NO_ERROR
);
1908 EXPECT_FALSE(framebuffer_manager
->IsComplete(framebuffer
));
1909 framebuffer_manager
->MarkAsComplete(framebuffer
);
1910 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
1912 // Test deleting renderbuffer marks fbo as not complete.
1913 DoDeleteRenderbuffer(client_renderbuffer_id_
, kServiceRenderbufferId
);
1915 EXPECT_FALSE(framebuffer_manager
->IsComplete(framebuffer
));
1917 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
1920 DoDeleteFramebuffer(client_framebuffer_id_
,
1921 kServiceFramebufferId
,
1930 TEST_P(GLES2DecoderWithShaderTest
,
1931 RenderbufferChangesMarkFBOAsNotCompleteBoundFBO
) {
1932 CheckRenderbufferChangesMarkFBOAsNotComplete(true);
1935 TEST_P(GLES2DecoderWithShaderTest
,
1936 RenderbufferChangesMarkFBOAsNotCompleteUnboundFBO
) {
1937 CheckRenderbufferChangesMarkFBOAsNotComplete(false);
1940 void GLES2DecoderWithShaderTest::CheckTextureChangesMarkFBOAsNotComplete(
1942 FramebufferManager
* framebuffer_manager
= group().framebuffer_manager();
1943 const GLuint kFBOClientTextureId
= 4100;
1944 const GLuint kFBOServiceTextureId
= 4101;
1946 // Register a texture id.
1947 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
1948 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
1949 .RetiresOnSaturation();
1950 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
1954 // Setup "render to" texture.
1955 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
1957 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
1959 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1960 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
1961 GL_COLOR_ATTACHMENT0
,
1963 kFBOClientTextureId
,
1964 kFBOServiceTextureId
,
1969 GL_RENDERBUFFER
, client_renderbuffer_id_
, kServiceRenderbufferId
);
1971 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
1972 DoRenderbufferStorage(GL_RENDERBUFFER
,
1973 GL_DEPTH_COMPONENT16
,
1978 DoFramebufferRenderbuffer(GL_FRAMEBUFFER
,
1979 GL_DEPTH_ATTACHMENT
,
1981 client_renderbuffer_id_
,
1982 kServiceRenderbufferId
,
1986 DoBindFramebuffer(GL_FRAMEBUFFER
, 0, 0);
1989 Framebuffer
* framebuffer
=
1990 framebuffer_manager
->GetFramebuffer(client_framebuffer_id_
);
1991 ASSERT_TRUE(framebuffer
!= NULL
);
1992 framebuffer_manager
->MarkAsComplete(framebuffer
);
1993 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
1995 // Test TexImage2D marks fbo as not complete.
1997 GL_TEXTURE_2D
, 0, GL_RGB
, 1, 1, 0, GL_RGB
, GL_UNSIGNED_BYTE
, 0, 0);
1998 EXPECT_FALSE(framebuffer_manager
->IsComplete(framebuffer
));
1999 framebuffer_manager
->MarkAsComplete(framebuffer
);
2000 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
2002 // Test CopyImage2D marks fbo as not complete.
2003 EXPECT_CALL(*gl_
, GetError())
2004 .WillOnce(Return(GL_NO_ERROR
))
2005 .RetiresOnSaturation();
2006 EXPECT_CALL(*gl_
, CopyTexImage2D(GL_TEXTURE_2D
, 0, GL_RGB
, 0, 0, 1, 1, 0))
2008 .RetiresOnSaturation();
2009 EXPECT_CALL(*gl_
, GetError())
2010 .WillOnce(Return(GL_NO_ERROR
))
2011 .RetiresOnSaturation();
2013 cmd
.Init(GL_TEXTURE_2D
, 0, GL_RGB
, 0, 0, 1, 1);
2014 // Unbind fbo and bind again after CopyTexImage2D tp avoid feedback loops.
2016 DoBindFramebuffer(GL_FRAMEBUFFER
, 0, 0);
2018 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2021 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2023 EXPECT_FALSE(framebuffer_manager
->IsComplete(framebuffer
));
2025 // Test deleting texture marks fbo as not complete.
2026 framebuffer_manager
->MarkAsComplete(framebuffer
);
2027 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
2028 DoDeleteTexture(kFBOClientTextureId
, kFBOServiceTextureId
);
2031 EXPECT_FALSE(framebuffer_manager
->IsComplete(framebuffer
));
2033 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
2036 DoDeleteFramebuffer(client_framebuffer_id_
,
2037 kServiceFramebufferId
,
2046 TEST_P(GLES2DecoderWithShaderTest
, TextureChangesMarkFBOAsNotCompleteBoundFBO
) {
2047 CheckTextureChangesMarkFBOAsNotComplete(true);
2050 TEST_P(GLES2DecoderWithShaderTest
,
2051 TextureChangesMarkFBOAsNotCompleteUnboundFBO
) {
2052 CheckTextureChangesMarkFBOAsNotComplete(false);
2055 TEST_P(GLES2DecoderTest
, CanChangeSurface
) {
2056 scoped_refptr
<GLSurfaceMock
> other_surface(new GLSurfaceMock
);
2057 EXPECT_CALL(*other_surface
.get(), GetBackingFrameBufferObject())
2058 .WillOnce(Return(7));
2059 EXPECT_CALL(*gl_
, BindFramebufferEXT(GL_FRAMEBUFFER_EXT
, 7));
2061 decoder_
->SetSurface(other_surface
);
2064 TEST_P(GLES2DecoderTest
, DrawBuffersEXTImmediateSuccceeds
) {
2065 const GLsizei count
= 1;
2066 const GLenum bufs
[] = {GL_COLOR_ATTACHMENT0
};
2067 DrawBuffersEXTImmediate
& cmd
= *GetImmediateAs
<DrawBuffersEXTImmediate
>();
2068 cmd
.Init(count
, bufs
);
2071 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2072 EXPECT_CALL(*gl_
, DrawBuffersARB(count
, _
)).Times(1).RetiresOnSaturation();
2073 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(bufs
)));
2074 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2077 TEST_P(GLES2DecoderTest
, DrawBuffersEXTImmediateFails
) {
2078 const GLsizei count
= 1;
2079 const GLenum bufs
[] = {GL_COLOR_ATTACHMENT1_EXT
};
2080 DrawBuffersEXTImmediate
& cmd
= *GetImmediateAs
<DrawBuffersEXTImmediate
>();
2081 cmd
.Init(count
, bufs
);
2084 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2085 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(bufs
)));
2086 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2089 TEST_P(GLES2DecoderTest
, DrawBuffersEXTImmediateBackbuffer
) {
2090 const GLsizei count
= 1;
2091 const GLenum bufs
[] = {GL_BACK
};
2092 DrawBuffersEXTImmediate
& cmd
= *GetImmediateAs
<DrawBuffersEXTImmediate
>();
2093 cmd
.Init(count
, bufs
);
2096 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2097 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(bufs
)));
2098 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2100 DoBindFramebuffer(GL_FRAMEBUFFER
, 0, 0); // unbind
2102 EXPECT_CALL(*gl_
, DrawBuffersARB(count
, _
)).Times(1).RetiresOnSaturation();
2104 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(bufs
)));
2105 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2108 TEST_P(GLES2DecoderManualInitTest
, InvalidateFramebufferBinding
) {
2110 init
.gl_version
= "opengl es 3.0";
2113 // EXPECT_EQ can't be used to compare function pointers
2115 gfx::MockGLInterface::GetGLProcAddress("glInvalidateFramebuffer") !=
2116 gfx::g_driver_gl
.fn
.glDiscardFramebufferEXTFn
);
2118 gfx::MockGLInterface::GetGLProcAddress("glInvalidateFramebuffer") !=
2119 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT"));
2122 TEST_P(GLES2DecoderManualInitTest
, DiscardFramebufferEXT
) {
2124 init
.extensions
= "GL_EXT_discard_framebuffer";
2125 init
.gl_version
= "opengl es 2.0";
2128 // EXPECT_EQ can't be used to compare function pointers
2130 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT") ==
2131 gfx::g_driver_gl
.fn
.glDiscardFramebufferEXTFn
);
2133 const GLenum target
= GL_FRAMEBUFFER
;
2134 const GLsizei count
= 1;
2135 const GLenum attachments
[] = {GL_COLOR_ATTACHMENT0
};
2139 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2140 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2141 GL_COLOR_ATTACHMENT0
,
2147 FramebufferManager
* framebuffer_manager
= group().framebuffer_manager();
2148 Framebuffer
* framebuffer
=
2149 framebuffer_manager
->GetFramebuffer(client_framebuffer_id_
);
2150 EXPECT_TRUE(framebuffer
->IsCleared());
2152 EXPECT_CALL(*gl_
, DiscardFramebufferEXT(target
, count
, _
))
2154 .RetiresOnSaturation();
2155 DiscardFramebufferEXTImmediate
& cmd
=
2156 *GetImmediateAs
<DiscardFramebufferEXTImmediate
>();
2157 cmd
.Init(target
, count
, attachments
);
2159 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(attachments
)));
2160 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2161 EXPECT_FALSE(framebuffer
->IsCleared());
2164 TEST_P(GLES2DecoderTest
, DiscardFramebufferEXTUnsupported
) {
2165 const GLenum target
= GL_FRAMEBUFFER
;
2166 const GLsizei count
= 1;
2167 const GLenum attachments
[] = {GL_COLOR_EXT
};
2168 DiscardFramebufferEXTImmediate
& cmd
=
2169 *GetImmediateAs
<DiscardFramebufferEXTImmediate
>();
2170 cmd
.Init(target
, count
, attachments
);
2172 // Should not result into a call into GL.
2173 EXPECT_EQ(error::kNoError
, ExecuteImmediateCmd(cmd
, sizeof(attachments
)));
2174 EXPECT_EQ(GL_INVALID_OPERATION
, GetGLError());
2177 TEST_P(GLES2DecoderManualInitTest
,
2178 DiscardedAttachmentsEXTMarksFramebufferIncomplete
) {
2180 init
.extensions
= "GL_EXT_discard_framebuffer";
2181 init
.gl_version
= "opengl es 2.0";
2182 init
.has_alpha
= true;
2183 init
.bind_generates_resource
= true;
2186 const GLuint kFBOClientTextureId
= 4100;
2187 const GLuint kFBOServiceTextureId
= 4101;
2189 // Register a texture id.
2190 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2191 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2192 .RetiresOnSaturation();
2193 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2195 // Setup "render to" texture.
2196 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2198 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2200 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2201 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2202 GL_COLOR_ATTACHMENT0
,
2204 kFBOClientTextureId
,
2205 kFBOServiceTextureId
,
2208 DoEnableDisable(GL_SCISSOR_TEST
, false);
2209 DoScissor(0, 0, 1, 1);
2211 // Setup "render from" texture.
2214 SetupExpectationsForFramebufferClearing(GL_FRAMEBUFFER
, // target
2215 GL_COLOR_BUFFER_BIT
, // clear bits
2220 false, // scissor test
2222 SetupExpectationsForApplyingDirtyState(false, // Framebuffer is RGB
2223 false, // Framebuffer has depth
2224 false, // Framebuffer has stencil
2225 0x1111, // color bits
2226 false, // depth mask
2227 false, // depth enabled
2228 0, // front stencil mask
2229 0, // back stencil mask
2230 false); // stencil enabled
2232 EXPECT_CALL(*gl_
, Clear(GL_COLOR_BUFFER_BIT
)).Times(1).RetiresOnSaturation();
2235 clear_cmd
.Init(GL_COLOR_BUFFER_BIT
);
2236 EXPECT_EQ(error::kNoError
, ExecuteCmd(clear_cmd
));
2237 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2239 // Check that framebuffer is cleared and complete.
2240 FramebufferManager
* framebuffer_manager
= group().framebuffer_manager();
2241 Framebuffer
* framebuffer
=
2242 framebuffer_manager
->GetFramebuffer(client_framebuffer_id_
);
2243 EXPECT_TRUE(framebuffer
->IsCleared());
2244 EXPECT_TRUE(framebuffer_manager
->IsComplete(framebuffer
));
2246 // Check that Discard GL_COLOR_ATTACHMENT0, sets the attachment as uncleared
2247 // and the framebuffer as incomplete.
2249 gfx::MockGLInterface::GetGLProcAddress("glDiscardFramebufferEXT") ==
2250 gfx::g_driver_gl
.fn
.glDiscardFramebufferEXTFn
);
2252 const GLenum target
= GL_FRAMEBUFFER
;
2253 const GLsizei count
= 1;
2254 const GLenum attachments
[] = {GL_COLOR_ATTACHMENT0
};
2256 DiscardFramebufferEXTImmediate
& discard_cmd
=
2257 *GetImmediateAs
<DiscardFramebufferEXTImmediate
>();
2258 discard_cmd
.Init(target
, count
, attachments
);
2260 EXPECT_CALL(*gl_
, DiscardFramebufferEXT(target
, count
, _
))
2262 .RetiresOnSaturation();
2263 EXPECT_EQ(error::kNoError
,
2264 ExecuteImmediateCmd(discard_cmd
, sizeof(attachments
)));
2265 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2266 EXPECT_FALSE(framebuffer
->IsCleared());
2267 EXPECT_FALSE(framebuffer_manager
->IsComplete(framebuffer
));
2270 TEST_P(GLES2DecoderManualInitTest
, ReadFormatExtension
) {
2272 init
.extensions
= "GL_OES_read_format";
2273 init
.bind_generates_resource
= true;
2276 EXPECT_CALL(*gl_
, GetError())
2277 .WillOnce(Return(GL_NO_ERROR
))
2278 .WillOnce(Return(GL_NO_ERROR
))
2279 .WillOnce(Return(GL_NO_ERROR
))
2280 .WillOnce(Return(GL_NO_ERROR
))
2281 .RetiresOnSaturation();
2282 EXPECT_CALL(*gl_
, GetError()).Times(6).RetiresOnSaturation();
2284 typedef GetIntegerv::Result Result
;
2285 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
2287 const GLuint kFBOClientTextureId
= 4100;
2288 const GLuint kFBOServiceTextureId
= 4101;
2290 // Register a texture id.
2291 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2292 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2293 .RetiresOnSaturation();
2294 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2296 // Setup "render to" texture.
2297 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2299 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2301 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2302 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2303 GL_COLOR_ATTACHMENT0
,
2305 kFBOClientTextureId
,
2306 kFBOServiceTextureId
,
2311 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(1).RetiresOnSaturation();
2312 cmd
.Init(GL_IMPLEMENTATION_COLOR_READ_FORMAT
,
2314 shared_memory_offset_
);
2315 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2316 EXPECT_EQ(1, result
->GetNumResults());
2317 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2320 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(1).RetiresOnSaturation();
2321 cmd
.Init(GL_IMPLEMENTATION_COLOR_READ_TYPE
,
2323 shared_memory_offset_
);
2324 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2325 EXPECT_EQ(1, result
->GetNumResults());
2326 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2329 TEST_P(GLES2DecoderManualInitTest
, NoReadFormatExtension
) {
2331 init
.bind_generates_resource
= true;
2334 EXPECT_CALL(*gl_
, GetError())
2335 .WillOnce(Return(GL_NO_ERROR
))
2336 .WillOnce(Return(GL_NO_ERROR
))
2337 .WillOnce(Return(GL_NO_ERROR
))
2338 .WillOnce(Return(GL_NO_ERROR
))
2339 .RetiresOnSaturation();
2341 typedef GetIntegerv::Result Result
;
2342 Result
* result
= static_cast<Result
*>(shared_memory_address_
);
2344 const GLuint kFBOClientTextureId
= 4100;
2345 const GLuint kFBOServiceTextureId
= 4101;
2347 // Register a texture id.
2348 EXPECT_CALL(*gl_
, GenTextures(_
, _
))
2349 .WillOnce(SetArgumentPointee
<1>(kFBOServiceTextureId
))
2350 .RetiresOnSaturation();
2351 GenHelper
<GenTexturesImmediate
>(kFBOClientTextureId
);
2353 // Setup "render to" texture.
2354 DoBindTexture(GL_TEXTURE_2D
, kFBOClientTextureId
, kFBOServiceTextureId
);
2356 GL_TEXTURE_2D
, 0, GL_RGBA
, 1, 1, 0, GL_RGBA
, GL_UNSIGNED_BYTE
, 0, 0);
2358 GL_FRAMEBUFFER
, client_framebuffer_id_
, kServiceFramebufferId
);
2359 DoFramebufferTexture2D(GL_FRAMEBUFFER
,
2360 GL_COLOR_ATTACHMENT0
,
2362 kFBOClientTextureId
,
2363 kFBOServiceTextureId
,
2368 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
2369 cmd
.Init(GL_IMPLEMENTATION_COLOR_READ_FORMAT
,
2371 shared_memory_offset_
);
2372 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2373 EXPECT_EQ(1, result
->GetNumResults());
2374 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2377 EXPECT_CALL(*gl_
, GetIntegerv(_
, _
)).Times(0).RetiresOnSaturation();
2378 cmd
.Init(GL_IMPLEMENTATION_COLOR_READ_TYPE
,
2380 shared_memory_offset_
);
2381 EXPECT_EQ(error::kNoError
, ExecuteCmd(cmd
));
2382 EXPECT_EQ(1, result
->GetNumResults());
2383 EXPECT_EQ(GL_NO_ERROR
, GetGLError());
2386 // TODO(gman): PixelStorei
2388 // TODO(gman): SwapBuffers
2390 } // namespace gles2