• 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/ui_resource_layer.h"
6 
7 #include "cc/resources/prioritized_resource_manager.h"
8 #include "cc/resources/resource_provider.h"
9 #include "cc/resources/resource_update_queue.h"
10 #include "cc/resources/scoped_ui_resource.h"
11 #include "cc/test/fake_layer_tree_host.h"
12 #include "cc/test/fake_layer_tree_host_client.h"
13 #include "cc/test/fake_output_surface.h"
14 #include "cc/test/fake_output_surface_client.h"
15 #include "cc/test/geometry_test_utils.h"
16 #include "cc/trees/layer_tree_host.h"
17 #include "cc/trees/occlusion_tracker.h"
18 #include "cc/trees/single_thread_proxy.h"
19 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/skia/include/core/SkBitmap.h"
22 
23 using ::testing::Mock;
24 using ::testing::_;
25 using ::testing::AtLeast;
26 using ::testing::AnyNumber;
27 
28 namespace cc {
29 namespace {
30 
31 class UIResourceLayerTest : public testing::Test {
32  public:
UIResourceLayerTest()33   UIResourceLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
34 
35  protected:
SetUp()36   virtual void SetUp() {
37     layer_tree_host_ = FakeLayerTreeHost::Create(&fake_client_);
38     layer_tree_host_->InitializeSingleThreaded(
39         &fake_client_, base::MessageLoopProxy::current());
40   }
41 
TearDown()42   virtual void TearDown() {
43     Mock::VerifyAndClearExpectations(layer_tree_host_.get());
44   }
45 
46   FakeLayerTreeHostClient fake_client_;
47   scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
48 };
49 
TEST_F(UIResourceLayerTest,SetBitmap)50 TEST_F(UIResourceLayerTest, SetBitmap) {
51   scoped_refptr<UIResourceLayer> test_layer = UIResourceLayer::Create();
52   ASSERT_TRUE(test_layer.get());
53   test_layer->SetIsDrawable(true);
54   test_layer->SetBounds(gfx::Size(100, 100));
55 
56   layer_tree_host_->SetRootLayer(test_layer);
57   Mock::VerifyAndClearExpectations(layer_tree_host_.get());
58   EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
59 
60   ResourceUpdateQueue queue;
61   gfx::Rect screen_space_clip_rect;
62   OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect);
63   test_layer->SavePaintProperties();
64   test_layer->Update(&queue, &occlusion_tracker);
65 
66   EXPECT_FALSE(test_layer->DrawsContent());
67 
68   SkBitmap bitmap;
69   bitmap.allocN32Pixels(10, 10);
70   bitmap.setImmutable();
71 
72   test_layer->SetBitmap(bitmap);
73   test_layer->Update(&queue, &occlusion_tracker);
74 
75   EXPECT_TRUE(test_layer->DrawsContent());
76 }
77 
TEST_F(UIResourceLayerTest,SetUIResourceId)78 TEST_F(UIResourceLayerTest, SetUIResourceId) {
79   scoped_refptr<UIResourceLayer> test_layer = UIResourceLayer::Create();
80   ASSERT_TRUE(test_layer.get());
81   test_layer->SetIsDrawable(true);
82   test_layer->SetBounds(gfx::Size(100, 100));
83 
84   layer_tree_host_->SetRootLayer(test_layer);
85   Mock::VerifyAndClearExpectations(layer_tree_host_.get());
86   EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
87 
88   ResourceUpdateQueue queue;
89   gfx::Rect screen_space_clip_rect;
90   OcclusionTracker<Layer> occlusion_tracker(screen_space_clip_rect);
91   test_layer->SavePaintProperties();
92   test_layer->Update(&queue, &occlusion_tracker);
93 
94   EXPECT_FALSE(test_layer->DrawsContent());
95 
96   bool is_opaque = false;
97   scoped_ptr<ScopedUIResource> resource = ScopedUIResource::Create(
98       layer_tree_host_.get(), UIResourceBitmap(gfx::Size(10, 10), is_opaque));
99   test_layer->SetUIResourceId(resource->id());
100   test_layer->Update(&queue, &occlusion_tracker);
101 
102   EXPECT_TRUE(test_layer->DrawsContent());
103 }
104 
105 }  // namespace
106 }  // namespace cc
107