Switch to cairo-drm, drop struct buffer hacks.

This commit is contained in:
Kristian Høgsberg 2009-01-15 11:37:43 -05:00
parent 32692d2f48
commit 0ac16f056d
7 changed files with 118 additions and 171 deletions

View file

@ -24,104 +24,10 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <i915_drm.h>
#include <sys/ioctl.h>
#include <math.h>
#include <cairo.h>
#include "cairo-util.h"
struct buffer *
buffer_create(int fd, int width, int height, int stride)
{
struct buffer *buffer;
struct drm_i915_gem_create create;
struct drm_gem_flink flink;
buffer = malloc(sizeof *buffer);
buffer->width = width;
buffer->height = height;
buffer->stride = stride;
memset(&create, 0, sizeof(create));
create.size = height * stride;
if (ioctl(fd, DRM_IOCTL_I915_GEM_CREATE, &create) != 0) {
fprintf(stderr, "gem create failed: %m\n");
free(buffer);
return NULL;
}
flink.handle = create.handle;
if (ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink) != 0) {
fprintf(stderr, "gem flink failed: %m\n");
free(buffer);
return 0;
}
buffer->handle = flink.handle;
buffer->name = flink.name;
return buffer;
}
int
buffer_destroy(struct buffer *buffer, int fd)
{
struct drm_gem_close close;
close.handle = buffer->handle;
if (ioctl(fd, DRM_IOCTL_GEM_CLOSE, &close) < 0) {
fprintf(stderr, "gem close failed: %m\n");
return -1;
}
free(buffer);
return 0;
}
int
buffer_data(struct buffer *buffer, int fd, void *data)
{
struct drm_i915_gem_pwrite pwrite;
pwrite.handle = buffer->handle;
pwrite.offset = 0;
pwrite.size = buffer->height * buffer->stride;
pwrite.data_ptr = (uint64_t) (uintptr_t) data;
if (ioctl(fd, DRM_IOCTL_I915_GEM_PWRITE, &pwrite) < 0) {
fprintf(stderr, "gem pwrite failed: %m\n");
return -1;
}
return 0;
}
struct buffer *
buffer_create_from_cairo_surface(int fd, cairo_surface_t *surface)
{
struct buffer *buffer;
int32_t width, height, stride;
void *data;
width = cairo_image_surface_get_width(surface);
height = cairo_image_surface_get_height(surface);
stride = cairo_image_surface_get_stride(surface);
data = cairo_image_surface_get_data(surface);
buffer = buffer_create(fd, width, height, stride);
if (buffer == NULL)
return NULL;
if (buffer_data(buffer, fd, data) < 0) {
buffer_destroy(buffer, fd);
return NULL;
}
return buffer;
}
#define ARRAY_LENGTH(a) (sizeof (a) / sizeof (a)[0])
void