Flutter Engine
The Flutter Engine
bmpfilterqualityrepeat.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"
11#include "include/core/SkFont.h"
14#include "include/core/SkRect.h"
17#include "include/core/SkSize.h"
22#include "tools/ToolUtils.h"
24
25// Inspired by svg/as-border-image/svg-as-border-image.html. Draws a four-color checker board bitmap
26// such that it is stretched and repeat tiled with different filter qualities. It is testing whether
27// the bmp filter respects the repeat mode at the tile seams.
29public:
31
32protected:
33
34 void onOnceBeforeDraw() override {
35 fBmp.allocN32Pixels(40, 40, true);
36 SkCanvas canvas(fBmp);
37 SkBitmap colorBmp;
38 colorBmp.allocN32Pixels(20, 20, true);
39 colorBmp.eraseColor(0xFFFF0000);
40 canvas.drawImage(colorBmp.asImage(), 0, 0);
41 colorBmp.eraseColor(ToolUtils::color_to_565(0xFF008200));
42 canvas.drawImage(colorBmp.asImage(), 20, 0);
43 colorBmp.eraseColor(ToolUtils::color_to_565(0xFFFF9000));
44 canvas.drawImage(colorBmp.asImage(), 0, 20);
45 colorBmp.eraseColor(ToolUtils::color_to_565(0xFF2000FF));
46 canvas.drawImage(colorBmp.asImage(), 20, 20);
47 }
48
49 SkString getName() const override { return SkString("bmp_filter_quality_repeat"); }
50
51 SkISize getISize() override { return SkISize::Make(1000, 400); }
52
53 void onDraw(SkCanvas* canvas) override {
54 this->drawAll(canvas, 2.5f);
55 canvas->translate(0, 250);
56 canvas->scale(0.5, 0.5);
57 this->drawAll(canvas, 1);
58 }
59
60private:
61 void drawAll(SkCanvas* canvas, SkScalar scaleX) const {
62 SkRect rect = SkRect::MakeLTRB(20, 60, 220, 210);
63 SkMatrix lm = SkMatrix::I();
64 lm.setScaleX(scaleX);
65 lm.setTranslateX(423);
66 lm.setTranslateY(330);
67
68 SkPaint textPaint;
69 textPaint.setAntiAlias(true);
70
71 SkPaint bmpPaint(textPaint);
72
74
75 SkAutoCanvasRestore acr(canvas, true);
76
77 const struct {
78 const char* name;
80 } recs[] = {
85 };
86
87 for (const auto& rec : recs) {
88 constexpr SkTileMode kTM = SkTileMode::kRepeat;
89 bmpPaint.setShader(fBmp.makeShader(kTM, kTM, rec.sampling, lm));
90 canvas->drawRect(rect, bmpPaint);
91 canvas->drawString(rec.name, 20, 40, font, textPaint);
92 canvas->translate(250, 0);
93 }
94
95 }
96
97 SkBitmap fBmp;
98
99 using INHERITED = skiagm::GM;
100};
101
102//////////////////////////////////////////////////////////////////////////////
103
SkTileMode
Definition: SkTileMode.h:13
void onDraw(SkCanvas *canvas) override
SkString getName() const override
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkBitmap.cpp:669
void allocN32Pixels(int width, int height, bool isOpaque=false)
Definition: SkBitmap.cpp:232
void eraseColor(SkColor4f) const
Definition: SkBitmap.cpp:442
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void translate(SkScalar dx, SkScalar dy)
Definition: SkCanvas.cpp:1278
void scale(SkScalar sx, SkScalar sy)
Definition: SkCanvas.cpp:1289
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
Definition: SkFont.h:35
SkMatrix & setTranslateY(SkScalar v)
Definition: SkMatrix.h:530
SkMatrix & setTranslateX(SkScalar v)
Definition: SkMatrix.h:524
static const SkMatrix & I()
Definition: SkMatrix.cpp:1544
SkMatrix & setScaleX(SkScalar v)
Definition: SkMatrix.h:500
void setAntiAlias(bool aa)
Definition: SkPaint.h:170
Definition: gm.h:110
void setBGColor(SkColor)
Definition: gm.cpp:159
float SkScalar
Definition: extension.cpp:12
#define DEF_GM(CODE)
Definition: gm.h:40
sk_sp< SkBlender > blender SkRect rect
Definition: SkRecords.h:350
SkSamplingOptions sampling
Definition: SkRecords.h:337
SkFont DefaultPortableFont()
SkColor color_to_565(SkColor color)
Definition: ToolUtils.cpp:139
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
font
Font Metadata and Metrics.
SkSamplingOptions(SkFilterMode::kLinear))
static constexpr SkCubicResampler Mitchell()
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20
static constexpr SkRect MakeLTRB(float l, float t, float r, float b)
Definition: SkRect.h:646