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

Side by Side Diff: cc/picture_layer_tiling_set.cc

Issue 11704002: cc: Generate tilings at other scales for impl-side painting (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address review comments Created 7 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/picture_layer_tiling_set.h" 5 #include "cc/picture_layer_tiling_set.h"
6 6
7 namespace cc { 7 namespace cc {
8 8
9 namespace {
10
11 class LargestToSmallestScaleFunctor {
12 public:
13 bool operator() (PictureLayerTiling* left, PictureLayerTiling* right) {
14 return left->contents_scale() > right->contents_scale();
15 }
16 };
17
18 } // namespace
19
20
9 PictureLayerTilingSet::PictureLayerTilingSet( 21 PictureLayerTilingSet::PictureLayerTilingSet(
10 PictureLayerTilingClient * client) 22 PictureLayerTilingClient * client)
11 : client_(client) { 23 : client_(client) {
12 } 24 }
13 25
14 PictureLayerTilingSet::~PictureLayerTilingSet() { 26 PictureLayerTilingSet::~PictureLayerTilingSet() {
15 } 27 }
16 28
17 void PictureLayerTilingSet::CloneAll( 29 void PictureLayerTilingSet::CloneAll(
18 const PictureLayerTilingSet& other, 30 const PictureLayerTilingSet& other,
(...skipping 11 matching lines...) Expand all
30 void PictureLayerTilingSet::Clone( 42 void PictureLayerTilingSet::Clone(
31 const PictureLayerTiling* tiling, 43 const PictureLayerTiling* tiling,
32 const Region& invalidation) { 44 const Region& invalidation) {
33 45
34 for (size_t i = 0; i < tilings_.size(); ++i) 46 for (size_t i = 0; i < tilings_.size(); ++i)
35 DCHECK_NE(tilings_[i]->contents_scale(), tiling->contents_scale()); 47 DCHECK_NE(tilings_[i]->contents_scale(), tiling->contents_scale());
36 48
37 tilings_.append(tiling->Clone()); 49 tilings_.append(tiling->Clone());
38 tilings_.last()->SetClient(client_); 50 tilings_.last()->SetClient(client_);
39 tilings_.last()->Invalidate(invalidation); 51 tilings_.last()->Invalidate(invalidation);
52
53 sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor());
40 } 54 }
41 55
42 void PictureLayerTilingSet::SetLayerBounds(gfx::Size layer_bounds) { 56 void PictureLayerTilingSet::SetLayerBounds(gfx::Size layer_bounds) {
43 if (layer_bounds_ == layer_bounds) 57 if (layer_bounds_ == layer_bounds)
44 return; 58 return;
45 layer_bounds_ = layer_bounds; 59 layer_bounds_ = layer_bounds;
46 for (size_t i = 0; i < tilings_.size(); ++i) 60 for (size_t i = 0; i < tilings_.size(); ++i)
47 tilings_[i]->SetLayerBounds(layer_bounds); 61 tilings_[i]->SetLayerBounds(layer_bounds);
48 } 62 }
49 63
50 gfx::Size PictureLayerTilingSet::LayerBounds() const { 64 gfx::Size PictureLayerTilingSet::LayerBounds() const {
51 return layer_bounds_; 65 return layer_bounds_;
52 } 66 }
53 67
54 const PictureLayerTiling* PictureLayerTilingSet::AddTiling( 68 PictureLayerTiling* PictureLayerTilingSet::AddTiling(
55 float contents_scale, 69 float contents_scale,
56 gfx::Size tile_size) { 70 gfx::Size tile_size) {
57 tilings_.append(PictureLayerTiling::Create(contents_scale, tile_size)); 71 tilings_.append(PictureLayerTiling::Create(contents_scale, tile_size));
58 tilings_.last()->SetClient(client_); 72 PictureLayerTiling* appended = tilings_.last();
59 tilings_.last()->SetLayerBounds(layer_bounds_); 73 appended->SetClient(client_);
60 return tilings_.last(); 74 appended->SetLayerBounds(layer_bounds_);
75
76 sort(tilings_.begin(), tilings_.end(), LargestToSmallestScaleFunctor());
77 return appended;
78 }
79
80 void PictureLayerTilingSet::RemoveAll() {
81 tilings_.clear();
82 }
83
84 void PictureLayerTilingSet::Remove(PictureLayerTiling* tiling) {
85 for (size_t i = 0; i < tilings_.size(); ++i) {
86 if (tilings_[i] == tiling) {
87 tilings_.remove(i);
88 return;
89 }
90 }
61 } 91 }
62 92
63 void PictureLayerTilingSet::Reset() { 93 void PictureLayerTilingSet::Reset() {
64 for (size_t i = 0; i < tilings_.size(); ++i) 94 for (size_t i = 0; i < tilings_.size(); ++i)
65 tilings_[i]->Reset(); 95 tilings_[i]->Reset();
66 } 96 }
67 97
68 PictureLayerTilingSet::Iterator::Iterator(const PictureLayerTilingSet* set, 98 PictureLayerTilingSet::Iterator::Iterator(
69 float contents_scale, 99 const PictureLayerTilingSet* set,
70 gfx::Rect content_rect) 100 float contents_scale,
101 gfx::Rect content_rect,
102 float ideal_contents_scale)
71 : set_(set), 103 : set_(set),
72 contents_scale_(contents_scale), 104 contents_scale_(contents_scale),
105 ideal_contents_scale_(ideal_contents_scale),
73 current_tiling_(-1) { 106 current_tiling_(-1) {
74 missing_region_.Union(content_rect); 107 missing_region_.Union(content_rect);
108
109 for (ideal_tiling_ = 0;
110 ideal_tiling_ < set_->tilings_.size();
111 ++ideal_tiling_) {
112 PictureLayerTiling* tiling = set_->tilings_[ideal_tiling_];
113 if (tiling->contents_scale() < ideal_contents_scale_) {
114 if (ideal_tiling_ > 0)
115 ideal_tiling_--;
116 break;
117 }
118 }
119
75 ++(*this); 120 ++(*this);
76 } 121 }
77 122
78 PictureLayerTilingSet::Iterator::~Iterator() { 123 PictureLayerTilingSet::Iterator::~Iterator() {
79 } 124 }
80 125
81 gfx::Rect PictureLayerTilingSet::Iterator::geometry_rect() const { 126 gfx::Rect PictureLayerTilingSet::Iterator::geometry_rect() const {
82 if (!tiling_iter_) { 127 if (!tiling_iter_) {
83 if (!region_iter_.has_rect()) 128 if (!region_iter_.has_rect())
84 return gfx::Rect(); 129 return gfx::Rect();
(...skipping 19 matching lines...) Expand all
104 return NULL; 149 return NULL;
105 return *tiling_iter_; 150 return *tiling_iter_;
106 } 151 }
107 152
108 Tile* PictureLayerTilingSet::Iterator::operator*() const { 153 Tile* PictureLayerTilingSet::Iterator::operator*() const {
109 if (!tiling_iter_) 154 if (!tiling_iter_)
110 return NULL; 155 return NULL;
111 return *tiling_iter_; 156 return *tiling_iter_;
112 } 157 }
113 158
159 PictureLayerTiling* PictureLayerTilingSet::Iterator::CurrentTiling() {
160 if (current_tiling_ < 0 || current_tiling_ >= set_->tilings_.size())
161 return NULL;
162 return set_->tilings_[current_tiling_];
163 }
164
165 int PictureLayerTilingSet::Iterator::NextTiling() const {
166 // Prefer hi-res tiles, but prefer the least hi-res if bigger than ideal,
167 // since it won't add any additional fidelity on screen.
168 if (current_tiling_ < 0)
169 return ideal_tiling_;
170 else if (current_tiling_ > ideal_tiling_)
171 return current_tiling_ + 1;
172 else if (current_tiling_)
173 return current_tiling_ - 1;
174 else
175 return ideal_tiling_ + 1;
176 }
177
114 PictureLayerTilingSet::Iterator& PictureLayerTilingSet::Iterator::operator++() { 178 PictureLayerTilingSet::Iterator& PictureLayerTilingSet::Iterator::operator++() {
115 bool first_time = current_tiling_ < 0; 179 bool first_time = current_tiling_ < 0;
116 180
117 if (!*this && !first_time) 181 if (!*this && !first_time)
118 return *this; 182 return *this;
119 183
120 if (tiling_iter_) 184 if (tiling_iter_)
121 ++tiling_iter_; 185 ++tiling_iter_;
122 186
123 // Loop until we find a valid place to stop. 187 // Loop until we find a valid place to stop.
124 while (true) { 188 while (true) {
125 while (tiling_iter_ && (!*tiling_iter_ || !tiling_iter_->GetResourceId())) { 189 while (tiling_iter_ && (!*tiling_iter_ || !tiling_iter_->GetResourceId())) {
126 missing_region_.Union(tiling_iter_.geometry_rect()); 190 missing_region_.Union(tiling_iter_.geometry_rect());
127 ++tiling_iter_; 191 ++tiling_iter_;
128 } 192 }
129 if (tiling_iter_) 193 if (tiling_iter_)
130 return *this; 194 return *this;
131 195
132 // If the set of current rects for this tiling is done, go to the next 196 // If the set of current rects for this tiling is done, go to the next
133 // tiling and set up to iterate through all of the remaining holes. 197 // tiling and set up to iterate through all of the remaining holes.
134 // This will also happen the first time through the loop. 198 // This will also happen the first time through the loop.
135 if (!region_iter_.has_rect()) { 199 if (!region_iter_.has_rect()) {
136 current_tiling_++; 200 current_tiling_ = NextTiling();
137 current_region_.Swap(missing_region_); 201 current_region_.Swap(missing_region_);
138 missing_region_.Clear(); 202 missing_region_.Clear();
139 region_iter_ = Region::Iterator(current_region_); 203 region_iter_ = Region::Iterator(current_region_);
140 204
141 // All done and all filled. 205 // All done and all filled.
142 if (!region_iter_.has_rect()) { 206 if (!region_iter_.has_rect()) {
143 current_tiling_ = set_->tilings_.size(); 207 current_tiling_ = set_->tilings_.size();
144 return *this; 208 return *this;
145 } 209 }
146 210
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 device_viewport, 252 device_viewport,
189 layer_content_scale_x, 253 layer_content_scale_x,
190 layer_content_scale_y, 254 layer_content_scale_y,
191 last_screen_transform, 255 last_screen_transform,
192 current_screen_transform, 256 current_screen_transform,
193 time_delta); 257 time_delta);
194 } 258 }
195 } 259 }
196 260
197 } // namespace cc 261 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698