Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 5 of file Canvas_accessTopLayerPixels_b.cpp.

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