OLD | NEW |
---|---|
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 const double kMaxTimeToVisibleInSeconds = 1000.0; | |
15 } | |
16 | |
9 namespace cc { | 17 namespace cc { |
10 | 18 |
11 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( | 19 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Create( |
12 float contents_scale, | 20 float contents_scale, |
13 gfx::Size tile_size) { | 21 gfx::Size tile_size) { |
14 return make_scoped_ptr(new PictureLayerTiling(contents_scale, tile_size)); | 22 return make_scoped_ptr(new PictureLayerTiling(contents_scale, tile_size)); |
15 } | 23 } |
16 | 24 |
17 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Clone() const { | 25 scoped_ptr<PictureLayerTiling> PictureLayerTiling::Clone() const { |
18 return make_scoped_ptr(new PictureLayerTiling(*this)); | 26 return make_scoped_ptr(new PictureLayerTiling(*this)); |
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
259 DCHECK_LE(texture_rect.right(), texture_size().width()); | 267 DCHECK_LE(texture_rect.right(), texture_size().width()); |
260 DCHECK_LE(texture_rect.bottom(), texture_size().height()); | 268 DCHECK_LE(texture_rect.bottom(), texture_size().height()); |
261 | 269 |
262 return texture_rect; | 270 return texture_rect; |
263 } | 271 } |
264 | 272 |
265 gfx::Size PictureLayerTiling::Iterator::texture_size() const { | 273 gfx::Size PictureLayerTiling::Iterator::texture_size() const { |
266 return tiling_->tiling_data_.max_texture_size(); | 274 return tiling_->tiling_data_.max_texture_size(); |
267 } | 275 } |
268 | 276 |
277 void PictureLayerTiling::UpdateTilePriorities( | |
278 const gfx::Size& view_port, | |
279 const gfx::Transform& last_transform, | |
280 const gfx::Transform& current_transform, | |
281 double time_delta) { | |
282 gfx::Rect countent_rect = ContentRect(); | |
283 if (countent_rect.IsEmpty()) | |
284 return; | |
285 | |
286 gfx::Rect view_rect(gfx::Point(), view_port); | |
287 int right = tiling_data_.TileXIndexFromSrcCoord(countent_rect.width() - 1); | |
288 int bottom = tiling_data_.TileYIndexFromSrcCoord(countent_rect.height() - 1); | |
289 for (int j = 0; j <= bottom; ++j) { | |
290 for (int i = 0; i <= right; ++i) { | |
291 gfx::Rect content_rect = tiling_data_.TileBounds(i, j); | |
292 gfx::Rect layer_rect = gfx::ToEnclosingRect( | |
epennerAtGoogle
2012/11/29 22:52:55
Question for Enne. Is this scale correct in order
| |
293 gfx::ScaleRect(content_rect, 1 / contents_scale_)); | |
294 gfx::Rect screen_rect = MathUtil::mapClippedRect( | |
epennerAtGoogle
2012/11/29 22:07:50
I think this might bite us performance-wise if we
| |
295 current_transform, layer_rect); | |
danakj
2012/11/29 22:57:30
What is current_transform? If it's the screen spac
epennerAtGoogle
2012/11/29 23:02:58
The trouble is there is multiple content scales, s
qinmin
2012/11/30 00:35:00
Ok, passing the content_scale from the layer to th
| |
296 gfx::Rect previous_rect = MathUtil::mapClippedRect( | |
297 last_transform, layer_rect); | |
298 | |
299 TilePriority priority; | |
300 priority.resolution = HIGH_RESOLUTION; | |
301 priority.time_to_visible_in_seconds = TimeForBoundsToIntersect( | |
302 previous_rect, screen_rect, time_delta, view_rect); | |
303 | |
epennerAtGoogle
2012/11/29 22:07:50
I think for painting we are better off using manha
qinmin
2012/11/29 22:44:17
I like the idea of manhattan distance, it saves th
| |
304 int x_offset = 0; | |
305 if (screen_rect.right() < view_rect.x()) | |
306 x_offset = view_rect.x() - screen_rect.right(); | |
307 else if (screen_rect.x() > view_rect.right()) | |
308 x_offset = screen_rect.x() - view_rect.right(); | |
309 | |
310 int y_offset = 0; | |
311 if (screen_rect.bottom() < view_rect.y()) | |
312 y_offset = view_rect.y() - screen_rect.bottom(); | |
313 else if (screen_rect.y() > view_rect.bottom()) | |
314 y_offset = screen_rect.y() - view_rect.bottom(); | |
315 | |
316 priority.distance_to_visible_in_pixels = | |
317 gfx::Vector2dF(x_offset, x_offset).Length(); | |
318 // TODO(qinmin): pass the correct tree to this function. | |
319 TileAt(i, j)->set_priority(ACTIVE_TREE, priority); | |
320 } | |
321 } | |
322 } | |
323 | |
324 double PictureLayerTiling::TimeForBoundsToIntersect(gfx::Rect previous_bounds, | |
epennerAtGoogle
2012/11/29 22:07:50
This is super clever.
| |
325 gfx::Rect current_bounds, | |
326 double time_delta, | |
327 gfx::Rect target_bounds) { | |
328 if (current_bounds.Intersects(target_bounds)) | |
329 return 0; | |
330 | |
331 if (previous_bounds.Intersects(target_bounds) || time_delta == 0) | |
332 return kMaxTimeToVisibleInSeconds; | |
333 | |
334 // As we are trying to solve the case of both scaling and scrolling, using | |
335 // a single coordinate with velocity is not enough. The logic here is to | |
336 // calculate the velocity for each edge. Then we calculate the time range that | |
337 // each edge will stay on the same side of the target bounds. If there is an | |
338 // overlap between these time ranges, the bounds must have intersect with | |
epennerAtGoogle
2012/11/29 22:07:50
I was initially confused by the comment but now I
| |
339 // each other during that period of time. | |
340 double velocity = | |
341 (current_bounds.right() - previous_bounds.right()) / time_delta; | |
342 PictureLayerTiling::Range range = TimeRangeValueLargerThanThreshold( | |
343 current_bounds.right(), target_bounds.x(), velocity); | |
344 | |
345 velocity = (current_bounds.x() - previous_bounds.x()) / time_delta; | |
346 range = range.Intersects(TimeRangeValueLargerThanThreshold( | |
347 -current_bounds.x(), -target_bounds.right(), -velocity)); | |
348 | |
349 | |
350 velocity = (current_bounds.y() - previous_bounds.y()) / time_delta; | |
351 range = range.Intersects(TimeRangeValueLargerThanThreshold( | |
352 -current_bounds.y(), -target_bounds.bottom(), -velocity)); | |
353 | |
354 velocity = (current_bounds.bottom() - previous_bounds.bottom()) / time_delta; | |
355 range = range.Intersects(TimeRangeValueLargerThanThreshold( | |
356 current_bounds.bottom(), target_bounds.y(), velocity)); | |
357 | |
358 return range.IsEmpty() ? kMaxTimeToVisibleInSeconds : range.start_; | |
359 } | |
360 | |
361 PictureLayerTiling::Range PictureLayerTiling::TimeRangeValueLargerThanThreshold( | |
362 int value, int threshold, double velocity) { | |
363 double minimum_time = 0; | |
364 double maximum_time = kMaxTimeToVisibleInSeconds; | |
365 | |
366 if (velocity > 0) { | |
367 if (value < threshold) | |
368 minimum_time = std::min(kMaxTimeToVisibleInSeconds, | |
369 (threshold - value) / velocity); | |
370 } else if (velocity <= 0) { | |
371 if (value < threshold) | |
372 minimum_time = kMaxTimeToVisibleInSeconds; | |
373 else if (velocity != 0) | |
374 maximum_time = std::min(maximum_time, (threshold - value) / velocity); | |
375 } | |
376 | |
377 return PictureLayerTiling::Range(minimum_time, maximum_time); | |
378 } | |
379 | |
380 PictureLayerTiling::Range PictureLayerTiling::Range::Intersects( | |
381 const PictureLayerTiling::Range& other) { | |
382 start_ = std::max(start_, other.start_); | |
383 end_ = std::min(end_, other.end_); | |
384 return PictureLayerTiling::Range(start_, end_); | |
385 } | |
386 | |
387 bool PictureLayerTiling::Range::IsEmpty() { | |
388 return start_ >= end_; | |
389 } | |
390 | |
269 } // namespace cc | 391 } // namespace cc |
OLD | NEW |