1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
22 #include <Xw_Extension.h>
24 #ifdef HAVE_X11_EXTENSIONS_MULTIBUF_H
25 # include <X11/extensions/multibuf.h>
28 /* ifdef then trace on */
30 #define TRACE_OPEN_PIXMAP
31 #define TRACE_OPEN_BACKGROUND_PIXMAP
32 #define TRACE_CLOSE_PIXMAP
33 #define TRACE_CLOSE_BACKGROUND_PIXMAP
37 XW_STATUS Xw_open_pixmap (awindow)
38 XW_EXT_WINDOW *awindow
40 Open a DoubleBuffer PIXMAP depending of the Window size
42 returns ERROR if NO More PIXMAP is available on this Window
43 returns SUCCESS if successful
45 XW_STATUS Xw_open_background_pixmap (awindow)
46 XW_EXT_WINDOW *awindow
48 Open a Background PIXMAP depending of the Window size
50 returns ERROR if NO More PIXMAP is available on this Window
51 returns SUCCESS if successful
53 XW_STATUS Xw_close_pixmap (awindow)
54 XW_EXT_WINDOW *awindow
56 Close the DoubleBuffer PIXMAP attached to this Window
58 returns ERROR if NO More PIXMAP exist
59 returns SUCCESS if successful
61 XW_STATUS Xw_close_background_pixmap (awindow)
62 XW_EXT_WINDOW *awindow
64 Close the Background PIXMAP attached to this Window
66 returns ERROR if NO More PIXMAP exist
67 returns SUCCESS if successful
70 static char SetDoubleBuffer = '\0' ;
73 XW_STATUS Xw_open_pixmap (void *awindow)
75 XW_STATUS Xw_open_pixmap (awindow)
77 #endif /*XW_PROTOTYPE*/
79 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
80 XW_EXT_DISPLAY *pdisplay = pwindow->connexion;
83 XW_STATUS status = XW_ERROR;
85 if( !Xw_isdefine_window(pwindow) ) {
86 /*ERROR*Bad EXT_WINDOW Address*/
87 Xw_set_error(24,"Xw_open_pixmap",pwindow) ;
91 if( SetDoubleBuffer == '\0' ) {
92 SetDoubleBuffer = 'U' ;
93 if( Xw_get_env("Xw_SET_DOUBLE_BUFFER",svalue,sizeof(svalue)) ) {
94 if( strlen(svalue) ) {
95 SetDoubleBuffer = svalue[0] ;
97 printf(" Xw_SET_DOUBLE_BUFFER is '%c'\n",SetDoubleBuffer) ;
101 if( (SetDoubleBuffer == 'B') &&
102 (pdisplay->server == XW_SERVER_IS_SUN) && (_DEPTH != 24) ) {
103 SetDoubleBuffer = 'P'; /* BUG sur SUN */
104 /*WARNING*MultiBufferingExtension is not accessible here*/
105 Xw_set_error(126,"Xw_open_pixmap",pwindow) ;
108 #ifndef HAVE_X11_EXTENSIONS_MULTIBUF_H
109 if( SetDoubleBuffer == 'B' ) {
110 SetDoubleBuffer = 'P'; /* MULTIBUF unavailable under SGI IRIX 6.5 */
111 /*WARNING*MultiBufferingExtension is not accessible here*/
112 Xw_set_error(126,"Xw_open_pixmap",pwindow) ;
115 if( SetDoubleBuffer == 'B' ) {
116 if( _NWBUFFER == 0 ) {
117 int mOptCode,fEvent,fError,maxmono,maxstereo ;
118 XmbufBufferInfo *pmono,*pstereo ;
119 if( XQueryExtension(_DISPLAY,"Multi-Buffering",
120 &mOptCode,&fEvent,&fError) &&
121 XmbufGetScreenInfo(_DISPLAY,_WINDOW,
122 &maxmono,&pmono,&maxstereo,&pstereo) ) {
123 _NWBUFFER = XmbufCreateBuffers(_DISPLAY,_WINDOW,2,
124 MultibufferUpdateActionUntouched,
125 MultibufferUpdateHintFrequent,
128 if( _NWBUFFER == 2 ) {
129 XFillRectangle(_DISPLAY,_BWBUFFER,pwindow->qgwind.gcclear,
130 0,0,_WIDTH,_HEIGHT) ;
132 if( _NWBUFFER > 0 ) XmbufDestroyBuffers(_DISPLAY,_WINDOW) ;
137 SetDoubleBuffer = 'P';
138 /*WARNING*MultiBufferingExtension is not accessible here*/
139 Xw_set_error(126,"Xw_open_pixmap",pwindow) ;
144 if( (SetDoubleBuffer == 'U') ||
145 (SetDoubleBuffer == 'Y') ||
146 (SetDoubleBuffer == 'P') ) {
149 if( !Xw_get_trace() ) Xw_set_synchronize(_DISPLAY,True) ;
150 _PIXMAP = XCreatePixmap(_DISPLAY,_WINDOW,_WIDTH,_HEIGHT,_DEPTH) ;
151 if( !Xw_get_trace() ) Xw_set_synchronize(_DISPLAY,False) ;
153 Xw_get_error(&error,&gravity);
154 if( _PIXMAP && (error < 1000) ) {
155 XFillRectangle(_DISPLAY,_PIXMAP,pwindow->qgwind.gcclear,
156 0,0,_WIDTH,_HEIGHT) ;
158 /*ERROR*DISABLE Double Buffer*/
160 Xw_set_error(71,"Xw_open_pixmap",0) ;
165 if( _PIXMAP || _NWBUFFER ) status = XW_SUCCESS;
167 #ifdef TRACE_OPEN_PIXMAP
168 if( Xw_get_trace() ) {
169 printf(" %d = Xw_open_pixmap(%lx)\n",status,(long ) pwindow) ;
177 XW_STATUS Xw_close_pixmap (void *awindow)
179 XW_STATUS Xw_close_pixmap (awindow)
181 #endif /*XW_PROTOTYPE*/
183 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
185 if( !Xw_isdefine_window(pwindow) ) {
186 /*ERROR*Bad EXT_WINDOW Address*/
187 Xw_set_error(24,"Xw_open_pixmap",pwindow) ;
191 #ifdef HAVE_X11_EXTENSIONS_MULTIBUF_H
192 if( _NWBUFFER > 0 ) XmbufDestroyBuffers(_DISPLAY,_WINDOW) ;
194 if( _PIXMAP ) XFreePixmap(_DISPLAY,_PIXMAP) ;
200 _DRAWABLE = _WINDOW ;
202 #ifdef TRACE_CLOSE_PIXMAP
203 if( Xw_get_trace() ) {
204 printf(" Xw_close_pixmap(%lx)\n",(long ) pwindow) ;
212 XW_STATUS Xw_open_background_pixmap (void *awindow)
214 XW_STATUS Xw_open_background_pixmap (awindow)
216 #endif /*XW_PROTOTYPE*/
218 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
221 if( !Xw_isdefine_window(pwindow) ) {
222 /*ERROR*Bad EXT_WINDOW Address*/
223 Xw_set_error(24,"Xw_open_background_pixmap",pwindow) ;
227 if( _BPIXMAP ) Xw_close_background_pixmap(awindow) ;
230 if( !Xw_get_trace() ) Xw_set_synchronize(_DISPLAY,True) ;
231 _BPIXMAP = XCreatePixmap(_DISPLAY,_WINDOW,_WIDTH,_HEIGHT,_DEPTH) ;
232 if( !Xw_get_trace() ) Xw_set_synchronize(_DISPLAY,False) ;
234 Xw_get_error(&error,&gravity);
235 if( !_BPIXMAP || (error >= 1000) ) {
236 /*ERROR*DISABLE Double Buffer*/
238 Xw_set_error(71,"Xw_open_background_pixmap",0) ;
242 XFillRectangle(_DISPLAY,_BPIXMAP,pwindow->qgwind.gcclear,0,0,_WIDTH,_HEIGHT);
244 #ifdef TRACE_OPEN_BACKGROUND_PIXMAP
245 if( Xw_get_trace() ) {
246 printf(" Xw_open_background_pixmap(%lx)\n",(long ) pwindow) ;
254 XW_STATUS Xw_close_background_pixmap (void *awindow)
256 XW_STATUS Xw_close_background_pixmap (awindow)
258 #endif /*XW_PROTOTYPE*/
260 XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
262 if( !Xw_isdefine_window(pwindow) ) {
263 /*ERROR*Bad EXT_WINDOW Address*/
264 Xw_set_error(24,"Xw_close_background_pixmap",pwindow) ;
269 XFreePixmap(_DISPLAY,_BPIXMAP) ;
276 #ifdef TRACE_CLOSE_BACKGROUND_PIXMAP
277 if( Xw_get_trace() ) {
278 printf(" Xw_close_background_pixmap(%lx)\n",(long ) pwindow) ;
281 return (XW_SUCCESS) ;