blob: 86c293b257379f5cbebf9721b261ee148ffa493a [file] [log] [blame]
Hal Canary87515122019-03-15 14:22:51 -04001// 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#ifndef examples_DEFINED
4#define examples_DEFINED
5
Mike Kleinc0bd9f92019-04-23 12:05:21 -05006#include "tools/Registry.h"
Hal Canary87515122019-03-15 14:22:51 -04007#include "skia.h"
8
9#include <cmath>
10#include <string>
11
12namespace fiddle {
13struct Example {
14 void (*fFunc)(SkCanvas*);
15 const char* fName;
Hal Canary9d9312b2020-01-16 12:45:33 -050016 double fAnimationDuration;
Hal Canary87515122019-03-15 14:22:51 -040017 int fImageIndex;
18 int fWidth;
19 int fHeight;
Hal Canary9d9312b2020-01-16 12:45:33 -050020 int fOffscreenWidth;
21 int fOffscreenHeight;
22 int fOffscreenSampleCount;
Hal Canary87515122019-03-15 14:22:51 -040023 bool fText;
24 bool fSRGB;
25 bool fF16;
Hal Canary87515122019-03-15 14:22:51 -040026 bool fOffscreen;
Hal Canary9d9312b2020-01-16 12:45:33 -050027 bool fOffscreenTexturable;
28 bool fOffscreenMipMap;
Hal Canary87515122019-03-15 14:22:51 -040029};
30}
31
32extern GrBackendTexture backEndTexture;
33extern GrBackendRenderTarget backEndRenderTarget;
34extern GrBackendTexture backEndTextureRenderTarget;
35extern SkBitmap source;
36extern sk_sp<SkImage> image;
37extern double duration; // The total duration of the animation in seconds.
38extern double frame; // A value in [0, 1] of where we are in the animation.
39
Hal Canary9d9312b2020-01-16 12:45:33 -050040#define REGISTER_FIDDLE(NAME, WIDTH, HEIGHT, TEXT, IMG_INDEX, DURATION, SRGB, F16, \
41 OFSCR, OFSCR_WIDTH, OFSCR_HEIGHT, OFSCR_SAMPLECOUNT, \
42 OFSCR_TEXTURABLE, OFSCR_MIPMAP) \
43 namespace example_##NAME { void draw(SkCanvas*); } \
44 sk_tools::Registry<fiddle::Example> reg_##NAME( \
45 fiddle::Example{&example_##NAME::draw, #NAME, DURATION, IMG_INDEX, \
46 WIDTH, HEIGHT, OFSCR_WIDTH, OFSCR_HEIGHT, OFSCR_SAMPLECOUNT, \
47 TEXT, SRGB, F16, OFSCR, OFSCR_TEXTURABLE, OFSCR_MIPMAP}); \
Hal Canary87515122019-03-15 14:22:51 -040048 namespace example_##NAME
49
Hal Canary9d9312b2020-01-16 12:45:33 -050050#define REG_FIDDLE_SRGB(NAME, W, H, T, I, DURATION, F16) \
51 REGISTER_FIDDLE(NAME, W, H, T, I, DURATION, true, F16, \
52 false, 64, 64, 0, false, false)
53
54#define REG_FIDDLE_ANIMATED(NAME, W, H, T, I, DURATION) \
55 REGISTER_FIDDLE(NAME, W, H, T, I, DURATION, false, false, \
56 false, 64, 64, 0, false, false)
57
Hal Canary88000422020-01-15 11:51:12 -050058#define REG_FIDDLE(NAME, W, H, TEXT, I) \
59 REG_FIDDLE_ANIMATED(NAME, W, H, TEXT, I, 0)
60
Hal Canary87515122019-03-15 14:22:51 -040061#endif // examples_DEFINED