Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(770)

Unified Diff: cc/picture_layer_tiling_set.cc

Issue 11417111: cc: Add PictureLayerTilingSet to manage PictureLayerTiling (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix win_rel Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « cc/picture_layer_tiling_set.h ('k') | cc/picture_layer_tiling_set_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/picture_layer_tiling_set.cc
diff --git a/cc/picture_layer_tiling_set.cc b/cc/picture_layer_tiling_set.cc
new file mode 100644
index 0000000000000000000000000000000000000000..b5d97feee87b38ce84e823480cd127ff41016cd3
--- /dev/null
+++ b/cc/picture_layer_tiling_set.cc
@@ -0,0 +1,157 @@
+// Copyright 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "cc/picture_layer_tiling_set.h"
+
+namespace cc {
+
+PictureLayerTilingSet::PictureLayerTilingSet(
+ PictureLayerTilingClient * client)
+ : client_(client) {
+}
+
+PictureLayerTilingSet::~PictureLayerTilingSet() {
+}
+
+void PictureLayerTilingSet::CloneFrom(const PictureLayerTilingSet& other) {
+ layer_bounds_ = other.layer_bounds_;
+ tilings_.clear();
+ tilings_.reserve(other.tilings_.size());
+ for (size_t i = 0; i < other.tilings_.size(); ++i) {
+ tilings_.append(other.tilings_[i]->Clone());
+ }
+}
+
+void PictureLayerTilingSet::SetLayerBounds(gfx::Size layer_bounds) {
+ layer_bounds_ = layer_bounds;
+ for (size_t i = 0; i < tilings_.size(); ++i)
+ tilings_[i]->SetLayerBounds(layer_bounds);
+}
+
+gfx::Size PictureLayerTilingSet::LayerBounds() const {
+ return layer_bounds_;
+}
+
+void PictureLayerTilingSet::Invalidate(const Region& invalidation) {
+ for (size_t i = 0; i < tilings_.size(); ++i)
+ tilings_[i]->Invalidate(invalidation);
+}
+
+void PictureLayerTilingSet::AddTiling(float contents_scale,
+ gfx::Size tile_size) {
+ tilings_.append(PictureLayerTiling::Create(contents_scale, tile_size));
+ tilings_.last()->SetClient(client_);
+ tilings_.last()->SetLayerBounds(layer_bounds_);
+}
+
+PictureLayerTilingSet::Iterator::Iterator(PictureLayerTilingSet* set,
+ float contents_scale,
+ gfx::Rect content_rect)
+ : set_(set),
+ contents_scale_(contents_scale),
+ current_tiling_(-1) {
+ missing_region_.Union(content_rect);
+ ++(*this);
+}
+
+PictureLayerTilingSet::Iterator::~Iterator() {
+}
+
+gfx::Rect PictureLayerTilingSet::Iterator::geometry_rect() const {
+ if (!tiling_iter_) {
+ if (!region_iter_.has_rect())
+ return gfx::Rect();
+ return region_iter_.rect();
+ }
+ return tiling_iter_.geometry_rect();
+}
+
+gfx::RectF PictureLayerTilingSet::Iterator::texture_rect() const {
+ if (!tiling_iter_)
+ return gfx::RectF();
+ return tiling_iter_.texture_rect();
+}
+
+gfx::Size PictureLayerTilingSet::Iterator::texture_size() const {
+ if (!tiling_iter_)
+ return gfx::Size();
+ return tiling_iter_.texture_size();
+}
+
+Tile* PictureLayerTilingSet::Iterator::operator->() const {
+ if (!tiling_iter_)
+ return NULL;
+ return *tiling_iter_;
+}
+
+Tile* PictureLayerTilingSet::Iterator::operator*() const {
+ if (!tiling_iter_)
+ return NULL;
+ return *tiling_iter_;
+}
+
+PictureLayerTilingSet::Iterator& PictureLayerTilingSet::Iterator::operator++() {
+ bool first_time = current_tiling_ < 0;
+
+ if (!*this && !first_time)
+ return *this;
+
+ if (tiling_iter_)
+ ++tiling_iter_;
+
+ // Loop until we find a valid place to stop.
+ while (true) {
+ while (tiling_iter_ && !tiling_iter_->resource_id()) {
+ missing_region_.Union(tiling_iter_.geometry_rect());
+ ++tiling_iter_;
+ }
+ if (tiling_iter_)
+ return *this;
+
+ // If the set of current rects for this tiling is done, go to the next
+ // tiling and set up to iterate through all of the remaining holes.
+ // This will also happen the first time through the loop.
+ if (!region_iter_.has_rect()) {
+ current_tiling_++;
+ current_region_.Swap(missing_region_);
+ missing_region_.Clear();
+ region_iter_ = Region::Iterator(current_region_);
+
+ // All done and all filled.
+ if (!region_iter_.has_rect()) {
+ current_tiling_ = set_->tilings_.size();
+ return *this;
+ }
+
+ // No more valid tiles, return this checkerboard rect.
+ if (current_tiling_ >= static_cast<int>(set_->tilings_.size()))
+ return *this;
+ }
+
+ // Pop a rect off. If there are no more tilings, then these will be
+ // treated as geometry with null tiles that the caller can checkerboard.
+ gfx::Rect last_rect = region_iter_.rect();
+ region_iter_.next();
+
+ // Done, found next checkerboard rect to return.
+ if (current_tiling_ >= static_cast<int>(set_->tilings_.size()))
+ return *this;
+
+ // Construct a new iterator for the next tiling, but we need to loop
+ // again until we get to a valid one.
+ tiling_iter_ = PictureLayerTiling::Iterator(
+ set_->tilings_[current_tiling_],
+ contents_scale_,
+ last_rect);
+ }
+
+ return *this;
+}
+
+PictureLayerTilingSet::Iterator::operator bool() const {
+ return current_tiling_ < static_cast<int>(set_->tilings_.size()) ||
+ region_iter_.has_rect();
+}
+
+} // namespace cc
« no previous file with comments | « cc/picture_layer_tiling_set.h ('k') | cc/picture_layer_tiling_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698