Disable flaky AnimatedContentSamplerParameterizedTest.FrameTimestampsConvergeTowardsE...
[chromium-blink-merge.git] / cc / layers / picture_layer_unittest.cc
blob37070127a779b5f391520b3d14e96984e3b2fa9d
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/resources/resource_update_queue.h"
11 #include "cc/test/fake_layer_tree_host.h"
12 #include "cc/test/fake_picture_layer.h"
13 #include "cc/test/fake_picture_layer_impl.h"
14 #include "cc/test/fake_proxy.h"
15 #include "cc/test/impl_side_painting_settings.h"
16 #include "cc/trees/occlusion_tracker.h"
17 #include "cc/trees/single_thread_proxy.h"
18 #include "testing/gtest/include/gtest/gtest.h"
20 namespace cc {
21 namespace {
23 class MockContentLayerClient : public ContentLayerClient {
24 public:
25 void PaintContents(SkCanvas* canvas,
26 const gfx::Rect& clip,
27 PaintingControlSetting picture_control) override {}
28 void PaintContentsToDisplayList(
29 DisplayItemList* display_list,
30 const gfx::Rect& clip,
31 PaintingControlSetting picture_control) override {
32 NOTIMPLEMENTED();
34 bool FillsBoundsCompletely() const override { return false; };
37 TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
38 MockContentLayerClient client;
39 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
40 layer->SetBounds(gfx::Size(10, 10));
42 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
43 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client);
44 host->SetRootLayer(layer);
45 layer->SetIsDrawable(true);
46 layer->SavePaintProperties();
48 OcclusionTracker<Layer> occlusion(gfx::Rect(0, 0, 1000, 1000));
49 scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue);
50 layer->Update(queue.get(), &occlusion);
52 EXPECT_EQ(0, host->source_frame_number());
53 host->CommitComplete();
54 EXPECT_EQ(1, host->source_frame_number());
56 layer->SetBounds(gfx::Size(0, 0));
57 layer->SavePaintProperties();
58 // Intentionally skipping Update since it would normally be skipped on
59 // a layer with empty bounds.
61 FakeProxy proxy;
63 DebugScopedSetImplThread impl_thread(&proxy);
65 TestSharedBitmapManager shared_bitmap_manager;
66 FakeLayerTreeHostImpl host_impl(ImplSidePaintingSettings(), &proxy,
67 &shared_bitmap_manager, nullptr);
68 host_impl.CreatePendingTree();
69 scoped_ptr<FakePictureLayerImpl> layer_impl =
70 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1);
72 layer->PushPropertiesTo(layer_impl.get());
73 EXPECT_FALSE(layer_impl->CanHaveTilings());
74 EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0));
75 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize());
76 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings());
80 TEST(PictureLayerTest, SuitableForGpuRasterization) {
81 MockContentLayerClient client;
82 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
83 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
84 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client);
85 host->SetRootLayer(layer);
86 RecordingSource* recording_source = layer->GetRecordingSourceForTesting();
88 // Layer is suitable for gpu rasterization by default.
89 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization());
90 EXPECT_TRUE(layer->IsSuitableForGpuRasterization());
92 // Veto gpu rasterization.
93 recording_source->SetUnsuitableForGpuRasterizationForTesting();
94 EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization());
95 EXPECT_FALSE(layer->IsSuitableForGpuRasterization());
98 TEST(PictureLayerTest, UseTileGridSize) {
99 LayerTreeSettings settings;
100 settings.default_tile_grid_size = gfx::Size(123, 123);
102 MockContentLayerClient client;
103 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
104 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
105 scoped_ptr<FakeLayerTreeHost> host =
106 FakeLayerTreeHost::Create(&host_client, settings);
107 host->SetRootLayer(layer);
109 // Tile-grid is set according to its setting.
110 gfx::Size size =
111 layer->GetRecordingSourceForTesting()->GetTileGridSizeForTesting();
112 EXPECT_EQ(size.width(), 123);
113 EXPECT_EQ(size.height(), 123);
116 // PicturePile uses the source frame number as a unit for measuring invalidation
117 // frequency. When a pile moves between compositors, the frame number increases
118 // non-monotonically. This executes that code path under this scenario allowing
119 // for the code to verify correctness with DCHECKs.
120 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) {
121 LayerTreeSettings settings;
122 settings.single_thread_proxy_scheduler = false;
124 FakeLayerTreeHostClient host_client1(FakeLayerTreeHostClient::DIRECT_3D);
125 FakeLayerTreeHostClient host_client2(FakeLayerTreeHostClient::DIRECT_3D);
126 scoped_ptr<SharedBitmapManager> shared_bitmap_manager(
127 new TestSharedBitmapManager());
129 MockContentLayerClient client;
130 scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(&client);
132 LayerTreeHost::InitParams params;
133 params.client = &host_client1;
134 params.shared_bitmap_manager = shared_bitmap_manager.get();
135 params.settings = &settings;
136 params.main_task_runner = base::ThreadTaskRunnerHandle::Get();
137 scoped_ptr<LayerTreeHost> host1 =
138 LayerTreeHost::CreateSingleThreaded(&host_client1, &params);
139 host_client1.SetLayerTreeHost(host1.get());
141 params.client = &host_client2;
142 scoped_ptr<LayerTreeHost> host2 =
143 LayerTreeHost::CreateSingleThreaded(&host_client2, &params);
144 host_client2.SetLayerTreeHost(host2.get());
146 // The PictureLayer is put in one LayerTreeHost.
147 host1->SetRootLayer(layer);
148 // Do a main frame, record the picture layers.
149 EXPECT_EQ(0u, layer->update_count());
150 layer->SetNeedsDisplay();
151 host1->Composite(base::TimeTicks::Now());
152 EXPECT_EQ(1u, layer->update_count());
153 EXPECT_EQ(1, host1->source_frame_number());
155 // The source frame number in |host1| is now higher than host2.
156 layer->SetNeedsDisplay();
157 host1->Composite(base::TimeTicks::Now());
158 EXPECT_EQ(2u, layer->update_count());
159 EXPECT_EQ(2, host1->source_frame_number());
161 // Then moved to another LayerTreeHost.
162 host1->SetRootLayer(nullptr);
163 host2->SetRootLayer(layer);
165 // Do a main frame, record the picture layers. The frame number has changed
166 // non-monotonically.
167 layer->SetNeedsDisplay();
168 host2->Composite(base::TimeTicks::Now());
169 EXPECT_EQ(3u, layer->update_count());
170 EXPECT_EQ(1, host2->source_frame_number());
173 } // namespace
174 } // namespace cc