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

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

Issue 913133004: cc: Make PaintedScrollbarLayer not use ContentsScalingLayer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix thumb rects under device scale Created 5 years, 10 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
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 2012 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 "base/containers/hash_tables.h" 5 #include "base/containers/hash_tables.h"
6 #include "cc/animation/scrollbar_animation_controller.h" 6 #include "cc/animation/scrollbar_animation_controller.h"
7 #include "cc/layers/append_quads_data.h" 7 #include "cc/layers/append_quads_data.h"
8 #include "cc/layers/painted_scrollbar_layer.h" 8 #include "cc/layers/painted_scrollbar_layer.h"
9 #include "cc/layers/painted_scrollbar_layer_impl.h" 9 #include "cc/layers/painted_scrollbar_layer_impl.h"
10 #include "cc/layers/scrollbar_layer_interface.h" 10 #include "cc/layers/scrollbar_layer_interface.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } else { 52 } else {
53 child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1->id()); 53 child2 = PaintedScrollbarLayer::Create(scrollbar.Pass(), child1->id());
54 } 54 }
55 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); 55 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id());
56 layer_tree_root->AddChild(child1); 56 layer_tree_root->AddChild(child1);
57 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1); 57 layer_tree_root->InsertChild(child2, reverse_order ? 0 : 1);
58 host->SetRootLayer(layer_tree_root); 58 host->SetRootLayer(layer_tree_root);
59 return host->CommitAndCreateLayerImplTree(); 59 return host->CommitAndCreateLayerImplTree();
60 } 60 }
61 61
62 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) { 62 class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost {
63 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D); 63 public:
64 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client); 64 FakeResourceTrackingLayerTreeHost(FakeLayerTreeHostClient* client,
65 const LayerTreeSettings& settings)
66 : FakeLayerTreeHost(client, settings),
67 next_id_(1),
68 total_ui_resource_created_(0),
69 total_ui_resource_deleted_(0) {
70 InitializeSingleThreaded(client, base::MessageLoopProxy::current(),
71 nullptr);
72 }
73
74 UIResourceId CreateUIResource(UIResourceClient* content) override {
75 total_ui_resource_created_++;
76 UIResourceId nid = next_id_++;
77 ui_resource_bitmap_map_.insert(
78 std::make_pair(nid, content->GetBitmap(nid, false)));
79 return nid;
80 }
81
82 // Deletes a UI resource. May safely be called more than once.
83 void DeleteUIResource(UIResourceId id) override {
84 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id);
85 if (iter != ui_resource_bitmap_map_.end()) {
86 ui_resource_bitmap_map_.erase(iter);
87 total_ui_resource_deleted_++;
88 }
89 }
90
91 size_t UIResourceCount() { return ui_resource_bitmap_map_.size(); }
92 int TotalUIResourceDeleted() { return total_ui_resource_deleted_; }
93 int TotalUIResourceCreated() { return total_ui_resource_created_; }
94
95 gfx::Size ui_resource_size(UIResourceId id) {
96 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id);
97 if (iter != ui_resource_bitmap_map_.end())
98 return iter->second.GetSize();
99 return gfx::Size();
100 }
101
102 UIResourceBitmap* ui_resource_bitmap(UIResourceId id) {
103 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id);
104 if (iter != ui_resource_bitmap_map_.end())
105 return &iter->second;
106 return nullptr;
107 }
108
109 private:
110 typedef base::hash_map<UIResourceId, UIResourceBitmap> UIResourceBitmapMap;
danakj 2015/02/12 19:35:43 nit: prefer using
enne (OOO) 2015/02/12 21:55:56 Done.
111 UIResourceBitmapMap ui_resource_bitmap_map_;
112
113 int next_id_;
114 int total_ui_resource_created_;
115 int total_ui_resource_deleted_;
116 };
117
118 class ScrollbarLayerTest : public testing::Test {
119 public:
120 ScrollbarLayerTest() : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {
121 layer_tree_settings_.single_thread_proxy_scheduler = false;
122 layer_tree_host_.reset(new FakeResourceTrackingLayerTreeHost(
123 &fake_client_, layer_tree_settings_));
124 fake_client_.SetLayerTreeHost(layer_tree_host_.get());
125 // Force output surface creation for renderer capabilities.
126 layer_tree_host_->Composite(base::TimeTicks());
127 EXPECT_FALSE(layer_tree_host_->output_surface_lost());
128 }
129
130 protected:
131 FakeLayerTreeHostClient fake_client_;
132 LayerTreeSettings layer_tree_settings_;
133 scoped_ptr<FakeResourceTrackingLayerTreeHost> layer_tree_host_;
134 };
135
136 TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer) {
65 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 137 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
66 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 138 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
67 host.get(), scrollbar.Pass(), false, false, 0, 0); 139 layer_tree_host_.get(), scrollbar.Pass(), false, false, 0, 0);
68 140
69 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; 141 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0];
70 PaintedScrollbarLayerImpl* cc_child2 = 142 PaintedScrollbarLayerImpl* cc_child2 =
71 static_cast<PaintedScrollbarLayerImpl*>( 143 static_cast<PaintedScrollbarLayerImpl*>(
72 layer_impl_tree_root->children()[1]); 144 layer_impl_tree_root->children()[1]);
73 145
74 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); 146 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL);
75 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2); 147 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2);
76 } 148 }
77 149
78 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { 150 TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) {
79 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
80 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
81 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 151 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
82 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 152 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
83 host.get(), scrollbar.Pass(), true, false, 0, 0); 153 layer_tree_host_.get(), scrollbar.Pass(), true, false, 0, 0);
84 154
85 PaintedScrollbarLayerImpl* cc_child1 = 155 PaintedScrollbarLayerImpl* cc_child1 =
86 static_cast<PaintedScrollbarLayerImpl*>( 156 static_cast<PaintedScrollbarLayerImpl*>(
87 layer_impl_tree_root->children()[0]); 157 layer_impl_tree_root->children()[0]);
88 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; 158 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1];
89 159
90 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); 160 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL);
91 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1); 161 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1);
92 } 162 }
93 163
94 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { 164 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
95 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
96 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
97
98 // Create and attach a non-overlay scrollbar. 165 // Create and attach a non-overlay scrollbar.
99 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 166 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
100 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 167 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
101 host.get(), scrollbar.Pass(), false, false, 0, 0); 168 layer_tree_host_.get(), scrollbar.Pass(), false, false, 0, 0);
102 PaintedScrollbarLayerImpl* scrollbar_layer_impl = 169 PaintedScrollbarLayerImpl* scrollbar_layer_impl =
103 static_cast<PaintedScrollbarLayerImpl*>( 170 static_cast<PaintedScrollbarLayerImpl*>(
104 layer_impl_tree_root->children()[1]); 171 layer_impl_tree_root->children()[1]);
105 172
106 // When the scrollbar is not an overlay scrollbar, the scroll should be 173 // When the scrollbar is not an overlay scrollbar, the scroll should be
107 // responded to on the main thread as the compositor does not yet implement 174 // responded to on the main thread as the compositor does not yet implement
108 // scrollbar scrolling. 175 // scrollbar scrolling.
109 EXPECT_EQ(InputHandler::ScrollOnMainThread, 176 EXPECT_EQ(InputHandler::ScrollOnMainThread,
110 scrollbar_layer_impl->TryScroll( 177 scrollbar_layer_impl->TryScroll(
111 gfx::Point(0, 0), InputHandler::Gesture, ScrollBlocksOnNone)); 178 gfx::Point(0, 0), InputHandler::Gesture, ScrollBlocksOnNone));
112 179
113 // Create and attach an overlay scrollbar. 180 // Create and attach an overlay scrollbar.
114 scrollbar.reset(new FakeScrollbar(false, false, true)); 181 scrollbar.reset(new FakeScrollbar(false, false, true));
115 182
116 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 183 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
117 host.get(), scrollbar.Pass(), false, false, 0, 0); 184 layer_tree_host_.get(), scrollbar.Pass(), false, false, 0, 0);
118 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( 185 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
119 layer_impl_tree_root->children()[1]); 186 layer_impl_tree_root->children()[1]);
120 187
121 // The user shouldn't be able to drag an overlay scrollbar and the scroll 188 // The user shouldn't be able to drag an overlay scrollbar and the scroll
122 // may be handled in the compositor. 189 // may be handled in the compositor.
123 EXPECT_EQ(InputHandler::ScrollIgnored, 190 EXPECT_EQ(InputHandler::ScrollIgnored,
124 scrollbar_layer_impl->TryScroll( 191 scrollbar_layer_impl->TryScroll(
125 gfx::Point(0, 0), InputHandler::Gesture, ScrollBlocksOnNone)); 192 gfx::Point(0, 0), InputHandler::Gesture, ScrollBlocksOnNone));
126 } 193 }
127 194
128 TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) { 195 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) {
129 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
130 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
131
132 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 196 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
133 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 197 scoped_refptr<Layer> layer_tree_root = Layer::Create();
134 scoped_refptr<Layer> scroll_layer = Layer::Create(); 198 scoped_refptr<Layer> scroll_layer = Layer::Create();
135 scoped_refptr<Layer> content_layer = Layer::Create(); 199 scoped_refptr<Layer> content_layer = Layer::Create();
136 scoped_refptr<Layer> scrollbar_layer = 200 scoped_refptr<Layer> scrollbar_layer =
137 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); 201 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id());
138 202
139 // Choose bounds to give max_scroll_offset = (30, 50). 203 // Choose bounds to give max_scroll_offset = (30, 50).
140 layer_tree_root->SetBounds(gfx::Size(70, 150)); 204 layer_tree_root->SetBounds(gfx::Size(70, 150));
141 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 205 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
142 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); 206 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20));
143 scroll_layer->SetBounds(gfx::Size(100, 200)); 207 scroll_layer->SetBounds(gfx::Size(100, 200));
144 content_layer->SetBounds(gfx::Size(100, 200)); 208 content_layer->SetBounds(gfx::Size(100, 200));
145 209
146 host->SetRootLayer(layer_tree_root); 210 layer_tree_host_->SetRootLayer(layer_tree_root);
147 layer_tree_root->AddChild(scroll_layer); 211 layer_tree_root->AddChild(scroll_layer);
148 scroll_layer->AddChild(content_layer); 212 scroll_layer->AddChild(content_layer);
149 layer_tree_root->AddChild(scrollbar_layer); 213 layer_tree_root->AddChild(scrollbar_layer);
150 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 214 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
151 scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); 215 scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id());
152 216
153 layer_tree_root->SavePaintProperties(); 217 layer_tree_root->SavePaintProperties();
154 content_layer->SavePaintProperties(); 218 content_layer->SavePaintProperties();
155 219
156 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); 220 LayerImpl* layer_impl_tree_root =
221 layer_tree_host_->CommitAndCreateLayerImplTree();
157 222
158 ScrollbarLayerImplBase* cc_scrollbar_layer = 223 ScrollbarLayerImplBase* cc_scrollbar_layer =
159 static_cast<PaintedScrollbarLayerImpl*>( 224 static_cast<PaintedScrollbarLayerImpl*>(
160 layer_impl_tree_root->children()[1]); 225 layer_impl_tree_root->children()[1]);
161 226
162 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); 227 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos());
163 EXPECT_EQ(30, cc_scrollbar_layer->maximum()); 228 EXPECT_EQ(30, cc_scrollbar_layer->maximum());
164 229
165 layer_tree_root->SetBounds(gfx::Size(700, 1500)); 230 layer_tree_root->SetBounds(gfx::Size(700, 1500));
166 layer_tree_root->SavePaintProperties(); 231 layer_tree_root->SavePaintProperties();
167 scroll_layer->SetBounds(gfx::Size(1000, 2000)); 232 scroll_layer->SetBounds(gfx::Size(1000, 2000));
168 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200)); 233 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200));
169 scroll_layer->SavePaintProperties(); 234 scroll_layer->SavePaintProperties();
170 content_layer->SetBounds(gfx::Size(1000, 2000)); 235 content_layer->SetBounds(gfx::Size(1000, 2000));
171 content_layer->SavePaintProperties(); 236 content_layer->SavePaintProperties();
172 237
173 ScrollbarAnimationController* scrollbar_controller = 238 ScrollbarAnimationController* scrollbar_controller =
174 layer_impl_tree_root->scrollbar_animation_controller(); 239 layer_impl_tree_root->scrollbar_animation_controller();
175 layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); 240 layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree();
176 EXPECT_EQ(scrollbar_controller, 241 EXPECT_EQ(scrollbar_controller,
177 layer_impl_tree_root->scrollbar_animation_controller()); 242 layer_impl_tree_root->scrollbar_animation_controller());
178 243
179 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); 244 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos());
180 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); 245 EXPECT_EQ(300, cc_scrollbar_layer->maximum());
181 246
182 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; 247 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0];
183 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34)); 248 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34));
184 249
185 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); 250 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos());
186 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); 251 EXPECT_EQ(300, cc_scrollbar_layer->maximum());
187 } 252 }
188 253
189 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \ 254 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \
190 do { \ 255 do { \
191 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ 256 scrollbar_layer->UpdateInternalContentScale(); \
192 root_clip_layer_impl = host->CommitAndCreateLayerImplTree(); \ 257 scrollbar_layer->UpdateThumbAndTrackGeometry(); \
193 root_layer_impl = root_clip_layer_impl->children()[0]; \ 258 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \
194 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ 259 root_layer_impl = root_clip_layer_impl->children()[0]; \
195 root_layer_impl->children()[1]); \ 260 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \
196 scrollbar_layer_impl->ScrollbarParametersDidChange(false); \ 261 root_layer_impl->children()[1]); \
262 scrollbar_layer_impl->ScrollbarParametersDidChange(false); \
197 } while (false) 263 } while (false)
198 264
199 TEST(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { 265 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) {
200 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
201 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
202 scoped_refptr<Layer> root_clip_layer = Layer::Create(); 266 scoped_refptr<Layer> root_clip_layer = Layer::Create();
203 scoped_refptr<Layer> root_layer = Layer::Create(); 267 scoped_refptr<Layer> root_layer = Layer::Create();
204 scoped_refptr<Layer> content_layer = Layer::Create(); 268 scoped_refptr<Layer> content_layer = Layer::Create();
205 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 269 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
206 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); 270 FakePaintedScrollbarLayer::Create(false, true, root_layer->id());
207 271
208 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 272 root_layer->SetScrollClipLayerId(root_clip_layer->id());
209 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 273 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
210 root_clip_layer->SetBounds(gfx::Size(20, 50)); 274 root_clip_layer->SetBounds(gfx::Size(20, 50));
211 root_layer->SetBounds(gfx::Size(100, 50)); 275 root_layer->SetBounds(gfx::Size(100, 50));
212 content_layer->SetBounds(gfx::Size(100, 50)); 276 content_layer->SetBounds(gfx::Size(100, 50));
213 277
214 host->SetRootLayer(root_clip_layer); 278 layer_tree_host_->SetRootLayer(root_clip_layer);
215 root_clip_layer->AddChild(root_layer); 279 root_clip_layer->AddChild(root_layer);
216 root_layer->AddChild(content_layer); 280 root_layer->AddChild(content_layer);
217 root_layer->AddChild(scrollbar_layer); 281 root_layer->AddChild(scrollbar_layer);
218 282
219 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 283 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
220 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 284 scrollbar_layer->SetBounds(gfx::Size(70, 10));
221 scrollbar_layer->SetScrollLayer(root_layer->id()); 285 scrollbar_layer->SetScrollLayer(root_layer->id());
222 scrollbar_layer->SetClipLayer(root_clip_layer->id()); 286 scrollbar_layer->SetClipLayer(root_clip_layer->id());
223 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 287 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
224 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 288 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
225 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 289 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
226 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); 290 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
227
228 scrollbar_layer->UpdateThumbAndTrackGeometry();
229 LayerImpl* root_clip_layer_impl = nullptr; 291 LayerImpl* root_clip_layer_impl = nullptr;
230 LayerImpl* root_layer_impl = nullptr; 292 LayerImpl* root_layer_impl = nullptr;
231 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; 293 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr;
232 294
233 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 295 UPDATE_AND_EXTRACT_LAYER_POINTERS();
234 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), 296 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
235 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 297 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
236 298
237 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); 299 scrollbar_layer->fake_scrollbar()->set_has_thumb(false);
238 300
239 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 301 UPDATE_AND_EXTRACT_LAYER_POINTERS();
240 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), 302 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(),
241 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 303 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
242 } 304 }
243 305
244 TEST(ScrollbarLayerTest, ThumbRect) { 306 TEST_F(ScrollbarLayerTest, ThumbRect) {
245 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
246 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
247 scoped_refptr<Layer> root_clip_layer = Layer::Create(); 307 scoped_refptr<Layer> root_clip_layer = Layer::Create();
248 scoped_refptr<Layer> root_layer = Layer::Create(); 308 scoped_refptr<Layer> root_layer = Layer::Create();
249 scoped_refptr<Layer> content_layer = Layer::Create(); 309 scoped_refptr<Layer> content_layer = Layer::Create();
250 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 310 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
251 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); 311 FakePaintedScrollbarLayer::Create(false, true, root_layer->id());
252 312
253 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 313 root_layer->SetScrollClipLayerId(root_clip_layer->id());
254 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 314 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
255 root_clip_layer->SetBounds(gfx::Size(20, 50)); 315 root_clip_layer->SetBounds(gfx::Size(20, 50));
256 root_layer->SetBounds(gfx::Size(100, 50)); 316 root_layer->SetBounds(gfx::Size(100, 50));
257 content_layer->SetBounds(gfx::Size(100, 50)); 317 content_layer->SetBounds(gfx::Size(100, 50));
258 318
259 host->SetRootLayer(root_clip_layer); 319 layer_tree_host_->SetRootLayer(root_clip_layer);
260 root_clip_layer->AddChild(root_layer); 320 root_clip_layer->AddChild(root_layer);
261 root_layer->AddChild(content_layer); 321 root_layer->AddChild(content_layer);
262 root_layer->AddChild(scrollbar_layer); 322 root_layer->AddChild(scrollbar_layer);
263 323
264 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 324 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
265 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 325 scrollbar_layer->SetBounds(gfx::Size(70, 10));
266 scrollbar_layer->SetScrollLayer(root_layer->id()); 326 scrollbar_layer->SetScrollLayer(root_layer->id());
267 scrollbar_layer->SetClipLayer(root_clip_layer->id()); 327 scrollbar_layer->SetClipLayer(root_clip_layer->id());
268 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 328 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
269 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 329 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
270 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 330 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
271 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); 331 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
272 scrollbar_layer->UpdateThumbAndTrackGeometry();
273 LayerImpl* root_clip_layer_impl = nullptr; 332 LayerImpl* root_clip_layer_impl = nullptr;
274 LayerImpl* root_layer_impl = nullptr; 333 LayerImpl* root_layer_impl = nullptr;
275 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; 334 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr;
276 335
277 // Thumb is at the edge of the scrollbar (should be inset to 336 // Thumb is at the edge of the scrollbar (should be inset to
278 // the start of the track within the scrollbar layer's 337 // the start of the track within the scrollbar layer's
279 // position). 338 // position).
280 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 339 UPDATE_AND_EXTRACT_LAYER_POINTERS();
281 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), 340 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
282 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 341 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 // Shrink the track in the non-scrolling dimension so that it only covers the 374 // Shrink the track in the non-scrolling dimension so that it only covers the
316 // middle third of the scrollbar layer (this does not affect the thumb 375 // middle third of the scrollbar layer (this does not affect the thumb
317 // position). 376 // position).
318 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6)); 377 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6));
319 378
320 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 379 UPDATE_AND_EXTRACT_LAYER_POINTERS();
321 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), 380 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(),
322 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 381 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
323 } 382 }
324 383
325 TEST(ScrollbarLayerTest, SolidColorDrawQuads) { 384 // Verify that under non-1 device scales that the thumb rect is also scaled.
385 TEST_F(ScrollbarLayerTest, ThumbRectDeviceScale) {
enne (OOO) 2015/02/12 21:55:56 I removed this test in favor of adding a few rect
386 scoped_refptr<Layer> root_clip_layer = Layer::Create();
387 scoped_refptr<Layer> root_layer = Layer::Create();
388 scoped_refptr<Layer> content_layer = Layer::Create();
389 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
390 FakePaintedScrollbarLayer::Create(false, true, root_layer->id());
391
392 root_layer->SetScrollClipLayerId(root_clip_layer->id());
393 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
394 root_clip_layer->SetBounds(gfx::Size(20, 50));
395 root_layer->SetBounds(gfx::Size(100, 50));
396 content_layer->SetBounds(gfx::Size(100, 50));
397
398 layer_tree_host_->SetDeviceScaleFactor(3.f);
399 layer_tree_host_->SetRootLayer(root_clip_layer);
400 root_clip_layer->AddChild(root_layer);
401 root_layer->AddChild(content_layer);
402 root_layer->AddChild(scrollbar_layer);
403
404 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
405 scrollbar_layer->SetBounds(gfx::Size(70, 10));
406 scrollbar_layer->SetScrollLayer(root_layer->id());
407 scrollbar_layer->SetClipLayer(root_clip_layer->id());
408 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
409 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
410 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
411 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
412 LayerImpl* root_clip_layer_impl = nullptr;
413 LayerImpl* root_layer_impl = nullptr;
414 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr;
415
416 // Thumb is at the edge of the scrollbar (should be inset to
417 // the start of the track within the scrollbar layer's
418 // position).
419 UPDATE_AND_EXTRACT_LAYER_POINTERS();
420 EXPECT_EQ(gfx::Rect(30, 0, 12, 30).ToString(),
421 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
422
423 // Scroll all the way right.
424 root_layer->SetScrollOffset(gfx::ScrollOffset(80, 0));
425
426 UPDATE_AND_EXTRACT_LAYER_POINTERS();
427 EXPECT_EQ(gfx::Rect(168, 0, 12, 30).ToString(),
428 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
429
430 // Change thumb thickness and length.
431 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(4);
432 scrollbar_layer->fake_scrollbar()->set_thumb_length(6);
433
434 UPDATE_AND_EXTRACT_LAYER_POINTERS();
435 EXPECT_EQ(gfx::Rect(162, 0, 18, 12).ToString(),
436 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
437 }
438
439 TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) {
326 const int kThumbThickness = 3; 440 const int kThumbThickness = 3;
327 const int kTrackStart = 1; 441 const int kTrackStart = 1;
328 const int kTrackLength = 100; 442 const int kTrackLength = 100;
329 443
330 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
331 LayerTreeSettings layer_tree_settings;
332 scoped_ptr<FakeLayerTreeHost> host =
333 FakeLayerTreeHost::Create(&client, layer_tree_settings);
334
335 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 444 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
336 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 445 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
337 host.get(), scrollbar.Pass(), false, true, kThumbThickness, kTrackStart); 446 layer_tree_host_.get(), scrollbar.Pass(), false, true, kThumbThickness,
447 kTrackStart);
338 ScrollbarLayerImplBase* scrollbar_layer_impl = 448 ScrollbarLayerImplBase* scrollbar_layer_impl =
339 static_cast<SolidColorScrollbarLayerImpl*>( 449 static_cast<SolidColorScrollbarLayerImpl*>(
340 layer_impl_tree_root->children()[1]); 450 layer_impl_tree_root->children()[1]);
341 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); 451 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
342 scrollbar_layer_impl->SetCurrentPos(10.f); 452 scrollbar_layer_impl->SetCurrentPos(10.f);
343 scrollbar_layer_impl->SetMaximum(100); 453 scrollbar_layer_impl->SetMaximum(100);
344 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); 454 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f);
345 455
346 // Thickness should be overridden to 3. 456 // Thickness should be overridden to 3.
347 { 457 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 AppendQuadsData data; 503 AppendQuadsData data;
394 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); 504 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data);
395 505
396 const QuadList& quads = render_pass->quad_list; 506 const QuadList& quads = render_pass->quad_list;
397 ASSERT_EQ(1u, quads.size()); 507 ASSERT_EQ(1u, quads.size());
398 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); 508 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material);
399 EXPECT_EQ(gfx::Rect(1, 0, 19, 3), quads.front()->rect); 509 EXPECT_EQ(gfx::Rect(1, 0, 19, 3), quads.front()->rect);
400 } 510 }
401 } 511 }
402 512
403 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { 513 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
404 const int kThumbThickness = 3; 514 const int kThumbThickness = 3;
405 const int kTrackStart = 0; 515 const int kTrackStart = 0;
406 const int kTrackLength = 10; 516 const int kTrackLength = 10;
407 517
408 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
409 LayerTreeSettings layer_tree_settings;
410 scoped_ptr<FakeLayerTreeHost> host =
411 FakeLayerTreeHost::Create(&client, layer_tree_settings);
412
413 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 518 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
414 519
415 { 520 {
416 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 521 scoped_refptr<Layer> layer_tree_root = Layer::Create();
417 scoped_refptr<Layer> scroll_layer = Layer::Create(); 522 scoped_refptr<Layer> scroll_layer = Layer::Create();
418 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 523 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
419 scoped_refptr<Layer> child1 = Layer::Create(); 524 scoped_refptr<Layer> child1 = Layer::Create();
420 scoped_refptr<Layer> child2; 525 scoped_refptr<Layer> child2;
421 const bool kIsLeftSideVerticalScrollbar = false; 526 const bool kIsLeftSideVerticalScrollbar = false;
422 child2 = SolidColorScrollbarLayer::Create(scrollbar->Orientation(), 527 child2 = SolidColorScrollbarLayer::Create(scrollbar->Orientation(),
423 kThumbThickness, 528 kThumbThickness,
424 kTrackStart, 529 kTrackStart,
425 kIsLeftSideVerticalScrollbar, 530 kIsLeftSideVerticalScrollbar,
426 child1->id()); 531 child1->id());
427 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 532 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
428 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); 533 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id());
429 scroll_layer->AddChild(child1); 534 scroll_layer->AddChild(child1);
430 scroll_layer->InsertChild(child2, 1); 535 scroll_layer->InsertChild(child2, 1);
431 layer_tree_root->AddChild(scroll_layer); 536 layer_tree_root->AddChild(scroll_layer);
432 host->SetRootLayer(layer_tree_root); 537 layer_tree_host_->SetRootLayer(layer_tree_root);
433 } 538 }
434 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); 539 LayerImpl* layer_impl_tree_root =
540 layer_tree_host_->CommitAndCreateLayerImplTree();
435 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; 541 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0];
436 542
437 ScrollbarLayerImplBase* scrollbar_layer_impl = 543 ScrollbarLayerImplBase* scrollbar_layer_impl =
438 static_cast<PaintedScrollbarLayerImpl*>(scroll_layer_impl->children()[1]); 544 static_cast<PaintedScrollbarLayerImpl*>(scroll_layer_impl->children()[1]);
439 545
440 // Choose layer bounds to give max_scroll_offset = (8, 8). 546 // Choose layer bounds to give max_scroll_offset = (8, 8).
441 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); 547 layer_impl_tree_root->SetBounds(gfx::Size(2, 2));
442 scroll_layer_impl->SetBounds(gfx::Size(10, 10)); 548 scroll_layer_impl->SetBounds(gfx::Size(10, 10));
443 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); 549 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f));
444 550
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
571 void BeginTest() override { 677 void BeginTest() override {
572 scroll_layer_ = Layer::Create(); 678 scroll_layer_ = Layer::Create();
573 layer_tree_host()->root_layer()->AddChild(scroll_layer_); 679 layer_tree_host()->root_layer()->AddChild(scroll_layer_);
574 680
575 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 681 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
576 scrollbar_layer_ = 682 scrollbar_layer_ =
577 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_->id()); 683 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_->id());
578 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); 684 scrollbar_layer_->SetScrollLayer(scroll_layer_->id());
579 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); 685 scrollbar_layer_->SetLayerTreeHost(layer_tree_host());
580 scrollbar_layer_->SetBounds(bounds_); 686 scrollbar_layer_->SetBounds(bounds_);
687 scrollbar_layer_->SetIsDrawable(true);
581 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); 688 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_);
582 689
583 PostSetNeedsCommitToMainThread(); 690 PostSetNeedsCommitToMainThread();
584 } 691 }
585 692
586 void DidCommitAndDrawFrame() override { 693 void DidCommitAndDrawFrame() override {
587 const int kMaxTextureSize = 694 const int kMaxTextureSize =
588 layer_tree_host()->GetRendererCapabilities().max_texture_size; 695 layer_tree_host()->GetRendererCapabilities().max_texture_size;
589 696
590 // Check first that we're actually testing something. 697 // Check first that we're actually testing something.
591 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); 698 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize);
592 699
593 EXPECT_EQ(scrollbar_layer_->content_bounds().width(), 700 EXPECT_EQ(scrollbar_layer_->internal_content_bounds().width(),
594 kMaxTextureSize - 1); 701 kMaxTextureSize - 1);
595 EXPECT_EQ(scrollbar_layer_->content_bounds().height(), 702 EXPECT_EQ(scrollbar_layer_->internal_content_bounds().height(),
596 kMaxTextureSize - 1); 703 kMaxTextureSize - 1);
597 704
598 EndTest(); 705 EndTest();
599 } 706 }
600 707
601 void AfterTest() override {} 708 void AfterTest() override {}
602 709
603 private: 710 private:
604 scoped_refptr<PaintedScrollbarLayer> scrollbar_layer_; 711 scoped_refptr<PaintedScrollbarLayer> scrollbar_layer_;
605 scoped_refptr<Layer> scroll_layer_; 712 scoped_refptr<Layer> scroll_layer_;
(...skipping 11 matching lines...) Expand all
617 724
618 TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) { 725 TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) {
619 scoped_ptr<TestWebGraphicsContext3D> context = 726 scoped_ptr<TestWebGraphicsContext3D> context =
620 TestWebGraphicsContext3D::Create(); 727 TestWebGraphicsContext3D::Create();
621 int max_size = 0; 728 int max_size = 0;
622 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); 729 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
623 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); 730 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100));
624 RunTest(true, true, true); 731 RunTest(true, true, true);
625 } 732 }
626 733
627 class FakeLayerTreeHost : public LayerTreeHost { 734 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest {
628 public: 735 public:
629 FakeLayerTreeHost(FakeLayerTreeHostClient* client,
630 const LayerTreeSettings& settings)
631 : LayerTreeHost(client, nullptr, nullptr, settings),
632 next_id_(1),
633 total_ui_resource_created_(0),
634 total_ui_resource_deleted_(0) {
635 InitializeSingleThreaded(client,
636 base::MessageLoopProxy::current(),
637 nullptr);
638 }
639
640 UIResourceId CreateUIResource(UIResourceClient* content) override {
641 total_ui_resource_created_++;
642 UIResourceId nid = next_id_++;
643 ui_resource_bitmap_map_.insert(
644 std::make_pair(nid, content->GetBitmap(nid, false)));
645 return nid;
646 }
647
648 // Deletes a UI resource. May safely be called more than once.
649 void DeleteUIResource(UIResourceId id) override {
650 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id);
651 if (iter != ui_resource_bitmap_map_.end()) {
652 ui_resource_bitmap_map_.erase(iter);
653 total_ui_resource_deleted_++;
654 }
655 }
656
657 size_t UIResourceCount() { return ui_resource_bitmap_map_.size(); }
658 int TotalUIResourceDeleted() { return total_ui_resource_deleted_; }
659 int TotalUIResourceCreated() { return total_ui_resource_created_; }
660
661 gfx::Size ui_resource_size(UIResourceId id) {
662 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id);
663 if (iter != ui_resource_bitmap_map_.end())
664 return iter->second.GetSize();
665 return gfx::Size();
666 }
667
668 UIResourceBitmap* ui_resource_bitmap(UIResourceId id) {
669 UIResourceBitmapMap::iterator iter = ui_resource_bitmap_map_.find(id);
670 if (iter != ui_resource_bitmap_map_.end())
671 return &iter->second;
672 return nullptr;
673 }
674
675 private:
676 typedef base::hash_map<UIResourceId, UIResourceBitmap>
677 UIResourceBitmapMap;
678 UIResourceBitmapMap ui_resource_bitmap_map_;
679
680 int next_id_;
681 int total_ui_resource_created_;
682 int total_ui_resource_deleted_;
683 };
684
685 class ScrollbarLayerTestResourceCreationAndRelease : public testing::Test {
686 public:
687 ScrollbarLayerTestResourceCreationAndRelease()
688 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
689
690 void TestResourceUpload(int num_updates, 736 void TestResourceUpload(int num_updates,
691 size_t expected_resources, 737 size_t expected_resources,
692 int expected_created, 738 int expected_created,
693 int expected_deleted, 739 int expected_deleted,
694 bool use_solid_color_scrollbar) { 740 bool use_solid_color_scrollbar) {
695 layer_tree_host_.reset(
696 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
697
698 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); 741 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
699 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 742 scoped_refptr<Layer> layer_tree_root = Layer::Create();
700 scoped_refptr<Layer> content_layer = Layer::Create(); 743 scoped_refptr<Layer> content_layer = Layer::Create();
701 scoped_refptr<Layer> scrollbar_layer; 744 scoped_refptr<Layer> scrollbar_layer;
702 if (use_solid_color_scrollbar) { 745 if (use_solid_color_scrollbar) {
703 const int kThumbThickness = 3; 746 const int kThumbThickness = 3;
704 const int kTrackStart = 0; 747 const int kTrackStart = 0;
705 const bool kIsLeftSideVerticalScrollbar = false; 748 const bool kIsLeftSideVerticalScrollbar = false;
706 scrollbar_layer = 749 scrollbar_layer =
707 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), 750 SolidColorScrollbarLayer::Create(scrollbar->Orientation(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
742 785
743 // A non-solid-color scrollbar should have requested two textures. 786 // A non-solid-color scrollbar should have requested two textures.
744 EXPECT_EQ(expected_resources, layer_tree_host_->UIResourceCount()); 787 EXPECT_EQ(expected_resources, layer_tree_host_->UIResourceCount());
745 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); 788 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated());
746 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); 789 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted());
747 790
748 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 791 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
749 792
750 scrollbar_layer->ClearRenderSurface(); 793 scrollbar_layer->ClearRenderSurface();
751 } 794 }
752
753 protected:
754 FakeLayerTreeHostClient fake_client_;
755 LayerTreeSettings layer_tree_settings_;
756 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
757 }; 795 };
758 796
759 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, ResourceUpload) { 797 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, ResourceUpload) {
760 bool use_solid_color_scrollbars = false; 798 bool use_solid_color_scrollbars = false;
761 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); 799 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
762 int num_updates[3] = {1, 5, 10}; 800 int num_updates[3] = {1, 5, 10};
801 int created = 0;
802 int deleted = 0;
763 for (int j = 0; j < 3; j++) { 803 for (int j = 0; j < 3; j++) {
764 TestResourceUpload(num_updates[j], 804 created += num_updates[j] * 2;
765 2, 805 deleted = created - 2;
766 num_updates[j] * 2, 806 TestResourceUpload(num_updates[j], 2, created, deleted,
767 (num_updates[j] - 1) * 2,
768 use_solid_color_scrollbars); 807 use_solid_color_scrollbars);
769 } 808 }
770 } 809 }
771 810
772 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, 811 TEST_F(ScrollbarLayerTestResourceCreationAndRelease,
773 SolidColorNoResourceUpload) { 812 SolidColorNoResourceUpload) {
774 bool use_solid_color_scrollbars = true; 813 bool use_solid_color_scrollbars = true;
775 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); 814 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
776 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); 815 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars);
777 } 816 }
778 817
779 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { 818 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) {
780 FakeLayerTreeHostClient fake_client_(FakeLayerTreeHostClient::DIRECT_3D);
781 LayerTreeSettings layer_tree_settings_;
782 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
783
784 layer_tree_host_.reset(
785 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
786
787 gfx::Point scrollbar_location(0, 185); 819 gfx::Point scrollbar_location(0, 185);
788 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 820 scoped_refptr<Layer> layer_tree_root = Layer::Create();
789 scoped_refptr<Layer> content_layer = Layer::Create(); 821 scoped_refptr<Layer> content_layer = Layer::Create();
790 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 822 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
791 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); 823 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
792 824
793 layer_tree_root->AddChild(content_layer); 825 layer_tree_root->AddChild(content_layer);
794 layer_tree_root->AddChild(scrollbar_layer); 826 layer_tree_root->AddChild(scrollbar_layer);
795 827
796 layer_tree_host_->SetRootLayer(layer_tree_root); 828 layer_tree_host_->SetRootLayer(layer_tree_root);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 EXPECT_NE(0, scrollbar_layer->track_resource_id()); 943 EXPECT_NE(0, scrollbar_layer->track_resource_id());
912 EXPECT_EQ(0, scrollbar_layer->thumb_resource_id()); 944 EXPECT_EQ(0, scrollbar_layer->thumb_resource_id());
913 EXPECT_EQ(resource_count, layer_tree_host_->UIResourceCount()); 945 EXPECT_EQ(resource_count, layer_tree_host_->UIResourceCount());
914 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); 946 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated());
915 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); 947 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted());
916 948
917 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 949 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
918 scrollbar_layer->ClearRenderSurface(); 950 scrollbar_layer->ClearRenderSurface();
919 } 951 }
920 952
921 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { 953 class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest {
922 public: 954 public:
923 ScaledScrollbarLayerTestResourceCreation()
924 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
925
926 void TestResourceUpload(const float test_scale) { 955 void TestResourceUpload(const float test_scale) {
927 layer_tree_host_.reset(
928 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
929
930 gfx::Point scrollbar_location(0, 185); 956 gfx::Point scrollbar_location(0, 185);
931 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 957 scoped_refptr<Layer> layer_tree_root = Layer::Create();
932 scoped_refptr<Layer> content_layer = Layer::Create(); 958 scoped_refptr<Layer> content_layer = Layer::Create();
933 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 959 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
934 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); 960 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
935 961
936 layer_tree_root->AddChild(content_layer); 962 layer_tree_root->AddChild(content_layer);
937 layer_tree_root->AddChild(scrollbar_layer); 963 layer_tree_root->AddChild(scrollbar_layer);
938 964
939 layer_tree_host_->SetRootLayer(layer_tree_root); 965 layer_tree_host_->SetRootLayer(layer_tree_root);
(...skipping 29 matching lines...) Expand all
969 scrollbar_layer->Update(&queue, &occlusion_tracker); 995 scrollbar_layer->Update(&queue, &occlusion_tracker);
970 996
971 // Verify that we have not generated any content uploads that are larger 997 // Verify that we have not generated any content uploads that are larger
972 // than their destination textures. 998 // than their destination textures.
973 999
974 gfx::Size track_size = layer_tree_host_->ui_resource_size( 1000 gfx::Size track_size = layer_tree_host_->ui_resource_size(
975 scrollbar_layer->track_resource_id()); 1001 scrollbar_layer->track_resource_id());
976 gfx::Size thumb_size = layer_tree_host_->ui_resource_size( 1002 gfx::Size thumb_size = layer_tree_host_->ui_resource_size(
977 scrollbar_layer->thumb_resource_id()); 1003 scrollbar_layer->thumb_resource_id());
978 1004
979 EXPECT_LE(track_size.width(), scrollbar_layer->content_bounds().width()); 1005 EXPECT_LE(track_size.width(),
980 EXPECT_LE(track_size.height(), scrollbar_layer->content_bounds().height()); 1006 scrollbar_layer->internal_content_bounds().width());
981 EXPECT_LE(thumb_size.width(), scrollbar_layer->content_bounds().width()); 1007 EXPECT_LE(track_size.height(),
982 EXPECT_LE(thumb_size.height(), scrollbar_layer->content_bounds().height()); 1008 scrollbar_layer->internal_content_bounds().height());
1009 EXPECT_LE(thumb_size.width(),
1010 scrollbar_layer->internal_content_bounds().width());
1011 EXPECT_LE(thumb_size.height(),
1012 scrollbar_layer->internal_content_bounds().height());
983 1013
984 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 1014 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
985 1015
986 scrollbar_layer->ClearRenderSurface(); 1016 scrollbar_layer->ClearRenderSurface();
987 } 1017 }
988
989 protected:
990 FakeLayerTreeHostClient fake_client_;
991 LayerTreeSettings layer_tree_settings_;
992 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
993 }; 1018 };
994 1019
995 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { 1020 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
996 // Pick a test scale that moves the scrollbar's (non-zero) position to 1021 // Pick a test scale that moves the scrollbar's (non-zero) position to
997 // a non-pixel-aligned location. 1022 // a non-pixel-aligned location.
998 TestResourceUpload(.041f); 1023 TestResourceUpload(.041f);
999 TestResourceUpload(1.41f); 1024 TestResourceUpload(1.41f);
1000 TestResourceUpload(4.1f); 1025 TestResourceUpload(4.1f);
1001 } 1026 }
1002 1027
1003 class ScaledScrollbarLayerTestScaledRasterization : public testing::Test { 1028 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest {
1004 public: 1029 public:
1005 ScaledScrollbarLayerTestScaledRasterization()
1006 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
1007
1008 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { 1030 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) {
1009 layer_tree_host_.reset(
1010 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
1011
1012 bool paint_during_update = true; 1031 bool paint_during_update = true;
1013 bool has_thumb = false; 1032 bool has_thumb = false;
1014 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 1033 scoped_refptr<Layer> layer_tree_root = Layer::Create();
1015 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 1034 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
1016 FakePaintedScrollbarLayer::Create(paint_during_update, 1035 FakePaintedScrollbarLayer::Create(paint_during_update,
1017 has_thumb, 1036 has_thumb,
1018 layer_tree_root->id()); 1037 layer_tree_root->id());
1019 1038
1020 layer_tree_root->AddChild(scrollbar_layer); 1039 layer_tree_root->AddChild(scrollbar_layer);
1021 1040
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 } 1094 }
1076 1095
1077 protected: 1096 protected:
1078 // On Android, Skia uses ABGR 1097 // On Android, Skia uses ABGR
1079 static SkColor argb_to_skia(SkColor c) { 1098 static SkColor argb_to_skia(SkColor c) {
1080 return (SkColorGetA(c) << SK_A32_SHIFT) | 1099 return (SkColorGetA(c) << SK_A32_SHIFT) |
1081 (SkColorGetR(c) << SK_R32_SHIFT) | 1100 (SkColorGetR(c) << SK_R32_SHIFT) |
1082 (SkColorGetG(c) << SK_G32_SHIFT) | 1101 (SkColorGetG(c) << SK_G32_SHIFT) |
1083 (SkColorGetB(c) << SK_B32_SHIFT); 1102 (SkColorGetB(c) << SK_B32_SHIFT);
1084 } 1103 }
1085
1086 FakeLayerTreeHostClient fake_client_;
1087 LayerTreeSettings layer_tree_settings_;
1088 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
1089 }; 1104 };
1090 1105
1091 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) { 1106 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) {
1092 // Try rasterization at coordinates and scale that caused problematic 1107 // Try rasterization at coordinates and scale that caused problematic
1093 // rounding and clipping errors. 1108 // rounding and clipping errors.
1094 // Vertical Scrollbars. 1109 // Vertical Scrollbars.
1095 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); 1110 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
1096 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); 1111 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
1097 1112
1098 // Horizontal Scrollbars. 1113 // Horizontal Scrollbars.
1099 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); 1114 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
1100 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); 1115 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
1101 } 1116 }
1102 1117
1103 } // namespace 1118 } // namespace
1104 } // namespace cc 1119 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698