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

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

Issue 2278283003: Refactor client visibility handling (Closed)
Patch Set: feedback Created 4 years, 3 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
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 <stdint.h> 7 #include <stdint.h>
8 8
9 #include <set> 9 #include <set>
10 10
(...skipping 2061 matching lines...) Expand 10 before | Expand all | Expand 10 after
2072 }; 2072 };
2073 2073
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 GLRendererWithMockContextCacheControllerTest : public ::testing::Test {
2083 protected: 2083 protected:
2084 class MockContextProvider : public TestContextProvider { 2084 class MockContextCacheController : public ContextCacheController {
2085 public: 2085 public:
2086 explicit MockContextProvider(std::unique_ptr<TestContextSupport> support) 2086 explicit MockContextCacheController(gpu::ContextSupport* support)
2087 : TestContextProvider(std::move(support), 2087 : ContextCacheController(support) {}
2088 base::MakeUnique<TestGLES2Interface>(), 2088 MOCK_METHOD0(OnClientBecameVisible, void());
2089 TestWebGraphicsContext3D::Create()) {} 2089 MOCK_METHOD0(OnClientBecameNotVisible, void());
2090 2090
2091 MOCK_METHOD0(DeleteCachedResources, void()); 2091 std::unique_ptr<ScopedVisibility> ClientBecameVisible() {
2092 if (num_visible_clients_ == 0)
2093 OnClientBecameVisible();
2094 ++num_visible_clients_;
2095 return CreateScopedVisibilityForTesting();
danakj 2016/08/29 23:56:20 this could just call ContextCacheController::OnCli
ericrk 2016/08/30 18:18:58 Made un-virtual, so no longer an issue.
2096 }
2097
2098 void ClientBecameNotVisible(
2099 std::unique_ptr<ScopedVisibility> scoped_visibility) {
2100 --num_visible_clients_;
2101 if (num_visible_clients_ == 0)
2102 OnClientBecameNotVisible();
2103 ReleaseScopedVisibilityForTesting(std::move(scoped_visibility));
2104 }
2092 2105
2093 private: 2106 private:
2094 ~MockContextProvider() = default; 2107 int num_visible_clients_ = 0;
2095 };
2096
2097 class MockContextSupport : public TestContextSupport {
2098 public:
2099 MockContextSupport() {}
2100 MOCK_METHOD1(SetAggressivelyFreeResources,
2101 void(bool aggressively_free_resources));
2102 MOCK_METHOD2(SetClientVisible, void(int client_id, bool is_visible));
2103 MOCK_CONST_METHOD0(AnyClientsVisible, bool());
2104 }; 2108 };
2105 2109
2106 void SetUp() override { 2110 void SetUp() override {
2107 auto context_support = base::MakeUnique<MockContextSupport>(); 2111 auto support = base::MakeUnique<TestContextSupport>();
2108 context_support_ptr_ = context_support.get(); 2112 auto context = TestWebGraphicsContext3D::Create();
2109 context_provider_ = new MockContextProvider(std::move(context_support)); 2113 auto cache_controller =
2110 output_surface_ = FakeOutputSurface::Create3d(context_provider_); 2114 base::MakeUnique<::testing::StrictMock<MockContextCacheController>>(
2115 support.get());
2116 mock_cache_controller_ = cache_controller.get();
2117 auto context_provider = TestContextProvider::Create(
2118 std::move(context), std::move(support), std::move(cache_controller));
2119 output_surface_ = FakeOutputSurface::Create3d(std::move(context_provider));
2111 output_surface_->BindToClient(&output_surface_client_); 2120 output_surface_->BindToClient(&output_surface_client_);
2112 resource_provider_ = 2121 resource_provider_ =
2113 FakeResourceProvider::Create(output_surface_.get(), nullptr); 2122 FakeResourceProvider::Create(output_surface_.get(), nullptr);
2114 renderer_ = 2123 renderer_ =
2115 base::MakeUnique<GLRenderer>(&settings_, output_surface_.get(), 2124 base::MakeUnique<GLRenderer>(&settings_, output_surface_.get(),
2116 resource_provider_.get(), nullptr, 0); 2125 resource_provider_.get(), nullptr, 0);
2117 renderer_->Initialize(); 2126 renderer_->Initialize();
2118 } 2127 }
2119 2128
2120 RendererSettings settings_; 2129 RendererSettings settings_;
2121 FakeOutputSurfaceClient output_surface_client_; 2130 FakeOutputSurfaceClient output_surface_client_;
2122 MockContextSupport* context_support_ptr_; 2131 MockContextCacheController* mock_cache_controller_;
2123 scoped_refptr<MockContextProvider> context_provider_;
2124 std::unique_ptr<OutputSurface> output_surface_; 2132 std::unique_ptr<OutputSurface> output_surface_;
2125 std::unique_ptr<ResourceProvider> resource_provider_; 2133 std::unique_ptr<ResourceProvider> resource_provider_;
2126 std::unique_ptr<GLRenderer> renderer_; 2134 std::unique_ptr<GLRenderer> renderer_;
2127 }; 2135 };
2128 2136
2129 TEST_F(GLRendererWithMockContextTest, 2137 TEST_F(GLRendererWithMockContextCacheControllerTest,
2130 ContextPurgedWhenRendererBecomesInvisible) { 2138 ContextPurgedWhenRendererBecomesInvisible) {
2131 // Ensure our expectations run in order. 2139 EXPECT_CALL(*mock_cache_controller_, OnClientBecameVisible());
2132 ::testing::InSequence s; 2140 renderer_->SetVisible(true);
2141 Mock::VerifyAndClearExpectations(mock_cache_controller_);
2133 2142
2134 EXPECT_CALL(*context_support_ptr_, SetClientVisible(0, true)); 2143 EXPECT_CALL(*mock_cache_controller_, OnClientBecameNotVisible());
2135 EXPECT_CALL(*context_support_ptr_, AnyClientsVisible())
2136 .WillOnce(Return(true));
2137 EXPECT_CALL(*context_support_ptr_, SetAggressivelyFreeResources(false));
2138 renderer_->SetVisible(true);
2139 Mock::VerifyAndClearExpectations(context_support_ptr_);
2140
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));
2146 renderer_->SetVisible(false); 2144 renderer_->SetVisible(false);
2147 Mock::VerifyAndClearExpectations(context_support_ptr_); 2145 Mock::VerifyAndClearExpectations(mock_cache_controller_);
2148 } 2146 }
2149 2147
2150 } // namespace 2148 } // namespace
2151 } // namespace cc 2149 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698