Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions display_list/geometry/dl_geometry_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ static_assert(sizeof(SkIRect) == sizeof(DlIRect));
static_assert(sizeof(SkVector) == sizeof(DlSize));

static constexpr DlScalar kEhCloseEnough = impeller::kEhCloseEnough;
static constexpr DlScalar kPi = impeller::kPi;

constexpr inline bool DlScalarNearlyZero(DlScalar x,
DlScalar tolerance = kEhCloseEnough) {
Expand Down Expand Up @@ -142,6 +143,11 @@ inline const SkIRect& ToSkIRect(const DlIRect& rect) {
return *reinterpret_cast<const SkIRect*>(&rect);
}

inline std::optional<const SkIRect> ToOptSkIRect(
std::optional<const DlIRect> rect) {
return rect.has_value() ? std::optional(ToSkIRect(*rect)) : std::nullopt;
}

inline const SkRect* ToSkRect(const DlRect* rect) {
return rect == nullptr ? nullptr : reinterpret_cast<const SkRect*>(rect);
}
Expand All @@ -158,6 +164,10 @@ inline const SkRect* ToSkRects(const DlRect* rects) {
return rects == nullptr ? nullptr : reinterpret_cast<const SkRect*>(rects);
}

inline const SkSize& ToSkSize(const DlSize& size) {
return *reinterpret_cast<const SkSize*>(&size);
}

inline const SkISize& ToSkISize(const DlISize& size) {
return *reinterpret_cast<const SkISize*>(&size);
}
Expand Down
35 changes: 35 additions & 0 deletions display_list/geometry/dl_path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,35 @@

namespace flutter {

DlPath DlPath::MakeRect(DlRect rect) {
return DlPath(SkPath::Rect(ToSkRect(rect)));
}

DlPath DlPath::MakeRectLTRB(DlScalar left,
DlScalar top,
DlScalar right,
DlScalar bottom) {
return DlPath(SkPath().addRect(left, top, right, bottom));
}

DlPath DlPath::MakeRectXYWH(DlScalar x,
DlScalar y,
DlScalar width,
DlScalar height) {
return DlPath(SkPath().addRect(SkRect::MakeXYWH(x, y, width, height)));
}

DlPath DlPath::MakeOval(DlRect bounds) {
return DlPath(SkPath::Oval(ToSkRect(bounds)));
}

DlPath DlPath::MakeOvalLTRB(DlScalar left,
DlScalar top,
DlScalar right,
DlScalar bottom) {
return DlPath(SkPath::Oval(SkRect::MakeLTRB(left, top, right, bottom)));
}

const SkPath& DlPath::GetSkPath() const {
return data_->sk_path;
}
Expand Down Expand Up @@ -76,6 +105,12 @@ bool DlPath::IsVolatile() const {
return data_->sk_path.isVolatile();
}

DlPath DlPath::operator+(const DlPath& other) const {
SkPath path = data_->sk_path;
path.addPath(other.data_->sk_path);
return DlPath(path);
}

using Path = impeller::Path;
using PathBuilder = impeller::PathBuilder;
using FillType = impeller::FillType;
Expand Down
18 changes: 18 additions & 0 deletions display_list/geometry/dl_path.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,22 @@ class DlPath {
public:
static constexpr uint32_t kMaxVolatileUses = 2;

static DlPath MakeRect(DlRect rect);
static DlPath MakeRectLTRB(DlScalar left,
DlScalar top,
DlScalar right,
DlScalar bottom);
static DlPath MakeRectXYWH(DlScalar x,
DlScalar y,
DlScalar width,
DlScalar height);

static DlPath MakeOval(DlRect bounds);
static DlPath MakeOvalLTRB(DlScalar left,
DlScalar top,
DlScalar right,
DlScalar bottom);

DlPath() : data_(std::make_shared<Data>(SkPath())) {}
explicit DlPath(const SkPath& path) : data_(std::make_shared<Data>(path)) {}

Expand Down Expand Up @@ -50,6 +66,8 @@ class DlPath {
bool IsConverted() const;
bool IsVolatile() const;

DlPath operator+(const DlPath& other) const;

private:
struct Data {
explicit Data(const SkPath& path) : sk_path(path) {}
Expand Down
32 changes: 15 additions & 17 deletions flow/compositor_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace flutter {

std::optional<SkRect> FrameDamage::ComputeClipRect(
std::optional<DlRect> FrameDamage::ComputeClipRect(
flutter::LayerTree& layer_tree,
bool has_raster_cache,
bool impeller_enabled) {
Expand All @@ -21,17 +21,15 @@ std::optional<SkRect> FrameDamage::ComputeClipRect(
prev_layer_tree_ ? prev_layer_tree_->paint_region_map()
: empty_paint_region_map,
has_raster_cache, impeller_enabled);
context.PushCullRect(SkRect::MakeIWH(layer_tree.frame_size().width(),
layer_tree.frame_size().height()));
context.PushCullRect(DlRect::MakeSize(layer_tree.frame_size()));
{
DiffContext::AutoSubtreeRestore subtree(&context);
const Layer* prev_root_layer = nullptr;
if (!prev_layer_tree_ ||
prev_layer_tree_->frame_size() != layer_tree.frame_size()) {
// If there is no previous layer tree assume the entire frame must be
// repainted.
context.MarkSubtreeDirty(SkRect::MakeIWH(
layer_tree.frame_size().width(), layer_tree.frame_size().height()));
context.MarkSubtreeDirty(DlRect::MakeSize(layer_tree.frame_size()));
} else {
prev_root_layer = prev_layer_tree_->root_layer();
}
Expand All @@ -41,7 +39,7 @@ std::optional<SkRect> FrameDamage::ComputeClipRect(
damage_ =
context.ComputeDamage(additional_damage_, horizontal_clip_alignment_,
vertical_clip_alignment_);
return SkRect::Make(damage_->buffer_damage);
return DlRect::Make(damage_->buffer_damage);
}
return std::nullopt;
}
Expand Down Expand Up @@ -120,7 +118,7 @@ RasterStatus CompositorContext::ScopedFrame::Raster(
FrameDamage* frame_damage) {
TRACE_EVENT0("flutter", "CompositorContext::ScopedFrame::Raster");

std::optional<SkRect> clip_rect;
std::optional<DlRect> clip_rect;
if (frame_damage) {
clip_rect = frame_damage->ComputeClipRect(layer_tree, !ignore_raster_cache,
!gr_context_);
Expand Down Expand Up @@ -159,7 +157,7 @@ RasterStatus CompositorContext::ScopedFrame::Raster(

void CompositorContext::ScopedFrame::PaintLayerTreeSkia(
flutter::LayerTree& layer_tree,
std::optional<SkRect> clip_rect,
std::optional<DlRect> clip_rect,
bool needs_save_layer,
bool ignore_raster_cache) {
DlAutoCanvasRestore restore(canvas(), clip_rect.has_value());
Expand All @@ -171,7 +169,7 @@ void CompositorContext::ScopedFrame::PaintLayerTreeSkia(

if (needs_save_layer) {
TRACE_EVENT0("flutter", "Canvas::saveLayer");
SkRect bounds = SkRect::Make(layer_tree.frame_size());
SkRect bounds = SkRect::Make(ToSkISize(layer_tree.frame_size()));
DlPaint paint;
paint.setBlendMode(DlBlendMode::kSrc);
canvas()->SaveLayer(&bounds, &paint);
Expand All @@ -185,10 +183,10 @@ void CompositorContext::ScopedFrame::PaintLayerTreeSkia(

void CompositorContext::ScopedFrame::PaintLayerTreeImpeller(
flutter::LayerTree& layer_tree,
std::optional<SkRect> clip_rect,
std::optional<DlRect> clip_rect,
bool ignore_raster_cache) {
if (canvas() && clip_rect) {
canvas()->Translate(-clip_rect->x(), -clip_rect->y());
canvas()->Translate(-clip_rect->GetX(), -clip_rect->GetY());
}

layer_tree.Paint(*this, ignore_raster_cache);
Expand All @@ -208,17 +206,17 @@ void CompositorContext::ScopedFrame::PaintLayerTreeImpeller(
constexpr float kImpellerRepaintRatio = 0.7f;

bool CompositorContext::ShouldPerformPartialRepaint(
std::optional<SkRect> damage_rect,
SkISize layer_tree_size) {
std::optional<DlRect> damage_rect,
DlISize layer_tree_size) {
if (!damage_rect.has_value()) {
return false;
}
if (damage_rect->width() >= layer_tree_size.width() &&
damage_rect->height() >= layer_tree_size.height()) {
if (damage_rect->GetWidth() >= layer_tree_size.width &&
damage_rect->GetHeight() >= layer_tree_size.height) {
return false;
}
auto rx = damage_rect->width() / layer_tree_size.width();
auto ry = damage_rect->height() / layer_tree_size.height();
auto rx = damage_rect->GetWidth() / layer_tree_size.width;
auto ry = damage_rect->GetHeight() / layer_tree_size.height;
return rx <= kImpellerRepaintRatio || ry <= kImpellerRepaintRatio;
}

Expand Down
22 changes: 11 additions & 11 deletions flow/compositor_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ class FrameDamage {

// Adds additional damage (accumulated for double / triple buffering).
// This is area that will be repainted alongside any changed part.
void AddAdditionalDamage(const SkIRect& damage) {
additional_damage_.join(damage);
void AddAdditionalDamage(const DlIRect& damage) {
additional_damage_ = additional_damage_.Union(damage);
}

// Specifies clip rect alignment.
Expand All @@ -72,17 +72,17 @@ class FrameDamage {
// If previous layer tree is not specified, clip rect will be nullopt,
// but the paint region of layer_tree will be calculated so that it can be
// used for diffing of subsequent frames.
std::optional<SkRect> ComputeClipRect(flutter::LayerTree& layer_tree,
std::optional<DlRect> ComputeClipRect(flutter::LayerTree& layer_tree,
bool has_raster_cache,
bool impeller_enabled);

// See Damage::frame_damage.
std::optional<SkIRect> GetFrameDamage() const {
std::optional<DlIRect> GetFrameDamage() const {
return damage_ ? std::make_optional(damage_->frame_damage) : std::nullopt;
}

// See Damage::buffer_damage.
std::optional<SkIRect> GetBufferDamage() {
std::optional<DlIRect> GetBufferDamage() {
return (damage_ && !ignore_damage_)
? std::make_optional(damage_->buffer_damage)
: std::nullopt;
Expand All @@ -95,7 +95,7 @@ class FrameDamage {
void Reset() { ignore_damage_ = true; }

private:
SkIRect additional_damage_ = SkIRect::MakeEmpty();
DlIRect additional_damage_;
std::optional<Damage> damage_;
const LayerTree* prev_layer_tree_ = nullptr;
int vertical_clip_alignment_ = 1;
Expand Down Expand Up @@ -141,20 +141,20 @@ class CompositorContext {

private:
void PaintLayerTreeSkia(flutter::LayerTree& layer_tree,
std::optional<SkRect> clip_rect,
std::optional<DlRect> clip_rect,
bool needs_save_layer,
bool ignore_raster_cache);

void PaintLayerTreeImpeller(flutter::LayerTree& layer_tree,
std::optional<SkRect> clip_rect,
std::optional<DlRect> clip_rect,
bool ignore_raster_cache);

CompositorContext& context_;
GrDirectContext* gr_context_;
DlCanvas* canvas_;
impeller::AiksContext* aiks_context_;
ExternalViewEmbedder* view_embedder_;
const SkMatrix& root_surface_transformation_;
const SkMatrix root_surface_transformation_;
const bool instrumentation_enabled_;
const bool surface_supports_readback_;
fml::RefPtr<fml::RasterThreadMerger> raster_thread_merger_;
Expand Down Expand Up @@ -210,8 +210,8 @@ class CompositorContext {
/// @brief Whether Impeller shouild attempt a partial repaint.
/// The Impeller backend requires an additional blit pass, which may
/// not be worthwhile if the damage region is large.
static bool ShouldPerformPartialRepaint(std::optional<SkRect> damage_rect,
SkISize layer_tree_size);
static bool ShouldPerformPartialRepaint(std::optional<DlRect> damage_rect,
DlISize layer_tree_size);

FML_DISALLOW_COPY_AND_ASSIGN(CompositorContext);
};
Expand Down
Loading
Loading