From 0614ec788d532d666b34abaf1846e75c22bf99c5 Mon Sep 17 00:00:00 2001 From: Akos Kiss Date: Wed, 14 Jan 2015 16:51:36 +0000 Subject: [PATCH 1/3] Enhance the detection of SSE2-compatible targets Assuming that any target that doesn't have "arm" in its name is an i686 or x86_64 and thus SSE2-compatible is incorrect (counter examples: aarch64 or mips). Make the check as fool-proof as possible. --- makefile.cargo | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/makefile.cargo b/makefile.cargo index 0b32992..ef6ab32 100644 --- a/makefile.cargo +++ b/makefile.cargo @@ -77,7 +77,13 @@ CXXFLAGS += \ USE_CLANG = $(shell $(CXX) --version|grep -c 'clang') -ifneq (arm,$(findstring arm,$(TARGET))) +ifeq (i686,$(findstring i686,$(TARGET))) + supports_sse = true +endif +ifeq (x86_64,$(findstring x86_64,$(TARGET))) + supports_sse = true +endif +ifeq (true,$(supports_sse)) AZURE_CPP_SRC += \ libazure/BlurSSE2.cpp \ libazure/FilterProcessingSSE2.cpp \ From dcb529e12ae2cb4677770798f87f6b5192d28cad Mon Sep 17 00:00:00 2001 From: Josh Matthews Date: Fri, 16 Jan 2015 16:56:47 -0500 Subject: [PATCH 2/3] Update rustc to 00b112c45a604fa6f4b59af2a40c9deeadfdb7c6/rustc-1.0.0-dev. --- src/azure.rs | 4 ++-- src/azure_hl.rs | 19 ++++++++++--------- src/lib.rs | 2 -- 3 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/azure.rs b/src/azure.rs index 838663a..f2187c6 100644 --- a/src/azure.rs +++ b/src/azure.rs @@ -243,7 +243,7 @@ pub static AZ_ATT_TRANSFER_DISABLE_B: u32 = 2; pub static AZ_ATT_TRANSFER_DISABLE_A: u32 = 3; #[repr(C)] -#[deriving(Clone)] +#[derive(Clone)] pub struct struct__AzColor { pub r: AzFloat, pub g: AzFloat, @@ -325,7 +325,7 @@ pub struct struct__AzMatrix { pub type AzMatrix = struct__AzMatrix; #[repr(C)] -#[deriving(PartialEq, Clone)] +#[derive(PartialEq, Clone)] pub struct struct__AzMatrix5x4 { pub _11: AzFloat, pub _12: AzFloat, pub _13: AzFloat, pub _14: AzFloat, pub _21: AzFloat, pub _22: AzFloat, pub _23: AzFloat, pub _24: AzFloat, diff --git a/src/azure_hl.rs b/src/azure_hl.rs index d43ba48..4d9723d 100644 --- a/src/azure_hl.rs +++ b/src/azure_hl.rs @@ -107,7 +107,7 @@ impl AsAzurePoint for Point2D { } } -#[deriving(Copy, Clone)] +#[derive(Copy, Clone)] pub struct Color { pub r: AzFloat, pub g: AzFloat, @@ -195,7 +195,7 @@ impl StrokeOptions { miter_limit: miter_limit, mDashPattern: ptr::null_mut(), mDashLength: 0, - fields: AZ_CAP_BUTT as u8 << 4 | AZ_JOIN_MITER_OR_BEVEL as u8 + fields: (AZ_CAP_BUTT as u8) << 4 | AZ_JOIN_MITER_OR_BEVEL as u8 } } @@ -285,7 +285,7 @@ impl SurfaceFormat { } } -#[deriving(Copy)] +#[derive(Copy)] pub enum Filter { Good, Linear, @@ -320,7 +320,7 @@ impl DrawSurfaceOptions { } -#[deriving(Clone, PartialEq)] +#[derive(Clone, PartialEq)] pub enum BackendType { None, Direct2D, @@ -802,14 +802,14 @@ impl GradientStops { } #[repr(C)] -#[deriving(Clone)] +#[derive(Clone)] pub struct GradientStop { pub offset: AzFloat, pub color: Color, } #[repr(i32)] -#[deriving(Clone, PartialEq)] +#[derive(Clone, PartialEq)] pub enum ExtendMode { Clamp = 0, Repeat = 1, @@ -879,11 +879,12 @@ impl Drop for DataSourceSurface { } impl DataSourceSurface { - pub fn with_data(&self, f: |&[u8]|) { + pub fn with_data(&self, f: F) { unsafe { let buf = AzDataSourceSurfaceGetData(self.azure_data_source_surface) as *const u8; let len = self.stride() * self.size().height; - slice::raw::buf_as_slice(buf, len as uint, f); + let slice = slice::from_raw_buf(&buf, len as usize); + f(slice) } } @@ -1339,7 +1340,7 @@ impl FilterInput for FilterNode { } } -#[deriving(PartialEq, Clone, Show)] +#[derive(PartialEq, Clone, Show)] pub struct Matrix5x4 { pub m11: AzFloat, pub m12: AzFloat, pub m13: AzFloat, pub m14: AzFloat, pub m21: AzFloat, pub m22: AzFloat, pub m23: AzFloat, pub m24: AzFloat, diff --git a/src/lib.rs b/src/lib.rs index 5349fb4..a995dc3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,6 @@ #![crate_name = "azure"] #![crate_type = "rlib"] -#![feature(globs)] - extern crate libc; extern crate geom; #[cfg(target_os = "linux")] From 99792b5c4634d439ebaf681ac7955a74ef18b319 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Tue, 13 Jan 2015 08:23:20 -0800 Subject: [PATCH 3/3] Support cubic Bezier curves --- src/azure-c.cpp | 18 ++++++++++++++++++ src/azure-c.h | 5 +++++ src/azure.rs | 7 +++++++ src/azure_hl.rs | 41 +++++++++++++++++++++++++++++++++++++++-- 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/src/azure-c.cpp b/src/azure-c.cpp index c68827f..daf3520 100644 --- a/src/azure-c.cpp +++ b/src/azure-c.cpp @@ -668,6 +668,24 @@ extern "C" void AzPathBuilderArc(AzPathBuilderRef aPathBuilder, gfxPathBuilder->Arc(*gfxOrigin, aRadius, aStartAngle, aEndAngle, aAntiClockwise); } +extern "C" void +AzPathBuilderBezierTo(AzPathBuilderRef aPathBuilder, + const AzPoint *aControlPoint1, + const AzPoint *aControlPoint2, + const AzPoint *aControlPoint3) { + gfx::PathBuilder *gfxPathBuilder = static_cast(aPathBuilder); + const gfx::Point *gfxControlPoint1 = reinterpret_cast(aControlPoint1); + const gfx::Point *gfxControlPoint2 = reinterpret_cast(aControlPoint2); + const gfx::Point *gfxControlPoint3 = reinterpret_cast(aControlPoint3); + gfxPathBuilder->BezierTo(*gfxControlPoint1, *gfxControlPoint2, *gfxControlPoint3); +} + +extern "C" void +AzPathBuilderClose(AzPathBuilderRef aPathBuilder) { + gfx::PathBuilder *gfxPathBuilder = static_cast(aPathBuilder); + gfxPathBuilder->Close(); +} + extern "C" AzPathRef AzPathBuilderFinish(AzPathBuilderRef aPathBuilder) { gfx::PathBuilder *gfxPathBuilder = static_cast(aPathBuilder); diff --git a/src/azure-c.h b/src/azure-c.h index 36e9661..8802a28 100644 --- a/src/azure-c.h +++ b/src/azure-c.h @@ -453,6 +453,11 @@ void AzPathBuilderArc(AzPathBuilderRef aPathBuilder, AzFloat aStartAngle, AzFloat aEndAngle, bool aAntiClockwise); +void AzPathBuilderBezierTo(AzPathBuilderRef aPathBuilder, + const AzPoint *aControlPoint1, + const AzPoint *aControlPoint2, + const AzPoint *aControlPoint3); +void AzPathBuilderClose(AzPathBuilderRef aPathBuilder); AzPathRef AzPathBuilderFinish(AzPathBuilderRef aPathBuilder); AzLinearGradientPatternRef AzCreateLinearGradientPattern(const AzPoint *aBegin, diff --git a/src/azure.rs b/src/azure.rs index f2187c6..afd7207 100644 --- a/src/azure.rs +++ b/src/azure.rs @@ -588,6 +588,13 @@ pub fn AzPathBuilderArc(aPathBuilder: AzPathBuilderRef, aEndAngle: AzFloat, aAntiClockwise: bool); +pub fn AzPathBuilderBezierTo(aPathBuilder: AzPathBuilderRef, + aControlPoint1: *const AzPoint, + aControlPoint2: *const AzPoint, + aControlPoint3: *const AzPoint); + +pub fn AzPathBuilderClose(aPathBuilder: AzPathBuilderRef); + pub fn AzPathBuilderFinish(aPathBuilder: AzPathBuilderRef) -> AzPathRef; pub fn AzReleasePath(aPath: AzPathRef); diff --git a/src/azure_hl.rs b/src/azure_hl.rs index 4d9723d..732a08f 100644 --- a/src/azure_hl.rs +++ b/src/azure_hl.rs @@ -53,7 +53,8 @@ use azure::{AzFilterNodeSetSourceSurfaceInput, AzReleaseFilterNode, AzDrawTarget use azure::{AzFilterNodeSetColorAttribute, AzFilterNodeSetFloatAttribute}; use azure::{AzFilterNodeSetMatrix5x4Attribute, AzFilterNodeSetFilterNodeInput}; use azure::{AzFilterNodeSetFloatArrayAttribute, AzFilterNodeSetBoolAttribute}; -use azure::{AzDrawTargetDrawFilter, AzFilterNodeRef, AzFilterType}; +use azure::{AzDrawTargetDrawFilter, AzFilterNodeRef, AzFilterType, AzPathBuilderBezierTo}; +use azure::{AzPathBuilderClose}; use std::sync::Arc; use geom::matrix2d::Matrix2D; @@ -404,7 +405,7 @@ impl DrawTarget { size: Size2D, stride: i32, format: SurfaceFormat) -> DrawTarget { - assert!((data.len() - offset) as i32 >= stride * size.height); + assert!((data.len() - (offset as usize)) as i32 >= stride * size.height); let azure_draw_target = unsafe { AzCreateDrawTargetForData(backend.as_azure_backend_type(), data.as_mut_slice().as_mut_ptr().offset(offset as int), @@ -955,6 +956,26 @@ impl PathBuilder { } } + /// Adds a cubic Bézier curve to the current figure. + pub fn bezier_curve_to(&self, + control_point_1: &Point2D, + control_point_2: &Point2D, + control_point_3: &Point2D) { + unsafe { + AzPathBuilderBezierTo(self.azure_path_builder, + &control_point_1.as_azure_point(), + &control_point_2.as_azure_point(), + &control_point_3.as_azure_point()) + } + } + + /// Closes the current path. + pub fn close(&self) { + unsafe { + AzPathBuilderClose(self.azure_path_builder) + } + } + pub fn finish(&self) -> Path { let az_path = unsafe { AzPathBuilderFinish(self.azure_path_builder) }; Path { @@ -1025,6 +1046,22 @@ pub fn current_gl_context() -> AzGLContext { } } +pub enum Pattern { + Color(ColorPattern), + LinearGradient(LinearGradientPattern), +} + +impl Pattern { + pub fn to_pattern_ref(&self) -> PatternRef { + match *self { + Pattern::Color(ref color_pattern) => PatternRef::Color(color_pattern), + Pattern::LinearGradient(ref linear_gradient_pattern) => { + PatternRef::LinearGradient(linear_gradient_pattern) + } + } + } +} + pub struct FilterNode { pub azure_filter_node: AzFilterNodeRef, }