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