Flutter Engine
The Flutter Engine
tiledscaledbitmap.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2014 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"
15#include "include/core/SkSize.h"
18
19 /***
20 *
21 * This GM reproduces Skia bug 2904, in which a tiled bitmap shader was failing to draw correctly
22 * when fractional image scaling was ignored by the high quality bitmap scaler.
23 *
24 ***/
25
26namespace skiagm {
27
28class TiledScaledBitmapGM : public GM {
29public:
30
32 }
33
34protected:
35 SkString getName() const override { return SkString("tiledscaledbitmap"); }
36
37 SkISize getISize() override { return SkISize::Make(1016, 616); }
38
39 static SkBitmap make_bm(int width, int height) {
40 SkBitmap bm;
43 SkCanvas canvas(bm);
45 paint.setAntiAlias(true);
46 canvas.drawCircle(width/2.f, height/2.f, width/4.f, paint);
47 return bm;
48 }
49
50 void onOnceBeforeDraw() override {
51 fBitmap = make_bm(360, 288);
52 }
53
54 void onDraw(SkCanvas* canvas) override {
56
57 paint.setAntiAlias(true);
58
59 SkMatrix mat;
60 mat.setScale(121.f/360.f, 93.f/288.f);
61 mat.postTranslate(-72, -72);
62
65 canvas->drawRect({ 8, 8, 1008, 608 }, paint);
66 }
67
68private:
69 SkBitmap fBitmap;
70
71 using INHERITED = GM;
72};
73
74//////////////////////////////////////////////////////////////////////////////
75
76DEF_GM(return new TiledScaledBitmapGM;)
77} // namespace skiagm
constexpr SkColor SK_ColorTRANSPARENT
Definition: SkColor.h:99
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 drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
Definition: SkCanvas.cpp:2707
SkMatrix & postTranslate(SkScalar dx, SkScalar dy)
Definition: SkMatrix.cpp:281
SkMatrix & setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition: SkMatrix.cpp:296
Definition: gm.h:110
GM(SkColor backgroundColor=SK_ColorWHITE)
Definition: gm.cpp:81
SkScalar width()
Definition: gm.h:159
SkScalar height()
Definition: gm.h:162
void onDraw(SkCanvas *canvas) override
static SkBitmap make_bm(int width, int height)
SkString getName() const override
const Paint & paint
Definition: color_source.cc:38
DEF_GM(return F(C(clipbox), 0.0f, 0.0f, {})) DEF_GM(return F(C(clipbox)
static constexpr SkCubicResampler Mitchell()
Definition: SkSize.h:16
static constexpr SkISize Make(int32_t w, int32_t h)
Definition: SkSize.h:20