blob: b580c93d179793f03f1a074fc3cb91970609a173 [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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.
Mike Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04004// HASH=a803910ada4f8733f0b62456afead55f
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Surface_MakeRaster, 256, 256, true, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void 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