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

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

Issue 2322943003: cc: Move UI Resource management out of LayerTreeHost. (Closed)
Patch Set: virtual dtor Created 4 years, 3 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/resources/scoped_ui_resource.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/threading/thread_task_runner_handle.h" 7 #include "base/threading/thread_task_runner_handle.h"
8 #include "cc/resources/resource_provider.h" 8 #include "cc/resources/resource_provider.h"
9 #include "cc/resources/scoped_ui_resource.h" 9 #include "cc/resources/scoped_ui_resource.h"
10 #include "cc/test/fake_layer_tree_host.h" 10 #include "cc/test/fake_layer_tree_host.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 layer_tree_host_->SetRootLayer(test_layer); 96 layer_tree_host_->SetRootLayer(test_layer);
97 Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 97 Mock::VerifyAndClearExpectations(layer_tree_host_.get());
98 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get()); 98 EXPECT_EQ(test_layer->layer_tree_host(), layer_tree_host_.get());
99 99
100 test_layer->SavePaintProperties(); 100 test_layer->SavePaintProperties();
101 test_layer->Update(); 101 test_layer->Update();
102 102
103 EXPECT_FALSE(test_layer->DrawsContent()); 103 EXPECT_FALSE(test_layer->DrawsContent());
104 104
105 bool is_opaque = false; 105 bool is_opaque = false;
106 std::unique_ptr<ScopedUIResource> resource = ScopedUIResource::Create( 106 std::unique_ptr<ScopedUIResource> resource =
107 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(10, 10), is_opaque)); 107 ScopedUIResource::Create(layer_tree_host_->GetUIResourceManager(),
108 UIResourceBitmap(gfx::Size(10, 10), is_opaque));
108 test_layer->SetUIResourceId(resource->id()); 109 test_layer->SetUIResourceId(resource->id());
109 test_layer->Update(); 110 test_layer->Update();
110 111
111 EXPECT_TRUE(test_layer->DrawsContent()); 112 EXPECT_TRUE(test_layer->DrawsContent());
112 113
113 // ID is preserved even when you set ID first and attach it to the tree. 114 // ID is preserved even when you set ID first and attach it to the tree.
114 layer_tree_host_->SetRootLayer(nullptr); 115 layer_tree_host_->SetRootLayer(nullptr);
115 std::unique_ptr<ScopedUIResource> shared_resource = ScopedUIResource::Create( 116 std::unique_ptr<ScopedUIResource> shared_resource =
116 layer_tree_host_.get(), UIResourceBitmap(gfx::Size(5, 5), is_opaque)); 117 ScopedUIResource::Create(layer_tree_host_->GetUIResourceManager(),
118 UIResourceBitmap(gfx::Size(5, 5), is_opaque));
117 test_layer->SetUIResourceId(shared_resource->id()); 119 test_layer->SetUIResourceId(shared_resource->id());
118 layer_tree_host_->SetRootLayer(test_layer); 120 layer_tree_host_->SetRootLayer(test_layer);
119 EXPECT_EQ(shared_resource->id(), test_layer->GetUIResourceId()); 121 EXPECT_EQ(shared_resource->id(), test_layer->GetUIResourceId());
120 EXPECT_TRUE(test_layer->DrawsContent()); 122 EXPECT_TRUE(test_layer->DrawsContent());
121 } 123 }
122 124
123 TEST_F(UIResourceLayerTest, BitmapClearedOnSetUIResourceId) { 125 TEST_F(UIResourceLayerTest, BitmapClearedOnSetUIResourceId) {
124 scoped_refptr<UIResourceLayer> test_layer = TestUIResourceLayer::Create(); 126 scoped_refptr<UIResourceLayer> test_layer = TestUIResourceLayer::Create();
125 ASSERT_TRUE(test_layer.get()); 127 ASSERT_TRUE(test_layer.get());
126 test_layer->SetBounds(gfx::Size(100, 100)); 128 test_layer->SetBounds(gfx::Size(100, 100));
127 129
128 SkBitmap bitmap; 130 SkBitmap bitmap;
129 bitmap.allocN32Pixels(10, 10); 131 bitmap.allocN32Pixels(10, 10);
130 bitmap.setImmutable(); 132 bitmap.setImmutable();
131 ASSERT_FALSE(bitmap.isNull()); 133 ASSERT_FALSE(bitmap.isNull());
132 ASSERT_TRUE(bitmap.pixelRef()->unique()); 134 ASSERT_TRUE(bitmap.pixelRef()->unique());
133 135
134 test_layer->SetBitmap(bitmap); 136 test_layer->SetBitmap(bitmap);
135 ASSERT_FALSE(bitmap.pixelRef()->unique()); 137 ASSERT_FALSE(bitmap.pixelRef()->unique());
136 138
137 test_layer->SetUIResourceId(0); 139 test_layer->SetUIResourceId(0);
138 EXPECT_TRUE(bitmap.pixelRef()->unique()); 140 EXPECT_TRUE(bitmap.pixelRef()->unique());
139 } 141 }
140 142
141 } // namespace 143 } // namespace
142 } // namespace cc 144 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/ui_resource_layer.cc ('k') | cc/resources/scoped_ui_resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698