From 5b2a4940c710974d7081de6c7c0ad05396cabc4f Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Thu, 6 Nov 2014 10:49:34 -0800 Subject: [PATCH] Add support for shadows --- src/azure-c.cpp | 22 ++++++++++++++++++++++ src/azure-c.h | 7 +++++++ src/azure.rs | 9 +++++++++ src/azure_hl.rs | 31 +++++++++++++++++++++++++------ 4 files changed, 63 insertions(+), 6 deletions(-) diff --git a/src/azure-c.cpp b/src/azure-c.cpp index f451f4e..ab5d5d9 100644 --- a/src/azure-c.cpp +++ b/src/azure-c.cpp @@ -379,6 +379,28 @@ AzDrawTargetDrawSurface(AzDrawTargetRef aDrawTarget, gfxDrawTarget->DrawSurface(gfxSourceSurface, *gfxDest, *gfxSource, *gfxDrawSurfaceOptions, *gfxDrawOptions); } +extern "C" void +AzDrawTargetDrawSurfaceWithShadow(AzDrawTargetRef aDrawTarget, + AzSourceSurfaceRef aSurface, + const AzPoint* aPoint, + const AzColor* aColor, + const AzPoint* aOffset, + AzFloat aSigma, + AzCompositionOp aOperator) { + gfx::DrawTarget* gfxDrawTarget = static_cast(aDrawTarget); + gfx::SourceSurface* gfxSourceSurface = static_cast(aSurface); + const gfx::Point* gfxPoint = reinterpret_cast(aPoint); + const gfx::Color* gfxColor = reinterpret_cast(aColor); + const gfx::Point* gfxOffset = reinterpret_cast(aOffset); + gfx::CompositionOp gfxOperator = static_cast(aOperator); + gfxDrawTarget->DrawSurfaceWithShadow(gfxSourceSurface, + *gfxPoint, + *gfxColor, + *gfxOffset, + aSigma, + gfxOperator); +} + extern "C" AzSourceSurfaceRef AzDrawTargetGetSnapshot(AzDrawTargetRef aDrawTarget) { gfx::DrawTarget *gfxDrawTarget = static_cast(aDrawTarget); diff --git a/src/azure-c.h b/src/azure-c.h index c6dc6e5..65c2d67 100644 --- a/src/azure-c.h +++ b/src/azure-c.h @@ -359,6 +359,13 @@ void AzDrawTargetDrawSurface(AzDrawTargetRef aDrawTarget, AzRect *aSource, AzDrawSurfaceOptionsRef aSurfOptions, AzDrawOptions *aOptions); +void AzDrawTargetDrawSurfaceWithShadow(AzDrawTargetRef aDrawTarget, + AzSourceSurfaceRef aSurface, + const AzPoint* aPoint, + const AzColor* aColor, + const AzPoint* aOffset, + AzFloat aSigma, + AzCompositionOp aOperator); AzSourceSurfaceRef AzDrawTargetGetSnapshot(AzDrawTargetRef aDrawTarget); AzSourceSurfaceRef AzDrawTargetCreateSourceSurfaceFromData(AzDrawTargetRef aDrawTarget, const unsigned char *aData, diff --git a/src/azure.rs b/src/azure.rs index bb39930..db360bd 100644 --- a/src/azure.rs +++ b/src/azure.rs @@ -97,6 +97,7 @@ pub static AZ_OP_SATURATION: u32 = 23_u32; pub static AZ_OP_COLOR: u32 = 24_u32; pub static AZ_OP_LUMINOSITY: u32 = 25_u32; pub static AZ_OP_COUNT: u32 = 26_u32; +pub type AzCompositionOp = enum_AzCompositionOp; pub type enum_AzExtendMode = c_uint; pub static AZ_EXTEND_CLAMP: u32 = 0_u32; @@ -391,6 +392,14 @@ pub fn AzDrawTargetFillGlyphs(aDrawTarget: AzDrawTargetRef, aFont: AzScaledFontR pub fn AzDrawTargetDrawSurface(aDrawTarget: AzDrawTargetRef, aSurface: AzSourceSurfaceRef, aDest: *mut AzRect, aSource: *mut AzRect, aSurfOptions: AzDrawSurfaceOptionsRef, aOptions: *mut AzDrawOptions); +pub fn AzDrawTargetDrawSurfaceWithShadow(aDrawTarget: AzDrawTargetRef, + aSurface: AzSourceSurfaceRef, + aDest: *const AzPoint, + aColor: *const AzColor, + aOffset: *const AzPoint, + aSigma: AzFloat, + aOperator: AzCompositionOp); + pub fn AzDrawTargetGetSnapshot(aDrawTarget: AzDrawTargetRef) -> AzSourceSurfaceRef; pub fn AzDrawTargetCreateSourceSurfaceFromData(aDrawTarget: AzDrawTargetRef, aData: *const u8, aSize: *mut AzIntSize, aStride: i32, aFormat: AzSurfaceFormat) -> AzSourceSurfaceRef; diff --git a/src/azure_hl.rs b/src/azure_hl.rs index 1f956d4..3ae2069 100644 --- a/src/azure_hl.rs +++ b/src/azure_hl.rs @@ -9,6 +9,7 @@ use azure::{AzPoint, AzRect, AzFloat, AzIntSize, AzColor, AzColorPatternRef, AzG use azure::{AzStrokeOptions, AzDrawOptions, AzSurfaceFormat, AzFilter, AzDrawSurfaceOptions}; use azure::{AzBackendType, AzDrawTargetRef, AzSourceSurfaceRef, AzDataSourceSurfaceRef}; use azure::{AzScaledFontRef, AzGlyphRenderingOptionsRef, AzExtendMode, AzGradientStop}; +use azure::{AzCompositionOp}; use azure::{struct__AzColor, struct__AzGlyphBuffer}; use azure::{struct__AzDrawOptions, struct__AzDrawSurfaceOptions, struct__AzIntSize}; use azure::{struct__AzPoint, struct__AzRect, struct__AzStrokeOptions}; @@ -33,6 +34,7 @@ use azure::{AzPathBuilderArc, AzPathBuilderFinish, AzReleasePathBuilder}; use azure::{AzDrawTargetFill, AzPathRef, AzReleasePath, AzDrawTargetPushClip, AzDrawTargetPopClip}; use azure::{AzGLNativeContextRef, AzLinearGradientPatternRef, AzMatrix, AzPatternRef}; use azure::{AzCreateLinearGradientPattern, AzDrawTargetPushClipRect}; +use azure::{AzDrawTargetDrawSurfaceWithShadow}; use sync::Arc; use geom::matrix2d::Matrix2D; @@ -532,11 +534,11 @@ impl DrawTarget { } pub fn draw_surface(&self, - surface: SourceSurface, - dest: Rect, - source: Rect, - surf_options: DrawSurfaceOptions, - options: DrawOptions) { + surface: SourceSurface, + dest: Rect, + source: Rect, + surf_options: DrawSurfaceOptions, + options: DrawOptions) { unsafe { AzDrawTargetDrawSurface(self.azure_draw_target, surface.azure_source_surface, @@ -547,6 +549,24 @@ impl DrawTarget { } } + pub fn draw_surface_with_shadow(&self, + surface: SourceSurface, + dest: &Point2D, + color: &Color, + offset: &Point2D, + sigma: AzFloat, + operator: CompositionOp) { + unsafe { + AzDrawTargetDrawSurfaceWithShadow(self.azure_draw_target, + surface.azure_source_surface, + mem::transmute::<_,*const AzPoint>(dest), + mem::transmute::<_,*const AzColor>(color), + mem::transmute::<_,*const AzPoint>(offset), + sigma, + operator as AzCompositionOp) + } + } + pub fn snapshot(&self) -> SourceSurface { unsafe { let azure_surface = AzDrawTargetGetSnapshot(self.azure_draw_target); @@ -631,7 +651,6 @@ impl DrawTarget { unsafe { AzDrawTargetPopClip(self.azure_draw_target); } - } }