Skip to content

Commit

Permalink
Improve DisplayList bounds calculations (flutter#28656)
Browse files Browse the repository at this point in the history
  • Loading branch information
flar authored Sep 17, 2021
1 parent 969f68d commit e1e6a41
Show file tree
Hide file tree
Showing 8 changed files with 1,546 additions and 461 deletions.
46 changes: 23 additions & 23 deletions flow/display_list.cc
Original file line number Diff line number Diff line change
Expand Up @@ -797,33 +797,33 @@ struct DrawTextBlobOp final : DLOp {
};

// 4 byte header + 28 byte payload packs evenly into 32 bytes
#define DEFINE_DRAW_SHADOW_OP(name, occludes) \
struct Draw##name##Op final : DLOp { \
static const auto kType = DisplayListOpType::kDraw##name; \
\
Draw##name##Op(const SkPath& path, \
SkColor color, \
SkScalar elevation, \
SkScalar dpr) \
: color(color), elevation(elevation), dpr(dpr), path(path) {} \
\
const SkColor color; \
const SkScalar elevation; \
const SkScalar dpr; \
const SkPath path; \
\
void dispatch(Dispatcher& dispatcher) const { \
dispatcher.drawShadow(path, color, elevation, occludes, dpr); \
} \
#define DEFINE_DRAW_SHADOW_OP(name, nonoccluding) \
struct Draw##name##Op final : DLOp { \
static const auto kType = DisplayListOpType::kDraw##name; \
\
Draw##name##Op(const SkPath& path, \
SkColor color, \
SkScalar elevation, \
SkScalar dpr) \
: color(color), elevation(elevation), dpr(dpr), path(path) {} \
\
const SkColor color; \
const SkScalar elevation; \
const SkScalar dpr; \
const SkPath path; \
\
void dispatch(Dispatcher& dispatcher) const { \
dispatcher.drawShadow(path, color, elevation, nonoccluding, dpr); \
} \
};
DEFINE_DRAW_SHADOW_OP(Shadow, false)
DEFINE_DRAW_SHADOW_OP(ShadowOccludes, true)
DEFINE_DRAW_SHADOW_OP(NonOccludingShadow, true)
#undef DEFINE_DRAW_SHADOW_OP

#pragma pack(pop, DLOp_Alignment)

void DisplayList::ComputeBounds() {
DisplayListBoundsCalculator calculator(bounds_cull_);
DisplayListBoundsCalculator calculator(&bounds_cull_);
Dispatch(calculator);
bounds_ = calculator.getBounds();
}
Expand Down Expand Up @@ -1365,10 +1365,10 @@ void DisplayListBuilder::drawTextBlob(const sk_sp<SkTextBlob> blob,
void DisplayListBuilder::drawShadow(const SkPath& path,
const SkColor color,
const SkScalar elevation,
bool occludes,
bool transparentOccluder,
SkScalar dpr) {
occludes //
? Push<DrawShadowOccludesOp>(0, 1, path, color, elevation, dpr)
transparentOccluder //
? Push<DrawNonOccludingShadowOp>(0, 1, path, color, elevation, dpr)
: Push<DrawShadowOp>(0, 1, path, color, elevation, dpr);
}

Expand Down
10 changes: 5 additions & 5 deletions flow/display_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace flutter {
V(DrawTextBlob) \
\
V(DrawShadow) \
V(DrawShadowOccludes)
V(DrawNonOccludingShadow)

#define DL_OP_TO_ENUM_VALUE(name) k##name,
enum class DisplayListOpType { FOR_EACH_DISPLAY_LIST_OP(DL_OP_TO_ENUM_VALUE) };
Expand Down Expand Up @@ -245,8 +245,8 @@ class Dispatcher {
virtual void setMaskBlurFilter(SkBlurStyle style, SkScalar sigma) = 0;

virtual void save() = 0;
virtual void restore() = 0;
virtual void saveLayer(const SkRect* bounds, bool restoreWithPaint) = 0;
virtual void restore() = 0;

virtual void translate(SkScalar tx, SkScalar ty) = 0;
virtual void scale(SkScalar sx, SkScalar sy) = 0;
Expand Down Expand Up @@ -325,7 +325,7 @@ class Dispatcher {
virtual void drawShadow(const SkPath& path,
const SkColor color,
const SkScalar elevation,
bool occludes,
bool transparentOccluder,
SkScalar dpr) = 0;
};

Expand Down Expand Up @@ -358,8 +358,8 @@ class DisplayListBuilder final : public virtual Dispatcher, public SkRefCnt {
void setMaskBlurFilter(SkBlurStyle style, SkScalar sigma) override;

void save() override;
void restore() override;
void saveLayer(const SkRect* bounds, bool restoreWithPaint) override;
void restore() override;

void translate(SkScalar tx, SkScalar ty) override;
void scale(SkScalar sx, SkScalar sy) override;
Expand Down Expand Up @@ -440,7 +440,7 @@ class DisplayListBuilder final : public virtual Dispatcher, public SkRefCnt {
void drawShadow(const SkPath& path,
const SkColor color,
const SkScalar elevation,
bool occludes,
bool transparentOccluder,
SkScalar dpr) override;

sk_sp<DisplayList> Build();
Expand Down
4 changes: 2 additions & 2 deletions flow/display_list_canvas.cc
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,10 @@ void DisplayListCanvasDispatcher::drawTextBlob(const sk_sp<SkTextBlob> blob,
void DisplayListCanvasDispatcher::drawShadow(const SkPath& path,
const SkColor color,
const SkScalar elevation,
bool occludes,
bool transparentOccluder,
SkScalar dpr) {
flutter::PhysicalShapeLayer::DrawShadow(canvas_, path, color, elevation,
occludes, dpr);
transparentOccluder, dpr);
}

DisplayListCanvasRecorder::DisplayListCanvasRecorder(const SkRect& bounds)
Expand Down
2 changes: 1 addition & 1 deletion flow/display_list_canvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ class DisplayListCanvasDispatcher : public virtual Dispatcher,
void drawShadow(const SkPath& path,
const SkColor color,
const SkScalar elevation,
bool occludes,
bool transparentOccluder,
SkScalar dpr) override;

private:
Expand Down
Loading

0 comments on commit e1e6a41

Please sign in to comment.