• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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=484d60dab5d846bf28c7a4d48892324a
5 REG_FIDDLE(Surface_readPixels_2, 256, 64, false, 0) {
draw(SkCanvas * canvas)6 void draw(SkCanvas* canvas) {
7     sk_sp<SkSurface> surf(SkSurface::MakeRasterN32Premul(64, 64));
8     auto surfCanvas = surf->getCanvas();
9     surfCanvas->clear(SK_ColorRED);
10     SkPaint paint;
11     surfCanvas->drawOval({4, 8, 58, 54}, paint);
12     SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
13     sk_sp<SkData> data(SkData::MakeUninitialized(info.minRowBytes() * info.height()));
14     sk_bzero(data->writable_data(), info.minRowBytes() * info.height());
15     for (int x : { 32, -32 } ) {
16         for (int y : { 32, -32 } ) {
17             surf->readPixels(info, data->writable_data(), info.minRowBytes(), x, y);
18         }
19     }
20     sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, info.minRowBytes());
21     canvas->drawImage(image, 0, 0);
22 }
23 }  // END FIDDLE
24