1 | /*
|
---|
2 | * Copyright (c) 2009 Tiago Vignatti
|
---|
3 | *
|
---|
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
|
---|
11 | * conditions:
|
---|
12 | *
|
---|
13 | * The above copyright notice and this permission notice shall be
|
---|
14 | * included in all copies or substantial portions of the Software.
|
---|
15 | *
|
---|
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.
|
---|
24 | *
|
---|
25 | */
|
---|
26 |
|
---|
27 | #ifdef HAVE_XORG_CONFIG_H
|
---|
28 | #include <xorg-config.h>
|
---|
29 | #endif
|
---|
30 |
|
---|
31 | #include "misc.h"
|
---|
32 | #include "xf86.h"
|
---|
33 | #include "xf86_OSproc.h"
|
---|
34 | #include <X11/X.h>
|
---|
35 | #include "colormapst.h"
|
---|
36 | #include "scrnintstr.h"
|
---|
37 | #include "screenint.h"
|
---|
38 | #include "gcstruct.h"
|
---|
39 | #include "pixmapstr.h"
|
---|
40 | #include "pixmap.h"
|
---|
41 | #include "windowstr.h"
|
---|
42 | #include "window.h"
|
---|
43 | #include "xf86str.h"
|
---|
44 | #include "mipointer.h"
|
---|
45 | #include "mipointrst.h"
|
---|
46 | #include "picturestr.h"
|
---|
47 |
|
---|
48 | #define WRAP_SCREEN(x,y) {pScreenPriv->x = pScreen->x; pScreen->x = y;}
|
---|
49 |
|
---|
50 | #define UNWRAP_SCREEN(x) pScreen->x = pScreenPriv->x
|
---|
51 |
|
---|
52 | #define SCREEN_PRIV() ((VGAarbiterScreenPtr) dixLookupPrivate(&(pScreen)->devPrivates, VGAarbiterScreenKey))
|
---|
53 |
|
---|
54 | #define SCREEN_PROLOG(x) (pScreen->x = SCREEN_PRIV()->x)
|
---|
55 |
|
---|
56 | #define SCREEN_EPILOG(x,y) do { \
|
---|
57 | SCREEN_PRIV()->x = pScreen->x; \
|
---|
58 | pScreen->x = y; \
|
---|
59 | } while (0)
|
---|
60 |
|
---|
61 | #define WRAP_PICT(x,y) if (ps) {pScreenPriv->x = ps->x;\
|
---|
62 | ps->x = y;}
|
---|
63 |
|
---|
64 | #define UNWRAP_PICT(x) if (ps) {ps->x = pScreenPriv->x;}
|
---|
65 |
|
---|
66 | #define PICTURE_PROLOGUE(field) ps->field = \
|
---|
67 | ((VGAarbiterScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, \
|
---|
68 | VGAarbiterScreenKey))->field
|
---|
69 |
|
---|
70 | #define PICTURE_EPILOGUE(field, wrap) ps->field = wrap
|
---|
71 |
|
---|
72 | #define WRAP_SCREEN_INFO(x,y) do {pScreenPriv->x = pScrn->x; pScrn->x = y;} while(0)
|
---|
73 |
|
---|
74 | #define UNWRAP_SCREEN_INFO(x) pScrn->x = pScreenPriv->x
|
---|
75 |
|
---|
76 | #define SPRITE_PROLOG miPointerScreenPtr PointPriv = \
|
---|
77 | (miPointerScreenPtr)dixLookupPrivate(&pScreen->devPrivates, \
|
---|
78 | miPointerScreenKey); VGAarbiterScreenPtr pScreenPriv = \
|
---|
79 | ((VGAarbiterScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, \
|
---|
80 | VGAarbiterScreenKey)); PointPriv->spriteFuncs = pScreenPriv->miSprite;
|
---|
81 |
|
---|
82 | #define SPRITE_EPILOG pScreenPriv->miSprite = PointPriv->spriteFuncs;\
|
---|
83 | PointPriv->spriteFuncs = &VGAarbiterSpriteFuncs;
|
---|
84 |
|
---|
85 | #define WRAP_SPRITE do { pScreenPriv->miSprite = PointPriv->spriteFuncs;\
|
---|
86 | PointPriv->spriteFuncs = &VGAarbiterSpriteFuncs; \
|
---|
87 | } while (0)
|
---|
88 |
|
---|
89 | #define UNWRAP_SPRITE PointPriv->spriteFuncs = pScreenPriv->miSprite
|
---|
90 |
|
---|
91 | #define GC_WRAP(x) pGCPriv->wrapOps = (x)->ops;\
|
---|
92 | pGCPriv->wrapFuncs = (x)->funcs; (x)->ops = &VGAarbiterGCOps;\
|
---|
93 | (x)->funcs = &VGAarbiterGCFuncs;
|
---|
94 |
|
---|
95 | #define GC_UNWRAP(x) VGAarbiterGCPtr pGCPriv = \
|
---|
96 | (VGAarbiterGCPtr)dixLookupPrivate(&(x)->devPrivates, VGAarbiterGCKey);\
|
---|
97 | (x)->ops = pGCPriv->wrapOps; (x)->funcs = pGCPriv->wrapFuncs;
|
---|
98 |
|
---|
99 | static inline void
|
---|
100 | VGAGet(ScreenPtr pScreen)
|
---|
101 | {
|
---|
102 | pci_device_vgaarb_set_target(xf86ScreenToScrn(pScreen)->vgaDev);
|
---|
103 | pci_device_vgaarb_lock();
|
---|
104 | }
|
---|
105 |
|
---|
106 | static inline void
|
---|
107 | VGAPut(void)
|
---|
108 | {
|
---|
109 | pci_device_vgaarb_unlock();
|
---|
110 | }
|
---|
111 |
|
---|
112 | typedef struct _VGAarbiterScreen {
|
---|
113 | CreateGCProcPtr CreateGC;
|
---|
114 | CloseScreenProcPtr CloseScreen;
|
---|
115 | ScreenBlockHandlerProcPtr BlockHandler;
|
---|
116 | ScreenWakeupHandlerProcPtr WakeupHandler;
|
---|
117 | GetImageProcPtr GetImage;
|
---|
118 | GetSpansProcPtr GetSpans;
|
---|
119 | SourceValidateProcPtr SourceValidate;
|
---|
120 | CopyWindowProcPtr CopyWindow;
|
---|
121 | ClearToBackgroundProcPtr ClearToBackground;
|
---|
122 | CreatePixmapProcPtr CreatePixmap;
|
---|
123 | SaveScreenProcPtr SaveScreen;
|
---|
124 | /* Colormap */
|
---|
125 | StoreColorsProcPtr StoreColors;
|
---|
126 | /* Cursor */
|
---|
127 | DisplayCursorProcPtr DisplayCursor;
|
---|
128 | RealizeCursorProcPtr RealizeCursor;
|
---|
129 | UnrealizeCursorProcPtr UnrealizeCursor;
|
---|
130 | RecolorCursorProcPtr RecolorCursor;
|
---|
131 | SetCursorPositionProcPtr SetCursorPosition;
|
---|
132 | void (*AdjustFrame) (ScrnInfoPtr, int, int);
|
---|
133 | Bool (*SwitchMode) (ScrnInfoPtr, DisplayModePtr);
|
---|
134 | Bool (*EnterVT) (ScrnInfoPtr);
|
---|
135 | void (*LeaveVT) (ScrnInfoPtr);
|
---|
136 | void (*FreeScreen) (ScrnInfoPtr);
|
---|
137 | miPointerSpriteFuncPtr miSprite;
|
---|
138 | CompositeProcPtr Composite;
|
---|
139 | GlyphsProcPtr Glyphs;
|
---|
140 | CompositeRectsProcPtr CompositeRects;
|
---|
141 | } VGAarbiterScreenRec, *VGAarbiterScreenPtr;
|
---|
142 |
|
---|
143 | typedef struct _VGAarbiterGC {
|
---|
144 | const GCOps *wrapOps;
|
---|
145 | const GCFuncs *wrapFuncs;
|
---|
146 | } VGAarbiterGCRec, *VGAarbiterGCPtr;
|
---|
147 |
|
---|
148 | /* Screen funcs */
|
---|
149 | static void VGAarbiterBlockHandler(ScreenPtr pScreen, void *pTimeout,
|
---|
150 | void *pReadmask);
|
---|
151 | static void VGAarbiterWakeupHandler(ScreenPtr pScreen,
|
---|
152 | unsigned long result, void *pReadmask);
|
---|
153 | static Bool VGAarbiterCloseScreen(ScreenPtr pScreen);
|
---|
154 | static void VGAarbiterGetImage(DrawablePtr pDrawable, int sx, int sy, int w,
|
---|
155 | int h, unsigned int format,
|
---|
156 | unsigned long planemask, char *pdstLine);
|
---|
157 | static void VGAarbiterGetSpans(DrawablePtr pDrawable, int wMax, DDXPointPtr ppt,
|
---|
158 | int *pwidth, int nspans, char *pdstStart);
|
---|
159 | static void VGAarbiterSourceValidate(DrawablePtr pDrawable, int x, int y,
|
---|
160 | int width, int height,
|
---|
161 | unsigned int subWindowMode);
|
---|
162 | static void VGAarbiterCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg,
|
---|
163 | RegionPtr prgnSrc);
|
---|
164 | static void VGAarbiterClearToBackground(WindowPtr pWin, int x, int y, int w,
|
---|
165 | int h, Bool generateExposures);
|
---|
166 | static PixmapPtr VGAarbiterCreatePixmap(ScreenPtr pScreen, int w, int h,
|
---|
167 | int depth, unsigned int usage_hint);
|
---|
168 | static Bool VGAarbiterCreateGC(GCPtr pGC);
|
---|
169 | static Bool VGAarbiterSaveScreen(ScreenPtr pScreen, Bool unblank);
|
---|
170 | static void VGAarbiterStoreColors(ColormapPtr pmap, int ndef, xColorItem
|
---|
171 | * pdefs);
|
---|
172 | static void VGAarbiterRecolorCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
|
---|
173 | CursorPtr pCurs, Bool displayed);
|
---|
174 | static Bool VGAarbiterRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
|
---|
175 | CursorPtr pCursor);
|
---|
176 | static Bool VGAarbiterUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
|
---|
177 | CursorPtr pCursor);
|
---|
178 | static Bool VGAarbiterDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
|
---|
179 | CursorPtr pCursor);
|
---|
180 | static Bool VGAarbiterSetCursorPosition(DeviceIntPtr pDev, ScreenPtr
|
---|
181 | pScreen, int x, int y,
|
---|
182 | Bool generateEvent);
|
---|
183 | static void VGAarbiterAdjustFrame(ScrnInfoPtr pScrn, int x, int y);
|
---|
184 | static Bool VGAarbiterSwitchMode(ScrnInfoPtr pScrn, DisplayModePtr mode);
|
---|
185 | static Bool VGAarbiterEnterVT(ScrnInfoPtr pScrn);
|
---|
186 | static void VGAarbiterLeaveVT(ScrnInfoPtr pScrn);
|
---|
187 | static void VGAarbiterFreeScreen(ScrnInfoPtr pScrn);
|
---|
188 |
|
---|
189 | /* GC funcs */
|
---|
190 | static void VGAarbiterValidateGC(GCPtr pGC, unsigned long changes,
|
---|
191 | DrawablePtr pDraw);
|
---|
192 | static void VGAarbiterChangeGC(GCPtr pGC, unsigned long mask);
|
---|
193 | static void VGAarbiterCopyGC(GCPtr pGCSrc, unsigned long mask, GCPtr pGCDst);
|
---|
194 | static void VGAarbiterDestroyGC(GCPtr pGC);
|
---|
195 | static void VGAarbiterChangeClip(GCPtr pGC, int type, void *pvalue,
|
---|
196 | int nrects);
|
---|
197 | static void VGAarbiterDestroyClip(GCPtr pGC);
|
---|
198 | static void VGAarbiterCopyClip(GCPtr pgcDst, GCPtr pgcSrc);
|
---|
199 |
|
---|
200 | /* GC ops */
|
---|
201 | static void VGAarbiterFillSpans(DrawablePtr pDraw, GC * pGC, int nInit,
|
---|
202 | DDXPointPtr pptInit, int *pwidthInit,
|
---|
203 | int fSorted);
|
---|
204 | static void VGAarbiterSetSpans(DrawablePtr pDraw, GCPtr pGC, char *pcharsrc,
|
---|
205 | register DDXPointPtr ppt, int *pwidth,
|
---|
206 | int nspans, int fSorted);
|
---|
207 | static void VGAarbiterPutImage(DrawablePtr pDraw, GCPtr pGC, int depth, int x,
|
---|
208 | int y, int w, int h, int leftPad, int format,
|
---|
209 | char *pImage);
|
---|
210 | static RegionPtr VGAarbiterCopyArea(DrawablePtr pSrc, DrawablePtr pDst,
|
---|
211 | GC * pGC, int srcx, int srcy, int width,
|
---|
212 | int height, int dstx, int dsty);
|
---|
213 | static RegionPtr VGAarbiterCopyPlane(DrawablePtr pSrc, DrawablePtr pDst,
|
---|
214 | GCPtr pGC, int srcx, int srcy, int width,
|
---|
215 | int height, int dstx, int dsty,
|
---|
216 | unsigned long bitPlane);
|
---|
217 | static void VGAarbiterPolyPoint(DrawablePtr pDraw, GCPtr pGC, int mode, int npt,
|
---|
218 | xPoint * pptInit);
|
---|
219 | static void VGAarbiterPolylines(DrawablePtr pDraw, GCPtr pGC, int mode, int npt,
|
---|
220 | DDXPointPtr pptInit);
|
---|
221 | static void VGAarbiterPolySegment(DrawablePtr pDraw, GCPtr pGC, int nseg,
|
---|
222 | xSegment * pSeg);
|
---|
223 | static void VGAarbiterPolyRectangle(DrawablePtr pDraw, GCPtr pGC,
|
---|
224 | int nRectsInit, xRectangle *pRectsInit);
|
---|
225 | static void VGAarbiterPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs,
|
---|
226 | xArc * parcs);
|
---|
227 | static void VGAarbiterFillPolygon(DrawablePtr pDraw, GCPtr pGC, int shape,
|
---|
228 | int mode, int count, DDXPointPtr ptsIn);
|
---|
229 | static void VGAarbiterPolyFillRect(DrawablePtr pDraw, GCPtr pGC, int nrectFill,
|
---|
230 | xRectangle *prectInit);
|
---|
231 | static void VGAarbiterPolyFillArc(DrawablePtr pDraw, GCPtr pGC, int narcs,
|
---|
232 | xArc * parcs);
|
---|
233 | static int VGAarbiterPolyText8(DrawablePtr pDraw, GCPtr pGC, int x, int y,
|
---|
234 | int count, char *chars);
|
---|
235 | static int VGAarbiterPolyText16(DrawablePtr pDraw, GCPtr pGC, int x, int y,
|
---|
236 | int count, unsigned short *chars);
|
---|
237 | static void VGAarbiterImageText8(DrawablePtr pDraw, GCPtr pGC, int x, int y,
|
---|
238 | int count, char *chars);
|
---|
239 | static void VGAarbiterImageText16(DrawablePtr pDraw, GCPtr pGC, int x, int y,
|
---|
240 | int count, unsigned short *chars);
|
---|
241 | static void VGAarbiterImageGlyphBlt(DrawablePtr pDraw, GCPtr pGC, int xInit,
|
---|
242 | int yInit, unsigned int nglyph,
|
---|
243 | CharInfoPtr * ppci, void *pglyphBase);
|
---|
244 | static void VGAarbiterPolyGlyphBlt(DrawablePtr pDraw, GCPtr pGC, int xInit,
|
---|
245 | int yInit, unsigned int nglyph,
|
---|
246 | CharInfoPtr * ppci, void *pglyphBase);
|
---|
247 | static void VGAarbiterPushPixels(GCPtr pGC, PixmapPtr pBitMap, DrawablePtr
|
---|
248 | pDraw, int dx, int dy, int xOrg, int yOrg);
|
---|
249 |
|
---|
250 | /* miSpriteFuncs */
|
---|
251 | static Bool VGAarbiterSpriteRealizeCursor(DeviceIntPtr pDev, ScreenPtr
|
---|
252 | pScreen, CursorPtr pCur);
|
---|
253 | static Bool VGAarbiterSpriteUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr
|
---|
254 | pScreen, CursorPtr pCur);
|
---|
255 | static void VGAarbiterSpriteSetCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
|
---|
256 | CursorPtr pCur, int x, int y);
|
---|
257 | static void VGAarbiterSpriteMoveCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
|
---|
258 | int x, int y);
|
---|
259 | static Bool VGAarbiterDeviceCursorInitialize(DeviceIntPtr pDev,
|
---|
260 | ScreenPtr pScreen);
|
---|
261 | static void VGAarbiterDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen);
|
---|
262 |
|
---|
263 | static void VGAarbiterComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask,
|
---|
264 | PicturePtr pDst, INT16 xSrc, INT16 ySrc,
|
---|
265 | INT16 xMask, INT16 yMask, INT16 xDst,
|
---|
266 | INT16 yDst, CARD16 width, CARD16 height);
|
---|
267 | static void VGAarbiterGlyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
|
---|
268 | PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
|
---|
269 | int nlist, GlyphListPtr list, GlyphPtr * glyphs);
|
---|
270 | static void VGAarbiterCompositeRects(CARD8 op, PicturePtr pDst,
|
---|
271 | xRenderColor * color, int nRect,
|
---|
272 | xRectangle *rects);
|
---|