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 <stddef.h> | 7 #include <stddef.h> |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
44 | 44 |
45 // Even for really wide viewports, at some point GPU raster should use | 45 // Even for really wide viewports, at some point GPU raster should use |
46 // less than 4 tiles to fill the viewport. This is set to 256 as a | 46 // less than 4 tiles to fill the viewport. This is set to 256 as a |
47 // sane minimum for now, but we might want to tune this for low-end. | 47 // sane minimum for now, but we might want to tune this for low-end. |
48 const int kMinHeightForGpuRasteredTile = 256; | 48 const int kMinHeightForGpuRasteredTile = 256; |
49 | 49 |
50 // When making odd-sized tiles, round them up to increase the chances | 50 // When making odd-sized tiles, round them up to increase the chances |
51 // of using the same tile size. | 51 // of using the same tile size. |
52 const int kTileRoundUp = 64; | 52 const int kTileRoundUp = 64; |
53 | 53 |
54 // When sizing tiles relative to the viewport, we keep them as a multiple of | |
55 // this. | |
56 // TODO(crbug.com/622885) But why not just use kTileMinimalAlignment. | |
enne (OOO)
2016/06/28 18:39:01
I suspect it's for the same reason as kTileRoundUp
| |
57 const int kTileViewportAlignment = 32; | |
58 | |
54 // For performance reasons and to support compressed tile textures, tile | 59 // For performance reasons and to support compressed tile textures, tile |
55 // width and height should be an even multiple of 4 in size. | 60 // width and height should be an even multiple of 4 in size. |
56 const int kTileMinimalAlignment = 4; | 61 const int kTileMinimalAlignment = 4; |
57 | 62 |
58 } // namespace | 63 } // namespace |
59 | 64 |
60 namespace cc { | 65 namespace cc { |
61 | 66 |
62 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, | 67 PictureLayerImpl::PictureLayerImpl(LayerTreeImpl* tree_impl, |
63 int id, | 68 int id, |
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
708 layer_tree_impl()->resource_provider()->max_texture_size(); | 713 layer_tree_impl()->resource_provider()->max_texture_size(); |
709 | 714 |
710 if (is_mask_) { | 715 if (is_mask_) { |
711 // Masks are not tiled, so if we can't cover the whole mask with one tile, | 716 // Masks are not tiled, so if we can't cover the whole mask with one tile, |
712 // we shouldn't have such a tiling at all. | 717 // we shouldn't have such a tiling at all. |
713 DCHECK_LE(content_bounds.width(), max_texture_size); | 718 DCHECK_LE(content_bounds.width(), max_texture_size); |
714 DCHECK_LE(content_bounds.height(), max_texture_size); | 719 DCHECK_LE(content_bounds.height(), max_texture_size); |
715 return content_bounds; | 720 return content_bounds; |
716 } | 721 } |
717 | 722 |
718 int default_tile_width = 0; | 723 int tile_width = 0; |
719 int default_tile_height = 0; | 724 int tile_height = 0; |
720 if (layer_tree_impl()->use_gpu_rasterization()) { | 725 if (layer_tree_impl()->use_gpu_rasterization()) { |
enne (OOO)
2016/06/28 18:39:01
This function is a little long and hard to read.
| |
721 // For GPU rasterization, we pick an ideal tile size using the viewport | 726 // For GPU rasterization, we pick an ideal tile size using the viewport |
722 // so we don't need any settings. The current approach uses 4 tiles | 727 // so we don't need any settings. The current approach uses 4 tiles |
723 // to cover the viewport vertically. | 728 // to cover the viewport vertically. |
724 int viewport_width = gpu_raster_max_texture_size_.width(); | 729 int viewport_width = gpu_raster_max_texture_size_.width(); |
725 int viewport_height = gpu_raster_max_texture_size_.height(); | 730 int viewport_height = gpu_raster_max_texture_size_.height(); |
726 default_tile_width = viewport_width; | 731 tile_width = viewport_width; |
727 | 732 |
728 // Also, increase the height proportionally as the width decreases, and | 733 // Also, increase the height proportionally as the width decreases, and |
729 // pad by our border texels to make the tiles exactly match the viewport. | 734 // pad by our border texels to make the tiles exactly match the viewport. |
730 int divisor = 4; | 735 int divisor = 4; |
731 if (content_bounds.width() <= viewport_width / 2) | 736 if (content_bounds.width() <= viewport_width / 2) |
732 divisor = 2; | 737 divisor = 2; |
733 if (content_bounds.width() <= viewport_width / 4) | 738 if (content_bounds.width() <= viewport_width / 4) |
734 divisor = 1; | 739 divisor = 1; |
735 default_tile_height = | 740 tile_height = |
736 MathUtil::UncheckedRoundUp(viewport_height, divisor) / divisor; | 741 MathUtil::UncheckedRoundUp(viewport_height, divisor) / divisor; |
737 | 742 |
738 // Grow default sizes to account for overlapping border texels. | 743 // Grow default sizes to account for overlapping border texels. |
739 default_tile_width += 2 * PictureLayerTiling::kBorderTexels; | 744 tile_width += 2 * PictureLayerTiling::kBorderTexels; |
740 default_tile_height += 2 * PictureLayerTiling::kBorderTexels; | 745 tile_height += 2 * PictureLayerTiling::kBorderTexels; |
741 | 746 |
742 default_tile_height = | 747 tile_height = std::max(tile_height, kMinHeightForGpuRasteredTile); |
743 std::max(default_tile_height, kMinHeightForGpuRasteredTile); | |
744 } else { | 748 } else { |
745 // For CPU rasterization we use tile-size settings. | 749 // For CPU rasterization we use stuff. |
enne (OOO)
2016/06/28 18:39:01
stuff, eh?
| |
750 int tile_size; | |
vmpstr
2016/06/29 01:40:23
Initialize to 0, so that DCHECK on 787 fails if we
| |
746 const LayerTreeSettings& settings = layer_tree_impl()->settings(); | 751 const LayerTreeSettings& settings = layer_tree_impl()->settings(); |
747 int max_untiled_content_width = settings.max_untiled_layer_size.width(); | 752 // TODO(crbug.com/622885): Supply the physical device size along with the |
748 int max_untiled_content_height = settings.max_untiled_layer_size.height(); | 753 // device scale factor to layer tree host. Use that instead of the viewport. |
749 default_tile_width = settings.default_tile_size.width(); | 754 // Then we should have use_viewport_for_tile_size always be true, and use it |
750 default_tile_height = settings.default_tile_size.height(); | 755 // for ganesh also (maybe with different |num_tiles| for it). |
756 if (settings.use_viewport_for_tile_size) { | |
757 int min_tile_size = 256; | |
758 int max_tile_size = 512; | |
751 | 759 |
752 // If the content width is small, increase tile size vertically. | 760 gfx::Size stable_size = layer_tree_impl()->GetStableScreenSize(); |
753 // If the content height is small, increase tile size horizontally. | 761 int display_width = stable_size.width(); |
754 // If both are less than the untiled-size, use a single tile. | 762 int display_height = stable_size.height(); |
755 if (content_bounds.width() < default_tile_width) | 763 |
756 default_tile_height = max_untiled_content_height; | 764 // Pick tile sizes for portrait mode on small screens. On bigger screens |
757 if (content_bounds.height() < default_tile_height) | 765 // we'll use the max tile sizes anyhow. |
758 default_tile_width = max_untiled_content_width; | 766 if (display_width > display_height) |
759 if (content_bounds.width() < max_untiled_content_width && | 767 std::swap(display_width, display_height); |
760 content_bounds.height() < max_untiled_content_height) { | 768 int num_tiles = 3; |
vmpstr
2016/06/29 01:40:23
can you const int kNumTiles this?
| |
761 default_tile_height = max_untiled_content_height; | 769 |
762 default_tile_width = max_untiled_content_width; | 770 // Tiles overlap by a border, so make the display seem that many pixels |
771 // larger. | |
772 display_width += (num_tiles - 1) * PictureLayerTiling::kBorderTexels; | |
773 | |
774 // These are the ideal tile size to put |num_tiles| across the screen at a | |
775 // time, rounded up to a multiple of kTileViewportAlignment, so the last | |
776 // tile will end up usually entending past the right edge of the screen a | |
777 // bit. | |
778 tile_size = MathUtil::UncheckedRoundUp( | |
779 (display_width + num_tiles - 1) / num_tiles, kTileViewportAlignment); | |
780 tile_size = std::max(tile_size, min_tile_size); | |
781 tile_size = std::min(tile_size, max_tile_size); | |
782 } else { | |
783 tile_size = 256; | |
784 if (layer_tree_impl()->device_scale_factor() >= 2.f) | |
785 tile_size = 512; | |
786 } | |
787 DCHECK_GT(tile_size, 0); | |
788 | |
789 tile_width = tile_height = tile_size; | |
790 | |
791 if (content_bounds.width() < kMaxUntiledContentSize && | |
792 content_bounds.height() < kMaxUntiledContentSize) { | |
793 // Small layers should not be tiled. | |
794 tile_width = tile_height = kMaxUntiledContentSize; | |
795 } else if (content_bounds.width() < tile_width) { | |
796 // If the content width is small, increase tile size vertically. | |
797 tile_height *= 2; | |
vmpstr
2016/06/29 01:40:23
Kind of overly safe, but can this break kMaxUntile
| |
798 } else if (content_bounds.height() < tile_height) { | |
799 // If the content height is small, increase tile size horizontally. | |
800 tile_width *= 2; | |
763 } | 801 } |
764 } | 802 } |
803 DCHECK_GT(tile_width, 0); | |
804 DCHECK_GT(tile_height, 0); | |
765 | 805 |
766 int tile_width = default_tile_width; | 806 // Shrink the tile width/height to be closer content width/height to save |
enne (OOO)
2016/06/28 18:39:01
closer...to?
| |
767 int tile_height = default_tile_height; | 807 // space, if there's a smaller multiple of kTileRoundUp. |
768 | 808 if (content_bounds.width() < tile_width) { |
769 // Clamp the tile width/height to the content width/height to save space. | 809 int before_tile_width = tile_width; |
770 if (content_bounds.width() < default_tile_width) { | 810 tile_width = |
771 tile_width = std::min(tile_width, content_bounds.width()); | 811 MathUtil::UncheckedRoundUp(content_bounds.width(), kTileRoundUp); |
772 tile_width = MathUtil::UncheckedRoundUp(tile_width, kTileRoundUp); | 812 tile_width = std::min(tile_width, before_tile_width); |
773 tile_width = std::min(tile_width, default_tile_width); | |
774 } | 813 } |
775 if (content_bounds.height() < default_tile_height) { | 814 if (content_bounds.height() < tile_height) { |
776 tile_height = std::min(tile_height, content_bounds.height()); | 815 int before_tile_height = tile_height; |
777 tile_height = MathUtil::UncheckedRoundUp(tile_height, kTileRoundUp); | 816 tile_height = |
778 tile_height = std::min(tile_height, default_tile_height); | 817 MathUtil::UncheckedRoundUp(content_bounds.height(), kTileRoundUp); |
818 tile_height = std::min(tile_height, before_tile_height); | |
779 } | 819 } |
780 | 820 |
781 // Ensure that tile width and height are properly aligned. | 821 // Ensure that tile width and height are properly aligned. |
782 tile_width = MathUtil::UncheckedRoundUp(tile_width, kTileMinimalAlignment); | 822 tile_width = MathUtil::UncheckedRoundUp(tile_width, kTileMinimalAlignment); |
783 tile_height = MathUtil::UncheckedRoundUp(tile_height, kTileMinimalAlignment); | 823 tile_height = MathUtil::UncheckedRoundUp(tile_height, kTileMinimalAlignment); |
784 | 824 |
785 // Under no circumstance should we be larger than the max texture size. | 825 // Under no circumstance should we be larger than the max texture size. |
786 tile_width = std::min(tile_width, max_texture_size); | 826 tile_width = std::min(tile_width, max_texture_size); |
787 tile_height = std::min(tile_height, max_texture_size); | 827 tile_height = std::min(tile_height, max_texture_size); |
788 return gfx::Size(tile_width, tile_height); | 828 return gfx::Size(tile_width, tile_height); |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1291 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { | 1331 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { |
1292 return !layer_tree_impl()->IsRecycleTree(); | 1332 return !layer_tree_impl()->IsRecycleTree(); |
1293 } | 1333 } |
1294 | 1334 |
1295 bool PictureLayerImpl::HasValidTilePriorities() const { | 1335 bool PictureLayerImpl::HasValidTilePriorities() const { |
1296 return IsOnActiveOrPendingTree() && | 1336 return IsOnActiveOrPendingTree() && |
1297 is_drawn_render_surface_layer_list_member(); | 1337 is_drawn_render_surface_layer_list_member(); |
1298 } | 1338 } |
1299 | 1339 |
1300 } // namespace cc | 1340 } // namespace cc |
OLD | NEW |