surface.c revision 7d2bdc2d4db8321a72edcc921a0fcfa4e4d41ef9
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#include <util/u_format.h>
33
34VdpStatus
35vlVdpVideoSurfaceCreate(VdpDevice device,
36 VdpChromaType chroma_type,
37 uint32_t width,
38 uint32_t height,
39 VdpVideoSurface *surface)
40{
41 printf("[VDPAU] Creating a surface\n");
42
43 vlVdpSurface *p_surf;
44 VdpStatus ret;
45
46 if (!(width && height))
47 {
48 ret = VDP_STATUS_INVALID_SIZE;
49 goto inv_size;
50 }
51
52
53 if (!vlCreateHTAB()) {
54 ret = VDP_STATUS_RESOURCES;
55 goto no_htab;
56 }
57
58 p_surf = CALLOC(1, sizeof(p_surf));
59 if (!p_surf) {
60 ret = VDP_STATUS_RESOURCES;
61 goto no_res;
62 }
63
64 vlVdpDevice *dev = vlGetDataHTAB(device);
65 if (!dev) {
66 ret = VDP_STATUS_INVALID_HANDLE;
67 goto inv_device;
68 }
69
70 p_surf->chroma_format = TypeToPipe(chroma_type);
71 p_surf->device = dev;
72 p_surf->width = width;
73 p_surf->height = height;
74
75 *surface = vlAddDataHTAB(p_surf);
76 if (*surface == 0) {
77 ret = VDP_STATUS_ERROR;
78 goto no_handle;
79 }
80
81 return VDP_STATUS_OK;
82
83no_handle:
84 FREE(p_surf->psurface);
85inv_device:
86no_surf:
87 FREE(p_surf);
88no_res:
89 // vlDestroyHTAB(); XXX: Do not destroy this tab, I think.
90no_htab:
91inv_size:
92 return ret;
93}
94
95VdpStatus
96vlVdpVideoSurfaceDestroy ( VdpVideoSurface surface )
97{
98 vlVdpSurface *p_surf;
99
100 p_surf = (vlVdpSurface *)vlGetDataHTAB((vlHandle)surface);
101 if (!p_surf)
102 return VDP_STATUS_INVALID_HANDLE;
103
104 if (p_surf->psurface) {
105 if (p_surf->psurface->texture) {
106 if (p_surf->psurface->texture->screen)
107 p_surf->psurface->texture->screen->tex_surface_destroy(p_surf->psurface);
108 }
109 }
110 FREE(p_surf);
111 return VDP_STATUS_OK;
112}
113
114VdpStatus
115vlVdpVideoSurfaceGetParameters ( VdpVideoSurface surface,
116 VdpChromaType *chroma_type,
117 uint32_t *width,
118 uint32_t *height
119)
120{
121 if (!(width && height && chroma_type))
122 return VDP_STATUS_INVALID_POINTER;
123
124
125 vlVdpSurface *p_surf = vlGetDataHTAB(surface);
126 if (!p_surf)
127 return VDP_STATUS_INVALID_HANDLE;
128
129
130 if (!(p_surf->chroma_format > 0 && p_surf->chroma_format < 3))
131 return VDP_STATUS_INVALID_CHROMA_TYPE;
132
133 *width = p_surf->width;
134 *height = p_surf->height;
135 *chroma_type = PipeToType(p_surf->chroma_format);
136
137 return VDP_STATUS_OK;
138}
139
140VdpStatus
141vlVdpVideoSurfaceGetBitsYCbCr ( VdpVideoSurface surface,
142 VdpYCbCrFormat destination_ycbcr_format,
143 void *const *destination_data,
144 uint32_t const *destination_pitches
145)
146{
147 if (!vlCreateHTAB())
148 return VDP_STATUS_RESOURCES;
149
150
151 vlVdpSurface *p_surf = vlGetDataHTAB(surface);
152 if (!p_surf)
153 return VDP_STATUS_INVALID_HANDLE;
154
155 if (!p_surf->psurface)
156 return VDP_STATUS_RESOURCES;
157
158
159 return VDP_STATUS_OK;
160}
161
162VdpStatus
163vlVdpVideoSurfacePutBitsYCbCr ( VdpVideoSurface surface,
164 VdpYCbCrFormat source_ycbcr_format,
165 void const *const *source_data,
166 uint32_t const *source_pitches
167)
168{
169 uint32_t size_surface_bytes;
170 const struct util_format_description *format_desc;
171 enum pipe_format pformat = FormatToPipe(source_ycbcr_format);
172
173 if (!vlCreateHTAB())
174 return VDP_STATUS_RESOURCES;
175
176
177 vlVdpSurface *p_surf = vlGetDataHTAB(surface);
178 if (!p_surf)
179 return VDP_STATUS_INVALID_HANDLE;
180
181
182 //size_surface_bytes = ( source_pitches[0] * p_surf->height util_format_get_blockheight(pformat) );
183 /*util_format_translate(enum pipe_format dst_format,
184 void *dst, unsigned dst_stride,
185 unsigned dst_x, unsigned dst_y,
186 enum pipe_format src_format,
187 const void *src, unsigned src_stride,
188 unsigned src_x, unsigned src_y,
189 unsigned width, unsigned height);*/
190
191 return VDP_STATUS_NO_IMPLEMENTATION;
192
193}
194