Skip to content

Commit 21a7760

Browse files
committed
readme changes
1 parent 1ab11e6 commit 21a7760

File tree

2 files changed

+79
-34
lines changed

2 files changed

+79
-34
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
steps:
1515
- uses: actions/checkout@v4
16-
16+
1717
- uses: msys2/setup-msys2@v2
1818
id: msys2
1919
with:
@@ -60,7 +60,7 @@ jobs:
6060
6161
mkdir -p ../skia/lib/win-x64
6262
cp --recursive include ../skia/include
63-
cp --recursive out/lib/*.lib ../skia/lib/win-x64/
63+
cp --recursive out/lib/*.lib ../skia/lib/win-x86_64/
6464
6565
cd ..
6666
rm -rf skia_repo

README.md

Lines changed: 77 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -4,51 +4,96 @@ This repository provides Zig bindings to the Skia C API. It builds Skia for mult
44

55
## Features
66

7-
- Builds Skia for multiple platforms (Linux, macOS, Windows, etc.)
8-
- Exposes the raw Skia C API headers
9-
- Compatible with Zig's `@cImport` for easy integration
7+
- Pre-built Skia binaries
8+
- Exposes the raw Skia C API headers (exposed throug a simple `@cImport` of the Skia headers)
9+
10+
## Project status
11+
*Warning*: This wrapper is in very early stage and not stable for production use. Also not all
12+
features and plaforms are ready.
13+
14+
[x] Skia build for Windows x86_64
15+
[ ] Skia build for macOS x86_64
16+
[ ] Skia build for macOS Apple Silicon
17+
[ ] Skia build for Linux
1018

1119
## Getting Started
1220

13-
### Prerequisites
21+
### Usage
1422

15-
Before building, ensure you have the following dependencies installed:
23+
1. Import the `skia-zig` package into your project:
24+
```bash
25+
zig fetch --save https://github.com/basdp/skia-zig/releases/download/alpha-v1/skia-zig-alpha-v1.zip
26+
```
1627

17-
- Zig (v0.10.0 or higher)
18-
- CMake
19-
- Ninja
20-
- Python 3
21-
- Clang (for compiling Skia)
28+
2. Add the dependency to your `build.zig` file, somewhere below `b.addExecutable(...)` or whatever you are building:
2229

23-
### Building
30+
```zig
31+
const skia_dep = b.dependency("skia-zig", .{
32+
.target = target,
33+
.optimize = optimize,
34+
});
35+
exe.root_module.addImport("skia-zig", skia_dep.module("skia-zig"));
36+
```
37+
38+
3. You can now import `skia-zig` in your Zig code:
39+
```zig
40+
const skia = @import("skia-zig");
2441
25-
To build Skia and set up the bindings for use in Zig, follow these steps:
42+
pub fn main() !void {
43+
const gr_glinterface = skia.gr_glinterface_create_native_interface();
44+
defer skia.gr_glinterface_unref(gr_glinterface);
45+
const gr_context = skia.gr_direct_context_make_gl(gr_glinterface) orelse return error.SkiaCreateContextFailed;
46+
defer skia.gr_direct_context_free_gpu_resources(gr_context);
2647
27-
1. Clone the repository:
48+
const gl_info = skia.gr_gl_framebufferinfo_t{
49+
.fFBOID = 0,
50+
.fFormat = gl.RGBA8,
51+
};
2852
29-
```bash
30-
git clone https://github.com/yourusername/skia-zig-bindings.git
31-
cd skia-zig-bindings
32-
```
53+
const samples: = ... // get from GL or something
54+
const stencil_bits = ... // get from GL or something
3355
34-
2. Build Skia for your platform:
56+
const backendRenderTarget = skia.gr_backendrendertarget_new_gl(640, 480, samples, stencil_bits, &gl_info) orelse return error.SkiaCreateRenderTargetFailed;
3557
36-
```bash
37-
./build_skia.sh
38-
```
58+
const color_type = skia.RGBA_8888_SK_COLORTYPE;
59+
const colorspace = null;
60+
const props = null;
61+
const surface = skia.sk_surface_new_backend_render_target(@ptrCast(gr_context), backendRenderTarget, skia.BOTTOM_LEFT_GR_SURFACE_ORIGIN, color_type, colorspace, props) orelse return error.SkiaCreateSurfaceFailed;
62+
defer skia.sk_surface_unref(surface);
3963
40-
This will download Skia, build it for your platform, and place the compiled libraries and headers in the `build/` directory.
64+
const canvas = skia.sk_surface_get_canvas(surface) orelse unreachable;
4165
42-
3. Link the Skia libraries and include the C headers in your Zig project.
66+
while (/* app is running */) {
67+
skia.sk_canvas_clear(canvas, 0xffffffff);
4368
44-
### Usage
69+
const fill = skia.sk_paint_new() orelse return error.SkiaCreatePaintFailed;
70+
defer skia.sk_paint_delete(fill);
71+
skia.sk_paint_set_color(fill, 0xff0000ff);
72+
skia.sk_canvas_draw_paint(canvas, fill);
4573
46-
After building, you can import the Skia C API headers in your Zig code as follows:
74+
// Your Skia drawing here
4775
48-
```zig
49-
const skia = @cImport({
50-
@cInclude("skia/c/sk_canvas.h");
51-
@cInclude("skia/c/sk_paint.h");
52-
@cInclude("skia/c/sk_surface.h");
53-
// Add other Skia headers as needed
54-
});
76+
skia.sk_canvas_flush(canvas);
77+
}
78+
}
79+
```
80+
81+
82+
### Setting your ABI to MSVC on Windows
83+
84+
Skia requires a msvc ABI on Windows, so make sure you target that abi. There are two possible
85+
options to do so:
86+
87+
1. Set the target from the command line while building:
88+
89+
```bash
90+
zig build -Dtarget=x86_64-windows-msvc
91+
```
92+
93+
2. Or better yet; replace the `const target = ...` line in your `build.zig` file:
94+
95+
```zig
96+
const target = b.standardTargetOptions(.{ .default_target = .{
97+
.abi = if (b.graph.host.result.os.tag == .windows) .msvc else null,
98+
} });
99+
```

0 commit comments

Comments
 (0)