• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "testing/gtest/include/gtest/gtest.h"
16 
17 namespace cc {
18 namespace {
19 
20 class MockContentLayerClient : public ContentLayerClient {
21  public:
PaintContents(SkCanvas * canvas,gfx::Rect clip,gfx::RectF * opaque)22   virtual void PaintContents(SkCanvas* canvas,
23                              gfx::Rect clip,
24                              gfx::RectF* opaque) OVERRIDE {}
DidChangeLayerCanUseLCDText()25   virtual void DidChangeLayerCanUseLCDText() OVERRIDE {}
26 };
27 
TEST(PictureLayerTest,NoTilesIfEmptyBounds)28 TEST(PictureLayerTest, NoTilesIfEmptyBounds) {
29   MockContentLayerClient client;
30   scoped_refptr<PictureLayer> layer = PictureLayer::Create(&client);
31   layer->SetBounds(gfx::Size(10, 10));
32 
33   scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create();
34   host->SetRootLayer(layer);
35   layer->SetIsDrawable(true);
36   layer->SavePaintProperties();
37 
38   OcclusionTracker occlusion(gfx::Rect(0, 0, 1000, 1000), false);
39   scoped_ptr<ResourceUpdateQueue> queue(new ResourceUpdateQueue);
40   layer->Update(queue.get(), &occlusion);
41 
42   layer->SetBounds(gfx::Size(0, 0));
43   layer->SavePaintProperties();
44   // Intentionally skipping Update since it would normally be skipped on
45   // a layer with empty bounds.
46 
47   FakeProxy proxy;
48 #ifndef NDEBUG
49   proxy.SetCurrentThreadIsImplThread(true);
50 #endif
51   {
52     FakeLayerTreeHostImpl host_impl(ImplSidePaintingSettings(), &proxy);
53     host_impl.CreatePendingTree();
54     scoped_ptr<FakePictureLayerImpl> layer_impl =
55         FakePictureLayerImpl::Create(host_impl.pending_tree(), 1);
56 
57     layer->PushPropertiesTo(layer_impl.get());
58     EXPECT_FALSE(layer_impl->CanHaveTilings());
59     EXPECT_TRUE(layer_impl->bounds() == gfx::Size(0, 0));
60     EXPECT_TRUE(layer_impl->pile()->size() == gfx::Size(0, 0));
61     EXPECT_FALSE(layer_impl->pile()->HasRecordings());
62   }
63 #ifndef NDEBUG
64   proxy.SetCurrentThreadIsImplThread(false);
65 #endif
66 }
67 
68 }  // namespace
69 }  // namespace cc
70