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 virtual void PaintContents(
25 const gfx::Rect
& clip
,
26 ContentLayerClient::GraphicsContextStatus gc_status
) OVERRIDE
{}
27 virtual void DidChangeLayerCanUseLCDText() OVERRIDE
{}
28 virtual bool FillsBoundsCompletely() const OVERRIDE
{
33 TEST(PictureLayerTest
, NoTilesIfEmptyBounds
) {
34 MockContentLayerClient client
;
35 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
36 layer
->SetBounds(gfx::Size(10, 10));
38 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create();
39 host
->SetRootLayer(layer
);
40 layer
->SetIsDrawable(true);
41 layer
->SavePaintProperties();
43 OcclusionTracker
<Layer
> occlusion(gfx::Rect(0, 0, 1000, 1000));
44 scoped_ptr
<ResourceUpdateQueue
> queue(new ResourceUpdateQueue
);
45 layer
->Update(queue
.get(), &occlusion
);
47 layer
->SetBounds(gfx::Size(0, 0));
48 layer
->SavePaintProperties();
49 // Intentionally skipping Update since it would normally be skipped on
50 // a layer with empty bounds.
54 DebugScopedSetImplThread
impl_thread(&proxy
);
56 TestSharedBitmapManager shared_bitmap_manager
;
57 FakeLayerTreeHostImpl
host_impl(
58 ImplSidePaintingSettings(), &proxy
, &shared_bitmap_manager
);
59 host_impl
.CreatePendingTree();
60 scoped_ptr
<FakePictureLayerImpl
> layer_impl
=
61 FakePictureLayerImpl::Create(host_impl
.pending_tree(), 1);
63 layer
->PushPropertiesTo(layer_impl
.get());
64 EXPECT_FALSE(layer_impl
->CanHaveTilings());
65 EXPECT_TRUE(layer_impl
->bounds() == gfx::Size(0, 0));
66 EXPECT_EQ(gfx::Size(), layer_impl
->pile()->tiling_size());
67 EXPECT_FALSE(layer_impl
->pile()->HasRecordings());
71 TEST(PictureLayerTest
, SuitableForGpuRasterization
) {
72 MockContentLayerClient client
;
73 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
74 PicturePile
* pile
= layer
->GetPicturePileForTesting();
76 // Layer is suitable for gpu rasterization by default.
77 EXPECT_TRUE(pile
->is_suitable_for_gpu_rasterization());
78 EXPECT_TRUE(layer
->IsSuitableForGpuRasterization());
80 // Veto gpu rasterization.
81 pile
->SetUnsuitableForGpuRasterizationForTesting();
82 EXPECT_FALSE(pile
->is_suitable_for_gpu_rasterization());
83 EXPECT_FALSE(layer
->IsSuitableForGpuRasterization());
86 TEST(PictureLayerTest
, RecordingModes
) {
87 MockContentLayerClient client
;
88 scoped_refptr
<PictureLayer
> layer
= PictureLayer::Create(&client
);
90 LayerTreeSettings settings
;
91 scoped_ptr
<FakeLayerTreeHost
> host
= FakeLayerTreeHost::Create(settings
);
92 host
->SetRootLayer(layer
);
93 EXPECT_EQ(Picture::RECORD_NORMALLY
, layer
->RecordingMode());
95 settings
.recording_mode
= LayerTreeSettings::RecordWithSkRecord
;
96 host
= FakeLayerTreeHost::Create(settings
);
97 host
->SetRootLayer(layer
);
98 EXPECT_EQ(Picture::RECORD_WITH_SKRECORD
, layer
->RecordingMode());