Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Canvas_MakeRasterDirect.cpp
Go to the documentation of this file.
1// Copyright 2019 Google LLC.
2// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
4// HASH=525285073aae7e53eb8f454a398f880c
5REG_FIDDLE(Canvas_MakeRasterDirect, 256, 256, true, 0) {
6void draw(SkCanvas*) {
7 SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); // device aligned, 32 bpp, Premultiplied
8 const size_t minRowBytes = info.minRowBytes(); // bytes used by one bitmap row
9 const size_t size = info.computeMinByteSize(); // bytes used by all rows
10 SkPMColor* pixels = new SkPMColor[size]; // allocate storage for pixels
11 // create a SkCanvas backed by a raster device, and delete it when the
12 // function goes out of scope.
13 std::unique_ptr<SkCanvas> canvas = SkCanvas::MakeRasterDirect(info, pixels, minRowBytes);
14 canvas->clear(SK_ColorWHITE); // white is Unpremultiplied, in ARGB order
15 SkPMColor pmWhite = pixels[0]; // the Premultiplied format may vary
16 SkPaint paint; // by default, draws black
17 canvas->drawPoint(1, 1, paint); // draw in the center
18 for (int y = 0; y < info.height(); ++y) {
19 for (int x = 0; x < info.width(); ++x) {
20 SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
21 }
22 SkDebugf("\n");
23 }
24 delete[] pixels;
25}
26} // END FIDDLE
static void info(const char *fmt,...) SK_PRINTF_LIKE(1
Definition DM.cpp:213
uint32_t SkPMColor
Definition SkColor.h:205
constexpr SkColor SK_ColorWHITE
Definition SkColor.h:122
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static void draw(SkCanvas *canvas, SkRect &target, int x, int y)
Definition aaclip.cpp:27
static std::unique_ptr< SkCanvas > MakeRasterDirect(const SkImageInfo &info, void *pixels, size_t rowBytes, const SkSurfaceProps *props=nullptr)
const Paint & paint
#define REG_FIDDLE(NAME, W, H, TEXT, I)
Definition examples.h:60
double y
double x
static SkImageInfo MakeN32Premul(int width, int height)