]> git.sesse.net Git - rdpsrv/blob - Xserver/programs/Xserver/cfb/cfbscrinit.c
Import X server from vnc-3.3.7.
[rdpsrv] / Xserver / programs / Xserver / cfb / cfbscrinit.c
1 /************************************************************
2 Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
3
4                     All Rights Reserved
5
6 Permission  to  use,  copy,  modify,  and  distribute   this
7 software  and  its documentation for any purpose and without
8 fee is hereby granted, provided that the above copyright no-
9 tice  appear  in all copies and that both that copyright no-
10 tice and this permission notice appear in  supporting  docu-
11 mentation,  and  that the names of Sun or X Consortium
12 not be used in advertising or publicity pertaining to 
13 distribution  of  the software  without specific prior 
14 written permission. Sun and X Consortium make no 
15 representations about the suitability of this software for 
16 any purpose. It is provided "as is" without any express or 
17 implied warranty.
18
19 SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO  THIS  SOFTWARE,
20 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
21 NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE  LI-
22 ABLE  FOR  ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
23 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,  DATA  OR
24 PROFITS,  WHETHER  IN  AN  ACTION OF CONTRACT, NEGLIGENCE OR
25 OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
26 THE USE OR PERFORMANCE OF THIS SOFTWARE.
27
28 ********************************************************/
29 /* $XConsortium: cfbscrinit.c,v 5.32 94/04/17 20:29:00 dpw Exp $ */
30
31 #include "X.h"
32 #include "Xmd.h"
33 #include "servermd.h"
34 #include "scrnintstr.h"
35 #include "pixmapstr.h"
36 #include "resource.h"
37 #include "colormap.h"
38 #include "colormapst.h"
39 #include "cfb.h"
40 #include "mi.h"
41 #include "mistruct.h"
42 #include "dix.h"
43 #include "cfbmskbits.h"
44 #include "mibstore.h"
45
46
47 miBSFuncRec cfbBSFuncRec = {
48     cfbSaveAreas,
49     cfbRestoreAreas,
50     (void (*)()) 0,
51     (PixmapPtr (*)()) 0,
52     (PixmapPtr (*)()) 0,
53 };
54
55 Bool
56 cfbCloseScreen (index, pScreen)
57     int         index;
58     ScreenPtr   pScreen;
59 {
60     int     d;
61     DepthPtr    depths = pScreen->allowedDepths;
62
63     for (d = 0; d < pScreen->numDepths; d++)
64         xfree (depths[d].vids);
65     xfree (depths);
66     xfree (pScreen->visuals);
67 #ifdef CFB_NEED_SCREEN_PRIVATE
68     xfree (pScreen->devPrivates[cfbScreenPrivateIndex].ptr);
69 #else
70     xfree (pScreen->devPrivate);
71 #endif
72     return TRUE;
73 }
74
75 Bool
76 cfbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
77     register ScreenPtr pScreen;
78     pointer pbits;              /* pointer to screen bitmap */
79     int xsize, ysize;           /* in pixels */
80     int dpix, dpiy;             /* dots per inch */
81     int width;                  /* pixel width of frame buffer */
82 {
83     int i;
84     extern RegionPtr    (*cfbPuntCopyPlane)();
85
86     if (!cfbAllocatePrivates(pScreen, (int *) 0, (int *) 0))
87         return FALSE;
88     pScreen->defColormap = FakeClientID(0);
89     /* let CreateDefColormap do whatever it wants for pixels */ 
90     pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0;
91     pScreen->QueryBestSize = mfbQueryBestSize;
92     /* SaveScreen */
93     pScreen->GetImage = cfbGetImage;
94     pScreen->GetSpans = cfbGetSpans;
95     pScreen->CreateWindow = cfbCreateWindow;
96     pScreen->DestroyWindow = cfbDestroyWindow;
97     pScreen->PositionWindow = cfbPositionWindow;
98     pScreen->ChangeWindowAttributes = cfbChangeWindowAttributes;
99     pScreen->RealizeWindow = cfbMapWindow;
100     pScreen->UnrealizeWindow = cfbUnmapWindow;
101     pScreen->PaintWindowBackground = cfbPaintWindow;
102     pScreen->PaintWindowBorder = cfbPaintWindow;
103     pScreen->CopyWindow = cfbCopyWindow;
104     pScreen->CreatePixmap = cfbCreatePixmap;
105     pScreen->DestroyPixmap = cfbDestroyPixmap;
106     pScreen->RealizeFont = mfbRealizeFont;
107     pScreen->UnrealizeFont = mfbUnrealizeFont;
108     pScreen->CreateGC = cfbCreateGC;
109     pScreen->CreateColormap = cfbInitializeColormap;
110     pScreen->DestroyColormap = (void (*)())NoopDDA;
111 #ifdef  STATIC_COLOR
112     pScreen->InstallColormap = cfbInstallColormap;
113     pScreen->UninstallColormap = cfbUninstallColormap;
114     pScreen->ListInstalledColormaps = cfbListInstalledColormaps;
115     pScreen->StoreColors = (void (*)())NoopDDA;
116 #endif
117     pScreen->ResolveColor = cfbResolveColor;
118     pScreen->BitmapToRegion = mfbPixmapToRegion;
119
120     mfbRegisterCopyPlaneProc (pScreen, cfbCopyPlane);
121     return TRUE;
122 }
123
124 #ifdef CFB_NEED_SCREEN_PRIVATE
125 Bool
126 cfbCreateScreenResources(pScreen)
127     ScreenPtr pScreen;
128 {
129     Bool retval;
130
131     pointer oldDevPrivate = pScreen->devPrivate;
132     pScreen->devPrivate = pScreen->devPrivates[cfbScreenPrivateIndex].ptr;
133     retval = miCreateScreenResources(pScreen);
134     pScreen->devPrivates[cfbScreenPrivateIndex].ptr = pScreen->devPrivate;
135     pScreen->devPrivate = oldDevPrivate;
136     return retval;
137 }
138 #endif
139
140 cfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
141     register ScreenPtr pScreen;
142     pointer pbits;              /* pointer to screen bitmap */
143     int xsize, ysize;           /* in pixels */
144     int dpix, dpiy;             /* dots per inch */
145     int width;                  /* pixel width of frame buffer */
146 {
147     int i, j;
148 #ifdef CFB_NEED_SCREEN_PRIVATE
149     pointer oldDevPrivate;
150 #endif
151     VisualPtr   visuals;
152     DepthPtr    depths;
153     int         nvisuals;
154     int         ndepths;
155     int         rootdepth;
156     VisualID    defaultVisual;
157
158     rootdepth = 0;
159     if (!cfbInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
160                          &defaultVisual,((unsigned long)1<<(PSZ-1)), 8))
161         return FALSE;
162 #ifdef CFB_NEED_SCREEN_PRIVATE
163     oldDevPrivate = pScreen->devPrivate;
164 #endif
165     if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
166                         rootdepth, ndepths, depths,
167                         defaultVisual, nvisuals, visuals,
168                         (miBSFuncPtr) 0))
169         return FALSE;
170     /* overwrite miCloseScreen with our own */
171     pScreen->CloseScreen = cfbCloseScreen;
172     /* init backing store here so we can overwrite CloseScreen without stepping
173      * on the backing store wrapped version */
174     miInitializeBackingStore (pScreen, &cfbBSFuncRec);
175 #ifdef CFB_NEED_SCREEN_PRIVATE
176     pScreen->CreateScreenResources = cfbCreateScreenResources;
177     pScreen->devPrivates[cfbScreenPrivateIndex].ptr = pScreen->devPrivate;
178     pScreen->devPrivate = oldDevPrivate;
179 #endif
180     return TRUE;
181 }
182
183 /* dts * (inch/dot) * (25.4 mm / inch) = mm */
184 Bool
185 cfbScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
186     register ScreenPtr pScreen;
187     pointer pbits;              /* pointer to screen bitmap */
188     int xsize, ysize;           /* in pixels */
189     int dpix, dpiy;             /* dots per inch */
190     int width;                  /* pixel width of frame buffer */
191 {
192     if (!cfbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width))
193         return FALSE;
194     return cfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width);
195 }