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

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

Issue 913393004: Revert of cc: Make PaintedScrollbarLayer not use ContentsScalingLayer (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « cc/layers/scrollbar_layer_impl_base.h ('k') | cc/test/fake_layer_tree_host.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 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 class FakeResourceTrackingLayerTreeHost : public FakeLayerTreeHost { 62 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer) {
63 public: 63 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
64 FakeResourceTrackingLayerTreeHost(FakeLayerTreeHostClient* client, 64 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&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 using UIResourceBitmapMap = base::hash_map<UIResourceId, UIResourceBitmap>;
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) {
137 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 65 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
138 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 66 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
139 layer_tree_host_.get(), scrollbar.Pass(), false, false, 0, 0); 67 host.get(), scrollbar.Pass(), false, false, 0, 0);
140 68
141 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0]; 69 LayerImpl* cc_child1 = layer_impl_tree_root->children()[0];
142 PaintedScrollbarLayerImpl* cc_child2 = 70 PaintedScrollbarLayerImpl* cc_child2 =
143 static_cast<PaintedScrollbarLayerImpl*>( 71 static_cast<PaintedScrollbarLayerImpl*>(
144 layer_impl_tree_root->children()[1]); 72 layer_impl_tree_root->children()[1]);
145 73
146 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL); 74 EXPECT_EQ(cc_child1->scrollbars()->size(), 1UL);
147 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2); 75 EXPECT_EQ(*(cc_child1->scrollbars()->begin()), cc_child2);
148 } 76 }
149 77
150 TEST_F(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) { 78 TEST(ScrollbarLayerTest, ResolveScrollLayerPointer_ReverseOrder) {
79 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
80 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
151 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 81 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
152 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 82 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
153 layer_tree_host_.get(), scrollbar.Pass(), true, false, 0, 0); 83 host.get(), scrollbar.Pass(), true, false, 0, 0);
154 84
155 PaintedScrollbarLayerImpl* cc_child1 = 85 PaintedScrollbarLayerImpl* cc_child1 =
156 static_cast<PaintedScrollbarLayerImpl*>( 86 static_cast<PaintedScrollbarLayerImpl*>(
157 layer_impl_tree_root->children()[0]); 87 layer_impl_tree_root->children()[0]);
158 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1]; 88 LayerImpl* cc_child2 = layer_impl_tree_root->children()[1];
159 89
160 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL); 90 EXPECT_EQ(cc_child2->scrollbars()->size(), 1UL);
161 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1); 91 EXPECT_EQ(*(cc_child2->scrollbars()->begin()), cc_child1);
162 } 92 }
163 93
164 TEST_F(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) { 94 TEST(ScrollbarLayerTest, ShouldScrollNonOverlayOnMainThread) {
95 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
96 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
97
165 // Create and attach a non-overlay scrollbar. 98 // Create and attach a non-overlay scrollbar.
166 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 99 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
167 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 100 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
168 layer_tree_host_.get(), scrollbar.Pass(), false, false, 0, 0); 101 host.get(), scrollbar.Pass(), false, false, 0, 0);
169 PaintedScrollbarLayerImpl* scrollbar_layer_impl = 102 PaintedScrollbarLayerImpl* scrollbar_layer_impl =
170 static_cast<PaintedScrollbarLayerImpl*>( 103 static_cast<PaintedScrollbarLayerImpl*>(
171 layer_impl_tree_root->children()[1]); 104 layer_impl_tree_root->children()[1]);
172 105
173 // When the scrollbar is not an overlay scrollbar, the scroll should be 106 // When the scrollbar is not an overlay scrollbar, the scroll should be
174 // responded to on the main thread as the compositor does not yet implement 107 // responded to on the main thread as the compositor does not yet implement
175 // scrollbar scrolling. 108 // scrollbar scrolling.
176 EXPECT_EQ(InputHandler::ScrollOnMainThread, 109 EXPECT_EQ(InputHandler::ScrollOnMainThread,
177 scrollbar_layer_impl->TryScroll( 110 scrollbar_layer_impl->TryScroll(
178 gfx::Point(0, 0), InputHandler::Gesture, ScrollBlocksOnNone)); 111 gfx::Point(0, 0), InputHandler::Gesture, ScrollBlocksOnNone));
179 112
180 // Create and attach an overlay scrollbar. 113 // Create and attach an overlay scrollbar.
181 scrollbar.reset(new FakeScrollbar(false, false, true)); 114 scrollbar.reset(new FakeScrollbar(false, false, true));
182 115
183 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 116 layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
184 layer_tree_host_.get(), scrollbar.Pass(), false, false, 0, 0); 117 host.get(), scrollbar.Pass(), false, false, 0, 0);
185 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( 118 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>(
186 layer_impl_tree_root->children()[1]); 119 layer_impl_tree_root->children()[1]);
187 120
188 // The user shouldn't be able to drag an overlay scrollbar and the scroll 121 // The user shouldn't be able to drag an overlay scrollbar and the scroll
189 // may be handled in the compositor. 122 // may be handled in the compositor.
190 EXPECT_EQ(InputHandler::ScrollIgnored, 123 EXPECT_EQ(InputHandler::ScrollIgnored,
191 scrollbar_layer_impl->TryScroll( 124 scrollbar_layer_impl->TryScroll(
192 gfx::Point(0, 0), InputHandler::Gesture, ScrollBlocksOnNone)); 125 gfx::Point(0, 0), InputHandler::Gesture, ScrollBlocksOnNone));
193 } 126 }
194 127
195 TEST_F(ScrollbarLayerTest, ScrollOffsetSynchronization) { 128 TEST(PaintedScrollbarLayerTest, ScrollOffsetSynchronization) {
129 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
130 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
131
196 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 132 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
197 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 133 scoped_refptr<Layer> layer_tree_root = Layer::Create();
198 scoped_refptr<Layer> scroll_layer = Layer::Create(); 134 scoped_refptr<Layer> scroll_layer = Layer::Create();
199 scoped_refptr<Layer> content_layer = Layer::Create(); 135 scoped_refptr<Layer> content_layer = Layer::Create();
200 scoped_refptr<Layer> scrollbar_layer = 136 scoped_refptr<Layer> scrollbar_layer =
201 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id()); 137 PaintedScrollbarLayer::Create(scrollbar.Pass(), layer_tree_root->id());
202 138
203 // Choose bounds to give max_scroll_offset = (30, 50). 139 // Choose bounds to give max_scroll_offset = (30, 50).
204 layer_tree_root->SetBounds(gfx::Size(70, 150)); 140 layer_tree_root->SetBounds(gfx::Size(70, 150));
205 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 141 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
206 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20)); 142 scroll_layer->SetScrollOffset(gfx::ScrollOffset(10, 20));
207 scroll_layer->SetBounds(gfx::Size(100, 200)); 143 scroll_layer->SetBounds(gfx::Size(100, 200));
208 content_layer->SetBounds(gfx::Size(100, 200)); 144 content_layer->SetBounds(gfx::Size(100, 200));
209 145
210 layer_tree_host_->SetRootLayer(layer_tree_root); 146 host->SetRootLayer(layer_tree_root);
211 layer_tree_root->AddChild(scroll_layer); 147 layer_tree_root->AddChild(scroll_layer);
212 scroll_layer->AddChild(content_layer); 148 scroll_layer->AddChild(content_layer);
213 layer_tree_root->AddChild(scrollbar_layer); 149 layer_tree_root->AddChild(scrollbar_layer);
214 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 150 scrollbar_layer->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
215 scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); 151 scrollbar_layer->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id());
216 152
217 layer_tree_root->SavePaintProperties(); 153 layer_tree_root->SavePaintProperties();
218 content_layer->SavePaintProperties(); 154 content_layer->SavePaintProperties();
219 155
220 LayerImpl* layer_impl_tree_root = 156 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree();
221 layer_tree_host_->CommitAndCreateLayerImplTree();
222 157
223 ScrollbarLayerImplBase* cc_scrollbar_layer = 158 ScrollbarLayerImplBase* cc_scrollbar_layer =
224 static_cast<PaintedScrollbarLayerImpl*>( 159 static_cast<PaintedScrollbarLayerImpl*>(
225 layer_impl_tree_root->children()[1]); 160 layer_impl_tree_root->children()[1]);
226 161
227 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos()); 162 EXPECT_EQ(10.f, cc_scrollbar_layer->current_pos());
228 EXPECT_EQ(30, cc_scrollbar_layer->maximum()); 163 EXPECT_EQ(30, cc_scrollbar_layer->maximum());
229 164
230 layer_tree_root->SetBounds(gfx::Size(700, 1500)); 165 layer_tree_root->SetBounds(gfx::Size(700, 1500));
231 layer_tree_root->SavePaintProperties(); 166 layer_tree_root->SavePaintProperties();
232 scroll_layer->SetBounds(gfx::Size(1000, 2000)); 167 scroll_layer->SetBounds(gfx::Size(1000, 2000));
233 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200)); 168 scroll_layer->SetScrollOffset(gfx::ScrollOffset(100, 200));
234 scroll_layer->SavePaintProperties(); 169 scroll_layer->SavePaintProperties();
235 content_layer->SetBounds(gfx::Size(1000, 2000)); 170 content_layer->SetBounds(gfx::Size(1000, 2000));
236 content_layer->SavePaintProperties(); 171 content_layer->SavePaintProperties();
237 172
238 ScrollbarAnimationController* scrollbar_controller = 173 ScrollbarAnimationController* scrollbar_controller =
239 layer_impl_tree_root->scrollbar_animation_controller(); 174 layer_impl_tree_root->scrollbar_animation_controller();
240 layer_impl_tree_root = layer_tree_host_->CommitAndCreateLayerImplTree(); 175 layer_impl_tree_root = host->CommitAndCreateLayerImplTree();
241 EXPECT_EQ(scrollbar_controller, 176 EXPECT_EQ(scrollbar_controller,
242 layer_impl_tree_root->scrollbar_animation_controller()); 177 layer_impl_tree_root->scrollbar_animation_controller());
243 178
244 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos()); 179 EXPECT_EQ(100.f, cc_scrollbar_layer->current_pos());
245 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); 180 EXPECT_EQ(300, cc_scrollbar_layer->maximum());
246 181
247 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; 182 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0];
248 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34)); 183 scroll_layer_impl->ScrollBy(gfx::Vector2d(12, 34));
249 184
250 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos()); 185 EXPECT_EQ(112.f, cc_scrollbar_layer->current_pos());
251 EXPECT_EQ(300, cc_scrollbar_layer->maximum()); 186 EXPECT_EQ(300, cc_scrollbar_layer->maximum());
252 } 187 }
253 188
254 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \ 189 #define UPDATE_AND_EXTRACT_LAYER_POINTERS() \
255 do { \ 190 do { \
256 scrollbar_layer->UpdateInternalContentScale(); \ 191 scrollbar_layer->UpdateThumbAndTrackGeometry(); \
257 scrollbar_layer->UpdateThumbAndTrackGeometry(); \ 192 root_clip_layer_impl = host->CommitAndCreateLayerImplTree(); \
258 root_clip_layer_impl = layer_tree_host_->CommitAndCreateLayerImplTree(); \ 193 root_layer_impl = root_clip_layer_impl->children()[0]; \
259 root_layer_impl = root_clip_layer_impl->children()[0]; \ 194 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \
260 scrollbar_layer_impl = static_cast<PaintedScrollbarLayerImpl*>( \ 195 root_layer_impl->children()[1]); \
261 root_layer_impl->children()[1]); \ 196 scrollbar_layer_impl->ScrollbarParametersDidChange(false); \
262 scrollbar_layer_impl->ScrollbarParametersDidChange(false); \
263 } while (false) 197 } while (false)
264 198
265 TEST_F(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) { 199 TEST(ScrollbarLayerTest, UpdatePropertiesOfScrollBarWhenThumbRemoved) {
200 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
201 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
266 scoped_refptr<Layer> root_clip_layer = Layer::Create(); 202 scoped_refptr<Layer> root_clip_layer = Layer::Create();
267 scoped_refptr<Layer> root_layer = Layer::Create(); 203 scoped_refptr<Layer> root_layer = Layer::Create();
268 scoped_refptr<Layer> content_layer = Layer::Create(); 204 scoped_refptr<Layer> content_layer = Layer::Create();
269 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 205 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
270 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); 206 FakePaintedScrollbarLayer::Create(false, true, root_layer->id());
271 207
272 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 208 root_layer->SetScrollClipLayerId(root_clip_layer->id());
273 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 209 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
274 root_clip_layer->SetBounds(gfx::Size(20, 50)); 210 root_clip_layer->SetBounds(gfx::Size(20, 50));
275 root_layer->SetBounds(gfx::Size(100, 50)); 211 root_layer->SetBounds(gfx::Size(100, 50));
276 content_layer->SetBounds(gfx::Size(100, 50)); 212 content_layer->SetBounds(gfx::Size(100, 50));
277 213
278 layer_tree_host_->SetRootLayer(root_clip_layer); 214 host->SetRootLayer(root_clip_layer);
279 root_clip_layer->AddChild(root_layer); 215 root_clip_layer->AddChild(root_layer);
280 root_layer->AddChild(content_layer); 216 root_layer->AddChild(content_layer);
281 root_layer->AddChild(scrollbar_layer); 217 root_layer->AddChild(scrollbar_layer);
282 218
283 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 219 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
284 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 220 scrollbar_layer->SetBounds(gfx::Size(70, 10));
285 scrollbar_layer->SetScrollLayer(root_layer->id()); 221 scrollbar_layer->SetScrollLayer(root_layer->id());
286 scrollbar_layer->SetClipLayer(root_clip_layer->id()); 222 scrollbar_layer->SetClipLayer(root_clip_layer->id());
287 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 223 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
288 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 224 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
289 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 225 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
290 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); 226 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
227
228 scrollbar_layer->UpdateThumbAndTrackGeometry();
291 LayerImpl* root_clip_layer_impl = nullptr; 229 LayerImpl* root_clip_layer_impl = nullptr;
292 LayerImpl* root_layer_impl = nullptr; 230 LayerImpl* root_layer_impl = nullptr;
293 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; 231 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr;
294 232
295 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 233 UPDATE_AND_EXTRACT_LAYER_POINTERS();
296 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), 234 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
297 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 235 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
298 236
299 scrollbar_layer->fake_scrollbar()->set_has_thumb(false); 237 scrollbar_layer->fake_scrollbar()->set_has_thumb(false);
300 238
301 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 239 UPDATE_AND_EXTRACT_LAYER_POINTERS();
302 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(), 240 EXPECT_EQ(gfx::Rect(10, 0, 0, 0).ToString(),
303 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 241 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
304 } 242 }
305 243
306 TEST_F(ScrollbarLayerTest, ThumbRect) { 244 TEST(ScrollbarLayerTest, ThumbRect) {
245 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
246 scoped_ptr<FakeLayerTreeHost> host = FakeLayerTreeHost::Create(&client);
307 scoped_refptr<Layer> root_clip_layer = Layer::Create(); 247 scoped_refptr<Layer> root_clip_layer = Layer::Create();
308 scoped_refptr<Layer> root_layer = Layer::Create(); 248 scoped_refptr<Layer> root_layer = Layer::Create();
309 scoped_refptr<Layer> content_layer = Layer::Create(); 249 scoped_refptr<Layer> content_layer = Layer::Create();
310 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 250 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
311 FakePaintedScrollbarLayer::Create(false, true, root_layer->id()); 251 FakePaintedScrollbarLayer::Create(false, true, root_layer->id());
312 252
313 root_layer->SetScrollClipLayerId(root_clip_layer->id()); 253 root_layer->SetScrollClipLayerId(root_clip_layer->id());
314 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0). 254 // Give the root-clip a size that will result in MaxScrollOffset = (80, 0).
315 root_clip_layer->SetBounds(gfx::Size(20, 50)); 255 root_clip_layer->SetBounds(gfx::Size(20, 50));
316 root_layer->SetBounds(gfx::Size(100, 50)); 256 root_layer->SetBounds(gfx::Size(100, 50));
317 content_layer->SetBounds(gfx::Size(100, 50)); 257 content_layer->SetBounds(gfx::Size(100, 50));
318 258
319 layer_tree_host_->SetRootLayer(root_clip_layer); 259 host->SetRootLayer(root_clip_layer);
320 root_clip_layer->AddChild(root_layer); 260 root_clip_layer->AddChild(root_layer);
321 root_layer->AddChild(content_layer); 261 root_layer->AddChild(content_layer);
322 root_layer->AddChild(scrollbar_layer); 262 root_layer->AddChild(scrollbar_layer);
323 263
324 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0)); 264 root_layer->SetScrollOffset(gfx::ScrollOffset(0, 0));
325 scrollbar_layer->SetBounds(gfx::Size(70, 10)); 265 scrollbar_layer->SetBounds(gfx::Size(70, 10));
326 scrollbar_layer->SetScrollLayer(root_layer->id()); 266 scrollbar_layer->SetScrollLayer(root_layer->id());
327 scrollbar_layer->SetClipLayer(root_clip_layer->id()); 267 scrollbar_layer->SetClipLayer(root_clip_layer->id());
328 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10)); 268 scrollbar_layer->fake_scrollbar()->set_location(gfx::Point(20, 10));
329 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10)); 269 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 10, 50, 10));
330 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10); 270 scrollbar_layer->fake_scrollbar()->set_thumb_thickness(10);
331 scrollbar_layer->fake_scrollbar()->set_thumb_length(4); 271 scrollbar_layer->fake_scrollbar()->set_thumb_length(4);
272 scrollbar_layer->UpdateThumbAndTrackGeometry();
332 LayerImpl* root_clip_layer_impl = nullptr; 273 LayerImpl* root_clip_layer_impl = nullptr;
333 LayerImpl* root_layer_impl = nullptr; 274 LayerImpl* root_layer_impl = nullptr;
334 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr; 275 PaintedScrollbarLayerImpl* scrollbar_layer_impl = nullptr;
335 276
336 // Thumb is at the edge of the scrollbar (should be inset to 277 // Thumb is at the edge of the scrollbar (should be inset to
337 // the start of the track within the scrollbar layer's 278 // the start of the track within the scrollbar layer's
338 // position). 279 // position).
339 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 280 UPDATE_AND_EXTRACT_LAYER_POINTERS();
340 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(), 281 EXPECT_EQ(gfx::Rect(10, 0, 4, 10).ToString(),
341 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 282 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 // Shrink the track in the non-scrolling dimension so that it only covers the 315 // Shrink the track in the non-scrolling dimension so that it only covers the
375 // middle third of the scrollbar layer (this does not affect the thumb 316 // middle third of the scrollbar layer (this does not affect the thumb
376 // position). 317 // position).
377 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6)); 318 scrollbar_layer->fake_scrollbar()->set_track_rect(gfx::Rect(30, 12, 50, 6));
378 319
379 UPDATE_AND_EXTRACT_LAYER_POINTERS(); 320 UPDATE_AND_EXTRACT_LAYER_POINTERS();
380 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(), 321 EXPECT_EQ(gfx::Rect(44, 0, 6, 4).ToString(),
381 scrollbar_layer_impl->ComputeThumbQuadRect().ToString()); 322 scrollbar_layer_impl->ComputeThumbQuadRect().ToString());
382 } 323 }
383 324
384 TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { 325 TEST(ScrollbarLayerTest, SolidColorDrawQuads) {
385 const int kThumbThickness = 3; 326 const int kThumbThickness = 3;
386 const int kTrackStart = 1; 327 const int kTrackStart = 1;
387 const int kTrackLength = 100; 328 const int kTrackLength = 100;
388 329
330 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
331 LayerTreeSettings layer_tree_settings;
332 scoped_ptr<FakeLayerTreeHost> host =
333 FakeLayerTreeHost::Create(&client, layer_tree_settings);
334
389 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 335 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
390 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( 336 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar(
391 layer_tree_host_.get(), scrollbar.Pass(), false, true, kThumbThickness, 337 host.get(), scrollbar.Pass(), false, true, kThumbThickness, kTrackStart);
392 kTrackStart);
393 ScrollbarLayerImplBase* scrollbar_layer_impl = 338 ScrollbarLayerImplBase* scrollbar_layer_impl =
394 static_cast<SolidColorScrollbarLayerImpl*>( 339 static_cast<SolidColorScrollbarLayerImpl*>(
395 layer_impl_tree_root->children()[1]); 340 layer_impl_tree_root->children()[1]);
396 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); 341 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness));
397 scrollbar_layer_impl->SetCurrentPos(10.f); 342 scrollbar_layer_impl->SetCurrentPos(10.f);
398 scrollbar_layer_impl->SetMaximum(100); 343 scrollbar_layer_impl->SetMaximum(100);
399 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); 344 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f);
400 345
401 // Thickness should be overridden to 3. 346 // Thickness should be overridden to 3.
402 { 347 {
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
448 AppendQuadsData data; 393 AppendQuadsData data;
449 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); 394 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data);
450 395
451 const QuadList& quads = render_pass->quad_list; 396 const QuadList& quads = render_pass->quad_list;
452 ASSERT_EQ(1u, quads.size()); 397 ASSERT_EQ(1u, quads.size());
453 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); 398 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material);
454 EXPECT_EQ(gfx::Rect(1, 0, 19, 3), quads.front()->rect); 399 EXPECT_EQ(gfx::Rect(1, 0, 19, 3), quads.front()->rect);
455 } 400 }
456 } 401 }
457 402
458 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { 403 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) {
459 const int kThumbThickness = 3; 404 const int kThumbThickness = 3;
460 const int kTrackStart = 0; 405 const int kTrackStart = 0;
461 const int kTrackLength = 10; 406 const int kTrackLength = 10;
462 407
408 FakeLayerTreeHostClient client(FakeLayerTreeHostClient::DIRECT_3D);
409 LayerTreeSettings layer_tree_settings;
410 scoped_ptr<FakeLayerTreeHost> host =
411 FakeLayerTreeHost::Create(&client, layer_tree_settings);
412
463 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); 413 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true));
464 414
465 { 415 {
466 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 416 scoped_refptr<Layer> layer_tree_root = Layer::Create();
467 scoped_refptr<Layer> scroll_layer = Layer::Create(); 417 scoped_refptr<Layer> scroll_layer = Layer::Create();
468 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); 418 scroll_layer->SetScrollClipLayerId(layer_tree_root->id());
469 scoped_refptr<Layer> child1 = Layer::Create(); 419 scoped_refptr<Layer> child1 = Layer::Create();
470 scoped_refptr<Layer> child2; 420 scoped_refptr<Layer> child2;
471 const bool kIsLeftSideVerticalScrollbar = false; 421 const bool kIsLeftSideVerticalScrollbar = false;
472 child2 = SolidColorScrollbarLayer::Create(scrollbar->Orientation(), 422 child2 = SolidColorScrollbarLayer::Create(scrollbar->Orientation(),
473 kThumbThickness, 423 kThumbThickness,
474 kTrackStart, 424 kTrackStart,
475 kIsLeftSideVerticalScrollbar, 425 kIsLeftSideVerticalScrollbar,
476 child1->id()); 426 child1->id());
477 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); 427 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id());
478 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); 428 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id());
479 scroll_layer->AddChild(child1); 429 scroll_layer->AddChild(child1);
480 scroll_layer->InsertChild(child2, 1); 430 scroll_layer->InsertChild(child2, 1);
481 layer_tree_root->AddChild(scroll_layer); 431 layer_tree_root->AddChild(scroll_layer);
482 layer_tree_host_->SetRootLayer(layer_tree_root); 432 host->SetRootLayer(layer_tree_root);
483 } 433 }
484 LayerImpl* layer_impl_tree_root = 434 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree();
485 layer_tree_host_->CommitAndCreateLayerImplTree();
486 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; 435 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0];
487 436
488 ScrollbarLayerImplBase* scrollbar_layer_impl = 437 ScrollbarLayerImplBase* scrollbar_layer_impl =
489 static_cast<PaintedScrollbarLayerImpl*>(scroll_layer_impl->children()[1]); 438 static_cast<PaintedScrollbarLayerImpl*>(scroll_layer_impl->children()[1]);
490 439
491 // Choose layer bounds to give max_scroll_offset = (8, 8). 440 // Choose layer bounds to give max_scroll_offset = (8, 8).
492 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); 441 layer_impl_tree_root->SetBounds(gfx::Size(2, 2));
493 scroll_layer_impl->SetBounds(gfx::Size(10, 10)); 442 scroll_layer_impl->SetBounds(gfx::Size(10, 10));
494 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); 443 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f));
495 444
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 void BeginTest() override { 571 void BeginTest() override {
623 scroll_layer_ = Layer::Create(); 572 scroll_layer_ = Layer::Create();
624 layer_tree_host()->root_layer()->AddChild(scroll_layer_); 573 layer_tree_host()->root_layer()->AddChild(scroll_layer_);
625 574
626 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); 575 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar);
627 scrollbar_layer_ = 576 scrollbar_layer_ =
628 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_->id()); 577 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_->id());
629 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); 578 scrollbar_layer_->SetScrollLayer(scroll_layer_->id());
630 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); 579 scrollbar_layer_->SetLayerTreeHost(layer_tree_host());
631 scrollbar_layer_->SetBounds(bounds_); 580 scrollbar_layer_->SetBounds(bounds_);
632 scrollbar_layer_->SetIsDrawable(true);
633 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); 581 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_);
634 582
635 PostSetNeedsCommitToMainThread(); 583 PostSetNeedsCommitToMainThread();
636 } 584 }
637 585
638 void DidCommitAndDrawFrame() override { 586 void DidCommitAndDrawFrame() override {
639 const int kMaxTextureSize = 587 const int kMaxTextureSize =
640 layer_tree_host()->GetRendererCapabilities().max_texture_size; 588 layer_tree_host()->GetRendererCapabilities().max_texture_size;
641 589
642 // Check first that we're actually testing something. 590 // Check first that we're actually testing something.
643 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); 591 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize);
644 592
645 EXPECT_EQ(scrollbar_layer_->internal_content_bounds().width(), 593 EXPECT_EQ(scrollbar_layer_->content_bounds().width(),
646 kMaxTextureSize - 1); 594 kMaxTextureSize - 1);
647 EXPECT_EQ(scrollbar_layer_->internal_content_bounds().height(), 595 EXPECT_EQ(scrollbar_layer_->content_bounds().height(),
648 kMaxTextureSize - 1); 596 kMaxTextureSize - 1);
649 597
650 EndTest(); 598 EndTest();
651 } 599 }
652 600
653 void AfterTest() override {} 601 void AfterTest() override {}
654 602
655 private: 603 private:
656 scoped_refptr<PaintedScrollbarLayer> scrollbar_layer_; 604 scoped_refptr<PaintedScrollbarLayer> scrollbar_layer_;
657 scoped_refptr<Layer> scroll_layer_; 605 scoped_refptr<Layer> scroll_layer_;
(...skipping 11 matching lines...) Expand all
669 617
670 TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) { 618 TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) {
671 scoped_ptr<TestWebGraphicsContext3D> context = 619 scoped_ptr<TestWebGraphicsContext3D> context =
672 TestWebGraphicsContext3D::Create(); 620 TestWebGraphicsContext3D::Create();
673 int max_size = 0; 621 int max_size = 0;
674 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); 622 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size);
675 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); 623 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100));
676 RunTest(true, true, true); 624 RunTest(true, true, true);
677 } 625 }
678 626
679 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { 627 class FakeLayerTreeHost : public LayerTreeHost {
680 public: 628 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
681 void TestResourceUpload(int num_updates, 690 void TestResourceUpload(int num_updates,
682 size_t expected_resources, 691 size_t expected_resources,
683 int expected_created, 692 int expected_created,
684 int expected_deleted, 693 int expected_deleted,
685 bool use_solid_color_scrollbar) { 694 bool use_solid_color_scrollbar) {
695 layer_tree_host_.reset(
696 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
697
686 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); 698 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false));
687 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 699 scoped_refptr<Layer> layer_tree_root = Layer::Create();
688 scoped_refptr<Layer> content_layer = Layer::Create(); 700 scoped_refptr<Layer> content_layer = Layer::Create();
689 scoped_refptr<Layer> scrollbar_layer; 701 scoped_refptr<Layer> scrollbar_layer;
690 if (use_solid_color_scrollbar) { 702 if (use_solid_color_scrollbar) {
691 const int kThumbThickness = 3; 703 const int kThumbThickness = 3;
692 const int kTrackStart = 0; 704 const int kTrackStart = 0;
693 const bool kIsLeftSideVerticalScrollbar = false; 705 const bool kIsLeftSideVerticalScrollbar = false;
694 scrollbar_layer = 706 scrollbar_layer =
695 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), 707 SolidColorScrollbarLayer::Create(scrollbar->Orientation(),
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 742
731 // A non-solid-color scrollbar should have requested two textures. 743 // A non-solid-color scrollbar should have requested two textures.
732 EXPECT_EQ(expected_resources, layer_tree_host_->UIResourceCount()); 744 EXPECT_EQ(expected_resources, layer_tree_host_->UIResourceCount());
733 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); 745 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated());
734 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); 746 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted());
735 747
736 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 748 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
737 749
738 scrollbar_layer->ClearRenderSurface(); 750 scrollbar_layer->ClearRenderSurface();
739 } 751 }
752
753 protected:
754 FakeLayerTreeHostClient fake_client_;
755 LayerTreeSettings layer_tree_settings_;
756 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
740 }; 757 };
741 758
742 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, ResourceUpload) { 759 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, ResourceUpload) {
743 bool use_solid_color_scrollbars = false; 760 bool use_solid_color_scrollbars = false;
744 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); 761 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
745 int num_updates[3] = {1, 5, 10}; 762 int num_updates[3] = {1, 5, 10};
746 int created = 0;
747 int deleted = 0;
748 for (int j = 0; j < 3; j++) { 763 for (int j = 0; j < 3; j++) {
749 created += num_updates[j] * 2; 764 TestResourceUpload(num_updates[j],
750 deleted = created - 2; 765 2,
751 TestResourceUpload(num_updates[j], 2, created, deleted, 766 num_updates[j] * 2,
767 (num_updates[j] - 1) * 2,
752 use_solid_color_scrollbars); 768 use_solid_color_scrollbars);
753 } 769 }
754 } 770 }
755 771
756 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, 772 TEST_F(ScrollbarLayerTestResourceCreationAndRelease,
757 SolidColorNoResourceUpload) { 773 SolidColorNoResourceUpload) {
758 bool use_solid_color_scrollbars = true; 774 bool use_solid_color_scrollbars = true;
759 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); 775 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars);
760 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); 776 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars);
761 } 777 }
762 778
763 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { 779 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
764 gfx::Point scrollbar_location(0, 185); 787 gfx::Point scrollbar_location(0, 185);
765 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 788 scoped_refptr<Layer> layer_tree_root = Layer::Create();
766 scoped_refptr<Layer> content_layer = Layer::Create(); 789 scoped_refptr<Layer> content_layer = Layer::Create();
767 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 790 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
768 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); 791 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
769 792
770 layer_tree_root->AddChild(content_layer); 793 layer_tree_root->AddChild(content_layer);
771 layer_tree_root->AddChild(scrollbar_layer); 794 layer_tree_root->AddChild(scrollbar_layer);
772 795
773 layer_tree_host_->SetRootLayer(layer_tree_root); 796 layer_tree_host_->SetRootLayer(layer_tree_root);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
888 EXPECT_NE(0, scrollbar_layer->track_resource_id()); 911 EXPECT_NE(0, scrollbar_layer->track_resource_id());
889 EXPECT_EQ(0, scrollbar_layer->thumb_resource_id()); 912 EXPECT_EQ(0, scrollbar_layer->thumb_resource_id());
890 EXPECT_EQ(resource_count, layer_tree_host_->UIResourceCount()); 913 EXPECT_EQ(resource_count, layer_tree_host_->UIResourceCount());
891 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); 914 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated());
892 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); 915 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted());
893 916
894 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 917 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
895 scrollbar_layer->ClearRenderSurface(); 918 scrollbar_layer->ClearRenderSurface();
896 } 919 }
897 920
898 class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest { 921 class ScaledScrollbarLayerTestResourceCreation : public testing::Test {
899 public: 922 public:
923 ScaledScrollbarLayerTestResourceCreation()
924 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
925
900 void TestResourceUpload(const float test_scale) { 926 void TestResourceUpload(const float test_scale) {
927 layer_tree_host_.reset(
928 new FakeLayerTreeHost(&fake_client_, layer_tree_settings_));
929
901 gfx::Point scrollbar_location(0, 185); 930 gfx::Point scrollbar_location(0, 185);
902 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 931 scoped_refptr<Layer> layer_tree_root = Layer::Create();
903 scoped_refptr<Layer> content_layer = Layer::Create(); 932 scoped_refptr<Layer> content_layer = Layer::Create();
904 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 933 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
905 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); 934 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id());
906 935
907 layer_tree_root->AddChild(content_layer); 936 layer_tree_root->AddChild(content_layer);
908 layer_tree_root->AddChild(scrollbar_layer); 937 layer_tree_root->AddChild(scrollbar_layer);
909 938
910 layer_tree_host_->SetRootLayer(layer_tree_root); 939 layer_tree_host_->SetRootLayer(layer_tree_root);
(...skipping 29 matching lines...) Expand all
940 scrollbar_layer->Update(&queue, &occlusion_tracker); 969 scrollbar_layer->Update(&queue, &occlusion_tracker);
941 970
942 // Verify that we have not generated any content uploads that are larger 971 // Verify that we have not generated any content uploads that are larger
943 // than their destination textures. 972 // than their destination textures.
944 973
945 gfx::Size track_size = layer_tree_host_->ui_resource_size( 974 gfx::Size track_size = layer_tree_host_->ui_resource_size(
946 scrollbar_layer->track_resource_id()); 975 scrollbar_layer->track_resource_id());
947 gfx::Size thumb_size = layer_tree_host_->ui_resource_size( 976 gfx::Size thumb_size = layer_tree_host_->ui_resource_size(
948 scrollbar_layer->thumb_resource_id()); 977 scrollbar_layer->thumb_resource_id());
949 978
950 EXPECT_LE(track_size.width(), 979 EXPECT_LE(track_size.width(), scrollbar_layer->content_bounds().width());
951 scrollbar_layer->internal_content_bounds().width()); 980 EXPECT_LE(track_size.height(), scrollbar_layer->content_bounds().height());
952 EXPECT_LE(track_size.height(), 981 EXPECT_LE(thumb_size.width(), scrollbar_layer->content_bounds().width());
953 scrollbar_layer->internal_content_bounds().height()); 982 EXPECT_LE(thumb_size.height(), scrollbar_layer->content_bounds().height());
954 EXPECT_LE(thumb_size.width(),
955 scrollbar_layer->internal_content_bounds().width());
956 EXPECT_LE(thumb_size.height(),
957 scrollbar_layer->internal_content_bounds().height());
958 983
959 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); 984 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get());
960 985
961 scrollbar_layer->ClearRenderSurface(); 986 scrollbar_layer->ClearRenderSurface();
962 } 987 }
988
989 protected:
990 FakeLayerTreeHostClient fake_client_;
991 LayerTreeSettings layer_tree_settings_;
992 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
963 }; 993 };
964 994
965 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { 995 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) {
966 // Pick a test scale that moves the scrollbar's (non-zero) position to 996 // Pick a test scale that moves the scrollbar's (non-zero) position to
967 // a non-pixel-aligned location. 997 // a non-pixel-aligned location.
968 TestResourceUpload(.041f); 998 TestResourceUpload(.041f);
969 TestResourceUpload(1.41f); 999 TestResourceUpload(1.41f);
970 TestResourceUpload(4.1f); 1000 TestResourceUpload(4.1f);
971 } 1001 }
972 1002
973 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { 1003 class ScaledScrollbarLayerTestScaledRasterization : public testing::Test {
974 public: 1004 public:
1005 ScaledScrollbarLayerTestScaledRasterization()
1006 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {}
1007
975 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { 1008 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
976 bool paint_during_update = true; 1012 bool paint_during_update = true;
977 bool has_thumb = false; 1013 bool has_thumb = false;
978 scoped_refptr<Layer> layer_tree_root = Layer::Create(); 1014 scoped_refptr<Layer> layer_tree_root = Layer::Create();
979 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = 1015 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer =
980 FakePaintedScrollbarLayer::Create(paint_during_update, 1016 FakePaintedScrollbarLayer::Create(paint_during_update,
981 has_thumb, 1017 has_thumb,
982 layer_tree_root->id()); 1018 layer_tree_root->id());
983 1019
984 layer_tree_root->AddChild(scrollbar_layer); 1020 layer_tree_root->AddChild(scrollbar_layer);
985 1021
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1039 } 1075 }
1040 1076
1041 protected: 1077 protected:
1042 // On Android, Skia uses ABGR 1078 // On Android, Skia uses ABGR
1043 static SkColor argb_to_skia(SkColor c) { 1079 static SkColor argb_to_skia(SkColor c) {
1044 return (SkColorGetA(c) << SK_A32_SHIFT) | 1080 return (SkColorGetA(c) << SK_A32_SHIFT) |
1045 (SkColorGetR(c) << SK_R32_SHIFT) | 1081 (SkColorGetR(c) << SK_R32_SHIFT) |
1046 (SkColorGetG(c) << SK_G32_SHIFT) | 1082 (SkColorGetG(c) << SK_G32_SHIFT) |
1047 (SkColorGetB(c) << SK_B32_SHIFT); 1083 (SkColorGetB(c) << SK_B32_SHIFT);
1048 } 1084 }
1085
1086 FakeLayerTreeHostClient fake_client_;
1087 LayerTreeSettings layer_tree_settings_;
1088 scoped_ptr<FakeLayerTreeHost> layer_tree_host_;
1049 }; 1089 };
1050 1090
1051 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) { 1091 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) {
1052 // Try rasterization at coordinates and scale that caused problematic 1092 // Try rasterization at coordinates and scale that caused problematic
1053 // rounding and clipping errors. 1093 // rounding and clipping errors.
1054 // Vertical Scrollbars. 1094 // Vertical Scrollbars.
1055 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); 1095 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f);
1056 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); 1096 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f);
1057 1097
1058 // Horizontal Scrollbars. 1098 // Horizontal Scrollbars.
1059 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); 1099 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f);
1060 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); 1100 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f);
1061 } 1101 }
1062 1102
1063 } // namespace 1103 } // namespace
1064 } // namespace cc 1104 } // namespace cc
OLDNEW
« no previous file with comments | « cc/layers/scrollbar_layer_impl_base.h ('k') | cc/test/fake_layer_tree_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698