blob: 5cb097ff957aba9eb0125278b99b02f4be95fa80 [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
John Stiles7bf79992021-06-25 11:05:20 -04009#include <cinttypes>
Hal Canary87515122019-03-15 14:22:51 -040010#include <cmath>
11#include <string>
12
13namespace fiddle {
14struct Example {
15 void (*fFunc)(SkCanvas*);
16 const char* fName;
Hal Canary9d9312b2020-01-16 12:45:33 -050017 double fAnimationDuration;
Hal Canary87515122019-03-15 14:22:51 -040018 int fImageIndex;
19 int fWidth;
20 int fHeight;
Hal Canary9d9312b2020-01-16 12:45:33 -050021 int fOffscreenWidth;
22 int fOffscreenHeight;
23 int fOffscreenSampleCount;
Hal Canary87515122019-03-15 14:22:51 -040024 bool fText;
25 bool fSRGB;
26 bool fF16;
Hal Canary87515122019-03-15 14:22:51 -040027 bool fOffscreen;
Hal Canary9d9312b2020-01-16 12:45:33 -050028 bool fOffscreenTexturable;
29 bool fOffscreenMipMap;
Hal Canary87515122019-03-15 14:22:51 -040030};
31}
32
33extern GrBackendTexture backEndTexture;
34extern GrBackendRenderTarget backEndRenderTarget;
35extern GrBackendTexture backEndTextureRenderTarget;
36extern SkBitmap source;
37extern sk_sp<SkImage> image;
38extern double duration; // The total duration of the animation in seconds.
39extern double frame; // A value in [0, 1] of where we are in the animation.
Kevin Lubick1e971192023-11-10 16:14:44 -050040extern sk_sp<SkFontMgr> fontMgr; // Can load some system fonts
Hal Canary87515122019-03-15 14:22:51 -040041
Hal Canary9d9312b2020-01-16 12:45:33 -050042#define REGISTER_FIDDLE(NAME, WIDTH, HEIGHT, TEXT, IMG_INDEX, DURATION, SRGB, F16, \
43 OFSCR, OFSCR_WIDTH, OFSCR_HEIGHT, OFSCR_SAMPLECOUNT, \
44 OFSCR_TEXTURABLE, OFSCR_MIPMAP) \
45 namespace example_##NAME { void draw(SkCanvas*); } \
46 sk_tools::Registry<fiddle::Example> reg_##NAME( \
47 fiddle::Example{&example_##NAME::draw, #NAME, DURATION, IMG_INDEX, \
48 WIDTH, HEIGHT, OFSCR_WIDTH, OFSCR_HEIGHT, OFSCR_SAMPLECOUNT, \
49 TEXT, SRGB, F16, OFSCR, OFSCR_TEXTURABLE, OFSCR_MIPMAP}); \
Hal Canary87515122019-03-15 14:22:51 -040050 namespace example_##NAME
51
Hal Canary9d9312b2020-01-16 12:45:33 -050052#define REG_FIDDLE_SRGB(NAME, W, H, T, I, DURATION, F16) \
53 REGISTER_FIDDLE(NAME, W, H, T, I, DURATION, true, F16, \
54 false, 64, 64, 0, false, false)
55
56#define REG_FIDDLE_ANIMATED(NAME, W, H, T, I, DURATION) \
57 REGISTER_FIDDLE(NAME, W, H, T, I, DURATION, false, false, \
58 false, 64, 64, 0, false, false)
59
Hal Canary88000422020-01-15 11:51:12 -050060#define REG_FIDDLE(NAME, W, H, TEXT, I) \
61 REG_FIDDLE_ANIMATED(NAME, W, H, TEXT, I, 0)
62
Hal Canary87515122019-03-15 14:22:51 -040063#endif // examples_DEFINED