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
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
|
/* $XConsortium: Xdbeproto.h,v 1.1 95/05/25 17:29:33 dpw Exp dpw $ */
/******************************************************************************
*
* Copyright (c) 1994, 1995 Hewlett-Packard Company
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* 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 HEWLETT-PACKARD COMPANY 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.
*
* Except as contained in this notice, the name of the Hewlett-Packard
* Company shall not be used in advertising or otherwise to promote the
* sale, use or other dealings in this Software without prior written
* authorization from the Hewlett-Packard Company.
*
* $Header: midbe.c,v 55.16 95/05/19 14:53:50 yip Exp $
*
* Machine-independent DBE code
*
*****************************************************************************/
/* INCLUDES */
#define NEED_REPLIES
#define NEED_EVENTS
#include <stdio.h>
#include "X.h"
#include "Xproto.h"
#include "misc.h"
#include "os.h"
#include "windowstr.h"
#include "scrnintstr.h"
#include "pixmapstr.h"
#include "extnsionst.h"
#include "dixstruct.h"
#include "resource.h"
#include "opaque.h"
#include "dbestruct.h"
#include "midbestruct.h"
#include "regionstr.h"
#include "gcstruct.h"
#include "inputstr.h"
/* DEFINES */
/* TYPEDEFS */
/* GLOBALS */
static int miDbePrivPrivGeneration = 0;
static int miDbeWindowPrivPrivIndex = -1;
static int miDbeScreenPrivPrivIndex = -1;
RESTYPE dbeDrawableResType;
RESTYPE dbeWindowPrivResType;
int dbeScreenPrivIndex = -1;
int dbeWindowPrivIndex = -1;
/* EXTERNS */
/* FORWARDS */
static void miDbeAliasBuffers(
DbeWindowPrivPtr pDbeWindowPriv);
static int miDbeAllocBackBufferName(
WindowPtr pWin,
XID bufId,
xDbeSwapAction swapAction);
static void miDbeBeginIdiom(
ClientPtr client);
static void miDbeEndIdiom(
ClientPtr client);
static Bool miDbeGetVisualInfo(
ScreenPtr pScreen,
XdbeScreenVisualInfo *pScrVisInfo);
Bool miDbeInit(
ScreenPtr pScreen,
DbeScreenPrivPtr pDbeScreenPriv);
static Bool miDbePositionWindow(
WindowPtr pWin,
int x,
int y);
static void miDbeResetProc(
ScreenPtr pScreen);
static int miDbeSwapBuffers(
ClientPtr client,
int nWindows,
WindowPtr *pWins,
xDbeSwapAction *actions);
static void miDbeWinPrivDelete(
DbeWindowPrivPtr pDbeWindowPriv,
XID bufId);
/******************************************************************************
*
* DBE MI Procedure: miDbeInit
*
* Description:
*
* This is the MI initialization function called by DbeExtensionInit().
*
*****************************************************************************/
Bool
miDbeInit(
ScreenPtr pScreen,
DbeScreenPrivPtr pDbeScreenPriv)
{
MiDbeScreenPrivPrivPtr pDbeScreenPrivPriv;
/* Copy resource types created by DIX */
dbeDrawableResType = pDbeScreenPriv->dbeDrawableResType;
dbeWindowPrivResType = pDbeScreenPriv->dbeWindowPrivResType;
/* Copy private indices created by DIX */
dbeScreenPrivIndex = pDbeScreenPriv->dbeScreenPrivIndex;
dbeWindowPrivIndex = pDbeScreenPriv->dbeWindowPrivIndex;
/* Reset the screen and window priv privs if generations do not match. */
if (miDbePrivPrivGeneration != serverGeneration)
{
/*
**********************************************************************
** Allocate the screen priv priv.
**********************************************************************
*/
miDbeScreenPrivPrivIndex = (*pDbeScreenPriv->AllocScrnPrivPrivIndex)(
pScreen);
if (!(*pDbeScreenPriv->AllocScrnPrivPriv)(pScreen,
miDbeScreenPrivPrivIndex, sizeof(MiDbeScreenPrivPrivRec)))
{
return(FALSE);
}
if (!(pDbeScreenPriv=(*pDbeScreenPriv->AllocScrnPriv)(pDbeScreenPriv)))
{
return(FALSE);
}
if (!(pDbeScreenPrivPriv = (MiDbeScreenPrivPrivPtr)xalloc(
sizeof(MiDbeScreenPrivPrivRec))))
{
return(FALSE);
}
/* Reset the pointer to the screen priv in case it changed from the
* AllocScrnPriv() call.
*/
pScreen->devPrivates[dbeScreenPrivIndex].ptr=(pointer)pDbeScreenPriv;
pDbeScreenPriv->devPrivates[miDbeScreenPrivPrivIndex].ptr =
(pointer)pDbeScreenPrivPriv;
pDbeScreenPrivPriv = MI_DBE_SCREEN_PRIV_PRIV(pDbeScreenPriv);
pDbeScreenPrivPriv->pDbeScreenPriv = pDbeScreenPriv;
/*
**********************************************************************
** Allocate the window priv priv.
**********************************************************************
*/
miDbeWindowPrivPrivIndex = (*pDbeScreenPriv->AllocWinPrivPrivIndex)(
pScreen);
if (!(*pDbeScreenPriv->AllocWinPrivPriv)(pScreen,
miDbeWindowPrivPrivIndex, sizeof(MiDbeWindowPrivPrivRec)))
{
return(FALSE);
}
/* Make sure we only do this code once. */
miDbePrivPrivGeneration = serverGeneration;
} /* if -- Reset priv privs. */
/* Wrap functions. */
pDbeScreenPriv->PositionWindow = pScreen->PositionWindow;
pScreen->PositionWindow = miDbePositionWindow;
/* Initialize the per-screen DBE function pointers. */
pDbeScreenPriv->GetVisualInfo = miDbeGetVisualInfo;
pDbeScreenPriv->AllocBackBufferName = (int (*)())miDbeAllocBackBufferName;
pDbeScreenPriv->SwapBuffers = miDbeSwapBuffers;
pDbeScreenPriv->BeginIdiom = miDbeBeginIdiom;
pDbeScreenPriv->EndIdiom = miDbeEndIdiom;
pDbeScreenPriv->ResetProc = miDbeResetProc;
pDbeScreenPriv->WinPrivDelete = miDbeWinPrivDelete;
return(TRUE);
} /* miDbeInit() */
/******************************************************************************
*
* DBE MI Procedure: miDbeGetVisualInfo
*
* Description:
*
* This is the MI function for the DbeGetVisualInfo request. This function
* is called through pDbeScreenPriv->GetVisualInfo. This function is also
* called for the DbeAllocateBackBufferName request at the extension level;
* it is called by ProcDbeAllocateBackBufferName() in dbe.c.
*
* If memory allocation fails or we can not get the visual info, this
* function returns FALSE. Otherwise, it returns TRUE for success.
*
*****************************************************************************/
static Bool
miDbeGetVisualInfo(
ScreenPtr pScreen,
XdbeScreenVisualInfo *pScrVisInfo)
{
register int i, j, k;
register int count;
DepthPtr pDepth;
XdbeVisualInfo *visInfo;
/* Determine number of visuals for this screen. */
for (i = 0, count = 0; i < pScreen->numDepths; i++)
{
count += pScreen->allowedDepths[i].numVids;
}
/* Allocate an array of XdbeVisualInfo items. */
if (!(visInfo = (XdbeVisualInfo *)xalloc(count * sizeof(XdbeVisualInfo))))
{
return(FALSE); /* memory alloc failure */
}
for (i = 0, k = 0; i < pScreen->numDepths; i++)
{
/* For each depth of this screen, get visual information. */
pDepth = &pScreen->allowedDepths[i];
for (j = 0; j < pDepth->numVids; j++)
{
/* For each visual for this depth of this screen, get visual ID
* and visual depth. Since this is MI code, we will always return
* the same performance level for all visuals (0). A higher
* performance level value indicates higher performance.
*/
visInfo[k].visual = pDepth->vids[j];
visInfo[k].depth = pDepth->depth;
visInfo[k].perflevel = 0;
k++;
}
}
/* Record the number of visuals and point visual_depth to
* the array of visual info.
*/
pScrVisInfo->count = count;
pScrVisInfo->visinfo = visInfo;
return(TRUE); /* success */
} /* miDbeGetVisualInfo() */
/******************************************************************************
*
* DBE MI Procedure: miAllocBackBufferName
*
* Description:
*
* This is the MI function for the DbeAllocateBackBufferName request.
*
*****************************************************************************/
static int
miDbeAllocBackBufferName(
WindowPtr pWin,
XID bufId,
xDbeSwapAction swapAction)
{
ScreenPtr pScreen;
DbeWindowPrivPtr pDbeWindowPriv;
MiDbeWindowPrivPrivPtr pDbeWindowPrivPriv;
DbeScreenPrivPtr pDbeScreenPriv;
GCPtr pGC;
xRectangle clearRect;
pScreen = pWin->drawable.pScreen;
if ((pDbeWindowPriv = DBE_WINDOW_PRIV(pWin)) == NULL)
{
/* There is no buffer associated with the window.
* We have to create everything.
*/
pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
/* Allocate a window priv. */
if (!(pDbeWindowPriv = (*pDbeScreenPriv->AllocWinPriv)(pScreen)))
{
return(BadAlloc);
}
/* Setup the window priv priv. */
pDbeWindowPrivPriv = MI_DBE_WINDOW_PRIV_PRIV(pDbeWindowPriv);
pDbeWindowPrivPriv->pDbeWindowPriv = pDbeWindowPriv;
/* Fill out the window priv information. */
pDbeWindowPriv->pWindow = pWin;
pDbeWindowPriv->width = pWin->drawable.width;
pDbeWindowPriv->height = pWin->drawable.height;
pDbeWindowPriv->x = pWin->drawable.x;
pDbeWindowPriv->y = pWin->drawable.y;
pDbeWindowPriv->idList.id = bufId;
pDbeWindowPriv->idList.prev = NULL;
pDbeWindowPriv->idList.next = NULL;
pDbeWindowPriv->nBufferIDs = 0;
pDbeWindowPriv->pPixmapFront = 0;
pDbeWindowPriv->pPixmapBack = 0;
/* Get a front pixmap. */
if (!(pDbeWindowPriv->pPixmapFront = (*pScreen->CreatePixmap)(pScreen,
pDbeWindowPriv->width, pDbeWindowPriv->height,
pWin->drawable.depth)))
{
xfree(pDbeWindowPriv);
return(BadAlloc);
}
/* Get a back pixmap. */
if (!(pDbeWindowPriv->pPixmapBack = (*pScreen->CreatePixmap)(pScreen,
pDbeWindowPriv->width, pDbeWindowPriv->height,
pWin->drawable.depth)))
{
(*pScreen->DestroyPixmap)(pDbeWindowPriv->pPixmapFront);
xfree(pDbeWindowPriv);
return(BadAlloc);
}
/* Make the window priv a DBE window priv resource. */
if (!AddResource(bufId, dbeWindowPrivResType, (pointer)pDbeWindowPriv))
{
(*pScreen->DestroyPixmap)(pDbeWindowPriv->pPixmapFront);
(*pScreen->DestroyPixmap)(pDbeWindowPriv->pPixmapBack);
xfree(pDbeWindowPriv);
return(BadAlloc);
}
/* Make the back pixmap a DBE drawable resource. */
if (!AddResource(bufId, dbeDrawableResType,
(pointer)pDbeWindowPriv->pPixmapBack))
{
/* free the buffer and the drawable resource */
FreeResource(bufId, RT_NONE);
return(BadAlloc);
}
pWin->devPrivates[dbeWindowPrivIndex].ptr = (pointer)pDbeWindowPriv;
pDbeWindowPriv->devPrivates[miDbeWindowPrivPrivIndex].ptr =
(pointer)pDbeWindowPrivPriv;
/* Clear the back buffer. */
pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen);
if ((*pDbeScreenPriv->SetupBackgroundPainter)(pWin, pGC))
{
ValidateGC((DrawablePtr)pDbeWindowPriv->pPixmapBack, pGC);
clearRect.x = clearRect.y = 0;
clearRect.width = pDbeWindowPriv->pPixmapBack->drawable.width;
clearRect.height = pDbeWindowPriv->pPixmapBack->drawable.height;
(*pGC->ops->PolyFillRect)((DrawablePtr)pDbeWindowPriv->pPixmapBack,
pGC, 1, &clearRect);
}
FreeScratchGC(pGC);
} /* if ((pDbeWindowPriv = DBE_WINDOW_PRIV(pWin)) == NULL) */
else
{
/* A buffer is already associated with the window.
* Place the new buffer ID information at the head of the ID list.
*/
DbeBufferIdPtr pDbeBufferId;
/* Allocate a new ID node. */
if (!(pDbeBufferId = (DbeBufferIdPtr)xalloc(sizeof(DbeBufferIdRec))))
{
return(BadAlloc);
}
/* Associate the new ID with an existing pixmap. */
if (!AddResource(bufId, dbeDrawableResType,
(pointer)pDbeWindowPriv->pPixmapBack))
{
xfree(pDbeBufferId);
return(BadAlloc);
}
/* Associate the new ID with an existing window priv. */
if (!AddResource(bufId, dbeWindowPrivResType, (pointer)pDbeWindowPriv))
{
xfree(pDbeBufferId);
return(BadAlloc);
}
/* Copy the first ID node's data. Fix the prev pointer.
* Remember, the head of the list is a record in the window priv.
*/
pDbeBufferId->id = pDbeWindowPriv->idList.id;
pDbeBufferId->prev = &pDbeWindowPriv->idList;
pDbeBufferId->next = pDbeWindowPriv->idList.next;
/* Fill in our new first node data. */
pDbeWindowPriv->idList.id = bufId;
pDbeWindowPriv->idList.prev = NULL;
pDbeWindowPriv->idList.next = pDbeBufferId;
/* Fix the third node's prev pointer, if that node exists. */
if (pDbeBufferId->next)
{
pDbeBufferId->next->prev = pDbeBufferId;
}
}
/* Increment the number of buffers (XIDs) associated with this window. */
pDbeWindowPriv->nBufferIDs++;
/* Set swap action on all calls. */
pDbeWindowPriv->swapAction = swapAction;
return(Success);
} /* miDbeAllocBackBufferName() */
/******************************************************************************
*
* DBE MI Procedure: miDbeSwapBuffers
*
* Description:
*
* This is the MI function for the DbeSwapBuffers request.
*
*****************************************************************************/
static int
miDbeSwapBuffers(
ClientPtr client,
int nWindows,
WindowPtr *pWins,
xDbeSwapAction *actions)
{
DbeScreenPrivPtr pDbeScreenPriv;
GCPtr pGC;
WindowPtr pWin;
register int i;
DbeWindowPrivPtr pDbeWindowPriv;
PixmapPtr pTempPixmap;
xRectangle clearRect;
for (i = 0; i < nWindows; i++)
{
pWin = pWins[i];
pDbeScreenPriv = DBE_SCREEN_PRIV_FROM_WINDOW(pWin);
pDbeWindowPriv = DBE_WINDOW_PRIV(pWin);
pGC = GetScratchGC(pWin->drawable.depth, pWin->drawable.pScreen);
/*
**********************************************************************
**
** Setup before swap.
**
**********************************************************************
*/
switch(actions[i])
{
case XdbeUndefined:
break;
case XdbeBackground:
break;
case XdbeUntouched:
ValidateGC((DrawablePtr)pDbeWindowPriv->pPixmapFront, pGC);
(*pGC->ops->CopyArea)((DrawablePtr)pWin,
(DrawablePtr)pDbeWindowPriv->pPixmapFront, pGC, 0, 0,
pWin->drawable.width, pWin->drawable.height, 0, 0);
break;
case XdbeCopied:
break;
} /* switch(actions[i]) */
/*
**********************************************************************
**
** Swap.
**
**********************************************************************
*/
ValidateGC((DrawablePtr)pWin, pGC);
(*pGC->ops->CopyArea)((DrawablePtr)pDbeWindowPriv->pPixmapBack,
(DrawablePtr)pWin,
pGC, 0, 0, pWin->drawable.width,
pWin->drawable.height, 0, 0);
/*
**********************************************************************
**
** Setup after swap.
**
**********************************************************************
*/
switch(actions[i])
{
case XdbeUndefined:
break;
case XdbeBackground:
if ((*pDbeScreenPriv->SetupBackgroundPainter)(pWin, pGC))
{
ValidateGC((DrawablePtr)pDbeWindowPriv->pPixmapBack, pGC);
clearRect.x = 0;
clearRect.y = 0;
clearRect.width =
pDbeWindowPriv->pPixmapBack->drawable.width;
clearRect.height =
pDbeWindowPriv->pPixmapBack->drawable.height;
(*pGC->ops->PolyFillRect)(
(DrawablePtr)pDbeWindowPriv->pPixmapBack, pGC, 1,
&clearRect);
}
break;
case XdbeUntouched:
/* Swap pixmap pointers. */
pTempPixmap = pDbeWindowPriv->pPixmapBack;
pDbeWindowPriv->pPixmapBack = pDbeWindowPriv->pPixmapFront;
pDbeWindowPriv->pPixmapFront = pTempPixmap;
miDbeAliasBuffers(pDbeWindowPriv);
break;
case XdbeCopied:
break;
} /* switch(actions[i]) */
FreeScratchGC(pGC);
} /* for (i = 0; i < nWindows; i++) */
return(Success);
} /* miSwapBuffers() */
/******************************************************************************
*
* DBE MI Procedure: miDbeBeginIdiom
*
* Description:
*
* This is the MI function for the DbeBeginIdiom request.
* This function is a NOOP since we can not take advantage of hardware.
*
*****************************************************************************/
static void
miDbeBeginIdiom(
ClientPtr client)
{
} /* miDbeBeginIdiom() */
/******************************************************************************
*
* DBE MI Procedure: miDbeEndIdiom
*
* Description:
*
* This is the MI function for the DbeEndIdiom request.
* This function is a NOOP since we can not take advantage of hardware.
*
*****************************************************************************/
static void
miDbeEndIdiom(
ClientPtr client)
{
} /* miDbeEndIdiom() */
/******************************************************************************
*
* DBE MI Procedure: miDbeWinPrivDelete
*
* Description:
*
* This is the MI function for deleting the dbeWindowPrivResType resource.
* This function is invoked indirectly by calling FreeResource() to free
* the resources associated with a DBE buffer ID. There are 5 ways that
* miDbeWinPrivDelete() can be called by FreeResource(). They are:
*
* - A DBE window is destroyed, in which case the DbeDestroyWindow()
* wrapper is invoked. The wrapper calls FreeResource() for all DBE
* buffer IDs.
*
* - miDbeAllocBackBufferName() calls FreeResource() to clean up resources
* after a buffer allocation failure.
*
* - The PositionWindow wrapper, miDbePositionWindow(), calls
* FreeResource() when it fails to create buffers of the new size.
* FreeResource() is called for all DBE buffer IDs.
*
* - FreeClientResources() calls FreeResource() when a client dies or the
* the server resets.
*
* When FreeResource() is called for a DBE buffer ID, the delete function
* for the only other type of DBE resource, dbeDrawableResType, is also
* invoked. This delete function (DbeDrawableDelete) is a NOOP to make
* resource deletion easier. It is not guaranteed which delete function is
* called first. Hence, we will let miDbeWinPrivDelete() free all DBE
* resources.
*
* This function deletes/frees the following stuff associated with
* the window private:
*
* - the ID node in the ID list representing the passed in ID.
*
* In addition, pDbeWindowPriv->nBufferIDs is decremented.
*
* If this function is called for the last/only buffer ID for a window,
* these are additionally deleted/freed:
*
* - the front and back pixmaps
* - the window priv itself
*
*****************************************************************************/
static void
miDbeWinPrivDelete(
DbeWindowPrivPtr pDbeWindowPriv,
XID bufId)
{
DbeBufferIdPtr pID, pDbeBufferId = NULL;
/*
**************************************************************************
** Find the ID on the ID list.
**************************************************************************
*/
pID = &pDbeWindowPriv->idList;
while (pID)
{
if (pID->id == bufId)
{
pDbeBufferId = pID;
break;
}
pID = pID->next;
}
if (pDbeBufferId == NULL)
{
/* This should never happen. */
return;
}
/*
**************************************************************************
** Remove the buffer name from the ID list.
**************************************************************************
*/
if (pDbeBufferId->prev == NULL)
{
/* Node to delete is head of list. Remember, this is a record in the
* DBE window private, not a pointer. It can not be freed.
*/
if (pDbeWindowPriv->idList.next == NULL)
{
/* This is the only node in the list. */
pDbeWindowPriv->idList.id = (XID)0;
}
else
{
/* There are at least two nodes in the list. */
/* Remember the second node, which we will free below. */
pID = pDbeWindowPriv->idList.next;
if (pDbeWindowPriv->idList.next->next)
{
/* Fix the third node's prev pointer, if there is one. */
pDbeWindowPriv->idList.next->next->prev =
&pDbeWindowPriv->idList;
}
/* Copy the second node to the ID record in the window private. */
pDbeWindowPriv->idList.id = pDbeWindowPriv->idList.next->id;
pDbeWindowPriv->idList.next = pDbeWindowPriv->idList.next->next;
/* Free the second node since we copied it to the head of the
* list.
*/
xfree(pID);
}
}
else
{
/* Node to delete is somewhere after the beginning of the list. */
pDbeBufferId->prev->next = pDbeBufferId->next;
if (pDbeBufferId->next)
{
/* Correct next node's pointers if there is a next node. */
pDbeBufferId->next->prev = pDbeBufferId->prev;
}
xfree(pDbeBufferId);
}
/*
**************************************************************************
** Decrement the number of buffer IDs for this window.
**************************************************************************
*/
pDbeWindowPriv->nBufferIDs--;
if (pDbeWindowPriv->nBufferIDs != 0)
{
/* We still have at least one more buffer ID associated with this
* window.
*/
return;
}
/*
**************************************************************************
** We have no more buffer IDs associated with this window. We need to
** free some more stuff.
**************************************************************************
*/
/* Destroy the front and back pixmaps. */
if (pDbeWindowPriv->pPixmapFront)
{
(*pDbeWindowPriv->pWindow->drawable.pScreen->DestroyPixmap)(
pDbeWindowPriv->pPixmapFront);
}
if (pDbeWindowPriv->pPixmapBack)
{
(*pDbeWindowPriv->pWindow->drawable.pScreen->DestroyPixmap)(
pDbeWindowPriv->pPixmapBack);
}
/* Reset the DBE window priv pointer. */
pDbeWindowPriv->pWindow->devPrivates[dbeWindowPrivIndex].ptr =
(pointer)NULL;
/* Free the window priv. */
xfree(pDbeWindowPriv);
} /* miDbeWinPrivDelete() */
/******************************************************************************
*
* DBE MI Procedure: miDbePositionWindow
*
* Description:
*
* This function was cloned from miMbxPositionWindow() in mimultibuf.c.
* This function resizes the buffer when the window is resized.
*
*****************************************************************************/
static Bool
miDbePositionWindow(
WindowPtr pWin,
int x,
int y)
{
ScreenPtr pScreen;
DbeScreenPrivPtr pDbeScreenPriv;
DbeWindowPrivPtr pDbeWindowPriv;
int width, height;
int dx, dy, dw, dh;
int sourcex, sourcey;
int destx, desty;
int savewidth, saveheight;
PixmapPtr pPixmapFront;
PixmapPtr pPixmapBack;
Bool clear;
GCPtr pGC;
xRectangle clearRect;
Bool ret;
/*
**************************************************************************
** 1. Unwrap the member routine.
**************************************************************************
*/
pScreen = pWin->drawable.pScreen;
pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
pScreen->PositionWindow = pDbeScreenPriv->PositionWindow;
/*
**************************************************************************
** 2. Do any work necessary before the member routine is called.
**
** In this case we do not need to do anything.
**************************************************************************
*/
/*
**************************************************************************
** 3. Call the member routine, saving its result if necessary.
**************************************************************************
*/
ret = (*pScreen->PositionWindow)(pWin, x, y);
/*
**************************************************************************
** 4. Rewrap the member routine, restoring the wrapper value first in case
** the wrapper (or something that it wrapped) change this value.
**************************************************************************
*/
pDbeScreenPriv->PositionWindow = pScreen->PositionWindow;
pScreen->PositionWindow = miDbePositionWindow;
/*
**************************************************************************
** 5. Do any work necessary after the member routine has been called.
**************************************************************************
*/
if (!(pDbeWindowPriv = DBE_WINDOW_PRIV(pWin)))
{
return(ret);
}
if (pDbeWindowPriv->width == pWin->drawable.width &&
pDbeWindowPriv->height == pWin->drawable.height)
{
return(ret);
}
width = pWin->drawable.width;
height = pWin->drawable.height;
dx = pWin->drawable.x - pDbeWindowPriv->x;
dy = pWin->drawable.y - pDbeWindowPriv->y;
dw = width - pDbeWindowPriv->width;
dh = height - pDbeWindowPriv->height;
GravityTranslate (0, 0, -dx, -dy, dw, dh, pWin->bitGravity, &destx, &desty);
clear = ((pDbeWindowPriv->width < (unsigned short)width ) ||
(pDbeWindowPriv->height < (unsigned short)height) ||
(pWin->bitGravity == ForgetGravity));
sourcex = 0;
sourcey = 0;
savewidth = pDbeWindowPriv->width;
saveheight = pDbeWindowPriv->height;
/* Clip rectangle to source and destination. */
if (destx < 0)
{
savewidth += destx;
sourcex -= destx;
destx = 0;
}
if (destx + savewidth > width)
{
savewidth = width - destx;
}
if (desty < 0)
{
saveheight += desty;
sourcey -= desty;
desty = 0;
}
if (desty + saveheight > height)
{
saveheight = height - desty;
}
pDbeWindowPriv->width = width;
pDbeWindowPriv->height = height;
pDbeWindowPriv->x = pWin->drawable.x;
pDbeWindowPriv->y = pWin->drawable.y;
pGC = GetScratchGC (pWin->drawable.depth, pScreen);
if (clear)
{
if ((*pDbeScreenPriv->SetupBackgroundPainter)(pWin, pGC))
{
clearRect.x = 0;
clearRect.y = 0;
clearRect.width = width;
clearRect.height = height;
}
else
{
clear = FALSE;
}
}
/* Create DBE buffer pixmaps equal to size of resized window. */
pPixmapFront = (*pScreen->CreatePixmap)(pScreen, width, height,
pWin->drawable.depth);
pPixmapBack = (*pScreen->CreatePixmap)(pScreen, width, height,
pWin->drawable.depth);
if (!pPixmapFront || !pPixmapBack)
{
/* We failed at creating 1 or 2 of the pixmaps. */
if (pPixmapFront)
{
(*pScreen->DestroyPixmap)(pPixmapFront);
}
if (pPixmapBack)
{
(*pScreen->DestroyPixmap)(pPixmapBack);
}
/* Destroy all buffers for this window. */
while (pDbeWindowPriv)
{
/* miDbeWinPrivDelete() will free the window private if there no
* more buffer IDs associated with this window.
*/
FreeResource(pDbeWindowPriv->idList.id, RT_NONE);
pDbeWindowPriv = DBE_WINDOW_PRIV(pWin);
}
FreeScratchGC(pGC);
return(FALSE);
}
else
{
/* Clear out the new DBE buffer pixmaps. */
ValidateGC((DrawablePtr)pPixmapFront, pGC);
/* I suppose this could avoid quite a bit of work if
* it computed the minimal area required.
*/
if (clear)
{
(*pGC->ops->PolyFillRect)((DrawablePtr)pPixmapFront, pGC, 1,
&clearRect);
(*pGC->ops->PolyFillRect)((DrawablePtr)pPixmapBack , pGC, 1,
&clearRect);
}
/* Copy the contents of the old DBE pixmaps to the new pixmaps. */
if (pWin->bitGravity != ForgetGravity)
{
(*pGC->ops->CopyArea)((DrawablePtr)pDbeWindowPriv->pPixmapFront,
(DrawablePtr)pPixmapFront, pGC, sourcex, sourcey,
savewidth, saveheight, destx, desty);
(*pGC->ops->CopyArea)((DrawablePtr)pDbeWindowPriv->pPixmapBack,
(DrawablePtr)pPixmapBack, pGC, sourcex, sourcey,
savewidth, saveheight, destx, desty);
}
/* Destroy the old pixmaps, and point the DBE window priv to the new
* pixmaps.
*/
(*pScreen->DestroyPixmap)(pDbeWindowPriv->pPixmapFront);
(*pScreen->DestroyPixmap)(pDbeWindowPriv->pPixmapBack);
pDbeWindowPriv->pPixmapFront = pPixmapFront;
pDbeWindowPriv->pPixmapBack = pPixmapBack;
/* Make sure all XID are associated with the new back pixmap. */
miDbeAliasBuffers(pDbeWindowPriv);
FreeScratchGC(pGC);
}
return(ret);
} /* miDbePositionWindow() */
/******************************************************************************
*
* DBE MI Procedure: miDbeAliasBuffers
*
* Description:
*
* This function associates all XIDs of a buffer with the back pixmap
* stored in the window priv.
*
*****************************************************************************/
static void
miDbeAliasBuffers(
DbeWindowPrivPtr pDbeWindowPriv)
{
DbeBufferIdPtr pDbeBufferId = &pDbeWindowPriv->idList;
while (pDbeBufferId)
{
ChangeResourceValue(pDbeBufferId->id, dbeDrawableResType,
(pointer)pDbeWindowPriv->pPixmapBack);
pDbeBufferId = pDbeBufferId->next;
}
} /* miDbeAliasBuffers() */
/******************************************************************************
*
* DBE MI Procedure: miDbeResetProc
*
* Description:
*
* This function is called from DbeResetProc(), which is called at the end
* of every server generation. This function peforms any MI-specific
* shutdown tasks.
*
*****************************************************************************/
static void
miDbeResetProc(
ScreenPtr pScreen)
{
DbeScreenPrivPtr pDbeScreenPriv;
pDbeScreenPriv = DBE_SCREEN_PRIV(pScreen);
/* Unwrap wrappers */
pScreen->PositionWindow = pDbeScreenPriv->PositionWindow;
} /* miDbeResetProc() */
|