xref: /aosp_15_r20/external/skia/docs/examples/Surface_MakeRaster_2.cpp (revision c8dee2aa9b3f27cf6c858bd81872bdeb2c07ed17)
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_MakeRaster_2, 256, 256, true, 0) {
draw(SkCanvas *)5 void draw(SkCanvas* ) {
6     SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3);
7     sk_sp<SkSurface> surface(SkSurfaces::Raster(info));
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         for (int y = 0; y < info.height(); ++y) {
17             for (int x = 0; x < info.width(); ++x) {
18                 SkDebugf("%c", colorPtr[x] == pmWhite ? '-' : 'x');
19             }
20             colorPtr += info.width();
21             SkDebugf("\n");
22         }
23     }
24 }
25 }  // END FIDDLE
26