]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/mi/miscrinit.c
Support RDP5 logon packets.
[rdpsrv] / Xserver / programs / Xserver / mi / miscrinit.c
1 /* $XConsortium: miscrinit.c /main/13 1996/08/12 21:51:16 dpw $ */
2 /* $XFree86: xc/programs/Xserver/mi/miscrinit.c,v 3.2 1996/12/23 07:09:46 dawes Exp $ */
3 /*
4
5 Copyright (c) 1990  X Consortium
6
7 Permission is hereby granted, free of charge, to any person obtaining
8 a copy of this software and associated documentation files (the
9 "Software"), to deal in the Software without restriction, including
10 without limitation the rights to use, copy, modify, merge, publish,
11 distribute, sublicense, and/or sell copies of the Software, and to
12 permit persons to whom the Software is furnished to do so, subject to
13 the following conditions:
14
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 OTHER DEALINGS IN THE SOFTWARE.
25
26 Except as contained in this notice, the name of the X Consortium shall
27 not be used in advertising or otherwise to promote the sale, use or
28 other dealings in this Software without prior written authorization
29 from the X Consortium.
30
31 */
32
33 #include "X.h"
34 #include "servermd.h"
35 #include "misc.h"
36 #include "mi.h"
37 #include "scrnintstr.h"
38 #include "pixmapstr.h"
39 #include "mibstore.h"
40 #include "dix.h"
41 #include "miline.h"
42
43 /* We use this structure to propogate some information from miScreenInit to
44  * miCreateScreenResources.  miScreenInit allocates the structure, fills it
45  * in, and puts it into pScreen->devPrivate.  miCreateScreenResources 
46  * extracts the info and frees the structure.  We could've accomplished the
47  * same thing by adding fields to the screen structure, but they would have
48  * ended up being redundant, and would have exposed this mi implementation
49  * detail to the whole server.
50  */
51
52 typedef struct
53 {
54     pointer pbits; /* pointer to framebuffer */
55     int width;    /* delta to add to a framebuffer addr to move one row down */
56 } miScreenInitParmsRec, *miScreenInitParmsPtr;
57
58
59 /* this plugs into pScreen->ModifyPixmapHeader */
60 Bool
61 miModifyPixmapHeader(pPixmap, width, height, depth, bitsPerPixel, devKind,
62                      pPixData)
63     PixmapPtr   pPixmap;
64     int         width;
65     int         height;
66     int         depth;
67     int         bitsPerPixel;
68     int         devKind;
69     pointer     pPixData;
70 {
71     if (!pPixmap)
72         return FALSE;
73     pPixmap->drawable.depth = depth;
74     pPixmap->drawable.bitsPerPixel = bitsPerPixel;
75     pPixmap->drawable.id = 0;
76     pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
77     pPixmap->drawable.x = 0;
78     pPixmap->drawable.y = 0;
79     pPixmap->drawable.width = width;
80     pPixmap->drawable.height = height;
81     pPixmap->devKind = devKind;
82     pPixmap->refcnt = 1;
83     pPixmap->devPrivate.ptr = pPixData;
84     return TRUE;
85 }
86
87
88 /*ARGSUSED*/
89 Bool
90 miCloseScreen (index, pScreen)
91     int         index;
92     ScreenPtr   pScreen;
93 {
94     return ((*pScreen->DestroyPixmap)((PixmapPtr)pScreen->devPrivate));
95 }
96
97 /* With the introduction of pixmap privates, the "screen pixmap" can no
98  * longer be created in miScreenInit, since all the modules that could
99  * possibly ask for pixmap private space have not been initialized at
100  * that time.  pScreen->CreateScreenResources is called after all
101  * possible private-requesting modules have been inited; we create the
102  * screen pixmap here.
103  */
104 Bool
105 miCreateScreenResources(pScreen)
106     ScreenPtr pScreen;
107 {
108     miScreenInitParmsPtr pScrInitParms;
109     pointer value;
110
111     pScrInitParms = (miScreenInitParmsPtr)pScreen->devPrivate;
112
113     /* if width is non-zero, pScreen->devPrivate will be a pixmap
114      * else it will just take the value pbits
115      */
116     if (pScrInitParms->width)
117     {
118         PixmapPtr pPixmap;
119
120         /* create a pixmap with no data, then redirect it to point to
121          * the screen
122          */
123         pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth);
124         if (!pPixmap)
125             return FALSE;
126
127         if (!(*pScreen->ModifyPixmapHeader)(pPixmap, pScreen->width,
128                     pScreen->height, pScreen->rootDepth, pScreen->rootDepth,
129                     PixmapBytePad(pScrInitParms->width, pScreen->rootDepth),
130                     pScrInitParms->pbits))
131             return FALSE;
132         value = (pointer)pPixmap;
133     }
134     else
135     {
136         value = pScrInitParms->pbits;
137     }
138     xfree(pScreen->devPrivate); /* freeing miScreenInitParmsRec */
139     pScreen->devPrivate = value; /* pPixmap or pbits */
140     return TRUE;
141 }
142
143 Bool
144 miScreenDevPrivateInit(pScreen, width, pbits)
145     register ScreenPtr pScreen;
146     int width;
147     pointer pbits;
148 {
149     miScreenInitParmsPtr pScrInitParms;
150
151     /* Stash pbits and width in a short-lived miScreenInitParmsRec attached
152      * to the screen, until CreateScreenResources can put them in the
153      * screen pixmap.
154      */
155     pScrInitParms = (miScreenInitParmsPtr)xalloc(sizeof(miScreenInitParmsRec));
156     if (!pScrInitParms)
157         return FALSE;
158     pScrInitParms->pbits = pbits;
159     pScrInitParms->width = width;
160     pScreen->devPrivate = (pointer)pScrInitParms;
161     return TRUE;
162 }
163
164 /*
165  * If you pass in bsfuncs, then you must preinitialize the missing
166  * screen procs before calling miScreenInit, so that the backing store
167  * code can correctly wrap them.
168  */
169
170 Bool
171 miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
172              rootDepth, numDepths, depths, rootVisual, numVisuals, visuals,
173              bsfuncs)
174     register ScreenPtr pScreen;
175     pointer pbits;              /* pointer to screen bits */
176     int xsize, ysize;           /* in pixels */
177     int dpix, dpiy;             /* dots per inch */
178     int width;                  /* pixel width of frame buffer */
179     int rootDepth;              /* depth of root window */
180     int numDepths;              /* number of depths supported */
181     DepthRec *depths;           /* supported depths */
182     VisualID rootVisual;        /* root visual */
183     int numVisuals;             /* number of visuals supported */
184     VisualRec *visuals;         /* supported visuals */
185     miBSFuncPtr bsfuncs;        /* backing store functions */
186 {
187     pScreen->width = xsize;
188     pScreen->height = ysize;
189     pScreen->mmWidth = (xsize * 254 + dpix * 5) / (dpix * 10);
190     pScreen->mmHeight = (ysize * 254 + dpiy * 5) / (dpiy * 10);
191     pScreen->numDepths = numDepths;
192     pScreen->rootDepth = rootDepth;
193     pScreen->allowedDepths = depths;
194     pScreen->rootVisual = rootVisual;
195     /* defColormap */
196     pScreen->minInstalledCmaps = 1;
197     pScreen->maxInstalledCmaps = 1;
198     pScreen->backingStoreSupport = Always;
199     pScreen->saveUnderSupport = NotUseful;
200     /* whitePixel, blackPixel */
201     pScreen->ModifyPixmapHeader = miModifyPixmapHeader;
202     pScreen->CreateScreenResources = miCreateScreenResources;
203     pScreen->numVisuals = numVisuals;
204     pScreen->visuals = visuals;
205     if (width)
206     {
207 #ifdef MITSHM
208         ShmRegisterFbFuncs(pScreen);
209 #endif
210         pScreen->CloseScreen = miCloseScreen;
211     }
212     /* else CloseScreen */
213     /* QueryBestSize, SaveScreen, GetImage, GetSpans */
214     pScreen->PointerNonInterestBox = (void (*)()) 0;
215     pScreen->SourceValidate = (void (*)()) 0;
216     /* CreateWindow, DestroyWindow, PositionWindow, ChangeWindowAttributes */
217     /* RealizeWindow, UnrealizeWindow */
218     pScreen->ValidateTree = miValidateTree;
219     pScreen->PostValidateTree = (void (*)()) 0;
220     pScreen->WindowExposures = miWindowExposures;
221     /* PaintWindowBackground, PaintWindowBorder, CopyWindow */
222     pScreen->ClearToBackground = miClearToBackground;
223     pScreen->ClipNotify = (void (*)()) 0;
224     /* CreatePixmap, DestroyPixmap */
225     /* RealizeFont, UnrealizeFont */
226     /* CreateGC */
227     /* CreateColormap, DestroyColormap, InstallColormap, UninstallColormap */
228     /* ListInstalledColormaps, StoreColors, ResolveColor */
229     pScreen->RegionCreate = miRegionCreate;
230     pScreen->RegionInit = miRegionInit;
231     pScreen->RegionCopy = miRegionCopy;
232     pScreen->RegionDestroy = miRegionDestroy;
233     pScreen->RegionUninit = miRegionUninit;
234     pScreen->Intersect = miIntersect;
235     pScreen->Union = miUnion;
236     pScreen->Subtract = miSubtract;
237     pScreen->Inverse = miInverse;
238     pScreen->RegionReset = miRegionReset;
239     pScreen->TranslateRegion = miTranslateRegion;
240     pScreen->RectIn = miRectIn;
241     pScreen->PointInRegion = miPointInRegion;
242     pScreen->RegionNotEmpty = miRegionNotEmpty;
243     pScreen->RegionEmpty = miRegionEmpty;
244     pScreen->RegionExtents = miRegionExtents;
245     pScreen->RegionAppend = miRegionAppend;
246     pScreen->RegionValidate = miRegionValidate;
247     /* BitmapToRegion */
248     pScreen->RectsToRegion = miRectsToRegion;
249     pScreen->SendGraphicsExpose = miSendGraphicsExpose;
250     pScreen->BlockHandler = (void (*)())NoopDDA;
251     pScreen->WakeupHandler = (void (*)())NoopDDA;
252     pScreen->blockData = (pointer)0;
253     pScreen->wakeupData = (pointer)0;
254     if (bsfuncs)
255         miInitializeBackingStore (pScreen, bsfuncs);
256     pScreen->MarkWindow = miMarkWindow;
257     pScreen->MarkOverlappedWindows = miMarkOverlappedWindows;
258     pScreen->ChangeSaveUnder = miChangeSaveUnder;
259     pScreen->PostChangeSaveUnder = miPostChangeSaveUnder;
260     pScreen->MoveWindow = miMoveWindow;
261     pScreen->ResizeWindow = miSlideAndSizeWindow;
262     pScreen->GetLayerWindow = miGetLayerWindow;
263     pScreen->HandleExposures = miHandleValidateExposures;
264     pScreen->ReparentWindow = (void (*)())0;
265     pScreen->ChangeBorderWidth = miChangeBorderWidth;
266 #ifdef SHAPE
267     pScreen->SetShape = miSetShape;
268 #endif
269     pScreen->MarkUnrealizedWindow = miMarkUnrealizedWindow;
270
271     miSetZeroLineBias(pScreen, DEFAULTZEROLINEBIAS);
272
273     return miScreenDevPrivateInit(pScreen, width, pbits);
274 }
275
276 int
277 miAllocateGCPrivateIndex()
278 {
279     static int privateIndex = -1;
280     static unsigned long miGeneration = 0;
281
282     if (miGeneration != serverGeneration)
283     {
284         privateIndex = AllocateGCPrivateIndex();
285         miGeneration = serverGeneration;
286     }
287     return privateIndex;
288 }
289
290 int miZeroLineScreenIndex;
291 int miZeroLineGeneration;
292
293 void
294 miSetZeroLineBias(pScreen, bias)
295     ScreenPtr pScreen;
296     unsigned int bias;
297 {
298     if (miZeroLineGeneration != serverGeneration)
299     {
300         miZeroLineScreenIndex = AllocateScreenPrivateIndex();
301         miZeroLineGeneration = serverGeneration;
302     }
303     if (miZeroLineScreenIndex >= 0)
304         pScreen->devPrivates[miZeroLineScreenIndex].uval = bias;
305 }