First import
[xorg_rtime.git] / xorg-server-1.4 / mfb / mfbscrinit.c
blob0707c1a74fe3c961920c3586ffb0bbfc6e0939dc
1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28 All Rights Reserved
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44 SOFTWARE.
46 ******************************************************************/
48 #ifdef HAVE_DIX_CONFIG_H
49 #include <dix-config.h>
50 #endif
52 #include <string.h>
54 #include <X11/X.h>
55 #include <X11/Xproto.h> /* for xColorItem */
56 #include <X11/Xmd.h>
57 #include "scrnintstr.h"
58 #include "pixmapstr.h"
59 #include "windowstr.h"
60 #include "resource.h"
61 #include "colormap.h"
62 #include "mfb.h"
63 #include "mistruct.h"
64 #include "dix.h"
65 #include "mi.h"
66 #include "mibstore.h"
67 #include "migc.h"
68 #include "servermd.h"
70 #ifdef PIXMAP_PER_WINDOW
71 int frameWindowPrivateIndex;
72 int frameGetWindowPrivateIndex(void) { return frameWindowPrivateIndex; }
73 #endif
74 int mfbWindowPrivateIndex;
75 int mfbGetWindowPrivateIndex(void) { return mfbWindowPrivateIndex; }
76 int mfbGCPrivateIndex;
77 int mfbGetGCPrivateIndex(void) { return mfbGCPrivateIndex; }
78 static unsigned long mfbGeneration = 0;
80 static VisualRec visual = {
81 /* vid class bpRGB cmpE nplan rMask gMask bMask oRed oGreen oBlue */
82 0, StaticGray, 1, 2, 1, 0, 0, 0, 0, 0, 0
85 static VisualID VID;
87 static DepthRec depth = {
88 /* depth numVid vids */
89 1, 1, &VID
93 BSFuncRec mfbBSFuncRec = {
94 mfbSaveAreas,
95 mfbRestoreAreas,
96 (BackingStoreSetClipmaskRgnProcPtr) 0,
97 (BackingStoreGetImagePixmapProcPtr) 0,
98 (BackingStoreGetSpansPixmapProcPtr) 0,
102 Bool
103 mfbAllocatePrivates(pScreen, pWinIndex, pGCIndex)
104 ScreenPtr pScreen;
105 int *pWinIndex, *pGCIndex;
107 if (mfbGeneration != serverGeneration)
109 #ifdef PIXMAP_PER_WINDOW
110 frameWindowPrivateIndex = AllocateWindowPrivateIndex();
111 #endif
112 mfbWindowPrivateIndex = AllocateWindowPrivateIndex();
113 mfbGCPrivateIndex = miAllocateGCPrivateIndex();
114 visual.vid = FakeClientID(0);
115 VID = visual.vid;
116 mfbGeneration = serverGeneration;
118 if (pWinIndex)
119 *pWinIndex = mfbWindowPrivateIndex;
120 if (pGCIndex)
121 *pGCIndex = mfbGCPrivateIndex;
122 pScreen->GetWindowPixmap = mfbGetWindowPixmap;
123 pScreen->SetWindowPixmap = mfbSetWindowPixmap;
124 return (AllocateWindowPrivate(pScreen, mfbWindowPrivateIndex,
125 sizeof(mfbPrivWin)) &&
126 AllocateGCPrivate(pScreen, mfbGCPrivateIndex, sizeof(mfbPrivGC)));
130 /* dts * (inch/dot) * (25.4 mm / inch) = mm */
131 Bool
132 mfbScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width)
133 register ScreenPtr pScreen;
134 pointer pbits; /* pointer to screen bitmap */
135 int xsize, ysize; /* in pixels */
136 int dpix, dpiy; /* dots per inch */
137 int width; /* pixel width of frame buffer */
139 if (!mfbAllocatePrivates(pScreen, (int *)NULL, (int *)NULL))
140 return FALSE;
141 pScreen->defColormap = (Colormap) FakeClientID(0);
142 /* whitePixel, blackPixel */
143 pScreen->QueryBestSize = mfbQueryBestSize;
144 /* SaveScreen */
145 pScreen->GetImage = mfbGetImage;
146 pScreen->GetSpans = mfbGetSpans;
147 pScreen->CreateWindow = mfbCreateWindow;
148 pScreen->DestroyWindow = mfbDestroyWindow;
149 pScreen->PositionWindow = mfbPositionWindow;
150 pScreen->ChangeWindowAttributes = mfbChangeWindowAttributes;
151 pScreen->RealizeWindow = mfbMapWindow;
152 pScreen->UnrealizeWindow = mfbUnmapWindow;
153 pScreen->PaintWindowBackground = mfbPaintWindow;
154 pScreen->PaintWindowBorder = mfbPaintWindow;
155 pScreen->CopyWindow = mfbCopyWindow;
156 pScreen->CreatePixmap = mfbCreatePixmap;
157 pScreen->DestroyPixmap = mfbDestroyPixmap;
158 pScreen->RealizeFont = mfbRealizeFont;
159 pScreen->UnrealizeFont = mfbUnrealizeFont;
160 pScreen->CreateGC = mfbCreateGC;
161 pScreen->CreateColormap = mfbCreateColormap;
162 pScreen->DestroyColormap = mfbDestroyColormap;
163 pScreen->InstallColormap = mfbInstallColormap;
164 pScreen->UninstallColormap = mfbUninstallColormap;
165 pScreen->ListInstalledColormaps = mfbListInstalledColormaps;
166 pScreen->StoreColors = (StoreColorsProcPtr)NoopDDA;
167 pScreen->ResolveColor = mfbResolveColor;
168 pScreen->BitmapToRegion = mfbPixmapToRegion;
169 if (!miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
170 1, 1, &depth, VID, 1, &visual))
171 return FALSE;
172 pScreen->BackingStoreFuncs = mfbBSFuncRec;
173 return TRUE;
176 PixmapPtr
177 mfbGetWindowPixmap(pWin)
178 WindowPtr pWin;
180 #ifdef PIXMAP_PER_WINDOW
181 return (PixmapPtr)(pWin->devPrivates[frameWindowPrivateIndex].ptr);
182 #else
183 ScreenPtr pScreen = pWin->drawable.pScreen;
185 return (* pScreen->GetScreenPixmap)(pScreen);
186 #endif
189 void
190 mfbSetWindowPixmap(pWin, pPix)
191 WindowPtr pWin;
192 PixmapPtr pPix;
194 #ifdef PIXMAP_PER_WINDOW
195 pWin->devPrivates[frameWindowPrivateIndex].ptr = (pointer)pPix;
196 #else
197 (* pWin->drawable.pScreen->SetScreenPixmap)(pPix);
198 #endif
201 void mfbFillInScreen(ScreenPtr pScreen)
203 pScreen->ChangeWindowAttributes = mfbChangeWindowAttributes;
204 pScreen->RealizeWindow = mfbMapWindow;
205 pScreen->UnrealizeWindow = mfbUnmapWindow;
206 pScreen->DestroyPixmap = mfbDestroyPixmap;
207 pScreen->RealizeFont = mfbRealizeFont;
208 pScreen->UnrealizeFont = mfbUnrealizeFont;
209 pScreen->BitmapToRegion = mfbPixmapToRegion;