diff options
Diffstat (limited to 'src/gallium/state_trackers')
-rw-r--r-- | src/gallium/state_trackers/vdpau/surface.c | 24 | ||||
-rw-r--r-- | src/gallium/state_trackers/xorg/xvmc/subpicture.c | 71 |
2 files changed, 79 insertions, 16 deletions
diff --git a/src/gallium/state_trackers/vdpau/surface.c b/src/gallium/state_trackers/vdpau/surface.c index c2945c787da..f20087f3fca 100644 --- a/src/gallium/state_trackers/vdpau/surface.c +++ b/src/gallium/state_trackers/vdpau/surface.c @@ -33,6 +33,7 @@ #include <util/u_memory.h> #include <util/u_debug.h> +#include <util/u_rect.h> #include "vdpau_private.h" @@ -159,6 +160,7 @@ vlVdpVideoSurfacePutBitsYCbCr(VdpVideoSurface surface, uint32_t const *source_pitches) { enum pipe_format pformat = FormatToPipe(source_ycbcr_format); + struct pipe_context *pipe; struct pipe_video_context *context; struct pipe_sampler_view **sampler_views; unsigned i; @@ -170,8 +172,9 @@ vlVdpVideoSurfacePutBitsYCbCr(VdpVideoSurface surface, if (!p_surf) return VDP_STATUS_INVALID_HANDLE; + pipe = p_surf->device->context->pipe; context = p_surf->device->context->vpipe; - if (!context) + if (!pipe && !context) return VDP_STATUS_INVALID_HANDLE; if (p_surf->video_buffer == NULL || pformat != p_surf->video_buffer->buffer_format) { @@ -186,7 +189,24 @@ vlVdpVideoSurfacePutBitsYCbCr(VdpVideoSurface surface, for (i = 0; i < 3; ++i) { //TODO put nr of planes into util format struct pipe_sampler_view *sv = sampler_views[i ? i ^ 3 : 0]; struct pipe_box dst_box = { 0, 0, 0, sv->texture->width0, sv->texture->height0, 1 }; - context->upload_sampler(context, sv, &dst_box, source_data[i], source_pitches[i], 0, 0); + + struct pipe_transfer *transfer; + void *map; + + transfer = pipe->get_transfer(pipe, sv->texture, 0, PIPE_TRANSFER_WRITE, &dst_box); + if (!transfer) + return VDP_STATUS_RESOURCES; + + map = pipe->transfer_map(pipe, transfer); + if (map) { + util_copy_rect(map, sv->texture->format, transfer->stride, 0, 0, + dst_box.width, dst_box.height, + source_data[i], source_pitches[i], 0, 0); + + pipe->transfer_unmap(pipe, transfer); + } + + pipe->transfer_destroy(pipe, transfer); } return VDP_STATUS_OK; diff --git a/src/gallium/state_trackers/xorg/xvmc/subpicture.c b/src/gallium/state_trackers/xorg/xvmc/subpicture.c index b4594ad5e08..4ecb0e1f887 100644 --- a/src/gallium/state_trackers/xorg/xvmc/subpicture.c +++ b/src/gallium/state_trackers/xorg/xvmc/subpicture.c @@ -39,6 +39,7 @@ #include <util/u_math.h> #include <util/u_format.h> #include <util/u_sampler.h> +#include <util/u_rect.h> #include <vl_winsys.h> @@ -192,12 +193,37 @@ static Status Validate(Display *dpy, XvPortID port, int surface_type_id, int xvi return i < num_subpics ? Success : BadMatch; } +static void +upload_sampler(struct pipe_context *pipe, struct pipe_sampler_view *dst, + const struct pipe_box *dst_box, const void *src, unsigned src_stride, + unsigned src_x, unsigned src_y) +{ + struct pipe_transfer *transfer; + void *map; + + transfer = pipe->get_transfer(pipe, dst->texture, 0, PIPE_TRANSFER_WRITE, dst_box); + if (!transfer) + return; + + map = pipe->transfer_map(pipe, transfer); + if (map) { + util_copy_rect(map, dst->texture->format, transfer->stride, 0, 0, + dst_box->width, dst_box->height, + src, src_stride, src_x, src_y); + + pipe->transfer_unmap(pipe, transfer); + } + + pipe->transfer_destroy(pipe, transfer); +} + PUBLIC Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture *subpicture, unsigned short width, unsigned short height, int xvimage_id) { XvMCContextPrivate *context_priv; XvMCSubpicturePrivate *subpicture_priv; + struct pipe_context *pipe; struct pipe_video_context *vpipe; struct pipe_resource tex_templ, *tex; struct pipe_sampler_view sampler_templ; @@ -211,6 +237,7 @@ Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture * return XvMCBadContext; context_priv = context->privData; + pipe = context_priv->vctx->pipe; vpipe = context_priv->vctx->vpipe; if (!subpicture) @@ -254,7 +281,7 @@ Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture * u_sampler_view_default_template(&sampler_templ, tex, tex->format); XvIDToSwizzle(xvimage_id, &sampler_templ); - subpicture_priv->sampler = vpipe->create_sampler_view(vpipe, tex, &sampler_templ); + subpicture_priv->sampler = pipe->create_sampler_view(pipe, tex, &sampler_templ); pipe_resource_reference(&tex, NULL); if (!subpicture_priv->sampler) { FREE(subpicture_priv); @@ -283,7 +310,7 @@ Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture * memset(&sampler_templ, 0, sizeof(sampler_templ)); u_sampler_view_default_template(&sampler_templ, tex, tex->format); sampler_templ.swizzle_a = PIPE_SWIZZLE_ONE; - subpicture_priv->palette = vpipe->create_sampler_view(vpipe, tex, &sampler_templ); + subpicture_priv->palette = pipe->create_sampler_view(pipe, tex, &sampler_templ); pipe_resource_reference(&tex, NULL); if (!subpicture_priv->sampler) { FREE(subpicture_priv); @@ -304,8 +331,12 @@ Status XvMCClearSubpicture(Display *dpy, XvMCSubpicture *subpicture, short x, sh { XvMCSubpicturePrivate *subpicture_priv; XvMCContextPrivate *context_priv; + struct pipe_context *pipe; + struct pipe_sampler_view *dst; struct pipe_box dst_box = {x, y, 0, width, height, 1}; - float color_f[4]; + struct pipe_transfer *transfer; + union util_color uc; + void *map; assert(dpy); @@ -314,15 +345,28 @@ Status XvMCClearSubpicture(Display *dpy, XvMCSubpicture *subpicture, short x, sh /* Convert color to float */ util_format_read_4f(PIPE_FORMAT_B8G8R8A8_UNORM, - color_f, 1, &color, 4, + uc.f, 1, &color, 4, 0, 0, 1, 1); subpicture_priv = subpicture->privData; context_priv = subpicture_priv->context->privData; + pipe = context_priv->vctx->pipe; + dst = subpicture_priv->sampler; + /* TODO: Assert clear rect is within bounds? Or clip? */ - context_priv->vctx->vpipe->clear_sampler(context_priv->vctx->vpipe, - subpicture_priv->sampler, &dst_box, - color_f); + transfer = pipe->get_transfer(pipe, dst->texture, 0, PIPE_TRANSFER_WRITE, &dst_box); + if (!transfer) + return XvMCBadSubpicture; + + map = pipe->transfer_map(pipe, transfer); + if (map) { + util_fill_rect(map, dst->texture->format, transfer->stride, 0, 0, + dst_box.width, dst_box.height, &uc); + + pipe->transfer_unmap(pipe, transfer); + } + + pipe->transfer_destroy(pipe, transfer); return Success; } @@ -334,7 +378,7 @@ Status XvMCCompositeSubpicture(Display *dpy, XvMCSubpicture *subpicture, XvImage { XvMCSubpicturePrivate *subpicture_priv; XvMCContextPrivate *context_priv; - struct pipe_video_context *vpipe; + struct pipe_context *pipe; struct pipe_box dst_box = {dstx, dsty, 0, width, height, 1}; unsigned src_stride; @@ -356,13 +400,12 @@ Status XvMCCompositeSubpicture(Display *dpy, XvMCSubpicture *subpicture, XvImage subpicture_priv = subpicture->privData; context_priv = subpicture_priv->context->privData; - vpipe = context_priv->vctx->vpipe; + pipe = context_priv->vctx->pipe; /* clipping should be done by upload_sampler and regardles what the documentation says image->pitches[0] doesn't seems to be in bytes, so don't use it */ src_stride = image->width * util_format_get_blocksize(subpicture_priv->sampler->texture->format); - vpipe->upload_sampler(vpipe, subpicture_priv->sampler, &dst_box, - image->data, src_stride, srcx, srcy); + upload_sampler(pipe, subpicture_priv->sampler, &dst_box, image->data, src_stride, srcx, srcy); XVMC_MSG(XVMC_TRACE, "[XvMC] Subpicture %p composited.\n", subpicture); @@ -396,7 +439,7 @@ Status XvMCSetSubpicturePalette(Display *dpy, XvMCSubpicture *subpicture, unsign { XvMCSubpicturePrivate *subpicture_priv; XvMCContextPrivate *context_priv; - struct pipe_video_context *vpipe; + struct pipe_context *pipe; struct pipe_box dst_box = {0, 0, 0, 0, 1, 1}; assert(dpy); @@ -407,11 +450,11 @@ Status XvMCSetSubpicturePalette(Display *dpy, XvMCSubpicture *subpicture, unsign subpicture_priv = subpicture->privData; context_priv = subpicture_priv->context->privData; - vpipe = context_priv->vctx->vpipe; + pipe = context_priv->vctx->pipe; dst_box.width = subpicture->num_palette_entries; - vpipe->upload_sampler(vpipe, subpicture_priv->palette, &dst_box, palette, 0, 0, 0); + upload_sampler(pipe, subpicture_priv->palette, &dst_box, palette, 0, 0, 0); XVMC_MSG(XVMC_TRACE, "[XvMC] Palette of Subpicture %p set.\n", subpicture); |