canvas: rename snapshot(_data) to surface() -> SourceSurface/bytes() -> AsRef<[u8]> (#36793)

`surface()` returns `SourceSurface` which is/was meant as optimization
when passing from canvas to canvas (in vello that would be wgpu texture;
but raquote does not really have this) while bytes returns something
that must impl AsRef<[u8]> (this is more generic then `&[u8]` as it
allows us to have type with drop impl - wgpu's BufferView).

Testing: This is just refactoring (protected by rust), but there are WPT
tests.

Signed-off-by: sagudev <16504129+sagudev@users.noreply.github.com>
This commit is contained in:
sagudev 2025-05-01 16:18:56 +02:00 committed by GitHub
parent 0d21992edd
commit 5cdb0865ba
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 11 deletions

View file

@ -21,6 +21,7 @@ pub(crate) trait Backend: Clone + Sized {
type DrawTarget: GenericDrawTarget<Self>;
type PathBuilder: GenericPathBuilder<Self>;
type SourceSurface;
type Bytes<'a>: AsRef<[u8]>;
type Path: PathHelpers<Self> + Clone;
type GradientStop;
type GradientStops;
@ -98,7 +99,6 @@ pub(crate) trait GenericDrawTarget<B: Backend> {
fn pop_clip(&mut self);
fn push_clip(&mut self, path: &B::Path);
fn set_transform(&mut self, matrix: &Transform2D<f32>);
fn snapshot(&self) -> B::SourceSurface;
fn stroke(
&mut self,
path: &B::Path,
@ -121,7 +121,8 @@ pub(crate) trait GenericDrawTarget<B: Backend> {
stroke_options: &B::StrokeOptions,
draw_options: &B::DrawOptions,
);
fn snapshot_data(&self) -> &[u8];
fn surface(&self) -> B::SourceSurface;
fn bytes(&'_ self) -> B::Bytes<'_>;
}
/// A generic PathBuilder that abstracts the interface for azure's and raqote's PathBuilder.