blob: 09cb87cc90cd1550f1f7daab91492100eab81dc8 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 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 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "include/core/SkCanvas.h"
8#include "include/core/SkPaint.h"
9#include "include/core/SkVertices.h"
10#include "include/effects/SkBlurMaskFilter.h"
11#include "include/effects/SkGradientShader.h"
12#include "samplecode/Sample.h"
13#include "src/core/SkBlurMask.h"
14#include "src/core/SkReadBuffer.h"
15#include "src/core/SkWriteBuffer.h"
reed@android.com63e34c62009-10-06 21:19:18 +000016
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "tools/ToolUtils.h"
Hal Canarydb683012016-11-23 08:55:18 -070018
reed@android.com8af96022009-10-12 17:02:22 +000019#define BG_COLOR 0xFFDDDDDD
20
reed@android.com63e34c62009-10-06 21:19:18 +000021typedef void (*SlideProc)(SkCanvas*);
22
23///////////////////////////////////////////////////////////////////////////////
24
Mike Kleinc0bd9f92019-04-23 12:05:21 -050025#include "include/effects/Sk1DPathEffect.h"
26#include "include/effects/Sk2DPathEffect.h"
27#include "include/effects/SkCornerPathEffect.h"
28#include "include/effects/SkDashPathEffect.h"
29#include "include/effects/SkDiscretePathEffect.h"
reed@android.com63e34c62009-10-06 21:19:18 +000030
31static void compose_pe(SkPaint* paint) {
32 SkPathEffect* pe = paint->getPathEffect();
reeda4393342016-03-18 11:22:57 -070033 sk_sp<SkPathEffect> corner = SkCornerPathEffect::Make(25);
34 sk_sp<SkPathEffect> compose;
reed@android.com63e34c62009-10-06 21:19:18 +000035 if (pe) {
Mike Reeda07741a2017-02-25 22:34:32 -050036 compose = SkPathEffect::MakeCompose(sk_ref_sp(pe), corner);
reed@android.com63e34c62009-10-06 21:19:18 +000037 } else {
38 compose = corner;
39 }
reeda4393342016-03-18 11:22:57 -070040 paint->setPathEffect(compose);
reed@android.com63e34c62009-10-06 21:19:18 +000041}
42
43static void hair_pe(SkPaint* paint) {
44 paint->setStrokeWidth(0);
45}
46
47static void hair2_pe(SkPaint* paint) {
48 paint->setStrokeWidth(0);
49 compose_pe(paint);
50}
51
52static void stroke_pe(SkPaint* paint) {
53 paint->setStrokeWidth(12);
54 compose_pe(paint);
55}
56
57static void dash_pe(SkPaint* paint) {
58 SkScalar inter[] = { 20, 10, 10, 10 };
59 paint->setStrokeWidth(12);
reeda4393342016-03-18 11:22:57 -070060 paint->setPathEffect(SkDashPathEffect::Make(inter, SK_ARRAY_COUNT(inter), 0));
reed@android.com63e34c62009-10-06 21:19:18 +000061 compose_pe(paint);
62}
63
64static const int gXY[] = {
654, 0, 0, -4, 8, -4, 12, 0, 8, 4, 0, 4
66};
67
68static void scale(SkPath* path, SkScalar scale) {
69 SkMatrix m;
70 m.setScale(scale, scale);
71 path->transform(m);
72}
73
74static void one_d_pe(SkPaint* paint) {
75 SkPath path;
76 path.moveTo(SkIntToScalar(gXY[0]), SkIntToScalar(gXY[1]));
77 for (unsigned i = 2; i < SK_ARRAY_COUNT(gXY); i += 2)
78 path.lineTo(SkIntToScalar(gXY[i]), SkIntToScalar(gXY[i+1]));
79 path.close();
80 path.offset(SkIntToScalar(-6), 0);
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +000081 scale(&path, 1.5f);
rmistry@google.comae933ce2012-08-23 18:19:56 +000082
reeda4393342016-03-18 11:22:57 -070083 paint->setPathEffect(SkPath1DPathEffect::Make(path, SkIntToScalar(21), 0,
84 SkPath1DPathEffect::kRotate_Style));
reed@android.com63e34c62009-10-06 21:19:18 +000085 compose_pe(paint);
86}
87
88typedef void (*PE_Proc)(SkPaint*);
89static const PE_Proc gPE[] = { hair_pe, hair2_pe, stroke_pe, dash_pe, one_d_pe };
90
91static void fill_pe(SkPaint* paint) {
92 paint->setStyle(SkPaint::kFill_Style);
halcanary96fcdcc2015-08-27 07:41:13 -070093 paint->setPathEffect(nullptr);
reed@android.com63e34c62009-10-06 21:19:18 +000094}
95
96static void discrete_pe(SkPaint* paint) {
reeda4393342016-03-18 11:22:57 -070097 paint->setPathEffect(SkDiscretePathEffect::Make(10, 4));
reed@android.com63e34c62009-10-06 21:19:18 +000098}
99
reeda4393342016-03-18 11:22:57 -0700100static sk_sp<SkPathEffect> MakeTileEffect() {
reed@google.com43e9f202011-08-09 19:01:50 +0000101 SkMatrix m;
102 m.setScale(SkIntToScalar(12), SkIntToScalar(12));
reed@android.com63e34c62009-10-06 21:19:18 +0000103
reed@google.com43e9f202011-08-09 19:01:50 +0000104 SkPath path;
105 path.addCircle(0, 0, SkIntToScalar(5));
rmistry@google.comae933ce2012-08-23 18:19:56 +0000106
reeda4393342016-03-18 11:22:57 -0700107 return SkPath2DPathEffect::Make(m, path);
reed@google.com43e9f202011-08-09 19:01:50 +0000108}
reed@android.com63e34c62009-10-06 21:19:18 +0000109
110static void tile_pe(SkPaint* paint) {
reeda4393342016-03-18 11:22:57 -0700111 paint->setPathEffect(MakeTileEffect());
reed@android.com63e34c62009-10-06 21:19:18 +0000112}
113
114static const PE_Proc gPE2[] = { fill_pe, discrete_pe, tile_pe };
115
116static void patheffect_slide(SkCanvas* canvas) {
117 SkPaint paint;
118 paint.setAntiAlias(true);
119 paint.setStyle(SkPaint::kStroke_Style);
120
121 SkPath path;
122 path.moveTo(20, 20);
123 path.lineTo(70, 120);
124 path.lineTo(120, 30);
125 path.lineTo(170, 80);
126 path.lineTo(240, 50);
127
128 size_t i;
129 canvas->save();
130 for (i = 0; i < SK_ARRAY_COUNT(gPE); i++) {
131 gPE[i](&paint);
132 canvas->drawPath(path, paint);
133 canvas->translate(0, 75);
134 }
135 canvas->restore();
136
137 path.reset();
138 SkRect r = { 0, 0, 250, 120 };
Mike Reed4241f5e2019-09-14 19:13:23 +0000139 path.addOval(r, SkPath::kCW_Direction);
reed@android.com63e34c62009-10-06 21:19:18 +0000140 r.inset(50, 50);
Mike Reed4241f5e2019-09-14 19:13:23 +0000141 path.addRect(r, SkPath::kCCW_Direction);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000142
reed@android.com63e34c62009-10-06 21:19:18 +0000143 canvas->translate(320, 20);
144 for (i = 0; i < SK_ARRAY_COUNT(gPE2); i++) {
145 gPE2[i](&paint);
146 canvas->drawPath(path, paint);
147 canvas->translate(0, 160);
148 }
149}
150
151///////////////////////////////////////////////////////////////////////////////
152
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500153#include "include/effects/SkGradientShader.h"
reed@android.com63e34c62009-10-06 21:19:18 +0000154
155struct GradData {
156 int fCount;
157 const SkColor* fColors;
158 const SkScalar* fPos;
159};
160
161static const SkColor gColors[] = {
162SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorWHITE, SK_ColorBLACK
163};
164static const SkScalar gPos0[] = { 0, SK_Scalar1 };
165static const SkScalar gPos1[] = { SK_Scalar1/4, SK_Scalar1*3/4 };
166static const SkScalar gPos2[] = {
1670, SK_Scalar1/8, SK_Scalar1/2, SK_Scalar1*7/8, SK_Scalar1
168};
169
170static const GradData gGradData[] = {
halcanary96fcdcc2015-08-27 07:41:13 -0700171{ 2, gColors, nullptr },
reed@android.com63e34c62009-10-06 21:19:18 +0000172{ 2, gColors, gPos0 },
173{ 2, gColors, gPos1 },
halcanary96fcdcc2015-08-27 07:41:13 -0700174{ 5, gColors, nullptr },
reed@android.com63e34c62009-10-06 21:19:18 +0000175{ 5, gColors, gPos2 }
176};
177
Mike Reedfae8fce2019-04-03 10:27:45 -0400178static sk_sp<SkShader> MakeLinear(const SkPoint pts[2], const GradData& data, SkTileMode tm) {
reed8a21c9f2016-03-08 18:50:00 -0800179 return SkGradientShader::MakeLinear(pts, data.fColors, data.fPos, data.fCount, tm);
reed@android.com63e34c62009-10-06 21:19:18 +0000180}
181
Mike Reedfae8fce2019-04-03 10:27:45 -0400182static sk_sp<SkShader> MakeRadial(const SkPoint pts[2], const GradData& data, SkTileMode tm) {
reed@android.com63e34c62009-10-06 21:19:18 +0000183 SkPoint center;
184 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
185 SkScalarAve(pts[0].fY, pts[1].fY));
reed8a21c9f2016-03-08 18:50:00 -0800186 return SkGradientShader::MakeRadial(center, center.fX, data.fColors,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000187 data.fPos, data.fCount, tm);
reed@android.com63e34c62009-10-06 21:19:18 +0000188}
189
Mike Reedfae8fce2019-04-03 10:27:45 -0400190static sk_sp<SkShader> MakeSweep(const SkPoint pts[2], const GradData& data, SkTileMode tm) {
reed@android.com63e34c62009-10-06 21:19:18 +0000191 SkPoint center;
192 center.set(SkScalarAve(pts[0].fX, pts[1].fX),
193 SkScalarAve(pts[0].fY, pts[1].fY));
reed8a21c9f2016-03-08 18:50:00 -0800194 return SkGradientShader::MakeSweep(center.fX, center.fY, data.fColors, data.fPos, data.fCount);
reed@android.com63e34c62009-10-06 21:19:18 +0000195}
196
Mike Reedfae8fce2019-04-03 10:27:45 -0400197static sk_sp<SkShader> Make2Conical(const SkPoint pts[2], const GradData& data, SkTileMode tm) {
reed@android.com63e34c62009-10-06 21:19:18 +0000198 SkPoint center0, center1;
199 center0.set(SkScalarAve(pts[0].fX, pts[1].fX),
200 SkScalarAve(pts[0].fY, pts[1].fY));
201 center1.set(SkScalarInterp(pts[0].fX, pts[1].fX, SkIntToScalar(3)/5),
202 SkScalarInterp(pts[0].fY, pts[1].fY, SkIntToScalar(1)/4));
reed8a21c9f2016-03-08 18:50:00 -0800203 return SkGradientShader::MakeTwoPointConical(center1, (pts[1].fX - pts[0].fX) / 7,
reed@android.com63e34c62009-10-06 21:19:18 +0000204 center0, (pts[1].fX - pts[0].fX) / 2,
commit-bot@chromium.org83f23d82014-05-22 12:27:41 +0000205 data.fColors, data.fPos, data.fCount, tm);
reed@android.com63e34c62009-10-06 21:19:18 +0000206}
207
Mike Reedfae8fce2019-04-03 10:27:45 -0400208typedef sk_sp<SkShader> (*GradMaker)(const SkPoint pts[2], const GradData&, SkTileMode);
reed@android.com63e34c62009-10-06 21:19:18 +0000209static const GradMaker gGradMakers[] = {
reed71a6cbf2015-05-04 08:32:51 -0700210 MakeLinear, MakeRadial, MakeSweep, Make2Conical
reed@android.com63e34c62009-10-06 21:19:18 +0000211};
212
213static void gradient_slide(SkCanvas* canvas) {
214 SkPoint pts[2] = {
215 { 0, 0 },
216 { SkIntToScalar(100), SkIntToScalar(100) }
217 };
Mike Reedfae8fce2019-04-03 10:27:45 -0400218 SkTileMode tm = SkTileMode::kClamp;
reed@android.com63e34c62009-10-06 21:19:18 +0000219 SkRect r = { 0, 0, SkIntToScalar(100), SkIntToScalar(100) };
220 SkPaint paint;
221 paint.setAntiAlias(true);
222 paint.setDither(true);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000223
reed@android.com63e34c62009-10-06 21:19:18 +0000224 canvas->translate(SkIntToScalar(20), SkIntToScalar(10));
225 for (size_t i = 0; i < SK_ARRAY_COUNT(gGradData); i++) {
226 canvas->save();
227 for (size_t j = 0; j < SK_ARRAY_COUNT(gGradMakers); j++) {
reed8a21c9f2016-03-08 18:50:00 -0800228 paint.setShader(gGradMakers[j](pts, gGradData[i], tm));
reed@android.com63e34c62009-10-06 21:19:18 +0000229 canvas->drawRect(r, paint);
reed@android.com63e34c62009-10-06 21:19:18 +0000230 canvas->translate(0, SkIntToScalar(120));
231 }
232 canvas->restore();
233 canvas->translate(SkIntToScalar(120), 0);
234 }
235}
236
237///////////////////////////////////////////////////////////////////////////////
238
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500239#include "include/core/SkStream.h"
240#include "include/utils/SkRandom.h"
241#include "samplecode/DecodeFile.h"
242#include "src/core/SkOSFile.h"
reed@android.com63e34c62009-10-06 21:19:18 +0000243
reed8a21c9f2016-03-08 18:50:00 -0800244static sk_sp<SkShader> make_shader0(SkIPoint* size) {
reed@android.com63e34c62009-10-06 21:19:18 +0000245 SkBitmap bm;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000246
msarettd15750c2016-03-18 15:48:49 -0700247 decode_file("/skimages/logo.gif", &bm);
reed@android.com63e34c62009-10-06 21:19:18 +0000248 size->set(bm.width(), bm.height());
Mike Reed50acf8f2019-04-08 13:20:23 -0400249 return bm.makeShader();
reed@android.com63e34c62009-10-06 21:19:18 +0000250}
251
reed8a21c9f2016-03-08 18:50:00 -0800252static sk_sp<SkShader> make_shader1(const SkIPoint& size) {
senorblanco@chromium.org64cc5792011-05-19 19:58:58 +0000253 SkPoint pts[] = { { 0, 0 },
254 { SkIntToScalar(size.fX), SkIntToScalar(size.fY) } };
reed@android.com63e34c62009-10-06 21:19:18 +0000255 SkColor colors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorBLUE, SK_ColorRED };
reed8a21c9f2016-03-08 18:50:00 -0800256 return SkGradientShader::MakeLinear(pts, colors, nullptr,
Mike Reedfae8fce2019-04-03 10:27:45 -0400257 SK_ARRAY_COUNT(colors), SkTileMode::kMirror);
reed@android.com63e34c62009-10-06 21:19:18 +0000258}
259
reed@android.comf2b98d62010-12-20 18:26:13 +0000260class Rec {
261public:
Mike Reed887cdf12017-04-03 11:11:09 -0400262 SkVertices::VertexMode fMode;
reed@android.com63e34c62009-10-06 21:19:18 +0000263 int fCount;
264 SkPoint* fVerts;
265 SkPoint* fTexs;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000266
halcanary96fcdcc2015-08-27 07:41:13 -0700267 Rec() : fCount(0), fVerts(nullptr), fTexs(nullptr) {}
reed@android.com63e34c62009-10-06 21:19:18 +0000268 ~Rec() { delete[] fVerts; delete[] fTexs; }
269};
270
caryclark@google.com02939ce2012-06-06 12:09:51 +0000271static void make_tris(Rec* rec) {
reed@android.com63e34c62009-10-06 21:19:18 +0000272 int n = 10;
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000273 SkRandom rand;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000274
Mike Reed887cdf12017-04-03 11:11:09 -0400275 rec->fMode = SkVertices::kTriangles_VertexMode;
reed@android.com63e34c62009-10-06 21:19:18 +0000276 rec->fCount = n * 3;
277 rec->fVerts = new SkPoint[rec->fCount];
rmistry@google.comae933ce2012-08-23 18:19:56 +0000278
reed@android.com63e34c62009-10-06 21:19:18 +0000279 for (int i = 0; i < n; i++) {
280 SkPoint* v = &rec->fVerts[i*3];
281 for (int j = 0; j < 3; j++) {
282 v[j].set(rand.nextUScalar1() * 250, rand.nextUScalar1() * 250);
283 }
284 }
285}
286
caryclark@google.com02939ce2012-06-06 12:09:51 +0000287static void make_fan(Rec* rec, int texWidth, int texHeight) {
reed@android.com63e34c62009-10-06 21:19:18 +0000288 const SkScalar tx = SkIntToScalar(texWidth);
289 const SkScalar ty = SkIntToScalar(texHeight);
290 const int n = 24;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000291
Mike Reed887cdf12017-04-03 11:11:09 -0400292 rec->fMode = SkVertices::kTriangleFan_VertexMode;
reed@android.com63e34c62009-10-06 21:19:18 +0000293 rec->fCount = n + 2;
294 rec->fVerts = new SkPoint[rec->fCount];
295 rec->fTexs = new SkPoint[rec->fCount];
rmistry@google.comae933ce2012-08-23 18:19:56 +0000296
reed@android.com63e34c62009-10-06 21:19:18 +0000297 SkPoint* v = rec->fVerts;
298 SkPoint* t = rec->fTexs;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000299
reed@android.com63e34c62009-10-06 21:19:18 +0000300 v[0].set(0, 0);
301 t[0].set(0, 0);
302 for (int i = 0; i < n; i++) {
Brian Osman4428f2c2019-04-02 10:59:28 -0400303 SkScalar r = SK_ScalarPI * 2 * i / n,
304 sin = SkScalarSin(r),
305 cos = SkScalarCos(r);
reed@android.com63e34c62009-10-06 21:19:18 +0000306 v[i+1].set(cos, sin);
307 t[i+1].set(i*tx/n, ty);
308 }
309 v[n+1] = v[1];
310 t[n+1].set(tx, ty);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000311
reed@android.com63e34c62009-10-06 21:19:18 +0000312 SkMatrix m;
313 m.setScale(SkIntToScalar(100), SkIntToScalar(100));
314 m.postTranslate(SkIntToScalar(110), SkIntToScalar(110));
315 m.mapPoints(v, rec->fCount);
316}
317
caryclark@google.com02939ce2012-06-06 12:09:51 +0000318static void make_strip(Rec* rec, int texWidth, int texHeight) {
reed@android.com63e34c62009-10-06 21:19:18 +0000319 const SkScalar tx = SkIntToScalar(texWidth);
320 const SkScalar ty = SkIntToScalar(texHeight);
321 const int n = 24;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000322
Mike Reed887cdf12017-04-03 11:11:09 -0400323 rec->fMode = SkVertices::kTriangleStrip_VertexMode;
reed@android.com63e34c62009-10-06 21:19:18 +0000324 rec->fCount = 2 * (n + 1);
325 rec->fVerts = new SkPoint[rec->fCount];
326 rec->fTexs = new SkPoint[rec->fCount];
rmistry@google.comae933ce2012-08-23 18:19:56 +0000327
reed@android.com63e34c62009-10-06 21:19:18 +0000328 SkPoint* v = rec->fVerts;
329 SkPoint* t = rec->fTexs;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000330
reed@android.com63e34c62009-10-06 21:19:18 +0000331 for (int i = 0; i < n; i++) {
Brian Osman4428f2c2019-04-02 10:59:28 -0400332 SkScalar r = SK_ScalarPI * 2 * i / n,
333 sin = SkScalarSin(r),
334 cos = SkScalarCos(r);
reed@android.com63e34c62009-10-06 21:19:18 +0000335 v[i*2 + 0].set(cos/2, sin/2);
336 v[i*2 + 1].set(cos, sin);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000337
reed@android.com63e34c62009-10-06 21:19:18 +0000338 t[i*2 + 0].set(tx * i / n, ty);
339 t[i*2 + 1].set(tx * i / n, 0);
340 }
341 v[2*n + 0] = v[0];
342 v[2*n + 1] = v[1];
rmistry@google.comae933ce2012-08-23 18:19:56 +0000343
reed@android.com63e34c62009-10-06 21:19:18 +0000344 t[2*n + 0].set(tx, ty);
345 t[2*n + 1].set(tx, 0);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000346
reed@android.com63e34c62009-10-06 21:19:18 +0000347 SkMatrix m;
348 m.setScale(SkIntToScalar(100), SkIntToScalar(100));
349 m.postTranslate(SkIntToScalar(110), SkIntToScalar(110));
350 m.mapPoints(v, rec->fCount);
351}
352
353static void mesh_slide(SkCanvas* canvas) {
354 Rec fRecs[3];
355 SkIPoint size;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000356
reed8a21c9f2016-03-08 18:50:00 -0800357 auto fShader0 = make_shader0(&size);
358 auto fShader1 = make_shader1(size);
reed@android.comf2b98d62010-12-20 18:26:13 +0000359
reed@android.com63e34c62009-10-06 21:19:18 +0000360 make_strip(&fRecs[0], size.fX, size.fY);
361 make_fan(&fRecs[1], size.fX, size.fY);
362 make_tris(&fRecs[2]);
363
reed@android.com63e34c62009-10-06 21:19:18 +0000364 SkPaint paint;
365 paint.setDither(true);
reed93a12152015-03-16 10:08:34 -0700366 paint.setFilterQuality(kLow_SkFilterQuality);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000367
senorblanco@chromium.org64cc5792011-05-19 19:58:58 +0000368 for (size_t i = 0; i < SK_ARRAY_COUNT(fRecs); i++) {
Mike Reed887cdf12017-04-03 11:11:09 -0400369 auto verts = SkVertices::MakeCopy(fRecs[i].fMode, fRecs[i].fCount,
370 fRecs[i].fVerts, fRecs[i].fTexs, nullptr);
reed@android.com63e34c62009-10-06 21:19:18 +0000371 canvas->save();
rmistry@google.comae933ce2012-08-23 18:19:56 +0000372
halcanary96fcdcc2015-08-27 07:41:13 -0700373 paint.setShader(nullptr);
Mike Reed887cdf12017-04-03 11:11:09 -0400374 canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000375
reed@android.com63e34c62009-10-06 21:19:18 +0000376 canvas->translate(SkIntToScalar(210), 0);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000377
reed@android.com63e34c62009-10-06 21:19:18 +0000378 paint.setShader(fShader0);
Mike Reed887cdf12017-04-03 11:11:09 -0400379 canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000380
reed@android.com63e34c62009-10-06 21:19:18 +0000381 canvas->translate(SkIntToScalar(210), 0);
rmistry@google.comae933ce2012-08-23 18:19:56 +0000382
reed@android.com63e34c62009-10-06 21:19:18 +0000383 paint.setShader(fShader1);
Mike Reed887cdf12017-04-03 11:11:09 -0400384 canvas->drawVertices(verts, SkBlendMode::kModulate, paint);
reed@android.com63e34c62009-10-06 21:19:18 +0000385 canvas->restore();
rmistry@google.comae933ce2012-08-23 18:19:56 +0000386
reed@android.com63e34c62009-10-06 21:19:18 +0000387 canvas->translate(0, SkIntToScalar(250));
388 }
389}
390
391///////////////////////////////////////////////////////////////////////////////
392
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500393#include "include/core/SkTypeface.h"
reed@android.com8af96022009-10-12 17:02:22 +0000394
reed@android.com8af96022009-10-12 17:02:22 +0000395///////////////////////////////////////////////////////////////////////////////
396
Mike Kleinc0bd9f92019-04-23 12:05:21 -0500397#include "include/core/SkImageEncoder.h"
reed@android.com63e34c62009-10-06 21:19:18 +0000398
399static const SlideProc gProc[] = {
400 patheffect_slide,
401 gradient_slide,
reed@android.com8af96022009-10-12 17:02:22 +0000402 mesh_slide,
reed@android.com63e34c62009-10-06 21:19:18 +0000403};
404
Ben Wagnerb2c4ea62018-08-08 11:36:17 -0400405class SlideView : public Sample {
reed@android.com63e34c62009-10-06 21:19:18 +0000406 int fIndex;
reed@google.com7b185902012-03-12 21:13:48 +0000407 bool fOnce;
reed@android.com63e34c62009-10-06 21:19:18 +0000408public:
409 SlideView() {
reed@google.com7b185902012-03-12 21:13:48 +0000410 fOnce = false;
411 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000412
reed@google.com7b185902012-03-12 21:13:48 +0000413 void init() {
414 if (fOnce) {
415 return;
416 }
417 fOnce = true;
418
reed@android.com63e34c62009-10-06 21:19:18 +0000419 fIndex = 0;
rmistry@google.comae933ce2012-08-23 18:19:56 +0000420
reed@android.com63e34c62009-10-06 21:19:18 +0000421 SkBitmap bm;
commit-bot@chromium.orga8c18312014-02-17 02:55:57 +0000422 bm.allocN32Pixels(1024, 768);
reed@android.com63e34c62009-10-06 21:19:18 +0000423 SkCanvas canvas(bm);
424 SkScalar s = SkIntToScalar(1024) / 640;
425 canvas.scale(s, s);
426 for (size_t i = 0; i < SK_ARRAY_COUNT(gProc); i++) {
427 canvas.save();
reed@android.com8af96022009-10-12 17:02:22 +0000428 canvas.drawColor(BG_COLOR);
reed@android.com63e34c62009-10-06 21:19:18 +0000429 gProc[i](&canvas);
430 canvas.restore();
431 SkString str;
senorblanco@chromium.org3a67a662012-07-09 18:22:08 +0000432 str.printf("/skimages/slide_" SK_SIZE_T_SPECIFIER ".png", i);
Mike Kleinea3f0142019-03-20 11:12:10 -0500433 ToolUtils::EncodeImageToFile(str.c_str(), bm, SkEncodedImageFormat::kPNG, 100);
reed@android.com63e34c62009-10-06 21:19:18 +0000434 }
reed@google.com81e3d7f2011-06-01 12:42:36 +0000435 this->setBGColor(BG_COLOR);
reed@android.com63e34c62009-10-06 21:19:18 +0000436 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000437
reed@android.com63e34c62009-10-06 21:19:18 +0000438protected:
Hal Canary8a027312019-07-03 10:55:44 -0400439 SkString name() override { return SkString("Slides"); }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000440
mtklein36352bf2015-03-25 18:17:31 -0700441 void onDrawContent(SkCanvas* canvas) override {
reed@google.com7b185902012-03-12 21:13:48 +0000442 this->init();
reed@android.com63e34c62009-10-06 21:19:18 +0000443 gProc[fIndex](canvas);
444 }
445
Hal Canaryb1f411a2019-08-29 10:39:22 -0400446 Sample::Click* onFindClickHandler(SkScalar x, SkScalar y, skui::ModifierKey) override {
reed@google.com7b185902012-03-12 21:13:48 +0000447 this->init();
reed@android.com63e34c62009-10-06 21:19:18 +0000448 fIndex = (fIndex + 1) % SK_ARRAY_COUNT(gProc);
halcanary96fcdcc2015-08-27 07:41:13 -0700449 return nullptr;
reed@android.com63e34c62009-10-06 21:19:18 +0000450 }
451
452private:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -0400453 typedef Sample INHERITED;
reed@android.com63e34c62009-10-06 21:19:18 +0000454};
455
456//////////////////////////////////////////////////////////////////////////////
457
Ben Wagnerb2c4ea62018-08-08 11:36:17 -0400458DEF_SAMPLE( return new SlideView(); )