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