Skip to content
Myr

shm.h

This file

Path

shm.h

98 lines · 2.7 KiB · C

Last changed by

Implement gamma-correct blendingDaniel Eklöfbefore adoption2d19826

History of this file

Take it

1#pragma once23#include <stdbool.h>4#include <stddef.h>5#include <sys/types.h>67#include <pixman.h>8#include <wayland-client.h>910#include <tllist.h>1112#if defined(FUZZEL_ENABLE_CAIRO)13#include <cairo.h>14#endif1516struct damage;1718struct buffer {19    int width;20    int height;21    int stride;2223    void *data;2425    struct wl_buffer *wl_buf;26    pixman_image_t **pix;27#if defined(FUZZEL_ENABLE_CAIRO)28    cairo_t **cairo;29#endif30    size_t pix_instances;3132    unsigned age;3334    /*35     * First item in the array is used to track frame-to-frame36     * damage. This is used when re-applying damage from the last37     * frame, when the compositor doesn't release buffers immediately38     * (forcing us to double buffer)39     *40     * The remaining items are used to track surface damage. Each41     * worker thread adds its own cell damage to "its" region. When42     * the frame is done, all damage is converted to a single region,43     * which is then used in calls to wl_surface_damage_buffer().44     */45    pixman_region32_t *dirty;46};4748void shm_fini(void);49void shm_set_max_pool_size(off_t max_pool_size);5051struct buffer_chain;52struct buffer_chain *shm_chain_new(53    struct wl_shm *shm, bool scrollable, size_t pix_instances,54    pixman_format_code_t pix_fmt_with_alpha,55    pixman_format_code_t pix_fmt_without_alpha);56void shm_chain_free(struct buffer_chain *chain);5758/*59 * Returns a single buffer.60 *61 * May returned a cached buffer. If so, the buffer's age indicates how62 * many shm_get_buffer() calls have been made for the same63 * width/height while the buffer was still busy.64 *65 * A newly allocated buffer has an age of 1234.66 */67struct buffer *shm_get_buffer(68    struct buffer_chain *chain, int width, int height, bool with_alpha);69/*70 * Returns many buffers, described by 'info', all sharing the same SHM71 * buffer pool.72 *73 * Never returns cached buffers. However, the newly created buffers74 * are all inserted into the regular buffer cache, and are treated75 * just like buffers created by shm_get_buffer().76 *77 * This function is useful when allocating many small buffers, with78 * (roughly) the same life time.79 *80 * Buffers are tagged for immediate purging, and will be destroyed as81 * soon as the compositor releases them.82 */83void shm_get_many(84    struct buffer_chain *chain, size_t count,85    int widths[static count], int heights[static count],86    struct buffer *bufs[static count], bool with_alpha);8788void shm_did_not_use_buf(struct buffer *buf);8990bool shm_can_scroll(const struct buffer *buf);91bool shm_scroll(struct buffer *buf, int rows,92                int top_margin, int top_keep_rows,93                int bottom_margin, int bottom_keep_rows);9495void shm_addref(struct buffer *buf);96void shm_unref(struct buffer *buf);9798void shm_purge(struct buffer_chain *chain);