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