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 $ */
5 Copyright (c) 1990 X Consortium
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:
15 The above copyright notice and this permission notice shall be included
16 in all copies or substantial portions of the Software.
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.
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.
37 #include "scrnintstr.h"
38 #include "pixmapstr.h"
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.
54 pointer pbits; /* pointer to framebuffer */
55 int width; /* delta to add to a framebuffer addr to move one row down */
56 } miScreenInitParmsRec, *miScreenInitParmsPtr;
59 /* this plugs into pScreen->ModifyPixmapHeader */
61 miModifyPixmapHeader(pPixmap, width, height, depth, bitsPerPixel, devKind,
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;
83 pPixmap->devPrivate.ptr = pPixData;
90 miCloseScreen (index, pScreen)
94 return ((*pScreen->DestroyPixmap)((PixmapPtr)pScreen->devPrivate));
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.
105 miCreateScreenResources(pScreen)
108 miScreenInitParmsPtr pScrInitParms;
111 pScrInitParms = (miScreenInitParmsPtr)pScreen->devPrivate;
113 /* if width is non-zero, pScreen->devPrivate will be a pixmap
114 * else it will just take the value pbits
116 if (pScrInitParms->width)
120 /* create a pixmap with no data, then redirect it to point to
123 pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth);
127 if (!(*pScreen->ModifyPixmapHeader)(pPixmap, pScreen->width,
128 pScreen->height, pScreen->rootDepth, pScreen->rootDepth,
129 PixmapBytePad(pScrInitParms->width, pScreen->rootDepth),
130 pScrInitParms->pbits))
132 value = (pointer)pPixmap;
136 value = pScrInitParms->pbits;
138 xfree(pScreen->devPrivate); /* freeing miScreenInitParmsRec */
139 pScreen->devPrivate = value; /* pPixmap or pbits */
144 miScreenDevPrivateInit(pScreen, width, pbits)
145 register ScreenPtr pScreen;
149 miScreenInitParmsPtr pScrInitParms;
151 /* Stash pbits and width in a short-lived miScreenInitParmsRec attached
152 * to the screen, until CreateScreenResources can put them in the
155 pScrInitParms = (miScreenInitParmsPtr)xalloc(sizeof(miScreenInitParmsRec));
158 pScrInitParms->pbits = pbits;
159 pScrInitParms->width = width;
160 pScreen->devPrivate = (pointer)pScrInitParms;
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.
171 miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
172 rootDepth, numDepths, depths, rootVisual, numVisuals, visuals,
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 */
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;
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;
208 ShmRegisterFbFuncs(pScreen);
210 pScreen->CloseScreen = miCloseScreen;
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 */
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;
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;
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;
267 pScreen->SetShape = miSetShape;
269 pScreen->MarkUnrealizedWindow = miMarkUnrealizedWindow;
271 miSetZeroLineBias(pScreen, DEFAULTZEROLINEBIAS);
273 return miScreenDevPrivateInit(pScreen, width, pbits);
277 miAllocateGCPrivateIndex()
279 static int privateIndex = -1;
280 static unsigned long miGeneration = 0;
282 if (miGeneration != serverGeneration)
284 privateIndex = AllocateGCPrivateIndex();
285 miGeneration = serverGeneration;
290 int miZeroLineScreenIndex;
291 int miZeroLineGeneration;
294 miSetZeroLineBias(pScreen, bias)
298 if (miZeroLineGeneration != serverGeneration)
300 miZeroLineScreenIndex = AllocateScreenPrivateIndex();
301 miZeroLineGeneration = serverGeneration;
303 if (miZeroLineScreenIndex >= 0)
304 pScreen->devPrivates[miZeroLineScreenIndex].uval = bias;