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=102d014d7f753db2a9b9ee08893aaf11
5 REG_FIDDLE(Canvas_readPixels_a, 64, 64, false, 0) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7 canvas->clear(SK_ColorBLUE);
8 SkPaint paint;
9 canvas->drawCircle(32, 32, 28, paint);
10 SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
11 sk_sp<SkData> data(SkData::MakeUninitialized(info.minRowBytes() * info.height()));
12 sk_bzero(data->writable_data(), info.minRowBytes() * info.height());
13 for (int x : { 32, -32 } ) {
14 for (int y : { 32, -32 } ) {
15 canvas->readPixels(info, data->writable_data(), info.minRowBytes(), x, y);
16 }
17 }
18 sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, info.minRowBytes());
19 canvas->drawImage(image, 0, 0);
20 }
21 } // END FIDDLE
22