00001 /* $Xorg: GrayPixmap.c,v 1.4 2001/02/09 02:03:52 xorgcvs Exp $ */ 00002 00003 /* 00004 00005 Copyright 1987, 1988, 1998 The Open Group 00006 00007 Permission to use, copy, modify, distribute, and sell this software and its 00008 documentation for any purpose is hereby granted without fee, provided that 00009 the above copyright notice appear in all copies and that both that 00010 copyright notice and this permission notice appear in supporting 00011 documentation. 00012 00013 The above copyright notice and this permission notice shall be included in 00014 all copies or substantial portions of the Software. 00015 00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 00019 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00020 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00021 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00022 00023 Except as contained in this notice, the name of The Open Group shall not be 00024 used in advertising or otherwise to promote the sale, use or other dealings 00025 in this Software without prior written authorization from The Open Group. 00026 00027 */ 00028 00029 /*********************************************************** 00030 00031 Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts. 00032 00033 All Rights Reserved 00034 00035 Permission to use, copy, modify, and distribute this software and its 00036 documentation for any purpose and without fee is hereby granted, 00037 provided that the above copyright notice appear in all copies and that 00038 both that copyright notice and this permission notice appear in 00039 supporting documentation, and that the name of Digital not be 00040 used in advertising or publicity pertaining to distribution of the 00041 software without specific, written prior permission. 00042 00043 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 00044 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 00045 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 00046 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 00047 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 00048 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 00049 SOFTWARE. 00050 00051 ******************************************************************/ 00052 /* $XFree86: xc/lib/Xmu/GrayPixmap.c,v 1.5 2001/01/17 19:42:55 dawes Exp $ */ 00053 00054 #include <stdio.h> 00055 #include <X11/Intrinsic.h> 00056 #include <X11/Xmu/Drawing.h> 00057 00058 typedef struct _PixmapCache { 00059 Screen *screen; 00060 Pixmap pixmap; 00061 Pixel foreground, background; 00062 unsigned int depth; 00063 int ref_count; 00064 struct _PixmapCache *next; 00065 } CacheEntry; 00066 00067 static CacheEntry *pixmapCache = NULL; 00068 00069 00070 00071 Pixmap 00072 XmuCreateStippledPixmap(Screen *screen, Pixel fore, Pixel back, 00073 unsigned int depth) 00074 /* 00075 * Creates a stippled pixmap of specified depth 00076 * caches these so that multiple requests share the pixmap 00077 */ 00078 { 00079 register Display *display = DisplayOfScreen(screen); 00080 CacheEntry *cachePtr; 00081 Pixmap stippled_pixmap; 00082 static unsigned char pixmap_bits[] = { 00083 0x02, 0x01, 00084 }; 00085 00086 /* 00087 * Creates a stippled pixmap of depth DefaultDepth(screen) 00088 * caches these so that multiple requests share the pixmap 00089 */ 00090 00091 #define pixmap_width 2 00092 #define pixmap_height 2 00093 00094 /* see if we already have a pixmap suitable for this screen */ 00095 for (cachePtr = pixmapCache; cachePtr; cachePtr = cachePtr->next) { 00096 if (cachePtr->screen == screen && cachePtr->foreground == fore && 00097 cachePtr->background == back && cachePtr->depth == depth) 00098 return( cachePtr->ref_count++, cachePtr->pixmap ); 00099 } 00100 00101 stippled_pixmap = XCreatePixmapFromBitmapData (display, 00102 RootWindowOfScreen(screen), (char *)pixmap_bits, 00103 pixmap_width, pixmap_height, fore, back, depth); 00104 00105 /* and insert it at the head of the cache */ 00106 cachePtr = XtNew(CacheEntry); 00107 cachePtr->screen = screen; 00108 cachePtr->foreground = fore; 00109 cachePtr->background = back; 00110 cachePtr->depth = depth; 00111 cachePtr->pixmap = stippled_pixmap; 00112 cachePtr->ref_count = 1; 00113 cachePtr->next = pixmapCache; 00114 pixmapCache = cachePtr; 00115 00116 return( stippled_pixmap ); 00117 } 00118 00119 void 00120 XmuReleaseStippledPixmap(Screen *screen, Pixmap pixmap) 00121 { 00122 register Display *display = DisplayOfScreen(screen); 00123 CacheEntry *cachePtr, **prevP; 00124 for (prevP = &pixmapCache, cachePtr = pixmapCache; cachePtr;) { 00125 if (cachePtr->screen == screen && cachePtr->pixmap == pixmap) { 00126 if (--cachePtr->ref_count == 0) { 00127 XFreePixmap( display, pixmap ); 00128 *prevP = cachePtr->next; 00129 XtFree( (char*)cachePtr ); 00130 break; 00131 } 00132 } 00133 prevP = &cachePtr->next; 00134 cachePtr = *prevP; 00135 } 00136 }
1.5.1