1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
|
/*
* Copyright © 2007 Intel Corporation
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*
* Authors:
* Zhenyu Wang <zhenyu.z.wang@intel.com>
*
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#define _INTEL_XVMC_SERVER_
#include "i830.h"
#include "intel_bufmgr.h"
#include "i830_hwmc.h"
#include "i915_hwmc.h"
#include "i965_hwmc.h"
#include <X11/extensions/Xv.h>
#include <X11/extensions/XvMC.h>
#include <fourcc.h>
struct intel_xvmc_driver *xvmc_driver;
/* set global current driver for xvmc */
static Bool intel_xvmc_set_driver(struct intel_xvmc_driver *d)
{
if (xvmc_driver) {
ErrorF("XvMC driver already set!\n");
return FALSE;
} else
xvmc_driver = d;
return TRUE;
}
/* check chip type and load xvmc driver */
/* This must be first called! */
Bool intel_xvmc_probe(ScrnInfoPtr scrn)
{
intel_screen_private *intel = intel_get_screen_private(scrn);
Bool ret = FALSE;
if (!intel->XvMCEnabled)
return FALSE;
/* Needs KMS support. */
if (IS_I915G(intel) || IS_I915GM(intel))
return FALSE;
if (IS_I9XX(intel)) {
if (IS_I915(intel))
ret = intel_xvmc_set_driver(&i915_xvmc_driver);
else if (IS_G4X(intel) || IS_IGDNG(intel))
ret = intel_xvmc_set_driver(&vld_xvmc_driver);
else
ret = intel_xvmc_set_driver(&i965_xvmc_driver);
} else {
ErrorF("Your chipset doesn't support XvMC.\n");
return FALSE;
}
return TRUE;
}
Bool intel_xvmc_screen_init(ScreenPtr pScreen)
{
ScrnInfoPtr scrn = xf86Screens[pScreen->myNum];
intel_screen_private *intel = intel_get_screen_private(scrn);
char buf[64];
if (!xvmc_driver)
return FALSE;
if (xf86XvMCScreenInit(pScreen, 1, &xvmc_driver->adaptor)) {
xf86DrvMsg(scrn->scrnIndex, X_INFO,
"[XvMC] %s driver initialized.\n",
xvmc_driver->name);
} else {
intel->XvMCEnabled = FALSE;
xf86DrvMsg(scrn->scrnIndex, X_INFO,
"[XvMC] Failed to initialize XvMC.\n");
return FALSE;
}
sprintf(buf, "pci:%04x:%02x:%02x.%d",
intel->PciInfo->domain,
intel->PciInfo->bus, intel->PciInfo->dev, intel->PciInfo->func);
xf86XvMCRegisterDRInfo(pScreen, INTEL_XVMC_LIBNAME,
buf,
INTEL_XVMC_MAJOR, INTEL_XVMC_MINOR,
INTEL_XVMC_PATCHLEVEL);
return TRUE;
}
/* i915 hwmc support */
#define _INTEL_XVMC_SERVER_
#define I915_XVMC_MAX_BUFFERS 2
#define I915_XVMC_MAX_CONTEXTS 4
#define I915_XVMC_MAX_SURFACES 20
static XF86MCSurfaceInfoRec i915_YV12_mpg2_surface = {
SURFACE_TYPE_MPEG2_MPML,
XVMC_CHROMA_FORMAT_420,
0,
720,
576,
720,
576,
XVMC_MPEG_2,
/* XVMC_OVERLAID_SURFACE | XVMC_SUBPICTURE_INDEPENDENT_SCALING, */
0,
/* &yv12_subpicture_list */
NULL,
};
static XF86MCSurfaceInfoRec i915_YV12_mpg1_surface = {
SURFACE_TYPE_MPEG1_MPML,
XVMC_CHROMA_FORMAT_420,
0,
720,
576,
720,
576,
XVMC_MPEG_1,
/* XVMC_OVERLAID_SURFACE | XVMC_SUBPICTURE_INDEPENDENT_SCALING, */
0,
NULL,
};
static XF86MCSurfaceInfoPtr ppSI[2] = {
(XF86MCSurfaceInfoPtr) & i915_YV12_mpg2_surface,
(XF86MCSurfaceInfoPtr) & i915_YV12_mpg1_surface
};
/* Check context size not exceed surface type max */
static void i915_check_context_size(XvMCContextPtr ctx)
{
int i;
for (i = 0; i < ARRAY_SIZE(ppSI); i++) {
if (ctx->surface_type_id == ppSI[i]->surface_type_id) {
if (ctx->width > ppSI[i]->max_width)
ctx->width = ppSI[i]->max_width;
if (ctx->height > ppSI[i]->max_height)
ctx->height = ppSI[i]->max_height;
}
}
}
/*
* i915_xvmc_create_context
*
* Some info about the private data:
*
* Set *num_priv to the number of 32bit words that make up the size of
* of the data that priv will point to.
*
* *priv = (long *) xcalloc (elements, sizeof(element))
* *num_priv = (elements * sizeof(element)) >> 2;
*
**************************************************************************/
static int i915_xvmc_create_context(ScrnInfoPtr scrn, XvMCContextPtr pContext,
int *num_priv, long **priv)
{
intel_screen_private *intel = intel_get_screen_private(scrn);
I915XvMCCreateContextRec *contextRec = NULL;
*priv = NULL;
*num_priv = 0;
if (!intel->XvMCEnabled) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"[XvMC] i915: XvMC disabled!\n");
return BadAlloc;
}
i915_check_context_size(pContext);
*priv = xcalloc(1, sizeof(I915XvMCCreateContextRec));
contextRec = (I915XvMCCreateContextRec *) * priv;
if (!*priv) {
*num_priv = 0;
return BadAlloc;
}
*num_priv = sizeof(I915XvMCCreateContextRec) >> 2;
contextRec->comm.type = xvmc_driver->flag;
/* i915 private context */
contextRec->deviceID = DEVICE_ID(intel->PciInfo);
return Success;
}
static int i915_xvmc_create_surface(ScrnInfoPtr scrn, XvMCSurfacePtr pSurf,
int *num_priv, long **priv)
{
intel_screen_private *intel = intel_get_screen_private(scrn);
if (!intel->XvMCEnabled) {
xf86DrvMsg(scrn->scrnIndex, X_ERROR,
"[XvMC] i915: XvMC disabled!\n");
return BadAlloc;
}
*priv = NULL;
*num_priv = 0;
return Success;
}
static void i915_xvmc_destroy_context(ScrnInfoPtr scrn,
XvMCContextPtr pContext)
{
return;
}
static void i915_xvmc_destroy_surface(ScrnInfoPtr scrn, XvMCSurfacePtr pSurf)
{
return;
}
static int create_subpicture(ScrnInfoPtr scrn, XvMCSubpicturePtr subpicture,
int *num_priv, CARD32 ** priv)
{
return Success;
}
static void destroy_subpicture(ScrnInfoPtr scrn, XvMCSubpicturePtr subpicture)
{
}
/* Fill in the device dependent adaptor record.
* This is named "Intel(R) Textured Video" because this code falls under the
* XV extenstion, the name must match or it won't be used.
*
* Surface and Subpicture - see above
* Function pointers to functions below
*/
static XF86MCAdaptorRec pAdapt = {
.name = "Intel(R) Textured Video",
.num_surfaces = ARRAY_SIZE(ppSI),
.surfaces = ppSI,
.num_subpictures = 0,
.subpictures = NULL,
.CreateContext =
(xf86XvMCCreateContextProcPtr) i915_xvmc_create_context,
.DestroyContext =
(xf86XvMCDestroyContextProcPtr) i915_xvmc_destroy_context,
.CreateSurface =
(xf86XvMCCreateSurfaceProcPtr) i915_xvmc_create_surface,
.DestroySurface =
(xf86XvMCDestroySurfaceProcPtr) i915_xvmc_destroy_surface,
.CreateSubpicture = create_subpicture,
.DestroySubpicture = destroy_subpicture,
};
/* new xvmc driver interface */
struct intel_xvmc_driver i915_xvmc_driver = {
.name = "i915_xvmc",
.adaptor = &pAdapt,
.flag = XVMC_I915_MPEG2_MC,
};
/* i965 and later hwmc support */
#define STRIDE(w) (w)
#define SIZE_YUV420(w, h) (h * (STRIDE(w) + STRIDE(w >> 1)))
#define VLD_MAX_SLICE_LEN (32*1024)
#ifndef XVMC_VLD
#define XVMC_VLD 0x00020000
#endif
static int create_context(ScrnInfoPtr scrn,
XvMCContextPtr context, int *num_privates,
CARD32 ** private)
{
struct i965_xvmc_context *private_context, *context_dup;
intel_screen_private *intel = intel_get_screen_private(scrn);
unsigned int blocknum =
(((context->width + 15) / 16) * ((context->height + 15) / 16));
unsigned int blocksize = 6 * blocknum * 64 * sizeof(short);
blocksize = (blocksize + 4095) & (~4095);
if ((private_context = Xcalloc(sizeof(*private_context))) == NULL) {
ErrorF("XVMC Can not allocate private context\n");
return BadAlloc;
}
if ((context_dup = Xcalloc(sizeof(*private_context))) == NULL) {
ErrorF("XVMC Can not allocate private context\n");
return BadAlloc;
}
private_context->is_g4x = IS_G4X(intel);
private_context->is_965_q = IS_965_Q(intel);
private_context->is_igdng = IS_IGDNG(intel);
private_context->comm.type = xvmc_driver->flag;
*num_privates = sizeof(*private_context) / sizeof(CARD32);
*private = (CARD32 *) private_context;
memcpy(context_dup, private_context, sizeof(*private_context));
context->driver_priv = context_dup;
return Success;
}
static void destroy_context(ScrnInfoPtr scrn, XvMCContextPtr context)
{
struct i965_xvmc_context *private_context;
private_context = context->driver_priv;
Xfree(private_context);
}
static int create_surface(ScrnInfoPtr scrn, XvMCSurfacePtr surface,
int *num_priv, CARD32 ** priv)
{
XvMCContextPtr ctx = surface->context;
struct i965_xvmc_surface *priv_surface, *surface_dup;
struct i965_xvmc_context *priv_ctx = ctx->driver_priv;
int i;
for (i = 0; i < I965_MAX_SURFACES; i++) {
if (priv_ctx->surfaces[i] == NULL) {
priv_surface = Xcalloc(sizeof(*priv_surface));
if (priv_surface == NULL)
return BadAlloc;
surface_dup = Xcalloc(sizeof(*priv_surface));
if (surface_dup == NULL)
return BadAlloc;
priv_surface->no = i;
priv_surface->handle = priv_surface;
priv_surface->w = ctx->width;
priv_surface->h = ctx->height;
priv_ctx->surfaces[i] = surface->driver_priv
= priv_surface;
memcpy(surface_dup, priv_surface,
sizeof(*priv_surface));
*num_priv = sizeof(*priv_surface) / sizeof(CARD32);
*priv = (CARD32 *) surface_dup;
break;
}
}
if (i >= I965_MAX_SURFACES) {
ErrorF("I965 XVMC too many surfaces in one context\n");
return BadAlloc;
}
return Success;
}
static void destory_surface(ScrnInfoPtr scrn, XvMCSurfacePtr surface)
{
XvMCContextPtr ctx = surface->context;
struct i965_xvmc_surface *priv_surface = surface->driver_priv;
struct i965_xvmc_context *priv_ctx = ctx->driver_priv;
priv_ctx->surfaces[priv_surface->no] = NULL;
Xfree(priv_surface);
}
static XF86MCSurfaceInfoRec yv12_mpeg2_vld_surface = {
FOURCC_YV12,
XVMC_CHROMA_FORMAT_420,
0,
1936,
1096,
1920,
1080,
XVMC_MPEG_2 | XVMC_VLD,
XVMC_INTRA_UNSIGNED,
NULL
};
static XF86MCSurfaceInfoRec yv12_mpeg2_surface = {
FOURCC_YV12,
XVMC_CHROMA_FORMAT_420,
0,
1936,
1096,
1920,
1080,
XVMC_MPEG_2 | XVMC_MOCOMP,
/* XVMC_OVERLAID_SURFACE | XVMC_SUBPICTURE_INDEPENDENT_SCALING, */
XVMC_INTRA_UNSIGNED,
/* &yv12_subpicture_list */
NULL
};
static XF86MCSurfaceInfoRec yv12_mpeg1_surface = {
FOURCC_YV12,
XVMC_CHROMA_FORMAT_420,
0,
1920,
1080,
1920,
1080,
XVMC_MPEG_1 | XVMC_MOCOMP,
/*XVMC_OVERLAID_SURFACE | XVMC_SUBPICTURE_INDEPENDENT_SCALING |
XVMC_INTRA_UNSIGNED, */
XVMC_INTRA_UNSIGNED,
/*&yv12_subpicture_list */
NULL
};
static XF86MCSurfaceInfoPtr surface_info[] = {
&yv12_mpeg2_surface,
&yv12_mpeg1_surface
};
static XF86MCSurfaceInfoPtr surface_info_vld[] = {
&yv12_mpeg2_vld_surface,
&yv12_mpeg2_surface,
};
static XF86MCAdaptorRec adaptor_vld = {
.name = "Intel(R) Textured Video",
.num_surfaces = sizeof(surface_info_vld) / sizeof(surface_info_vld[0]),
.surfaces = surface_info_vld,
.CreateContext = create_context,
.DestroyContext = destroy_context,
.CreateSurface = create_surface,
.DestroySurface = destory_surface,
.CreateSubpicture = create_subpicture,
.DestroySubpicture = destroy_subpicture
};
static XF86MCAdaptorRec adaptor = {
.name = "Intel(R) Textured Video",
.num_surfaces = sizeof(surface_info) / sizeof(surface_info[0]),
.surfaces = surface_info,
.CreateContext = create_context,
.DestroyContext = destroy_context,
.CreateSurface = create_surface,
.DestroySurface = destory_surface,
.CreateSubpicture = create_subpicture,
.DestroySubpicture = destroy_subpicture
};
struct intel_xvmc_driver i965_xvmc_driver = {
.name = "i965_xvmc",
.adaptor = &adaptor,
.flag = XVMC_I965_MPEG2_MC,
};
struct intel_xvmc_driver vld_xvmc_driver = {
.name = "xvmc_vld",
.adaptor = &adaptor_vld,
.flag = XVMC_I965_MPEG2_VLD,
};
|