Flutter Engine
The Flutter Engine
third_party
skia
modules
sksg
src
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
8
#include "
include/core/SkCanvas.h
"
9
#include "
include/core/SkPaint.h
"
10
#include "
include/core/SkPath.h
"
11
#include "
include/core/SkPathUtils.h
"
12
#include "
include/core/SkPoint.h
"
13
#include "
include/private/base/SkAssert.h
"
14
#include "
modules/sksg/include/SkSGDraw.h
"
15
#include "
modules/sksg/include/SkSGGeometryNode.h
"
16
#include "
modules/sksg/include/SkSGNode.h
"
17
#include "
modules/sksg/include/SkSGPaint.h
"
18
19
class
SkMatrix
;
20
21
namespace
sksg
{
22
23
Draw::Draw
(
sk_sp<GeometryNode>
geometry,
sk_sp<PaintNode>
paint
)
24
: fGeometry(
std
::move(geometry))
25
, fPaint(
std
::move(
paint
)) {
26
this->
observeInval
(fGeometry);
27
this->
observeInval
(fPaint);
28
}
29
30
Draw::~Draw
() {
31
this->
unobserveInval
(fGeometry);
32
this->
unobserveInval
(fPaint);
33
}
34
35
void
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
49
const
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
68
SkRect
Draw::onRevalidate
(
InvalidationController
* ic,
const
SkMatrix
& ctm) {
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
SkAssert.h
SkASSERT
#define SkASSERT(cond)
Definition:
SkAssert.h:116
SkCanvas.h
SkPaint.h
SkPathUtils.h
SkPath.h
SkPoint.h
SkSGDraw.h
SkSGGeometryNode.h
SkSGNode.h
SkSGPaint.h
SkCanvas
Definition:
SkCanvas.h:106
SkCanvas::getTotalMatrix
SkMatrix getTotalMatrix() const
Definition:
SkCanvas.cpp:1629
SkMatrix
Definition:
SkMatrix.h:54
SkPaint::kStroke_Style
@ kStroke_Style
set to stroke geometry
Definition:
SkPaint.h:194
SkPath
Definition:
SkPath.h:59
SkPath::contains
bool contains(SkScalar x, SkScalar y) const
Definition:
SkPath.cpp:3118
sk_sp
Definition:
SkRefCnt.h:220
sksg::Draw::onRevalidate
SkRect onRevalidate(InvalidationController *, const SkMatrix &) override
Definition:
SkSGDraw.cpp:68
sksg::Draw::~Draw
~Draw() override
Definition:
SkSGDraw.cpp:30
sksg::Draw::onRender
void onRender(SkCanvas *, const RenderContext *) const override
Definition:
SkSGDraw.cpp:35
sksg::Draw::onNodeAt
const RenderNode * onNodeAt(const SkPoint &) const override
Definition:
SkSGDraw.cpp:49
sksg::Draw::Draw
Draw(sk_sp< GeometryNode >, sk_sp< PaintNode > paint)
Definition:
SkSGDraw.cpp:23
sksg::InvalidationController
Definition:
SkSGInvalidationController.h:24
sksg::Node::observeInval
void observeInval(const sk_sp< Node > &)
Definition:
SkSGNode.cpp:61
sksg::Node::unobserveInval
void unobserveInval(const sk_sp< Node > &)
Definition:
SkSGNode.cpp:84
sksg::Node::bounds
const SkRect & bounds() const
Definition:
SkSGNode.h:55
sksg::Node::hasInval
bool hasInval() const
Definition:
SkSGNode.h:60
sksg::RenderNode
Definition:
SkSGRenderNode.h:34
paint
const Paint & paint
Definition:
color_source.cc:38
dart_profiler_symbols.p
p
Definition:
dart_profiler_symbols.py:55
skpathutils::FillPathWithPaint
SK_API bool FillPathWithPaint(const SkPath &src, const SkPaint &paint, SkPath *dst, const SkRect *cullRect, SkScalar resScale=1)
Definition:
SkPathUtils.cpp:23
sksg
Definition:
Skottie.h:32
std
Definition:
ref_ptr.h:256
SkPoint
Definition:
SkPoint_impl.h:163
SkRect
Definition:
extension.cpp:13
sksg::RenderNode::RenderContext
Definition:
SkSGRenderNode.h:60
sksg::RenderNode::RenderContext::modulatePaint
void modulatePaint(const SkMatrix &ctm, SkPaint *, bool is_layer_paint=false) const
Definition:
SkSGRenderNode.cpp:102
Generated on Sun Jun 23 2024 21:56:07 for Flutter Engine by
1.9.4