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 | |
| 9 | #include <cmath> |
| 10 | #include <string> |
| 11 | |
| 12 | namespace fiddle { |
| 13 | struct Example { |
| 14 | void (*fFunc)(SkCanvas*); |
| 15 | const char* fName; |
Hal Canary | 9d9312b | 2020-01-16 12:45:33 -0500 | [diff] [blame] | 16 | double fAnimationDuration; |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 17 | int fImageIndex; |
| 18 | int fWidth; |
| 19 | int fHeight; |
Hal Canary | 9d9312b | 2020-01-16 12:45:33 -0500 | [diff] [blame] | 20 | int fOffscreenWidth; |
| 21 | int fOffscreenHeight; |
| 22 | int fOffscreenSampleCount; |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 23 | bool fText; |
| 24 | bool fSRGB; |
| 25 | bool fF16; |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 26 | bool fOffscreen; |
Hal Canary | 9d9312b | 2020-01-16 12:45:33 -0500 | [diff] [blame] | 27 | bool fOffscreenTexturable; |
| 28 | bool fOffscreenMipMap; |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 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 | |
Hal Canary | 9d9312b | 2020-01-16 12:45:33 -0500 | [diff] [blame] | 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}); \ |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 48 | namespace example_##NAME |
| 49 | |
Hal Canary | 9d9312b | 2020-01-16 12:45:33 -0500 | [diff] [blame] | 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 | |
Hal Canary | 8800042 | 2020-01-15 11:51:12 -0500 | [diff] [blame] | 58 | #define REG_FIDDLE(NAME, W, H, TEXT, I) \ |
| 59 | REG_FIDDLE_ANIMATED(NAME, W, H, TEXT, I, 0) |
| 60 | |
Hal Canary | 8751512 | 2019-03-15 14:22:51 -0400 | [diff] [blame] | 61 | #endif // examples_DEFINED |