[librsvg: 7/14] Add an alpha-only flag to SharedImageSurface
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 7/14] Add an alpha-only flag to SharedImageSurface
- Date: Sun, 15 Jul 2018 17:55:56 +0000 (UTC)
commit cfc20af4626b4cf2f264fe266f43c238efb0852b
Author: Ivan Molodetskikh <yalterz gmail com>
Date: Sun Jul 15 13:57:27 2018 +0300
Add an alpha-only flag to SharedImageSurface
rsvg_internals/src/surface_utils/shared_surface.rs | 28 +++++++++++++++++++++-
1 file changed, 27 insertions(+), 1 deletion(-)
---
diff --git a/rsvg_internals/src/surface_utils/shared_surface.rs
b/rsvg_internals/src/surface_utils/shared_surface.rs
index f4ffd632..23cc45be 100644
--- a/rsvg_internals/src/surface_utils/shared_surface.rs
+++ b/rsvg_internals/src/surface_utils/shared_surface.rs
@@ -46,6 +46,12 @@ pub struct SharedImageSurface {
width: i32,
height: i32,
stride: isize,
+
+ /// Whether this surface contains meaningful data only in the alpha channel.
+ ///
+ /// This is used for optimizations, particularly in `convolve()` to skip processing other
+ /// channels.
+ alpha_only: bool,
}
impl SharedImageSurface {
@@ -82,9 +88,23 @@ impl SharedImageSurface {
width,
height,
stride,
+ alpha_only: false,
})
}
+ /// Creates a `SharedImageSurface` from a unique `ImageSurface` with meaningful data only in
+ /// the alpha channel.
+ ///
+ /// # Panics
+ /// Panics if the surface format isn't `ARgb32` and if the surface is not unique, that is, its
+ /// reference count isn't 1.
+ #[inline]
+ pub fn new_alpha_only(surface: ImageSurface) -> Result<Self, cairo::Status> {
+ let mut rv = Self::new(surface)?;
+ rv.alpha_only = true;
+ Ok(rv)
+ }
+
/// Converts this `SharedImageSurface` back into a Cairo image surface.
///
/// # Panics
@@ -111,6 +131,12 @@ impl SharedImageSurface {
self.height
}
+ /// Returns `true` if the surface contains meaningful data only in the alpha channel.
+ #[inline]
+ pub fn is_alpha_only(&self) -> bool {
+ self.alpha_only
+ }
+
/// Retrieves the pixel value at the given coordinates.
#[inline]
pub fn get_pixel(&self, x: u32, y: u32) -> Pixel {
@@ -226,7 +252,7 @@ impl SharedImageSurface {
}
}
- SharedImageSurface::new(output_surface)
+ SharedImageSurface::new_alpha_only(output_surface)
}
/// Returns a surface with pre-multiplication of color values undone.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]