Fwd: MakeFromStream is not available in Canvaskit

199 views
Skip to first unread message

Steven Whelan

unread,
May 10, 2024, 3:07:54 AMMay 10
to skia-d...@googlegroups.com

Hi, 
In C++,I am trying to read a .skp file as SKPicture as below

const char* skpFilePath = "layer_0.skp";
SkFILEStream stream(skpFilePath);
sk_sp<SkPicture> skPicture =SkPicture::MakeFromStream(&stream);
canvas->drawPicture(skPicture.get());

This C++ code works fine. I want to do this in browser. I believe skia cannot run in browser without CanvasKit js binding.

But I cannot find any of these methods in Canvaskit.
I don't think there is any way to run a native C++ command in browser other than using JS bindings.


John Stiles

unread,
May 10, 2024, 9:45:56 AMMay 10
to skia-d...@googlegroups.com
I believe you are looking for "MakePicture":

CanvasKit is not a perfect 1:1 mirror of Skia. It doesn't have the concept of files, for instance, so SkFILEStream is out (in fact, all the stream methods are unsupported). If there is something critical missing that you need, it is probably possible to add a binding, and you can submit a patch in Gerrit to add it to mainline Skia, but make sure to look for alternatives first.
--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/CAO%2BCLgCTGB_iA9Xay5WWjdBuuvbtj8QTkhd9382xwC%3DQfBfT2w%40mail.gmail.com.

Steven Whelan

unread,
May 12, 2024, 3:47:59 AMMay 12
to skia-discuss
Thanks John
I am now trying to load this .skp file in javascript and then trying to use MakePicture command to get SKPicture.
However I am getting the picture as null.
The corresponding C++ code works fine on the same .skp file. Also, I have verified in skia debugger  that the file is not corrupt.

if (file) {
console.log('File is not null');
const reader = new FileReader();
reader.onload = function(e) {
const buffer = e.target.result;
// Initialize CanvasKit and use the buffer as before...
CanvasKitInit({
locateFile: (file) => `https://unpkg.com/canvask...@0.39.1/bin/${file}`
}).then((CanvasKit) => {
// Create an SkPicture object from the .skp file
console.log('buffer:', buffer);
const picture = CanvasKit.MakePicture(buffer);

The buffer is not null, but the picture is.
What could I be doing wrong?

kjlu...@google.com

unread,
May 13, 2024, 10:50:25 AMMay 13
to skia-discuss
We do have tests for loading in skps from bytes: https://github.com/google/skia/blob/dde1f5dba18343252c185dee776e653bf6049b1b/modules/canvaskit/tests/core_test.js#L894-L900

Perhaps see if you and us are doing anything different; maybe that buffer is not quite the right type?

Steven Whelan

unread,
May 13, 2024, 12:48:21 PMMay 13
to skia-d...@googlegroups.com
Thank you for your response.
I am able to render the .skp file generated in the test - which is also available for download here - https://fiddle.skia.org/c/cbb8dee39e9f1576cd97c2d504db8eee
But I am not able to render the .skp file that is generated by SKIA Debugger. Could it be because of the large size?

Thanks


You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/YLAQGFY12kg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/81f6ce33-4d36-409f-92e1-7bb8227ca15an%40googlegroups.com.

Steven Whelan

unread,
May 13, 2024, 12:53:04 PMMay 13
to skia-d...@googlegroups.com
I generated the .skp for google.com through SKIA Debugger which I am trying to load via javascript

Steven Whelan

unread,
May 13, 2024, 12:59:21 PMMay 13
to skia-d...@googlegroups.com
Thank you for your response.
MakePicture is not null for  the .skp file generated in the test - which is also available for download here - https://fiddle.skia.org/c/cbb8dee39e9f1576cd97c2d504db8eee
But when I load .skp file layer_0.skp generated from Chromium for google.com using the steps mentioned here - https://skia.org/docs/user/tips/  then MakePicture returns null.
Could size be a reason?



On Mon, May 13, 2024 at 8:20 PM 'kjlu...@google.com' via skia-discuss <skia-d...@googlegroups.com> wrote:
You received this message because you are subscribed to a topic in the Google Groups "skia-discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/skia-discuss/YLAQGFY12kg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/81f6ce33-4d36-409f-92e1-7bb8227ca15an%40googlegroups.com.

John Stiles

unread,
May 13, 2024, 3:05:34 PMMay 13
to skia-d...@googlegroups.com
We won't be able to debug this for you, unfortunately. Please use a debugger and step through to see where it is failing. 

Steven

unread,
Jun 15, 2024, 4:06:30 AMJun 15
to skia-discuss
Hi I am sorry to be asking this question again.

However, MakePicture is returning null for all .SKP files apart from the one used in the above example.
I have tested almost all .SKPs from https://fiddle.skia.org/named/ but none of them is working.

On debugging canvaskit.js , I found out that  MakePicture internally calls this method
a._MakePicture  which further calls y = p ? b[0].fromWireType(N) : void 0;
 From here var d = this.Tf(a);  and then finally this.wf(a)   which returns 0 even if a is not 0. This makes the whole result null.

I don't know why one .SKP is working and no other Fiddle.org SKPs are working.
Could you please help me on what could be the issue or how I can debug it better?
Reply all
Reply to author
Forward
0 new messages