Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | Public Attributes | List of all members
SkSharingSerialContext Struct Reference

#include <SkSharingProc.h>

Static Public Member Functions

static void collectNonTextureImagesFromPicture (const SkPicture *pic, SkSharingSerialContext *sharingCtx)
 
static sk_sp< SkDataserializeImage (SkImage *img, void *ctx)
 

Public Attributes

skia_private::THashMap< uint32_t, sk_sp< SkImage > > fNonTexMap
 
skia_private::THashMap< uint32_t, intfImageMap
 

Detailed Description

This serial proc serializes each image it encounters only once, using their uniqueId as the property for sameness.

It's most basic usage involves setting your imageProc to SkSharingSerialContext::serializeImage and creating an SkSharingSerialContext in an appropriate scope to outlive all the images that will be encountered before serialization.

Optionally, collectNonTextureImagesFromPicture can be called with an SkSharingContext and an SkPicture that may reference not-yet-released texture backed images. It will make non-texture copies if necessary and store them in the context. If present, they will be used in the final serialization.

This is intended to be used on Android with MultiPictureDocument's onEndPage parameter, in a lambda that captures the context, because MPD cannot make assumptions about the type of proc it receives and clients (Chrome) build MPD without this source file.

Definition at line 37 of file SkSharingProc.h.

Member Function Documentation

◆ collectNonTextureImagesFromPicture()

void SkSharingSerialContext::collectNonTextureImagesFromPicture ( const SkPicture pic,
SkSharingSerialContext sharingCtx 
)
static

Definition at line 34 of file SkSharingProc.cpp.

35 {
36 SkSerialProcs tempProc;
37 tempProc.fImageCtx = sharingCtx;
38 tempProc.fImageProc = collectNonTextureImagesProc;
40 pic->serialize(&ns, &tempProc);
41}
sk_sp< SkData > serialize(const SkSerialProcs *procs=nullptr) const
SkSerialImageProc fImageProc

◆ serializeImage()

sk_sp< SkData > SkSharingSerialContext::serializeImage ( SkImage img,
void *  ctx 
)
static

Definition at line 43 of file SkSharingProc.cpp.

43 {
44 SkSharingSerialContext* context = reinterpret_cast<SkSharingSerialContext*>(ctx);
45 uint32_t id = img->uniqueID(); // get this process's id for the image. these are not hashes.
46 // find out if we have already serialized this, and if so, what its in-file id is.
47 int* fid = context->fImageMap.find(id);
48 if (!fid) {
49 // When not present, add its id to the map and return its usual serialized form.
50 context->fImageMap[id] = context->fImageMap.count(); // Next in-file id
51 // encode the image or it's non-texture replacement if one was collected
52 sk_sp<SkImage>* replacementImage = context->fNonTexMap.find(id);
53 if (replacementImage) {
54 img = replacementImage->get();
55 }
56 return SkPngEncoder::Encode(nullptr, img, {});
57 }
58 // if present, return only the in-file id we registered the first time we serialized it.
59 return SkData::MakeWithCopy(fid, sizeof(*fid));
60}
static sk_sp< SkData > MakeWithCopy(const void *data, size_t length)
Definition SkData.cpp:111
uint32_t uniqueID() const
Definition SkImage.h:311
T * get() const
Definition SkRefCnt.h:303
int count() const
Definition SkTHash.h:460
V * find(const K &key) const
Definition SkTHash.h:479
SK_API bool Encode(SkWStream *dst, const SkPixmap &src, const Options &options)
skia_private::THashMap< uint32_t, sk_sp< SkImage > > fNonTexMap
skia_private::THashMap< uint32_t, int > fImageMap
const uintptr_t id

Member Data Documentation

◆ fImageMap

skia_private::THashMap<uint32_t, int> SkSharingSerialContext::fImageMap

Definition at line 54 of file SkSharingProc.h.

◆ fNonTexMap

skia_private::THashMap<uint32_t, sk_sp<SkImage> > SkSharingSerialContext::fNonTexMap

Definition at line 42 of file SkSharingProc.h.


The documentation for this struct was generated from the following files: