GrayPixmap.c revision 6c321187
1/* $Xorg: GrayPixmap.c,v 1.4 2001/02/09 02:03:52 xorgcvs Exp $ */ 2 3/* 4 5Copyright 1987, 1988, 1998 The Open Group 6 7Permission to use, copy, modify, distribute, and sell this software and its 8documentation for any purpose is hereby granted without fee, provided that 9the above copyright notice appear in all copies and that both that 10copyright notice and this permission notice appear in supporting 11documentation. 12 13The above copyright notice and this permission notice shall be included in 14all copies or substantial portions of the Software. 15 16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 20AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 21CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 23Except as contained in this notice, the name of The Open Group shall not be 24used in advertising or otherwise to promote the sale, use or other dealings 25in this Software without prior written authorization from The Open Group. 26 27*/ 28 29/*********************************************************** 30 31Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. 32 33 All Rights Reserved 34 35Permission to use, copy, modify, and distribute this software and its 36documentation for any purpose and without fee is hereby granted, 37provided that the above copyright notice appear in all copies and that 38both that copyright notice and this permission notice appear in 39supporting documentation, and that the name of Digital not be 40used in advertising or publicity pertaining to distribution of the 41software without specific, written prior permission. 42 43DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 44ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 45DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 46ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 47WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 48ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 49SOFTWARE. 50 51******************************************************************/ 52/* $XFree86: xc/lib/Xmu/GrayPixmap.c,v 1.5 2001/01/17 19:42:55 dawes Exp $ */ 53 54#ifdef HAVE_CONFIG_H 55#include <config.h> 56#endif 57#include <stdio.h> 58#include <X11/Intrinsic.h> 59#include <X11/Xmu/Drawing.h> 60 61typedef struct _PixmapCache { 62 Screen *screen; 63 Pixmap pixmap; 64 Pixel foreground, background; 65 unsigned int depth; 66 int ref_count; 67 struct _PixmapCache *next; 68 } CacheEntry; 69 70static CacheEntry *pixmapCache = NULL; 71 72 73 74Pixmap 75XmuCreateStippledPixmap(Screen *screen, Pixel fore, Pixel back, 76 unsigned int depth) 77/* 78 * Creates a stippled pixmap of specified depth 79 * caches these so that multiple requests share the pixmap 80 */ 81{ 82 register Display *display = DisplayOfScreen(screen); 83 CacheEntry *cachePtr; 84 Pixmap stippled_pixmap; 85 static unsigned char pixmap_bits[] = { 86 0x02, 0x01, 87 }; 88 89/* 90 * Creates a stippled pixmap of depth DefaultDepth(screen) 91 * caches these so that multiple requests share the pixmap 92 */ 93 94#define pixmap_width 2 95#define pixmap_height 2 96 97 /* see if we already have a pixmap suitable for this screen */ 98 for (cachePtr = pixmapCache; cachePtr; cachePtr = cachePtr->next) { 99 if (cachePtr->screen == screen && cachePtr->foreground == fore && 100 cachePtr->background == back && cachePtr->depth == depth) 101 return( cachePtr->ref_count++, cachePtr->pixmap ); 102 } 103 104 stippled_pixmap = XCreatePixmapFromBitmapData (display, 105 RootWindowOfScreen(screen), (char *)pixmap_bits, 106 pixmap_width, pixmap_height, fore, back, depth); 107 108 /* and insert it at the head of the cache */ 109 cachePtr = XtNew(CacheEntry); 110 cachePtr->screen = screen; 111 cachePtr->foreground = fore; 112 cachePtr->background = back; 113 cachePtr->depth = depth; 114 cachePtr->pixmap = stippled_pixmap; 115 cachePtr->ref_count = 1; 116 cachePtr->next = pixmapCache; 117 pixmapCache = cachePtr; 118 119 return( stippled_pixmap ); 120} 121 122void 123XmuReleaseStippledPixmap(Screen *screen, Pixmap pixmap) 124{ 125 register Display *display = DisplayOfScreen(screen); 126 CacheEntry *cachePtr, **prevP; 127 for (prevP = &pixmapCache, cachePtr = pixmapCache; cachePtr;) { 128 if (cachePtr->screen == screen && cachePtr->pixmap == pixmap) { 129 if (--cachePtr->ref_count == 0) { 130 XFreePixmap( display, pixmap ); 131 *prevP = cachePtr->next; 132 XtFree( (char*)cachePtr ); 133 break; 134 } 135 } 136 prevP = &cachePtr->next; 137 cachePtr = *prevP; 138 } 139} 140