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/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 1549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1560 iteration_stage_(TilePriority::EVENTUALLY), | 1560 iteration_stage_(TilePriority::EVENTUALLY), |
1561 required_for_activation_(false), | 1561 required_for_activation_(false), |
1562 layer_(NULL) {} | 1562 layer_(NULL) {} |
1563 | 1563 |
1564 PictureLayerImpl::LayerEvictionTileIterator::LayerEvictionTileIterator( | 1564 PictureLayerImpl::LayerEvictionTileIterator::LayerEvictionTileIterator( |
1565 PictureLayerImpl* layer, | 1565 PictureLayerImpl* layer, |
1566 TreePriority tree_priority) | 1566 TreePriority tree_priority) |
1567 : iterator_index_(0), | 1567 : iterator_index_(0), |
1568 iteration_stage_(TilePriority::EVENTUALLY), | 1568 iteration_stage_(TilePriority::EVENTUALLY), |
1569 required_for_activation_(false), | 1569 required_for_activation_(false), |
1570 layer_(layer) { | 1570 layer_(layer), |
| 1571 tree_priority_(tree_priority) { |
1571 // Early out if the layer has no tilings. | 1572 // Early out if the layer has no tilings. |
1572 // TODO(vmpstr): Once tile priorities are determined by the iterators, ensure | 1573 // TODO(vmpstr): Once tile priorities are determined by the iterators, ensure |
1573 // that layers that don't have valid tile priorities have lowest priorities so | 1574 // that layers that don't have valid tile priorities have lowest priorities so |
1574 // they evict their tiles first (crbug.com/381704) | 1575 // they evict their tiles first (crbug.com/381704) |
1575 if (!layer_->tilings_ || !layer_->tilings_->num_tilings()) | 1576 if (!layer_->tilings_ || !layer_->tilings_->num_tilings()) |
1576 return; | 1577 return; |
1577 | 1578 |
1578 size_t high_res_tiling_index = layer_->tilings_->num_tilings(); | 1579 size_t high_res_tiling_index = layer_->tilings_->num_tilings(); |
1579 size_t low_res_tiling_index = layer_->tilings_->num_tilings(); | 1580 size_t low_res_tiling_index = layer_->tilings_->num_tilings(); |
1580 for (size_t i = 0; i < layer_->tilings_->num_tilings(); ++i) { | 1581 for (size_t i = 0; i < layer_->tilings_->num_tilings(); ++i) { |
1581 PictureLayerTiling* tiling = layer_->tilings_->tiling_at(i); | 1582 PictureLayerTiling* tiling = layer_->tilings_->tiling_at(i); |
1582 if (tiling->resolution() == HIGH_RESOLUTION) | 1583 if (tiling->resolution() == HIGH_RESOLUTION) |
1583 high_res_tiling_index = i; | 1584 high_res_tiling_index = i; |
1584 else if (tiling->resolution() == LOW_RESOLUTION) | 1585 else if (tiling->resolution() == LOW_RESOLUTION) |
1585 low_res_tiling_index = i; | 1586 low_res_tiling_index = i; |
1586 } | 1587 } |
1587 | 1588 |
1588 iterators_.reserve(layer_->tilings_->num_tilings()); | 1589 iterators_.reserve(layer_->tilings_->num_tilings()); |
| 1590 tilings_.reserve(layer_->tilings_->num_tilings()); |
1589 | 1591 |
1590 // Higher resolution non-ideal goes first. | 1592 // Higher resolution non-ideal goes first. |
1591 for (size_t i = 0; i < high_res_tiling_index; ++i) { | 1593 for (size_t i = 0; i < high_res_tiling_index; ++i) |
1592 iterators_.push_back(PictureLayerTiling::TilingEvictionTileIterator( | 1594 tilings_.push_back(layer_->tilings_->tiling_at(i)); |
1593 layer_->tilings_->tiling_at(i), tree_priority)); | |
1594 } | |
1595 | 1595 |
1596 // Lower resolution non-ideal goes next. | 1596 // Lower resolution non-ideal goes next. |
1597 for (size_t i = layer_->tilings_->num_tilings() - 1; | 1597 for (size_t i = layer_->tilings_->num_tilings() - 1; |
1598 i > high_res_tiling_index; | 1598 i > high_res_tiling_index; |
1599 --i) { | 1599 --i) { |
1600 PictureLayerTiling* tiling = layer_->tilings_->tiling_at(i); | 1600 PictureLayerTiling* tiling = layer_->tilings_->tiling_at(i); |
1601 if (tiling->resolution() == LOW_RESOLUTION) | 1601 if (tiling->resolution() == LOW_RESOLUTION) |
1602 continue; | 1602 continue; |
1603 | 1603 |
1604 iterators_.push_back( | 1604 tilings_.push_back(tiling); |
1605 PictureLayerTiling::TilingEvictionTileIterator(tiling, tree_priority)); | |
1606 } | 1605 } |
1607 | 1606 |
1608 // Now, put the low res tiling if we have one. | 1607 // Now, put the low res tiling if we have one. |
1609 if (low_res_tiling_index < layer_->tilings_->num_tilings()) { | 1608 if (low_res_tiling_index < layer_->tilings_->num_tilings()) |
1610 iterators_.push_back(PictureLayerTiling::TilingEvictionTileIterator( | 1609 tilings_.push_back(layer_->tilings_->tiling_at(low_res_tiling_index)); |
1611 layer_->tilings_->tiling_at(low_res_tiling_index), tree_priority)); | |
1612 } | |
1613 | 1610 |
1614 // Finally, put the high res tiling if we have one. | 1611 // Finally, put the high res tiling if we have one. |
1615 if (high_res_tiling_index < layer_->tilings_->num_tilings()) { | 1612 if (high_res_tiling_index < layer_->tilings_->num_tilings()) |
1616 iterators_.push_back(PictureLayerTiling::TilingEvictionTileIterator( | 1613 tilings_.push_back(layer_->tilings_->tiling_at(high_res_tiling_index)); |
1617 layer_->tilings_->tiling_at(high_res_tiling_index), tree_priority)); | |
1618 } | |
1619 | 1614 |
1620 DCHECK_GT(iterators_.size(), 0u); | 1615 DCHECK_GT(tilings_.size(), 0u); |
1621 | 1616 |
| 1617 EnsureCurrentIteratorCreated(); |
1622 if (!iterators_[iterator_index_] || | 1618 if (!iterators_[iterator_index_] || |
1623 !IsCorrectType(&iterators_[iterator_index_])) { | 1619 !IsCorrectType(&iterators_[iterator_index_])) { |
1624 AdvanceToNextIterator(); | 1620 AdvanceToNextIterator(); |
1625 } | 1621 } |
1626 } | 1622 } |
1627 | 1623 |
1628 PictureLayerImpl::LayerEvictionTileIterator::~LayerEvictionTileIterator() {} | 1624 PictureLayerImpl::LayerEvictionTileIterator::~LayerEvictionTileIterator() {} |
1629 | 1625 |
1630 Tile* PictureLayerImpl::LayerEvictionTileIterator::operator*() { | 1626 Tile* PictureLayerImpl::LayerEvictionTileIterator::operator*() { |
1631 DCHECK(*this); | 1627 DCHECK(*this); |
(...skipping 14 matching lines...) Expand all Loading... |
1646 !IsCorrectType(&iterators_[iterator_index_])) { | 1642 !IsCorrectType(&iterators_[iterator_index_])) { |
1647 AdvanceToNextIterator(); | 1643 AdvanceToNextIterator(); |
1648 } | 1644 } |
1649 return *this; | 1645 return *this; |
1650 } | 1646 } |
1651 | 1647 |
1652 void PictureLayerImpl::LayerEvictionTileIterator::AdvanceToNextIterator() { | 1648 void PictureLayerImpl::LayerEvictionTileIterator::AdvanceToNextIterator() { |
1653 ++iterator_index_; | 1649 ++iterator_index_; |
1654 | 1650 |
1655 while (true) { | 1651 while (true) { |
1656 while (iterator_index_ < iterators_.size()) { | 1652 while (iterator_index_ < tilings_.size()) { |
| 1653 EnsureCurrentIteratorCreated(); |
1657 if (iterators_[iterator_index_] && | 1654 if (iterators_[iterator_index_] && |
1658 IsCorrectType(&iterators_[iterator_index_])) { | 1655 IsCorrectType(&iterators_[iterator_index_])) { |
1659 return; | 1656 return; |
1660 } | 1657 } |
1661 ++iterator_index_; | 1658 ++iterator_index_; |
1662 } | 1659 } |
1663 | 1660 |
1664 // If we're NOW and required_for_activation, then this was the last pass | 1661 // If we're NOW and required_for_activation, then this was the last pass |
1665 // through the iterators. | 1662 // through the iterators. |
1666 if (iteration_stage_ == TilePriority::NOW && required_for_activation_) | 1663 if (iteration_stage_ == TilePriority::NOW && required_for_activation_) |
1667 break; | 1664 break; |
1668 | 1665 |
1669 if (!required_for_activation_) { | 1666 if (!required_for_activation_) { |
1670 required_for_activation_ = true; | 1667 required_for_activation_ = true; |
1671 } else { | 1668 } else { |
1672 required_for_activation_ = false; | 1669 required_for_activation_ = false; |
1673 iteration_stage_ = | 1670 iteration_stage_ = |
1674 static_cast<TilePriority::PriorityBin>(iteration_stage_ - 1); | 1671 static_cast<TilePriority::PriorityBin>(iteration_stage_ - 1); |
1675 } | 1672 } |
1676 iterator_index_ = 0; | 1673 iterator_index_ = 0; |
1677 } | 1674 } |
1678 } | 1675 } |
1679 | 1676 |
1680 PictureLayerImpl::LayerEvictionTileIterator::operator bool() const { | 1677 PictureLayerImpl::LayerEvictionTileIterator::operator bool() const { |
1681 return iterator_index_ < iterators_.size(); | 1678 return iterator_index_ < tilings_.size(); |
1682 } | 1679 } |
1683 | 1680 |
1684 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( | 1681 bool PictureLayerImpl::LayerEvictionTileIterator::IsCorrectType( |
1685 PictureLayerTiling::TilingEvictionTileIterator* it) const { | 1682 PictureLayerTiling::TilingEvictionTileIterator* it) const { |
1686 return it->get_type() == iteration_stage_ && | 1683 return it->get_type() == iteration_stage_ && |
1687 (**it)->required_for_activation() == required_for_activation_; | 1684 (**it)->required_for_activation() == required_for_activation_; |
1688 } | 1685 } |
1689 | 1686 |
| 1687 void |
| 1688 PictureLayerImpl::LayerEvictionTileIterator::EnsureCurrentIteratorCreated() { |
| 1689 if (iterator_index_ < iterators_.size()) |
| 1690 return; |
| 1691 |
| 1692 DCHECK_EQ(iterator_index_, iterators_.size()); |
| 1693 DCHECK_LT(iterator_index_, tilings_.size()); |
| 1694 |
| 1695 iterators_.push_back(PictureLayerTiling::TilingEvictionTileIterator( |
| 1696 tilings_[iterator_index_], tree_priority_)); |
| 1697 } |
| 1698 |
1690 } // namespace cc | 1699 } // namespace cc |
OLD | NEW |