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