miscrinit.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /*
  2. Copyright 1990, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included
  9. in all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  13. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  14. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  15. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  16. OTHER DEALINGS IN THE SOFTWARE.
  17. Except as contained in this notice, the name of The Open Group shall
  18. not be used in advertising or otherwise to promote the sale, use or
  19. other dealings in this Software without prior written authorization
  20. from The Open Group.
  21. */
  22. #ifdef HAVE_DIX_CONFIG_H
  23. #include <dix-config.h>
  24. #endif
  25. #include <X11/X.h>
  26. #include "servermd.h"
  27. #include "misc.h"
  28. #include "mi.h"
  29. #include "scrnintstr.h"
  30. #include "pixmapstr.h"
  31. #include "dix.h"
  32. #include "miline.h"
  33. #define _XSHM_SERVER_
  34. #include <X11/extensions/XShm.h>
  35. #include "shmint.h"
  36. /* We use this structure to propogate some information from miScreenInit to
  37. * miCreateScreenResources. miScreenInit allocates the structure, fills it
  38. * in, and puts it into pScreen->devPrivate. miCreateScreenResources
  39. * extracts the info and frees the structure. We could've accomplished the
  40. * same thing by adding fields to the screen structure, but they would have
  41. * ended up being redundant, and would have exposed this mi implementation
  42. * detail to the whole server.
  43. */
  44. typedef struct
  45. {
  46. pointer pbits; /* pointer to framebuffer */
  47. int width; /* delta to add to a framebuffer addr to move one row down */
  48. } miScreenInitParmsRec, *miScreenInitParmsPtr;
  49. /* this plugs into pScreen->ModifyPixmapHeader */
  50. _X_EXPORT Bool
  51. miModifyPixmapHeader(pPixmap, width, height, depth, bitsPerPixel, devKind,
  52. pPixData)
  53. PixmapPtr pPixmap;
  54. int width;
  55. int height;
  56. int depth;
  57. int bitsPerPixel;
  58. int devKind;
  59. pointer pPixData;
  60. {
  61. if (!pPixmap)
  62. return FALSE;
  63. /*
  64. * If all arguments are specified, reinitialize everything (including
  65. * validated state).
  66. */
  67. if ((width > 0) && (height > 0) && (depth > 0) && (bitsPerPixel > 0) &&
  68. (devKind > 0) && pPixData) {
  69. pPixmap->drawable.depth = depth;
  70. pPixmap->drawable.bitsPerPixel = bitsPerPixel;
  71. pPixmap->drawable.id = 0;
  72. pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
  73. pPixmap->drawable.x = 0;
  74. pPixmap->drawable.y = 0;
  75. pPixmap->drawable.width = width;
  76. pPixmap->drawable.height = height;
  77. pPixmap->devKind = devKind;
  78. pPixmap->refcnt = 1;
  79. pPixmap->devPrivate.ptr = pPixData;
  80. } else {
  81. /*
  82. * Only modify specified fields, keeping all others intact.
  83. */
  84. if (width > 0)
  85. pPixmap->drawable.width = width;
  86. if (height > 0)
  87. pPixmap->drawable.height = height;
  88. if (depth > 0)
  89. pPixmap->drawable.depth = depth;
  90. if (bitsPerPixel > 0)
  91. pPixmap->drawable.bitsPerPixel = bitsPerPixel;
  92. else if ((bitsPerPixel < 0) && (depth > 0))
  93. pPixmap->drawable.bitsPerPixel = BitsPerPixel(depth);
  94. /*
  95. * CAVEAT: Non-SI DDXen may use devKind and devPrivate fields for
  96. * other purposes.
  97. */
  98. if (devKind > 0)
  99. pPixmap->devKind = devKind;
  100. else if ((devKind < 0) && ((width > 0) || (depth > 0)))
  101. pPixmap->devKind = PixmapBytePad(pPixmap->drawable.width,
  102. pPixmap->drawable.depth);
  103. if (pPixData)
  104. pPixmap->devPrivate.ptr = pPixData;
  105. }
  106. return TRUE;
  107. }
  108. /*ARGSUSED*/
  109. Bool
  110. miCloseScreen (iScreen, pScreen)
  111. int iScreen;
  112. ScreenPtr pScreen;
  113. {
  114. return ((*pScreen->DestroyPixmap)((PixmapPtr)pScreen->devPrivate));
  115. }
  116. /* With the introduction of pixmap privates, the "screen pixmap" can no
  117. * longer be created in miScreenInit, since all the modules that could
  118. * possibly ask for pixmap private space have not been initialized at
  119. * that time. pScreen->CreateScreenResources is called after all
  120. * possible private-requesting modules have been inited; we create the
  121. * screen pixmap here.
  122. */
  123. _X_EXPORT Bool
  124. miCreateScreenResources(pScreen)
  125. ScreenPtr pScreen;
  126. {
  127. miScreenInitParmsPtr pScrInitParms;
  128. pointer value;
  129. pScrInitParms = (miScreenInitParmsPtr)pScreen->devPrivate;
  130. /* if width is non-zero, pScreen->devPrivate will be a pixmap
  131. * else it will just take the value pbits
  132. */
  133. if (pScrInitParms->width)
  134. {
  135. PixmapPtr pPixmap;
  136. /* create a pixmap with no data, then redirect it to point to
  137. * the screen
  138. */
  139. pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, pScreen->rootDepth);
  140. if (!pPixmap)
  141. return FALSE;
  142. if (!(*pScreen->ModifyPixmapHeader)(pPixmap, pScreen->width,
  143. pScreen->height, pScreen->rootDepth,
  144. BitsPerPixel(pScreen->rootDepth),
  145. PixmapBytePad(pScrInitParms->width, pScreen->rootDepth),
  146. pScrInitParms->pbits))
  147. return FALSE;
  148. value = (pointer)pPixmap;
  149. }
  150. else
  151. {
  152. value = pScrInitParms->pbits;
  153. }
  154. free(pScreen->devPrivate); /* freeing miScreenInitParmsRec */
  155. pScreen->devPrivate = value; /* pPixmap or pbits */
  156. return TRUE;
  157. }
  158. Bool
  159. miScreenDevPrivateInit(pScreen, width, pbits)
  160. ScreenPtr pScreen;
  161. int width;
  162. pointer pbits;
  163. {
  164. miScreenInitParmsPtr pScrInitParms;
  165. /* Stash pbits and width in a short-lived miScreenInitParmsRec attached
  166. * to the screen, until CreateScreenResources can put them in the
  167. * screen pixmap.
  168. */
  169. pScrInitParms = (miScreenInitParmsPtr)malloc(sizeof(miScreenInitParmsRec));
  170. if (!pScrInitParms)
  171. return FALSE;
  172. pScrInitParms->pbits = pbits;
  173. pScrInitParms->width = width;
  174. pScreen->devPrivate = (pointer)pScrInitParms;
  175. return TRUE;
  176. }
  177. _X_EXPORT Bool
  178. miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
  179. rootDepth, numDepths, depths, rootVisual, numVisuals, visuals)
  180. ScreenPtr pScreen;
  181. pointer pbits; /* pointer to screen bits */
  182. int xsize, ysize; /* in pixels */
  183. int dpix, dpiy; /* dots per inch */
  184. int width; /* pixel width of frame buffer */
  185. int rootDepth; /* depth of root window */
  186. int numDepths; /* number of depths supported */
  187. DepthRec *depths; /* supported depths */
  188. VisualID rootVisual; /* root visual */
  189. int numVisuals; /* number of visuals supported */
  190. VisualRec *visuals; /* supported visuals */
  191. {
  192. pScreen->width = xsize;
  193. pScreen->height = ysize;
  194. pScreen->mmWidth = (xsize * 254 + dpix * 5) / (dpix * 10);
  195. pScreen->mmHeight = (ysize * 254 + dpiy * 5) / (dpiy * 10);
  196. pScreen->numDepths = numDepths;
  197. pScreen->rootDepth = rootDepth;
  198. pScreen->allowedDepths = depths;
  199. pScreen->rootVisual = rootVisual;
  200. /* defColormap */
  201. pScreen->minInstalledCmaps = 1;
  202. pScreen->maxInstalledCmaps = 1;
  203. pScreen->backingStoreSupport = NotUseful;
  204. pScreen->saveUnderSupport = NotUseful;
  205. /* whitePixel, blackPixel */
  206. pScreen->ModifyPixmapHeader = miModifyPixmapHeader;
  207. pScreen->CreateScreenResources = miCreateScreenResources;
  208. pScreen->GetScreenPixmap = miGetScreenPixmap;
  209. pScreen->SetScreenPixmap = miSetScreenPixmap;
  210. pScreen->numVisuals = numVisuals;
  211. pScreen->visuals = visuals;
  212. if (width)
  213. {
  214. ShmRegisterFbFuncs(pScreen);
  215. pScreen->CloseScreen = miCloseScreen;
  216. }
  217. /* else CloseScreen */
  218. /* QueryBestSize, SaveScreen, GetImage, GetSpans */
  219. pScreen->PointerNonInterestBox = (PointerNonInterestBoxProcPtr) 0;
  220. pScreen->SourceValidate = (SourceValidateProcPtr) 0;
  221. /* CreateWindow, DestroyWindow, PositionWindow, ChangeWindowAttributes */
  222. /* RealizeWindow, UnrealizeWindow */
  223. pScreen->ValidateTree = miValidateTree;
  224. pScreen->PostValidateTree = (PostValidateTreeProcPtr) 0;
  225. pScreen->WindowExposures = miWindowExposures;
  226. /* PaintWindowBackground, PaintWindowBorder, CopyWindow */
  227. pScreen->ClearToBackground = miClearToBackground;
  228. pScreen->ClipNotify = (ClipNotifyProcPtr) 0;
  229. pScreen->RestackWindow = (RestackWindowProcPtr) 0;
  230. /* CreatePixmap, DestroyPixmap */
  231. /* RealizeFont, UnrealizeFont */
  232. /* CreateGC */
  233. /* CreateColormap, DestroyColormap, InstallColormap, UninstallColormap */
  234. /* ListInstalledColormaps, StoreColors, ResolveColor */
  235. /* BitmapToRegion */
  236. pScreen->SendGraphicsExpose = miSendGraphicsExpose;
  237. pScreen->BlockHandler = (ScreenBlockHandlerProcPtr)NoopDDA;
  238. pScreen->WakeupHandler = (ScreenWakeupHandlerProcPtr)NoopDDA;
  239. pScreen->blockData = (pointer)0;
  240. pScreen->wakeupData = (pointer)0;
  241. pScreen->MarkWindow = miMarkWindow;
  242. pScreen->MarkOverlappedWindows = miMarkOverlappedWindows;
  243. pScreen->MoveWindow = miMoveWindow;
  244. pScreen->ResizeWindow = miSlideAndSizeWindow;
  245. pScreen->GetLayerWindow = miGetLayerWindow;
  246. pScreen->HandleExposures = miHandleValidateExposures;
  247. pScreen->ReparentWindow = (ReparentWindowProcPtr) 0;
  248. pScreen->ChangeBorderWidth = miChangeBorderWidth;
  249. pScreen->SetShape = miSetShape;
  250. pScreen->MarkUnrealizedWindow = miMarkUnrealizedWindow;
  251. miSetZeroLineBias(pScreen, DEFAULTZEROLINEBIAS);
  252. return miScreenDevPrivateInit(pScreen, width, pbits);
  253. }
  254. _X_EXPORT int
  255. miAllocateGCPrivateIndex()
  256. {
  257. static int privateIndex = -1;
  258. static unsigned long miGeneration = 0;
  259. if (miGeneration != serverGeneration)
  260. {
  261. privateIndex = AllocateGCPrivateIndex();
  262. miGeneration = serverGeneration;
  263. }
  264. return privateIndex;
  265. }
  266. _X_EXPORT int miZeroLineScreenIndex;
  267. unsigned int miZeroLineGeneration = 0;
  268. _X_EXPORT void
  269. miSetZeroLineBias(pScreen, bias)
  270. ScreenPtr pScreen;
  271. unsigned int bias;
  272. {
  273. if (miZeroLineGeneration != serverGeneration)
  274. {
  275. miZeroLineScreenIndex = AllocateScreenPrivateIndex();
  276. miZeroLineGeneration = serverGeneration;
  277. }
  278. if (miZeroLineScreenIndex >= 0)
  279. pScreen->devPrivates[miZeroLineScreenIndex].uval = bias;
  280. }
  281. _X_EXPORT PixmapPtr
  282. miGetScreenPixmap(pScreen)
  283. ScreenPtr pScreen;
  284. {
  285. return (PixmapPtr)(pScreen->devPrivate);
  286. }
  287. _X_EXPORT void
  288. miSetScreenPixmap(pPix)
  289. PixmapPtr pPix;
  290. {
  291. if (pPix)
  292. pPix->drawable.pScreen->devPrivate = (pointer)pPix;
  293. }