Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
SkSGDraw.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2017 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
10#include "include/core/SkPath.h"
18
19class SkMatrix;
20
21namespace sksg {
22
24 : fGeometry(std::move(geometry))
25 , fPaint(std::move(paint)) {
26 this->observeInval(fGeometry);
27 this->observeInval(fPaint);
28}
29
31 this->unobserveInval(fGeometry);
32 this->unobserveInval(fPaint);
33}
34
35void Draw::onRender(SkCanvas* canvas, const RenderContext* ctx) const {
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}
48
49const RenderNode* Draw::onNodeAt(const SkPoint& p) const {
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}
67
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}
79
80} // namespace sksg
#define SkASSERT(cond)
Definition SkAssert.h:116
SkMatrix getTotalMatrix() const
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
bool contains(SkScalar x, SkScalar y) const
Definition SkPath.cpp:3054
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
Definition SkSGDraw.cpp:68
~Draw() override
Definition SkSGDraw.cpp:30
void onRender(SkCanvas *, const RenderContext *) const override
Definition SkSGDraw.cpp:35
const RenderNode * onNodeAt(const SkPoint &) const override
Definition SkSGDraw.cpp:49
Draw(sk_sp< GeometryNode >, sk_sp< PaintNode > paint)
Definition SkSGDraw.cpp:23
void observeInval(const sk_sp< Node > &)
Definition SkSGNode.cpp:61
void unobserveInval(const sk_sp< Node > &)
Definition SkSGNode.cpp:84
const SkRect & bounds() const
Definition SkSGNode.h:55
bool hasInval() const
Definition SkSGNode.h:60
const Paint & paint
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)
Definition Skottie.h:32
Definition ref_ptr.h:256
void modulatePaint(const SkMatrix &ctm, SkPaint *, bool is_layer_paint=false) const