~thopiekar/arm-mali/libvdpau-sunxi

1 by Jens Kuske
First release
1
/*
2
 * Copyright (c) 2013 Jens Kuske <jenskuske@gmail.com>
3
 *
4
 * This library is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU Lesser General Public
6
 * License as published by the Free Software Foundation; either
7
 * version 2.1 of the License, or (at your option) any later version.
8
 *
9
 * This library is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 * Lesser General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU Lesser General Public
15
 * License along with this library; if not, write to the Free Software
16
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17
 *
18
 */
19
16.1.11 by Jens Kuske
Make OSD support runtime switchable through VDPAU_OSD environment variable
20
#include <string.h>
16.1.1 by Jens Kuske
Add basic output surface support with g2d
21
#include <unistd.h>
22
#include <fcntl.h>
71 by Jens Kuske
Use libcedrus
23
#include <cedrus/cedrus.h>
1 by Jens Kuske
First release
24
#include "vdpau_private.h"
25
28 by rellla
Codestyling of function definition.
26
VdpStatus vdp_imp_device_create_x11(Display *display,
27
                                    int screen,
28
                                    VdpDevice *device,
29
                                    VdpGetProcAddress **get_proc_address)
1 by Jens Kuske
First release
30
{
31
	if (!display || !device || !get_proc_address)
32
		return VDP_STATUS_INVALID_POINTER;
33
48 by Jens Kuske
Simplify handle creation
34
	device_ctx_t *dev = handle_create(sizeof(*dev), device);
1 by Jens Kuske
First release
35
	if (!dev)
36
		return VDP_STATUS_RESOURCES;
37
3 by Jens Kuske
Add quick and dirty X window integration
38
	dev->display = XOpenDisplay(XDisplayString(display));
1 by Jens Kuske
First release
39
	dev->screen = screen;
40
71 by Jens Kuske
Use libcedrus
41
	dev->cedrus = cedrus_open();
42
	if (!dev->cedrus)
1 by Jens Kuske
First release
43
	{
65 by rellla
Add missing XCloseDisplay, if ve_open fails
44
		XCloseDisplay(dev->display);
48 by Jens Kuske
Simplify handle creation
45
		handle_destroy(*device);
1 by Jens Kuske
First release
46
		return VDP_STATUS_ERROR;
47
	}
48
71 by Jens Kuske
Use libcedrus
49
	VDPAU_DBG("VE version 0x%04x opened", cedrus_get_ve_version(dev->cedrus));
72 by Andreas Baierl
Add CPU fallback for G2D
50
	*get_proc_address = vdp_get_proc_address;
71 by Jens Kuske
Use libcedrus
51
16.1.11 by Jens Kuske
Make OSD support runtime switchable through VDPAU_OSD environment variable
52
	char *env_vdpau_osd = getenv("VDPAU_OSD");
72 by Andreas Baierl
Add CPU fallback for G2D
53
	char *env_vdpau_g2d = getenv("VDPAU_DISABLE_G2D");
16.1.11 by Jens Kuske
Make OSD support runtime switchable through VDPAU_OSD environment variable
54
	if (env_vdpau_osd && strncmp(env_vdpau_osd, "1", 1) == 0)
72 by Andreas Baierl
Add CPU fallback for G2D
55
		dev->osd_enabled = 1;
56
	else
57
	{
58
		VDPAU_DBG("OSD disabled!");
59
		return VDP_STATUS_OK;
60
	}
61
62
	if (!env_vdpau_g2d || strncmp(env_vdpau_g2d, "1", 1) !=0)
16.1.1 by Jens Kuske
Add basic output surface support with g2d
63
	{
16.1.11 by Jens Kuske
Make OSD support runtime switchable through VDPAU_OSD environment variable
64
		dev->g2d_fd = open("/dev/g2d", O_RDWR);
65
		if (dev->g2d_fd != -1)
72 by Andreas Baierl
Add CPU fallback for G2D
66
		{
67
			dev->g2d_enabled = 1;
68
			VDPAU_DBG("OSD enabled, using G2D!");
69
		}
16.1.1 by Jens Kuske
Add basic output surface support with g2d
70
	}
71
72 by Andreas Baierl
Add CPU fallback for G2D
72
	if (!dev->g2d_enabled)
73
		VDPAU_DBG("OSD enabled, using pixman");
1 by Jens Kuske
First release
74
75
	return VDP_STATUS_OK;
76
}
77
78
VdpStatus vdp_device_destroy(VdpDevice device)
79
{
80
	device_ctx_t *dev = handle_get(device);
81
	if (!dev)
82
		return VDP_STATUS_INVALID_HANDLE;
83
72 by Andreas Baierl
Add CPU fallback for G2D
84
	if (dev->g2d_enabled)
16.1.11 by Jens Kuske
Make OSD support runtime switchable through VDPAU_OSD environment variable
85
		close(dev->g2d_fd);
71 by Jens Kuske
Use libcedrus
86
	cedrus_close(dev->cedrus);
3 by Jens Kuske
Add quick and dirty X window integration
87
	XCloseDisplay(dev->display);
1 by Jens Kuske
First release
88
89
	handle_destroy(device);
90
91
	return VDP_STATUS_OK;
92
}
93
28 by rellla
Codestyling of function definition.
94
VdpStatus vdp_preemption_callback_register(VdpDevice device,
95
                                           VdpPreemptionCallback callback,
96
                                           void *context)
1 by Jens Kuske
First release
97
{
98
	if (!callback)
99
		return VDP_STATUS_INVALID_POINTER;
100
101
	device_ctx_t *dev = handle_get(device);
102
	if (!dev)
103
		return VDP_STATUS_INVALID_HANDLE;
104
105
	dev->preemption_callback = callback;
106
	dev->preemption_callback_context = context;
107
108
	return VDP_STATUS_OK;
109
}
110
111
static void *const functions[] =
112
{
58 by Jens Kuske
Remove unnecessary address operators from function pointers
113
	[VDP_FUNC_ID_GET_ERROR_STRING]                                      = vdp_get_error_string,
114
	[VDP_FUNC_ID_GET_PROC_ADDRESS]                                      = vdp_get_proc_address,
115
	[VDP_FUNC_ID_GET_API_VERSION]                                       = vdp_get_api_version,
116
	[VDP_FUNC_ID_GET_INFORMATION_STRING]                                = vdp_get_information_string,
117
	[VDP_FUNC_ID_DEVICE_DESTROY]                                        = vdp_device_destroy,
118
	[VDP_FUNC_ID_GENERATE_CSC_MATRIX]                                   = vdp_generate_csc_matrix,
119
	[VDP_FUNC_ID_VIDEO_SURFACE_QUERY_CAPABILITIES]                      = vdp_video_surface_query_capabilities,
120
	[VDP_FUNC_ID_VIDEO_SURFACE_QUERY_GET_PUT_BITS_Y_CB_CR_CAPABILITIES] = vdp_video_surface_query_get_put_bits_y_cb_cr_capabilities,
121
	[VDP_FUNC_ID_VIDEO_SURFACE_CREATE]                                  = vdp_video_surface_create,
122
	[VDP_FUNC_ID_VIDEO_SURFACE_DESTROY]                                 = vdp_video_surface_destroy,
123
	[VDP_FUNC_ID_VIDEO_SURFACE_GET_PARAMETERS]                          = vdp_video_surface_get_parameters,
124
	[VDP_FUNC_ID_VIDEO_SURFACE_GET_BITS_Y_CB_CR]                        = vdp_video_surface_get_bits_y_cb_cr,
125
	[VDP_FUNC_ID_VIDEO_SURFACE_PUT_BITS_Y_CB_CR]                        = vdp_video_surface_put_bits_y_cb_cr,
126
	[VDP_FUNC_ID_OUTPUT_SURFACE_QUERY_CAPABILITIES]                     = vdp_output_surface_query_capabilities,
127
	[VDP_FUNC_ID_OUTPUT_SURFACE_QUERY_GET_PUT_BITS_NATIVE_CAPABILITIES] = vdp_output_surface_query_get_put_bits_native_capabilities,
128
	[VDP_FUNC_ID_OUTPUT_SURFACE_QUERY_PUT_BITS_INDEXED_CAPABILITIES]    = vdp_output_surface_query_put_bits_indexed_capabilities,
129
	[VDP_FUNC_ID_OUTPUT_SURFACE_QUERY_PUT_BITS_Y_CB_CR_CAPABILITIES]    = vdp_output_surface_query_put_bits_y_cb_cr_capabilities,
130
	[VDP_FUNC_ID_OUTPUT_SURFACE_CREATE]                                 = vdp_output_surface_create,
131
	[VDP_FUNC_ID_OUTPUT_SURFACE_DESTROY]                                = vdp_output_surface_destroy,
132
	[VDP_FUNC_ID_OUTPUT_SURFACE_GET_PARAMETERS]                         = vdp_output_surface_get_parameters,
133
	[VDP_FUNC_ID_OUTPUT_SURFACE_GET_BITS_NATIVE]                        = vdp_output_surface_get_bits_native,
134
	[VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_NATIVE]                        = vdp_output_surface_put_bits_native,
135
	[VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_INDEXED]                       = vdp_output_surface_put_bits_indexed,
136
	[VDP_FUNC_ID_OUTPUT_SURFACE_PUT_BITS_Y_CB_CR]                       = vdp_output_surface_put_bits_y_cb_cr,
137
	[VDP_FUNC_ID_BITMAP_SURFACE_QUERY_CAPABILITIES]                     = vdp_bitmap_surface_query_capabilities,
138
	[VDP_FUNC_ID_BITMAP_SURFACE_CREATE]                                 = vdp_bitmap_surface_create,
139
	[VDP_FUNC_ID_BITMAP_SURFACE_DESTROY]                                = vdp_bitmap_surface_destroy,
140
	[VDP_FUNC_ID_BITMAP_SURFACE_GET_PARAMETERS]                         = vdp_bitmap_surface_get_parameters,
141
	[VDP_FUNC_ID_BITMAP_SURFACE_PUT_BITS_NATIVE]                        = vdp_bitmap_surface_put_bits_native,
142
	[VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_OUTPUT_SURFACE]                  = vdp_output_surface_render_output_surface,
143
	[VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_BITMAP_SURFACE]                  = vdp_output_surface_render_bitmap_surface,
1 by Jens Kuske
First release
144
	[VDP_FUNC_ID_OUTPUT_SURFACE_RENDER_VIDEO_SURFACE_LUMA]              = NULL,
58 by Jens Kuske
Remove unnecessary address operators from function pointers
145
	[VDP_FUNC_ID_DECODER_QUERY_CAPABILITIES]                            = vdp_decoder_query_capabilities,
146
	[VDP_FUNC_ID_DECODER_CREATE]                                        = vdp_decoder_create,
147
	[VDP_FUNC_ID_DECODER_DESTROY]                                       = vdp_decoder_destroy,
148
	[VDP_FUNC_ID_DECODER_GET_PARAMETERS]                                = vdp_decoder_get_parameters,
149
	[VDP_FUNC_ID_DECODER_RENDER]                                        = vdp_decoder_render,
150
	[VDP_FUNC_ID_VIDEO_MIXER_QUERY_FEATURE_SUPPORT]                     = vdp_video_mixer_query_feature_support,
151
	[VDP_FUNC_ID_VIDEO_MIXER_QUERY_PARAMETER_SUPPORT]                   = vdp_video_mixer_query_parameter_support,
152
	[VDP_FUNC_ID_VIDEO_MIXER_QUERY_ATTRIBUTE_SUPPORT]                   = vdp_video_mixer_query_attribute_support,
153
	[VDP_FUNC_ID_VIDEO_MIXER_QUERY_PARAMETER_VALUE_RANGE]               = vdp_video_mixer_query_parameter_value_range,
154
	[VDP_FUNC_ID_VIDEO_MIXER_QUERY_ATTRIBUTE_VALUE_RANGE]               = vdp_video_mixer_query_attribute_value_range,
155
	[VDP_FUNC_ID_VIDEO_MIXER_CREATE]                                    = vdp_video_mixer_create,
156
	[VDP_FUNC_ID_VIDEO_MIXER_SET_FEATURE_ENABLES]                       = vdp_video_mixer_set_feature_enables,
157
	[VDP_FUNC_ID_VIDEO_MIXER_SET_ATTRIBUTE_VALUES]                      = vdp_video_mixer_set_attribute_values,
158
	[VDP_FUNC_ID_VIDEO_MIXER_GET_FEATURE_SUPPORT]                       = vdp_video_mixer_get_feature_support,
159
	[VDP_FUNC_ID_VIDEO_MIXER_GET_FEATURE_ENABLES]                       = vdp_video_mixer_get_feature_enables,
160
	[VDP_FUNC_ID_VIDEO_MIXER_GET_PARAMETER_VALUES]                      = vdp_video_mixer_get_parameter_values,
161
	[VDP_FUNC_ID_VIDEO_MIXER_GET_ATTRIBUTE_VALUES]                      = vdp_video_mixer_get_attribute_values,
162
	[VDP_FUNC_ID_VIDEO_MIXER_DESTROY]                                   = vdp_video_mixer_destroy,
163
	[VDP_FUNC_ID_VIDEO_MIXER_RENDER]                                    = vdp_video_mixer_render,
164
	[VDP_FUNC_ID_PRESENTATION_QUEUE_TARGET_DESTROY]                     = vdp_presentation_queue_target_destroy,
165
	[VDP_FUNC_ID_PRESENTATION_QUEUE_CREATE]                             = vdp_presentation_queue_create,
166
	[VDP_FUNC_ID_PRESENTATION_QUEUE_DESTROY]                            = vdp_presentation_queue_destroy,
167
	[VDP_FUNC_ID_PRESENTATION_QUEUE_SET_BACKGROUND_COLOR]               = vdp_presentation_queue_set_background_color,
168
	[VDP_FUNC_ID_PRESENTATION_QUEUE_GET_BACKGROUND_COLOR]               = vdp_presentation_queue_get_background_color,
169
	[VDP_FUNC_ID_PRESENTATION_QUEUE_GET_TIME]                           = vdp_presentation_queue_get_time,
170
	[VDP_FUNC_ID_PRESENTATION_QUEUE_DISPLAY]                            = vdp_presentation_queue_display,
171
	[VDP_FUNC_ID_PRESENTATION_QUEUE_BLOCK_UNTIL_SURFACE_IDLE]           = vdp_presentation_queue_block_until_surface_idle,
172
	[VDP_FUNC_ID_PRESENTATION_QUEUE_QUERY_SURFACE_STATUS]               = vdp_presentation_queue_query_surface_status,
173
	[VDP_FUNC_ID_PREEMPTION_CALLBACK_REGISTER]                          = vdp_preemption_callback_register,
1 by Jens Kuske
First release
174
};
175
28 by rellla
Codestyling of function definition.
176
VdpStatus vdp_get_proc_address(VdpDevice device_handle,
177
                               VdpFuncId function_id,
178
                               void **function_pointer)
1 by Jens Kuske
First release
179
{
180
	if (!function_pointer)
181
		return VDP_STATUS_INVALID_POINTER;
182
183
	device_ctx_t *device = handle_get(device_handle);
184
	if (!device)
185
		return VDP_STATUS_INVALID_HANDLE;
186
187
	if (function_id < ARRAY_SIZE(functions))
188
	{
189
		*function_pointer = functions[function_id];
190
		if (*function_pointer == NULL)
191
			return VDP_STATUS_INVALID_FUNC_ID;
192
		else
193
			return VDP_STATUS_OK;
194
	}
195
	else if (function_id == VDP_FUNC_ID_BASE_WINSYS)
196
	{
197
		*function_pointer = &vdp_presentation_queue_target_create_x11;
198
199
		return VDP_STATUS_OK;
200
	}
201
202
	return VDP_STATUS_INVALID_FUNC_ID;
203
}
204
205
char const *vdp_get_error_string(VdpStatus status)
206
{
207
	switch (status)
208
	{
209
	case VDP_STATUS_OK:
210
		return "No error.";
211
	case VDP_STATUS_NO_IMPLEMENTATION:
212
		return "No backend implementation could be loaded.";
213
	case VDP_STATUS_DISPLAY_PREEMPTED:
214
		return "The display was preempted, or a fatal error occurred. The application must re-initialize VDPAU.";
215
	case VDP_STATUS_INVALID_HANDLE:
216
		return "An invalid handle value was provided.";
217
	case VDP_STATUS_INVALID_POINTER:
218
		return "An invalid pointer was provided.";
219
	case VDP_STATUS_INVALID_CHROMA_TYPE:
220
		return "An invalid/unsupported VdpChromaType value was supplied.";
221
	case VDP_STATUS_INVALID_Y_CB_CR_FORMAT:
222
		return "An invalid/unsupported VdpYCbCrFormat value was supplied.";
223
	case VDP_STATUS_INVALID_RGBA_FORMAT:
224
		return "An invalid/unsupported VdpRGBAFormat value was supplied.";
225
	case VDP_STATUS_INVALID_INDEXED_FORMAT:
226
		return "An invalid/unsupported VdpIndexedFormat value was supplied.";
227
	case VDP_STATUS_INVALID_COLOR_STANDARD:
228
		return "An invalid/unsupported VdpColorStandard value was supplied.";
229
	case VDP_STATUS_INVALID_COLOR_TABLE_FORMAT:
230
		return "An invalid/unsupported VdpColorTableFormat value was supplied.";
231
	case VDP_STATUS_INVALID_BLEND_FACTOR:
232
		return "An invalid/unsupported VdpOutputSurfaceRenderBlendFactor value was supplied.";
233
	case VDP_STATUS_INVALID_BLEND_EQUATION:
234
		return "An invalid/unsupported VdpOutputSurfaceRenderBlendEquation value was supplied.";
235
	case VDP_STATUS_INVALID_FLAG:
236
		return "An invalid/unsupported flag value/combination was supplied.";
237
	case VDP_STATUS_INVALID_DECODER_PROFILE:
238
		return "An invalid/unsupported VdpDecoderProfile value was supplied.";
239
	case VDP_STATUS_INVALID_VIDEO_MIXER_FEATURE:
240
		return "An invalid/unsupported VdpVideoMixerFeature value was supplied.";
241
	case VDP_STATUS_INVALID_VIDEO_MIXER_PARAMETER:
242
		return "An invalid/unsupported VdpVideoMixerParameter value was supplied.";
243
	case VDP_STATUS_INVALID_VIDEO_MIXER_ATTRIBUTE:
244
		return "An invalid/unsupported VdpVideoMixerAttribute value was supplied.";
245
	case VDP_STATUS_INVALID_VIDEO_MIXER_PICTURE_STRUCTURE:
246
		return "An invalid/unsupported VdpVideoMixerPictureStructure value was supplied.";
247
	case VDP_STATUS_INVALID_FUNC_ID:
248
		return "An invalid/unsupported VdpFuncId value was supplied.";
249
	case VDP_STATUS_INVALID_SIZE:
250
		return "The size of a supplied object does not match the object it is being used with.";
251
	case VDP_STATUS_INVALID_VALUE:
252
		return "An invalid/unsupported value was supplied.";
253
	case VDP_STATUS_INVALID_STRUCT_VERSION:
254
		return "An invalid/unsupported structure version was specified in a versioned structure.";
255
	case VDP_STATUS_RESOURCES:
256
		return "The system does not have enough resources to complete the requested operation at this time.";
257
	case VDP_STATUS_HANDLE_DEVICE_MISMATCH:
258
		return "The set of handles supplied are not all related to the same VdpDevice.";
259
	case VDP_STATUS_ERROR:
260
		return "A catch-all error, used when no other error code applies.";
261
	default:
262
		return "Unknown Error";
263
   }
264
}
265
266
VdpStatus vdp_get_api_version(uint32_t *api_version)
267
{
268
	if (!api_version)
269
		return VDP_STATUS_INVALID_POINTER;
270
271
	*api_version = 1;
272
	return VDP_STATUS_OK;
273
}
274
275
VdpStatus vdp_get_information_string(char const **information_string)
276
{
277
	if (!information_string)
278
		return VDP_STATUS_INVALID_POINTER;
279
280
	*information_string = "sunxi VDPAU Driver";
281
	return VDP_STATUS_OK;
282
}
283