22eadc1889b327efa56fc6666480dfdafe602b6b
3 #include <X11/extensions/XvMClib.h>
4 #include <vl_context.h>
5 #include <xsp_winsys.h>
7 static Status
Validate(Display
*display
, XvPortID port
, int surface_type_id
, unsigned int width
, unsigned int height
, int flags
, int *chroma_format
)
9 unsigned int found_port
= 0;
10 unsigned int found_surface
= 0;
11 XvAdaptorInfo
*adaptor_info
;
12 unsigned int num_adaptors
;
14 unsigned int max_width
, max_height
;
18 assert(display
&& chroma_format
);
20 ret
= XvQueryAdaptors(display
, XDefaultRootWindow(display
), &num_adaptors
, &adaptor_info
);
24 /* Scan through all adaptors looking for this port and surface */
25 for (i
= 0; i
< num_adaptors
&& !found_port
; ++i
)
27 /* Scan through all ports of this adaptor looking for our port */
28 for (j
= 0; j
< adaptor_info
[i
].num_ports
&& !found_port
; ++j
)
30 /* If this is our port, scan through all its surfaces looking for our surface */
31 if (adaptor_info
[i
].base_id
+ j
== port
)
33 XvMCSurfaceInfo
*surface_info
;
36 surface_info
= XvMCListSurfaceTypes(display
, adaptor_info
[i
].base_id
, &num_types
);
40 for (k
= 0; k
< num_types
&& !found_surface
; ++k
)
42 if (surface_info
[k
].surface_type_id
== surface_type_id
)
45 max_width
= surface_info
[k
].max_width
;
46 max_height
= surface_info
[k
].max_height
;
47 *chroma_format
= surface_info
[k
].chroma_format
;
55 XvFreeAdaptorInfo(adaptor_info
);
62 XvFreeAdaptorInfo(adaptor_info
);
68 if (width
> max_width
|| height
> max_height
)
70 if (flags
!= XVMC_DIRECT
&& flags
!= 0)
76 static enum VL_FORMAT
FormatToVL(int xvmc_format
)
78 enum VL_FORMAT vl_format
;
82 case XVMC_CHROMA_FORMAT_420
:
84 vl_format
= VL_FORMAT_YCBCR_420
;
87 case XVMC_CHROMA_FORMAT_422
:
89 vl_format
= VL_FORMAT_YCBCR_422
;
92 case XVMC_CHROMA_FORMAT_444
:
94 vl_format
= VL_FORMAT_YCBCR_444
;
104 Status
XvMCCreateContext(Display
*display
, XvPortID port
, int surface_type_id
, int width
, int height
, int flags
, XvMCContext
*context
)
108 struct VL_CONTEXT
*vl_ctx
;
109 struct pipe_context
*pipe
;
114 return XvMCBadContext
;
116 ret
= Validate(display
, port
, surface_type_id
, width
, height
, flags
, &chroma_format
);
120 pipe
= create_pipe_context(display
);
124 vlCreateContext(display
, pipe
, width
, height
, FormatToVL(chroma_format
), &vl_ctx
);
126 context
->context_id
= XAllocID(display
);
127 context
->surface_type_id
= surface_type_id
;
128 context
->width
= width
;
129 context
->height
= height
;
130 context
->flags
= flags
;
131 context
->port
= port
;
132 context
->privData
= vl_ctx
;
137 Status
XvMCDestroyContext(Display
*display
, XvMCContext
*context
)
139 struct VL_CONTEXT
*vl_ctx
;
140 struct pipe_context
*pipe
;
145 return XvMCBadContext
;
147 vl_ctx
= context
->privData
;
149 assert(display
== vl_ctx
->display
);
152 vlDestroyContext(vl_ctx
);
153 destroy_pipe_context(pipe
);
158 /* XXX: The following are here temporarily, need to be implemented in the DDX driver */
159 /* TODO: Figure out which of these need to be in DDX, which are better off in DDX, which can stay */
161 Bool
XvMCQueryExtension(Display
*display
, int *event_base
, int *err_base
)
169 Status
XvMCQueryVersion(Display
*display
, int *major
, int *minor
)
177 XvMCSurfaceInfo
* XvMCListSurfaceTypes(Display
*display
, XvPortID port
, int *num
)
179 XvMCSurfaceInfo
*surface_info
= calloc(1, sizeof(XvMCSurfaceInfo
));
183 surface_info
->chroma_format
= XVMC_CHROMA_FORMAT_420
;
184 surface_info
->max_width
= 2048;
185 surface_info
->max_height
= 2048;
186 surface_info
->mc_type
= XVMC_IDCT
| XVMC_MPEG_2
;
187 surface_info
->surface_type_id
= 123; /* FIXME: XAllocID(display)*/;
188 surface_info
->flags
|= XVMC_INTRA_UNSIGNED
;
193 XvImageFormatValues
* XvMCListSubpictureTypes(Display
* display
, XvPortID port
, int surface_type_id
, int *count_return
)