image: implement ref-counted image release

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Idb30c621744eb9aa151fcaca012d93cc6a6a6964
This commit is contained in:
raf 2026-04-27 22:03:12 +03:00
commit edae535674
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
4 changed files with 108 additions and 40 deletions

17
include/chroma.h vendored
View file

@ -4,7 +4,7 @@
#include "wlr-layer-shell-unstable-v1.h"
#include "xdg-shell.h"
#include <EGL/egl.h>
#include <GL/gl.h>
#include <GLES2/gl2.h>
#include <signal.h>
#include <stdbool.h>
#include <stdint.h>
@ -16,7 +16,7 @@
#define MAX_OUTPUTS 16
#define MAX_PATH_LEN 4096
#define CONFIG_FILE_NAME "chroma.conf"
#define CONFIG_FILE_NAME "chroma.toml"
// Log levels
#define CHROMA_LOG_ERROR 0
@ -73,6 +73,7 @@ typedef struct {
int channels;
char path[MAX_PATH_LEN];
bool loaded;
int ref_count; // Number of outputs using this image
} chroma_image_t;
// Wayland output information
@ -116,6 +117,7 @@ typedef struct {
bool gl_resources_initialized;
bool texture_uploaded;
bool vbo_dirty; // track VBO needs update
bool configured; // track if initial configure received
} chroma_output_t;
// Config mapping structure
@ -162,6 +164,9 @@ typedef struct chroma_state {
EGLDisplay egl_display;
EGLContext egl_context;
EGLConfig egl_config;
// Shared OpenGL resources
GLuint shader_program;
// Outputs
chroma_output_t outputs[MAX_OUTPUTS];
@ -235,12 +240,15 @@ void chroma_layer_surface_closed(void *data,
// Image loading
void chroma_image_init_stb(void);
int chroma_image_load(chroma_image_t *image, const char *path,
const chroma_config_t *config);
const chroma_config_t *config, int output_width,
int output_height);
void chroma_image_free(chroma_image_t *image);
void chroma_image_release(chroma_image_t *image);
chroma_image_t *chroma_image_find_by_path(chroma_state_t *state,
const char *path);
chroma_image_t *chroma_image_get_or_load(chroma_state_t *state,
const char *path);
const char *path, int output_width,
int output_height);
int chroma_image_validate(const char *path);
int chroma_image_get_info(const char *path, int *width, int *height,
int *channels);
@ -248,6 +256,7 @@ void chroma_images_cleanup(chroma_state_t *state);
// Configuration
int chroma_config_load(chroma_config_t *config, const char *config_file);
int chroma_config_load_toml(chroma_config_t *config, const char *config_file);
void chroma_config_free(chroma_config_t *config);
const char *chroma_config_get_image_for_output(chroma_config_t *config,
const char *output_name,