开发者

Is the format saved by Android's Picture.writeToStream() documented?

I know I can look at the source, but I'm 开发者_开发问答wondering if there's any documentation for the format used by android.graphics.Picture.writeToStream(OutputStream).


You could check out SkPictureRecord.cpp. It looks like the details of drawing functions are simply serialized linearly via methods like:

void addScalar(SkScalar scalar) {
    fWriter.writeScalar(scalar);
}

In any case, as with most private details of the SDK, leveraging this knowledge is likely to get you into trouble when the SDK changes.


I would guess that it is the same as the format of all these "skp" files here:

http://skia.googlecode.com/svn/skp/

Which you can open with the Skia Debugger which is included in skia (if you can get it to compile!).

Having said that, the skia debugger segfaulted when I tried to open the output of writeToStream() for my test view.

Code details

This is the function the Android code calls through to. As you can see it is versioned. The test files in that directory are version 9. The output of Canvas.writeToStream() on my Galaxy S2 is version 1. Here is where the java code calls through to:

http://code.google.com/p/skia/source/browse/trunk/src/core/SkPicture.cpp#291

But that is obviously a way newer version than the one on my phone, since it is version 9:

http://code.google.com/p/skia/source/browse/trunk/include/core/SkPicture.h#161

The pictures are restored using SkPicture's constructor which isn't backwards compatible:

http://code.google.com/p/skia/source/browse/trunk/src/core/SkPicture.cpp#269

Which is a bit of a shame and makes it quite hacky to use as a serialization format since you'll have to sniff the PICTURE_VERSION on Android and then do funky stuff to give Android the right version.

Edit

The PICTURE_VERSION is 1 up to and including ICS, and 2 in Jellybean:

https://github.com/android/platform_external_skia/blob/master/include/core/SkUserConfig.h#L44

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜