Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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. |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 3 | #include "tools/fiddle/examples.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=b932a2bd68455fb0af2e7a1ed19e36b3 |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Surface_MakeRasterN32Premul, 256, 256, true, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | void 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 |