| 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_PROLOG(x) pScreen->x = ((VGAarbiterScreenPtr) \ |
| 53 | dixLookupPrivate(&(pScreen)->devPrivates, VGAarbiterScreenKey))->x |
| 54 | |
| 55 | #define SCREEN_EPILOG(x,y) pScreen->x = y; |
| 56 | |
| 57 | #define WRAP_PICT(x,y) if (ps) {pScreenPriv->x = ps->x;\ |
| 58 | ps->x = y;} |
| 59 | |
| 60 | #define UNWRAP_PICT(x) if (ps) {ps->x = pScreenPriv->x;} |
| 61 | |
| 62 | #define PICTURE_PROLOGUE(field) ps->field = \ |
| 63 | ((VGAarbiterScreenPtr)dixLookupPrivate(&(pScreen)->devPrivates, \ |
| 64 | VGAarbiterScreenKey))->field |
| 65 | |
| 66 | #define PICTURE_EPILOGUE(field, wrap) ps->field = wrap |
| 67 | |
| 68 | #define WRAP_SCREEN_INFO(x,y) do {pScreenPriv->x = pScrn->x; pScrn->x = y;} while(0) |
| 69 | |
| 70 | #define UNWRAP_SCREEN_INFO(x) pScrn->x = pScreenPriv->x |
| 71 | |
| 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; |
| 77 | |
| 78 | #define SPRITE_EPILOG pScreenPriv->miSprite = PointPriv->spriteFuncs;\ |
| 79 | PointPriv->spriteFuncs = &VGAarbiterSpriteFuncs; |
| 80 | |
| 81 | #define WRAP_SPRITE do { pScreenPriv->miSprite = PointPriv->spriteFuncs;\ |
| 82 | PointPriv->spriteFuncs = &VGAarbiterSpriteFuncs; \ |
| 83 | } while (0) |
| 84 | |
| 85 | #define UNWRAP_SPRITE PointPriv->spriteFuncs = pScreenPriv->miSprite |
| 86 | |
| 87 | #define GC_WRAP(x) pGCPriv->wrapOps = (x)->ops;\ |
| 88 | pGCPriv->wrapFuncs = (x)->funcs; (x)->ops = &VGAarbiterGCOps;\ |
| 89 | (x)->funcs = &VGAarbiterGCFuncs; |
| 90 | |
| 91 | #define GC_UNWRAP(x) VGAarbiterGCPtr pGCPriv = \ |
| 92 | (VGAarbiterGCPtr)dixLookupPrivate(&(x)->devPrivates, VGAarbiterGCKey);\ |
| 93 | (x)->ops = pGCPriv->wrapOps; (x)->funcs = pGCPriv->wrapFuncs; |
| 94 | |
| 95 | static inline void |
| 96 | VGAGet(ScreenPtr pScreen) |
| 97 | { |
| 98 | pci_device_vgaarb_set_target(xf86ScreenToScrn(pScreen)->vgaDev); |
| 99 | pci_device_vgaarb_lock(); |
| 100 | } |
| 101 | |
| 102 | static inline void |
| 103 | VGAPut(void) |
| 104 | { |
| 105 | pci_device_vgaarb_unlock(); |
| 106 | } |
| 107 | |
| 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; |
| 120 | /* Colormap */ |
| 121 | StoreColorsProcPtr StoreColors; |
| 122 | /* Cursor */ |
| 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; |
| 138 | |
| 139 | typedef struct _VGAarbiterGC { |
| 140 | GCOps *wrapOps; |
| 141 | GCFuncs *wrapFuncs; |
| 142 | } VGAarbiterGCRec, *VGAarbiterGCPtr; |
| 143 | |
| 144 | /* Screen funcs */ |
| 145 | static void VGAarbiterBlockHandler(ScreenPtr pScreen, pointer pTimeout, |
| 146 | pointer pReadmask); |
| 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, |
| 159 | RegionPtr prgnSrc); |
| 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 |
| 167 | * pdefs); |
| 168 | static void VGAarbiterRecolorCursor(DeviceIntPtr pDev, ScreenPtr pScreen, |
| 169 | CursorPtr pCurs, Bool displayed); |
| 170 | static Bool VGAarbiterRealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, |
| 171 | CursorPtr pCursor); |
| 172 | static Bool VGAarbiterUnrealizeCursor(DeviceIntPtr pDev, ScreenPtr pScreen, |
| 173 | CursorPtr pCursor); |
| 174 | static Bool VGAarbiterDisplayCursor(DeviceIntPtr pDev, ScreenPtr pScreen, |
| 175 | CursorPtr pCursor); |
| 176 | static Bool VGAarbiterSetCursorPosition(DeviceIntPtr pDev, ScreenPtr |
| 177 | pScreen, int x, int y, |
| 178 | Bool generateEvent); |
| 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); |
| 184 | |
| 185 | /* GC funcs */ |
| 186 | static void VGAarbiterValidateGC(GCPtr pGC, unsigned long changes, |
| 187 | DrawablePtr pDraw); |
| 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, |
| 192 | int nrects); |
| 193 | static void VGAarbiterDestroyClip(GCPtr pGC); |
| 194 | static void VGAarbiterCopyClip(GCPtr pgcDst, GCPtr pgcSrc); |
| 195 | |
| 196 | /* GC ops */ |
| 197 | static void VGAarbiterFillSpans(DrawablePtr pDraw, GC * pGC, int nInit, |
| 198 | DDXPointPtr pptInit, int *pwidthInit, |
| 199 | int fSorted); |
| 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, |
| 205 | char *pImage); |
| 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, |
| 214 | xPoint * pptInit); |
| 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, |
| 218 | xSegment * pSeg); |
| 219 | static void VGAarbiterPolyRectangle(DrawablePtr pDraw, GCPtr pGC, |
| 220 | int nRectsInit, xRectangle *pRectsInit); |
| 221 | static void VGAarbiterPolyArc(DrawablePtr pDraw, GCPtr pGC, int narcs, |
| 222 | xArc * parcs); |
| 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, |
| 228 | xArc * parcs); |
| 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); |
| 245 | |
| 246 | /* miSpriteFuncs */ |
| 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, |
| 254 | int x, int y); |
| 255 | static Bool VGAarbiterDeviceCursorInitialize(DeviceIntPtr pDev, |
| 256 | ScreenPtr pScreen); |
| 257 | static void VGAarbiterDeviceCursorCleanup(DeviceIntPtr pDev, ScreenPtr pScreen); |
| 258 | |
| 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, |
| 268 | xRectangle *rects); |