Flutter Engine
The Flutter Engine
morphology.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2012 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"
11#include "include/core/SkFont.h"
14#include "include/core/SkRect.h"
16#include "include/core/SkSize.h"
21#include "tools/ToolUtils.h"
23
24#define WIDTH 700
25#define HEIGHT 560
26
27namespace skiagm {
28
29class MorphologyGM : public GM {
30public:
32 this->setBGColor(0xFF000000);
33 }
34
35protected:
36 SkString getName() const override { return SkString("morphology"); }
37
38 void onOnceBeforeDraw() override {
40
43 paint.setColor(0xFFFFFFFF);
44 surf->getCanvas()->drawString("ABC", 10, 55, font, paint);
45 surf->getCanvas()->drawString("XYZ", 10, 110, font, paint);
46
47 fImage = surf->makeImageSnapshot();
48 }
49
50 SkISize getISize() override { return SkISize::Make(WIDTH, HEIGHT); }
51
52 void drawClippedBitmap(SkCanvas* canvas, const SkPaint& paint, int x, int y) {
53 canvas->save();
55 canvas->clipIRect(fImage->bounds());
56 canvas->drawImage(fImage, 0, 0, SkSamplingOptions(), &paint);
57 canvas->restore();
58 }
59
60 void onDraw(SkCanvas* canvas) override {
61 struct {
62 int fWidth, fHeight;
63 int fRadiusX, fRadiusY;
64 } samples[] = {
65 { 140, 140, 0, 0 },
66 { 140, 140, 0, 2 },
67 { 140, 140, 2, 0 },
68 { 140, 140, 2, 2 },
69 { 24, 24, 25, 25 },
70 };
72 SkIRect cropRect = SkIRect::MakeXYWH(25, 20, 100, 80);
73
74 for (unsigned j = 0; j < 4; ++j) {
75 for (unsigned i = 0; i < std::size(samples); ++i) {
76 const SkIRect* cr = j & 0x02 ? &cropRect : nullptr;
77 if (j & 0x01) {
78 paint.setImageFilter(SkImageFilters::Erode(
79 samples[i].fRadiusX, samples[i].fRadiusY, nullptr, cr));
80 } else {
81 paint.setImageFilter(SkImageFilters::Dilate(
82 samples[i].fRadiusX, samples[i].fRadiusY, nullptr, cr));
83 }
84 this->drawClippedBitmap(canvas, paint, i * 140, j * 140);
85 }
86 }
87 }
88
89private:
90 sk_sp<SkImage> fImage;
91
92 using INHERITED = GM;
93};
94
95//////////////////////////////////////////////////////////////////////////////
96
97DEF_GM(return new MorphologyGM;)
98
99} // namespace skiagm
#define SkIntToScalar(x)
Definition: SkScalar.h:57
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void clipIRect(const SkIRect &irect, SkClipOp op=SkClipOp::kIntersect)
Definition: SkCanvas.h:991
int save()
Definition: SkCanvas.cpp:447
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
Definition: SkFont.h:35
static sk_sp< SkImageFilter > Erode(SkScalar radiusX, SkScalar radiusY, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
static sk_sp< SkImageFilter > Dilate(SkScalar radiusX, SkScalar radiusY, sk_sp< SkImageFilter > input, const CropRect &cropRect={})
SkIRect bounds() const
Definition: SkImage.h:303
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
void setBGColor(SkColor)
Definition: gm.cpp:159
SkISize getISize() override
Definition: morphology.cpp:50
SkString getName() const override
Definition: morphology.cpp:36
void onOnceBeforeDraw() override
Definition: morphology.cpp:38
void drawClippedBitmap(SkCanvas *canvas, const SkPaint &paint, int x, int y)
Definition: morphology.cpp:52
void onDraw(SkCanvas *canvas) override
Definition: morphology.cpp:60
const Paint & paint
Definition: color_source.cc:38
#define WIDTH
Definition: morphology.cpp:24
#define HEIGHT
Definition: morphology.cpp:25
double y
double x
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
sk_sp< SkTypeface > DefaultPortableTypeface()
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259
font
Font Metadata and Metrics.
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
SkSamplingOptions(SkFilterMode::kLinear))
Definition: SkRect.h:32
static constexpr SkIRect MakeXYWH(int32_t x, int32_t y, int32_t w, int32_t h)
Definition: SkRect.h:104
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static SkImageInfo MakeN32Premul(int width, int height)