| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "cc/output/gl_renderer.h" | 5 #include "cc/output/gl_renderer.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "cc/base/math_util.h" | 9 #include "cc/base/math_util.h" |
| 10 #include "cc/output/compositor_frame_metadata.h" | 10 #include "cc/output/compositor_frame_metadata.h" |
| (...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 239 FakeRendererClient renderer_client_; | 239 FakeRendererClient renderer_client_; |
| 240 scoped_ptr<ResourceProvider> resource_provider_; | 240 scoped_ptr<ResourceProvider> resource_provider_; |
| 241 scoped_ptr<FakeRendererGL> renderer_; | 241 scoped_ptr<FakeRendererGL> renderer_; |
| 242 }; | 242 }; |
| 243 | 243 |
| 244 // Closing the namespace here so that GLRendererShaderTest can take advantage | 244 // Closing the namespace here so that GLRendererShaderTest can take advantage |
| 245 // of the friend relationship with GLRenderer and all of the mock classes | 245 // of the friend relationship with GLRenderer and all of the mock classes |
| 246 // declared above it. | 246 // declared above it. |
| 247 } // namespace | 247 } // namespace |
| 248 | 248 |
| 249 | |
| 250 // Gives unique shader ids and unique program ids for tests that need them. | |
| 251 class ShaderCreatorMockGraphicsContext : public TestWebGraphicsContext3D { | |
| 252 public: | |
| 253 ShaderCreatorMockGraphicsContext() | |
| 254 : next_program_id_number_(10000), | |
| 255 next_shader_id_number_(1) {} | |
| 256 | |
| 257 bool hasShader(WebGLId shader) { | |
| 258 return shader_set_.find(shader) != shader_set_.end(); | |
| 259 } | |
| 260 | |
| 261 bool hasProgram(WebGLId program) { | |
| 262 return program_set_.find(program) != program_set_.end(); | |
| 263 } | |
| 264 | |
| 265 virtual WebGLId createProgram() { | |
| 266 unsigned program = next_program_id_number_; | |
| 267 program_set_.insert(program); | |
| 268 next_program_id_number_++; | |
| 269 return program; | |
| 270 } | |
| 271 | |
| 272 virtual void deleteProgram(WebGLId program) { | |
| 273 ASSERT_TRUE(hasProgram(program)); | |
| 274 program_set_.erase(program); | |
| 275 } | |
| 276 | |
| 277 virtual void useProgram(WebGLId program) { | |
| 278 if (!program) | |
| 279 return; | |
| 280 ASSERT_TRUE(hasProgram(program)); | |
| 281 } | |
| 282 | |
| 283 virtual WebKit::WebGLId createShader(WebKit::WGC3Denum) { | |
| 284 unsigned shader = next_shader_id_number_; | |
| 285 shader_set_.insert(shader); | |
| 286 next_shader_id_number_++; | |
| 287 return shader; | |
| 288 } | |
| 289 | |
| 290 virtual void deleteShader(WebKit::WebGLId shader) { | |
| 291 ASSERT_TRUE(hasShader(shader)); | |
| 292 shader_set_.erase(shader); | |
| 293 } | |
| 294 | |
| 295 virtual void attachShader(WebGLId program, WebGLId shader) { | |
| 296 ASSERT_TRUE(hasProgram(program)); | |
| 297 ASSERT_TRUE(hasShader(shader)); | |
| 298 } | |
| 299 | |
| 300 protected: | |
| 301 unsigned next_program_id_number_; | |
| 302 unsigned next_shader_id_number_; | |
| 303 std::set<unsigned> program_set_; | |
| 304 std::set<unsigned> shader_set_; | |
| 305 }; | |
| 306 | |
| 307 class GLRendererShaderTest : public testing::Test { | 249 class GLRendererShaderTest : public testing::Test { |
| 308 protected: | 250 protected: |
| 309 GLRendererShaderTest() { | 251 GLRendererShaderTest() { |
| 310 output_surface_ = FakeOutputSurface::Create3d( | 252 output_surface_ = FakeOutputSurface::Create3d().Pass(); |
| 311 scoped_ptr<TestWebGraphicsContext3D>( | |
| 312 new ShaderCreatorMockGraphicsContext())).Pass(); | |
| 313 CHECK(output_surface_->BindToClient(&output_surface_client_)); | 253 CHECK(output_surface_->BindToClient(&output_surface_client_)); |
| 314 | 254 |
| 315 resource_provider_ = | 255 resource_provider_ = |
| 316 ResourceProvider::Create(output_surface_.get(), NULL, 0, false).Pass(); | 256 ResourceProvider::Create(output_surface_.get(), NULL, 0, false).Pass(); |
| 317 renderer_.reset(new FakeRendererGL(&renderer_client_, | 257 renderer_.reset(new FakeRendererGL(&renderer_client_, |
| 318 &settings_, | 258 &settings_, |
| 319 output_surface_.get(), | 259 output_surface_.get(), |
| 320 resource_provider_.get())); | 260 resource_provider_.get())); |
| 321 renderer_->Initialize(); | 261 renderer_->Initialize(); |
| 322 } | 262 } |
| (...skipping 1540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1863 base::MessageLoop::current()->Run(); | 1803 base::MessageLoop::current()->Run(); |
| 1864 | 1804 |
| 1865 // The sync point should have happened. | 1805 // The sync point should have happened. |
| 1866 EXPECT_EQ(1, sync_point_callback_count); | 1806 EXPECT_EQ(1, sync_point_callback_count); |
| 1867 EXPECT_EQ(1, other_callback_count); | 1807 EXPECT_EQ(1, other_callback_count); |
| 1868 } | 1808 } |
| 1869 #endif // OS_ANDROID | 1809 #endif // OS_ANDROID |
| 1870 | 1810 |
| 1871 } // namespace | 1811 } // namespace |
| 1872 } // namespace cc | 1812 } // namespace cc |
| OLD | NEW |