blob: 3de585ba4e7e63341629ffeccedd6723a4582e4e [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=b932a2bd68455fb0af2e7a1ed19e36b3
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Surface_MakeRasterN32Premul, 256, 256, true, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* ) {
7 sk_sp<SkSurface> surface(SkSurface::MakeRasterN32Premul(3, 3));
8 SkCanvas* canvas = surface->getCanvas();
9 canvas->clear(SK_ColorWHITE);
10 SkPixmap pixmap;
11 if (surface->peekPixels(&pixmap)) {
12 const uint32_t* colorPtr = pixmap.addr32();
13 SkPMColor pmWhite = colorPtr[0];
14 SkPaint paint;
15 canvas->drawPoint(1, 1, paint);
16 canvas->flush(); // ensure that point was drawn
17 for (int y = 0; y < surface->height(); ++y) {
18 for (int x = 0; x < surface->width(); ++x) {
19 SkDebugf("%c", colorPtr[x] == pmWhite ? '-' : 'x');
20 }
21 colorPtr += surface->width();
22 SkDebugf("\n");
23 }
24 }
25}
26} // END FIDDLE