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