Flutter Engine
The Flutter Engine
drawminibitmaprect.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2015 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"
16#include "include/core/SkRect.h"
20#include "include/core/SkSize.h"
26#include "src/base/SkMathPriv.h"
27#include "src/base/SkRandom.h"
28#include "tools/GpuToolUtils.h"
29#include "tools/ToolUtils.h"
30
31static sk_sp<SkImage> makebm(int w, int h) {
34 SkCanvas* canvas = surface->getCanvas();
35
36 const SkScalar wScalar = SkIntToScalar(w);
37 const SkScalar hScalar = SkIntToScalar(h);
38
39 const SkPoint pt = { wScalar / 2, hScalar / 2 };
40
41 const SkScalar radius = 4 * std::max(wScalar, hScalar);
42
47
48 constexpr SkScalar pos[] = {0,
49 SK_Scalar1 / 6,
50 2 * SK_Scalar1 / 6,
51 3 * SK_Scalar1 / 6,
52 4 * SK_Scalar1 / 6,
53 5 * SK_Scalar1 / 6,
55
58 SkRect rect = SkRect::MakeWH(wScalar, hScalar);
59 SkMatrix mat = SkMatrix::I();
60 for (int i = 0; i < 4; ++i) {
62 pt, radius,
63 colors, pos,
66 0, &mat));
67 canvas->drawRect(rect, paint);
68 rect.inset(wScalar / 8, hScalar / 8);
69 mat.postScale(SK_Scalar1 / 4, SK_Scalar1 / 4);
70 }
71 return surface->makeImageSnapshot();
72}
73
74constexpr int gSize = 1024;
75constexpr int gSurfaceSize = 2048;
76
77// This GM calls drawImageRect several times using the same texture. This is intended to exercise
78// combining GrDrawOps during these calls.
80public:
81 DrawMiniBitmapRectGM(bool antiAlias) : fAA(antiAlias) {
82 fName.set("drawminibitmaprect");
83 if (fAA) {
84 fName.appendf("_aa");
85 }
86 }
87
88protected:
89 SkString getName() const override { return fName; }
90
91 SkISize getISize() override { return SkISize::Make(gSize, gSize); }
92
93 void onDraw(SkCanvas* canvas) override {
94 if (nullptr == fImage) {
96 }
97
98 const SkRect dstRect = { 0, 0, SkIntToScalar(64), SkIntToScalar(64)};
99 const int kMaxSrcRectSize = 1 << (SkNextLog2(gSurfaceSize) + 2);
100
101 constexpr int kPadX = 30;
102 constexpr int kPadY = 40;
103
104 int rowCount = 0;
105 canvas->translate(SkIntToScalar(kPadX), SkIntToScalar(kPadY));
106 canvas->save();
107 SkRandom random;
108
110 paint.setAntiAlias(fAA);
111 for (int w = 1; w <= kMaxSrcRectSize; w *= 3) {
112 for (int h = 1; h <= kMaxSrcRectSize; h *= 3) {
113
114 const SkIRect srcRect =
115 SkIRect::MakeXYWH((gSurfaceSize - w) / 2, (gSurfaceSize - h) / 2, w, h);
116 canvas->save();
117 switch (random.nextU() % 3) {
118 case 0:
119 canvas->rotate(random.nextF() * 10.f);
120 break;
121 case 1:
122 canvas->rotate(-random.nextF() * 10.f);
123 break;
124 case 2:
125 // rect stays rect
126 break;
127 }
128 canvas->drawImageRect(fImage.get(), SkRect::Make(srcRect), dstRect,
131 canvas->restore();
132
133 canvas->translate(dstRect.width() + SK_Scalar1 * kPadX, 0);
134 ++rowCount;
135 if ((dstRect.width() + 2 * kPadX) * rowCount > gSize) {
136 canvas->restore();
137 canvas->translate(0, dstRect.height() + SK_Scalar1 * kPadY);
138 canvas->save();
139 rowCount = 0;
140 }
141 }
142 }
143 canvas->restore();
144 }
145
146private:
147 bool fAA;
148 sk_sp<SkImage> fImage;
149 SkString fName;
150
151 using INHERITED = skiagm::GM;
152};
153
154DEF_GM( return new DrawMiniBitmapRectGM(true); )
155DEF_GM( return new DrawMiniBitmapRectGM(false); )
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
SkPoint pos
#define SkASSERT(cond)
Definition: SkAssert.h:116
constexpr SkColor SK_ColorYELLOW
Definition: SkColor.h:139
constexpr SkColor SK_ColorMAGENTA
Definition: SkColor.h:147
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorCYAN
Definition: SkColor.h:143
constexpr SkColor SK_ColorBLUE
Definition: SkColor.h:135
constexpr SkColor SK_ColorRED
Definition: SkColor.h:126
constexpr SkColor SK_ColorGREEN
Definition: SkColor.h:131
static int SkNextLog2(uint32_t value)
Definition: SkMathPriv.h:238
#define SK_Scalar1
Definition: SkScalar.h:18
#define SkIntToScalar(x)
Definition: SkScalar.h:57
SkString getName() const override
SkISize getISize() override
DrawMiniBitmapRectGM(bool antiAlias)
void onDraw(SkCanvas *canvas) override
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void restore()
Definition: SkCanvas.cpp:461
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
@ kFast_SrcRectConstraint
sample outside bounds; faster
Definition: SkCanvas.h:1543
void rotate(SkScalar degrees)
Definition: SkCanvas.cpp:1300
void drawImageRect(const SkImage *, const SkRect &src, const SkRect &dst, const SkSamplingOptions &, const SkPaint *, SrcRectConstraint)
Definition: SkCanvas.cpp:2333
int save()
Definition: SkCanvas.cpp:447
static sk_sp< SkShader > MakeRadial(const SkPoint &center, SkScalar radius, const SkColor colors[], const SkScalar pos[], int count, SkTileMode mode, uint32_t flags=0, const SkMatrix *localMatrix=nullptr)
SkMatrix & postScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:360
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
uint32_t nextU()
Definition: SkRandom.h:42
float nextF()
Definition: SkRandom.h:55
void set(const SkString &src)
Definition: SkString.h:186
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition: SkString.cpp:550
T * get() const
Definition: SkRefCnt.h:303
Definition: gm.h:110
const Paint & paint
Definition: color_source.cc:38
constexpr int gSurfaceSize
constexpr int gSize
static sk_sp< SkImage > makebm(int w, int h)
VkSurfaceKHR surface
Definition: main.cc:49
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
static float max(float r, float g, float b)
Definition: hsl.cpp:49
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
PODArray< SkColor > colors
Definition: SkRecords.h:276
SK_API sk_sp< SkSurface > Raster(const SkImageInfo &imageInfo, size_t rowBytes, const SkSurfaceProps *surfaceProps)
sk_sp< SkImage > MakeTextureImage(SkCanvas *canvas, sk_sp< SkImage > orig)
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
SkScalar w
SkScalar h
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)
static SkRect Make(const SkISize &size)
Definition: SkRect.h:669
constexpr float height() const
Definition: SkRect.h:769
constexpr float width() const
Definition: SkRect.h:762
static constexpr SkRect MakeWH(float w, float h)
Definition: SkRect.h:609