• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef examples_DEFINED
4 #define examples_DEFINED
5 
6 #include "tools/Registry.h"
7 #include "skia.h"
8 
9 #include <cinttypes>
10 #include <cmath>
11 #include <string>
12 
13 namespace fiddle {
14 struct Example {
15     void (*fFunc)(SkCanvas*);
16     const char* fName;
17     double fAnimationDuration;
18     int fImageIndex;
19     int fWidth;
20     int fHeight;
21     int fOffscreenWidth;
22     int fOffscreenHeight;
23     int fOffscreenSampleCount;
24     bool fText;
25     bool fSRGB;
26     bool fF16;
27     bool fOffscreen;
28     bool fOffscreenTexturable;
29     bool fOffscreenMipMap;
30 };
31 }
32 
33 extern GrBackendTexture backEndTexture;
34 extern GrBackendRenderTarget backEndRenderTarget;
35 extern GrBackendTexture backEndTextureRenderTarget;
36 extern SkBitmap source;
37 extern sk_sp<SkImage> image;
38 extern double duration; // The total duration of the animation in seconds.
39 extern double frame;    // A value in [0, 1] of where we are in the animation.
40 
41 #define REGISTER_FIDDLE(NAME, WIDTH, HEIGHT, TEXT, IMG_INDEX, DURATION, SRGB, F16,   \
42                         OFSCR, OFSCR_WIDTH, OFSCR_HEIGHT, OFSCR_SAMPLECOUNT,         \
43                         OFSCR_TEXTURABLE, OFSCR_MIPMAP)                              \
44     namespace example_##NAME { void draw(SkCanvas*);  }                              \
45     sk_tools::Registry<fiddle::Example> reg_##NAME(                                  \
46         fiddle::Example{&example_##NAME::draw, #NAME, DURATION, IMG_INDEX,           \
47                         WIDTH, HEIGHT, OFSCR_WIDTH, OFSCR_HEIGHT, OFSCR_SAMPLECOUNT, \
48                         TEXT, SRGB, F16, OFSCR, OFSCR_TEXTURABLE, OFSCR_MIPMAP});    \
49     namespace example_##NAME
50 
51 #define REG_FIDDLE_SRGB(NAME, W, H, T, I, DURATION, F16)   \
52     REGISTER_FIDDLE(NAME, W, H, T, I, DURATION, true, F16, \
53                     false, 64, 64, 0, false, false)
54 
55 #define REG_FIDDLE_ANIMATED(NAME, W, H, T, I, DURATION)       \
56     REGISTER_FIDDLE(NAME, W, H, T, I, DURATION, false, false, \
57                     false, 64, 64, 0, false, false)
58 
59 #define REG_FIDDLE(NAME, W, H, TEXT, I)         \
60     REG_FIDDLE_ANIMATED(NAME, W, H, TEXT, I, 0)
61 
62 #endif  // examples_DEFINED
63