273f65802928adf0633212ae8edad01092120ddc
3 #include <X11/extensions/XvMClib.h>
4 #include <pipe/p_context.h>
5 #include <vl_display.h>
7 #include <vl_context.h>
10 static Status Validate
23 unsigned int found_surface
= 0;
24 XvAdaptorInfo
*adaptor_info
;
25 unsigned int num_adaptors
;
27 unsigned int max_width
, max_height
;
31 assert(display
&& chroma_format
);
35 ret
= XvQueryAdaptors(display
, XDefaultRootWindow(display
), &num_adaptors
, &adaptor_info
);
39 /* Scan through all adaptors looking for this port and surface */
40 for (i
= 0; i
< num_adaptors
&& !*found_port
; ++i
)
42 /* Scan through all ports of this adaptor looking for our port */
43 for (j
= 0; j
< adaptor_info
[i
].num_ports
&& !*found_port
; ++j
)
45 /* If this is our port, scan through all its surfaces looking for our surface */
46 if (adaptor_info
[i
].base_id
+ j
== port
)
48 XvMCSurfaceInfo
*surface_info
;
51 surface_info
= XvMCListSurfaceTypes(display
, adaptor_info
[i
].base_id
, &num_types
);
55 for (k
= 0; k
< num_types
&& !found_surface
; ++k
)
57 if (surface_info
[k
].surface_type_id
== surface_type_id
)
60 max_width
= surface_info
[k
].max_width
;
61 max_height
= surface_info
[k
].max_height
;
62 *chroma_format
= surface_info
[k
].chroma_format
;
63 *mc_type
= surface_info
[k
].mc_type
;
71 XvFreeAdaptorInfo(adaptor_info
);
78 XvFreeAdaptorInfo(adaptor_info
);
84 if (width
> max_width
|| height
> max_height
)
86 if (flags
!= XVMC_DIRECT
&& flags
!= 0)
92 static enum vlProfile
ProfileToVL(int xvmc_profile
)
94 if (xvmc_profile
& XVMC_MPEG_1
)
96 else if (xvmc_profile
& XVMC_MPEG_2
)
97 return vlProfileMpeg2Main
;
98 else if (xvmc_profile
& XVMC_H263
)
100 else if (xvmc_profile
& XVMC_MPEG_4
)
108 static enum vlEntryPoint
EntryToVL(int xvmc_entry
)
110 return xvmc_entry
& XVMC_IDCT
? vlEntryPointIDCT
: vlEntryPointMC
;
113 static enum vlFormat
FormatToVL(int xvmc_format
)
117 case XVMC_CHROMA_FORMAT_420
:
118 return vlFormatYCbCr420
;
119 case XVMC_CHROMA_FORMAT_422
:
120 return vlFormatYCbCr422
;
121 case XVMC_CHROMA_FORMAT_444
:
122 return vlFormatYCbCr444
;
130 Status
XvMCCreateContext(Display
*display
, XvPortID port
, int surface_type_id
, int width
, int height
, int flags
, XvMCContext
*context
)
136 struct vlDisplay
*vl_dpy
;
137 struct vlScreen
*vl_scrn
;
138 struct vlContext
*vl_ctx
;
139 struct pipe_context
*pipe
;
144 return XvMCBadContext
;
146 ret
= Validate(display
, port
, surface_type_id
, width
, height
, flags
, &found_port
, &chroma_format
, &mc_type
);
148 /* XXX: Success and XvBadPort have the same value */
149 if (ret
!= Success
|| !found_port
)
152 /* XXX: Assumes default screen, should check which screen port is on */
153 pipe
= create_pipe_context(display
, XDefaultScreen(display
));
157 vlCreateDisplay(display
, &vl_dpy
);
158 vlCreateScreen(vl_dpy
, XDefaultScreen(display
), pipe
->screen
, &vl_scrn
);
165 FormatToVL(chroma_format
),
166 ProfileToVL(mc_type
),
171 context
->context_id
= XAllocID(display
);
172 context
->surface_type_id
= surface_type_id
;
173 context
->width
= width
;
174 context
->height
= height
;
175 context
->flags
= flags
;
176 context
->port
= port
;
177 context
->privData
= vl_ctx
;
182 Status
XvMCDestroyContext(Display
*display
, XvMCContext
*context
)
184 struct vlContext
*vl_ctx
;
185 struct vlScreen
*vl_screen
;
186 struct vlDisplay
*vl_dpy
;
187 struct pipe_context
*pipe
;
192 return XvMCBadContext
;
194 vl_ctx
= context
->privData
;
196 assert(display
== vlGetNativeDisplay(vlGetDisplay(vlContextGetScreen(vl_ctx
))));
198 pipe
= vlGetPipeContext(vl_ctx
);
199 vl_screen
= vlContextGetScreen(vl_ctx
);
200 vl_dpy
= vlGetDisplay(vl_screen
);
201 vlDestroyContext(vl_ctx
);
202 vlDestroyScreen(vl_screen
);
203 vlDestroyDisplay(vl_dpy
);
204 destroy_pipe_context(pipe
);