surface.c revision 06a49b18729890417094aa9602c1cc1ea8b970e2
1/************************************************************************** 2 * 3 * Copyright 2010 Thomas Balling Sørensen. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28#include "vdpau_private.h" 29#include <pipe/p_screen.h> 30#include <pipe/p_state.h> 31#include <util/u_memory.h> 32 33VdpStatus 34vlVdpVideoSurfaceCreate(VdpDevice device, 35 VdpChromaType chroma_type, 36 uint32_t width, 37 uint32_t height, 38 VdpVideoSurface *surface) 39{ 40 vlVdpSurface *p_surf; 41 VdpStatus ret; 42 43 if (!(width && height)) 44 { 45 ret = VDP_STATUS_INVALID_SIZE; 46 goto inv_size; 47 } 48 49 50 if (!vlCreateHTAB()) { 51 ret = VDP_STATUS_RESOURCES; 52 goto no_htab; 53 } 54 55 p_surf = CALLOC(0, sizeof(p_surf)); 56 if (!p_surf) { 57 ret = VDP_STATUS_RESOURCES; 58 goto no_res; 59 } 60 61 p_surf->psurface = CALLOC(0,sizeof(struct pipe_surface)); 62 if (!p_surf->psurface) { 63 ret = VDP_STATUS_RESOURCES; 64 goto no_surf; 65 } 66 67 vlVdpDevice *dev = vlGetDataHTAB(device); 68 if (!dev) { 69 ret = VDP_STATUS_INVALID_HANDLE; 70 goto inv_device; 71 } 72 73 if (!dev->vlscreen) 74 dev->vlscreen = vl_screen_create(dev->display, dev->screen); 75 if (!dev->vlscreen) { 76 ret = VDP_STATUS_RESOURCES; 77 goto inv_device; 78 } 79 80 p_surf->psurface->height = height; 81 p_surf->psurface->width = width; 82 p_surf->psurface->level = 0; 83 p_surf->psurface->usage = PIPE_USAGE_DEFAULT; 84 p_surf->chroma_format = FormatToPipe(chroma_type); 85 p_surf->vlscreen = dev->vlscreen; 86 87 *surface = vlAddDataHTAB(p_surf); 88 if (*surface == 0) { 89 ret = VDP_STATUS_ERROR; 90 goto no_handle; 91 } 92 93 return VDP_STATUS_OK; 94 95no_handle: 96 FREE(p_surf->psurface); 97inv_device: 98no_surf: 99 FREE(p_surf); 100no_res: 101 // vlDestroyHTAB(); XXX: Do not destroy this tab, I think. 102no_htab: 103inv_size: 104 return ret; 105} 106 107VdpStatus 108vlVdpVideoSurfaceDestroy ( VdpVideoSurface surface ) 109{ 110 vlVdpSurface *p_surf; 111 112 p_surf = (vlVdpSurface *)vlGetDataHTAB((vlHandle)surface); 113 if (!p_surf) 114 return VDP_STATUS_INVALID_HANDLE; 115 116 if (p_surf->psurface) 117 p_surf->vlscreen->pscreen->tex_surface_destroy(p_surf->psurface); 118 119 FREE(p_surf); 120 return VDP_STATUS_OK; 121} 122 123VdpStatus 124vlVdpVideoSurfaceGetParameters ( VdpVideoSurface surface, 125 VdpChromaType *chroma_type, 126 uint32_t *width, 127 uint32_t *height 128) 129{ 130 if (!(width && height && chroma_type)) 131 return VDP_STATUS_INVALID_POINTER; 132 133 134 if (!vlCreateHTAB()) 135 return VDP_STATUS_RESOURCES; 136 137 138 vlVdpSurface *p_surf = vlGetDataHTAB(surface); 139 if (!p_surf) 140 return VDP_STATUS_INVALID_HANDLE; 141 142 143 if (!(p_surf->psurface && p_surf->chroma_format)) 144 return VDP_STATUS_INVALID_HANDLE; 145 146 *width = p_surf->psurface->width; 147 *height = p_surf->psurface->height; 148 *chroma_type = PipeToType(p_surf->chroma_format); 149 150 return VDP_STATUS_OK; 151} 152 153VdpStatus 154vlVdpVideoSurfaceGetBitsYCbCr ( VdpVideoSurface surface, 155 VdpYCbCrFormat destination_ycbcr_format, 156 void *const *destination_data, 157 uint32_t const *destination_pitches 158) 159{ 160 161 162} 163