1/* 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 */ 7#include "include/core/SkCanvas.h" 8#include "include/core/SkPaint.h" 9#include "include/effects/SkColorMatrixFilter.h" 10#include "include/effects/SkDiscretePathEffect.h" 11#include "include/effects/SkGradientShader.h" 12#include "samplecode/Sample.h" 13#include "src/core/SkBlurMask.h" 14#include "src/effects/SkEmbossMaskFilter.h" 15 16 17//#define COLOR 0xFFFF8844 18#define COLOR 0xFF888888 19 20static void paint_proc0(SkPaint*) { 21} 22 23static void paint_proc1(SkPaint* paint) { 24 paint->setMaskFilter(SkMaskFilter::MakeBlur( 25 kNormal_SkBlurStyle, 26 SkBlurMask::ConvertRadiusToSigma(2))); 27} 28 29static void paint_proc2(SkPaint* paint) { 30 paint->setMaskFilter(SkEmbossMaskFilter::Make( 31 SkBlurMask::ConvertRadiusToSigma(SkIntToScalar(1)), 32 { { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 64, 16 })); 33} 34 35static void paint_proc3(SkPaint* paint) { 36 SkColor colors[] = { SK_ColorRED, COLOR, SK_ColorBLUE }; 37 SkPoint pts[] = { { 3, 0 }, { 7, 5 } }; 38 paint->setShader(SkGradientShader::MakeLinear(pts, colors, nullptr, SK_ARRAY_COUNT(colors), 39 SkTileMode::kMirror)); 40} 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 58class EffectsView : public Sample { 59public: 60 SkPath fPath; 61 SkPaint fPaint[SK_ARRAY_COUNT(gPaintProcs)]; 62 63 EffectsView() { 64 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 } 78 79 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 } 84 85 this->setBGColor(0xFFDDDDDD); 86 } 87 88protected: 89 SkString name() override { return SkString("Effects"); } 90 91 void onDrawContent(SkCanvas* canvas) override { 92 canvas->scale(3, 3); 93 canvas->translate(10, 30); 94 for (size_t i = 0; i < SK_ARRAY_COUNT(fPaint); i++) { 95 canvas->drawPath(fPath, fPaint[i]); 96 canvas->translate(32, 0); 97 } 98 } 99 100private: 101 using INHERITED = Sample; 102}; 103 104/////////////////////////////////////////////////////////////////////////////// 105 106DEF_SAMPLE( return new EffectsView(); ) 107