2 * Common internal rootless definitions and code
4 * Greg Parker gparker@cs.stanford.edu
7 /* Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
9 Permission is hereby granted, free of charge, to any person
10 obtaining a copy of this software and associated documentation files
11 (the "Software"), to deal in the Software without restriction,
12 including without limitation the rights to use, copy, modify, merge,
13 publish, distribute, sublicense, and/or sell copies of the Software,
14 and to permit persons to whom the Software is furnished to do so,
15 subject to the following conditions:
17 The above copyright notice and this permission notice shall be
18 included in all copies or substantial portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 NONINFRINGEMENT. IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT
24 HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
27 DEALINGS IN THE SOFTWARE.
29 Except as contained in this notice, the name(s) of the above
30 copyright holders shall not be used in advertising or otherwise to
31 promote the sale, use or other dealings in this Software without
32 prior written authorization. */
34 /* $XFree86: xc/programs/Xserver/hw/darwin/quartz/rootlessCommon.h,v 1.6 2002/07/24 05:58:33 torrey Exp $ */
36 #ifndef _ROOTLESSCOMMON_H
37 #define _ROOTLESSCOMMON_H
41 #include "pixmapstr.h"
42 #include "windowstr.h"
45 #include "picturestr.h"
48 /* Debug output, or not. */
50 #define RL_DEBUG_MSG ErrorF
52 #define RL_DEBUG_MSG(a, ...)
56 #define MIN(x,y) ((x) < (y) ? (x) : (y))
58 #define MAX(x,y) ((x) > (y) ? (x) : (y))
60 /* Global variables */
61 extern int rootlessGCPrivateIndex;
62 extern int rootlessScreenPrivateIndex;
63 extern int rootlessWindowPrivateIndex;
64 extern int rootlessNoDRIDrawing;
66 /* RootlessGCRec: private per-gc data */
68 GCFuncs *originalFuncs;
72 /* RootlessWindowRec: private per-window data */
73 typedef struct RootlessWindowRec {
75 unsigned int width, height;
76 unsigned int borderWidth;
82 /* Valid when locked (i.e. is_drawing is set) */
84 unsigned int rowbytes;
89 unsigned long unrealize_time; /* in seconds */
91 unsigned int is_drawing :1;
92 unsigned int is_update_disabled :1;
93 unsigned int is_reorder_pending :1;
94 unsigned int is_offscreen :1;
95 unsigned int is_obscured :1;
98 /* RootlessScreenRec: per-screen private data */
102 CreateScreenResourcesProcPtr CreateScreenResources;
103 CloseScreenProcPtr CloseScreen;
105 CreateWindowProcPtr CreateWindow;
106 DestroyWindowProcPtr DestroyWindow;
107 RealizeWindowProcPtr RealizeWindow;
108 UnrealizeWindowProcPtr UnrealizeWindow;
109 ReparentWindowProcPtr ReparentWindow;
110 MoveWindowProcPtr MoveWindow;
111 ResizeWindowProcPtr ResizeWindow;
112 RestackWindowProcPtr RestackWindow;
113 ChangeBorderWidthProcPtr ChangeBorderWidth;
114 PositionWindowProcPtr PositionWindow;
115 ChangeWindowAttributesProcPtr ChangeWindowAttributes;
117 CreateGCProcPtr CreateGC;
118 PaintWindowBackgroundProcPtr PaintWindowBackground;
119 PaintWindowBorderProcPtr PaintWindowBorder;
120 CopyWindowProcPtr CopyWindow;
121 GetImageProcPtr GetImage;
122 SourceValidateProcPtr SourceValidate;
124 MarkOverlappedWindowsProcPtr MarkOverlappedWindows;
125 ValidateTreeProcPtr ValidateTree;
128 SetShapeProcPtr SetShape;
132 CompositeProcPtr Composite;
133 GlyphsProcPtr Glyphs;
136 InstallColormapProcPtr InstallColormap;
137 UninstallColormapProcPtr UninstallColormap;
138 StoreColorsProcPtr StoreColors;
141 unsigned int pixmap_data_size;
143 ColormapPtr colormap;
145 void *redisplay_timer;
146 CARD32 last_redisplay;
148 unsigned int redisplay_timer_set :1;
149 unsigned int redisplay_queued :1;
150 unsigned int redisplay_expired :1;
151 unsigned int colormap_changed :1;
155 /* "Definition of the Porting Layer for the X11 Sample Server" says
156 unwrap and rewrap of screen functions is unnecessary, but
157 screen->CreateGC changes after a call to cfbCreateGC. */
159 #define SCREEN_UNWRAP(screen, fn) \
160 screen->fn = SCREENREC(screen)->fn;
162 #define SCREEN_WRAP(screen, fn) \
163 SCREENREC(screen)->fn = screen->fn; \
164 screen->fn = Rootless##fn
166 /* Accessors for screen and window privates */
168 #define SCREENREC(pScreen) \
169 ((RootlessScreenRec*)(pScreen)->devPrivates[rootlessScreenPrivateIndex].ptr)
171 #define WINREC(pWin) \
172 ((RootlessWindowRec *)(pWin)->devPrivates[rootlessWindowPrivateIndex].ptr)
174 /* BoxRec manipulators (Copied from shadowfb) */
176 #define TRIM_BOX(box, pGC) { \
177 BoxPtr extents = &pGC->pCompositeClip->extents;\
178 if(box.x1 < extents->x1) box.x1 = extents->x1; \
179 if(box.x2 > extents->x2) box.x2 = extents->x2; \
180 if(box.y1 < extents->y1) box.y1 = extents->y1; \
181 if(box.y2 > extents->y2) box.y2 = extents->y2; \
184 #define TRANSLATE_BOX(box, pDraw) { \
185 box.x1 += pDraw->x; \
186 box.x2 += pDraw->x; \
187 box.y1 += pDraw->y; \
188 box.y2 += pDraw->y; \
191 #define TRIM_AND_TRANSLATE_BOX(box, pDraw, pGC) { \
192 TRANSLATE_BOX(box, pDraw); \
193 TRIM_BOX(box, pGC); \
196 #define BOX_NOT_EMPTY(box) \
197 (((box.x2 - box.x1) > 0) && ((box.y2 - box.y1) > 0))
199 /* We don't want to clip windows to the edge of the screen. HUGE_ROOT
200 temporarily makes the root window really big. This is needed as a
201 wrapper around any function that calls SetWinSize or SetBorderSize
202 which clip a window against its parents, including the root. */
204 extern RegionRec rootlessHugeRoot;
206 #define HUGE_ROOT(pWin) \
208 WindowPtr w = pWin; \
209 while (w->parent != NULL) \
211 saveRoot = w->winSize; \
212 w->winSize = rootlessHugeRoot; \
215 #define NORMAL_ROOT(pWin) \
217 WindowPtr w = pWin; \
218 while (w->parent != NULL) \
220 w->winSize = saveRoot; \
223 /* Returns TRUE if this window is a top-level window (i.e. child of the root)
224 The root is not a top-level window. */
225 #define IsTopLevel(pWin) \
226 ((pWin) != NULL && (pWin)->parent != NULL && (pWin)->parent->parent == NULL)
228 /* Returns TRUE if this window is a root window */
229 #define IsRoot(pWin) \
230 ((pWin) == WindowTable[(pWin)->drawable.pScreen->myNum])
232 /* Returns the top-level parent of pWindow.
233 The root is the top-level parent of itself, even though the root is
234 not otherwise considered to be a top-level window. */
235 extern WindowPtr TopLevelParent (WindowPtr pWindow);
237 /* Returns TRUE if this window is visible inside a frame (e.g. it is
238 visible and has a top-level or root parent) */
239 extern Bool IsFramedWindow (WindowPtr pWin);
241 /* Adjust base address of pixmap by DX,DY */
242 extern void TranslatePixmapBase (PixmapPtr pPix, int dx, int dy);
244 /* Prepare a window for direct access to its backing buffer. */
245 extern void RootlessStartDrawing (WindowPtr pWindow);
247 /* Mark that no more drawing operations will hit the window until ``start
248 drawing'' is issued again. */
249 extern void RootlessFinishedDrawing (WindowPtr pWindow);
251 /* Finish drawing to a window's backing buffer. */
252 extern void RootlessStopDrawing (WindowPtr pWindow, Bool flush);
254 /* Routines that cause regions to get redrawn.
255 DamageRegion and DamageRect are in global coordinates.
256 DamageBox is in window-local coordinates. */
257 extern void RootlessDamageRegion (WindowPtr pWindow, RegionPtr pRegion);
258 extern void RootlessDamageRect (WindowPtr pWindow, int x, int y, int w, int h);
259 extern void RootlessDamageBox (WindowPtr pWindow, BoxPtr pBox);
260 extern void RootlessRedisplay (WindowPtr pWindow);
261 extern void RootlessRedisplayScreen (ScreenPtr pScreen);
263 extern void RootlessQueueRedisplay (ScreenPtr pScreen);
264 extern Bool RootlessMayRedisplay (ScreenPtr pScreen);
265 extern void RootlessScreenExpose (ScreenPtr pScreen);
267 /* Return the colormap currently installed on the given screen. */
268 extern ColormapPtr RootlessGetColormap (ScreenPtr pScreen);
270 /* Convert colormap to ARGB. */
271 extern Bool RootlessResolveColormap (ScreenPtr pScreen, int first_color,
272 int n_colors, uint32_t *colors);
274 extern void RootlessFlushWindowColormap (WindowPtr pWin);
275 extern void RootlessFlushScreenColormaps (ScreenPtr pScreen);
277 /* Move windows back to their position relative to the screen origin. */
278 extern void RootlessRepositionWindow (WindowPtr pWin);
279 extern void RootlessRepositionWindows (ScreenPtr pScreen);
281 /* Move the window to it's correct place in the physical stacking order */
282 extern void RootlessReorderWindow (WindowPtr pWin);
284 /* Bit mask for alpha channel with a particular number of bits per
285 pixel. Note that we only care for 32bpp data. OS X uses planar alpha
287 #define RootlessAlphaMask(bpp) ((bpp) == 32 ? 0xFF000000 : 0)
290 extern void RootlessComposite(CARD8 op, PicturePtr pSrc,
291 PicturePtr pMask, PicturePtr pDst,
292 INT16 xSrc, INT16 ySrc,
293 INT16 xMask, INT16 yMask,
294 INT16 xDst, INT16 yDst,
295 CARD16 width, CARD16 height);
298 extern void RootlessNativeWindowStateChanged (xp_window_id id,
301 extern void RootlessEnableRoot (ScreenPtr pScreen);
302 extern void RootlessDisableRoot (ScreenPtr pScreen);
303 extern void RootlessSetWindowLevel (WindowPtr pWin, int level);
305 #endif /* _ROOTLESSCOMMON_H */