Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Functions
UnpremulGPU.cpp File Reference
#include "tools/fiddle/examples.h"

Go to the source code of this file.

Functions

 REG_FIDDLE (UnpremulGPU, 256, 256, false, 6)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( UnpremulGPU  ,
256  ,
256  ,
false  ,
 
)

Definition at line 4 of file UnpremulGPU.cpp.

4 {
5void draw(SkCanvas* canvas) {
6 canvas->clear(0xffa020a0);
8 SkBitmap premulBitmap;
9 premulBitmap.allocPixels(premulInfo);
10 for (int y = 0; y < 10; y++) {
11 for (int x = 0; x < 10; x++) {
12 *(premulBitmap.getAddr32(x, y)) = 0x80808080;
13 }
14 }
15 sk_sp<SkImage> premulImage = premulBitmap.asImage();
16
17 SkImageInfo unpremulInfo = premulInfo.makeAlphaType(kUnpremul_SkAlphaType);
18 SkBitmap unpremulBitmap;
19 unpremulBitmap.allocPixels(unpremulInfo);
20 for (int y = 0; y < 10; y++) {
21 for (int x = 0; x < 10; x++) {
22 *(unpremulBitmap.getAddr32(x, y)) = 0x80FFFFFF;
23 }
24 }
25 sk_sp<SkImage> unpremulImage = unpremulBitmap.asImage();
26
29 paint.setShader(premulImage->makeShader(tile, tile, SkSamplingOptions()));
30 canvas->drawCircle(10.0f, 10.0f, 10.0f, paint);
31
32 paint.setShader(unpremulImage->makeShader(tile, tile, SkSamplingOptions()));
33 canvas->drawCircle(10.0f, 35.0f, 10.0f, paint);
34}
35} // END FIDDLE
kUnpremul_SkAlphaType
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
Definition SkAlphaType.h:29
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
uint32_t * getAddr32(int x, int y) const
Definition SkBitmap.h:1260
void clear(SkColor color)
Definition SkCanvas.h:1199
void drawCircle(SkScalar cx, SkScalar cy, SkScalar radius, const SkPaint &paint)
const Paint & paint
double y
double x
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
static SkImageInfo MakeS32(int width, int height, SkAlphaType at)