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