Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Typedefs | Functions | Variables
ClipSlide.cpp File Reference
#include "include/core/SkCanvas.h"
#include "include/core/SkColorPriv.h"
#include "include/core/SkFont.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPathBuilder.h"
#include "include/core/SkRRect.h"
#include "include/core/SkShader.h"
#include "src/base/SkRandom.h"
#include "src/core/SkPathPriv.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"
#include "tools/fonts/FontToolUtils.h"
#include "tools/viewer/ClickHandlerSlide.h"
#include "tools/viewer/Slide.h"
#include "src/core/SkEdgeClipper.h"

Go to the source code of this file.

Classes

class  ClipSlide
 
struct  SkHalfPlane
 
class  HalfPlaneSlide
 
class  HalfPlaneSlide2
 
class  CameraSlide
 
class  HalfPlaneSlide3
 
class  HalfPlaneCoonsSlide
 

Typedefs

typedef void(* CanvasProc) (SkCanvas *, bool)
 

Functions

static void show_text (SkCanvas *canvas, bool doAA)
 
static void show_fill (SkCanvas *canvas, bool doAA)
 
static SkScalar randRange (SkRandom &rand, SkScalar min, SkScalar max)
 
static void show_stroke (SkCanvas *canvas, bool doAA, SkScalar strokeWidth, int n)
 
static void show_hair (SkCanvas *canvas, bool doAA)
 
static void show_thick (SkCanvas *canvas, bool doAA)
 
static SkPath clip (const SkPath &path, SkPoint p0, SkPoint p1)
 
static void draw_halfplane (SkCanvas *canvas, SkPoint p0, SkPoint p1, SkColor c)
 
static SkPath make_path ()
 
static void draw_halfplane (SkCanvas *canvas, const SkHalfPlane &p, SkColor c)
 
static void compute_half_planes (const SkMatrix &mx, SkScalar width, SkScalar height, SkHalfPlane planes[4])
 
static SkM44 inv (const SkM44 &m)
 
static SkHalfPlane half_plane_w0 (const SkMatrix &m)
 

Variables

constexpr int W = 150
 
constexpr int H = 200
 

Typedef Documentation

◆ CanvasProc

typedef void(* CanvasProc) (SkCanvas *, bool)

Definition at line 103 of file ClipSlide.cpp.

Function Documentation

◆ clip()

static SkPath clip ( const SkPath path,
SkPoint  p0,
SkPoint  p1 
)
static

Definition at line 216 of file ClipSlide.cpp.

216 {
217 SkMatrix mx, inv;
218 SkVector v = p1 - p0;
219 mx.setAll(v.fX, -v.fY, p0.fX,
220 v.fY, v.fX, p0.fY,
221 0, 0, 1);
223
224 SkPath rotated;
225 path.transform(inv, &rotated);
226
227 SkScalar big = 1e28f;
228 SkRect clip = {-big, 0, big, big };
229
230 struct Rec {
231 SkPathBuilder fResult;
232 SkPoint fPrev = {0, 0};
233 } rec;
234
235 SkEdgeClipper::ClipPath(rotated, clip, false,
236 [](SkEdgeClipper* clipper, bool newCtr, void* ctx) {
237 Rec* rec = (Rec*)ctx;
238
239 bool addLineTo = false;
240 SkPoint pts[4];
241 SkPath::Verb verb;
242 while ((verb = clipper->next(pts)) != SkPath::kDone_Verb) {
243 if (newCtr) {
244 rec->fResult.moveTo(pts[0]);
245 rec->fPrev = pts[0];
246 newCtr = false;
247 }
248
249 if (addLineTo || pts[0] != rec->fPrev) {
250 rec->fResult.lineTo(pts[0]);
251 }
252
253 switch (verb) {
255 rec->fResult.lineTo(pts[1]);
256 rec->fPrev = pts[1];
257 break;
259 rec->fResult.quadTo(pts[1], pts[2]);
260 rec->fPrev = pts[2];
261 break;
263 rec->fResult.cubicTo(pts[1], pts[2], pts[3]);
264 rec->fPrev = pts[3];
265 break;
266 default: break;
267 }
268 addLineTo = true;
269 }
270 }, &rec);
271
272 return rec.fResult.detach().makeTransform(mx);
273}
static SkPath clip(const SkPath &path, SkPoint p0, SkPoint p1)
static SkM44 inv(const SkM44 &m)
#define SkAssertResult(cond)
Definition SkAssert.h:123
static void ClipPath(const SkPath &path, const SkRect &clip, bool canCullToTheRight, void(*consume)(SkEdgeClipper *, bool newCtr, void *ctx), void *ctx)
SkPath::Verb next(SkPoint pts[])
SkMatrix & setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar persp0, SkScalar persp1, SkScalar persp2)
Definition SkMatrix.h:562
bool invert(SkMatrix *inverse) const
Definition SkMatrix.h:1206
@ kDone_Verb
Definition SkPath.h:1464
@ kCubic_Verb
Definition SkPath.h:1462
@ kQuad_Verb
Definition SkPath.h:1460
@ kLine_Verb
Definition SkPath.h:1459
float SkScalar
Definition extension.cpp:12
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
Definition switches.h:57
float fX
x-axis value
float fY
y-axis value

◆ compute_half_planes()

static void compute_half_planes ( const SkMatrix mx,
SkScalar  width,
SkScalar  height,
SkHalfPlane  planes[4] 
)
static

Definition at line 348 of file ClipSlide.cpp.

349 {
350 SkScalar a = mx[0], b = mx[1], c = mx[2],
351 d = mx[3], e = mx[4], f = mx[5],
352 g = mx[6], h = mx[7], i = mx[8];
353
354 planes[0] = { 2*g - 2*a/width, 2*h - 2*b/width, 2*i - 2*c/width };
355 planes[1] = { 2*a/width, 2*b/width, 2*c/width };
356 planes[2] = { 2*g - 2*d/height, 2*h - 2*e/height, 2*i - 2*f/height };
357 planes[3] = { 2*d/height, 2*e/height, 2*f/height };
358}
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
Definition main.cc:19
static bool b
struct MyStruct a[10]
SkScalar h
int32_t height
int32_t width

◆ draw_halfplane() [1/2]

static void draw_halfplane ( SkCanvas canvas,
const SkHalfPlane p,
SkColor  c 
)
static

Definition at line 342 of file ClipSlide.cpp.

342 {
343 SkPoint pts[2];
344 p.twoPts(pts);
345 draw_halfplane(canvas, pts[0], pts[1], c);
346}
static void draw_halfplane(SkCanvas *canvas, SkPoint p0, SkPoint p1, SkColor c)

◆ draw_halfplane() [2/2]

static void draw_halfplane ( SkCanvas canvas,
SkPoint  p0,
SkPoint  p1,
SkColor  c 
)
static

Definition at line 275 of file ClipSlide.cpp.

275 {
276 SkVector v = p1 - p0;
277 p0 = p0 - v * 1000;
278 p1 = p1 + v * 1000;
279
281 paint.setColor(c);
282 canvas->drawLine(p0, p1, paint);
283}
void drawLine(SkScalar x0, SkScalar y0, SkScalar x1, SkScalar y1, const SkPaint &paint)
const Paint & paint

◆ half_plane_w0()

static SkHalfPlane half_plane_w0 ( const SkMatrix m)
static

Definition at line 433 of file ClipSlide.cpp.

433 {
435}
static constexpr int kMPersp1
input y perspective factor
Definition SkMatrix.h:360
static constexpr int kMPersp0
input x perspective factor
Definition SkMatrix.h:359
static constexpr int kMPersp2
perspective bias
Definition SkMatrix.h:361

◆ inv()

static SkM44 inv ( const SkM44 m)
static

Definition at line 427 of file ClipSlide.cpp.

427 {
428 SkM44 inverse;
429 SkAssertResult(m.invert(&inverse));
430 return inverse;
431}
Definition SkM44.h:150

◆ make_path()

static SkPath make_path ( )
static

Definition at line 285 of file ClipSlide.cpp.

285 {
286 SkRandom rand;
287 auto rand_pt = [&rand]() {
288 auto x = rand.nextF();
289 auto y = rand.nextF();
290 return SkPoint{x * 400, y * 400};
291 };
292
294 for (int i = 0; i < 4; ++i) {
295 SkPoint pts[6];
296 for (auto& p : pts) {
297 p = rand_pt();
298 }
299 path.moveTo(pts[0]).quadTo(pts[1], pts[2]).quadTo(pts[3], pts[4]).lineTo(pts[5]);
300 }
301 return path.detach();
302}
static SkPoint rand_pt(SkRandom &rand)
float nextF()
Definition SkRandom.h:55
double y
double x

◆ randRange()

static SkScalar randRange ( SkRandom rand,
SkScalar  min,
SkScalar  max 
)
static

Definition at line 59 of file ClipSlide.cpp.

59 {
60 SkASSERT(min <= max);
61 return min + rand.nextUScalar1() * (max - min);
62}
#define SkASSERT(cond)
Definition SkAssert.h:116
SkScalar nextUScalar1()
Definition SkRandom.h:101
static float max(float r, float g, float b)
Definition hsl.cpp:49
static float min(float r, float g, float b)
Definition hsl.cpp:48

◆ show_fill()

static void show_fill ( SkCanvas canvas,
bool  doAA 
)
static

Definition at line 39 of file ClipSlide.cpp.

39 {
40 SkRandom rand;
42 paint.setAntiAlias(doAA);
43
44 for (int i = 0; i < 50; ++i) {
45 SkRect r;
46
47 r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
48 rand.nextUScalar1() * W, rand.nextUScalar1() * H);
49 paint.setColor(rand.nextU());
50 canvas->drawRect(r, paint);
51
52 r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
53 rand.nextUScalar1() * W, rand.nextUScalar1() * H);
54 paint.setColor(rand.nextU());
55 canvas->drawOval(r, paint);
56 }
57}
constexpr int W
Definition ClipSlide.cpp:23
void drawRect(const SkRect &rect, const SkPaint &paint)
void drawOval(const SkRect &oval, const SkPaint &paint)
uint32_t nextU()
Definition SkRandom.h:42
SkScalar nextSScalar1()
Definition SkRandom.h:113
Definition SkMD5.cpp:130
void setXYWH(float x, float y, float width, float height)
Definition SkRect.h:931

◆ show_hair()

static void show_hair ( SkCanvas canvas,
bool  doAA 
)
static

Definition at line 95 of file ClipSlide.cpp.

95 {
96 show_stroke(canvas, doAA, 0, 150);
97}
static void show_stroke(SkCanvas *canvas, bool doAA, SkScalar strokeWidth, int n)
Definition ClipSlide.cpp:64

◆ show_stroke()

static void show_stroke ( SkCanvas canvas,
bool  doAA,
SkScalar  strokeWidth,
int  n 
)
static

Definition at line 64 of file ClipSlide.cpp.

64 {
65 SkRandom rand;
67 paint.setAntiAlias(doAA);
69 paint.setStrokeWidth(strokeWidth);
70
71 for (int i = 0; i < n; ++i) {
72 SkRect r;
73
74 r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
75 rand.nextUScalar1() * W, rand.nextUScalar1() * H);
76 paint.setColor(rand.nextU());
77 canvas->drawRect(r, paint);
78
79 r.setXYWH(rand.nextSScalar1() * W, rand.nextSScalar1() * H,
80 rand.nextUScalar1() * W, rand.nextUScalar1() * H);
81 paint.setColor(rand.nextU());
82 canvas->drawOval(r, paint);
83
84 const SkScalar minx = -SkIntToScalar(W)/4;
85 const SkScalar maxx = 5*SkIntToScalar(W)/4;
86 const SkScalar miny = -SkIntToScalar(H)/4;
87 const SkScalar maxy = 5*SkIntToScalar(H)/4;
88 paint.setColor(rand.nextU());
89 canvas->drawLine(randRange(rand, minx, maxx), randRange(rand, miny, maxy),
90 randRange(rand, minx, maxx), randRange(rand, miny, maxy),
91 paint);
92 }
93}
static const int strokeWidth
Definition BlurTest.cpp:60
static SkScalar randRange(SkRandom &rand, SkScalar min, SkScalar max)
Definition ClipSlide.cpp:59
#define SkIntToScalar(x)
Definition SkScalar.h:57
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194

◆ show_text()

static void show_text ( SkCanvas canvas,
bool  doAA 
)
static

Definition at line 26 of file ClipSlide.cpp.

26 {
27 SkRandom rand;
30 font.setEdging(doAA ? SkFont::Edging::kSubpixelAntiAlias : SkFont::Edging::kAlias);
31
32 for (int i = 0; i < 200; ++i) {
33 paint.setColor((SK_A32_MASK << SK_A32_SHIFT) | rand.nextU());
34 canvas->drawString("Hamburgefons", rand.nextSScalar1() * W, rand.nextSScalar1() * H + 20,
35 font, paint);
36 }
37}
#define SK_A32_MASK
Definition SkColorPriv.h:45
#define SK_A32_SHIFT
Definition SkTypes.h:54
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition SkCanvas.h:1803
@ kSubpixelAntiAlias
glyph positioned in pixel using transparency
sk_sp< SkTypeface > DefaultTypeface()
font
Font Metadata and Metrics.

◆ show_thick()

static void show_thick ( SkCanvas canvas,
bool  doAA 
)
static

Definition at line 99 of file ClipSlide.cpp.

99 {
100 show_stroke(canvas, doAA, SkIntToScalar(5), 50);
101}

Variable Documentation

◆ H

constexpr int H = 200
constexpr

Definition at line 24 of file ClipSlide.cpp.

◆ W

constexpr int W = 150
constexpr

Definition at line 23 of file ClipSlide.cpp.