1 /* 2 * Copyright 2014 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 8 #include "gm.h" 9 10 #include "SkBlurMask.h" 11 #include "SkCanvas.h" 12 #include "SkColorFilter.h" 13 #include "SkEmbossMaskFilter.h" 14 #include "SkFont.h" 15 16 static SkBitmap make_bm() { 17 SkBitmap bm; 18 bm.allocN32Pixels(100, 100); 19 20 SkCanvas canvas(bm); 21 canvas.clear(0); 22 SkPaint paint; 23 paint.setAntiAlias(true); 24 canvas.drawCircle(50, 50, 50, paint); 25 return bm; 26 } 27 28 class EmbossGM : public skiagm::GM { 29 public: 30 EmbossGM() { 31 } 32 33 protected: 34 SkString onShortName() override { 35 return SkString("emboss"); 36 } 37 38 SkISize onISize() override { 39 return SkISize::Make(600, 120); 40 } 41 42 void onDraw(SkCanvas* canvas) override { 43 SkPaint paint; 44 SkBitmap bm = make_bm(); 45 canvas->drawBitmap(bm, 10, 10, &paint); 46 canvas->translate(bm.width() + SkIntToScalar(10), 0); 47 48 paint.setMaskFilter(SkEmbossMaskFilter::Make( 49 SkBlurMask::ConvertRadiusToSigma(3), 50 { { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 128, 16*2 })); 51 canvas->drawBitmap(bm, 10, 10, &paint); 52 canvas->translate(bm.width() + SkIntToScalar(10), 0); 53 54 // this combination of emboss+colorfilter used to crash -- so we exercise it to 55 // confirm that we have a fix. 56 paint.setColorFilter(SkColorFilter::MakeModeFilter(0xFFFF0000, SkBlendMode::kSrcATop)); 57 canvas->drawBitmap(bm, 10, 10, &paint); 58 canvas->translate(bm.width() + SkIntToScalar(10), 0); 59 60 paint.setAntiAlias(true); 61 paint.setStyle(SkPaint::kStroke_Style); 62 paint.setStrokeWidth(SkIntToScalar(10)); 63 paint.setMaskFilter(SkEmbossMaskFilter::Make( 64 SkBlurMask::ConvertRadiusToSigma(4), 65 { { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 128, 16*2 })); 66 paint.setColorFilter(nullptr); 67 paint.setShader(SkShader::MakeColorShader(SK_ColorBLUE)); 68 paint.setDither(true); 69 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50), 70 SkIntToScalar(30), paint); 71 canvas->translate(SkIntToScalar(100), 0); 72 73 paint.setStyle(SkPaint::kFill_Style); 74 canvas->drawString("Hello", 0, 50, SkFont(nullptr, 50), paint); 75 } 76 77 private: 78 typedef skiagm::GM INHERITED; 79 }; 80 81 DEF_GM(return new EmbossGM;) 82