[librsvg: 15/27] Resolve solid colors / opacity / current_color as early as PaintServer.resolve
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 15/27] Resolve solid colors / opacity / current_color as early as PaintServer.resolve
- Date: Fri, 5 Mar 2021 23:36:27 +0000 (UTC)
commit be887573933ae409b3828c9238e14fd8af8138f4
Author: Federico Mena Quintero <federico gnome org>
Date: Fri Mar 5 13:46:54 2021 -0600
Resolve solid colors / opacity / current_color as early as PaintServer.resolve
This lets us get rid of the current_color concern as soon as possible,
and thus avoid passing it everywhere.
src/drawing_ctx.rs | 86 ++++++++++++++++++--------------------------------
src/filters/context.rs | 22 ++++++-------
src/paint_server.rs | 57 +++++++++++++++++++++++----------
3 files changed, 81 insertions(+), 84 deletions(-)
---
diff --git a/src/drawing_ctx.rs b/src/drawing_ctx.rs
index ebf7f5df..ec483479 100644
--- a/src/drawing_ctx.rs
+++ b/src/drawing_ctx.rs
@@ -23,7 +23,7 @@ use crate::float_eq_cairo::ApproxEqCairo;
use crate::gradient::{GradientVariant, SpreadMethod, UserSpaceGradient};
use crate::marker;
use crate::node::{CascadedValues, Node, NodeBorrow, NodeDraw};
-use crate::paint_server::{resolve_color, PaintServer, UserSpacePaintSource};
+use crate::paint_server::{PaintServer, UserSpacePaintSource};
use crate::path_builder::*;
use crate::pattern::UserSpacePattern;
use crate::properties::ComputedValues;
@@ -1117,7 +1117,6 @@ impl DrawingCtx {
&mut self,
paint_source: &UserSpacePaintSource,
opacity: UnitInterval,
- current_color: cssparser::RGBA,
acquired_nodes: &mut AcquiredNodes<'_>,
) -> Result<bool, RenderingError> {
match *paint_source {
@@ -1125,7 +1124,7 @@ impl DrawingCtx {
if self.set_gradient(gradient, opacity)? {
Ok(true)
} else if let Some(c) = c {
- self.set_color(resolve_color(&c, opacity, current_color))
+ self.set_color(c)
} else {
Ok(false)
}
@@ -1134,14 +1133,12 @@ impl DrawingCtx {
if self.set_pattern(pattern, acquired_nodes, opacity)? {
Ok(true)
} else if let Some(c) = c {
- self.set_color(resolve_color(&c, opacity, current_color))
+ self.set_color(c)
} else {
Ok(false)
}
}
- UserSpacePaintSource::SolidColor(c) => {
- self.set_color(resolve_color(&c, opacity, current_color))
- }
+ UserSpacePaintSource::SolidColor(c) => self.set_color(c),
UserSpacePaintSource::None => Ok(false),
}
}
@@ -1154,7 +1151,6 @@ impl DrawingCtx {
acquired_nodes: &mut AcquiredNodes<'_>,
paint_source: &UserSpacePaintSource,
opacity: UnitInterval,
- current_color: cssparser::RGBA,
) -> Result<SharedImageSurface, cairo::Status> {
let mut surface = ExclusiveImageSurface::new(width, height, SurfaceType::SRgb)?;
@@ -1162,7 +1158,7 @@ impl DrawingCtx {
// FIXME: we are ignoring any error
let _ = self.with_cairo_context(cr, &mut |dc| {
- dc.set_paint_source(paint_source, opacity, current_color, acquired_nodes)
+ dc.set_paint_source(paint_source, opacity, acquired_nodes)
.map(|had_paint_server| {
if had_paint_server {
cr.paint();
@@ -1212,20 +1208,15 @@ impl DrawingCtx {
let paint_source = values
.stroke()
.0
- .resolve(acquired_nodes)?
+ .resolve(acquired_nodes, values.stroke_opacity().0, current_color)?
.to_user_space(bbox, self, values);
- self.set_paint_source(
- &paint_source,
- values.stroke_opacity().0,
- current_color,
- acquired_nodes,
- )
- .map(|had_paint_server| {
- if had_paint_server {
- cr.stroke_preserve();
- }
- })?;
+ self.set_paint_source(&paint_source, values.stroke_opacity().0, acquired_nodes)
+ .map(|had_paint_server| {
+ if had_paint_server {
+ cr.stroke_preserve();
+ }
+ })?;
Ok(())
}
@@ -1241,20 +1232,15 @@ impl DrawingCtx {
let paint_source = values
.fill()
.0
- .resolve(acquired_nodes)?
+ .resolve(acquired_nodes, values.fill_opacity().0, current_color)?
.to_user_space(bbox, self, values);
- self.set_paint_source(
- &paint_source,
- values.fill_opacity().0,
- current_color,
- acquired_nodes,
- )
- .map(|had_paint_server| {
- if had_paint_server {
- cr.fill_preserve();
- }
- })?;
+ self.set_paint_source(&paint_source, values.fill_opacity().0, acquired_nodes)
+ .map(|had_paint_server| {
+ if had_paint_server {
+ cr.fill_preserve();
+ }
+ })?;
Ok(())
}
@@ -1435,20 +1421,15 @@ impl DrawingCtx {
let current_color = values.color().0;
let res = if !clipping {
- let paint_source = values.fill().0.resolve(acquired_nodes)?.to_user_space(
- &bbox,
- saved_cr.draw_ctx,
- values,
- );
+ let paint_source = values
+ .fill()
+ .0
+ .resolve(acquired_nodes, values.fill_opacity().0, current_color)?
+ .to_user_space(&bbox, saved_cr.draw_ctx, values);
saved_cr
.draw_ctx
- .set_paint_source(
- &paint_source,
- values.fill_opacity().0,
- current_color,
- acquired_nodes,
- )
+ .set_paint_source(&paint_source, values.fill_opacity().0, acquired_nodes)
.map(|had_paint_server| {
if had_paint_server {
pangocairo::functions::update_layout(&cr, &layout);
@@ -1465,20 +1446,15 @@ impl DrawingCtx {
let mut need_layout_path = clipping;
let res = if !clipping {
- let paint_source = values.stroke().0.resolve(acquired_nodes)?.to_user_space(
- &bbox,
- saved_cr.draw_ctx,
- values,
- );
+ let paint_source = values
+ .stroke()
+ .0
+ .resolve(acquired_nodes, values.stroke_opacity().0, current_color)?
+ .to_user_space(&bbox, saved_cr.draw_ctx, values);
saved_cr
.draw_ctx
- .set_paint_source(
- &paint_source,
- values.stroke_opacity().0,
- current_color,
- acquired_nodes,
- )
+ .set_paint_source(&paint_source, values.stroke_opacity().0, acquired_nodes)
.map(|had_paint_server| {
if had_paint_server {
need_layout_path = true;
diff --git a/src/filters/context.rs b/src/filters/context.rs
index 53507fa0..c5eed5a4 100644
--- a/src/filters/context.rs
+++ b/src/filters/context.rs
@@ -288,11 +288,11 @@ impl FilterContext {
.map(FilterInput::StandardInput),
Input::FillPaint => {
- let fill_paint_source = values.fill().0.resolve(acquired_nodes)?.to_user_space(
- &self.node_bbox,
- draw_ctx,
- values,
- );
+ let fill_paint_source = values
+ .fill()
+ .0
+ .resolve(acquired_nodes, values.fill_opacity().0, values.color().0)?
+ .to_user_space(&self.node_bbox, draw_ctx, values);
draw_ctx
.get_paint_source_surface(
@@ -301,18 +301,17 @@ impl FilterContext {
acquired_nodes,
&fill_paint_source,
values.fill_opacity().0,
- values.color().0,
)
.map_err(FilterError::CairoError)
.map(FilterInput::StandardInput)
}
Input::StrokePaint => {
- let stroke_paint_source = values.stroke().0.resolve(acquired_nodes)?.to_user_space(
- &self.node_bbox,
- draw_ctx,
- values,
- );
+ let stroke_paint_source = values
+ .stroke()
+ .0
+ .resolve(acquired_nodes, values.stroke_opacity().0, values.color().0)?
+ .to_user_space(&self.node_bbox, draw_ctx, values);
draw_ctx
.get_paint_source_surface(
@@ -321,7 +320,6 @@ impl FilterContext {
acquired_nodes,
&stroke_paint_source,
values.stroke_opacity().0,
- values.color().0,
)
.map_err(FilterError::CairoError)
.map(FilterInput::StandardInput)
diff --git a/src/paint_server.rs b/src/paint_server.rs
index e4011c9a..e87b024d 100644
--- a/src/paint_server.rs
+++ b/src/paint_server.rs
@@ -29,16 +29,16 @@ pub enum PaintServer {
pub enum PaintSource {
None,
- Gradient(ResolvedGradient, Option<cssparser::Color>),
- Pattern(ResolvedPattern, Option<cssparser::Color>),
- SolidColor(cssparser::Color),
+ Gradient(ResolvedGradient, Option<cssparser::RGBA>),
+ Pattern(ResolvedPattern, Option<cssparser::RGBA>),
+ SolidColor(cssparser::RGBA),
}
pub enum UserSpacePaintSource {
None,
- Gradient(UserSpaceGradient, Option<cssparser::Color>),
- Pattern(UserSpacePattern, Option<cssparser::Color>),
- SolidColor(cssparser::Color),
+ Gradient(UserSpaceGradient, Option<cssparser::RGBA>),
+ Pattern(UserSpacePattern, Option<cssparser::RGBA>),
+ SolidColor(cssparser::RGBA),
}
impl Parse for PaintServer {
@@ -82,6 +82,8 @@ impl PaintServer {
pub fn resolve(
&self,
acquired_nodes: &mut AcquiredNodes<'_>,
+ opacity: UnitInterval,
+ current_color: cssparser::RGBA,
) -> Result<PaintSource, RenderingError> {
match self {
PaintServer::Iri {
@@ -94,15 +96,28 @@ impl PaintServer {
assert!(node.is_element());
match *node.borrow_element() {
- Element::LinearGradient(ref g) => g
- .resolve(&node, acquired_nodes)
- .map(|g| PaintSource::Gradient(g, *alternate)),
- Element::Pattern(ref p) => p
- .resolve(&node, acquired_nodes)
- .map(|p| PaintSource::Pattern(p, *alternate)),
- Element::RadialGradient(ref g) => g
- .resolve(&node, acquired_nodes)
- .map(|g| PaintSource::Gradient(g, *alternate)),
+ Element::LinearGradient(ref g) => {
+ g.resolve(&node, acquired_nodes).map(|g| {
+ PaintSource::Gradient(
+ g,
+ alternate.map(|c| resolve_color(&c, opacity, current_color)),
+ )
+ })
+ }
+ Element::Pattern(ref p) => p.resolve(&node, acquired_nodes).map(|p| {
+ PaintSource::Pattern(
+ p,
+ alternate.map(|c| resolve_color(&c, opacity, current_color)),
+ )
+ }),
+ Element::RadialGradient(ref g) => {
+ g.resolve(&node, acquired_nodes).map(|g| {
+ PaintSource::Gradient(
+ g,
+ alternate.map(|c| resolve_color(&c, opacity, current_color)),
+ )
+ })
+ }
_ => Err(AcquireError::InvalidLinkType(iri.as_ref().clone())),
}
})
@@ -125,7 +140,11 @@ impl PaintServer {
iri
);
- Ok(PaintSource::SolidColor(*color))
+ Ok(PaintSource::SolidColor(resolve_color(
+ color,
+ opacity,
+ current_color,
+ )))
}
(_, _) => {
@@ -138,7 +157,11 @@ impl PaintServer {
}
}),
- PaintServer::SolidColor(color) => Ok(PaintSource::SolidColor(*color)),
+ PaintServer::SolidColor(color) => Ok(PaintSource::SolidColor(resolve_color(
+ color,
+ opacity,
+ current_color,
+ ))),
PaintServer::None => Ok(PaintSource::None),
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]