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 extern sk_sp<SkFontMgr> fontMgr; // Can load some system fonts 41 42 #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}); \ 50 namespace example_##NAME 51 52 #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 60 #define REG_FIDDLE(NAME, W, H, TEXT, I) \ 61 REG_FIDDLE_ANIMATED(NAME, W, H, TEXT, I, 0) 62 63 #endif // examples_DEFINED 64