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" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 4 | // HASH=102d014d7f753db2a9b9ee08893aaf11 |
Hal Canary | a7181e7c | 2019-03-18 16:06:34 -0400 | [diff] [blame] | 5 | REG_FIDDLE(Canvas_readPixels_a, 64, 64, false, 0) { |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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 |