1cb93a386Sopenharmony_ci// Copyright 2020 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_ciREG_FIDDLE(draw_pixel_array_nocopy, 256, 256, false, 5) {
5cb93a386Sopenharmony_ciconstexpr int kWidth = 4;
6cb93a386Sopenharmony_ciconstexpr int kHeight = 4;
7cb93a386Sopenharmony_cistatic const uint32_t kPixels[kHeight * kWidth] = {
8cb93a386Sopenharmony_ci        0xFF000000, 0xFF005500, 0xFF00AA00, 0xFF00FF00,
9cb93a386Sopenharmony_ci        0xFF000055, 0xFF005555, 0xFF00AA55, 0xFF00FF55,
10cb93a386Sopenharmony_ci        0xFF0000AA, 0xFF0055AA, 0xFF00AAAA, 0xFF00FFAA,
11cb93a386Sopenharmony_ci        0xFF0000FF, 0xFF0055FF, 0xFF00AAFF, 0xFF00FFFF,
12cb93a386Sopenharmony_ci};
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_civoid draw(SkCanvas* canvas) {
15cb93a386Sopenharmony_ci    SkPixmap pixmap(SkImageInfo::Make(kWidth, kHeight, kN32_SkColorType, kPremul_SkAlphaType),
16cb93a386Sopenharmony_ci                    kPixels, sizeof(uint32_t) * kWidth);
17cb93a386Sopenharmony_ci    sk_sp<SkImage> img = SkImage::MakeFromRaster(pixmap, nullptr, nullptr);
18cb93a386Sopenharmony_ci
19cb93a386Sopenharmony_ci    canvas->scale(16, 16);
20cb93a386Sopenharmony_ci    canvas->drawImage(img, 6, 6);
21cb93a386Sopenharmony_ci}
22cb93a386Sopenharmony_ci}  // END FIDDLE
23