rootlessCommon.h revision 706f2543
132001f49Smrg/*
232001f49Smrg * Common internal rootless definitions and code
37ec3b29aSmrg */
432001f49Smrg/*
532001f49Smrg * Copyright (c) 2001 Greg Parker. All Rights Reserved.
632001f49Smrg * Copyright (c) 2002-2004 Torrey T. Lyons. All Rights Reserved.
732001f49Smrg *
832001f49Smrg * Permission is hereby granted, free of charge, to any person obtaining a
932001f49Smrg * copy of this software and associated documentation files (the "Software"),
1032001f49Smrg * to deal in the Software without restriction, including without limitation
1132001f49Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1232001f49Smrg * and/or sell copies of the Software, and to permit persons to whom the
1332001f49Smrg * Software is furnished to do so, subject to the following conditions:
1432001f49Smrg *
1532001f49Smrg * The above copyright notice and this permission notice shall be included in
1632001f49Smrg * all copies or substantial portions of the Software.
1732001f49Smrg *
1832001f49Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1932001f49Smrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2032001f49Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
2132001f49Smrg * THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
2232001f49Smrg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2332001f49Smrg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2432001f49Smrg * DEALINGS IN THE SOFTWARE.
2532001f49Smrg *
2632001f49Smrg * Except as contained in this notice, the name(s) of the above copyright
2732001f49Smrg * holders shall not be used in advertising or otherwise to promote the sale,
2832001f49Smrg * use or other dealings in this Software without prior written authorization.
2932001f49Smrg */
3032001f49Smrg
3132001f49Smrg#ifdef HAVE_DIX_CONFIG_H
3232001f49Smrg#include <dix-config.h>
3332001f49Smrg#endif
3432001f49Smrg
3532001f49Smrg#include <stdint.h>
3632001f49Smrg#ifndef _ROOTLESSCOMMON_H
3732001f49Smrg#define _ROOTLESSCOMMON_H
3832001f49Smrg
3932001f49Smrg#include "misc.h"
4032001f49Smrg#include "rootless.h"
4132001f49Smrg#include "fb.h"
4232001f49Smrg
4332001f49Smrg#include "scrnintstr.h"
4432001f49Smrg
4532001f49Smrg#include "picturestr.h"
4632001f49Smrg
4732001f49Smrg
4832001f49Smrg// Debug output, or not.
4932001f49Smrg#ifdef ROOTLESSDEBUG
5032001f49Smrg#define RL_DEBUG_MSG ErrorF
5132001f49Smrg#else
5232001f49Smrg#define RL_DEBUG_MSG(a, ...)
5332001f49Smrg#endif
5432001f49Smrg
5532001f49Smrg
5632001f49Smrg// Global variables
5732001f49Smrgextern DevPrivateKeyRec rootlessGCPrivateKeyRec;
5832001f49Smrg#define rootlessGCPrivateKey (&rootlessGCPrivateKeyRec)
5932001f49Smrg
6032001f49Smrgextern DevPrivateKeyRec rootlessScreenPrivateKeyRec;
6132001f49Smrg#define rootlessScreenPrivateKey (&rootlessScreenPrivateKeyRec)
6232001f49Smrg
6332001f49Smrgextern DevPrivateKeyRec rootlessWindowPrivateKeyRec;
6432001f49Smrg#define rootlessWindowPrivateKey (&rootlessWindowPrivateKeyRec)
6532001f49Smrg
6632001f49Smrgextern DevPrivateKeyRec rootlessWindowOldPixmapPrivateKeyRec;
6732001f49Smrg#define rootlessWindowOldPixmapPrivateKey (&rootlessWindowOldPixmapPrivateKeyRec)
6832001f49Smrg
6932001f49Smrg
7032001f49Smrg// RootlessGCRec: private per-gc data
7132001f49Smrgtypedef struct {
7232001f49Smrg    GCFuncs *originalFuncs;
7332001f49Smrg    GCOps *originalOps;
7432001f49Smrg} RootlessGCRec;
7532001f49Smrg
7632001f49Smrg
7732001f49Smrg// RootlessScreenRec: per-screen private data
7832001f49Smrgtypedef struct _RootlessScreenRec {
7932001f49Smrg    // Rootless implementation functions
8032001f49Smrg    RootlessFrameProcsPtr imp;
8132001f49Smrg
8232001f49Smrg    // Wrapped screen functions
8332001f49Smrg    CreateScreenResourcesProcPtr CreateScreenResources;
8432001f49Smrg    CloseScreenProcPtr CloseScreen;
8532001f49Smrg
8632001f49Smrg    CreateWindowProcPtr CreateWindow;
8732001f49Smrg    DestroyWindowProcPtr DestroyWindow;
8832001f49Smrg    RealizeWindowProcPtr RealizeWindow;
8932001f49Smrg    UnrealizeWindowProcPtr UnrealizeWindow;
9032001f49Smrg    MoveWindowProcPtr MoveWindow;
9132001f49Smrg    ResizeWindowProcPtr ResizeWindow;
9232001f49Smrg    RestackWindowProcPtr RestackWindow;
9332001f49Smrg    ReparentWindowProcPtr ReparentWindow;
9432001f49Smrg    ChangeBorderWidthProcPtr ChangeBorderWidth;
9532001f49Smrg    PositionWindowProcPtr PositionWindow;
9632001f49Smrg    ChangeWindowAttributesProcPtr ChangeWindowAttributes;
9732001f49Smrg
9832001f49Smrg    CreateGCProcPtr CreateGC;
9932001f49Smrg    CopyWindowProcPtr CopyWindow;
10032001f49Smrg    GetImageProcPtr GetImage;
10132001f49Smrg    SourceValidateProcPtr SourceValidate;
10232001f49Smrg
10332001f49Smrg    MarkOverlappedWindowsProcPtr MarkOverlappedWindows;
10432001f49Smrg    ValidateTreeProcPtr ValidateTree;
10532001f49Smrg
10632001f49Smrg    SetShapeProcPtr SetShape;
10732001f49Smrg
10832001f49Smrg    CompositeProcPtr Composite;
10932001f49Smrg    GlyphsProcPtr Glyphs;
11032001f49Smrg
11132001f49Smrg    InstallColormapProcPtr InstallColormap;
11232001f49Smrg    UninstallColormapProcPtr UninstallColormap;
11332001f49Smrg    StoreColorsProcPtr StoreColors;
11432001f49Smrg
11532001f49Smrg    void *pixmap_data;
11632001f49Smrg    unsigned int pixmap_data_size;
11732001f49Smrg
11832001f49Smrg    ColormapPtr colormap;
11932001f49Smrg
12032001f49Smrg    void *redisplay_timer;
12132001f49Smrg    unsigned int redisplay_timer_set :1;
12232001f49Smrg    unsigned int redisplay_queued :1;
12332001f49Smrg    unsigned int redisplay_expired :1;
12432001f49Smrg    unsigned int colormap_changed :1;
12532001f49Smrg} RootlessScreenRec, *RootlessScreenPtr;
12632001f49Smrg
12732001f49Smrg// "Definition of the Porting Layer for the X11 Sample Server" says
12832001f49Smrg// unwrap and rewrap of screen functions is unnecessary, but
12932001f49Smrg// screen->CreateGC changes after a call to cfbCreateGC.
13032001f49Smrg
13132001f49Smrg#define SCREEN_UNWRAP(screen, fn) \
13232001f49Smrg    screen->fn = SCREENREC(screen)->fn;
13332001f49Smrg
13432001f49Smrg#define SCREEN_WRAP(screen, fn) \
13532001f49Smrg    SCREENREC(screen)->fn = screen->fn; \
13632001f49Smrg    screen->fn = Rootless##fn
13732001f49Smrg
13832001f49Smrg
13932001f49Smrg// Accessors for screen and window privates
14032001f49Smrg
14132001f49Smrg#define SCREENREC(pScreen) ((RootlessScreenRec *) \
14232001f49Smrg    dixLookupPrivate(&(pScreen)->devPrivates, rootlessScreenPrivateKey))
14332001f49Smrg
14432001f49Smrg#define SETSCREENREC(pScreen, v) \
14532001f49Smrg    dixSetPrivate(&(pScreen)->devPrivates, rootlessScreenPrivateKey, v)
14632001f49Smrg
14732001f49Smrg#define WINREC(pWin) ((RootlessWindowRec *) \
14832001f49Smrg    dixLookupPrivate(&(pWin)->devPrivates, rootlessWindowPrivateKey))
14932001f49Smrg
15032001f49Smrg#define SETWINREC(pWin, v) \
15132001f49Smrg    dixSetPrivate(&(pWin)->devPrivates, rootlessWindowPrivateKey, v)
15232001f49Smrg
15332001f49Smrg// Call a rootless implementation function.
15432001f49Smrg// Many rootless implementation functions are allowed to be NULL.
15532001f49Smrg#define CallFrameProc(pScreen, proc, params)            \
15632001f49Smrg    if (SCREENREC(pScreen)->frameProcs.proc) {          \
15732001f49Smrg        RL_DEBUG_MSG("calling frame proc " #proc " ");  \
15832001f49Smrg        SCREENREC(pScreen)->frameProcs.proc params;     \
15932001f49Smrg    }
16032001f49Smrg
16132001f49Smrg
16232001f49Smrg// BoxRec manipulators
16332001f49Smrg// Copied from shadowfb
16432001f49Smrg
16532001f49Smrg#define TRIM_BOX(box, pGC) { \
16632001f49Smrg    BoxPtr extents = &pGC->pCompositeClip->extents;\
16732001f49Smrg    if(box.x1 < extents->x1) box.x1 = extents->x1; \
16832001f49Smrg    if(box.x2 > extents->x2) box.x2 = extents->x2; \
16932001f49Smrg    if(box.y1 < extents->y1) box.y1 = extents->y1; \
17032001f49Smrg    if(box.y2 > extents->y2) box.y2 = extents->y2; \
17132001f49Smrg}
17232001f49Smrg
17332001f49Smrg#define TRANSLATE_BOX(box, pDraw) { \
17432001f49Smrg    box.x1 += pDraw->x; \
17532001f49Smrg    box.x2 += pDraw->x; \
17632001f49Smrg    box.y1 += pDraw->y; \
17732001f49Smrg    box.y2 += pDraw->y; \
17832001f49Smrg}
17932001f49Smrg
18032001f49Smrg#define TRIM_AND_TRANSLATE_BOX(box, pDraw, pGC) { \
18132001f49Smrg    TRANSLATE_BOX(box, pDraw); \
18232001f49Smrg    TRIM_BOX(box, pGC); \
18332001f49Smrg}
18432001f49Smrg
18532001f49Smrg#define BOX_NOT_EMPTY(box) \
18632001f49Smrg    (((box.x2 - box.x1) > 0) && ((box.y2 - box.y1) > 0))
18732001f49Smrg
18832001f49Smrg
18932001f49Smrg// HUGE_ROOT and NORMAL_ROOT
19032001f49Smrg// We don't want to clip windows to the edge of the screen.
19132001f49Smrg// HUGE_ROOT temporarily makes the root window really big.
19232001f49Smrg// This is needed as a wrapper around any function that calls
19332001f49Smrg// SetWinSize or SetBorderSize which clip a window against its
19432001f49Smrg// parents, including the root.
19532001f49Smrg
19632001f49Smrgextern RegionRec rootlessHugeRoot;
19732001f49Smrg
19832001f49Smrg#define HUGE_ROOT(pWin)                         \
19932001f49Smrg    do {                                        \
20032001f49Smrg        WindowPtr w = pWin;                     \
20132001f49Smrg        while (w->parent)                       \
20232001f49Smrg            w = w->parent;                      \
20332001f49Smrg        saveRoot = w->winSize;                  \
20432001f49Smrg        w->winSize = rootlessHugeRoot;          \
20532001f49Smrg    } while (0)
20632001f49Smrg
20732001f49Smrg#define NORMAL_ROOT(pWin)                       \
20832001f49Smrg    do {                                        \
20932001f49Smrg        WindowPtr w = pWin;                     \
21032001f49Smrg        while (w->parent)                       \
21132001f49Smrg            w = w->parent;                      \
21232001f49Smrg        w->winSize = saveRoot;                  \
21332001f49Smrg    } while (0)
21432001f49Smrg
21532001f49Smrg
21632001f49Smrg// Returns TRUE if this window is a top-level window (i.e. child of the root)
21732001f49Smrg// The root is not a top-level window.
21832001f49Smrg#define IsTopLevel(pWin) \
21932001f49Smrg    ((pWin)  &&  (pWin)->parent  &&  !(pWin)->parent->parent)
22032001f49Smrg
22132001f49Smrg// Returns TRUE if this window is a root window
22232001f49Smrg#define IsRoot(pWin) \
22332001f49Smrg    ((pWin) == (pWin)->drawable.pScreen->root)
22432001f49Smrg
22532001f49Smrg
22632001f49Smrg/*
22732001f49Smrg * SetPixmapBaseToScreen
22832001f49Smrg *  Move the given pixmap's base address to where pixel (0, 0)
22932001f49Smrg *  would be if the pixmap's actual data started at (x, y).
23032001f49Smrg *  Can't access the bits before the first word of the drawable's data in
23132001f49Smrg *  rootless mode, so make sure our base address is always 32-bit aligned.
23232001f49Smrg */
23332001f49Smrg#define SetPixmapBaseToScreen(pix, _x, _y) {                                \
23432001f49Smrg    PixmapPtr   _pPix = (PixmapPtr) (pix);                                  \
23532001f49Smrg    _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) -              \
23632001f49Smrg                            ((int)(_x) * _pPix->drawable.bitsPerPixel/8 +   \
23732001f49Smrg                             (int)(_y) * _pPix->devKind);                   \
23832001f49Smrg    if (_pPix->drawable.bitsPerPixel != FB_UNIT) {                          \
23932001f49Smrg        size_t _diff = ((size_t) _pPix->devPrivate.ptr) &               \
24032001f49Smrg                         (FB_UNIT / CHAR_BIT - 1);                          \
24132001f49Smrg        _pPix->devPrivate.ptr = (char *) (_pPix->devPrivate.ptr) -          \
24232001f49Smrg                                _diff;                                      \
24332001f49Smrg        _pPix->drawable.x = _diff /                                         \
24432001f49Smrg                            (_pPix->drawable.bitsPerPixel / CHAR_BIT);      \
24532001f49Smrg    }                                                                       \
24632001f49Smrg}
24732001f49Smrg
24832001f49Smrg
24932001f49Smrg// Returns TRUE if this window is visible inside a frame
25032001f49Smrg// (e.g. it is visible and has a top-level or root parent)
25132001f49SmrgBool IsFramedWindow(WindowPtr pWin);
25232001f49Smrg
25332001f49Smrg// Routines that cause regions to get redrawn.
25432001f49Smrg// DamageRegion and DamageRect are in global coordinates.
25532001f49Smrg// DamageBox is in window-local coordinates.
25632001f49Smrgvoid RootlessDamageRegion(WindowPtr pWindow, RegionPtr pRegion);
25732001f49Smrgvoid RootlessDamageRect(WindowPtr pWindow, int x, int y, int w, int h);
25832001f49Smrgvoid RootlessDamageBox(WindowPtr pWindow, BoxPtr pBox);
25932001f49Smrgvoid RootlessRedisplay(WindowPtr pWindow);
26032001f49Smrgvoid RootlessRedisplayScreen(ScreenPtr pScreen);
26132001f49Smrg
26232001f49Smrgvoid RootlessQueueRedisplay(ScreenPtr pScreen);
26332001f49Smrg
26432001f49Smrg/* Return the colormap currently installed on the given screen. */
26532001f49SmrgColormapPtr RootlessGetColormap (ScreenPtr pScreen);
26632001f49Smrg
26732001f49Smrg/* Convert colormap to ARGB. */
26832001f49SmrgBool RootlessResolveColormap (ScreenPtr pScreen, int first_color,
26932001f49Smrg			      int n_colors, uint32_t *colors);
27032001f49Smrg
27132001f49Smrgvoid RootlessFlushWindowColormap (WindowPtr pWin);
27232001f49Smrgvoid RootlessFlushScreenColormaps (ScreenPtr pScreen);
27332001f49Smrg
27432001f49Smrg// Move a window to its proper location on the screen.
27532001f49Smrgvoid RootlessRepositionWindow(WindowPtr pWin);
27632001f49Smrg
27732001f49Smrg// Move the window to it's correct place in the physical stacking order.
27832001f49Smrgvoid RootlessReorderWindow(WindowPtr pWin);
27932001f49Smrg
28032001f49Smrgvoid RootlessScreenExpose (ScreenPtr pScreen);
28132001f49Smrgvoid RootlessHideAllWindows (void);
28232001f49Smrgvoid RootlessShowAllWindows (void);
28332001f49Smrgvoid RootlessUpdateRooted (Bool state);
28432001f49Smrg
28532001f49Smrgvoid RootlessEnableRoot (ScreenPtr pScreen);
28632001f49Smrgvoid RootlessDisableRoot (ScreenPtr pScreen);
28732001f49Smrg
28832001f49Smrgvoid RootlessSetPixmapOfAncestors(WindowPtr pWin);
28932001f49Smrg
29032001f49Smrg#endif /* _ROOTLESSCOMMON_H */
29132001f49Smrg