Flutter Engine
The Flutter Engine
ninepatchstretch.cpp
Go to the documentation of this file.
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
8#include "gm/gm.h"
14#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
20#include "tools/ToolUtils.h"
21
25}
26
28 const int kFixed = 28;
29 const int kStretchy = 8;
30 const int kSize = 2*kFixed + kStretchy;
31
33 SkCanvas* canvas = surface->getCanvas();
34
37 const SkScalar radius = SkIntToScalar(kFixed) - strokeWidth/2;
38
39 center->setXYWH(kFixed, kFixed, kStretchy, kStretchy);
40
42 paint.setAntiAlias(true);
43
44 paint.setColor(0xFFFF0000);
45 canvas->drawRoundRect(r, radius, radius, paint);
46 r.setXYWH(SkIntToScalar(kFixed), 0, SkIntToScalar(kStretchy), SkIntToScalar(kSize));
47 paint.setColor(0x8800FF00);
48 canvas->drawRect(r, paint);
49 r.setXYWH(0, SkIntToScalar(kFixed), SkIntToScalar(kSize), SkIntToScalar(kStretchy));
50 paint.setColor(0x880000FF);
51 canvas->drawRect(r, paint);
52
53 return surface->makeImageSnapshot();
54}
55
57public:
60
62
63protected:
64 SkString getName() const override { return SkString("ninepatch-stretch"); }
65
66 SkISize getISize() override { return SkISize::Make(760, 800); }
67
68 void onDraw(SkCanvas* canvas) override {
69 if (!fImage || !fImage->isValid(canvas->recordingContext())) {
70 fImage = make_image(canvas, &fCenter);
71 }
72
73 // amount of bm that should not be stretched (unless we have to)
74 const SkScalar fixed = SkIntToScalar(fImage->width() - fCenter.width());
75
76 const SkSize size[] = {
77 { fixed * 4 / 5, fixed * 4 / 5 }, // shrink in both axes
78 { fixed * 4 / 5, fixed * 4 }, // shrink in X
79 { fixed * 4, fixed * 4 / 5 }, // shrink in Y
80 { fixed * 4, fixed * 4 }
81 };
82
83 canvas->drawImage(fImage, 10, 10);
84
87
90 for (int iy = 0; iy < 2; ++iy) {
91 for (int ix = 0; ix < 2; ++ix) {
92 int i = ix * 2 + iy;
93 SkRect r = SkRect::MakeXYWH(x + ix * fixed, y + iy * fixed,
94 size[i].width(), size[i].height());
95 canvas->drawImageNine(fImage.get(), fCenter, r, fm);
96 }
97 }
98 canvas->translate(0, 400);
99 }
100 }
101
102private:
103 using INHERITED = skiagm::GM;
104};
105DEF_GM( return new NinePatchStretchGM; )
static const int strokeWidth
Definition: BlurTest.cpp:60
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
#define SkIntToScalar(x)
Definition: SkScalar.h:57
static SkScalar center(float pos0, float pos1)
#define N
Definition: beziers.cpp:19
SkISize getISize() override
void onDraw(SkCanvas *canvas) override
SkString getName() const override
sk_sp< SkImage > fImage
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void drawImageNine(const SkImage *image, const SkIRect &center, const SkRect &dst, SkFilterMode filter, const SkPaint *paint=nullptr)
Definition: SkCanvas.cpp:1769
virtual GrRecordingContext * recordingContext() const
Definition: SkCanvas.cpp:1637
void drawRoundRect(const SkRect &rect, SkScalar rx, SkScalar ry, const SkPaint &paint)
Definition: SkCanvas.cpp:2717
void drawImage(const SkImage *image, SkScalar left, SkScalar top)
Definition: SkCanvas.h:1528
int width() const
Definition: SkImage.h:285
virtual bool isValid(GrRecordingContext *context) const =0
T * get() const
Definition: SkRefCnt.h:303
Definition: gm.h:110
SkScalar width()
Definition: gm.h:159
SkScalar height()
Definition: gm.h:162
const Paint & paint
Definition: color_source.cc:38
VkSurfaceKHR surface
Definition: main.cc:49
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
constexpr int kSize
double y
double x
sk_sp< SkSurface > makeSurface(SkCanvas *canvas, const SkImageInfo &info, const SkSurfaceProps *props)
Definition: ToolUtils.cpp:512
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
string root
Definition: scale_cpu.py:20
static sk_sp< SkSurface > make_surface(SkCanvas *root, int N)
static sk_sp< SkImage > make_image(SkCanvas *root, SkIRect *center)
Definition: SkRect.h:32
constexpr int32_t width() const
Definition: SkRect.h:158
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)
void setXYWH(float x, float y, float width, float height)
Definition: SkRect.h:931
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
Definition: SkSize.h:52