| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/strings/string_number_conversions.h" | 11 #include "base/strings/string_number_conversions.h" |
| 12 #include "base/strings/string_split.h" | 12 #include "base/strings/string_split.h" |
| 13 #include "gpu/command_buffer/common/gles2_cmd_format.h" | 13 #include "gpu/command_buffer/common/gles2_cmd_format.h" |
| 14 #include "gpu/command_buffer/common/gles2_cmd_utils.h" | 14 #include "gpu/command_buffer/common/gles2_cmd_utils.h" |
| 15 #include "gpu/command_buffer/service/cmd_buffer_engine.h" | 15 #include "gpu/command_buffer/service/cmd_buffer_engine.h" |
| 16 #include "gpu/command_buffer/service/context_group.h" | 16 #include "gpu/command_buffer/service/context_group.h" |
| 17 #include "gpu/command_buffer/service/gles2_cmd_decoder_mock.h" | |
| 18 #include "gpu/command_buffer/service/logger.h" | 17 #include "gpu/command_buffer/service/logger.h" |
| 19 #include "gpu/command_buffer/service/program_manager.h" | 18 #include "gpu/command_buffer/service/program_manager.h" |
| 20 #include "gpu/command_buffer/service/test_helper.h" | 19 #include "gpu/command_buffer/service/test_helper.h" |
| 21 #include "gpu/command_buffer/service/vertex_attrib_manager.h" | 20 #include "gpu/command_buffer/service/vertex_attrib_manager.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "ui/gl/gl_implementation.h" | 22 #include "ui/gl/gl_implementation.h" |
| 24 #include "ui/gl/gl_mock.h" | 23 #include "ui/gl/gl_mock.h" |
| 25 #include "ui/gl/gl_surface.h" | 24 #include "ui/gl/gl_surface.h" |
| 26 | 25 |
| 27 using ::gfx::MockGLInterface; | 26 using ::gfx::MockGLInterface; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 54 client_vertex_shader_id_(121), | 53 client_vertex_shader_id_(121), |
| 55 client_fragment_shader_id_(122), | 54 client_fragment_shader_id_(122), |
| 56 client_query_id_(123), | 55 client_query_id_(123), |
| 57 client_vertexarray_id_(124) { | 56 client_vertexarray_id_(124) { |
| 58 memset(immediate_buffer_, 0xEE, sizeof(immediate_buffer_)); | 57 memset(immediate_buffer_, 0xEE, sizeof(immediate_buffer_)); |
| 59 } | 58 } |
| 60 | 59 |
| 61 GLES2DecoderTestBase::~GLES2DecoderTestBase() {} | 60 GLES2DecoderTestBase::~GLES2DecoderTestBase() {} |
| 62 | 61 |
| 63 void GLES2DecoderTestBase::SetUp() { | 62 void GLES2DecoderTestBase::SetUp() { |
| 64 InitDecoder( | 63 InitState init; |
| 65 "", // extensions | 64 init.gl_version = "3.0"; |
| 66 "3.0", // gl version | 65 init.has_alpha = true; |
| 67 true, // has alpha | 66 init.has_depth = true; |
| 68 true, // has depth | 67 init.request_alpha = true; |
| 69 false, // has stencil | 68 init.request_depth = true; |
| 70 true, // request alpha | 69 init.bind_generates_resource = true; |
| 71 true, // request depth | 70 InitDecoder(init); |
| 72 false, // request stencil | |
| 73 true); // bind generates resource | |
| 74 } | 71 } |
| 75 | 72 |
| 76 void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() { | 73 void GLES2DecoderTestBase::AddExpectationsForVertexAttribManager() { |
| 77 for (GLint ii = 0; ii < kNumVertexAttribs; ++ii) { | 74 for (GLint ii = 0; ii < kNumVertexAttribs; ++ii) { |
| 78 EXPECT_CALL(*gl_, VertexAttrib4f(ii, 0.0f, 0.0f, 0.0f, 1.0f)) | 75 EXPECT_CALL(*gl_, VertexAttrib4f(ii, 0.0f, 0.0f, 0.0f, 1.0f)) |
| 79 .Times(1) | 76 .Times(1) |
| 80 .RetiresOnSaturation(); | 77 .RetiresOnSaturation(); |
| 81 } | 78 } |
| 82 } | 79 } |
| 83 | 80 |
| 84 void GLES2DecoderTestBase::InitDecoder( | 81 GLES2DecoderTestBase::InitState::InitState() |
| 85 const char* extensions, | 82 : has_alpha(false), |
| 86 const char* gl_version, | 83 has_depth(false), |
| 87 bool has_alpha, | 84 has_stencil(false), |
| 88 bool has_depth, | 85 request_alpha(false), |
| 89 bool has_stencil, | 86 request_depth(false), |
| 90 bool request_alpha, | 87 request_stencil(false), |
| 91 bool request_depth, | 88 bind_generates_resource(false), |
| 92 bool request_stencil, | 89 lose_context_when_out_of_memory(false) {} |
| 93 bool bind_generates_resource) { | 90 |
| 94 InitDecoderWithCommandLine(extensions, | 91 void GLES2DecoderTestBase::InitDecoder(const InitState& init) { |
| 95 gl_version, | 92 InitDecoderWithCommandLine(init, NULL); |
| 96 has_alpha, | |
| 97 has_depth, | |
| 98 has_stencil, | |
| 99 request_alpha, | |
| 100 request_depth, | |
| 101 request_stencil, | |
| 102 bind_generates_resource, | |
| 103 NULL); | |
| 104 } | 93 } |
| 105 | 94 |
| 106 void GLES2DecoderTestBase::InitDecoderWithCommandLine( | 95 void GLES2DecoderTestBase::InitDecoderWithCommandLine( |
| 107 const char* extensions, | 96 const InitState& init, |
| 108 const char* gl_version, | |
| 109 bool has_alpha, | |
| 110 bool has_depth, | |
| 111 bool has_stencil, | |
| 112 bool request_alpha, | |
| 113 bool request_depth, | |
| 114 bool request_stencil, | |
| 115 bool bind_generates_resource, | |
| 116 const base::CommandLine* command_line) { | 97 const base::CommandLine* command_line) { |
| 117 Framebuffer::ClearFramebufferCompleteComboMap(); | 98 Framebuffer::ClearFramebufferCompleteComboMap(); |
| 118 | 99 |
| 119 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); | 100 gfx::SetGLGetProcAddressProc(gfx::MockGLInterface::GetGLProcAddress); |
| 120 gfx::GLSurface::InitializeOneOffWithMockBindingsForTests(); | 101 gfx::GLSurface::InitializeOneOffWithMockBindingsForTests(); |
| 121 | 102 |
| 122 gl_.reset(new StrictMock<MockGLInterface>()); | 103 gl_.reset(new StrictMock<MockGLInterface>()); |
| 123 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); | 104 ::gfx::MockGLInterface::SetGLInterface(gl_.get()); |
| 124 | 105 |
| 125 // Only create stream texture manager if extension is requested. | 106 // Only create stream texture manager if extension is requested. |
| 126 std::vector<std::string> list; | 107 std::vector<std::string> list; |
| 127 base::SplitString(std::string(extensions), ' ', &list); | 108 base::SplitString(init.extensions, ' ', &list); |
| 128 scoped_refptr<FeatureInfo> feature_info; | 109 scoped_refptr<FeatureInfo> feature_info; |
| 129 if (command_line) | 110 if (command_line) |
| 130 feature_info = new FeatureInfo(*command_line); | 111 feature_info = new FeatureInfo(*command_line); |
| 131 group_ = scoped_refptr<ContextGroup>(new ContextGroup( | 112 group_ = scoped_refptr<ContextGroup>( |
| 132 NULL, | 113 new ContextGroup(NULL, |
| 133 NULL, | 114 NULL, |
| 134 memory_tracker_, | 115 memory_tracker_, |
| 135 feature_info.get(), | 116 feature_info.get(), |
| 136 bind_generates_resource)); | 117 init.bind_generates_resource)); |
| 137 | 118 |
| 138 InSequence sequence; | 119 InSequence sequence; |
| 139 | 120 |
| 140 surface_ = new gfx::GLSurfaceStub; | 121 surface_ = new gfx::GLSurfaceStub; |
| 141 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight)); | 122 surface_->SetSize(gfx::Size(kBackBufferWidth, kBackBufferHeight)); |
| 142 | 123 |
| 143 // Context needs to be created before initializing ContextGroup, which will | 124 // Context needs to be created before initializing ContextGroup, which will |
| 144 // in turn initialize FeatureInfo, which needs a context to determine | 125 // in turn initialize FeatureInfo, which needs a context to determine |
| 145 // extension support. | 126 // extension support. |
| 146 context_ = new gfx::GLContextStubWithExtensions; | 127 context_ = new gfx::GLContextStubWithExtensions; |
| 147 context_->AddExtensionsString(extensions); | 128 context_->AddExtensionsString(init.extensions.c_str()); |
| 148 context_->SetGLVersionString(gl_version); | 129 context_->SetGLVersionString(init.gl_version.c_str()); |
| 149 | 130 |
| 150 context_->MakeCurrent(surface_.get()); | 131 context_->MakeCurrent(surface_.get()); |
| 151 gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_); | 132 gfx::GLSurface::InitializeDynamicMockBindingsForTests(context_); |
| 152 | 133 |
| 153 TestHelper::SetupContextGroupInitExpectations(gl_.get(), | 134 TestHelper::SetupContextGroupInitExpectations(gl_.get(), |
| 154 DisallowedFeatures(), extensions, gl_version); | 135 DisallowedFeatures(), |
| 136 init.extensions.c_str(), |
| 137 init.gl_version.c_str()); |
| 155 | 138 |
| 156 // We initialize the ContextGroup with a MockGLES2Decoder so that | 139 // We initialize the ContextGroup with a MockGLES2Decoder so that |
| 157 // we can use the ContextGroup to figure out how the real GLES2Decoder | 140 // we can use the ContextGroup to figure out how the real GLES2Decoder |
| 158 // will initialize itself. | 141 // will initialize itself. |
| 159 mock_decoder_.reset(new MockGLES2Decoder()); | 142 mock_decoder_.reset(new MockGLES2Decoder()); |
| 160 EXPECT_TRUE( | 143 EXPECT_TRUE( |
| 161 group_->Initialize(mock_decoder_.get(), DisallowedFeatures())); | 144 group_->Initialize(mock_decoder_.get(), DisallowedFeatures())); |
| 162 | 145 |
| 163 if (group_->feature_info()->workarounds().init_vertex_attributes) | 146 if (group_->feature_info()->workarounds().init_vertex_attributes) |
| 164 AddExpectationsForVertexAttribManager(); | 147 AddExpectationsForVertexAttribManager(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 .RetiresOnSaturation(); | 204 .RetiresOnSaturation(); |
| 222 } | 205 } |
| 223 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) | 206 EXPECT_CALL(*gl_, ActiveTexture(GL_TEXTURE0)) |
| 224 .Times(1) | 207 .Times(1) |
| 225 .RetiresOnSaturation(); | 208 .RetiresOnSaturation(); |
| 226 | 209 |
| 227 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0)) | 210 EXPECT_CALL(*gl_, BindFramebufferEXT(GL_FRAMEBUFFER, 0)) |
| 228 .Times(1) | 211 .Times(1) |
| 229 .RetiresOnSaturation(); | 212 .RetiresOnSaturation(); |
| 230 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _)) | 213 EXPECT_CALL(*gl_, GetIntegerv(GL_ALPHA_BITS, _)) |
| 231 .WillOnce(SetArgumentPointee<1>(has_alpha ? 8 : 0)) | 214 .WillOnce(SetArgumentPointee<1>(init.has_alpha ? 8 : 0)) |
| 232 .RetiresOnSaturation(); | 215 .RetiresOnSaturation(); |
| 233 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _)) | 216 EXPECT_CALL(*gl_, GetIntegerv(GL_DEPTH_BITS, _)) |
| 234 .WillOnce(SetArgumentPointee<1>(has_depth ? 24 : 0)) | 217 .WillOnce(SetArgumentPointee<1>(init.has_depth ? 24 : 0)) |
| 235 .RetiresOnSaturation(); | 218 .RetiresOnSaturation(); |
| 236 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _)) | 219 EXPECT_CALL(*gl_, GetIntegerv(GL_STENCIL_BITS, _)) |
| 237 .WillOnce(SetArgumentPointee<1>(has_stencil ? 8 : 0)) | 220 .WillOnce(SetArgumentPointee<1>(init.has_stencil ? 8 : 0)) |
| 238 .RetiresOnSaturation(); | 221 .RetiresOnSaturation(); |
| 239 | 222 |
| 240 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE)) | 223 EXPECT_CALL(*gl_, Enable(GL_VERTEX_PROGRAM_POINT_SIZE)) |
| 241 .Times(1) | 224 .Times(1) |
| 242 .RetiresOnSaturation(); | 225 .RetiresOnSaturation(); |
| 243 | 226 |
| 244 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE)) | 227 EXPECT_CALL(*gl_, Enable(GL_POINT_SPRITE)) |
| 245 .Times(1) | 228 .Times(1) |
| 246 .RetiresOnSaturation(); | 229 .RetiresOnSaturation(); |
| 247 | 230 |
| 248 static GLint max_viewport_dims[] = { | 231 static GLint max_viewport_dims[] = { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 | 268 |
| 286 engine_.reset(new StrictMock<MockCommandBufferEngine>()); | 269 engine_.reset(new StrictMock<MockCommandBufferEngine>()); |
| 287 scoped_refptr<gpu::Buffer> buffer = | 270 scoped_refptr<gpu::Buffer> buffer = |
| 288 engine_->GetSharedMemoryBuffer(kSharedMemoryId); | 271 engine_->GetSharedMemoryBuffer(kSharedMemoryId); |
| 289 shared_memory_offset_ = kSharedMemoryOffset; | 272 shared_memory_offset_ = kSharedMemoryOffset; |
| 290 shared_memory_address_ = | 273 shared_memory_address_ = |
| 291 reinterpret_cast<int8*>(buffer->memory()) + shared_memory_offset_; | 274 reinterpret_cast<int8*>(buffer->memory()) + shared_memory_offset_; |
| 292 shared_memory_id_ = kSharedMemoryId; | 275 shared_memory_id_ = kSharedMemoryId; |
| 293 shared_memory_base_ = buffer->memory(); | 276 shared_memory_base_ = buffer->memory(); |
| 294 | 277 |
| 295 int32 attributes[] = { | 278 static const int32 kLoseContextWhenOutOfMemory = 0x10003; |
| 296 EGL_ALPHA_SIZE, request_alpha ? 8 : 0, | 279 |
| 297 EGL_DEPTH_SIZE, request_depth ? 24 : 0, | 280 int32 attributes[] = {EGL_ALPHA_SIZE, |
| 298 EGL_STENCIL_SIZE, request_stencil ? 8 : 0, | 281 init.request_alpha ? 8 : 0, |
| 299 }; | 282 EGL_DEPTH_SIZE, |
| 283 init.request_depth ? 24 : 0, |
| 284 EGL_STENCIL_SIZE, |
| 285 init.request_stencil ? 8 : 0, |
| 286 kLoseContextWhenOutOfMemory, |
| 287 init.lose_context_when_out_of_memory ? 1 : 0, }; |
| 300 std::vector<int32> attribs(attributes, attributes + arraysize(attributes)); | 288 std::vector<int32> attribs(attributes, attributes + arraysize(attributes)); |
| 301 | 289 |
| 302 decoder_.reset(GLES2Decoder::Create(group_.get())); | 290 decoder_.reset(GLES2Decoder::Create(group_.get())); |
| 303 decoder_->GetLogger()->set_log_synthesized_gl_errors(false); | 291 decoder_->GetLogger()->set_log_synthesized_gl_errors(false); |
| 304 decoder_->Initialize(surface_, | 292 decoder_->Initialize(surface_, |
| 305 context_, | 293 context_, |
| 306 false, | 294 false, |
| 307 surface_->GetSize(), | 295 surface_->GetSize(), |
| 308 DisallowedFeatures(), | 296 DisallowedFeatures(), |
| 309 attribs); | 297 attribs); |
| (...skipping 1154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1464 SetupDefaultProgram(); | 1452 SetupDefaultProgram(); |
| 1465 } | 1453 } |
| 1466 | 1454 |
| 1467 // Include the auto-generated part of this file. We split this because it means | 1455 // Include the auto-generated part of this file. We split this because it means |
| 1468 // we can easily edit the non-auto generated parts right here in this file | 1456 // we can easily edit the non-auto generated parts right here in this file |
| 1469 // instead of having to edit some template or the code generator. | 1457 // instead of having to edit some template or the code generator. |
| 1470 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h" | 1458 #include "gpu/command_buffer/service/gles2_cmd_decoder_unittest_0_autogen.h" |
| 1471 | 1459 |
| 1472 } // namespace gles2 | 1460 } // namespace gles2 |
| 1473 } // namespace gpu | 1461 } // namespace gpu |
| OLD | NEW |