Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4b8218d

Browse files
authored
[DisplayList] Pre-Compute saveLayer bounds in DLBuilder (#50935)
Previously the DisplayListBuilder would only pass along bounds for a saveLayer when they were supplied by the caller that was building the DisplayList. This would require Impeller to use post-processing of the EntityPass lists to compute them on its own. DisplayList can now compute those bounds as it builds the DisplayList to save dispatch clients from having to do so on their own. It will also provide an indicator in the case when the caller supplied bounds that ended up being too small to capture all of the content, causing clipping by the layer render target.
1 parent ee65a91 commit 4b8218d

33 files changed

+987
-196
lines changed

display_list/benchmarking/dl_complexity_gl.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ unsigned int DisplayListGLComplexityCalculator::GLHelper::BatchedComplexity() {
4949
}
5050

5151
void DisplayListGLComplexityCalculator::GLHelper::saveLayer(
52-
const SkRect* bounds,
52+
const SkRect& bounds,
5353
const SaveLayerOptions options,
5454
const DlImageFilter* backdrop) {
5555
if (IsComplex()) {
@@ -615,7 +615,8 @@ void DisplayListGLComplexityCalculator::GLHelper::drawDisplayList(
615615
}
616616
GLHelper helper(Ceiling() - CurrentComplexityScore());
617617
if (opacity < SK_Scalar1 && !display_list->can_apply_group_opacity()) {
618-
helper.saveLayer(nullptr, SaveLayerOptions::kWithAttributes, nullptr);
618+
auto bounds = display_list->bounds();
619+
helper.saveLayer(bounds, SaveLayerOptions::kWithAttributes, nullptr);
619620
}
620621
display_list->Dispatch(helper);
621622
AccumulateComplexity(helper.ComplexityScore());

display_list/benchmarking/dl_complexity_gl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DisplayListGLComplexityCalculator
3535
explicit GLHelper(unsigned int ceiling)
3636
: ComplexityCalculatorHelper(ceiling) {}
3737

38-
void saveLayer(const SkRect* bounds,
38+
void saveLayer(const SkRect& bounds,
3939
const SaveLayerOptions options,
4040
const DlImageFilter* backdrop) override;
4141

display_list/benchmarking/dl_complexity_metal.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ DisplayListMetalComplexityCalculator::MetalHelper::BatchedComplexity() {
6363
}
6464

6565
void DisplayListMetalComplexityCalculator::MetalHelper::saveLayer(
66-
const SkRect* bounds,
66+
const SkRect& bounds,
6767
const SaveLayerOptions options,
6868
const DlImageFilter* backdrop) {
6969
if (IsComplex()) {
@@ -559,7 +559,8 @@ void DisplayListMetalComplexityCalculator::MetalHelper::drawDisplayList(
559559
}
560560
MetalHelper helper(Ceiling() - CurrentComplexityScore());
561561
if (opacity < SK_Scalar1 && !display_list->can_apply_group_opacity()) {
562-
helper.saveLayer(nullptr, SaveLayerOptions::kWithAttributes, nullptr);
562+
auto bounds = display_list->bounds();
563+
helper.saveLayer(bounds, SaveLayerOptions::kWithAttributes, nullptr);
563564
}
564565
display_list->Dispatch(helper);
565566
AccumulateComplexity(helper.ComplexityScore());

display_list/benchmarking/dl_complexity_metal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class DisplayListMetalComplexityCalculator
3535
explicit MetalHelper(unsigned int ceiling)
3636
: ComplexityCalculatorHelper(ceiling) {}
3737

38-
void saveLayer(const SkRect* bounds,
38+
void saveLayer(const SkRect& bounds,
3939
const SaveLayerOptions options,
4040
const DlImageFilter* backdrop) override;
4141

display_list/display_list.h

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ namespace flutter {
8888
\
8989
V(Save) \
9090
V(SaveLayer) \
91-
V(SaveLayerBounds) \
9291
V(SaveLayerBackdrop) \
93-
V(SaveLayerBackdropBounds) \
9492
V(Restore) \
9593
\
9694
V(Translate) \
@@ -165,6 +163,7 @@ class SaveLayerOptions {
165163
SaveLayerOptions without_optimizations() const {
166164
SaveLayerOptions options;
167165
options.fRendersWithAttributes = fRendersWithAttributes;
166+
options.fBoundsFromCaller = fBoundsFromCaller;
168167
return options;
169168
}
170169

@@ -182,6 +181,33 @@ class SaveLayerOptions {
182181
return options;
183182
}
184183

184+
// Returns true iff the bounds for the saveLayer operation were provided
185+
// by the caller, otherwise the bounds will have been computed by the
186+
// DisplayListBuilder and provided for reference.
187+
bool bounds_from_caller() const { return fBoundsFromCaller; }
188+
SaveLayerOptions with_bounds_from_caller() const {
189+
SaveLayerOptions options(this);
190+
options.fBoundsFromCaller = true;
191+
return options;
192+
}
193+
SaveLayerOptions without_bounds_from_caller() const {
194+
SaveLayerOptions options(this);
195+
options.fBoundsFromCaller = false;
196+
return options;
197+
}
198+
bool bounds_were_calculated() const { return !fBoundsFromCaller; }
199+
200+
// Returns true iff the bounds for the saveLayer do not fully cover the
201+
// contained rendering operations. This will only occur if the original
202+
// caller supplied bounds and those bounds were not a strict superset
203+
// of the content bounds computed by the DisplayListBuilder.
204+
bool content_is_clipped() const { return fContentIsClipped; }
205+
SaveLayerOptions with_content_is_clipped() const {
206+
SaveLayerOptions options(this);
207+
options.fContentIsClipped = true;
208+
return options;
209+
}
210+
185211
SaveLayerOptions& operator=(const SaveLayerOptions& other) {
186212
flags_ = other.flags_;
187213
return *this;
@@ -198,6 +224,8 @@ class SaveLayerOptions {
198224
struct {
199225
unsigned fRendersWithAttributes : 1;
200226
unsigned fCanDistributeOpacity : 1;
227+
unsigned fBoundsFromCaller : 1;
228+
unsigned fContentIsClipped : 1;
201229
};
202230
uint32_t flags_;
203231
};

0 commit comments

Comments
 (0)