2 /* Copyright (C) 2002 Olivier Chapuis */
3 /* This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 /* ---------------------------- included header files ---------------------- */
27 #include "PictureBase.h"
29 #include "FRenderInit.h"
30 #include "FRenderInterface.h"
32 #include "PictureGraphics.h"
33 #include "PictureUtils.h"
37 /* ---------------------------- local definitions -------------------------- */
39 /* ---------------------------- local macros ------------------------------- */
41 /* ---------------------------- imports ------------------------------------ */
43 /* ---------------------------- included code files ------------------------ */
45 /* ---------------------------- local types -------------------------------- */
47 /* ---------------------------- forward declarations ----------------------- */
49 /* ---------------------------- local variables ---------------------------- */
51 static Bool PGrabImageError
= True
;
53 /* ---------------------------- exported variables (globals) --------------- */
55 /* ---------------------------- local functions ---------------------------- */
57 int FSetBackingStore(Display
*dpy
, Window win
, int backing_store
)
59 XWindowAttributes attributes
;
60 XSetWindowAttributes set_attributes
;
63 XGetWindowAttributes(dpy
, win
, &attributes
);
64 if (attributes
.backing_store
== backing_store
)
68 old_bs
= attributes
.backing_store
;
69 set_attributes
.backing_store
= backing_store
;
70 XChangeWindowAttributes(dpy
, win
, CWBackingStore
, &set_attributes
);
75 void PCopyArea(Display
*dpy
, Pixmap pixmap
, Pixmap mask
, int depth
,
77 int src_x
, int src_y
, int src_w
, int src_h
,
78 int dest_x
, int dest_y
)
86 my_gc
= fvwmlib_XCreateGC(dpy
, d
, 0, NULL
);
88 gcm
= GCClipMask
| GCClipXOrigin
| GCClipYOrigin
;
89 gcv
.clip_x_origin
= dest_x
- src_x
; /* */
90 gcv
.clip_y_origin
= dest_y
- src_y
; /* */
96 XChangeGC(dpy
,my_gc
,gcm
,&gcv
);
100 XChangeGC(dpy
,gc
,gcm
,&gcv
);
102 XCopyArea(dpy
, pixmap
, d
,
103 (my_gc
!= None
)? my_gc
:gc
,
104 src_x
, src_y
, src_w
, src_h
,
109 /* monochrome bitmap */
110 gcv
.clip_mask
= mask
;
113 gcv
.foreground
= PictureWhitePixel();
114 gcv
.background
= PictureBlackPixel();
115 gcm
|= GCBackground
|GCForeground
;
116 XChangeGC(dpy
,my_gc
,gcm
,&gcv
);
120 XChangeGC(dpy
,gc
,gcm
,&gcv
);
122 XCopyPlane(dpy
, pixmap
, d
,
123 (my_gc
!= None
)? my_gc
:gc
,
124 src_x
, src_y
, src_w
, src_h
,
134 gcv
.clip_mask
= None
;
135 XChangeGC(dpy
, gc
, gcm
, &gcv
);
140 void PTileRectangle(Display
*dpy
, Window win
, Pixmap pixmap
, Pixmap mask
,
142 int src_x
, int src_y
,
143 Drawable d
, GC gc
, GC mono_gc
,
144 int dest_x
, int dest_y
, int dest_w
, int dest_h
)
146 Pixmap tile_mask
= None
;
150 GC my_mono_gc
= None
;
154 my_gc
= fvwmlib_XCreateGC(dpy
, d
, 0, NULL
);
156 if (mono_gc
== None
&& (mask
!= None
|| Pdepth
!= depth
))
159 my_mono_gc
= fvwmlib_XCreateGC(dpy
, mask
, 0, NULL
);
160 else if (depth
!= Pdepth
)
161 my_mono_gc
= fvwmlib_XCreateGC(dpy
, pixmap
, 0, NULL
);
166 /* create a till mask */
167 tile_mask
= XCreatePixmap(dpy
, win
, dest_w
, dest_h
, 1);
169 gcv
.ts_x_origin
= src_x
;
170 gcv
.ts_y_origin
= src_y
;
171 gcv
.fill_style
= FillTiled
;
172 gcm
= GCFillStyle
| GCTileStipXOrigin
| GCTileStipYOrigin
|
176 XChangeGC(dpy
, mono_gc
, gcm
, &gcv
);
182 gcm
|= GCBackground
|GCForeground
;
183 XChangeGC(dpy
, my_mono_gc
, gcm
, &gcv
);
185 XFillRectangle(dpy
, tile_mask
,
186 (mono_gc
!= None
)? mono_gc
:my_mono_gc
,
187 src_x
, src_y
, dest_w
, dest_h
);
190 gcv
.fill_style
= FillSolid
;
192 XChangeGC(dpy
, mono_gc
, gcm
, &gcv
);
197 gcv
.ts_x_origin
= dest_x
- src_x
;
198 gcv
.ts_y_origin
= dest_y
- src_y
;
199 gcv
.fill_style
= FillTiled
;
200 gcm
= GCFillStyle
| GCTile
| GCTileStipXOrigin
| GCTileStipYOrigin
;
201 gcv
.clip_mask
= tile_mask
;
202 gcv
.clip_x_origin
= dest_x
;
203 gcv
.clip_y_origin
= dest_y
;;
204 gcm
|= GCClipMask
| GCClipXOrigin
| GCClipYOrigin
;
207 Pixmap my_pixmap
= None
;
210 (mono_gc
!= None
)? mono_gc
:my_mono_gc
, gcm
, &gcv
);
211 my_pixmap
= XCreatePixmap(dpy
, win
, dest_w
, dest_h
, 1);
212 XFillRectangle(dpy
, my_pixmap
,
213 (mono_gc
!= None
)? mono_gc
:my_mono_gc
,
214 0, 0, dest_w
, dest_h
);
215 gcv
.clip_mask
= my_pixmap
;
216 gcv
.fill_style
= FillSolid
;
217 gcm
= GCFillStyle
| GCClipMask
;
219 (mono_gc
!= None
)? mono_gc
:my_mono_gc
,
221 XCopyPlane(dpy
, my_pixmap
, d
,
222 (my_gc
!= None
)? my_gc
:gc
,
223 0, 0, dest_w
, dest_h
, dest_x
, dest_y
, 1);
224 if (my_pixmap
!= None
)
226 XFreePixmap(dpy
, my_pixmap
);
231 XChangeGC(dpy
, (gc
!= None
)? gc
:my_gc
, gcm
, &gcv
);
232 XFillRectangle(dpy
, d
,
233 (gc
!= None
)? gc
:my_gc
,
234 dest_x
, dest_y
, dest_w
, dest_h
);
242 gcv
.clip_mask
= None
;
243 gcv
.fill_style
= FillSolid
;
244 gcm
= GCFillStyle
| GCClipMask
;
245 XChangeGC(dpy
, gc
, gcm
, &gcv
);
247 if (my_mono_gc
!= None
)
249 XFreeGC(dpy
, my_mono_gc
);
251 else if (mono_gc
!= None
)
253 gcv
.clip_mask
= None
;
254 gcv
.fill_style
= FillSolid
;
255 gcm
= GCFillStyle
| GCClipMask
;
256 XChangeGC(dpy
, mono_gc
, gcm
, &gcv
);
258 if (tile_mask
!= None
)
260 XFreePixmap(dpy
, tile_mask
);
265 void PGrabImageErrorHandler(void)
267 PGrabImageError
= True
;
272 Display
*dpy
, Drawable d
, int x
, int y
, int w
, int h
, Bool d_is_a_window
)
275 Bool try_to_grab
= True
;
276 XWindowAttributes xwa
;
277 XErrorHandler saved_eh
= NULL
;
284 XGetWindowAttributes(dpy
, d
, &xwa
);
287 if (xwa
.map_state
!= IsViewable
&&
288 xwa
.backing_store
== NotUseful
)
292 fprintf(stderr
, "Bad attribute! %i,%i\n",
293 xwa
.map_state
!= IsViewable
,
294 xwa
.backing_store
== NotUseful
);
299 saved_eh
= XSetErrorHandler(
300 (XErrorHandler
) PGrabImageErrorHandler
);
302 fprintf(stderr
, "Attribute ok! %i,%i\n",
303 xwa
.map_state
!= IsViewable
,
304 xwa
.backing_store
== NotUseful
);
310 fim
= FGetFImage(dpy
, d
, Pvisual
, Pdepth
, x
, y
, w
, h
, AllPlanes
,
315 fprintf(stderr
, "XGetImage error during the grab\n");
319 FDestroyFImage(dpy
, fim
);
325 XSetErrorHandler((XErrorHandler
) saved_eh
);
331 MyXUngrabServer(dpy
);
337 Pixmap
PCreateRenderPixmap(
338 Display
*dpy
, Window win
, Pixmap pixmap
, Pixmap mask
, Pixmap alpha
,
339 int depth
, int added_alpha_percent
, Pixel tint
, int tint_percent
,
340 Bool d_is_a_window
, Drawable d
, GC gc
, GC mono_gc
, GC alpha_gc
,
341 int src_x
, int src_y
, int src_w
, int src_h
,
342 int dest_x
, int dest_y
, int dest_w
, int dest_h
, Bool do_repeat
,
343 int *new_w
, int *new_h
, Bool
*new_do_repeat
,
346 FImage
*pixmap_fim
= NULL
;
347 FImage
*mask_fim
= NULL
;
348 FImage
*alpha_fim
= NULL
;
349 FImage
*dest_fim
= NULL
;
350 FImage
*new_mask_fim
= NULL
;
351 FImage
*out_fim
= NULL
;
352 Pixmap pixmap_copy
= None
;
353 Pixmap src_pix
= None
;
354 Pixmap out_pix
= None
;
355 unsigned short *am
= NULL
;
356 XColor
*colors
= NULL
, *dest_colors
= NULL
;
357 XColor tint_color
, c
;
358 int w
,h
, n_src_w
, n_src_h
;
359 int j
, i
, j1
, i1
, m
= 0, k
= 0, l
= 0;
360 Bool do_free_mono_gc
= False
;
361 Bool make_new_mask
= False
;
365 *new_do_repeat
= do_repeat
;
369 pixmap_copy
= XCreatePixmap(dpy
, win
, src_w
, src_h
, Pdepth
);
372 gc
= PictureDefaultGC(dpy
, win
);
374 if (pixmap_copy
&& gc
)
377 dpy
, pixmap
, pixmap_copy
, gc
,
378 src_x
, src_y
, src_w
, src_h
,
388 src_pix
= (pixmap_copy
)? pixmap_copy
:pixmap
;
390 if (src_pix
== ParentRelative
)
392 pixmap_fim
= PGrabXImage(
393 dpy
, d
, dest_x
, dest_y
, dest_w
, dest_h
, d_is_a_window
);
397 pixmap_fim
= FGetFImage(
398 dpy
, src_pix
, Pvisual
, Pdepth
, src_x
, src_y
, src_w
,
399 src_h
, AllPlanes
, ZPixmap
);
408 mask_fim
= FGetFImage(
409 dpy
, mask
, Pvisual
, 1, src_x
, src_y
, src_w
, src_h
,
416 if (src_x
!= 0 || src_y
!= 0)
417 make_new_mask
= True
;
421 alpha_fim
= FGetFImage(
422 dpy
, alpha
, Pvisual
, FRenderGetAlphaDepth(), src_x
,
423 src_y
, src_w
, src_h
, AllPlanes
, ZPixmap
);
431 if (alpha
!= None
|| added_alpha_percent
< 100)
433 dest_fim
= PGrabXImage(
434 dpy
, d
, dest_x
, dest_y
, dest_w
, dest_h
, d_is_a_window
);
435 /* accept this error */
438 if (dest_fim
&& do_repeat
&& (dest_w
> src_w
|| dest_h
> src_h
))
440 *new_do_repeat
= False
;
443 make_new_mask
= True
;
447 n_src_w
= (w
< src_w
)? w
:src_w
;
448 n_src_h
= (h
< src_h
)? h
:src_h
;
452 n_src_w
= w
= (dest_w
< src_w
)? dest_w
:src_w
;
453 n_src_h
= h
= (dest_h
< src_h
)? dest_h
:src_h
;
458 out_pix
= XCreatePixmap(dpy
, win
, w
, h
, Pdepth
);
459 out_fim
= FCreateFImage(
460 dpy
, Pvisual
, Pdepth
, ZPixmap
, w
, h
);
463 gc
= PictureDefaultGC(dpy
, win
);
466 if (!out_pix
|| !out_fim
|| !gc
)
472 colors
= (XColor
*)safemalloc(n_src_w
* n_src_h
* sizeof(XColor
));
476 (XColor
*)safemalloc(w
* h
* sizeof(XColor
));
478 am
= (unsigned short *)safemalloc(
479 n_src_w
* n_src_h
* sizeof(unsigned short));
481 if (tint_percent
> 0)
483 tint_color
.pixel
= tint
;
484 XQueryColor(dpy
, Pcmap
, &tint_color
);
487 for (j
= 0; j
< n_src_h
; j
++)
489 for (i
= 0; i
< n_src_w
; i
++, m
++)
491 if (mask_fim
!= NULL
&&
492 (XGetPixel(mask_fim
->im
, i
, j
) == 0))
496 else if (alpha_fim
!= NULL
)
498 am
[m
] = XGetPixel(alpha_fim
->im
, i
, j
);
499 if (am
[m
] == 0 && !dest_fim
)
501 make_new_mask
= True
;
508 if (added_alpha_percent
< 100)
510 am
[m
] = (unsigned short)
511 ((am
[m
] * added_alpha_percent
) / 100);
520 make_new_mask
= True
;
527 else if (am
[m
] < 255)
529 dest_colors
[l
++].pixel
=
530 XGetPixel(dest_fim
->im
, i
, j
);
535 XGetPixel(pixmap_fim
->im
, i
, j
);
541 for (i
= 0; i
< k
; i
+= 256)
542 XQueryColors(dpy
, Pcmap
, &colors
[i
], min(k
- i
, 256));
544 if (do_repeat
&& dest_fim
&& (n_src_h
< h
|| n_src_w
< w
))
546 for (j1
= 0; j1
< h
+n_src_h
; j1
+=n_src_h
)
548 for (i1
= 0; i1
< w
+n_src_w
; i1
+= n_src_w
)
551 !(i1
==0 && j1
==0) && j
< n_src_h
&& j
+j1
< h
;
554 for(i
= 0; i
< n_src_w
&& i
+i1
< w
; i
++)
557 if (am
[m
] > 0 && am
[m
] < 255)
559 dest_colors
[l
++].pixel
=
572 for (i
= 0; i
< l
; i
+= 256)
573 XQueryColors(dpy
, Pcmap
, &dest_colors
[i
], min(l
- i
, 256));
577 *new_mask
= XCreatePixmap(dpy
, win
, w
, h
, 1);
580 new_mask_fim
= FCreateFImage(
581 dpy
, Pvisual
, 1, ZPixmap
, w
, h
);
584 mono_gc
= fvwmlib_XCreateGC(
585 dpy
, *new_mask
, 0, NULL
);
586 do_free_mono_gc
= True
;
592 c
.flags
= DoRed
| DoGreen
| DoBlue
;
593 for (j
= 0; j
< n_src_h
; j
++)
595 for (i
= 0; i
< n_src_w
; i
++, m
++)
601 XPutPixel(new_mask_fim
->im
, i
, j
, 1);
603 if (tint_percent
> 0)
605 colors
[k
].blue
= (unsigned short)
606 (((100-tint_percent
)*
611 colors
[k
].green
= (unsigned short)
612 (((100-tint_percent
)*
617 colors
[k
].red
= (unsigned short)
618 (((100-tint_percent
)*
624 c
.blue
= colors
[k
].blue
;
625 c
.green
= colors
[k
].green
;
626 c
.red
= colors
[k
].red
;
627 if (am
[m
] < 255 && dest_fim
)
629 c
.blue
= (unsigned short)
631 dest_colors
[l
].blue
+
634 c
.green
= (unsigned short)
636 dest_colors
[l
].green
+
639 c
.red
= (unsigned short)
646 PictureAllocColor(Pdpy
, Pcmap
, &c
, False
);
647 colors
[k
].pixel
= c
.pixel
;
654 c
.pixel
= XGetPixel(dest_fim
->im
, i
, j
);
659 pixmap_fim
->im
, i
, j
);
663 XPutPixel(new_mask_fim
->im
, i
, j
, 0);
666 XPutPixel(out_fim
->im
, i
, j
, c
.pixel
);
670 /* tile: editor ligne width limit 107 !!*/
671 if (do_repeat
&& dest_fim
&& (n_src_h
< h
|| n_src_w
< w
))
673 for (j1
= 0; j1
< h
+n_src_h
; j1
+=n_src_h
)
675 for (i1
= 0; i1
< w
+n_src_w
; i1
+= n_src_w
)
679 !(i1
==0 && j1
==0) && j
< n_src_h
; j
++)
681 for(i
= 0; i
< n_src_w
; i
++)
684 if (!(i
+i1
< w
&& j
+j1
< h
))
698 new_mask_fim
->im
, i
+i1
,
701 c
.blue
= colors
[k
].blue
;
702 c
.green
= colors
[k
].green
;
703 c
.red
= colors
[k
].red
;
704 c
.pixel
= colors
[k
].pixel
;
708 c
.blue
= (unsigned short)
710 dest_colors
[l
].blue
+
713 c
.green
= (unsigned short)
715 dest_colors
[l
].green
+
718 c
.red
= (unsigned short)
725 Pdpy
, Pcmap
, &c
, False
);
731 dest_fim
->im
, i
+i1
, j
+j1
);
735 new_mask_fim
->im
, i
+i1
,
739 XPutPixel(out_fim
->im
, i
+i1
, j
+j1
, c
.pixel
);
747 FPutFImage(dpy
, out_pix
, gc
, out_fim
, 0, 0, 0, 0, w
, h
);
748 if (*new_mask
&& mono_gc
)
751 dpy
, *new_mask
, mono_gc
, new_mask_fim
,
770 XFreePixmap(dpy
, pixmap_copy
);
774 FDestroyFImage(dpy
, pixmap_fim
);
778 FDestroyFImage(dpy
, mask_fim
);
782 FDestroyFImage(dpy
, alpha_fim
);
786 FDestroyFImage(dpy
, dest_fim
);
790 FDestroyFImage(dpy
, new_mask_fim
);
792 if (do_free_mono_gc
&& mono_gc
)
794 XFreeGC(dpy
, mono_gc
);
798 FDestroyFImage(dpy
, out_fim
);
804 XFreePixmap(dpy
, out_pix
);
807 if (*new_mask
!= None
)
809 XFreePixmap(dpy
, *new_mask
);
817 /* never used and tested */
819 Pixmap
PCreateDitherPixmap(
820 Display
*dpy
, Window win
, Drawable src
, Pixmap mask
, int depth
, GC gc
,
821 int in_width
, int in_height
, int out_width
, int out_height
)
824 FImage
*mask_fim
= NULL
;
826 Pixmap out_pix
= None
;
830 int j
, i
, m
= 0, k
= 0, x
= 0, y
= 0;
837 dpy
, src
, Pvisual
, depth
, 0, 0, in_width
, in_height
,
838 AllPlanes
, ZPixmap
)))
844 mask_fim
= FGetFImage(
845 dpy
, mask
, Pvisual
, 1, 0, 0, in_width
, in_height
,
849 FDestroyFImage(dpy
, mask_fim
);
853 out_pix
= XCreatePixmap(dpy
, win
, out_width
, out_height
, Pdepth
);
854 out_fim
= FCreateFImage(
855 dpy
, Pvisual
, Pdepth
, ZPixmap
, out_width
, out_height
);
858 gc
= PictureDefaultGC(dpy
, win
);
861 if (!out_pix
|| !out_fim
|| !gc
)
863 FDestroyFImage(dpy
, src_fim
);
866 FDestroyFImage(dpy
, mask_fim
);
870 XFreePixmap(dpy
, out_pix
);
874 FDestroyFImage(dpy
, out_fim
);
879 colors
= (XColor
*)safemalloc(out_width
* out_height
* sizeof(XColor
));
880 cm
= (unsigned char *)safemalloc(out_width
* out_height
* sizeof(char));
883 for (j
= 0; j
< out_height
; j
++,y
++)
887 for (i
= 0; i
< out_width
; i
++,x
++)
891 if (mask_fim
!= NULL
&&
892 (XGetPixel(mask_fim
->im
, x
, y
) == 0))
899 colors
[k
++].pixel
= XGetPixel(src_fim
->im
, x
, y
);
904 for (i
= 0; i
< k
; i
+= 256)
905 XQueryColors(dpy
, Pcmap
, &colors
[i
], min(k
- i
, 256));
908 for (j
= 0; j
< out_height
; j
++)
910 for (i
= 0; i
< out_width
; i
++)
916 PictureAllocColorAllProp(
917 Pdpy
, Pcmap
, &c
, i
, j
, False
, False
,
922 c
.pixel
= XGetPixel(src_fim
->im
, i
, j
);
924 XPutPixel(out_fim
->im
, i
, j
, c
.pixel
);
930 FDestroyFImage(dpy
, src_fim
);
933 FDestroyFImage(dpy
, mask_fim
);
936 dpy
, out_pix
, gc
, out_fim
, 0, 0, 0, 0, out_width
, out_height
);
937 FDestroyFImage(dpy
, out_fim
);
942 /* ---------------------------- interface functions ------------------------ */
944 Pixmap
PictureBitmapToPixmap(
945 Display
*dpy
, Window win
, Pixmap src
, int depth
, GC gc
,
946 int src_x
, int src_y
, int src_w
, int src_h
)
950 dest
= XCreatePixmap(dpy
, win
, src_w
, src_h
, depth
);
951 if (dest
&& gc
== None
)
953 gc
= PictureDefaultGC(dpy
, win
);
959 src_x
, src_y
, src_w
, src_h
, 0, 0, 1);
965 void PGraphicsRenderPixmaps(
966 Display
*dpy
, Window win
, Pixmap pixmap
, Pixmap mask
, Pixmap alpha
,
967 int depth
, FvwmRenderAttributes
*fra
, Drawable d
,
968 GC gc
, GC mono_gc
, GC alpha_gc
,
969 int src_x
, int src_y
, int src_w
, int src_h
,
970 int dest_x
, int dest_y
, int dest_w
, int dest_h
, int do_repeat
)
972 FvwmRenderAttributes t_fra
;
973 Pixmap xrs_pixmap
= None
;
974 Pixmap xrs_mask
= None
;
975 Pixmap tmp_pixmap
, tmp_mask
;
978 t_fra
.added_alpha_percent
= 100;
979 t_fra
.tint_percent
= 0;
985 t_fra
.mask
= fra
->mask
;
986 if (fra
->mask
& FRAM_HAVE_ICON_CSET
)
988 t_fra
.added_alpha_percent
=
989 fra
->colorset
->icon_alpha_percent
;
990 t_fra
.tint_percent
= fra
->colorset
->icon_tint_percent
;
991 t_fra
.tint
= fra
->colorset
->icon_tint
;
993 if (fra
->mask
& FRAM_HAVE_ADDED_ALPHA
)
995 t_fra
.added_alpha_percent
= fra
->added_alpha_percent
;
997 if (fra
->mask
& FRAM_HAVE_TINT
)
999 t_fra
.tint_percent
= fra
->tint_percent
;
1000 t_fra
.tint
= fra
->tint
;
1003 if (dest_w
== 0 && dest_h
== 0)
1005 dest_w
= src_w
; dest_h
= src_h
;
1008 /* use XRender only when "needed" (backing store pbs) */
1009 if (t_fra
.tint_percent
> 0 || t_fra
.added_alpha_percent
< 100
1012 /* for testing XRender simulation add && 0 */
1014 dpy
, win
, pixmap
, mask
, alpha
, depth
,
1015 t_fra
.added_alpha_percent
, t_fra
.tint
,
1017 d
, gc
, alpha_gc
, src_x
, src_y
, src_w
, src_h
,
1018 dest_x
, dest_y
, dest_w
, dest_h
, do_repeat
))
1024 /* no render extension or something strange happen */
1025 if (t_fra
.tint_percent
> 0 || t_fra
.added_alpha_percent
< 100
1028 int new_w
, new_h
, new_do_repeat
;
1030 d_is_a_window
= !!(t_fra
.mask
& FRAM_DEST_IS_A_WINDOW
);
1031 xrs_pixmap
= PCreateRenderPixmap(
1032 dpy
, win
, pixmap
, mask
, alpha
, depth
,
1033 t_fra
.added_alpha_percent
, t_fra
.tint
,
1034 t_fra
.tint_percent
, d_is_a_window
, d
,
1035 gc
, mono_gc
, alpha_gc
,
1036 src_x
, src_y
, src_w
, src_h
,
1037 dest_x
, dest_y
, dest_w
, dest_h
, do_repeat
,
1038 &new_w
, &new_h
, &new_do_repeat
, &xrs_mask
);
1046 do_repeat
= new_do_repeat
;
1049 tmp_pixmap
= (xrs_pixmap
!= None
)? xrs_pixmap
:pixmap
;
1050 tmp_mask
= (xrs_mask
!= None
)? xrs_mask
:mask
;
1054 dpy
, win
, tmp_pixmap
, tmp_mask
, depth
,
1055 src_x
, src_y
, d
, gc
, mono_gc
, dest_x
, dest_y
, dest_w
,
1061 dpy
, tmp_pixmap
, tmp_mask
, depth
, d
, gc
,
1062 src_x
, src_y
, src_w
, src_h
, dest_x
, dest_y
);
1066 XFreePixmap(dpy
, xrs_pixmap
);
1070 XFreePixmap(dpy
, xrs_mask
);
1074 void PGraphicsRenderPicture(
1075 Display
*dpy
, Window win
, FvwmPicture
*p
, FvwmRenderAttributes
*fra
,
1076 Drawable d
, GC gc
, GC mono_gc
, GC alpha_gc
,
1077 int src_x
, int src_y
, int src_w
, int src_h
,
1078 int dest_x
, int dest_y
, int dest_w
, int dest_h
, int do_repeat
)
1080 PGraphicsRenderPixmaps(
1081 dpy
, win
, p
->picture
, p
->mask
, p
->alpha
, p
->depth
, fra
,
1082 d
, gc
, mono_gc
, alpha_gc
,
1083 src_x
, src_y
, src_w
, src_h
,
1084 dest_x
, dest_y
, dest_w
, dest_h
, do_repeat
);
1087 void PGraphicsCopyPixmaps(
1088 Display
*dpy
, Pixmap pixmap
, Pixmap mask
, Pixmap alpha
,
1089 int depth
, Drawable d
, GC gc
, int src_x
, int src_y
, int src_w
, int src_h
,
1090 int dest_x
, int dest_y
)
1092 PGraphicsRenderPixmaps(
1093 dpy
, None
, pixmap
, mask
, alpha
, depth
, 0, d
, gc
, None
, None
,
1094 src_x
, src_y
, src_w
, src_h
, dest_x
, dest_y
, src_w
, src_h
, False
);
1097 void PGraphicsCopyFvwmPicture(
1098 Display
*dpy
, FvwmPicture
*p
, Drawable d
, GC gc
,
1099 int src_x
, int src_y
, int src_w
, int src_h
, int dest_x
, int dest_y
)
1101 PGraphicsRenderPicture(
1102 dpy
, None
, p
, 0, d
, gc
, None
, None
, src_x
, src_y
, src_w
, src_h
,
1103 dest_x
, dest_y
, src_w
, src_h
, False
);
1106 void PGraphicsTileRectangle(
1107 Display
*dpy
, Window win
, Pixmap pixmap
, Pixmap mask
, Pixmap alpha
,
1108 int depth
, Drawable d
, GC gc
, GC mono_gc
,
1109 int src_x
, int src_y
, int src_w
, int src_h
,
1110 int dest_x
, int dest_y
, int dest_w
, int dest_h
)
1112 PGraphicsRenderPixmaps(
1113 dpy
, win
, pixmap
, mask
, alpha
, depth
, 0, d
, gc
, mono_gc
, None
,
1114 src_x
, src_y
, dest_w
, dest_h
, dest_x
, dest_y
, dest_w
, dest_h
,
1118 FvwmPicture
*PGraphicsCreateStretchPicture(
1119 Display
*dpy
, Window win
, FvwmPicture
*src
,
1120 int dest_width
, int dest_height
, GC gc
, GC mono_gc
, GC alpha_gc
)
1122 Pixmap pixmap
= None
, mask
= None
, alpha
= None
;
1125 if (src
== NULL
|| src
->picture
== None
)
1129 pixmap
= CreateStretchPixmap(
1130 dpy
, src
->picture
, src
->width
, src
->height
, src
->depth
,
1131 dest_width
, dest_height
, gc
);
1138 mask
= CreateStretchPixmap(
1139 dpy
, src
->mask
, src
->width
, src
->height
, 1,
1140 dest_width
, dest_height
, mono_gc
);
1144 alpha
= CreateStretchPixmap(
1145 dpy
, src
->alpha
, src
->width
, src
->height
,
1146 FRenderGetAlphaDepth(),
1147 dest_width
, dest_height
, alpha_gc
);
1150 q
= (FvwmPicture
*)safemalloc(sizeof(FvwmPicture
));
1151 memset(q
, 0, sizeof(FvwmPicture
));
1156 q
->picture
= pixmap
;
1159 q
->width
= dest_width
;
1160 q
->height
= dest_height
;
1161 q
->depth
= src
->depth
;
1162 q
->alloc_pixels
= 0;
1163 q
->nalloc_pixels
= 0;
1168 FvwmPicture
*PGraphicsCreateTiledPicture(
1169 Display
*dpy
, Window win
, FvwmPicture
*src
,
1170 int dest_width
, int dest_height
, GC gc
, GC mono_gc
, GC alpha_gc
)
1172 Pixmap pixmap
= None
, mask
= None
, alpha
= None
;
1175 if (src
== NULL
|| src
->picture
== None
)
1179 pixmap
= CreateTiledPixmap(
1180 dpy
, src
->picture
, src
->width
, src
->height
, dest_width
,
1181 dest_height
, src
->depth
, gc
);
1188 mask
= CreateTiledPixmap(
1189 dpy
, src
->mask
, src
->width
, src
->height
, dest_width
,
1190 dest_height
, 1, mono_gc
);
1194 alpha
= CreateTiledPixmap(
1195 dpy
, src
->alpha
, src
->width
, src
->height
, dest_width
,
1196 dest_height
, FRenderGetAlphaDepth(), alpha_gc
);
1199 q
= (FvwmPicture
*)safemalloc(sizeof(FvwmPicture
));
1200 memset(q
, 0, sizeof(FvwmPicture
));
1205 q
->picture
= pixmap
;
1208 q
->width
= dest_width
;
1209 q
->height
= dest_height
;
1210 q
->depth
= src
->depth
;
1211 q
->alloc_pixels
= 0;
1212 q
->nalloc_pixels
= 0;
1217 Pixmap
PGraphicsCreateTransparency(
1218 Display
*dpy
, Window win
, FvwmRenderAttributes
*fra
, GC gc
,
1219 int x
, int y
, int width
, int height
, Bool parent_relative
)
1221 Pixmap r
= None
, dp
= None
;
1224 int dummy
, sx
, sy
, sw
, sh
;
1225 int gx
= x
, gy
= y
, gh
= height
, gw
= width
;
1226 int old_backing_store
= -1;
1228 if (parent_relative
)
1230 old_backing_store
= FSetBackingStore(dpy
, win
, Always
);
1231 XSetWindowBackgroundPixmap(dpy
, win
, ParentRelative
);
1232 XClearArea(dpy
, win
, x
, y
, width
, height
, False
);
1236 if (parent_relative
)
1238 /* this block is not useful if backing store ... */
1240 dpy
, win
, &root
, (int *)&junk
, (int *)&junk
,
1241 (unsigned int *)&sw
, (unsigned int *)&sh
,
1242 (unsigned int *)&junk
, (unsigned int *)&junk
))
1246 XTranslateCoordinates(
1247 dpy
, win
, DefaultRootWindow(dpy
), x
, y
, &sx
, &sy
, &junk
);
1248 if (sx
>= DisplayWidth(dpy
, DefaultScreen(dpy
)))
1252 if (sy
>= DisplayHeight(dpy
, DefaultScreen(dpy
)))
1276 if (sx
+ gw
> DisplayWidth(dpy
, DefaultScreen(dpy
)))
1278 gw
= DisplayWidth(dpy
, DefaultScreen(dpy
)) - sx
;
1280 if (sy
+ gh
> DisplayHeight(dpy
, DefaultScreen(dpy
)))
1282 gh
= DisplayHeight(dpy
, DefaultScreen(dpy
)) - sy
;
1287 stderr
,"Geo: %i,%i,%i,%i / %i,%i,%i,%i / %i,%i,%i,%i\n",
1288 gx
,gy
,gw
,gh
, x
,y
,width
,height
, sx
,sy
,sw
,sh
);
1290 if (XRenderSupport
&& FRenderGetExtensionSupported())
1292 r
= XCreatePixmap(dpy
, win
, gw
, gh
, Pdepth
);
1294 dpy
, win
, ParentRelative
, None
, None
, Pdepth
, 100,
1295 fra
->tint
, fra
->tint_percent
, r
, gc
, None
,
1296 gx
, gy
, gw
, gh
, 0, 0, gw
, gh
, False
))
1300 XFreePixmap(dpy
, r
);
1302 r
= PCreateRenderPixmap(
1303 dpy
, win
, ParentRelative
, None
, None
, Pdepth
, 100, fra
->tint
,
1306 gc
, None
, None
, gx
, gy
, gw
, gh
, gx
, gy
, gw
, gh
,
1307 False
, &dummy
, &dummy
, &dummy
, &dp
);
1310 if (old_backing_store
>= 0)
1312 FSetBackingStore(dpy
, win
, old_backing_store
);
1317 void PGraphicsTintRectangle(
1318 Display
*dpy
, Window win
, Pixel tint
, int tint_percent
,
1319 Drawable dest
, Bool dest_is_a_window
, GC gc
, GC mono_gc
, GC alpha_gc
,
1320 int dest_x
, int dest_y
, int dest_w
, int dest_h
)
1323 FvwmRenderAttributes fra
;
1326 /* this does not work. why? */
1327 if (FRenderTintRectangle(
1328 dpy
, win
, None
, tint
, tint_percent
, dest
,
1329 dest_x
, dest_y
, dest_w
, dest_h
))
1336 dpy
, win
, ParentRelative
, None
, None
, Pdepth
, 100,
1337 tint
, tint_percent
, win
, gc
, None
,
1338 dest_x
, dest_y
, dest_w
, dest_h
,
1339 dest_x
, dest_y
, dest_w
, dest_h
, False
))
1346 if (dest_is_a_window
)
1349 fra
.tint_percent
= tint_percent
;
1350 fra
.mask
= FRAM_DEST_IS_A_WINDOW
| FRAM_HAVE_TINT
;
1351 p
= PGraphicsCreateTransparency(
1352 dpy
, dest
, &fra
, gc
, dest_x
, dest_y
, dest_w
, dest_h
,
1357 dpy
, p
, dest
, gc
, 0, 0, dest_w
, dest_h
,
1359 XFreePixmap(dpy
, p
);
1364 #if 0 /* humm... maybe useful one day with menus */
1365 Pixmap
PGraphicsCreateTranslucent(
1366 Display
*dpy
, Window win
, FvwmRenderAttributes
*fra
, GC gc
,
1367 int x
, int y
, int width
, int height
)
1370 int gx
= x
, gy
= y
, gh
= height
, gw
= width
;
1371 FvwmRenderAttributes t_fra
;
1372 Pixmap root_pix
= None
;
1376 t_fra
.added_alpha_percent
= 100;
1377 t_fra
.tint_percent
= 0;
1383 if (fra
->mask
& FRAM_HAVE_TINT
)
1385 t_fra
.tint_percent
= fra
->tint_percent
;
1386 t_fra
.tint
= fra
->tint
;
1387 t_fra
.mask
= FRAM_HAVE_TINT
;
1391 if (x
>= DisplayWidth(dpy
, DefaultScreen(dpy
)))
1395 if (y
>= DisplayHeight(dpy
, DefaultScreen(dpy
)))
1417 if (gx
+ gw
> DisplayWidth(dpy
, DefaultScreen(dpy
)))
1419 gw
= DisplayWidth(dpy
, DefaultScreen(dpy
)) - gx
;
1421 if (gy
+ gh
> DisplayHeight(dpy
, DefaultScreen(dpy
)))
1423 gh
= DisplayHeight(dpy
, DefaultScreen(dpy
)) - gy
;
1426 /* make a screen shoot */
1428 unsigned long valuemask
= GCSubwindowMode
;
1431 values
.subwindow_mode
= IncludeInferiors
;
1432 root_pix
= XCreatePixmap(dpy
, win
, gw
, gh
, Pdepth
);
1433 my_gc
= fvwmlib_XCreateGC(dpy
, win
, 0, NULL
);
1434 XChangeGC(dpy
, my_gc
, valuemask
, &values
);
1437 dpy
, DefaultRootWindow(dpy
), root_pix
, my_gc
,
1438 gx
, gy
, gw
, gh
, 0, 0);
1439 MyXUngrabServer(dpy
);
1442 if (XRenderSupport
&& FRenderGetExtensionSupported())
1444 r
= XCreatePixmap(dpy
, win
, gw
, gh
, Pdepth
);
1446 dpy
, win
, root_pix
, None
, None
, Pdepth
,
1447 t_fra
.added_alpha_percent
, t_fra
.tint
,
1448 t_fra
.tint_percent
, r
, gc
, None
,
1449 0, 0, gw
, gh
, 0, 0, gw
, gh
, False
))
1453 XFreePixmap(dpy
, r
);
1456 r
= PCreateRenderPixmap(
1457 dpy
, win
, root_pix
, None
, None
, Pdepth
, 100,
1458 fra
->tint
, fra
->tint_percent
, True
, win
,
1459 gc
, None
, None
, 0, 0, gw
, gh
, gx
, gy
, gw
, gh
,
1460 False
, &dummy
, &dummy
, &dummy
, &dp
);
1465 XFreePixmap(dpy
, root_pix
);
1469 XFreePixmap(dpy
, dp
);
1476 /* never tested and used ! */
1477 Pixmap
PGraphicsCreateDitherPixmap(
1478 Display
*dpy
, Window win
, Drawable src
, Pixmap mask
, int depth
, GC gc
,
1479 int in_width
, int in_height
, int out_width
, int out_height
)
1481 return PCreateDitherPixmap(
1482 dpy
, win
, src
, mask
, depth
, gc
,
1483 in_width
, in_height
, out_width
, out_height
);