dump skia picture recordings / SkPictureRecorder

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

dump skia picture recordings / SkPictureRecorder

Postby vania » Sat Jan 30, 2021 8:44 pm

would it be possible to dump skia pictures from CEF?

chromium and thus CEF uses skia, skia can record "drawing instructions" via SkPictureRecorder

in chromium it is possible to save whole frame renders as skp - https://www.chromium.org/developers/how ... m-chromium

is something like that possible with CEF?

I noticed that in OSR/software_output_device_proxy.cc there is some logic that looks like it could be "hacked" to record, but before i start hacking I wanted to ask maybe there is a cleaner way somehow?

any leads / hints are greatly appreciated!

thanks so much
vania
Newbie
 
Posts: 2
Joined: Sat Jan 30, 2021 8:35 pm

Re: dump skia picture recordings / SkPictureRecorder

Postby magreenblatt » Sat Jan 30, 2021 9:40 pm

What is the use case?
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: dump skia picture recordings / SkPictureRecorder

Postby vania » Sat Jan 30, 2021 10:16 pm

having page renders in skpicture is very practical for various reasons, just to name a few:

1) lots of people still use qt webkit just because it allows them to render pages to SVG / pdf (such as https://wkhtmltopdf.org/), qt webkit is very dead but there is no alternative, from skpicture it is trivial to save to true vector svg / pdf

this is something quite interesting - if you try to save to svg on chromium based browsers or on libwebkit-gtk (which uses the latest webkit codebase) you will get a SVG but it wont be vector just an embedded PNG, only qt webkit because it still uses webkit 1 can vector render, with skp it is possible to achieve the same

2) my personal interest in this is that i have used qt webkit in my toy "remote browser isolation" project, the interesting aspect was that it allowed me to render pages into SVG (which is a vector format so no loss of quality) - then i diffed subsequent frames and compressed the diff, streamed that to client browser where i use wasm to decompress/patch and display, works reasonably well / fast and is lossless yet qt webkit is very much outdated with "a lot" of critical security bugs thus I would like to port my toy project to something based on chromium / ideally CEF - i was thinking using SKP directly (serialized skpicture) diff / compress the same way but try to use canvaskit on the browser side to "replay the SKP"

sure there could be a ton more use cases, this is just what i have in mind

muchas gracias
vania
Newbie
 
Posts: 2
Joined: Sat Jan 30, 2021 8:35 pm

Re: dump skia picture recordings / SkPictureRecorder

Postby magreenblatt » Sun Jan 31, 2021 11:33 am

It might be doable, but I’m not sure what changes would be required. The compositor will likely complicate things. You can build CEF/Chromium locally to play with it.
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: dump skia picture recordings / SkPictureRecorder

Postby bigben0123 » Wed Jun 23, 2021 4:12 am

You can refer to the code to serialize layer to skp. It's easy only if you get the root layer object.

Code: Select all
#include "base/base64.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/debug/profiler.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"

void GpuBenchmarking::PrintToSkPicture(v8::Isolate* isolate,
                                       const std::string& dirname) {
  GpuBenchmarkingContext context(render_frame_.get());

  const cc::Layer* root_layer = context.layer_tree_host()->root_layer();
  if (!root_layer)
    return;

  base::FilePath dirpath = base::FilePath::FromUTF8Unsafe(dirname);
  if (!base::CreateDirectory(dirpath) || !base::PathIsWritable(dirpath)) {
    std::string msg("Path is not writable: ");
    msg.append(dirpath.MaybeAsASCII());
    isolate->ThrowException(v8::Exception::Error(
        v8::String::NewFromUtf8(isolate, msg.c_str(),
                                v8::NewStringType::kNormal, msg.length())
            .ToLocalChecked()));
    return;
  }

  SkPictureSerializer serializer(dirpath);
  serializer.Serialize(root_layer);
}


skp is SkPicture. Replay:
Code: Select all
  function SkpExample(CanvasKit, skpData) {
    if (!skpData || !CanvasKit) {
      return;
    }

    const surface = CanvasKit.MakeSWCanvasSurface('skp');
    if (!surface) {
      console.error('Could not make surface');
      return;
    }

    const pic = CanvasKit.MakePicture(skpData);

    function drawFrame(canvas) {
      canvas.clear(CanvasKit.TRANSPARENT);
      // this particular file has a path drawing at (68,582) that's 1300x1300 pixels
      // scale it down to 500x500 and translate it to fit.
      const scale = 500.0/1300;
      canvas.scale(scale, scale);
      canvas.translate(-68, -582);
      canvas.drawPicture(pic);
    }
    // Intentionally just draw frame once
    surface.drawOnce(drawFrame);
  }


It's fun to stream and replay.
bigben0123
Newbie
 
Posts: 1
Joined: Wed Jun 23, 2021 3:48 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 45 guests