Use bucket parameter in GetIfChanged for support binaries.
[chromium-blink-merge.git] / cc / layers / picture_layer_unittest.cc
blobac20e4ca47c79ad7596ca8ea0e26571b45fa0743
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"
18 namespace cc {
19 namespace {
21 class MockContentLayerClient : public ContentLayerClient {
22 public:
23 void PaintContents(
24 SkCanvas* canvas,
25 const gfx::Rect& clip,
26 ContentLayerClient::GraphicsContextStatus gc_status) override {}
27 scoped_refptr<DisplayItemList> PaintContentsToDisplayList(
28 const gfx::Rect& clip,
29 GraphicsContextStatus gc_status) override {
30 NOTIMPLEMENTED();
31 return DisplayItemList::Create();
33 bool FillsBoundsCompletely() const override { return false; };
36 TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
37 MockContentLayerClient client;
38 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
39 layer->SetBounds(gfx::Size(10, 10));
41 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
42 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client);
43 host->SetRootLayer(layer);
44 layer->SetIsDrawable(true);
45 layer->SavePaintProperties();
47 OcclusionTracker<Layer> occlusion(gfx::Rect(0, 0, 1000, 1000));
48 scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue);
49 layer->Update(queue.get(), &occlusion);
51 EXPECT_EQ(0, host->source_frame_number());
52 host->CommitComplete();
53 EXPECT_EQ(1, host->source_frame_number());
55 layer->SetBounds(gfx::Size(0, 0));
56 layer->SavePaintProperties();
57 // Intentionally skipping Update since it would normally be skipped on
58 // a layer with empty bounds.
60 FakeProxy proxy;
62 DebugScopedSetImplThread impl_thread(&proxy);
64 TestSharedBitmapManager shared_bitmap_manager;
65 FakeLayerTreeHostImpl host_impl(
66 ImplSidePaintingSettings(), &proxy, &shared_bitmap_manager);
67 host_impl.CreatePendingTree();
68 scoped_ptr<FakePictureLayerImpl> layer_impl =
69 FakePictureLayerImpl::Create(host_impl.pending_tree(), 1);
71 layer->PushPropertiesTo(layer_impl.get());
72 EXPECT_FALSE(layer_impl->CanHaveTilings());
73 EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0));
74 EXPECT_EQ(gfx::Size(), layer_impl->raster_source()->GetSize());
75 EXPECT_FALSE(layer_impl->raster_source()->HasRecordings());
79 TEST(PictureLayerTest, SuitableForGpuRasterization) {
80 MockContentLayerClient client;
81 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
82 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
83 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client);
84 host->SetRootLayer(layer);
85 RecordingSource* recording_source = layer->GetRecordingSourceForTesting();
87 // Layer is suitable for gpu rasterization by default.
88 EXPECT_TRUE(recording_source->IsSuitableForGpuRasterization());
89 EXPECT_TRUE(layer->IsSuitableForGpuRasterization());
91 // Veto gpu rasterization.
92 recording_source->SetUnsuitableForGpuRasterizationForTesting();
93 EXPECT_FALSE(recording_source->IsSuitableForGpuRasterization());
94 EXPECT_FALSE(layer->IsSuitableForGpuRasterization());
97 TEST(PictureLayerTest, UseTileGridSize) {
98 LayerTreeSettings settings;
99 settings.default_tile_grid_size = gfx::Size(123, 123);
101 MockContentLayerClient client;
102 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
103 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
104 scoped_ptr<FakeLayerTreeHost> host =
105 FakeLayerTreeHost::Create(&host_client, settings);
106 host->SetRootLayer(layer);
108 // Tile-grid is set according to its setting.
109 SkTileGridFactory::TileGridInfo info =
110 layer->GetRecordingSourceForTesting()->GetTileGridInfoForTesting();
111 EXPECT_EQ(info.fTileInterval.width(), 123 - 2 * info.fMargin.width());
112 EXPECT_EQ(info.fTileInterval.height(), 123 - 2 * info.fMargin.height());
115 } // namespace
116 } // namespace cc