diff --git a/azure-c.cpp b/azure-c.cpp index a6edb15..e2e85c3 100644 --- a/azure-c.cpp +++ b/azure-c.cpp @@ -282,6 +282,29 @@ AzDrawTargetClearRect(AzDrawTargetRef aDrawTarget, AzRect *aRect) { gfxDrawTarget->ClearRect(*gfxRect); } +extern "C" void +AzDrawTargetFill(AzDrawTargetRef aDrawTarget, AzPathRef aPath, + AzPatternRef aPattern, AzDrawOptions *aDrawOptions) { + gfx::DrawTarget *gfxDrawTarget = static_cast(aDrawTarget); + gfx::Path *gfxPath = static_cast(aPath); + gfx::Pattern *gfxPattern = static_cast(aPattern); + gfx::DrawOptions *gfxDrawOptions = reinterpret_cast(aDrawOptions); + gfxDrawTarget->Fill(gfxPath, *gfxPattern, *gfxDrawOptions); +} + +extern "C" void +AzDrawTargetPushClip(AzDrawTargetRef aDrawTarget, const AzPathRef *aPath) { + gfx::DrawTarget *gfxDrawTarget = static_cast(aDrawTarget); + const gfx::Path *gfxPath = reinterpret_cast(aPath); + gfxDrawTarget->PushClip(gfxPath); +} + +extern "C" void +AzDrawTargetPopClip(AzDrawTargetRef aDrawTarget) { + gfx::DrawTarget *gfxDrawTarget = static_cast(aDrawTarget); + gfxDrawTarget->PopClip(); +} + extern "C" void AzDrawTargetFillRect(AzDrawTargetRef aDrawTarget, AzRect *aRect, AzPatternRef aPattern) { @@ -456,3 +479,46 @@ extern "C" AzGLContext AzSkiaGetCurrentGLContext() { return SkNativeSharedGLContext::GetCurrent(); } + +// FIXME: Needs to take a FillRule +extern "C" AzPathBuilderRef +AzCreatePathBuilder(AzDrawTargetRef aDrawTarget) { + gfx::DrawTarget *gfxDrawTarget = static_cast(aDrawTarget); + RefPtr gfxPathBuilder = gfxDrawTarget->CreatePathBuilder(); + gfxPathBuilder->AddRef(); + return gfxPathBuilder; +} + +extern "C" void +AzReleasePathBuilder(AzPathBuilderRef aPathBuilder) { + gfx::PathBuilder *gfxPathBuilder = static_cast(aPathBuilder); + gfxPathBuilder->Release(); +} + +extern "C" void +AzPathBuilderMoveTo(AzPathBuilderRef aPathBuilder, const AzPoint *aPoint) { + gfx::PathBuilder *gfxPathBuilder = static_cast(aPathBuilder); + const gfx::Point *gfxPoint = reinterpret_cast(aPoint); + gfxPathBuilder->MoveTo(*gfxPoint); +} + +extern "C" void +AzPathBuilderLineTo(AzPathBuilderRef aPathBuilder, const AzPoint *aPoint) { + gfx::PathBuilder *gfxPathBuilder = static_cast(aPathBuilder); + const gfx::Point *gfxPoint = reinterpret_cast(aPoint); + gfxPathBuilder->LineTo(*gfxPoint); +} + +extern "C" AzPathRef +AzPathBuilderFinish(AzPathBuilderRef aPathBuilder) { + gfx::PathBuilder *gfxPathBuilder = static_cast(aPathBuilder); + RefPtr gfxPath = gfxPathBuilder->Finish(); + gfxPath->AddRef(); + return gfxPath; +} + +extern "C" void +AzReleasePath(AzPathRef aPath) { + gfx::Path *gfxPath = static_cast(aPath); + gfxPath->Release(); +} diff --git a/azure-c.h b/azure-c.h index a134562..35400bf 100644 --- a/azure-c.h +++ b/azure-c.h @@ -296,6 +296,8 @@ typedef void* AzSourceSurfaceRef; typedef void* AzDrawSurfaceOptionsRef; typedef void* AzDataSourceSurfaceRef; typedef void* AzGLContextMetadataRef; +typedef void* AzPathBuilderRef; +typedef void* AzPathRef; typedef GrGLSharedContext AzGLContext; typedef GrGLNativeContext* AzGLNativeContextRef; diff --git a/azure.rs b/azure.rs index c59f389..29be455 100644 --- a/azure.rs +++ b/azure.rs @@ -284,6 +284,10 @@ pub type AzGLContextMetadataRef = *c_void; pub type AzGLNativeContextRef = *c_void; +pub type AzPathRef = *c_void; + +pub type AzPathBuilderRef = *c_void; + #[link_args="-lazure"] extern { @@ -332,6 +336,12 @@ pub fn AzDrawTargetStrokeRect(aDrawTarget: AzDrawTargetRef, aRect: *AzRect, aPat pub fn AzDrawTargetStrokeLine(aDrawTarget: AzDrawTargetRef, aStart: *AzPoint, aEnd: *AzPoint, aPattern: AzPatternRef, aStrokeOptions: *AzStrokeOptions, aDrawOptions: *AzDrawOptions); +pub fn AzDrawTargetFill(aDrawTarget: AzDrawTargetRef, aPath: AzPathRef, aPattern: AzPatternRef, aOptions: *AzDrawOptions); + +pub fn AzDrawTargetPushClip(aDrawTarget: AzDrawTargetRef, aPath: AzPathRef); + +pub fn AzDrawTargetPopClip(aDrawTarget: AzDrawTargetRef); + pub fn AzDrawTargetFillGlyphs(aDrawTarget: AzDrawTargetRef, aFont: AzScaledFontRef, aGlyphBuffer: *AzGlyphBuffer, aPattern: AzPatternRef, aOptions: *AzDrawOptions, aRenderingOptions: AzGlyphRenderingOptionsRef); pub fn AzDrawTargetDrawSurface(aDrawTarget: AzDrawTargetRef, aSurface: AzSourceSurfaceRef, aDest: *AzRect, aSource: *AzRect, aSurfOptions: AzDrawSurfaceOptionsRef, aOptions: *AzDrawOptions); @@ -364,4 +374,16 @@ pub fn AzDestroyFontOptions(aOptions: *AzFontOptions); pub fn AzSkiaGetCurrentGLContext() -> AzGLContext; +pub fn AzCreatePathBuilder(aDrawTarget: AzDrawTargetRef) -> AzPathBuilderRef; + +pub fn AzReleasePathBuilder(aPathBuilder: AzPathBuilderRef); + +pub fn AzPathBuilderMoveTo(aPathBuilder: AzPathBuilderRef, aPoint: *AzPoint); + +pub fn AzPathBuilderLineTo(aPathBuilder: AzPathBuilderRef, aPoint: *AzPoint); + +pub fn AzPathBuilderFinish(aPathBuilder: AzPathBuilderRef) -> AzPathRef; + +pub fn AzReleasePath(aPath: AzPathRef); + } diff --git a/azure_hl.rs b/azure_hl.rs index 97842a0..b1d6d22 100644 --- a/azure_hl.rs +++ b/azure_hl.rs @@ -27,6 +27,8 @@ use azure::{AzSourceSurfaceGetDataSurface, AzSourceSurfaceGetFormat}; use azure::{AzSourceSurfaceGetSize, AzCreateSkiaDrawTargetForFBO, AzSkiaGetCurrentGLContext}; use azure::{AzSkiaSharedGLContextMakeCurrent, AzSkiaSharedGLContextStealSurface}; use azure::{AzSkiaSharedGLContextFlush, AzSkiaGrGLSharedSurfaceRef}; +use azure::{AzCreatePathBuilder, AzPathBuilderRef, AzPathBuilderMoveTo, AzPathBuilderLineTo, AzPathBuilderFinish, AzReleasePathBuilder}; +use azure::{AzDrawTargetFill, AzPathRef, AzReleasePath, AzDrawTargetPushClip, AzDrawTargetPopClip}; use extra::arc::Arc; use geom::matrix2d::Matrix2D; @@ -433,6 +435,16 @@ impl DrawTarget { } } + #[fixed_stack_segment] + pub fn fill(&self, path: &Path, pattern: &ColorPattern, draw_options: &DrawOptions) { + unsafe { + AzDrawTargetFill(self.azure_draw_target, + path.azure_path, + pattern.azure_color_pattern, + &draw_options.as_azure_draw_options()); + } + } + #[fixed_stack_segment] pub fn fill_rect(&self, rect: &Rect, pattern: &ColorPattern) { unsafe { @@ -539,6 +551,30 @@ impl DrawTarget { renderingOptions); } } + + #[fixed_stack_segment] + pub fn create_path_builder(&self) -> PathBuilder { + unsafe { + PathBuilder { + azure_path_builder: AzCreatePathBuilder(self.azure_draw_target) + } + } + } + + #[fixed_stack_segment] + pub fn push_clip(&self, path: &Path) { + unsafe { + AzDrawTargetPushClip(self.azure_draw_target,path.azure_path); + } + } + + #[fixed_stack_segment] + pub fn pop_clip(&self) { + unsafe { + AzDrawTargetPopClip(self.azure_draw_target); + } + + } } // Ugly workaround for the lack of explicit self. @@ -655,6 +691,60 @@ impl SourceSurfaceMethods for DataSourceSurface { } } +struct Path { + priv azure_path: AzPathRef +} + +impl Drop for Path { + #[fixed_stack_segment] + fn drop(&mut self){ + unsafe { + AzReleasePath(self.azure_path); + } + } +} + +struct PathBuilder { + priv azure_path_builder: AzPathBuilderRef +} + +impl PathBuilder { + #[fixed_stack_segment] + pub fn move_to(&self, point: Point2D) { + unsafe { + let az_point = point.as_azure_point(); + AzPathBuilderMoveTo(self.azure_path_builder, &az_point); + } + } + + #[fixed_stack_segment] + pub fn line_to(&self, point: Point2D) { + unsafe { + let az_point = point.as_azure_point(); + AzPathBuilderLineTo(self.azure_path_builder, &az_point); + } + } + + #[fixed_stack_segment] + pub fn finish(&self) -> Path{ + unsafe { + let az_path = AzPathBuilderFinish(self.azure_path_builder); + Path { + azure_path : az_path + } + } + } +} + +impl Drop for PathBuilder { + #[fixed_stack_segment] + fn drop(&mut self) { + unsafe { + AzReleasePathBuilder(self.azure_path_builder); + } + } +} + #[fixed_stack_segment] pub fn current_gl_context() -> AzGLContext { unsafe {