#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
-#include <sys/ioctl.h>
#include <xf86drm.h>
#include "state_tracker/drm_driver.h"
#include "pipe/p_screen.h"
+#include "util/u_format.h"
+#include "util/u_inlines.h"
#include "util/u_memory.h"
struct renderonly *
return copy;
}
-struct renderonly_scanout *
-renderonly_scanout_for_prime(struct pipe_resource *rsc, struct renderonly *ro)
-{
- struct renderonly_scanout *scanout;
-
- scanout = CALLOC_STRUCT(renderonly_scanout);
- if (!scanout)
- return NULL;
-
- scanout->prime = rsc;
-
- return scanout;
-}
-
void
-renderonly_scanout_destroy(struct renderonly_scanout *scanout)
+renderonly_scanout_destroy(struct renderonly_scanout *scanout,
+ struct renderonly *ro)
{
+ struct drm_mode_destroy_dumb destroy_dumb = { };
+
+ if (ro->kms_fd != -1) {
+ destroy_dumb.handle = scanout->handle;
+ drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
+ }
FREE(scanout);
}
struct renderonly_scanout *
renderonly_create_kms_dumb_buffer_for_resource(struct pipe_resource *rsc,
- struct renderonly *ro)
+ struct renderonly *ro,
+ struct winsys_handle *out_handle)
{
- struct pipe_screen *screen = rsc->screen;
struct renderonly_scanout *scanout;
- struct winsys_handle handle;
- int prime_fd, err;
+ int err;
struct drm_mode_create_dumb create_dumb = {
.width = rsc->width0,
.height = rsc->height0,
- .bpp = 32,
+ .bpp = util_format_get_blocksizebits(rsc->format),
};
struct drm_mode_destroy_dumb destroy_dumb = { };
return NULL;
/* create dumb buffer at scanout GPU */
- err = ioctl(ro->kms_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
+ err = drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_CREATE_DUMB, &create_dumb);
if (err < 0) {
fprintf(stderr, "DRM_IOCTL_MODE_CREATE_DUMB failed: %s\n",
strerror(errno));
scanout->handle = create_dumb.handle;
scanout->stride = create_dumb.pitch;
- /* export dumb buffer */
+ if (!out_handle)
+ return scanout;
+
+ /* fill in winsys handle */
+ memset(out_handle, 0, sizeof(*out_handle));
+ out_handle->type = DRM_API_HANDLE_TYPE_FD;
+ out_handle->stride = create_dumb.pitch;
+
err = drmPrimeHandleToFD(ro->kms_fd, create_dumb.handle, O_CLOEXEC,
- &prime_fd);
+ (int *)&out_handle->handle);
if (err < 0) {
fprintf(stderr, "failed to export dumb buffer: %s\n", strerror(errno));
goto free_dumb;
}
- /* import dumb buffer */
- handle.type = DRM_API_HANDLE_TYPE_FD;
- handle.handle = prime_fd;
- handle.stride = create_dumb.pitch;
-
- scanout->prime = screen->resource_from_handle(screen, rsc,
- &handle, PIPE_HANDLE_USAGE_READ_WRITE);
-
- if (!scanout->prime) {
- fprintf(stderr, "failed to create resource_from_handle: %s\n", strerror(errno));
- goto free_dumb;
- }
-
return scanout;
free_dumb:
destroy_dumb.handle = scanout->handle;
- ioctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
+ drmIoctl(ro->kms_fd, DRM_IOCTL_MODE_DESTROY_DUMB, &destroy_dumb);
free_scanout:
FREE(scanout);
struct renderonly_scanout *
renderonly_create_gpu_import_for_resource(struct pipe_resource *rsc,
- struct renderonly *ro)
+ struct renderonly *ro,
+ struct winsys_handle *out_handle)
{
struct pipe_screen *screen = rsc->screen;
struct renderonly_scanout *scanout;