How can I make skia render to a gbm surface

108 Views Asked by At

I want to render to a gbm buffer so that I can present it on the screen. Is it possible to do that?

I've tried to render to a dumb buffer, however it is very slow (of course).

This is my code of rendering into a dumbbuffer (with crate drm and skia_safe used):

use drm::Device as _;
use skia_safe::surfaces;

let drm = MyDevice::new("/dev/dri/card0");
let dumbbuffer = drm.create_dumb_buffer(size.into(), drm::buffer::DrmFourcc::Xrgb_8888, 32).unwrap();
let framebuffer = drm.add_framebuffer(&dumbbuffer, 32, 32).unwrap();
let surface = surfaces::raster_n32_premul(size).unwrap();

// Draw something to the surface here...
let paint = Paint::new(Color4f::new(255.0, 255.0, 255.0, 255.0),&ColorSpace::new_srgb());
surface.canvas().draw_circle(Point(0.0,0.0), 50.0, &paint);

// Grab pixels from the surface
let bytes = surface.peek_pixels().map(|pixel| pixel.bytes().map(|bytes| bytes.to_owned())).flatten();

// Copy it into the dumb buffer
let mapping = drm.map_dumb_buffer(&mut dumbbuffer).unwrap();
let len = mapping.len();
mapping.copy_from_slice(&[bytes, &vec![0; len - bytes.len()]].concat());
0

There are 0 best solutions below