2 * Copyright (c) 2009 Tiago Vignatti
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use,
8 * copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following
13 * The above copyright notice and this permission notice shall be
14 * included in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
27 #ifdef HAVE_XORG_CONFIG_H
28 #include <xorg-config.h>
33 #include "xf86_OSproc.h"
35 #include "colormapst.h"
36 #include "scrnintstr.h"
37 #include "screenint.h"
39 #include "pixmapstr.h"
41 #include "windowstr.h"
44 #include "mipointer.h"
45 #include "mipointrst.h"
46 #include "picturestr.h"
48 #define WRAP_SCREEN(x,y) {pScreenPriv->x = pScreen->x; pScreen->x = y;}
50 #define UNWRAP_SCREEN(x) pScreen->x = pScreenPriv->x
52 #define SCREEN_PROLOG(x) pScreen->x = ((VGAarbiterScreenPtr) \
53 dixLookupPrivate(&(pScreen)->devPrivates, VGAarbiterScreenKey))->x
55 #define SCREEN_EPILOG(x,y) pScreen->x = y;
57 #define WRAP_PICT(x,y) if (ps) {pScreenPriv->x = ps->x;\
60 #define UNWRAP_PICT(x) if (ps) {ps->x = pScreenPriv->x;}
62 #define PICTURE_PROLOGUE(field) ps->field = \
63 ((VGAarbiterScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, \
64 VGAarbiterScreenKey))->field
66 #define PICTURE_EPILOGUE(field, wrap) ps->field = wrap
68 #define WRAP_SCREEN_INFO(x,y) do {pScreenPriv->x = pScrn->x; pScrn->x = y;} while(0)
70 #define UNWRAP_SCREEN_INFO(x) pScrn->x = pScreenPriv->x
72 #define SPRITE_PROLOG miPointerScreenPtr PointPriv = \
73 (miPointerScreenPtr)dixLookupPrivate(&pScreen->devPrivates, \
74 miPointerScreenKey); VGAarbiterScreenPtr pScreenPriv = \
75 ((VGAarbiterScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, \
76 VGAarbiterScreenKey)); PointPriv->spriteFuncs = pScreenPriv->miSprite;
78 #define SPRITE_EPILOG pScreenPriv->miSprite = PointPriv->spriteFuncs;\
79 PointPriv->spriteFuncs = &VGAarbiterSpriteFuncs;
81 #define WRAP_SPRITE do { pScreenPriv->miSprite = PointPriv->spriteFuncs;\
82 PointPriv->spriteFuncs = &VGAarbiterSpriteFuncs; \
85 #define UNWRAP_SPRITE PointPriv->spriteFuncs = pScreenPriv->miSprite
87 #define GC_WRAP(x) pGCPriv->wrapOps = (x)->ops;\
88 pGCPriv->wrapFuncs = (x)->funcs; (x)->ops = &VGAarbiterGCOps;\
89 (x)->funcs = &VGAarbiterGCFuncs;
91 #define GC_UNWRAP(x) VGAarbiterGCPtr pGCPriv = \
92 (VGAarbiterGCPtr)dixLookupPrivate(&(x)->devPrivates, VGAarbiterGCKey);\
93 (x)->ops = pGCPriv->wrapOps; (x)->funcs = pGCPriv->wrapFuncs;
96 VGAGet(ScreenPtr pScreen
)
98 pci_device_vgaarb_set_target(xf86ScreenToScrn(pScreen
)->vgaDev
);
99 pci_device_vgaarb_lock();
105 pci_device_vgaarb_unlock();
108 typedef struct _VGAarbiterScreen
{
109 CreateGCProcPtr CreateGC
;
110 CloseScreenProcPtr CloseScreen
;
111 ScreenBlockHandlerProcPtr BlockHandler
;
112 ScreenWakeupHandlerProcPtr WakeupHandler
;
113 GetImageProcPtr GetImage
;
114 GetSpansProcPtr GetSpans
;
115 SourceValidateProcPtr SourceValidate
;
116 CopyWindowProcPtr CopyWindow
;
117 ClearToBackgroundProcPtr ClearToBackground
;
118 CreatePixmapProcPtr CreatePixmap
;
119 SaveScreenProcPtr SaveScreen
;
121 StoreColorsProcPtr StoreColors
;
123 DisplayCursorProcPtr DisplayCursor
;
124 RealizeCursorProcPtr RealizeCursor
;
125 UnrealizeCursorProcPtr UnrealizeCursor
;
126 RecolorCursorProcPtr RecolorCursor
;
127 SetCursorPositionProcPtr SetCursorPosition
;
128 void (*AdjustFrame
) (ScrnInfoPtr
, int, int);
129 Bool (*SwitchMode
) (ScrnInfoPtr
, DisplayModePtr
);
130 Bool (*EnterVT
) (ScrnInfoPtr
);
131 void (*LeaveVT
) (ScrnInfoPtr
);
132 void (*FreeScreen
) (ScrnInfoPtr
);
133 miPointerSpriteFuncPtr miSprite
;
134 CompositeProcPtr Composite
;
135 GlyphsProcPtr Glyphs
;
136 CompositeRectsProcPtr CompositeRects
;
137 } VGAarbiterScreenRec
, *VGAarbiterScreenPtr
;
139 typedef struct _VGAarbiterGC
{
142 } VGAarbiterGCRec
, *VGAarbiterGCPtr
;
145 static void VGAarbiterBlockHandler(ScreenPtr pScreen
, pointer pTimeout
,
147 static void VGAarbiterWakeupHandler(ScreenPtr pScreen
,
148 unsigned long result
, pointer pReadmask
);
149 static Bool
VGAarbiterCloseScreen(ScreenPtr pScreen
);
150 static void VGAarbiterGetImage(DrawablePtr pDrawable
, int sx
, int sy
, int w
,
151 int h
, unsigned int format
,
152 unsigned long planemask
, char *pdstLine
);
153 static void VGAarbiterGetSpans(DrawablePtr pDrawable
, int wMax
, DDXPointPtr ppt
,
154 int *pwidth
, int nspans
, char *pdstStart
);
155 static void VGAarbiterSourceValidate(DrawablePtr pDrawable
, int x
, int y
,
156 int width
, int height
,
157 unsigned int subWindowMode
);
158 static void VGAarbiterCopyWindow(WindowPtr pWin
, DDXPointRec ptOldOrg
,
160 static void VGAarbiterClearToBackground(WindowPtr pWin
, int x
, int y
, int w
,
161 int h
, Bool generateExposures
);
162 static PixmapPtr
VGAarbiterCreatePixmap(ScreenPtr pScreen
, int w
, int h
,
163 int depth
, unsigned int usage_hint
);
164 static Bool
VGAarbiterCreateGC(GCPtr pGC
);
165 static Bool
VGAarbiterSaveScreen(ScreenPtr pScreen
, Bool unblank
);
166 static void VGAarbiterStoreColors(ColormapPtr pmap
, int ndef
, xColorItem
168 static void VGAarbiterRecolorCursor(DeviceIntPtr pDev
, ScreenPtr pScreen
,
169 CursorPtr pCurs
, Bool displayed
);
170 static Bool
VGAarbiterRealizeCursor(DeviceIntPtr pDev
, ScreenPtr pScreen
,
172 static Bool
VGAarbiterUnrealizeCursor(DeviceIntPtr pDev
, ScreenPtr pScreen
,
174 static Bool
VGAarbiterDisplayCursor(DeviceIntPtr pDev
, ScreenPtr pScreen
,
176 static Bool
VGAarbiterSetCursorPosition(DeviceIntPtr pDev
, ScreenPtr
177 pScreen
, int x
, int y
,
179 static void VGAarbiterAdjustFrame(ScrnInfoPtr pScrn
, int x
, int y
);
180 static Bool
VGAarbiterSwitchMode(ScrnInfoPtr pScrn
, DisplayModePtr mode
);
181 static Bool
VGAarbiterEnterVT(ScrnInfoPtr pScrn
);
182 static void VGAarbiterLeaveVT(ScrnInfoPtr pScrn
);
183 static void VGAarbiterFreeScreen(ScrnInfoPtr pScrn
);
186 static void VGAarbiterValidateGC(GCPtr pGC
, unsigned long changes
,
188 static void VGAarbiterChangeGC(GCPtr pGC
, unsigned long mask
);
189 static void VGAarbiterCopyGC(GCPtr pGCSrc
, unsigned long mask
, GCPtr pGCDst
);
190 static void VGAarbiterDestroyGC(GCPtr pGC
);
191 static void VGAarbiterChangeClip(GCPtr pGC
, int type
, pointer pvalue
,
193 static void VGAarbiterDestroyClip(GCPtr pGC
);
194 static void VGAarbiterCopyClip(GCPtr pgcDst
, GCPtr pgcSrc
);
197 static void VGAarbiterFillSpans(DrawablePtr pDraw
, GC
* pGC
, int nInit
,
198 DDXPointPtr pptInit
, int *pwidthInit
,
200 static void VGAarbiterSetSpans(DrawablePtr pDraw
, GCPtr pGC
, char *pcharsrc
,
201 register DDXPointPtr ppt
, int *pwidth
,
202 int nspans
, int fSorted
);
203 static void VGAarbiterPutImage(DrawablePtr pDraw
, GCPtr pGC
, int depth
, int x
,
204 int y
, int w
, int h
, int leftPad
, int format
,
206 static RegionPtr
VGAarbiterCopyArea(DrawablePtr pSrc
, DrawablePtr pDst
,
207 GC
* pGC
, int srcx
, int srcy
, int width
,
208 int height
, int dstx
, int dsty
);
209 static RegionPtr
VGAarbiterCopyPlane(DrawablePtr pSrc
, DrawablePtr pDst
,
210 GCPtr pGC
, int srcx
, int srcy
, int width
,
211 int height
, int dstx
, int dsty
,
212 unsigned long bitPlane
);
213 static void VGAarbiterPolyPoint(DrawablePtr pDraw
, GCPtr pGC
, int mode
, int npt
,
215 static void VGAarbiterPolylines(DrawablePtr pDraw
, GCPtr pGC
, int mode
, int npt
,
216 DDXPointPtr pptInit
);
217 static void VGAarbiterPolySegment(DrawablePtr pDraw
, GCPtr pGC
, int nseg
,
219 static void VGAarbiterPolyRectangle(DrawablePtr pDraw
, GCPtr pGC
,
220 int nRectsInit
, xRectangle
*pRectsInit
);
221 static void VGAarbiterPolyArc(DrawablePtr pDraw
, GCPtr pGC
, int narcs
,
223 static void VGAarbiterFillPolygon(DrawablePtr pDraw
, GCPtr pGC
, int shape
,
224 int mode
, int count
, DDXPointPtr ptsIn
);
225 static void VGAarbiterPolyFillRect(DrawablePtr pDraw
, GCPtr pGC
, int nrectFill
,
226 xRectangle
*prectInit
);
227 static void VGAarbiterPolyFillArc(DrawablePtr pDraw
, GCPtr pGC
, int narcs
,
229 static int VGAarbiterPolyText8(DrawablePtr pDraw
, GCPtr pGC
, int x
, int y
,
230 int count
, char *chars
);
231 static int VGAarbiterPolyText16(DrawablePtr pDraw
, GCPtr pGC
, int x
, int y
,
232 int count
, unsigned short *chars
);
233 static void VGAarbiterImageText8(DrawablePtr pDraw
, GCPtr pGC
, int x
, int y
,
234 int count
, char *chars
);
235 static void VGAarbiterImageText16(DrawablePtr pDraw
, GCPtr pGC
, int x
, int y
,
236 int count
, unsigned short *chars
);
237 static void VGAarbiterImageGlyphBlt(DrawablePtr pDraw
, GCPtr pGC
, int xInit
,
238 int yInit
, unsigned int nglyph
,
239 CharInfoPtr
* ppci
, pointer pglyphBase
);
240 static void VGAarbiterPolyGlyphBlt(DrawablePtr pDraw
, GCPtr pGC
, int xInit
,
241 int yInit
, unsigned int nglyph
,
242 CharInfoPtr
* ppci
, pointer pglyphBase
);
243 static void VGAarbiterPushPixels(GCPtr pGC
, PixmapPtr pBitMap
, DrawablePtr
244 pDraw
, int dx
, int dy
, int xOrg
, int yOrg
);
247 static Bool
VGAarbiterSpriteRealizeCursor(DeviceIntPtr pDev
, ScreenPtr
248 pScreen
, CursorPtr pCur
);
249 static Bool
VGAarbiterSpriteUnrealizeCursor(DeviceIntPtr pDev
, ScreenPtr
250 pScreen
, CursorPtr pCur
);
251 static void VGAarbiterSpriteSetCursor(DeviceIntPtr pDev
, ScreenPtr pScreen
,
252 CursorPtr pCur
, int x
, int y
);
253 static void VGAarbiterSpriteMoveCursor(DeviceIntPtr pDev
, ScreenPtr pScreen
,
255 static Bool
VGAarbiterDeviceCursorInitialize(DeviceIntPtr pDev
,
257 static void VGAarbiterDeviceCursorCleanup(DeviceIntPtr pDev
, ScreenPtr pScreen
);
259 static void VGAarbiterComposite(CARD8 op
, PicturePtr pSrc
, PicturePtr pMask
,
260 PicturePtr pDst
, INT16 xSrc
, INT16 ySrc
,
261 INT16 xMask
, INT16 yMask
, INT16 xDst
,
262 INT16 yDst
, CARD16 width
, CARD16 height
);
263 static void VGAarbiterGlyphs(CARD8 op
, PicturePtr pSrc
, PicturePtr pDst
,
264 PictFormatPtr maskFormat
, INT16 xSrc
, INT16 ySrc
,
265 int nlist
, GlyphListPtr list
, GlyphPtr
* glyphs
);
266 static void VGAarbiterCompositeRects(CARD8 op
, PicturePtr pDst
,
267 xRenderColor
* color
, int nRect
,