Merge remote branch 'origin/master' into pipe-video
[mesa.git] / src / gallium / state_trackers / vdpau / device.c
1 /**************************************************************************
2 *
3 * Copyright 2010 Younes Manton.
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/vdpau_x11.h>
29 #include <pipe/p_compiler.h>
30 #include <vl_winsys.h>
31 #include <util/u_memory.h>
32 #include <util/u_debug.h>
33 #include "vdpau_private.h"
34
35 VdpDeviceCreateX11 vdp_imp_device_create_x11;
36
37 PUBLIC VdpStatus
38 vdp_imp_device_create_x11(Display *display, int screen, VdpDevice *device, VdpGetProcAddress **get_proc_address)
39 {
40 VdpStatus ret;
41 vlVdpDevice *dev = NULL;
42 struct vl_screen *vlscreen = 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 dev->display = display;
58 dev->screen = screen;
59
60 *device = vlAddDataHTAB(dev);
61 if (*device == 0) {
62 ret = VDP_STATUS_ERROR;
63 goto no_handle;
64 }
65
66 *get_proc_address = &vlVdpGetProcAddress;
67
68 debug_printf("[VDPAU] Device created succesfully\n");
69
70 return VDP_STATUS_OK;
71
72 no_handle:
73 FREE(dev);
74 no_dev:
75 vlDestroyHTAB();
76 no_htab:
77 return ret;
78 }
79
80 VdpStatus
81 vlVdpDeviceDestroy(VdpDevice device)
82 {
83 vlVdpDevice *dev = vlGetDataHTAB(device);
84 if (!dev)
85 return VDP_STATUS_INVALID_HANDLE;
86 FREE(dev);
87 vlDestroyHTAB();
88
89 debug_printf("[VDPAU] Device destroyed succesfully\n");
90
91 return VDP_STATUS_OK;
92 }
93
94 VdpStatus
95 vlVdpGetProcAddress(VdpDevice device, VdpFuncId function_id, void **function_pointer)
96 {
97 vlVdpDevice *dev = vlGetDataHTAB(device);
98 if (!dev)
99 return VDP_STATUS_INVALID_HANDLE;
100
101 if (!function_pointer)
102 return VDP_STATUS_INVALID_POINTER;
103
104 if (!vlGetFuncFTAB(function_id, function_pointer))
105 return VDP_STATUS_INVALID_FUNC_ID;
106
107 return VDP_STATUS_OK;
108 }
109
110 #define _ERROR_TYPE(TYPE,STRING) \
111 case TYPE: \
112 return STRING; \
113 break
114
115 char const *
116 vlVdpGetErrorString (
117 VdpStatus status)
118 {
119 switch (status)
120 {
121 _ERROR_TYPE(VDP_STATUS_OK,"The operation completed successfully; no error.");
122 _ERROR_TYPE(VDP_STATUS_NO_IMPLEMENTATION,"No backend implementation could be loaded.");
123 _ERROR_TYPE(VDP_STATUS_DISPLAY_PREEMPTED,"The display was preempted, or a fatal error occurred. The application must re-initialize VDPAU.");
124 _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.");
125 _ERROR_TYPE(VDP_STATUS_INVALID_POINTER ,"An invalid pointer was provided. Typically, this means that a NULL pointer was provided for an 'output' parameter.");
126 _ERROR_TYPE(VDP_STATUS_INVALID_CHROMA_TYPE ,"An invalid/unsupported VdpChromaType value was supplied.");
127 _ERROR_TYPE(VDP_STATUS_INVALID_Y_CB_CR_FORMAT,"An invalid/unsupported VdpYCbCrFormat value was supplied.");
128 _ERROR_TYPE(VDP_STATUS_INVALID_RGBA_FORMAT,"An invalid/unsupported VdpRGBAFormat value was supplied.");
129 _ERROR_TYPE(VDP_STATUS_INVALID_INDEXED_FORMAT,"An invalid/unsupported VdpIndexedFormat value was supplied.");
130 _ERROR_TYPE(VDP_STATUS_INVALID_COLOR_STANDARD,"An invalid/unsupported VdpColorStandard value was supplied.");
131 _ERROR_TYPE(VDP_STATUS_INVALID_COLOR_TABLE_FORMAT,"An invalid/unsupported VdpColorTableFormat value was supplied.");
132 _ERROR_TYPE(VDP_STATUS_INVALID_BLEND_FACTOR,"An invalid/unsupported VdpOutputSurfaceRenderBlendFactor value was supplied.");
133 _ERROR_TYPE(VDP_STATUS_INVALID_BLEND_EQUATION,"An invalid/unsupported VdpOutputSurfaceRenderBlendEquation value was supplied.");
134 _ERROR_TYPE(VDP_STATUS_INVALID_FLAG,"An invalid/unsupported flag value/combination was supplied.");
135 _ERROR_TYPE(VDP_STATUS_INVALID_DECODER_PROFILE,"An invalid/unsupported VdpDecoderProfile value was supplied.");
136 _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE,"An invalid/unsupported VdpVideoMixerFeature value was supplied.");
137 _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER ,"An invalid/unsupported VdpVideoMixerParameter value was supplied.");
138 _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE,"An invalid/unsupported VdpVideoMixerAttribute value was supplied.");
139 _ERROR_TYPE(VDP_STATUS_INVALID_VIDEO_MIXER_PICTURE_STRUCTURE,"An invalid/unsupported VdpVideoMixerPictureStructure value was supplied.");
140 _ERROR_TYPE(VDP_STATUS_INVALID_FUNC_ID,"An invalid/unsupported VdpFuncId value was supplied.");
141 _ERROR_TYPE(VDP_STATUS_INVALID_SIZE,"The size of a supplied object does not match the object it is being used with.\
142 For example, a VdpVideoMixer is configured to process VdpVideoSurface objects of a specific size.\
143 If presented with a VdpVideoSurface of a different size, this error will be raised.");
144 _ERROR_TYPE(VDP_STATUS_INVALID_VALUE,"An invalid/unsupported value was supplied.\
145 This is a catch-all error code for values of type other than those with a specific error code.");
146 _ERROR_TYPE(VDP_STATUS_INVALID_STRUCT_VERSION,"An invalid/unsupported structure version was specified in a versioned structure. \
147 This implies that the implementation is older than the header file the application was built against.");
148 _ERROR_TYPE(VDP_STATUS_RESOURCES,"The system does not have enough resources to complete the requested operation at this time.");
149 _ERROR_TYPE(VDP_STATUS_HANDLE_DEVICE_MISMATCH,"The set of handles supplied are not all related to the same VdpDevice.When performing operations \
150 that operate on multiple surfaces, such as VdpOutputSurfaceRenderOutputSurface or VdpVideoMixerRender, \
151 all supplied surfaces must have been created within the context of the same VdpDevice object. \
152 This error is raised if they were not.");
153 _ERROR_TYPE(VDP_STATUS_ERROR,"A catch-all error, used when no other error code applies.");
154 }
155 }