mirror of
https://github.com/servo/servo.git
synced 2025-08-04 13:10:20 +01:00
Implement a few functions to make tests in draw-image and draw-path pass
This commit is contained in:
parent
8cb8e7c627
commit
dc78b6a989
2 changed files with 53 additions and 16 deletions
|
@ -239,7 +239,7 @@ pub trait GenericDrawTarget {
|
||||||
stride: i32,
|
stride: i32,
|
||||||
) -> Option<SourceSurface>;
|
) -> Option<SourceSurface>;
|
||||||
fn draw_surface(
|
fn draw_surface(
|
||||||
&self,
|
&mut self,
|
||||||
surface: SourceSurface,
|
surface: SourceSurface,
|
||||||
dest: Rect<f64>,
|
dest: Rect<f64>,
|
||||||
source: Rect<f64>,
|
source: Rect<f64>,
|
||||||
|
@ -340,7 +340,7 @@ pub enum SourceSurface {
|
||||||
#[cfg(feature = "canvas2d-azure")]
|
#[cfg(feature = "canvas2d-azure")]
|
||||||
Azure(azure::azure_hl::SourceSurface),
|
Azure(azure::azure_hl::SourceSurface),
|
||||||
#[cfg(feature = "canvas2d-raqote")]
|
#[cfg(feature = "canvas2d-raqote")]
|
||||||
Raqote(()),
|
Raqote(Vec<u8>), // TODO: See if we can avoid the alloc (probably?)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -1133,7 +1133,7 @@ pub struct CanvasPaintState<'a> {
|
||||||
/// dest_rect: Area of the destination target where the pixels will be copied
|
/// dest_rect: Area of the destination target where the pixels will be copied
|
||||||
/// smoothing_enabled: It determines if smoothing is applied to the image result
|
/// smoothing_enabled: It determines if smoothing is applied to the image result
|
||||||
fn write_image(
|
fn write_image(
|
||||||
draw_target: &dyn GenericDrawTarget,
|
draw_target: &mut dyn GenericDrawTarget,
|
||||||
image_data: Vec<u8>,
|
image_data: Vec<u8>,
|
||||||
image_size: Size2D<f64>,
|
image_size: Size2D<f64>,
|
||||||
dest_rect: Rect<f64>,
|
dest_rect: Rect<f64>,
|
||||||
|
|
|
@ -188,7 +188,7 @@ impl Path {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn copy_to_builder(&self) -> Box<dyn GenericPathBuilder> {
|
pub fn copy_to_builder(&self) -> Box<dyn GenericPathBuilder> {
|
||||||
unimplemented!()
|
Box::new(PathBuilder(Some(raqote::PathBuilder::from(self.as_raqote().clone()))))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn as_raqote(&self) -> &raqote::Path {
|
pub fn as_raqote(&self) -> &raqote::Path {
|
||||||
|
@ -221,13 +221,23 @@ impl GenericDrawTarget for raqote::DrawTarget {
|
||||||
&options,
|
&options,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
#[allow(unsafe_code)]
|
||||||
fn copy_surface(
|
fn copy_surface(
|
||||||
&mut self,
|
&mut self,
|
||||||
_surface: SourceSurface,
|
surface: SourceSurface,
|
||||||
_source: Rect<i32>,
|
source: Rect<i32>,
|
||||||
_destination: Point2D<i32>,
|
destination: Point2D<i32>,
|
||||||
) {
|
) {
|
||||||
unimplemented!();
|
let mut dt = raqote::DrawTarget::new(source.size.width, source.size.height);
|
||||||
|
let data = surface.as_raqote();
|
||||||
|
let s = unsafe { std::slice::from_raw_parts(data.as_ptr() as *const u32, data.len() / 4) };
|
||||||
|
dt.get_data_mut().copy_from_slice(s);
|
||||||
|
raqote::DrawTarget::copy_surface(
|
||||||
|
self,
|
||||||
|
&dt,
|
||||||
|
source.to_box2d(),
|
||||||
|
destination
|
||||||
|
);
|
||||||
}
|
}
|
||||||
fn create_gradient_stops(
|
fn create_gradient_stops(
|
||||||
&self,
|
&self,
|
||||||
|
@ -248,21 +258,40 @@ impl GenericDrawTarget for raqote::DrawTarget {
|
||||||
}
|
}
|
||||||
fn create_source_surface_from_data(
|
fn create_source_surface_from_data(
|
||||||
&self,
|
&self,
|
||||||
_data: &[u8],
|
data: &[u8],
|
||||||
_size: Size2D<i32>,
|
_size: Size2D<i32>,
|
||||||
_stride: i32,
|
_stride: i32,
|
||||||
) -> Option<SourceSurface> {
|
) -> Option<SourceSurface> {
|
||||||
unimplemented!();
|
Some(SourceSurface::Raqote(data.to_vec()))
|
||||||
}
|
}
|
||||||
|
#[allow(unsafe_code)]
|
||||||
fn draw_surface(
|
fn draw_surface(
|
||||||
&self,
|
&mut self,
|
||||||
_surface: SourceSurface,
|
surface: SourceSurface,
|
||||||
_dest: Rect<f64>,
|
dest: Rect<f64>,
|
||||||
_source: Rect<f64>,
|
source: Rect<f64>,
|
||||||
_filter: Filter,
|
_filter: Filter,
|
||||||
_draw_options: &DrawOptions,
|
draw_options: &DrawOptions,
|
||||||
) {
|
) {
|
||||||
unimplemented!();
|
let v = surface.as_raqote();
|
||||||
|
let image = raqote::Image {
|
||||||
|
width: source.size.width as i32,
|
||||||
|
height: source.size.height as i32,
|
||||||
|
data: unsafe {
|
||||||
|
std::slice::from_raw_parts(
|
||||||
|
v.as_ptr() as *const u32,
|
||||||
|
v.len() * std::mem::size_of::<u8>(),
|
||||||
|
) },
|
||||||
|
};
|
||||||
|
raqote::DrawTarget::draw_image_with_size_at(
|
||||||
|
self,
|
||||||
|
dest.size.width as f32,
|
||||||
|
dest.size.height as f32,
|
||||||
|
dest.origin.x as f32,
|
||||||
|
dest.origin.y as f32,
|
||||||
|
&image,
|
||||||
|
draw_options.as_raqote(),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
fn draw_surface_with_shadow(
|
fn draw_surface_with_shadow(
|
||||||
&self,
|
&self,
|
||||||
|
@ -617,3 +646,11 @@ impl ToRaqoteStyle for CompositionStyle {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl SourceSurface {
|
||||||
|
fn as_raqote(&self) -> &Vec<u8> {
|
||||||
|
match self {
|
||||||
|
SourceSurface::Raqote(s) => s,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue