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 <cmath> |
8 #include <limits> | 9 #include <limits> |
9 #include <set> | 10 #include <set> |
10 | 11 |
11 #include "base/debug/trace_event_argument.h" | 12 #include "base/debug/trace_event_argument.h" |
12 #include "base/time/time.h" | 13 #include "base/time/time.h" |
13 #include "cc/base/math_util.h" | 14 #include "cc/base/math_util.h" |
14 #include "cc/base/util.h" | 15 #include "cc/base/util.h" |
15 #include "cc/debug/debug_colors.h" | 16 #include "cc/debug/debug_colors.h" |
16 #include "cc/debug/micro_benchmark_impl.h" | 17 #include "cc/debug/micro_benchmark_impl.h" |
17 #include "cc/debug/traced_value.h" | 18 #include "cc/debug/traced_value.h" |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 for (PictureLayerTilingSet::CoverageIterator iter( | 248 for (PictureLayerTilingSet::CoverageIterator iter( |
248 tilings_.get(), | 249 tilings_.get(), |
249 max_contents_scale, | 250 max_contents_scale, |
250 scaled_visible_content_rect, | 251 scaled_visible_content_rect, |
251 ideal_contents_scale_); | 252 ideal_contents_scale_); |
252 iter; | 253 iter; |
253 ++iter) { | 254 ++iter) { |
254 SkColor color; | 255 SkColor color; |
255 float width; | 256 float width; |
256 if (*iter && iter->IsReadyToDraw()) { | 257 if (*iter && iter->IsReadyToDraw()) { |
257 ManagedTileState::DrawInfo::Mode mode = iter->draw_info().mode(); | 258 TileDrawInfo::Mode mode = iter->draw_info().mode(); |
258 if (mode == ManagedTileState::DrawInfo::SOLID_COLOR_MODE) { | 259 if (mode == TileDrawInfo::SOLID_COLOR_MODE) { |
259 color = DebugColors::SolidColorTileBorderColor(); | 260 color = DebugColors::SolidColorTileBorderColor(); |
260 width = DebugColors::SolidColorTileBorderWidth(layer_tree_impl()); | 261 width = DebugColors::SolidColorTileBorderWidth(layer_tree_impl()); |
261 } else if (mode == ManagedTileState::DrawInfo::PICTURE_PILE_MODE) { | 262 } else if (mode == TileDrawInfo::PICTURE_PILE_MODE) { |
262 color = DebugColors::PictureTileBorderColor(); | 263 color = DebugColors::PictureTileBorderColor(); |
263 width = DebugColors::PictureTileBorderWidth(layer_tree_impl()); | 264 width = DebugColors::PictureTileBorderWidth(layer_tree_impl()); |
264 } else if (iter.resolution() == HIGH_RESOLUTION) { | 265 } else if (iter.resolution() == HIGH_RESOLUTION) { |
265 color = DebugColors::HighResTileBorderColor(); | 266 color = DebugColors::HighResTileBorderColor(); |
266 width = DebugColors::HighResTileBorderWidth(layer_tree_impl()); | 267 width = DebugColors::HighResTileBorderWidth(layer_tree_impl()); |
267 } else if (iter.resolution() == LOW_RESOLUTION) { | 268 } else if (iter.resolution() == LOW_RESOLUTION) { |
268 color = DebugColors::LowResTileBorderColor(); | 269 color = DebugColors::LowResTileBorderColor(); |
269 width = DebugColors::LowResTileBorderWidth(layer_tree_impl()); | 270 width = DebugColors::LowResTileBorderWidth(layer_tree_impl()); |
270 } else if (iter->contents_scale() > max_contents_scale) { | 271 } else if (iter->contents_scale() > max_contents_scale) { |
271 color = DebugColors::ExtraHighResTileBorderColor(); | 272 color = DebugColors::ExtraHighResTileBorderColor(); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 gfx::Rect visible_geometry_rect = | 316 gfx::Rect visible_geometry_rect = |
316 scaled_occlusion.GetUnoccludedContentRect(geometry_rect); | 317 scaled_occlusion.GetUnoccludedContentRect(geometry_rect); |
317 if (visible_geometry_rect.IsEmpty()) | 318 if (visible_geometry_rect.IsEmpty()) |
318 continue; | 319 continue; |
319 | 320 |
320 append_quads_data->visible_content_area += | 321 append_quads_data->visible_content_area += |
321 visible_geometry_rect.width() * visible_geometry_rect.height(); | 322 visible_geometry_rect.width() * visible_geometry_rect.height(); |
322 | 323 |
323 bool has_draw_quad = false; | 324 bool has_draw_quad = false; |
324 if (*iter && iter->IsReadyToDraw()) { | 325 if (*iter && iter->IsReadyToDraw()) { |
325 const ManagedTileState::DrawInfo& draw_info = iter->draw_info(); | 326 const TileDrawInfo& draw_info = iter->draw_info(); |
326 switch (draw_info.mode()) { | 327 switch (draw_info.mode()) { |
327 case ManagedTileState::DrawInfo::RESOURCE_MODE: { | 328 case TileDrawInfo::RESOURCE_MODE: { |
328 gfx::RectF texture_rect = iter.texture_rect(); | 329 gfx::RectF texture_rect = iter.texture_rect(); |
329 | 330 |
330 // The raster_contents_scale_ is the best scale that the layer is | 331 // The raster_contents_scale_ is the best scale that the layer is |
331 // trying to produce, even though it may not be ideal. Since that's | 332 // trying to produce, even though it may not be ideal. Since that's |
332 // the best the layer can promise in the future, consider those as | 333 // the best the layer can promise in the future, consider those as |
333 // complete. But if a tile is ideal scale, we don't want to consider | 334 // complete. But if a tile is ideal scale, we don't want to consider |
334 // it incomplete and trying to replace it with a tile at a worse | 335 // it incomplete and trying to replace it with a tile at a worse |
335 // scale. | 336 // scale. |
336 if (iter->contents_scale() != raster_contents_scale_ && | 337 if (iter->contents_scale() != raster_contents_scale_ && |
337 iter->contents_scale() != ideal_contents_scale_ && | 338 iter->contents_scale() != ideal_contents_scale_ && |
338 geometry_rect.Intersects(scaled_viewport_for_tile_priority)) { | 339 geometry_rect.Intersects(scaled_viewport_for_tile_priority)) { |
339 append_quads_data->num_incomplete_tiles++; | 340 append_quads_data->num_incomplete_tiles++; |
340 } | 341 } |
341 | 342 |
342 TileDrawQuad* quad = | 343 TileDrawQuad* quad = |
343 render_pass->CreateAndAppendDrawQuad<TileDrawQuad>(); | 344 render_pass->CreateAndAppendDrawQuad<TileDrawQuad>(); |
344 quad->SetNew(shared_quad_state, | 345 quad->SetNew(shared_quad_state, |
345 geometry_rect, | 346 geometry_rect, |
346 opaque_rect, | 347 opaque_rect, |
347 visible_geometry_rect, | 348 visible_geometry_rect, |
348 draw_info.get_resource_id(), | 349 draw_info.get_resource_id(), |
349 texture_rect, | 350 texture_rect, |
350 iter.texture_size(), | 351 iter.texture_size(), |
351 draw_info.contents_swizzled(), | 352 draw_info.contents_swizzled(), |
352 nearest_neighbor_); | 353 nearest_neighbor_); |
353 has_draw_quad = true; | 354 has_draw_quad = true; |
354 break; | 355 break; |
355 } | 356 } |
356 case ManagedTileState::DrawInfo::PICTURE_PILE_MODE: { | 357 case TileDrawInfo::PICTURE_PILE_MODE: { |
357 if (!layer_tree_impl() | 358 if (!layer_tree_impl() |
358 ->GetRendererCapabilities() | 359 ->GetRendererCapabilities() |
359 .allow_rasterize_on_demand) { | 360 .allow_rasterize_on_demand) { |
360 ++on_demand_missing_tile_count; | 361 ++on_demand_missing_tile_count; |
361 break; | 362 break; |
362 } | 363 } |
363 | 364 |
364 gfx::RectF texture_rect = iter.texture_rect(); | 365 gfx::RectF texture_rect = iter.texture_rect(); |
365 | 366 |
366 ResourceProvider* resource_provider = | 367 ResourceProvider* resource_provider = |
367 layer_tree_impl()->resource_provider(); | 368 layer_tree_impl()->resource_provider(); |
368 ResourceFormat format = | 369 ResourceFormat format = |
369 resource_provider->memory_efficient_texture_format(); | 370 resource_provider->memory_efficient_texture_format(); |
370 PictureDrawQuad* quad = | 371 PictureDrawQuad* quad = |
371 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>(); | 372 render_pass->CreateAndAppendDrawQuad<PictureDrawQuad>(); |
372 quad->SetNew(shared_quad_state, geometry_rect, opaque_rect, | 373 quad->SetNew(shared_quad_state, geometry_rect, opaque_rect, |
373 visible_geometry_rect, texture_rect, iter.texture_size(), | 374 visible_geometry_rect, texture_rect, iter.texture_size(), |
374 nearest_neighbor_, format, iter->content_rect(), | 375 nearest_neighbor_, format, iter->content_rect(), |
375 iter->contents_scale(), raster_source_); | 376 iter->contents_scale(), raster_source_); |
376 has_draw_quad = true; | 377 has_draw_quad = true; |
377 break; | 378 break; |
378 } | 379 } |
379 case ManagedTileState::DrawInfo::SOLID_COLOR_MODE: { | 380 case TileDrawInfo::SOLID_COLOR_MODE: { |
380 SolidColorDrawQuad* quad = | 381 SolidColorDrawQuad* quad = |
381 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); | 382 render_pass->CreateAndAppendDrawQuad<SolidColorDrawQuad>(); |
382 quad->SetNew(shared_quad_state, | 383 quad->SetNew(shared_quad_state, |
383 geometry_rect, | 384 geometry_rect, |
384 visible_geometry_rect, | 385 visible_geometry_rect, |
385 draw_info.get_solid_color(), | 386 draw_info.get_solid_color(), |
386 false); | 387 false); |
387 has_draw_quad = true; | 388 has_draw_quad = true; |
388 break; | 389 break; |
389 } | 390 } |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
591 | 592 |
592 if (!can_have_tilings) { | 593 if (!can_have_tilings) { |
593 RemoveAllTilings(); | 594 RemoveAllTilings(); |
594 return; | 595 return; |
595 } | 596 } |
596 | 597 |
597 // We could do this after doing UpdateTiles, which would avoid doing this for | 598 // We could do this after doing UpdateTiles, which would avoid doing this for |
598 // tilings that are going to disappear on the pending tree (if scale changed). | 599 // tilings that are going to disappear on the pending tree (if scale changed). |
599 // But that would also be more complicated, so we just do it here for now. | 600 // But that would also be more complicated, so we just do it here for now. |
600 tilings_->UpdateTilingsToCurrentRasterSource( | 601 tilings_->UpdateTilingsToCurrentRasterSource( |
601 raster_source_.get(), pending_set, invalidation_, MinimumContentsScale()); | 602 raster_source_, pending_set, invalidation_, MinimumContentsScale(), |
| 603 MaximumContentsScale()); |
602 } | 604 } |
603 | 605 |
604 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { | 606 void PictureLayerImpl::NotifyTileStateChanged(const Tile* tile) { |
605 if (layer_tree_impl()->IsActiveTree()) { | 607 if (layer_tree_impl()->IsActiveTree()) { |
606 gfx::RectF layer_damage_rect = | 608 gfx::RectF layer_damage_rect = |
607 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); | 609 gfx::ScaleRect(tile->content_rect(), 1.f / tile->contents_scale()); |
608 AddDamageRect(layer_damage_rect); | 610 AddDamageRect(layer_damage_rect); |
609 } | 611 } |
610 } | 612 } |
611 | 613 |
(...skipping 17 matching lines...) Expand all Loading... |
629 // To avoid an edge case after lost context where the tree is up to date but | 631 // To avoid an edge case after lost context where the tree is up to date but |
630 // the tilings have not been managed, request an update draw properties | 632 // the tilings have not been managed, request an update draw properties |
631 // to force tilings to get managed. | 633 // to force tilings to get managed. |
632 layer_tree_impl()->set_needs_update_draw_properties(); | 634 layer_tree_impl()->set_needs_update_draw_properties(); |
633 } | 635 } |
634 | 636 |
635 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { | 637 skia::RefPtr<SkPicture> PictureLayerImpl::GetPicture() { |
636 return raster_source_->GetFlattenedPicture(); | 638 return raster_source_->GetFlattenedPicture(); |
637 } | 639 } |
638 | 640 |
639 scoped_refptr<Tile> PictureLayerImpl::CreateTile(PictureLayerTiling* tiling, | 641 scoped_refptr<Tile> PictureLayerImpl::CreateTile( |
640 const gfx::Rect& content_rect) { | 642 float contents_scale, |
641 DCHECK(!raster_source_->IsSolidColor()); | 643 const gfx::Rect& content_rect) { |
642 if (!raster_source_->CoversRect(content_rect, tiling->contents_scale())) | |
643 return scoped_refptr<Tile>(); | |
644 | |
645 int flags = 0; | 644 int flags = 0; |
646 | 645 |
647 // We don't handle solid color masks, so we shouldn't bother analyzing those. | 646 // We don't handle solid color masks, so we shouldn't bother analyzing those. |
648 // Otherwise, always analyze to maximize memory savings. | 647 // Otherwise, always analyze to maximize memory savings. |
649 if (!is_mask_) | 648 if (!is_mask_) |
650 flags = Tile::USE_PICTURE_ANALYSIS; | 649 flags = Tile::USE_PICTURE_ANALYSIS; |
651 | 650 |
652 return layer_tree_impl()->tile_manager()->CreateTile( | 651 return layer_tree_impl()->tile_manager()->CreateTile( |
653 raster_source_.get(), content_rect.size(), content_rect, | 652 raster_source_.get(), content_rect.size(), content_rect, contents_scale, |
654 tiling->contents_scale(), id(), layer_tree_impl()->source_frame_number(), | 653 id(), layer_tree_impl()->source_frame_number(), flags); |
655 flags); | |
656 } | 654 } |
657 | 655 |
658 const Region* PictureLayerImpl::GetPendingInvalidation() { | 656 const Region* PictureLayerImpl::GetPendingInvalidation() { |
659 if (layer_tree_impl()->IsPendingTree()) | 657 if (layer_tree_impl()->IsPendingTree()) |
660 return &invalidation_; | 658 return &invalidation_; |
661 if (layer_tree_impl()->IsRecycleTree()) | 659 if (layer_tree_impl()->IsRecycleTree()) |
662 return nullptr; | 660 return nullptr; |
663 DCHECK(layer_tree_impl()->IsActiveTree()); | 661 DCHECK(layer_tree_impl()->IsActiveTree()); |
664 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) | 662 if (PictureLayerImpl* twin_layer = GetPendingOrActiveTwinLayer()) |
665 return &twin_layer->invalidation_; | 663 return &twin_layer->invalidation_; |
(...skipping 26 matching lines...) Expand all Loading... |
692 return layer_tree_impl()->RequiresHighResToDraw(); | 690 return layer_tree_impl()->RequiresHighResToDraw(); |
693 } | 691 } |
694 | 692 |
695 gfx::Size PictureLayerImpl::CalculateTileSize( | 693 gfx::Size PictureLayerImpl::CalculateTileSize( |
696 const gfx::Size& content_bounds) const { | 694 const gfx::Size& content_bounds) const { |
697 int max_texture_size = | 695 int max_texture_size = |
698 layer_tree_impl()->resource_provider()->max_texture_size(); | 696 layer_tree_impl()->resource_provider()->max_texture_size(); |
699 | 697 |
700 if (is_mask_) { | 698 if (is_mask_) { |
701 // Masks are not tiled, so if we can't cover the whole mask with one tile, | 699 // Masks are not tiled, so if we can't cover the whole mask with one tile, |
702 // don't make any tiles at all. Returning an empty size signals this. | 700 // we shouldn't have such a tiling at all. |
703 if (content_bounds.width() > max_texture_size || | 701 DCHECK_LE(content_bounds.width(), max_texture_size); |
704 content_bounds.height() > max_texture_size) | 702 DCHECK_LE(content_bounds.height(), max_texture_size); |
705 return gfx::Size(); | |
706 return content_bounds; | 703 return content_bounds; |
707 } | 704 } |
708 | 705 |
709 int default_tile_width = 0; | 706 int default_tile_width = 0; |
710 int default_tile_height = 0; | 707 int default_tile_height = 0; |
711 if (layer_tree_impl()->use_gpu_rasterization()) { | 708 if (layer_tree_impl()->use_gpu_rasterization()) { |
712 // For GPU rasterization, we pick an ideal tile size using the viewport | 709 // For GPU rasterization, we pick an ideal tile size using the viewport |
713 // so we don't need any settings. The current approach uses 4 tiles | 710 // so we don't need any settings. The current approach uses 4 tiles |
714 // to cover the viewport vertically. | 711 // to cover the viewport vertically. |
715 int viewport_width = layer_tree_impl()->device_viewport_size().width(); | 712 int viewport_width = layer_tree_impl()->device_viewport_size().width(); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 if (!iter || !*iter) { | 783 if (!iter || !*iter) { |
787 *resource_id = 0; | 784 *resource_id = 0; |
788 return; | 785 return; |
789 } | 786 } |
790 | 787 |
791 // Masks only supported if they fit on exactly one tile. | 788 // Masks only supported if they fit on exactly one tile. |
792 DCHECK(iter.geometry_rect() == content_rect) | 789 DCHECK(iter.geometry_rect() == content_rect) |
793 << "iter rect " << iter.geometry_rect().ToString() << " content rect " | 790 << "iter rect " << iter.geometry_rect().ToString() << " content rect " |
794 << content_rect.ToString(); | 791 << content_rect.ToString(); |
795 | 792 |
796 const ManagedTileState::DrawInfo& draw_info = iter->draw_info(); | 793 const TileDrawInfo& draw_info = iter->draw_info(); |
797 if (!draw_info.IsReadyToDraw() || | 794 if (!draw_info.IsReadyToDraw() || |
798 draw_info.mode() != ManagedTileState::DrawInfo::RESOURCE_MODE) { | 795 draw_info.mode() != TileDrawInfo::RESOURCE_MODE) { |
799 *resource_id = 0; | 796 *resource_id = 0; |
800 return; | 797 return; |
801 } | 798 } |
802 | 799 |
803 *resource_id = draw_info.get_resource_id(); | 800 *resource_id = draw_info.get_resource_id(); |
804 *resource_size = iter.texture_size(); | 801 *resource_size = iter.texture_size(); |
805 } | 802 } |
806 | 803 |
807 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) { | 804 void PictureLayerImpl::SetNearestNeighbor(bool nearest_neighbor) { |
808 if (nearest_neighbor_ == nearest_neighbor) | 805 if (nearest_neighbor_ == nearest_neighbor) |
809 return; | 806 return; |
810 | 807 |
811 nearest_neighbor_ = nearest_neighbor; | 808 nearest_neighbor_ = nearest_neighbor; |
812 NoteLayerPropertyChanged(); | 809 NoteLayerPropertyChanged(); |
813 } | 810 } |
814 | 811 |
815 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { | 812 PictureLayerTiling* PictureLayerImpl::AddTiling(float contents_scale) { |
816 DCHECK(CanHaveTilingWithScale(contents_scale)) << | 813 DCHECK(CanHaveTilings()); |
817 "contents_scale: " << contents_scale; | 814 DCHECK_GE(contents_scale, MinimumContentsScale()); |
818 | 815 DCHECK_LE(contents_scale, MaximumContentsScale()); |
819 PictureLayerTiling* tiling = | |
820 tilings_->AddTiling(contents_scale, raster_source_->GetSize()); | |
821 | |
822 DCHECK(raster_source_->HasRecordings()); | 816 DCHECK(raster_source_->HasRecordings()); |
823 | 817 return tilings_->AddTiling(contents_scale, raster_source_); |
824 return tiling; | |
825 } | 818 } |
826 | 819 |
827 void PictureLayerImpl::RemoveAllTilings() { | 820 void PictureLayerImpl::RemoveAllTilings() { |
828 if (tilings_) | 821 if (tilings_) |
829 tilings_->RemoveAllTilings(); | 822 tilings_->RemoveAllTilings(); |
830 // If there are no tilings, then raster scales are no longer meaningful. | 823 // If there are no tilings, then raster scales are no longer meaningful. |
831 ResetRasterScale(); | 824 ResetRasterScale(); |
832 } | 825 } |
833 | 826 |
834 void PictureLayerImpl::AddTilingsForRasterScale() { | 827 void PictureLayerImpl::AddTilingsForRasterScale() { |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
906 if (raster_device_scale_ != ideal_device_scale_) | 899 if (raster_device_scale_ != ideal_device_scale_) |
907 return true; | 900 return true; |
908 | 901 |
909 // When the source scale changes we want to match it, but not when animating | 902 // When the source scale changes we want to match it, but not when animating |
910 // or when we've fixed the scale in place. | 903 // or when we've fixed the scale in place. |
911 if (!draw_properties().screen_space_transform_is_animating && | 904 if (!draw_properties().screen_space_transform_is_animating && |
912 !raster_source_scale_is_fixed_ && | 905 !raster_source_scale_is_fixed_ && |
913 raster_source_scale_ != ideal_source_scale_) | 906 raster_source_scale_ != ideal_source_scale_) |
914 return true; | 907 return true; |
915 | 908 |
| 909 if (raster_contents_scale_ > MaximumContentsScale()) |
| 910 return true; |
| 911 if (raster_contents_scale_ < MinimumContentsScale()) |
| 912 return true; |
| 913 |
916 return false; | 914 return false; |
917 } | 915 } |
918 | 916 |
919 void PictureLayerImpl::RecalculateRasterScales() { | 917 void PictureLayerImpl::RecalculateRasterScales() { |
920 float old_raster_contents_scale = raster_contents_scale_; | 918 float old_raster_contents_scale = raster_contents_scale_; |
921 float old_raster_page_scale = raster_page_scale_; | 919 float old_raster_page_scale = raster_page_scale_; |
922 float old_raster_source_scale = raster_source_scale_; | 920 float old_raster_source_scale = raster_source_scale_; |
923 | 921 |
924 raster_device_scale_ = ideal_device_scale_; | 922 raster_device_scale_ = ideal_device_scale_; |
925 raster_page_scale_ = ideal_page_scale_; | 923 raster_page_scale_ = ideal_page_scale_; |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
996 // the ideal scale here. The current ideal scale may be way too large in the | 994 // the ideal scale here. The current ideal scale may be way too large in the |
997 // case of an animation with scale, and will be constantly changing. | 995 // case of an animation with scale, and will be constantly changing. |
998 if (can_raster_at_maximum_scale) | 996 if (can_raster_at_maximum_scale) |
999 raster_contents_scale_ = maximum_scale; | 997 raster_contents_scale_ = maximum_scale; |
1000 else | 998 else |
1001 raster_contents_scale_ = 1.f * ideal_page_scale_ * ideal_device_scale_; | 999 raster_contents_scale_ = 1.f * ideal_page_scale_ * ideal_device_scale_; |
1002 } | 1000 } |
1003 | 1001 |
1004 raster_contents_scale_ = | 1002 raster_contents_scale_ = |
1005 std::max(raster_contents_scale_, MinimumContentsScale()); | 1003 std::max(raster_contents_scale_, MinimumContentsScale()); |
| 1004 raster_contents_scale_ = |
| 1005 std::min(raster_contents_scale_, MaximumContentsScale()); |
| 1006 DCHECK_GE(raster_contents_scale_, MinimumContentsScale()); |
| 1007 DCHECK_LE(raster_contents_scale_, MaximumContentsScale()); |
1006 | 1008 |
1007 // If this layer would create zero or one tiles at this content scale, | 1009 // If this layer would create zero or one tiles at this content scale, |
1008 // don't create a low res tiling. | 1010 // don't create a low res tiling. |
1009 gfx::Size raster_bounds = gfx::ToCeiledSize( | 1011 gfx::Size raster_bounds = gfx::ToCeiledSize( |
1010 gfx::ScaleSize(raster_source_->GetSize(), raster_contents_scale_)); | 1012 gfx::ScaleSize(raster_source_->GetSize(), raster_contents_scale_)); |
1011 gfx::Size tile_size = CalculateTileSize(raster_bounds); | 1013 gfx::Size tile_size = CalculateTileSize(raster_bounds); |
1012 bool tile_covers_bounds = tile_size.width() >= raster_bounds.width() && | 1014 bool tile_covers_bounds = tile_size.width() >= raster_bounds.width() && |
1013 tile_size.height() >= raster_bounds.height(); | 1015 tile_size.height() >= raster_bounds.height(); |
1014 if (tile_size.IsEmpty() || tile_covers_bounds) { | 1016 if (tile_size.IsEmpty() || tile_covers_bounds) { |
1015 low_res_raster_contents_scale_ = raster_contents_scale_; | 1017 low_res_raster_contents_scale_ = raster_contents_scale_; |
1016 return; | 1018 return; |
1017 } | 1019 } |
1018 | 1020 |
1019 float low_res_factor = | 1021 float low_res_factor = |
1020 layer_tree_impl()->settings().low_res_contents_scale_factor; | 1022 layer_tree_impl()->settings().low_res_contents_scale_factor; |
1021 low_res_raster_contents_scale_ = std::max( | 1023 low_res_raster_contents_scale_ = |
1022 raster_contents_scale_ * low_res_factor, | 1024 std::max(raster_contents_scale_ * low_res_factor, MinimumContentsScale()); |
1023 MinimumContentsScale()); | |
1024 DCHECK_LE(low_res_raster_contents_scale_, raster_contents_scale_); | 1025 DCHECK_LE(low_res_raster_contents_scale_, raster_contents_scale_); |
1025 DCHECK_GE(low_res_raster_contents_scale_, MinimumContentsScale()); | 1026 DCHECK_GE(low_res_raster_contents_scale_, MinimumContentsScale()); |
| 1027 DCHECK_LE(low_res_raster_contents_scale_, MaximumContentsScale()); |
1026 } | 1028 } |
1027 | 1029 |
1028 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( | 1030 void PictureLayerImpl::CleanUpTilingsOnActiveLayer( |
1029 std::vector<PictureLayerTiling*> used_tilings) { | 1031 std::vector<PictureLayerTiling*> used_tilings) { |
1030 DCHECK(layer_tree_impl()->IsActiveTree()); | 1032 DCHECK(layer_tree_impl()->IsActiveTree()); |
1031 if (tilings_->num_tilings() == 0) | 1033 if (tilings_->num_tilings() == 0) |
1032 return; | 1034 return; |
1033 | 1035 |
1034 float min_acceptable_high_res_scale = std::min( | 1036 float min_acceptable_high_res_scale = std::min( |
1035 raster_contents_scale_, ideal_contents_scale_); | 1037 raster_contents_scale_, ideal_contents_scale_); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 // dimension. Bump the minimum contents scale up in this case to prevent | 1073 // dimension. Bump the minimum contents scale up in this case to prevent |
1072 // this from happening. | 1074 // this from happening. |
1073 int min_dimension = std::min(raster_source_->GetSize().width(), | 1075 int min_dimension = std::min(raster_source_->GetSize().width(), |
1074 raster_source_->GetSize().height()); | 1076 raster_source_->GetSize().height()); |
1075 if (!min_dimension) | 1077 if (!min_dimension) |
1076 return setting_min; | 1078 return setting_min; |
1077 | 1079 |
1078 return std::max(1.f / min_dimension, setting_min); | 1080 return std::max(1.f / min_dimension, setting_min); |
1079 } | 1081 } |
1080 | 1082 |
| 1083 float PictureLayerImpl::MaximumContentsScale() const { |
| 1084 // Masks can not have tilings that would become larger than the |
| 1085 // max_texture_size since they use a single tile for the entire |
| 1086 // tiling. Other layers can have tilings of any scale. |
| 1087 if (!is_mask_) |
| 1088 return std::numeric_limits<float>::max(); |
| 1089 |
| 1090 int max_texture_size = |
| 1091 layer_tree_impl()->resource_provider()->max_texture_size(); |
| 1092 float max_scale_width = |
| 1093 static_cast<float>(max_texture_size) / bounds().width(); |
| 1094 float max_scale_height = |
| 1095 static_cast<float>(max_texture_size) / bounds().height(); |
| 1096 float max_scale = std::min(max_scale_width, max_scale_height); |
| 1097 // We require that multiplying the layer size by the contents scale and |
| 1098 // ceiling produces a value <= |max_texture_size|. Because for large layer |
| 1099 // sizes floating point ambiguity may crop up, making the result larger or |
| 1100 // smaller than expected, we use a slightly smaller floating point value for |
| 1101 // the scale, to help ensure that the resulting content bounds will never end |
| 1102 // up larger than |max_texture_size|. |
| 1103 return nextafterf(max_scale, 0.f); |
| 1104 } |
| 1105 |
1081 void PictureLayerImpl::ResetRasterScale() { | 1106 void PictureLayerImpl::ResetRasterScale() { |
1082 raster_page_scale_ = 0.f; | 1107 raster_page_scale_ = 0.f; |
1083 raster_device_scale_ = 0.f; | 1108 raster_device_scale_ = 0.f; |
1084 raster_source_scale_ = 0.f; | 1109 raster_source_scale_ = 0.f; |
1085 raster_contents_scale_ = 0.f; | 1110 raster_contents_scale_ = 0.f; |
1086 low_res_raster_contents_scale_ = 0.f; | 1111 low_res_raster_contents_scale_ = 0.f; |
1087 raster_source_scale_is_fixed_ = false; | 1112 raster_source_scale_is_fixed_ = false; |
1088 | 1113 |
1089 // When raster scales aren't valid, don't update tile priorities until | 1114 // When raster scales aren't valid, don't update tile priorities until |
1090 // this layer has been updated via UpdateDrawProperties. | 1115 // this layer has been updated via UpdateDrawProperties. |
1091 should_update_tile_priorities_ = false; | 1116 should_update_tile_priorities_ = false; |
1092 } | 1117 } |
1093 | 1118 |
1094 bool PictureLayerImpl::CanHaveTilings() const { | 1119 bool PictureLayerImpl::CanHaveTilings() const { |
1095 if (raster_source_->IsSolidColor()) | 1120 if (raster_source_->IsSolidColor()) |
1096 return false; | 1121 return false; |
1097 if (!DrawsContent()) | 1122 if (!DrawsContent()) |
1098 return false; | 1123 return false; |
1099 if (!raster_source_->HasRecordings()) | 1124 if (!raster_source_->HasRecordings()) |
1100 return false; | 1125 return false; |
1101 // If the |raster_source_| has a recording it should have non-empty bounds. | 1126 // If the |raster_source_| has a recording it should have non-empty bounds. |
1102 DCHECK(!raster_source_->GetSize().IsEmpty()); | 1127 DCHECK(!raster_source_->GetSize().IsEmpty()); |
1103 return true; | 1128 if (MaximumContentsScale() < MinimumContentsScale()) |
1104 } | |
1105 | |
1106 bool PictureLayerImpl::CanHaveTilingWithScale(float contents_scale) const { | |
1107 if (!CanHaveTilings()) | |
1108 return false; | |
1109 if (contents_scale < MinimumContentsScale()) | |
1110 return false; | 1129 return false; |
1111 return true; | 1130 return true; |
1112 } | 1131 } |
1113 | 1132 |
1114 void PictureLayerImpl::SanityCheckTilingState() const { | 1133 void PictureLayerImpl::SanityCheckTilingState() const { |
1115 #if DCHECK_IS_ON | 1134 #if DCHECK_IS_ON |
1116 // Recycle tree doesn't have any restrictions. | 1135 // Recycle tree doesn't have any restrictions. |
1117 if (layer_tree_impl()->IsRecycleTree()) | 1136 if (layer_tree_impl()->IsRecycleTree()) |
1118 return; | 1137 return; |
1119 | 1138 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1306 | 1325 |
1307 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { | 1326 bool PictureLayerImpl::AllTilesRequiredForDrawAreReadyToDraw() const { |
1308 if (!layer_tree_impl()->IsActiveTree()) | 1327 if (!layer_tree_impl()->IsActiveTree()) |
1309 return true; | 1328 return true; |
1310 | 1329 |
1311 return AllTilesRequiredAreReadyToDraw( | 1330 return AllTilesRequiredAreReadyToDraw( |
1312 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); | 1331 &PictureLayerTiling::IsTileRequiredForDrawIfVisible); |
1313 } | 1332 } |
1314 | 1333 |
1315 } // namespace cc | 1334 } // namespace cc |
OLD | NEW |