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 <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 | 10 |
(...skipping 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2074 TEST_F(GLRendererPartialSwapTest, PartialSwap) { | 2074 TEST_F(GLRendererPartialSwapTest, PartialSwap) { |
2075 RunTest(true); | 2075 RunTest(true); |
2076 } | 2076 } |
2077 | 2077 |
2078 TEST_F(GLRendererPartialSwapTest, NoPartialSwap) { | 2078 TEST_F(GLRendererPartialSwapTest, NoPartialSwap) { |
2079 RunTest(false); | 2079 RunTest(false); |
2080 } | 2080 } |
2081 | 2081 |
2082 class GLRendererWithMockContextTest : public ::testing::Test { | 2082 class GLRendererWithMockContextTest : public ::testing::Test { |
2083 protected: | 2083 protected: |
2084 class MockContextProvider : public TestContextProvider { | |
2085 public: | |
2086 explicit MockContextProvider(std::unique_ptr<TestContextSupport> support) | |
2087 : TestContextProvider(std::move(support), | |
2088 base::MakeUnique<TestGLES2Interface>(), | |
2089 TestWebGraphicsContext3D::Create()) {} | |
2090 | |
2091 MOCK_METHOD0(DeleteCachedResources, void()); | |
2092 | |
2093 private: | |
2094 ~MockContextProvider() = default; | |
2095 }; | |
2096 | |
2097 class MockContextSupport : public TestContextSupport { | 2084 class MockContextSupport : public TestContextSupport { |
2098 public: | 2085 public: |
2099 MockContextSupport() {} | 2086 MockContextSupport() {} |
2100 MOCK_METHOD1(SetAggressivelyFreeResources, | 2087 MOCK_METHOD1(SetAggressivelyFreeResources, |
2101 void(bool aggressively_free_resources)); | 2088 void(bool aggressively_free_resources)); |
2102 MOCK_METHOD2(SetClientVisible, void(int client_id, bool is_visible)); | |
2103 MOCK_CONST_METHOD0(AnyClientsVisible, bool()); | |
2104 }; | 2089 }; |
2105 | 2090 |
2106 void SetUp() override { | 2091 void SetUp() override { |
2107 auto context_support = base::MakeUnique<MockContextSupport>(); | 2092 auto context_support = base::MakeUnique<MockContextSupport>(); |
2108 context_support_ptr_ = context_support.get(); | 2093 context_support_ptr_ = context_support.get(); |
2109 context_provider_ = new MockContextProvider(std::move(context_support)); | 2094 auto context_provider = TestContextProvider::Create( |
2110 output_surface_ = FakeOutputSurface::Create3d(context_provider_); | 2095 TestWebGraphicsContext3D::Create(), std::move(context_support)); |
| 2096 output_surface_ = FakeOutputSurface::Create3d(std::move(context_provider)); |
2111 output_surface_->BindToClient(&output_surface_client_); | 2097 output_surface_->BindToClient(&output_surface_client_); |
2112 resource_provider_ = | 2098 resource_provider_ = |
2113 FakeResourceProvider::Create(output_surface_.get(), nullptr); | 2099 FakeResourceProvider::Create(output_surface_.get(), nullptr); |
2114 renderer_ = | 2100 renderer_ = |
2115 base::MakeUnique<GLRenderer>(&settings_, output_surface_.get(), | 2101 base::MakeUnique<GLRenderer>(&settings_, output_surface_.get(), |
2116 resource_provider_.get(), nullptr, 0); | 2102 resource_provider_.get(), nullptr, 0); |
2117 renderer_->Initialize(); | 2103 renderer_->Initialize(); |
2118 } | 2104 } |
2119 | 2105 |
2120 RendererSettings settings_; | 2106 RendererSettings settings_; |
2121 FakeOutputSurfaceClient output_surface_client_; | 2107 FakeOutputSurfaceClient output_surface_client_; |
2122 MockContextSupport* context_support_ptr_; | 2108 MockContextSupport* context_support_ptr_; |
2123 scoped_refptr<MockContextProvider> context_provider_; | |
2124 std::unique_ptr<OutputSurface> output_surface_; | 2109 std::unique_ptr<OutputSurface> output_surface_; |
2125 std::unique_ptr<ResourceProvider> resource_provider_; | 2110 std::unique_ptr<ResourceProvider> resource_provider_; |
2126 std::unique_ptr<GLRenderer> renderer_; | 2111 std::unique_ptr<GLRenderer> renderer_; |
2127 }; | 2112 }; |
2128 | 2113 |
2129 TEST_F(GLRendererWithMockContextTest, | 2114 TEST_F(GLRendererWithMockContextTest, |
2130 ContextPurgedWhenRendererBecomesInvisible) { | 2115 ContextPurgedWhenRendererBecomesInvisible) { |
2131 // Ensure our expectations run in order. | |
2132 ::testing::InSequence s; | |
2133 | |
2134 EXPECT_CALL(*context_support_ptr_, SetClientVisible(0, true)); | |
2135 EXPECT_CALL(*context_support_ptr_, AnyClientsVisible()) | |
2136 .WillOnce(Return(true)); | |
2137 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(false)); | 2116 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(false)); |
2138 renderer_->SetVisible(true); | 2117 renderer_->SetVisible(true); |
2139 Mock::VerifyAndClearExpectations(context_support_ptr_); | 2118 Mock::VerifyAndClearExpectations(context_support_ptr_); |
2140 | 2119 |
2141 EXPECT_CALL(*context_support_ptr_, SetClientVisible(0, false)); | |
2142 EXPECT_CALL(*context_support_ptr_, AnyClientsVisible()) | |
2143 .WillOnce(Return(false)); | |
2144 EXPECT_CALL(*context_provider_, DeleteCachedResources()); | |
2145 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true)); | 2120 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(true)); |
2146 renderer_->SetVisible(false); | 2121 renderer_->SetVisible(false); |
2147 Mock::VerifyAndClearExpectations(context_support_ptr_); | 2122 Mock::VerifyAndClearExpectations(context_support_ptr_); |
2148 } | 2123 } |
2149 | 2124 |
2150 } // namespace | 2125 } // namespace |
2151 } // namespace cc | 2126 } // namespace cc |
OLD | NEW |