• 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 <cmath>
10 #include <string>
11 
12 namespace fiddle {
13 struct Example {
14     void (*fFunc)(SkCanvas*);
15     const char* fName;
16     double fAnimationDuration;
17     int fImageIndex;
18     int fWidth;
19     int fHeight;
20     int fOffscreenWidth;
21     int fOffscreenHeight;
22     int fOffscreenSampleCount;
23     bool fText;
24     bool fSRGB;
25     bool fF16;
26     bool fOffscreen;
27     bool fOffscreenTexturable;
28     bool fOffscreenMipMap;
29 };
30 }
31 
32 extern GrBackendTexture backEndTexture;
33 extern GrBackendRenderTarget backEndRenderTarget;
34 extern GrBackendTexture backEndTextureRenderTarget;
35 extern SkBitmap source;
36 extern sk_sp<SkImage> image;
37 extern double duration; // The total duration of the animation in seconds.
38 extern double frame;    // A value in [0, 1] of where we are in the animation.
39 
40 #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});    \
48     namespace example_##NAME
49 
50 #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 
58 #define REG_FIDDLE(NAME, W, H, TEXT, I)         \
59     REG_FIDDLE_ANIMATED(NAME, W, H, TEXT, I, 0)
60 
61 #endif  // examples_DEFINED
62