Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
395 changes: 276 additions & 119 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions Cargo.toml
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"
]
21 changes: 21 additions & 0 deletions pgpu-render/Cargo.toml
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"
29 changes: 29 additions & 0 deletions pgpu-render/build.rs
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");
}
142 changes: 142 additions & 0 deletions pgpu-render/pgpu.h
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>
Copy link
Contributor

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?

Copy link
Collaborator Author

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.

#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"
Loading