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