blob: 24a519aa9406a993078219f98237f7477d4f29c9 [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"
Kevin Lubick5c93acf2023-05-09 12:11:43 -04004REG_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 Canary87515122019-03-15 14:22:51 -04008 }
Kevin Lubick5c93acf2023-05-09 12:11:43 -04009 sk_free(pixels);
Hal Canary87515122019-03-15 14:22:51 -040010 }
Kevin Lubick5c93acf2023-05-09 12:11:43 -040011
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 Lubick5c93acf2023-05-09 12:11:43 -040024 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 Canary87515122019-03-15 14:22:51 -040031} // END FIDDLE