Commit 6f9f402c authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

Avoid unnecessary tiling invalidation on LCD text changes

Don't invalidate tiling:
- when LCDTextDisallowedReason changes from one reason to another
  as long as PicureLayerImpl::can_use_lcd_text() is the same as
  HighResTiling()->can_use_lcd_text().
- if there is no text, but keep the high res tiling with the existing
  LCD text and raster translation they don't matter without text.

This doesn't fix the root cause of the bug (crrev.com/c/2411492 by
vmpstr@ does), but is just a performance improvement.

Bug: 1127803
Change-Id: I2dfd9523b32cc4a3de828892e726514f3186151f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2410580
Commit-Queue: vmpstr <vmpstr@chromium.org>
Reviewed-by: default avatarvmpstr <vmpstr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807033}
parent 4143bf38
...@@ -14,6 +14,8 @@ ...@@ -14,6 +14,8 @@
#include <set> #include <set>
#include <utility> #include <utility>
#include "base/logging.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/no_destructor.h" #include "base/no_destructor.h"
#include "base/numerics/ranges.h" #include "base/numerics/ranges.h"
...@@ -810,20 +812,15 @@ void PictureLayerImpl::UpdateRasterSource( ...@@ -810,20 +812,15 @@ void PictureLayerImpl::UpdateRasterSource(
} }
} }
bool PictureLayerImpl::UpdateCanUseLCDText( void PictureLayerImpl::UpdateCanUseLCDText(
bool raster_translation_aligns_pixels) { bool raster_translation_aligns_pixels) {
// If we have pending/active trees, the active tree doesn't update lcd text // If we have pending/active trees, the active tree doesn't update lcd text
// status but copies it from the pending tree. // status but copies it from the pending tree.
if (!layer_tree_impl()->IsSyncTree()) if (!layer_tree_impl()->IsSyncTree())
return false; return;
auto new_lcd_text_disallowed_reason = lcd_text_disallowed_reason_ =
ComputeLCDTextDisallowedReason(raster_translation_aligns_pixels); ComputeLCDTextDisallowedReason(raster_translation_aligns_pixels);
if (lcd_text_disallowed_reason_ == new_lcd_text_disallowed_reason)
return false;
lcd_text_disallowed_reason_ = new_lcd_text_disallowed_reason;
return true;
} }
bool PictureLayerImpl::HasWillChangeTransformHint() const { bool PictureLayerImpl::HasWillChangeTransformHint() const {
...@@ -1200,6 +1197,9 @@ bool PictureLayerImpl::CanRecreateHighResTilingForLCDTextAndRasterTranslation( ...@@ -1200,6 +1197,9 @@ bool PictureLayerImpl::CanRecreateHighResTilingForLCDTextAndRasterTranslation(
// Also avoid re-rasterization during pinch-zoom. // Also avoid re-rasterization during pinch-zoom.
if (layer_tree_impl()->PinchGestureActive()) if (layer_tree_impl()->PinchGestureActive())
return false; return false;
// Keep the current LCD text and raster translation if there is no text.
if (lcd_text_disallowed_reason_ == LCDTextDisallowedReason::kNoText)
return false;
return true; return true;
} }
...@@ -1211,11 +1211,12 @@ void PictureLayerImpl::UpdateTilingsForRasterScaleAndTranslation( ...@@ -1211,11 +1211,12 @@ void PictureLayerImpl::UpdateTilingsForRasterScaleAndTranslation(
gfx::Vector2dF raster_translation; gfx::Vector2dF raster_translation;
bool raster_translation_aligns_pixels = bool raster_translation_aligns_pixels =
CalculateRasterTranslation(raster_translation); CalculateRasterTranslation(raster_translation);
bool can_use_lcd_text_changed = UpdateCanUseLCDText(raster_translation_aligns_pixels);
UpdateCanUseLCDText(raster_translation_aligns_pixels);
if (high_res) { if (high_res) {
bool raster_translation_is_not_ideal = bool raster_translation_is_not_ideal =
high_res->raster_transform().translation() != raster_translation; high_res->raster_transform().translation() != raster_translation;
bool can_use_lcd_text_changed =
high_res->can_use_lcd_text() != can_use_lcd_text();
bool should_recreate_high_res = bool should_recreate_high_res =
(raster_translation_is_not_ideal || can_use_lcd_text_changed) && (raster_translation_is_not_ideal || can_use_lcd_text_changed) &&
CanRecreateHighResTilingForLCDTextAndRasterTranslation(*high_res); CanRecreateHighResTilingForLCDTextAndRasterTranslation(*high_res);
......
...@@ -222,8 +222,7 @@ class CC_EXPORT PictureLayerImpl ...@@ -222,8 +222,7 @@ class CC_EXPORT PictureLayerImpl
LCDTextDisallowedReason ComputeLCDTextDisallowedReason( LCDTextDisallowedReason ComputeLCDTextDisallowedReason(
bool raster_translation_aligns_pixels) const; bool raster_translation_aligns_pixels) const;
// Returns true if the LCD state changed. void UpdateCanUseLCDText(bool raster_translation_aligns_pixels);
bool UpdateCanUseLCDText(bool raster_translation_aligns_pixels);
// TODO(crbug.com/1114504): For now this checks the immediate transform node // TODO(crbug.com/1114504): For now this checks the immediate transform node
// only. The callers may actually want to know if this layer or ancestor has // only. The callers may actually want to know if this layer or ancestor has
......
...@@ -5066,8 +5066,20 @@ TEST_F(LegacySWPictureLayerImplTest, UpdateLCDTextInvalidatesPendingTree) { ...@@ -5066,8 +5066,20 @@ TEST_F(LegacySWPictureLayerImplTest, UpdateLCDTextInvalidatesPendingTree) {
for (Tile* tile : pending_layer()->HighResTiling()->AllTilesForTesting()) for (Tile* tile : pending_layer()->HighResTiling()->AllTilesForTesting())
EXPECT_FALSE(tile->can_use_lcd_text()); EXPECT_FALSE(tile->can_use_lcd_text());
// Change of the specific LCD text disallowed reason should not invalidate
// tilings.
pending_layer()->SetContentsOpaque(true); pending_layer()->SetContentsOpaque(true);
pending_layer()->UpdateTiles(); FilterOperations blur_filter;
blur_filter.Append(FilterOperation::CreateBlurFilter(4.0f));
SetFilter(pending_layer(), blur_filter);
UpdateDrawProperties(host_impl()->pending_tree());
EXPECT_FALSE(pending_layer()->can_use_lcd_text());
EXPECT_TRUE(pending_layer()->HighResTiling()->has_tiles());
for (Tile* tile : pending_layer()->HighResTiling()->AllTilesForTesting())
EXPECT_FALSE(tile->can_use_lcd_text());
SetFilter(pending_layer(), FilterOperations());
UpdateDrawProperties(host_impl()->pending_tree());
EXPECT_TRUE(pending_layer()->can_use_lcd_text()); EXPECT_TRUE(pending_layer()->can_use_lcd_text());
EXPECT_TRUE(pending_layer()->HighResTiling()->has_tiles()); EXPECT_TRUE(pending_layer()->HighResTiling()->has_tiles());
for (Tile* tile : pending_layer()->HighResTiling()->AllTilesForTesting()) for (Tile* tile : pending_layer()->HighResTiling()->AllTilesForTesting())
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment