Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
SkDashPathEffect.cpp File Reference
#include "include/effects/SkDashPathEffect.h"
#include "include/core/SkFlattenable.h"
#include "include/core/SkMatrix.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPathEffect.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRect.h"
#include "include/core/SkStrokeRec.h"
#include "include/private/base/SkAlign.h"
#include "include/private/base/SkFloatingPoint.h"
#include "include/private/base/SkMalloc.h"
#include "include/private/base/SkTemplates.h"
#include "include/private/base/SkTo.h"
#include "src/core/SkReadBuffer.h"
#include "src/core/SkWriteBuffer.h"
#include "src/effects/SkDashImpl.h"
#include "src/utils/SkDashPathPriv.h"
#include <algorithm>
#include <cstdint>
#include <cstring>

Go to the source code of this file.

Functions

static void outset_for_stroke (SkRect *rect, const SkStrokeRec &rec)
 
static bool cull_line (SkPoint *pts, const SkStrokeRec &rec, const SkMatrix &ctm, const SkRect *cullRect, const SkScalar intervalLength)
 

Function Documentation

◆ cull_line()

static bool cull_line ( SkPoint pts,
const SkStrokeRec rec,
const SkMatrix ctm,
const SkRect cullRect,
const SkScalar  intervalLength 
)
static

Definition at line 78 of file SkDashPathEffect.cpp.

80 {
81 if (nullptr == cullRect) {
82 SkASSERT(false); // Shouldn't ever occur in practice
83 return false;
84 }
85
86 SkScalar dx = pts[1].x() - pts[0].x();
87 SkScalar dy = pts[1].y() - pts[0].y();
88
89 if ((dx && dy) || (!dx && !dy)) {
90 return false;
91 }
92
93 SkRect bounds = *cullRect;
94 outset_for_stroke(&bounds, rec);
95
96 // cullRect is in device space while pts are in the local coordinate system
97 // defined by the ctm. We want our answer in the local coordinate system.
98
101 if (!ctm.invert(&inv)) {
102 return false;
103 }
104
105 inv.mapRect(&bounds);
106
107 if (dx) {
108 SkASSERT(dx && !dy);
109 SkScalar minX = pts[0].fX;
110 SkScalar maxX = pts[1].fX;
111
112 if (dx < 0) {
113 using std::swap;
114 swap(minX, maxX);
115 }
116
117 SkASSERT(minX < maxX);
118 if (maxX <= bounds.fLeft || minX >= bounds.fRight) {
119 return false;
120 }
121
122 // Now we actually perform the chop, removing the excess to the left and
123 // right of the bounds (keeping our new line "in phase" with the dash,
124 // hence the (mod intervalLength).
125
126 if (minX < bounds.fLeft) {
127 minX = bounds.fLeft - SkScalarMod(bounds.fLeft - minX, intervalLength);
128 }
129 if (maxX > bounds.fRight) {
130 maxX = bounds.fRight + SkScalarMod(maxX - bounds.fRight, intervalLength);
131 }
132
133 SkASSERT(maxX > minX);
134 if (dx < 0) {
135 using std::swap;
136 swap(minX, maxX);
137 }
138 pts[0].fX = minX;
139 pts[1].fX = maxX;
140 } else {
141 SkASSERT(dy && !dx);
142 SkScalar minY = pts[0].fY;
143 SkScalar maxY = pts[1].fY;
144
145 if (dy < 0) {
146 using std::swap;
147 swap(minY, maxY);
148 }
149
150 SkASSERT(minY < maxY);
151 if (maxY <= bounds.fTop || minY >= bounds.fBottom) {
152 return false;
153 }
154
155 // Now we actually perform the chop, removing the excess to the top and
156 // bottom of the bounds (keeping our new line "in phase" with the dash,
157 // hence the (mod intervalLength).
158
159 if (minY < bounds.fTop) {
160 minY = bounds.fTop - SkScalarMod(bounds.fTop - minY, intervalLength);
161 }
162 if (maxY > bounds.fBottom) {
163 maxY = bounds.fBottom + SkScalarMod(maxY - bounds.fBottom, intervalLength);
164 }
165
166 SkASSERT(maxY > minY);
167 if (dy < 0) {
168 using std::swap;
169 swap(minY, maxY);
170 }
171 pts[0].fY = minY;
172 pts[1].fY = maxY;
173 }
174
175 return true;
176}
static SkM44 inv(const SkM44 &m)
Definition 3d.cpp:26
#define SkASSERT(cond)
Definition SkAssert.h:116
static void outset_for_stroke(SkRect *rect, const SkStrokeRec &rec)
#define SkScalarMod(x, y)
Definition SkScalar.h:41
bool invert(SkMatrix *inverse) const
Definition SkMatrix.h:1206
bool rectStaysRect() const
Definition SkMatrix.h:271
float SkScalar
Definition extension.cpp:12
Optional< SkRect > bounds
Definition SkRecords.h:189
skia_private::AutoTArray< sk_sp< SkImageFilter > > filters TypedMatrix matrix TypedMatrix matrix SkScalar dx
Definition SkRecords.h:208
static void swap(TArray< T, M > &a, TArray< T, M > &b)
Definition SkTArray.h:737
float fX
x-axis value
float fY
y-axis value
constexpr float y() const
constexpr float x() const

◆ outset_for_stroke()

static void outset_for_stroke ( SkRect rect,
const SkStrokeRec rec 
)
static

Definition at line 64 of file SkDashPathEffect.cpp.

64 {
65 SkScalar radius = SkScalarHalf(rec.getWidth());
66 if (0 == radius) {
67 radius = SK_Scalar1; // hairlines
68 }
69 if (SkPaint::kMiter_Join == rec.getJoin()) {
70 radius *= rec.getMiter();
71 }
72 rect->outset(radius, radius);
73}
#define SK_Scalar1
Definition SkScalar.h:18
#define SkScalarHalf(a)
Definition SkScalar.h:75
@ kMiter_Join
extends to miter limit
Definition SkPaint.h:359
SkScalar getWidth() const
Definition SkStrokeRec.h:42
SkPaint::Join getJoin() const
Definition SkStrokeRec.h:45
SkScalar getMiter() const
Definition SkStrokeRec.h:43
sk_sp< SkBlender > blender SkRect rect
Definition SkRecords.h:350