blob: 58769780d5aae2a814336f1423a7f72e91e223ef [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=2d991a231e49d1de13eeb2ba9b440e01
Hal Canarya7181e7c2019-03-18 16:06:34 -04005REG_FIDDLE(Surface_readPixels_3, 256, 256, false, 0) {
Hal Canary87515122019-03-15 14:22:51 -04006void draw(SkCanvas* canvas) {
7 sk_sp<SkSurface> surf(SkSurface::MakeRasterN32Premul(64, 64));
8 auto surfCanvas = surf->getCanvas();
9 surfCanvas->clear(SK_ColorGREEN);
10 SkPaint paint;
11 surfCanvas->drawOval({2, 10, 58, 54}, paint);
12 SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
13 SkBitmap bitmap;
14 bitmap.setInfo(info);
15 bitmap.allocPixels();
16 for (int x : { 32, -32 } ) {
17 for (int y : { 32, -32 } ) {
18 surf->readPixels(bitmap, x, y);
19 }
20 }
21 canvas->drawBitmap(bitmap, 0, 0);
22}
23} // END FIDDLE