Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(615)

Side by Side Diff: cc/layers/picture_layer_impl.cc

Issue 2099903002: Make tile size a function of the device scale factor. Base URL: https://chromium.googlesource.com/chromium/src.git@layouttests-display
Patch Set: Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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.
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
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()) {
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.
750 int tile_size;
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 int display_width = layer_tree_impl()->device_viewport_size().width();
753 // If the content height is small, increase tile size horizontally. 761 // TODO(crbug.com/622885): Make this independent of the top controls, but
754 // If both are less than the untiled-size, use a single tile. 762 // large enough to not have small tiles at the bottom.
755 if (content_bounds.width() < default_tile_width) 763 int display_height = layer_tree_impl()->device_viewport_size().height();
756 default_tile_height = max_untiled_content_height; 764
757 if (content_bounds.height() < default_tile_height) 765 int portrait_num_tiles = 3;
758 default_tile_width = max_untiled_content_width; 766 int landscape_num_tiles = 5;
759 if (content_bounds.width() < max_untiled_content_width && 767
760 content_bounds.height() < max_untiled_content_height) { 768 int num_tiles = display_width < display_height ? portrait_num_tiles
761 default_tile_height = max_untiled_content_height; 769 : landscape_num_tiles;
762 default_tile_width = max_untiled_content_width; 770
771 // Tiles overlap by a border, so make the display seem that many pixels
772 // larger.
773 display_width += (num_tiles - 1) * PictureLayerTiling::kBorderTexels;
774
775 // These are the ideal tile size to put |num_tiles| across the screen at a
776 // time, rounded up to a multiple of kTileViewportAlignment, so the last
777 // tile will end up usually entending past the right edge of the screen a
778 // bit.
779 tile_size = MathUtil::UncheckedRoundUp(
780 (display_width + num_tiles - 1) / num_tiles, kTileViewportAlignment);
781 tile_size = std::max(tile_size, min_tile_size);
782 tile_size = std::min(tile_size, max_tile_size);
783 } else {
784 tile_size = 256;
785 if (layer_tree_impl()->device_scale_factor() >= 2.f)
786 tile_size = 512;
787 }
788 DCHECK_GT(tile_size, 0);
789
790 tile_width = tile_height = tile_size;
791
792 if (content_bounds.width() < kMaxUntiledContentSize &&
793 content_bounds.height() < kMaxUntiledContentSize) {
794 // Small layers should not be tiled.
795 tile_width = tile_height = kMaxUntiledContentSize;
796 } else if (content_bounds.width() < tile_width) {
797 // If the content width is small, increase tile size vertically.
798 tile_height *= 2;
799 } else if (content_bounds.height() < tile_height) {
800 // If the content height is small, increase tile size horizontally.
801 tile_width *= 2;
763 } 802 }
764 } 803 }
804 DCHECK_GT(tile_width, 0);
805 DCHECK_GT(tile_height, 0);
765 806
766 int tile_width = default_tile_width; 807 // Shrink the tile width/height to be closer content width/height to save
767 int tile_height = default_tile_height; 808 // space, if there's a smaller multiple of kTileRoundUp.
768 809 if (content_bounds.width() < tile_width) {
769 // Clamp the tile width/height to the content width/height to save space. 810 int before_tile_width = tile_width;
770 if (content_bounds.width() < default_tile_width) { 811 tile_width =
771 tile_width = std::min(tile_width, content_bounds.width()); 812 MathUtil::UncheckedRoundUp(content_bounds.width(), kTileRoundUp);
772 tile_width = MathUtil::UncheckedRoundUp(tile_width, kTileRoundUp); 813 tile_width = std::min(tile_width, before_tile_width);
773 tile_width = std::min(tile_width, default_tile_width);
774 } 814 }
775 if (content_bounds.height() < default_tile_height) { 815 if (content_bounds.height() < tile_height) {
776 tile_height = std::min(tile_height, content_bounds.height()); 816 int before_tile_height = tile_height;
777 tile_height = MathUtil::UncheckedRoundUp(tile_height, kTileRoundUp); 817 tile_height =
778 tile_height = std::min(tile_height, default_tile_height); 818 MathUtil::UncheckedRoundUp(content_bounds.height(), kTileRoundUp);
819 tile_height = std::min(tile_height, before_tile_height);
779 } 820 }
780 821
781 // Ensure that tile width and height are properly aligned. 822 // Ensure that tile width and height are properly aligned.
782 tile_width = MathUtil::UncheckedRoundUp(tile_width, kTileMinimalAlignment); 823 tile_width = MathUtil::UncheckedRoundUp(tile_width, kTileMinimalAlignment);
783 tile_height = MathUtil::UncheckedRoundUp(tile_height, kTileMinimalAlignment); 824 tile_height = MathUtil::UncheckedRoundUp(tile_height, kTileMinimalAlignment);
784 825
785 // Under no circumstance should we be larger than the max texture size. 826 // Under no circumstance should we be larger than the max texture size.
786 tile_width = std::min(tile_width, max_texture_size); 827 tile_width = std::min(tile_width, max_texture_size);
787 tile_height = std::min(tile_height, max_texture_size); 828 tile_height = std::min(tile_height, max_texture_size);
788 return gfx::Size(tile_width, tile_height); 829 return gfx::Size(tile_width, tile_height);
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after
1291 bool PictureLayerImpl::IsOnActiveOrPendingTree() const { 1332 bool PictureLayerImpl::IsOnActiveOrPendingTree() const {
1292 return !layer_tree_impl()->IsRecycleTree(); 1333 return !layer_tree_impl()->IsRecycleTree();
1293 } 1334 }
1294 1335
1295 bool PictureLayerImpl::HasValidTilePriorities() const { 1336 bool PictureLayerImpl::HasValidTilePriorities() const {
1296 return IsOnActiveOrPendingTree() && 1337 return IsOnActiveOrPendingTree() &&
1297 is_drawn_render_surface_layer_list_member(); 1338 is_drawn_render_surface_layer_list_member();
1298 } 1339 }
1299 1340
1300 } // namespace cc 1341 } // namespace cc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698