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=8e6530b26ab4096a9a91cfaadda1c568 |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Surface_MakeRasterDirectReleaseProc, 256, 256, true, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 6 | static void release_direct_surface_storage(void* pixels, void* context) { |
| 7 | if (pixels == context) { |
| 8 | SkDebugf("expected release context\n"); |
| 9 | } |
| 10 | sk_free(pixels); |
| 11 | } |
| 12 | |
| 13 | void draw(SkCanvas* ) { |
| 14 | SkImageInfo info = SkImageInfo::MakeN32Premul(3, 3); |
| 15 | const size_t rowBytes = info.minRowBytes(); |
| 16 | void* pixels = sk_malloc_throw(info.computeByteSize(rowBytes)); |
| 17 | sk_sp<SkSurface> surface(SkSurface::MakeRasterDirectReleaseProc(info, pixels, rowBytes, |
| 18 | release_direct_surface_storage, pixels)); |
| 19 | SkCanvas* canvas = surface->getCanvas(); |
| 20 | canvas->clear(SK_ColorWHITE); |
| 21 | SkPMColor* colorPtr = (SkPMColor*) pixels; |
| 22 | SkPMColor pmWhite = colorPtr[0]; |
| 23 | SkPaint paint; |
| 24 | canvas->drawPoint(1, 1, paint); |
| 25 | canvas->flush(); // ensure that point was drawn |
| 26 | for (int y = 0; y < info.height(); ++y) { |
| 27 | for (int x = 0; x < info.width(); ++x) { |
| 28 | SkDebugf("%c", *colorPtr++ == pmWhite ? '-' : 'x'); |
| 29 | } |
| 30 | SkDebugf("\n"); |
| 31 | } |
| 32 | } |
| 33 | } // END FIDDLE |