]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - glsdk/xserver.git/blob - fb/fbscreen.c
Imported Upstream version 1.11.4
[glsdk/xserver.git] / fb / fbscreen.c
1 /*
2  * Copyright © 1998 Keith Packard
3  *
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.
13  *
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.
21  */
23 #ifdef HAVE_DIX_CONFIG_H
24 #include <dix-config.h>
25 #endif
27 #include "fb.h"
29 Bool
30 fbCloseScreen (int index, ScreenPtr pScreen)
31 {
32     int     d;
33     DepthPtr    depths = pScreen->allowedDepths;
35     for (d = 0; d < pScreen->numDepths; d++)
36         free(depths[d].vids);
37     free(depths);
38     free(pScreen->visuals);
39     free(pScreen->devPrivate);
40     return TRUE;
41 }
43 Bool
44 fbRealizeFont(ScreenPtr pScreen, FontPtr pFont)
45 {
46     return TRUE;
47 }
49 Bool
50 fbUnrealizeFont(ScreenPtr pScreen, FontPtr pFont)
51 {
52     return TRUE;
53 }
55 void
56 fbQueryBestSize (int class, 
57                  unsigned short *width, unsigned short *height,
58                  ScreenPtr pScreen)
59 {
60     unsigned short  w;
61     
62     switch (class) {
63     case CursorShape:
64         if (*width > pScreen->width)
65             *width = pScreen->width;
66         if (*height > pScreen->height)
67             *height = pScreen->height;
68         break;
69     case TileShape:
70     case StippleShape:
71         w = *width;
72         if ((w & (w - 1)) && w < FB_UNIT)
73         {
74             for (w = 1; w < *width; w <<= 1)
75                 ;
76             *width = w;
77         }
78     }
79 }
81 PixmapPtr
82 _fbGetWindowPixmap (WindowPtr pWindow)
83 {
84     return fbGetWindowPixmap (pWindow);
85 }
87 void
88 _fbSetWindowPixmap (WindowPtr pWindow, PixmapPtr pPixmap)
89 {
90     dixSetPrivate(&pWindow->devPrivates, fbGetWinPrivateKey(), pPixmap);
91 }
93 Bool
94 fbSetupScreen(ScreenPtr pScreen, 
95               pointer   pbits,          /* pointer to screen bitmap */
96               int       xsize,          /* in pixels */
97               int       ysize,
98               int       dpix,           /* dots per inch */
99               int       dpiy,
100               int       width,          /* pixel width of frame buffer */
101               int       bpp)            /* bits per pixel for screen */
103     if (!fbAllocatePrivates(pScreen, NULL))
104         return FALSE;
105     pScreen->defColormap = FakeClientID(0);
106     /* let CreateDefColormap do whatever it wants for pixels */ 
107     pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0;
108     pScreen->QueryBestSize = fbQueryBestSize;
109     /* SaveScreen */
110     pScreen->GetImage = fbGetImage;
111     pScreen->GetSpans = fbGetSpans;
112     pScreen->CreateWindow = fbCreateWindow;
113     pScreen->DestroyWindow = fbDestroyWindow;
114     pScreen->PositionWindow = fbPositionWindow;
115     pScreen->ChangeWindowAttributes = fbChangeWindowAttributes;
116     pScreen->RealizeWindow = fbMapWindow;
117     pScreen->UnrealizeWindow = fbUnmapWindow;
118     pScreen->CopyWindow = fbCopyWindow;
119     pScreen->CreatePixmap = fbCreatePixmap;
120     pScreen->DestroyPixmap = fbDestroyPixmap;
121     pScreen->RealizeFont = fbRealizeFont;
122     pScreen->UnrealizeFont = fbUnrealizeFont;
123     pScreen->CreateGC = fbCreateGC;
124     pScreen->CreateColormap = fbInitializeColormap;
125     pScreen->DestroyColormap = (void (*)(ColormapPtr))NoopDDA;
126     pScreen->InstallColormap = fbInstallColormap;
127     pScreen->UninstallColormap = fbUninstallColormap;
128     pScreen->ListInstalledColormaps = fbListInstalledColormaps;
129     pScreen->StoreColors = (void (*)(ColormapPtr, int, xColorItem *))NoopDDA;
130     pScreen->ResolveColor = fbResolveColor;
131     pScreen->BitmapToRegion = fbPixmapToRegion;
132     
133     pScreen->GetWindowPixmap = _fbGetWindowPixmap;
134     pScreen->SetWindowPixmap = _fbSetWindowPixmap;
136     return TRUE;
139 #ifdef FB_ACCESS_WRAPPER
140 Bool
141 wfbFinishScreenInit(ScreenPtr           pScreen,
142                     pointer             pbits,
143                     int                 xsize,
144                     int                 ysize,
145                     int                 dpix,
146                     int                 dpiy,
147                     int                 width,
148                     int                 bpp,
149                     SetupWrapProcPtr    setupWrap,
150                     FinishWrapProcPtr   finishWrap)
151 #else
152 Bool
153 fbFinishScreenInit(ScreenPtr    pScreen,
154                    pointer      pbits,
155                    int          xsize,
156                    int          ysize,
157                    int          dpix,
158                    int          dpiy,
159                    int          width,
160                    int          bpp)
161 #endif
163     VisualPtr   visuals;
164     DepthPtr    depths;
165     int         nvisuals;
166     int         ndepths;
167     int         rootdepth;
168     VisualID    defaultVisual;
169     int         imagebpp = bpp;
171 #ifdef FB_DEBUG
172     int stride;
173     
174     ysize -= 2;
175     stride = (width * bpp) / 8;
176     fbSetBits ((FbStip *) pbits, 
177                stride / sizeof (FbStip), FB_HEAD_BITS);
178     pbits = (void *) ((char *) pbits + stride);
179     fbSetBits ((FbStip *) ((char *) pbits + stride * ysize),
180                            stride / sizeof (FbStip), FB_TAIL_BITS);
181 #endif
182     /*
183      * By default, a 24bpp screen will use 32bpp images, this avoids
184      * problems with many applications which just can't handle packed
185      * pixels.  If you want real 24bit images, include a 24bpp
186      * format in the pixmap formats
187      */
188     if (bpp == 24)
189     {
190         int     f;
191         
192         imagebpp = 32;
193         /*
194          * Check to see if we're advertising a 24bpp image format,
195          * in which case windows will use it in preference to a 32 bit
196          * format.
197          */
198         for (f = 0; f < screenInfo.numPixmapFormats; f++)
199         {
200             if (screenInfo.formats[f].bitsPerPixel == 24)
201             {
202                 imagebpp = 24;
203                 break;
204             }
205         }           
206     }
207     if (imagebpp == 32)
208     {
209         fbGetScreenPrivate(pScreen)->win32bpp = bpp;
210         fbGetScreenPrivate(pScreen)->pix32bpp = bpp;
211     }
212     else
213     {
214         fbGetScreenPrivate(pScreen)->win32bpp = 32;
215         fbGetScreenPrivate(pScreen)->pix32bpp = 32;
216     }
217 #ifdef FB_ACCESS_WRAPPER
218     fbGetScreenPrivate(pScreen)->setupWrap = setupWrap;
219     fbGetScreenPrivate(pScreen)->finishWrap = finishWrap;
220 #endif
221     rootdepth = 0;
222     if (!fbInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
223                         &defaultVisual,((unsigned long)1<<(imagebpp-1)), 8))
224         return FALSE;
225     if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
226                         rootdepth, ndepths, depths,
227                         defaultVisual, nvisuals, visuals))
228         return FALSE;
229     /* overwrite miCloseScreen with our own */
230     pScreen->CloseScreen = fbCloseScreen;
231     if (bpp == 24 && imagebpp == 32)
232     {
233         pScreen->ModifyPixmapHeader = fb24_32ModifyPixmapHeader;
234         pScreen->CreateScreenResources = fb24_32CreateScreenResources;
235     }
236     return TRUE;
239 /* dts * (inch/dot) * (25.4 mm / inch) = mm */
240 #ifdef FB_ACCESS_WRAPPER
241 Bool
242 wfbScreenInit(ScreenPtr         pScreen,
243               pointer           pbits,
244               int               xsize,
245               int               ysize,
246               int               dpix,
247               int               dpiy,
248               int               width,
249               int               bpp,
250               SetupWrapProcPtr  setupWrap,
251               FinishWrapProcPtr finishWrap)
253     if (!fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp))
254         return FALSE;
255     if (!wfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy,
256                              width, bpp, setupWrap, finishWrap))
257         return FALSE;
258     return TRUE;
260 #else
261 Bool
262 fbScreenInit(ScreenPtr  pScreen,
263              pointer    pbits,
264              int        xsize,
265              int        ysize,
266              int        dpix,
267              int        dpiy,
268              int        width,
269              int        bpp)
271     if (!fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp))
272         return FALSE;
273     if (!fbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, 
274                             width, bpp))
275         return FALSE;
276     return TRUE;
278 #endif