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