| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "cc/layers/picture_layer.h" | |
| 6 | |
| 7 #include "cc/layers/content_layer_client.h" | |
| 8 #include "cc/layers/picture_layer_impl.h" | |
| 9 #include "cc/resources/resource_update_queue.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/impl_side_painting_settings.h" | |
| 15 #include "cc/trees/occlusion_tracker.h" | |
| 16 #include "cc/trees/single_thread_proxy.h" | |
| 17 #include "testing/gtest/include/gtest/gtest.h" | |
| 18 | |
| 19 namespace cc { | |
| 20 namespace { | |
| 21 | |
| 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 DisplayItemList::Create(); | |
| 32 } | |
| 33 bool FillsBoundsCompletely() const override { return false; }; | |
| 34 }; | |
| 35 | |
| 36 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { | |
| 37 MockContentLayerClient client; | |
| 38 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); | |
| 39 layer->SetBounds(gfx::Size(10, 10)); | |
| 40 | |
| 41 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | |
| 42 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client); | |
| 43 host->SetRootLayer(layer); | |
| 44 layer->SetIsDrawable(true); | |
| 45 layer->SavePaintProperties(); | |
| 46 | |
| 47 OcclusionTracker<Layer> occlusion(gfx::Rect(0, 0, 1000, 1000)); | |
| 48 scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue); | |
| 49 layer->Update(queue.get(), &occlusion); | |
| 50 | |
| 51 EXPECT_EQ(0, host->source_frame_number()); | |
| 52 host->CommitComplete(); | |
| 53 EXPECT_EQ(1, host->source_frame_number()); | |
| 54 | |
| 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. | |
| 59 | |
| 60 FakeProxy proxy; | |
| 61 { | |
| 62 DebugScopedSetImplThread impl_thread(&proxy); | |
| 63 | |
| 64 TestSharedBitmapManager shared_bitmap_manager; | |
| 65 FakeLayerTreeHostImpl host_impl(ImplSidePaintingSettings(), &proxy, | |
| 66 &shared_bitmap_manager, nullptr); | |
| 67 host_impl.CreatePendingTree(); | |
| 68 scoped_ptr<FakePictureLayerImpl> layer_impl = | |
| 69 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1); | |
| 70 | |
| 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()); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 TEST(PictureLayerTest, SuitableForGpuRasterization) { | |
| 80 MockContentLayerClient client; | |
| 81 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); | |
| 82 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | |
| 83 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client); | |
| 84 host->SetRootLayer(layer); | |
| 85 RecordingSource* recording_source = layer->GetRecordingSourceForTesting(); | |
| 86 | |
| 87 // Layer is suitable for gpu rasterization by default. | |
| 88 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization()); | |
| 89 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); | |
| 90 | |
| 91 // Veto gpu rasterization. | |
| 92 recording_source->SetUnsuitableForGpuRasterizationForTesting(); | |
| 93 EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization()); | |
| 94 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); | |
| 95 } | |
| 96 | |
| 97 TEST(PictureLayerTest, UseTileGridSize) { | |
| 98 LayerTreeSettings settings; | |
| 99 settings.default_tile_grid_size = gfx::Size(123, 123); | |
| 100 | |
| 101 MockContentLayerClient client; | |
| 102 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); | |
| 103 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); | |
| 104 scoped_ptr<FakeLayerTreeHost> host = | |
| 105 FakeLayerTreeHost::Create(&host_client, settings); | |
| 106 host->SetRootLayer(layer); | |
| 107 | |
| 108 // Tile-grid is set according to its setting. | |
| 109 gfx::Size size = | |
| 110 layer->GetRecordingSourceForTesting()->GetTileGridSizeForTesting(); | |
| 111 EXPECT_EQ(size.width(), 123); | |
| 112 EXPECT_EQ(size.height(), 123); | |
| 113 } | |
| 114 | |
| 115 // PicturePile uses the source frame number as a unit for measuring invalidation | |
| 116 // frequency. When a pile moves between compositors, the frame number increases | |
| 117 // non-monotonically. This executes that code path under this scenario allowing | |
| 118 // for the code to verify correctness with DCHECKs. | |
| 119 TEST(PictureLayerTest, NonMonotonicSourceFrameNumber) { | |
| 120 LayerTreeSettings settings; | |
| 121 settings.single_thread_proxy_scheduler = false; | |
| 122 | |
| 123 FakeLayerTreeHostClient host_client1(FakeLayerTreeHostClient::DIRECT_3D); | |
| 124 FakeLayerTreeHostClient host_client2(FakeLayerTreeHostClient::DIRECT_3D); | |
| 125 scoped_ptr<SharedBitmapManager> shared_bitmap_manager( | |
| 126 new TestSharedBitmapManager()); | |
| 127 | |
| 128 MockContentLayerClient client; | |
| 129 scoped_refptr<FakePictureLayer> layer = FakePictureLayer::Create(&client); | |
| 130 | |
| 131 scoped_ptr<LayerTreeHost> host1 = LayerTreeHost::CreateSingleThreaded( | |
| 132 &host_client1, &host_client1, shared_bitmap_manager.get(), nullptr, | |
| 133 nullptr, settings, base::MessageLoopProxy::current(), nullptr); | |
| 134 host_client1.SetLayerTreeHost(host1.get()); | |
| 135 | |
| 136 scoped_ptr<LayerTreeHost> host2 = LayerTreeHost::CreateSingleThreaded( | |
| 137 &host_client2, &host_client2, shared_bitmap_manager.get(), nullptr, | |
| 138 nullptr, settings, base::MessageLoopProxy::current(), nullptr); | |
| 139 host_client2.SetLayerTreeHost(host2.get()); | |
| 140 | |
| 141 // The PictureLayer is put in one LayerTreeHost. | |
| 142 host1->SetRootLayer(layer); | |
| 143 // Do a main frame, record the picture layers. | |
| 144 EXPECT_EQ(0u, layer->update_count()); | |
| 145 layer->SetNeedsDisplay(); | |
| 146 host1->Composite(base::TimeTicks::Now()); | |
| 147 EXPECT_EQ(1u, layer->update_count()); | |
| 148 EXPECT_EQ(1, host1->source_frame_number()); | |
| 149 | |
| 150 // The source frame number in |host1| is now higher than host2. | |
| 151 layer->SetNeedsDisplay(); | |
| 152 host1->Composite(base::TimeTicks::Now()); | |
| 153 EXPECT_EQ(2u, layer->update_count()); | |
| 154 EXPECT_EQ(2, host1->source_frame_number()); | |
| 155 | |
| 156 // Then moved to another LayerTreeHost. | |
| 157 host1->SetRootLayer(nullptr); | |
| 158 host2->SetRootLayer(layer); | |
| 159 | |
| 160 // Do a main frame, record the picture layers. The frame number has changed | |
| 161 // non-monotonically. | |
| 162 layer->SetNeedsDisplay(); | |
| 163 host2->Composite(base::TimeTicks::Now()); | |
| 164 EXPECT_EQ(3u, layer->update_count()); | |
| 165 EXPECT_EQ(1, host2->source_frame_number()); | |
| 166 } | |
| 167 | |
| 168 } // namespace | |
| 169 } // namespace cc | |
| OLD | NEW |