9c2b6648bb55d6db8fb1c27f9c0be584ff5dacf0
3 #include <X11/extensions/XvMClib.h>
4 #include <X11/Xlibint.h>
5 #include <pipe/p_context.h>
6 #include <vl_display.h>
8 #include <vl_context.h>
11 static Status Validate
24 unsigned int found_surface
= 0;
25 XvAdaptorInfo
*adaptor_info
;
26 unsigned int num_adaptors
;
28 unsigned int max_width
, max_height
;
32 assert(display
&& chroma_format
);
36 ret
= XvQueryAdaptors(display
, XDefaultRootWindow(display
), &num_adaptors
, &adaptor_info
);
40 /* Scan through all adaptors looking for this port and surface */
41 for (i
= 0; i
< num_adaptors
&& !*found_port
; ++i
)
43 /* Scan through all ports of this adaptor looking for our port */
44 for (j
= 0; j
< adaptor_info
[i
].num_ports
&& !*found_port
; ++j
)
46 /* If this is our port, scan through all its surfaces looking for our surface */
47 if (adaptor_info
[i
].base_id
+ j
== port
)
49 XvMCSurfaceInfo
*surface_info
;
52 surface_info
= XvMCListSurfaceTypes(display
, adaptor_info
[i
].base_id
, &num_types
);
56 for (k
= 0; k
< num_types
&& !found_surface
; ++k
)
58 if (surface_info
[k
].surface_type_id
== surface_type_id
)
61 max_width
= surface_info
[k
].max_width
;
62 max_height
= surface_info
[k
].max_height
;
63 *chroma_format
= surface_info
[k
].chroma_format
;
64 *mc_type
= surface_info
[k
].mc_type
;
72 XvFreeAdaptorInfo(adaptor_info
);
79 XvFreeAdaptorInfo(adaptor_info
);
85 if (width
> max_width
|| height
> max_height
)
87 if (flags
!= XVMC_DIRECT
&& flags
!= 0)
93 static enum vlProfile
ProfileToVL(int xvmc_profile
)
95 if (xvmc_profile
& XVMC_MPEG_1
)
97 else if (xvmc_profile
& XVMC_MPEG_2
)
98 return vlProfileMpeg2Main
;
99 else if (xvmc_profile
& XVMC_H263
)
101 else if (xvmc_profile
& XVMC_MPEG_4
)
109 static enum vlEntryPoint
EntryToVL(int xvmc_entry
)
111 return xvmc_entry
& XVMC_IDCT
? vlEntryPointIDCT
: vlEntryPointMC
;
114 static enum vlFormat
FormatToVL(int xvmc_format
)
118 case XVMC_CHROMA_FORMAT_420
:
119 return vlFormatYCbCr420
;
120 case XVMC_CHROMA_FORMAT_422
:
121 return vlFormatYCbCr422
;
122 case XVMC_CHROMA_FORMAT_444
:
123 return vlFormatYCbCr444
;
131 Status
XvMCCreateContext(Display
*display
, XvPortID port
, int surface_type_id
, int width
, int height
, int flags
, XvMCContext
*context
)
137 struct vlDisplay
*vl_dpy
;
138 struct vlScreen
*vl_scrn
;
139 struct vlContext
*vl_ctx
;
140 struct pipe_context
*pipe
;
141 Display
*dpy
= display
;
146 return XvMCBadContext
;
148 ret
= Validate(display
, port
, surface_type_id
, width
, height
, flags
, &found_port
, &chroma_format
, &mc_type
);
150 /* XXX: Success and XvBadPort have the same value */
151 if (ret
!= Success
|| !found_port
)
154 /* XXX: Assumes default screen, should check which screen port is on */
155 pipe
= create_pipe_context(display
, XDefaultScreen(display
));
159 vlCreateDisplay(display
, &vl_dpy
);
160 vlCreateScreen(vl_dpy
, XDefaultScreen(display
), pipe
->screen
, &vl_scrn
);
167 FormatToVL(chroma_format
),
168 ProfileToVL(mc_type
),
173 context
->context_id
= XAllocID(display
);
174 context
->surface_type_id
= surface_type_id
;
175 context
->width
= width
;
176 context
->height
= height
;
177 context
->flags
= flags
;
178 context
->port
= port
;
179 context
->privData
= vl_ctx
;
185 Status
XvMCDestroyContext(Display
*display
, XvMCContext
*context
)
187 struct vlContext
*vl_ctx
;
188 struct vlScreen
*vl_screen
;
189 struct vlDisplay
*vl_dpy
;
190 struct pipe_context
*pipe
;
195 return XvMCBadContext
;
197 vl_ctx
= context
->privData
;
199 assert(display
== vlGetNativeDisplay(vlGetDisplay(vlContextGetScreen(vl_ctx
))));
201 pipe
= vlGetPipeContext(vl_ctx
);
202 vl_screen
= vlContextGetScreen(vl_ctx
);
203 vl_dpy
= vlGetDisplay(vl_screen
);
204 vlDestroyContext(vl_ctx
);
205 vlDestroyScreen(vl_screen
);
206 vlDestroyDisplay(vl_dpy
);
207 destroy_pipe_context(pipe
);