Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions | Variables
patch.cpp File Reference
#include "gm/gm.h"
#include "include/core/SkBlendMode.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkColor.h"
#include "include/core/SkImage.h"
#include "include/core/SkPaint.h"
#include "include/core/SkPath.h"
#include "include/core/SkPoint.h"
#include "include/core/SkRefCnt.h"
#include "include/core/SkScalar.h"
#include "include/core/SkShader.h"
#include "include/core/SkTileMode.h"
#include "include/core/SkTypes.h"
#include "include/effects/SkGradientShader.h"
#include "src/utils/SkPatchUtils.h"
#include "tools/DecodeUtils.h"
#include "tools/Resources.h"

Go to the source code of this file.

Functions

static sk_sp< SkShadermake_shader ()
 
static void draw_control_points (SkCanvas *canvas, const SkPoint cubics[12])
 
static void dopatch (SkCanvas *canvas, const SkColor colors[], sk_sp< SkImage > img, const SkMatrix *localMatrix)
 
 DEF_SIMPLE_GM (patch_primitive, canvas, 1500, 1100)
 
 DEF_SIMPLE_GM (patch_image, canvas, 1500, 1100)
 
 DEF_SIMPLE_GM (patch_image_persp, canvas, 1500, 1100)
 
 DEF_SIMPLE_GM (patch_alpha, canvas, 1500, 1100)
 
 DEF_SIMPLE_GM (patch_alpha_test, canvas, 550, 250)
 

Variables

const SkPoint gCubics [SkPatchUtils::kNumCtrlPts]
 
const SkPoint gTexCoords [SkPatchUtils::kNumCorners]
 

Function Documentation

◆ DEF_SIMPLE_GM() [1/5]

DEF_SIMPLE_GM ( patch_alpha  ,
canvas  ,
1500  ,
1100   
)

Definition at line 179 of file patch.cpp.

179 {
181 SK_ColorRED, 0x0000FF00, SK_ColorBLUE, 0x00FF00FF,
182 };
183 dopatch(canvas, colors, nullptr, nullptr);
184}
uint32_t SkColor
Definition SkColor.h:37
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorRED
Definition SkColor.h:126
PODArray< SkColor > colors
Definition SkRecords.h:276
static void dopatch(SkCanvas *canvas, const SkColor colors[], sk_sp< SkImage > img, const SkMatrix *localMatrix)
Definition patch.cpp:97

◆ DEF_SIMPLE_GM() [2/5]

DEF_SIMPLE_GM ( patch_alpha_test  ,
canvas  ,
550  ,
250   
)

Definition at line 187 of file patch.cpp.

187 {
188 canvas->translate(-75, -75);
189
191 0x80FF0000, 0x80FF0000, 0x80FF0000, 0x80FF0000,
192 };
194 canvas->drawPatch(gCubics, colors, nullptr, SkBlendMode::kDst, paint);
195
196 canvas->translate(300, 0);
197
198 SkPath path;
199 path.moveTo(gCubics[0]);
200 path.cubicTo(gCubics[ 1], gCubics[ 2], gCubics[ 3]);
201 path.cubicTo(gCubics[ 4], gCubics[ 5], gCubics[ 6]);
202 path.cubicTo(gCubics[ 7], gCubics[ 8], gCubics[ 9]);
203 path.cubicTo(gCubics[10], gCubics[11], gCubics[ 0]);
204 paint.setColor(colors[0]);
205 canvas->drawPath(path, paint);
206}
const Paint & paint
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
const SkPoint gCubics[SkPatchUtils::kNumCtrlPts]
Definition patch.cpp:81

◆ DEF_SIMPLE_GM() [3/5]

DEF_SIMPLE_GM ( patch_image  ,
canvas  ,
1500  ,
1100   
)

Definition at line 164 of file patch.cpp.

164 {
167 };
168 dopatch(canvas, colors, ToolUtils::GetResourceAsImage("images/mandrill_128.png"), nullptr);
169}
constexpr SkColor SK_ColorCYAN
Definition SkColor.h:143
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
sk_sp< SkImage > GetResourceAsImage(const char *resource)
Definition DecodeUtils.h:25

◆ DEF_SIMPLE_GM() [4/5]

DEF_SIMPLE_GM ( patch_image_persp  ,
canvas  ,
1500  ,
1100   
)

Definition at line 170 of file patch.cpp.

170 {
173 };
174 SkMatrix localM;
175 localM.reset();
176 localM[6] = 0.00001f; // force perspective
177 dopatch(canvas, colors, ToolUtils::GetResourceAsImage("images/mandrill_128.png"), &localM);
178}
SkMatrix & reset()
Definition SkMatrix.cpp:49

◆ DEF_SIMPLE_GM() [5/5]

DEF_SIMPLE_GM ( patch_primitive  ,
canvas  ,
1500  ,
1100   
)

Definition at line 158 of file patch.cpp.

158 {
161 };
162 dopatch(canvas, colors, nullptr, nullptr);
163}

◆ dopatch()

static void dopatch ( SkCanvas canvas,
const SkColor  colors[],
sk_sp< SkImage img,
const SkMatrix localMatrix 
)
static

Definition at line 97 of file patch.cpp.

98 {
100 paint.setColor(SK_ColorGREEN);
101
102 const SkBlendMode modes[] = {
106 };
107
108 SkPoint texStorage[4];
109 const SkPoint* tex = gTexCoords;
110
111 sk_sp<SkShader> shader;
112 if (img) {
113 SkScalar w = img->width();
114 SkScalar h = img->height();
115 shader = img->makeShader(SkSamplingOptions(), localMatrix);
116 texStorage[0].set(0, 0);
117 texStorage[1].set(w, 0);
118 texStorage[2].set(w, h);
119 texStorage[3].set(0, h);
120 tex = texStorage;
121 } else {
122 shader = make_shader();
123 }
124
125 canvas->save();
126 for (int y = 0; y < 3; y++) {
127 for (int x = 0; x < 4; x++) {
128 canvas->save();
129 canvas->translate(x * 350.0f, y * 350.0f);
130 switch (x) {
131 case 0:
132 canvas->drawPatch(gCubics, nullptr, nullptr, modes[y], paint);
133 break;
134 case 1:
135 canvas->drawPatch(gCubics, colors, nullptr, modes[y], paint);
136 break;
137 case 2:
138 paint.setShader(shader);
139 canvas->drawPatch(gCubics, nullptr, tex, modes[y], paint);
140 paint.setShader(nullptr);
141 break;
142 case 3:
143 paint.setShader(shader);
144 canvas->drawPatch(gCubics, colors, tex, modes[y], paint);
145 paint.setShader(nullptr);
146 break;
147 default:
148 break;
149 }
150
152 canvas->restore();
153 }
154 }
155 canvas->restore();
156}
SkBlendMode
Definition SkBlendMode.h:38
@ kColorDodge
brighten destination to reflect source
void drawPatch(const SkPoint cubics[12], const SkColor colors[4], const SkPoint texCoords[4], SkBlendMode mode, const SkPaint &paint)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
int save()
Definition SkCanvas.cpp:451
int width() const
Definition SkImage.h:285
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition SkImage.cpp:179
int height() const
Definition SkImage.h:291
float SkScalar
Definition extension.cpp:12
double y
double x
const SkPoint gTexCoords[SkPatchUtils::kNumCorners]
Definition patch.cpp:92
static sk_sp< SkShader > make_shader()
Definition patch.cpp:26
static void draw_control_points(SkCanvas *canvas, const SkPoint cubics[12])
Definition patch.cpp:37
SkScalar w
SkScalar h
void set(float x, float y)

◆ draw_control_points()

static void draw_control_points ( SkCanvas canvas,
const SkPoint  cubics[12] 
)
static

Definition at line 37 of file patch.cpp.

37 {
38 //draw control points
41 SkPatchUtils::GetBottomCubic(cubics, bottom);
43 SkPatchUtils::GetTopCubic(cubics, top);
48
49 paint.setColor(SK_ColorBLACK);
50 paint.setStrokeWidth(0.5f);
51 SkPoint corners[4] = { bottom[0], bottom[3], top[0], top[3] };
52 canvas->drawPoints(SkCanvas::kLines_PointMode, 4, bottom, paint);
53 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, bottom + 1, paint);
57
58 canvas->drawPoints(SkCanvas::kLines_PointMode, 2, top + 1, paint);
61
62 paint.setStrokeWidth(2);
63
64 paint.setColor(SK_ColorRED);
65 canvas->drawPoints(SkCanvas::kPoints_PointMode, 4, corners, paint);
66
67 paint.setColor(SK_ColorBLUE);
68 canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, bottom + 1, paint);
69
70 paint.setColor(SK_ColorCYAN);
71 canvas->drawPoints(SkCanvas::kPoints_PointMode, 2, top + 1, paint);
72
73 paint.setColor(SK_ColorYELLOW);
75
76 paint.setColor(SK_ColorGREEN);
78}
constexpr SkColor SK_ColorYELLOW
Definition SkColor.h:139
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
static bool left(const SkPoint &p0, const SkPoint &p1)
static bool right(const SkPoint &p0, const SkPoint &p1)
void drawPoints(PointMode mode, size_t count, const SkPoint pts[], const SkPaint &paint)
@ kLines_PointMode
draw each pair of points as a line segment
Definition SkCanvas.h:1242
@ kPoints_PointMode
draw each point separately
Definition SkCanvas.h:1241
static void GetTopCubic(const SkPoint cubics[12], SkPoint points[4])
static void GetRightCubic(const SkPoint cubics[12], SkPoint points[4])
static void GetLeftCubic(const SkPoint cubics[12], SkPoint points[4])
static void GetBottomCubic(const SkPoint cubics[12], SkPoint points[4])

◆ make_shader()

static sk_sp< SkShader > make_shader ( )
static

Definition at line 26 of file patch.cpp.

26 {
27 const SkColor colors[] = {
30 };
31 const SkPoint pts[] = { { 100.f / 4.f, 0.f }, { 3.f * 100.f / 4.f, 100.f } };
32
33 return SkGradientShader::MakeLinear(pts, colors, nullptr, std::size(colors),
35}
constexpr SkColor SK_ColorMAGENTA
Definition SkColor.h:147
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
static sk_sp< SkShader > MakeLinear(const SkPoint pts[2], const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)

Variable Documentation

◆ gCubics

Initial value:
= {
{100,100},{150,50},{250,150}, {300,100},
{250, 150},{350,250},
{300,300},{250,250},{150,350},{100,300},
{50,250},{150,150}
}

Definition at line 81 of file patch.cpp.

81 {
82 //top points
83 {100,100},{150,50},{250,150}, {300,100},
84 //right points
85 {250, 150},{350,250},
86 //bottom points
87 {300,300},{250,250},{150,350},{100,300},
88 //left points
89 {50,250},{150,150}
90};

◆ gTexCoords

Initial value:
= {
{0.0f, 0.0f}, {100.0f, 0.0f}, {100.0f,100.0f}, {0.0f, 100.0f}
}

Definition at line 92 of file patch.cpp.

92 {
93 {0.0f, 0.0f}, {100.0f, 0.0f}, {100.0f,100.0f}, {0.0f, 100.0f}
94};