1 #include "xorg_tracker.h"
4 #include <X11/extensions/Xv.h>
7 /*XXX get these from pipe's texture limits */
8 #define IMAGE_MAX_WIDTH 2048
9 #define IMAGE_MAX_HEIGHT 2048
11 #define MAKE_ATOM(a) MakeAtom(a, sizeof(a) - 1, TRUE)
13 static Atom xvBrightness
, xvContrast
;
15 #define NUM_TEXTURED_ATTRIBUTES 2
16 static XF86AttributeRec TexturedAttributes
[NUM_TEXTURED_ATTRIBUTES
] = {
17 {XvSettable
| XvGettable
, -128, 127, "XV_BRIGHTNESS"},
18 {XvSettable
| XvGettable
, 0, 255, "XV_CONTRAST"}
22 static XF86VideoFormatRec Formats
[NUM_FORMATS
] = {
23 {15, TrueColor
}, {16, TrueColor
}, {24, TrueColor
}
26 static XF86VideoEncodingRec DummyEncoding
[1] = {
30 IMAGE_MAX_WIDTH
, IMAGE_MAX_HEIGHT
,
36 static XF86ImageRec Images
[NUM_IMAGES
] = {
41 struct xorg_xv_port_priv
{
50 stop_video(ScrnInfoPtr pScrn
, pointer data
, Bool shutdown
)
52 struct xorg_xv_port_priv
*priv
= (struct xorg_xv_port_priv
*)data
;
54 REGION_EMPTY(pScrn
->pScreen
, &priv
->clip
);
58 set_port_attribute(ScrnInfoPtr pScrn
,
59 Atom attribute
, INT32 value
, pointer data
)
61 struct xorg_xv_port_priv
*priv
= (struct xorg_xv_port_priv
*)data
;
63 if (attribute
== xvBrightness
) {
64 if ((value
< -128) || (value
> 127))
66 priv
->brightness
= value
;
67 } else if (attribute
== xvContrast
) {
68 if ((value
< 0) || (value
> 255))
70 priv
->contrast
= value
;
78 get_port_attribute(ScrnInfoPtr pScrn
,
79 Atom attribute
, INT32
* value
, pointer data
)
81 struct xorg_xv_port_priv
*priv
= (struct xorg_xv_port_priv
*)data
;
83 if (attribute
== xvBrightness
)
84 *value
= priv
->brightness
;
85 else if (attribute
== xvContrast
)
86 *value
= priv
->contrast
;
94 query_best_size(ScrnInfoPtr pScrn
,
96 short vid_w
, short vid_h
,
97 short drw_w
, short drw_h
,
98 unsigned int *p_w
, unsigned int *p_h
, pointer data
)
100 if (vid_w
> (drw_w
<< 1))
102 if (vid_h
> (drw_h
<< 1))
110 put_image(ScrnInfoPtr pScrn
,
111 short src_x
, short src_y
,
112 short drw_x
, short drw_y
,
113 short src_w
, short src_h
,
114 short drw_w
, short drw_h
,
115 int id
, unsigned char *buf
,
116 short width
, short height
,
117 Bool sync
, RegionPtr clipBoxes
, pointer data
,
124 query_image_attributes(ScrnInfoPtr pScrn
,
126 unsigned short *w
, unsigned short *h
,
127 int *pitches
, int *offsets
)
131 if (*w
> IMAGE_MAX_WIDTH
)
132 *w
= IMAGE_MAX_WIDTH
;
133 if (*h
> IMAGE_MAX_HEIGHT
)
134 *h
= IMAGE_MAX_HEIGHT
;
154 static struct xorg_xv_port_priv
*
155 port_priv_create(ScreenPtr pScreen
)
157 /*ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];*/
158 /*modesettingPtr ms = modesettingPTR(pScrn);*/
159 struct xorg_xv_port_priv
*priv
= NULL
;
161 priv
= calloc(1, sizeof(struct xorg_xv_port_priv
));
166 REGION_NULL(pScreen
, &priv
->clip
);
171 static XF86VideoAdaptorPtr
172 xorg_setup_textured_adapter(ScreenPtr pScreen
)
174 /*ScrnInfoPtr pScrn = xf86Screens[pScreen->myNum];*/
175 /*modesettingPtr ms = modesettingPTR(pScrn);*/
176 XF86VideoAdaptorPtr adapt
;
177 XF86AttributePtr attrs
;
178 DevUnion
*dev_unions
;
182 nattributes
= NUM_TEXTURED_ATTRIBUTES
;
184 adapt
= calloc(1, sizeof(XF86VideoAdaptorRec
));
185 dev_unions
= calloc(nports
, sizeof(DevUnion
));
186 attrs
= calloc(nattributes
, sizeof(XF86AttributeRec
));
187 if (adapt
== NULL
|| dev_unions
== NULL
|| attrs
== NULL
) {
194 adapt
->type
= XvWindowMask
| XvInputMask
| XvImageMask
;
196 adapt
->name
= "Gallium3D Textured Video";
197 adapt
->nEncodings
= 1;
198 adapt
->pEncodings
= DummyEncoding
;
199 adapt
->nFormats
= NUM_FORMATS
;
200 adapt
->pFormats
= Formats
;
202 adapt
->pPortPrivates
= dev_unions
;
203 adapt
->nAttributes
= nattributes
;
204 adapt
->pAttributes
= attrs
;
205 memcpy(attrs
, TexturedAttributes
, nattributes
* sizeof(XF86AttributeRec
));
206 adapt
->nImages
= NUM_IMAGES
;
207 adapt
->pImages
= Images
;
208 adapt
->PutVideo
= NULL
;
209 adapt
->PutStill
= NULL
;
210 adapt
->GetVideo
= NULL
;
211 adapt
->GetStill
= NULL
;
212 adapt
->StopVideo
= stop_video
;
213 adapt
->SetPortAttribute
= set_port_attribute
;
214 adapt
->GetPortAttribute
= get_port_attribute
;
215 adapt
->QueryBestSize
= query_best_size
;
216 adapt
->PutImage
= put_image
;
217 adapt
->QueryImageAttributes
= query_image_attributes
;
219 for (i
= 0; i
< nports
; i
++) {
220 struct xorg_xv_port_priv
*priv
=
221 port_priv_create(pScreen
);
223 adapt
->pPortPrivates
[i
].ptr
= (pointer
) (priv
);
231 xorg_init_video(ScreenPtr pScreen
)
233 ScrnInfoPtr pScrn
= xf86Screens
[pScreen
->myNum
];
234 /*modesettingPtr ms = modesettingPTR(pScrn);*/
235 XF86VideoAdaptorPtr
*adaptors
, *new_adaptors
= NULL
;
236 XF86VideoAdaptorPtr textured_adapter
;
239 num_adaptors
= xf86XVListGenericAdaptors(pScrn
, &adaptors
);
240 new_adaptors
= malloc((num_adaptors
+ 1) * sizeof(XF86VideoAdaptorPtr
*));
241 if (new_adaptors
== NULL
)
244 memcpy(new_adaptors
, adaptors
, num_adaptors
* sizeof(XF86VideoAdaptorPtr
));
245 adaptors
= new_adaptors
;
247 /* Add the adaptors supported by our hardware. First, set up the atoms
248 * that will be used by both output adaptors.
250 xvBrightness
= MAKE_ATOM("XV_BRIGHTNESS");
251 xvContrast
= MAKE_ATOM("XV_CONTRAST");
253 textured_adapter
= xorg_setup_textured_adapter(pScreen
);
255 debug_assert(textured_adapter
);
257 if (textured_adapter
) {
258 adaptors
[num_adaptors
++] = textured_adapter
;
262 xf86XVScreenInit(pScreen
, adaptors
, num_adaptors
);
264 xf86DrvMsg(pScrn
->scrnIndex
, X_WARNING
,
265 "Disabling Xv because no adaptors could be initialized.\n");