mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-15 23:08:05 +02:00
Add a new surface backend that allocates pixel buffers through GBM (Generic Buffer Manager), allowing Cairo-rendered content to be imported directly by GPU compositors via DMA-BUF file descriptors without an intermediate memory copy. The backend renders on the CPU via pixman (like the image backend) but allocates its buffer through GBM with a linear modifier, making it suitable for zero-copy handoff to GPU-based compositors such as Mutter/Clutter (GNOME) or GSK (GTK 4). New public API (cairo-gbm.h): - cairo_gbm_surface_create() — allocate a new GBM-backed surface - cairo_gbm_surface_create_for_bo() — wrap an existing gbm_bo - cairo_gbm_surface_get_bo() — retrieve the underlying gbm_bo - cairo_gbm_surface_get_dma_buf_fd() — export a DMA-BUF fd for the buffer Build integration: - New 'gbm' meson option (auto-detected via libgbm + libdrm) - CAIRO_HAS_GBM_SURFACE feature flag Test coverage: - Dedicated API + error-path tests (test/gbm-surface.c) - Surface-as-source pattern test (test/gbm-surface-source.c) - GBM boilerplate target for the full test suite - Entries in api-special-cases.c and error-setters.c
74 lines
2.1 KiB
C
74 lines
2.1 KiB
C
/*
|
|
* Copyright © 2026 Red Hat, Inc.
|
|
*
|
|
* Permission to use, copy, modify, distribute, and sell this software
|
|
* and its documentation for any purpose is hereby granted without
|
|
* fee, provided that the above copyright notice appear in all copies
|
|
* and that both that copyright notice and this permission notice
|
|
* appear in supporting documentation, and that the name of
|
|
* Red Hat, Inc. not be used in advertising or publicity pertaining to
|
|
* distribution of the software without specific, written prior
|
|
* permission. Red Hat, Inc. makes no representations about the
|
|
* suitability of this software for any purpose. It is provided "as
|
|
* is" without express or implied warranty.
|
|
*
|
|
* RED HAT, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
|
|
* SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
|
|
* FITNESS, IN NO EVENT SHALL RED HAT, INC. BE LIABLE FOR ANY SPECIAL,
|
|
* INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
|
|
* RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
|
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
|
|
* IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
*
|
|
* Author: Alberto Ruiz <aruiz@redhat.com>
|
|
*/
|
|
|
|
#include "cairo-test.h"
|
|
|
|
#include <cairo-gbm.h>
|
|
|
|
#include <gbm.h>
|
|
#include <fcntl.h>
|
|
#include <unistd.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "surface-source.c"
|
|
|
|
static cairo_surface_t *
|
|
create_source_surface (int size)
|
|
{
|
|
#if CAIRO_HAS_GBM_SURFACE
|
|
int fd;
|
|
struct gbm_device *dev;
|
|
cairo_surface_t *surface;
|
|
|
|
fd = open ("/dev/dri/renderD128", O_RDWR);
|
|
if (fd < 0)
|
|
return NULL;
|
|
|
|
dev = gbm_create_device (fd);
|
|
if (dev == NULL) {
|
|
close (fd);
|
|
return NULL;
|
|
}
|
|
|
|
surface = cairo_gbm_surface_create (dev, CAIRO_FORMAT_ARGB32, size, size);
|
|
if (cairo_surface_status (surface)) {
|
|
cairo_surface_destroy (surface);
|
|
gbm_device_destroy (dev);
|
|
close (fd);
|
|
return NULL;
|
|
}
|
|
|
|
return surface;
|
|
#else
|
|
return NULL;
|
|
#endif
|
|
}
|
|
|
|
CAIRO_TEST (gbm_surface_source,
|
|
"Test using a GBM surface as the source",
|
|
"source, gbm", /* keywords */
|
|
NULL, /* requirements */
|
|
SIZE, SIZE,
|
|
preamble, draw)
|