return (struct pipe_texture*)tex;
}
+static struct pipe_texture*
+ r300_texture_from_handle(struct pipe_screen* screen,
+ const struct pipe_texture* base,
+ struct winsys_handle *whandle)
+{
+ struct radeon_winsys* winsys = (struct radeon_winsys*)screen->winsys;
+ struct r300_screen* rscreen = r300_screen(screen);
+ struct pipe_buffer *buffer;
+ struct r300_texture* tex;
+ unsigned stride;
+
+ /* Support only 2D textures without mipmaps */
+ if (base->target != PIPE_TEXTURE_2D ||
+ base->depth0 != 1 ||
+ base->last_level != 0) {
+ return NULL;
+ }
+
+ buffer = winsys->buffer_from_handle(winsys, screen, whandle, &stride);
+ if (!buffer) {
+ return NULL;
+ }
+
+ tex = CALLOC_STRUCT(r300_texture);
+ if (!tex) {
+ return NULL;
+ }
+
+ tex->tex = *base;
+ pipe_reference_init(&tex->tex.reference, 1);
+ tex->tex.screen = screen;
+
+ tex->stride_override = stride;
+ tex->pitch[0] = stride / util_format_get_blocksize(base->format);
+
+ r300_setup_flags(tex);
+ r300_setup_texture_state(rscreen, tex);
+
+ /* one ref already taken */
+ tex->buffer = buffer;
+
+ return (struct pipe_texture*)tex;
+}
+
+static boolean
+ r300_texture_get_handle(struct pipe_screen* screen,
+ struct pipe_texture *texture,
+ struct winsys_handle *whandle)
+{
+ struct radeon_winsys* winsys = (struct radeon_winsys*)screen->winsys;
+ struct r300_texture* tex = (struct r300_texture*)texture;
+ unsigned stride;
+
+ if (!tex) {
+ return FALSE;
+ }
+
+ stride = r300_texture_get_stride(r300_screen(screen), tex, 0);
+
+ winsys->buffer_get_handle(winsys, tex->buffer, stride, whandle);
+
+ return TRUE;
+}
+
static struct pipe_video_surface *
r300_video_surface_create(struct pipe_screen *screen,
enum pipe_video_chroma_format chroma_format,
void r300_init_screen_texture_functions(struct pipe_screen* screen)
{
screen->texture_create = r300_texture_create;
+ screen->texture_from_handle = r300_texture_from_handle;
+ screen->texture_get_handle = r300_texture_get_handle;
screen->texture_destroy = r300_texture_destroy;
screen->get_tex_surface = r300_get_tex_surface;
screen->tex_surface_destroy = r300_tex_surface_destroy;
return 0;
}
+/* Create a buffer from a handle. */
+static struct pipe_buffer* radeon_buffer_from_handle(struct radeon_winsys *radeon_ws,
+ struct pipe_screen *screen,
+ struct winsys_handle *whandle,
+ unsigned *stride)
+{
+ struct radeon_bo_manager* bom = radeon_ws->priv->bom;
+ struct radeon_pipe_buffer* radeon_buffer;
+ struct radeon_bo* bo = NULL;
+
+ bo = radeon_bo_open(bom, whandle->handle, 0, 0, 0, 0);
+ if (bo == NULL) {
+ return NULL;
+ }
+
+ radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer);
+ if (radeon_buffer == NULL) {
+ radeon_bo_unref(bo);
+ return NULL;
+ }
+
+ pipe_reference_init(&radeon_buffer->base.reference, 1);
+ radeon_buffer->base.screen = screen;
+ radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL;
+ radeon_buffer->bo = bo;
+
+ *stride = whandle->stride;
+
+ return &radeon_buffer->base;
+}
+
+static boolean radeon_buffer_get_handle(struct radeon_winsys *radeon_ws,
+ struct pipe_buffer *buffer,
+ unsigned stride,
+ struct winsys_handle *whandle)
+{
+ int retval, fd;
+ struct drm_gem_flink flink;
+ struct radeon_pipe_buffer* radeon_buffer;
+
+ radeon_buffer = (struct radeon_pipe_buffer*)buffer;
+
+
+ if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) {
+ if (!radeon_buffer->flinked) {
+ fd = radeon_ws->priv->fd;
+
+ flink.handle = radeon_buffer->bo->handle;
+
+ retval = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
+ if (retval) {
+ debug_printf("radeon: DRM_IOCTL_GEM_FLINK failed, error %d\n",
+ retval);
+ return FALSE;
+ }
+
+ radeon_buffer->flink = flink.name;
+ radeon_buffer->flinked = TRUE;
+ }
+
+ whandle->handle = radeon_buffer->flink;
+ } else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) {
+ whandle->handle = ((struct radeon_pipe_buffer*)buffer)->bo->handle;
+ }
+ whandle->stride = stride;
+
+ return TRUE;
+}
+
struct radeon_winsys* radeon_pipe_winsys(int fd)
{
struct radeon_winsys* radeon_ws;
radeon_ws->base.get_name = radeon_get_name;
radeon_ws->buffer_set_tiling = radeon_buffer_set_tiling;
+ radeon_ws->buffer_from_handle = radeon_buffer_from_handle;
+ radeon_ws->buffer_get_handle = radeon_buffer_get_handle;
return radeon_ws;
}
}
}
-
-boolean radeon_buffer_from_texture(struct drm_api* api,
- struct pipe_screen* screen,
- struct pipe_texture* texture,
- struct pipe_buffer** buffer,
- unsigned* stride)
-{
- /* XXX fix this */
- return r300_get_texture_buffer(screen, texture, buffer, stride);
-}
-
-/* Create a buffer from a handle. */
-/* XXX what's up with name? */
-struct pipe_buffer* radeon_buffer_from_handle(struct drm_api* api,
- struct pipe_screen* screen,
- const char* name,
- unsigned handle)
-{
- struct radeon_bo_manager* bom =
- ((struct radeon_winsys*)screen->winsys)->priv->bom;
- struct radeon_pipe_buffer* radeon_buffer;
- struct radeon_bo* bo = NULL;
-
- bo = radeon_bo_open(bom, handle, 0, 0, 0, 0);
- if (bo == NULL) {
- return NULL;
- }
-
- radeon_buffer = CALLOC_STRUCT(radeon_pipe_buffer);
- if (radeon_buffer == NULL) {
- radeon_bo_unref(bo);
- return NULL;
- }
-
- pipe_reference_init(&radeon_buffer->base.reference, 1);
- radeon_buffer->base.screen = screen;
- radeon_buffer->base.usage = PIPE_BUFFER_USAGE_PIXEL;
- radeon_buffer->bo = bo;
- return &radeon_buffer->base;
-}
-
-static struct pipe_texture*
-radeon_texture_from_shared_handle(struct drm_api *api,
- struct pipe_screen *screen,
- struct pipe_texture *templ,
- const char *name,
- unsigned stride,
- unsigned handle)
-{
- struct pipe_buffer *buffer;
- struct pipe_texture *blanket;
-
- buffer = radeon_buffer_from_handle(api, screen, name, handle);
- if (!buffer) {
- return NULL;
- }
-
- blanket = screen->texture_blanket(screen, templ, &stride, buffer);
-
- pipe_buffer_reference(&buffer, NULL);
-
- return blanket;
-}
-
-static boolean radeon_shared_handle_from_texture(struct drm_api *api,
- struct pipe_screen *screen,
- struct pipe_texture *texture,
- unsigned *stride,
- unsigned *handle)
-{
- int retval, fd;
- struct drm_gem_flink flink;
- struct radeon_pipe_buffer* radeon_buffer;
- struct pipe_buffer *buffer = NULL;
-
- if (!radeon_buffer_from_texture(api, screen, texture, &buffer, stride)) {
- return FALSE;
- }
-
- radeon_buffer = (struct radeon_pipe_buffer*)buffer;
- if (!radeon_buffer->flinked) {
- fd = ((struct radeon_winsys*)screen->winsys)->priv->fd;
-
- flink.handle = radeon_buffer->bo->handle;
-
- retval = ioctl(fd, DRM_IOCTL_GEM_FLINK, &flink);
- if (retval) {
- debug_printf("radeon: DRM_IOCTL_GEM_FLINK failed, error %d\n",
- retval);
- return FALSE;
- }
-
- radeon_buffer->flink = flink.name;
- radeon_buffer->flinked = TRUE;
- }
-
- *handle = radeon_buffer->flink;
- return TRUE;
-}
-
-static boolean radeon_local_handle_from_texture(struct drm_api *api,
- struct pipe_screen *screen,
- struct pipe_texture *texture,
- unsigned *stride,
- unsigned *handle)
-{
- struct pipe_buffer *buffer = NULL;
- if (!radeon_buffer_from_texture(api, screen, texture, &buffer, stride)) {
- return FALSE;
- }
-
- *handle = ((struct radeon_pipe_buffer*)buffer)->bo->handle;
-
- pipe_buffer_reference(&buffer, NULL);
-
- return TRUE;
-}
-
static void radeon_drm_api_destroy(struct drm_api *api)
{
return;
.name = "radeon",
.driver_name = "radeon",
.create_screen = radeon_create_screen,
- .texture_from_shared_handle = radeon_texture_from_shared_handle,
- .shared_handle_from_texture = radeon_shared_handle_from_texture,
- .local_handle_from_texture = radeon_local_handle_from_texture,
.destroy = radeon_drm_api_destroy,
};
int drmFB,
struct drm_create_screen_arg *arg);
-
-boolean radeon_buffer_from_texture(struct drm_api* api,
- struct pipe_screen* screen,
- struct pipe_texture* texture,
- struct pipe_buffer** buffer,
- unsigned* stride);
-
-struct pipe_buffer* radeon_buffer_from_handle(struct drm_api* api,
- struct pipe_screen* screen,
- const char* name,
- unsigned handle);
-
-boolean radeon_handle_from_buffer(struct drm_api* api,
- struct pipe_screen* screen,
- struct pipe_buffer* buffer,
- unsigned* handle);
-
-boolean radeon_global_handle_from_buffer(struct drm_api* api,
- struct pipe_screen* screen,
- struct pipe_buffer* buffer,
- unsigned* handle);
-
void radeon_destroy_drm_api(struct drm_api* api);
/* Guess at whether this chipset should use r300g.
/* VRAM size. */
uint32_t vram_size;
+ /* Create a buffer from a winsys handle. */
+ struct pipe_buffer *(*buffer_from_handle)(struct radeon_winsys *winsys,
+ struct pipe_screen *screen,
+ struct winsys_handle *whandle,
+ unsigned *stride);
+
+ /* Get the handle from a buffer. */
+ boolean (*buffer_get_handle)(struct radeon_winsys *winsys,
+ struct pipe_buffer *buffer,
+ unsigned stride,
+ struct winsys_handle *whandle);
+
/* Add a pipe_buffer to the list of buffer objects to validate. */
boolean (*add_buffer)(struct radeon_winsys* winsys,
struct pipe_buffer* pbuffer,