Flutter Engine
The Flutter Engine
Functions
UnpremulBugs.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (UnpremulBugs, 400, 400, false, 6)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( UnpremulBugs  ,
400  ,
400  ,
false  ,
 
)

Definition at line 4 of file UnpremulBugs.cpp.

4 {
5void fill(SkBitmap & b, SkColor c, int n) {
6 for (int y = 0; y < n; y++) {
7 for (int x = 0; x < n; x++) {
8 *(b.getAddr32(x, y)) = c;
9 }
10 }
11}
12
13void doCell(SkCanvas* canvas, float x, float y, SkAlphaType at, SkColor c, int n) {
15 SkBitmap bmp;
16 bmp.allocPixels(info);
17 fill(bmp, c, n);
18 sk_sp<SkImage> img = bmp.asImage();
19
22
23 paint.setShader(img->makeShader(tile, tile, SkSamplingOptions()));
24 canvas->drawRect(SkRect::MakeXYWH(x, y, 50, 50), paint);
25}
26
27void draw(SkCanvas* canvas) {
28 canvas->clear(SK_ColorBLACK);
29
30 doCell(canvas, 0, 0, kPremul_SkAlphaType, 0x80404040, 2);
31 doCell(canvas, 0, 50, kUnpremul_SkAlphaType, 0x80808080, 2);
32 doCell(canvas, 50, 0, kPremul_SkAlphaType, 0x80808080, 2);
33 doCell(canvas, 50, 50, kUnpremul_SkAlphaType, 0x80FFFFFF, 2);
34
35 doCell(canvas, 110, 0, kPremul_SkAlphaType, 0x80404040, 1);
36 doCell(canvas, 110, 50, kUnpremul_SkAlphaType, 0x80808080, 1);
37 doCell(canvas, 160, 0, kPremul_SkAlphaType, 0x80808080, 1);
38 doCell(canvas, 160, 50, kUnpremul_SkAlphaType, 0x80FFFFFF, 1);
39
40 SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 12);
42 paint.setColor(SK_ColorWHITE);
43 canvas->drawString("Premul", 220, 20, font, paint);
44 canvas->drawString("Unpremul", 220, 70, font, paint);
45 canvas->drawString("Gray", 5, 120, font, paint);
46 canvas->drawString("White", 55, 120, font, paint);
47 canvas->drawString("Gray", 115, 120, font, paint);
48 canvas->drawString("White", 165, 120, font, paint);
49
50 canvas->drawString("2x2", 40, 150, font, paint);
51 canvas->drawString("1x1", 150, 150, font, paint);
52}
53} // END FIDDLE
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition: DM.cpp:213
kUnpremul_SkAlphaType
SkAlphaType
Definition: SkAlphaType.h:26
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition: SkAlphaType.h:29
uint32_t SkColor
Definition: SkColor.h:37
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
SkTileMode
Definition: SkTileMode.h:13
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void allocPixels(const SkImageInfo &info, size_t rowBytes)
Definition: SkBitmap.cpp:258
sk_sp< SkImage > asImage() const
Definition: SkBitmap.cpp:645
void drawRect(const SkRect &rect, const SkPaint &paint)
Definition: SkCanvas.cpp:1673
void clear(SkColor color)
Definition: SkCanvas.h:1199
void drawString(const char str[], SkScalar x, SkScalar y, const SkFont &font, const SkPaint &paint)
Definition: SkCanvas.h:1803
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
Definition: SkFont.h:35
sk_sp< SkShader > makeShader(SkTileMode tmx, SkTileMode tmy, const SkSamplingOptions &, const SkMatrix *localMatrix=nullptr) const
Definition: SkImage.cpp:179
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
static bool b
double y
double x
font
Font Metadata and Metrics.
static SkImageInfo MakeS32(int width, int height, SkAlphaType at)
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659