[g3dvl] and finally remove pipe_video_context
[mesa.git] / src / gallium / state_trackers / vdpau / device.c
1 /**************************************************************************
2 *
3 * Copyright 2010 Younes Manton og 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 <pipe/p_compiler.h>
29
30 #include <util/u_memory.h>
31 #include <util/u_debug.h>
32
33 #include <vl_winsys.h>
34
35 #include "vdpau_private.h"
36
37 PUBLIC VdpStatus
38 vdp_imp_device_create_x11(Display *display, int screen, VdpDevice *device,
39 VdpGetProcAddress **get_proc_address)
40 {
41 VdpStatus ret;
42 vlVdpDevice *dev = NULL;
43
44 if (!(display && device && get_proc_address))
45 return VDP_STATUS_INVALID_POINTER;
46
47 if (!vlCreateHTAB()) {
48 ret = VDP_STATUS_RESOURCES;
49 goto no_htab;
50 }
51
52 dev = CALLOC(1, sizeof(vlVdpDevice));
53 if (!dev) {
54 ret = VDP_STATUS_RESOURCES;
55 goto no_dev;
56 }
57
58 dev->display = display;
59 dev->screen = screen;
60 dev->vscreen = vl_screen_create(display, screen);
61 if (!dev->vscreen) {
62 ret = VDP_STATUS_RESOURCES;
63 goto no_vscreen;
64 }
65
66 dev->context = vl_video_create(dev->vscreen);
67 if (!dev->context) {
68 ret = VDP_STATUS_RESOURCES;
69 goto no_context;
70 }
71
72 *device = vlAddDataHTAB(dev);
73 if (*device == 0) {
74 ret = VDP_STATUS_ERROR;
75 goto no_handle;
76 }
77
78 *get_proc_address = &vlVdpGetProcAddress;
79 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Device created succesfully\n");
80
81 return VDP_STATUS_OK;
82
83 no_handle:
84 /* Destroy vscreen */
85 no_context:
86 vl_screen_destroy(dev->vscreen);
87 no_vscreen:
88 FREE(dev);
89 no_dev:
90 vlDestroyHTAB();
91 no_htab:
92 return ret;
93 }
94
95 PUBLIC VdpStatus
96 vlVdpPresentationQueueTargetCreateX11(VdpDevice device, Drawable drawable,
97 VdpPresentationQueueTarget *target)
98 {
99 vlVdpPresentationQueueTarget *pqt;
100 VdpStatus ret;
101
102 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Creating PresentationQueueTarget\n");
103
104 if (!drawable)
105 return VDP_STATUS_INVALID_HANDLE;
106
107 vlVdpDevice *dev = vlGetDataHTAB(device);
108 if (!dev)
109 return VDP_STATUS_INVALID_HANDLE;
110
111 pqt = CALLOC(1, sizeof(vlVdpPresentationQueue));
112 if (!pqt)
113 return VDP_STATUS_RESOURCES;
114
115 pqt->device = dev;
116 pqt->drawable = drawable;
117
118 *target = vlAddDataHTAB(pqt);
119 if (*target == 0) {
120 ret = VDP_STATUS_ERROR;
121 goto no_handle;
122 }
123
124 return VDP_STATUS_OK;
125
126 no_handle:
127 FREE(pqt);
128 return ret;
129 }
130
131 VdpStatus
132 vlVdpPresentationQueueTargetDestroy(VdpPresentationQueueTarget presentation_queue_target)
133 {
134 vlVdpPresentationQueueTarget *pqt;
135
136 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying PresentationQueueTarget\n");
137
138 pqt = vlGetDataHTAB(presentation_queue_target);
139 if (!pqt)
140 return VDP_STATUS_INVALID_HANDLE;
141
142 vlRemoveDataHTAB(presentation_queue_target);
143 FREE(pqt);
144
145 return VDP_STATUS_OK;
146 }
147
148 VdpStatus
149 vlVdpDeviceDestroy(VdpDevice device)
150 {
151 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Destroying destroy\n");
152
153 vlVdpDevice *dev = vlGetDataHTAB(device);
154 if (!dev)
155 return VDP_STATUS_INVALID_HANDLE;
156
157 FREE(dev);
158 vlDestroyHTAB();
159
160 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Device destroyed succesfully\n");
161
162 return VDP_STATUS_OK;
163 }
164
165 VdpStatus
166 vlVdpGetProcAddress(VdpDevice device, VdpFuncId function_id, void **function_pointer)
167 {
168 vlVdpDevice *dev = vlGetDataHTAB(device);
169 if (!dev)
170 return VDP_STATUS_INVALID_HANDLE;
171
172 if (!function_pointer)
173 return VDP_STATUS_INVALID_POINTER;
174
175 if (!vlGetFuncFTAB(function_id, function_pointer))
176 return VDP_STATUS_INVALID_FUNC_ID;
177
178 VDPAU_MSG(VDPAU_TRACE, "[VDPAU] Got proc adress %p for id %d\n", *function_pointer, function_id);
179
180 return VDP_STATUS_OK;
181 }
182
183 #define _ERROR_TYPE(TYPE,STRING) case TYPE: return STRING;
184
185 char const *
186 vlVdpGetErrorString (VdpStatus status)
187 {
188 switch (status) {
189 _ERROR_TYPE(VDP_STATUS_OK,"The operation completed successfully; no error.");
190 _ERROR_TYPE(VDP_STATUS_NO_IMPLEMENTATION,"No backend implementation could be loaded.");
191 _ERROR_TYPE(VDP_STATUS_DISPLAY_PREEMPTED,"The display was preempted, or a fatal error occurred. The application must re-initialize VDPAU.");
192 _ERROR_TYPE(VDP_STATUS_INVALID_HANDLE,"An invalid handle value was provided. Either the handle does not exist at all, or refers to an object of an incorrect type.");
193 _ERROR_TYPE(VDP_STATUS_INVALID_POINTER ,"An invalid pointer was provided. Typically, this means that a NULL pointer was provided for an 'output' parameter.");
194 _ERROR_TYPE(VDP_STATUS_INVALID_CHROMA_TYPE ,"An invalid/unsupported VdpChromaType value was supplied.");
195 _ERROR_TYPE(VDP_STATUS_INVALID_Y_CB_CR_FORMAT,"An invalid/unsupported VdpYCbCrFormat value was supplied.");
196 _ERROR_TYPE(VDP_STATUS_INVALID_RGBA_FORMAT,"An invalid/unsupported VdpRGBAFormat value was supplied.");
197 _ERROR_TYPE(VDP_STATUS_INVALID_INDEXED_FORMAT,"An invalid/unsupported VdpIndexedFormat value was supplied.");
198 _ERROR_TYPE(VDP_STATUS_INVALID_COLOR_STANDARD,"An invalid/unsupported VdpColorStandard value was supplied.");
199 _ERROR_TYPE(VDP_STATUS_INVALID_COLOR_TABLE_FORMAT,"An invalid/unsupported VdpColorTableFormat value was supplied.");
200 _ERROR_TYPE(VDP_STATUS_INVALID_BLEND_FACTOR,"An invalid/unsupported VdpOutputSurfaceRenderBlendFactor value was supplied.");
201 _ERROR_TYPE(VDP_STATUS_INVALID_BLEND_EQUATION,"An invalid/unsupported VdpOutputSurfaceRenderBlendEquation value was supplied.");
202 _ERROR_TYPE(VDP_STATUS_INVALID_FLAG,"An invalid/unsupported flag value/combination was supplied.");
203 _ERROR_TYPE(VDP_STATUS_INVALID_DECODER_PROFILE,"An invalid/unsupported VdpDecoderProfile value was supplied.");
204 _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE,"An invalid/unsupported VdpVideoMixerFeature value was supplied.");
205 _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER ,"An invalid/unsupported VdpVideoMixerParameter value was supplied.");
206 _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE,"An invalid/unsupported VdpVideoMixerAttribute value was supplied.");
207 _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_PICTURE_STRUCTURE,"An invalid/unsupported VdpVideoMixerPictureStructure value was supplied.");
208 _ERROR_TYPE(VDP_STATUS_INVALID_FUNC_ID,"An invalid/unsupported VdpFuncId value was supplied.");
209 _ERROR_TYPE(VDP_STATUS_INVALID_SIZE,"The size of a supplied object does not match the object it is being used with.\
210 For example, a VdpVideoMixer is configured to process VdpVideoSurface objects of a specific size.\
211 If presented with a VdpVideoSurface of a different size, this error will be raised.");
212 _ERROR_TYPE(VDP_STATUS_INVALID_VALUE,"An invalid/unsupported value was supplied.\
213 This is a catch-all error code for values of type other than those with a specific error code.");
214 _ERROR_TYPE(VDP_STATUS_INVALID_STRUCT_VERSION,"An invalid/unsupported structure version was specified in a versioned structure. \
215 This implies that the implementation is older than the header file the application was built against.");
216 _ERROR_TYPE(VDP_STATUS_RESOURCES,"The system does not have enough resources to complete the requested operation at this time.");
217 _ERROR_TYPE(VDP_STATUS_HANDLE_DEVICE_MISMATCH,"The set of handles supplied are not all related to the same VdpDevice.When performing operations \
218 that operate on multiple surfaces, such as VdpOutputSurfaceRenderOutputSurface or VdpVideoMixerRender, \
219 all supplied surfaces must have been created within the context of the same VdpDevice object. \
220 This error is raised if they were not.");
221 _ERROR_TYPE(VDP_STATUS_ERROR,"A catch-all error, used when no other error code applies.");
222 default: return "Unknown Error";
223 }
224 }