Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 6 | #include "tools/Registry.h" |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 7 | #include "skia.h" |
| 8 | |
John Stiles | 7bf7999 | 2021-06-25 11:05:20 -0400 | [diff] [blame] | 9 | #include <cinttypes> |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 10 | #include <cmath> |
| 11 | #include <string> |
| 12 | |
| 13 | namespace fiddle { |
| 14 | struct Example { |
| 15 | void (*fFunc)(SkCanvas*); |
| 16 | const char* fName; |
Hal Canary | 9d9312b | 2020-01-16 12:45:33 -0500 | [diff] [blame] | 17 | double fAnimationDuration; |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 18 | int fImageIndex; |
| 19 | int fWidth; |
| 20 | int fHeight; |
Hal Canary | 9d9312b | 2020-01-16 12:45:33 -0500 | [diff] [blame] | 21 | int fOffscreenWidth; |
| 22 | int fOffscreenHeight; |
| 23 | int fOffscreenSampleCount; |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 24 | bool fText; |
| 25 | bool fSRGB; |
| 26 | bool fF16; |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 27 | bool fOffscreen; |
Hal Canary | 9d9312b | 2020-01-16 12:45:33 -0500 | [diff] [blame] | 28 | bool fOffscreenTexturable; |
| 29 | bool fOffscreenMipMap; |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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. |
Kevin Lubick | 1e97119 | 2023-11-10 16:14:44 -0500 | [diff] [blame] | 40 | extern sk_sp<SkFontMgr> fontMgr; // Can load some system fonts |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 41 | |
Hal Canary | 9d9312b | 2020-01-16 12:45:33 -0500 | [diff] [blame] | 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}); \ |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 50 | namespace example_##NAME |
| 51 | |
Hal Canary | 9d9312b | 2020-01-16 12:45:33 -0500 | [diff] [blame] | 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 | |
Hal Canary | 8800042 | 2020-01-15 11:51:12 -0500 | [diff] [blame] | 60 | #define REG_FIDDLE(NAME, W, H, TEXT, I) \ |
| 61 | REG_FIDDLE_ANIMATED(NAME, W, H, TEXT, I, 0) |
| 62 | |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 63 | #endif // examples_DEFINED |