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/layers/picture_layer_impl.h" | 5 #include "cc/layers/picture_layer_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 | 9 |
10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 // tiling's scale if the desired scale is within this ratio. | 33 // tiling's scale if the desired scale is within this ratio. |
34 const float kSnapToExistingTilingRatio = 0.2f; | 34 const float kSnapToExistingTilingRatio = 0.2f; |
35 } | 35 } |
36 | 36 |
37 namespace cc { | 37 namespace cc { |
38 | 38 |
39 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) | 39 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, int id) |
40 : LayerImpl(tree_impl, id), | 40 : LayerImpl(tree_impl, id), |
41 twin_layer_(NULL), | 41 twin_layer_(NULL), |
42 pile_(PicturePileImpl::Create()), | 42 pile_(PicturePileImpl::Create()), |
43 last_content_scale_(0), | |
44 is_mask_(false), | 43 is_mask_(false), |
45 ideal_page_scale_(0.f), | 44 ideal_page_scale_(0.f), |
46 ideal_device_scale_(0.f), | 45 ideal_device_scale_(0.f), |
47 ideal_source_scale_(0.f), | 46 ideal_source_scale_(0.f), |
48 ideal_contents_scale_(0.f), | 47 ideal_contents_scale_(0.f), |
49 raster_page_scale_(0.f), | 48 raster_page_scale_(0.f), |
50 raster_device_scale_(0.f), | 49 raster_device_scale_(0.f), |
51 raster_source_scale_(0.f), | 50 raster_source_scale_(0.f), |
52 raster_contents_scale_(0.f), | 51 raster_contents_scale_(0.f), |
53 low_res_raster_contents_scale_(0.f), | 52 low_res_raster_contents_scale_(0.f), |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
327 current_frame_time_in_seconds)) { | 326 current_frame_time_in_seconds)) { |
328 tiling_needs_update = true; | 327 tiling_needs_update = true; |
329 break; | 328 break; |
330 } | 329 } |
331 } | 330 } |
332 if (!tiling_needs_update) | 331 if (!tiling_needs_update) |
333 return; | 332 return; |
334 | 333 |
335 UpdateLCDTextStatus(can_use_lcd_text()); | 334 UpdateLCDTextStatus(can_use_lcd_text()); |
336 | 335 |
337 gfx::Transform current_screen_space_transform = screen_space_transform(); | 336 // Use visible_content_rect, unless it's empty. If it's empty, then |
338 | 337 // try to inverse project the viewport into layer space and use that. |
339 gfx::Size viewport_size = layer_tree_impl()->DrawViewportSize(); | 338 gfx::Rect visible_rect_in_content_space = visible_content_rect(); |
340 gfx::Rect viewport_in_content_space; | 339 if (visible_rect_in_content_space.IsEmpty()) { |
341 gfx::Transform screen_to_layer(gfx::Transform::kSkipInitialization); | 340 gfx::Transform screen_to_layer(gfx::Transform::kSkipInitialization); |
342 if (screen_space_transform().GetInverse(&screen_to_layer)) { | 341 if (screen_space_transform().GetInverse(&screen_to_layer)) { |
343 viewport_in_content_space = MathUtil::ProjectEnclosingClippedRect( | 342 gfx::Size viewport_size = layer_tree_impl()->DrawViewportSize(); |
344 screen_to_layer, gfx::Rect(viewport_size)); | 343 visible_rect_in_content_space = |
| 344 gfx::ToEnclosingRect(MathUtil::ProjectClippedRect( |
| 345 screen_to_layer, gfx::Rect(viewport_size))); |
| 346 visible_rect_in_content_space.Intersect(gfx::Rect(content_bounds())); |
| 347 } |
345 } | 348 } |
346 | 349 |
347 WhichTree tree = | 350 WhichTree tree = |
348 layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; | 351 layer_tree_impl()->IsActiveTree() ? ACTIVE_TREE : PENDING_TREE; |
349 size_t max_tiles_for_interest_area = | 352 |
350 layer_tree_impl()->settings().max_tiles_for_interest_area; | 353 tilings_->UpdateTilePriorities(tree, |
351 tilings_->UpdateTilePriorities( | 354 visible_rect_in_content_space, |
352 tree, | 355 contents_scale_x(), |
353 viewport_size, | 356 current_frame_time_in_seconds); |
354 viewport_in_content_space, | |
355 visible_content_rect(), | |
356 last_bounds_, | |
357 bounds(), | |
358 last_content_scale_, | |
359 contents_scale_x(), | |
360 last_screen_space_transform_, | |
361 current_screen_space_transform, | |
362 current_frame_time_in_seconds, | |
363 max_tiles_for_interest_area); | |
364 | 357 |
365 if (layer_tree_impl()->IsPendingTree()) | 358 if (layer_tree_impl()->IsPendingTree()) |
366 MarkVisibleResourcesAsRequired(); | 359 MarkVisibleResourcesAsRequired(); |
367 | 360 |
368 last_screen_space_transform_ = current_screen_space_transform; | |
369 last_bounds_ = bounds(); | |
370 last_content_scale_ = contents_scale_x(); | |
371 | |
372 // Tile priorities were modified. | 361 // Tile priorities were modified. |
373 layer_tree_impl()->DidModifyTilePriorities(); | 362 layer_tree_impl()->DidModifyTilePriorities(); |
374 } | 363 } |
375 | 364 |
376 void PictureLayerImpl::DidBecomeActive() { | 365 void PictureLayerImpl::DidBecomeActive() { |
377 LayerImpl::DidBecomeActive(); | 366 LayerImpl::DidBecomeActive(); |
378 tilings_->DidBecomeActive(); | 367 tilings_->DidBecomeActive(); |
379 layer_tree_impl()->DidModifyTilePriorities(); | 368 layer_tree_impl()->DidModifyTilePriorities(); |
380 } | 369 } |
381 | 370 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
505 if (!twin_layer_ || twin_layer_->should_use_gpu_rasterization() != | 494 if (!twin_layer_ || twin_layer_->should_use_gpu_rasterization() != |
506 should_use_gpu_rasterization()) | 495 should_use_gpu_rasterization()) |
507 return NULL; | 496 return NULL; |
508 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i) | 497 for (size_t i = 0; i < twin_layer_->tilings_->num_tilings(); ++i) |
509 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() == | 498 if (twin_layer_->tilings_->tiling_at(i)->contents_scale() == |
510 tiling->contents_scale()) | 499 tiling->contents_scale()) |
511 return twin_layer_->tilings_->tiling_at(i); | 500 return twin_layer_->tilings_->tiling_at(i); |
512 return NULL; | 501 return NULL; |
513 } | 502 } |
514 | 503 |
| 504 size_t PictureLayerImpl::GetMaxTilesForInterestArea() const { |
| 505 return layer_tree_impl()->settings().max_tiles_for_interest_area; |
| 506 } |
| 507 |
| 508 float PictureLayerImpl::GetSkewportTargetTimeInSeconds() const { |
| 509 return layer_tree_impl()->settings().skewport_target_time_in_seconds; |
| 510 } |
| 511 |
| 512 int PictureLayerImpl::GetSkewportExtrapolationLimitInContentPixels() const { |
| 513 return layer_tree_impl() |
| 514 ->settings() |
| 515 .skewport_extrapolation_limit_in_content_pixels; |
| 516 } |
| 517 |
515 gfx::Size PictureLayerImpl::CalculateTileSize( | 518 gfx::Size PictureLayerImpl::CalculateTileSize( |
516 const gfx::Size& content_bounds) const { | 519 const gfx::Size& content_bounds) const { |
517 if (is_mask_) { | 520 if (is_mask_) { |
518 int max_size = layer_tree_impl()->MaxTextureSize(); | 521 int max_size = layer_tree_impl()->MaxTextureSize(); |
519 return gfx::Size( | 522 return gfx::Size( |
520 std::min(max_size, content_bounds.width()), | 523 std::min(max_size, content_bounds.width()), |
521 std::min(max_size, content_bounds.height())); | 524 std::min(max_size, content_bounds.height())); |
522 } | 525 } |
523 | 526 |
524 int max_texture_size = | 527 int max_texture_size = |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
715 continue; | 718 continue; |
716 } | 719 } |
717 for (PictureLayerTiling::CoverageIterator iter(tiling, | 720 for (PictureLayerTiling::CoverageIterator iter(tiling, |
718 contents_scale_x(), | 721 contents_scale_x(), |
719 rect); | 722 rect); |
720 iter; | 723 iter; |
721 ++iter) { | 724 ++iter) { |
722 if (!*iter || !iter->IsReadyToDraw()) | 725 if (!*iter || !iter->IsReadyToDraw()) |
723 continue; | 726 continue; |
724 | 727 |
725 // This iteration is over the visible content rect which is potentially | |
726 // less conservative than projecting the viewport into the layer. | |
727 // Ignore tiles that are know to be outside the viewport. | |
728 if (iter->priority(PENDING_TREE).distance_to_visible_in_pixels != 0) | |
729 continue; | |
730 | |
731 missing_region.Subtract(iter.geometry_rect()); | 728 missing_region.Subtract(iter.geometry_rect()); |
732 iter->MarkRequiredForActivation(); | 729 iter->MarkRequiredForActivation(); |
733 } | 730 } |
734 } | 731 } |
735 DCHECK(high_res) << "There must be one high res tiling"; | 732 DCHECK(high_res) << "There must be one high res tiling"; |
736 | 733 |
737 // If these pointers are null (because no twin, no matching tiling, or the | 734 // If these pointers are null (because no twin, no matching tiling, or the |
738 // simpification just below), then high res tiles will be required to fill any | 735 // simpification just below), then high res tiles will be required to fill any |
739 // holes left by the first pass above. If the pointers are valid, then this | 736 // holes left by the first pass above. If the pointers are valid, then this |
740 // layer is allowed to skip any tiles that are not ready on its twin. | 737 // layer is allowed to skip any tiles that are not ready on its twin. |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
789 for (PictureLayerTiling::CoverageIterator iter(tiling, | 786 for (PictureLayerTiling::CoverageIterator iter(tiling, |
790 contents_scale, | 787 contents_scale, |
791 rect); | 788 rect); |
792 iter; | 789 iter; |
793 ++iter) { | 790 ++iter) { |
794 Tile* tile = *iter; | 791 Tile* tile = *iter; |
795 // A null tile (i.e. missing recording) can just be skipped. | 792 // A null tile (i.e. missing recording) can just be skipped. |
796 if (!tile) | 793 if (!tile) |
797 continue; | 794 continue; |
798 | 795 |
799 // This iteration is over the visible content rect which is potentially | |
800 // less conservative than projecting the viewport into the layer. | |
801 // Ignore tiles that are know to be outside the viewport. | |
802 if (tile->priority(PENDING_TREE).distance_to_visible_in_pixels != 0) | |
803 continue; | |
804 | |
805 // If the missing region doesn't cover it, this tile is fully | 796 // If the missing region doesn't cover it, this tile is fully |
806 // covered by acceptable tiles at other scales. | 797 // covered by acceptable tiles at other scales. |
807 if (!missing_region.Intersects(iter.geometry_rect())) | 798 if (!missing_region.Intersects(iter.geometry_rect())) |
808 continue; | 799 continue; |
809 | 800 |
810 // If the twin tile doesn't exist (i.e. missing recording or so far away | 801 // If the twin tile doesn't exist (i.e. missing recording or so far away |
811 // that it is outside the visible tile rect) or this tile is shared between | 802 // that it is outside the visible tile rect) or this tile is shared between |
812 // with the twin, then this tile isn't required to prevent flashing. | 803 // with the twin, then this tile isn't required to prevent flashing. |
813 if (optional_twin_tiling) { | 804 if (optional_twin_tiling) { |
814 Tile* twin_tile = optional_twin_tiling->TileAt(iter.i(), iter.j()); | 805 Tile* twin_tile = optional_twin_tiling->TileAt(iter.i(), iter.j()); |
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1235 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { | 1226 size_t PictureLayerImpl::GPUMemoryUsageInBytes() const { |
1236 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); | 1227 const_cast<PictureLayerImpl*>(this)->DoPostCommitInitializationIfNeeded(); |
1237 return tilings_->GPUMemoryUsageInBytes(); | 1228 return tilings_->GPUMemoryUsageInBytes(); |
1238 } | 1229 } |
1239 | 1230 |
1240 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { | 1231 void PictureLayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { |
1241 benchmark->RunOnLayer(this); | 1232 benchmark->RunOnLayer(this); |
1242 } | 1233 } |
1243 | 1234 |
1244 } // namespace cc | 1235 } // namespace cc |
OLD | NEW |