Commit 7e9abb8a authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[BGPT] Collect graphics layers only when needed

- Call LocalFrameView::SetGraphicsLayersChanged() when graphics layer
  hierarchy changes or any graphics layer changes property tree state
  or offset. The function also sets PaintArtifactCompositorNeedsUpdate.

- Use a long-live paint controller in LocalFrameView to collect
  foreign layers of graphics layers. If graphics layers didn't change,
  just use the previous collected foreign layers.

Change-Id: I0c95b19098807cf0c640d9d26c62e68eb33acec9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1600302Reviewed-by: default avatarPhilip Rogers <pdr@chromium.org>
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#658313}
parent bf623ab3
...@@ -2474,7 +2474,6 @@ void LocalFrameView::RunPaintLifecyclePhase() { ...@@ -2474,7 +2474,6 @@ void LocalFrameView::RunPaintLifecyclePhase() {
} }
}); });
} }
paint_controller_ = nullptr;
} }
} }
} }
...@@ -2508,18 +2507,6 @@ void LocalFrameView::PerformScrollAnchoringAdjustments() { ...@@ -2508,18 +2507,6 @@ void LocalFrameView::PerformScrollAnchoringAdjustments() {
static void RecordGraphicsLayerAsForeignLayer( static void RecordGraphicsLayerAsForeignLayer(
GraphicsContext& context, GraphicsContext& context,
const GraphicsLayer* graphics_layer) { const GraphicsLayer* graphics_layer) {
// Copy the first chunk's safe opaque background color over to the cc::Layer
// in the foreign layer wrapper.
if (graphics_layer->DrawsContent()) {
auto& chunks =
graphics_layer->GetPaintController().GetPaintArtifact().PaintChunks();
SkColor safe_background_color = SK_ColorWHITE;
if (chunks.size()) {
safe_background_color = chunks[0].safe_opaque_background_color;
}
graphics_layer->CcLayer()->SetSafeOpaqueBackgroundColor(
safe_background_color);
}
// TODO(trchen): Currently the GraphicsLayer hierarchy is still built during // TODO(trchen): Currently the GraphicsLayer hierarchy is still built during
// CompositingUpdate, and we have to clear them here to ensure no extraneous // CompositingUpdate, and we have to clear them here to ensure no extraneous
// layers are still attached. In future we will disable all those layer // layers are still attached. In future we will disable all those layer
...@@ -2719,6 +2706,13 @@ void LocalFrameView::PushPaintArtifactToCompositor() { ...@@ -2719,6 +2706,13 @@ void LocalFrameView::PushPaintArtifactToCompositor() {
SCOPED_UMA_AND_UKM_TIMER(EnsureUkmAggregator(), SCOPED_UMA_AND_UKM_TIMER(EnsureUkmAggregator(),
LocalFrameUkmAggregator::kCompositingCommit); LocalFrameUkmAggregator::kCompositingCommit);
// Skip updating property trees, pushing cc::Layers, and issuing raster
// invalidations if possible.
if (!paint_artifact_compositor_->NeedsUpdate()) {
DCHECK(paint_controller_);
return;
}
PaintArtifactCompositor::ViewportProperties viewport_properties; PaintArtifactCompositor::ViewportProperties viewport_properties;
if (GetFrame().IsMainFrame()) { if (GetFrame().IsMainFrame()) {
const auto& viewport = page->GetVisualViewport(); const auto& viewport = page->GetVisualViewport();
...@@ -2731,17 +2725,14 @@ void LocalFrameView::PushPaintArtifactToCompositor() { ...@@ -2731,17 +2725,14 @@ void LocalFrameView::PushPaintArtifactToCompositor() {
settings.prefer_compositing_to_lcd_text = settings.prefer_compositing_to_lcd_text =
page->GetSettings().GetPreferCompositingToLCDTextEnabled(); page->GetSettings().GetPreferCompositingToLCDTextEnabled();
// Skip updating property trees, pushing cc::Layers, and issuing raster
// invalidations if possible.
if (!paint_artifact_compositor_->NeedsUpdate())
return;
if (RuntimeEnabledFeatures::BlinkGenPropertyTreesEnabled() && if (RuntimeEnabledFeatures::BlinkGenPropertyTreesEnabled() &&
!RuntimeEnabledFeatures::CompositeAfterPaintEnabled()) { !RuntimeEnabledFeatures::CompositeAfterPaintEnabled() &&
// BlinkGenPropertyTrees just needs a transient PaintController to !paint_controller_) {
// collect the foreign layers which doesn't need caching. It also // BlinkGenPropertyTrees just needs a transient PaintController to collect
// shouldn't affect caching status of DisplayItemClients because it's // the foreign layers which doesn't need caching. It also shouldn't affect
// FinishCycle() is not synchronized with other PaintControllers. // caching status of DisplayItemClients because it's FinishCycle() is not
// synchronized with other PaintControllers. It may live across frame update
// until GraphicsLayersDidChange() is called.
paint_controller_ = paint_controller_ =
std::make_unique<PaintController>(PaintController::kTransient); std::make_unique<PaintController>(PaintController::kTransient);
...@@ -4000,12 +3991,22 @@ void LocalFrameView::SetIntersectionObservationState( ...@@ -4000,12 +3991,22 @@ void LocalFrameView::SetIntersectionObservationState(
intersection_observation_state_ = state; intersection_observation_state_ = state;
} }
void LocalFrameView::SetPaintArtifactCompositorNeedsUpdate() const { void LocalFrameView::SetPaintArtifactCompositorNeedsUpdate() {
LocalFrameView* root = GetFrame().LocalFrameRoot().View(); LocalFrameView* root = GetFrame().LocalFrameRoot().View();
if (root && root->paint_artifact_compositor_) if (root && root->paint_artifact_compositor_)
root->paint_artifact_compositor_->SetNeedsUpdate(); root->paint_artifact_compositor_->SetNeedsUpdate();
} }
void LocalFrameView::GraphicsLayersDidChange() {
LocalFrameView* root = GetFrame().LocalFrameRoot().View();
if (root) {
// We will re-collect GraphicsLayers in PushPaintArtifactsToCompositor().
root->paint_controller_ = nullptr;
if (root->paint_artifact_compositor_)
root->paint_artifact_compositor_->SetNeedsUpdate();
}
}
PaintArtifactCompositor* LocalFrameView::GetPaintArtifactCompositor() const { PaintArtifactCompositor* LocalFrameView::GetPaintArtifactCompositor() const {
LocalFrameView* root = GetFrame().LocalFrameRoot().View(); LocalFrameView* root = GetFrame().LocalFrameRoot().View();
return root ? root->paint_artifact_compositor_.get() : nullptr; return root ? root->paint_artifact_compositor_.get() : nullptr;
......
...@@ -205,7 +205,8 @@ class CORE_EXPORT LocalFrameView final ...@@ -205,7 +205,8 @@ class CORE_EXPORT LocalFrameView final
void ForceUpdateViewportIntersections(); void ForceUpdateViewportIntersections();
void SetPaintArtifactCompositorNeedsUpdate() const; void SetPaintArtifactCompositorNeedsUpdate();
void GraphicsLayersDidChange();
// Marks this frame, and ancestor frames, as needing a mandatory compositing // Marks this frame, and ancestor frames, as needing a mandatory compositing
// update. This overrides throttling for one frame, up to kCompositingClean. // update. This overrides throttling for one frame, up to kCompositingClean.
...@@ -938,7 +939,14 @@ class CORE_EXPORT LocalFrameView final ...@@ -938,7 +939,14 @@ class CORE_EXPORT LocalFrameView final
std::unique_ptr<Vector<ObjectPaintInvalidation>> std::unique_ptr<Vector<ObjectPaintInvalidation>>
tracked_object_paint_invalidations_; tracked_object_paint_invalidations_;
// For CompositeAfterPaint only. // For BlinkGenPropertyTrees/CompositeAfterPaint only. It's created lazily
// when it's used.
// - For BlinkGenPropertyTrees, we use it in PushPaintArtifactToCompositor()
// to collect GraphicsLayers as foreign layers. It's transient, but may live
// across frame updates until GraphicsLayersDidChange() is called.
// - For CompositeAfterPaint, we use it in PaintTree() for all paintings of
// the frame tree in PaintTree(). It caches display items and subsequences
// across frame updates and repaints.
std::unique_ptr<PaintController> paint_controller_; std::unique_ptr<PaintController> paint_controller_;
std::unique_ptr<PaintArtifactCompositor> paint_artifact_compositor_; std::unique_ptr<PaintArtifactCompositor> paint_artifact_compositor_;
......
...@@ -1156,9 +1156,9 @@ void VisualViewport::SetOverlayScrollbarsHidden(bool hidden) { ...@@ -1156,9 +1156,9 @@ void VisualViewport::SetOverlayScrollbarsHidden(bool hidden) {
ScrollableArea::SetScrollbarsHiddenIfOverlay(hidden); ScrollableArea::SetScrollbarsHiddenIfOverlay(hidden);
} }
void VisualViewport::SetPaintArtifactCompositorNeedsUpdate() const { void VisualViewport::GraphicsLayersDidChange() {
if (MainFrame() && MainFrame()->View()) if (MainFrame() && MainFrame()->View())
MainFrame()->View()->SetPaintArtifactCompositorNeedsUpdate(); MainFrame()->View()->GraphicsLayersDidChange();
} }
PaintArtifactCompositor* VisualViewport::GetPaintArtifactCompositor() const { PaintArtifactCompositor* VisualViewport::GetPaintArtifactCompositor() const {
......
...@@ -295,7 +295,7 @@ class CORE_EXPORT VisualViewport final ...@@ -295,7 +295,7 @@ class CORE_EXPORT VisualViewport final
GraphicsLayerPaintingPhase, GraphicsLayerPaintingPhase,
const IntRect&) const override; const IntRect&) const override;
void SetOverlayScrollbarsHidden(bool) override; void SetOverlayScrollbarsHidden(bool) override;
void SetPaintArtifactCompositorNeedsUpdate() const override; void GraphicsLayersDidChange() override;
String DebugName(const GraphicsLayer*) const override; String DebugName(const GraphicsLayer*) const override;
const ScrollableArea* GetScrollableAreaForTesting( const ScrollableArea* GetScrollableAreaForTesting(
......
...@@ -3506,10 +3506,10 @@ void CompositedLayerMapping::SetOverlayScrollbarsHidden(bool hidden) { ...@@ -3506,10 +3506,10 @@ void CompositedLayerMapping::SetOverlayScrollbarsHidden(bool hidden) {
scrollable_area->SetScrollbarsHiddenIfOverlay(hidden); scrollable_area->SetScrollbarsHiddenIfOverlay(hidden);
} }
void CompositedLayerMapping::SetPaintArtifactCompositorNeedsUpdate() const { void CompositedLayerMapping::GraphicsLayersDidChange() {
LocalFrameView* frame_view = GetLayoutObject().GetFrameView(); LocalFrameView* frame_view = GetLayoutObject().GetFrameView();
DCHECK(frame_view); DCHECK(frame_view);
frame_view->SetPaintArtifactCompositorNeedsUpdate(); frame_view->GraphicsLayersDidChange();
} }
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
......
...@@ -215,7 +215,7 @@ class CORE_EXPORT CompositedLayerMapping final : public GraphicsLayerClient { ...@@ -215,7 +215,7 @@ class CORE_EXPORT CompositedLayerMapping final : public GraphicsLayerClient {
bool ShouldThrottleRendering() const override; bool ShouldThrottleRendering() const override;
bool IsTrackingRasterInvalidations() const override; bool IsTrackingRasterInvalidations() const override;
void SetOverlayScrollbarsHidden(bool) override; void SetOverlayScrollbarsHidden(bool) override;
void SetPaintArtifactCompositorNeedsUpdate() const override; void GraphicsLayersDidChange() override;
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
void VerifyNotPainting() override; void VerifyNotPainting() override;
......
...@@ -514,8 +514,12 @@ void LinkHighlightImpl::Paint(GraphicsContext& context) { ...@@ -514,8 +514,12 @@ void LinkHighlightImpl::Paint(GraphicsContext& context) {
void LinkHighlightImpl::SetPaintArtifactCompositorNeedsUpdate() { void LinkHighlightImpl::SetPaintArtifactCompositorNeedsUpdate() {
DCHECK(node_); DCHECK(node_);
if (auto* frame_view = node_->GetDocument().View()) if (auto* frame_view = node_->GetDocument().View()) {
frame_view->SetPaintArtifactCompositorNeedsUpdate(); if (RuntimeEnabledFeatures::CompositeAfterPaintEnabled())
frame_view->SetPaintArtifactCompositorNeedsUpdate();
else
frame_view->GraphicsLayersDidChange();
}
} }
} // namespace blink } // namespace blink
...@@ -259,7 +259,7 @@ void GraphicsLayer::RemoveFromParent() { ...@@ -259,7 +259,7 @@ void GraphicsLayer::RemoveFromParent() {
!RuntimeEnabledFeatures::CompositeAfterPaintEnabled()) { !RuntimeEnabledFeatures::CompositeAfterPaintEnabled()) {
CcLayer()->RemoveFromParent(); CcLayer()->RemoveFromParent();
} else { } else {
SetPaintArtifactCompositorNeedsUpdate(); client_.GraphicsLayersDidChange();
} }
} }
...@@ -323,10 +323,12 @@ bool GraphicsLayer::Paint(GraphicsContext::DisabledMode disabled_mode) { ...@@ -323,10 +323,12 @@ bool GraphicsLayer::Paint(GraphicsContext::DisabledMode disabled_mode) {
return false; return false;
#endif #endif
if (PaintWithoutCommit(disabled_mode)) if (PaintWithoutCommit(disabled_mode)) {
GetPaintController().CommitNewDisplayItems(); GetPaintController().CommitNewDisplayItems();
else if (!needs_check_raster_invalidation_) UpdateSafeOpaqueBackgroundColor();
} else if (!needs_check_raster_invalidation_) {
return false; return false;
}
#if DCHECK_IS_ON() #if DCHECK_IS_ON()
if (VLOG_IS_ON(2)) { if (VLOG_IS_ON(2)) {
...@@ -360,6 +362,15 @@ bool GraphicsLayer::Paint(GraphicsContext::DisabledMode disabled_mode) { ...@@ -360,6 +362,15 @@ bool GraphicsLayer::Paint(GraphicsContext::DisabledMode disabled_mode) {
return true; return true;
} }
void GraphicsLayer::UpdateSafeOpaqueBackgroundColor() {
if (!DrawsContent())
return;
// Copy the first chunk's safe opaque background color over to the cc::Layer.
const auto& chunks = GetPaintController().GetPaintArtifact().PaintChunks();
CcLayer()->SetSafeOpaqueBackgroundColor(
chunks.size() ? chunks[0].safe_opaque_background_color : SK_ColorWHITE);
}
bool GraphicsLayer::PaintWithoutCommitForTesting( bool GraphicsLayer::PaintWithoutCommitForTesting(
const base::Optional<IntRect>& interest_rect) { const base::Optional<IntRect>& interest_rect) {
return PaintWithoutCommit(GraphicsContext::kNothingDisabled, return PaintWithoutCommit(GraphicsContext::kNothingDisabled,
...@@ -403,7 +414,7 @@ void GraphicsLayer::UpdateChildList() { ...@@ -403,7 +414,7 @@ void GraphicsLayer::UpdateChildList() {
// When using layer lists, cc::Layers are created in PaintArtifactCompositor. // When using layer lists, cc::Layers are created in PaintArtifactCompositor.
if (RuntimeEnabledFeatures::BlinkGenPropertyTreesEnabled() || if (RuntimeEnabledFeatures::BlinkGenPropertyTreesEnabled() ||
RuntimeEnabledFeatures::CompositeAfterPaintEnabled()) { RuntimeEnabledFeatures::CompositeAfterPaintEnabled()) {
SetPaintArtifactCompositorNeedsUpdate(); client_.GraphicsLayersDidChange();
return; return;
} }
...@@ -740,10 +751,6 @@ void GraphicsLayer::SetContentsVisible(bool contents_visible) { ...@@ -740,10 +751,6 @@ void GraphicsLayer::SetContentsVisible(bool contents_visible) {
UpdateLayerIsDrawable(); UpdateLayerIsDrawable();
} }
void GraphicsLayer::SetPaintArtifactCompositorNeedsUpdate() const {
client_.SetPaintArtifactCompositorNeedsUpdate();
}
void GraphicsLayer::SetClipParent(cc::Layer* parent) { void GraphicsLayer::SetClipParent(cc::Layer* parent) {
has_clip_parent_ = !!parent; has_clip_parent_ = !!parent;
CcLayer()->SetClipParent(parent); CcLayer()->SetClipParent(parent);
...@@ -876,6 +883,7 @@ void GraphicsLayer::SetContentsRect(const IntRect& rect) { ...@@ -876,6 +883,7 @@ void GraphicsLayer::SetContentsRect(const IntRect& rect) {
contents_rect_ = rect; contents_rect_ = rect;
UpdateContentsRect(); UpdateContentsRect();
client_.GraphicsLayersDidChange();
} }
void GraphicsLayer::SetContentsToImage( void GraphicsLayer::SetContentsToImage(
...@@ -1055,7 +1063,7 @@ void GraphicsLayer::SetLayerState(const PropertyTreeState& layer_state, ...@@ -1055,7 +1063,7 @@ void GraphicsLayer::SetLayerState(const PropertyTreeState& layer_state,
} }
if (RuntimeEnabledFeatures::BlinkGenPropertyTreesEnabled()) if (RuntimeEnabledFeatures::BlinkGenPropertyTreesEnabled())
SetPaintArtifactCompositorNeedsUpdate(); client_.GraphicsLayersDidChange();
} }
void GraphicsLayer::SetContentsPropertyTreeState( void GraphicsLayer::SetContentsPropertyTreeState(
...@@ -1063,11 +1071,15 @@ void GraphicsLayer::SetContentsPropertyTreeState( ...@@ -1063,11 +1071,15 @@ void GraphicsLayer::SetContentsPropertyTreeState(
DCHECK(ContentsLayer()); DCHECK(ContentsLayer());
if (contents_property_tree_state_) { if (contents_property_tree_state_) {
if (*contents_property_tree_state_ == layer_state)
return;
*contents_property_tree_state_ = layer_state; *contents_property_tree_state_ = layer_state;
} else { } else {
contents_property_tree_state_ = contents_property_tree_state_ =
std::make_unique<PropertyTreeState>(layer_state); std::make_unique<PropertyTreeState>(layer_state);
} }
if (RuntimeEnabledFeatures::BlinkGenPropertyTreesEnabled())
client_.GraphicsLayersDidChange();
} }
scoped_refptr<cc::DisplayItemList> GraphicsLayer::PaintContentsToDisplayList( scoped_refptr<cc::DisplayItemList> GraphicsLayer::PaintContentsToDisplayList(
......
...@@ -171,8 +171,6 @@ class PLATFORM_EXPORT GraphicsLayer : public cc::LayerClient, ...@@ -171,8 +171,6 @@ class PLATFORM_EXPORT GraphicsLayer : public cc::LayerClient,
void SetScrollParent(cc::Layer*); void SetScrollParent(cc::Layer*);
void SetClipParent(cc::Layer*); void SetClipParent(cc::Layer*);
void SetPaintArtifactCompositorNeedsUpdate() const;
// For special cases, e.g. drawing missing tiles on Android. // For special cases, e.g. drawing missing tiles on Android.
// The compositor should never paint this color in normal cases because the // The compositor should never paint this color in normal cases because the
// Layer will paint the background by itself. // Layer will paint the background by itself.
...@@ -333,6 +331,7 @@ class PLATFORM_EXPORT GraphicsLayer : public cc::LayerClient, ...@@ -333,6 +331,7 @@ class PLATFORM_EXPORT GraphicsLayer : public cc::LayerClient,
size_t GetApproximateUnsharedMemoryUsage() const final; size_t GetApproximateUnsharedMemoryUsage() const final;
void PaintRecursivelyInternal(Vector<GraphicsLayer*>& repainted_layers); void PaintRecursivelyInternal(Vector<GraphicsLayer*>& repainted_layers);
void UpdateSafeOpaqueBackgroundColor();
// Returns true if PaintController::PaintArtifact() changed and needs commit. // Returns true if PaintController::PaintArtifact() changed and needs commit.
bool PaintWithoutCommit( bool PaintWithoutCommit(
......
...@@ -96,7 +96,7 @@ class PLATFORM_EXPORT GraphicsLayerClient { ...@@ -96,7 +96,7 @@ class PLATFORM_EXPORT GraphicsLayerClient {
virtual void SetOverlayScrollbarsHidden(bool) {} virtual void SetOverlayScrollbarsHidden(bool) {}
virtual void SetPaintArtifactCompositorNeedsUpdate() const {} virtual void GraphicsLayersDidChange() {}
virtual String DebugName(const GraphicsLayer*) const = 0; virtual String DebugName(const GraphicsLayer*) const = 0;
......
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