fbscreen.c 8.0 KB

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