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