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