SkSerialProcs.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright 2017 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkSerialProcs_DEFINED
  8. #define SkSerialProcs_DEFINED
  9. #include "SkImage.h"
  10. #include "SkPicture.h"
  11. #include "SkTypeface.h"
  12. /**
  13. * A serial-proc is asked to serialize the specified object (e.g. picture or image).
  14. * If a data object is returned, it will be used (even if it is zero-length).
  15. * If null is returned, then Skia will take its default action.
  16. *
  17. * The default action for pictures is to use Skia's internal format.
  18. * The default action for images is to encode either in its native format or PNG.
  19. * The default action for typefaces is to use Skia's internal format.
  20. */
  21. typedef sk_sp<SkData> (*SkSerialPictureProc)(SkPicture*, void* ctx);
  22. typedef sk_sp<SkData> (*SkSerialImageProc)(SkImage*, void* ctx);
  23. typedef sk_sp<SkData> (*SkSerialTypefaceProc)(SkTypeface*, void* ctx);
  24. /**
  25. * Called with the encoded form of a picture (previously written with a custom
  26. * SkSerialPictureProc proc). Return a picture object, or nullptr indicating failure.
  27. */
  28. typedef sk_sp<SkPicture> (*SkDeserialPictureProc)(const void* data, size_t length, void* ctx);
  29. /**
  30. * Called with the encoded from of an image. The proc can return an image object, or if it
  31. * returns nullptr, then Skia will take its default action to try to create an image from the data.
  32. *
  33. * Note that unlike SkDeserialPictureProc and SkDeserialTypefaceProc, return nullptr from this
  34. * does not indicate failure, but is a signal for Skia to take its default action.
  35. */
  36. typedef sk_sp<SkImage> (*SkDeserialImageProc)(const void* data, size_t length, void* ctx);
  37. /**
  38. * Called with the encoded form of a typeface (previously written with a custom
  39. * SkSerialTypefaceProc proc). Return a typeface object, or nullptr indicating failure.
  40. */
  41. typedef sk_sp<SkTypeface> (*SkDeserialTypefaceProc)(const void* data, size_t length, void* ctx);
  42. struct SK_API SkSerialProcs {
  43. SkSerialPictureProc fPictureProc = nullptr;
  44. void* fPictureCtx = nullptr;
  45. SkSerialImageProc fImageProc = nullptr;
  46. void* fImageCtx = nullptr;
  47. SkSerialTypefaceProc fTypefaceProc = nullptr;
  48. void* fTypefaceCtx = nullptr;
  49. };
  50. struct SK_API SkDeserialProcs {
  51. SkDeserialPictureProc fPictureProc = nullptr;
  52. void* fPictureCtx = nullptr;
  53. SkDeserialImageProc fImageProc = nullptr;
  54. void* fImageCtx = nullptr;
  55. SkDeserialTypefaceProc fTypefaceProc = nullptr;
  56. void* fTypefaceCtx = nullptr;
  57. };
  58. #endif