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

Side by Side Diff: cc/output/gl_renderer_unittest.cc

Issue 20185002: ContextProvider in OutputSurface (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: contextprovider: don't access Context3d() in OutputSurface contructors, it's not bound yet Created 7 years, 4 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
« no previous file with comments | « cc/output/gl_renderer.cc ('k') | cc/output/output_surface.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/debug/test_web_graphics_context_3d.h" 10 #include "cc/debug/test_web_graphics_context_3d.h"
11 #include "cc/output/compositor_frame_metadata.h" 11 #include "cc/output/compositor_frame_metadata.h"
12 #include "cc/resources/prioritized_resource_manager.h" 12 #include "cc/resources/prioritized_resource_manager.h"
13 #include "cc/resources/resource_provider.h" 13 #include "cc/resources/resource_provider.h"
14 #include "cc/resources/sync_point_helper.h" 14 #include "cc/resources/sync_point_helper.h"
15 #include "cc/test/fake_impl_proxy.h" 15 #include "cc/test/fake_impl_proxy.h"
16 #include "cc/test/fake_layer_tree_host_impl.h" 16 #include "cc/test/fake_layer_tree_host_impl.h"
17 #include "cc/test/fake_output_surface.h" 17 #include "cc/test/fake_output_surface.h"
18 #include "cc/test/fake_output_surface_client.h"
18 #include "cc/test/mock_quad_culler.h" 19 #include "cc/test/mock_quad_culler.h"
19 #include "cc/test/pixel_test.h" 20 #include "cc/test/pixel_test.h"
20 #include "cc/test/render_pass_test_common.h" 21 #include "cc/test/render_pass_test_common.h"
21 #include "cc/test/render_pass_test_utils.h" 22 #include "cc/test/render_pass_test_utils.h"
22 #include "gpu/GLES2/gl2extchromium.h" 23 #include "gpu/GLES2/gl2extchromium.h"
23 #include "testing/gmock/include/gmock/gmock.h" 24 #include "testing/gmock/include/gmock/gmock.h"
24 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
25 #include "third_party/khronos/GLES2/gl2.h" 26 #include "third_party/khronos/GLES2/gl2.h"
26 #include "third_party/skia/include/core/SkImageFilter.h" 27 #include "third_party/skia/include/core/SkImageFilter.h"
27 #include "third_party/skia/include/core/SkMatrix.h" 28 #include "third_party/skia/include/core/SkMatrix.h"
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 using GLRenderer::Initialize; 226 using GLRenderer::Initialize;
226 using GLRenderer::IsBackbufferDiscarded; 227 using GLRenderer::IsBackbufferDiscarded;
227 using GLRenderer::DoDrawQuad; 228 using GLRenderer::DoDrawQuad;
228 using GLRenderer::BeginDrawingFrame; 229 using GLRenderer::BeginDrawingFrame;
229 using GLRenderer::FinishDrawingQuadList; 230 using GLRenderer::FinishDrawingQuadList;
230 using GLRenderer::stencil_enabled; 231 using GLRenderer::stencil_enabled;
231 }; 232 };
232 233
233 class GLRendererTest : public testing::Test { 234 class GLRendererTest : public testing::Test {
234 protected: 235 protected:
235 GLRendererTest() 236 GLRendererTest() {
236 : output_surface_(FakeOutputSurface::Create3d( 237 scoped_ptr<FrameCountingContext> context3d(new FrameCountingContext);
237 scoped_ptr<WebKit::WebGraphicsContext3D>( 238 context3d_ = context3d.get();
238 new FrameCountingContext()))),
239 resource_provider_(ResourceProvider::Create(output_surface_.get(), 0)),
240 renderer_(&mock_client_,
241 output_surface_.get(),
242 resource_provider_.get()) {}
243 239
244 virtual void SetUp() { renderer_.Initialize(); } 240 output_surface_ = FakeOutputSurface::Create3d(
241 context3d.PassAs<TestWebGraphicsContext3D>()).Pass();
242 CHECK(output_surface_->BindToClient(&output_surface_client_));
245 243
246 void SwapBuffers() { renderer_.SwapBuffers(); } 244 resource_provider_ =
247 245 ResourceProvider::Create(output_surface_.get(), 0).Pass();
248 FrameCountingContext* Context() { 246 renderer_ = make_scoped_ptr(new FakeRendererGL(
249 return static_cast<FrameCountingContext*>(output_surface_->context3d()); 247 &renderer_client_,
248 output_surface_.get(),
249 resource_provider_.get()));
250 } 250 }
251 251
252 scoped_ptr<OutputSurface> output_surface_; 252 virtual void SetUp() { renderer_->Initialize(); }
253 FakeRendererClient mock_client_; 253
254 void SwapBuffers() { renderer_->SwapBuffers(); }
255
256 FrameCountingContext* context3d_;
257 FakeOutputSurfaceClient output_surface_client_;
258 scoped_ptr<FakeOutputSurface> output_surface_;
259 FakeRendererClient renderer_client_;
254 scoped_ptr<ResourceProvider> resource_provider_; 260 scoped_ptr<ResourceProvider> resource_provider_;
255 FakeRendererGL renderer_; 261 scoped_ptr<FakeRendererGL> renderer_;
256 }; 262 };
257 263
258 // Closing the namespace here so that GLRendererShaderTest can take advantage 264 // Closing the namespace here so that GLRendererShaderTest can take advantage
259 // of the friend relationship with GLRenderer and all of the mock classes 265 // of the friend relationship with GLRenderer and all of the mock classes
260 // declared above it. 266 // declared above it.
261 } // namespace 267 } // namespace
262 268
263 269
264 // Gives unique shader ids and unique program ids for tests that need them. 270 // Gives unique shader ids and unique program ids for tests that need them.
265 class ShaderCreatorMockGraphicsContext : public TestWebGraphicsContext3D { 271 class ShaderCreatorMockGraphicsContext : public TestWebGraphicsContext3D {
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 319
314 protected: 320 protected:
315 unsigned next_program_id_number_; 321 unsigned next_program_id_number_;
316 unsigned next_shader_id_number_; 322 unsigned next_shader_id_number_;
317 std::set<unsigned> program_set_; 323 std::set<unsigned> program_set_;
318 std::set<unsigned> shader_set_; 324 std::set<unsigned> shader_set_;
319 }; 325 };
320 326
321 class GLRendererShaderTest : public testing::Test { 327 class GLRendererShaderTest : public testing::Test {
322 protected: 328 protected:
323 GLRendererShaderTest() 329 GLRendererShaderTest() {
324 : output_surface_(FakeOutputSurface::Create3d( 330 output_surface_ = FakeOutputSurface::Create3d(
325 scoped_ptr<WebKit::WebGraphicsContext3D>( 331 scoped_ptr<TestWebGraphicsContext3D>(
326 new ShaderCreatorMockGraphicsContext()))), 332 new ShaderCreatorMockGraphicsContext())).Pass();
327 resource_provider_(ResourceProvider::Create(output_surface_.get(), 0)), 333 CHECK(output_surface_->BindToClient(&output_surface_client_));
328 renderer_(scoped_ptr<FakeRendererGL>( 334
329 new FakeRendererGL(&mock_client_, 335 resource_provider_ = ResourceProvider::Create(output_surface_.get(),
330 output_surface_.get(), 336 0).Pass();
331 resource_provider_.get()))) { 337 renderer_.reset(new FakeRendererGL(&renderer_client_,
338 output_surface_.get(),
339 resource_provider_.get()));
332 renderer_->Initialize(); 340 renderer_->Initialize();
333 } 341 }
334 342
335 void TestRenderPassProgram() { 343 void TestRenderPassProgram() {
336 EXPECT_PROGRAM_VALID(renderer_->render_pass_program_); 344 EXPECT_PROGRAM_VALID(renderer_->render_pass_program_);
337 EXPECT_EQ(renderer_->render_pass_program_->program(), 345 EXPECT_EQ(renderer_->render_pass_program_->program(),
338 renderer_->program_shadow_); 346 renderer_->program_shadow_);
339 } 347 }
340 348
341 void TestRenderPassColorMatrixProgram() { 349 void TestRenderPassColorMatrixProgram() {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 EXPECT_EQ(renderer_->render_pass_mask_color_matrix_program_aa_->program(), 387 EXPECT_EQ(renderer_->render_pass_mask_color_matrix_program_aa_->program(),
380 renderer_->program_shadow_); 388 renderer_->program_shadow_);
381 } 389 }
382 390
383 void TestSolidColorProgramAA() { 391 void TestSolidColorProgramAA() {
384 EXPECT_PROGRAM_VALID(renderer_->solid_color_program_aa_); 392 EXPECT_PROGRAM_VALID(renderer_->solid_color_program_aa_);
385 EXPECT_EQ(renderer_->solid_color_program_aa_->program(), 393 EXPECT_EQ(renderer_->solid_color_program_aa_->program(),
386 renderer_->program_shadow_); 394 renderer_->program_shadow_);
387 } 395 }
388 396
389 scoped_ptr<OutputSurface> output_surface_; 397 FakeOutputSurfaceClient output_surface_client_;
390 FakeRendererClient mock_client_; 398 scoped_ptr<FakeOutputSurface> output_surface_;
399 FakeRendererClient renderer_client_;
391 scoped_ptr<ResourceProvider> resource_provider_; 400 scoped_ptr<ResourceProvider> resource_provider_;
392 scoped_ptr<FakeRendererGL> renderer_; 401 scoped_ptr<FakeRendererGL> renderer_;
393 }; 402 };
394 403
395 namespace { 404 namespace {
396 405
397 // Test GLRenderer discardBackbuffer functionality: 406 // Test GLRenderer discardBackbuffer functionality:
398 // Suggest recreating framebuffer when one already exists. 407 // Suggest recreating framebuffer when one already exists.
399 // Expected: it does nothing. 408 // Expected: it does nothing.
400 TEST_F(GLRendererTest, SuggestBackbufferYesWhenItAlreadyExistsShouldDoNothing) { 409 TEST_F(GLRendererTest, SuggestBackbufferYesWhenItAlreadyExistsShouldDoNothing) {
401 renderer_.SetDiscardBackBufferWhenNotVisible(false); 410 renderer_->SetDiscardBackBufferWhenNotVisible(false);
402 EXPECT_EQ(0, mock_client_.set_full_root_layer_damage_count()); 411 EXPECT_EQ(0, renderer_client_.set_full_root_layer_damage_count());
403 EXPECT_FALSE(renderer_.IsBackbufferDiscarded()); 412 EXPECT_FALSE(renderer_->IsBackbufferDiscarded());
404 413
405 SwapBuffers(); 414 SwapBuffers();
406 EXPECT_EQ(1, Context()->frame_count()); 415 EXPECT_EQ(1, context3d_->frame_count());
407 } 416 }
408 417
409 // Test GLRenderer DiscardBackbuffer functionality: 418 // Test GLRenderer DiscardBackbuffer functionality:
410 // Suggest discarding framebuffer when one exists and the renderer is not 419 // Suggest discarding framebuffer when one exists and the renderer is not
411 // visible. 420 // visible.
412 // Expected: it is discarded and damage tracker is reset. 421 // Expected: it is discarded and damage tracker is reset.
413 TEST_F( 422 TEST_F(
414 GLRendererTest, 423 GLRendererTest,
415 SuggestBackbufferNoShouldDiscardBackbufferAndDamageRootLayerIfNotVisible) { 424 SuggestBackbufferNoShouldDiscardBackbufferAndDamageRootLayerIfNotVisible) {
416 renderer_.SetVisible(false); 425 renderer_->SetVisible(false);
417 renderer_.SetDiscardBackBufferWhenNotVisible(true); 426 renderer_->SetDiscardBackBufferWhenNotVisible(true);
418 EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count()); 427 EXPECT_EQ(1, renderer_client_.set_full_root_layer_damage_count());
419 EXPECT_TRUE(renderer_.IsBackbufferDiscarded()); 428 EXPECT_TRUE(renderer_->IsBackbufferDiscarded());
420 } 429 }
421 430
422 // Test GLRenderer DiscardBackbuffer functionality: 431 // Test GLRenderer DiscardBackbuffer functionality:
423 // Suggest discarding framebuffer when one exists and the renderer is visible. 432 // Suggest discarding framebuffer when one exists and the renderer is visible.
424 // Expected: the allocation is ignored. 433 // Expected: the allocation is ignored.
425 TEST_F(GLRendererTest, SuggestBackbufferNoDoNothingWhenVisible) { 434 TEST_F(GLRendererTest, SuggestBackbufferNoDoNothingWhenVisible) {
426 renderer_.SetVisible(true); 435 renderer_->SetVisible(true);
427 renderer_.SetDiscardBackBufferWhenNotVisible(true); 436 renderer_->SetDiscardBackBufferWhenNotVisible(true);
428 EXPECT_EQ(0, mock_client_.set_full_root_layer_damage_count()); 437 EXPECT_EQ(0, renderer_client_.set_full_root_layer_damage_count());
429 EXPECT_FALSE(renderer_.IsBackbufferDiscarded()); 438 EXPECT_FALSE(renderer_->IsBackbufferDiscarded());
430 } 439 }
431 440
432 // Test GLRenderer DiscardBackbuffer functionality: 441 // Test GLRenderer DiscardBackbuffer functionality:
433 // Suggest discarding framebuffer when one does not exist. 442 // Suggest discarding framebuffer when one does not exist.
434 // Expected: it does nothing. 443 // Expected: it does nothing.
435 TEST_F(GLRendererTest, SuggestBackbufferNoWhenItDoesntExistShouldDoNothing) { 444 TEST_F(GLRendererTest, SuggestBackbufferNoWhenItDoesntExistShouldDoNothing) {
436 renderer_.SetVisible(false); 445 renderer_->SetVisible(false);
437 renderer_.SetDiscardBackBufferWhenNotVisible(true); 446 renderer_->SetDiscardBackBufferWhenNotVisible(true);
438 EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count()); 447 EXPECT_EQ(1, renderer_client_.set_full_root_layer_damage_count());
439 EXPECT_TRUE(renderer_.IsBackbufferDiscarded()); 448 EXPECT_TRUE(renderer_->IsBackbufferDiscarded());
440 449
441 renderer_.SetDiscardBackBufferWhenNotVisible(true); 450 renderer_->SetDiscardBackBufferWhenNotVisible(true);
442 EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count()); 451 EXPECT_EQ(1, renderer_client_.set_full_root_layer_damage_count());
443 EXPECT_TRUE(renderer_.IsBackbufferDiscarded()); 452 EXPECT_TRUE(renderer_->IsBackbufferDiscarded());
444 } 453 }
445 454
446 // Test GLRenderer DiscardBackbuffer functionality: 455 // Test GLRenderer DiscardBackbuffer functionality:
447 // Begin drawing a frame while a framebuffer is discarded. 456 // Begin drawing a frame while a framebuffer is discarded.
448 // Expected: will recreate framebuffer. 457 // Expected: will recreate framebuffer.
449 TEST_F(GLRendererTest, DiscardedBackbufferIsRecreatedForScopeDuration) { 458 TEST_F(GLRendererTest, DiscardedBackbufferIsRecreatedForScopeDuration) {
450 renderer_.SetVisible(false); 459 renderer_->SetVisible(false);
451 renderer_.SetDiscardBackBufferWhenNotVisible(true); 460 renderer_->SetDiscardBackBufferWhenNotVisible(true);
452 EXPECT_TRUE(renderer_.IsBackbufferDiscarded()); 461 EXPECT_TRUE(renderer_->IsBackbufferDiscarded());
453 EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count()); 462 EXPECT_EQ(1, renderer_client_.set_full_root_layer_damage_count());
454 463
455 renderer_.SetVisible(true); 464 renderer_->SetVisible(true);
456 renderer_.DrawFrame(mock_client_.render_passes_in_draw_order()); 465 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
457 EXPECT_FALSE(renderer_.IsBackbufferDiscarded()); 466 EXPECT_FALSE(renderer_->IsBackbufferDiscarded());
458 467
459 SwapBuffers(); 468 SwapBuffers();
460 EXPECT_EQ(1, Context()->frame_count()); 469 EXPECT_EQ(1, context3d_->frame_count());
461 } 470 }
462 471
463 TEST_F(GLRendererTest, FramebufferDiscardedAfterReadbackWhenNotVisible) { 472 TEST_F(GLRendererTest, FramebufferDiscardedAfterReadbackWhenNotVisible) {
464 renderer_.SetVisible(false); 473 renderer_->SetVisible(false);
465 renderer_.SetDiscardBackBufferWhenNotVisible(true); 474 renderer_->SetDiscardBackBufferWhenNotVisible(true);
466 EXPECT_TRUE(renderer_.IsBackbufferDiscarded()); 475 EXPECT_TRUE(renderer_->IsBackbufferDiscarded());
467 EXPECT_EQ(1, mock_client_.set_full_root_layer_damage_count()); 476 EXPECT_EQ(1, renderer_client_.set_full_root_layer_damage_count());
468 477
469 char pixels[4]; 478 char pixels[4];
470 renderer_.DrawFrame(mock_client_.render_passes_in_draw_order()); 479 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
471 EXPECT_FALSE(renderer_.IsBackbufferDiscarded()); 480 EXPECT_FALSE(renderer_->IsBackbufferDiscarded());
472 481
473 renderer_.GetFramebufferPixels(pixels, gfx::Rect(0, 0, 1, 1)); 482 renderer_->GetFramebufferPixels(pixels, gfx::Rect(0, 0, 1, 1));
474 EXPECT_TRUE(renderer_.IsBackbufferDiscarded()); 483 EXPECT_TRUE(renderer_->IsBackbufferDiscarded());
475 EXPECT_EQ(2, mock_client_.set_full_root_layer_damage_count()); 484 EXPECT_EQ(2, renderer_client_.set_full_root_layer_damage_count());
476 } 485 }
477 486
478 TEST_F(GLRendererTest, ExternalStencil) { 487 TEST_F(GLRendererTest, ExternalStencil) {
479 EXPECT_FALSE(renderer_.stencil_enabled()); 488 EXPECT_FALSE(renderer_->stencil_enabled());
480 489
481 mock_client_.EnableExternalStencilTest(); 490 renderer_client_.EnableExternalStencilTest();
482 mock_client_.root_render_pass()->has_transparent_background = false; 491 renderer_client_.root_render_pass()->has_transparent_background = false;
483 492
484 renderer_.DrawFrame(mock_client_.render_passes_in_draw_order()); 493 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
485 EXPECT_TRUE(renderer_.stencil_enabled()); 494 EXPECT_TRUE(renderer_->stencil_enabled());
486 } 495 }
487 496
488 class ForbidSynchronousCallContext : public TestWebGraphicsContext3D { 497 class ForbidSynchronousCallContext : public TestWebGraphicsContext3D {
489 public: 498 public:
490 ForbidSynchronousCallContext() {} 499 ForbidSynchronousCallContext() {}
491 500
492 virtual bool getActiveAttrib(WebGLId program, 501 virtual bool getActiveAttrib(WebGLId program,
493 WGC3Duint index, 502 WGC3Duint index,
494 ActiveInfo& info) { 503 ActiveInfo& info) {
495 ADD_FAILURE(); 504 ADD_FAILURE();
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
631 virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index, 640 virtual WGC3Dsizeiptr getVertexAttribOffset(WGC3Duint index,
632 WGC3Denum pname) { 641 WGC3Denum pname) {
633 ADD_FAILURE(); 642 ADD_FAILURE();
634 return 0; 643 return 0;
635 } 644 }
636 }; 645 };
637 646
638 // This test isn't using the same fixture as GLRendererTest, and you can't mix 647 // This test isn't using the same fixture as GLRendererTest, and you can't mix
639 // TEST() and TEST_F() with the same name, Hence LRC2. 648 // TEST() and TEST_F() with the same name, Hence LRC2.
640 TEST(GLRendererTest2, InitializationDoesNotMakeSynchronousCalls) { 649 TEST(GLRendererTest2, InitializationDoesNotMakeSynchronousCalls) {
641 FakeRendererClient mock_client; 650 FakeOutputSurfaceClient output_surface_client;
642 scoped_ptr<OutputSurface> output_surface( 651 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
643 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( 652 scoped_ptr<TestWebGraphicsContext3D>(new ForbidSynchronousCallContext)));
644 new ForbidSynchronousCallContext))); 653 CHECK(output_surface->BindToClient(&output_surface_client));
654
645 scoped_ptr<ResourceProvider> resource_provider( 655 scoped_ptr<ResourceProvider> resource_provider(
646 ResourceProvider::Create(output_surface.get(), 0)); 656 ResourceProvider::Create(output_surface.get(), 0));
657
658 FakeRendererClient renderer_client;
647 FakeRendererGL renderer( 659 FakeRendererGL renderer(
648 &mock_client, output_surface.get(), resource_provider.get()); 660 &renderer_client, output_surface.get(), resource_provider.get());
649 661
650 EXPECT_TRUE(renderer.Initialize()); 662 EXPECT_TRUE(renderer.Initialize());
651 } 663 }
652 664
653 class LoseContextOnFirstGetContext : public TestWebGraphicsContext3D { 665 class LoseContextOnFirstGetContext : public TestWebGraphicsContext3D {
654 public: 666 public:
655 LoseContextOnFirstGetContext() : context_lost_(false) {} 667 LoseContextOnFirstGetContext() : context_lost_(false) {}
656 668
657 virtual bool makeContextCurrent() OVERRIDE { return !context_lost_; } 669 virtual bool makeContextCurrent() OVERRIDE { return !context_lost_; }
658 670
(...skipping 11 matching lines...) Expand all
670 682
671 virtual WGC3Denum getGraphicsResetStatusARB() OVERRIDE { 683 virtual WGC3Denum getGraphicsResetStatusARB() OVERRIDE {
672 return context_lost_ ? 1 : 0; 684 return context_lost_ ? 1 : 0;
673 } 685 }
674 686
675 private: 687 private:
676 bool context_lost_; 688 bool context_lost_;
677 }; 689 };
678 690
679 TEST(GLRendererTest2, InitializationWithQuicklyLostContextDoesNotAssert) { 691 TEST(GLRendererTest2, InitializationWithQuicklyLostContextDoesNotAssert) {
680 FakeRendererClient mock_client; 692 FakeOutputSurfaceClient output_surface_client;
681 scoped_ptr<OutputSurface> output_surface( 693 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
682 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( 694 scoped_ptr<TestWebGraphicsContext3D>(new LoseContextOnFirstGetContext)));
683 new LoseContextOnFirstGetContext))); 695 CHECK(output_surface->BindToClient(&output_surface_client));
696
684 scoped_ptr<ResourceProvider> resource_provider( 697 scoped_ptr<ResourceProvider> resource_provider(
685 ResourceProvider::Create(output_surface.get(), 0)); 698 ResourceProvider::Create(output_surface.get(), 0));
699
700 FakeRendererClient renderer_client;
686 FakeRendererGL renderer( 701 FakeRendererGL renderer(
687 &mock_client, output_surface.get(), resource_provider.get()); 702 &renderer_client, output_surface.get(), resource_provider.get());
688 703
689 renderer.Initialize(); 704 renderer.Initialize();
690 } 705 }
691 706
692 class ClearCountingContext : public TestWebGraphicsContext3D { 707 class ClearCountingContext : public TestWebGraphicsContext3D {
693 public: 708 public:
694 ClearCountingContext() : clear_(0) {} 709 ClearCountingContext() : clear_(0) {}
695 710
696 virtual void clear(WGC3Dbitfield) { clear_++; } 711 virtual void clear(WGC3Dbitfield) { clear_++; }
697 712
698 int clear_count() const { return clear_; } 713 int clear_count() const { return clear_; }
699 714
700 private: 715 private:
701 int clear_; 716 int clear_;
702 }; 717 };
703 718
704 TEST(GLRendererTest2, OpaqueBackground) { 719 TEST(GLRendererTest2, OpaqueBackground) {
705 FakeRendererClient mock_client; 720 scoped_ptr<ClearCountingContext> context_owned(new ClearCountingContext);
721 ClearCountingContext* context = context_owned.get();
722
723 FakeOutputSurfaceClient output_surface_client;
706 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 724 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
707 scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); 725 context_owned.PassAs<TestWebGraphicsContext3D>()));
708 ClearCountingContext* context = 726 CHECK(output_surface->BindToClient(&output_surface_client));
709 static_cast<ClearCountingContext*>(output_surface->context3d()); 727
710 scoped_ptr<ResourceProvider> resource_provider( 728 scoped_ptr<ResourceProvider> resource_provider(
711 ResourceProvider::Create(output_surface.get(), 0)); 729 ResourceProvider::Create(output_surface.get(), 0));
730
731 FakeRendererClient renderer_client;
712 FakeRendererGL renderer( 732 FakeRendererGL renderer(
713 &mock_client, output_surface.get(), resource_provider.get()); 733 &renderer_client, output_surface.get(), resource_provider.get());
714 734
715 mock_client.root_render_pass()->has_transparent_background = false; 735 renderer_client.root_render_pass()->has_transparent_background = false;
716 736
717 EXPECT_TRUE(renderer.Initialize()); 737 EXPECT_TRUE(renderer.Initialize());
718 738
719 renderer.DrawFrame(mock_client.render_passes_in_draw_order()); 739 renderer.DrawFrame(renderer_client.render_passes_in_draw_order());
720 740
721 // On DEBUG builds, render passes with opaque background clear to blue to 741 // On DEBUG builds, render passes with opaque background clear to blue to
722 // easily see regions that were not drawn on the screen. 742 // easily see regions that were not drawn on the screen.
723 #ifdef NDEBUG 743 #ifdef NDEBUG
724 EXPECT_EQ(0, context->clear_count()); 744 EXPECT_EQ(0, context->clear_count());
725 #else 745 #else
726 EXPECT_EQ(1, context->clear_count()); 746 EXPECT_EQ(1, context->clear_count());
727 #endif 747 #endif
728 } 748 }
729 749
730 TEST(GLRendererTest2, TransparentBackground) { 750 TEST(GLRendererTest2, TransparentBackground) {
731 FakeRendererClient mock_client; 751 scoped_ptr<ClearCountingContext> context_owned(new ClearCountingContext);
752 ClearCountingContext* context = context_owned.get();
753
754 FakeOutputSurfaceClient output_surface_client;
732 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d( 755 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
733 scoped_ptr<WebKit::WebGraphicsContext3D>(new ClearCountingContext))); 756 context_owned.PassAs<TestWebGraphicsContext3D>()));
734 ClearCountingContext* context = 757 CHECK(output_surface->BindToClient(&output_surface_client));
735 static_cast<ClearCountingContext*>(output_surface->context3d()); 758
736 scoped_ptr<ResourceProvider> resource_provider( 759 scoped_ptr<ResourceProvider> resource_provider(
737 ResourceProvider::Create(output_surface.get(), 0)); 760 ResourceProvider::Create(output_surface.get(), 0));
761
762 FakeRendererClient renderer_client;
738 FakeRendererGL renderer( 763 FakeRendererGL renderer(
739 &mock_client, output_surface.get(), resource_provider.get()); 764 &renderer_client, output_surface.get(), resource_provider.get());
740 765
741 mock_client.root_render_pass()->has_transparent_background = true; 766 renderer_client.root_render_pass()->has_transparent_background = true;
742 767
743 EXPECT_TRUE(renderer.Initialize()); 768 EXPECT_TRUE(renderer.Initialize());
744 769
745 renderer.DrawFrame(mock_client.render_passes_in_draw_order()); 770 renderer.DrawFrame(renderer_client.render_passes_in_draw_order());
746 771
747 EXPECT_EQ(1, context->clear_count()); 772 EXPECT_EQ(1, context->clear_count());
748 } 773 }
749 774
750 class VisibilityChangeIsLastCallTrackingContext 775 class VisibilityChangeIsLastCallTrackingContext
751 : public TestWebGraphicsContext3D { 776 : public TestWebGraphicsContext3D {
752 public: 777 public:
753 VisibilityChangeIsLastCallTrackingContext() 778 VisibilityChangeIsLastCallTrackingContext()
754 : last_call_was_set_visibility_(false) {} 779 : last_call_was_set_visibility_(false) {}
755 780
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
792 // Methods added for test. 817 // Methods added for test.
793 bool last_call_was_set_visibility() const { 818 bool last_call_was_set_visibility() const {
794 return last_call_was_set_visibility_; 819 return last_call_was_set_visibility_;
795 } 820 }
796 821
797 private: 822 private:
798 bool last_call_was_set_visibility_; 823 bool last_call_was_set_visibility_;
799 }; 824 };
800 825
801 TEST(GLRendererTest2, VisibilityChangeIsLastCall) { 826 TEST(GLRendererTest2, VisibilityChangeIsLastCall) {
802 FakeRendererClient mock_client; 827 scoped_ptr<VisibilityChangeIsLastCallTrackingContext> context_owned(
803 scoped_ptr<OutputSurface> output_surface( 828 new VisibilityChangeIsLastCallTrackingContext);
804 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( 829 VisibilityChangeIsLastCallTrackingContext* context = context_owned.get();
805 new VisibilityChangeIsLastCallTrackingContext))); 830
806 VisibilityChangeIsLastCallTrackingContext* context = 831 FakeOutputSurfaceClient output_surface_client;
807 static_cast<VisibilityChangeIsLastCallTrackingContext*>( 832 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
808 output_surface->context3d()); 833 context_owned.PassAs<TestWebGraphicsContext3D>()));
834 CHECK(output_surface->BindToClient(&output_surface_client));
835
809 scoped_ptr<ResourceProvider> resource_provider( 836 scoped_ptr<ResourceProvider> resource_provider(
810 ResourceProvider::Create(output_surface.get(), 0)); 837 ResourceProvider::Create(output_surface.get(), 0));
838
839 FakeRendererClient renderer_client;
811 FakeRendererGL renderer( 840 FakeRendererGL renderer(
812 &mock_client, output_surface.get(), resource_provider.get()); 841 &renderer_client, output_surface.get(), resource_provider.get());
813 842
814 EXPECT_TRUE(renderer.Initialize()); 843 EXPECT_TRUE(renderer.Initialize());
815 844
816 // Ensure that the call to setVisibilityCHROMIUM is the last call issue to the 845 // Ensure that the call to setVisibilityCHROMIUM is the last call issue to the
817 // GPU process, after glFlush is called, and after the RendererClient's 846 // GPU process, after glFlush is called, and after the RendererClient's
818 // SetManagedMemoryPolicy is called. Plumb this tracking between both the 847 // SetManagedMemoryPolicy is called. Plumb this tracking between both the
819 // RenderClient and the Context by giving them both a pointer to a variable on 848 // RenderClient and the Context by giving them both a pointer to a variable on
820 // the stack. 849 // the stack.
821 renderer.SetVisible(true); 850 renderer.SetVisible(true);
822 renderer.DrawFrame(mock_client.render_passes_in_draw_order()); 851 renderer.DrawFrame(renderer_client.render_passes_in_draw_order());
823 renderer.SetVisible(false); 852 renderer.SetVisible(false);
824 EXPECT_TRUE(context->last_call_was_set_visibility()); 853 EXPECT_TRUE(context->last_call_was_set_visibility());
825 } 854 }
826 855
827 class TextureStateTrackingContext : public TestWebGraphicsContext3D { 856 class TextureStateTrackingContext : public TestWebGraphicsContext3D {
828 public: 857 public:
829 TextureStateTrackingContext() : active_texture_(GL_INVALID_ENUM) {} 858 TextureStateTrackingContext() : active_texture_(GL_INVALID_ENUM) {}
830 859
831 virtual WebString getString(WGC3Denum name) { 860 virtual WebString getString(WGC3Denum name) {
832 if (name == GL_EXTENSIONS) 861 if (name == GL_EXTENSIONS)
(...skipping 14 matching lines...) Expand all
847 active_texture_ = texture; 876 active_texture_ = texture;
848 } 877 }
849 878
850 WGC3Denum active_texture() const { return active_texture_; } 879 WGC3Denum active_texture() const { return active_texture_; }
851 880
852 private: 881 private:
853 WGC3Denum active_texture_; 882 WGC3Denum active_texture_;
854 }; 883 };
855 884
856 TEST(GLRendererTest2, ActiveTextureState) { 885 TEST(GLRendererTest2, ActiveTextureState) {
857 FakeRendererClient fake_client; 886 scoped_ptr<TextureStateTrackingContext> context_owned(
858 scoped_ptr<OutputSurface> output_surface( 887 new TextureStateTrackingContext);
859 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( 888 TextureStateTrackingContext* context = context_owned.get();
860 new TextureStateTrackingContext))); 889
861 TextureStateTrackingContext* context = 890 FakeOutputSurfaceClient output_surface_client;
862 static_cast<TextureStateTrackingContext*>(output_surface->context3d()); 891 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
892 context_owned.PassAs<TestWebGraphicsContext3D>()));
893 CHECK(output_surface->BindToClient(&output_surface_client));
894
863 scoped_ptr<ResourceProvider> resource_provider( 895 scoped_ptr<ResourceProvider> resource_provider(
864 ResourceProvider::Create(output_surface.get(), 0)); 896 ResourceProvider::Create(output_surface.get(), 0));
897
898 FakeRendererClient renderer_client;
865 FakeRendererGL renderer( 899 FakeRendererGL renderer(
866 &fake_client, output_surface.get(), resource_provider.get()); 900 &renderer_client, output_surface.get(), resource_provider.get());
867 901
868 // During initialization we are allowed to set any texture parameters. 902 // During initialization we are allowed to set any texture parameters.
869 EXPECT_CALL(*context, texParameteri(_, _, _)).Times(AnyNumber()); 903 EXPECT_CALL(*context, texParameteri(_, _, _)).Times(AnyNumber());
870 EXPECT_TRUE(renderer.Initialize()); 904 EXPECT_TRUE(renderer.Initialize());
871 905
872 cc::RenderPass::Id id(1, 1); 906 cc::RenderPass::Id id(1, 1);
873 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create(); 907 scoped_ptr<TestRenderPass> pass = TestRenderPass::Create();
874 pass->SetNew(id, 908 pass->SetNew(id,
875 gfx::Rect(0, 0, 100, 100), 909 gfx::Rect(0, 0, 100, 100),
876 gfx::Rect(0, 0, 100, 100), 910 gfx::Rect(0, 0, 100, 100),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
931 public: 965 public:
932 MOCK_METHOD1(clear, void(WGC3Dbitfield mask)); 966 MOCK_METHOD1(clear, void(WGC3Dbitfield mask));
933 MOCK_METHOD4(drawElements, 967 MOCK_METHOD4(drawElements,
934 void(WGC3Denum mode, 968 void(WGC3Denum mode,
935 WGC3Dsizei count, 969 WGC3Dsizei count,
936 WGC3Denum type, 970 WGC3Denum type,
937 WGC3Dintptr offset)); 971 WGC3Dintptr offset));
938 }; 972 };
939 973
940 TEST(GLRendererTest2, ShouldClearRootRenderPass) { 974 TEST(GLRendererTest2, ShouldClearRootRenderPass) {
941 NoClearRootRenderPassFakeClient mock_client; 975 scoped_ptr<NoClearRootRenderPassMockContext> mock_context_owned(
942 scoped_ptr<OutputSurface> output_surface( 976 new NoClearRootRenderPassMockContext);
943 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( 977 NoClearRootRenderPassMockContext* mock_context = mock_context_owned.get();
944 new NoClearRootRenderPassMockContext))); 978
945 NoClearRootRenderPassMockContext* mock_context = 979 FakeOutputSurfaceClient output_surface_client;
946 static_cast<NoClearRootRenderPassMockContext*>( 980 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
947 output_surface->context3d()); 981 mock_context_owned.PassAs<TestWebGraphicsContext3D>()));
982 CHECK(output_surface->BindToClient(&output_surface_client));
983
948 scoped_ptr<ResourceProvider> resource_provider( 984 scoped_ptr<ResourceProvider> resource_provider(
949 ResourceProvider::Create(output_surface.get(), 0)); 985 ResourceProvider::Create(output_surface.get(), 0));
986
987 NoClearRootRenderPassFakeClient renderer_client;
950 FakeRendererGL renderer( 988 FakeRendererGL renderer(
951 &mock_client, output_surface.get(), resource_provider.get()); 989 &renderer_client, output_surface.get(), resource_provider.get());
952 EXPECT_TRUE(renderer.Initialize()); 990 EXPECT_TRUE(renderer.Initialize());
953 991
954 gfx::Rect viewport_rect(mock_client.DeviceViewport()); 992 gfx::Rect viewport_rect(renderer_client.DeviceViewport());
955 ScopedPtrVector<RenderPass>& render_passes = 993 ScopedPtrVector<RenderPass>& render_passes =
956 *mock_client.render_passes_in_draw_order(); 994 *renderer_client.render_passes_in_draw_order();
957 render_passes.clear(); 995 render_passes.clear();
958 996
959 RenderPass::Id root_pass_id(1, 0); 997 RenderPass::Id root_pass_id(1, 0);
960 TestRenderPass* root_pass = AddRenderPass( 998 TestRenderPass* root_pass = AddRenderPass(
961 &render_passes, root_pass_id, viewport_rect, gfx::Transform()); 999 &render_passes, root_pass_id, viewport_rect, gfx::Transform());
962 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); 1000 AddQuad(root_pass, viewport_rect, SK_ColorGREEN);
963 1001
964 RenderPass::Id child_pass_id(2, 0); 1002 RenderPass::Id child_pass_id(2, 0);
965 TestRenderPass* child_pass = AddRenderPass( 1003 TestRenderPass* child_pass = AddRenderPass(
966 &render_passes, child_pass_id, viewport_rect, gfx::Transform()); 1004 &render_passes, child_pass_id, viewport_rect, gfx::Transform());
(...skipping 14 matching lines...) Expand all
981 EXPECT_CALL(*mock_context, drawElements(_, _, _, _)).Times(1); 1019 EXPECT_CALL(*mock_context, drawElements(_, _, _, _)).Times(1);
982 1020
983 // The second render pass is the root one, clearing should be prevented. 1021 // The second render pass is the root one, clearing should be prevented.
984 EXPECT_CALL(*mock_context, clear(clear_bits)).Times(0) 1022 EXPECT_CALL(*mock_context, clear(clear_bits)).Times(0)
985 .After(first_render_pass); 1023 .After(first_render_pass);
986 1024
987 EXPECT_CALL(*mock_context, drawElements(_, _, _, _)).Times(AnyNumber()) 1025 EXPECT_CALL(*mock_context, drawElements(_, _, _, _)).Times(AnyNumber())
988 .After(first_render_pass); 1026 .After(first_render_pass);
989 1027
990 renderer.DecideRenderPassAllocationsForFrame( 1028 renderer.DecideRenderPassAllocationsForFrame(
991 *mock_client.render_passes_in_draw_order()); 1029 *renderer_client.render_passes_in_draw_order());
992 renderer.DrawFrame(mock_client.render_passes_in_draw_order()); 1030 renderer.DrawFrame(renderer_client.render_passes_in_draw_order());
993 1031
994 // In multiple render passes all but the root pass should clear the 1032 // In multiple render passes all but the root pass should clear the
995 // framebuffer. 1033 // framebuffer.
996 Mock::VerifyAndClearExpectations(&mock_context); 1034 Mock::VerifyAndClearExpectations(&mock_context);
997 } 1035 }
998 1036
999 class ScissorTestOnClearCheckingContext : public TestWebGraphicsContext3D { 1037 class ScissorTestOnClearCheckingContext : public TestWebGraphicsContext3D {
1000 public: 1038 public:
1001 ScissorTestOnClearCheckingContext() : scissor_enabled_(false) {} 1039 ScissorTestOnClearCheckingContext() : scissor_enabled_(false) {}
1002 1040
1003 virtual void clear(WGC3Dbitfield) { EXPECT_FALSE(scissor_enabled_); } 1041 virtual void clear(WGC3Dbitfield) { EXPECT_FALSE(scissor_enabled_); }
1004 1042
1005 virtual void enable(WGC3Denum cap) { 1043 virtual void enable(WGC3Denum cap) {
1006 if (cap == GL_SCISSOR_TEST) 1044 if (cap == GL_SCISSOR_TEST)
1007 scissor_enabled_ = true; 1045 scissor_enabled_ = true;
1008 } 1046 }
1009 1047
1010 virtual void disable(WGC3Denum cap) { 1048 virtual void disable(WGC3Denum cap) {
1011 if (cap == GL_SCISSOR_TEST) 1049 if (cap == GL_SCISSOR_TEST)
1012 scissor_enabled_ = false; 1050 scissor_enabled_ = false;
1013 } 1051 }
1014 1052
1015 private: 1053 private:
1016 bool scissor_enabled_; 1054 bool scissor_enabled_;
1017 }; 1055 };
1018 1056
1019 TEST(GLRendererTest2, ScissorTestWhenClearing) { 1057 TEST(GLRendererTest2, ScissorTestWhenClearing) {
1020 FakeRendererClient mock_client; 1058 scoped_ptr<ScissorTestOnClearCheckingContext> context_owned(
1021 scoped_ptr<OutputSurface> output_surface( 1059 new ScissorTestOnClearCheckingContext);
1022 FakeOutputSurface::Create3d(scoped_ptr<WebKit::WebGraphicsContext3D>( 1060
1023 new ScissorTestOnClearCheckingContext))); 1061 FakeOutputSurfaceClient output_surface_client;
1062 scoped_ptr<OutputSurface> output_surface(FakeOutputSurface::Create3d(
1063 context_owned.PassAs<TestWebGraphicsContext3D>()));
1064 CHECK(output_surface->BindToClient(&output_surface_client));
1065
1024 scoped_ptr<ResourceProvider> resource_provider( 1066 scoped_ptr<ResourceProvider> resource_provider(
1025 ResourceProvider::Create(output_surface.get(), 0)); 1067 ResourceProvider::Create(output_surface.get(), 0));
1068
1069 FakeRendererClient renderer_client;
1026 FakeRendererGL renderer( 1070 FakeRendererGL renderer(
1027 &mock_client, output_surface.get(), resource_provider.get()); 1071 &renderer_client, output_surface.get(), resource_provider.get());
1028 EXPECT_TRUE(renderer.Initialize()); 1072 EXPECT_TRUE(renderer.Initialize());
1029 EXPECT_FALSE(renderer.Capabilities().using_partial_swap); 1073 EXPECT_FALSE(renderer.Capabilities().using_partial_swap);
1030 1074
1031 gfx::Rect viewport_rect(mock_client.DeviceViewport()); 1075 gfx::Rect viewport_rect(renderer_client.DeviceViewport());
1032 ScopedPtrVector<RenderPass>& render_passes = 1076 ScopedPtrVector<RenderPass>& render_passes =
1033 *mock_client.render_passes_in_draw_order(); 1077 *renderer_client.render_passes_in_draw_order();
1034 render_passes.clear(); 1078 render_passes.clear();
1035 1079
1036 gfx::Rect grand_child_rect(25, 25); 1080 gfx::Rect grand_child_rect(25, 25);
1037 RenderPass::Id grand_child_pass_id(3, 0); 1081 RenderPass::Id grand_child_pass_id(3, 0);
1038 TestRenderPass* grand_child_pass = AddRenderPass( 1082 TestRenderPass* grand_child_pass = AddRenderPass(
1039 &render_passes, grand_child_pass_id, grand_child_rect, gfx::Transform()); 1083 &render_passes, grand_child_pass_id, grand_child_rect, gfx::Transform());
1040 AddClippedQuad(grand_child_pass, grand_child_rect, SK_ColorYELLOW); 1084 AddClippedQuad(grand_child_pass, grand_child_rect, SK_ColorYELLOW);
1041 1085
1042 gfx::Rect child_rect(50, 50); 1086 gfx::Rect child_rect(50, 50);
1043 RenderPass::Id child_pass_id(2, 0); 1087 RenderPass::Id child_pass_id(2, 0);
1044 TestRenderPass* child_pass = AddRenderPass( 1088 TestRenderPass* child_pass = AddRenderPass(
1045 &render_passes, child_pass_id, child_rect, gfx::Transform()); 1089 &render_passes, child_pass_id, child_rect, gfx::Transform());
1046 AddQuad(child_pass, child_rect, SK_ColorBLUE); 1090 AddQuad(child_pass, child_rect, SK_ColorBLUE);
1047 1091
1048 RenderPass::Id root_pass_id(1, 0); 1092 RenderPass::Id root_pass_id(1, 0);
1049 TestRenderPass* root_pass = AddRenderPass( 1093 TestRenderPass* root_pass = AddRenderPass(
1050 &render_passes, root_pass_id, viewport_rect, gfx::Transform()); 1094 &render_passes, root_pass_id, viewport_rect, gfx::Transform());
1051 AddQuad(root_pass, viewport_rect, SK_ColorGREEN); 1095 AddQuad(root_pass, viewport_rect, SK_ColorGREEN);
1052 1096
1053 AddRenderPassQuad(root_pass, child_pass); 1097 AddRenderPassQuad(root_pass, child_pass);
1054 AddRenderPassQuad(child_pass, grand_child_pass); 1098 AddRenderPassQuad(child_pass, grand_child_pass);
1055 1099
1056 renderer.DecideRenderPassAllocationsForFrame( 1100 renderer.DecideRenderPassAllocationsForFrame(
1057 *mock_client.render_passes_in_draw_order()); 1101 *renderer_client.render_passes_in_draw_order());
1058 renderer.DrawFrame(mock_client.render_passes_in_draw_order()); 1102 renderer.DrawFrame(renderer_client.render_passes_in_draw_order());
1059 } 1103 }
1060 1104
1061 class NonReshapableOutputSurface : public FakeOutputSurface { 1105 class NonReshapableOutputSurface : public FakeOutputSurface {
1062 public: 1106 public:
1063 explicit NonReshapableOutputSurface( 1107 explicit NonReshapableOutputSurface(
1064 scoped_ptr<WebKit::WebGraphicsContext3D> context3d) 1108 scoped_ptr<TestWebGraphicsContext3D> context3d)
1065 : FakeOutputSurface(context3d.Pass(), false) {} 1109 : FakeOutputSurface(
1110 TestContextProvider::Create(context3d.Pass()),
1111 false) {}
1066 virtual gfx::Size SurfaceSize() const OVERRIDE { return gfx::Size(500, 500); } 1112 virtual gfx::Size SurfaceSize() const OVERRIDE { return gfx::Size(500, 500); }
1067 }; 1113 };
1068 1114
1069 class OffsetViewportRendererClient : public FakeRendererClient { 1115 class OffsetViewportRendererClient : public FakeRendererClient {
1070 public: 1116 public:
1071 virtual gfx::Rect DeviceViewport() const OVERRIDE { 1117 virtual gfx::Rect DeviceViewport() const OVERRIDE {
1072 return gfx::Rect(10, 10, 100, 100); 1118 return gfx::Rect(10, 10, 100, 100);
1073 } 1119 }
1074 }; 1120 };
1075 1121
(...skipping 25 matching lines...) Expand all
1101 private: 1147 private:
1102 bool did_call_viewport_; 1148 bool did_call_viewport_;
1103 bool did_call_scissor_; 1149 bool did_call_scissor_;
1104 }; 1150 };
1105 1151
1106 TEST(GLRendererTest2, ScissorAndViewportWithinNonreshapableSurface) { 1152 TEST(GLRendererTest2, ScissorAndViewportWithinNonreshapableSurface) {
1107 // In Android WebView, the OutputSurface is unable to respect reshape() calls 1153 // In Android WebView, the OutputSurface is unable to respect reshape() calls
1108 // and maintains a fixed size. This test verifies that glViewport and 1154 // and maintains a fixed size. This test verifies that glViewport and
1109 // glScissor's Y coordinate is flipped correctly in this environment, and that 1155 // glScissor's Y coordinate is flipped correctly in this environment, and that
1110 // the glViewport can be at a nonzero origin within the surface. 1156 // the glViewport can be at a nonzero origin within the surface.
1111 OffsetViewportRendererClient mock_client; 1157 scoped_ptr<FlippedScissorAndViewportContext> context_owned(
1112 scoped_ptr<OutputSurface> output_surface(make_scoped_ptr( 1158 new FlippedScissorAndViewportContext);
1113 new NonReshapableOutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>( 1159
1114 new FlippedScissorAndViewportContext)))); 1160 FakeOutputSurfaceClient output_surface_client;
1161 scoped_ptr<OutputSurface> output_surface(new NonReshapableOutputSurface(
1162 context_owned.PassAs<TestWebGraphicsContext3D>()));
1163 CHECK(output_surface->BindToClient(&output_surface_client));
1164
1115 scoped_ptr<ResourceProvider> resource_provider( 1165 scoped_ptr<ResourceProvider> resource_provider(
1116 ResourceProvider::Create(output_surface.get(), 0)); 1166 ResourceProvider::Create(output_surface.get(), 0));
1167
1168 OffsetViewportRendererClient renderer_client;
1117 FakeRendererGL renderer( 1169 FakeRendererGL renderer(
1118 &mock_client, output_surface.get(), resource_provider.get()); 1170 &renderer_client, output_surface.get(), resource_provider.get());
1119 EXPECT_TRUE(renderer.Initialize()); 1171 EXPECT_TRUE(renderer.Initialize());
1120 EXPECT_FALSE(renderer.Capabilities().using_partial_swap); 1172 EXPECT_FALSE(renderer.Capabilities().using_partial_swap);
1121 1173
1122 gfx::Rect viewport_rect(mock_client.DeviceViewport().size()); 1174 gfx::Rect viewport_rect(renderer_client.DeviceViewport().size());
1123 gfx::Rect quad_rect = gfx::Rect(20, 20, 20, 20); 1175 gfx::Rect quad_rect = gfx::Rect(20, 20, 20, 20);
1124 ScopedPtrVector<RenderPass>& render_passes = 1176 ScopedPtrVector<RenderPass>& render_passes =
1125 *mock_client.render_passes_in_draw_order(); 1177 *renderer_client.render_passes_in_draw_order();
1126 render_passes.clear(); 1178 render_passes.clear();
1127 1179
1128 RenderPass::Id root_pass_id(1, 0); 1180 RenderPass::Id root_pass_id(1, 0);
1129 TestRenderPass* root_pass = AddRenderPass( 1181 TestRenderPass* root_pass = AddRenderPass(
1130 &render_passes, root_pass_id, viewport_rect, gfx::Transform()); 1182 &render_passes, root_pass_id, viewport_rect, gfx::Transform());
1131 AddClippedQuad(root_pass, quad_rect, SK_ColorGREEN); 1183 AddClippedQuad(root_pass, quad_rect, SK_ColorGREEN);
1132 1184
1133 renderer.DecideRenderPassAllocationsForFrame( 1185 renderer.DecideRenderPassAllocationsForFrame(
1134 *mock_client.render_passes_in_draw_order()); 1186 *renderer_client.render_passes_in_draw_order());
1135 renderer.DrawFrame(mock_client.render_passes_in_draw_order()); 1187 renderer.DrawFrame(renderer_client.render_passes_in_draw_order());
1136 } 1188 }
1137 1189
1138 TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) { 1190 TEST_F(GLRendererShaderTest, DrawRenderPassQuadShaderPermutations) {
1139 gfx::Rect viewport_rect(mock_client_.DeviceViewport()); 1191 gfx::Rect viewport_rect(renderer_client_.DeviceViewport());
1140 ScopedPtrVector<RenderPass>* render_passes = 1192 ScopedPtrVector<RenderPass>* render_passes =
1141 mock_client_.render_passes_in_draw_order(); 1193 renderer_client_.render_passes_in_draw_order();
1142 1194
1143 gfx::Rect child_rect(50, 50); 1195 gfx::Rect child_rect(50, 50);
1144 RenderPass::Id child_pass_id(2, 0); 1196 RenderPass::Id child_pass_id(2, 0);
1145 TestRenderPass* child_pass; 1197 TestRenderPass* child_pass;
1146 1198
1147 RenderPass::Id root_pass_id(1, 0); 1199 RenderPass::Id root_pass_id(1, 0);
1148 TestRenderPass* root_pass; 1200 TestRenderPass* root_pass;
1149 1201
1150 cc::ResourceProvider::ResourceId mask = 1202 cc::ResourceProvider::ResourceId mask =
1151 resource_provider_->CreateResource(gfx::Size(20, 12), 1203 resource_provider_->CreateResource(gfx::Size(20, 12),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
1186 root_pass = AddRenderPass( 1238 root_pass = AddRenderPass(
1187 render_passes, root_pass_id, viewport_rect, gfx::Transform()); 1239 render_passes, root_pass_id, viewport_rect, gfx::Transform());
1188 1240
1189 AddRenderPassQuad(root_pass, 1241 AddRenderPassQuad(root_pass,
1190 child_pass, 1242 child_pass,
1191 0, 1243 0,
1192 skia::RefPtr<SkImageFilter>(), 1244 skia::RefPtr<SkImageFilter>(),
1193 gfx::Transform()); 1245 gfx::Transform());
1194 1246
1195 renderer_->DecideRenderPassAllocationsForFrame( 1247 renderer_->DecideRenderPassAllocationsForFrame(
1196 *mock_client_.render_passes_in_draw_order()); 1248 *renderer_client_.render_passes_in_draw_order());
1197 renderer_->DrawFrame(mock_client_.render_passes_in_draw_order()); 1249 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
1198 TestRenderPassProgram(); 1250 TestRenderPassProgram();
1199 1251
1200 // RenderPassColorMatrixProgram 1252 // RenderPassColorMatrixProgram
1201 render_passes->clear(); 1253 render_passes->clear();
1202 1254
1203 child_pass = AddRenderPass( 1255 child_pass = AddRenderPass(
1204 render_passes, child_pass_id, child_rect, transform_causing_aa); 1256 render_passes, child_pass_id, child_rect, transform_causing_aa);
1205 1257
1206 root_pass = AddRenderPass( 1258 root_pass = AddRenderPass(
1207 render_passes, root_pass_id, viewport_rect, gfx::Transform()); 1259 render_passes, root_pass_id, viewport_rect, gfx::Transform());
1208 1260
1209 AddRenderPassQuad(root_pass, child_pass, 0, filter, gfx::Transform()); 1261 AddRenderPassQuad(root_pass, child_pass, 0, filter, gfx::Transform());
1210 1262
1211 renderer_->DecideRenderPassAllocationsForFrame( 1263 renderer_->DecideRenderPassAllocationsForFrame(
1212 *mock_client_.render_passes_in_draw_order()); 1264 *renderer_client_.render_passes_in_draw_order());
1213 renderer_->DrawFrame(mock_client_.render_passes_in_draw_order()); 1265 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
1214 TestRenderPassColorMatrixProgram(); 1266 TestRenderPassColorMatrixProgram();
1215 1267
1216 // RenderPassMaskProgram 1268 // RenderPassMaskProgram
1217 render_passes->clear(); 1269 render_passes->clear();
1218 1270
1219 child_pass = AddRenderPass( 1271 child_pass = AddRenderPass(
1220 render_passes, child_pass_id, child_rect, gfx::Transform()); 1272 render_passes, child_pass_id, child_rect, gfx::Transform());
1221 1273
1222 root_pass = AddRenderPass( 1274 root_pass = AddRenderPass(
1223 render_passes, root_pass_id, viewport_rect, gfx::Transform()); 1275 render_passes, root_pass_id, viewport_rect, gfx::Transform());
1224 1276
1225 AddRenderPassQuad(root_pass, 1277 AddRenderPassQuad(root_pass,
1226 child_pass, 1278 child_pass,
1227 mask, 1279 mask,
1228 skia::RefPtr<SkImageFilter>(), 1280 skia::RefPtr<SkImageFilter>(),
1229 gfx::Transform()); 1281 gfx::Transform());
1230 1282
1231 renderer_->DecideRenderPassAllocationsForFrame( 1283 renderer_->DecideRenderPassAllocationsForFrame(
1232 *mock_client_.render_passes_in_draw_order()); 1284 *renderer_client_.render_passes_in_draw_order());
1233 renderer_->DrawFrame(mock_client_.render_passes_in_draw_order()); 1285 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
1234 TestRenderPassMaskProgram(); 1286 TestRenderPassMaskProgram();
1235 1287
1236 // RenderPassMaskColorMatrixProgram 1288 // RenderPassMaskColorMatrixProgram
1237 render_passes->clear(); 1289 render_passes->clear();
1238 1290
1239 child_pass = AddRenderPass( 1291 child_pass = AddRenderPass(
1240 render_passes, child_pass_id, child_rect, gfx::Transform()); 1292 render_passes, child_pass_id, child_rect, gfx::Transform());
1241 1293
1242 root_pass = AddRenderPass( 1294 root_pass = AddRenderPass(
1243 render_passes, root_pass_id, viewport_rect, gfx::Transform()); 1295 render_passes, root_pass_id, viewport_rect, gfx::Transform());
1244 1296
1245 AddRenderPassQuad(root_pass, child_pass, mask, filter, gfx::Transform()); 1297 AddRenderPassQuad(root_pass, child_pass, mask, filter, gfx::Transform());
1246 1298
1247 renderer_->DecideRenderPassAllocationsForFrame( 1299 renderer_->DecideRenderPassAllocationsForFrame(
1248 *mock_client_.render_passes_in_draw_order()); 1300 *renderer_client_.render_passes_in_draw_order());
1249 renderer_->DrawFrame(mock_client_.render_passes_in_draw_order()); 1301 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
1250 TestRenderPassMaskColorMatrixProgram(); 1302 TestRenderPassMaskColorMatrixProgram();
1251 1303
1252 // RenderPassProgramAA 1304 // RenderPassProgramAA
1253 render_passes->clear(); 1305 render_passes->clear();
1254 1306
1255 child_pass = AddRenderPass( 1307 child_pass = AddRenderPass(
1256 render_passes, child_pass_id, child_rect, transform_causing_aa); 1308 render_passes, child_pass_id, child_rect, transform_causing_aa);
1257 1309
1258 root_pass = AddRenderPass( 1310 root_pass = AddRenderPass(
1259 render_passes, root_pass_id, viewport_rect, gfx::Transform()); 1311 render_passes, root_pass_id, viewport_rect, gfx::Transform());
1260 1312
1261 AddRenderPassQuad(root_pass, 1313 AddRenderPassQuad(root_pass,
1262 child_pass, 1314 child_pass,
1263 0, 1315 0,
1264 skia::RefPtr<SkImageFilter>(), 1316 skia::RefPtr<SkImageFilter>(),
1265 transform_causing_aa); 1317 transform_causing_aa);
1266 1318
1267 renderer_->DecideRenderPassAllocationsForFrame( 1319 renderer_->DecideRenderPassAllocationsForFrame(
1268 *mock_client_.render_passes_in_draw_order()); 1320 *renderer_client_.render_passes_in_draw_order());
1269 renderer_->DrawFrame(mock_client_.render_passes_in_draw_order()); 1321 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
1270 TestRenderPassProgramAA(); 1322 TestRenderPassProgramAA();
1271 1323
1272 // RenderPassColorMatrixProgramAA 1324 // RenderPassColorMatrixProgramAA
1273 render_passes->clear(); 1325 render_passes->clear();
1274 1326
1275 child_pass = AddRenderPass( 1327 child_pass = AddRenderPass(
1276 render_passes, child_pass_id, child_rect, transform_causing_aa); 1328 render_passes, child_pass_id, child_rect, transform_causing_aa);
1277 1329
1278 root_pass = AddRenderPass( 1330 root_pass = AddRenderPass(
1279 render_passes, root_pass_id, viewport_rect, gfx::Transform()); 1331 render_passes, root_pass_id, viewport_rect, gfx::Transform());
1280 1332
1281 AddRenderPassQuad(root_pass, child_pass, 0, filter, transform_causing_aa); 1333 AddRenderPassQuad(root_pass, child_pass, 0, filter, transform_causing_aa);
1282 1334
1283 renderer_->DecideRenderPassAllocationsForFrame( 1335 renderer_->DecideRenderPassAllocationsForFrame(
1284 *mock_client_.render_passes_in_draw_order()); 1336 *renderer_client_.render_passes_in_draw_order());
1285 renderer_->DrawFrame(mock_client_.render_passes_in_draw_order()); 1337 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
1286 TestRenderPassColorMatrixProgramAA(); 1338 TestRenderPassColorMatrixProgramAA();
1287 1339
1288 // RenderPassMaskProgramAA 1340 // RenderPassMaskProgramAA
1289 render_passes->clear(); 1341 render_passes->clear();
1290 1342
1291 child_pass = AddRenderPass(render_passes, child_pass_id, child_rect, 1343 child_pass = AddRenderPass(render_passes, child_pass_id, child_rect,
1292 transform_causing_aa); 1344 transform_causing_aa);
1293 1345
1294 root_pass = AddRenderPass(render_passes, root_pass_id, viewport_rect, 1346 root_pass = AddRenderPass(render_passes, root_pass_id, viewport_rect,
1295 gfx::Transform()); 1347 gfx::Transform());
1296 1348
1297 AddRenderPassQuad(root_pass, child_pass, mask, skia::RefPtr<SkImageFilter>(), 1349 AddRenderPassQuad(root_pass, child_pass, mask, skia::RefPtr<SkImageFilter>(),
1298 transform_causing_aa); 1350 transform_causing_aa);
1299 1351
1300 renderer_->DecideRenderPassAllocationsForFrame( 1352 renderer_->DecideRenderPassAllocationsForFrame(
1301 *mock_client_.render_passes_in_draw_order()); 1353 *renderer_client_.render_passes_in_draw_order());
1302 renderer_->DrawFrame(mock_client_.render_passes_in_draw_order()); 1354 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
1303 TestRenderPassMaskProgramAA(); 1355 TestRenderPassMaskProgramAA();
1304 1356
1305 // RenderPassMaskColorMatrixProgramAA 1357 // RenderPassMaskColorMatrixProgramAA
1306 render_passes->clear(); 1358 render_passes->clear();
1307 1359
1308 child_pass = AddRenderPass(render_passes, child_pass_id, child_rect, 1360 child_pass = AddRenderPass(render_passes, child_pass_id, child_rect,
1309 transform_causing_aa); 1361 transform_causing_aa);
1310 1362
1311 root_pass = AddRenderPass(render_passes, root_pass_id, viewport_rect, 1363 root_pass = AddRenderPass(render_passes, root_pass_id, viewport_rect,
1312 transform_causing_aa); 1364 transform_causing_aa);
1313 1365
1314 AddRenderPassQuad(root_pass, child_pass, mask, filter, transform_causing_aa); 1366 AddRenderPassQuad(root_pass, child_pass, mask, filter, transform_causing_aa);
1315 1367
1316 renderer_->DecideRenderPassAllocationsForFrame( 1368 renderer_->DecideRenderPassAllocationsForFrame(
1317 *mock_client_.render_passes_in_draw_order()); 1369 *renderer_client_.render_passes_in_draw_order());
1318 renderer_->DrawFrame(mock_client_.render_passes_in_draw_order()); 1370 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
1319 TestRenderPassMaskColorMatrixProgramAA(); 1371 TestRenderPassMaskColorMatrixProgramAA();
1320 } 1372 }
1321 1373
1322 // At this time, the AA code path cannot be taken if the surface's rect would 1374 // At this time, the AA code path cannot be taken if the surface's rect would
1323 // project incorrectly by the given transform, because of w<0 clipping. 1375 // project incorrectly by the given transform, because of w<0 clipping.
1324 TEST_F(GLRendererShaderTest, DrawRenderPassQuadSkipsAAForClippingTransform) { 1376 TEST_F(GLRendererShaderTest, DrawRenderPassQuadSkipsAAForClippingTransform) {
1325 gfx::Rect child_rect(50, 50); 1377 gfx::Rect child_rect(50, 50);
1326 RenderPass::Id child_pass_id(2, 0); 1378 RenderPass::Id child_pass_id(2, 0);
1327 TestRenderPass* child_pass; 1379 TestRenderPass* child_pass;
1328 1380
1329 gfx::Rect viewport_rect(mock_client_.DeviceViewport()); 1381 gfx::Rect viewport_rect(renderer_client_.DeviceViewport());
1330 RenderPass::Id root_pass_id(1, 0); 1382 RenderPass::Id root_pass_id(1, 0);
1331 TestRenderPass* root_pass; 1383 TestRenderPass* root_pass;
1332 1384
1333 gfx::Transform transform_preventing_aa; 1385 gfx::Transform transform_preventing_aa;
1334 transform_preventing_aa.ApplyPerspectiveDepth(40.0); 1386 transform_preventing_aa.ApplyPerspectiveDepth(40.0);
1335 transform_preventing_aa.RotateAboutYAxis(-20.0); 1387 transform_preventing_aa.RotateAboutYAxis(-20.0);
1336 transform_preventing_aa.Scale(30.0, 1.0); 1388 transform_preventing_aa.Scale(30.0, 1.0);
1337 1389
1338 // Verify that the test transform and test rect actually do cause the clipped 1390 // Verify that the test transform and test rect actually do cause the clipped
1339 // flag to trigger. Otherwise we are not testing the intended scenario. 1391 // flag to trigger. Otherwise we are not testing the intended scenario.
1340 bool clipped = false; 1392 bool clipped = false;
1341 MathUtil::MapQuad(transform_preventing_aa, 1393 MathUtil::MapQuad(transform_preventing_aa,
1342 gfx::QuadF(child_rect), 1394 gfx::QuadF(child_rect),
1343 &clipped); 1395 &clipped);
1344 ASSERT_TRUE(clipped); 1396 ASSERT_TRUE(clipped);
1345 1397
1346 // Set up the render pass quad to be drawn 1398 // Set up the render pass quad to be drawn
1347 ScopedPtrVector<RenderPass>* render_passes = 1399 ScopedPtrVector<RenderPass>* render_passes =
1348 mock_client_.render_passes_in_draw_order(); 1400 renderer_client_.render_passes_in_draw_order();
1349 1401
1350 render_passes->clear(); 1402 render_passes->clear();
1351 1403
1352 child_pass = AddRenderPass( 1404 child_pass = AddRenderPass(
1353 render_passes, child_pass_id, child_rect, transform_preventing_aa); 1405 render_passes, child_pass_id, child_rect, transform_preventing_aa);
1354 1406
1355 root_pass = AddRenderPass( 1407 root_pass = AddRenderPass(
1356 render_passes, root_pass_id, viewport_rect, gfx::Transform()); 1408 render_passes, root_pass_id, viewport_rect, gfx::Transform());
1357 1409
1358 AddRenderPassQuad(root_pass, 1410 AddRenderPassQuad(root_pass,
1359 child_pass, 1411 child_pass,
1360 0, 1412 0,
1361 skia::RefPtr<SkImageFilter>(), 1413 skia::RefPtr<SkImageFilter>(),
1362 transform_preventing_aa); 1414 transform_preventing_aa);
1363 1415
1364 renderer_->DecideRenderPassAllocationsForFrame( 1416 renderer_->DecideRenderPassAllocationsForFrame(
1365 *mock_client_.render_passes_in_draw_order()); 1417 *renderer_client_.render_passes_in_draw_order());
1366 renderer_->DrawFrame(mock_client_.render_passes_in_draw_order()); 1418 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
1367 1419
1368 // If use_aa incorrectly ignores clipping, it will use the 1420 // If use_aa incorrectly ignores clipping, it will use the
1369 // RenderPassProgramAA shader instead of the RenderPassProgram. 1421 // RenderPassProgramAA shader instead of the RenderPassProgram.
1370 TestRenderPassProgram(); 1422 TestRenderPassProgram();
1371 } 1423 }
1372 1424
1373 TEST_F(GLRendererShaderTest, DrawSolidColorShader) { 1425 TEST_F(GLRendererShaderTest, DrawSolidColorShader) {
1374 gfx::Rect viewport_rect(mock_client_.DeviceViewport()); 1426 gfx::Rect viewport_rect(renderer_client_.DeviceViewport());
1375 ScopedPtrVector<RenderPass>* render_passes = 1427 ScopedPtrVector<RenderPass>* render_passes =
1376 mock_client_.render_passes_in_draw_order(); 1428 renderer_client_.render_passes_in_draw_order();
1377 1429
1378 RenderPass::Id root_pass_id(1, 0); 1430 RenderPass::Id root_pass_id(1, 0);
1379 TestRenderPass* root_pass; 1431 TestRenderPass* root_pass;
1380 1432
1381 gfx::Transform pixel_aligned_transform_causing_aa; 1433 gfx::Transform pixel_aligned_transform_causing_aa;
1382 pixel_aligned_transform_causing_aa.Translate(25.5f, 25.5f); 1434 pixel_aligned_transform_causing_aa.Translate(25.5f, 25.5f);
1383 pixel_aligned_transform_causing_aa.Scale(0.5f, 0.5f); 1435 pixel_aligned_transform_causing_aa.Scale(0.5f, 0.5f);
1384 1436
1385 render_passes->clear(); 1437 render_passes->clear();
1386 1438
1387 root_pass = AddRenderPass( 1439 root_pass = AddRenderPass(
1388 render_passes, root_pass_id, viewport_rect, gfx::Transform()); 1440 render_passes, root_pass_id, viewport_rect, gfx::Transform());
1389 AddTransformedQuad(root_pass, 1441 AddTransformedQuad(root_pass,
1390 viewport_rect, 1442 viewport_rect,
1391 SK_ColorYELLOW, 1443 SK_ColorYELLOW,
1392 pixel_aligned_transform_causing_aa); 1444 pixel_aligned_transform_causing_aa);
1393 1445
1394 renderer_->DecideRenderPassAllocationsForFrame( 1446 renderer_->DecideRenderPassAllocationsForFrame(
1395 *mock_client_.render_passes_in_draw_order()); 1447 *renderer_client_.render_passes_in_draw_order());
1396 renderer_->DrawFrame(mock_client_.render_passes_in_draw_order()); 1448 renderer_->DrawFrame(renderer_client_.render_passes_in_draw_order());
1397 1449
1398 TestSolidColorProgramAA(); 1450 TestSolidColorProgramAA();
1399 } 1451 }
1400 1452
1401 class OutputSurfaceMockContext : public TestWebGraphicsContext3D { 1453 class OutputSurfaceMockContext : public TestWebGraphicsContext3D {
1402 public: 1454 public:
1403 // Specifically override methods even if they are unused (used in conjunction 1455 // Specifically override methods even if they are unused (used in conjunction
1404 // with StrictMock). We need to make sure that GLRenderer does not issue 1456 // with StrictMock). We need to make sure that GLRenderer does not issue
1405 // framebuffer-related GL calls directly. Instead these are supposed to go 1457 // framebuffer-related GL calls directly. Instead these are supposed to go
1406 // through the OutputSurface abstraction. 1458 // through the OutputSurface abstraction.
(...skipping 13 matching lines...) Expand all
1420 if (name == GL_EXTENSIONS) 1472 if (name == GL_EXTENSIONS)
1421 return WebString( 1473 return WebString(
1422 "GL_CHROMIUM_post_sub_buffer GL_CHROMIUM_discard_backbuffer"); 1474 "GL_CHROMIUM_post_sub_buffer GL_CHROMIUM_discard_backbuffer");
1423 return WebString(); 1475 return WebString();
1424 } 1476 }
1425 }; 1477 };
1426 1478
1427 class MockOutputSurface : public OutputSurface { 1479 class MockOutputSurface : public OutputSurface {
1428 public: 1480 public:
1429 MockOutputSurface() 1481 MockOutputSurface()
1430 : OutputSurface(scoped_ptr<WebKit::WebGraphicsContext3D>( 1482 : OutputSurface(TestContextProvider::Create(
1431 new StrictMock<OutputSurfaceMockContext>)) { 1483 scoped_ptr<TestWebGraphicsContext3D>(
1484 new StrictMock<OutputSurfaceMockContext>))) {
1432 surface_size_ = gfx::Size(100, 100); 1485 surface_size_ = gfx::Size(100, 100);
1433 } 1486 }
1434 virtual ~MockOutputSurface() {} 1487 virtual ~MockOutputSurface() {}
1435 1488
1436 MOCK_METHOD0(EnsureBackbuffer, void()); 1489 MOCK_METHOD0(EnsureBackbuffer, void());
1437 MOCK_METHOD0(DiscardBackbuffer, void()); 1490 MOCK_METHOD0(DiscardBackbuffer, void());
1438 MOCK_METHOD2(Reshape, void(gfx::Size size, float scale_factor)); 1491 MOCK_METHOD2(Reshape, void(gfx::Size size, float scale_factor));
1439 MOCK_METHOD0(BindFramebuffer, void()); 1492 MOCK_METHOD0(BindFramebuffer, void());
1440 MOCK_METHOD1(SwapBuffers, void(CompositorFrame* frame)); 1493 MOCK_METHOD1(SwapBuffers, void(CompositorFrame* frame));
1441 }; 1494 };
1442 1495
1443 class MockOutputSurfaceTest : public testing::Test, public FakeRendererClient { 1496 class MockOutputSurfaceTest : public testing::Test, public FakeRendererClient {
1444 protected: 1497 protected:
1445 MockOutputSurfaceTest() 1498 virtual void SetUp() {
1446 : resource_provider_(ResourceProvider::Create(&output_surface_, 0)), 1499 FakeOutputSurfaceClient output_surface_client_;
1447 renderer_(this, &output_surface_, resource_provider_.get()) {} 1500 CHECK(output_surface_.BindToClient(&output_surface_client_));
1448 1501
1449 virtual void SetUp() { EXPECT_TRUE(renderer_.Initialize()); } 1502 resource_provider_ = ResourceProvider::Create(&output_surface_, 0).Pass();
1450 1503
1451 void SwapBuffers() { renderer_.SwapBuffers(); } 1504 renderer_.reset(new FakeRendererGL(this,
1505 &output_surface_,
1506 resource_provider_.get()));
1507 EXPECT_TRUE(renderer_->Initialize());
1508 }
1509
1510 void SwapBuffers() { renderer_->SwapBuffers(); }
1452 1511
1453 void DrawFrame() { 1512 void DrawFrame() {
1454 gfx::Rect viewport_rect(DeviceViewport()); 1513 gfx::Rect viewport_rect(DeviceViewport());
1455 ScopedPtrVector<RenderPass>* render_passes = render_passes_in_draw_order(); 1514 ScopedPtrVector<RenderPass>* render_passes = render_passes_in_draw_order();
1456 render_passes->clear(); 1515 render_passes->clear();
1457 1516
1458 RenderPass::Id render_pass_id(1, 0); 1517 RenderPass::Id render_pass_id(1, 0);
1459 TestRenderPass* render_pass = AddRenderPass( 1518 TestRenderPass* render_pass = AddRenderPass(
1460 render_passes, render_pass_id, viewport_rect, gfx::Transform()); 1519 render_passes, render_pass_id, viewport_rect, gfx::Transform());
1461 AddQuad(render_pass, viewport_rect, SK_ColorGREEN); 1520 AddQuad(render_pass, viewport_rect, SK_ColorGREEN);
1462 1521
1463 EXPECT_CALL(output_surface_, EnsureBackbuffer()).WillRepeatedly(Return()); 1522 EXPECT_CALL(output_surface_, EnsureBackbuffer()).WillRepeatedly(Return());
1464 1523
1465 EXPECT_CALL(output_surface_, 1524 EXPECT_CALL(output_surface_,
1466 Reshape(DeviceViewport().size(), DeviceScaleFactor())).Times(1); 1525 Reshape(DeviceViewport().size(), DeviceScaleFactor())).Times(1);
1467 1526
1468 EXPECT_CALL(output_surface_, BindFramebuffer()).Times(1); 1527 EXPECT_CALL(output_surface_, BindFramebuffer()).Times(1);
1469 1528
1470 EXPECT_CALL(*Context(), drawElements(_, _, _, _)).Times(1); 1529 EXPECT_CALL(*Context(), drawElements(_, _, _, _)).Times(1);
1471 1530
1472 renderer_.DecideRenderPassAllocationsForFrame( 1531 renderer_->DecideRenderPassAllocationsForFrame(
1473 *render_passes_in_draw_order()); 1532 *render_passes_in_draw_order());
1474 renderer_.DrawFrame(render_passes_in_draw_order()); 1533 renderer_->DrawFrame(render_passes_in_draw_order());
1475 } 1534 }
1476 1535
1477 OutputSurfaceMockContext* Context() { 1536 OutputSurfaceMockContext* Context() {
1478 return static_cast<OutputSurfaceMockContext*>(output_surface_.context3d()); 1537 return static_cast<OutputSurfaceMockContext*>(
1538 output_surface_.context_provider()->Context3d());
1479 } 1539 }
1480 1540
1541 FakeOutputSurfaceClient output_surface_client_;
1481 StrictMock<MockOutputSurface> output_surface_; 1542 StrictMock<MockOutputSurface> output_surface_;
1482 scoped_ptr<ResourceProvider> resource_provider_; 1543 scoped_ptr<ResourceProvider> resource_provider_;
1483 FakeRendererGL renderer_; 1544 scoped_ptr<FakeRendererGL> renderer_;
1484 }; 1545 };
1485 1546
1486 TEST_F(MockOutputSurfaceTest, DrawFrameAndSwap) { 1547 TEST_F(MockOutputSurfaceTest, DrawFrameAndSwap) {
1487 DrawFrame(); 1548 DrawFrame();
1488 1549
1489 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); 1550 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
1490 renderer_.SwapBuffers(); 1551 renderer_->SwapBuffers();
1491 } 1552 }
1492 1553
1493 TEST_F(MockOutputSurfaceTest, DrawFrameAndResizeAndSwap) { 1554 TEST_F(MockOutputSurfaceTest, DrawFrameAndResizeAndSwap) {
1494 DrawFrame(); 1555 DrawFrame();
1495 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); 1556 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
1496 renderer_.SwapBuffers(); 1557 renderer_->SwapBuffers();
1497 1558
1498 set_viewport_and_scale(gfx::Size(2, 2), 2.f); 1559 set_viewport_and_scale(gfx::Size(2, 2), 2.f);
1499 renderer_.ViewportChanged(); 1560 renderer_->ViewportChanged();
1500 1561
1501 DrawFrame(); 1562 DrawFrame();
1502 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); 1563 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
1503 renderer_.SwapBuffers(); 1564 renderer_->SwapBuffers();
1504 1565
1505 DrawFrame(); 1566 DrawFrame();
1506 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); 1567 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
1507 renderer_.SwapBuffers(); 1568 renderer_->SwapBuffers();
1508 1569
1509 set_viewport_and_scale(gfx::Size(1, 1), 1.f); 1570 set_viewport_and_scale(gfx::Size(1, 1), 1.f);
1510 renderer_.ViewportChanged(); 1571 renderer_->ViewportChanged();
1511 1572
1512 DrawFrame(); 1573 DrawFrame();
1513 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1); 1574 EXPECT_CALL(output_surface_, SwapBuffers(_)).Times(1);
1514 renderer_.SwapBuffers(); 1575 renderer_->SwapBuffers();
1515 } 1576 }
1516 1577
1517 class GLRendererTestSyncPoint : public GLRendererPixelTest { 1578 class GLRendererTestSyncPoint : public GLRendererPixelTest {
1518 protected: 1579 protected:
1519 static void SyncPointCallback(int* callback_count) { 1580 static void SyncPointCallback(int* callback_count) {
1520 ++(*callback_count); 1581 ++(*callback_count);
1521 base::MessageLoop::current()->QuitWhenIdle(); 1582 base::MessageLoop::current()->QuitWhenIdle();
1522 } 1583 }
1523 1584
1524 static void OtherCallback(int* callback_count) { 1585 static void OtherCallback(int* callback_count) {
1525 ++(*callback_count); 1586 ++(*callback_count);
1526 base::MessageLoop::current()->QuitWhenIdle(); 1587 base::MessageLoop::current()->QuitWhenIdle();
1527 } 1588 }
1528 }; 1589 };
1529 1590
1530 #if !defined(OS_ANDROID) 1591 #if !defined(OS_ANDROID)
1531 TEST_F(GLRendererTestSyncPoint, SignalSyncPointOnLostContext) { 1592 TEST_F(GLRendererTestSyncPoint, SignalSyncPointOnLostContext) {
1532 int sync_point_callback_count = 0; 1593 int sync_point_callback_count = 0;
1533 int other_callback_count = 0; 1594 int other_callback_count = 0;
1534 unsigned sync_point = output_surface_->context3d()->insertSyncPoint(); 1595 unsigned sync_point =
1596 output_surface_->context_provider()->Context3d()->insertSyncPoint();
1535 1597
1536 output_surface_->context3d()->loseContextCHROMIUM( 1598 output_surface_->context_provider()->Context3d()->loseContextCHROMIUM(
1537 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB); 1599 GL_GUILTY_CONTEXT_RESET_ARB, GL_INNOCENT_CONTEXT_RESET_ARB);
1538 1600
1539 SyncPointHelper::SignalSyncPoint( 1601 SyncPointHelper::SignalSyncPoint(
1540 output_surface_->context3d(), 1602 output_surface_->context_provider()->Context3d(),
1541 sync_point, 1603 sync_point,
1542 base::Bind(&SyncPointCallback, &sync_point_callback_count)); 1604 base::Bind(&SyncPointCallback, &sync_point_callback_count));
1543 EXPECT_EQ(0, sync_point_callback_count); 1605 EXPECT_EQ(0, sync_point_callback_count);
1544 EXPECT_EQ(0, other_callback_count); 1606 EXPECT_EQ(0, other_callback_count);
1545 1607
1546 // Make the sync point happen. 1608 // Make the sync point happen.
1547 output_surface_->context3d()->finish(); 1609 output_surface_->context_provider()->Context3d()->finish();
1548 // Post a task after the sync point. 1610 // Post a task after the sync point.
1549 base::MessageLoop::current()->PostTask( 1611 base::MessageLoop::current()->PostTask(
1550 FROM_HERE, 1612 FROM_HERE,
1551 base::Bind(&OtherCallback, &other_callback_count)); 1613 base::Bind(&OtherCallback, &other_callback_count));
1552 1614
1553 base::MessageLoop::current()->Run(); 1615 base::MessageLoop::current()->Run();
1554 1616
1555 // The sync point shouldn't have happened since the context was lost. 1617 // The sync point shouldn't have happened since the context was lost.
1556 EXPECT_EQ(0, sync_point_callback_count); 1618 EXPECT_EQ(0, sync_point_callback_count);
1557 EXPECT_EQ(1, other_callback_count); 1619 EXPECT_EQ(1, other_callback_count);
1558 } 1620 }
1559 1621
1560 TEST_F(GLRendererTestSyncPoint, SignalSyncPoint) { 1622 TEST_F(GLRendererTestSyncPoint, SignalSyncPoint) {
1561 int sync_point_callback_count = 0; 1623 int sync_point_callback_count = 0;
1562 int other_callback_count = 0; 1624 int other_callback_count = 0;
1563 unsigned sync_point = output_surface_->context3d()->insertSyncPoint(); 1625 unsigned sync_point =
1626 output_surface_->context_provider()->Context3d()->insertSyncPoint();
1564 1627
1565 SyncPointHelper::SignalSyncPoint( 1628 SyncPointHelper::SignalSyncPoint(
1566 output_surface_->context3d(), 1629 output_surface_->context_provider()->Context3d(),
1567 sync_point, 1630 sync_point,
1568 base::Bind(&SyncPointCallback, &sync_point_callback_count)); 1631 base::Bind(&SyncPointCallback, &sync_point_callback_count));
1569 EXPECT_EQ(0, sync_point_callback_count); 1632 EXPECT_EQ(0, sync_point_callback_count);
1570 EXPECT_EQ(0, other_callback_count); 1633 EXPECT_EQ(0, other_callback_count);
1571 1634
1572 // Make the sync point happen. 1635 // Make the sync point happen.
1573 output_surface_->context3d()->finish(); 1636 output_surface_->context_provider()->Context3d()->finish();
1574 // Post a task after the sync point. 1637 // Post a task after the sync point.
1575 base::MessageLoop::current()->PostTask( 1638 base::MessageLoop::current()->PostTask(
1576 FROM_HERE, 1639 FROM_HERE,
1577 base::Bind(&OtherCallback, &other_callback_count)); 1640 base::Bind(&OtherCallback, &other_callback_count));
1578 1641
1579 base::MessageLoop::current()->Run(); 1642 base::MessageLoop::current()->Run();
1580 1643
1581 // The sync point should have happened. 1644 // The sync point should have happened.
1582 EXPECT_EQ(1, sync_point_callback_count); 1645 EXPECT_EQ(1, sync_point_callback_count);
1583 EXPECT_EQ(1, other_callback_count); 1646 EXPECT_EQ(1, other_callback_count);
1584 } 1647 }
1585 #endif // OS_ANDROID 1648 #endif // OS_ANDROID
1586 1649
1587 } // namespace 1650 } // namespace
1588 } // namespace cc 1651 } // namespace cc
OLDNEW
« no previous file with comments | « cc/output/gl_renderer.cc ('k') | cc/output/output_surface.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698