Skip to content

Commit

Permalink
DisplayList SaveLayer (and root layer) read-back flags (#53104)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
flar committed May 30, 2024
1 parent 01f2264 commit bf2e32d
Show file tree
Hide file tree
Showing 12 changed files with 503 additions and 120 deletions.
8 changes: 7 additions & 1 deletion display_list/display_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ DisplayList::DisplayList()
bounds_({0, 0, 0, 0}),
can_apply_group_opacity_(true),
is_ui_thread_safe_(true),
modifies_transparent_black_(false) {}
modifies_transparent_black_(false),
root_has_backdrop_filter_(false),
max_root_blend_mode_(DlBlendMode::kClear) {}

DisplayList::DisplayList(DisplayListStorage&& storage,
size_t byte_count,
Expand All @@ -36,6 +38,8 @@ DisplayList::DisplayList(DisplayListStorage&& storage,
bool can_apply_group_opacity,
bool is_ui_thread_safe,
bool modifies_transparent_black,
DlBlendMode max_root_blend_mode,
bool root_has_backdrop_filter,
sk_sp<const DlRTree> rtree)
: storage_(std::move(storage)),
byte_count_(byte_count),
Expand All @@ -48,6 +52,8 @@ DisplayList::DisplayList(DisplayListStorage&& storage,
can_apply_group_opacity_(can_apply_group_opacity),
is_ui_thread_safe_(is_ui_thread_safe),
modifies_transparent_black_(modifies_transparent_black),
root_has_backdrop_filter_(root_has_backdrop_filter),
max_root_blend_mode_(max_root_blend_mode),
rtree_(std::move(rtree)) {}

DisplayList::~DisplayList() {
Expand Down
31 changes: 31 additions & 0 deletions display_list/display_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <memory>
#include <optional>

#include "flutter/display_list/dl_blend_mode.h"
#include "flutter/display_list/dl_sampling_options.h"
#include "flutter/display_list/geometry/dl_rtree.h"
#include "flutter/fml/logging.h"
Expand Down Expand Up @@ -208,6 +209,13 @@ class SaveLayerOptions {
return options;
}

bool contains_backdrop_filter() const { return fHasBackdropFilter; }
SaveLayerOptions with_contains_backdrop_filter() const {
SaveLayerOptions options(this);
options.fHasBackdropFilter = true;
return options;
}

SaveLayerOptions& operator=(const SaveLayerOptions& other) {
flags_ = other.flags_;
return *this;
Expand All @@ -226,6 +234,7 @@ class SaveLayerOptions {
unsigned fCanDistributeOpacity : 1;
unsigned fBoundsFromCaller : 1;
unsigned fContentIsClipped : 1;
unsigned fHasBackdropFilter : 1;
};
uint32_t flags_;
};
Expand Down Expand Up @@ -313,6 +322,24 @@ class DisplayList : public SkRefCnt {

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

/// @brief Indicates if there are any saveLayer operations at the root
/// surface level of the DisplayList that use a backdrop filter.
///
/// This condition can be used to determine what kind of surface to create
/// for the root layer into which to render the DisplayList as some GPUs
/// can support surfaces that do or do not support the readback that would
/// be required for the backdrop filter to do its work.
bool root_has_backdrop_filter() const { return root_has_backdrop_filter_; }

/// @brief Indicates the maximum DlBlendMode used on any rendering op
/// in the root surface of the DisplayList.
///
/// This condition can be used to determine what kind of surface to create
/// for the root layer into which to render the DisplayList as some GPUs
/// can support surfaces that do or do not support the readback that would
/// be required for the indicated blend mode to do its work.
DlBlendMode max_root_blend_mode() const { return max_root_blend_mode_; }

private:
DisplayList(DisplayListStorage&& ptr,
size_t byte_count,
Expand All @@ -324,6 +351,8 @@ class DisplayList : public SkRefCnt {
bool can_apply_group_opacity,
bool is_ui_thread_safe,
bool modifies_transparent_black,
DlBlendMode max_root_blend_mode,
bool root_has_backdrop_filter,
sk_sp<const DlRTree> rtree);

static uint32_t next_unique_id();
Expand All @@ -345,6 +374,8 @@ class DisplayList : public SkRefCnt {
const bool can_apply_group_opacity_;
const bool is_ui_thread_safe_;
const bool modifies_transparent_black_;
const bool root_has_backdrop_filter_;
const DlBlendMode max_root_blend_mode_;

const sk_sp<const DlRTree> rtree_;

Expand Down
Loading

0 comments on commit bf2e32d

Please sign in to comment.