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
{
25 const gfx::Rect
& clip
,
26 ContentLayerClient::GraphicsContextStatus gc_status
) override
{}
27 void DidChangeLayerCanUseLCDText() override
{}
28 bool FillsBoundsCompletely() const override
{ return false; };
31 TEST(PictureLayerTest
, NoTilesIfEmptyBounds
) {
32 MockContentLayerClient client
;
33 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
34 layer
->SetBounds(gfx::Size(10, 10));
36 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
37 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(&host_client
);
38 host
->SetRootLayer(layer
);
39 layer
->SetIsDrawable(true);
40 layer
->SavePaintProperties();
42 OcclusionTracker
<Layer
> occlusion(gfx::Rect(0, 0, 1000, 1000));
43 scoped_ptr
<ResourceUpdateQueue
> queue(new ResourceUpdateQueue
);
44 layer
->Update(queue
.get(), &occlusion
);
46 EXPECT_EQ(0, host
->source_frame_number());
47 host
->CommitComplete();
48 EXPECT_EQ(1, host
->source_frame_number());
50 layer
->SetBounds(gfx::Size(0, 0));
51 layer
->SavePaintProperties();
52 // Intentionally skipping Update since it would normally be skipped on
53 // a layer with empty bounds.
57 DebugScopedSetImplThread
impl_thread(&proxy
);
59 TestSharedBitmapManager shared_bitmap_manager
;
60 FakeLayerTreeHostImpl
host_impl(
61 ImplSidePaintingSettings(), &proxy
, &shared_bitmap_manager
);
62 host_impl
.CreatePendingTree();
63 scoped_ptr
<FakePictureLayerImpl
> layer_impl
=
64 FakePictureLayerImpl::Create(host_impl
.pending_tree(), 1);
66 layer
->PushPropertiesTo(layer_impl
.get());
67 EXPECT_FALSE(layer_impl
->CanHaveTilings());
68 EXPECT_TRUE(layer_impl
->bounds() == gfx::Size(0, 0));
69 EXPECT_EQ(gfx::Size(), layer_impl
->raster_source()->GetSize());
70 EXPECT_FALSE(layer_impl
->raster_source()->HasRecordings());
74 TEST(PictureLayerTest
, SuitableForGpuRasterization
) {
75 MockContentLayerClient client
;
76 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
77 RecordingSource
* recording_source
= layer
->GetRecordingSourceForTesting();
79 // Layer is suitable for gpu rasterization by default.
80 EXPECT_TRUE(recording_source
->IsSuitableForGpuRasterization());
81 EXPECT_TRUE(layer
->IsSuitableForGpuRasterization());
83 // Veto gpu rasterization.
84 recording_source
->SetUnsuitableForGpuRasterizationForTesting();
85 EXPECT_FALSE(recording_source
->IsSuitableForGpuRasterization());
86 EXPECT_FALSE(layer
->IsSuitableForGpuRasterization());
89 TEST(PictureLayerTest
, UseTileGridSize
) {
90 LayerTreeSettings settings
;
91 settings
.default_tile_grid_size
= gfx::Size(123, 123);
93 MockContentLayerClient client
;
94 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
95 FakeLayerTreeHostClient
host_client(FakeLayerTreeHostClient::DIRECT_3D
);
96 scoped_ptr
<FakeLayerTreeHost
> host
=
97 FakeLayerTreeHost::Create(&host_client
, settings
);
98 host
->SetRootLayer(layer
);
100 // Tile-grid is set according to its setting.
101 SkTileGridFactory::TileGridInfo info
=
102 layer
->GetRecordingSourceForTesting()->GetTileGridInfoForTesting();
103 EXPECT_EQ(info
.fTileInterval
.width(), 123 - 2 * info
.fMargin
.width());
104 EXPECT_EQ(info
.fTileInterval
.height(), 123 - 2 * info
.fMargin
.height());