Create raqote::SolidSource with premultiplied color

SolidSource expects a premultiplied color.
This commit is contained in:
pylbrecht 2019-11-05 20:09:32 +01:00
parent 77a8bc4a1d
commit 5c6a12a116

View file

@ -84,12 +84,12 @@ impl Backend for RaqoteBackend {
impl<'a> CanvasPaintState<'a> { impl<'a> CanvasPaintState<'a> {
pub fn new(_antialias: AntialiasMode) -> CanvasPaintState<'a> { pub fn new(_antialias: AntialiasMode) -> CanvasPaintState<'a> {
let solid_src = raqote::SolidSource { let solid_src = raqote::SolidSource::from_unpremultiplied_argb(
r: 0, 255,
g: 0, 0,
b: 0, 0,
a: 255, 0,
}; );
CanvasPaintState { CanvasPaintState {
draw_options: DrawOptions::Raqote(raqote::DrawOptions::new()), draw_options: DrawOptions::Raqote(raqote::DrawOptions::new()),
fill_style: Pattern::Raqote(raqote::Source::Solid(solid_src)), fill_style: Pattern::Raqote(raqote::Source::Solid(solid_src)),
@ -99,12 +99,12 @@ impl<'a> CanvasPaintState<'a> {
shadow_offset_x: 0.0, shadow_offset_x: 0.0,
shadow_offset_y: 0.0, shadow_offset_y: 0.0,
shadow_blur: 0.0, shadow_blur: 0.0,
shadow_color: Color::Raqote(raqote::SolidSource { shadow_color: Color::Raqote(raqote::SolidSource::from_unpremultiplied_argb(
r: 0, 0,
g: 0, 0,
b: 0, 0,
a: 0, 0,
}), )),
} }
} }
} }
@ -221,12 +221,12 @@ impl GenericDrawTarget for raqote::DrawTarget {
raqote::DrawTarget::fill( raqote::DrawTarget::fill(
self, self,
&pb.finish(), &pb.finish(),
&raqote::Source::Solid(raqote::SolidSource { &raqote::Source::Solid(raqote::SolidSource::from_unpremultiplied_argb(
r: 0, 0,
g: 0, 0,
b: 0, 0,
a: 0, 0,
}), )),
&options, &options,
); );
} }
@ -652,12 +652,12 @@ impl<'a> ToRaqoteSource<'a> for FillOrStrokeStyle {
use canvas_traits::canvas::FillOrStrokeStyle::*; use canvas_traits::canvas::FillOrStrokeStyle::*;
match self { match self {
Color(rgba) => Some(raqote::Source::Solid(raqote::SolidSource { Color(rgba) => Some(raqote::Source::Solid(raqote::SolidSource::from_unpremultiplied_argb(
r: rgba.red, rgba.alpha,
g: rgba.green, rgba.red,
b: rgba.blue, rgba.green,
a: rgba.alpha, rgba.blue,
})), ))),
LinearGradient(style) => { LinearGradient(style) => {
let stops = style.stops.into_iter().map(|s| s.to_raqote()).collect(); let stops = style.stops.into_iter().map(|s| s.to_raqote()).collect();
let gradient = raqote::Gradient { stops }; let gradient = raqote::Gradient { stops };
@ -715,12 +715,12 @@ impl ToRaqoteStyle for RGBA {
type Target = raqote::SolidSource; type Target = raqote::SolidSource;
fn to_raqote_style(self) -> Self::Target { fn to_raqote_style(self) -> Self::Target {
raqote::SolidSource { raqote::SolidSource::from_unpremultiplied_argb(
r: self.red, self.alpha,
g: self.green, self.red,
b: self.blue, self.green,
a: self.alpha, self.blue,
} )
} }
} }