output.c revision 28f8ff6b622d63e8ffe322ab2cdf5197941f1a40
1/************************************************************************** 2 * 3 * Copyright 2010 Thomas Balling Sørensen. 4 * Copyright 2011 Christian König. 5 * All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the 9 * "Software"), to deal in the Software without restriction, including 10 * without limitation the rights to use, copy, modify, merge, publish, 11 * distribute, sub license, and/or sell copies of the Software, and to 12 * permit persons to whom the Software is furnished to do so, subject to 13 * the following conditions: 14 * 15 * The above copyright notice and this permission notice (including the 16 * next paragraph) shall be included in all copies or substantial portions 17 * of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 * 27 **************************************************************************/ 28 29#include <vdpau/vdpau.h> 30 31#include "util/u_debug.h" 32#include "util/u_memory.h" 33#include "util/u_sampler.h" 34 35#include "vdpau_private.h" 36 37VdpStatus 38vlVdpOutputSurfaceCreate(VdpDevice device, 39 VdpRGBAFormat rgba_format, 40 uint32_t width, uint32_t height, 41 VdpOutputSurface *surface) 42{ 43 struct pipe_context *pipe; 44 struct pipe_resource res_tmpl, *res; 45 struct pipe_sampler_view sv_templ; 46 struct pipe_surface surf_templ; 47 48 vlVdpOutputSurface *vlsurface = NULL; 49 50 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Creating output surface\n"); 51 if (!(width && height)) 52 return VDP_STATUS_INVALID_SIZE; 53 54 vlVdpDevice *dev = vlGetDataHTAB(device); 55 if (!dev) 56 return VDP_STATUS_INVALID_HANDLE; 57 58 pipe = dev->context->pipe; 59 if (!pipe) 60 return VDP_STATUS_INVALID_HANDLE; 61 62 vlsurface = CALLOC(1, sizeof(vlVdpOutputSurface)); 63 if (!vlsurface) 64 return VDP_STATUS_RESOURCES; 65 66 memset(&res_tmpl, 0, sizeof(res_tmpl)); 67 68 res_tmpl.target = PIPE_TEXTURE_2D; 69 res_tmpl.format = FormatRGBAToPipe(rgba_format); 70 res_tmpl.width0 = width; 71 res_tmpl.height0 = height; 72 res_tmpl.depth0 = 1; 73 res_tmpl.array_size = 1; 74 res_tmpl.bind = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; 75 res_tmpl.usage = PIPE_USAGE_STATIC; 76 77 res = pipe->screen->resource_create(pipe->screen, &res_tmpl); 78 if (!res) { 79 FREE(dev); 80 return VDP_STATUS_ERROR; 81 } 82 83 memset(&sv_templ, 0, sizeof(sv_templ)); 84 u_sampler_view_default_template(&sv_templ, res, res->format); 85 86 // as long as we don't have a background picture we don't want an alpha channel 87 sv_templ.swizzle_a = PIPE_SWIZZLE_ONE; 88 89 vlsurface->sampler_view = pipe->create_sampler_view(pipe, res, &sv_templ); 90 if (!vlsurface->sampler_view) { 91 pipe_resource_reference(&res, NULL); 92 FREE(dev); 93 return VDP_STATUS_ERROR; 94 } 95 96 memset(&surf_templ, 0, sizeof(surf_templ)); 97 surf_templ.format = res->format; 98 surf_templ.usage = PIPE_BIND_SAMPLER_VIEW | PIPE_BIND_RENDER_TARGET; 99 vlsurface->surface = pipe->create_surface(pipe, res, &surf_templ); 100 if (!vlsurface->surface) { 101 pipe_resource_reference(&res, NULL); 102 FREE(dev); 103 return VDP_STATUS_ERROR; 104 } 105 106 *surface = vlAddDataHTAB(vlsurface); 107 if (*surface == 0) { 108 pipe_resource_reference(&res, NULL); 109 FREE(dev); 110 return VDP_STATUS_ERROR; 111 } 112 113 pipe_resource_reference(&res, NULL); 114 115 return VDP_STATUS_OK; 116} 117 118VdpStatus 119vlVdpOutputSurfaceDestroy(VdpOutputSurface surface) 120{ 121 vlVdpOutputSurface *vlsurface; 122 123 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying output surface\n"); 124 125 vlsurface = vlGetDataHTAB(surface); 126 if (!vlsurface) 127 return VDP_STATUS_INVALID_HANDLE; 128 129 pipe_surface_reference(&vlsurface->surface, NULL); 130 pipe_sampler_view_reference(&vlsurface->sampler_view, NULL); 131 132 vlRemoveDataHTAB(surface); 133 FREE(vlsurface); 134 135 return VDP_STATUS_OK; 136} 137 138VdpStatus 139vlVdpOutputSurfaceGetParameters(VdpOutputSurface surface, 140 VdpRGBAFormat *rgba_format, 141 uint32_t *width, uint32_t *height) 142{ 143 vlVdpOutputSurface *vlsurface; 144 145 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] getting surface parameters\n"); 146 147 vlsurface = vlGetDataHTAB(surface); 148 if (!vlsurface) 149 return VDP_STATUS_INVALID_HANDLE; 150 151 *rgba_format = PipeToFormatRGBA(vlsurface->sampler_view->texture->format); 152 *width = vlsurface->sampler_view->texture->width0; 153 *height = vlsurface->sampler_view->texture->height0; 154 155 return VDP_STATUS_OK; 156} 157 158VdpStatus 159vlVdpOutputSurfaceGetBitsNative(VdpOutputSurface surface, 160 VdpRect const *source_rect, 161 void *const *destination_data, 162 uint32_t const *destination_pitches) 163{ 164 return VDP_STATUS_NO_IMPLEMENTATION; 165} 166 167VdpStatus 168vlVdpOutputSurfacePutBitsNative(VdpOutputSurface surface, 169 void const *const *source_data, 170 uint32_t const *source_pitches, 171 VdpRect const *destination_rect) 172{ 173 return VDP_STATUS_NO_IMPLEMENTATION; 174} 175 176VdpStatus 177vlVdpOutputSurfacePutBitsIndexed(VdpOutputSurface surface, 178 VdpIndexedFormat source_indexed_format, 179 void const *const *source_data, 180 uint32_t const *source_pitch, 181 VdpRect const *destination_rect, 182 VdpColorTableFormat color_table_format, 183 void const *color_table) 184{ 185 return VDP_STATUS_NO_IMPLEMENTATION; 186} 187 188VdpStatus 189vlVdpOutputSurfacePutBitsYCbCr(VdpOutputSurface surface, 190 VdpYCbCrFormat source_ycbcr_format, 191 void const *const *source_data, 192 uint32_t const *source_pitches, 193 VdpRect const *destination_rect, 194 VdpCSCMatrix const *csc_matrix) 195{ 196 return VDP_STATUS_NO_IMPLEMENTATION; 197} 198 199VdpStatus 200vlVdpOutputSurfaceRenderOutputSurface(VdpOutputSurface destination_surface, 201 VdpRect const *destination_rect, 202 VdpOutputSurface source_surface, 203 VdpRect const *source_rect, 204 VdpColor const *colors, 205 VdpOutputSurfaceRenderBlendState const *blend_state, 206 uint32_t flags) 207{ 208 return VDP_STATUS_NO_IMPLEMENTATION; 209} 210 211VdpStatus 212vlVdpOutputSurfaceRenderBitmapSurface(VdpOutputSurface destination_surface, 213 VdpRect const *destination_rect, 214 VdpBitmapSurface source_surface, 215 VdpRect const *source_rect, 216 VdpColor const *colors, 217 VdpOutputSurfaceRenderBlendState const *blend_state, 218 uint32_t flags) 219{ 220 return VDP_STATUS_NO_IMPLEMENTATION; 221} 222