Reland "Non-SFI mode: Switch to newlib. (patchset #4 id:60001 of https://codereview...
[chromium-blink-merge.git] / cc / layers / picture_layer_unittest.cc
blobb607f2eff99534c28a2aa743a816c1b3d828a1f2
1 // Copyright 2013 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.
5 #include "cc/layers/picture_layer.h"
7 #include "base/thread_task_runner_handle.h"
8 #include "cc/layers/content_layer_client.h"
9 #include "cc/layers/picture_layer_impl.h"
10 #include "cc/test/fake_layer_tree_host.h"
11 #include "cc/test/fake_picture_layer.h"
12 #include "cc/test/fake_picture_layer_impl.h"
13 #include "cc/test/fake_proxy.h"
14 #include "cc/test/test_shared_bitmap_manager.h"
15 #include "cc/test/test_task_graph_runner.h"
16 #include "cc/trees/single_thread_proxy.h"
17 #include "testing/gtest/include/gtest/gtest.h"
19 namespace cc {
20 namespace {
22 class MockContentLayerClient : public ContentLayerClient {
23 public:
24 void PaintContents(SkCanvas* canvas,
25 const gfx::Rect& clip,
26 PaintingControlSetting picture_control) override {}
27 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
28 const gfx::Rect& clip,
29 PaintingControlSetting picture_control) override {
30 NOTIMPLEMENTED();
31 return nullptr;
33 bool FillsBoundsCompletely() const override { return false; };
36 TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
37 MockContentLayerClient client;
38 scoped_refptr<PictureLayer> layer =
39 PictureLayer::Create(LayerSettings(), &client);
40 layer->SetBounds(gfx::Size(10, 10));
42 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
43 TestTaskGraphRunner task_graph_runner;
44 scoped_ptr<FakeLayerTreeHost> host =
45 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
46 host->SetRootLayer(layer);
47 layer->SetIsDrawable(true);
48 layer->SavePaintProperties();
49 layer->Update();
51 EXPECT_EQ(0, host->source_frame_number());
52 host->CommitComplete();
53 EXPECT_EQ(1, host->source_frame_number());
55 layer->SetBounds(gfx::Size(0, 0));
56 layer->SavePaintProperties();
57 // Intentionally skipping Update since it would normally be skipped on
58 // a layer with empty bounds.
60 FakeProxy proxy;
62 DebugScopedSetImplThread impl_thread(&proxy);
64 TestSharedBitmapManager shared_bitmap_manager;
65 FakeLayerTreeHostImpl host_impl(LayerTreeSettings(), &proxy,
66 &shared_bitmap_manager, &task_graph_runner);
67 host_impl.CreatePendingTree();
68 scoped_ptr<FakePictureLayerImpl> layer_impl =
69 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1);
71 layer->PushPropertiesTo(layer_impl.get());
72 EXPECT_FALSE(layer_impl->CanHaveTilings());
73 EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0));
74 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize());
75 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings());
79 TEST(PictureLayerTest, SuitableForGpuRasterization) {
80 MockContentLayerClient client;
81 scoped_refptr<PictureLayer> layer =
82 PictureLayer::Create(LayerSettings(), &client);
83 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
84 TestTaskGraphRunner task_graph_runner;
85 scoped_ptr<FakeLayerTreeHost> host =
86 FakeLayerTreeHost::Create(&host_client, &task_graph_runner);
87 host->SetRootLayer(layer);
88 RecordingSource* recording_source = layer->GetRecordingSourceForTesting();
90 // Layer is suitable for gpu rasterization by default.
91 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization());
92 EXPECT_TRUE(layer->IsSuitableForGpuRasterization());
94 // Veto gpu rasterization.
95 recording_source->SetUnsuitableForGpuRasterizationForTesting();
96 EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization());
97 EXPECT_FALSE(layer->IsSuitableForGpuRasterization());
100 TEST(PictureLayerTest, UseTileGridSize) {
101 LayerTreeSettings settings;
102 settings.default_tile_grid_size = gfx::Size(123, 123);
104 MockContentLayerClient client;
105 scoped_refptr<PictureLayer> layer =
106 PictureLayer::Create(LayerSettings(), &client);
107 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
108 TestTaskGraphRunner task_graph_runner;
109 scoped_ptr<FakeLayerTreeHost> host =
110 FakeLayerTreeHost::Create(&host_client, &task_graph_runner, settings);
111 host->SetRootLayer(layer);
113 // Tile-grid is set according to its setting.
114 gfx::Size size =
115 layer->GetRecordingSourceForTesting()->GetTileGridSizeForTesting();
116 EXPECT_EQ(size.width(), 123);
117 EXPECT_EQ(size.height(), 123);
120 // PicturePile uses the source frame number as a unit for measuring invalidation
121 // frequency. When a pile moves between compositors, the frame number increases
122 // non-monotonically. This executes that code path under this scenario allowing
123 // for the code to verify correctness with DCHECKs.
124 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) {
125 LayerTreeSettings settings;
126 settings.single_thread_proxy_scheduler = false;
127 settings.use_zero_copy = true;
128 settings.use_one_copy = false;
130 FakeLayerTreeHostClient host_client1(FakeLayerTreeHostClient::DIRECT_3D);
131 FakeLayerTreeHostClient host_client2(FakeLayerTreeHostClient::DIRECT_3D);
132 TestSharedBitmapManager shared_bitmap_manager;
133 TestTaskGraphRunner task_graph_runner;
135 MockContentLayerClient client;
136 scoped_refptr<FakePictureLayer> layer =
137 FakePictureLayer::Create(LayerSettings(), &client);
139 LayerTreeHost::InitParams params;
140 params.client = &host_client1;
141 params.shared_bitmap_manager = &shared_bitmap_manager;
142 params.settings = &settings;
143 params.task_graph_runner = &task_graph_runner;
144 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
145 scoped_ptr<LayerTreeHost> host1 =
146 LayerTreeHost::CreateSingleThreaded(&host_client1, &params);
147 host_client1.SetLayerTreeHost(host1.get());
149 params.client = &host_client2;
150 scoped_ptr<LayerTreeHost> host2 =
151 LayerTreeHost::CreateSingleThreaded(&host_client2, &params);
152 host_client2.SetLayerTreeHost(host2.get());
154 // The PictureLayer is put in one LayerTreeHost.
155 host1->SetRootLayer(layer);
156 // Do a main frame, record the picture layers.
157 EXPECT_EQ(0, layer->update_count());
158 layer->SetNeedsDisplay();
159 host1->Composite(base::TimeTicks::Now());
160 EXPECT_EQ(1, layer->update_count());
161 EXPECT_EQ(1, host1->source_frame_number());
163 // The source frame number in |host1| is now higher than host2.
164 layer->SetNeedsDisplay();
165 host1->Composite(base::TimeTicks::Now());
166 EXPECT_EQ(2, layer->update_count());
167 EXPECT_EQ(2, host1->source_frame_number());
169 // Then moved to another LayerTreeHost.
170 host1->SetRootLayer(nullptr);
171 host2->SetRootLayer(layer);
173 // Do a main frame, record the picture layers. The frame number has changed
174 // non-monotonically.
175 layer->SetNeedsDisplay();
176 host2->Composite(base::TimeTicks::Now());
177 EXPECT_EQ(3, layer->update_count());
178 EXPECT_EQ(1, host2->source_frame_number());
181 } // namespace
182 } // namespace cc