2 * Common internal rootless definitions and code
5 * Copyright (c) 2001 Greg Parker. All Rights Reserved.
6 * Copyright (c) 2002-2004 Torrey T. Lyons. All Rights Reserved.
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:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
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.
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.
31 #ifdef HAVE_DIX_CONFIG_H
32 #include <dix-config.h>
36 #ifndef _ROOTLESSCOMMON_H
37 #define _ROOTLESSCOMMON_H
43 #include "scrnintstr.h"
45 #include "picturestr.h"
47 // Debug output, or not.
49 #define RL_DEBUG_MSG ErrorF
51 #define RL_DEBUG_MSG(a, ...)
55 extern DevPrivateKeyRec rootlessGCPrivateKeyRec
;
57 #define rootlessGCPrivateKey (&rootlessGCPrivateKeyRec)
59 extern DevPrivateKeyRec rootlessScreenPrivateKeyRec
;
61 #define rootlessScreenPrivateKey (&rootlessScreenPrivateKeyRec)
63 extern DevPrivateKeyRec rootlessWindowPrivateKeyRec
;
65 #define rootlessWindowPrivateKey (&rootlessWindowPrivateKeyRec)
67 extern DevPrivateKeyRec rootlessWindowOldPixmapPrivateKeyRec
;
69 #define rootlessWindowOldPixmapPrivateKey (&rootlessWindowOldPixmapPrivateKeyRec)
71 // RootlessGCRec: private per-gc data
73 GCFuncs
*originalFuncs
;
77 // RootlessScreenRec: per-screen private data
78 typedef struct _RootlessScreenRec
{
79 // Rootless implementation functions
80 RootlessFrameProcsPtr imp
;
82 // Wrapped screen functions
83 CreateScreenResourcesProcPtr CreateScreenResources
;
84 CloseScreenProcPtr CloseScreen
;
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
;
98 CreateGCProcPtr CreateGC
;
99 CopyWindowProcPtr CopyWindow
;
100 GetImageProcPtr GetImage
;
101 SourceValidateProcPtr SourceValidate
;
103 MarkOverlappedWindowsProcPtr MarkOverlappedWindows
;
104 ValidateTreeProcPtr ValidateTree
;
106 SetShapeProcPtr SetShape
;
108 CompositeProcPtr Composite
;
109 GlyphsProcPtr Glyphs
;
111 InstallColormapProcPtr InstallColormap
;
112 UninstallColormapProcPtr UninstallColormap
;
113 StoreColorsProcPtr StoreColors
;
116 unsigned int pixmap_data_size
;
118 ColormapPtr colormap
;
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
;
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.
131 #define SCREEN_UNWRAP(screen, fn) \
132 screen->fn = SCREENREC(screen)->fn;
134 #define SCREEN_WRAP(screen, fn) \
135 SCREENREC(screen)->fn = screen->fn; \
136 screen->fn = Rootless##fn
138 // Accessors for screen and window privates
140 #define SCREENREC(pScreen) ((RootlessScreenRec *) \
141 dixLookupPrivate(&(pScreen)->devPrivates, rootlessScreenPrivateKey))
143 #define SETSCREENREC(pScreen, v) \
144 dixSetPrivate(&(pScreen)->devPrivates, rootlessScreenPrivateKey, v)
146 #define WINREC(pWin) ((RootlessWindowRec *) \
147 dixLookupPrivate(&(pWin)->devPrivates, rootlessWindowPrivateKey))
149 #define SETWINREC(pWin, v) \
150 dixSetPrivate(&(pWin)->devPrivates, rootlessWindowPrivateKey, v)
152 // Call a rootless implementation function.
153 // Many rootless implementation functions are allowed to be NULL.
154 #define CallFrameProc(pScreen, proc, params) \
155 if (SCREENREC(pScreen)->frameProcs.proc) { \
156 RL_DEBUG_MSG("calling frame proc " #proc " "); \
157 SCREENREC(pScreen)->frameProcs.proc params; \
160 // BoxRec manipulators
161 // Copied from shadowfb
163 #define TRIM_BOX(box, pGC) { \
164 BoxPtr extents = &pGC->pCompositeClip->extents;\
165 if(box.x1 < extents->x1) box.x1 = extents->x1; \
166 if(box.x2 > extents->x2) box.x2 = extents->x2; \
167 if(box.y1 < extents->y1) box.y1 = extents->y1; \
168 if(box.y2 > extents->y2) box.y2 = extents->y2; \
171 #define TRANSLATE_BOX(box, pDraw) { \
172 box.x1 += pDraw->x; \
173 box.x2 += pDraw->x; \
174 box.y1 += pDraw->y; \
175 box.y2 += pDraw->y; \
178 #define TRIM_AND_TRANSLATE_BOX(box, pDraw, pGC) { \
179 TRANSLATE_BOX(box, pDraw); \
180 TRIM_BOX(box, pGC); \
183 #define BOX_NOT_EMPTY(box) \
184 (((box.x2 - box.x1) > 0) && ((box.y2 - box.y1) > 0))
186 // HUGE_ROOT and NORMAL_ROOT
187 // We don't want to clip windows to the edge of the screen.
188 // HUGE_ROOT temporarily makes the root window really big.
189 // This is needed as a wrapper around any function that calls
190 // SetWinSize or SetBorderSize which clip a window against its
191 // parents, including the root.
193 extern RegionRec rootlessHugeRoot
;
195 #define HUGE_ROOT(pWin) \
197 WindowPtr w = pWin; \
200 saveRoot = w->winSize; \
201 w->winSize = rootlessHugeRoot; \
204 #define NORMAL_ROOT(pWin) \
206 WindowPtr w = pWin; \
209 w->winSize = saveRoot; \
212 // Returns TRUE if this window is a top-level window (i.e. child of the root)
213 // The root is not a top-level window.
214 #define IsTopLevel(pWin) \
215 ((pWin) && (pWin)->parent && !(pWin)->parent->parent)
217 // Returns TRUE if this window is a root window
218 #define IsRoot(pWin) \
219 ((pWin) == (pWin)->drawable.pScreen->root)
222 * SetPixmapBaseToScreen
223 * Move the given pixmap's base address to where pixel (0, 0)
224 * would be if the pixmap's actual data started at (x, y).
225 * Can't access the bits before the first word of the drawable's data in
226 * rootless mode, so make sure our base address is always 32-bit aligned.
228 #define SetPixmapBaseToScreen(pix, _x, _y) { \
229 PixmapPtr _pPix = (PixmapPtr) (pix); \
230 _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) - \
231 ((int)(_x) * _pPix->drawable.bitsPerPixel/8 + \
232 (int)(_y) * _pPix->devKind); \
233 if (_pPix->drawable.bitsPerPixel != FB_UNIT) { \
234 size_t _diff = ((size_t) _pPix->devPrivate.ptr) & \
235 (FB_UNIT / CHAR_BIT - 1); \
236 _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) - \
238 _pPix->drawable.x = _diff / \
239 (_pPix->drawable.bitsPerPixel / CHAR_BIT); \
243 // Returns TRUE if this window is visible inside a frame
244 // (e.g. it is visible and has a top-level or root parent)
245 Bool
IsFramedWindow(WindowPtr pWin
);
247 // Routines that cause regions to get redrawn.
248 // DamageRegion and DamageRect are in global coordinates.
249 // DamageBox is in window-local coordinates.
250 void RootlessDamageRegion(WindowPtr pWindow
, RegionPtr pRegion
);
251 void RootlessDamageRect(WindowPtr pWindow
, int x
, int y
, int w
, int h
);
252 void RootlessDamageBox(WindowPtr pWindow
, BoxPtr pBox
);
253 void RootlessRedisplay(WindowPtr pWindow
);
254 void RootlessRedisplayScreen(ScreenPtr pScreen
);
256 void RootlessQueueRedisplay(ScreenPtr pScreen
);
258 /* Return the colormap currently installed on the given screen. */
259 ColormapPtr
RootlessGetColormap(ScreenPtr pScreen
);
261 /* Convert colormap to ARGB. */
262 Bool
RootlessResolveColormap(ScreenPtr pScreen
, int first_color
,
263 int n_colors
, uint32_t * colors
);
265 void RootlessFlushWindowColormap(WindowPtr pWin
);
266 void RootlessFlushScreenColormaps(ScreenPtr pScreen
);
268 // Move a window to its proper location on the screen.
269 void RootlessRepositionWindow(WindowPtr pWin
);
271 // Move the window to it's correct place in the physical stacking order.
272 void RootlessReorderWindow(WindowPtr pWin
);
274 void RootlessScreenExpose(ScreenPtr pScreen
);
275 void RootlessHideAllWindows(void);
276 void RootlessShowAllWindows(void);
277 void RootlessUpdateRooted(Bool state
);
279 void RootlessEnableRoot(ScreenPtr pScreen
);
280 void RootlessDisableRoot(ScreenPtr pScreen
);
282 void RootlessSetPixmapOfAncestors(WindowPtr pWin
);
284 #endif /* _ROOTLESSCOMMON_H */