Initial commit
[xorg_rtime.git] / xorg-server-1.4 / afb / afbscrinit.c
blob7cb74234526cb341b9ebd8be917de845dd063fbc
1 /***********************************************************
3 Copyright (c) 1987 X Consortium
5 Permission is hereby granted, free of charge, to any person obtaining a copy
6 of this software and associated documentation files (the "Software"), to deal
7 in the Software without restriction, including without limitation the rights
8 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 copies of the Software, and to permit persons to whom the Software is
10 furnished to do so, subject to the following conditions:
12 The above copyright notice and this permission notice shall be included in
13 all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
19 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 Except as contained in this notice, the name of the X Consortium shall not be
23 used in advertising or otherwise to promote the sale, use or other dealings
24 in this Software without prior written authorization from the X Consortium.
27 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
29 All Rights Reserved
31 Permission to use, copy, modify, and distribute this software and its
32 documentation for any purpose and without fee is hereby granted,
33 provided that the above copyright notice appear in all copies and that
34 both that copyright notice and this permission notice appear in
35 supporting documentation, and that the name of Digital not be
36 used in advertising or publicity pertaining to distribution of the
37 software without specific, written prior permission.
39 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
40 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
41 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
42 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
43 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
44 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
45 SOFTWARE.
47 ******************************************************************/
49 #ifdef HAVE_DIX_CONFIG_H
50 #include <dix-config.h>
51 #endif
53 #include <stdlib.h>
55 #include <X11/X.h>
56 #include <X11/Xproto.h> /* for xColorItem */
57 #include <X11/Xmd.h>
58 #include "scrnintstr.h"
59 #include "pixmapstr.h"
60 #include "windowstr.h"
61 #include "resource.h"
62 #include "colormap.h"
63 #include "afb.h"
64 #include "mistruct.h"
65 #include "dix.h"
66 #include "mi.h"
67 #include "mibstore.h"
68 #include "migc.h"
69 #include "servermd.h"
71 #ifdef PIXMAP_PER_WINDOW
72 int frameWindowPrivateIndex;
73 #endif
74 int afbWindowPrivateIndex;
75 int afbGCPrivateIndex;
76 int afbScreenPrivateIndex;
78 static unsigned long afbGeneration = 0;
80 static BSFuncRec afbBSFuncRec = {
81 afbSaveAreas,
82 afbRestoreAreas,
83 (BackingStoreSetClipmaskRgnProcPtr) 0,
84 (BackingStoreGetImagePixmapProcPtr) 0,
85 (BackingStoreGetSpansPixmapProcPtr) 0,
88 static Bool
89 afbCloseScreen(int index, ScreenPtr pScreen)
91 int d;
92 DepthPtr depths = pScreen->allowedDepths;
94 for (d = 0; d < pScreen->numDepths; d++)
95 xfree(depths[d].vids);
96 xfree(depths);
97 xfree(pScreen->visuals);
98 xfree(pScreen->devPrivates[afbScreenPrivateIndex].ptr);
99 return(TRUE);
102 static Bool
103 afbCreateScreenResources(ScreenPtr pScreen)
105 Bool retval;
107 pointer oldDevPrivate = pScreen->devPrivate;
109 pScreen->devPrivate = pScreen->devPrivates[afbScreenPrivateIndex].ptr;
110 retval = miCreateScreenResources(pScreen);
112 /* Modify screen's pixmap devKind value stored off devPrivate to
113 * be the width of a single plane in longs rather than the width
114 * of a chunky screen in longs as incorrectly setup by the mi routine.
116 ((PixmapPtr)pScreen->devPrivate)->devKind = BitmapBytePad(pScreen->width);
117 pScreen->devPrivates[afbScreenPrivateIndex].ptr = pScreen->devPrivate;
118 pScreen->devPrivate = oldDevPrivate;
119 return(retval);
122 static PixmapPtr
123 afbGetWindowPixmap(WindowPtr pWin)
125 #ifdef PIXMAP_PER_WINDOW
126 return (PixmapPtr)(pWin->devPrivates[frameWindowPrivateIndex].ptr);
127 #else
128 ScreenPtr pScreen = pWin->drawable.pScreen;
130 return (* pScreen->GetScreenPixmap)(pScreen);
131 #endif
134 static void
135 afbSetWindowPixmap(WindowPtr pWin, PixmapPtr pPix)
137 #ifdef PIXMAP_PER_WINDOW
138 pWin->devPrivates[frameWindowPrivateIndex].ptr = (pointer)pPix;
139 #else
140 (* pWin->drawable.pScreen->SetScreenPixmap)(pPix);
141 #endif
144 static Bool
145 afbAllocatePrivates(ScreenPtr pScreen, int *pWinIndex, int *pGCIndex)
147 if (afbGeneration != serverGeneration) {
148 #ifdef PIXMAP_PER_WINDOW
149 frameWindowPrivateIndex = AllocateWindowPrivateIndex();
150 #endif
151 afbWindowPrivateIndex = AllocateWindowPrivateIndex();
152 afbGCPrivateIndex = AllocateGCPrivateIndex();
153 afbGeneration = serverGeneration;
155 if (pWinIndex)
156 *pWinIndex = afbWindowPrivateIndex;
157 if (pGCIndex)
158 *pGCIndex = afbGCPrivateIndex;
160 afbScreenPrivateIndex = AllocateScreenPrivateIndex();
161 pScreen->GetWindowPixmap = afbGetWindowPixmap;
162 pScreen->SetWindowPixmap = afbSetWindowPixmap;
163 return(AllocateWindowPrivate(pScreen, afbWindowPrivateIndex, sizeof(afbPrivWin)) &&
164 AllocateGCPrivate(pScreen, afbGCPrivateIndex, sizeof(afbPrivGC)));
167 /* dts * (inch/dot) * (25.4 mm / inch) = mm */
168 Bool
169 afbScreenInit(register ScreenPtr pScreen, pointer pbits, int xsize, int ysize, int dpix, int dpiy, int width)
171 /* pointer to screen bitmap */
172 /* in pixels */
173 /* dots per inch */
174 /* pixel width of frame buffer */
176 VisualPtr visuals;
177 DepthPtr depths;
178 int nvisuals;
179 int ndepths;
180 int rootdepth;
181 VisualID defaultVisual;
182 pointer oldDevPrivate;
184 rootdepth = 0;
185 if (!afbInitVisuals(&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
186 &defaultVisual, 256, 8)) {
187 ErrorF("afbInitVisuals: FALSE\n");
188 return FALSE;
190 if (!afbAllocatePrivates(pScreen,(int *)NULL, (int *)NULL)) {
191 ErrorF("afbAllocatePrivates: FALSE\n");
192 return FALSE;
195 pScreen->defColormap = (Colormap)FakeClientID(0);
196 /* whitePixel, blackPixel */
197 pScreen->blackPixel = 0;
198 pScreen->whitePixel = 0;
199 pScreen->QueryBestSize = afbQueryBestSize;
200 /* SaveScreen */
201 pScreen->GetImage = afbGetImage;
202 pScreen->GetSpans = afbGetSpans;
203 pScreen->CreateWindow = afbCreateWindow;
204 pScreen->DestroyWindow = afbDestroyWindow;
205 pScreen->PositionWindow = afbPositionWindow;
206 pScreen->ChangeWindowAttributes = afbChangeWindowAttributes;
207 pScreen->RealizeWindow = afbMapWindow;
208 pScreen->UnrealizeWindow = afbUnmapWindow;
209 pScreen->PaintWindowBackground = afbPaintWindow;
210 pScreen->PaintWindowBorder = afbPaintWindow;
211 pScreen->CopyWindow = afbCopyWindow;
212 pScreen->CreatePixmap = afbCreatePixmap;
213 pScreen->DestroyPixmap = afbDestroyPixmap;
214 pScreen->RealizeFont = afbRealizeFont;
215 pScreen->UnrealizeFont = afbUnrealizeFont;
216 pScreen->CreateGC = afbCreateGC;
217 pScreen->CreateColormap = afbInitializeColormap;
218 pScreen->DestroyColormap = (DestroyColormapProcPtr)NoopDDA;
219 pScreen->InstallColormap = afbInstallColormap;
220 pScreen->UninstallColormap = afbUninstallColormap;
221 pScreen->ListInstalledColormaps = afbListInstalledColormaps;
222 pScreen->StoreColors = (StoreColorsProcPtr)NoopDDA;
223 pScreen->ResolveColor = afbResolveColor;
224 pScreen->BitmapToRegion = afbPixmapToRegion;
225 oldDevPrivate = pScreen->devPrivate;
226 if (!miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width, rootdepth,
227 ndepths, depths, defaultVisual, nvisuals, visuals)) {
228 ErrorF("miScreenInit: FALSE\n");
229 return FALSE;
232 pScreen->CloseScreen = afbCloseScreen;
233 pScreen->CreateScreenResources = afbCreateScreenResources;
234 pScreen->BackingStoreFuncs = afbBSFuncRec;
236 pScreen->devPrivates[afbScreenPrivateIndex].ptr = pScreen->devPrivate;
237 pScreen->devPrivate = oldDevPrivate;
239 return TRUE;