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=8e6530b26ab4096a9a91cfaadda1c568
5 REG_FIDDLE(Surface_MakeRasterDirectReleaseProc, 256, 256, true, 0) {
release_direct_surface_storage(void * pixels,void * context)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
draw(SkCanvas *)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
34