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

Side by Side Diff: cc/test/test_layer_tree_host_base.cc

Issue 1988053002: Revert of cc: Refactor layer/tile manager unittest to extract common code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
« no previous file with comments | « cc/test/test_layer_tree_host_base.h ('k') | cc/tiles/tile_manager_perftest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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/test/test_layer_tree_host_base.h"
6
7 #include "cc/test/fake_output_surface.h"
8 #include "cc/test/fake_raster_source.h"
9 #include "cc/trees/layer_tree_impl.h"
10
11 namespace cc {
12
13 TestLayerTreeHostBase::TestLayerTreeHostBase()
14 : task_runner_provider_(base::ThreadTaskRunnerHandle::Get()),
15 pending_layer_(nullptr),
16 active_layer_(nullptr),
17 old_pending_layer_(nullptr),
18 root_id_(6),
19 id_(7) {}
20
21 TestLayerTreeHostBase::~TestLayerTreeHostBase() = default;
22
23 void TestLayerTreeHostBase::SetUp() {
24 output_surface_ = CreateOutputSurface();
25 task_graph_runner_ = CreateTaskGraphRunner();
26 host_impl_ = CreateHostImpl(CreateSettings(), &task_runner_provider_,
27 &shared_bitmap_manager_, task_graph_runner_.get(),
28 &gpu_memory_buffer_manager_);
29 InitializeRenderer();
30 SetInitialTreePriority();
31 }
32
33 LayerTreeSettings TestLayerTreeHostBase::CreateSettings() {
34 return LayerTreeSettings();
35 }
36
37 std::unique_ptr<OutputSurface> TestLayerTreeHostBase::CreateOutputSurface() {
38 return FakeOutputSurface::Create3d();
39 }
40
41 std::unique_ptr<FakeLayerTreeHostImpl> TestLayerTreeHostBase::CreateHostImpl(
42 const LayerTreeSettings& settings,
43 TaskRunnerProvider* task_runner_provider,
44 SharedBitmapManager* shared_bitmap_manager,
45 TaskGraphRunner* task_graph_runner,
46 gpu::GpuMemoryBufferManager* gpu_memory_buffer_manager) {
47 return base::WrapUnique(new FakeLayerTreeHostImpl(
48 settings, task_runner_provider, shared_bitmap_manager, task_graph_runner,
49 gpu_memory_buffer_manager));
50 }
51
52 std::unique_ptr<TaskGraphRunner>
53 TestLayerTreeHostBase::CreateTaskGraphRunner() {
54 return base::WrapUnique(new TestTaskGraphRunner);
55 }
56
57 void TestLayerTreeHostBase::InitializeRenderer() {
58 host_impl_->SetVisible(true);
59 host_impl_->InitializeRenderer(output_surface_.get());
60 }
61
62 void TestLayerTreeHostBase::ResetOutputSurface(
63 std::unique_ptr<OutputSurface> output_surface) {
64 host_impl()->DidLoseOutputSurface();
65 host_impl()->SetVisible(true);
66 host_impl()->InitializeRenderer(output_surface.get());
67 output_surface_ = std::move(output_surface);
68 }
69
70 std::unique_ptr<FakeLayerTreeHostImpl> TestLayerTreeHostBase::TakeHostImpl() {
71 return std::move(host_impl_);
72 }
73
74 void TestLayerTreeHostBase::SetupDefaultTrees(const gfx::Size& layer_bounds) {
75 scoped_refptr<FakeRasterSource> pending_raster_source =
76 FakeRasterSource::CreateFilled(layer_bounds);
77 scoped_refptr<FakeRasterSource> active_raster_source =
78 FakeRasterSource::CreateFilled(layer_bounds);
79
80 SetupTrees(std::move(pending_raster_source), std::move(active_raster_source));
81 }
82
83 void TestLayerTreeHostBase::SetupTrees(
84 scoped_refptr<RasterSource> pending_raster_source,
85 scoped_refptr<RasterSource> active_raster_source) {
86 SetupPendingTree(std::move(active_raster_source));
87 ActivateTree();
88 SetupPendingTree(std::move(pending_raster_source));
89 }
90
91 void TestLayerTreeHostBase::SetupPendingTree(
92 scoped_refptr<RasterSource> raster_source) {
93 SetupPendingTree(std::move(raster_source), gfx::Size(), Region());
94 }
95
96 void TestLayerTreeHostBase::SetupPendingTree(
97 scoped_refptr<RasterSource> raster_source,
98 const gfx::Size& tile_size,
99 const Region& invalidation) {
100 host_impl()->CreatePendingTree();
101 host_impl()->pending_tree()->PushPageScaleFromMainThread(1.f, 0.00001f,
102 100000.f);
103 LayerTreeImpl* pending_tree = host_impl()->pending_tree();
104 pending_tree->SetDeviceScaleFactor(
105 host_impl()->active_tree()->device_scale_factor());
106
107 // Steal from the recycled tree if possible.
108 LayerImpl* pending_root = pending_tree->root_layer();
109 std::unique_ptr<FakePictureLayerImpl> pending_layer;
110 DCHECK(!pending_root || pending_root->id() == root_id_);
111 if (!pending_root) {
112 std::unique_ptr<LayerImpl> new_pending_root =
113 LayerImpl::Create(pending_tree, root_id_);
114 pending_layer = FakePictureLayerImpl::Create(pending_tree, id_);
115 if (!tile_size.IsEmpty())
116 pending_layer->set_fixed_tile_size(tile_size);
117 pending_layer->SetDrawsContent(true);
118 pending_layer->SetScrollClipLayer(new_pending_root->id());
119 pending_root = new_pending_root.get();
120 pending_tree->SetRootLayer(std::move(new_pending_root));
121 } else {
122 pending_layer.reset(static_cast<FakePictureLayerImpl*>(
123 pending_root->RemoveChildForTesting(pending_root->children()[0])
124 .release()));
125 if (!tile_size.IsEmpty())
126 pending_layer->set_fixed_tile_size(tile_size);
127 }
128 pending_root->test_properties()->force_render_surface = true;
129 // The bounds() just mirror the raster source size.
130 pending_layer->SetBounds(raster_source->GetSize());
131 pending_layer->SetRasterSourceOnPending(raster_source, invalidation);
132
133 pending_root->AddChild(std::move(pending_layer));
134 pending_tree->SetViewportLayersFromIds(Layer::INVALID_ID,
135 pending_tree->root_layer()->id(),
136 Layer::INVALID_ID, Layer::INVALID_ID);
137
138 pending_layer_ = static_cast<FakePictureLayerImpl*>(
139 host_impl()->pending_tree()->LayerById(id_));
140
141 // Add tilings/tiles for the layer.
142 bool update_lcd_text = false;
143 RebuildPropertyTreesOnPendingTree();
144 host_impl()->pending_tree()->UpdateDrawProperties(update_lcd_text);
145 }
146
147 void TestLayerTreeHostBase::ActivateTree() {
148 RebuildPropertyTreesOnPendingTree();
149 host_impl()->ActivateSyncTree();
150 CHECK(!host_impl()->pending_tree());
151 CHECK(host_impl()->recycle_tree());
152 old_pending_layer_ = pending_layer_;
153 pending_layer_ = nullptr;
154 active_layer_ = static_cast<FakePictureLayerImpl*>(
155 host_impl()->active_tree()->LayerById(id_));
156
157 bool update_lcd_text = false;
158 host_impl()->active_tree()->UpdateDrawProperties(update_lcd_text);
159 }
160
161 void TestLayerTreeHostBase::RebuildPropertyTreesOnPendingTree() {
162 host_impl()->pending_tree()->property_trees()->needs_rebuild = true;
163 host_impl()->pending_tree()->BuildPropertyTreesForTesting();
164 }
165
166 void TestLayerTreeHostBase::SetInitialTreePriority() {
167 GlobalStateThatImpactsTilePriority state;
168
169 state.soft_memory_limit_in_bytes = 100 * 1000 * 1000;
170 state.num_resources_limit = 10000;
171 state.hard_memory_limit_in_bytes = state.soft_memory_limit_in_bytes * 2;
172 state.memory_limit_policy = ALLOW_ANYTHING;
173 state.tree_priority = SAME_PRIORITY_FOR_BOTH_TREES;
174
175 host_impl_->resource_pool()->SetResourceUsageLimits(
176 state.soft_memory_limit_in_bytes, state.num_resources_limit);
177 host_impl_->tile_manager()->SetGlobalStateForTesting(state);
178 }
179
180 } // namespace cc
OLDNEW
« no previous file with comments | « cc/test/test_layer_tree_host_base.h ('k') | cc/tiles/tile_manager_perftest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698