base: Change DCHECK_IS_ON to a macro DCHECK_IS_ON().
[chromium-blink-merge.git] / gpu / command_buffer / service / gles2_cmd_decoder_unittest.cc
blob8794e422f59e33050962061bf3f74fe357bbdb21
1 // Copyright (c) 2012 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_unittest.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.h"
19 #include "gpu/command_buffer/service/gpu_switches.h"
20 #include "gpu/command_buffer/service/image_manager.h"
21 #include "gpu/command_buffer/service/mailbox_manager.h"
22 #include "gpu/command_buffer/service/mocks.h"
23 #include "gpu/command_buffer/service/program_manager.h"
24 #include "gpu/command_buffer/service/test_helper.h"
25 #include "testing/gtest/include/gtest/gtest.h"
26 #include "ui/gl/gl_implementation.h"
27 #include "ui/gl/gl_mock.h"
28 #include "ui/gl/gl_surface_stub.h"
31 #if !defined(GL_DEPTH24_STENCIL8)
32 #define GL_DEPTH24_STENCIL8 0x88F0
33 #endif
35 using ::gfx::MockGLInterface;
36 using ::testing::_;
37 using ::testing::AtLeast;
38 using ::testing::DoAll;
39 using ::testing::InSequence;
40 using ::testing::Invoke;
41 using ::testing::MatcherCast;
42 using ::testing::Mock;
43 using ::testing::Pointee;
44 using ::testing::Return;
45 using ::testing::SaveArg;
46 using ::testing::SetArrayArgument;
47 using ::testing::SetArgumentPointee;
48 using ::testing::SetArgPointee;
49 using ::testing::StrEq;
50 using ::testing::StrictMock;
52 namespace gpu {
53 namespace gles2 {
55 using namespace cmds;
57 void GLES2DecoderRGBBackbufferTest::SetUp() {
58 // Test codepath with workaround clear_alpha_in_readpixels because
59 // ReadPixelsEmulator emulates the incorrect driver behavior.
60 base::CommandLine command_line(0, NULL);
61 command_line.AppendSwitchASCII(
62 switches::kGpuDriverBugWorkarounds,
63 base::IntToString(gpu::CLEAR_ALPHA_IN_READPIXELS));
64 InitState init;
65 init.gl_version = "3.0";
66 init.bind_generates_resource = true;
67 InitDecoderWithCommandLine(init, &command_line);
68 SetupDefaultProgram();
71 // Override default setup so nothing gets setup.
72 void GLES2DecoderManualInitTest::SetUp() {
75 void GLES2DecoderManualInitTest::EnableDisableTest(GLenum cap,
76 bool enable,
77 bool expect_set) {
78 if (expect_set) {
79 SetupExpectationsForEnableDisable(cap, enable);
81 if (enable) {
82 Enable cmd;
83 cmd.Init(cap);
84 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
85 EXPECT_EQ(GL_NO_ERROR, GetGLError());
86 } else {
87 Disable cmd;
88 cmd.Init(cap);
89 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
90 EXPECT_EQ(GL_NO_ERROR, GetGLError());
94 TEST_P(GLES2DecoderTest, GetIntegervCached) {
95 struct TestInfo {
96 GLenum pname;
97 GLint expected;
99 TestInfo tests[] = {
101 GL_MAX_TEXTURE_SIZE, TestHelper::kMaxTextureSize,
104 GL_MAX_CUBE_MAP_TEXTURE_SIZE, TestHelper::kMaxCubeMapTextureSize,
107 GL_MAX_RENDERBUFFER_SIZE, TestHelper::kMaxRenderbufferSize,
110 typedef GetIntegerv::Result Result;
111 for (size_t ii = 0; ii < sizeof(tests) / sizeof(tests[0]); ++ii) {
112 const TestInfo& test = tests[ii];
113 Result* result = static_cast<Result*>(shared_memory_address_);
114 EXPECT_CALL(*gl_, GetError())
115 .WillOnce(Return(GL_NO_ERROR))
116 .WillOnce(Return(GL_NO_ERROR))
117 .RetiresOnSaturation();
118 EXPECT_CALL(*gl_, GetIntegerv(test.pname, _)).Times(0);
119 result->size = 0;
120 GetIntegerv cmd2;
121 cmd2.Init(test.pname, shared_memory_id_, shared_memory_offset_);
122 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
123 EXPECT_EQ(decoder_->GetGLES2Util()->GLGetNumValuesReturned(test.pname),
124 result->GetNumResults());
125 EXPECT_EQ(GL_NO_ERROR, GetGLError());
126 EXPECT_EQ(test.expected, result->GetData()[0]);
130 TEST_P(GLES2DecoderWithShaderTest, GetMaxValueInBufferCHROMIUM) {
131 SetupIndexBuffer();
132 GetMaxValueInBufferCHROMIUM::Result* result =
133 static_cast<GetMaxValueInBufferCHROMIUM::Result*>(shared_memory_address_);
134 *result = 0;
136 GetMaxValueInBufferCHROMIUM cmd;
137 cmd.Init(client_element_buffer_id_,
138 kValidIndexRangeCount,
139 GL_UNSIGNED_SHORT,
140 kValidIndexRangeStart * 2,
141 kSharedMemoryId,
142 kSharedMemoryOffset);
143 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
144 EXPECT_EQ(7u, *result);
145 EXPECT_EQ(GL_NO_ERROR, GetGLError());
146 cmd.Init(client_element_buffer_id_,
147 kValidIndexRangeCount + 1,
148 GL_UNSIGNED_SHORT,
149 kValidIndexRangeStart * 2,
150 kSharedMemoryId,
151 kSharedMemoryOffset);
152 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
153 EXPECT_EQ(100u, *result);
154 EXPECT_EQ(GL_NO_ERROR, GetGLError());
156 cmd.Init(kInvalidClientId,
157 kValidIndexRangeCount,
158 GL_UNSIGNED_SHORT,
159 kValidIndexRangeStart * 2,
160 kSharedMemoryId,
161 kSharedMemoryOffset);
162 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
163 EXPECT_EQ(GL_INVALID_VALUE, GetGLError());
164 cmd.Init(client_element_buffer_id_,
165 kOutOfRangeIndexRangeEnd,
166 GL_UNSIGNED_SHORT,
167 kValidIndexRangeStart * 2,
168 kSharedMemoryId,
169 kSharedMemoryOffset);
170 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
171 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
172 cmd.Init(client_element_buffer_id_,
173 kValidIndexRangeCount + 1,
174 GL_UNSIGNED_SHORT,
175 kOutOfRangeIndexRangeEnd * 2,
176 kSharedMemoryId,
177 kSharedMemoryOffset);
178 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
179 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
180 cmd.Init(client_element_buffer_id_,
181 kValidIndexRangeCount + 1,
182 GL_UNSIGNED_SHORT,
183 kValidIndexRangeStart * 2,
184 kSharedMemoryId,
185 kSharedMemoryOffset);
186 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
187 cmd.Init(client_buffer_id_,
188 kValidIndexRangeCount + 1,
189 GL_UNSIGNED_SHORT,
190 kValidIndexRangeStart * 2,
191 kSharedMemoryId,
192 kSharedMemoryOffset);
193 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
194 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
195 cmd.Init(client_element_buffer_id_,
196 kValidIndexRangeCount + 1,
197 GL_UNSIGNED_SHORT,
198 kValidIndexRangeStart * 2,
199 kInvalidSharedMemoryId,
200 kSharedMemoryOffset);
201 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
202 cmd.Init(client_element_buffer_id_,
203 kValidIndexRangeCount + 1,
204 GL_UNSIGNED_SHORT,
205 kValidIndexRangeStart * 2,
206 kSharedMemoryId,
207 kInvalidSharedMemoryOffset);
208 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
211 TEST_P(GLES2DecoderTest, IsBuffer) {
212 EXPECT_FALSE(DoIsBuffer(client_buffer_id_));
213 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
214 EXPECT_TRUE(DoIsBuffer(client_buffer_id_));
215 DoDeleteBuffer(client_buffer_id_, kServiceBufferId);
216 EXPECT_FALSE(DoIsBuffer(client_buffer_id_));
219 TEST_P(GLES2DecoderTest, IsFramebuffer) {
220 EXPECT_FALSE(DoIsFramebuffer(client_framebuffer_id_));
221 DoBindFramebuffer(
222 GL_FRAMEBUFFER, client_framebuffer_id_, kServiceFramebufferId);
223 EXPECT_TRUE(DoIsFramebuffer(client_framebuffer_id_));
224 DoDeleteFramebuffer(client_framebuffer_id_,
225 kServiceFramebufferId,
226 true,
227 GL_FRAMEBUFFER,
229 true,
230 GL_FRAMEBUFFER,
232 EXPECT_FALSE(DoIsFramebuffer(client_framebuffer_id_));
235 TEST_P(GLES2DecoderTest, IsProgram) {
236 // IsProgram is true as soon as the program is created.
237 EXPECT_TRUE(DoIsProgram(client_program_id_));
238 EXPECT_CALL(*gl_, DeleteProgram(kServiceProgramId))
239 .Times(1)
240 .RetiresOnSaturation();
241 DoDeleteProgram(client_program_id_, kServiceProgramId);
242 EXPECT_FALSE(DoIsProgram(client_program_id_));
245 TEST_P(GLES2DecoderTest, IsRenderbuffer) {
246 EXPECT_FALSE(DoIsRenderbuffer(client_renderbuffer_id_));
247 DoBindRenderbuffer(
248 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
249 EXPECT_TRUE(DoIsRenderbuffer(client_renderbuffer_id_));
250 DoDeleteRenderbuffer(client_renderbuffer_id_, kServiceRenderbufferId);
251 EXPECT_FALSE(DoIsRenderbuffer(client_renderbuffer_id_));
254 TEST_P(GLES2DecoderTest, IsShader) {
255 // IsShader is true as soon as the program is created.
256 EXPECT_TRUE(DoIsShader(client_shader_id_));
257 DoDeleteShader(client_shader_id_, kServiceShaderId);
258 EXPECT_FALSE(DoIsShader(client_shader_id_));
261 TEST_P(GLES2DecoderTest, IsTexture) {
262 EXPECT_FALSE(DoIsTexture(client_texture_id_));
263 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
264 EXPECT_TRUE(DoIsTexture(client_texture_id_));
265 DoDeleteTexture(client_texture_id_, kServiceTextureId);
266 EXPECT_FALSE(DoIsTexture(client_texture_id_));
269 TEST_P(GLES2DecoderManualInitTest, BindGeneratesResourceFalse) {
270 InitState init;
271 init.gl_version = "3.0";
272 InitDecoder(init);
274 BindTexture cmd1;
275 cmd1.Init(GL_TEXTURE_2D, kInvalidClientId);
276 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd1));
277 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
279 BindBuffer cmd2;
280 cmd2.Init(GL_ARRAY_BUFFER, kInvalidClientId);
281 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd2));
282 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
284 BindFramebuffer cmd3;
285 cmd3.Init(GL_FRAMEBUFFER, kInvalidClientId);
286 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd3));
287 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
289 BindRenderbuffer cmd4;
290 cmd4.Init(GL_RENDERBUFFER, kInvalidClientId);
291 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd4));
292 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
295 TEST_P(GLES2DecoderTest, EnableFeatureCHROMIUMBadBucket) {
296 const uint32 kBadBucketId = 123;
297 EnableFeatureCHROMIUM cmd;
298 cmd.Init(kBadBucketId, shared_memory_id_, shared_memory_offset_);
299 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
302 TEST_P(GLES2DecoderTest, RequestExtensionCHROMIUMBadBucket) {
303 const uint32 kBadBucketId = 123;
304 RequestExtensionCHROMIUM cmd;
305 cmd.Init(kBadBucketId);
306 EXPECT_NE(error::kNoError, ExecuteCmd(cmd));
309 TEST_P(GLES2DecoderTest, BeginQueryEXTDisabled) {
310 // Test something fails if off.
313 TEST_P(GLES2DecoderManualInitTest, BeginEndQueryEXT) {
314 InitState init;
315 init.extensions = "GL_EXT_occlusion_query_boolean";
316 init.gl_version = "opengl es 2.0";
317 init.has_alpha = true;
318 init.request_alpha = true;
319 init.bind_generates_resource = true;
320 InitDecoder(init);
322 // Test end fails if no begin.
323 EndQueryEXT end_cmd;
324 end_cmd.Init(GL_ANY_SAMPLES_PASSED_EXT, 1);
325 EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
326 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
328 BeginQueryEXT begin_cmd;
330 // Test id = 0 fails.
331 begin_cmd.Init(
332 GL_ANY_SAMPLES_PASSED_EXT, 0, kSharedMemoryId, kSharedMemoryOffset);
333 EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
334 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
336 GenHelper<GenQueriesEXTImmediate>(kNewClientId);
338 // Test valid parameters work.
339 EXPECT_CALL(*gl_, GenQueriesARB(1, _))
340 .WillOnce(SetArgumentPointee<1>(kNewServiceId))
341 .RetiresOnSaturation();
342 EXPECT_CALL(*gl_, BeginQueryARB(GL_ANY_SAMPLES_PASSED_EXT, kNewServiceId))
343 .Times(1)
344 .RetiresOnSaturation();
346 // Query object should not be created untill BeginQueriesEXT.
347 QueryManager* query_manager = decoder_->GetQueryManager();
348 ASSERT_TRUE(query_manager != NULL);
349 QueryManager::Query* query = query_manager->GetQuery(kNewClientId);
350 EXPECT_TRUE(query == NULL);
352 // BeginQueryEXT should fail if id is not generated from GenQueriesEXT.
353 begin_cmd.Init(GL_ANY_SAMPLES_PASSED_EXT,
354 kInvalidClientId,
355 kSharedMemoryId,
356 kSharedMemoryOffset);
357 EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
358 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
360 begin_cmd.Init(GL_ANY_SAMPLES_PASSED_EXT,
361 kNewClientId,
362 kSharedMemoryId,
363 kSharedMemoryOffset);
364 EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
365 EXPECT_EQ(GL_NO_ERROR, GetGLError());
367 // After BeginQueriesEXT id name should have query object associated with it.
368 query = query_manager->GetQuery(kNewClientId);
369 ASSERT_TRUE(query != NULL);
370 EXPECT_FALSE(query->pending());
372 // Test trying begin again fails
373 EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
374 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
376 // Test end fails with different target
377 end_cmd.Init(GL_ANY_SAMPLES_PASSED_CONSERVATIVE_EXT, 1);
378 EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
379 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
381 // Test end succeeds
382 EXPECT_CALL(*gl_, EndQueryARB(GL_ANY_SAMPLES_PASSED_EXT))
383 .Times(1)
384 .RetiresOnSaturation();
385 end_cmd.Init(GL_ANY_SAMPLES_PASSED_EXT, 1);
386 EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
387 EXPECT_EQ(GL_NO_ERROR, GetGLError());
388 EXPECT_TRUE(query->pending());
390 EXPECT_CALL(*gl_, DeleteQueriesARB(1, _)).Times(1).RetiresOnSaturation();
393 struct QueryType {
394 GLenum type;
395 bool is_gl;
398 const QueryType kQueryTypes[] = {
399 {GL_COMMANDS_ISSUED_CHROMIUM, false},
400 {GL_LATENCY_QUERY_CHROMIUM, false},
401 {GL_ASYNC_PIXEL_UNPACK_COMPLETED_CHROMIUM, false},
402 {GL_ASYNC_PIXEL_PACK_COMPLETED_CHROMIUM, false},
403 {GL_GET_ERROR_QUERY_CHROMIUM, false},
404 {GL_COMMANDS_COMPLETED_CHROMIUM, false},
405 {GL_ANY_SAMPLES_PASSED_EXT, true},
408 static void CheckBeginEndQueryBadMemoryFails(GLES2DecoderTestBase* test,
409 GLuint client_id,
410 GLuint service_id,
411 const QueryType& query_type,
412 int32 shm_id,
413 uint32 shm_offset) {
414 // We need to reset the decoder on each iteration, because we lose the
415 // context every time.
416 GLES2DecoderTestBase::InitState init;
417 init.extensions = "GL_EXT_occlusion_query_boolean GL_ARB_sync";
418 init.gl_version = "opengl es 2.0";
419 init.has_alpha = true;
420 init.request_alpha = true;
421 init.bind_generates_resource = true;
422 test->InitDecoder(init);
423 ::testing::StrictMock< ::gfx::MockGLInterface>* gl = test->GetGLMock();
425 BeginQueryEXT begin_cmd;
427 test->GenHelper<GenQueriesEXTImmediate>(client_id);
429 if (query_type.is_gl) {
430 EXPECT_CALL(*gl, GenQueriesARB(1, _))
431 .WillOnce(SetArgumentPointee<1>(service_id))
432 .RetiresOnSaturation();
433 EXPECT_CALL(*gl, BeginQueryARB(query_type.type, service_id))
434 .Times(1)
435 .RetiresOnSaturation();
438 // Test bad shared memory fails
439 begin_cmd.Init(query_type.type, client_id, shm_id, shm_offset);
440 error::Error error1 = test->ExecuteCmd(begin_cmd);
442 if (query_type.is_gl) {
443 EXPECT_CALL(*gl, EndQueryARB(query_type.type))
444 .Times(1)
445 .RetiresOnSaturation();
447 if (query_type.type == GL_GET_ERROR_QUERY_CHROMIUM) {
448 EXPECT_CALL(*gl, GetError())
449 .WillOnce(Return(GL_NO_ERROR))
450 .RetiresOnSaturation();
452 GLsync kGlSync = reinterpret_cast<GLsync>(0xdeadbeef);
453 if (query_type.type == GL_COMMANDS_COMPLETED_CHROMIUM) {
454 EXPECT_CALL(*gl, Flush()).RetiresOnSaturation();
455 EXPECT_CALL(*gl, FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0))
456 .WillOnce(Return(kGlSync))
457 .RetiresOnSaturation();
458 #if DCHECK_IS_ON()
459 EXPECT_CALL(*gl, IsSync(kGlSync))
460 .WillOnce(Return(GL_TRUE))
461 .RetiresOnSaturation();
462 #endif
465 EndQueryEXT end_cmd;
466 end_cmd.Init(query_type.type, 1);
467 error::Error error2 = test->ExecuteCmd(end_cmd);
469 if (query_type.is_gl) {
470 EXPECT_CALL(
471 *gl, GetQueryObjectuivARB(service_id, GL_QUERY_RESULT_AVAILABLE_EXT, _))
472 .WillOnce(SetArgumentPointee<2>(1))
473 .RetiresOnSaturation();
474 EXPECT_CALL(*gl, GetQueryObjectuivARB(service_id, GL_QUERY_RESULT_EXT, _))
475 .WillOnce(SetArgumentPointee<2>(1))
476 .RetiresOnSaturation();
478 if (query_type.type == GL_COMMANDS_COMPLETED_CHROMIUM) {
479 #if DCHECK_IS_ON()
480 EXPECT_CALL(*gl, IsSync(kGlSync))
481 .WillOnce(Return(GL_TRUE))
482 .RetiresOnSaturation();
483 #endif
484 EXPECT_CALL(*gl, ClientWaitSync(kGlSync, _, _))
485 .WillOnce(Return(GL_ALREADY_SIGNALED))
486 .RetiresOnSaturation();
489 QueryManager* query_manager = test->GetDecoder()->GetQueryManager();
490 ASSERT_TRUE(query_manager != NULL);
491 bool process_success = query_manager->ProcessPendingQueries(false);
493 EXPECT_TRUE(error1 != error::kNoError || error2 != error::kNoError ||
494 !process_success);
496 if (query_type.is_gl) {
497 EXPECT_CALL(*gl, DeleteQueriesARB(1, _)).Times(1).RetiresOnSaturation();
499 if (query_type.type == GL_COMMANDS_COMPLETED_CHROMIUM) {
500 #if DCHECK_IS_ON()
501 EXPECT_CALL(*gl, IsSync(kGlSync))
502 .WillOnce(Return(GL_TRUE))
503 .RetiresOnSaturation();
504 #endif
505 EXPECT_CALL(*gl, DeleteSync(kGlSync)).Times(1).RetiresOnSaturation();
507 test->ResetDecoder();
510 TEST_P(GLES2DecoderManualInitTest, BeginEndQueryEXTBadMemoryIdFails) {
511 for (size_t i = 0; i < arraysize(kQueryTypes); ++i) {
512 CheckBeginEndQueryBadMemoryFails(this,
513 kNewClientId,
514 kNewServiceId,
515 kQueryTypes[i],
516 kInvalidSharedMemoryId,
517 kSharedMemoryOffset);
521 TEST_P(GLES2DecoderManualInitTest, BeginEndQueryEXTBadMemoryOffsetFails) {
522 for (size_t i = 0; i < arraysize(kQueryTypes); ++i) {
523 // Out-of-bounds.
524 CheckBeginEndQueryBadMemoryFails(this,
525 kNewClientId,
526 kNewServiceId,
527 kQueryTypes[i],
528 kSharedMemoryId,
529 kInvalidSharedMemoryOffset);
530 // Overflow.
531 CheckBeginEndQueryBadMemoryFails(this,
532 kNewClientId,
533 kNewServiceId,
534 kQueryTypes[i],
535 kSharedMemoryId,
536 0xfffffffcu);
540 TEST_P(GLES2DecoderTest, BeginEndQueryEXTCommandsIssuedCHROMIUM) {
541 BeginQueryEXT begin_cmd;
543 GenHelper<GenQueriesEXTImmediate>(kNewClientId);
545 // Test valid parameters work.
546 begin_cmd.Init(GL_COMMANDS_ISSUED_CHROMIUM,
547 kNewClientId,
548 kSharedMemoryId,
549 kSharedMemoryOffset);
550 EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
551 EXPECT_EQ(GL_NO_ERROR, GetGLError());
553 QueryManager* query_manager = decoder_->GetQueryManager();
554 ASSERT_TRUE(query_manager != NULL);
555 QueryManager::Query* query = query_manager->GetQuery(kNewClientId);
556 ASSERT_TRUE(query != NULL);
557 EXPECT_FALSE(query->pending());
559 // Test end succeeds
560 EndQueryEXT end_cmd;
561 end_cmd.Init(GL_COMMANDS_ISSUED_CHROMIUM, 1);
562 EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
563 EXPECT_EQ(GL_NO_ERROR, GetGLError());
564 EXPECT_FALSE(query->pending());
567 TEST_P(GLES2DecoderTest, BeginEndQueryEXTGetErrorQueryCHROMIUM) {
568 BeginQueryEXT begin_cmd;
570 GenHelper<GenQueriesEXTImmediate>(kNewClientId);
572 // Test valid parameters work.
573 begin_cmd.Init(GL_GET_ERROR_QUERY_CHROMIUM,
574 kNewClientId,
575 kSharedMemoryId,
576 kSharedMemoryOffset);
577 EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
578 EXPECT_EQ(GL_NO_ERROR, GetGLError());
580 QueryManager* query_manager = decoder_->GetQueryManager();
581 ASSERT_TRUE(query_manager != NULL);
582 QueryManager::Query* query = query_manager->GetQuery(kNewClientId);
583 ASSERT_TRUE(query != NULL);
584 EXPECT_FALSE(query->pending());
586 // Test end succeeds
587 QuerySync* sync = static_cast<QuerySync*>(shared_memory_address_);
589 EXPECT_CALL(*gl_, GetError())
590 .WillOnce(Return(GL_INVALID_VALUE))
591 .RetiresOnSaturation();
593 EndQueryEXT end_cmd;
594 end_cmd.Init(GL_GET_ERROR_QUERY_CHROMIUM, 1);
595 EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
596 EXPECT_EQ(GL_NO_ERROR, GetGLError());
597 EXPECT_FALSE(query->pending());
598 EXPECT_EQ(static_cast<GLenum>(GL_INVALID_VALUE),
599 static_cast<GLenum>(sync->result));
602 TEST_P(GLES2DecoderManualInitTest, BeginEndQueryEXTCommandsCompletedCHROMIUM) {
603 InitState init;
604 init.extensions = "GL_EXT_occlusion_query_boolean GL_ARB_sync";
605 init.gl_version = "opengl es 2.0";
606 init.has_alpha = true;
607 init.request_alpha = true;
608 init.bind_generates_resource = true;
609 InitDecoder(init);
611 GenHelper<GenQueriesEXTImmediate>(kNewClientId);
613 BeginQueryEXT begin_cmd;
614 begin_cmd.Init(GL_COMMANDS_COMPLETED_CHROMIUM,
615 kNewClientId,
616 kSharedMemoryId,
617 kSharedMemoryOffset);
618 EXPECT_EQ(error::kNoError, ExecuteCmd(begin_cmd));
619 EXPECT_EQ(GL_NO_ERROR, GetGLError());
621 QueryManager* query_manager = decoder_->GetQueryManager();
622 ASSERT_TRUE(query_manager != NULL);
623 QueryManager::Query* query = query_manager->GetQuery(kNewClientId);
624 ASSERT_TRUE(query != NULL);
625 EXPECT_FALSE(query->pending());
627 GLsync kGlSync = reinterpret_cast<GLsync>(0xdeadbeef);
628 EXPECT_CALL(*gl_, Flush()).RetiresOnSaturation();
629 EXPECT_CALL(*gl_, FenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0))
630 .WillOnce(Return(kGlSync))
631 .RetiresOnSaturation();
632 #if DCHECK_IS_ON()
633 EXPECT_CALL(*gl_, IsSync(kGlSync))
634 .WillOnce(Return(GL_TRUE))
635 .RetiresOnSaturation();
636 #endif
638 EndQueryEXT end_cmd;
639 end_cmd.Init(GL_COMMANDS_COMPLETED_CHROMIUM, 1);
640 EXPECT_EQ(error::kNoError, ExecuteCmd(end_cmd));
641 EXPECT_EQ(GL_NO_ERROR, GetGLError());
642 EXPECT_TRUE(query->pending());
644 #if DCHECK_IS_ON()
645 EXPECT_CALL(*gl_, IsSync(kGlSync))
646 .WillOnce(Return(GL_TRUE))
647 .RetiresOnSaturation();
648 #endif
649 EXPECT_CALL(*gl_, ClientWaitSync(kGlSync, _, _))
650 .WillOnce(Return(GL_TIMEOUT_EXPIRED))
651 .RetiresOnSaturation();
652 bool process_success = query_manager->ProcessPendingQueries(false);
654 EXPECT_TRUE(process_success);
655 EXPECT_TRUE(query->pending());
657 #if DCHECK_IS_ON()
658 EXPECT_CALL(*gl_, IsSync(kGlSync))
659 .WillOnce(Return(GL_TRUE))
660 .RetiresOnSaturation();
661 #endif
662 EXPECT_CALL(*gl_, ClientWaitSync(kGlSync, _, _))
663 .WillOnce(Return(GL_ALREADY_SIGNALED))
664 .RetiresOnSaturation();
665 process_success = query_manager->ProcessPendingQueries(false);
667 EXPECT_TRUE(process_success);
668 EXPECT_FALSE(query->pending());
670 #if DCHECK_IS_ON()
671 EXPECT_CALL(*gl_, IsSync(kGlSync))
672 .WillOnce(Return(GL_TRUE))
673 .RetiresOnSaturation();
674 #endif
675 EXPECT_CALL(*gl_, DeleteSync(kGlSync)).Times(1).RetiresOnSaturation();
676 ResetDecoder();
679 TEST_P(GLES2DecoderTest, IsEnabledReturnsCachedValue) {
680 // NOTE: There are no expectations because no GL functions should be
681 // called for DEPTH_TEST or STENCIL_TEST
682 static const GLenum kStates[] = {
683 GL_DEPTH_TEST, GL_STENCIL_TEST,
685 for (size_t ii = 0; ii < arraysize(kStates); ++ii) {
686 Enable enable_cmd;
687 GLenum state = kStates[ii];
688 enable_cmd.Init(state);
689 EXPECT_EQ(error::kNoError, ExecuteCmd(enable_cmd));
690 IsEnabled::Result* result =
691 static_cast<IsEnabled::Result*>(shared_memory_address_);
692 IsEnabled is_enabled_cmd;
693 is_enabled_cmd.Init(state, shared_memory_id_, shared_memory_offset_);
694 EXPECT_EQ(error::kNoError, ExecuteCmd(is_enabled_cmd));
695 EXPECT_NE(0u, *result);
696 Disable disable_cmd;
697 disable_cmd.Init(state);
698 EXPECT_EQ(error::kNoError, ExecuteCmd(disable_cmd));
699 EXPECT_EQ(error::kNoError, ExecuteCmd(is_enabled_cmd));
700 EXPECT_EQ(0u, *result);
704 TEST_P(GLES2DecoderManualInitTest, GpuMemoryManagerCHROMIUM) {
705 InitState init;
706 init.extensions = "GL_ARB_texture_rectangle";
707 init.gl_version = "3.0";
708 init.bind_generates_resource = true;
709 InitDecoder(init);
711 Texture* texture = GetTexture(client_texture_id_)->texture();
712 EXPECT_TRUE(texture != NULL);
713 EXPECT_TRUE(texture->pool() == GL_TEXTURE_POOL_UNMANAGED_CHROMIUM);
715 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
717 TexParameteri cmd;
718 cmd.Init(GL_TEXTURE_2D,
719 GL_TEXTURE_POOL_CHROMIUM,
720 GL_TEXTURE_POOL_UNMANAGED_CHROMIUM);
721 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
722 EXPECT_EQ(GL_NO_ERROR, GetGLError());
724 cmd.Init(GL_TEXTURE_2D,
725 GL_TEXTURE_POOL_CHROMIUM,
726 GL_TEXTURE_POOL_MANAGED_CHROMIUM);
727 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
728 EXPECT_EQ(GL_NO_ERROR, GetGLError());
730 EXPECT_TRUE(texture->pool() == GL_TEXTURE_POOL_MANAGED_CHROMIUM);
732 cmd.Init(GL_TEXTURE_2D, GL_TEXTURE_POOL_CHROMIUM, GL_NONE);
733 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
734 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
737 namespace {
739 class SizeOnlyMemoryTracker : public MemoryTracker {
740 public:
741 SizeOnlyMemoryTracker() {
742 // These are the default textures. 1 for TEXTURE_2D and 6 faces for
743 // TEXTURE_CUBE_MAP.
744 const size_t kInitialUnmanagedPoolSize = 7 * 4;
745 const size_t kInitialManagedPoolSize = 0;
746 pool_infos_[MemoryTracker::kUnmanaged].initial_size =
747 kInitialUnmanagedPoolSize;
748 pool_infos_[MemoryTracker::kManaged].initial_size = kInitialManagedPoolSize;
751 // Ensure a certain amount of GPU memory is free. Returns true on success.
752 MOCK_METHOD1(EnsureGPUMemoryAvailable, bool(size_t size_needed));
754 virtual void TrackMemoryAllocatedChange(size_t old_size,
755 size_t new_size,
756 Pool pool) {
757 PoolInfo& info = pool_infos_[pool];
758 info.size += new_size - old_size;
761 size_t GetPoolSize(Pool pool) {
762 const PoolInfo& info = pool_infos_[pool];
763 return info.size - info.initial_size;
766 private:
767 virtual ~SizeOnlyMemoryTracker() {}
768 struct PoolInfo {
769 PoolInfo() : initial_size(0), size(0) {}
770 size_t initial_size;
771 size_t size;
773 std::map<Pool, PoolInfo> pool_infos_;
776 } // anonymous namespace.
778 TEST_P(GLES2DecoderManualInitTest, MemoryTrackerInitialSize) {
779 scoped_refptr<SizeOnlyMemoryTracker> memory_tracker =
780 new SizeOnlyMemoryTracker();
781 set_memory_tracker(memory_tracker.get());
782 InitState init;
783 init.gl_version = "3.0";
784 init.bind_generates_resource = true;
785 InitDecoder(init);
786 // Expect that initial size - size is 0.
787 EXPECT_EQ(0u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
788 EXPECT_EQ(0u, memory_tracker->GetPoolSize(MemoryTracker::kManaged));
791 TEST_P(GLES2DecoderManualInitTest, MemoryTrackerTexImage2D) {
792 scoped_refptr<SizeOnlyMemoryTracker> memory_tracker =
793 new SizeOnlyMemoryTracker();
794 set_memory_tracker(memory_tracker.get());
795 InitState init;
796 init.gl_version = "3.0";
797 init.bind_generates_resource = true;
798 InitDecoder(init);
799 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
800 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
801 .WillOnce(Return(true))
802 .RetiresOnSaturation();
803 DoTexImage2D(GL_TEXTURE_2D,
805 GL_RGBA,
809 GL_RGBA,
810 GL_UNSIGNED_BYTE,
811 kSharedMemoryId,
812 kSharedMemoryOffset);
813 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
814 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(64))
815 .WillOnce(Return(true))
816 .RetiresOnSaturation();
817 DoTexImage2D(GL_TEXTURE_2D,
819 GL_RGBA,
823 GL_RGBA,
824 GL_UNSIGNED_BYTE,
825 kSharedMemoryId,
826 kSharedMemoryOffset);
827 EXPECT_EQ(64u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
828 EXPECT_EQ(GL_NO_ERROR, GetGLError());
829 // Check we get out of memory and no call to glTexImage2D if Ensure fails.
830 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(64))
831 .WillOnce(Return(false))
832 .RetiresOnSaturation();
833 TexImage2D cmd;
834 cmd.Init(GL_TEXTURE_2D,
836 GL_RGBA,
839 GL_RGBA,
840 GL_UNSIGNED_BYTE,
841 kSharedMemoryId,
842 kSharedMemoryOffset);
843 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
844 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
845 EXPECT_EQ(64u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
848 TEST_P(GLES2DecoderManualInitTest, MemoryTrackerTexStorage2DEXT) {
849 scoped_refptr<SizeOnlyMemoryTracker> memory_tracker =
850 new SizeOnlyMemoryTracker();
851 set_memory_tracker(memory_tracker.get());
852 InitState init;
853 init.gl_version = "3.0";
854 init.bind_generates_resource = true;
855 InitDecoder(init);
856 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
857 // Check we get out of memory and no call to glTexStorage2DEXT
858 // if Ensure fails.
859 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
860 .WillOnce(Return(false))
861 .RetiresOnSaturation();
862 TexStorage2DEXT cmd;
863 cmd.Init(GL_TEXTURE_2D, 1, GL_RGBA8, 8, 4);
864 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
865 EXPECT_EQ(0u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
866 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
869 TEST_P(GLES2DecoderManualInitTest, MemoryTrackerCopyTexImage2D) {
870 GLenum target = GL_TEXTURE_2D;
871 GLint level = 0;
872 GLenum internal_format = GL_RGBA;
873 GLsizei width = 4;
874 GLsizei height = 8;
875 GLint border = 0;
876 scoped_refptr<SizeOnlyMemoryTracker> memory_tracker =
877 new SizeOnlyMemoryTracker();
878 set_memory_tracker(memory_tracker.get());
879 InitState init;
880 init.gl_version = "3.0";
881 init.has_alpha = true;
882 init.request_alpha = true;
883 init.bind_generates_resource = true;
884 InitDecoder(init);
885 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
886 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
887 .WillOnce(Return(true))
888 .RetiresOnSaturation();
889 EXPECT_CALL(*gl_, GetError())
890 .WillOnce(Return(GL_NO_ERROR))
891 .WillOnce(Return(GL_NO_ERROR))
892 .RetiresOnSaturation();
893 EXPECT_CALL(*gl_,
894 CopyTexImage2D(
895 target, level, internal_format, 0, 0, width, height, border))
896 .Times(1)
897 .RetiresOnSaturation();
898 CopyTexImage2D cmd;
899 cmd.Init(target, level, internal_format, 0, 0, width, height);
900 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
901 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
902 EXPECT_EQ(GL_NO_ERROR, GetGLError());
903 // Check we get out of memory and no call to glCopyTexImage2D if Ensure fails.
904 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
905 .WillOnce(Return(false))
906 .RetiresOnSaturation();
907 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
908 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
909 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
912 TEST_P(GLES2DecoderManualInitTest, MemoryTrackerRenderbufferStorage) {
913 scoped_refptr<SizeOnlyMemoryTracker> memory_tracker =
914 new SizeOnlyMemoryTracker();
915 set_memory_tracker(memory_tracker.get());
916 InitState init;
917 init.gl_version = "3.0";
918 init.bind_generates_resource = true;
919 InitDecoder(init);
920 DoBindRenderbuffer(
921 GL_RENDERBUFFER, client_renderbuffer_id_, kServiceRenderbufferId);
922 EnsureRenderbufferBound(false);
923 EXPECT_CALL(*gl_, GetError())
924 .WillOnce(Return(GL_NO_ERROR))
925 .WillOnce(Return(GL_NO_ERROR))
926 .RetiresOnSaturation();
927 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
928 .WillOnce(Return(true))
929 .RetiresOnSaturation();
930 EXPECT_CALL(*gl_, RenderbufferStorageEXT(GL_RENDERBUFFER, GL_RGBA, 8, 4))
931 .Times(1)
932 .RetiresOnSaturation();
933 RenderbufferStorage cmd;
934 cmd.Init(GL_RENDERBUFFER, GL_RGBA4, 8, 4);
935 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
936 EXPECT_EQ(GL_NO_ERROR, GetGLError());
937 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
938 // Check we get out of memory and no call to glRenderbufferStorage if Ensure
939 // fails.
940 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
941 .WillOnce(Return(false))
942 .RetiresOnSaturation();
943 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
944 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
945 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kUnmanaged));
948 TEST_P(GLES2DecoderManualInitTest, MemoryTrackerBufferData) {
949 scoped_refptr<SizeOnlyMemoryTracker> memory_tracker =
950 new SizeOnlyMemoryTracker();
951 set_memory_tracker(memory_tracker.get());
952 InitState init;
953 init.gl_version = "3.0";
954 init.bind_generates_resource = true;
955 InitDecoder(init);
956 DoBindBuffer(GL_ARRAY_BUFFER, client_buffer_id_, kServiceBufferId);
957 EXPECT_CALL(*gl_, GetError())
958 .WillOnce(Return(GL_NO_ERROR))
959 .WillOnce(Return(GL_NO_ERROR))
960 .RetiresOnSaturation();
961 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
962 .WillOnce(Return(true))
963 .RetiresOnSaturation();
964 EXPECT_CALL(*gl_, BufferData(GL_ARRAY_BUFFER, 128, _, GL_STREAM_DRAW))
965 .Times(1)
966 .RetiresOnSaturation();
967 BufferData cmd;
968 cmd.Init(GL_ARRAY_BUFFER, 128, 0, 0, GL_STREAM_DRAW);
969 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
970 EXPECT_EQ(GL_NO_ERROR, GetGLError());
971 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kManaged));
972 // Check we get out of memory and no call to glBufferData if Ensure
973 // fails.
974 EXPECT_CALL(*memory_tracker.get(), EnsureGPUMemoryAvailable(128))
975 .WillOnce(Return(false))
976 .RetiresOnSaturation();
977 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
978 EXPECT_EQ(GL_OUT_OF_MEMORY, GetGLError());
979 EXPECT_EQ(128u, memory_tracker->GetPoolSize(MemoryTracker::kManaged));
982 TEST_P(GLES2DecoderManualInitTest, ImmutableCopyTexImage2D) {
983 const GLenum kTarget = GL_TEXTURE_2D;
984 const GLint kLevel = 0;
985 const GLenum kInternalFormat = GL_RGBA;
986 const GLenum kSizedInternalFormat = GL_RGBA8;
987 const GLsizei kWidth = 4;
988 const GLsizei kHeight = 8;
989 const GLint kBorder = 0;
990 InitState init;
991 init.extensions = "GL_EXT_texture_storage";
992 init.gl_version = "3.0";
993 init.has_alpha = true;
994 init.request_alpha = true;
995 init.bind_generates_resource = true;
996 InitDecoder(init);
997 DoBindTexture(GL_TEXTURE_2D, client_texture_id_, kServiceTextureId);
999 // CopyTexImage2D will call arbitrary amount of GetErrors.
1000 EXPECT_CALL(*gl_, GetError())
1001 .Times(AtLeast(1));
1003 EXPECT_CALL(*gl_,
1004 CopyTexImage2D(
1005 kTarget, kLevel, kInternalFormat, 0, 0, kWidth, kHeight,
1006 kBorder))
1007 .Times(1);
1009 EXPECT_CALL(*gl_,
1010 TexStorage2DEXT(
1011 kTarget, kLevel, kSizedInternalFormat, kWidth, kHeight))
1012 .Times(1);
1013 CopyTexImage2D copy_cmd;
1014 copy_cmd.Init(kTarget, kLevel, kInternalFormat, 0, 0, kWidth, kHeight);
1015 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_cmd));
1016 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1018 TexStorage2DEXT storage_cmd;
1019 storage_cmd.Init(kTarget, kLevel, kSizedInternalFormat, kWidth, kHeight);
1020 EXPECT_EQ(error::kNoError, ExecuteCmd(storage_cmd));
1021 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1023 // This should not invoke CopyTexImage2D.
1024 copy_cmd.Init(kTarget, kLevel, kInternalFormat, 0, 0, kWidth, kHeight);
1025 EXPECT_EQ(error::kNoError, ExecuteCmd(copy_cmd));
1026 EXPECT_EQ(GL_INVALID_OPERATION, GetGLError());
1029 TEST_P(GLES2DecoderTest, LoseContextCHROMIUMValidArgs) {
1030 EXPECT_CALL(*mock_decoder_, LoseContext(GL_GUILTY_CONTEXT_RESET_ARB))
1031 .Times(1);
1032 cmds::LoseContextCHROMIUM cmd;
1033 cmd.Init(GL_GUILTY_CONTEXT_RESET_ARB, GL_GUILTY_CONTEXT_RESET_ARB);
1034 EXPECT_EQ(error::kLostContext, ExecuteCmd(cmd));
1035 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1038 TEST_P(GLES2DecoderTest, LoseContextCHROMIUMInvalidArgs0_0) {
1039 EXPECT_CALL(*mock_decoder_, LoseContext(_))
1040 .Times(0);
1041 cmds::LoseContextCHROMIUM cmd;
1042 cmd.Init(GL_NONE, GL_GUILTY_CONTEXT_RESET_ARB);
1043 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1044 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1047 TEST_P(GLES2DecoderTest, LoseContextCHROMIUMInvalidArgs1_0) {
1048 EXPECT_CALL(*mock_decoder_, LoseContext(_))
1049 .Times(0);
1050 cmds::LoseContextCHROMIUM cmd;
1051 cmd.Init(GL_GUILTY_CONTEXT_RESET_ARB, GL_NONE);
1052 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
1053 EXPECT_EQ(GL_INVALID_ENUM, GetGLError());
1056 class GLES2DecoderDoCommandsTest : public GLES2DecoderTest {
1057 public:
1058 GLES2DecoderDoCommandsTest() {
1059 for (int i = 0; i < 3; i++) {
1060 cmds_[i].Init(GL_BLEND);
1062 entries_per_cmd_ = ComputeNumEntries(cmds_[0].ComputeSize());
1065 void SetExpectationsForNCommands(int num_commands) {
1066 for (int i = 0; i < num_commands; i++)
1067 SetupExpectationsForEnableDisable(GL_BLEND, true);
1070 protected:
1071 Enable cmds_[3];
1072 int entries_per_cmd_;
1075 // Test that processing with 0 entries does nothing.
1076 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsOneOfZero) {
1077 int num_processed = -1;
1078 SetExpectationsForNCommands(0);
1079 EXPECT_EQ(
1080 error::kNoError,
1081 decoder_->DoCommands(1, &cmds_, entries_per_cmd_ * 0, &num_processed));
1082 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1083 EXPECT_EQ(0, num_processed);
1086 // Test processing at granularity of single commands.
1087 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsOneOfOne) {
1088 int num_processed = -1;
1089 SetExpectationsForNCommands(1);
1090 EXPECT_EQ(
1091 error::kNoError,
1092 decoder_->DoCommands(1, &cmds_, entries_per_cmd_ * 1, &num_processed));
1093 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1094 EXPECT_EQ(entries_per_cmd_, num_processed);
1097 // Test processing at granularity of multiple commands.
1098 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsThreeOfThree) {
1099 int num_processed = -1;
1100 SetExpectationsForNCommands(3);
1101 EXPECT_EQ(
1102 error::kNoError,
1103 decoder_->DoCommands(3, &cmds_, entries_per_cmd_ * 3, &num_processed));
1104 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1105 EXPECT_EQ(entries_per_cmd_ * 3, num_processed);
1108 // Test processing a request smaller than available entries.
1109 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsTwoOfThree) {
1110 int num_processed = -1;
1111 SetExpectationsForNCommands(2);
1112 EXPECT_EQ(
1113 error::kNoError,
1114 decoder_->DoCommands(2, &cmds_, entries_per_cmd_ * 3, &num_processed));
1115 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1116 EXPECT_EQ(entries_per_cmd_ * 2, num_processed);
1119 // Test that processing stops on a command with size 0.
1120 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsZeroCmdSize) {
1121 cmds_[1].header.size = 0;
1122 int num_processed = -1;
1123 SetExpectationsForNCommands(1);
1124 EXPECT_EQ(
1125 error::kInvalidSize,
1126 decoder_->DoCommands(2, &cmds_, entries_per_cmd_ * 2, &num_processed));
1127 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1128 EXPECT_EQ(entries_per_cmd_, num_processed);
1131 // Test that processing stops on a command with size greater than available.
1132 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsOutOfBounds) {
1133 int num_processed = -1;
1134 SetExpectationsForNCommands(1);
1135 EXPECT_EQ(error::kOutOfBounds,
1136 decoder_->DoCommands(
1137 2, &cmds_, entries_per_cmd_ * 2 - 1, &num_processed));
1138 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1139 EXPECT_EQ(entries_per_cmd_, num_processed);
1142 // Test that commands with bad argument size are skipped without processing.
1143 TEST_P(GLES2DecoderDoCommandsTest, DoCommandsBadArgSize) {
1144 cmds_[1].header.size += 1;
1145 int num_processed = -1;
1146 SetExpectationsForNCommands(1);
1147 EXPECT_EQ(error::kInvalidArguments,
1148 decoder_->DoCommands(
1149 2, &cmds_, entries_per_cmd_ * 2 + 1, &num_processed));
1150 EXPECT_EQ(GL_NO_ERROR, GetGLError());
1151 EXPECT_EQ(entries_per_cmd_ + cmds_[1].header.size, num_processed);
1154 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderTest, ::testing::Bool());
1156 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderWithShaderTest, ::testing::Bool());
1158 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderManualInitTest, ::testing::Bool());
1160 INSTANTIATE_TEST_CASE_P(Service,
1161 GLES2DecoderRGBBackbufferTest,
1162 ::testing::Bool());
1164 INSTANTIATE_TEST_CASE_P(Service, GLES2DecoderDoCommandsTest, ::testing::Bool());
1166 } // namespace gles2
1167 } // namespace gpu