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

Go to the source code of this file.

Functions

 REG_FIDDLE (Canvas_accessTopLayerPixels_b, 256, 256, false, 0)
 

Function Documentation

◆ REG_FIDDLE()

REG_FIDDLE ( Canvas_accessTopLayerPixels_b  ,
256  ,
256  ,
false  ,
 
)

Definition at line 4 of file Canvas_accessTopLayerPixels_b.cpp.

4 {
5void draw(SkCanvas* canvas) {
7 SkFont font(fontMgr->matchFamilyStyle(nullptr, {}), 100);
8 canvas->drawString("ABC", 20, 160, font, paint);
9 SkRect layerBounds = SkRect::MakeXYWH(32, 32, 192, 192);
10 canvas->saveLayerAlpha(&layerBounds, 128);
11 canvas->clear(SK_ColorWHITE);
12 canvas->drawString("DEF", 20, 160, font, paint);
13 SkImageInfo imageInfo;
14 size_t rowBytes;
15 SkIPoint origin;
16 uint32_t* access = (uint32_t*) canvas->accessTopLayerPixels(&imageInfo, &rowBytes, &origin);
17 if (access) {
18 int h = imageInfo.height();
19 int v = imageInfo.width();
20 int rowWords = rowBytes / sizeof(uint32_t);
21 for (int y = 0; y < h; ++y) {
22 int newY = (y - h / 2) * 2 + h / 2;
23 if (newY < 0 || newY >= h) {
24 continue;
25 }
26 for (int x = 0; x < v; ++x) {
27 int newX = (x - v / 2) * 2 + v / 2;
28 if (newX < 0 || newX >= v) {
29 continue;
30 }
31 if (access[y * rowWords + x] == SK_ColorBLACK) {
32 access[newY * rowWords + newX] = SK_ColorGRAY;
33 }
34 }
35 }
36 }
37 canvas->restore();
38}
39} // END FIDDLE
constexpr SkColor SK_ColorGRAY
Definition: SkColor.h:113
constexpr SkColor SK_ColorBLACK
Definition: SkColor.h:103
constexpr SkColor SK_ColorWHITE
Definition: SkColor.h:122
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition: aaclip.cpp:27
void restore()
Definition: SkCanvas.cpp:461
int saveLayerAlpha(const SkRect *bounds, U8CPU alpha)
Definition: SkCanvas.h:661
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
void * accessTopLayerPixels(SkImageInfo *info, size_t *rowBytes, SkIPoint *origin=nullptr)
Definition: SkCanvas.cpp:1245
sk_sp< SkTypeface > matchFamilyStyle(const char familyName[], const SkFontStyle &) const
Definition: SkFontMgr.cpp:109
Definition: SkFont.h:35
const Paint & paint
Definition: color_source.cc:38
sk_sp< SkFontMgr > fontMgr
Definition: examples.cpp:32
double y
double x
font
Font Metadata and Metrics.
SkScalar h
int width() const
Definition: SkImageInfo.h:365
int height() const
Definition: SkImageInfo.h:371
static constexpr SkRect MakeXYWH(float x, float y, float w, float h)
Definition: SkRect.h:659