aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/programs/Xserver/hw/nxagent/Drawable.h
blob: 1101f989f46183cc8d6be7dc87ce0de62b710c3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
/**************************************************************************/
/*                                                                        */
/* Copyright (c) 2001, 2011 NoMachine (http://www.nomachine.com)          */
/* Copyright (c) 2008-2014 Oleksandr Shneyder <o.shneyder@phoca-gmbh.de>  */
/* Copyright (c) 2011-2016 Mike Gabriel <mike.gabriel@das-netzwerkteam.de>*/
/* Copyright (c) 2014-2016 Mihai Moldovan <ionic@ionic.de>                */
/* Copyright (c) 2014-2016 Ulrich Sibiller <uli42@gmx.de>                 */
/* Copyright (c) 2015-2016 Qindel Group (http://www.qindel.com)           */
/*                                                                        */
/* NXAGENT, NX protocol compression and NX extensions to this software    */
/* are copyright of the aforementioned persons and companies.             */
/*                                                                        */
/* Redistribution and use of the present software is allowed according    */
/* to terms specified in the file LICENSE which comes in the source       */
/* distribution.                                                          */
/*                                                                        */
/* All rights reserved.                                                   */
/*                                                                        */
/* NOTE: This software has received contributions from various other      */
/* contributors, only the core maintainers and supporters are listed as   */
/* copyright holders. Please contact us, if you feel you should be listed */
/* as copyright holder, as well.                                          */
/*                                                                        */
/**************************************************************************/

#ifndef __Drawable_H__
#define __Drawable_H__

#include "resource.h"
#include "Windows.h"
#include "Pixmaps.h"

/*
 * Structures and macros used to manage the Lazy encoding.
 */

typedef struct
{
  DrawablePtr pDrawable;
  int         drawableType;
  int         abort;
  int         windowBitmaps;
  int         pixmapBitmaps;
  int         backgroundBitmaps;

} _nxagentSynchronizationRec;

extern _nxagentSynchronizationRec nxagentSynchronization;

enum DrawableStatus
{
  Synchronized,
  NotSynchronized
};

enum SynchronizationPredicate
{
  Needed,
  NotNeeded,
  Delayed
};

/*
 * Shall the synchronization wait for the
 * drawable wakening?
 */

#define DONT_WAIT 0
#define DO_WAIT   1

/*
 * How the synchronization loop can be
 * interrupted? A 0 mask means that the
 * loop can't be stopped.
 */

#define EVENT_BREAK       (1 << 0)
#define CONGESTION_BREAK  (1 << 1)
#define BLOCKING_BREAK    (1 << 2)

#define NEVER_BREAK  0
#define ALWAYS_BREAK (EVENT_BREAK      | \
                      CONGESTION_BREAK | \
                      BLOCKING_BREAK)

/*
 * Minimum value of usage counter which
 * a pixmap should have to be synchronized.
 */

#define MINIMUM_PIXMAP_USAGE_COUNTER 2

/*
 * This is the macro used to get the external XID
 * from a generic pointer to a drawable.
 */

#define nxagentDrawable(pDrawable) \
  ((pDrawable)->type == DRAWABLE_WINDOW ? \
      nxagentWindow((WindowPtr)pDrawable) : \
          nxagentPixmap((PixmapPtr)pDrawable))

#define nxagentVirtualDrawable(pDrawable) \
  (DrawablePtr)((pDrawable)->type == DRAWABLE_WINDOW ? \
      NULL : nxagentVirtualPixmap((PixmapPtr)pDrawable))

#define nxagentDrawablePicture(pDrawable) \
  ((DrawablePtr)((pDrawable)->type == DRAWABLE_WINDOW ? \
      nxagentWindowPriv((WindowPtr)pDrawable) -> pPicture : \
          nxagentPixmapPriv((PixmapPtr)pDrawable) -> pPicture))

#define nxagentCorruptedRegion(pDrawable) \
    ((pDrawable) -> type == DRAWABLE_PIXMAP ? \
        nxagentPixmapCorruptedRegion((PixmapPtr) pDrawable) : \
            nxagentWindowCorruptedRegion((WindowPtr) pDrawable))

#define nxagentDrawableStatus(pDrawable) \
    (RegionNil(nxagentCorruptedRegion(pDrawable)) ? \
        Synchronized : NotSynchronized)

#define nxagentDrawableContainGlyphs(pDrawable) \
    ((pDrawable) -> type == DRAWABLE_PIXMAP ? \
        nxagentPixmapContainGlyphs((PixmapPtr) (pDrawable)) : \
            nxagentWindowContainGlyphs((WindowPtr) (pDrawable)))

#define nxagentSetDrawableContainGlyphs(pDrawable, value) \
do \
{ \
  if ((pDrawable) -> type == DRAWABLE_PIXMAP) \
  { \
    nxagentPixmapContainGlyphs(nxagentRealPixmap((PixmapPtr) (pDrawable))) = (value); \
  } \
  else \
  { \
    nxagentWindowContainGlyphs((WindowPtr) (pDrawable)) = (value); \
  } \
} while (0)

#define nxagentDrawableBitmap(pDrawable) \
    ((pDrawable) -> type == DRAWABLE_PIXMAP ? \
        nxagentPixmapPriv(nxagentRealPixmap((PixmapPtr) (pDrawable))) -> synchronizationBitmap : \
            nxagentWindowPriv((WindowPtr) (pDrawable)) -> synchronizationBitmap)

#define nxagentDrawableTimestamp(pDrawable) \
    ((pDrawable) -> type == DRAWABLE_PIXMAP ? \
        nxagentPixmapTimestamp((PixmapPtr) pDrawable) : \
            nxagentWindowTimestamp((WindowPtr) pDrawable))

#define nxagentDrawableType(pDrawable) \
    ((pDrawable) -> type == DRAWABLE_PIXMAP ? "pixmap" : "window")

extern RESTYPE RT_NX_CORR_BACKGROUND;
extern RESTYPE RT_NX_CORR_WINDOW;
extern RESTYPE RT_NX_CORR_PIXMAP;

extern int nxagentCorruptedPixmaps;
extern int nxagentCorruptedWindows;
extern int nxagentCorruptedBackgrounds;

extern int nxagentForceSynchronization;

extern RegionPtr nxagentCreateRegion(DrawablePtr pDrawable, GCPtr pGC, int x, int y,
                                  int width, int height);

#define nxagentFreeRegion(pRegion) RegionDestroy(pRegion);

extern void nxagentMarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion);
extern void nxagentUnmarkCorruptedRegion(DrawablePtr pDrawable, RegionPtr pRegion);
extern void nxagentMoveCorruptedRegion(WindowPtr pWin, unsigned int mask);
extern void nxagentIncreasePixmapUsageCounter(PixmapPtr pPixmap);

extern int  nxagentSynchronizeRegion(DrawablePtr pDrawable, RegionPtr pRegion, unsigned int breakMask, WindowPtr owner);
extern void nxagentSynchronizeBox(DrawablePtr pDrawable, BoxPtr pBox, unsigned int breakMask);
extern int  nxagentSynchronizeDrawable(DrawablePtr pDrawable, int wait, unsigned int breakMask, WindowPtr owner);
extern int  nxagentSynchronizeDrawableData(DrawablePtr pDrawable, unsigned int breakMask, WindowPtr owner);
extern void nxagentSynchronizationLoop(unsigned int mask);

extern int nxagentSynchronizationPredicate(void);

extern BoxPtr nxagentGetOptimizedRegionBoxes(RegionPtr pRegion);

extern void nxagentCleanCorruptedDrawable(DrawablePtr pDrawable);

extern void nxagentUnmarkExposedRegion(WindowPtr pWin, RegionPtr pRegion, RegionPtr pOther);
extern void nxagentSendDeferredBackgroundExposures(void);

extern void nxagentClearRegion(DrawablePtr pDrawable, RegionPtr pRegion);
extern void nxagentFillRemoteRegion(DrawablePtr pDrawable, RegionPtr pRegion);

extern void nxagentAllocateCorruptedResource(DrawablePtr pDrawable, RESTYPE type);
extern void nxagentDestroyCorruptedResource(DrawablePtr pDrawable, RESTYPE type);
extern int nxagentDestroyCorruptedBackgroundResource(void * p, XID id);
extern int nxagentDestroyCorruptedWindowResource(void * p, XID id);
extern int nxagentDestroyCorruptedPixmapResource(void * p, XID id);

extern void nxagentCreateDrawableBitmap(DrawablePtr pDrawable);
extern void nxagentDestroyDrawableBitmap(DrawablePtr pDrawable);

extern void nxagentRegionsOnScreen(void);

#define PRINT_REGION_BOXES(pRegion, strRegion) \
do \
{ \
  int i; \
  int numRects; \
  BoxPtr pBox; \
\
  if (pRegion == NullRegion) \
  { \
    fprintf(stderr, "printRegionBoxes:: Region " strRegion " is null.\n"); \
    break; \
  } \
\
  numRects = RegionNumRects(pRegion); \
  pBox = RegionRects(pRegion); \
\
  fprintf(stderr, "printRegionBoxes:: Region " strRegion " at [%p] has [%d] boxes:\n", \
              (void *) (pRegion), numRects); \
\
  for (i = 0; i < numRects; i++) \
  { \
    fprintf(stderr, "[%d] [%d,%d,%d,%d]\n", \
                i, pBox[i].x1, pBox[i].y1, pBox[i].x2, pBox[i].y2); \
  } \
\
} while (0)

#endif /* __Drawable_H__ */