1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
|
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "cc/trees/layer_tree_host.h"
#include "cc/test/fake_content_layer_client.h"
#include "cc/test/fake_picture_layer.h"
#include "cc/test/fake_picture_layer_impl.h"
#include "cc/test/layer_tree_test.h"
#include "cc/trees/layer_tree_impl.h"
namespace cc {
namespace {
// These tests deal with picture layers.
class LayerTreeHostPictureTest : public LayerTreeTest {
protected:
void SetupTreeWithSinglePictureLayer(const gfx::Size& size) {
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(size);
root_picture_layer_ = FakePictureLayer::Create(&client_);
root_picture_layer_->SetBounds(size);
root->AddChild(root_picture_layer_);
layer_tree_host()->SetRootLayer(root);
}
scoped_refptr<FakePictureLayer> root_picture_layer_;
FakeContentLayerClient client_;
};
class LayerTreeHostPictureTestTwinLayer
: public LayerTreeHostPictureTest {
void SetupTree() override {
SetupTreeWithSinglePictureLayer(gfx::Size(1, 1));
}
void BeginTest() override {
activates_ = 0;
PostSetNeedsCommitToMainThread();
}
void DidCommit() override {
switch (layer_tree_host()->source_frame_number()) {
case 2:
// Drop the picture layer from the tree.
layer_tree_host()->root_layer()->children()[0]->RemoveFromParent();
break;
case 3:
// Add a new picture layer.
scoped_refptr<FakePictureLayer> picture =
FakePictureLayer::Create(&client_);
layer_tree_host()->root_layer()->AddChild(picture);
break;
}
}
void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
LayerImpl* pending_root_impl = impl->pending_tree()->root_layer();
LayerImpl* active_root_impl = impl->active_tree()->root_layer();
if (pending_root_impl->children().empty()) {
EXPECT_EQ(2, activates_);
return;
}
FakePictureLayerImpl* pending_picture_impl =
static_cast<FakePictureLayerImpl*>(pending_root_impl->children()[0]);
if (!active_root_impl) {
EXPECT_EQ(0, activates_);
EXPECT_EQ(nullptr, pending_picture_impl->GetPendingOrActiveTwinLayer());
return;
}
if (active_root_impl->children().empty()) {
EXPECT_EQ(3, activates_);
EXPECT_EQ(nullptr, pending_picture_impl->GetPendingOrActiveTwinLayer());
return;
}
FakePictureLayerImpl* active_picture_impl =
static_cast<FakePictureLayerImpl*>(active_root_impl->children()[0]);
// After the first activation, when we commit again, we'll have a pending
// and active layer. Then we recreate a picture layer in the 4th activate
// and the next commit will have a pending and active twin again.
EXPECT_TRUE(activates_ == 1 || activates_ == 4);
EXPECT_EQ(pending_picture_impl,
active_picture_impl->GetPendingOrActiveTwinLayer());
EXPECT_EQ(active_picture_impl,
pending_picture_impl->GetPendingOrActiveTwinLayer());
EXPECT_EQ(nullptr, active_picture_impl->GetRecycledTwinLayer());
}
void DidActivateTreeOnThread(LayerTreeHostImpl* impl) override {
LayerImpl* active_root_impl = impl->active_tree()->root_layer();
LayerImpl* recycle_root_impl = impl->recycle_tree()->root_layer();
if (active_root_impl->children().empty()) {
EXPECT_EQ(2, activates_);
} else {
FakePictureLayerImpl* active_picture_impl =
static_cast<FakePictureLayerImpl*>(active_root_impl->children()[0]);
FakePictureLayerImpl* recycle_picture_impl =
static_cast<FakePictureLayerImpl*>(recycle_root_impl->children()[0]);
EXPECT_EQ(nullptr, active_picture_impl->GetPendingOrActiveTwinLayer());
EXPECT_EQ(recycle_picture_impl,
active_picture_impl->GetRecycledTwinLayer());
}
++activates_;
if (activates_ <= 4)
PostSetNeedsCommitToMainThread();
else
EndTest();
}
void AfterTest() override {}
int activates_;
};
SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(LayerTreeHostPictureTestTwinLayer);
class LayerTreeHostPictureTestResizeViewportWithGpuRaster
: public LayerTreeHostPictureTest {
void InitializeSettings(LayerTreeSettings* settings) override {
settings->gpu_rasterization_forced = true;
}
void SetupTree() override {
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(gfx::Size(768, 960));
client_.set_fill_with_nonsolid_color(true);
picture_ = FakePictureLayer::Create(&client_);
picture_->SetBounds(gfx::Size(768, 960));
root->AddChild(picture_);
layer_tree_host()->SetRootLayer(root);
LayerTreeHostPictureTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
LayerImpl* child = impl->sync_tree()->root_layer()->children()[0];
FakePictureLayerImpl* picture_impl =
static_cast<FakePictureLayerImpl*>(child);
gfx::Size tile_size =
picture_impl->HighResTiling()->TileAt(0, 0)->content_rect().size();
switch (impl->sync_tree()->source_frame_number()) {
case 0:
tile_size_ = tile_size;
// GPU Raster picks a tile size based on the viewport size.
EXPECT_EQ(gfx::Size(768, 256), tile_size);
break;
case 1:
// When the viewport changed size, the new frame's tiles should change
// along with it.
EXPECT_NE(gfx::Size(768, 256), tile_size);
}
}
void DidCommit() override {
switch (layer_tree_host()->source_frame_number()) {
case 1:
// Change the picture layer's size along with the viewport, so it will
// consider picking a new tile size.
picture_->SetBounds(gfx::Size(768, 1056));
layer_tree_host()->SetViewportSize(gfx::Size(768, 1056));
break;
case 2:
EndTest();
}
}
void AfterTest() override {}
gfx::Size tile_size_;
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> picture_;
};
SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(
LayerTreeHostPictureTestResizeViewportWithGpuRaster);
class LayerTreeHostPictureTestChangeLiveTilesRectWithRecycleTree
: public LayerTreeHostPictureTest {
void SetupTree() override {
frame_ = 0;
did_post_commit_ = false;
scoped_refptr<Layer> root = Layer::Create();
root->SetBounds(gfx::Size(100, 100));
// The layer is big enough that the live tiles rect won't cover the full
// layer.
client_.set_fill_with_nonsolid_color(true);
picture_ = FakePictureLayer::Create(&client_);
picture_->SetBounds(gfx::Size(100, 100000));
root->AddChild(picture_);
layer_tree_host()->SetRootLayer(root);
LayerTreeHostPictureTest::SetupTree();
}
void BeginTest() override { PostSetNeedsCommitToMainThread(); }
void DrawLayersOnThread(LayerTreeHostImpl* impl) override {
LayerImpl* child = impl->active_tree()->root_layer()->children()[0];
FakePictureLayerImpl* picture_impl =
static_cast<FakePictureLayerImpl*>(child);
FakePictureLayerImpl* recycled_impl = static_cast<FakePictureLayerImpl*>(
picture_impl->GetRecycledTwinLayer());
switch (++frame_) {
case 1: {
PictureLayerTiling* tiling = picture_impl->HighResTiling();
PictureLayerTiling* recycled_tiling = recycled_impl->HighResTiling();
int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y();
// There should be tiles at the top of the picture layer but not at the
// bottom.
EXPECT_TRUE(tiling->TileAt(0, 0));
EXPECT_FALSE(tiling->TileAt(0, num_tiles_y));
// The recycled tiling matches it.
EXPECT_TRUE(recycled_tiling->TileAt(0, 0));
EXPECT_FALSE(recycled_tiling->TileAt(0, num_tiles_y));
// The live tiles rect matches on the recycled tree.
EXPECT_EQ(tiling->live_tiles_rect(),
recycled_tiling->live_tiles_rect());
// Make the bottom of the layer visible.
picture_impl->SetPosition(gfx::PointF(0.f, -100000.f + 100.f));
impl->SetNeedsRedraw();
break;
}
case 2: {
PictureLayerTiling* tiling = picture_impl->HighResTiling();
PictureLayerTiling* recycled_tiling = recycled_impl->HighResTiling();
// There not be tiles at the top of the layer now.
EXPECT_FALSE(tiling->TileAt(0, 0));
// The recycled twin tiling should not have unshared tiles at the top
// either.
EXPECT_FALSE(recycled_tiling->TileAt(0, 0));
// The live tiles rect matches on the recycled tree.
EXPECT_EQ(tiling->live_tiles_rect(),
recycled_tiling->live_tiles_rect());
// Make the top of the layer visible again.
picture_impl->SetPosition(gfx::PointF());
impl->SetNeedsRedraw();
break;
}
case 3: {
PictureLayerTiling* tiling = picture_impl->HighResTiling();
PictureLayerTiling* recycled_tiling = recycled_impl->HighResTiling();
int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y();
// There should be tiles at the top of the picture layer again.
EXPECT_TRUE(tiling->TileAt(0, 0));
EXPECT_FALSE(tiling->TileAt(0, num_tiles_y));
// The recycled tiling should also have tiles at the top.
EXPECT_TRUE(recycled_tiling->TileAt(0, 0));
EXPECT_FALSE(recycled_tiling->TileAt(0, num_tiles_y));
// The live tiles rect matches on the recycled tree.
EXPECT_EQ(tiling->live_tiles_rect(),
recycled_tiling->live_tiles_rect());
// Make a new main frame without changing the picture layer at all, so
// it won't need to update or push properties.
did_post_commit_ = true;
PostSetNeedsCommitToMainThread();
break;
}
}
}
void WillActivateTreeOnThread(LayerTreeHostImpl* impl) override {
LayerImpl* child = impl->sync_tree()->root_layer()->children()[0];
FakePictureLayerImpl* picture_impl =
static_cast<FakePictureLayerImpl*>(child);
PictureLayerTiling* tiling = picture_impl->HighResTiling();
int num_tiles_y = tiling->TilingDataForTesting().num_tiles_y();
// The pending layer should always have tiles at the top of it each commit.
// The tile is part of the required for activation set so it should exist.
EXPECT_TRUE(tiling->TileAt(0, 0));
EXPECT_FALSE(tiling->TileAt(0, num_tiles_y));
if (did_post_commit_)
EndTest();
}
void AfterTest() override {}
int frame_;
bool did_post_commit_;
FakeContentLayerClient client_;
scoped_refptr<FakePictureLayer> picture_;
};
SINGLE_AND_MULTI_THREAD_IMPL_TEST_F(
LayerTreeHostPictureTestChangeLiveTilesRectWithRecycleTree);
} // namespace
} // namespace cc
|