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>
35 #ifndef _ROOTLESSCOMMON_H
36 #define _ROOTLESSCOMMON_H
42 #include "picturestr.h"
46 // Debug output, or not.
48 #define RL_DEBUG_MSG ErrorF
50 #define RL_DEBUG_MSG(a, ...)
55 extern int rootlessGCPrivateIndex
;
56 extern int rootlessScreenPrivateIndex
;
57 extern int rootlessWindowPrivateIndex
;
60 // RootlessGCRec: private per-gc data
62 GCFuncs
*originalFuncs
;
67 // RootlessScreenRec: per-screen private data
68 typedef struct _RootlessScreenRec
{
69 // Rootless implementation functions
70 RootlessFrameProcsPtr imp
;
72 // Wrapped screen functions
73 CreateScreenResourcesProcPtr CreateScreenResources
;
74 CloseScreenProcPtr CloseScreen
;
76 CreateWindowProcPtr CreateWindow
;
77 DestroyWindowProcPtr DestroyWindow
;
78 RealizeWindowProcPtr RealizeWindow
;
79 UnrealizeWindowProcPtr UnrealizeWindow
;
80 MoveWindowProcPtr MoveWindow
;
81 ResizeWindowProcPtr ResizeWindow
;
82 RestackWindowProcPtr RestackWindow
;
83 ReparentWindowProcPtr ReparentWindow
;
84 ChangeBorderWidthProcPtr ChangeBorderWidth
;
85 PositionWindowProcPtr PositionWindow
;
86 ChangeWindowAttributesProcPtr ChangeWindowAttributes
;
88 CreateGCProcPtr CreateGC
;
89 PaintWindowBackgroundProcPtr PaintWindowBackground
;
90 PaintWindowBorderProcPtr PaintWindowBorder
;
91 CopyWindowProcPtr CopyWindow
;
92 GetImageProcPtr GetImage
;
93 SourceValidateProcPtr SourceValidate
;
95 MarkOverlappedWindowsProcPtr MarkOverlappedWindows
;
96 ValidateTreeProcPtr ValidateTree
;
99 SetShapeProcPtr SetShape
;
103 CompositeProcPtr Composite
;
104 GlyphsProcPtr Glyphs
;
108 unsigned int pixmap_data_size
;
110 void *redisplay_timer
;
111 unsigned int redisplay_timer_set
:1;
112 unsigned int redisplay_queued
:1;
113 unsigned int redisplay_expired
:1;
114 } RootlessScreenRec
, *RootlessScreenPtr
;
118 #define MIN(x,y) ((x) < (y) ? (x) : (y))
120 #define MAX(x,y) ((x) > (y) ? (x) : (y))
122 // "Definition of the Porting Layer for the X11 Sample Server" says
123 // unwrap and rewrap of screen functions is unnecessary, but
124 // screen->CreateGC changes after a call to cfbCreateGC.
126 #define SCREEN_UNWRAP(screen, fn) \
127 screen->fn = SCREENREC(screen)->fn;
129 #define SCREEN_WRAP(screen, fn) \
130 SCREENREC(screen)->fn = screen->fn; \
131 screen->fn = Rootless##fn
134 // Accessors for screen and window privates
136 #define SCREENREC(pScreen) \
137 ((RootlessScreenRec *)(pScreen)->devPrivates[rootlessScreenPrivateIndex].ptr)
139 #define WINREC(pWin) \
140 ((RootlessWindowRec *)(pWin)->devPrivates[rootlessWindowPrivateIndex].ptr)
143 // Call a rootless implementation function.
144 // Many rootless implementation functions are allowed to be NULL.
145 #define CallFrameProc(pScreen, proc, params) \
146 if (SCREENREC(pScreen)->frameProcs.proc) { \
147 RL_DEBUG_MSG("calling frame proc " #proc " "); \
148 SCREENREC(pScreen)->frameProcs.proc params; \
152 // BoxRec manipulators
153 // Copied from shadowfb
155 #define TRIM_BOX(box, pGC) { \
156 BoxPtr extents = &pGC->pCompositeClip->extents;\
157 if(box.x1 < extents->x1) box.x1 = extents->x1; \
158 if(box.x2 > extents->x2) box.x2 = extents->x2; \
159 if(box.y1 < extents->y1) box.y1 = extents->y1; \
160 if(box.y2 > extents->y2) box.y2 = extents->y2; \
163 #define TRANSLATE_BOX(box, pDraw) { \
164 box.x1 += pDraw->x; \
165 box.x2 += pDraw->x; \
166 box.y1 += pDraw->y; \
167 box.y2 += pDraw->y; \
170 #define TRIM_AND_TRANSLATE_BOX(box, pDraw, pGC) { \
171 TRANSLATE_BOX(box, pDraw); \
172 TRIM_BOX(box, pGC); \
175 #define BOX_NOT_EMPTY(box) \
176 (((box.x2 - box.x1) > 0) && ((box.y2 - box.y1) > 0))
179 // HUGE_ROOT and NORMAL_ROOT
180 // We don't want to clip windows to the edge of the screen.
181 // HUGE_ROOT temporarily makes the root window really big.
182 // This is needed as a wrapper around any function that calls
183 // SetWinSize or SetBorderSize which clip a window against its
184 // parents, including the root.
186 extern RegionRec rootlessHugeRoot
;
188 #define HUGE_ROOT(pWin) \
190 WindowPtr w = pWin; \
193 saveRoot = w->winSize; \
194 w->winSize = rootlessHugeRoot; \
197 #define NORMAL_ROOT(pWin) \
199 WindowPtr w = pWin; \
202 w->winSize = saveRoot; \
206 // Returns TRUE if this window is a top-level window (i.e. child of the root)
207 // The root is not a top-level window.
208 #define IsTopLevel(pWin) \
209 ((pWin) && (pWin)->parent && !(pWin)->parent->parent)
211 // Returns TRUE if this window is a root window
212 #define IsRoot(pWin) \
213 ((pWin) == WindowTable[(pWin)->drawable.pScreen->myNum])
217 * SetPixmapBaseToScreen
218 * Move the given pixmap's base address to where pixel (0, 0)
219 * would be if the pixmap's actual data started at (x, y).
220 * Can't access the bits before the first word of the drawable's data in
221 * rootless mode, so make sure our base address is always 32-bit aligned.
223 #define SetPixmapBaseToScreen(pix, _x, _y) { \
224 PixmapPtr _pPix = (PixmapPtr) (pix); \
225 _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) - \
226 ((int)(_x) * _pPix->drawable.bitsPerPixel/8 + \
227 (int)(_y) * _pPix->devKind); \
228 if (_pPix->drawable.bitsPerPixel != FB_UNIT) { \
229 unsigned _diff = ((unsigned) _pPix->devPrivate.ptr) & \
230 (FB_UNIT / CHAR_BIT - 1); \
231 _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) - \
233 _pPix->drawable.x = _diff / \
234 (_pPix->drawable.bitsPerPixel / CHAR_BIT); \
239 // Returns TRUE if this window is visible inside a frame
240 // (e.g. it is visible and has a top-level or root parent)
241 Bool
IsFramedWindow(WindowPtr pWin
);
243 // Routines that cause regions to get redrawn.
244 // DamageRegion and DamageRect are in global coordinates.
245 // DamageBox is in window-local coordinates.
246 void RootlessDamageRegion(WindowPtr pWindow
, RegionPtr pRegion
);
247 void RootlessDamageRect(WindowPtr pWindow
, int x
, int y
, int w
, int h
);
248 void RootlessDamageBox(WindowPtr pWindow
, BoxPtr pBox
);
249 void RootlessRedisplay(WindowPtr pWindow
);
250 void RootlessRedisplayScreen(ScreenPtr pScreen
);
252 void RootlessQueueRedisplay(ScreenPtr pScreen
);
254 // Move a window to its proper location on the screen.
255 void RootlessRepositionWindow(WindowPtr pWin
);
257 // Move the window to it's correct place in the physical stacking order.
258 void RootlessReorderWindow(WindowPtr pWin
);
260 #endif /* _ROOTLESSCOMMON_H */