11e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
21e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
31e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// found in the LICENSE file.
41e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
51e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "cc/layers/picture_layer.h"
61e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
71e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "cc/layers/content_layer_client.h"
81e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "cc/layers/picture_layer_impl.h"
91e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "cc/resources/resource_update_queue.h"
101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "cc/test/fake_layer_tree_host.h"
111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "cc/test/fake_picture_layer_impl.h"
121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "cc/test/fake_proxy.h"
131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "cc/test/impl_side_painting_settings.h"
141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "cc/trees/occlusion_tracker.h"
1523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)#include "cc/trees/single_thread_proxy.h"
161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace cc {
191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)namespace {
201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class MockContentLayerClient : public ContentLayerClient {
221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) public:
23010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual void PaintContents(
24010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      SkCanvas* canvas,
25010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      const gfx::Rect& clip,
26010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      ContentLayerClient::GraphicsContextStatus gc_status) OVERRIDE {}
271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
28effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  virtual bool FillsBoundsCompletely() const OVERRIDE {
29effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch    return false;
30effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  };
311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)};
321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  MockContentLayerClient client;
351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  layer->SetBounds(gfx::Size(10, 10));
371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
381320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
391320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&host_client);
401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  host->SetRootLayer(layer);
411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  layer->SetIsDrawable(true);
421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  layer->SavePaintProperties();
431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
44a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  OcclusionTracker<Layer> occlusion(gfx::Rect(0, 0, 1000, 1000));
451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue);
461e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  layer->Update(queue.get(), &occlusion);
471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  layer->SetBounds(gfx::Size(0, 0));
491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  layer->SavePaintProperties();
501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Intentionally skipping Update since it would normally be skipped on
511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // a layer with empty bounds.
521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  FakeProxy proxy;
541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  {
5523730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    DebugScopedSetImplThread impl_thread(&proxy);
5623730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)
5723730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    TestSharedBitmapManager shared_bitmap_manager;
5823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    FakeLayerTreeHostImpl host_impl(
5923730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)        ImplSidePaintingSettings(), &proxy, &shared_bitmap_manager);
601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    host_impl.CreatePendingTree();
611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    scoped_ptr<FakePictureLayerImpl> layer_impl =
621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)        FakePictureLayerImpl::Create(host_impl.pending_tree(), 1);
631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    layer->PushPropertiesTo(layer_impl.get());
651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    EXPECT_FALSE(layer_impl->CanHaveTilings());
661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0));
67116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch    EXPECT_EQ(gfx::Size(), layer_impl->pile()->tiling_size());
6823730a6e56a168d1879203e4b3819bb36e3d8f1fTorne (Richard Coles)    EXPECT_FALSE(layer_impl->pile()->HasRecordings());
691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
72010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST(PictureLayerTest, SuitableForGpuRasterization) {
73a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  MockContentLayerClient client;
74a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
75a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  PicturePile* pile = layer->GetPicturePileForTesting();
76010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
77010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Layer is suitable for gpu rasterization by default.
78a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  EXPECT_TRUE(pile->is_suitable_for_gpu_rasterization());
79010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_TRUE(layer->IsSuitableForGpuRasterization());
80010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)
81010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  // Veto gpu rasterization.
82a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  pile->SetUnsuitableForGpuRasterizationForTesting();
83010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_FALSE(pile->is_suitable_for_gpu_rasterization());
84010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_FALSE(layer->IsSuitableForGpuRasterization());
85a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
86a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
87010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)TEST(PictureLayerTest, RecordingModes) {
88a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  MockContentLayerClient client;
89a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
90a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
91010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  LayerTreeSettings settings;
921320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  FakeLayerTreeHostClient host_client(FakeLayerTreeHostClient::DIRECT_3D);
931320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  scoped_ptr<FakeLayerTreeHost> host =
941320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci      FakeLayerTreeHost::Create(&host_client, settings);
95a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  host->SetRootLayer(layer);
96010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(Picture::RECORD_NORMALLY, layer->RecordingMode());
97a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
98010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  settings.recording_mode = LayerTreeSettings::RecordWithSkRecord;
991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  host = FakeLayerTreeHost::Create(&host_client, settings);
100a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch  host->SetRootLayer(layer);
101010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  EXPECT_EQ(Picture::RECORD_WITH_SKRECORD, layer->RecordingMode());
102a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch}
103a02191e04bc25c4935f804f2c080ae28663d096dBen Murdoch
1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace
1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}  // namespace cc
106