Commit Graph

65 Commits

Author SHA1 Message Date
bors-servo fed372229a
Auto merge of #406 - lu-zero:simpler-c-api-instructions, r=pcwalton
Simplify the cargo-c usage and generate the library as libpathfinder
2020-07-30 21:41:51 -04:00
bors-servo bad735e88d
Auto merge of #426 - pcwalton:text-baseline-c, r=pcwalton
Expose `CanvasRenderingContext2D::set_text_baseline()` to C.

Closes #425.
2020-07-29 13:45:07 -04:00
Patrick Walton 9517fe8c63 Expose `CanvasRenderingContext2D::set_text_baseline()` to C.
Closes #425.
2020-07-29 10:43:37 -07:00
Ben Gachowski 56b432b466 Replace PATHFINDER_MACOS with __APPLE__ 2020-07-28 20:16:42 -04:00
Ben Gachowski 3ff09fb43b Add [defines] section to cbindgen.toml 2020-07-28 20:05:33 -04:00
Patrick Walton d01bc5d002 Make the fields of `TextMetrics` lazily calculated, and add an API that
eliminates double layouts.

This adds an extension to the HTML canvas API that allows you to pass the
`TextMetrics` object returned by `measure_text()` to `fill_text()` and/or
`stroke_text()` to draw the measured text without laying it out again. It
improves performance on the `canvas_nanovg` demo.
2020-07-21 19:33:15 -07:00
Luca Barbato 03017e9a23 Simplify the cargo-c usage and generate the library as libpathfinder 2020-07-20 18:22:15 +02:00
bors-servo a51176a3ba
Auto merge of #377 - NickSpag:feature/expose-embeddedresourceloader-to-c-api, r=pcwalton
Expose EmbeddedResourceLoader to c api

### Background
This PR exposes the c api to the EmbeddedResourceLoader, to prevent some of the issues mentioned [here](https://github.com/servo/pathfinder/issues/234).

### Approach
- Followed `PFFilesystemResourceLoaderLocate` and simply exposed the ERL's new and boxed it in the ResourceLoaderWrapper
- Used the `Create` terminology in the signature to match the rest of the api where a new() is called

### Notes
- I successfully tested it in a little .NET binding project I'm working on.
- Moved the \`gl\` section comment down with the GL methods, as it seemed a little out of place. added a \`resources\` one. then moved the destroy fn in to the new section.

Let me know if I misinterpreted anything or if there are any changes, stylistic or otherwise, that you'd prefer. Thanks!
2020-06-29 16:13:20 -04:00
Patrick Walton 42289eec6e Fix Metal memory management and the `canvas_metal_minimal`, `canvas_nanovg`,
and `macos_app` examples.

`winit` does not create an autorelease pool, so the Metal backend had not taken
the presence of one into account. Now the Metal backend creates and flushes
autorelease pools as necessary.

Closes #334.
Closes #376.
2020-06-29 12:48:49 -07:00
Nick Spagnola 04787f1514
move destroy fn out of `gl` 2020-06-29 07:01:19 -07:00
Nick Spagnola bd6d7eb489
cleanup comments 2020-06-29 07:00:28 -07:00
Nick Spagnola 43bc5a5829
expose EmbeddedResourceLoader to c api 2020-06-29 06:59:54 -07:00
Emmanuel Gil Peyrot 9e670287d0 Expose `pathfinder_svg` to the C API 2020-06-24 17:35:43 -07:00
Patrick Walton bc0b37c56a Panic when invalid arguments are passed to the C API.
Closes #352.
2020-06-24 11:45:47 -07:00
Patrick Walton 4877e0da57 Expose OpenGL 4.x in the C bindings 2020-06-24 11:34:28 -07:00
Patrick Walton db80dd8aaa Use `cargo-c`, and update the README.
Closes #343.
2020-06-23 17:37:59 -07:00
Patrick Walton 72cdef2c2a Update the C backend 2020-06-23 13:15:59 -07:00
bors-servo 5e3fb5fed0
Auto merge of #356 - linkmauve:c-resources-path, r=pcwalton
Expose creating a resource loader from a path to C

This is useful when Pathfinder is shipped by a Linux distribution, and not with everything bundled.
2020-06-16 12:11:35 -04:00
Emmanuel Gil Peyrot 5e8c20e78c Expose creating a resource loader from a path to C 2020-06-11 16:02:09 +02:00
Emmanuel Gil Peyrot f2c0aba352 C API: Only use foreign-types on macOS
Its only use is for CoreAnimationLayerRef::from_ptr() in
PFMetalDeviceCreate, so this fixes a warning on other platforms.

The last time I tried to fix this warning I didn’t notice that it was
actually used, and thus 2d2bc14e5c broke
the macOS build in #257.
2020-06-05 17:12:35 +02:00
Patrick Walton 1a37b7f819
Merge pull request #327 from pcwalton/glfw-c-example
Add an example showing how to use the Pathfinder C API with GLFW
2020-05-08 16:53:06 -07:00
Patrick Walton feb6cca419
Merge pull request #326 from pcwalton/c-font-context-docs
Document `PFCanvasFontContextCreateWithFonts()`.
2020-05-08 15:10:07 -07:00
Patrick Walton bbf4c88d0d Add an example showing how to use the Pathfinder C API with GLFW
Closes #258.
2020-05-08 15:09:21 -07:00
Patrick Walton b669cc7087 Document `PFCanvasFontContextCreateWithFonts()`.
Closes #247.
2020-05-08 14:27:41 -07:00
Patrick Walton 9998fe49bd Provide a placeholder definition of `CAMetalLayer` in the C API.
Closes #260.
2020-05-08 14:07:06 -07:00
Patrick Walton 2421de6616 Enable compute shader by default if the OpenGL version is high enough. 2020-05-08 12:16:31 -07:00
Patrick Walton ac83f79d94 Add a compute shader path, optimize GPU memory management, and switch from SDL
to `surfman`.

This is a large commit; explanations of each change follow.

This adds an optional compute shader path, off by default, for rendering fills
to alpha masks. It usually does not improve performance at present, but it
provides a good baseline for further optimizations. Later improvements will
likely aim to avoid writes to the mask texture entirely. Supporting
infrastructure for compute shader has been added to `pathfinder_gpu` for the
OpenGL and Metal backends.

The Metal backend has been optimized to avoid unneccessary buffer allocations
and reflection. As part of this, argument buffers have been removed, as the
current SPIRV-Cross compiler no longer requires them.

The GPU renderer has been improved to avoid stalls. Now, separate buffers are
allocated for each fill batch and for each frame. This can be extended in the
future to allow for separate buffers for tile draw operations as well.

SDL usage has been removed in favor of the native Rust `surfman` and `winit`.
Because `surfman` allows for selection of the integrated GPU on multi-GPU
system, it is chosen by default. The demo supports a new
`--high-performance-gpu` option to opt into the discrete GPU.
2020-04-30 13:33:29 -07:00
Patrick Walton 5efdf2a04a Implement the missing pieces of `TextMetrics` for canvas.
This required a `font-kit` upgrade, and with it a `skribo` upgrade.
2020-04-14 15:01:30 -07:00
Patrick Walton ba7fe4be39 Add the ability to merge scenes together, and expose it to the canvas API.
Closes #268.
2020-04-02 14:04:58 -07:00
Patrick Walton 542d2c27fa Add `translate`, `rotate`, and `scale` methods to `CanvasRenderingContext2D`. 2020-04-02 11:40:53 -07:00
Patrick Walton 794dd55038 Add some implicit conversions between scalars and vectors where appropriate 2020-04-01 17:20:32 -07:00
Patrick Walton 0f35d9c817 Add an embedded resource loader that places resources directly in the binary.
This is useful for WebGL and for downstream crates.io use.
2020-02-28 17:10:53 -08:00
Patrick Walton 3ad1c25796 Implement the even-odd fill rule 2020-02-17 14:44:48 -08:00
Emmanuel Gil Peyrot 6ce416e77c Bump all outdated dependencies
I’m pleasantly surprised that none of these required any (visible) code
change, but tests pass so let’s go with that. :)
2020-02-06 09:39:50 +01:00
Emmanuel Gil Peyrot 2d2bc14e5c Remove unused import 2020-02-06 08:45:14 +01:00
Patrick Walton 706b6dbd1d Add an API for gradients to the canvas frontend, not implemented yet 2020-02-05 20:01:11 -08:00
Patrick Walton 2db43797c3 Split colors out into their own crate.
A lot of downstream consumers of `pathfinder_gpu` want to use colors without
the path stuff.
2020-01-31 09:17:04 +01:00
Patrick Walton 0662f6433f Allow any texture format to be uploaded; fix Metal compilation on newer rustcs 2019-12-20 11:48:51 -08:00
Kamal Ahmad 29713c5cd9 Bump lyon, font-kit and skribo versions to fix crashes 2019-11-20 22:51:03 +05:00
est31 3928e8d964 Rename the feature text → pf-text 2019-08-05 22:49:08 +02:00
est31 fa1a32bdbb Make text rendering optional in pathfinder_canvas 2019-07-27 06:13:02 +02:00
Atul Varma 84b4d1a5a8 Add canvas save and restore methods to C API. 2019-07-13 19:41:30 -04:00
Atul Varma d72e61d60b Add PFCanvasSetCurrentTransform, PFCanvasResetTransform. 2019-07-13 19:38:58 -04:00
Patrick Walton bcac119324 Rename `Transform2DF` to `Transform2F` and `Transform3DF` to `Transform4F` 2019-07-11 14:59:10 -07:00
Patrick Walton 6785ba0623 Flesh out the Metal C API more 2019-06-24 22:55:55 -07:00
Patrick Walton a8d20cb37f Add transform support to the C API, and fix build problems 2019-06-24 14:03:26 -07:00
Patrick Walton 82171088c5 Expose text alignment in the C API 2019-06-24 12:06:05 -07:00
Patrick Walton 2c49a3360e Add Metal support to the C API 2019-06-21 13:37:17 -07:00
Patrick Walton 1c34b12948 Add some font functions to the C API 2019-06-21 13:17:11 -07:00
Patrick Walton 1caad35b46 Use `cbindgen` instead of hand-writing a header file 2019-06-21 11:35:18 -07:00
Patrick Walton 9107f21966 wip 2019-06-21 10:40:32 -07:00
Patrick Walton 431dcf3d2e Rename `pathfinder_geometry::basic` to simply `pathfinder_geometry`, and move
the remaining code in that crate to a new crate, `pathfinder_content`

The old hierarchy was confusing.
2019-06-21 10:06:19 -07:00
Patrick Walton 0012f09eeb Fix examples 2019-06-20 21:43:57 -07:00
Patrick Walton 3f601be08c Add C bindings to fill and stroke styles 2019-06-20 16:57:20 -07:00
Patrick Walton 36db39883c Add C bindings to the canvas text APIs 2019-06-20 16:07:38 -07:00
Patrick Walton 2129e4f2e1 Add missing path methods to the C API 2019-06-20 15:51:25 -07:00
Patrick Walton d2fbb23031 Expose more stroke features in the C API 2019-06-20 13:01:54 -07:00
Patrick Walton 487577a11b Add Metal support.
This commit substantially reworks the `pathfinder_gpu` API to better support
modern APIs like Metal. It should open the door to `gfx-rs`, `wgpu`, Vulkan,
and D3D12 backends relatively straightforwardly.

A new example, `canvas_metal_minimal`, has been added.

Note that the new Metal shaders require a patched version of `spirv-cross` to
build properly. An upstream patch is forthcoming.
2019-06-20 11:47:22 -07:00
Atul Varma 6d41cb4dad
Mention PFCanvasCreate() consumes the font context 2019-06-04 18:00:22 -04:00
Patrick Walton e3112d1a84 Add `PFCanvasFontContextClone()` 2019-06-04 14:55:59 -07:00
Patrick Walton a1b0df0a42 Rename `Point2DF` to `Vector2F`, `Point3DF` to `Vector4F`, and `LineSegmentF`
to `LineSegment2F`.

Straw poll on Twitter suggested that these names were preferred.
2019-06-03 12:39:29 -07:00
Patrick Walton eeaf51ce72 Expose line cap features to C 2019-05-30 21:28:52 -07:00
Patrick Walton 9138e1e0bb Pass in the font context to the canvas rendering context constructor so that it
can be reused.

Creating a system font source can do I/O on some platforms, so obviously we
don't want to do it every frame.
2019-05-29 21:15:42 -07:00
Patrick Walton e1bcc11ace Change the `F32` and `I32` suffixes to `F` and `I` to match the C API.
They're shorter and less noisy.
2019-05-29 19:17:16 -07:00
Patrick Walton e04cc273ee Add enough C bindings to recreate `canvas_minimal` in C.
Closes #12.
2019-05-25 20:21:38 -07:00