• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "cc/output/delegating_renderer.h"
6 #include "cc/output/gl_renderer.h"
7 #include "cc/output/output_surface.h"
8 #include "cc/test/fake_output_surface_client.h"
9 #include "cc/test/fake_renderer_client.h"
10 #include "cc/test/test_context_provider.h"
11 #include "cc/test/test_web_graphics_context_3d.h"
12 #include "testing/gmock/include/gmock/gmock.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 
15 namespace cc {
16 namespace {
17 
18 class MockContextProvider : public TestContextProvider {
19  public:
MockContextProvider(scoped_ptr<TestWebGraphicsContext3D> context)20   explicit MockContextProvider(scoped_ptr<TestWebGraphicsContext3D> context)
21       : TestContextProvider(context.Pass()) {}
22   MOCK_METHOD0(DeleteCachedResources, void());
23 
24  protected:
~MockContextProvider()25   ~MockContextProvider() {}
26 };
27 
28 template <class T>
29 scoped_ptr<Renderer> CreateRenderer(RendererClient* client,
30                                     const LayerTreeSettings* settings,
31                                     OutputSurface* output_surface,
32                                     ResourceProvider* resource_provider);
33 
34 template <>
CreateRenderer(RendererClient * client,const LayerTreeSettings * settings,OutputSurface * output_surface,ResourceProvider * resource_provider)35 scoped_ptr<Renderer> CreateRenderer<DelegatingRenderer>(
36     RendererClient* client,
37     const LayerTreeSettings* settings,
38     OutputSurface* output_surface,
39     ResourceProvider* resource_provider) {
40   return DelegatingRenderer::Create(
41              client, settings, output_surface, resource_provider)
42       .PassAs<Renderer>();
43 }
44 
45 template <>
CreateRenderer(RendererClient * client,const LayerTreeSettings * settings,OutputSurface * output_surface,ResourceProvider * resource_provider)46 scoped_ptr<Renderer> CreateRenderer<GLRenderer>(
47     RendererClient* client,
48     const LayerTreeSettings* settings,
49     OutputSurface* output_surface,
50     ResourceProvider* resource_provider) {
51   return GLRenderer::Create(
52              client, settings, output_surface, resource_provider, NULL, 0)
53       .PassAs<Renderer>();
54 }
55 
56 template <typename T>
57 class RendererTest : public ::testing::Test {
58  protected:
SetUp()59   virtual void SetUp() {
60     context_provider_ =
61         new MockContextProvider(TestWebGraphicsContext3D::Create());
62     output_surface_.reset(new OutputSurface(context_provider_));
63     output_surface_->BindToClient(&output_surface_client_);
64     resource_provider_ = ResourceProvider::Create(
65         output_surface_.get(), NULL, NULL, 0, false, 1, false);
66     renderer_ = CreateRenderer<T>(&renderer_client_,
67                                   &tree_settings_,
68                                   output_surface_.get(),
69                                   resource_provider_.get());
70   }
71 
72   FakeRendererClient renderer_client_;
73   LayerTreeSettings tree_settings_;
74   FakeOutputSurfaceClient output_surface_client_;
75   scoped_refptr<MockContextProvider> context_provider_;
76   scoped_ptr<OutputSurface> output_surface_;
77   scoped_ptr<ResourceProvider> resource_provider_;
78   scoped_ptr<Renderer> renderer_;
79 };
80 
81 typedef ::testing::Types<DelegatingRenderer, GLRenderer> RendererTypes;
82 TYPED_TEST_CASE(RendererTest, RendererTypes);
83 
TYPED_TEST(RendererTest,ContextPurgedWhenRendererBecomesInvisible)84 TYPED_TEST(RendererTest, ContextPurgedWhenRendererBecomesInvisible) {
85   EXPECT_CALL(*(this->context_provider_.get()), DeleteCachedResources())
86       .Times(1);
87 
88   EXPECT_TRUE(this->renderer_->visible());
89   this->renderer_->SetVisible(false);
90   EXPECT_FALSE(this->renderer_->visible());
91 }
92 
93 }  // namespace
94 }  // namespace cc
95