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