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. 4 5 #include "cc/layers/picture_layer.h" 6 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" 17 18 namespace cc { 19 namespace { 20 21 class MockContentLayerClient : public ContentLayerClient { 22 public: 23 virtual void PaintContents( 24 SkCanvas* canvas, 25 const gfx::Rect& clip, 26 ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {} 27 virtual void DidChangeLayerCanUseLCDText() OVERRIDE {} 28 virtual bool FillsBoundsCompletely() const OVERRIDE { 29 return false; 30 }; 31 }; 32 33 TEST(PictureLayerTest, NoTilesIfEmptyBounds) { 34 MockContentLayerClient client; 35 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); 36 layer->SetBounds(gfx::Size(10, 10)); 37 38 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 39 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client); 40 host->SetRootLayer(layer); 41 layer->SetIsDrawable(true); 42 layer->SavePaintProperties(); 43 44 OcclusionTracker<Layer> occlusion(gfx::Rect(0, 0, 1000, 1000)); 45 scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue); 46 layer->Update(queue.get(), &occlusion); 47 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. 52 53 FakeProxy proxy; 54 { 55 DebugScopedSetImplThread impl_thread(&proxy); 56 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); 63 64 layer->PushPropertiesTo(layer_impl.get()); 65 EXPECT_FALSE(layer_impl->CanHaveTilings()); 66 EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0)); 67 EXPECT_EQ(gfx::Size(), layer_impl->pile()->tiling_size()); 68 EXPECT_FALSE(layer_impl->pile()->HasRecordings()); 69 } 70 } 71 72 TEST(PictureLayerTest, SuitableForGpuRasterization) { 73 MockContentLayerClient client; 74 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); 75 PicturePile* pile = layer->GetPicturePileForTesting(); 76 77 // Layer is suitable for gpu rasterization by default. 78 EXPECT_TRUE(pile->is_suitable_for_gpu_rasterization()); 79 EXPECT_TRUE(layer->IsSuitableForGpuRasterization()); 80 81 // Veto gpu rasterization. 82 pile->SetUnsuitableForGpuRasterizationForTesting(); 83 EXPECT_FALSE(pile->is_suitable_for_gpu_rasterization()); 84 EXPECT_FALSE(layer->IsSuitableForGpuRasterization()); 85 } 86 87 TEST(PictureLayerTest, RecordingModes) { 88 MockContentLayerClient client; 89 scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client); 90 91 LayerTreeSettings settings; 92 FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D); 93 scoped_ptr<FakeLayerTreeHost> host = 94 FakeLayerTreeHost::Create(&host_client, settings); 95 host->SetRootLayer(layer); 96 EXPECT_EQ(Picture::RECORD_NORMALLY, layer->RecordingMode()); 97 98 settings.recording_mode = LayerTreeSettings::RecordWithSkRecord; 99 host = FakeLayerTreeHost::Create(&host_client, settings); 100 host->SetRootLayer(layer); 101 EXPECT_EQ(Picture::RECORD_WITH_SKRECORD, layer->RecordingMode()); 102 } 103 104 } // namespace 105 } // namespace cc 106