diff --git a/.gitignore b/.gitignore index ac289464..d27c2533 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ node_modules /examples/c_canvas_minimal/build /shaders/build /c/build +/examples/macos_app/Pathfinder\ Example.xcodeproj/project.xcworkspace/xcuserdata/* # Editors *.swp diff --git a/Cargo.toml b/Cargo.toml index 1a061066..aefdaa99 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,6 @@ members = [ "examples/canvas_moire", "examples/canvas_text", "examples/lottie_basic", - "examples/convert", "examples/swf_basic", "geometry", "gl", @@ -29,5 +28,6 @@ members = [ "ui", "utils/area-lut", "utils/gamma-lut", - "utils/svg-to-skia" + "utils/svg-to-skia", + "utils/convert", ] diff --git a/README.md b/README.md index 5e946dd6..87364cf2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ # Pathfinder 3 Pathfinder 3 is a fast, practical, GPU-based rasterizer for fonts and vector graphics using OpenGL -and OpenGL ES 3.0+. +3.0+, OpenGL ES 3.0+, or Metal. Please note that Pathfinder is under heavy development and is incomplete in various areas. @@ -75,12 +75,6 @@ The SDL 2 library requires some additional manual installation steps. Follow the [`rust-sdl2` installation instructions](https://github.com/Rust-SDL2/rust-sdl2#sdl20-development-libraries) to make sure the libraries are installed. Note that SDL2 is only required to run the demo; Pathfinder itself has no dependency on the library. -On macOS, it is recommended that you force the use of the integrated GPU, as issues with Apple's -OpenGL drivers may limit performance on discrete GPUs. You can use -[gfxCardStatus.app](https://gfx.io/) for this. See the -[wiki](https://github.com/pcwalton/pathfinder/wiki/GPU-driver-compatibility) for more information -on GPU compatibility issues. - ## Authors The primary author is Patrick Walton (@pcwalton), with contributions from the Servo development diff --git a/c/cbindgen.toml b/c/cbindgen.toml index 4d096e5d..3d2de1f8 100644 --- a/c/cbindgen.toml +++ b/c/cbindgen.toml @@ -2,18 +2,53 @@ language = "C" header = """\ /* Generated code. Do not edit; instead run `cargo build` in `pathfinder_c`. */ +#ifndef PF_PATHFINDER_H +#define PF_PATHFINDER_H + +#ifdef __APPLE__ +#include +#endif + +#ifdef __cplusplus extern \"C\" { +#endif +""" +trailer = """\ +#ifdef __cplusplus +} +#endif + +#endif """ -trailer = "}" -include_guard = "PF_PATHFINDER_H" include_version = true [parse] parse_deps = true include = [ + "font-kit", "pathfinder_canvas", "pathfinder_content", "pathfinder_geometry", "pathfinder_gl", + "pathfinder_gpu", + "pathfinder_metal", "pathfinder_renderer", ] + +[export.rename] +"BuildOptions" = "PFBuildOptionsPrivate" +"CanvasFontContext" = "PFCanvasFontContextPrivate" +"CanvasRenderingContext2D" = "PFCanvasRenderingContext2DPrivate" +"DestFramebuffer_GLDevice" = "PFDestFramebufferGLDevicePrivate" +"DestFramebuffer_MetalDevice" = "PFDestFramebufferMetalDevicePrivate" +"FillStyle" = "PFFillStylePrivate" +"GLDevice" = "PFGLDevicePrivate" +"Handle" = "FKHandlePrivate" +"MetalDevice" = "PFMetalDevicePrivate" +"Path2D" = "PFPath2DPrivate" +"RenderTransform" = "PFRenderTransformPrivate" +"Renderer_GLDevice" = "PFRendererGLDevicePrivate" +"Renderer_MetalDevice" = "PFRendererMetalDevicePrivate" +"ResourceLoaderWrapper" = "PFResourceLoaderWrapperPrivate" +"Scene" = "PFScenePrivate" +"SceneProxy" = "PFSceneProxyPrivate" diff --git a/c/src/lib.rs b/c/src/lib.rs index 7b2e2ef9..a6879e66 100644 --- a/c/src/lib.rs +++ b/c/src/lib.rs @@ -19,6 +19,8 @@ use pathfinder_content::color::{ColorF, ColorU}; use pathfinder_content::outline::ArcDirection; use pathfinder_content::stroke::LineCap; use pathfinder_geometry::rect::{RectF, RectI}; +use pathfinder_geometry::transform2d::{Matrix2x2F, Transform2DF}; +use pathfinder_geometry::transform3d::{Perspective, Transform3DF}; use pathfinder_geometry::vector::{Vector2F, Vector2I}; use pathfinder_gl::{GLDevice, GLVersion}; use pathfinder_gpu::resources::{FilesystemResourceLoader, ResourceLoader}; @@ -26,7 +28,7 @@ use pathfinder_renderer::concurrent::rayon::RayonExecutor; use pathfinder_renderer::concurrent::scene_proxy::SceneProxy; use pathfinder_renderer::gpu::options::{DestFramebuffer, RendererOptions}; use pathfinder_renderer::gpu::renderer::Renderer; -use pathfinder_renderer::options::BuildOptions; +use pathfinder_renderer::options::{BuildOptions, RenderTransform}; use pathfinder_renderer::scene::Scene; use pathfinder_simd::default::F32x4; use std::ffi::CString; @@ -60,6 +62,11 @@ pub const PF_TEXT_ALIGN_RIGHT: u8 = 2; pub const PF_ARC_DIRECTION_CW: u8 = 0; pub const PF_ARC_DIRECTION_CCW: u8 = 1; +// `gl` + +pub const PF_GL_VERSION_GL3: u8 = 0; +pub const PF_GL_VERSION_GLES3: u8 = 1; + // `renderer` pub const PF_RENDERER_OPTIONS_FLAGS_HAS_BACKGROUND_COLOR: u8 = 0x1; @@ -120,10 +127,35 @@ pub struct PFRectI { pub origin: PFVector2I, pub lower_right: PFVector2I, } +/// Row-major order. +#[repr(C)] +pub struct PFMatrix2x2F { + pub m00: f32, pub m01: f32, + pub m10: f32, pub m11: f32, +} +/// Row-major order. +#[repr(C)] +pub struct PFTransform2DF { + pub matrix: PFMatrix2x2F, + pub vector: PFVector2F, +} +/// Row-major order. +#[repr(C)] +pub struct PFTransform3DF { + pub m00: f32, pub m01: f32, pub m02: f32, pub m03: f32, + pub m10: f32, pub m11: f32, pub m12: f32, pub m13: f32, + pub m20: f32, pub m21: f32, pub m22: f32, pub m23: f32, + pub m30: f32, pub m31: f32, pub m32: f32, pub m33: f32, +} +#[repr(C)] +pub struct PFPerspective { + pub transform: PFTransform3DF, + pub window_size: PFVector2I, +} // `gl` pub type PFGLDeviceRef = *mut GLDevice; -pub type PFGLVersion = GLVersion; +pub type PFGLVersion = u8; pub type PFGLFunctionLoader = extern "C" fn(name: *const c_char, userdata: *mut c_void) -> *const c_void; // `gpu` @@ -135,7 +167,8 @@ pub type PFMetalDestFramebufferRef = *mut DestFramebuffer; pub type PFMetalRendererRef = *mut Renderer; // FIXME(pcwalton): Double-boxing is unfortunate. Remove this when `std::raw::TraitObject` is // stable? -pub type PFResourceLoaderRef = *mut Box; +pub type PFResourceLoaderRef = *mut ResourceLoaderWrapper; +pub struct ResourceLoaderWrapper(Box); // `metal` #[cfg(all(target_os = "macos", not(feature = "pf-gl")))] @@ -150,20 +183,18 @@ pub struct PFRendererOptions { pub flags: PFRendererOptionsFlags, } pub type PFRendererOptionsFlags = u8; -// TODO(pcwalton) -#[repr(C)] -pub struct PFBuildOptions { - pub placeholder: u32, -} +pub type PFBuildOptionsRef = *mut BuildOptions; +pub type PFRenderTransformRef = *mut RenderTransform; // `canvas` -/// Consumes the font context. +/// This function internally adds a reference to the font context. Therefore, if you created the +/// font context, you must release it yourself to avoid a leak. #[no_mangle] pub unsafe extern "C" fn PFCanvasCreate(font_context: PFCanvasFontContextRef, size: *const PFVector2F) -> PFCanvasRef { - Box::into_raw(Box::new(CanvasRenderingContext2D::new(*Box::from_raw(font_context), + Box::into_raw(Box::new(CanvasRenderingContext2D::new((*font_context).clone(), (*size).to_rust()))) } @@ -188,17 +219,18 @@ pub unsafe extern "C" fn PFCanvasFontContextCreateWithFonts(fonts: *const FKHand } #[no_mangle] -pub unsafe extern "C" fn PFCanvasFontContextDestroy(font_context: PFCanvasFontContextRef) { - drop(Box::from_raw(font_context)) -} - -#[no_mangle] -pub unsafe extern "C" fn PFCanvasFontContextClone(font_context: PFCanvasFontContextRef) - -> PFCanvasFontContextRef { +pub unsafe extern "C" fn PFCanvasFontContextAddRef(font_context: PFCanvasFontContextRef) + -> PFCanvasFontContextRef { Box::into_raw(Box::new((*font_context).clone())) } -/// Consumes the canvas. +#[no_mangle] +pub unsafe extern "C" fn PFCanvasFontContextRelease(font_context: PFCanvasFontContextRef) { + drop(Box::from_raw(font_context)) +} + +/// This function takes ownership of the supplied canvas and will automatically destroy it when +/// the scene is destroyed. #[no_mangle] pub unsafe extern "C" fn PFCanvasCreateScene(canvas: PFCanvasRef) -> PFSceneRef { Box::into_raw(Box::new(Box::from_raw(canvas).into_scene())) @@ -315,13 +347,15 @@ pub unsafe extern "C" fn PFCanvasSetStrokeStyle(canvas: PFCanvasRef, (*canvas).set_stroke_style(*stroke_style) } -/// Consumes the path. +/// This function automatically destroys the path. If you wish to use the path again, clone it +/// first. #[no_mangle] pub unsafe extern "C" fn PFCanvasFillPath(canvas: PFCanvasRef, path: PFPathRef) { (*canvas).fill_path(*Box::from_raw(path)) } -/// Consumes the path. +/// This function automatically destroys the path. If you wish to use the path again, clone it +/// first. #[no_mangle] pub unsafe extern "C" fn PFCanvasStrokePath(canvas: PFCanvasRef, path: PFPathRef) { (*canvas).stroke_path(*Box::from_raw(path)) @@ -421,7 +455,7 @@ pub unsafe extern "C" fn PFFillStyleDestroy(fill_style: PFFillStyleRef) { #[no_mangle] pub unsafe extern "C" fn PFFilesystemResourceLoaderLocate() -> PFResourceLoaderRef { let loader = Box::new(FilesystemResourceLoader::locate()); - Box::into_raw(Box::new(loader as Box)) + Box::into_raw(Box::new(ResourceLoaderWrapper(loader as Box))) } #[no_mangle] @@ -435,6 +469,7 @@ pub unsafe extern "C" fn PFGLLoadWith(loader: PFGLFunctionLoader, userdata: *mut #[no_mangle] pub unsafe extern "C" fn PFGLDeviceCreate(version: PFGLVersion, default_framebuffer: u32) -> PFGLDeviceRef { + let version = match version { PF_GL_VERSION_GLES3 => GLVersion::GLES3, _ => GLVersion::GL3 }; Box::into_raw(Box::new(GLDevice::new(version, default_framebuffer))) } @@ -461,7 +496,9 @@ pub unsafe extern "C" fn PFGLDestFramebufferDestroy(dest_framebuffer: PFGLDestFr drop(Box::from_raw(dest_framebuffer)) } -/// Takes ownership of `device` and `dest_framebuffer`, but not `resources`. +/// This function takes ownership of and automatically takes responsibility for destroying `device` +/// and `dest_framebuffer`. However, it does not take ownership of `resources`; therefore, if you +/// created the resource loader, you must destroy it yourself to avoid a memory leak. #[no_mangle] pub unsafe extern "C" fn PFGLRendererCreate(device: PFGLDeviceRef, resources: PFResourceLoaderRef, @@ -469,7 +506,7 @@ pub unsafe extern "C" fn PFGLRendererCreate(device: PFGLDeviceRef, options: *const PFRendererOptions) -> PFGLRendererRef { Box::into_raw(Box::new(Renderer::new(*Box::from_raw(device), - &**resources, + &*((*resources).0), *Box::from_raw(dest_framebuffer), (*options).to_rust()))) } @@ -498,7 +535,9 @@ pub unsafe extern "C" fn PFMetalDestFramebufferDestroy(dest_framebuffer: drop(Box::from_raw(dest_framebuffer)) } -/// Takes ownership of `device` and `dest_framebuffer`, but not `resources`. +/// This function takes ownership of and automatically takes responsibility for destroying `device` +/// and `dest_framebuffer`. However, it does not take ownership of `resources`; therefore, if you +/// created the resource loader, you must destroy it yourself to avoid a memory leak. #[cfg(all(target_os = "macos", not(feature = "pf-gl")))] #[no_mangle] pub unsafe extern "C" fn PFMetalRendererCreate(device: PFMetalDeviceRef, @@ -507,7 +546,7 @@ pub unsafe extern "C" fn PFMetalRendererCreate(device: PFMetalDeviceRef, options: *const PFRendererOptions) -> PFMetalRendererRef { Box::into_raw(Box::new(Renderer::new(*Box::from_raw(device), - &**resources, + &*((*resources).0), *Box::from_raw(dest_framebuffer), (*options).to_rust()))) } @@ -518,25 +557,33 @@ pub unsafe extern "C" fn PFMetalRendererDestroy(renderer: PFMetalRendererRef) { drop(Box::from_raw(renderer)) } +/// Returns a reference to the Metal device in the renderer. +/// +/// This reference remains valid as long as the device is alive. #[cfg(all(target_os = "macos", not(feature = "pf-gl")))] #[no_mangle] -pub unsafe extern "C" fn PFMetalRendererGetDevice(renderer: PFMetalRendererRef) -> PFMetalDeviceRef { +pub unsafe extern "C" fn PFMetalRendererGetDevice(renderer: PFMetalRendererRef) + -> PFMetalDeviceRef { &mut (*renderer).device } +/// This function does not take ownership of `renderer` or `build_options`. Therefore, if you +/// created the renderer and/or options, you must destroy them yourself to avoid a leak. #[no_mangle] pub unsafe extern "C" fn PFSceneProxyBuildAndRenderGL(scene_proxy: PFSceneProxyRef, renderer: PFGLRendererRef, - build_options: *const PFBuildOptions) { - (*scene_proxy).build_and_render(&mut *renderer, (*build_options).to_rust()) + build_options: PFBuildOptionsRef) { + (*scene_proxy).build_and_render(&mut *renderer, (*build_options).clone()) } +/// This function does not take ownership of `renderer` or `build_options`. Therefore, if you +/// created the renderer and/or options, you must destroy them yourself to avoid a leak. #[cfg(all(target_os = "macos", not(feature = "pf-gl")))] #[no_mangle] pub unsafe extern "C" fn PFSceneProxyBuildAndRenderMetal(scene_proxy: PFSceneProxyRef, renderer: PFMetalRendererRef, - build_options: *const PFBuildOptions) { - (*scene_proxy).build_and_render(&mut *renderer, (*build_options).to_rust()) + build_options: PFBuildOptionsRef) { + (*scene_proxy).build_and_render(&mut *renderer, (*build_options).clone()) } // `metal` @@ -554,8 +601,60 @@ pub unsafe extern "C" fn PFMetalDeviceDestroy(device: PFMetalDeviceRef) { drop(Box::from_raw(device)) } +#[cfg(all(target_os = "macos", not(feature = "pf-gl")))] +#[no_mangle] +pub unsafe extern "C" fn PFMetalDevicePresentDrawable(device: PFMetalDeviceRef) { + (*device).present_drawable() +} + // `renderer` +#[no_mangle] +pub unsafe extern "C" fn PFRenderTransformCreate2D(transform: *const PFTransform2DF) + -> PFRenderTransformRef { + Box::into_raw(Box::new(RenderTransform::Transform2D((*transform).to_rust()))) +} + +#[no_mangle] +pub unsafe extern "C" fn PFRenderTransformCreatePerspective(perspective: *const PFPerspective) + -> PFRenderTransformRef { + Box::into_raw(Box::new(RenderTransform::Perspective((*perspective).to_rust()))) +} + +#[no_mangle] +pub unsafe extern "C" fn PFRenderTransformDestroy(transform: PFRenderTransformRef) { + drop(Box::from_raw(transform)) +} + +#[no_mangle] +pub unsafe extern "C" fn PFBuildOptionsCreate() -> PFBuildOptionsRef { + Box::into_raw(Box::new(BuildOptions::default())) +} + +#[no_mangle] +pub unsafe extern "C" fn PFBuildOptionsDestroy(options: PFBuildOptionsRef) { + drop(Box::from_raw(options)) +} + +/// Consumes the transform. +#[no_mangle] +pub unsafe extern "C" fn PFBuildOptionsSetTransform(options: PFBuildOptionsRef, + transform: PFRenderTransformRef) { + (*options).transform = *Box::from_raw(transform) +} + +#[no_mangle] +pub unsafe extern "C" fn PFBuildOptionsSetDilation(options: PFBuildOptionsRef, + dilation: *const PFVector2F) { + (*options).dilation = (*dilation).to_rust() +} + +#[no_mangle] +pub unsafe extern "C" fn PFBuildOptionsSetSubpixelAAEnabled(options: PFBuildOptionsRef, + subpixel_aa_enabled: bool) { + (*options).subpixel_aa_enabled = subpixel_aa_enabled +} + #[no_mangle] pub unsafe extern "C" fn PFSceneDestroy(scene: PFSceneRef) { drop(Box::from_raw(scene)) @@ -637,6 +736,40 @@ impl PFVector2I { } } +impl PFMatrix2x2F { + #[inline] + pub fn to_rust(&self) -> Matrix2x2F { + Matrix2x2F::row_major(self.m00, self.m01, self.m10, self.m11) + } +} + +impl PFTransform2DF { + #[inline] + pub fn to_rust(&self) -> Transform2DF { + Transform2DF { matrix: self.matrix.to_rust(), vector: self.vector.to_rust() } + } +} + +impl PFTransform3DF { + #[inline] + pub fn to_rust(&self) -> Transform3DF { + Transform3DF::row_major(self.m00, self.m01, self.m02, self.m03, + self.m10, self.m11, self.m12, self.m13, + self.m20, self.m21, self.m22, self.m23, + self.m30, self.m31, self.m32, self.m33) + } +} + +impl PFPerspective { + #[inline] + pub fn to_rust(&self) -> Perspective { + Perspective { + transform: self.transform.to_rust(), + window_size: self.window_size.to_rust(), + } + } +} + // Helpers for `renderer` impl PFRendererOptions { @@ -651,9 +784,3 @@ impl PFRendererOptions { } } } - -impl PFBuildOptions { - pub fn to_rust(&self) -> BuildOptions { - BuildOptions::default() - } -} diff --git a/examples/c_canvas_minimal/c_canvas_minimal.c b/examples/c_canvas_minimal/c_canvas_minimal.c index bcfa09b9..8feabc65 100644 --- a/examples/c_canvas_minimal/c_canvas_minimal.c +++ b/examples/c_canvas_minimal/c_canvas_minimal.c @@ -87,7 +87,7 @@ int main(int argc, const char **argv) { // Render the canvas to screen. PFSceneRef scene = PFCanvasCreateScene(canvas); PFSceneProxyRef scene_proxy = PFSceneProxyCreateFromSceneAndRayonExecutor(scene); - PFSceneProxyBuildAndRenderGL(scene_proxy, renderer, &(PFBuildOptions){0}); + PFSceneProxyBuildAndRenderGL(scene_proxy, renderer, PFBuildOptionsCreate()); SDL_GL_SwapWindow(window); // Wait for a keypress. diff --git a/examples/macos_app/Pathfinder Example.xcodeproj/project.pbxproj b/examples/macos_app/Pathfinder Example.xcodeproj/project.pbxproj new file mode 100644 index 00000000..9a359ecf --- /dev/null +++ b/examples/macos_app/Pathfinder Example.xcodeproj/project.pbxproj @@ -0,0 +1,354 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 50; + objects = { + +/* Begin PBXBuildFile section */ + 6A9A35B322C1E14700B86652 /* libpathfinder_c.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6A9A35B222C1E14700B86652 /* libpathfinder_c.a */; }; + 6AFD6FFA22BD780D00AC1ED3 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 6AFD6FF922BD780D00AC1ED3 /* AppDelegate.m */; }; + 6AFD6FFC22BD781000AC1ED3 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6AFD6FFB22BD781000AC1ED3 /* Assets.xcassets */; }; + 6AFD6FFF22BD781000AC1ED3 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = 6AFD6FFD22BD781000AC1ED3 /* MainMenu.xib */; }; + 6AFD700222BD781000AC1ED3 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 6AFD700122BD781000AC1ED3 /* main.m */; }; + 6AFD700B22BD7B7A00AC1ED3 /* PathfinderView.m in Sources */ = {isa = PBXBuildFile; fileRef = 6AFD700A22BD7B7A00AC1ED3 /* PathfinderView.m */; }; + 6AFD700F22BD930500AC1ED3 /* libharfbuzz.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6AFD700E22BD930500AC1ED3 /* libharfbuzz.a */; }; +/* End PBXBuildFile section */ + +/* Begin PBXFileReference section */ + 6A9A35B222C1E14700B86652 /* libpathfinder_c.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libpathfinder_c.a; path = ../../../target/release/libpathfinder_c.a; sourceTree = ""; }; + 6AFD6FF522BD780D00AC1ED3 /* Pathfinder Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Pathfinder Example.app"; sourceTree = BUILT_PRODUCTS_DIR; }; + 6AFD6FF822BD780D00AC1ED3 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; + 6AFD6FF922BD780D00AC1ED3 /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; + 6AFD6FFB22BD781000AC1ED3 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; + 6AFD6FFE22BD781000AC1ED3 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/MainMenu.xib; sourceTree = ""; }; + 6AFD700022BD781000AC1ED3 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; + 6AFD700122BD781000AC1ED3 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; + 6AFD700322BD781000AC1ED3 /* Pathfinder_Example.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Pathfinder_Example.entitlements; sourceTree = ""; }; + 6AFD700922BD7B7A00AC1ED3 /* PathfinderView.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PathfinderView.h; sourceTree = ""; }; + 6AFD700A22BD7B7A00AC1ED3 /* PathfinderView.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PathfinderView.m; sourceTree = ""; }; + 6AFD700E22BD930500AC1ED3 /* libharfbuzz.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; name = libharfbuzz.a; path = ../../../../../../../usr/local/lib/libharfbuzz.a; sourceTree = ""; }; +/* End PBXFileReference section */ + +/* Begin PBXFrameworksBuildPhase section */ + 6AFD6FF222BD780D00AC1ED3 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 6A9A35B322C1E14700B86652 /* libpathfinder_c.a in Frameworks */, + 6AFD700F22BD930500AC1ED3 /* libharfbuzz.a in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 6AFD6FEC22BD780D00AC1ED3 = { + isa = PBXGroup; + children = ( + 6AFD6FF722BD780D00AC1ED3 /* Pathfinder Example */, + 6AFD6FF622BD780D00AC1ED3 /* Products */, + ); + sourceTree = ""; + }; + 6AFD6FF622BD780D00AC1ED3 /* Products */ = { + isa = PBXGroup; + children = ( + 6AFD6FF522BD780D00AC1ED3 /* Pathfinder Example.app */, + ); + name = Products; + sourceTree = ""; + }; + 6AFD6FF722BD780D00AC1ED3 /* Pathfinder Example */ = { + isa = PBXGroup; + children = ( + 6AFD6FF822BD780D00AC1ED3 /* AppDelegate.h */, + 6AFD6FF922BD780D00AC1ED3 /* AppDelegate.m */, + 6AFD6FFB22BD781000AC1ED3 /* Assets.xcassets */, + 6AFD6FFD22BD781000AC1ED3 /* MainMenu.xib */, + 6AFD700022BD781000AC1ED3 /* Info.plist */, + 6AFD700922BD7B7A00AC1ED3 /* PathfinderView.h */, + 6AFD700A22BD7B7A00AC1ED3 /* PathfinderView.m */, + 6AFD700122BD781000AC1ED3 /* main.m */, + 6AFD700322BD781000AC1ED3 /* Pathfinder_Example.entitlements */, + 6A9A35B222C1E14700B86652 /* libpathfinder_c.a */, + 6AFD700E22BD930500AC1ED3 /* libharfbuzz.a */, + ); + path = "Pathfinder Example"; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 6AFD6FF422BD780D00AC1ED3 /* Pathfinder Example */ = { + isa = PBXNativeTarget; + buildConfigurationList = 6AFD700622BD781000AC1ED3 /* Build configuration list for PBXNativeTarget "Pathfinder Example" */; + buildPhases = ( + 6AFD6FF122BD780D00AC1ED3 /* Sources */, + 6AFD6FF222BD780D00AC1ED3 /* Frameworks */, + 6AFD6FF322BD780D00AC1ED3 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = "Pathfinder Example"; + productName = "Pathfinder Example"; + productReference = 6AFD6FF522BD780D00AC1ED3 /* Pathfinder Example.app */; + productType = "com.apple.product-type.application"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 6AFD6FED22BD780D00AC1ED3 /* Project object */ = { + isa = PBXProject; + attributes = { + LastUpgradeCheck = 1020; + ORGANIZATIONNAME = "The Pathfinder Project Deelopers"; + TargetAttributes = { + 6AFD6FF422BD780D00AC1ED3 = { + CreatedOnToolsVersion = 10.2.1; + SystemCapabilities = { + com.apple.Sandbox = { + enabled = 0; + }; + }; + }; + }; + }; + buildConfigurationList = 6AFD6FF022BD780D00AC1ED3 /* Build configuration list for PBXProject "Pathfinder Example" */; + compatibilityVersion = "Xcode 9.3"; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 6AFD6FEC22BD780D00AC1ED3; + productRefGroup = 6AFD6FF622BD780D00AC1ED3 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 6AFD6FF422BD780D00AC1ED3 /* Pathfinder Example */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 6AFD6FF322BD780D00AC1ED3 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6AFD6FFC22BD781000AC1ED3 /* Assets.xcassets in Resources */, + 6AFD6FFF22BD781000AC1ED3 /* MainMenu.xib in Resources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 6AFD6FF122BD780D00AC1ED3 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 6AFD700222BD781000AC1ED3 /* main.m in Sources */, + 6AFD700B22BD7B7A00AC1ED3 /* PathfinderView.m in Sources */, + 6AFD6FFA22BD780D00AC1ED3 /* AppDelegate.m in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXVariantGroup section */ + 6AFD6FFD22BD781000AC1ED3 /* MainMenu.xib */ = { + isa = PBXVariantGroup; + children = ( + 6AFD6FFE22BD781000AC1ED3 /* Base */, + ); + name = MainMenu.xib; + sourceTree = ""; + }; +/* End PBXVariantGroup section */ + +/* Begin XCBuildConfiguration section */ + 6AFD700422BD781000AC1ED3 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = macosx; + }; + name = Debug; + }; + 6AFD700522BD781000AC1ED3 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; + CLANG_CXX_LIBRARY = "libc++"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + CODE_SIGN_IDENTITY = "-"; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + GCC_C_LANGUAGE_STANDARD = gnu11; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.14; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = macosx; + }; + name = Release; + }; + 6AFD700722BD781000AC1ED3 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ""; + HEADER_SEARCH_PATHS = ../../c/build/include; + INFOPLIST_FILE = "Pathfinder Example/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + LIBRARY_SEARCH_PATHS = ( + ../../target/release, + /usr/local/lib, + ); + PRODUCT_BUNDLE_IDENTIFIER = "graphics.pathfinder.Pathfinder-Example"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 6AFD700822BD781000AC1ED3 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + CODE_SIGN_STYLE = Automatic; + COMBINE_HIDPI_IMAGES = YES; + FRAMEWORK_SEARCH_PATHS = ""; + HEADER_SEARCH_PATHS = ../../c/build/include; + INFOPLIST_FILE = "Pathfinder Example/Info.plist"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/../Frameworks", + ); + LIBRARY_SEARCH_PATHS = ( + ../../target/release, + /usr/local/lib, + ); + PRODUCT_BUNDLE_IDENTIFIER = "graphics.pathfinder.Pathfinder-Example"; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 6AFD6FF022BD780D00AC1ED3 /* Build configuration list for PBXProject "Pathfinder Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6AFD700422BD781000AC1ED3 /* Debug */, + 6AFD700522BD781000AC1ED3 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 6AFD700622BD781000AC1ED3 /* Build configuration list for PBXNativeTarget "Pathfinder Example" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 6AFD700722BD781000AC1ED3 /* Debug */, + 6AFD700822BD781000AC1ED3 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 6AFD6FED22BD780D00AC1ED3 /* Project object */; +} diff --git a/examples/macos_app/Pathfinder Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/examples/macos_app/Pathfinder Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 00000000..acd84826 --- /dev/null +++ b/examples/macos_app/Pathfinder Example.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + diff --git a/examples/macos_app/Pathfinder Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/examples/macos_app/Pathfinder Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/examples/macos_app/Pathfinder Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/examples/macos_app/Pathfinder Example.xcodeproj/xcshareddata/xcschemes/Pathfinder Example.xcscheme b/examples/macos_app/Pathfinder Example.xcodeproj/xcshareddata/xcschemes/Pathfinder Example.xcscheme new file mode 100644 index 00000000..06c13d8b --- /dev/null +++ b/examples/macos_app/Pathfinder Example.xcodeproj/xcshareddata/xcschemes/Pathfinder Example.xcscheme @@ -0,0 +1,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/macos_app/Pathfinder Example.xcodeproj/xcuserdata/pcwalton.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/examples/macos_app/Pathfinder Example.xcodeproj/xcuserdata/pcwalton.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist new file mode 100644 index 00000000..8f940316 --- /dev/null +++ b/examples/macos_app/Pathfinder Example.xcodeproj/xcuserdata/pcwalton.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/examples/macos_app/Pathfinder Example.xcodeproj/xcuserdata/pcwalton.xcuserdatad/xcschemes/xcschememanagement.plist b/examples/macos_app/Pathfinder Example.xcodeproj/xcuserdata/pcwalton.xcuserdatad/xcschemes/xcschememanagement.plist new file mode 100644 index 00000000..29a687c5 --- /dev/null +++ b/examples/macos_app/Pathfinder Example.xcodeproj/xcuserdata/pcwalton.xcuserdatad/xcschemes/xcschememanagement.plist @@ -0,0 +1,22 @@ + + + + + SchemeUserState + + Pathfinder Example.xcscheme_^#shared#^_ + + orderHint + 0 + + + SuppressBuildableAutocreation + + 6AFD6FF422BD780D00AC1ED3 + + primary + + + + + diff --git a/examples/macos_app/Pathfinder Example/AppDelegate.h b/examples/macos_app/Pathfinder Example/AppDelegate.h new file mode 100644 index 00000000..e8197344 --- /dev/null +++ b/examples/macos_app/Pathfinder Example/AppDelegate.h @@ -0,0 +1,15 @@ +// +// AppDelegate.h +// Pathfinder Example +// +// Created by Patrick Walton on 6/21/19. +// Copyright © 2019 The Pathfinder Project Developers. All rights reserved. +// + +#import + +@interface AppDelegate : NSObject + + +@end + diff --git a/examples/macos_app/Pathfinder Example/AppDelegate.m b/examples/macos_app/Pathfinder Example/AppDelegate.m new file mode 100644 index 00000000..a2448b23 --- /dev/null +++ b/examples/macos_app/Pathfinder Example/AppDelegate.m @@ -0,0 +1,28 @@ +// +// AppDelegate.m +// Pathfinder Example +// +// Created by Patrick Walton on 6/21/19. +// Copyright © 2019 The Pathfinder Project Developers. All rights reserved. +// + +#import "AppDelegate.h" + +@interface AppDelegate () + +@property (weak) IBOutlet NSWindow *window; +@end + +@implementation AppDelegate + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + // Insert code here to initialize your application +} + + +- (void)applicationWillTerminate:(NSNotification *)aNotification { + // Insert code here to tear down your application +} + + +@end diff --git a/examples/macos_app/Pathfinder Example/Assets.xcassets/AppIcon.appiconset/Contents.json b/examples/macos_app/Pathfinder Example/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000..2db2b1c7 --- /dev/null +++ b/examples/macos_app/Pathfinder Example/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,58 @@ +{ + "images" : [ + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "16x16", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "32x32", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "128x128", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "256x256", + "scale" : "2x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "1x" + }, + { + "idiom" : "mac", + "size" : "512x512", + "scale" : "2x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/macos_app/Pathfinder Example/Assets.xcassets/Contents.json b/examples/macos_app/Pathfinder Example/Assets.xcassets/Contents.json new file mode 100644 index 00000000..da4a164c --- /dev/null +++ b/examples/macos_app/Pathfinder Example/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/examples/macos_app/Pathfinder Example/Base.lproj/MainMenu.xib b/examples/macos_app/Pathfinder Example/Base.lproj/MainMenu.xib new file mode 100644 index 00000000..7423b96f --- /dev/null +++ b/examples/macos_app/Pathfinder Example/Base.lproj/MainMenu.xib @@ -0,0 +1,373 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/macos_app/Pathfinder Example/Info.plist b/examples/macos_app/Pathfinder Example/Info.plist new file mode 100644 index 00000000..bff81736 --- /dev/null +++ b/examples/macos_app/Pathfinder Example/Info.plist @@ -0,0 +1,32 @@ + + + + + CFBundleDevelopmentRegion + $(DEVELOPMENT_LANGUAGE) + CFBundleExecutable + $(EXECUTABLE_NAME) + CFBundleIconFile + + CFBundleIdentifier + $(PRODUCT_BUNDLE_IDENTIFIER) + CFBundleInfoDictionaryVersion + 6.0 + CFBundleName + $(PRODUCT_NAME) + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + $(MACOSX_DEPLOYMENT_TARGET) + NSHumanReadableCopyright + Copyright © 2019 The Pathfinder Project Developers. All rights reserved. + NSMainNibFile + MainMenu + NSPrincipalClass + NSApplication + + diff --git a/examples/macos_app/Pathfinder Example/PathfinderView.h b/examples/macos_app/Pathfinder Example/PathfinderView.h new file mode 100644 index 00000000..59cf7f5d --- /dev/null +++ b/examples/macos_app/Pathfinder Example/PathfinderView.h @@ -0,0 +1,30 @@ +// +// PathfinderView.h +// Pathfinder Example +// +// Created by Patrick Walton on 6/21/19. +// Copyright © 2019 The Pathfinder Project Developers. All rights reserved. +// + +#import +#import +#include + +NS_ASSUME_NONNULL_BEGIN + +@interface PathfinderView : NSView { + id mDevice; + PFMetalRendererRef mRenderer; + PFCanvasFontContextRef mFontContext; + PFBuildOptionsRef mBuildOptions; + CVDisplayLinkRef mDisplayLink; + int32_t mFrameNumber; + CGSize mLayerSize; + NSLock *mRenderLock; +} + +- (void)_render; + +@end + +NS_ASSUME_NONNULL_END diff --git a/examples/macos_app/Pathfinder Example/PathfinderView.m b/examples/macos_app/Pathfinder Example/PathfinderView.m new file mode 100644 index 00000000..03e539d3 --- /dev/null +++ b/examples/macos_app/Pathfinder Example/PathfinderView.m @@ -0,0 +1,194 @@ +// +// PathfinderView.m +// Pathfinder Example +// +// Created by Patrick Walton on 6/21/19. +// Copyright © 2019 The Pathfinder Project Developers. All rights reserved. +// + +#import +#import "PathfinderView.h" +#import +#include + +static CVReturn outputCallback(CVDisplayLinkRef displayLink, + const CVTimeStamp *now, + const CVTimeStamp *outputTime, + CVOptionFlags flagsIn, + CVOptionFlags *flagsOut, + void *userData) { + [(__bridge PathfinderView *)userData _render]; + return kCVReturnSuccess; +} + +static CATransform3D createPerspectiveMatrix(CGFloat fovY, + CGFloat aspect, + CGFloat zNear, + CGFloat zFar) { + CGFloat f = tan(1.0 / (fovY * 0.5)); + CGFloat zDenom = 1.0 / (zNear - zFar); + + CATransform3D transform = CATransform3DIdentity; + transform.m11 = f / aspect; + transform.m22 = f; + transform.m33 = (zFar + zNear) * zDenom; + transform.m34 = -1.0; + transform.m43 = 2.0 * zFar * zNear * zDenom; + return transform; +} + +static PFTransform3DF pfTransformFromCATransform(const CATransform3D *transform) { + // Core Animation matrices are in column-major order, while Pathfinder matrices are in + // row-major order (at least in the latter's C API). So transpose here. + PFTransform3DF pfTransform; + pfTransform.m00 = (float)transform->m11; + pfTransform.m01 = (float)transform->m21; + pfTransform.m02 = (float)transform->m31; + pfTransform.m03 = (float)transform->m41; + pfTransform.m10 = (float)transform->m12; + pfTransform.m11 = (float)transform->m22; + pfTransform.m12 = (float)transform->m32; + pfTransform.m13 = (float)transform->m42; + pfTransform.m20 = (float)transform->m13; + pfTransform.m21 = (float)transform->m23; + pfTransform.m22 = (float)transform->m33; + pfTransform.m23 = (float)transform->m43; + pfTransform.m30 = (float)transform->m14; + pfTransform.m31 = (float)transform->m24; + pfTransform.m32 = (float)transform->m34; + pfTransform.m33 = (float)transform->m44; + return pfTransform; +} + +@implementation PathfinderView + +#define FONT_SIZE 256.0f + +- (void)_render { + [mRenderLock lock]; + + CGSize size = mLayerSize; + + PFCanvasRef canvas = PFCanvasCreate(mFontContext, &(PFVector2F){size.width, size.height}); + PFFillStyleRef fillStyle = + PFFillStyleCreateColor(&(PFColorU){0, 0, 0, 255}); + PFCanvasSetFillStyle(canvas, fillStyle); + PFCanvasSetFontSize(canvas, FONT_SIZE); + PFCanvasSetTextAlign(canvas, PF_TEXT_ALIGN_CENTER); + PFVector2F textOrigin; + textOrigin.x = 0.0; + textOrigin.y = FONT_SIZE * 0.25; + PFCanvasFillText(canvas, "Pathfinder", 0, &textOrigin); + PFCanvasFillRect(canvas, &(const PFRectF){0.0, 0.0, 1.0, 1.0}); + PFFillStyleDestroy(fillStyle); + + PFSceneRef scene = PFCanvasCreateScene(canvas); + PFSceneProxyRef sceneProxy = PFSceneProxyCreateFromSceneAndRayonExecutor(scene); + + int32_t frame = mFrameNumber; + int32_t nT = frame % 240; + if (nT > 120) + nT = 240 - nT; + + CATransform3D transform = + CATransform3DMakeTranslation(0.0, 0.0, -8.0 + (CGFloat)nT / 120.0 * 8.0); + transform = CATransform3DRotate(transform, + frame / 120.0 * M_PI * 2.0, + 0.0, + 1.0, + 0.0); + transform = CATransform3DScale(transform, -2.0 / size.width, 2.0 / size.height, 1.0); + CGFloat aspect = size.width / size.height; + transform = CATransform3DConcat(transform, + createPerspectiveMatrix(M_PI * 0.25, aspect, 0.01, 10.0)); + PFPerspective pfPerspective; + pfPerspective.transform = pfTransformFromCATransform(&transform); + pfPerspective.window_size.x = size.width; + pfPerspective.window_size.y = size.height; + + PFBuildOptionsRef buildOptions = PFBuildOptionsCreate(); + PFRenderTransformRef renderTransform = PFRenderTransformCreatePerspective(&pfPerspective); + PFBuildOptionsSetTransform(buildOptions, renderTransform); + PFSceneProxyBuildAndRenderMetal(sceneProxy, mRenderer, buildOptions); + + PFMetalDevicePresentDrawable(PFMetalRendererGetDevice(mRenderer)); + + mFrameNumber++; + + [mRenderLock unlock]; +} + +- (void)_checkCVResult:(CVReturn)result { + if (result != kCVReturnSuccess) { + @throw [NSException exceptionWithName:@"CoreVideoCallFailed" + reason:@"Core Video call failed" + userInfo:nil]; + } +} + +- (void)_initializeIfNecessary:(CAMetalLayer *)layer { + if (mDevice != nil) + return; + + mFrameNumber = 0; + + mDevice = MTLCreateSystemDefaultDevice(); + [layer setDevice:mDevice]; + [layer setContentsScale:[[self window] backingScaleFactor]]; + + mRenderLock = [[NSLock alloc] init]; + mLayerSize = [self convertSizeToBacking:[layer bounds].size]; + + PFMetalDeviceRef device = PFMetalDeviceCreate(layer); + PFResourceLoaderRef resourceLoader = PFFilesystemResourceLoaderLocate(); + PFMetalDestFramebufferRef destFramebuffer = + PFMetalDestFramebufferCreateFullWindow(&(PFVector2I){mLayerSize.width, mLayerSize.height}); + + PFRendererOptions rendererOptions; + rendererOptions.background_color = (PFColorF){1.0, 1.0, 1.0, 1.0}; + rendererOptions.flags = PF_RENDERER_OPTIONS_FLAGS_HAS_BACKGROUND_COLOR; + mRenderer = PFMetalRendererCreate(device, + resourceLoader, + destFramebuffer, + &rendererOptions); + + mFontContext = PFCanvasFontContextCreateWithSystemSource(); + + mBuildOptions = PFBuildOptionsCreate(); + + [self _checkCVResult:CVDisplayLinkCreateWithActiveCGDisplays(&mDisplayLink)]; + [self _checkCVResult:CVDisplayLinkSetOutputCallback(mDisplayLink, + outputCallback, + (__bridge void *_Nullable)(self))]; + [self _checkCVResult:CVDisplayLinkStart(mDisplayLink)]; +} + +- (CALayer *)makeBackingLayer { + return [[CAMetalLayer alloc] init]; +} + +- (BOOL)wantsLayer { + return YES; +} + +- (BOOL)wantsUpdateLayer { + return YES; +} + +- (NSViewLayerContentsRedrawPolicy)layerContentsRedrawPolicy { + return NSViewLayerContentsRedrawOnSetNeedsDisplay; +} + +- (void)drawRect:(NSRect)dirtyRect { + [self _initializeIfNecessary:(CAMetalLayer *)[self layer]]; +} + +- (void)displayLayer:(CALayer *)layer { + [self _initializeIfNecessary:(CAMetalLayer *)layer]; +} + +- (void)awakeFromNib { + [self _initializeIfNecessary:(CAMetalLayer *)[self layer]]; +} + +@end diff --git a/examples/macos_app/Pathfinder Example/Pathfinder_Example.entitlements b/examples/macos_app/Pathfinder Example/Pathfinder_Example.entitlements new file mode 100644 index 00000000..0c67376e --- /dev/null +++ b/examples/macos_app/Pathfinder Example/Pathfinder_Example.entitlements @@ -0,0 +1,5 @@ + + + + + diff --git a/examples/macos_app/Pathfinder Example/main.m b/examples/macos_app/Pathfinder Example/main.m new file mode 100644 index 00000000..8f6058f1 --- /dev/null +++ b/examples/macos_app/Pathfinder Example/main.m @@ -0,0 +1,13 @@ +// +// main.m +// Pathfinder Example +// +// Created by Patrick Walton on 6/21/19. +// Copyright © 2019 The Pathfinder Project Developers. All rights reserved. +// + +#import + +int main(int argc, const char * argv[]) { + return NSApplicationMain(argc, argv); +} diff --git a/geometry/src/transform2d.rs b/geometry/src/transform2d.rs index b48c8882..89d30aae 100644 --- a/geometry/src/transform2d.rs +++ b/geometry/src/transform2d.rs @@ -116,8 +116,8 @@ impl Sub for Matrix2x2F { #[derive(Clone, Copy, Debug, PartialEq)] pub struct Transform2DF { // Row-major order. - matrix: Matrix2x2F, - vector: Vector2F, + pub matrix: Matrix2x2F, + pub vector: Vector2F, } impl Default for Transform2DF { diff --git a/examples/convert/Cargo.toml b/utils/convert/Cargo.toml similarity index 100% rename from examples/convert/Cargo.toml rename to utils/convert/Cargo.toml diff --git a/examples/convert/src/main.rs b/utils/convert/src/main.rs similarity index 100% rename from examples/convert/src/main.rs rename to utils/convert/src/main.rs