blob: 4540cd79f6dd458621ab25c02792d192233977df [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 */
Ben Wagnerb2c4ea62018-08-08 11:36:17 -04007#include "Sample.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00008#include "SkBlurMask.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +00009#include "SkCanvas.h"
reed@android.comba974cc2009-05-22 13:48:35 +000010#include "SkColorMatrixFilter.h"
11#include "SkDiscretePathEffect.h"
Ben Wagner339b84e2017-11-10 16:24:50 -050012#include "SkEmbossMaskFilter.h"
reed@android.comba974cc2009-05-22 13:48:35 +000013#include "SkGradientShader.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +000014#include "SkPaint.h"
robertphillips@google.comb7061172013-09-06 14:16:12 +000015
reed@android.comba974cc2009-05-22 13:48:35 +000016
17//#define COLOR 0xFFFF8844
18#define COLOR 0xFF888888
19
sugoi@google.com93c7ee32013-03-12 14:36:57 +000020static void paint_proc0(SkPaint*) {
reed@android.comba974cc2009-05-22 13:48:35 +000021}
22
23static void paint_proc1(SkPaint* paint) {
Mike Reed1be1f8d2018-03-14 13:01:17 -040024 paint->setMaskFilter(SkMaskFilter::MakeBlur(
commit-bot@chromium.orge3964552014-04-28 16:25:35 +000025 kNormal_SkBlurStyle,
reedefdfd512016-04-04 10:02:58 -070026 SkBlurMask::ConvertRadiusToSigma(2)));
reed@android.comba974cc2009-05-22 13:48:35 +000027}
28
29static void paint_proc2(SkPaint* paint) {
Ben Wagner339b84e2017-11-10 16:24:50 -050030 paint->setMaskFilter(SkEmbossMaskFilter::Make(
31 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)),
32 { { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 64, 16 }));
reed@android.comba974cc2009-05-22 13:48:35 +000033}
34
35static void paint_proc3(SkPaint* paint) {
36 SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE };
senorblanco@chromium.org64cc5792011-05-19 19:58:58 +000037 SkPoint pts[] = { { 3, 0 }, { 7, 5 } };
reed8a21c9f2016-03-08 18:50:00 -080038 paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors),
39 SkShader::kMirror_TileMode));
reed@android.comba974cc2009-05-22 13:48:35 +000040}
41
42static void paint_proc5(SkPaint* paint) {
43 paint_proc3(paint);
44 paint_proc2(paint);
45}
46
47typedef void (*PaintProc)(SkPaint*);
48const PaintProc gPaintProcs[] = {
49 paint_proc0,
50 paint_proc1,
51 paint_proc2,
52 paint_proc3,
53 paint_proc5,
54};
55
56///////////////////////////////////////////////////////////////////////////////
57
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040058class EffectsView : public Sample {
reed@android.comba974cc2009-05-22 13:48:35 +000059public:
60 SkPath fPath;
61 SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)];
62
rmistry@google.comae933ce2012-08-23 18:19:56 +000063 EffectsView() {
reed@android.comba974cc2009-05-22 13:48:35 +000064 size_t i;
65 const float pts[] = {
66 0, 0,
67 10, 0,
68 10, 5,
69 20, -5,
70 10, -15,
71 10, -10,
72 0, -10
73 };
74 fPath.moveTo(pts[0], pts[1]);
75 for (i = 2; i < SK_ARRAY_COUNT(pts); i += 2) {
76 fPath.lineTo(pts[i], pts[i+1]);
77 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000078
reed@android.comba974cc2009-05-22 13:48:35 +000079 for (i = 0; i < SK_ARRAY_COUNT(gPaintProcs); i++) {
80 fPaint[i].setAntiAlias(true);
81 fPaint[i].setColor(COLOR);
82 gPaintProcs[i](&fPaint[i]);
83 }
reed@android.com7d970c72010-04-22 16:07:49 +000084
reed@android.com7d970c72010-04-22 16:07:49 +000085 SkColorMatrix cm;
86 cm.setRotate(SkColorMatrix::kG_Axis, 180);
87 cm.setIdentity();
rmistry@google.comae933ce2012-08-23 18:19:56 +000088
mike@reedtribe.org5fd92432011-05-05 01:59:48 +000089 this->setBGColor(0xFFDDDDDD);
reed@android.comba974cc2009-05-22 13:48:35 +000090 }
rmistry@google.comae933ce2012-08-23 18:19:56 +000091
reed@android.comba974cc2009-05-22 13:48:35 +000092protected:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -040093 virtual bool onQuery(Sample::Event* evt) {
94 if (Sample::TitleQ(*evt)) {
95 Sample::TitleR(evt, "Effects");
reed@android.comba974cc2009-05-22 13:48:35 +000096 return true;
97 }
98 return this->INHERITED::onQuery(evt);
99 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000100
mike@reedtribe.org5fd92432011-05-05 01:59:48 +0000101 virtual void onDrawContent(SkCanvas* canvas) {
reed@android.comba974cc2009-05-22 13:48:35 +0000102 canvas->scale(3, 3);
103 canvas->translate(10, 30);
104 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) {
105 canvas->drawPath(fPath, fPaint[i]);
106 canvas->translate(32, 0);
107 }
108 }
rmistry@google.comae933ce2012-08-23 18:19:56 +0000109
reed@android.comba974cc2009-05-22 13:48:35 +0000110private:
Ben Wagnerb2c4ea62018-08-08 11:36:17 -0400111 typedef Sample INHERITED;
reed@android.comba974cc2009-05-22 13:48:35 +0000112};
113
114///////////////////////////////////////////////////////////////////////////////
115
Ben Wagnerb2c4ea62018-08-08 11:36:17 -0400116DEF_SAMPLE( return new EffectsView(); )