| 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 #include <set> | 9 #include <set> |
| 10 | 10 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 // tiling's scale if the desired scale is within this ratio. | 37 // tiling's scale if the desired scale is within this ratio. |
| 38 const float kSnapToExistingTilingRatio = 1.2f; | 38 const float kSnapToExistingTilingRatio = 1.2f; |
| 39 | 39 |
| 40 // Estimate skewport 60 frames ahead for pre-rasterization on the CPU. | 40 // Estimate skewport 60 frames ahead for pre-rasterization on the CPU. |
| 41 const float kCpuSkewportTargetTimeInFrames = 60.0f; | 41 const float kCpuSkewportTargetTimeInFrames = 60.0f; |
| 42 | 42 |
| 43 // Don't pre-rasterize on the GPU (except for kBackflingGuardDistancePixels in | 43 // Don't pre-rasterize on the GPU (except for kBackflingGuardDistancePixels in |
| 44 // TileManager::BinFromTilePriority). | 44 // TileManager::BinFromTilePriority). |
| 45 const float kGpuSkewportTargetTimeInFrames = 0.0f; | 45 const float kGpuSkewportTargetTimeInFrames = 0.0f; |
| 46 | 46 |
| 47 // Even for really wide viewports, at some point GPU raster should use |
| 48 // less than 4 tiles to fill the viewport. This is set to 128 as a |
| 49 // sane minimum for now, but we might want to increase with tuning. |
| 50 const int kMinHeightForGpuRasteredTile = 128; |
| 51 |
| 52 // When making odd-sized tiles, round them up to increase the chances |
| 53 // of using the same tile size. |
| 54 const int kTileRoundUp = 64; |
| 55 |
| 47 } // namespace | 56 } // namespace |
| 48 | 57 |
| 49 namespace cc { | 58 namespace cc { |
| 50 | 59 |
| 51 PictureLayerImpl::Pair::Pair() : active(NULL), pending(NULL) { | 60 PictureLayerImpl::Pair::Pair() : active(NULL), pending(NULL) { |
| 52 } | 61 } |
| 53 | 62 |
| 54 PictureLayerImpl::Pair::Pair(PictureLayerImpl* active_layer, | 63 PictureLayerImpl::Pair::Pair(PictureLayerImpl* active_layer, |
| 55 PictureLayerImpl* pending_layer) | 64 PictureLayerImpl* pending_layer) |
| 56 : active(active_layer), pending(pending_layer) { | 65 : active(active_layer), pending(pending_layer) { |
| (...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 667 | 676 |
| 668 if (pile_->is_mask()) { | 677 if (pile_->is_mask()) { |
| 669 // Masks are not tiled, so if we can't cover the whole mask with one tile, | 678 // Masks are not tiled, so if we can't cover the whole mask with one tile, |
| 670 // don't make any tiles at all. Returning an empty size signals this. | 679 // don't make any tiles at all. Returning an empty size signals this. |
| 671 if (content_bounds.width() > max_texture_size || | 680 if (content_bounds.width() > max_texture_size || |
| 672 content_bounds.height() > max_texture_size) | 681 content_bounds.height() > max_texture_size) |
| 673 return gfx::Size(); | 682 return gfx::Size(); |
| 674 return content_bounds; | 683 return content_bounds; |
| 675 } | 684 } |
| 676 | 685 |
| 677 gfx::Size default_tile_size = layer_tree_impl()->settings().default_tile_size; | 686 int default_tile_width = 0; |
| 687 int default_tile_height = 0; |
| 678 if (layer_tree_impl()->use_gpu_rasterization()) { | 688 if (layer_tree_impl()->use_gpu_rasterization()) { |
| 679 // TODO(ernstm) crbug.com/365877: We need a unified way to override the | 689 // For GPU rasterization, we pick an ideal tile size using the viewport |
| 680 // default-tile-size. | 690 // so we don't need any settings. The current approach uses 4 tiles |
| 681 default_tile_size = | 691 // to cover the viewport vertically. |
| 682 gfx::Size(layer_tree_impl()->device_viewport_size().width(), | 692 int viewport_width = layer_tree_impl()->device_viewport_size().width(); |
| 683 layer_tree_impl()->device_viewport_size().height() / 4); | 693 int viewport_height = layer_tree_impl()->device_viewport_size().height(); |
| 684 } | 694 default_tile_width = viewport_width; |
| 685 default_tile_size.SetToMin(gfx::Size(max_texture_size, max_texture_size)); | 695 default_tile_height = viewport_height / 4; |
| 696 default_tile_height = |
| 697 std::max(default_tile_height, kMinHeightForGpuRasteredTile); |
| 686 | 698 |
| 687 gfx::Size max_untiled_content_size = | 699 // Increase the tile-height proportionally when the content width |
| 688 layer_tree_impl()->settings().max_untiled_layer_size; | 700 // drops below half the viewport width. |
| 689 max_untiled_content_size.SetToMin( | 701 if (content_bounds.width() <= viewport_width / 2) |
| 690 gfx::Size(max_texture_size, max_texture_size)); | 702 default_tile_height *= 2; |
| 703 } else { |
| 704 // For CPU rasterization we use tile-size settings. |
| 705 const LayerTreeSettings& settings = layer_tree_impl()->settings(); |
| 706 int max_untiled_content_width = settings.max_untiled_layer_size.width(); |
| 707 int max_untiled_content_height = settings.max_untiled_layer_size.height(); |
| 708 default_tile_width = settings.default_tile_size.width(); |
| 709 default_tile_height = settings.default_tile_size.height(); |
| 691 | 710 |
| 692 bool any_dimension_too_large = | 711 // If the content width is small, increase tile size vertically. |
| 693 content_bounds.width() > max_untiled_content_size.width() || | 712 // If the content height is small, increase tile size horizontally. |
| 694 content_bounds.height() > max_untiled_content_size.height(); | 713 // If both are less than the untiled-size, use a single tile. |
| 695 | 714 if (content_bounds.width() < default_tile_width) |
| 696 bool any_dimension_one_tile = | 715 default_tile_height = max_untiled_content_height; |
| 697 content_bounds.width() <= default_tile_size.width() || | 716 if (content_bounds.height() < default_tile_height) |
| 698 content_bounds.height() <= default_tile_size.height(); | 717 default_tile_width = max_untiled_content_width; |
| 699 | 718 if (content_bounds.width() < max_untiled_content_width && |
| 700 // If long and skinny, tile at the max untiled content size, and clamp | 719 content_bounds.height() < max_untiled_content_height) { |
| 701 // the smaller dimension to the content size, e.g. 1000x12 layer with | 720 default_tile_height = max_untiled_content_height; |
| 702 // 500x500 max untiled size would get 500x12 tiles. Also do this | 721 default_tile_width = max_untiled_content_width; |
| 703 // if the layer is small. | 722 } |
| 704 if (any_dimension_one_tile || !any_dimension_too_large) { | |
| 705 int width = std::min( | |
| 706 std::max(max_untiled_content_size.width(), default_tile_size.width()), | |
| 707 content_bounds.width()); | |
| 708 int height = std::min( | |
| 709 std::max(max_untiled_content_size.height(), default_tile_size.height()), | |
| 710 content_bounds.height()); | |
| 711 // Round up to the closest multiple of 64. This improves recycling and | |
| 712 // avoids odd texture sizes. | |
| 713 width = RoundUp(width, 64); | |
| 714 height = RoundUp(height, 64); | |
| 715 return gfx::Size(width, height); | |
| 716 } | 723 } |
| 717 | 724 |
| 718 return default_tile_size; | 725 int tile_width = default_tile_width; |
| 726 int tile_height = default_tile_height; |
| 727 |
| 728 // Clamp the tile width/height to the content width/height to save space. |
| 729 if (content_bounds.width() < default_tile_width) { |
| 730 tile_width = std::min(tile_width, content_bounds.width()); |
| 731 tile_width = RoundUp(tile_width, kTileRoundUp); |
| 732 tile_width = std::min(tile_width, default_tile_width); |
| 733 } |
| 734 if (content_bounds.height() < default_tile_height) { |
| 735 tile_height = std::min(tile_height, content_bounds.height()); |
| 736 tile_height = RoundUp(tile_height, kTileRoundUp); |
| 737 tile_height = std::min(tile_height, default_tile_height); |
| 738 } |
| 739 |
| 740 // Under no circumstance should we be larger than the max texture size. |
| 741 tile_width = std::min(tile_width, max_texture_size); |
| 742 tile_height = std::min(tile_height, max_texture_size); |
| 743 return gfx::Size(tile_width, tile_height); |
| 719 } | 744 } |
| 720 | 745 |
| 721 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { | 746 void PictureLayerImpl::SyncFromActiveLayer(const PictureLayerImpl* other) { |
| 722 TRACE_EVENT0("cc", "SyncFromActiveLayer"); | 747 TRACE_EVENT0("cc", "SyncFromActiveLayer"); |
| 723 DCHECK(!other->needs_post_commit_initialization_); | 748 DCHECK(!other->needs_post_commit_initialization_); |
| 724 DCHECK(other->tilings_); | 749 DCHECK(other->tilings_); |
| 725 | 750 |
| 726 if (!DrawsContent()) { | 751 if (!DrawsContent()) { |
| 727 RemoveAllTilings(); | 752 RemoveAllTilings(); |
| 728 return; | 753 return; |
| (...skipping 1058 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1787 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); | 1812 PictureLayerTilingSet::TilingRange tiling_range = CurrentTilingRange(); |
| 1788 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; | 1813 size_t current_tiling_range_offset = current_tiling_ - tiling_range.start; |
| 1789 return tiling_range.end - 1 - current_tiling_range_offset; | 1814 return tiling_range.end - 1 - current_tiling_range_offset; |
| 1790 } | 1815 } |
| 1791 } | 1816 } |
| 1792 NOTREACHED(); | 1817 NOTREACHED(); |
| 1793 return 0; | 1818 return 0; |
| 1794 } | 1819 } |
| 1795 | 1820 |
| 1796 } // namespace cc | 1821 } // namespace cc |
| OLD | NEW |