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.
3 #include "tools/fiddle/examples.h"
4 REG_FIDDLE(Surface_MakeRaster, 256, 256, true, 0) {
draw(SkCanvas *)5 void draw(SkCanvas* ) {
6 SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3);
7 const size_t rowBytes = 64;
8 sk_sp<SkSurface> surface(SkSurfaces::Raster(info, rowBytes, nullptr));
9 SkCanvas* canvas = surface->getCanvas();
10 canvas->clear(SK_ColorWHITE);
11 SkPixmap pixmap;
12 if (surface->peekPixels(&pixmap)) {
13 const uint32_t* colorPtr = pixmap.addr32();
14 SkPMColor pmWhite = colorPtr[0];
15 SkPaint paint;
16 canvas->drawPoint(1, 1, paint);
17 for (int y = 0; y < info.height(); ++y) {
18 for (int x = 0; x < info.width(); ++x) {
19 SkDebugf("%c", colorPtr[x] == pmWhite ? '-' : 'x');
20 }
21 colorPtr += rowBytes / sizeof(colorPtr[0]);
22 SkDebugf("\n");
23 }
24 }
25 }
26 } // END FIDDLE
27