Add patch that contain Mali fixes.
[deb_xorg-server.git] / fb / fbscreen.c
CommitLineData
a09e091a
JB
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 */
22
23#ifdef HAVE_DIX_CONFIG_H
24#include <dix-config.h>
25#endif
26
27#include "fb.h"
28
29Bool
30fbCloseScreen(ScreenPtr pScreen)
31{
32 int d;
33 DepthPtr depths = pScreen->allowedDepths;
34
35 fbDestroyGlyphCache();
36 for (d = 0; d < pScreen->numDepths; d++)
37 free(depths[d].vids);
38 free(depths);
39 free(pScreen->visuals);
40 free(pScreen->devPrivate);
41 return TRUE;
42}
43
44Bool
45fbRealizeFont(ScreenPtr pScreen, FontPtr pFont)
46{
47 return TRUE;
48}
49
50Bool
51fbUnrealizeFont(ScreenPtr pScreen, FontPtr pFont)
52{
53 return TRUE;
54}
55
56void
57fbQueryBestSize(int class,
58 unsigned short *width, unsigned short *height,
59 ScreenPtr pScreen)
60{
61 unsigned short w;
62
63 switch (class) {
64 case CursorShape:
65 if (*width > pScreen->width)
66 *width = pScreen->width;
67 if (*height > pScreen->height)
68 *height = pScreen->height;
69 break;
70 case TileShape:
71 case StippleShape:
72 w = *width;
73 if ((w & (w - 1)) && w < FB_UNIT) {
74 for (w = 1; w < *width; w <<= 1);
75 *width = w;
76 }
77 }
78}
79
80PixmapPtr
81_fbGetWindowPixmap(WindowPtr pWindow)
82{
83 return fbGetWindowPixmap(pWindow);
84}
85
86void
87_fbSetWindowPixmap(WindowPtr pWindow, PixmapPtr pPixmap)
88{
89 dixSetPrivate(&pWindow->devPrivates, fbGetWinPrivateKey(pWindow), pPixmap);
90}
91
92Bool
93fbSetupScreen(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 */
97 int bpp)
98{ /* bits per pixel for screen */
99 if (!fbAllocatePrivates(pScreen))
100 return FALSE;
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;
105 /* SaveScreen */
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;
128
129 pScreen->GetWindowPixmap = _fbGetWindowPixmap;
130 pScreen->SetWindowPixmap = _fbSetWindowPixmap;
131
132 return TRUE;
133}
134
135#ifdef FB_ACCESS_WRAPPER
136Bool
137wfbFinishScreenInit(ScreenPtr pScreen,
138 pointer pbits,
139 int xsize,
140 int ysize,
141 int dpix,
142 int dpiy,
143 int width,
144 int bpp,
145 SetupWrapProcPtr setupWrap, FinishWrapProcPtr finishWrap)
146#else
147Bool
148fbFinishScreenInit(ScreenPtr pScreen,
149 pointer pbits,
150 int xsize, int ysize, int dpix, int dpiy, int width, int bpp)
151#endif
152{
153 VisualPtr visuals;
154 DepthPtr depths;
155 int nvisuals;
156 int ndepths;
157 int rootdepth;
158 VisualID defaultVisual;
159 int imagebpp = bpp;
160
161#ifdef FB_DEBUG
162 int stride;
163
164 ysize -= 2;
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);
170#endif
171 /*
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
176 */
177 if (bpp == 24) {
178 int f;
179
180 imagebpp = 32;
181 /*
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
184 * format.
185 */
186 for (f = 0; f < screenInfo.numPixmapFormats; f++) {
187 if (screenInfo.formats[f].bitsPerPixel == 24) {
188 imagebpp = 24;
189 break;
190 }
191 }
192 }
193 if (imagebpp == 32) {
194 fbGetScreenPrivate(pScreen)->win32bpp = bpp;
195 fbGetScreenPrivate(pScreen)->pix32bpp = bpp;
196 }
197 else {
198 fbGetScreenPrivate(pScreen)->win32bpp = 32;
199 fbGetScreenPrivate(pScreen)->pix32bpp = 32;
200 }
201#ifdef FB_ACCESS_WRAPPER
202 fbGetScreenPrivate(pScreen)->setupWrap = setupWrap;
203 fbGetScreenPrivate(pScreen)->finishWrap = finishWrap;
204#endif
205 rootdepth = 0;
206 if (!fbInitVisuals(&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
207 &defaultVisual, ((unsigned long) 1 << (imagebpp - 1)),
208 8))
209 return FALSE;
210 if (!miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
211 rootdepth, ndepths, depths,
212 defaultVisual, nvisuals, visuals))
213 return FALSE;
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;
219 }
220 return TRUE;
221}
222
223/* dts * (inch/dot) * (25.4 mm / inch) = mm */
224#ifdef FB_ACCESS_WRAPPER
225Bool
226wfbScreenInit(ScreenPtr pScreen,
227 pointer pbits,
228 int xsize,
229 int ysize,
230 int dpix,
231 int dpiy,
232 int width,
233 int bpp, SetupWrapProcPtr setupWrap, FinishWrapProcPtr finishWrap)
234{
235 if (!fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp))
236 return FALSE;
237 if (!wfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy,
238 width, bpp, setupWrap, finishWrap))
239 return FALSE;
240 return TRUE;
241}
242#else
243Bool
244fbScreenInit(ScreenPtr pScreen,
245 pointer pbits,
246 int xsize, int ysize, int dpix, int dpiy, int width, int bpp)
247{
248 if (!fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp))
249 return FALSE;
250 if (!fbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy,
251 width, bpp))
252 return FALSE;
253 return TRUE;
254}
255#endif