Is your feature request related to a problem? Please describe.
Add support for serializing SKPicture as skp stream or SKData object. Currently you can not serialize created SKPictures. For example when loading SVG image from file you can only draw resulting SKPicture and can not save for later use.
Describe the solution you'd like
Add support for the following skia methods:
https://github.com/google/skia/blob/90c300fb4ac9421b7274ba7c94c8c90f600766db/include/core/SkPicture.h#L157
https://github.com/google/skia/blob/90c300fb4ac9421b7274ba7c94c8c90f600766db/include/core/SkPicture.h#L169
Describe alternatives you've considered
Did not find any alternatives in SkiaSharp.
Additional context
https://github.com/google/skia/blob/master/site/user/api/skcanvas_creation.md#skpicture
#include "SkPictureRecorder.h"
#include "SkPicture.h"
#include "SkStream.h"
void picture(int width, int height,
void (*draw)(SkCanvas*),
const char* path) {
SkPictureRecorder recorder;
SkCanvas* recordingCanvas = recorder.beginRecording(SkIntToScalar(width),
SkIntToScalar(height));
draw(recordingCanvas);
sk_sp<SkPicture> picture = recorder.finishRecordingAsPicture();
SkFILEWStream skpStream(path);
// Open SKP files with `viewer --skps PATH_TO_SKP --slide SKP_FILE`
picture->serialize(&skpStream);
}
@wieslawsoltes is there a reason you closed this?
@mattleibow Any new on this issue? This would make debugging issues much easier as you can load created .skp into https://debugger.skia.org/

Oh wow. An old issue.
That is awesome. Let me get this is asap!
Wow indeed. That is a nice tool.
And you get some nice insights:
{
"command": "DrawPath",
"visible": true,
"path": {
"fillType": "winding",
"verbs": [
{
"move": [
20.5,
344.5
]
},
{
"cubic": [
[
20.5,
344.5
],
[
22,
333.5
],
[
10.5,
346.5
]
]
}
]
},
"paint": {
"strokeWidth": 1,
"antiAlias": true,
"style": "stroke",
"filterQuality": "low"
},
"auditTrail": {
"Ops": [
{
"Name": "SmallPathOp",
"ClientID": 310,
"OpsTaskID": 264,
"ChildID": 28,
"Bounds": {
"Left": 193.948,
"Right": 205.214,
"Top": 483.872,
"Bottom": 491.691
},
"Stack": [
"SkGpuDevice::drawPath",
"GrRenderTargetContext::drawPath",
"GrRenderTargetContext::drawShape",
"GrRenderTargetContext::internalDrawPath",
"GrSmallPathRenderer::onDrawPath",
"GrRenderTargetContext::addDrawOp"
]
}
]
}
}
Now that is very nice!
I got a PR up that should make this a cinch. Leave any comments, and once I merge CI will push to the preview feed: https://github.com/mono/SkiaSharp/pull/1514
@mattleibow Amazing!
Will test the preview.
PS. Now we can submit issues with recordings ;)
Oh yeah. That will be such a great help! The avalonia folks might also find this helpful... @danwalmsley @kekekeks?
I can compare my library svg rendering vs chrome svg rendering, like draw command by draw command, you can inspect filters and effects etc.
@mattleibow I also wonder if there is any built-in public skia API to inspect SKPicture draw commands
@mattleibow I also wonder if there is any built-in public skia API to inspect SKPicture draw commands
Like https://api.skia.org/classSkPicture.html#a9e5313999fc681ec64586dada8f5a259
virtual void SkPicture::playback ( SkCanvas * canvas,
AbortCallback * callback = nullptr
) const
@mattleibow I also wonder if there is any built-in public skia API to inspect SKPicture draw commands
Like https://api.skia.org/classSkPicture.html#a9e5313999fc681ec64586dada8f5a259
virtual void SkPicture::playback ( SkCanvas * canvas, AbortCallback * callback = nullptr ) const
But than I need to somehow intercept commands from SkCanvas
@wieslawsoltes There doesn't seem to be any APIs for anything too advanced on SKPicture. The playback is more for when drawing the picture. SKCanvas.DrawPicture does this in one operation, the Playback will basically replay all the commands you did. So, all the crops, draws and transforms. Not sure exactly how this works... Maybe if there was some background thread that would cancel it?
In the code there is basically a loop that goes through all the commands and provides a call to the abort method to optionally break.
SKPicture is basically an abstract type that never exists. There are some derived types that have all the props, but they are private/internal.
@mattleibow yeah looks like there is no way to get access to picture draw commands, also skp file format is undocumented and no plans for opening it by Google
Most helpful comment
Now that is very nice!
I got a PR up that should make this a cinch. Leave any comments, and once I merge CI will push to the preview feed: https://github.com/mono/SkiaSharp/pull/1514