1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC.
2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h"
4cb93a386Sopenharmony_ci// HASH=c26cfae4c42cb445240335cc12a50235
5cb93a386Sopenharmony_ciREG_FIDDLE(Canvas_const_SkBitmap_const_SkSurfaceProps, 256, 256, true, 0) {
6cb93a386Sopenharmony_civoid draw(SkCanvas* ) {
7cb93a386Sopenharmony_ci    SkBitmap bitmap;
8cb93a386Sopenharmony_ci    // create a bitmap 5 wide and 11 high
9cb93a386Sopenharmony_ci    bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11));
10cb93a386Sopenharmony_ci    SkCanvas canvas(bitmap, SkSurfaceProps(0, kUnknown_SkPixelGeometry));
11cb93a386Sopenharmony_ci    canvas.clear(SK_ColorWHITE);  // white is Unpremultiplied, in ARGB order
12cb93a386Sopenharmony_ci    SkPixmap pixmap;  // provides guaranteed access to the drawn pixels
13cb93a386Sopenharmony_ci    if (!canvas.peekPixels(&pixmap)) {
14cb93a386Sopenharmony_ci        SkDebugf("peekPixels should never fail.\n");
15cb93a386Sopenharmony_ci    }
16cb93a386Sopenharmony_ci    const SkPMColor* pixels = pixmap.addr32();  // points to top-left of bitmap
17cb93a386Sopenharmony_ci    SkPMColor pmWhite = pixels[0];  // the Premultiplied format may vary
18cb93a386Sopenharmony_ci    SkPaint paint;  // by default, draws black, 12 point text
19cb93a386Sopenharmony_ci    SkFont font;
20cb93a386Sopenharmony_ci    canvas.drawString("!", 1, 10, font, paint);  // 1 char at baseline (1, 10)
21cb93a386Sopenharmony_ci    for (int y = 0; y < bitmap.height(); ++y) {
22cb93a386Sopenharmony_ci        for (int x = 0; x < bitmap.width(); ++x) {
23cb93a386Sopenharmony_ci            SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
24cb93a386Sopenharmony_ci        }
25cb93a386Sopenharmony_ci        SkDebugf("\n");
26cb93a386Sopenharmony_ci    }
27cb93a386Sopenharmony_ci}
28cb93a386Sopenharmony_ci}  // END FIDDLE
29