This repository was archived by the owner on Feb 25, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6k
[DisplayList] collect clear colors from rendering ops #53214
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1042,6 +1042,9 @@ bool DisplayListBuilder::QuickReject(const SkRect& bounds) const { | |
| void DisplayListBuilder::drawPaint() { | ||
| OpResult result = PaintResult(current_, kDrawPaintFlags); | ||
| if (result != OpResult::kNoEffect && AccumulateUnbounded()) { | ||
| if (current_layer().update_clear_color(current_, false)) { | ||
| return; | ||
| } | ||
| Push<DrawPaintOp>(0); | ||
| CheckLayerOpacityCompatibility(); | ||
| UpdateLayerResult(result); | ||
|
|
@@ -1054,6 +1057,9 @@ void DisplayListBuilder::DrawPaint(const DlPaint& paint) { | |
| void DisplayListBuilder::DrawColor(DlColor color, DlBlendMode mode) { | ||
| OpResult result = PaintResult(DlPaint(color).setBlendMode(mode)); | ||
| if (result != OpResult::kNoEffect && AccumulateUnbounded()) { | ||
| if (current_layer().update_clear_color(color, mode)) { | ||
| return; | ||
| } | ||
| Push<DrawColorOp>(0, color, mode); | ||
| CheckLayerOpacityCompatibility(mode); | ||
| UpdateLayerResult(result, mode); | ||
|
|
@@ -1082,6 +1088,11 @@ void DisplayListBuilder::drawRect(const SkRect& rect) { | |
| OpResult result = PaintResult(current_, flags); | ||
| if (result != OpResult::kNoEffect && | ||
| AccumulateOpBounds(rect.makeSorted(), flags)) { | ||
| if (current_layer().still_clearing && | ||
| current_info().global_state.rect_covers_cull(rect) && | ||
| current_layer().update_clear_color(current_, true)) { | ||
| return; | ||
| } | ||
| Push<DrawRectOp>(0, rect); | ||
| CheckLayerOpacityCompatibility(); | ||
| UpdateLayerResult(result); | ||
|
|
@@ -1096,6 +1107,11 @@ void DisplayListBuilder::drawOval(const SkRect& bounds) { | |
| OpResult result = PaintResult(current_, flags); | ||
| if (result != OpResult::kNoEffect && | ||
| AccumulateOpBounds(bounds.makeSorted(), flags)) { | ||
| if (current_layer().still_clearing && | ||
| current_info().global_state.oval_covers_cull(bounds) && | ||
| current_layer().update_clear_color(current_, true)) { | ||
| return; | ||
| } | ||
| Push<DrawOvalOp>(0, bounds); | ||
| CheckLayerOpacityCompatibility(); | ||
| UpdateLayerResult(result); | ||
|
|
@@ -1112,6 +1128,11 @@ void DisplayListBuilder::drawCircle(const SkPoint& center, SkScalar radius) { | |
| SkRect bounds = SkRect::MakeLTRB(center.fX - radius, center.fY - radius, | ||
| center.fX + radius, center.fY + radius); | ||
| if (AccumulateOpBounds(bounds, flags)) { | ||
| if (current_layer().still_clearing && | ||
| current_info().global_state.oval_covers_cull(bounds) && | ||
| current_layer().update_clear_color(current_, true)) { | ||
| return; | ||
| } | ||
| Push<DrawCircleOp>(0, center, radius); | ||
| CheckLayerOpacityCompatibility(); | ||
| UpdateLayerResult(result); | ||
|
|
@@ -1134,6 +1155,11 @@ void DisplayListBuilder::drawRRect(const SkRRect& rrect) { | |
| OpResult result = PaintResult(current_, flags); | ||
| if (result != OpResult::kNoEffect && | ||
| AccumulateOpBounds(rrect.getBounds(), flags)) { | ||
| if (current_layer().still_clearing && | ||
| current_info().global_state.rrect_covers_cull(rrect) && | ||
| current_layer().update_clear_color(current_, true)) { | ||
| return; | ||
| } | ||
| Push<DrawRRectOp>(0, rrect); | ||
| CheckLayerOpacityCompatibility(); | ||
| UpdateLayerResult(result); | ||
|
|
@@ -1786,6 +1812,63 @@ bool DisplayListBuilder::AccumulateBounds(const SkRect& bounds, | |
| return true; | ||
| } | ||
|
|
||
| bool DisplayListBuilder::LayerInfo::update_clear_color(DlColor color, | ||
| DlBlendMode mode) { | ||
| if (still_clearing) { | ||
| switch (mode) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should be able to support all blend modes, if we clear more than 1 color we perform the blending on the CPU. clear color should not impact max_blend_mode I think |
||
| case DlBlendMode::kSrc: | ||
| if (color.isTransparent()) { | ||
| clear_color = DlColor::kTransparent(); | ||
| max_blend_mode = DlBlendMode::kClear; | ||
| } else { | ||
| clear_color = color; | ||
| max_blend_mode = DlBlendMode::kSrc; | ||
| } | ||
| return true; | ||
| case DlBlendMode::kSrcOver: | ||
| if (color.isTransparent()) { | ||
| // No changes to clear_color or max_blend_mode... | ||
| } else { | ||
| if (color.isOpaque() || clear_color.isTransparent()) { | ||
| clear_color = color; | ||
| max_blend_mode = DlBlendMode::kSrc; | ||
| } else { | ||
| DlScalar fSrc = color.getAlphaF(); | ||
| DlScalar fDst = clear_color.getAlphaF() * (1.0f - fSrc); | ||
| DlScalar fRed = | ||
| color.getRedF() * fSrc + clear_color.getRedF() * fDst; | ||
| DlScalar fGreen = | ||
| color.getGreenF() * fSrc + clear_color.getGreenF() * fDst; | ||
| DlScalar fBlue = | ||
| color.getBlueF() * fSrc + clear_color.getBlueF() * fDst; | ||
| clear_color = DlColor::MakeARGB(fSrc + fDst, fRed, fGreen, fBlue); | ||
| max_blend_mode = DlBlendMode::kSrc; | ||
| } | ||
| } | ||
| return true; | ||
| default: | ||
| break; | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| bool DisplayListBuilder::LayerInfo::update_clear_color(const DlPaint& paint, | ||
| bool has_geometry) { | ||
| if (paint.getColorSourcePtr() != nullptr || | ||
| paint.getColorFilterPtr() != nullptr || | ||
| paint.getImageFilterPtr() != nullptr) { | ||
| return false; | ||
| } | ||
| if (has_geometry) { | ||
| if (paint.getDrawStyle() != DlDrawStyle::kFill || | ||
| paint.getMaskFilterPtr() != nullptr) { | ||
| return false; | ||
| } | ||
| } | ||
| return update_clear_color(paint.getColor(), paint.getBlendMode()); | ||
| } | ||
|
|
||
| bool DisplayListBuilder::SaveInfo::AccumulateBoundsLocal(const SkRect& bounds) { | ||
| if (bounds.isEmpty()) { | ||
| return false; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The render target's clear color will ignore all clips, so any time we add a non-culled clip to the builder we have to turn off clear color optimization.
This is makes clip culling is super important
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of this actually, we may need to do clear color optimization while dispatching instead of recording, but lets discuss today and see if folks have ideas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought of that last night. I was thinking that turning off the optimization after receiving a clip would do the trick there, but there is also the fact that the DL Builder is still figuring out the right bounds for the save layer while it is recording and won't know the true bounds until Restore is called. So, perhaps this entire optimization is not possible. Or perhaps it only works for DrawColor and DrawPaint that happen right after a SaveLayer but before any clips.
We'll discuss later...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I should probably transfer all of the new code to the clip functions to cull unnecessary clips even if it doesn't get used for clear color overlap detection...