mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-25 22:25:58 +01:00
render/drm-format-set: add wlr_drm_format_set_copy()
This commit is contained in:
parent
21c4516838
commit
c9b378d21a
2 changed files with 27 additions and 0 deletions
|
@ -17,4 +17,6 @@ struct wlr_drm_format *wlr_drm_format_dup(const struct wlr_drm_format *format);
|
|||
struct wlr_drm_format *wlr_drm_format_intersect(
|
||||
const struct wlr_drm_format *a, const struct wlr_drm_format *b);
|
||||
|
||||
bool wlr_drm_format_set_copy(struct wlr_drm_format_set *dst, const struct wlr_drm_format_set *src);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -140,6 +140,31 @@ struct wlr_drm_format *wlr_drm_format_dup(const struct wlr_drm_format *format) {
|
|||
return duped_format;
|
||||
}
|
||||
|
||||
bool wlr_drm_format_set_copy(struct wlr_drm_format_set *dst, const struct wlr_drm_format_set *src) {
|
||||
struct wlr_drm_format **formats = malloc(src->len * sizeof(formats[0]));
|
||||
if (formats == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct wlr_drm_format_set out = {
|
||||
.len = 0,
|
||||
.capacity = src->len,
|
||||
.formats = formats,
|
||||
};
|
||||
|
||||
size_t i;
|
||||
for (i = 0; i < src->len; i++) {
|
||||
out.formats[out.len] = wlr_drm_format_dup(src->formats[i]);
|
||||
if (out.formats[out.len] == NULL) {
|
||||
wlr_drm_format_set_finish(&out);
|
||||
return false;
|
||||
}
|
||||
out.len++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
struct wlr_drm_format *wlr_drm_format_intersect(
|
||||
const struct wlr_drm_format *a, const struct wlr_drm_format *b) {
|
||||
assert(a->format == b->format);
|
||||
|
|
Loading…
Reference in a new issue