Skip to content

Commit bf2e32d

Browse files
authored
DisplayList SaveLayer (and root layer) read-back flags (flutter#53104)
The DisplayListBuilder now tracks the blend mode(s) used for its contents and whether it contains a child SaveLayer that uses a backdrop filter - both conditions that could require the graphics engine to use a different type of layer to satisfy the requests. blend modes are tracked as the "highest" blend mode enum used by any content (defaults to kClear) as the enum values tend to be ordered so that larger values will tend to require more complicated render-target accesses. The root layer of the DisplayList can be queried for both conditions on the root layer using methods on the DisplayList class.
1 parent 01f2264 commit bf2e32d

12 files changed

Lines changed: 503 additions & 120 deletions

display_list/display_list.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ DisplayList::DisplayList()
2424
bounds_({0, 0, 0, 0}),
2525
can_apply_group_opacity_(true),
2626
is_ui_thread_safe_(true),
27-
modifies_transparent_black_(false) {}
27+
modifies_transparent_black_(false),
28+
root_has_backdrop_filter_(false),
29+
max_root_blend_mode_(DlBlendMode::kClear) {}
2830

2931
DisplayList::DisplayList(DisplayListStorage&& storage,
3032
size_t byte_count,
@@ -36,6 +38,8 @@ DisplayList::DisplayList(DisplayListStorage&& storage,
3638
bool can_apply_group_opacity,
3739
bool is_ui_thread_safe,
3840
bool modifies_transparent_black,
41+
DlBlendMode max_root_blend_mode,
42+
bool root_has_backdrop_filter,
3943
sk_sp<const DlRTree> rtree)
4044
: storage_(std::move(storage)),
4145
byte_count_(byte_count),
@@ -48,6 +52,8 @@ DisplayList::DisplayList(DisplayListStorage&& storage,
4852
can_apply_group_opacity_(can_apply_group_opacity),
4953
is_ui_thread_safe_(is_ui_thread_safe),
5054
modifies_transparent_black_(modifies_transparent_black),
55+
root_has_backdrop_filter_(root_has_backdrop_filter),
56+
max_root_blend_mode_(max_root_blend_mode),
5157
rtree_(std::move(rtree)) {}
5258

5359
DisplayList::~DisplayList() {

display_list/display_list.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <memory>
99
#include <optional>
1010

11+
#include "flutter/display_list/dl_blend_mode.h"
1112
#include "flutter/display_list/dl_sampling_options.h"
1213
#include "flutter/display_list/geometry/dl_rtree.h"
1314
#include "flutter/fml/logging.h"
@@ -208,6 +209,13 @@ class SaveLayerOptions {
208209
return options;
209210
}
210211

212+
bool contains_backdrop_filter() const { return fHasBackdropFilter; }
213+
SaveLayerOptions with_contains_backdrop_filter() const {
214+
SaveLayerOptions options(this);
215+
options.fHasBackdropFilter = true;
216+
return options;
217+
}
218+
211219
SaveLayerOptions& operator=(const SaveLayerOptions& other) {
212220
flags_ = other.flags_;
213221
return *this;
@@ -226,6 +234,7 @@ class SaveLayerOptions {
226234
unsigned fCanDistributeOpacity : 1;
227235
unsigned fBoundsFromCaller : 1;
228236
unsigned fContentIsClipped : 1;
237+
unsigned fHasBackdropFilter : 1;
229238
};
230239
uint32_t flags_;
231240
};
@@ -313,6 +322,24 @@ class DisplayList : public SkRefCnt {
313322

314323
const DisplayListStorage& GetStorage() const { return storage_; }
315324

325+
/// @brief Indicates if there are any saveLayer operations at the root
326+
/// surface level of the DisplayList that use a backdrop filter.
327+
///
328+
/// This condition can be used to determine what kind of surface to create
329+
/// for the root layer into which to render the DisplayList as some GPUs
330+
/// can support surfaces that do or do not support the readback that would
331+
/// be required for the backdrop filter to do its work.
332+
bool root_has_backdrop_filter() const { return root_has_backdrop_filter_; }
333+
334+
/// @brief Indicates the maximum DlBlendMode used on any rendering op
335+
/// in the root surface of the DisplayList.
336+
///
337+
/// This condition can be used to determine what kind of surface to create
338+
/// for the root layer into which to render the DisplayList as some GPUs
339+
/// can support surfaces that do or do not support the readback that would
340+
/// be required for the indicated blend mode to do its work.
341+
DlBlendMode max_root_blend_mode() const { return max_root_blend_mode_; }
342+
316343
private:
317344
DisplayList(DisplayListStorage&& ptr,
318345
size_t byte_count,
@@ -324,6 +351,8 @@ class DisplayList : public SkRefCnt {
324351
bool can_apply_group_opacity,
325352
bool is_ui_thread_safe,
326353
bool modifies_transparent_black,
354+
DlBlendMode max_root_blend_mode,
355+
bool root_has_backdrop_filter,
327356
sk_sp<const DlRTree> rtree);
328357

329358
static uint32_t next_unique_id();
@@ -345,6 +374,8 @@ class DisplayList : public SkRefCnt {
345374
const bool can_apply_group_opacity_;
346375
const bool is_ui_thread_safe_;
347376
const bool modifies_transparent_black_;
377+
const bool root_has_backdrop_filter_;
378+
const DlBlendMode max_root_blend_mode_;
348379

349380
const sk_sp<const DlRTree> rtree_;
350381

0 commit comments

Comments
 (0)