Chromium Code Reviews| 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 "cc/layers/layer_impl.h" | 5 #include "cc/layers/layer_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 51 int id, | 51 int id, |
| 52 scoped_refptr<SyncedScrollOffset> scroll_offset) | 52 scoped_refptr<SyncedScrollOffset> scroll_offset) |
| 53 : parent_(nullptr), | 53 : parent_(nullptr), |
| 54 scroll_parent_(nullptr), | 54 scroll_parent_(nullptr), |
| 55 clip_parent_(nullptr), | 55 clip_parent_(nullptr), |
| 56 mask_layer_id_(-1), | 56 mask_layer_id_(-1), |
| 57 replica_layer_id_(-1), | 57 replica_layer_id_(-1), |
| 58 layer_id_(id), | 58 layer_id_(id), |
| 59 layer_tree_impl_(tree_impl), | 59 layer_tree_impl_(tree_impl), |
| 60 layer_list_impl_(tree_impl->list()), | 60 layer_list_impl_(tree_impl->list()), |
| 61 scroll_offset_(scroll_offset), | |
| 62 scroll_clip_layer_id_(Layer::INVALID_ID), | 61 scroll_clip_layer_id_(Layer::INVALID_ID), |
| 63 main_thread_scrolling_reasons_( | 62 main_thread_scrolling_reasons_( |
| 64 MainThreadScrollingReason::kNotScrollingOnMain), | 63 MainThreadScrollingReason::kNotScrollingOnMain), |
| 65 user_scrollable_horizontal_(true), | 64 user_scrollable_horizontal_(true), |
| 66 user_scrollable_vertical_(true), | 65 user_scrollable_vertical_(true), |
| 67 double_sided_(true), | 66 double_sided_(true), |
| 68 should_flatten_transform_(true), | 67 should_flatten_transform_(true), |
| 69 should_flatten_transform_from_property_tree_(false), | 68 should_flatten_transform_from_property_tree_(false), |
| 70 layer_property_changed_(false), | 69 layer_property_changed_(false), |
| 71 masks_to_bounds_(false), | 70 masks_to_bounds_(false), |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 | 481 |
| 483 bool LayerImpl::scrollable() const { | 482 bool LayerImpl::scrollable() const { |
| 484 return scroll_clip_layer_id_ != Layer::INVALID_ID; | 483 return scroll_clip_layer_id_ != Layer::INVALID_ID; |
| 485 } | 484 } |
| 486 | 485 |
| 487 bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const { | 486 bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const { |
| 488 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_ | 487 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_ |
| 489 : user_scrollable_vertical_; | 488 : user_scrollable_vertical_; |
| 490 } | 489 } |
| 491 | 490 |
| 492 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() { | |
| 493 DCHECK(layer_tree_impl()->IsActiveTree()); | |
| 494 scroll_offset_->AbortCommit(); | |
| 495 } | |
| 496 | |
| 497 skia::RefPtr<SkPicture> LayerImpl::GetPicture() { | 491 skia::RefPtr<SkPicture> LayerImpl::GetPicture() { |
| 498 return skia::RefPtr<SkPicture>(); | 492 return skia::RefPtr<SkPicture>(); |
| 499 } | 493 } |
| 500 | 494 |
| 501 scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) { | 495 scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
| 502 return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_); | 496 return LayerImpl::Create(tree_impl, layer_id_); |
| 503 } | 497 } |
| 504 | 498 |
| 505 void LayerImpl::set_main_thread_scrolling_reasons( | 499 void LayerImpl::set_main_thread_scrolling_reasons( |
| 506 uint32_t main_thread_scrolling_reasons) { | 500 uint32_t main_thread_scrolling_reasons) { |
| 507 if (main_thread_scrolling_reasons_ == main_thread_scrolling_reasons) | 501 if (main_thread_scrolling_reasons_ == main_thread_scrolling_reasons) |
| 508 return; | 502 return; |
| 509 | 503 |
| 510 if (main_thread_scrolling_reasons & | 504 if (main_thread_scrolling_reasons & |
| 511 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects && | 505 MainThreadScrollingReason::kHasNonLayerViewportConstrainedObjects && |
| 512 layer_tree_impl()) { | 506 layer_tree_impl()) { |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 564 layer->NoteLayerPropertyChanged(); | 558 layer->NoteLayerPropertyChanged(); |
| 565 | 559 |
| 566 layer->SetScrollClipLayer(scroll_clip_layer_id_); | 560 layer->SetScrollClipLayer(scroll_clip_layer_id_); |
| 567 layer->SetElementId(element_id_); | 561 layer->SetElementId(element_id_); |
| 568 layer->SetMutableProperties(mutable_properties_); | 562 layer->SetMutableProperties(mutable_properties_); |
| 569 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); | 563 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 570 layer->set_user_scrollable_vertical(user_scrollable_vertical_); | 564 layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
| 571 | 565 |
| 572 layer->SetScrollCompensationAdjustment(scroll_compensation_adjustment_); | 566 layer->SetScrollCompensationAdjustment(scroll_compensation_adjustment_); |
| 573 | 567 |
| 574 layer->PushScrollOffset(nullptr); | |
| 575 | |
| 576 layer->Set3dSortingContextId(sorting_context_id_); | 568 layer->Set3dSortingContextId(sorting_context_id_); |
| 577 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); | 569 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); |
| 578 | 570 |
| 579 layer->SetTransformTreeIndex(transform_tree_index_); | 571 layer->SetTransformTreeIndex(transform_tree_index_); |
| 580 layer->SetClipTreeIndex(clip_tree_index_); | 572 layer->SetClipTreeIndex(clip_tree_index_); |
| 581 layer->SetEffectTreeIndex(effect_tree_index_); | 573 layer->SetEffectTreeIndex(effect_tree_index_); |
| 582 layer->SetScrollTreeIndex(scroll_tree_index_); | 574 layer->SetScrollTreeIndex(scroll_tree_index_); |
| 583 layer->set_offset_to_transform_parent(offset_to_transform_parent_); | 575 layer->set_offset_to_transform_parent(offset_to_transform_parent_); |
| 584 | 576 |
| 585 LayerImpl* scroll_parent = nullptr; | 577 LayerImpl* scroll_parent = nullptr; |
| (...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1290 frame_timing_requests_ = requests; | 1282 frame_timing_requests_ = requests; |
| 1291 frame_timing_requests_dirty_ = true; | 1283 frame_timing_requests_dirty_ = true; |
| 1292 SetNeedsPushProperties(); | 1284 SetNeedsPushProperties(); |
| 1293 } | 1285 } |
| 1294 | 1286 |
| 1295 void LayerImpl::GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids) { | 1287 void LayerImpl::GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids) { |
| 1296 for (const auto& request : frame_timing_requests_) | 1288 for (const auto& request : frame_timing_requests_) |
| 1297 request_ids->push_back(request.id()); | 1289 request_ids->push_back(request.id()); |
| 1298 } | 1290 } |
| 1299 | 1291 |
| 1292 const SyncedScrollOffset* LayerImpl::synced_scroll_offset() const { | |
|
ajuma
2016/03/01 22:54:20
Would it make sense (in a follow up CL) to move al
sunxd
2016/03/02 17:45:34
Yeah, it makes sense. But there might be a lot of
| |
| 1293 return layer_tree_impl()->property_trees()->scroll_tree.synced_scroll_offset( | |
| 1294 id()); | |
| 1295 } | |
| 1296 | |
| 1297 SyncedScrollOffset* LayerImpl::synced_scroll_offset() { | |
| 1298 return layer_tree_impl()->property_trees()->scroll_tree.synced_scroll_offset( | |
| 1299 id()); | |
| 1300 } | |
| 1301 | |
| 1300 void LayerImpl::SetTransform(const gfx::Transform& transform) { | 1302 void LayerImpl::SetTransform(const gfx::Transform& transform) { |
| 1301 if (transform_ == transform) | 1303 if (transform_ == transform) |
| 1302 return; | 1304 return; |
| 1303 | 1305 |
| 1304 transform_ = transform; | 1306 transform_ = transform; |
| 1305 transform_is_invertible_ = transform_.IsInvertible(); | 1307 transform_is_invertible_ = transform_.IsInvertible(); |
| 1306 NoteLayerPropertyChangedForSubtree(); | 1308 NoteLayerPropertyChangedForSubtree(); |
| 1307 } | 1309 } |
| 1308 | 1310 |
| 1309 void LayerImpl::SetTransformAndInvertibility(const gfx::Transform& transform, | 1311 void LayerImpl::SetTransformAndInvertibility(const gfx::Transform& transform, |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1435 update_rect_ = update_rect; | 1437 update_rect_ = update_rect; |
| 1436 SetNeedsPushProperties(); | 1438 SetNeedsPushProperties(); |
| 1437 } | 1439 } |
| 1438 | 1440 |
| 1439 void LayerImpl::AddDamageRect(const gfx::Rect& damage_rect) { | 1441 void LayerImpl::AddDamageRect(const gfx::Rect& damage_rect) { |
| 1440 damage_rect_.Union(damage_rect); | 1442 damage_rect_.Union(damage_rect); |
| 1441 } | 1443 } |
| 1442 | 1444 |
| 1443 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) { | 1445 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) { |
| 1444 DCHECK(IsActive()); | 1446 DCHECK(IsActive()); |
| 1445 if (scroll_offset_->SetCurrent(scroll_offset)) | 1447 if (synced_scroll_offset()->SetCurrent(scroll_offset)) |
| 1446 DidUpdateScrollOffset(); | 1448 DidUpdateScrollOffset(); |
| 1447 } | 1449 } |
| 1448 | 1450 |
| 1449 void LayerImpl::PushScrollOffsetFromMainThread( | |
| 1450 const gfx::ScrollOffset& scroll_offset) { | |
| 1451 PushScrollOffset(&scroll_offset); | |
| 1452 } | |
| 1453 | |
| 1454 void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue( | |
| 1455 const gfx::ScrollOffset& scroll_offset) { | |
| 1456 scroll_offset_->set_clobber_active_value(); | |
| 1457 PushScrollOffset(&scroll_offset); | |
| 1458 } | |
| 1459 | |
| 1460 gfx::ScrollOffset LayerImpl::PullDeltaForMainThread() { | |
| 1461 // TODO(miletus): Remove all this temporary flooring machinery when | |
| 1462 // Blink fully supports fractional scrolls. | |
| 1463 gfx::ScrollOffset current_offset = CurrentScrollOffset(); | |
| 1464 gfx::ScrollOffset current_delta = IsActive() | |
| 1465 ? scroll_offset_->Delta() | |
| 1466 : scroll_offset_->PendingDelta().get(); | |
| 1467 gfx::ScrollOffset floored_delta(floor(current_delta.x()), | |
| 1468 floor(current_delta.y())); | |
| 1469 gfx::ScrollOffset diff_delta = floored_delta - current_delta; | |
| 1470 gfx::ScrollOffset tmp_offset = current_offset + diff_delta; | |
| 1471 scroll_offset_->SetCurrent(tmp_offset); | |
| 1472 gfx::ScrollOffset delta = scroll_offset_->PullDeltaForMainThread(); | |
| 1473 scroll_offset_->SetCurrent(current_offset); | |
| 1474 return delta; | |
| 1475 } | |
| 1476 | |
| 1477 gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const { | 1451 gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const { |
| 1478 return scroll_offset_->Current(IsActive()); | 1452 return synced_scroll_offset()->Current(IsActive()); |
| 1479 } | 1453 } |
| 1480 | 1454 |
| 1481 gfx::Vector2dF LayerImpl::ScrollDelta() const { | 1455 gfx::Vector2dF LayerImpl::ScrollDelta() const { |
| 1482 if (IsActive()) | 1456 if (IsActive()) |
| 1483 return gfx::Vector2dF(scroll_offset_->Delta().x(), | 1457 return gfx::Vector2dF(synced_scroll_offset()->Delta().x(), |
| 1484 scroll_offset_->Delta().y()); | 1458 synced_scroll_offset()->Delta().y()); |
| 1485 else | 1459 else |
| 1486 return gfx::Vector2dF(scroll_offset_->PendingDelta().get().x(), | 1460 return gfx::Vector2dF(synced_scroll_offset()->PendingDelta().get().x(), |
| 1487 scroll_offset_->PendingDelta().get().y()); | 1461 synced_scroll_offset()->PendingDelta().get().y()); |
| 1488 } | 1462 } |
| 1489 | 1463 |
| 1490 void LayerImpl::SetScrollDelta(const gfx::Vector2dF& delta) { | 1464 void LayerImpl::SetScrollDelta(const gfx::Vector2dF& delta) { |
| 1491 DCHECK(IsActive()); | 1465 DCHECK(IsActive()); |
| 1492 DCHECK(scrollable() || delta.IsZero()); | 1466 DCHECK(scrollable() || delta.IsZero()); |
| 1493 SetCurrentScrollOffset(scroll_offset_->ActiveBase() + | 1467 SetCurrentScrollOffset(synced_scroll_offset()->ActiveBase() + |
| 1494 gfx::ScrollOffset(delta)); | 1468 gfx::ScrollOffset(delta)); |
| 1495 } | 1469 } |
| 1496 | 1470 |
| 1497 gfx::ScrollOffset LayerImpl::BaseScrollOffset() const { | 1471 gfx::ScrollOffset LayerImpl::BaseScrollOffset() const { |
| 1498 if (IsActive()) | 1472 if (IsActive()) |
| 1499 return scroll_offset_->ActiveBase(); | 1473 return synced_scroll_offset()->ActiveBase(); |
| 1500 else | 1474 else |
| 1501 return scroll_offset_->PendingBase(); | 1475 return synced_scroll_offset()->PendingBase(); |
| 1502 } | 1476 } |
| 1503 | 1477 |
| 1504 void LayerImpl::PushScrollOffset(const gfx::ScrollOffset* scroll_offset) { | 1478 void LayerImpl::PushScrollOffsetFromMainThread( |
| 1505 DCHECK(scroll_offset || IsActive()); | 1479 const gfx::ScrollOffset& scroll_offset) { |
| 1506 bool changed = false; | 1480 bool changed = false; |
| 1507 if (scroll_offset) { | 1481 DCHECK(!IsActive() || !layer_list_impl_->FindPendingLayerById(id())); |
| 1508 DCHECK(!IsActive() || !layer_list_impl_->FindPendingLayerById(id())); | 1482 changed |= synced_scroll_offset()->PushFromMainThread(scroll_offset); |
| 1509 changed |= scroll_offset_->PushFromMainThread(*scroll_offset); | 1483 |
| 1510 } | |
| 1511 if (IsActive()) { | 1484 if (IsActive()) { |
| 1512 changed |= scroll_offset_->PushPendingToActive(); | 1485 changed |= synced_scroll_offset()->PushPendingToActive(); |
| 1513 } | 1486 } |
| 1514 | 1487 |
| 1515 if (changed) | 1488 if (changed) |
| 1516 DidUpdateScrollOffset(); | 1489 DidUpdateScrollOffset(); |
| 1517 } | 1490 } |
| 1518 | 1491 |
| 1519 void LayerImpl::UpdatePropertyTreeScrollOffset() { | 1492 void LayerImpl::UpdatePropertyTreeScrollOffset() { |
| 1520 // TODO(enne): in the future, scrolling should update the scroll tree | 1493 // TODO(enne): in the future, scrolling should update the scroll tree |
| 1521 // directly instead of going through layers. | 1494 // directly instead of going through layers. |
| 1522 if (transform_tree_index_ != -1) { | 1495 if (transform_tree_index_ != -1) { |
| 1523 TransformTree& transform_tree = | 1496 TransformTree& transform_tree = |
| 1524 layer_tree_impl()->property_trees()->transform_tree; | 1497 layer_tree_impl()->property_trees()->transform_tree; |
| 1525 TransformNode* node = transform_tree.Node(transform_tree_index_); | 1498 TransformNode* node = transform_tree.Node(transform_tree_index_); |
| 1526 gfx::ScrollOffset current_offset = scroll_offset_->Current(IsActive()); | 1499 gfx::ScrollOffset current_offset = |
| 1500 synced_scroll_offset()->Current(IsActive()); | |
| 1527 if (node->data.scroll_offset != current_offset) { | 1501 if (node->data.scroll_offset != current_offset) { |
| 1528 node->data.scroll_offset = current_offset; | 1502 node->data.scroll_offset = current_offset; |
| 1529 node->data.needs_local_transform_update = true; | 1503 node->data.needs_local_transform_update = true; |
| 1530 transform_tree.set_needs_update(true); | 1504 transform_tree.set_needs_update(true); |
| 1531 } | 1505 } |
| 1532 } | 1506 } |
| 1533 } | 1507 } |
| 1534 | 1508 |
| 1535 void LayerImpl::DidUpdateScrollOffset() { | 1509 void LayerImpl::DidUpdateScrollOffset() { |
| 1536 DCHECK(scroll_offset_); | |
| 1537 | |
| 1538 layer_tree_impl()->DidUpdateScrollState(id()); | 1510 layer_tree_impl()->DidUpdateScrollState(id()); |
| 1539 NoteLayerPropertyChangedForSubtree(); | 1511 NoteLayerPropertyChangedForSubtree(); |
| 1540 | |
| 1541 UpdatePropertyTreeScrollOffset(); | 1512 UpdatePropertyTreeScrollOffset(); |
| 1542 | 1513 |
| 1543 // Inform the pending twin that a property changed. | 1514 // Inform the pending twin that a property changed. |
| 1544 if (layer_tree_impl()->IsActiveTree()) { | 1515 if (layer_tree_impl()->IsActiveTree()) { |
| 1545 LayerImpl* pending_twin = layer_list_impl_->FindPendingLayerById(id()); | 1516 LayerImpl* pending_twin = layer_list_impl_->FindPendingLayerById(id()); |
| 1546 if (pending_twin) | 1517 if (pending_twin) |
| 1547 pending_twin->DidUpdateScrollOffset(); | 1518 pending_twin->DidUpdateScrollOffset(); |
| 1548 } | 1519 } |
| 1549 } | 1520 } |
| 1550 | 1521 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1631 | 1602 |
| 1632 state->SetInteger("draws_content", DrawsContent()); | 1603 state->SetInteger("draws_content", DrawsContent()); |
| 1633 state->SetInteger("gpu_memory_usage", | 1604 state->SetInteger("gpu_memory_usage", |
| 1634 base::saturated_cast<int>(GPUMemoryUsageInBytes())); | 1605 base::saturated_cast<int>(GPUMemoryUsageInBytes())); |
| 1635 | 1606 |
| 1636 if (mutable_properties_ != MutableProperty::kNone) { | 1607 if (mutable_properties_ != MutableProperty::kNone) { |
| 1637 state->SetInteger("element_id", base::saturated_cast<int>(element_id_)); | 1608 state->SetInteger("element_id", base::saturated_cast<int>(element_id_)); |
| 1638 state->SetInteger("mutable_properties", mutable_properties_); | 1609 state->SetInteger("mutable_properties", mutable_properties_); |
| 1639 } | 1610 } |
| 1640 | 1611 |
| 1641 MathUtil::AddToTracedValue( | 1612 MathUtil::AddToTracedValue("scroll_offset", |
| 1642 "scroll_offset", scroll_offset_ ? scroll_offset_->Current(IsActive()) | 1613 synced_scroll_offset() |
| 1643 : gfx::ScrollOffset(), | 1614 ? synced_scroll_offset()->Current(IsActive()) |
| 1644 state); | 1615 : gfx::ScrollOffset(), |
| 1616 state); | |
| 1645 | 1617 |
| 1646 MathUtil::AddToTracedValue("transform_origin", transform_origin_, state); | 1618 MathUtil::AddToTracedValue("transform_origin", transform_origin_, state); |
| 1647 | 1619 |
| 1648 bool clipped; | 1620 bool clipped; |
| 1649 gfx::QuadF layer_quad = | 1621 gfx::QuadF layer_quad = |
| 1650 MathUtil::MapQuad(ScreenSpaceTransform(), | 1622 MathUtil::MapQuad(ScreenSpaceTransform(), |
| 1651 gfx::QuadF(gfx::RectF(gfx::Rect(bounds()))), &clipped); | 1623 gfx::QuadF(gfx::RectF(gfx::Rect(bounds()))), &clipped); |
| 1652 MathUtil::AddToTracedValue("layer_quad", layer_quad, state); | 1624 MathUtil::AddToTracedValue("layer_quad", layer_quad, state); |
| 1653 if (!touch_event_handler_region_.IsEmpty()) { | 1625 if (!touch_event_handler_region_.IsEmpty()) { |
| 1654 state->BeginArray("touch_event_handler_region"); | 1626 state->BeginArray("touch_event_handler_region"); |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1831 .layer_transforms_should_scale_layer_contents) { | 1803 .layer_transforms_should_scale_layer_contents) { |
| 1832 return default_scale; | 1804 return default_scale; |
| 1833 } | 1805 } |
| 1834 | 1806 |
| 1835 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( | 1807 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1836 DrawTransform(), default_scale); | 1808 DrawTransform(), default_scale); |
| 1837 return std::max(transform_scales.x(), transform_scales.y()); | 1809 return std::max(transform_scales.x(), transform_scales.y()); |
| 1838 } | 1810 } |
| 1839 | 1811 |
| 1840 } // namespace cc | 1812 } // namespace cc |
| OLD | NEW |