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