examples.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. #include "tools/fiddle/examples.h"
  4. template sk_tools::Registry<fiddle::Example>* sk_tools::Registry<fiddle::Example>::gHead;
  5. // These globals are needed by fiddles:
  6. GrBackendTexture backEndTexture;
  7. GrBackendRenderTarget backEndRenderTarget;
  8. GrBackendTexture backEndTextureRenderTarget;
  9. SkBitmap source;
  10. sk_sp<SkImage> image;
  11. double duration = 1.0;
  12. double frame = 1.0;
  13. int main() {
  14. constexpr int kImgCount = 7;
  15. sk_sp<SkImage> images[kImgCount];
  16. SkBitmap bitmaps[kImgCount];
  17. for (int i = 1; i < kImgCount; ++i) {
  18. SkString path = SkStringPrintf("resources/images/example_%d.png", i);
  19. images[i] = SkImage::MakeFromEncoded(SkData::MakeFromFileName(path.c_str()));
  20. SkAssertResult(images[i] && images[i]->asLegacyBitmap(&bitmaps[i]));
  21. }
  22. for (const fiddle::Example& example : sk_tools::Registry<fiddle::Example>::Range()) {
  23. SkASSERT((unsigned)example.fImageIndex < (unsigned)kImgCount);
  24. image = images[example.fImageIndex];
  25. source = bitmaps[example.fImageIndex];
  26. SkBitmap bmp;
  27. bmp.allocN32Pixels(example.fWidth, example.fHeight);
  28. bmp.eraseColor(SK_ColorWHITE);
  29. SkCanvas canvas(bmp);
  30. SkDebugf("==> %s\n", example.fName);
  31. example.fFunc(&canvas);
  32. }
  33. }