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
4cb93a386Sopenharmony_ci#include "tools/fiddle/examples.h"
5cb93a386Sopenharmony_ci
6cb93a386Sopenharmony_citemplate sk_tools::Registry<fiddle::Example>* sk_tools::Registry<fiddle::Example>::gHead;
7cb93a386Sopenharmony_ci
8cb93a386Sopenharmony_ci// These globals are needed by fiddles:
9cb93a386Sopenharmony_ciGrBackendTexture backEndTexture;
10cb93a386Sopenharmony_ciGrBackendRenderTarget backEndRenderTarget;
11cb93a386Sopenharmony_ciGrBackendTexture backEndTextureRenderTarget;
12cb93a386Sopenharmony_ciSkBitmap source;
13cb93a386Sopenharmony_cisk_sp<SkImage> image;
14cb93a386Sopenharmony_cidouble duration = 1.0;
15cb93a386Sopenharmony_cidouble frame = 1.0;
16cb93a386Sopenharmony_ci
17cb93a386Sopenharmony_ciint main() {
18cb93a386Sopenharmony_ci    constexpr int kImgCount = 7;
19cb93a386Sopenharmony_ci    sk_sp<SkImage> images[kImgCount];
20cb93a386Sopenharmony_ci    SkBitmap bitmaps[kImgCount];
21cb93a386Sopenharmony_ci    for (int i = 1; i < kImgCount; ++i) {
22cb93a386Sopenharmony_ci        SkString path = SkStringPrintf("resources/images/example_%d.png", i);
23cb93a386Sopenharmony_ci        images[i] = SkImage::MakeFromEncoded(SkData::MakeFromFileName(path.c_str()));
24cb93a386Sopenharmony_ci        SkAssertResult(images[i] && images[i]->asLegacyBitmap(&bitmaps[i]));
25cb93a386Sopenharmony_ci    }
26cb93a386Sopenharmony_ci    for (const fiddle::Example& example : sk_tools::Registry<fiddle::Example>::Range()) {
27cb93a386Sopenharmony_ci        SkASSERT((unsigned)example.fImageIndex < (unsigned)kImgCount);
28cb93a386Sopenharmony_ci        image = images[example.fImageIndex];
29cb93a386Sopenharmony_ci        source = bitmaps[example.fImageIndex];
30cb93a386Sopenharmony_ci        SkBitmap bmp;
31cb93a386Sopenharmony_ci        bmp.allocN32Pixels(example.fWidth, example.fHeight);
32cb93a386Sopenharmony_ci        bmp.eraseColor(SK_ColorWHITE);
33cb93a386Sopenharmony_ci        SkCanvas canvas(bmp);
34cb93a386Sopenharmony_ci        SkDebugf("==> %s\n", example.fName);
35cb93a386Sopenharmony_ci        example.fFunc(&canvas);
36cb93a386Sopenharmony_ci    }
37cb93a386Sopenharmony_ci}
38