Skip to content

Commit dd755a0

Browse files
haasnNiklas Haas
authored and
Niklas Haas
committed
libplacebo: provide typedefs for all object types
Apart from significantly cutting down amount the typing the user needs to perform, I decided the past justification for keeping these as `const struct` rather than typedef'd names no longer makes sense due to the way libplacebo objects tend to have private parts hidden from the user. Bite the bullet and refactor all the things. Should be backwards compatible, but I decided to bump the major version to signal the significance of this API change.
1 parent 2459200 commit dd755a0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+1421
-1609
lines changed

demos/plplay.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ struct plplay {
3939

4040
// libplacebo
4141
pl_log log;
42-
struct pl_renderer *renderer;
43-
struct pl_queue *queue;
42+
pl_renderer renderer;
43+
pl_queue queue;
4444

4545
// libav*
4646
AVFormatContext *format;
@@ -172,7 +172,7 @@ static bool init_codec(struct plplay *p)
172172
return true;
173173
}
174174

175-
static bool map_frame(const struct pl_gpu *gpu, const struct pl_tex **tex,
175+
static bool map_frame(pl_gpu gpu, pl_tex *tex,
176176
const struct pl_source_frame *src,
177177
struct pl_frame *out_frame)
178178
{
@@ -183,7 +183,7 @@ static bool map_frame(const struct pl_gpu *gpu, const struct pl_tex **tex,
183183
return true;
184184
}
185185

186-
static void unmap_frame(const struct pl_gpu *gpu, struct pl_frame *frame,
186+
static void unmap_frame(pl_gpu gpu, struct pl_frame *frame,
187187
const struct pl_source_frame *src)
188188
{
189189
av_frame_free((AVFrame **) &src->frame_data);

demos/sdlimage.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ static pl_log logger;
2222
static struct window *win;
2323

2424
// For rendering
25-
static const struct pl_tex *img_tex;
26-
static const struct pl_tex *osd_tex;
25+
static pl_tex img_tex;
26+
static pl_tex osd_tex;
2727
static struct pl_plane img_plane;
2828
static struct pl_plane osd_plane;
29-
static struct pl_renderer *renderer;
29+
static pl_renderer renderer;
3030
static struct pl_custom_lut *lut;
3131

3232
struct file
@@ -97,7 +97,7 @@ static void uninit(int ret)
9797
exit(ret);
9898
}
9999

100-
static bool upload_plane(const SDL_Surface *img, const struct pl_tex **tex,
100+
static bool upload_plane(const SDL_Surface *img, pl_tex *tex,
101101
struct pl_plane *plane)
102102
{
103103
if (!img)
@@ -133,7 +133,7 @@ static bool upload_plane(const SDL_Surface *img, const struct pl_tex **tex,
133133

134134
static bool render_frame(const struct pl_swapchain_frame *frame)
135135
{
136-
const struct pl_tex *img = img_plane.texture;
136+
pl_tex img = img_plane.texture;
137137
struct pl_frame image = {
138138
.num_planes = 1,
139139
.planes = { img_plane },

demos/ui.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ struct ui_vertex {
1313
#define NUM_VERTEX_ATTRIBS 3
1414

1515
struct ui {
16-
const struct pl_gpu *gpu;
17-
struct pl_dispatch *dp;
16+
pl_gpu gpu;
17+
pl_dispatch dp;
1818
struct nk_context nk;
1919
struct nk_font_atlas atlas;
2020
struct nk_buffer cmds, verts, idx;
21-
const struct pl_tex *font_tex;
21+
pl_tex font_tex;
2222
struct pl_vertex_attrib attribs_pl[NUM_VERTEX_ATTRIBS];
2323
struct nk_draw_vertex_layout_element attribs_nk[NUM_VERTEX_ATTRIBS+1];
2424
struct nk_convert_config convert_cfg;
2525
};
2626

27-
struct ui *ui_create(const struct pl_gpu *gpu)
27+
struct ui *ui_create(pl_gpu gpu)
2828
{
2929
struct ui *ui = malloc(sizeof(struct ui));
3030
if (!ui)
@@ -154,7 +154,7 @@ bool ui_draw(struct ui *ui, const struct pl_swapchain_frame *frame)
154154
if (!cmd->elem_count)
155155
continue;
156156

157-
struct pl_shader *sh = pl_dispatch_begin(ui->dp);
157+
pl_shader sh = pl_dispatch_begin(ui->dp);
158158
pl_shader_custom(sh, &(struct pl_custom_shader) {
159159
.body = "color = texture(ui_tex, coord).r * vcolor;",
160160
.output = PL_SHADER_SIG_COLOR,

demos/ui.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
struct ui;
1717

18-
struct ui *ui_create(const struct pl_gpu *gpu);
18+
struct ui *ui_create(pl_gpu gpu);
1919
void ui_destroy(struct ui **ui);
2020

2121
// Update/Logic/Draw cycle

demos/video-filtering.c

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -171,29 +171,29 @@ void image_unlock(struct image *img);
171171
#define PARALLELISM 8
172172

173173
struct entry {
174-
const struct pl_buf *buf; // to stream the download
175-
const struct pl_tex *tex_in[MAX_PLANES];
176-
const struct pl_tex *tex_out[MAX_PLANES];
174+
pl_buf buf; // to stream the download
175+
pl_tex tex_in[MAX_PLANES];
176+
pl_tex tex_out[MAX_PLANES];
177177
struct image image;
178178

179179
// For entries that are associated with a held image, so we can unlock them
180180
// as soon as possible
181181
struct image *held_image;
182-
const struct pl_buf *held_buf;
182+
pl_buf held_buf;
183183
};
184184

185185
// For both APIs:
186186
struct priv {
187187
pl_log log;
188-
const struct pl_vulkan *vk;
189-
const struct pl_gpu *gpu;
190-
struct pl_dispatch *dp;
191-
struct pl_shader_obj *dither_state;
188+
pl_vulkan vk;
189+
pl_gpu gpu;
190+
pl_dispatch dp;
191+
pl_shader_obj dither_state;
192192

193193
// Timer objects
194-
struct pl_timer *render_timer;
195-
struct pl_timer *upload_timer;
196-
struct pl_timer *download_timer;
194+
pl_timer render_timer;
195+
pl_timer upload_timer;
196+
pl_timer download_timer;
197197
uint64_t render_sum;
198198
uint64_t upload_sum;
199199
uint64_t download_sum;
@@ -202,8 +202,8 @@ struct priv {
202202
int download_count;
203203

204204
// API #1: A simple pair of input and output textures
205-
const struct pl_tex *tex_in[MAX_PLANES];
206-
const struct pl_tex *tex_out[MAX_PLANES];
205+
pl_tex tex_in[MAX_PLANES];
206+
pl_tex tex_out[MAX_PLANES];
207207

208208
// API #2: A ring buffer of textures/buffers for streaming
209209
int idx_in; // points the next free entry
@@ -305,7 +305,7 @@ static void setup_plane_data(const struct image *img,
305305

306306
// For API 2 (direct rendering)
307307
if (img->associated_buf) {
308-
const struct pl_buf *buf = img->associated_buf->priv;
308+
pl_buf buf = img->associated_buf->priv;
309309
out[i].pixels = NULL;
310310
out[i].buf = buf;
311311
out[i].buf_offset = (uintptr_t) plane->data - (uintptr_t) buf->data;
@@ -319,13 +319,13 @@ static void setup_plane_data(const struct image *img,
319319
}
320320
}
321321

322-
static bool do_plane(struct priv *p, const struct pl_tex *dst, const struct pl_tex *src)
322+
static bool do_plane(struct priv *p, pl_tex dst, pl_tex src)
323323
{
324324
int new_depth = dst->params.format->component_depth[0];
325325

326326
// Do some debanding, and then also make sure to dither to the new depth
327327
// so that our debanded gradients are actually preserved well
328-
struct pl_shader *sh = pl_dispatch_begin(p->dp);
328+
pl_shader sh = pl_dispatch_begin(p->dp);
329329
pl_shader_deband(sh, &(struct pl_sample_src){ .tex = src }, NULL);
330330
pl_shader_dither(sh, new_depth, &p->dither_state, NULL);
331331
return pl_dispatch_finish(p->dp, &(struct pl_dispatch_params) {
@@ -369,7 +369,7 @@ bool api1_reconfig(void *priv, const struct image *proxy)
369369
setup_plane_data(proxy, data);
370370

371371
for (int i = 0; i < proxy->num_planes; i++) {
372-
const struct pl_fmt *fmt = pl_plane_find_fmt(p->gpu, NULL, &data[i]);
372+
pl_fmt fmt = pl_plane_find_fmt(p->gpu, NULL, &data[i]);
373373
if (!fmt) {
374374
fprintf(stderr, "Failed configuring filter: no good texture format!\n");
375375
return false;
@@ -478,7 +478,7 @@ static enum api2_status submit_work(struct priv *p, struct entry *e,
478478
setup_plane_data(img, data);
479479

480480
for (int i = 0; i < img->num_planes; i++) {
481-
const struct pl_fmt *fmt = pl_plane_find_fmt(p->gpu, NULL, &data[i]);
481+
pl_fmt fmt = pl_plane_find_fmt(p->gpu, NULL, &data[i]);
482482
if (!fmt)
483483
return API2_ERR_FMT;
484484

@@ -614,7 +614,7 @@ bool api2_alloc(void *priv, size_t size, struct api2_buf *out)
614614
{
615615
struct priv *p = priv;
616616

617-
const struct pl_buf *buf = pl_buf_create(p->gpu, &(struct pl_buf_params) {
617+
pl_buf buf = pl_buf_create(p->gpu, &(struct pl_buf_params) {
618618
.size = size,
619619
.host_mapped = true,
620620
});
@@ -633,7 +633,7 @@ bool api2_alloc(void *priv, size_t size, struct api2_buf *out)
633633
void api2_free(void *priv, const struct api2_buf *buf)
634634
{
635635
struct priv *p = priv;
636-
const struct pl_buf *plbuf = buf->priv;
636+
pl_buf plbuf = buf->priv;
637637
pl_buf_destroy(p->gpu, &plbuf);
638638
}
639639

demos/window.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55

66
struct window {
77
const struct window_impl *impl;
8-
const struct pl_swapchain *swapchain;
9-
const struct pl_gpu *gpu;
8+
pl_swapchain swapchain;
9+
pl_gpu gpu;
1010
bool window_lost;
1111
};
1212

demos/window_glfw.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ struct priv {
3838

3939
#ifdef USE_VK
4040
VkSurfaceKHR surf;
41-
const struct pl_vulkan *vk;
42-
const struct pl_vk_inst *vk_inst;
41+
pl_vulkan vk;
42+
pl_vk_inst vk_inst;
4343
#endif
4444

4545
#ifdef USE_GL
46-
const struct pl_opengl *gl;
46+
pl_opengl gl;
4747
#endif
4848

4949
float scroll_dx, scroll_dy;

demos/window_sdl.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ struct priv {
3838

3939
#ifdef USE_VK
4040
VkSurfaceKHR surf;
41-
const struct pl_vulkan *vk;
42-
const struct pl_vk_inst *vk_inst;
41+
pl_vulkan vk;
42+
pl_vk_inst vk_inst;
4343
#endif
4444

4545
#ifdef USE_GL
4646
SDL_GLContext gl_ctx;
47-
const struct pl_opengl *gl;
47+
pl_opengl gl;
4848
#endif
4949

5050
int scroll_dx, scroll_dy;

meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ project('libplacebo', ['c', 'cpp'],
22
license: 'LGPL2.1+',
33
default_options: ['c_std=c99', 'cpp_std=c++11', 'warning_level=2'],
44
meson_version: '>=0.51',
5-
version: '3.129.0',
5+
version: '4.130.0',
66
)
77

88
# Version number

src/colorspace.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,7 @@ static struct pl_bit_encoding pl_bit_encoding_merge(const struct pl_bit_encoding
128128
};
129129
}
130130

131-
void pl_color_repr_merge(struct pl_color_repr *orig,
132-
const struct pl_color_repr *new)
131+
void pl_color_repr_merge(struct pl_color_repr *orig, const struct pl_color_repr *new)
133132
{
134133
*orig = (struct pl_color_repr) {
135134
.sys = PL_DEF(orig->sys, new->sys),

0 commit comments

Comments
 (0)