Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
emboss.cpp
Go to the documentation of this file.
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/gm.h"
14#include "include/core/SkFont.h"
19#include "include/core/SkSize.h"
23#include "src/core/SkBlurMask.h"
26
29
31 paint.setAntiAlias(true);
32 surf->getCanvas()->drawCircle(50, 50, 50, paint);
33 return surf->makeImageSnapshot();
34}
35
36class EmbossGM : public skiagm::GM {
37public:
39 }
40
41protected:
42 SkString getName() const override { return SkString("emboss"); }
43
44 SkISize getISize() override { return SkISize::Make(600, 120); }
45
46 void onDraw(SkCanvas* canvas) override {
48 auto img = make_bm();
49 canvas->drawImage(img, 10, 10);
50 canvas->translate(img->width() + SkIntToScalar(10), 0);
51
52 paint.setMaskFilter(SkEmbossMaskFilter::Make(
54 { { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 128, 16*2 }));
55 canvas->drawImage(img, 10, 10, SkSamplingOptions(), &paint);
56 canvas->translate(img->width() + SkIntToScalar(10), 0);
57
58 // this combination of emboss+colorfilter used to crash -- so we exercise it to
59 // confirm that we have a fix.
60 paint.setColorFilter(SkColorFilters::Blend(0xFFFF0000, SkBlendMode::kSrcATop));
61 canvas->drawImage(img, 10, 10, SkSamplingOptions(), &paint);
62 canvas->translate(img->width() + SkIntToScalar(10), 0);
63
64 paint.setAntiAlias(true);
66 paint.setStrokeWidth(SkIntToScalar(10));
67 paint.setMaskFilter(SkEmbossMaskFilter::Make(
69 { { SK_Scalar1, SK_Scalar1, SK_Scalar1 }, 0, 128, 16*2 }));
70 paint.setColorFilter(nullptr);
71 paint.setShader(SkShaders::Color(SK_ColorBLUE));
72 paint.setDither(true);
73 canvas->drawCircle(SkIntToScalar(50), SkIntToScalar(50),
74 SkIntToScalar(30), paint);
75 canvas->translate(SkIntToScalar(100), 0);
76
79 canvas->drawString("Hello", 0, 50, font, paint);
80
81 paint.setShader(nullptr);
82 paint.setColor(SK_ColorGREEN);
83 canvas->drawString("World", 0, 100, font, paint);
84 }
85
86private:
87 using INHERITED = skiagm::GM;
88};
89
90DEF_GM(return new EmbossGM;)
@ kSrcATop
r = s*da + d*(1-sa)
constexpr SkColor SK_ColorBLUE
Definition SkColor.h:135
constexpr SkColor SK_ColorGREEN
Definition SkColor.h:131
#define SK_Scalar1
Definition SkScalar.h:18
#define SkIntToScalar(x)
Definition SkScalar.h:57
SkString getName() const override
Definition emboss.cpp:42
SkISize getISize() override
Definition emboss.cpp:44
EmbossGM()
Definition emboss.cpp:38
void onDraw(SkCanvas *canvas) override
Definition emboss.cpp:46
static SkScalar SK_SPI ConvertRadiusToSigma(SkScalar radius)
void translate(SkScalar dx, SkScalar dy)
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition SkCanvas.h:1803
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
static sk_sp< SkColorFilter > Blend(const SkColor4f &c, sk_sp< SkColorSpace >, SkBlendMode mode)
static sk_sp< SkMaskFilter > Make(SkScalar blurSigma, const Light &light)
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
@ kFill_Style
set to fill geometry
Definition SkPaint.h:193
const Paint & paint
static sk_sp< SkImage > make_bm()
Definition emboss.cpp:27
#define DEF_GM(CODE)
Definition gm.h:40
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
sk_sp< SkTypeface > DefaultPortableTypeface()
static constexpr SkISize Make(int32_t w, int32_t h)
Definition SkSize.h:20
static SkImageInfo MakeN32Premul(int width, int height)