OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "cc/picture_layer_tiling_set.h" |
| 6 |
| 7 namespace cc { |
| 8 |
| 9 PictureLayerTilingSet::PictureLayerTilingSet( |
| 10 PictureLayerTilingClient * client) |
| 11 : client_(client) { |
| 12 } |
| 13 |
| 14 PictureLayerTilingSet::~PictureLayerTilingSet() { |
| 15 } |
| 16 |
| 17 void PictureLayerTilingSet::CloneFrom(const PictureLayerTilingSet& other) { |
| 18 layer_bounds_ = other.layer_bounds_; |
| 19 tilings_.clear(); |
| 20 tilings_.reserve(other.tilings_.size()); |
| 21 for (size_t i = 0; i < other.tilings_.size(); ++i) { |
| 22 tilings_.append(other.tilings_[i]->Clone()); |
| 23 } |
| 24 } |
| 25 |
| 26 void PictureLayerTilingSet::SetLayerBounds(gfx::Size layer_bounds) { |
| 27 layer_bounds_ = layer_bounds; |
| 28 for (size_t i = 0; i < tilings_.size(); ++i) |
| 29 tilings_[i]->SetLayerBounds(layer_bounds); |
| 30 } |
| 31 |
| 32 gfx::Size PictureLayerTilingSet::LayerBounds() const { |
| 33 return layer_bounds_; |
| 34 } |
| 35 |
| 36 void PictureLayerTilingSet::Invalidate(const Region& invalidation) { |
| 37 for (size_t i = 0; i < tilings_.size(); ++i) |
| 38 tilings_[i]->Invalidate(invalidation); |
| 39 } |
| 40 |
| 41 void PictureLayerTilingSet::AddTiling(float contents_scale, |
| 42 gfx::Size tile_size) { |
| 43 tilings_.append(PictureLayerTiling::Create(contents_scale, tile_size)); |
| 44 tilings_.last()->SetClient(client_); |
| 45 tilings_.last()->SetLayerBounds(layer_bounds_); |
| 46 } |
| 47 |
| 48 PictureLayerTilingSet::Iterator::Iterator(PictureLayerTilingSet* set, |
| 49 float contents_scale, |
| 50 gfx::Rect content_rect) |
| 51 : set_(set), |
| 52 contents_scale_(contents_scale), |
| 53 current_tiling_(-1) { |
| 54 missing_region_.Union(content_rect); |
| 55 ++(*this); |
| 56 } |
| 57 |
| 58 PictureLayerTilingSet::Iterator::~Iterator() { |
| 59 } |
| 60 |
| 61 gfx::Rect PictureLayerTilingSet::Iterator::geometry_rect() const { |
| 62 if (!tiling_iter_) { |
| 63 if (!region_iter_.has_rect()) |
| 64 return gfx::Rect(); |
| 65 return region_iter_.rect(); |
| 66 } |
| 67 return tiling_iter_.geometry_rect(); |
| 68 } |
| 69 |
| 70 gfx::RectF PictureLayerTilingSet::Iterator::texture_rect() const { |
| 71 if (!tiling_iter_) |
| 72 return gfx::RectF(); |
| 73 return tiling_iter_.texture_rect(); |
| 74 } |
| 75 |
| 76 gfx::Size PictureLayerTilingSet::Iterator::texture_size() const { |
| 77 if (!tiling_iter_) |
| 78 return gfx::Size(); |
| 79 return tiling_iter_.texture_size(); |
| 80 } |
| 81 |
| 82 Tile* PictureLayerTilingSet::Iterator::operator->() const { |
| 83 if (!tiling_iter_) |
| 84 return NULL; |
| 85 return *tiling_iter_; |
| 86 } |
| 87 |
| 88 Tile* PictureLayerTilingSet::Iterator::operator*() const { |
| 89 if (!tiling_iter_) |
| 90 return NULL; |
| 91 return *tiling_iter_; |
| 92 } |
| 93 |
| 94 PictureLayerTilingSet::Iterator& PictureLayerTilingSet::Iterator::operator++() { |
| 95 bool first_time = current_tiling_ < 0; |
| 96 |
| 97 if (!*this && !first_time) |
| 98 return *this; |
| 99 |
| 100 if (tiling_iter_) |
| 101 ++tiling_iter_; |
| 102 |
| 103 // Loop until we find a valid place to stop. |
| 104 while (true) { |
| 105 while (tiling_iter_ && !tiling_iter_->resource_id()) { |
| 106 missing_region_.Union(tiling_iter_.geometry_rect()); |
| 107 ++tiling_iter_; |
| 108 } |
| 109 if (tiling_iter_) |
| 110 return *this; |
| 111 |
| 112 // If the set of current rects for this tiling is done, go to the next |
| 113 // tiling and set up to iterate through all of the remaining holes. |
| 114 // This will also happen the first time through the loop. |
| 115 if (!region_iter_.has_rect()) { |
| 116 current_tiling_++; |
| 117 current_region_.Swap(missing_region_); |
| 118 missing_region_.Clear(); |
| 119 region_iter_ = Region::Iterator(current_region_); |
| 120 |
| 121 // All done and all filled. |
| 122 if (!region_iter_.has_rect()) { |
| 123 current_tiling_ = set_->tilings_.size(); |
| 124 return *this; |
| 125 } |
| 126 |
| 127 // No more valid tiles, return this checkerboard rect. |
| 128 if (current_tiling_ >= static_cast<int>(set_->tilings_.size())) |
| 129 return *this; |
| 130 } |
| 131 |
| 132 // Pop a rect off. If there are no more tilings, then these will be |
| 133 // treated as geometry with null tiles that the caller can checkerboard. |
| 134 gfx::Rect last_rect = region_iter_.rect(); |
| 135 region_iter_.next(); |
| 136 |
| 137 // Done, found next checkerboard rect to return. |
| 138 if (current_tiling_ >= static_cast<int>(set_->tilings_.size())) |
| 139 return *this; |
| 140 |
| 141 // Construct a new iterator for the next tiling, but we need to loop |
| 142 // again until we get to a valid one. |
| 143 tiling_iter_ = PictureLayerTiling::Iterator( |
| 144 set_->tilings_[current_tiling_], |
| 145 contents_scale_, |
| 146 last_rect); |
| 147 } |
| 148 |
| 149 return *this; |
| 150 } |
| 151 |
| 152 PictureLayerTilingSet::Iterator::operator bool() const { |
| 153 return current_tiling_ < static_cast<int>(set_->tilings_.size()) || |
| 154 region_iter_.has_rect(); |
| 155 } |
| 156 |
| 157 } // namespace cc |
OLD | NEW |