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=dd92db963af190e849894038f39b598a
5 REG_FIDDLE(Canvas_copy_const_SkBitmap, 256, 256, true, 0) {
draw(SkCanvas *)6 void draw(SkCanvas* ) {
7     SkBitmap bitmap;
8     // create a bitmap 5 wide and 11 high
9     bitmap.allocPixels(SkImageInfo::MakeN32Premul(5, 11));
10     SkCanvas canvas(bitmap);
11     canvas.clear(SK_ColorWHITE);  // white is Unpremultiplied, in ARGB order
12     SkPixmap pixmap;  // provides guaranteed access to the drawn pixels
13     if (!canvas.peekPixels(&pixmap)) {
14         SkDebugf("peekPixels should never fail.\n");
15     }
16     const SkPMColor* pixels = pixmap.addr32();  // points to top-left of bitmap
17     SkPMColor pmWhite = pixels[0];  // the Premultiplied format may vary
18     SkPaint paint;  // by default, draws black, 12 point text
19     SkFont font;
20     canvas.drawString("!", 1, 10, font, paint);  // 1 char at baseline (1, 10)
21     for (int y = 0; y < bitmap.height(); ++y) {
22         for (int x = 0; x < bitmap.width(); ++x) {
23             SkDebugf("%c", *pixels++ == pmWhite ? '-' : 'x');
24         }
25         SkDebugf("\n");
26     }
27 }
28 }  // END FIDDLE
29