| OLD | NEW |
| 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 Loading... |
| 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 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) { |
| 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 Loading... |
| 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 TEST_F(ScrollbarLayerTest, SolidColorDrawQuads) { |
| 326 const int kThumbThickness = 3; | 385 const int kThumbThickness = 3; |
| 327 const int kTrackStart = 1; | 386 const int kTrackStart = 1; |
| 328 const int kTrackLength = 100; | 387 const int kTrackLength = 100; |
| 329 | 388 |
| 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)); | 389 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 336 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( | 390 LayerImpl* layer_impl_tree_root = LayerImplForScrollAreaAndScrollbar( |
| 337 host.get(), scrollbar.Pass(), false, true, kThumbThickness, kTrackStart); | 391 layer_tree_host_.get(), scrollbar.Pass(), false, true, kThumbThickness, |
| 392 kTrackStart); |
| 338 ScrollbarLayerImplBase* scrollbar_layer_impl = | 393 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 339 static_cast<SolidColorScrollbarLayerImpl*>( | 394 static_cast<SolidColorScrollbarLayerImpl*>( |
| 340 layer_impl_tree_root->children()[1]); | 395 layer_impl_tree_root->children()[1]); |
| 341 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 396 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 342 scrollbar_layer_impl->SetCurrentPos(10.f); | 397 scrollbar_layer_impl->SetCurrentPos(10.f); |
| 343 scrollbar_layer_impl->SetMaximum(100); | 398 scrollbar_layer_impl->SetMaximum(100); |
| 344 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); | 399 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.4f); |
| 345 | 400 |
| 346 // Thickness should be overridden to 3. | 401 // Thickness should be overridden to 3. |
| 347 { | 402 { |
| 348 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 403 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 349 AppendQuadsData data; | 404 AppendQuadsData data; |
| 350 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); | 405 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data); |
| 351 | 406 |
| 352 const QuadList& quads = render_pass->quad_list; | 407 const QuadList& quads = render_pass->quad_list; |
| 353 ASSERT_EQ(1u, quads.size()); | 408 ASSERT_EQ(1u, quads.size()); |
| 354 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 409 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 355 EXPECT_EQ(gfx::Rect(6, 0, 39, 3), quads.front()->rect); | 410 EXPECT_EQ(gfx::Rect(6, 0, 39, 3), quads.front()->rect); |
| 356 } | 411 } |
| 357 | 412 |
| 358 // Contents scale should scale the draw quad. | 413 // Contents scale should scale the draw quad. |
| 359 scrollbar_layer_impl->draw_properties().contents_scale_x = 2.f; | 414 scrollbar_layer_impl->draw_properties().contents_scale_x = 2.f; |
| 360 scrollbar_layer_impl->draw_properties().contents_scale_y = 2.f; | 415 scrollbar_layer_impl->draw_properties().contents_scale_y = 2.f; |
| 361 { | 416 { |
| 362 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 417 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 363 AppendQuadsData data; | 418 AppendQuadsData data; |
| 364 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); | 419 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data); |
| 365 | 420 |
| 366 const QuadList& quads = render_pass->quad_list; | 421 const QuadList& quads = render_pass->quad_list; |
| 367 ASSERT_EQ(1u, quads.size()); | 422 ASSERT_EQ(1u, quads.size()); |
| 368 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 423 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 369 EXPECT_EQ(gfx::Rect(12, 0, 78, 6), quads.front()->rect); | 424 EXPECT_EQ(gfx::Rect(12, 0, 78, 6), quads.front()->rect); |
| 370 } | 425 } |
| 371 scrollbar_layer_impl->draw_properties().contents_scale_x = 1.f; | 426 scrollbar_layer_impl->draw_properties().contents_scale_x = 1.f; |
| 372 scrollbar_layer_impl->draw_properties().contents_scale_y = 1.f; | 427 scrollbar_layer_impl->draw_properties().contents_scale_y = 1.f; |
| 373 | 428 |
| 374 // For solid color scrollbars, position and size should reflect the | 429 // For solid color scrollbars, position and size should reflect the |
| 375 // current viewport state. | 430 // current viewport state. |
| 376 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.2f); | 431 scrollbar_layer_impl->SetVisibleToTotalLengthRatio(0.2f); |
| 377 { | 432 { |
| 378 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 433 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 379 AppendQuadsData data; | 434 AppendQuadsData data; |
| 380 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); | 435 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data); |
| 381 | 436 |
| 382 const QuadList& quads = render_pass->quad_list; | 437 const QuadList& quads = render_pass->quad_list; |
| 383 ASSERT_EQ(1u, quads.size()); | 438 ASSERT_EQ(1u, quads.size()); |
| 384 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 439 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 385 EXPECT_EQ(gfx::Rect(8, 0, 19, 3), quads.front()->rect); | 440 EXPECT_EQ(gfx::Rect(8, 0, 19, 3), quads.front()->rect); |
| 386 } | 441 } |
| 387 | 442 |
| 388 // We shouldn't attempt div-by-zero when the maximum is zero. | 443 // We shouldn't attempt div-by-zero when the maximum is zero. |
| 389 scrollbar_layer_impl->SetCurrentPos(0.f); | 444 scrollbar_layer_impl->SetCurrentPos(0.f); |
| 390 scrollbar_layer_impl->SetMaximum(0); | 445 scrollbar_layer_impl->SetMaximum(0); |
| 391 { | 446 { |
| 392 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 447 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 393 AppendQuadsData data; | 448 AppendQuadsData data; |
| 394 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); | 449 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data); |
| 395 | 450 |
| 396 const QuadList& quads = render_pass->quad_list; | 451 const QuadList& quads = render_pass->quad_list; |
| 397 ASSERT_EQ(1u, quads.size()); | 452 ASSERT_EQ(1u, quads.size()); |
| 398 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 453 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 399 EXPECT_EQ(gfx::Rect(1, 0, 19, 3), quads.front()->rect); | 454 EXPECT_EQ(gfx::Rect(1, 0, 19, 3), quads.front()->rect); |
| 400 } | 455 } |
| 401 } | 456 } |
| 402 | 457 |
| 403 TEST(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { | 458 TEST_F(ScrollbarLayerTest, LayerDrivenSolidColorDrawQuads) { |
| 404 const int kThumbThickness = 3; | 459 const int kThumbThickness = 3; |
| 405 const int kTrackStart = 0; | 460 const int kTrackStart = 0; |
| 406 const int kTrackLength = 10; | 461 const int kTrackLength = 10; |
| 407 | 462 |
| 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)); | 463 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, true)); |
| 414 | 464 |
| 415 { | 465 { |
| 416 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 466 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 417 scoped_refptr<Layer> scroll_layer = Layer::Create(); | 467 scoped_refptr<Layer> scroll_layer = Layer::Create(); |
| 418 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); | 468 scroll_layer->SetScrollClipLayerId(layer_tree_root->id()); |
| 419 scoped_refptr<Layer> child1 = Layer::Create(); | 469 scoped_refptr<Layer> child1 = Layer::Create(); |
| 420 scoped_refptr<Layer> child2; | 470 scoped_refptr<Layer> child2; |
| 421 const bool kIsLeftSideVerticalScrollbar = false; | 471 const bool kIsLeftSideVerticalScrollbar = false; |
| 422 child2 = SolidColorScrollbarLayer::Create(scrollbar->Orientation(), | 472 child2 = SolidColorScrollbarLayer::Create(scrollbar->Orientation(), |
| 423 kThumbThickness, | 473 kThumbThickness, |
| 424 kTrackStart, | 474 kTrackStart, |
| 425 kIsLeftSideVerticalScrollbar, | 475 kIsLeftSideVerticalScrollbar, |
| 426 child1->id()); | 476 child1->id()); |
| 427 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); | 477 child2->ToScrollbarLayer()->SetScrollLayer(scroll_layer->id()); |
| 428 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); | 478 child2->ToScrollbarLayer()->SetClipLayer(layer_tree_root->id()); |
| 429 scroll_layer->AddChild(child1); | 479 scroll_layer->AddChild(child1); |
| 430 scroll_layer->InsertChild(child2, 1); | 480 scroll_layer->InsertChild(child2, 1); |
| 431 layer_tree_root->AddChild(scroll_layer); | 481 layer_tree_root->AddChild(scroll_layer); |
| 432 host->SetRootLayer(layer_tree_root); | 482 layer_tree_host_->SetRootLayer(layer_tree_root); |
| 433 } | 483 } |
| 434 LayerImpl* layer_impl_tree_root = host->CommitAndCreateLayerImplTree(); | 484 LayerImpl* layer_impl_tree_root = |
| 485 layer_tree_host_->CommitAndCreateLayerImplTree(); |
| 435 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; | 486 LayerImpl* scroll_layer_impl = layer_impl_tree_root->children()[0]; |
| 436 | 487 |
| 437 ScrollbarLayerImplBase* scrollbar_layer_impl = | 488 ScrollbarLayerImplBase* scrollbar_layer_impl = |
| 438 static_cast<PaintedScrollbarLayerImpl*>(scroll_layer_impl->children()[1]); | 489 static_cast<PaintedScrollbarLayerImpl*>(scroll_layer_impl->children()[1]); |
| 439 | 490 |
| 440 // Choose layer bounds to give max_scroll_offset = (8, 8). | 491 // Choose layer bounds to give max_scroll_offset = (8, 8). |
| 441 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); | 492 layer_impl_tree_root->SetBounds(gfx::Size(2, 2)); |
| 442 scroll_layer_impl->SetBounds(gfx::Size(10, 10)); | 493 scroll_layer_impl->SetBounds(gfx::Size(10, 10)); |
| 443 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); | 494 scroll_layer_impl->ScrollBy(gfx::Vector2dF(4.f, 0.f)); |
| 444 | 495 |
| 445 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); | 496 scrollbar_layer_impl->SetBounds(gfx::Size(kTrackLength, kThumbThickness)); |
| 446 scrollbar_layer_impl->SetCurrentPos(4.f); | 497 scrollbar_layer_impl->SetCurrentPos(4.f); |
| 447 scrollbar_layer_impl->SetMaximum(8); | 498 scrollbar_layer_impl->SetMaximum(8); |
| 448 | 499 |
| 449 { | 500 { |
| 450 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); | 501 scoped_ptr<RenderPass> render_pass = RenderPass::Create(); |
| 451 | 502 |
| 452 AppendQuadsData data; | 503 AppendQuadsData data; |
| 453 scrollbar_layer_impl->AppendQuads(render_pass.get(), Occlusion(), &data); | 504 scrollbar_layer_impl->AppendQuads(render_pass.get(), &data); |
| 454 | 505 |
| 455 const QuadList& quads = render_pass->quad_list; | 506 const QuadList& quads = render_pass->quad_list; |
| 456 ASSERT_EQ(1u, quads.size()); | 507 ASSERT_EQ(1u, quads.size()); |
| 457 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); | 508 EXPECT_EQ(DrawQuad::SOLID_COLOR, quads.front()->material); |
| 458 EXPECT_EQ(gfx::Rect(3, 0, 3, 3), quads.front()->rect); | 509 EXPECT_EQ(gfx::Rect(3, 0, 3, 3), quads.front()->rect); |
| 459 } | 510 } |
| 460 } | 511 } |
| 461 | 512 |
| 462 class ScrollbarLayerSolidColorThumbTest : public testing::Test { | 513 class ScrollbarLayerSolidColorThumbTest : public testing::Test { |
| 463 public: | 514 public: |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 void BeginTest() override { | 622 void BeginTest() override { |
| 572 scroll_layer_ = Layer::Create(); | 623 scroll_layer_ = Layer::Create(); |
| 573 layer_tree_host()->root_layer()->AddChild(scroll_layer_); | 624 layer_tree_host()->root_layer()->AddChild(scroll_layer_); |
| 574 | 625 |
| 575 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); | 626 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar); |
| 576 scrollbar_layer_ = | 627 scrollbar_layer_ = |
| 577 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_->id()); | 628 PaintedScrollbarLayer::Create(scrollbar.Pass(), scroll_layer_->id()); |
| 578 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); | 629 scrollbar_layer_->SetScrollLayer(scroll_layer_->id()); |
| 579 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); | 630 scrollbar_layer_->SetLayerTreeHost(layer_tree_host()); |
| 580 scrollbar_layer_->SetBounds(bounds_); | 631 scrollbar_layer_->SetBounds(bounds_); |
| 632 scrollbar_layer_->SetIsDrawable(true); |
| 581 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); | 633 layer_tree_host()->root_layer()->AddChild(scrollbar_layer_); |
| 582 | 634 |
| 583 PostSetNeedsCommitToMainThread(); | 635 PostSetNeedsCommitToMainThread(); |
| 584 } | 636 } |
| 585 | 637 |
| 586 void DidCommitAndDrawFrame() override { | 638 void DidCommitAndDrawFrame() override { |
| 587 const int kMaxTextureSize = | 639 const int kMaxTextureSize = |
| 588 layer_tree_host()->GetRendererCapabilities().max_texture_size; | 640 layer_tree_host()->GetRendererCapabilities().max_texture_size; |
| 589 | 641 |
| 590 // Check first that we're actually testing something. | 642 // Check first that we're actually testing something. |
| 591 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); | 643 EXPECT_GT(scrollbar_layer_->bounds().width(), kMaxTextureSize); |
| 592 | 644 |
| 593 EXPECT_EQ(scrollbar_layer_->content_bounds().width(), | 645 EXPECT_EQ(scrollbar_layer_->internal_content_bounds().width(), |
| 594 kMaxTextureSize - 1); | 646 kMaxTextureSize - 1); |
| 595 EXPECT_EQ(scrollbar_layer_->content_bounds().height(), | 647 EXPECT_EQ(scrollbar_layer_->internal_content_bounds().height(), |
| 596 kMaxTextureSize - 1); | 648 kMaxTextureSize - 1); |
| 597 | 649 |
| 598 EndTest(); | 650 EndTest(); |
| 599 } | 651 } |
| 600 | 652 |
| 601 void AfterTest() override {} | 653 void AfterTest() override {} |
| 602 | 654 |
| 603 private: | 655 private: |
| 604 scoped_refptr<PaintedScrollbarLayer> scrollbar_layer_; | 656 scoped_refptr<PaintedScrollbarLayer> scrollbar_layer_; |
| 605 scoped_refptr<Layer> scroll_layer_; | 657 scoped_refptr<Layer> scroll_layer_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 617 | 669 |
| 618 TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) { | 670 TEST_F(ScrollbarLayerTestMaxTextureSize, DelegatingRenderer) { |
| 619 scoped_ptr<TestWebGraphicsContext3D> context = | 671 scoped_ptr<TestWebGraphicsContext3D> context = |
| 620 TestWebGraphicsContext3D::Create(); | 672 TestWebGraphicsContext3D::Create(); |
| 621 int max_size = 0; | 673 int max_size = 0; |
| 622 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); | 674 context->getIntegerv(GL_MAX_TEXTURE_SIZE, &max_size); |
| 623 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); | 675 SetScrollbarBounds(gfx::Size(max_size + 100, max_size + 100)); |
| 624 RunTest(true, true, true); | 676 RunTest(true, true, true); |
| 625 } | 677 } |
| 626 | 678 |
| 627 class FakeLayerTreeHost : public LayerTreeHost { | 679 class ScrollbarLayerTestResourceCreationAndRelease : public ScrollbarLayerTest { |
| 628 public: | 680 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, | 681 void TestResourceUpload(int num_updates, |
| 691 size_t expected_resources, | 682 size_t expected_resources, |
| 692 int expected_created, | 683 int expected_created, |
| 693 int expected_deleted, | 684 int expected_deleted, |
| 694 bool use_solid_color_scrollbar) { | 685 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)); | 686 scoped_ptr<Scrollbar> scrollbar(new FakeScrollbar(false, true, false)); |
| 699 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 687 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 700 scoped_refptr<Layer> content_layer = Layer::Create(); | 688 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 701 scoped_refptr<Layer> scrollbar_layer; | 689 scoped_refptr<Layer> scrollbar_layer; |
| 702 if (use_solid_color_scrollbar) { | 690 if (use_solid_color_scrollbar) { |
| 703 const int kThumbThickness = 3; | 691 const int kThumbThickness = 3; |
| 704 const int kTrackStart = 0; | 692 const int kTrackStart = 0; |
| 705 const bool kIsLeftSideVerticalScrollbar = false; | 693 const bool kIsLeftSideVerticalScrollbar = false; |
| 706 scrollbar_layer = | 694 scrollbar_layer = |
| 707 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), | 695 SolidColorScrollbarLayer::Create(scrollbar->Orientation(), |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 | 730 |
| 743 // A non-solid-color scrollbar should have requested two textures. | 731 // A non-solid-color scrollbar should have requested two textures. |
| 744 EXPECT_EQ(expected_resources, layer_tree_host_->UIResourceCount()); | 732 EXPECT_EQ(expected_resources, layer_tree_host_->UIResourceCount()); |
| 745 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); | 733 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); |
| 746 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); | 734 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); |
| 747 | 735 |
| 748 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 736 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 749 | 737 |
| 750 scrollbar_layer->ClearRenderSurface(); | 738 scrollbar_layer->ClearRenderSurface(); |
| 751 } | 739 } |
| 752 | |
| 753 protected: | |
| 754 FakeLayerTreeHostClient fake_client_; | |
| 755 LayerTreeSettings layer_tree_settings_; | |
| 756 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; | |
| 757 }; | 740 }; |
| 758 | 741 |
| 759 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, ResourceUpload) { | 742 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, ResourceUpload) { |
| 760 bool use_solid_color_scrollbars = false; | 743 bool use_solid_color_scrollbars = false; |
| 761 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); | 744 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); |
| 762 int num_updates[3] = {1, 5, 10}; | 745 int num_updates[3] = {1, 5, 10}; |
| 746 int created = 0; |
| 747 int deleted = 0; |
| 763 for (int j = 0; j < 3; j++) { | 748 for (int j = 0; j < 3; j++) { |
| 764 TestResourceUpload(num_updates[j], | 749 created += num_updates[j] * 2; |
| 765 2, | 750 deleted = created - 2; |
| 766 num_updates[j] * 2, | 751 TestResourceUpload(num_updates[j], 2, created, deleted, |
| 767 (num_updates[j] - 1) * 2, | |
| 768 use_solid_color_scrollbars); | 752 use_solid_color_scrollbars); |
| 769 } | 753 } |
| 770 } | 754 } |
| 771 | 755 |
| 772 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, | 756 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, |
| 773 SolidColorNoResourceUpload) { | 757 SolidColorNoResourceUpload) { |
| 774 bool use_solid_color_scrollbars = true; | 758 bool use_solid_color_scrollbars = true; |
| 775 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); | 759 TestResourceUpload(0, 0, 0, 0, use_solid_color_scrollbars); |
| 776 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); | 760 TestResourceUpload(1, 0, 0, 0, use_solid_color_scrollbars); |
| 777 } | 761 } |
| 778 | 762 |
| 779 TEST_F(ScrollbarLayerTestResourceCreationAndRelease, TestResourceUpdate) { | 763 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); | 764 gfx::Point scrollbar_location(0, 185); |
| 788 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 765 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 789 scoped_refptr<Layer> content_layer = Layer::Create(); | 766 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 790 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 767 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 791 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); | 768 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); |
| 792 | 769 |
| 793 layer_tree_root->AddChild(content_layer); | 770 layer_tree_root->AddChild(content_layer); |
| 794 layer_tree_root->AddChild(scrollbar_layer); | 771 layer_tree_root->AddChild(scrollbar_layer); |
| 795 | 772 |
| 796 layer_tree_host_->SetRootLayer(layer_tree_root); | 773 layer_tree_host_->SetRootLayer(layer_tree_root); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 911 EXPECT_NE(0, scrollbar_layer->track_resource_id()); | 888 EXPECT_NE(0, scrollbar_layer->track_resource_id()); |
| 912 EXPECT_EQ(0, scrollbar_layer->thumb_resource_id()); | 889 EXPECT_EQ(0, scrollbar_layer->thumb_resource_id()); |
| 913 EXPECT_EQ(resource_count, layer_tree_host_->UIResourceCount()); | 890 EXPECT_EQ(resource_count, layer_tree_host_->UIResourceCount()); |
| 914 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); | 891 EXPECT_EQ(expected_created, layer_tree_host_->TotalUIResourceCreated()); |
| 915 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); | 892 EXPECT_EQ(expected_deleted, layer_tree_host_->TotalUIResourceDeleted()); |
| 916 | 893 |
| 917 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 894 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 918 scrollbar_layer->ClearRenderSurface(); | 895 scrollbar_layer->ClearRenderSurface(); |
| 919 } | 896 } |
| 920 | 897 |
| 921 class ScaledScrollbarLayerTestResourceCreation : public testing::Test { | 898 class ScaledScrollbarLayerTestResourceCreation : public ScrollbarLayerTest { |
| 922 public: | 899 public: |
| 923 ScaledScrollbarLayerTestResourceCreation() | |
| 924 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | |
| 925 | |
| 926 void TestResourceUpload(const float test_scale) { | 900 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); | 901 gfx::Point scrollbar_location(0, 185); |
| 931 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 902 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 932 scoped_refptr<Layer> content_layer = Layer::Create(); | 903 scoped_refptr<Layer> content_layer = Layer::Create(); |
| 933 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 904 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 934 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); | 905 FakePaintedScrollbarLayer::Create(false, true, layer_tree_root->id()); |
| 935 | 906 |
| 936 layer_tree_root->AddChild(content_layer); | 907 layer_tree_root->AddChild(content_layer); |
| 937 layer_tree_root->AddChild(scrollbar_layer); | 908 layer_tree_root->AddChild(scrollbar_layer); |
| 938 | 909 |
| 939 layer_tree_host_->SetRootLayer(layer_tree_root); | 910 layer_tree_host_->SetRootLayer(layer_tree_root); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 969 scrollbar_layer->Update(&queue, &occlusion_tracker); | 940 scrollbar_layer->Update(&queue, &occlusion_tracker); |
| 970 | 941 |
| 971 // Verify that we have not generated any content uploads that are larger | 942 // Verify that we have not generated any content uploads that are larger |
| 972 // than their destination textures. | 943 // than their destination textures. |
| 973 | 944 |
| 974 gfx::Size track_size = layer_tree_host_->ui_resource_size( | 945 gfx::Size track_size = layer_tree_host_->ui_resource_size( |
| 975 scrollbar_layer->track_resource_id()); | 946 scrollbar_layer->track_resource_id()); |
| 976 gfx::Size thumb_size = layer_tree_host_->ui_resource_size( | 947 gfx::Size thumb_size = layer_tree_host_->ui_resource_size( |
| 977 scrollbar_layer->thumb_resource_id()); | 948 scrollbar_layer->thumb_resource_id()); |
| 978 | 949 |
| 979 EXPECT_LE(track_size.width(), scrollbar_layer->content_bounds().width()); | 950 EXPECT_LE(track_size.width(), |
| 980 EXPECT_LE(track_size.height(), scrollbar_layer->content_bounds().height()); | 951 scrollbar_layer->internal_content_bounds().width()); |
| 981 EXPECT_LE(thumb_size.width(), scrollbar_layer->content_bounds().width()); | 952 EXPECT_LE(track_size.height(), |
| 982 EXPECT_LE(thumb_size.height(), scrollbar_layer->content_bounds().height()); | 953 scrollbar_layer->internal_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()); |
| 983 | 958 |
| 984 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); | 959 testing::Mock::VerifyAndClearExpectations(layer_tree_host_.get()); |
| 985 | 960 |
| 986 scrollbar_layer->ClearRenderSurface(); | 961 scrollbar_layer->ClearRenderSurface(); |
| 987 } | 962 } |
| 988 | |
| 989 protected: | |
| 990 FakeLayerTreeHostClient fake_client_; | |
| 991 LayerTreeSettings layer_tree_settings_; | |
| 992 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; | |
| 993 }; | 963 }; |
| 994 | 964 |
| 995 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { | 965 TEST_F(ScaledScrollbarLayerTestResourceCreation, ScaledResourceUpload) { |
| 996 // Pick a test scale that moves the scrollbar's (non-zero) position to | 966 // Pick a test scale that moves the scrollbar's (non-zero) position to |
| 997 // a non-pixel-aligned location. | 967 // a non-pixel-aligned location. |
| 998 TestResourceUpload(.041f); | 968 TestResourceUpload(.041f); |
| 999 TestResourceUpload(1.41f); | 969 TestResourceUpload(1.41f); |
| 1000 TestResourceUpload(4.1f); | 970 TestResourceUpload(4.1f); |
| 1001 } | 971 } |
| 1002 | 972 |
| 1003 class ScaledScrollbarLayerTestScaledRasterization : public testing::Test { | 973 class ScaledScrollbarLayerTestScaledRasterization : public ScrollbarLayerTest { |
| 1004 public: | 974 public: |
| 1005 ScaledScrollbarLayerTestScaledRasterization() | |
| 1006 : fake_client_(FakeLayerTreeHostClient::DIRECT_3D) {} | |
| 1007 | |
| 1008 void TestScale(const gfx::Rect scrollbar_rect, const float test_scale) { | 975 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; | 976 bool paint_during_update = true; |
| 1013 bool has_thumb = false; | 977 bool has_thumb = false; |
| 1014 scoped_refptr<Layer> layer_tree_root = Layer::Create(); | 978 scoped_refptr<Layer> layer_tree_root = Layer::Create(); |
| 1015 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = | 979 scoped_refptr<FakePaintedScrollbarLayer> scrollbar_layer = |
| 1016 FakePaintedScrollbarLayer::Create(paint_during_update, | 980 FakePaintedScrollbarLayer::Create(paint_during_update, |
| 1017 has_thumb, | 981 has_thumb, |
| 1018 layer_tree_root->id()); | 982 layer_tree_root->id()); |
| 1019 | 983 |
| 1020 layer_tree_root->AddChild(scrollbar_layer); | 984 layer_tree_root->AddChild(scrollbar_layer); |
| 1021 | 985 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1075 } | 1039 } |
| 1076 | 1040 |
| 1077 protected: | 1041 protected: |
| 1078 // On Android, Skia uses ABGR | 1042 // On Android, Skia uses ABGR |
| 1079 static SkColor argb_to_skia(SkColor c) { | 1043 static SkColor argb_to_skia(SkColor c) { |
| 1080 return (SkColorGetA(c) << SK_A32_SHIFT) | | 1044 return (SkColorGetA(c) << SK_A32_SHIFT) | |
| 1081 (SkColorGetR(c) << SK_R32_SHIFT) | | 1045 (SkColorGetR(c) << SK_R32_SHIFT) | |
| 1082 (SkColorGetG(c) << SK_G32_SHIFT) | | 1046 (SkColorGetG(c) << SK_G32_SHIFT) | |
| 1083 (SkColorGetB(c) << SK_B32_SHIFT); | 1047 (SkColorGetB(c) << SK_B32_SHIFT); |
| 1084 } | 1048 } |
| 1085 | |
| 1086 FakeLayerTreeHostClient fake_client_; | |
| 1087 LayerTreeSettings layer_tree_settings_; | |
| 1088 scoped_ptr<FakeLayerTreeHost> layer_tree_host_; | |
| 1089 }; | 1049 }; |
| 1090 | 1050 |
| 1091 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) { | 1051 TEST_F(ScaledScrollbarLayerTestScaledRasterization, TestLostPrecisionInClip) { |
| 1092 // Try rasterization at coordinates and scale that caused problematic | 1052 // Try rasterization at coordinates and scale that caused problematic |
| 1093 // rounding and clipping errors. | 1053 // rounding and clipping errors. |
| 1094 // Vertical Scrollbars. | 1054 // Vertical Scrollbars. |
| 1095 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); | 1055 TestScale(gfx::Rect(1240, 0, 15, 1333), 2.7754839f); |
| 1096 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); | 1056 TestScale(gfx::Rect(1240, 0, 15, 677), 2.46677136f); |
| 1097 | 1057 |
| 1098 // Horizontal Scrollbars. | 1058 // Horizontal Scrollbars. |
| 1099 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); | 1059 TestScale(gfx::Rect(0, 1240, 1333, 15), 2.7754839f); |
| 1100 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); | 1060 TestScale(gfx::Rect(0, 1240, 677, 15), 2.46677136f); |
| 1101 } | 1061 } |
| 1102 | 1062 |
| 1103 } // namespace | 1063 } // namespace |
| 1104 } // namespace cc | 1064 } // namespace cc |
| OLD | NEW |