Flutter Engine
The Flutter Engine
Static Public Member Functions | Protected Member Functions | List of all members
sksg::Draw Class Reference

#include <SkSGDraw.h>

Inheritance diagram for sksg::Draw:
sksg::RenderNode sksg::Node SkRefCnt SkRefCntBase

Static Public Member Functions

static sk_sp< DrawMake (sk_sp< GeometryNode > geo, sk_sp< PaintNode > paint)
 

Protected Member Functions

 Draw (sk_sp< GeometryNode >, sk_sp< PaintNode > paint)
 
 ~Draw () override
 
void onRender (SkCanvas *, const RenderContext *) const override
 
const RenderNodeonNodeAt (const SkPoint &) const override
 
SkRect onRevalidate (InvalidationController *, const SkMatrix &) override
 
- Protected Member Functions inherited from sksg::RenderNode
 RenderNode (uint32_t inval_traits=0)
 
virtual void onRender (SkCanvas *, const RenderContext *) const =0
 
virtual const RenderNodeonNodeAt (const SkPoint &p) const =0
 
- Protected Member Functions inherited from sksg::Node
 Node (uint32_t invalTraits)
 
 ~Node () override
 
const SkRectbounds () const
 
bool hasInval () const
 
virtual SkRect onRevalidate (InvalidationController *, const SkMatrix &ctm)=0
 
void observeInval (const sk_sp< Node > &)
 
void unobserveInval (const sk_sp< Node > &)
 

Additional Inherited Members

- Public Member Functions inherited from sksg::RenderNode
void render (SkCanvas *, const RenderContext *=nullptr) const
 
const RenderNodenodeAt (const SkPoint &point) const
 
bool isVisible () const
 
void setVisible (bool)
 
- Public Member Functions inherited from sksg::Node
const SkRectrevalidate (InvalidationController *, const SkMatrix &)
 
void invalidate (bool damage=true)
 
- Public Member Functions inherited from SkRefCntBase
 SkRefCntBase ()
 
virtual ~SkRefCntBase ()
 
bool unique () const
 
void ref () const
 
void unref () const
 
- Protected Types inherited from sksg::Node
enum  InvalTraits { kBubbleDamage_Trait = 1 << 0 , kOverrideDamage_Trait = 1 << 1 }
 

Detailed Description

Concrete rendering node.

Wraps and draws a [geometry, paint] tuple.

Think Skia SkCanvas::drawFoo(foo, paint) calls.

Definition at line 33 of file SkSGDraw.h.

Constructor & Destructor Documentation

◆ Draw()

sksg::Draw::Draw ( sk_sp< GeometryNode geometry,
sk_sp< PaintNode paint 
)
protected

Definition at line 23 of file SkSGDraw.cpp.

24 : fGeometry(std::move(geometry))
25 , fPaint(std::move(paint)) {
26 this->observeInval(fGeometry);
27 this->observeInval(fPaint);
28}
void observeInval(const sk_sp< Node > &)
Definition: SkSGNode.cpp:61
const Paint & paint
Definition: color_source.cc:38

◆ ~Draw()

sksg::Draw::~Draw ( )
overrideprotected

Definition at line 30 of file SkSGDraw.cpp.

30 {
31 this->unobserveInval(fGeometry);
32 this->unobserveInval(fPaint);
33}
void unobserveInval(const sk_sp< Node > &)
Definition: SkSGNode.cpp:84

Member Function Documentation

◆ Make()

static sk_sp< Draw > sksg::Draw::Make ( sk_sp< GeometryNode geo,
sk_sp< PaintNode paint 
)
inlinestatic

Definition at line 35 of file SkSGDraw.h.

35 {
36 return (geo && paint) ? sk_sp<Draw>(new Draw(std::move(geo), std::move(paint))) : nullptr;
37 }
Draw(sk_sp< GeometryNode >, sk_sp< PaintNode > paint)
Definition: SkSGDraw.cpp:23

◆ onNodeAt()

const RenderNode * sksg::Draw::onNodeAt ( const SkPoint p) const
overrideprotectedvirtual

Implements sksg::RenderNode.

Definition at line 49 of file SkSGDraw.cpp.

49 {
50 const auto paint = fPaint->makePaint();
51
52 if (!paint.getAlpha()) {
53 return nullptr;
54 }
55
56 if (paint.getStyle() == SkPaint::Style::kFill_Style && fGeometry->contains(p)) {
57 return this;
58 }
59
60 SkPath stroke_path;
61 if (!skpathutils::FillPathWithPaint(fGeometry->asPath(), paint, &stroke_path)) {
62 return nullptr;
63 }
64
65 return stroke_path.contains(p.x(), p.y()) ? this : nullptr;
66}
Definition: SkPath.h:59
bool contains(SkScalar x, SkScalar y) const
Definition: SkPath.cpp:3118
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)
Definition: SkPathUtils.cpp:23

◆ onRender()

void sksg::Draw::onRender ( SkCanvas canvas,
const RenderContext ctx 
) const
overrideprotectedvirtual

Implements sksg::RenderNode.

Definition at line 35 of file SkSGDraw.cpp.

35 {
36 auto paint = fPaint->makePaint();
37 if (ctx) {
38 ctx->modulatePaint(canvas->getTotalMatrix(), &paint);
39 }
40
41 const auto skipDraw = paint.nothingToDraw() ||
42 (paint.getStyle() == SkPaint::kStroke_Style && paint.getStrokeWidth() <= 0);
43
44 if (!skipDraw) {
45 fGeometry->draw(canvas, paint);
46 }
47}
SkMatrix getTotalMatrix() const
Definition: SkCanvas.cpp:1629
@ kStroke_Style
set to stroke geometry
Definition: SkPaint.h:194

◆ onRevalidate()

SkRect sksg::Draw::onRevalidate ( InvalidationController ic,
const SkMatrix ctm 
)
overrideprotectedvirtual

Implements sksg::Node.

Definition at line 68 of file SkSGDraw.cpp.

68 {
69 SkASSERT(this->hasInval());
70
71 auto bounds = fGeometry->revalidate(ic, ctm);
72 fPaint->revalidate(ic, ctm);
73
74 const auto paint = fPaint->makePaint();
75 SkASSERT(paint.canComputeFastBounds());
76
77 return paint.computeFastBounds(bounds, &bounds);
78}
#define SkASSERT(cond)
Definition: SkAssert.h:116
const SkRect & bounds() const
Definition: SkSGNode.h:55
bool hasInval() const
Definition: SkSGNode.h:60

The documentation for this class was generated from the following files: