pixmap.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. Copyright 1993, 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 "scrnintstr.h"
  27. #include "misc.h"
  28. #include "os.h"
  29. #include "windowstr.h"
  30. #include "resource.h"
  31. #include "dixstruct.h"
  32. #include "gcstruct.h"
  33. #include "servermd.h"
  34. #include "site.h"
  35. /*
  36. * Scratch pixmap management and device independent pixmap allocation
  37. * function.
  38. */
  39. /* callable by ddx */
  40. _X_EXPORT PixmapPtr
  41. GetScratchPixmapHeader(ScreenPtr pScreen, int width, int height, int depth,
  42. int bitsPerPixel, int devKind, pointer pPixData)
  43. {
  44. PixmapPtr pPixmap = pScreen->pScratchPixmap;
  45. if (pPixmap)
  46. pScreen->pScratchPixmap = NULL;
  47. else
  48. /* width and height of 0 means don't allocate any pixmap data */
  49. pPixmap = (*pScreen->CreatePixmap) (pScreen, 0, 0, depth);
  50. if (pPixmap) {
  51. if ((*pScreen->ModifyPixmapHeader) (pPixmap, width, height, depth,
  52. bitsPerPixel, devKind, pPixData))
  53. return pPixmap;
  54. (*pScreen->DestroyPixmap) (pPixmap);
  55. }
  56. return NullPixmap;
  57. }
  58. /* callable by ddx */
  59. _X_EXPORT void
  60. FreeScratchPixmapHeader(PixmapPtr pPixmap)
  61. {
  62. if (pPixmap) {
  63. ScreenPtr pScreen = pPixmap->drawable.pScreen;
  64. pPixmap->devPrivate.ptr = NULL; /* lest ddx chases bad ptr */
  65. if (pScreen->pScratchPixmap)
  66. (*pScreen->DestroyPixmap) (pPixmap);
  67. else
  68. pScreen->pScratchPixmap = pPixmap;
  69. }
  70. }
  71. Bool
  72. CreateScratchPixmapsForScreen(int scrnum)
  73. {
  74. /* let it be created on first use */
  75. screenInfo.screens[scrnum]->pScratchPixmap = NULL;
  76. return TRUE;
  77. }
  78. void
  79. FreeScratchPixmapsForScreen(int scrnum)
  80. {
  81. FreeScratchPixmapHeader(screenInfo.screens[scrnum]->pScratchPixmap);
  82. }
  83. /* callable by ddx */
  84. _X_EXPORT PixmapPtr
  85. AllocatePixmap(ScreenPtr pScreen, int pixDataSize)
  86. {
  87. PixmapPtr pPixmap;
  88. char *ptr;
  89. DevUnion *ppriv;
  90. unsigned *sizes;
  91. unsigned size;
  92. int i;
  93. if (pScreen->totalPixmapSize > ((size_t) - 1) - pixDataSize)
  94. return NullPixmap;
  95. pPixmap = calloc(1, pScreen->totalPixmapSize + pixDataSize);
  96. if (!pPixmap)
  97. return NullPixmap;
  98. ppriv = (DevUnion *) (pPixmap + 1);
  99. pPixmap->devPrivates = ppriv;
  100. sizes = pScreen->PixmapPrivateSizes;
  101. ptr = (char *) (ppriv + pScreen->PixmapPrivateLen);
  102. for (i = pScreen->PixmapPrivateLen; --i >= 0; ppriv++, sizes++) {
  103. if ((size = *sizes) != 0) {
  104. ppriv->ptr = (pointer) ptr;
  105. ptr += size;
  106. }
  107. else
  108. ppriv->ptr = (pointer) NULL;
  109. }
  110. #ifdef _XSERVER64
  111. if (pPixmap) {
  112. pPixmap->drawable.pad0 = 0;
  113. pPixmap->drawable.pad1 = 0;
  114. }
  115. #endif
  116. return pPixmap;
  117. }