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

Side by Side Diff: cc/picture_layer_impl.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_impl.h" 5 #include "cc/picture_layer_impl.h"
6 6
7 #include "base/time.h" 7 #include "base/time.h"
8 #include "cc/append_quads_data.h" 8 #include "cc/append_quads_data.h"
9 #include "cc/checkerboard_draw_quad.h" 9 #include "cc/checkerboard_draw_quad.h"
10 #include "cc/debug_border_draw_quad.h" 10 #include "cc/debug_border_draw_quad.h"
11 #include "cc/debug_colors.h" 11 #include "cc/debug_colors.h"
12 #include "cc/layer_tree_impl.h" 12 #include "cc/layer_tree_impl.h"
13 #include "cc/math_util.h" 13 #include "cc/math_util.h"
14 #include "cc/quad_sink.h" 14 #include "cc/quad_sink.h"
15 #include "cc/solid_color_draw_quad.h" 15 #include "cc/solid_color_draw_quad.h"
16 #include "cc/tile_draw_quad.h" 16 #include "cc/tile_draw_quad.h"
17 #include "ui/gfx/quad_f.h" 17 #include "ui/gfx/quad_f.h"
18 #include "ui/gfx/size_conversions.h" 18 #include "ui/gfx/size_conversions.h"
19 19
20 namespace {
21 const float kMaxScaleRatioDuringPinch = 2.0f;
22 }
23
20 namespace cc { 24 namespace cc {
21 25
22 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* treeImpl, int id) 26 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* treeImpl, int id)
23 : LayerImpl(treeImpl, id), 27 : LayerImpl(treeImpl, id),
24 tilings_(this), 28 tilings_(this),
25 pile_(PicturePileImpl::Create()), 29 pile_(PicturePileImpl::Create()),
26 last_update_time_(0), 30 last_update_time_(0),
31 last_content_scale_(0),
32 ideal_contents_scale_(0),
27 is_mask_(false) { 33 is_mask_(false) {
28 } 34 }
29 35
30 PictureLayerImpl::~PictureLayerImpl() { 36 PictureLayerImpl::~PictureLayerImpl() {
31 } 37 }
32 38
33 const char* PictureLayerImpl::layerTypeAsString() const { 39 const char* PictureLayerImpl::layerTypeAsString() const {
34 return "PictureLayer"; 40 return "PictureLayer";
35 } 41 }
36 42
37 void PictureLayerImpl::appendQuads(QuadSink& quadSink, 43 void PictureLayerImpl::appendQuads(QuadSink& quadSink,
38 AppendQuadsData& appendQuadsData) { 44 AppendQuadsData& appendQuadsData) {
39 45
40 const gfx::Rect& rect = visibleContentRect(); 46 const gfx::Rect& rect = visibleContentRect();
41 gfx::Rect content_rect(gfx::Point(), contentBounds()); 47 gfx::Rect content_rect(gfx::Point(), contentBounds());
42 48
43 SharedQuadState* sharedQuadState = 49 SharedQuadState* sharedQuadState =
44 quadSink.useSharedQuadState(createSharedQuadState()); 50 quadSink.useSharedQuadState(createSharedQuadState());
45 bool clipped = false; 51 bool clipped = false;
46 gfx::QuadF target_quad = MathUtil::mapQuad( 52 gfx::QuadF target_quad = MathUtil::mapQuad(
47 drawTransform(), 53 drawTransform(),
48 gfx::QuadF(rect), 54 gfx::QuadF(rect),
49 clipped); 55 clipped);
50 bool isAxisAlignedInTarget = !clipped && target_quad.IsRectilinear(); 56 bool isAxisAlignedInTarget = !clipped && target_quad.IsRectilinear();
51 bool useAA = !isAxisAlignedInTarget; 57 bool useAA = !isAxisAlignedInTarget;
52 58
53 if (showDebugBorders()) { 59 if (showDebugBorders()) {
54 for (PictureLayerTilingSet::Iterator iter(&tilings_, 60 for (PictureLayerTilingSet::Iterator iter(&tilings_,
55 contentsScaleX(), 61 contentsScaleX(),
56 rect); 62 rect,
63 ideal_contents_scale_);
57 iter; 64 iter;
58 ++iter) { 65 ++iter) {
59 SkColor color; 66 SkColor color;
60 float width; 67 float width;
61 if (*iter && iter->GetResourceId()) { 68 if (*iter && iter->GetResourceId()) {
62 color = DebugColors::TileBorderColor(); 69 color = DebugColors::TileBorderColor();
63 width = DebugColors::TileBorderWidth(layerTreeImpl()); 70 width = DebugColors::TileBorderWidth(layerTreeImpl());
64 } else { 71 } else {
65 color = DebugColors::MissingTileBorderColor(); 72 color = DebugColors::MissingTileBorderColor();
66 width = DebugColors::MissingTileBorderWidth(layerTreeImpl()); 73 width = DebugColors::MissingTileBorderWidth(layerTreeImpl());
67 } 74 }
68 75
69 scoped_ptr<DebugBorderDrawQuad> debugBorderQuad = 76 scoped_ptr<DebugBorderDrawQuad> debugBorderQuad =
70 DebugBorderDrawQuad::Create(); 77 DebugBorderDrawQuad::Create();
71 gfx::Rect geometry_rect = iter.geometry_rect(); 78 gfx::Rect geometry_rect = iter.geometry_rect();
72 debugBorderQuad->SetNew(sharedQuadState, geometry_rect, color, width); 79 debugBorderQuad->SetNew(sharedQuadState, geometry_rect, color, width);
73 quadSink.append(debugBorderQuad.PassAs<DrawQuad>(), appendQuadsData); 80 quadSink.append(debugBorderQuad.PassAs<DrawQuad>(), appendQuadsData);
74 } 81 }
75 } 82 }
76 83
77 for (PictureLayerTilingSet::Iterator iter(&tilings_, contentsScaleX(), rect); 84 // Keep track of the tilings that were used so that tilings that are
85 // unused can be considered for removal.
86 std::vector<PictureLayerTiling*> seen_tilings;
87
88 for (PictureLayerTilingSet::Iterator iter(&tilings_,
89 contentsScaleX(),
90 rect,
91 ideal_contents_scale_);
78 iter; 92 iter;
79 ++iter) { 93 ++iter) {
80 ResourceProvider::ResourceId resource = 0; 94 ResourceProvider::ResourceId resource = 0;
81 if (*iter) 95 if (*iter)
82 resource = iter->GetResourceId(); 96 resource = iter->GetResourceId();
83 97
84 gfx::Rect geometry_rect = iter.geometry_rect(); 98 gfx::Rect geometry_rect = iter.geometry_rect();
85 99
86 if (!resource) { 100 if (!resource) {
87 if (drawCheckerboardForMissingTiles()) { 101 if (drawCheckerboardForMissingTiles()) {
(...skipping 27 matching lines...) Expand all
115 opaque_rect, 129 opaque_rect,
116 resource, 130 resource,
117 texture_rect, 131 texture_rect,
118 iter.texture_size(), 132 iter.texture_size(),
119 iter->contents_swizzled(), 133 iter->contents_swizzled(),
120 outside_left_edge && useAA, 134 outside_left_edge && useAA,
121 outside_top_edge && useAA, 135 outside_top_edge && useAA,
122 outside_right_edge && useAA, 136 outside_right_edge && useAA,
123 outside_bottom_edge && useAA); 137 outside_bottom_edge && useAA);
124 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData); 138 quadSink.append(quad.PassAs<DrawQuad>(), appendQuadsData);
139
140 if (!seen_tilings.size() || seen_tilings.back() != iter.CurrentTiling())
141 seen_tilings.push_back(iter.CurrentTiling());
125 } 142 }
143
144 // During a pinch, a user could zoom in and out, so throwing away a tiling may
145 // be premature.
146 if (!layerTreeImpl()->PinchGestureActive())
147 CleanUpUnusedTilings(seen_tilings);
126 } 148 }
127 149
128 void PictureLayerImpl::dumpLayerProperties(std::string*, int indent) const { 150 void PictureLayerImpl::dumpLayerProperties(std::string*, int indent) const {
129 // TODO(enne): implement me 151 // TODO(enne): implement me
130 } 152 }
131 153
132 void PictureLayerImpl::didUpdateTransforms() { 154 void PictureLayerImpl::didUpdateTransforms() {
133 gfx::Transform current_screen_space_transform = 155 gfx::Transform current_screen_space_transform =
134 screenSpaceTransform(); 156 screenSpaceTransform();
135 double current_time = 157 double current_time =
136 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF(); 158 (base::TimeTicks::Now() - base::TimeTicks()).InSecondsF();
137 double time_delta = 0; 159 double time_delta = 0;
138 if (last_update_time_ != 0 && last_bounds_ == bounds() && 160 if (last_update_time_ != 0 && last_bounds_ == bounds() &&
139 last_content_bounds_ == contentBounds() && 161 last_content_bounds_ == contentBounds() &&
140 last_content_scale_x_ == contentsScaleX() && 162 last_content_scale_ == contentsScaleX()) {
141 last_content_scale_y_ == contentsScaleY()) {
142 time_delta = current_time - last_update_time_; 163 time_delta = current_time - last_update_time_;
143 } 164 }
144 WhichTree tree = layerTreeImpl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; 165 WhichTree tree = layerTreeImpl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE;
145 tilings_.UpdateTilePriorities( 166 tilings_.UpdateTilePriorities(
146 tree, 167 tree,
147 layerTreeImpl()->device_viewport_size(), 168 layerTreeImpl()->device_viewport_size(),
169 last_content_scale_,
148 contentsScaleX(), 170 contentsScaleX(),
149 contentsScaleY(),
150 last_screen_space_transform_, 171 last_screen_space_transform_,
151 current_screen_space_transform, 172 current_screen_space_transform,
152 time_delta); 173 time_delta);
153 174
154 last_screen_space_transform_ = current_screen_space_transform; 175 last_screen_space_transform_ = current_screen_space_transform;
155 last_update_time_ = current_time; 176 last_update_time_ = current_time;
156 last_bounds_ = bounds(); 177 last_bounds_ = bounds();
157 last_content_bounds_ = contentBounds(); 178 last_content_bounds_ = contentBounds();
158 last_content_scale_x_ = contentsScaleX(); 179 last_content_scale_ = contentsScaleX();
159 last_content_scale_y_ = contentsScaleY();
160 } 180 }
161 181
162 void PictureLayerImpl::calculateContentsScale( 182 void PictureLayerImpl::calculateContentsScale(
163 float ideal_contents_scale, 183 float ideal_contents_scale,
164 float* contents_scale_x, 184 float* contents_scale_x,
165 float* contents_scale_y, 185 float* contents_scale_y,
166 gfx::Size* content_bounds) { 186 gfx::Size* content_bounds) {
167 if (!drawsContent()) { 187 if (!drawsContent()) {
168 DCHECK(!tilings_.num_tilings()); 188 DCHECK(!tilings_.num_tilings());
169 return; 189 return;
170 } 190 }
171 191
172 float min_contents_scale = layerTreeImpl()->settings().minimumContentsScale; 192 float min_contents_scale = layerTreeImpl()->settings().minimumContentsScale;
173 ideal_contents_scale = std::max(ideal_contents_scale, min_contents_scale); 193 ideal_contents_scale_ = std::max(ideal_contents_scale, min_contents_scale);
174 194
175 ManageTilings(ideal_contents_scale); 195 ManageTilings(ideal_contents_scale_);
176 196
177 // The content scale and bounds for a PictureLayerImpl is somewhat fictitious. 197 // The content scale and bounds for a PictureLayerImpl is somewhat fictitious.
178 // There are (usually) several tilings at different scales. However, the 198 // There are (usually) several tilings at different scales. However, the
179 // content bounds is the (integer!) space in which quads are generated. 199 // content bounds is the (integer!) space in which quads are generated.
180 // In order to guarantee that we can fill this integer space with any set of 200 // In order to guarantee that we can fill this integer space with any set of
181 // tilings (and then map back to floating point texture coordinates), the 201 // tilings (and then map back to floating point texture coordinates), the
182 // contents scale must be at least as large as the largest of the tilings. 202 // contents scale must be at least as large as the largest of the tilings.
183 float max_contents_scale = min_contents_scale; 203 float max_contents_scale = min_contents_scale;
184 for (size_t i = 0; i < tilings_.num_tilings(); ++i) { 204 for (size_t i = 0; i < tilings_.num_tilings(); ++i) {
185 const PictureLayerTiling* tiling = tilings_.tiling_at(i); 205 const PictureLayerTiling* tiling = tilings_.tiling_at(i);
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
232 void PictureLayerImpl::SetIsMask(bool is_mask) { 252 void PictureLayerImpl::SetIsMask(bool is_mask) {
233 if (is_mask_ == is_mask) 253 if (is_mask_ == is_mask)
234 return; 254 return;
235 is_mask_ = is_mask; 255 is_mask_ = is_mask;
236 tilings_.Reset(); 256 tilings_.Reset();
237 } 257 }
238 258
239 ResourceProvider::ResourceId PictureLayerImpl::contentsResourceId() const { 259 ResourceProvider::ResourceId PictureLayerImpl::contentsResourceId() const {
240 gfx::Rect content_rect(gfx::Point(), contentBounds()); 260 gfx::Rect content_rect(gfx::Point(), contentBounds());
241 float scale = contentsScaleX(); 261 float scale = contentsScaleX();
242 for (PictureLayerTilingSet::Iterator iter(&tilings_, scale, content_rect); 262 for (PictureLayerTilingSet::Iterator iter(&tilings_,
263 scale,
264 content_rect,
265 ideal_contents_scale_);
243 iter; 266 iter;
244 ++iter) { 267 ++iter) {
245 // Mask resource not ready yet. 268 // Mask resource not ready yet.
246 if (!*iter || !iter->GetResourceId()) 269 if (!*iter || !iter->GetResourceId())
247 return 0; 270 return 0;
248 // Masks only supported if they fit on exactly one tile. 271 // Masks only supported if they fit on exactly one tile.
249 if (iter.geometry_rect() != content_rect) 272 if (iter.geometry_rect() != content_rect)
250 return 0; 273 return 0;
251 return iter->GetResourceId(); 274 return iter->GetResourceId();
252 } 275 }
253 return 0; 276 return 0;
254 } 277 }
255 278
256 void PictureLayerImpl::AddTiling(float contents_scale, gfx::Size tile_size) { 279 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) {
257 if (contents_scale < layerTreeImpl()->settings().minimumContentsScale) 280 if (contents_scale < layerTreeImpl()->settings().minimumContentsScale)
258 return; 281 return NULL;
259 282
260 const PictureLayerTiling* tiling = tilings_.AddTiling( 283 PictureLayerTiling* tiling = tilings_.AddTiling(
261 contents_scale, 284 contents_scale,
262 tile_size); 285 TileSize());
263 286
264 // If a new tiling is created on the active tree, sync it to the pending tree 287 // If a new tiling is created on the active tree, sync it to the pending tree
265 // so that it can share the same tiles. 288 // so that it can share the same tiles.
266 if (layerTreeImpl()->IsPendingTree()) 289 if (layerTreeImpl()->IsPendingTree())
267 return; 290 return tiling;
268 291
269 PictureLayerImpl* pending_twin = static_cast<PictureLayerImpl*>( 292 PictureLayerImpl* pending_twin = static_cast<PictureLayerImpl*>(
270 layerTreeImpl()->FindPendingTreeLayerById(id())); 293 layerTreeImpl()->FindPendingTreeLayerById(id()));
271 if (!pending_twin) 294 if (!pending_twin)
272 return; 295 return tiling;
273 DCHECK_EQ(id(), pending_twin->id()); 296 DCHECK_EQ(id(), pending_twin->id());
274 pending_twin->SyncTiling(tiling); 297 pending_twin->SyncTiling(tiling);
298 return tiling;
275 } 299 }
276 300
277 gfx::Size PictureLayerImpl::TileSize() const { 301 gfx::Size PictureLayerImpl::TileSize() const {
278 if (is_mask_) { 302 if (is_mask_) {
279 int max_size = layerTreeImpl()->MaxTextureSize(); 303 int max_size = layerTreeImpl()->MaxTextureSize();
280 return gfx::Size( 304 return gfx::Size(
281 std::min(max_size, contentBounds().width()), 305 std::min(max_size, contentBounds().width()),
282 std::min(max_size, contentBounds().height())); 306 std::min(max_size, contentBounds().height()));
283 } 307 }
284 308
285 return layerTreeImpl()->settings().defaultTileSize; 309 return layerTreeImpl()->settings().defaultTileSize;
286 } 310 }
287 311
312 namespace {
313
314 inline float PositiveRatio(float float1, float float2) {
315 DCHECK(float1 > 0);
316 DCHECK(float2 > 0);
317 return float1 > float2 ? float1 / float2 : float2 / float1;
318 }
319
320 inline bool IsCloserToThan(
321 PictureLayerTiling* layer1,
322 PictureLayerTiling* layer2,
323 float contents_scale) {
324 // Absolute value for ratios.
325 float ratio1 = PositiveRatio(layer1->contents_scale(), contents_scale);
326 float ratio2 = PositiveRatio(layer2->contents_scale(), contents_scale);
327 return ratio1 < ratio2;
328 }
329
330 } // namespace
331
288 void PictureLayerImpl::ManageTilings(float ideal_contents_scale) { 332 void PictureLayerImpl::ManageTilings(float ideal_contents_scale) {
289 if (drawsContent()) { 333 DCHECK(ideal_contents_scale);
290 // TODO(enne): Add tilings during pinch zoom 334 float low_res_factor = layerTreeImpl()->settings().lowResContentsScaleFactor;
291 // TODO(enne): Consider culling old tilings after pinch finishes. 335 float low_res_contents_scale = ideal_contents_scale * low_res_factor;
292 if (!tilings_.num_tilings()) { 336
293 AddTiling(ideal_contents_scale, TileSize()); 337 // Remove any tilings that don't exactly match the contents scale from the
danakj 2013/01/09 00:22:49 nit: Remove any tilings from the pending tree that
enne (OOO) 2013/01/09 00:38:38 Done.
294 // TODO(enne): Add a low-res tiling as well. 338 // pending tree. The pending tree should always come in crisp. However,
339 // don't do this during a pinch, to avoid throwing away a tiling that should
340 // have been kept.
341 if (layerTreeImpl()->IsPendingTree() &&
342 !layerTreeImpl()->PinchGestureActive()) {
343 std::vector<PictureLayerTiling*> remove_list;
344 for (size_t i = 0; i < tilings_.num_tilings(); ++i) {
345 PictureLayerTiling* tiling = tilings_.tiling_at(i);
346 if (tiling->contents_scale() == ideal_contents_scale)
347 continue;
348 else if (tiling->contents_scale() == low_res_contents_scale)
danakj 2013/01/09 00:22:49 nit: don't need the else
enne (OOO) 2013/01/09 00:38:38 No, but I'd have to put it on multiple lines anywa
danakj 2013/01/09 00:40:20 I mean you don't need the "else" part. Just the if
349 continue;
350 remove_list.push_back(tiling);
295 } 351 }
296 } else { 352
297 // TODO(enne): This should be unnecessary once there are two trees. 353 for (size_t i = 0; i < remove_list.size(); ++i)
298 tilings_.Reset(); 354 tilings_.Remove(remove_list[i]);
danakj 2013/01/09 00:22:49 n^2 removal :/ i take it the sizes here aren't lar
enne (OOO) 2013/01/09 00:38:38 Yes, n <= 4 99% of the time, and maybe n <= 6 if y
299 } 355 }
356
357 // Find existing tilings closest to ideal high / low res
danakj 2013/01/09 00:22:49 nit: period
enne (OOO) 2013/01/09 00:38:38 Done.
358 PictureLayerTiling* high_res = NULL;
359 PictureLayerTiling* low_res = NULL;
360 for (size_t i = 0; i < tilings_.num_tilings(); ++i) {
361 PictureLayerTiling* tiling = tilings_.tiling_at(i);
362 if (!high_res || IsCloserToThan(tiling, high_res, ideal_contents_scale))
363 high_res = tiling;
364 if (!low_res || IsCloserToThan(tiling, low_res, low_res_contents_scale))
365 low_res = tiling;
366
367 // Reset all tilings to non-ideal until the end of this function.
368 tiling->set_resolution(NON_IDEAL_RESOLUTION);
369 }
370
371 // The active tree always has calcDrawProperties called on it first, and
372 // any tilings added to the active tree will be synced to the pending tree.
373 // Therefore, only add tilings to the active tree.
374 if (layerTreeImpl()->IsActiveTree()) {
375 if (layerTreeImpl()->PinchGestureActive() && high_res) {
376 // If zooming out, if only available high-res tiling is very high
377 // resolution, create additional tilings closer to the ideal.
378 // When zooming in, add some additional tilings so that content
379 // "crisps up" prior to releasing pinch.
380 float ratio = PositiveRatio(
381 high_res->contents_scale(),
382 ideal_contents_scale);
383 if (ratio >= kMaxScaleRatioDuringPinch)
384 high_res = AddTiling(ideal_contents_scale);
385 } else {
386 // When not pinching or if no tilings, add exact contents scales.
387 if (!high_res || high_res->contents_scale() != ideal_contents_scale)
388 high_res = AddTiling(ideal_contents_scale);
389 if (!low_res || low_res->contents_scale() != low_res_contents_scale)
390 low_res = AddTiling(low_res_contents_scale);
danakj 2013/01/09 00:22:49 why do you add a low res during pinch here? but no
enne (OOO) 2013/01/09 00:38:38 If the high res is bad, then you at least still ha
391 }
392 }
393
394 if (high_res)
395 high_res->set_resolution(HIGH_RESOLUTION);
396 if (low_res && low_res != high_res)
397 low_res->set_resolution(LOW_RESOLUTION);
398 }
399
400 void PictureLayerImpl::CleanUpUnusedTilings(
401 std::vector<PictureLayerTiling*> used) {
danakj 2013/01/09 00:22:49 nit: used_tilings (match the name in the header)
enne (OOO) 2013/01/09 00:38:38 Variable name short for 80 col. /o\ Done.
402 std::vector<PictureLayerTiling*> to_remove;
403
404 for (size_t i = 0; i < tilings_.num_tilings(); ++i) {
405 PictureLayerTiling* tiling = tilings_.tiling_at(i);
406 // Don't remove the current high or low res tilinig.
407 if (tiling->resolution() != NON_IDEAL_RESOLUTION)
408 continue;
409 if (std::find(used.begin(), used.end(), tiling) == used.end())
410 to_remove.push_back(tiling);
411 }
412
413 for (size_t i = 0; i < to_remove.size(); ++i)
414 tilings_.Remove(to_remove[i]);
danakj 2013/01/09 00:22:49 n^2 again, it's okay?
enne (OOO) 2013/01/09 00:38:38 Yes.
300 } 415 }
301 416
302 } // namespace cc 417 } // namespace cc
OLDNEW
« no previous file with comments | « cc/picture_layer_impl.h ('k') | cc/picture_layer_tiling.h » ('j') | cc/picture_layer_tiling.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698