rootlessCommon.h revision 4642e01f
1/* 2 * Common internal rootless definitions and code 3 */ 4/* 5 * Copyright (c) 2001 Greg Parker. All Rights Reserved. 6 * Copyright (c) 2002-2004 Torrey T. Lyons. All Rights Reserved. 7 * 8 * Permission is hereby granted, free of charge, to any person obtaining a 9 * copy of this software and associated documentation files (the "Software"), 10 * to deal in the Software without restriction, including without limitation 11 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 12 * and/or sell copies of the Software, and to permit persons to whom the 13 * Software is furnished to do so, subject to the following conditions: 14 * 15 * The above copyright notice and this permission notice shall be included in 16 * all copies or substantial portions of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 21 * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 24 * DEALINGS IN THE SOFTWARE. 25 * 26 * Except as contained in this notice, the name(s) of the above copyright 27 * holders shall not be used in advertising or otherwise to promote the sale, 28 * use or other dealings in this Software without prior written authorization. 29 */ 30 31#ifdef HAVE_DIX_CONFIG_H 32#include <dix-config.h> 33#endif 34 35#include <stdint.h> 36#ifndef _ROOTLESSCOMMON_H 37#define _ROOTLESSCOMMON_H 38 39#include "rootless.h" 40#include "fb.h" 41 42#include "scrnintstr.h" 43 44#ifdef RENDER 45#include "picturestr.h" 46#endif 47 48 49// Debug output, or not. 50#ifdef ROOTLESSDEBUG 51#define RL_DEBUG_MSG ErrorF 52#else 53#define RL_DEBUG_MSG(a, ...) 54#endif 55 56 57// Global variables 58extern DevPrivateKey rootlessGCPrivateKey; 59extern DevPrivateKey rootlessScreenPrivateKey; 60extern DevPrivateKey rootlessWindowPrivateKey; 61extern DevPrivateKey rootlessWindowOldPixmapPrivateKey; 62 63 64// RootlessGCRec: private per-gc data 65typedef struct { 66 GCFuncs *originalFuncs; 67 GCOps *originalOps; 68} RootlessGCRec; 69 70 71// RootlessScreenRec: per-screen private data 72typedef struct _RootlessScreenRec { 73 // Rootless implementation functions 74 RootlessFrameProcsPtr imp; 75 76 // Wrapped screen functions 77 CreateScreenResourcesProcPtr CreateScreenResources; 78 CloseScreenProcPtr CloseScreen; 79 80 CreateWindowProcPtr CreateWindow; 81 DestroyWindowProcPtr DestroyWindow; 82 RealizeWindowProcPtr RealizeWindow; 83 UnrealizeWindowProcPtr UnrealizeWindow; 84 MoveWindowProcPtr MoveWindow; 85 ResizeWindowProcPtr ResizeWindow; 86 RestackWindowProcPtr RestackWindow; 87 ReparentWindowProcPtr ReparentWindow; 88 ChangeBorderWidthProcPtr ChangeBorderWidth; 89 PositionWindowProcPtr PositionWindow; 90 ChangeWindowAttributesProcPtr ChangeWindowAttributes; 91 92 CreateGCProcPtr CreateGC; 93 CopyWindowProcPtr CopyWindow; 94 GetImageProcPtr GetImage; 95 SourceValidateProcPtr SourceValidate; 96 97 MarkOverlappedWindowsProcPtr MarkOverlappedWindows; 98 ValidateTreeProcPtr ValidateTree; 99 100 SetShapeProcPtr SetShape; 101 102#ifdef RENDER 103 CompositeProcPtr Composite; 104 GlyphsProcPtr Glyphs; 105#endif 106 107 InstallColormapProcPtr InstallColormap; 108 UninstallColormapProcPtr UninstallColormap; 109 StoreColorsProcPtr StoreColors; 110 111 void *pixmap_data; 112 unsigned int pixmap_data_size; 113 114 ColormapPtr colormap; 115 116 void *redisplay_timer; 117 unsigned int redisplay_timer_set :1; 118 unsigned int redisplay_queued :1; 119 unsigned int redisplay_expired :1; 120 unsigned int colormap_changed :1; 121} RootlessScreenRec, *RootlessScreenPtr; 122 123 124#undef MIN 125#define MIN(x,y) ((x) < (y) ? (x) : (y)) 126#undef MAX 127#define MAX(x,y) ((x) > (y) ? (x) : (y)) 128 129// "Definition of the Porting Layer for the X11 Sample Server" says 130// unwrap and rewrap of screen functions is unnecessary, but 131// screen->CreateGC changes after a call to cfbCreateGC. 132 133#define SCREEN_UNWRAP(screen, fn) \ 134 screen->fn = SCREENREC(screen)->fn; 135 136#define SCREEN_WRAP(screen, fn) \ 137 SCREENREC(screen)->fn = screen->fn; \ 138 screen->fn = Rootless##fn 139 140 141// Accessors for screen and window privates 142 143#define SCREENREC(pScreen) ((RootlessScreenRec *) \ 144 dixLookupPrivate(&(pScreen)->devPrivates, rootlessScreenPrivateKey)) 145 146#define SETSCREENREC(pScreen, v) \ 147 dixSetPrivate(&(pScreen)->devPrivates, rootlessScreenPrivateKey, v) 148 149#define WINREC(pWin) ((RootlessWindowRec *) \ 150 dixLookupPrivate(&(pWin)->devPrivates, rootlessWindowPrivateKey)) 151 152#define SETWINREC(pWin, v) \ 153 dixSetPrivate(&(pWin)->devPrivates, rootlessWindowPrivateKey, v) 154 155// Call a rootless implementation function. 156// Many rootless implementation functions are allowed to be NULL. 157#define CallFrameProc(pScreen, proc, params) \ 158 if (SCREENREC(pScreen)->frameProcs.proc) { \ 159 RL_DEBUG_MSG("calling frame proc " #proc " "); \ 160 SCREENREC(pScreen)->frameProcs.proc params; \ 161 } 162 163 164// BoxRec manipulators 165// Copied from shadowfb 166 167#define TRIM_BOX(box, pGC) { \ 168 BoxPtr extents = &pGC->pCompositeClip->extents;\ 169 if(box.x1 < extents->x1) box.x1 = extents->x1; \ 170 if(box.x2 > extents->x2) box.x2 = extents->x2; \ 171 if(box.y1 < extents->y1) box.y1 = extents->y1; \ 172 if(box.y2 > extents->y2) box.y2 = extents->y2; \ 173} 174 175#define TRANSLATE_BOX(box, pDraw) { \ 176 box.x1 += pDraw->x; \ 177 box.x2 += pDraw->x; \ 178 box.y1 += pDraw->y; \ 179 box.y2 += pDraw->y; \ 180} 181 182#define TRIM_AND_TRANSLATE_BOX(box, pDraw, pGC) { \ 183 TRANSLATE_BOX(box, pDraw); \ 184 TRIM_BOX(box, pGC); \ 185} 186 187#define BOX_NOT_EMPTY(box) \ 188 (((box.x2 - box.x1) > 0) && ((box.y2 - box.y1) > 0)) 189 190 191// HUGE_ROOT and NORMAL_ROOT 192// We don't want to clip windows to the edge of the screen. 193// HUGE_ROOT temporarily makes the root window really big. 194// This is needed as a wrapper around any function that calls 195// SetWinSize or SetBorderSize which clip a window against its 196// parents, including the root. 197 198extern RegionRec rootlessHugeRoot; 199 200#define HUGE_ROOT(pWin) \ 201 do { \ 202 WindowPtr w = pWin; \ 203 while (w->parent) \ 204 w = w->parent; \ 205 saveRoot = w->winSize; \ 206 w->winSize = rootlessHugeRoot; \ 207 } while (0) 208 209#define NORMAL_ROOT(pWin) \ 210 do { \ 211 WindowPtr w = pWin; \ 212 while (w->parent) \ 213 w = w->parent; \ 214 w->winSize = saveRoot; \ 215 } while (0) 216 217 218// Returns TRUE if this window is a top-level window (i.e. child of the root) 219// The root is not a top-level window. 220#define IsTopLevel(pWin) \ 221 ((pWin) && (pWin)->parent && !(pWin)->parent->parent) 222 223// Returns TRUE if this window is a root window 224#define IsRoot(pWin) \ 225 ((pWin) == WindowTable[(pWin)->drawable.pScreen->myNum]) 226 227 228/* 229 * SetPixmapBaseToScreen 230 * Move the given pixmap's base address to where pixel (0, 0) 231 * would be if the pixmap's actual data started at (x, y). 232 * Can't access the bits before the first word of the drawable's data in 233 * rootless mode, so make sure our base address is always 32-bit aligned. 234 */ 235#define SetPixmapBaseToScreen(pix, _x, _y) { \ 236 PixmapPtr _pPix = (PixmapPtr) (pix); \ 237 _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) - \ 238 ((int)(_x) * _pPix->drawable.bitsPerPixel/8 + \ 239 (int)(_y) * _pPix->devKind); \ 240 if (_pPix->drawable.bitsPerPixel != FB_UNIT) { \ 241 size_t _diff = ((size_t) _pPix->devPrivate.ptr) & \ 242 (FB_UNIT / CHAR_BIT - 1); \ 243 _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) - \ 244 _diff; \ 245 _pPix->drawable.x = _diff / \ 246 (_pPix->drawable.bitsPerPixel / CHAR_BIT); \ 247 } \ 248} 249 250 251// Returns TRUE if this window is visible inside a frame 252// (e.g. it is visible and has a top-level or root parent) 253Bool IsFramedWindow(WindowPtr pWin); 254 255// Routines that cause regions to get redrawn. 256// DamageRegion and DamageRect are in global coordinates. 257// DamageBox is in window-local coordinates. 258void RootlessDamageRegion(WindowPtr pWindow, RegionPtr pRegion); 259void RootlessDamageRect(WindowPtr pWindow, int x, int y, int w, int h); 260void RootlessDamageBox(WindowPtr pWindow, BoxPtr pBox); 261void RootlessRedisplay(WindowPtr pWindow); 262void RootlessRedisplayScreen(ScreenPtr pScreen); 263 264void RootlessQueueRedisplay(ScreenPtr pScreen); 265 266/* Return the colormap currently installed on the given screen. */ 267ColormapPtr RootlessGetColormap (ScreenPtr pScreen); 268 269/* Convert colormap to ARGB. */ 270Bool RootlessResolveColormap (ScreenPtr pScreen, int first_color, 271 int n_colors, uint32_t *colors); 272 273void RootlessFlushWindowColormap (WindowPtr pWin); 274void RootlessFlushScreenColormaps (ScreenPtr pScreen); 275 276// xp_error 277int RootlessColormapCallback(void *data, int first_color, int n_colors, uint32_t *colors); 278 279// Move a window to its proper location on the screen. 280void RootlessRepositionWindow(WindowPtr pWin); 281 282// Move the window to it's correct place in the physical stacking order. 283void RootlessReorderWindow(WindowPtr pWin); 284 285void RootlessScreenExpose (ScreenPtr pScreen); 286void RootlessHideAllWindows (void); 287void RootlessShowAllWindows (void); 288void RootlessUpdateRooted (Bool state); 289 290void RootlessEnableRoot (ScreenPtr pScreen); 291void RootlessDisableRoot (ScreenPtr pScreen); 292 293 294#endif /* _ROOTLESSCOMMON_H */ 295