2 * Copyright © 1998 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
23 #ifdef HAVE_DIX_CONFIG_H
24 #include <dix-config.h>
30 fbCloseScreen(ScreenPtr pScreen
)
33 DepthPtr depths
= pScreen
->allowedDepths
;
35 fbDestroyGlyphCache();
36 for (d
= 0; d
< pScreen
->numDepths
; d
++)
39 free(pScreen
->visuals
);
40 free(pScreen
->devPrivate
);
45 fbRealizeFont(ScreenPtr pScreen
, FontPtr pFont
)
51 fbUnrealizeFont(ScreenPtr pScreen
, FontPtr pFont
)
57 fbQueryBestSize(int class,
58 unsigned short *width
, unsigned short *height
,
65 if (*width
> pScreen
->width
)
66 *width
= pScreen
->width
;
67 if (*height
> pScreen
->height
)
68 *height
= pScreen
->height
;
73 if ((w
& (w
- 1)) && w
< FB_UNIT
) {
74 for (w
= 1; w
< *width
; w
<<= 1);
81 _fbGetWindowPixmap(WindowPtr pWindow
)
83 return fbGetWindowPixmap(pWindow
);
87 _fbSetWindowPixmap(WindowPtr pWindow
, PixmapPtr pPixmap
)
89 dixSetPrivate(&pWindow
->devPrivates
, fbGetWinPrivateKey(pWindow
), pPixmap
);
93 fbSetupScreen(ScreenPtr pScreen
, pointer pbits
, /* pointer to screen bitmap */
94 int xsize
, /* in pixels */
95 int ysize
, int dpix
, /* dots per inch */
96 int dpiy
, int width
, /* pixel width of frame buffer */
98 { /* bits per pixel for screen */
99 if (!fbAllocatePrivates(pScreen
))
101 pScreen
->defColormap
= FakeClientID(0);
102 /* let CreateDefColormap do whatever it wants for pixels */
103 pScreen
->blackPixel
= pScreen
->whitePixel
= (Pixel
) 0;
104 pScreen
->QueryBestSize
= fbQueryBestSize
;
106 pScreen
->GetImage
= fbGetImage
;
107 pScreen
->GetSpans
= fbGetSpans
;
108 pScreen
->CreateWindow
= fbCreateWindow
;
109 pScreen
->DestroyWindow
= fbDestroyWindow
;
110 pScreen
->PositionWindow
= fbPositionWindow
;
111 pScreen
->ChangeWindowAttributes
= fbChangeWindowAttributes
;
112 pScreen
->RealizeWindow
= fbMapWindow
;
113 pScreen
->UnrealizeWindow
= fbUnmapWindow
;
114 pScreen
->CopyWindow
= fbCopyWindow
;
115 pScreen
->CreatePixmap
= fbCreatePixmap
;
116 pScreen
->DestroyPixmap
= fbDestroyPixmap
;
117 pScreen
->RealizeFont
= fbRealizeFont
;
118 pScreen
->UnrealizeFont
= fbUnrealizeFont
;
119 pScreen
->CreateGC
= fbCreateGC
;
120 pScreen
->CreateColormap
= fbInitializeColormap
;
121 pScreen
->DestroyColormap
= (void (*)(ColormapPtr
)) NoopDDA
;
122 pScreen
->InstallColormap
= fbInstallColormap
;
123 pScreen
->UninstallColormap
= fbUninstallColormap
;
124 pScreen
->ListInstalledColormaps
= fbListInstalledColormaps
;
125 pScreen
->StoreColors
= (void (*)(ColormapPtr
, int, xColorItem
*)) NoopDDA
;
126 pScreen
->ResolveColor
= fbResolveColor
;
127 pScreen
->BitmapToRegion
= fbPixmapToRegion
;
129 pScreen
->GetWindowPixmap
= _fbGetWindowPixmap
;
130 pScreen
->SetWindowPixmap
= _fbSetWindowPixmap
;
135 #ifdef FB_ACCESS_WRAPPER
137 wfbFinishScreenInit(ScreenPtr pScreen
,
145 SetupWrapProcPtr setupWrap
, FinishWrapProcPtr finishWrap
)
148 fbFinishScreenInit(ScreenPtr pScreen
,
150 int xsize
, int ysize
, int dpix
, int dpiy
, int width
, int bpp
)
158 VisualID defaultVisual
;
165 stride
= (width
* bpp
) / 8;
166 fbSetBits((FbStip
*) pbits
, stride
/ sizeof(FbStip
), FB_HEAD_BITS
);
167 pbits
= (void *) ((char *) pbits
+ stride
);
168 fbSetBits((FbStip
*) ((char *) pbits
+ stride
* ysize
),
169 stride
/ sizeof(FbStip
), FB_TAIL_BITS
);
172 * By default, a 24bpp screen will use 32bpp images, this avoids
173 * problems with many applications which just can't handle packed
174 * pixels. If you want real 24bit images, include a 24bpp
175 * format in the pixmap formats
182 * Check to see if we're advertising a 24bpp image format,
183 * in which case windows will use it in preference to a 32 bit
186 for (f
= 0; f
< screenInfo
.numPixmapFormats
; f
++) {
187 if (screenInfo
.formats
[f
].bitsPerPixel
== 24) {
193 if (imagebpp
== 32) {
194 fbGetScreenPrivate(pScreen
)->win32bpp
= bpp
;
195 fbGetScreenPrivate(pScreen
)->pix32bpp
= bpp
;
198 fbGetScreenPrivate(pScreen
)->win32bpp
= 32;
199 fbGetScreenPrivate(pScreen
)->pix32bpp
= 32;
201 #ifdef FB_ACCESS_WRAPPER
202 fbGetScreenPrivate(pScreen
)->setupWrap
= setupWrap
;
203 fbGetScreenPrivate(pScreen
)->finishWrap
= finishWrap
;
206 if (!fbInitVisuals(&visuals
, &depths
, &nvisuals
, &ndepths
, &rootdepth
,
207 &defaultVisual
, ((unsigned long) 1 << (imagebpp
- 1)),
210 if (!miScreenInit(pScreen
, pbits
, xsize
, ysize
, dpix
, dpiy
, width
,
211 rootdepth
, ndepths
, depths
,
212 defaultVisual
, nvisuals
, visuals
))
214 /* overwrite miCloseScreen with our own */
215 pScreen
->CloseScreen
= fbCloseScreen
;
216 if (bpp
== 24 && imagebpp
== 32) {
217 pScreen
->ModifyPixmapHeader
= fb24_32ModifyPixmapHeader
;
218 pScreen
->CreateScreenResources
= fb24_32CreateScreenResources
;
223 /* dts * (inch/dot) * (25.4 mm / inch) = mm */
224 #ifdef FB_ACCESS_WRAPPER
226 wfbScreenInit(ScreenPtr pScreen
,
233 int bpp
, SetupWrapProcPtr setupWrap
, FinishWrapProcPtr finishWrap
)
235 if (!fbSetupScreen(pScreen
, pbits
, xsize
, ysize
, dpix
, dpiy
, width
, bpp
))
237 if (!wfbFinishScreenInit(pScreen
, pbits
, xsize
, ysize
, dpix
, dpiy
,
238 width
, bpp
, setupWrap
, finishWrap
))
244 fbScreenInit(ScreenPtr pScreen
,
246 int xsize
, int ysize
, int dpix
, int dpiy
, int width
, int bpp
)
248 if (!fbSetupScreen(pScreen
, pbits
, xsize
, ysize
, dpix
, dpiy
, width
, bpp
))
250 if (!fbFinishScreenInit(pScreen
, pbits
, xsize
, ysize
, dpix
, dpiy
,