Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.cc

Issue 7099007: Enforce RGB even on buggy drivers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add checks for reading GL_ALPHA_BITS etc. Created 9 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h" 5 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 9
10 #include "base/string_number_conversions.h" 10 #include "base/string_number_conversions.h"
(...skipping 30 matching lines...) Expand all
41 client_renderbuffer_id_(103), 41 client_renderbuffer_id_(103),
42 client_shader_id_(104), 42 client_shader_id_(104),
43 client_texture_id_(106), 43 client_texture_id_(106),
44 client_element_buffer_id_(107) { 44 client_element_buffer_id_(107) {
45 memset(immediate_buffer_, 0xEE, sizeof(immediate_buffer_)); 45 memset(immediate_buffer_, 0xEE, sizeof(immediate_buffer_));
46 } 46 }
47 47
48 GLES2DecoderTestBase::~GLES2DecoderTestBase() {} 48 GLES2DecoderTestBase::~GLES2DecoderTestBase() {}
49 49
50 void GLES2DecoderTestBase::SetUp() { 50 void GLES2DecoderTestBase::SetUp() {
51 InitDecoder("", true); 51 InitDecoder("", true, true, false, true, true, false);
52 } 52 }
53 53
54 void GLES2DecoderTestBase::InitDecoder( 54 void GLES2DecoderTestBase::InitDecoder(
55 const char* extensions, bool has_alpha_backbuffer) { 55 const char* extensions,
56 bool has_alpha,
57 bool has_depth,
58 bool has_stencil,
59 bool request_alpha,
60 bool request_depth,
61 bool request_stencil) {
56 gl_.reset(new StrictMock<MockGLInterface>()); 62 gl_.reset(new StrictMock<MockGLInterface>());
57 ::gfx::GLInterface::SetGLInterface(gl_.get()); 63 ::gfx::GLInterface::SetGLInterface(gl_.get());
58 surface_manager_.reset(new StrictMock<MockSurfaceManager>); 64 surface_manager_.reset(new StrictMock<MockSurfaceManager>);
59 group_ = ContextGroup::Ref(new ContextGroup()); 65 group_ = ContextGroup::Ref(new ContextGroup());
60 66
61 InSequence sequence; 67 InSequence sequence;
62 68
63 TestHelper::SetupContextGroupInitExpectations(gl_.get(), 69 TestHelper::SetupContextGroupInitExpectations(gl_.get(),
64 DisallowedExtensions(), extensions); 70 DisallowedExtensions(), extensions);
65 71
66 EXPECT_TRUE(group_->Initialize(DisallowedExtensions(), extensions)); 72 EXPECT_TRUE(group_->Initialize(DisallowedExtensions(), extensions));
67 73
68 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
69 .WillOnce(SetArgumentPointee<1>(has_alpha_backbuffer ? 8 : 0))
70 .RetiresOnSaturation();
71 EXPECT_CALL(*gl_, EnableVertexAttribArray(0)) 74 EXPECT_CALL(*gl_, EnableVertexAttribArray(0))
72 .Times(1) 75 .Times(1)
73 .RetiresOnSaturation(); 76 .RetiresOnSaturation();
74 static GLuint attrib_0_id[] = { 77 static GLuint attrib_0_id[] = {
75 kServiceAttrib0BufferId, 78 kServiceAttrib0BufferId,
76 }; 79 };
77 static GLuint fixed_attrib_buffer_id[] = { 80 static GLuint fixed_attrib_buffer_id[] = {
78 kServiceFixedAttribBufferId, 81 kServiceFixedAttribBufferId,
79 }; 82 };
80 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_0_id), _)) 83 EXPECT_CALL(*gl_, GenBuffersARB(arraysize(attrib_0_id), _))
(...skipping 25 matching lines...) Expand all
106 .RetiresOnSaturation(); 109 .RetiresOnSaturation();
107 EXPECT_CALL(*gl_, BindTexture( 110 EXPECT_CALL(*gl_, BindTexture(
108 GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId)) 111 GL_TEXTURE_2D, TestHelper::kServiceDefaultTexture2dId))
109 .Times(1) 112 .Times(1)
110 .RetiresOnSaturation(); 113 .RetiresOnSaturation();
111 } 114 }
112 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) 115 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0))
113 .Times(1) 116 .Times(1)
114 .RetiresOnSaturation(); 117 .RetiresOnSaturation();
115 118
119 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _))
120 .WillOnce(SetArgumentPointee<1>(has_alpha ? 8 : 0))
121 .RetiresOnSaturation();
122 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _))
123 .WillOnce(SetArgumentPointee<1>(has_depth ? 24 : 0))
124 .RetiresOnSaturation();
125 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _))
126 .WillOnce(SetArgumentPointee<1>(has_stencil ? 8 : 0))
127 .RetiresOnSaturation();
128
116 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE)) 129 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE))
117 .Times(1) 130 .Times(1)
118 .RetiresOnSaturation(); 131 .RetiresOnSaturation();
119 132
120 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE)) 133 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE))
121 .Times(1) 134 .Times(1)
122 .RetiresOnSaturation(); 135 .RetiresOnSaturation();
123 136
124 engine_.reset(new StrictMock<MockCommandBufferEngine>()); 137 engine_.reset(new StrictMock<MockCommandBufferEngine>());
125 Buffer buffer = engine_->GetSharedMemoryBuffer(kSharedMemoryId); 138 Buffer buffer = engine_->GetSharedMemoryBuffer(kSharedMemoryId);
126 shared_memory_offset_ = kSharedMemoryOffset; 139 shared_memory_offset_ = kSharedMemoryOffset;
127 shared_memory_address_ = reinterpret_cast<int8*>(buffer.ptr) + 140 shared_memory_address_ = reinterpret_cast<int8*>(buffer.ptr) +
128 shared_memory_offset_; 141 shared_memory_offset_;
129 shared_memory_id_ = kSharedMemoryId; 142 shared_memory_id_ = kSharedMemoryId;
130 shared_memory_base_ = buffer.ptr; 143 shared_memory_base_ = buffer.ptr;
131 144
132 surface_ = new gfx::GLSurfaceStub; 145 surface_ = new gfx::GLSurfaceStub;
133 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight)); 146 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight));
134 147
135 context_ = new gfx::GLContextStub; 148 context_ = new gfx::GLContextStub;
136 149
150 // From <EGL/egl.h>.
151 const int32 EGL_ALPHA_SIZE = 0x3021;
152 const int32 EGL_DEPTH_SIZE = 0x3025;
153 const int32 EGL_STENCIL_SIZE = 0x3026;
154
155 int32 attributes[] = {
156 EGL_ALPHA_SIZE, request_alpha ? 8 : 0,
157 EGL_DEPTH_SIZE, request_depth ? 24 : 0,
158 EGL_STENCIL_SIZE, request_stencil ? 8 : 0,
159 };
160 std::vector<int32> attribs(attributes, attributes + arraysize(attributes));
161
137 decoder_.reset(GLES2Decoder::Create(surface_manager_.get(), group_.get())); 162 decoder_.reset(GLES2Decoder::Create(surface_manager_.get(), group_.get()));
138 decoder_->Initialize( 163 decoder_->Initialize(
139 surface_, context_, surface_->GetSize(), DisallowedExtensions(), 164 surface_, context_, surface_->GetSize(), DisallowedExtensions(),
140 NULL, std::vector<int32>(), NULL, 0); 165 NULL, attribs, NULL, 0);
141 decoder_->set_engine(engine_.get()); 166 decoder_->set_engine(engine_.get());
142 167
143 EXPECT_CALL(*gl_, GenBuffersARB(_, _)) 168 EXPECT_CALL(*gl_, GenBuffersARB(_, _))
144 .WillOnce(SetArgumentPointee<1>(kServiceBufferId)) 169 .WillOnce(SetArgumentPointee<1>(kServiceBufferId))
145 .RetiresOnSaturation(); 170 .RetiresOnSaturation();
146 GenHelper<GenBuffersImmediate>(client_buffer_id_); 171 GenHelper<GenBuffersImmediate>(client_buffer_id_);
147 EXPECT_CALL(*gl_, GenFramebuffersEXT(_, _)) 172 EXPECT_CALL(*gl_, GenFramebuffersEXT(_, _))
148 .WillOnce(SetArgumentPointee<1>(kServiceFramebufferId)) 173 .WillOnce(SetArgumentPointee<1>(kServiceFramebufferId))
149 .RetiresOnSaturation(); 174 .RetiresOnSaturation();
150 GenHelper<GenFramebuffersImmediate>(client_framebuffer_id_); 175 GenHelper<GenFramebuffersImmediate>(client_framebuffer_id_);
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
256 ClearSharedMemory(); 281 ClearSharedMemory();
257 } 282 }
258 } 283 }
259 284
260 void GLES2DecoderTestBase::SetupExpectationsForFramebufferAttachment( 285 void GLES2DecoderTestBase::SetupExpectationsForFramebufferAttachment(
261 GLuint clear_bits, 286 GLuint clear_bits,
262 GLclampf restore_red, 287 GLclampf restore_red,
263 GLclampf restore_green, 288 GLclampf restore_green,
264 GLclampf restore_blue, 289 GLclampf restore_blue,
265 GLclampf restore_alpha, 290 GLclampf restore_alpha,
266 GLuint restore_color_mask,
267 GLuint restore_stencil, 291 GLuint restore_stencil,
268 GLuint restore_stencil_front_mask,
269 GLuint restore_stencil_back_mask,
270 GLclampf restore_depth, 292 GLclampf restore_depth,
271 GLboolean restore_depth_mask,
272 bool restore_scissor_test) { 293 bool restore_scissor_test) {
273 InSequence sequence; 294 InSequence sequence;
274 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER)) 295 EXPECT_CALL(*gl_, CheckFramebufferStatusEXT(GL_FRAMEBUFFER))
275 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE)) 296 .WillOnce(Return(GL_FRAMEBUFFER_COMPLETE))
276 .RetiresOnSaturation(); 297 .RetiresOnSaturation();
277 if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0) { 298 if ((clear_bits & GL_COLOR_BUFFER_BIT) != 0) {
278 EXPECT_CALL(*gl_, ClearColor(0, 0, 0, 0)) 299 EXPECT_CALL(*gl_, ClearColor(0, 0, 0, 0))
279 .Times(1) 300 .Times(1)
280 .RetiresOnSaturation(); 301 .RetiresOnSaturation();
281 EXPECT_CALL(*gl_, ColorMask(1, 1, 1, 1)) 302 EXPECT_CALL(*gl_, ColorMask(1, 1, 1, 1))
(...skipping 19 matching lines...) Expand all
301 EXPECT_CALL(*gl_, Disable(GL_SCISSOR_TEST)) 322 EXPECT_CALL(*gl_, Disable(GL_SCISSOR_TEST))
302 .Times(1) 323 .Times(1)
303 .RetiresOnSaturation(); 324 .RetiresOnSaturation();
304 EXPECT_CALL(*gl_, Clear(clear_bits)) 325 EXPECT_CALL(*gl_, Clear(clear_bits))
305 .Times(1) 326 .Times(1)
306 .RetiresOnSaturation(); 327 .RetiresOnSaturation();
307 EXPECT_CALL(*gl_, ClearColor( 328 EXPECT_CALL(*gl_, ClearColor(
308 restore_red, restore_green, restore_blue, restore_alpha)) 329 restore_red, restore_green, restore_blue, restore_alpha))
309 .Times(1) 330 .Times(1)
310 .RetiresOnSaturation(); 331 .RetiresOnSaturation();
311 EXPECT_CALL(*gl_, ColorMask(
312 ((restore_color_mask & 0x1000) != 0) ? 1 : 0,
313 ((restore_color_mask & 0x0100) != 0) ? 1 : 0,
314 ((restore_color_mask & 0x0010) != 0) ? 1 : 0,
315 ((restore_color_mask & 0x0001) != 0) ? 1 : 0))
316 .Times(1)
317 .RetiresOnSaturation();
318 EXPECT_CALL(*gl_, ClearStencil(restore_stencil)) 332 EXPECT_CALL(*gl_, ClearStencil(restore_stencil))
319 .Times(1) 333 .Times(1)
320 .RetiresOnSaturation(); 334 .RetiresOnSaturation();
321 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, restore_stencil_front_mask))
322 .Times(1)
323 .RetiresOnSaturation();
324 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, restore_stencil_back_mask))
325 .Times(1)
326 .RetiresOnSaturation();
327 EXPECT_CALL(*gl_, ClearDepth(restore_depth)) 335 EXPECT_CALL(*gl_, ClearDepth(restore_depth))
328 .Times(1) 336 .Times(1)
329 .RetiresOnSaturation(); 337 .RetiresOnSaturation();
330 EXPECT_CALL(*gl_, DepthMask(restore_depth_mask))
331 .Times(1)
332 .RetiresOnSaturation();
333 if (restore_scissor_test) { 338 if (restore_scissor_test) {
334 EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST)) 339 EXPECT_CALL(*gl_, Enable(GL_SCISSOR_TEST))
335 .Times(1) 340 .Times(1)
336 .RetiresOnSaturation(); 341 .RetiresOnSaturation();
337 } 342 }
338 } 343 }
339 344
340 void GLES2DecoderTestBase::SetupShaderForUniform() { 345 void GLES2DecoderTestBase::SetupShaderForUniform() {
341 static AttribInfo attribs[] = { 346 static AttribInfo attribs[] = {
342 { "foo", 1, GL_FLOAT, 1, }, 347 { "foo", 1, GL_FLOAT, 1, },
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 GLuint client_id, GLuint service_id) { 384 GLuint client_id, GLuint service_id) {
380 EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(service_id))) 385 EXPECT_CALL(*gl_, DeleteBuffersARB(1, Pointee(service_id)))
381 .Times(1) 386 .Times(1)
382 .RetiresOnSaturation(); 387 .RetiresOnSaturation();
383 DeleteBuffers cmd; 388 DeleteBuffers cmd;
384 cmd.Init(1, shared_memory_id_, shared_memory_offset_); 389 cmd.Init(1, shared_memory_id_, shared_memory_offset_);
385 memcpy(shared_memory_address_, &client_id, sizeof(client_id)); 390 memcpy(shared_memory_address_, &client_id, sizeof(client_id));
386 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 391 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
387 } 392 }
388 393
394 void GLES2DecoderTestBase::SetupExpectationsForApplyingDirtyState(
395 bool framebuffer_is_rgb,
396 bool framebuffer_has_depth,
397 bool framebuffer_has_stencil,
398 GLuint color_bits,
399 bool depth_mask,
400 GLuint front_stencil_mask,
401 GLuint back_stencil_mask) {
402 EXPECT_CALL(*gl_, ColorMask(
403 (color_bits & 0x1000) != 0,
404 (color_bits & 0x0100) != 0,
405 (color_bits & 0x0010) != 0,
406 (color_bits & 0x0001) && !framebuffer_is_rgb))
407 .Times(1)
408 .RetiresOnSaturation();
409 EXPECT_CALL(*gl_, DepthMask(depth_mask))
410 .Times(1)
411 .RetiresOnSaturation();
412 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_FRONT, front_stencil_mask))
413 .Times(1)
414 .RetiresOnSaturation();
415 EXPECT_CALL(*gl_, StencilMaskSeparate(GL_BACK, back_stencil_mask))
416 .Times(1)
417 .RetiresOnSaturation();
418 }
419
420 void GLES2DecoderTestBase::SetupExpectationsForApplyingDefaultDirtyState() {
421 SetupExpectationsForApplyingDirtyState(
422 false, // Framebuffer is RGB
423 false, // Framebuffer has depth
424 false, // Framebuffer has stencil
425 0x1111, // color bits
426 true, // depth mask
427 0, // front stencil mask
428 0); // back stencil mask
429 }
430
389 void GLES2DecoderTestBase::DoBindFramebuffer( 431 void GLES2DecoderTestBase::DoBindFramebuffer(
390 GLenum target, GLuint client_id, GLuint service_id) { 432 GLenum target, GLuint client_id, GLuint service_id) {
391 EXPECT_CALL(*gl_, BindFramebufferEXT(target, service_id)) 433 EXPECT_CALL(*gl_, BindFramebufferEXT(target, service_id))
392 .Times(1) 434 .Times(1)
393 .RetiresOnSaturation(); 435 .RetiresOnSaturation();
394 BindFramebuffer cmd; 436 BindFramebuffer cmd;
395 cmd.Init(target, client_id); 437 cmd.Init(target, client_id);
396 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd)); 438 EXPECT_EQ(error::kNoError, ExecuteCmd(cmd));
397 } 439 }
398 440
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
528 const uint32 GLES2DecoderTestBase::kNewClientId; 570 const uint32 GLES2DecoderTestBase::kNewClientId;
529 const uint32 GLES2DecoderTestBase::kNewServiceId; 571 const uint32 GLES2DecoderTestBase::kNewServiceId;
530 const uint32 GLES2DecoderTestBase::kInvalidClientId; 572 const uint32 GLES2DecoderTestBase::kInvalidClientId;
531 573
532 const int GLES2DecoderTestBase::kBackBufferWidth; 574 const int GLES2DecoderTestBase::kBackBufferWidth;
533 const int GLES2DecoderTestBase::kBackBufferHeight; 575 const int GLES2DecoderTestBase::kBackBufferHeight;
534 #endif 576 #endif
535 577
536 void GLES2DecoderWithShaderTestBase::SetUp() { 578 void GLES2DecoderWithShaderTestBase::SetUp() {
537 GLES2DecoderTestBase::SetUp(); 579 GLES2DecoderTestBase::SetUp();
580 SetupDefaultProgram();
581 }
538 582
583 void GLES2DecoderWithShaderTestBase::SetupDefaultProgram() {
539 { 584 {
540 static AttribInfo attribs[] = { 585 static AttribInfo attribs[] = {
541 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, }, 586 { kAttrib1Name, kAttrib1Size, kAttrib1Type, kAttrib1Location, },
542 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, }, 587 { kAttrib2Name, kAttrib2Size, kAttrib2Type, kAttrib2Location, },
543 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, }, 588 { kAttrib3Name, kAttrib3Size, kAttrib3Type, kAttrib3Location, },
544 }; 589 };
545 static UniformInfo uniforms[] = { 590 static UniformInfo uniforms[] = {
546 { kUniform1Name, kUniform1Size, kUniform1Type, kUniform1Location, }, 591 { kUniform1Name, kUniform1Size, kUniform1Type, kUniform1Location, },
547 { kUniform2Name, kUniform2Size, kUniform2Type, kUniform2Location, }, 592 { kUniform2Name, kUniform2Size, kUniform2Type, kUniform2Location, },
548 { kUniform3Name, kUniform3Size, kUniform3Type, kUniform3Location, }, 593 { kUniform3Name, kUniform3Size, kUniform3Type, kUniform3Location, },
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
807 852
808 const char* GLES2DecoderWithShaderTestBase::kAttrib1Name = "attrib1"; 853 const char* GLES2DecoderWithShaderTestBase::kAttrib1Name = "attrib1";
809 const char* GLES2DecoderWithShaderTestBase::kAttrib2Name = "attrib2"; 854 const char* GLES2DecoderWithShaderTestBase::kAttrib2Name = "attrib2";
810 const char* GLES2DecoderWithShaderTestBase::kAttrib3Name = "attrib3"; 855 const char* GLES2DecoderWithShaderTestBase::kAttrib3Name = "attrib3";
811 const char* GLES2DecoderWithShaderTestBase::kUniform1Name = "uniform1"; 856 const char* GLES2DecoderWithShaderTestBase::kUniform1Name = "uniform1";
812 const char* GLES2DecoderWithShaderTestBase::kUniform2Name = "uniform2[0]"; 857 const char* GLES2DecoderWithShaderTestBase::kUniform2Name = "uniform2[0]";
813 const char* GLES2DecoderWithShaderTestBase::kUniform3Name = "uniform3[0]"; 858 const char* GLES2DecoderWithShaderTestBase::kUniform3Name = "uniform3[0]";
814 859
815 } // namespace gles2 860 } // namespace gles2
816 } // namespace gpu 861 } // namespace gpu
OLDNEW
« no previous file with comments | « gpu/command_buffer/service/gles2_cmd_decoder_unittest_base.h ('k') | gpu/command_buffer/service/texture_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698