blob: 6d4c2bcbf9ae61ccd2d1a11a2e71db29a6888c39 [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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 Kleinc0bd9f92019-04-23 12:05:21 -05003#include "tools/fiddle/examples.h"
Hal Canary87515122019-03-15 14:22:51 -04004// HASH=8e6530b26ab4096a9a91cfaadda1c568
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Surface_MakeRasterDirectReleaseProc, 256, 256, true, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006static 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
13void 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