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_MakeRasterDirect, 256, 256, true, 0) {
draw(SkCanvas *)5 void draw(SkCanvas*) {
6 SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3);
7 const size_t size = info.computeMinByteSize();
8 SkPMColor* pixels = new SkPMColor[size];
9 sk_sp<SkSurface> surface(SkSurfaces::WrapPixels(info, pixels, info.minRowBytes()));
10 SkCanvas* canvas = surface->getCanvas();
11 canvas->clear(SK_ColorWHITE);
12 SkPMColor pmWhite = pixels[0];
13 SkPaint paint;
14 canvas->drawPoint(1, 1, paint);
15 for (int y = 0; y < info.height(); ++y) {
16 for (int x = 0; x < info.width(); ++x) {
17 SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
18 }
19 SkDebugf("\n");
20 }
21 delete[] pixels;
22 }
23 } // END FIDDLE
24