cscg24-guacamole

CSCG 2024 Challenge 'Guacamole Mashup'
git clone https://git.sinitax.com/sinitax/cscg24-guacamole
Log | Files | Refs | sfeed.txt

buffer.h (4439B)


      1/*
      2 * Licensed to the Apache Software Foundation (ASF) under one
      3 * or more contributor license agreements.  See the NOTICE file
      4 * distributed with this work for additional information
      5 * regarding copyright ownership.  The ASF licenses this file
      6 * to you under the Apache License, Version 2.0 (the
      7 * "License"); you may not use this file except in compliance
      8 * with the License.  You may obtain a copy of the License at
      9 *
     10 *   http://www.apache.org/licenses/LICENSE-2.0
     11 *
     12 * Unless required by applicable law or agreed to in writing,
     13 * software distributed under the License is distributed on an
     14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
     15 * KIND, either express or implied.  See the License for the
     16 * specific language governing permissions and limitations
     17 * under the License.
     18 */
     19
     20#ifndef GUACENC_BUFFER_H
     21#define GUACENC_BUFFER_H
     22
     23#include "config.h"
     24
     25#include <cairo/cairo.h>
     26
     27#include <stdbool.h>
     28
     29/**
     30 * The image and size storage for either a buffer (a Guacamole layer with a
     31 * negative index) or a layer (a Guacamole layer with a non-negative index).
     32 */
     33typedef struct guacenc_buffer {
     34
     35    /**
     36     * Whether this buffer should be automatically resized to fit any draw
     37     * operation.
     38     */
     39    bool autosize;
     40
     41    /**
     42     * The width of this buffer or layer, in pixels.
     43     */
     44    int width;
     45
     46    /**
     47     * The height of this buffer or layer, in pixels.
     48     */
     49    int height;
     50
     51    /**
     52     * The number of bytes in each row of image data.
     53     */
     54    int stride;
     55
     56    /**
     57     * The underlying image data of this surface. If the width or height of
     58     * this surface are 0, this will be NULL.
     59     */
     60    unsigned char* image;
     61
     62    /**
     63     * The Cairo surface wrapping the underlying image data of this surface. If
     64     * the width or height of this surface are 0, this will be NULL.
     65     */
     66    cairo_surface_t* surface;
     67
     68    /**
     69     * The current graphics context of the Cairo surface. If the width or
     70     * height of this surface are 0, this will be NULL.
     71     */
     72    cairo_t* cairo;
     73
     74} guacenc_buffer;
     75
     76/**
     77 * Allocates and initializes a new buffer object. This allocation is
     78 * independent of the Guacamole video encoder display; the allocated
     79 * guacenc_buffer will not automatically be associated with the active display.
     80 *
     81 * @return
     82 *     A newly-allocated and initialized guacenc_buffer, or NULL if allocation
     83 *     fails.
     84 */
     85guacenc_buffer* guacenc_buffer_alloc();
     86
     87/**
     88 * Frees all memory associated with the given buffer object. If the buffer
     89 * provided is NULL, this function has no effect.
     90 *
     91 * @param buffer
     92 *     The buffer to free, which may be NULL.
     93 */
     94void guacenc_buffer_free(guacenc_buffer* buffer);
     95
     96/**
     97 * Resizes the given buffer to the given dimensions, allocating or freeing
     98 * memory as necessary, and updating the buffer's width, height, and stride
     99 * properties.
    100 *
    101 * @param buffer
    102 *     The buffer to resize.
    103 *
    104 * @param width
    105 *     The new width of the buffer, in pixels.
    106 *
    107 * @param height
    108 *     The new height of the buffer, in pixels.
    109 *
    110 * @return
    111 *     Zero if the resize operation is successful, non-zero on error.
    112 */
    113int guacenc_buffer_resize(guacenc_buffer* buffer, int width, int height);
    114
    115/**
    116 * Resizes the given buffer as necessary to contain at the given X/Y
    117 * coordinate, allocating or freeing memory as necessary, and updating the
    118 * buffer's width, height, and stride properties. If the buffer already
    119 * contains the given coordinate, this function has no effect.
    120 *
    121 * @param buffer
    122 *     The buffer to resize.
    123 *
    124 * @param x
    125 *     The X coordinate to ensure is within the buffer.
    126 *
    127 * @param y
    128 *     The Y coordinate to ensure is within the buffer.
    129 *
    130 * @return
    131 *     Zero if the resize operation is successful or no resize was performed,
    132 *     non-zero if the resize operation failed.
    133 */
    134int guacenc_buffer_fit(guacenc_buffer* buffer, int x, int y);
    135
    136/**
    137 * Copies the entire contents of the given source buffer to the destination
    138 * buffer, ignoring the current contents of the destination. The destination
    139 * buffer's contents are entirely replaced.
    140 *
    141 * @param dst
    142 *     The destination buffer whose contents should be replaced.
    143 *
    144 * @param src
    145 *     The source buffer whose contents should replace those of the destination
    146 *     buffer.
    147 *
    148 * @return
    149 *     Zero if the copy operation was successful, non-zero on failure.
    150 */
    151int guacenc_buffer_copy(guacenc_buffer* dst, guacenc_buffer* src);
    152
    153#endif
    154