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 "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_impl.h"
12 #include "cc/test/fake_proxy.h"
13 #include "cc/test/impl_side_painting_settings.h"
14 #include "cc/trees/occlusion_tracker.h"
15 #include "cc/trees/single_thread_proxy.h"
16 #include "testing/gtest/include/gtest/gtest.h"
21 class MockContentLayerClient
: public ContentLayerClient
{
23 void PaintContents(SkCanvas
* canvas
,
24 const gfx::Rect
& clip
,
25 PaintingControlSetting picture_control
) override
{}
26 scoped_refptr
<DisplayItemList
> PaintContentsToDisplayList(
27 const gfx::Rect
& clip
,
28 PaintingControlSetting picture_control
) override
{
30 return DisplayItemList::Create();
32 bool FillsBoundsCompletely() const override
{ return false; };
35 TEST(PictureLayerTest
, NoTilesIfEmptyBounds
) {
36 MockContentLayerClient client
;
37 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
38 layer
->SetBounds(gfx::Size(10, 10));
40 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
41 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&host_client
);
42 host
->SetRootLayer(layer
);
43 layer
->SetIsDrawable(true);
44 layer
->SavePaintProperties();
46 OcclusionTracker
<Layer
> occlusion(gfx::Rect(0, 0, 1000, 1000));
47 scoped_ptr
<ResourceUpdateQueue
> queue(new ResourceUpdateQueue
);
48 layer
->Update(queue
.get(), &occlusion
);
50 EXPECT_EQ(0, host
->source_frame_number());
51 host
->CommitComplete();
52 EXPECT_EQ(1, host
->source_frame_number());
54 layer
->SetBounds(gfx::Size(0, 0));
55 layer
->SavePaintProperties();
56 // Intentionally skipping Update since it would normally be skipped on
57 // a layer with empty bounds.
61 DebugScopedSetImplThread
impl_thread(&proxy
);
63 TestSharedBitmapManager shared_bitmap_manager
;
64 FakeLayerTreeHostImpl
host_impl(
65 ImplSidePaintingSettings(), &proxy
, &shared_bitmap_manager
);
66 host_impl
.CreatePendingTree();
67 scoped_ptr
<FakePictureLayerImpl
> layer_impl
=
68 FakePictureLayerImpl::Create(host_impl
.pending_tree(), 1);
70 layer
->PushPropertiesTo(layer_impl
.get());
71 EXPECT_FALSE(layer_impl
->CanHaveTilings());
72 EXPECT_TRUE(layer_impl
->bounds() == gfx::Size(0, 0));
73 EXPECT_EQ(gfx::Size(), layer_impl
->raster_source()->GetSize());
74 EXPECT_FALSE(layer_impl
->raster_source()->HasRecordings());
78 TEST(PictureLayerTest
, SuitableForGpuRasterization
) {
79 MockContentLayerClient client
;
80 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
81 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
82 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&host_client
);
83 host
->SetRootLayer(layer
);
84 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
86 // Layer is suitable for gpu rasterization by default.
87 EXPECT_TRUE(recording_source
->IsSuitableForGpuRasterization());
88 EXPECT_TRUE(layer
->IsSuitableForGpuRasterization());
90 // Veto gpu rasterization.
91 recording_source
->SetUnsuitableForGpuRasterizationForTesting();
92 EXPECT_FALSE(recording_source
->IsSuitableForGpuRasterization());
93 EXPECT_FALSE(layer
->IsSuitableForGpuRasterization());
96 TEST(PictureLayerTest
, UseTileGridSize
) {
97 LayerTreeSettings settings
;
98 settings
.default_tile_grid_size
= gfx::Size(123, 123);
100 MockContentLayerClient client
;
101 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
102 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
103 scoped_ptr
<FakeLayerTreeHost
> host
=
104 FakeLayerTreeHost::Create(&host_client
, settings
);
105 host
->SetRootLayer(layer
);
107 // Tile-grid is set according to its setting.
109 layer
->GetRecordingSourceForTesting()->GetTileGridSizeForTesting();
110 EXPECT_EQ(size
.width(), 123);
111 EXPECT_EQ(size
.height(), 123);