Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
purplestamp.cpp
Go to the documentation of this file.
1// Copyright 2020 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4REG_FIDDLE(purplestamp, 256, 256, false, 0) {
5// purplestamp
6
7// Whether to use a separate bitmap (with a color type) at all.
8bool drawWithRasterImage = true;
9
10// This works with either kN32_SkColorType or kAlpha_8_SkColorType.
11// Applies only if drawWithRasterImage is true.
12SkColorType colorType = kN32_SkColorType;
13
14void drawStamp(SkCanvas* canvas, int size) {
15 canvas->save();
16 canvas->clipRect(SkRect::MakeWH(size, size), SkClipOp::kIntersect, true);
17
18 canvas->clear(0x3F000000 /* translucent black */);
19
21 paint.setAntiAlias(true);
22 paint.setColor(SK_ColorBLACK);
23 canvas->drawRRect(
24 SkRRect::MakeOval(SkRect::MakeXYWH(size / 4, size / 4, size / 2, size / 2)), paint);
25
27 paint.setStrokeWidth(20);
28 canvas->drawRect(SkRect::MakeWH(size, size), paint);
29
30 canvas->restore();
31}
32
33sk_sp<SkImage> stampImage(int size) {
36 drawStamp(surface->getCanvas(), size);
37 return surface->makeImageSnapshot();
38}
39
40void draw(SkCanvas* canvas) {
42 paint.setColorFilter(SkColorFilters::Blend(0xFF7F00FF, SkBlendMode::kSrcIn));
43 paint.setAntiAlias(true);
44
46
47 canvas->rotate(30);
48 canvas->translate(60, 0);
49
50 int stampSize = 200;
51 if (drawWithRasterImage) {
52 canvas->drawImage(stampImage(stampSize), 0, 0, sampling, &paint);
53 } else {
54 canvas->saveLayer(nullptr, &paint);
55 drawStamp(canvas, stampSize);
56 canvas->restore();
57 }
58}
59} // END FIDDLE
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
@ kSrcIn
r = s * da
SkColorType
Definition SkColorType.h:19
constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103
static SkColorType colorType(AImageDecoder *decoder, const AImageDecoderHeaderInfo *headerInfo)
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
int saveLayer(const SkRect *bounds, const SkPaint *paint)
Definition SkCanvas.cpp:500
void drawRect(const SkRect &rect, const SkPaint &paint)
void clipRect(const SkRect &rect, SkClipOp op, bool doAntiAlias)
void restore()
Definition SkCanvas.cpp:465
void translate(SkScalar dx, SkScalar dy)
void clear(SkColor color)
Definition SkCanvas.h:1199
void rotate(SkScalar degrees)
void drawRRect(const SkRRect &rrect, const SkPaint &paint)
int save()
Definition SkCanvas.cpp:451
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition SkCanvas.h:1528
static sk_sp< SkColorFilter > Blend(const SkColor4f &c, sk_sp< SkColorSpace >, SkBlendMode mode)
@ kStroke_Style
set to stroke geometry
Definition SkPaint.h:194
static SkRRect MakeOval(const SkRect &oval)
Definition SkRRect.h:162
const Paint & paint
VkSurfaceKHR surface
Definition main.cc:49
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition SkRect.h:659
static constexpr SkRect MakeWH(float w, float h)
Definition SkRect.h:609