summaryrefslogtreecommitdiffstats
path: root/xorg/X11R7.6/rdp/rdpdraw.c
blob: e393e88ca878e20e549c75b277926dfd5e609411 (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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
/*
Copyright 2005-2012 Jay Sorg

Permission to use, copy, modify, distribute, and sell this software and its
documentation for any purpose is hereby granted without fee, provided that
the above copyright notice appear in all copies and that both that
copyright notice and this permission notice appear in supporting
documentation.

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Xserver drawing ops and funcs

*/

#include "rdp.h"
#include "gcops.h"
#include "rdpdraw.h"

#include "rdpCopyArea.h"
#include "rdpPolyFillRect.h"
#include "rdpPutImage.h"
#include "rdpPolyRectangle.h"
#include "rdpPolylines.h"
#include "rdpPolySegment.h"
#include "rdpFillSpans.h"
#include "rdpSetSpans.h"
#include "rdpCopyPlane.h"
#include "rdpPolyPoint.h"
#include "rdpPolyArc.h"
#include "rdpFillPolygon.h"
#include "rdpPolyFillArc.h"
#include "rdpPolyText8.h"
#include "rdpPolyText16.h"
#include "rdpImageText8.h"
#include "rdpImageText16.h"
#include "rdpImageGlyphBlt.h"
#include "rdpPolyGlyphBlt.h"
#include "rdpPushPixels.h"

#if 1
#define DEBUG_OUT_FUNCS(arg)
#define DEBUG_OUT_OPS(arg)
#else
#define DEBUG_OUT_FUNCS(arg) ErrorF arg
#define DEBUG_OUT_OPS(arg) ErrorF arg
#endif

#define LOG_LEVEL 1
#define LLOG(_level, _args) \
  do { if (_level < LOG_LEVEL) { ErrorF _args ; } } while (0)
#define LLOGLN(_level, _args) \
  do { if (_level < LOG_LEVEL) { ErrorF _args ; ErrorF("\n"); } } while (0)

extern rdpScreenInfoRec g_rdpScreen; /* from rdpmain.c */
extern DevPrivateKeyRec g_rdpGCIndex; /* from rdpmain.c */
extern DevPrivateKeyRec g_rdpWindowIndex; /* from rdpmain.c */
extern DevPrivateKeyRec g_rdpPixmapIndex; /* from rdpmain.c */
extern int g_Bpp; /* from rdpmain.c */
extern ScreenPtr g_pScreen; /* from rdpmain.c */
extern Bool g_wrapPixmap; /* from rdpmain.c */

ColormapPtr g_rdpInstalledColormap;

GCFuncs g_rdpGCFuncs =
{
  rdpValidateGC, rdpChangeGC, rdpCopyGC, rdpDestroyGC, rdpChangeClip,
  rdpDestroyClip, rdpCopyClip
};

GCOps g_rdpGCOps =
{
  rdpFillSpans, rdpSetSpans, rdpPutImage, rdpCopyArea, rdpCopyPlane,
  rdpPolyPoint, rdpPolylines, rdpPolySegment, rdpPolyRectangle,
  rdpPolyArc, rdpFillPolygon, rdpPolyFillRect, rdpPolyFillArc,
  rdpPolyText8, rdpPolyText16, rdpImageText8, rdpImageText16,
  rdpImageGlyphBlt, rdpPolyGlyphBlt, rdpPushPixels
};

/******************************************************************************/
/* return 0, draw nothing */
/* return 1, draw with no clip */
/* return 2, draw using clip */
int
rdp_get_clip(RegionPtr pRegion, DrawablePtr pDrawable, GCPtr pGC)
{
  WindowPtr pWindow;
  RegionPtr temp;
  BoxRec box;
  int rv;

  rv = 0;
  if (pDrawable->type == DRAWABLE_PIXMAP)
  {
    switch (pGC->clientClipType)
    {
      case CT_NONE:
        rv = 1;
        break;
      case CT_REGION:
        rv = 2;
        RegionCopy(pRegion, pGC->clientClip);
        break;
      default:
        rdpLog("unimp clip type %d\n", pGC->clientClipType);
        break;
    }
    if (rv == 2) /* check if the clip is the entire pixmap */
    {
      box.x1 = 0;
      box.y1 = 0;
      box.x2 = pDrawable->width;
      box.y2 = pDrawable->height;
      if (RegionContainsRect(pRegion, &box) == rgnIN)
      {
        rv = 1;
      }
    }
  }
  else if (pDrawable->type == DRAWABLE_WINDOW)
  {
    pWindow = (WindowPtr)pDrawable;
    if (pWindow->viewable)
    {
      if (pGC->subWindowMode == IncludeInferiors)
      {
        temp = &pWindow->borderClip;
      }
      else
      {
        temp = &pWindow->clipList;
      }
      if (RegionNotEmpty(temp))
      {
        switch (pGC->clientClipType)
        {
          case CT_NONE:
            rv = 2;
            RegionCopy(pRegion, temp);
            break;
          case CT_REGION:
            rv = 2;
            RegionCopy(pRegion, pGC->clientClip);
            RegionTranslate(pRegion,
                            pDrawable->x + pGC->clipOrg.x,
                            pDrawable->y + pGC->clipOrg.y);
            RegionIntersect(pRegion, pRegion, temp);
            break;
          default:
            rdpLog("unimp clip type %d\n", pGC->clientClipType);
            break;
        }
        if (rv == 2) /* check if the clip is the entire screen */
        {
          box.x1 = 0;
          box.y1 = 0;
          box.x2 = g_rdpScreen.width;
          box.y2 = g_rdpScreen.height;
          if (RegionContainsRect(pRegion, &box) == rgnIN)
          {
            rv = 1;
          }
        }
      }
    }
  }
  return rv;
}

/******************************************************************************/
void
GetTextBoundingBox(DrawablePtr pDrawable, FontPtr font, int x, int y,
                   int n, BoxPtr pbox)
{
  int maxAscent;
  int maxDescent;
  int maxCharWidth;

  if (FONTASCENT(font) > FONTMAXBOUNDS(font, ascent))
  {
    maxAscent = FONTASCENT(font);
  }
  else
  {
    maxAscent = FONTMAXBOUNDS(font, ascent);
  }
  if (FONTDESCENT(font) > FONTMAXBOUNDS(font, descent))
  {
    maxDescent = FONTDESCENT(font);
  }
  else
  {
    maxDescent = FONTMAXBOUNDS(font, descent);
  }
  if (FONTMAXBOUNDS(font, rightSideBearing) >
      FONTMAXBOUNDS(font, characterWidth))
  {
    maxCharWidth = FONTMAXBOUNDS(font, rightSideBearing);
  }
  else
  {
    maxCharWidth = FONTMAXBOUNDS(font, characterWidth);
  }
  pbox->x1 = pDrawable->x + x;
  pbox->y1 = pDrawable->y + y - maxAscent;
  pbox->x2 = pbox->x1 + maxCharWidth * n;
  pbox->y2 = pbox->y1 + maxAscent + maxDescent;
  if (FONTMINBOUNDS(font, leftSideBearing) < 0)
  {
    pbox->x1 += FONTMINBOUNDS(font, leftSideBearing);
  }
}

/******************************************************************************/
#define GC_FUNC_PROLOGUE(_pGC) \
{ \
  priv = (rdpGCPtr)(dixGetPrivateAddr(&(_pGC->devPrivates), &g_rdpGCIndex)); \
  (_pGC)->funcs = priv->funcs; \
  if (priv->ops != 0) \
  { \
    (_pGC)->ops = priv->ops; \
  } \
}

/******************************************************************************/
#define GC_FUNC_EPILOGUE(_pGC) \
{ \
  priv->funcs = (_pGC)->funcs; \
  (_pGC)->funcs = &g_rdpGCFuncs; \
  if (priv->ops != 0) \
  { \
    priv->ops = (_pGC)->ops; \
    (_pGC)->ops = &g_rdpGCOps; \
  } \
}

/******************************************************************************/
static void
rdpValidateGC(GCPtr pGC, unsigned long changes, DrawablePtr d)
{
  rdpGCRec* priv;
  int wrap;
  RegionPtr pRegion;

  LLOGLN(10, ("rdpValidateGC:"));
  GC_FUNC_PROLOGUE(pGC);
  pGC->funcs->ValidateGC(pGC, changes, d);
  if (g_wrapPixmap)
  {
    wrap = 1;
  }
  else
  {
    wrap = (d->type == DRAWABLE_WINDOW) && ((WindowPtr)d)->viewable;
    if (wrap)
    {
      if (pGC->subWindowMode == IncludeInferiors)
      {
        pRegion = &(((WindowPtr)d)->borderClip);
      }
      else
      {
        pRegion = &(((WindowPtr)d)->clipList);
      }
      wrap = RegionNotEmpty(pRegion);
    }
  }
  priv->ops = 0;
  if (wrap)
  {
    priv->ops = pGC->ops;
  }
  GC_FUNC_EPILOGUE(pGC);
}

/******************************************************************************/
static void
rdpChangeGC(GCPtr pGC, unsigned long mask)
{
  rdpGCRec* priv;

  DEBUG_OUT_FUNCS(("in rdpChangeGC\n"));
  GC_FUNC_PROLOGUE(pGC);
  pGC->funcs->ChangeGC(pGC, mask);
  GC_FUNC_EPILOGUE(pGC);
}

/******************************************************************************/
static void
rdpCopyGC(GCPtr src, unsigned long mask, GCPtr dst)
{
  rdpGCRec* priv;

  DEBUG_OUT_FUNCS(("in rdpCopyGC\n"));
  GC_FUNC_PROLOGUE(dst);
  dst->funcs->CopyGC(src, mask, dst);
  GC_FUNC_EPILOGUE(dst);
}

/******************************************************************************/
static void
rdpDestroyGC(GCPtr pGC)
{
  rdpGCRec* priv;

  DEBUG_OUT_FUNCS(("in rdpDestroyGC\n"));
  GC_FUNC_PROLOGUE(pGC);
  pGC->funcs->DestroyGC(pGC);
  GC_FUNC_EPILOGUE(pGC);
}

/******************************************************************************/
static void
rdpChangeClip(GCPtr pGC, int type, pointer pValue, int nrects)
{
  rdpGCRec* priv;

  DEBUG_OUT_FUNCS(("in rdpChangeClip\n"));
  GC_FUNC_PROLOGUE(pGC);
  pGC->funcs->ChangeClip(pGC, type, pValue, nrects);
  GC_FUNC_EPILOGUE(pGC);
}

/******************************************************************************/
static void
rdpDestroyClip(GCPtr pGC)
{
  rdpGCRec* priv;

  DEBUG_OUT_FUNCS(("in rdpDestroyClip\n"));
  GC_FUNC_PROLOGUE(pGC);
  pGC->funcs->DestroyClip(pGC);
  GC_FUNC_EPILOGUE(pGC);
}

/******************************************************************************/
static void
rdpCopyClip(GCPtr dst, GCPtr src)
{
  rdpGCRec* priv;

  DEBUG_OUT_FUNCS(("in rdpCopyClip\n"));
  GC_FUNC_PROLOGUE(dst);
  dst->funcs->CopyClip(dst, src);
  GC_FUNC_EPILOGUE(dst);
}

/******************************************************************************/
#define GC_OP_PROLOGUE(_pGC) \
{ \
  priv = (rdpGCPtr)dixGetPrivateAddr(&(pGC->devPrivates), &g_rdpGCIndex); \
  oldFuncs = _pGC->funcs; \
  (_pGC)->funcs = priv->funcs; \
  (_pGC)->ops = priv->ops; \
}

/******************************************************************************/
#define GC_OP_EPILOGUE(_pGC) \
{ \
  priv->ops = (_pGC)->ops; \
  (_pGC)->funcs = oldFuncs; \
  (_pGC)->ops = &g_rdpGCOps; \
}

/******************************************************************************/
Bool
rdpCloseScreen(int i, ScreenPtr pScreen)
{
  DEBUG_OUT_OPS(("in rdpCloseScreen\n"));
  pScreen->CloseScreen = g_rdpScreen.CloseScreen;
  pScreen->CreateGC = g_rdpScreen.CreateGC;
  //pScreen->PaintWindowBackground = g_rdpScreen.PaintWindowBackground;
  //pScreen->PaintWindowBorder = g_rdpScreen.PaintWindowBorder;
  pScreen->CopyWindow = g_rdpScreen.CopyWindow;
  pScreen->ClearToBackground = g_rdpScreen.ClearToBackground;
  pScreen->RestoreAreas = g_rdpScreen.RestoreAreas;
  return 1;
}

/******************************************************************************/
PixmapPtr
rdpCreatePixmap(ScreenPtr pScreen, int width, int height, int depth,
                unsigned usage_hint)
{
  PixmapPtr rv;
  rdpPixmapRec* priv;
  int org_width;

  org_width = width;
  width = (width + 3) & ~3;
  LLOGLN(10, ("rdpCreatePixmap: width %d org_width %d", width, org_width));
  pScreen->CreatePixmap = g_rdpScreen.CreatePixmap;
  rv = pScreen->CreatePixmap(pScreen, width, height, depth, usage_hint);
  priv = GETPIXPRIV(rv);
  priv->status = 1;
  pScreen->CreatePixmap = rdpCreatePixmap;
  pScreen->ModifyPixmapHeader(rv, org_width, 0, 0, 0, 0, 0);
  return rv;
}

/******************************************************************************/
Bool
rdpDestroyPixmap(PixmapPtr pPixmap)
{
  Bool rv;
  ScreenPtr pScreen;
  rdpPixmapRec* priv;

  //ErrorF("rdpDestroyPixmap:\n");
  priv = GETPIXPRIV(pPixmap);
  //ErrorF("  refcnt %d\n", pPixmap->refcnt);
  pScreen = pPixmap->drawable.pScreen;
  pScreen->DestroyPixmap = g_rdpScreen.DestroyPixmap;
  rv = pScreen->DestroyPixmap(pPixmap);
  pScreen->DestroyPixmap = rdpDestroyPixmap;
  return rv;
}

/******************************************************************************/
Bool
rdpCreateWindow(WindowPtr pWindow)
{
  ScreenPtr pScreen;
  rdpWindowRec* priv;
  Bool rv;

  //ErrorF("rdpCreateWindow:\n");
  priv = GETWINPRIV(pWindow);
  //ErrorF("  %p status %d\n", priv, priv->status);
  pScreen = pWindow->drawable.pScreen;
  pScreen->CreateWindow = g_rdpScreen.CreateWindow;
  rv = pScreen->CreateWindow(pWindow);
  pScreen->CreateWindow = rdpCreateWindow;
  return rv;
}

/******************************************************************************/
Bool
rdpDestroyWindow(WindowPtr pWindow)
{
  ScreenPtr pScreen;
  rdpWindowRec* priv;
  Bool rv;

  //ErrorF("rdpDestroyWindow:\n");
  priv = GETWINPRIV(pWindow);
  pScreen = pWindow->drawable.pScreen;
  pScreen->DestroyWindow = g_rdpScreen.DestroyWindow;
  rv = pScreen->DestroyWindow(pWindow);
  pScreen->DestroyWindow = rdpDestroyWindow;
  return rv;
}

/******************************************************************************/
Bool
rdpCreateGC(GCPtr pGC)
{
  rdpGCRec* priv;
  Bool rv;

  DEBUG_OUT_OPS(("in rdpCreateGC\n"));
  priv = GETGCPRIV(pGC);
  g_pScreen->CreateGC = g_rdpScreen.CreateGC;
  rv = g_pScreen->CreateGC(pGC);
  if (rv)
  {
    priv->funcs = pGC->funcs;
    priv->ops = 0;
    pGC->funcs = &g_rdpGCFuncs;
  }
  else
  {
    rdpLog("error in rdpCreateGC, CreateGC failed\n");
  }
  g_pScreen->CreateGC = rdpCreateGC;
  return rv;
}

/******************************************************************************/
void
rdpCopyWindow(WindowPtr pWin, DDXPointRec ptOldOrg, RegionPtr pOldRegion)
{
  RegionRec reg;
  RegionRec clip;
  int dx;
  int dy;
  int i;
  int j;
  int num_clip_rects;
  int num_reg_rects;
  BoxRec box1;
  BoxRec box2;

  DEBUG_OUT_OPS(("in rdpCopyWindow\n"));
  RegionInit(&reg, NullBox, 0);
  RegionCopy(&reg, pOldRegion);
  g_pScreen->CopyWindow = g_rdpScreen.CopyWindow;
  g_pScreen->CopyWindow(pWin, ptOldOrg, pOldRegion);
  RegionInit(&clip, NullBox, 0);
  RegionCopy(&clip, &pWin->borderClip);
  dx = pWin->drawable.x - ptOldOrg.x;
  dy = pWin->drawable.y - ptOldOrg.y;
  rdpup_begin_update();
  num_clip_rects = REGION_NUM_RECTS(&clip);
  num_reg_rects = REGION_NUM_RECTS(&reg);
  /* should maybe sort the rects instead of checking dy < 0 */
  /* If we can depend on the rects going from top to bottom, left
     to right we are ok */
  if (dy < 0 || (dy == 0 && dx < 0))
  {
    for (j = 0; j < num_clip_rects; j++)
    {
      box1 = REGION_RECTS(&clip)[j];
      rdpup_set_clip(box1.x1, box1.y1, box1.x2 - box1.x1, box1.y2 - box1.y1);
      for (i = 0; i < num_reg_rects; i++)
      {
        box2 = REGION_RECTS(&reg)[i];
        rdpup_screen_blt(box2.x1 + dx, box2.y1 + dy, box2.x2 - box2.x1,
                         box2.y2 - box2.y1, box2.x1, box2.y1);
      }
    }
  }
  else
  {
    for (j = num_clip_rects - 1; j >= 0; j--)
    {
      box1 = REGION_RECTS(&clip)[j];
      rdpup_set_clip(box1.x1, box1.y1, box1.x2 - box1.x1, box1.y2 - box1.y1);
      for (i = num_reg_rects - 1; i >= 0; i--)
      {
        box2 = REGION_RECTS(&reg)[i];
        rdpup_screen_blt(box2.x1 + dx, box2.y1 + dy, box2.x2 - box2.x1,
                         box2.y2 - box2.y1, box2.x1, box2.y1);
      }
    }
  }
  rdpup_reset_clip();
  rdpup_end_update();
  RegionUninit(&reg);
  RegionUninit(&clip);
  g_pScreen->CopyWindow = rdpCopyWindow;
}

/******************************************************************************/
void
rdpClearToBackground(WindowPtr pWin, int x, int y, int w, int h,
                     Bool generateExposures)
{
  int j;
  BoxRec box;
  RegionRec reg;

  DEBUG_OUT_OPS(("in rdpClearToBackground\n"));
  g_pScreen->ClearToBackground = g_rdpScreen.ClearToBackground;
  g_pScreen->ClearToBackground(pWin, x, y, w, h, generateExposures);
  if (!generateExposures)
  {
    if (w > 0 && h > 0)
    {
      box.x1 = x;
      box.y1 = y;
      box.x2 = box.x1 + w;
      box.y2 = box.y1 + h;
    }
    else
    {
      box.x1 = pWin->drawable.x;
      box.y1 = pWin->drawable.y;
      box.x2 = box.x1 + pWin->drawable.width;
      box.y2 = box.y1 + pWin->drawable.height;
    }
    RegionInit(&reg, &box, 0);
    RegionIntersect(&reg, &reg, &pWin->clipList);
    rdpup_begin_update();
    for (j = REGION_NUM_RECTS(&reg) - 1; j >= 0; j--)
    {
      box = REGION_RECTS(&reg)[j];
      rdpup_send_area(0, box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
    }
    rdpup_end_update();
    RegionUninit(&reg);
  }
  g_pScreen->ClearToBackground = rdpClearToBackground;
}

/******************************************************************************/
RegionPtr
rdpRestoreAreas(WindowPtr pWin, RegionPtr prgnExposed)
{
  RegionRec reg;
  RegionPtr rv;
  int j;
  BoxRec box;

  DEBUG_OUT_OPS(("in rdpRestoreAreas\n"));
  RegionInit(&reg, NullBox, 0);
  RegionCopy(&reg, prgnExposed);
  g_pScreen->RestoreAreas = g_rdpScreen.RestoreAreas;
  rv = g_pScreen->RestoreAreas(pWin, prgnExposed);
  rdpup_begin_update();
  for (j = REGION_NUM_RECTS(&reg) - 1; j >= 0; j--)
  {
    box = REGION_RECTS(&reg)[j];
    rdpup_send_area(0, box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
  }
  rdpup_end_update();
  RegionUninit(&reg);
  g_pScreen->RestoreAreas = rdpRestoreAreas;
  return rv;
}

/******************************************************************************/
void
rdpInstallColormap(ColormapPtr pmap)
{
  ColormapPtr oldpmap;

  oldpmap = g_rdpInstalledColormap;
  if (pmap != oldpmap)
  {
    if (oldpmap != (ColormapPtr)None)
    {
      WalkTree(pmap->pScreen, TellLostMap, (char*)&oldpmap->mid);
    }
    /* Install pmap */
    g_rdpInstalledColormap = pmap;
    WalkTree(pmap->pScreen, TellGainedMap, (char*)&pmap->mid);
    /*rfbSetClientColourMaps(0, 0);*/
  }
  /*g_rdpScreen.InstallColormap(pmap);*/
}

/******************************************************************************/
void
rdpUninstallColormap(ColormapPtr pmap)
{
  ColormapPtr curpmap;

  curpmap = g_rdpInstalledColormap;
  if (pmap == curpmap)
  {
    if (pmap->mid != pmap->pScreen->defColormap)
    {
      //curpmap = (ColormapPtr)LookupIDByType(pmap->pScreen->defColormap,
      //                                      RT_COLORMAP);
      //pmap->pScreen->InstallColormap(curpmap);
    }
  }
}

/******************************************************************************/
int
rdpListInstalledColormaps(ScreenPtr pScreen, Colormap* pmaps)
{
  *pmaps = g_rdpInstalledColormap->mid;
  return 1;
}

/******************************************************************************/
void
rdpStoreColors(ColormapPtr pmap, int ndef, xColorItem* pdefs)
{
}

/******************************************************************************/
Bool
rdpSaveScreen(ScreenPtr pScreen, int on)
{
  return 1;
}

/******************************************************************************/
/* it looks like all the antialias draws go through here */
void
rdpComposite(CARD8 op, PicturePtr pSrc, PicturePtr pMask, PicturePtr pDst,
             INT16 xSrc, INT16 ySrc, INT16 xMask, INT16 yMask, INT16 xDst,
             INT16 yDst, CARD16 width, CARD16 height)
{
  BoxRec box;
  PictureScreenPtr ps;
  RegionRec reg1;
  RegionRec reg2;
  DrawablePtr p;
  int j;
  int num_clips;

  DEBUG_OUT_OPS(("in rdpComposite\n"));
  ps = GetPictureScreen(g_pScreen);
  ps->Composite = g_rdpScreen.Composite;
  ps->Composite(op, pSrc, pMask, pDst, xSrc, ySrc,
                xMask, yMask, xDst, yDst, width, height);
  p = pDst->pDrawable;
  if (p->type == DRAWABLE_WINDOW)
  {
    if (pDst->clientClipType == CT_REGION)
    {
      box.x1 = p->x + xDst;
      box.y1 = p->y + yDst;
      box.x2 = box.x1 + width;
      box.y2 = box.y1 + height;
      RegionInit(&reg1, &box, 0);
      RegionInit(&reg2, NullBox, 0);
      RegionCopy(&reg2, pDst->clientClip);
      RegionTranslate(&reg2, p->x + pDst->clipOrigin.x,
                        p->y + pDst->clipOrigin.y);
      RegionIntersect(&reg1, &reg1, &reg2);
      num_clips = REGION_NUM_RECTS(&reg1);
      if (num_clips > 0)
      {
        rdpup_begin_update();
        for (j = num_clips - 1; j >= 0; j--)
        {
          box = REGION_RECTS(&reg1)[j];
          rdpup_send_area(0, box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
        }
        rdpup_end_update();
      }
      RegionUninit(&reg1);
      RegionUninit(&reg2);
    }
    else
    {
      box.x1 = p->x + xDst;
      box.y1 = p->y + yDst;
      box.x2 = box.x1 + width;
      box.y2 = box.y1 + height;
      rdpup_begin_update();
      rdpup_send_area(0, box.x1, box.y1, box.x2 - box.x1, box.y2 - box.y1);
      rdpup_end_update();
    }
  }
  ps->Composite = rdpComposite;
}