linebender / piet

An abstraction for 2D graphics.
Apache License 2.0
1.23k stars 95 forks source link

Can't resume drawing after calling `BitmapTarget::copy_raw_pixels`. #568

Open doinkythederp opened 3 months ago

doinkythederp commented 3 months ago

On Windows specifically, it's not possible to make further draws to a BitmapTarget after calling BitmapTarget::copy_raw_pixels. I believe this is because self.context.end_draw()?; is called during aforementioned method, without a corresponding begin_draw() call. It fails with an error code of BackendError(hresult 88990001).

Example:

use piet::{kurbo::Rect, Color, ImageFormat};
use piet_common::{Device, RenderContext};

fn main() {
    let mut piet = Device::new().unwrap();
    let mut bitmap = piet.bitmap_target(256, 256, 1.0).unwrap();
    {
        let mut rc = bitmap.render_context();
        let rect = Rect::new(10.0, 10.0, 100.0, 100.0);
        rc.fill(rect, &Color::RED);
        rc.finish().unwrap();
    }
    let mut data = vec![0; 256 * 256 * 4];
    bitmap
        .copy_raw_pixels(ImageFormat::RgbaPremul, &mut data)
        .unwrap();

    {
        let mut rc = bitmap.render_context();
        let rect = Rect::new(50.0, 50.0, 150.0, 150.0);
        rc.fill(rect, &Color::GREEN); // ERROR!
        rc.finish().unwrap();
    }
}