fbscreen.c 6.6 KB

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