mirror of
https://github.com/servo/servo.git
synced 2025-07-23 15:23:42 +01:00
Respect FilterMode when drawing images
This commit is contained in:
parent
16f06f24c5
commit
a473f50245
1 changed files with 29 additions and 10 deletions
|
@ -278,29 +278,39 @@ impl GenericDrawTarget for raqote::DrawTarget {
|
||||||
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,
|
||||||
) {
|
) {
|
||||||
let v = surface.as_raqote();
|
let surface_data = surface.as_raqote();
|
||||||
let image = raqote::Image {
|
let image = raqote::Image {
|
||||||
width: source.size.width as i32,
|
width: source.size.width as i32,
|
||||||
height: source.size.height as i32,
|
height: source.size.height as i32,
|
||||||
data: unsafe {
|
data: unsafe {
|
||||||
std::slice::from_raw_parts(
|
std::slice::from_raw_parts(
|
||||||
v.as_ptr() as *const u32,
|
surface_data.as_ptr() as *const u32,
|
||||||
v.len() / std::mem::size_of::<u32>(),
|
surface_data.len() / std::mem::size_of::<u32>(),
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
raqote::DrawTarget::draw_image_with_size_at(
|
let mut pb = raqote::PathBuilder::new();
|
||||||
self,
|
pb.rect(
|
||||||
dest.size.width as f32,
|
|
||||||
dest.size.height as f32,
|
|
||||||
dest.origin.x as f32,
|
dest.origin.x as f32,
|
||||||
dest.origin.y as f32,
|
dest.origin.y as f32,
|
||||||
&image,
|
dest.size.width as f32,
|
||||||
draw_options.as_raqote(),
|
dest.size.height as f32,
|
||||||
);
|
);
|
||||||
|
let source = raqote::Source::Image(
|
||||||
|
image,
|
||||||
|
raqote::ExtendMode::Pad,
|
||||||
|
filter.to_raqote(),
|
||||||
|
raqote::Transform::create_translation(-dest.origin.x as f32, -dest.origin.y as f32)
|
||||||
|
.post_scale(
|
||||||
|
image.width as f32 / dest.size.width as f32,
|
||||||
|
image.height as f32 / dest.size.height as f32,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
self.fill(&pb.finish(), &source, draw_options.as_raqote());
|
||||||
}
|
}
|
||||||
fn draw_surface_with_shadow(
|
fn draw_surface_with_shadow(
|
||||||
&self,
|
&self,
|
||||||
|
@ -446,6 +456,15 @@ impl GenericDrawTarget for raqote::DrawTarget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Filter {
|
||||||
|
fn to_raqote(&self) -> raqote::FilterMode {
|
||||||
|
match self {
|
||||||
|
Filter::Linear => raqote::FilterMode::Bilinear,
|
||||||
|
Filter::Point => raqote::FilterMode::Nearest,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
struct PathBuilder(Option<raqote::PathBuilder>);
|
struct PathBuilder(Option<raqote::PathBuilder>);
|
||||||
|
|
||||||
impl PathBuilder {
|
impl PathBuilder {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue