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

Side by Side Diff: cc/picture_layer_tiling.cc

Issue 11414238: implement the logic to set tile priorities based on current matrix (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: passing content scale from layer to tiling so that screenspacetransform can be applied Created 8 years 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.h" 5 #include "cc/picture_layer_tiling.h"
6
7 #include "cc/math_util.h"
6 #include "ui/gfx/rect_conversions.h" 8 #include "ui/gfx/rect_conversions.h"
7 #include "ui/gfx/size_conversions.h" 9 #include "ui/gfx/size_conversions.h"
8 10
11 #include <algorithm>
12
13 namespace {
14
15 const double kMaxTimeToVisibleInSeconds = 1000.0;
16
17 int manhattanDistance(const gfx::Rect& a, const gfx::Rect& b)
18 {
19 gfx::Rect c = gfx::UnionRects(a, b);
20 int x = std::max(0, c.width() - a.width() - b.width() + 1);
21 int y = std::max(0, c.height() - a.height() - b.height() + 1);
22 return (x + y);
23 }
24
25 }
26
9 namespace cc { 27 namespace cc {
10 28
11 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( 29 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create(
12 float contents_scale, 30 float contents_scale,
13 gfx::Size tile_size) { 31 gfx::Size tile_size) {
14 return make_scoped_ptr(new PictureLayerTiling(contents_scale, tile_size)); 32 return make_scoped_ptr(new PictureLayerTiling(contents_scale, tile_size));
15 } 33 }
16 34
17 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Clone() const { 35 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Clone() const {
18 return make_scoped_ptr(new PictureLayerTiling(*this)); 36 return make_scoped_ptr(new PictureLayerTiling(*this));
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 DCHECK_LE(texture_rect.right(), texture_size().width()); 277 DCHECK_LE(texture_rect.right(), texture_size().width());
260 DCHECK_LE(texture_rect.bottom(), texture_size().height()); 278 DCHECK_LE(texture_rect.bottom(), texture_size().height());
261 279
262 return texture_rect; 280 return texture_rect;
263 } 281 }
264 282
265 gfx::Size PictureLayerTiling::Iterator::texture_size() const { 283 gfx::Size PictureLayerTiling::Iterator::texture_size() const {
266 return tiling_->tiling_data_.max_texture_size(); 284 return tiling_->tiling_data_.max_texture_size();
267 } 285 }
268 286
287 void PictureLayerTiling::UpdateTilePriorities(
288 const gfx::Size& view_port,
289 float layer_content_scale,
290 const gfx::Transform& last_transform,
291 const gfx::Transform& current_transform,
292 double time_delta) {
293 gfx::Rect countent_rect = ContentRect();
294 if (countent_rect.IsEmpty())
295 return;
296
297 gfx::Rect view_rect(gfx::Point(), view_port);
298 int right = tiling_data_.TileXIndexFromSrcCoord(countent_rect.width() - 1);
299 int bottom = tiling_data_.TileYIndexFromSrcCoord(countent_rect.height() - 1);
300 for (int j = 0; j <= bottom; ++j) {
301 for (int i = 0; i <= right; ++i) {
302 gfx::Rect content_rect = tiling_data_.TileBounds(i, j);
303 gfx::Rect layer_content_rect = gfx::ToEnclosingRect(
304 gfx::ScaleRect(content_rect, layer_content_scale / contents_scale_));
305 gfx::Rect screen_rect = MathUtil::mapClippedRect(
306 current_transform, layer_content_rect);
307 gfx::Rect previous_rect = MathUtil::mapClippedRect(
308 last_transform, layer_content_rect);
309
310 TilePriority priority;
epenner 2012/11/30 19:29:31 Sorry if this is annoying, but after looking at th
qinmin 2012/11/30 20:32:35 Done, the math thingy are moved to TilePriority. A
311 priority.resolution = HIGH_RESOLUTION;
312 priority.time_to_visible_in_seconds = TimeForBoundsToIntersect(
313 previous_rect, screen_rect, time_delta, view_rect);
314
315 priority.distance_to_visible_in_pixels = manhattanDistance(screen_rect,
316 view_rect);
317 // TODO(qinmin): pass the correct tree to this function.
318 TileAt(i, j)->set_priority(ACTIVE_TREE, priority);
319 }
320 }
321 }
322
323 double PictureLayerTiling::TimeForBoundsToIntersect(gfx::Rect previous_bounds,
324 gfx::Rect current_bounds,
325 double time_delta,
326 gfx::Rect target_bounds) {
327 if (current_bounds.Intersects(target_bounds))
328 return 0;
329
330 if (previous_bounds.Intersects(target_bounds) || time_delta == 0)
331 return kMaxTimeToVisibleInSeconds;
332
333 // As we are trying to solve the case of both scaling and scrolling, using
334 // a single coordinate with velocity is not enough. The logic here is to
335 // calculate the velocity for each edge. Then we calculate the time range that
336 // each edge will stay on the same side of the target bounds. If there is an
337 // overlap between these time ranges, the bounds must have intersect with
338 // each other during that period of time.
339 double velocity =
340 (current_bounds.right() - previous_bounds.right()) / time_delta;
341 PictureLayerTiling::Range range = TimeRangeValueLargerThanThreshold(
342 current_bounds.right(), target_bounds.x(), velocity);
343
344 velocity = (current_bounds.x() - previous_bounds.x()) / time_delta;
345 range = range.Intersects(TimeRangeValueLargerThanThreshold(
346 -current_bounds.x(), -target_bounds.right(), -velocity));
347
348
349 velocity = (current_bounds.y() - previous_bounds.y()) / time_delta;
350 range = range.Intersects(TimeRangeValueLargerThanThreshold(
351 -current_bounds.y(), -target_bounds.bottom(), -velocity));
352
353 velocity = (current_bounds.bottom() - previous_bounds.bottom()) / time_delta;
354 range = range.Intersects(TimeRangeValueLargerThanThreshold(
355 current_bounds.bottom(), target_bounds.y(), velocity));
356
357 return range.IsEmpty() ? kMaxTimeToVisibleInSeconds : range.start_;
358 }
359
360 PictureLayerTiling::Range PictureLayerTiling::TimeRangeValueLargerThanThreshold(
361 int value, int threshold, double velocity) {
362 double minimum_time = 0;
363 double maximum_time = kMaxTimeToVisibleInSeconds;
364
365 if (velocity > 0) {
366 if (value < threshold)
367 minimum_time = std::min(kMaxTimeToVisibleInSeconds,
368 (threshold - value) / velocity);
369 } else if (velocity <= 0) {
370 if (value < threshold)
371 minimum_time = kMaxTimeToVisibleInSeconds;
372 else if (velocity != 0)
373 maximum_time = std::min(maximum_time, (threshold - value) / velocity);
374 }
375
376 return PictureLayerTiling::Range(minimum_time, maximum_time);
377 }
378
379 PictureLayerTiling::Range PictureLayerTiling::Range::Intersects(
380 const PictureLayerTiling::Range& other) {
381 start_ = std::max(start_, other.start_);
382 end_ = std::min(end_, other.end_);
383 return PictureLayerTiling::Range(start_, end_);
384 }
385
386 bool PictureLayerTiling::Range::IsEmpty() {
387 return start_ >= end_;
388 }
389
269 } // namespace cc 390 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698