OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/trees/layer_tree_host_impl.h" | 5 #include "cc/trees/layer_tree_host_impl.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 | 203 |
204 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { | 204 for (size_t i = 0; i < scroll_info.scrolls.size(); ++i) { |
205 if (scroll_info.scrolls[i].layer_id != id) | 205 if (scroll_info.scrolls[i].layer_id != id) |
206 continue; | 206 continue; |
207 times_encountered++; | 207 times_encountered++; |
208 } | 208 } |
209 | 209 |
210 ASSERT_EQ(0, times_encountered); | 210 ASSERT_EQ(0, times_encountered); |
211 } | 211 } |
212 | 212 |
213 LayerImpl* SetupScrollAndContentsLayers(gfx::Size content_size) { | 213 LayerImpl* CreateScrollAndContentsLayers(LayerTreeImpl* layer_tree_impl, |
| 214 gfx::Size content_size) { |
214 scoped_ptr<LayerImpl> root = | 215 scoped_ptr<LayerImpl> root = |
215 LayerImpl::Create(host_impl_->active_tree(), 1); | 216 LayerImpl::Create(layer_tree_impl, 1); |
216 root->SetBounds(content_size); | 217 root->SetBounds(content_size); |
217 root->SetContentBounds(content_size); | 218 root->SetContentBounds(content_size); |
218 root->SetPosition(gfx::PointF()); | 219 root->SetPosition(gfx::PointF()); |
219 root->SetAnchorPoint(gfx::PointF()); | 220 root->SetAnchorPoint(gfx::PointF()); |
220 | 221 |
221 scoped_ptr<LayerImpl> scroll = | 222 scoped_ptr<LayerImpl> scroll = |
222 LayerImpl::Create(host_impl_->active_tree(), 2); | 223 LayerImpl::Create(layer_tree_impl, 2); |
223 LayerImpl* scroll_layer = scroll.get(); | 224 LayerImpl* scroll_layer = scroll.get(); |
224 scroll->SetScrollable(true); | 225 scroll->SetScrollable(true); |
225 scroll->SetScrollOffset(gfx::Vector2d()); | 226 scroll->SetScrollOffset(gfx::Vector2d()); |
226 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), | 227 scroll->SetMaxScrollOffset(gfx::Vector2d(content_size.width(), |
227 content_size.height())); | 228 content_size.height())); |
228 scroll->SetBounds(content_size); | 229 scroll->SetBounds(content_size); |
229 scroll->SetContentBounds(content_size); | 230 scroll->SetContentBounds(content_size); |
230 scroll->SetPosition(gfx::PointF()); | 231 scroll->SetPosition(gfx::PointF()); |
231 scroll->SetAnchorPoint(gfx::PointF()); | 232 scroll->SetAnchorPoint(gfx::PointF()); |
232 | 233 |
233 scoped_ptr<LayerImpl> contents = | 234 scoped_ptr<LayerImpl> contents = |
234 LayerImpl::Create(host_impl_->active_tree(), 3); | 235 LayerImpl::Create(layer_tree_impl, 3); |
235 contents->SetDrawsContent(true); | 236 contents->SetDrawsContent(true); |
236 contents->SetBounds(content_size); | 237 contents->SetBounds(content_size); |
237 contents->SetContentBounds(content_size); | 238 contents->SetContentBounds(content_size); |
238 contents->SetPosition(gfx::PointF()); | 239 contents->SetPosition(gfx::PointF()); |
239 contents->SetAnchorPoint(gfx::PointF()); | 240 contents->SetAnchorPoint(gfx::PointF()); |
240 | 241 |
241 scroll->AddChild(contents.Pass()); | 242 scroll->AddChild(contents.Pass()); |
242 root->AddChild(scroll.Pass()); | 243 root->AddChild(scroll.Pass()); |
243 | 244 |
244 host_impl_->active_tree()->SetRootLayer(root.Pass()); | 245 layer_tree_impl->SetRootLayer(root.Pass()); |
| 246 return scroll_layer; |
| 247 } |
| 248 |
| 249 LayerImpl* SetupScrollAndContentsLayers(gfx::Size content_size) { |
| 250 LayerImpl* scroll_layer = CreateScrollAndContentsLayers( |
| 251 host_impl_->active_tree(), content_size); |
245 host_impl_->active_tree()->DidBecomeActive(); | 252 host_impl_->active_tree()->DidBecomeActive(); |
246 return scroll_layer; | 253 return scroll_layer; |
247 } | 254 } |
248 | 255 |
249 scoped_ptr<LayerImpl> CreateScrollableLayer(int id, gfx::Size size) { | 256 scoped_ptr<LayerImpl> CreateScrollableLayer(int id, gfx::Size size) { |
250 scoped_ptr<LayerImpl> layer = | 257 scoped_ptr<LayerImpl> layer = |
251 LayerImpl::Create(host_impl_->active_tree(), id); | 258 LayerImpl::Create(host_impl_->active_tree(), id); |
252 layer->SetScrollable(true); | 259 layer->SetScrollable(true); |
253 layer->SetDrawsContent(true); | 260 layer->SetDrawsContent(true); |
254 layer->SetBounds(size); | 261 layer->SetBounds(size); |
(...skipping 2249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2504 EXPECT_EQ(current_offset + scroll_delta, | 2511 EXPECT_EQ(current_offset + scroll_delta, |
2505 scroll_delegate.last_set_scroll_offset()); | 2512 scroll_delegate.last_set_scroll_offset()); |
2506 | 2513 |
2507 current_offset = gfx::Vector2dF(42.f, 41.f); | 2514 current_offset = gfx::Vector2dF(42.f, 41.f); |
2508 scroll_delegate.set_getter_return_value(current_offset); | 2515 scroll_delegate.set_getter_return_value(current_offset); |
2509 host_impl_->ScrollBy(gfx::Point(), scroll_delta); | 2516 host_impl_->ScrollBy(gfx::Point(), scroll_delta); |
2510 EXPECT_EQ(current_offset + scroll_delta, | 2517 EXPECT_EQ(current_offset + scroll_delta, |
2511 scroll_delegate.last_set_scroll_offset()); | 2518 scroll_delegate.last_set_scroll_offset()); |
2512 host_impl_->ScrollEnd(); | 2519 host_impl_->ScrollEnd(); |
2513 | 2520 |
| 2521 // Forces a full tree synchronization and ensures that the scroll delegate |
| 2522 // sees the correct size of the new tree. |
| 2523 gfx::Size new_size(42, 24); |
| 2524 host_impl_->CreatePendingTree(); |
| 2525 CreateScrollAndContentsLayers(host_impl_->pending_tree(), new_size); |
| 2526 host_impl_->ActivatePendingTree(); |
| 2527 EXPECT_EQ(new_size, scroll_delegate.scrollable_size()); |
| 2528 |
2514 // Un-setting the delegate should propagate the delegate's current offset to | 2529 // Un-setting the delegate should propagate the delegate's current offset to |
2515 // the root scrollable layer. | 2530 // the root scrollable layer. |
2516 current_offset = gfx::Vector2dF(13.f, 12.f); | 2531 current_offset = gfx::Vector2dF(13.f, 12.f); |
2517 scroll_delegate.set_getter_return_value(current_offset); | 2532 scroll_delegate.set_getter_return_value(current_offset); |
2518 host_impl_->SetRootLayerScrollOffsetDelegate(NULL); | 2533 host_impl_->SetRootLayerScrollOffsetDelegate(NULL); |
2519 | 2534 |
2520 EXPECT_EQ(current_offset.ToString(), | 2535 EXPECT_EQ(current_offset.ToString(), |
2521 scroll_layer->TotalScrollOffset().ToString()); | 2536 scroll_layer->TotalScrollOffset().ToString()); |
2522 } | 2537 } |
2523 | 2538 |
(...skipping 4250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6774 host_impl_.reset(); | 6789 host_impl_.reset(); |
6775 | 6790 |
6776 // The CopyOutputResult's callback was cancelled, the CopyOutputResult | 6791 // The CopyOutputResult's callback was cancelled, the CopyOutputResult |
6777 // released, and the texture deleted. | 6792 // released, and the texture deleted. |
6778 EXPECT_TRUE(context_provider->HasOneRef()); | 6793 EXPECT_TRUE(context_provider->HasOneRef()); |
6779 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); | 6794 EXPECT_EQ(0u, context_provider->TestContext3d()->NumTextures()); |
6780 } | 6795 } |
6781 | 6796 |
6782 } // namespace | 6797 } // namespace |
6783 } // namespace cc | 6798 } // namespace cc |
OLD | NEW |