Flutter Engine
The Flutter Engine
UnpremulGPU.cpp
Go to the documentation of this file.
1// Copyright 2020 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4REG_FIDDLE(UnpremulGPU, 256, 256, false, 6) {
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
REG_FIDDLE(UnpremulGPU, 256, 256, false, 6)
Definition: UnpremulGPU.cpp:4
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)
Definition: SkCanvas.cpp:2707
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
double y
double x
SkImageInfo makeAlphaType(SkAlphaType newAlphaType) const
Definition: SkImageInfo.h:466
static SkImageInfo MakeS32(int width, int height, SkAlphaType at)