aboutsummaryrefslogtreecommitdiffstats
path: root/unix/xserver/hw/vnc/vncDRI3Draw.c
blob: 8aa6625d37403bd15bcafbd42175266ad8ee79a7 (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
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
/* Copyright 2024 Pierre Ossman for Cendio AB
 *
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this software; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
 * USA.
 */

#ifdef HAVE_DIX_CONFIG_H
#include <dix-config.h>
#endif

#include "vncDRI3.h"

#include <fb.h>
#include <gcstruct.h>
#include <pixmapstr.h>

static DevPrivateKeyRec vncDRI3DrawScreenPrivateKey;
static DevPrivateKeyRec vncDRI3GCPrivateKey;

typedef struct vncDRI3DrawScreenPrivateRec {
  CloseScreenProcPtr CloseScreen;

  CreateGCProcPtr CreateGC;
  SourceValidateProcPtr SourceValidate;

  CompositeProcPtr Composite;
  GlyphsProcPtr Glyphs;
  CompositeRectsProcPtr CompositeRects;
  TrapezoidsProcPtr Trapezoids;
  TrianglesProcPtr Triangles;
  TriStripProcPtr TriStrip;
  TriFanProcPtr TriFan;
} vncDRI3DrawScreenPrivateRec, *vncDRI3DrawScreenPrivatePtr;

typedef struct vncDRI3GCPrivateRec {
  const GCFuncs *funcs;
  const GCOps *ops;
} vncDRI3GCPrivateRec, *vncDRI3GCPrivatePtr;

#define wrap(priv, real, mem, func) {\
  priv->mem = real->mem; \
  real->mem = func; \
}

#define unwrap(priv, real, mem) {\
  real->mem = priv->mem; \
}

static inline vncDRI3DrawScreenPrivatePtr vncDRI3DrawScreenPrivate(ScreenPtr screen)
{
  return (vncDRI3DrawScreenPrivatePtr)dixLookupPrivate(&(screen)->devPrivates, &vncDRI3DrawScreenPrivateKey);
}

static inline vncDRI3GCPrivatePtr vncDRI3GCPrivate(GCPtr gc)
{
  return (vncDRI3GCPrivatePtr)dixLookupPrivate(&(gc)->devPrivates, &vncDRI3GCPrivateKey);
}

static GCFuncs vncDRI3GCFuncs;
static GCOps vncDRI3GCOps;

/* GC functions */

static void vncDRI3ValidateGC(GCPtr gc, unsigned long changes,
                              DrawablePtr drawable)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  unwrap(gcPriv, gc, funcs);
  if (gcPriv->ops != NULL)
    unwrap(gcPriv, gc, ops);

  (*gc->funcs->ValidateGC)(gc, changes, drawable);

  if (vncDRI3IsHardwareDrawable(drawable)) {
    wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  } else {
    gcPriv->ops = NULL;
  }
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);
}

static void vncDRI3ChangeGC(GCPtr gc, unsigned long mask)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);
  unwrap(gcPriv, gc, funcs);
  if (gcPriv->ops != NULL)
    unwrap(gcPriv, gc, ops);
  (*gc->funcs->ChangeGC)(gc, mask);
  if (gcPriv->ops != NULL)
    wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);
}

static void vncDRI3CopyGC(GCPtr src, unsigned long mask, GCPtr dst)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(dst);
  unwrap(gcPriv, dst, funcs);
  if (gcPriv->ops != NULL)
    unwrap(gcPriv, dst, ops);
  (*dst->funcs->CopyGC)(src, mask, dst);
  if (gcPriv->ops != NULL)
    wrap(gcPriv, dst, ops, &vncDRI3GCOps);
  wrap(gcPriv, dst, funcs, &vncDRI3GCFuncs);
}

static void vncDRI3DestroyGC(GCPtr gc)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);
  unwrap(gcPriv, gc, funcs);
  if (gcPriv->ops != NULL)
    unwrap(gcPriv, gc, ops);
  (*gc->funcs->DestroyGC)(gc);
  if (gcPriv->ops != NULL)
    wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);
}

static void vncDRI3ChangeClip(GCPtr gc, int type, void *value, int nrects)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);
  unwrap(gcPriv, gc, funcs);
  if (gcPriv->ops != NULL)
    unwrap(gcPriv, gc, ops);
  (*gc->funcs->ChangeClip)(gc, type, value, nrects);
  if (gcPriv->ops != NULL)
    wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);
}

static void vncDRI3DestroyClip(GCPtr gc)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);
  unwrap(gcPriv, gc, funcs);
  if (gcPriv->ops != NULL)
    unwrap(gcPriv, gc, ops);
  (*gc->funcs->DestroyClip)(gc);
  if (gcPriv->ops != NULL)
    wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);
}

static void vncDRI3CopyClip(GCPtr dst, GCPtr src)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(dst);
  unwrap(gcPriv, dst, funcs);
  if (gcPriv->ops != NULL)
    unwrap(gcPriv, dst, ops);
  (*dst->funcs->CopyClip)(dst, src);
  if (gcPriv->ops != NULL)
    wrap(gcPriv, dst, ops, &vncDRI3GCOps);
  wrap(gcPriv, dst, funcs, &vncDRI3GCFuncs);
}

/* GC operations */

static void vncDRI3FillSpans(DrawablePtr drawable, GCPtr gc, int nInit,
                             DDXPointPtr pptInit, int *pwidthInit,
                             int fSorted)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->FillSpans)(drawable, gc, nInit, pptInit, pwidthInit, fSorted);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3SetSpans(DrawablePtr drawable, GCPtr gc, char *psrc,
                            DDXPointPtr ppt, int *pwidth, int nspans,
                            int fSorted)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->SetSpans)(drawable, gc, psrc, ppt, pwidth, nspans, fSorted);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3PutImage(DrawablePtr drawable, GCPtr gc, int depth,
                            int x, int y, int w, int h, int leftPad,
                            int format, char *pBits)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->PutImage)(drawable, gc, depth, x, y, w, h, leftPad, format, pBits);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static RegionPtr vncDRI3CopyArea(DrawablePtr src, DrawablePtr dst,
                                 GCPtr gc, int srcx, int srcy,
                                 int w, int h, int dstx, int dsty)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);
  RegionPtr ret;

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(dst);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  ret = (*gc->ops->CopyArea)(src, dst, gc, srcx, srcy, w, h, dstx, dsty);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(dst);

  return ret;
}

static RegionPtr vncDRI3CopyPlane(DrawablePtr src, DrawablePtr dst,
                                  GCPtr gc, int srcx, int srcy,
                                  int w, int h, int dstx, int dsty,
                                  unsigned long plane)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);
  RegionPtr ret;

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(dst);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  ret = (*gc->ops->CopyPlane)(src, dst, gc, srcx, srcy, w, h, dstx, dsty, plane);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(dst);

  return ret;
}

static void vncDRI3PolyPoint(DrawablePtr drawable, GCPtr gc, int mode,
                             int npt, xPoint *pts)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->PolyPoint)(drawable, gc, mode, npt, pts);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3Polylines(DrawablePtr drawable, GCPtr gc, int mode,
                             int npt, DDXPointPtr ppts)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->Polylines)(drawable, gc, mode, npt, ppts);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3PolySegment(DrawablePtr drawable, GCPtr gc, int nseg,
                               xSegment *segs)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->PolySegment)(drawable, gc, nseg, segs);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3PolyRectangle(DrawablePtr drawable, GCPtr gc,
                                 int nrects, xRectangle *rects)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->PolyRectangle)(drawable, gc, nrects, rects);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3PolyArc(DrawablePtr drawable, GCPtr gc, int narcs,
                           xArc *arcs)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->PolyArc)(drawable, gc, narcs, arcs);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3FillPolygon(DrawablePtr drawable, GCPtr gc,
                               int shape, int mode, int count,
                               DDXPointPtr pts)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->FillPolygon)(drawable, gc, shape, mode, count, pts);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3PolyFillRect(DrawablePtr drawable, GCPtr gc,
                                int nrects, xRectangle *rects)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->PolyFillRect)(drawable, gc, nrects, rects);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3PolyFillArc(DrawablePtr drawable, GCPtr gc,
                               int narcs, xArc *arcs)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->PolyFillArc)(drawable, gc, narcs, arcs);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static int vncDRI3PolyText8(DrawablePtr drawable, GCPtr gc,
                            int x, int y, int count, char *chars)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);
  int ret;

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  ret = (*gc->ops->PolyText8)(drawable, gc, x, y, count, chars);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);

  return ret;
}

static int vncDRI3PolyText16(DrawablePtr drawable, GCPtr gc,
                             int x, int y, int count,
                             unsigned short *chars)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);
  int ret;

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  ret = (*gc->ops->PolyText16)(drawable, gc, x, y, count, chars);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);

  return ret;
}

static void vncDRI3ImageText8(DrawablePtr drawable, GCPtr gc,
                              int x, int y, int count, char *chars)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->ImageText8)(drawable, gc, x, y, count, chars);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3ImageText16(DrawablePtr drawable, GCPtr gc,
                               int x, int y, int count,
                               unsigned short *chars)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->ImageText16)(drawable, gc, x, y, count, chars);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3ImageGlyphBlt(DrawablePtr drawable, GCPtr gc, int x,
                                 int y, unsigned int nglyph,
                                 CharInfoPtr *ppci, void * pglyphBase)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->ImageGlyphBlt)(drawable, gc, x, y, nglyph, ppci, pglyphBase);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3PolyGlyphBlt(DrawablePtr drawable, GCPtr gc, int x,
                                int y, unsigned int nglyph,
                                CharInfoPtr *ppci, void * pglyphBase)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->PolyGlyphBlt)(drawable, gc, x, y, nglyph, ppci, pglyphBase);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static void vncDRI3PushPixels(GCPtr gc, PixmapPtr pBitMap,
                              DrawablePtr drawable,
                              int w, int h, int x, int y)
{
  vncDRI3GCPrivatePtr gcPriv = vncDRI3GCPrivate(gc);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(gcPriv, gc, funcs);
  unwrap(gcPriv, gc, ops);
  (*gc->ops->PushPixels)(gc, pBitMap, drawable, w, h, x, y);
  wrap(gcPriv, gc, ops, &vncDRI3GCOps);
  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  vncDRI3SyncDrawableToGPU(drawable);
}

static GCFuncs vncDRI3GCFuncs = {
  .ValidateGC = vncDRI3ValidateGC,
  .ChangeGC = vncDRI3ChangeGC,
  .CopyGC = vncDRI3CopyGC,
  .DestroyGC = vncDRI3DestroyGC,
  .ChangeClip = vncDRI3ChangeClip,
  .DestroyClip = vncDRI3DestroyClip,
  .CopyClip = vncDRI3CopyClip,
};

static GCOps vncDRI3GCOps = {
  .FillSpans = vncDRI3FillSpans,
  .SetSpans = vncDRI3SetSpans,
  .PutImage = vncDRI3PutImage,
  .CopyArea = vncDRI3CopyArea,
  .CopyPlane = vncDRI3CopyPlane,
  .PolyPoint = vncDRI3PolyPoint,
  .Polylines = vncDRI3Polylines,
  .PolySegment = vncDRI3PolySegment,
  .PolyRectangle = vncDRI3PolyRectangle,
  .PolyArc = vncDRI3PolyArc,
  .FillPolygon = vncDRI3FillPolygon,
  .PolyFillRect = vncDRI3PolyFillRect,
  .PolyFillArc = vncDRI3PolyFillArc,
  .PolyText8 = vncDRI3PolyText8,
  .PolyText16 = vncDRI3PolyText16,
  .ImageText8 = vncDRI3ImageText8,
  .ImageText16 = vncDRI3ImageText16,
  .ImageGlyphBlt = vncDRI3ImageGlyphBlt,
  .PolyGlyphBlt = vncDRI3PolyGlyphBlt,
  .PushPixels = vncDRI3PushPixels,
};

static Bool vncDRI3CreateGC(GCPtr gc)
{
  ScreenPtr screen = gc->pScreen;
  vncDRI3DrawScreenPrivatePtr screenPriv = vncDRI3DrawScreenPrivate(screen);
  vncDRI3GCPrivatePtr gcPriv;
  Bool ret;

  unwrap(screenPriv, screen, CreateGC);
  ret = (*screen->CreateGC)(gc);
  wrap(screenPriv, screen, CreateGC, vncDRI3CreateGC);

  gcPriv = vncDRI3GCPrivate(gc);

  wrap(gcPriv, gc, funcs, &vncDRI3GCFuncs);

  return ret;
}

static void vncDRI3SourceValidate(DrawablePtr drawable,
                                  int x, int y,
                                  int width, int height,
                                  unsigned int subWindowMode)
{
  ScreenPtr screen = drawable->pScreen;
  vncDRI3DrawScreenPrivatePtr screenPriv = vncDRI3DrawScreenPrivate(screen);

  /* FIXME: Compute what we need to sync */
  vncDRI3SyncDrawableFromGPU(drawable);

  unwrap(screenPriv, screen, SourceValidate);
  screen->SourceValidate(drawable, x, y, width, height, subWindowMode);
  wrap(screenPriv, screen, SourceValidate, vncDRI3SourceValidate);
}

static void vncDRI3Composite(CARD8 op, PicturePtr pSrc,
                             PicturePtr pMask, PicturePtr pDst,
                             INT16 xSrc, INT16 ySrc, INT16 xMask,
                             INT16 yMask, INT16 xDst, INT16 yDst,
                             CARD16 width, CARD16 height)
{
  ScreenPtr screen = pDst->pDrawable->pScreen;
  PictureScreenPtr ps = GetPictureScreen(screen);
  vncDRI3DrawScreenPrivatePtr screenPriv = vncDRI3DrawScreenPrivate(screen);

  vncDRI3SyncDrawableFromGPU(pDst->pDrawable);

  unwrap(screenPriv, ps, Composite);
  (*ps->Composite)(op, pSrc, pMask, pDst, xSrc, ySrc,
                   xMask, yMask, xDst, yDst, width, height);
  wrap(screenPriv, ps, Composite, vncDRI3Composite);

  vncDRI3SyncDrawableToGPU(pDst->pDrawable);
}

static void vncDRI3Glyphs(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
                          PictFormatPtr maskFormat,
                          INT16 xSrc, INT16 ySrc, int nlists,
                          GlyphListPtr lists, GlyphPtr * glyphs)
{
  ScreenPtr screen = pDst->pDrawable->pScreen;
  PictureScreenPtr ps = GetPictureScreen(screen);
  vncDRI3DrawScreenPrivatePtr screenPriv = vncDRI3DrawScreenPrivate(screen);

  vncDRI3SyncDrawableFromGPU(pDst->pDrawable);

  unwrap(screenPriv, ps, Glyphs);
  (*ps->Glyphs)(op, pSrc, pDst, maskFormat, xSrc, ySrc,
                nlists, lists, glyphs);
  wrap(screenPriv, ps, Glyphs, vncDRI3Glyphs);

  vncDRI3SyncDrawableToGPU(pDst->pDrawable);
}

static void vncDRI3CompositeRects(CARD8 op, PicturePtr pDst,
            xRenderColor * color, int nRect, xRectangle *rects)
{
  ScreenPtr screen = pDst->pDrawable->pScreen;
  PictureScreenPtr ps = GetPictureScreen(screen);
  vncDRI3DrawScreenPrivatePtr screenPriv = vncDRI3DrawScreenPrivate(screen);

  vncDRI3SyncDrawableFromGPU(pDst->pDrawable);

  unwrap(screenPriv, ps, CompositeRects);
  (*ps->CompositeRects)(op, pDst, color, nRect, rects);
  wrap(screenPriv, ps, CompositeRects, vncDRI3CompositeRects);

  vncDRI3SyncDrawableToGPU(pDst->pDrawable);
}

static void vncDRI3Trapezoids(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
            PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
            int ntrap, xTrapezoid * traps)
{
  ScreenPtr screen = pDst->pDrawable->pScreen;
  PictureScreenPtr ps = GetPictureScreen(screen);
  vncDRI3DrawScreenPrivatePtr screenPriv = vncDRI3DrawScreenPrivate(screen);

  /* FIXME: Rarely used, so we just sync everything */
  vncDRI3SyncDrawableFromGPU(pDst->pDrawable);

  unwrap(screenPriv, ps, Trapezoids);
  (*ps->Trapezoids)(op, pSrc, pDst, maskFormat, xSrc, ySrc,
                    ntrap, traps);
  wrap(screenPriv, ps, Trapezoids, vncDRI3Trapezoids);

  vncDRI3SyncDrawableToGPU(pDst->pDrawable);
}

static void vncDRI3Triangles(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
            PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
            int ntri, xTriangle * tris)
{
  ScreenPtr screen = pDst->pDrawable->pScreen;
  PictureScreenPtr ps = GetPictureScreen(screen);
  vncDRI3DrawScreenPrivatePtr screenPriv = vncDRI3DrawScreenPrivate(screen);

  /* FIXME: Rarely used, so we just sync everything */
  vncDRI3SyncDrawableFromGPU(pDst->pDrawable);

  unwrap(screenPriv, ps, Triangles);
  (*ps->Triangles)(op, pSrc, pDst, maskFormat, xSrc, ySrc, ntri, tris);
  wrap(screenPriv, ps, Triangles, vncDRI3Triangles);

  vncDRI3SyncDrawableToGPU(pDst->pDrawable);
}

static void vncDRI3TriStrip(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
            PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
            int npoint, xPointFixed * points)
{
  ScreenPtr screen = pDst->pDrawable->pScreen;
  PictureScreenPtr ps = GetPictureScreen(screen);
  vncDRI3DrawScreenPrivatePtr screenPriv = vncDRI3DrawScreenPrivate(screen);

  /* FIXME: Rarely used, so we just sync everything */
  vncDRI3SyncDrawableFromGPU(pDst->pDrawable);

  unwrap(screenPriv, ps, TriStrip);
  (*ps->TriStrip)(op, pSrc, pDst, maskFormat, xSrc, ySrc,
                  npoint, points);
  wrap(screenPriv, ps, TriStrip, vncDRI3TriStrip)

  vncDRI3SyncDrawableToGPU(pDst->pDrawable);
}

static void vncDRI3TriFan(CARD8 op, PicturePtr pSrc, PicturePtr pDst,
            PictFormatPtr maskFormat, INT16 xSrc, INT16 ySrc,
            int npoint, xPointFixed * points)
{
  ScreenPtr screen = pDst->pDrawable->pScreen;
  PictureScreenPtr ps = GetPictureScreen(screen);
  vncDRI3DrawScreenPrivatePtr screenPriv = vncDRI3DrawScreenPrivate(screen);

  /* FIXME: Rarely used, so we just sync everything */
  vncDRI3SyncDrawableFromGPU(pDst->pDrawable);

  unwrap(screenPriv, ps, TriFan);
  (*ps->TriFan)(op, pSrc, pDst, maskFormat, xSrc, ySrc, npoint, points);
  wrap(screenPriv, ps, TriFan, vncDRI3TriFan);

  vncDRI3SyncDrawableToGPU(pDst->pDrawable);
}

static Bool vncDRI3DrawCloseScreen(ScreenPtr screen)
{
  vncDRI3DrawScreenPrivatePtr screenPriv = vncDRI3DrawScreenPrivate(screen);
  PictureScreenPtr ps;

  unwrap(screenPriv, screen, CloseScreen);

  unwrap(screenPriv, screen, CreateGC);
  unwrap(screenPriv, screen, SourceValidate);

  ps = GetPictureScreenIfSet(screen);
  if (ps) {
    unwrap(screenPriv, ps, Composite);
    unwrap(screenPriv, ps, Glyphs);
    unwrap(screenPriv, ps, CompositeRects);
    unwrap(screenPriv, ps, Trapezoids);
    unwrap(screenPriv, ps, Triangles);
    unwrap(screenPriv, ps, TriStrip);
    unwrap(screenPriv, ps, TriFan);
  }

  return (*screen->CloseScreen)(screen);
}

Bool vncDRI3DrawInit(ScreenPtr screen)
{
  vncDRI3DrawScreenPrivatePtr screenPriv;
  PictureScreenPtr ps;

  if (!dixRegisterPrivateKey(&vncDRI3DrawScreenPrivateKey,
                             PRIVATE_SCREEN,
                             sizeof(vncDRI3DrawScreenPrivateRec)))
    return FALSE;
  if (!dixRegisterPrivateKey(&vncDRI3GCPrivateKey, PRIVATE_GC,
                             sizeof(vncDRI3GCPrivateRec)))
    return FALSE;

  screenPriv = vncDRI3DrawScreenPrivate(screen);

  wrap(screenPriv, screen, CloseScreen, vncDRI3DrawCloseScreen);

  wrap(screenPriv, screen, CreateGC, vncDRI3CreateGC);
  wrap(screenPriv, screen, SourceValidate, vncDRI3SourceValidate);

  ps = GetPictureScreenIfSet(screen);
  if (ps) {
    wrap(screenPriv, ps, Composite, vncDRI3Composite);
    wrap(screenPriv, ps, Glyphs, vncDRI3Glyphs);
    wrap(screenPriv, ps, CompositeRects, vncDRI3CompositeRects);
    wrap(screenPriv, ps, Trapezoids, vncDRI3Trapezoids);
    wrap(screenPriv, ps, Triangles, vncDRI3Triangles);
    wrap(screenPriv, ps, TriStrip, vncDRI3TriStrip);
    wrap(screenPriv, ps, TriFan, vncDRI3TriFan);
  }

  return TRUE;
}