1cb93a386Sopenharmony_ci// Copyright 2019 Google LLC.
2cb93a386Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h"
4cb93a386Sopenharmony_ci// HASH=484d60dab5d846bf28c7a4d48892324a
5cb93a386Sopenharmony_ciREG_FIDDLE(Surface_readPixels_2, 256, 64, false, 0) {
6cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) {
7cb93a386Sopenharmony_ci    sk_sp<SkSurface> surf(SkSurface::MakeRasterN32Premul(64, 64));
8cb93a386Sopenharmony_ci    auto surfCanvas = surf->getCanvas();
9cb93a386Sopenharmony_ci    surfCanvas->clear(SK_ColorRED);
10cb93a386Sopenharmony_ci    SkPaint paint;
11cb93a386Sopenharmony_ci    surfCanvas->drawOval({4, 8, 58, 54}, paint);
12cb93a386Sopenharmony_ci    SkImageInfo info = SkImageInfo::Make(64, 64, kBGRA_8888_SkColorType, kPremul_SkAlphaType);
13cb93a386Sopenharmony_ci    sk_sp<SkData> data(SkData::MakeUninitialized(info.minRowBytes() * info.height()));
14cb93a386Sopenharmony_ci    sk_bzero(data->writable_data(), info.minRowBytes() * info.height());
15cb93a386Sopenharmony_ci    for (int x : { 32, -32 } ) {
16cb93a386Sopenharmony_ci        for (int y : { 32, -32 } ) {
17cb93a386Sopenharmony_ci            surf->readPixels(info, data->writable_data(), info.minRowBytes(), x, y);
18cb93a386Sopenharmony_ci        }
19cb93a386Sopenharmony_ci    }
20cb93a386Sopenharmony_ci    sk_sp<SkImage> image = SkImage::MakeRasterData(info, data, info.minRowBytes());
21cb93a386Sopenharmony_ci    canvas->drawImage(image, 0, 0);
22cb93a386Sopenharmony_ci}
23cb93a386Sopenharmony_ci}  // END FIDDLE
24