1 /* Copyright (C) 2000-2012 by George Williams */
2 /*
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are met:
5
6 * Redistributions of source code must retain the above copyright notice, this
7 * list of conditions and the following disclaimer.
8
9 * Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12
13 * The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
19 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
21 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
22 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
23 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
24 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
25 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #include <fontforge-config.h>
29
30 #include "gdrawP.h"
31 #include "ggadget.h"
32 #include "gwidgetP.h"
33
34 /* Temporarily do all drawing in this widget to a pixmap rather than the window */
35 /* if events are orderly then we can share one pixmap for all windows */
36 static GWindow pixmap, cairo_pixmap;
37 /* otherwise we create and destroy pixmaps */
38
_GWidget_GetPixmap(GWindow gw,GRect * rect)39 GWindow _GWidget_GetPixmap(GWindow gw,GRect *rect) {
40 #ifndef FONTFORGE_CAN_USE_GDK
41 GWindow ours;
42
43 if ( gw->display!=screen_display )
44 return( gw );
45 if ( gw->is_pixmap )
46 return( gw );
47 #ifdef UsingPThreads
48 this is a critical section if there are multiple pthreads
49 #endif
50 if ( GDrawHasCairo(gw)&gc_alpha ) {
51 if ( cairo_pixmap==NULL || cairo_pixmap->pos.width<rect->x+rect->width ||
52 cairo_pixmap->pos.height<rect->y+rect->height ) {
53 if ( cairo_pixmap!=NULL )
54 GDrawDestroyWindow(cairo_pixmap);
55 /* The 0x8000 on width is a hack to tell create pixmap to use*/
56 /* cairo convas */
57 cairo_pixmap = GDrawCreatePixmap(gw->display,gw,0x8000|gw->pos.width,gw->pos.height);
58 }
59 ours = cairo_pixmap;
60 cairo_pixmap = NULL;
61 } else {
62 if ( pixmap==NULL || pixmap->pos.width<rect->x+rect->width ||
63 pixmap->pos.height<rect->y+rect->height ) {
64 if ( pixmap!=NULL )
65 GDrawDestroyWindow(pixmap);
66 pixmap = GDrawCreatePixmap(gw->display,gw,gw->pos.width,gw->pos.height);
67 }
68 ours = pixmap;
69 pixmap = NULL;
70 }
71 #ifdef UsingPThreads
72 End critical section
73 #endif
74 if ( ours==NULL )
75 ours = gw;
76 else {
77 GWidgetD *gd = (GWidgetD *) (gw->widget_data);
78 ours->widget_data = gd;
79 gd->w = ours;
80 GDrawFillRect(ours,rect,gw->ggc->bg);
81 }
82 return( ours );
83 #else
84 GDrawFillRect(gw, rect, gw->ggc->bg);
85 return gw;
86 #endif /* FONTFORGE_CAN_USE_GDK */
87 }
88
_GWidget_RestorePixmap(GWindow gw,GWindow ours,GRect * rect)89 void _GWidget_RestorePixmap(GWindow gw, GWindow ours, GRect *rect) {
90 #ifndef FONTFORGE_CAN_USE_GDK
91 GWidgetD *gd = (GWidgetD *) (gw->widget_data);
92
93 if ( gw==ours )
94 return; /* it wasn't a pixmap, all drawing was to real window */
95 GDrawDrawPixmap(gw, ours, rect, rect->x, rect->y);
96
97 #ifdef UsingPThreads
98 this is a critical section if there are multiple pthreads
99 #endif
100 if ( GDrawHasCairo(gw)&gc_alpha ) {
101 if ( cairo_pixmap!=NULL )
102 GDrawDestroyWindow(ours);
103 else {
104 cairo_pixmap = ours;
105 ours->widget_data = NULL;
106 }
107 } else {
108 if ( pixmap!=NULL )
109 GDrawDestroyWindow(ours);
110 else {
111 pixmap = ours;
112 ours->widget_data = NULL;
113 }
114 }
115 gd->w = gw;
116 #ifdef UsingPThreads
117 End critical section
118 #endif
119 #endif /* FONTFORGE_CAN_USE_GDK */
120 }
121