rootlessCommon.h revision 6747b715
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 "misc.h" 40#include "rootless.h" 41#include "fb.h" 42 43#include "scrnintstr.h" 44 45#include "picturestr.h" 46 47 48// Debug output, or not. 49#ifdef ROOTLESSDEBUG 50#define RL_DEBUG_MSG ErrorF 51#else 52#define RL_DEBUG_MSG(a, ...) 53#endif 54 55 56// Global variables 57extern DevPrivateKeyRec rootlessGCPrivateKeyRec; 58#define rootlessGCPrivateKey (&rootlessGCPrivateKeyRec) 59 60extern DevPrivateKeyRec rootlessScreenPrivateKeyRec; 61#define rootlessScreenPrivateKey (&rootlessScreenPrivateKeyRec) 62 63extern DevPrivateKeyRec rootlessWindowPrivateKeyRec; 64#define rootlessWindowPrivateKey (&rootlessWindowPrivateKeyRec) 65 66extern DevPrivateKeyRec rootlessWindowOldPixmapPrivateKeyRec; 67#define rootlessWindowOldPixmapPrivateKey (&rootlessWindowOldPixmapPrivateKeyRec) 68 69 70// RootlessGCRec: private per-gc data 71typedef struct { 72 GCFuncs *originalFuncs; 73 GCOps *originalOps; 74} RootlessGCRec; 75 76 77// RootlessScreenRec: per-screen private data 78typedef struct _RootlessScreenRec { 79 // Rootless implementation functions 80 RootlessFrameProcsPtr imp; 81 82 // Wrapped screen functions 83 CreateScreenResourcesProcPtr CreateScreenResources; 84 CloseScreenProcPtr CloseScreen; 85 86 CreateWindowProcPtr CreateWindow; 87 DestroyWindowProcPtr DestroyWindow; 88 RealizeWindowProcPtr RealizeWindow; 89 UnrealizeWindowProcPtr UnrealizeWindow; 90 MoveWindowProcPtr MoveWindow; 91 ResizeWindowProcPtr ResizeWindow; 92 RestackWindowProcPtr RestackWindow; 93 ReparentWindowProcPtr ReparentWindow; 94 ChangeBorderWidthProcPtr ChangeBorderWidth; 95 PositionWindowProcPtr PositionWindow; 96 ChangeWindowAttributesProcPtr ChangeWindowAttributes; 97 98 CreateGCProcPtr CreateGC; 99 CopyWindowProcPtr CopyWindow; 100 GetImageProcPtr GetImage; 101 SourceValidateProcPtr SourceValidate; 102 103 MarkOverlappedWindowsProcPtr MarkOverlappedWindows; 104 ValidateTreeProcPtr ValidateTree; 105 106 SetShapeProcPtr SetShape; 107 108 CompositeProcPtr Composite; 109 GlyphsProcPtr Glyphs; 110 111 InstallColormapProcPtr InstallColormap; 112 UninstallColormapProcPtr UninstallColormap; 113 StoreColorsProcPtr StoreColors; 114 115 void *pixmap_data; 116 unsigned int pixmap_data_size; 117 118 ColormapPtr colormap; 119 120 void *redisplay_timer; 121 unsigned int redisplay_timer_set :1; 122 unsigned int redisplay_queued :1; 123 unsigned int redisplay_expired :1; 124 unsigned int colormap_changed :1; 125} RootlessScreenRec, *RootlessScreenPtr; 126 127// "Definition of the Porting Layer for the X11 Sample Server" says 128// unwrap and rewrap of screen functions is unnecessary, but 129// screen->CreateGC changes after a call to cfbCreateGC. 130 131#define SCREEN_UNWRAP(screen, fn) \ 132 screen->fn = SCREENREC(screen)->fn; 133 134#define SCREEN_WRAP(screen, fn) \ 135 SCREENREC(screen)->fn = screen->fn; \ 136 screen->fn = Rootless##fn 137 138 139// Accessors for screen and window privates 140 141#define SCREENREC(pScreen) ((RootlessScreenRec *) \ 142 dixLookupPrivate(&(pScreen)->devPrivates, rootlessScreenPrivateKey)) 143 144#define SETSCREENREC(pScreen, v) \ 145 dixSetPrivate(&(pScreen)->devPrivates, rootlessScreenPrivateKey, v) 146 147#define WINREC(pWin) ((RootlessWindowRec *) \ 148 dixLookupPrivate(&(pWin)->devPrivates, rootlessWindowPrivateKey)) 149 150#define SETWINREC(pWin, v) \ 151 dixSetPrivate(&(pWin)->devPrivates, rootlessWindowPrivateKey, v) 152 153// Call a rootless implementation function. 154// Many rootless implementation functions are allowed to be NULL. 155#define CallFrameProc(pScreen, proc, params) \ 156 if (SCREENREC(pScreen)->frameProcs.proc) { \ 157 RL_DEBUG_MSG("calling frame proc " #proc " "); \ 158 SCREENREC(pScreen)->frameProcs.proc params; \ 159 } 160 161 162// BoxRec manipulators 163// Copied from shadowfb 164 165#define TRIM_BOX(box, pGC) { \ 166 BoxPtr extents = &pGC->pCompositeClip->extents;\ 167 if(box.x1 < extents->x1) box.x1 = extents->x1; \ 168 if(box.x2 > extents->x2) box.x2 = extents->x2; \ 169 if(box.y1 < extents->y1) box.y1 = extents->y1; \ 170 if(box.y2 > extents->y2) box.y2 = extents->y2; \ 171} 172 173#define TRANSLATE_BOX(box, pDraw) { \ 174 box.x1 += pDraw->x; \ 175 box.x2 += pDraw->x; \ 176 box.y1 += pDraw->y; \ 177 box.y2 += pDraw->y; \ 178} 179 180#define TRIM_AND_TRANSLATE_BOX(box, pDraw, pGC) { \ 181 TRANSLATE_BOX(box, pDraw); \ 182 TRIM_BOX(box, pGC); \ 183} 184 185#define BOX_NOT_EMPTY(box) \ 186 (((box.x2 - box.x1) > 0) && ((box.y2 - box.y1) > 0)) 187 188 189// HUGE_ROOT and NORMAL_ROOT 190// We don't want to clip windows to the edge of the screen. 191// HUGE_ROOT temporarily makes the root window really big. 192// This is needed as a wrapper around any function that calls 193// SetWinSize or SetBorderSize which clip a window against its 194// parents, including the root. 195 196extern RegionRec rootlessHugeRoot; 197 198#define HUGE_ROOT(pWin) \ 199 do { \ 200 WindowPtr w = pWin; \ 201 while (w->parent) \ 202 w = w->parent; \ 203 saveRoot = w->winSize; \ 204 w->winSize = rootlessHugeRoot; \ 205 } while (0) 206 207#define NORMAL_ROOT(pWin) \ 208 do { \ 209 WindowPtr w = pWin; \ 210 while (w->parent) \ 211 w = w->parent; \ 212 w->winSize = saveRoot; \ 213 } while (0) 214 215 216// Returns TRUE if this window is a top-level window (i.e. child of the root) 217// The root is not a top-level window. 218#define IsTopLevel(pWin) \ 219 ((pWin) && (pWin)->parent && !(pWin)->parent->parent) 220 221// Returns TRUE if this window is a root window 222#define IsRoot(pWin) \ 223 ((pWin) == (pWin)->drawable.pScreen->root) 224 225 226/* 227 * SetPixmapBaseToScreen 228 * Move the given pixmap's base address to where pixel (0, 0) 229 * would be if the pixmap's actual data started at (x, y). 230 * Can't access the bits before the first word of the drawable's data in 231 * rootless mode, so make sure our base address is always 32-bit aligned. 232 */ 233#define SetPixmapBaseToScreen(pix, _x, _y) { \ 234 PixmapPtr _pPix = (PixmapPtr) (pix); \ 235 _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) - \ 236 ((int)(_x) * _pPix->drawable.bitsPerPixel/8 + \ 237 (int)(_y) * _pPix->devKind); \ 238 if (_pPix->drawable.bitsPerPixel != FB_UNIT) { \ 239 size_t _diff = ((size_t) _pPix->devPrivate.ptr) & \ 240 (FB_UNIT / CHAR_BIT - 1); \ 241 _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) - \ 242 _diff; \ 243 _pPix->drawable.x = _diff / \ 244 (_pPix->drawable.bitsPerPixel / CHAR_BIT); \ 245 } \ 246} 247 248 249// Returns TRUE if this window is visible inside a frame 250// (e.g. it is visible and has a top-level or root parent) 251Bool IsFramedWindow(WindowPtr pWin); 252 253// Routines that cause regions to get redrawn. 254// DamageRegion and DamageRect are in global coordinates. 255// DamageBox is in window-local coordinates. 256void RootlessDamageRegion(WindowPtr pWindow, RegionPtr pRegion); 257void RootlessDamageRect(WindowPtr pWindow, int x, int y, int w, int h); 258void RootlessDamageBox(WindowPtr pWindow, BoxPtr pBox); 259void RootlessRedisplay(WindowPtr pWindow); 260void RootlessRedisplayScreen(ScreenPtr pScreen); 261 262void RootlessQueueRedisplay(ScreenPtr pScreen); 263 264/* Return the colormap currently installed on the given screen. */ 265ColormapPtr RootlessGetColormap (ScreenPtr pScreen); 266 267/* Convert colormap to ARGB. */ 268Bool RootlessResolveColormap (ScreenPtr pScreen, int first_color, 269 int n_colors, uint32_t *colors); 270 271void RootlessFlushWindowColormap (WindowPtr pWin); 272void RootlessFlushScreenColormaps (ScreenPtr pScreen); 273 274// Move a window to its proper location on the screen. 275void RootlessRepositionWindow(WindowPtr pWin); 276 277// Move the window to it's correct place in the physical stacking order. 278void RootlessReorderWindow(WindowPtr pWin); 279 280void RootlessScreenExpose (ScreenPtr pScreen); 281void RootlessHideAllWindows (void); 282void RootlessShowAllWindows (void); 283void RootlessUpdateRooted (Bool state); 284 285void RootlessEnableRoot (ScreenPtr pScreen); 286void RootlessDisableRoot (ScreenPtr pScreen); 287 288void RootlessSetPixmapOfAncestors(WindowPtr pWin); 289 290#endif /* _ROOTLESSCOMMON_H */ 291