SkSharingProc.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /*
  2. * Copyright 2019 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 SkSharingProc_DEFINED
  8. #define SkSharingProc_DEFINED
  9. #include <unordered_map>
  10. #include <vector>
  11. #include "include/core/SkData.h"
  12. #include "include/core/SkImage.h"
  13. #include "include/core/SkSerialProcs.h"
  14. struct SkSharingSerialContext {
  15. // A map from the ids from SkImage::uniqueID() to ids used within the file
  16. std::unordered_map<uint32_t, uint32_t> fImageMap;
  17. // A serial proc that shares images between subpictures
  18. // To use this, create an instance of SkSerialProcs and populate it this way.
  19. // The client must retain ownership of the context.
  20. // auto ctx = std::make_unique<SkSharingSerialContext>()
  21. // SkSerialProcs procs;
  22. // procs.fImageProc = SkSharingSerialContext::serializeImage;
  23. // procs.fImageCtx = ctx.get();
  24. static sk_sp<SkData> serializeImage(SkImage* img, void* ctx);
  25. };
  26. struct SkSharingDeserialContext {
  27. // a list of unique images in the order they were encountered in the file
  28. // Subsequent occurrences of an image refer to it by it's index in this list.
  29. std::vector<sk_sp<SkImage>> fImages;
  30. // A deserial proc that can interpret id's in place of images as references to previous images.
  31. // Can also deserialize a SKP where all images are inlined (it's backwards compatible)
  32. static sk_sp<SkImage> deserializeImage(const void* data, size_t length, void* ctx);
  33. };
  34. #endif