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=b932a2bd68455fb0af2e7a1ed19e36b3
5REG_FIDDLE(Surface_MakeRasterN32Premul, 256, 256, true, 0) {
6void 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
27