-
Notifications
You must be signed in to change notification settings - Fork 224
New scene/resource API #168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
753b97c
Rebase on radial branch
dfrg f8f91e4
Add layer encoding
dfrg db2c4d2
Remove unused path representation
dfrg d243d38
render using the new scene API
dfrg ba7f857
add glyph provider API
dfrg c749add
rebase on timer query patch
dfrg 7f3639b
Merge branch 'linebender:master' into fragments
dfrg e12b063
Add Renderer::upload_scene()
dfrg b178741
Merge branch 'fragments' of https://github.com/dfrg/piet-gpu into fra…
dfrg 532b6ee
Add C api for glyph rendering
dfrg 3ff87c8
Make return value mutable
dfrg c95887b
Change metal format to BGRA8Unorm
dfrg a9356cc
Change color packing to match target format
dfrg 6f9e534
Address review feedback
dfrg 3afe2ea
Fix transform stack bugs in color glyph loader
dfrg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,11 @@ | ||
| [workspace] | ||
|
|
||
| members = [ | ||
| "pgpu-render", | ||
| "piet-gpu", | ||
| "piet-gpu-derive", | ||
| "piet-gpu-hal", | ||
| "piet-gpu-types", | ||
| "piet-scene", | ||
| "tests" | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| [package] | ||
| name = "pgpu-render" | ||
| version = "0.1.0" | ||
| description = "C interface for glyph rendering using piet-gpu." | ||
| license = "MIT/Apache-2.0" | ||
| edition = "2021" | ||
|
|
||
| [lib] | ||
| crate-type = ["cdylib"] | ||
|
|
||
| [dependencies] | ||
| piet-gpu = { path = "../piet-gpu" } | ||
| piet-gpu-hal = { path = "../piet-gpu-hal" } | ||
| piet-scene = { path = "../piet-scene" } | ||
|
|
||
| metal = "0.22" | ||
| cocoa = "0.24.0" | ||
| objc = "0.2.5" | ||
|
|
||
| [build-dependencies] | ||
| cbindgen = "0.20.0" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // Copyright 2022 The piet-gpu authors. | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // https://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| // | ||
| // Also licensed under MIT license, at your choice. | ||
|
|
||
| extern crate cbindgen; | ||
|
|
||
| use std::env; | ||
|
|
||
| fn main() { | ||
| let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); | ||
| cbindgen::Builder::new() | ||
| .with_crate(crate_dir) | ||
| .with_header("/** Automatically generated from pgpu-render/src/lib.rs with cbindgen. **/") | ||
| .generate() | ||
| .expect("Unable to generate bindings") | ||
| .write_to_file("pgpu.h"); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| /** Automatically generated from pgpu-render/src/lib.rs with cbindgen. **/ | ||
|
|
||
| #include <cstdarg> | ||
| #include <cstdint> | ||
| #include <cstdlib> | ||
| #include <ostream> | ||
| #include <new> | ||
|
|
||
| /// Encoded (possibly color) outline for a glyph. | ||
| struct PgpuGlyph; | ||
|
|
||
| /// Context for loading and scaling glyphs. | ||
| struct PgpuGlyphContext; | ||
|
|
||
| /// Context for loading a scaling glyphs from a specific font. | ||
| struct PgpuGlyphProvider; | ||
|
|
||
| /// State and resources for rendering a scene. | ||
| struct PgpuRenderer; | ||
|
|
||
| /// Encoded streams and resources describing a vector graphics scene. | ||
| struct PgpuScene; | ||
|
|
||
| /// Builder for constructing an encoded scene. | ||
| struct PgpuSceneBuilder; | ||
|
|
||
| /// Tag and value for a font variation axis. | ||
| struct PgpuFontVariation { | ||
| /// Tag that specifies the axis. | ||
| uint32_t tag; | ||
| /// Requested setting for the axis. | ||
| float value; | ||
| }; | ||
|
|
||
| /// Description of a font. | ||
| struct PgpuFontDesc { | ||
| /// Pointer to the context of the font file. | ||
| const uint8_t *data; | ||
| /// Size of the font file data in bytes. | ||
| uintptr_t data_len; | ||
| /// Index of the requested font in the font file. | ||
| uint32_t index; | ||
| /// Unique identifier for the font. | ||
| uint64_t unique_id; | ||
| /// Requested size in pixels per em unit. Set to 0.0 for | ||
| /// unscaled outlines. | ||
| float ppem; | ||
| /// Pointer to array of font variation settings. | ||
| const PgpuFontVariation *variations; | ||
| /// Number of font variation settings. | ||
| uintptr_t variations_len; | ||
| }; | ||
|
|
||
| /// Rectangle defined by minimum and maximum points. | ||
| struct PgpuRect { | ||
| float x0; | ||
| float y0; | ||
| float x1; | ||
| float y1; | ||
| }; | ||
|
|
||
| extern "C" { | ||
|
|
||
| /// Creates a new piet-gpu renderer for the specified Metal device and | ||
| /// command queue. | ||
| /// | ||
| /// device: MTLDevice* | ||
| /// queue: MTLCommandQueue* | ||
| PgpuRenderer *pgpu_renderer_new(void *device, void *queue); | ||
|
|
||
| /// Renders a prepared scene into a texture target. Commands for rendering are | ||
| /// recorded into the specified command buffer. Returns an id representing | ||
| /// resources that may have been allocated during this process. After the | ||
| /// command buffer has been retired, call `pgpu_renderer_release` with this id | ||
| /// to drop any associated resources. | ||
| /// | ||
| /// target: MTLTexture* | ||
| /// cmdbuf: MTLCommandBuffer* | ||
| uint32_t pgpu_renderer_render(PgpuRenderer *renderer, | ||
| const PgpuScene *scene, | ||
| void *target, | ||
| void *cmdbuf); | ||
|
|
||
| /// Releases the internal resources associated with the specified id from a | ||
| /// previous render operation. | ||
| void pgpu_renderer_release(PgpuRenderer *renderer, uint32_t id); | ||
|
|
||
| /// Destroys the piet-gpu renderer. | ||
| void pgpu_renderer_destroy(PgpuRenderer *renderer); | ||
|
|
||
| /// Creates a new, empty piet-gpu scene. | ||
| PgpuScene *pgpu_scene_new(); | ||
|
|
||
| /// Destroys the piet-gpu scene. | ||
| void pgpu_scene_destroy(PgpuScene *scene); | ||
|
|
||
| /// Creates a new builder for filling a piet-gpu scene. The specified scene | ||
| /// should not be accessed while the builder is live. | ||
| PgpuSceneBuilder *pgpu_scene_builder_new(PgpuScene *scene); | ||
|
|
||
| /// Adds a glyph with the specified transform to the underlying scene. | ||
| void pgpu_scene_builder_add_glyph(PgpuSceneBuilder *builder, | ||
| const PgpuGlyph *glyph, | ||
| const float (*transform)[6]); | ||
|
|
||
| /// Finalizes the scene builder, making the underlying scene ready for | ||
| /// rendering. This takes ownership and consumes the builder. | ||
| void pgpu_scene_builder_finish(PgpuSceneBuilder *builder); | ||
|
|
||
| /// Creates a new context for loading glyph outlines. | ||
| PgpuGlyphContext *pgpu_glyph_context_new(); | ||
|
|
||
| /// Destroys the glyph context. | ||
| void pgpu_glyph_context_destroy(PgpuGlyphContext *gcx); | ||
|
|
||
| /// Creates a new glyph provider for the specified glyph context and font | ||
| /// descriptor. May return nullptr if the font data is invalid. Only one glyph | ||
| /// provider may be live for a glyph context. | ||
| PgpuGlyphProvider *pgpu_glyph_provider_new(PgpuGlyphContext *gcx, const PgpuFontDesc *font); | ||
|
|
||
| /// Returns an encoded outline for the specified glyph provider and glyph id. | ||
| /// May return nullptr if the requested glyph is not available. | ||
| PgpuGlyph *pgpu_glyph_provider_get(PgpuGlyphProvider *provider, uint16_t gid); | ||
|
|
||
| /// Returns an encoded color outline for the specified glyph provider, color | ||
| /// palette index and glyph id. May return nullptr if the requested glyph is | ||
| /// not available. | ||
| PgpuGlyph *pgpu_glyph_provider_get_color(PgpuGlyphProvider *provider, | ||
| uint16_t palette_index, | ||
| uint16_t gid); | ||
|
|
||
| /// Destroys the glyph provider. | ||
| void pgpu_glyph_provider_destroy(PgpuGlyphProvider *provider); | ||
|
|
||
| /// Computes the bounding box for the glyph after applying the specified | ||
| /// transform. | ||
| PgpuRect pgpu_glyph_bbox(const PgpuGlyph *glyph, const float (*transform)[6]); | ||
|
|
||
| /// Destroys the glyph. | ||
| void pgpu_glyph_destroy(PgpuGlyph *glyph); | ||
|
|
||
| } // extern "C" | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this file is auto-generated? It's actually a bit hard to tell as some of the comments look hand-written. In any case, would it be possible to add a line at or near the top explaining what's going on?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is auto-generated. I'll configure the generator to add a comment at the top marking it as such.