Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: cc/layers/ui_resource_layer_unittest.cc

Issue 1783613004: CC Animation: Erase cc::LayerSettings everywhere. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@eraseandroid
Patch Set: Rebase. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « cc/layers/ui_resource_layer.cc ('k') | cc/layers/video_layer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "cc/layers/ui_resource_layer.h" 5 #include "cc/layers/ui_resource_layer.h"
6 6
7 #include "base/thread_task_runner_handle.h" 7 #include "base/thread_task_runner_handle.h"
8 #include "cc/layers/layer_settings.h"
9 #include "cc/resources/resource_provider.h" 8 #include "cc/resources/resource_provider.h"
10 #include "cc/resources/scoped_ui_resource.h" 9 #include "cc/resources/scoped_ui_resource.h"
11 #include "cc/test/fake_layer_tree_host.h" 10 #include "cc/test/fake_layer_tree_host.h"
12 #include "cc/test/fake_layer_tree_host_client.h" 11 #include "cc/test/fake_layer_tree_host_client.h"
13 #include "cc/test/fake_output_surface.h" 12 #include "cc/test/fake_output_surface.h"
14 #include "cc/test/fake_output_surface_client.h" 13 #include "cc/test/fake_output_surface_client.h"
15 #include "cc/test/geometry_test_utils.h" 14 #include "cc/test/geometry_test_utils.h"
16 #include "cc/test/test_task_graph_runner.h" 15 #include "cc/test/test_task_graph_runner.h"
17 #include "cc/trees/layer_tree_host.h" 16 #include "cc/trees/layer_tree_host.h"
18 #include "cc/trees/single_thread_proxy.h" 17 #include "cc/trees/single_thread_proxy.h"
19 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
20 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
21 #include "third_party/skia/include/core/SkBitmap.h" 20 #include "third_party/skia/include/core/SkBitmap.h"
22 21
23 using ::testing::Mock; 22 using ::testing::Mock;
24 using ::testing::_; 23 using ::testing::_;
25 using ::testing::AtLeast; 24 using ::testing::AtLeast;
26 using ::testing::AnyNumber; 25 using ::testing::AnyNumber;
27 26
28 namespace cc { 27 namespace cc {
29 namespace { 28 namespace {
30 29
31 class TestUIResourceLayer : public UIResourceLayer { 30 class TestUIResourceLayer : public UIResourceLayer {
32 public: 31 public:
33 static scoped_refptr<TestUIResourceLayer> Create( 32 static scoped_refptr<TestUIResourceLayer> Create() {
34 const LayerSettings& settings) { 33 return make_scoped_refptr(new TestUIResourceLayer());
35 return make_scoped_refptr(new TestUIResourceLayer(settings));
36 } 34 }
37 35
38 UIResourceId GetUIResourceId() { 36 UIResourceId GetUIResourceId() {
39 if (ui_resource_holder_) 37 if (ui_resource_holder_)
40 return ui_resource_holder_->id(); 38 return ui_resource_holder_->id();
41 return 0; 39 return 0;
42 } 40 }
43 41
44 protected: 42 protected:
45 explicit TestUIResourceLayer(const LayerSettings& settings) 43 TestUIResourceLayer() : UIResourceLayer() { SetIsDrawable(true); }
46 : UIResourceLayer(settings) {
47 SetIsDrawable(true);
48 }
49 ~TestUIResourceLayer() override {} 44 ~TestUIResourceLayer() override {}
50 }; 45 };
51 46
52 class UIResourceLayerTest : public testing::Test { 47 class UIResourceLayerTest : public testing::Test {
53 public: 48 public:
54 UIResourceLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} 49 UIResourceLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
55 50
56 protected: 51 protected:
57 void SetUp() override { 52 void SetUp() override {
58 layer_tree_host_ = 53 layer_tree_host_ =
59 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_); 54 FakeLayerTreeHost::Create(&fake_client_, &task_graph_runner_);
60 layer_tree_host_->InitializeSingleThreaded( 55 layer_tree_host_->InitializeSingleThreaded(
61 &fake_client_, base::ThreadTaskRunnerHandle::Get(), nullptr); 56 &fake_client_, base::ThreadTaskRunnerHandle::Get(), nullptr);
62 } 57 }
63 58
64 void TearDown() override { 59 void TearDown() override {
65 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 60 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
66 } 61 }
67 62
68 FakeLayerTreeHostClient fake_client_; 63 FakeLayerTreeHostClient fake_client_;
69 TestTaskGraphRunner task_graph_runner_; 64 TestTaskGraphRunner task_graph_runner_;
70 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; 65 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
71 LayerSettings layer_settings_;
72 }; 66 };
73 67
74 TEST_F(UIResourceLayerTest, SetBitmap) { 68 TEST_F(UIResourceLayerTest, SetBitmap) {
75 scoped_refptr<UIResourceLayer> test_layer = 69 scoped_refptr<UIResourceLayer> test_layer = TestUIResourceLayer::Create();
76 TestUIResourceLayer::Create(layer_settings_);
77 ASSERT_TRUE(test_layer.get()); 70 ASSERT_TRUE(test_layer.get());
78 test_layer->SetBounds(gfx::Size(100, 100)); 71 test_layer->SetBounds(gfx::Size(100, 100));
79 72
80 layer_tree_host_->SetRootLayer(test_layer); 73 layer_tree_host_->SetRootLayer(test_layer);
81 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 74 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
82 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); 75 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
83 76
84 test_layer->SavePaintProperties(); 77 test_layer->SavePaintProperties();
85 test_layer->Update(); 78 test_layer->Update();
86 79
87 EXPECT_FALSE(test_layer->DrawsContent()); 80 EXPECT_FALSE(test_layer->DrawsContent());
88 81
89 SkBitmap bitmap; 82 SkBitmap bitmap;
90 bitmap.allocN32Pixels(10, 10); 83 bitmap.allocN32Pixels(10, 10);
91 bitmap.setImmutable(); 84 bitmap.setImmutable();
92 85
93 test_layer->SetBitmap(bitmap); 86 test_layer->SetBitmap(bitmap);
94 test_layer->Update(); 87 test_layer->Update();
95 88
96 EXPECT_TRUE(test_layer->DrawsContent()); 89 EXPECT_TRUE(test_layer->DrawsContent());
97 } 90 }
98 91
99 TEST_F(UIResourceLayerTest, SetUIResourceId) { 92 TEST_F(UIResourceLayerTest, SetUIResourceId) {
100 scoped_refptr<TestUIResourceLayer> test_layer = 93 scoped_refptr<TestUIResourceLayer> test_layer = TestUIResourceLayer::Create();
101 TestUIResourceLayer::Create(layer_settings_);
102 ASSERT_TRUE(test_layer.get()); 94 ASSERT_TRUE(test_layer.get());
103 test_layer->SetBounds(gfx::Size(100, 100)); 95 test_layer->SetBounds(gfx::Size(100, 100));
104 96
105 layer_tree_host_->SetRootLayer(test_layer); 97 layer_tree_host_->SetRootLayer(test_layer);
106 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 98 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
107 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); 99 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
108 100
109 test_layer->SavePaintProperties(); 101 test_layer->SavePaintProperties();
110 test_layer->Update(); 102 test_layer->Update();
111 103
(...skipping 11 matching lines...) Expand all
123 layer_tree_host_->SetRootLayer(nullptr); 115 layer_tree_host_->SetRootLayer(nullptr);
124 scoped_ptr<ScopedUIResource> shared_resource = ScopedUIResource::Create( 116 scoped_ptr<ScopedUIResource> shared_resource = ScopedUIResource::Create(
125 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(5, 5), is_opaque)); 117 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(5, 5), is_opaque));
126 test_layer->SetUIResourceId(shared_resource->id()); 118 test_layer->SetUIResourceId(shared_resource->id());
127 layer_tree_host_->SetRootLayer(test_layer); 119 layer_tree_host_->SetRootLayer(test_layer);
128 EXPECT_EQ(shared_resource->id(), test_layer->GetUIResourceId()); 120 EXPECT_EQ(shared_resource->id(), test_layer->GetUIResourceId());
129 EXPECT_TRUE(test_layer->DrawsContent()); 121 EXPECT_TRUE(test_layer->DrawsContent());
130 } 122 }
131 123
132 TEST_F(UIResourceLayerTest, BitmapClearedOnSetUIResourceId) { 124 TEST_F(UIResourceLayerTest, BitmapClearedOnSetUIResourceId) {
133 scoped_refptr<UIResourceLayer> test_layer = 125 scoped_refptr<UIResourceLayer> test_layer = TestUIResourceLayer::Create();
134 TestUIResourceLayer::Create(layer_settings_);
135 ASSERT_TRUE(test_layer.get()); 126 ASSERT_TRUE(test_layer.get());
136 test_layer->SetBounds(gfx::Size(100, 100)); 127 test_layer->SetBounds(gfx::Size(100, 100));
137 128
138 SkBitmap bitmap; 129 SkBitmap bitmap;
139 bitmap.allocN32Pixels(10, 10); 130 bitmap.allocN32Pixels(10, 10);
140 bitmap.setImmutable(); 131 bitmap.setImmutable();
141 ASSERT_FALSE(bitmap.isNull()); 132 ASSERT_FALSE(bitmap.isNull());
142 ASSERT_TRUE(bitmap.pixelRef()->unique()); 133 ASSERT_TRUE(bitmap.pixelRef()->unique());
143 134
144 test_layer->SetBitmap(bitmap); 135 test_layer->SetBitmap(bitmap);
145 ASSERT_FALSE(bitmap.pixelRef()->unique()); 136 ASSERT_FALSE(bitmap.pixelRef()->unique());
146 137
147 test_layer->SetUIResourceId(0); 138 test_layer->SetUIResourceId(0);
148 EXPECT_TRUE(bitmap.pixelRef()->unique()); 139 EXPECT_TRUE(bitmap.pixelRef()->unique());
149 } 140 }
150 141
151 } // namespace 142 } // namespace
152 } // namespace cc 143 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/ui_resource_layer.cc ('k') | cc/layers/video_layer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698