2 * Functions to use the XRender extension
4 * Copyright 2001, 2002 Huw D M Davies for CodeWeavers
7 * Copyright 2000 Keith Packard, member of The XFree86 Project, Inc.
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/port.h"
37 #include "wine/library.h"
38 #include "wine/unicode.h"
39 #include "wine/debug.h"
41 static BOOL X11DRV_XRender_Installed
= FALSE
;
42 int using_client_side_fonts
= FALSE
;
44 WINE_DEFAULT_DEBUG_CHANNEL(xrender
);
46 #ifdef HAVE_X11_EXTENSIONS_XRENDER_H
49 #include <X11/extensions/Xrender.h>
51 static XRenderPictFormat
*screen_format
; /* format of screen */
52 static XRenderPictFormat
*mono_format
; /* format of mono bitmap */
57 SIZE devsize
; /* size in device coords */
61 #define INITIAL_REALIZED_BUF_SIZE 128
63 typedef enum { AA_None
= 0, AA_Grey
, AA_RGB
, AA_BGR
, AA_VRGB
, AA_VBGR
, AA_MAXVALUE
} AA_Type
;
68 XRenderPictFormat
*font_format
;
79 gsCacheEntryFormat
* format
[AA_MAXVALUE
];
90 COLORREF lastTextColor
;
94 static gsCacheEntry
*glyphsetCache
= NULL
;
95 static DWORD glyphsetCacheSize
= 0;
96 static INT lastfree
= -1;
99 #define INIT_CACHE_SIZE 10
101 static int antialias
= 1;
103 /* some default values just in case */
104 #ifndef SONAME_LIBX11
105 #define SONAME_LIBX11 "libX11.so"
107 #ifndef SONAME_LIBXEXT
108 #define SONAME_LIBXEXT "libXext.so"
110 #ifndef SONAME_LIBXRENDER
111 #define SONAME_LIBXRENDER "libXrender.so"
114 static void *xrender_handle
;
116 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
117 MAKE_FUNCPTR(XRenderAddGlyphs
)
118 MAKE_FUNCPTR(XRenderComposite
)
119 MAKE_FUNCPTR(XRenderCompositeString8
)
120 MAKE_FUNCPTR(XRenderCompositeString16
)
121 MAKE_FUNCPTR(XRenderCompositeString32
)
122 MAKE_FUNCPTR(XRenderCreateGlyphSet
)
123 MAKE_FUNCPTR(XRenderCreatePicture
)
124 MAKE_FUNCPTR(XRenderFillRectangle
)
125 MAKE_FUNCPTR(XRenderFindFormat
)
126 MAKE_FUNCPTR(XRenderFindVisualFormat
)
127 MAKE_FUNCPTR(XRenderFreeGlyphSet
)
128 MAKE_FUNCPTR(XRenderFreePicture
)
129 MAKE_FUNCPTR(XRenderSetPictureClipRectangles
)
130 #ifdef HAVE_XRENDERSETPICTURETRANSFORM
131 MAKE_FUNCPTR(XRenderSetPictureTransform
)
133 MAKE_FUNCPTR(XRenderQueryExtension
)
136 static CRITICAL_SECTION xrender_cs
;
137 static CRITICAL_SECTION_DEBUG critsect_debug
=
140 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
141 0, 0, { (DWORD_PTR
)(__FILE__
": xrender_cs") }
143 static CRITICAL_SECTION xrender_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
145 #define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
146 ( ( (ULONG)_x4 << 24 ) | \
147 ( (ULONG)_x3 << 16 ) | \
148 ( (ULONG)_x2 << 8 ) | \
151 #define MS_GASP_TAG MS_MAKE_TAG('g', 'a', 's', 'p')
153 #define GASP_GRIDFIT 0x01
154 #define GASP_DOGRAY 0x02
156 #ifdef WORDS_BIGENDIAN
157 #define get_be_word(x) (x)
159 #define get_be_word(x) RtlUshortByteSwap(x)
162 /***********************************************************************
163 * X11DRV_XRender_Init
165 * Let's see if our XServer has the extension available
168 void X11DRV_XRender_Init(void)
170 int error_base
, event_base
, i
;
171 XRenderPictFormat pf
;
173 if (client_side_with_render
&&
174 wine_dlopen(SONAME_LIBX11
, RTLD_NOW
|RTLD_GLOBAL
, NULL
, 0) &&
175 wine_dlopen(SONAME_LIBXEXT
, RTLD_NOW
|RTLD_GLOBAL
, NULL
, 0) &&
176 (xrender_handle
= wine_dlopen(SONAME_LIBXRENDER
, RTLD_NOW
, NULL
, 0)))
179 #define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(xrender_handle, #f, NULL, 0)) == NULL) goto sym_not_found;
180 LOAD_FUNCPTR(XRenderAddGlyphs
)
181 LOAD_FUNCPTR(XRenderComposite
)
182 LOAD_FUNCPTR(XRenderCompositeString8
)
183 LOAD_FUNCPTR(XRenderCompositeString16
)
184 LOAD_FUNCPTR(XRenderCompositeString32
)
185 LOAD_FUNCPTR(XRenderCreateGlyphSet
)
186 LOAD_FUNCPTR(XRenderCreatePicture
)
187 LOAD_FUNCPTR(XRenderFillRectangle
)
188 LOAD_FUNCPTR(XRenderFindFormat
)
189 LOAD_FUNCPTR(XRenderFindVisualFormat
)
190 LOAD_FUNCPTR(XRenderFreeGlyphSet
)
191 LOAD_FUNCPTR(XRenderFreePicture
)
192 LOAD_FUNCPTR(XRenderSetPictureClipRectangles
)
193 LOAD_FUNCPTR(XRenderQueryExtension
)
195 #ifdef HAVE_XRENDERSETPICTURETRANSFORM
196 #define LOAD_OPTIONAL_FUNCPTR(f) p##f = wine_dlsym(xrender_handle, #f, NULL, 0);
197 LOAD_OPTIONAL_FUNCPTR(XRenderSetPictureTransform
)
198 #undef LOAD_OPTIONAL_FUNCPTR
203 if(pXRenderQueryExtension(gdi_display
, &event_base
, &error_base
)) {
204 X11DRV_XRender_Installed
= TRUE
;
205 TRACE("Xrender is up and running error_base = %d\n", error_base
);
206 screen_format
= pXRenderFindVisualFormat(gdi_display
, visual
);
209 /* Xrender doesn't like DirectColor visuals, try to find a TrueColor one instead */
210 if (visual
->class == DirectColor
)
213 if (XMatchVisualInfo( gdi_display
, DefaultScreen(gdi_display
),
214 screen_depth
, TrueColor
, &info
))
216 screen_format
= pXRenderFindVisualFormat(gdi_display
, info
.visual
);
217 if (screen_format
) visual
= info
.visual
;
221 if(!screen_format
) /* This fails in buggy versions of libXrender.so */
225 "Wine has detected that you probably have a buggy version\n"
226 "of libXrender.so . Because of this client side font rendering\n"
227 "will be disabled. Please upgrade this library.\n");
228 X11DRV_XRender_Installed
= FALSE
;
231 pf
.type
= PictTypeDirect
;
234 pf
.direct
.alphaMask
= 1;
235 mono_format
= pXRenderFindFormat(gdi_display
, PictFormatType
|
236 PictFormatDepth
| PictFormatAlpha
|
237 PictFormatAlphaMask
, &pf
, 0);
239 ERR("mono_format == NULL?\n");
240 X11DRV_XRender_Installed
= FALSE
;
242 if (!visual
->red_mask
|| !visual
->green_mask
|| !visual
->blue_mask
) {
243 WARN("one or more of the colour masks are 0, disabling XRENDER. Try running in 16-bit mode or higher.\n");
244 X11DRV_XRender_Installed
= FALSE
;
251 if(X11DRV_XRender_Installed
|| client_side_with_core
)
253 glyphsetCache
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
254 sizeof(*glyphsetCache
) * INIT_CACHE_SIZE
);
256 glyphsetCacheSize
= INIT_CACHE_SIZE
;
258 for(i
= 0; i
< INIT_CACHE_SIZE
; i
++) {
259 glyphsetCache
[i
].next
= i
+ 1;
260 glyphsetCache
[i
].count
= -1;
262 glyphsetCache
[i
-1].next
= -1;
263 using_client_side_fonts
= 1;
265 if(!X11DRV_XRender_Installed
) {
266 TRACE("Xrender is not available on your XServer, client side rendering with the core protocol instead.\n");
267 if(screen_depth
<= 8 || !client_side_antialias_with_core
)
270 if(screen_depth
<= 8 || !client_side_antialias_with_render
)
274 else TRACE("Using X11 core fonts\n");
277 static BOOL
fontcmp(LFANDSIZE
*p1
, LFANDSIZE
*p2
)
279 if(p1
->hash
!= p2
->hash
) return TRUE
;
280 if(memcmp(&p1
->devsize
, &p2
->devsize
, sizeof(p1
->devsize
))) return TRUE
;
281 if(memcmp(&p1
->lf
, &p2
->lf
, offsetof(LOGFONTW
, lfFaceName
))) return TRUE
;
282 return strcmpW(p1
->lf
.lfFaceName
, p2
->lf
.lfFaceName
);
286 static void walk_cache(void)
290 EnterCriticalSection(&xrender_cs
);
291 for(i
=mru
; i
>= 0; i
= glyphsetCache
[i
].next
)
292 TRACE("item %d\n", i
);
293 LeaveCriticalSection(&xrender_cs
);
297 static int LookupEntry(LFANDSIZE
*plfsz
)
301 for(i
= mru
; i
>= 0; i
= glyphsetCache
[i
].next
) {
303 if(glyphsetCache
[i
].count
== -1) { /* reached free list so stop */
308 if(!fontcmp(&glyphsetCache
[i
].lfsz
, plfsz
)) {
309 glyphsetCache
[i
].count
++;
311 glyphsetCache
[prev_i
].next
= glyphsetCache
[i
].next
;
312 glyphsetCache
[i
].next
= mru
;
315 TRACE("found font in cache %d\n", i
);
320 TRACE("font not in cache\n");
324 static void FreeEntry(int entry
)
328 for(format
= 0; format
< AA_MAXVALUE
; format
++) {
329 gsCacheEntryFormat
* formatEntry
;
331 if( !glyphsetCache
[entry
].format
[format
] )
334 formatEntry
= glyphsetCache
[entry
].format
[format
];
336 if(formatEntry
->glyphset
) {
338 pXRenderFreeGlyphSet(gdi_display
, formatEntry
->glyphset
);
340 formatEntry
->glyphset
= 0;
342 if(formatEntry
->nrealized
) {
343 HeapFree(GetProcessHeap(), 0, formatEntry
->realized
);
344 formatEntry
->realized
= NULL
;
345 if(formatEntry
->bitmaps
) {
346 for(i
= 0; i
< formatEntry
->nrealized
; i
++)
347 if(formatEntry
->bitmaps
[i
])
348 HeapFree(GetProcessHeap(), 0, formatEntry
->bitmaps
[i
]);
349 HeapFree(GetProcessHeap(), 0, formatEntry
->bitmaps
);
350 formatEntry
->bitmaps
= NULL
;
351 HeapFree(GetProcessHeap(), 0, formatEntry
->gis
);
352 formatEntry
->gis
= NULL
;
354 formatEntry
->nrealized
= 0;
357 HeapFree(GetProcessHeap(), 0, formatEntry
);
358 glyphsetCache
[entry
].format
[format
] = NULL
;
362 static int AllocEntry(void)
364 int best
= -1, prev_best
= -1, i
, prev_i
= -1;
367 assert(glyphsetCache
[lastfree
].count
== -1);
368 glyphsetCache
[lastfree
].count
= 1;
370 lastfree
= glyphsetCache
[lastfree
].next
;
372 glyphsetCache
[best
].next
= mru
;
375 TRACE("empty space at %d, next lastfree = %d\n", mru
, lastfree
);
379 for(i
= mru
; i
>= 0; i
= glyphsetCache
[i
].next
) {
380 if(glyphsetCache
[i
].count
== 0) {
388 TRACE("freeing unused glyphset at cache %d\n", best
);
390 glyphsetCache
[best
].count
= 1;
392 glyphsetCache
[prev_best
].next
= glyphsetCache
[best
].next
;
393 glyphsetCache
[best
].next
= mru
;
401 TRACE("Growing cache\n");
404 glyphsetCache
= HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
406 (glyphsetCacheSize
+ INIT_CACHE_SIZE
)
407 * sizeof(*glyphsetCache
));
409 glyphsetCache
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
410 (glyphsetCacheSize
+ INIT_CACHE_SIZE
)
411 * sizeof(*glyphsetCache
));
413 for(best
= i
= glyphsetCacheSize
; i
< glyphsetCacheSize
+ INIT_CACHE_SIZE
;
415 glyphsetCache
[i
].next
= i
+ 1;
416 glyphsetCache
[i
].count
= -1;
418 glyphsetCache
[i
-1].next
= -1;
419 glyphsetCacheSize
+= INIT_CACHE_SIZE
;
421 lastfree
= glyphsetCache
[best
].next
;
422 glyphsetCache
[best
].count
= 1;
423 glyphsetCache
[best
].next
= mru
;
425 TRACE("new free cache slot at %d\n", mru
);
429 static BOOL
get_gasp_flags(X11DRV_PDEVICE
*physDev
, WORD
*flags
)
439 size
= GetFontData(physDev
->hdc
, MS_GASP_TAG
, 0, NULL
, 0);
440 if(size
== GDI_ERROR
)
443 gasp
= buffer
= HeapAlloc(GetProcessHeap(), 0, size
);
444 GetFontData(physDev
->hdc
, MS_GASP_TAG
, 0, gasp
, size
);
446 GetTextMetricsW(physDev
->hdc
, &tm
);
447 ppem
= abs(X11DRV_YWStoDS(physDev
, tm
.tmAscent
+ tm
.tmDescent
- tm
.tmInternalLeading
));
450 num_recs
= get_be_word(*gasp
);
454 *flags
= get_be_word(*(gasp
+ 1));
455 if(ppem
<= get_be_word(*gasp
))
459 TRACE("got flags %04x for ppem %ld\n", *flags
, ppem
);
461 HeapFree(GetProcessHeap(), 0, buffer
);
465 static int GetCacheEntry(X11DRV_PDEVICE
*physDev
, LFANDSIZE
*plfsz
)
471 static int hinter
= -1;
473 if((ret
= LookupEntry(plfsz
)) != -1) return ret
;
476 entry
= glyphsetCache
+ ret
;
477 entry
->lfsz
= *plfsz
;
478 for( format
= 0; format
< AA_MAXVALUE
; format
++ ) {
479 assert( !entry
->format
[format
] );
482 if(antialias
&& plfsz
->lf
.lfQuality
!= NONANTIALIASED_QUALITY
)
486 RASTERIZER_STATUS status
;
487 GetRasterizerCaps(&status
, sizeof(status
));
488 hinter
= status
.wFlags
& WINE_TT_HINTER_ENABLED
;
490 if(!hinter
|| !get_gasp_flags(physDev
, &flags
) || flags
& GASP_DOGRAY
)
491 entry
->aa_default
= AA_Grey
;
493 entry
->aa_default
= AA_None
;
496 entry
->aa_default
= AA_None
;
501 static void dec_ref_cache(int index
)
504 TRACE("dec'ing entry %d to %d\n", index
, glyphsetCache
[index
].count
- 1);
505 assert(glyphsetCache
[index
].count
> 0);
506 glyphsetCache
[index
].count
--;
509 static void lfsz_calc_hash(LFANDSIZE
*plfsz
)
511 DWORD hash
= 0, *ptr
;
514 hash
^= plfsz
->devsize
.cx
;
515 hash
^= plfsz
->devsize
.cy
;
516 for(i
= 0, ptr
= (DWORD
*)&plfsz
->lf
; i
< 7; i
++, ptr
++)
518 for(i
= 0, ptr
= (DWORD
*)&plfsz
->lf
.lfFaceName
; i
< LF_FACESIZE
/2; i
++, ptr
++) {
519 WCHAR
*pwc
= (WCHAR
*)ptr
;
529 /***********************************************************************
530 * X11DRV_XRender_Finalize
532 void X11DRV_XRender_Finalize(void)
536 EnterCriticalSection(&xrender_cs
);
537 for(i
= mru
; i
>= 0; i
= glyphsetCache
[i
].next
)
539 LeaveCriticalSection(&xrender_cs
);
543 /***********************************************************************
544 * X11DRV_XRender_SelectFont
546 BOOL
X11DRV_XRender_SelectFont(X11DRV_PDEVICE
*physDev
, HFONT hfont
)
550 GetObjectW(hfont
, sizeof(lfsz
.lf
), &lfsz
.lf
);
551 TRACE("h=%ld w=%ld weight=%ld it=%d charset=%d name=%s\n",
552 lfsz
.lf
.lfHeight
, lfsz
.lf
.lfWidth
, lfsz
.lf
.lfWeight
,
553 lfsz
.lf
.lfItalic
, lfsz
.lf
.lfCharSet
, debugstr_w(lfsz
.lf
.lfFaceName
));
554 lfsz
.devsize
.cx
= X11DRV_XWStoDS( physDev
, lfsz
.lf
.lfWidth
);
555 lfsz
.devsize
.cy
= X11DRV_YWStoDS( physDev
, lfsz
.lf
.lfHeight
);
556 lfsz_calc_hash(&lfsz
);
558 EnterCriticalSection(&xrender_cs
);
559 if(!physDev
->xrender
) {
560 physDev
->xrender
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
561 sizeof(*physDev
->xrender
));
562 physDev
->xrender
->cache_index
= -1;
564 else if(physDev
->xrender
->cache_index
!= -1)
565 dec_ref_cache(physDev
->xrender
->cache_index
);
566 physDev
->xrender
->cache_index
= GetCacheEntry(physDev
, &lfsz
);
567 LeaveCriticalSection(&xrender_cs
);
571 /***********************************************************************
572 * X11DRV_XRender_DeleteDC
574 void X11DRV_XRender_DeleteDC(X11DRV_PDEVICE
*physDev
)
577 if(physDev
->xrender
->tile_pict
)
578 pXRenderFreePicture(gdi_display
, physDev
->xrender
->tile_pict
);
580 if(physDev
->xrender
->tile_xpm
)
581 XFreePixmap(gdi_display
, physDev
->xrender
->tile_xpm
);
583 if(physDev
->xrender
->pict
) {
584 TRACE("freeing pict = %lx dc = %p\n", physDev
->xrender
->pict
, physDev
->hdc
);
585 pXRenderFreePicture(gdi_display
, physDev
->xrender
->pict
);
589 EnterCriticalSection(&xrender_cs
);
590 if(physDev
->xrender
->cache_index
!= -1)
591 dec_ref_cache(physDev
->xrender
->cache_index
);
592 LeaveCriticalSection(&xrender_cs
);
594 HeapFree(GetProcessHeap(), 0, physDev
->xrender
);
595 physDev
->xrender
= NULL
;
599 /***********************************************************************
600 * X11DRV_XRender_UpdateDrawable
602 * This gets called from X11DRV_SetDrawable and X11DRV_SelectBitmap.
603 * It deletes the pict when the drawable changes.
605 void X11DRV_XRender_UpdateDrawable(X11DRV_PDEVICE
*physDev
)
607 if(physDev
->xrender
->pict
) {
608 TRACE("freeing pict %08lx from dc %p drawable %08lx\n", physDev
->xrender
->pict
,
609 physDev
->hdc
, physDev
->drawable
);
612 pXRenderFreePicture(gdi_display
, physDev
->xrender
->pict
);
615 physDev
->xrender
->pict
= 0;
619 /************************************************************************
622 * Helper to ExtTextOut. Must be called inside xrender_cs
624 static BOOL
UploadGlyph(X11DRV_PDEVICE
*physDev
, int glyph
, AA_Type format
)
631 gsCacheEntry
*entry
= glyphsetCache
+ physDev
->xrender
->cache_index
;
632 gsCacheEntryFormat
*formatEntry
;
633 UINT ggo_format
= GGO_GLYPH_INDEX
;
634 XRenderPictFormat pf
;
636 /* If there is nothing for the current type, we create the entry. */
637 if( !entry
->format
[format
] ) {
638 entry
->format
[format
] = HeapAlloc(GetProcessHeap(),
640 sizeof(gsCacheEntryFormat
));
642 formatEntry
= entry
->format
[format
];
644 if(formatEntry
->nrealized
<= glyph
) {
645 formatEntry
->nrealized
= (glyph
/ 128 + 1) * 128;
647 if (formatEntry
->realized
)
648 formatEntry
->realized
= HeapReAlloc(GetProcessHeap(),
650 formatEntry
->realized
,
651 formatEntry
->nrealized
* sizeof(BOOL
));
653 formatEntry
->realized
= HeapAlloc(GetProcessHeap(),
655 formatEntry
->nrealized
* sizeof(BOOL
));
657 if(!X11DRV_XRender_Installed
) {
658 if (formatEntry
->bitmaps
)
659 formatEntry
->bitmaps
= HeapReAlloc(GetProcessHeap(),
661 formatEntry
->bitmaps
,
662 formatEntry
->nrealized
* sizeof(formatEntry
->bitmaps
[0]));
664 formatEntry
->bitmaps
= HeapAlloc(GetProcessHeap(),
666 formatEntry
->nrealized
* sizeof(formatEntry
->bitmaps
[0]));
668 if (formatEntry
->gis
)
669 formatEntry
->gis
= HeapReAlloc(GetProcessHeap(),
672 formatEntry
->nrealized
* sizeof(formatEntry
->gis
[0]));
674 formatEntry
->gis
= HeapAlloc(GetProcessHeap(),
676 formatEntry
->nrealized
* sizeof(formatEntry
->gis
[0]));
682 ggo_format
|= WINE_GGO_GRAY16_BITMAP
;
686 ERR("aa = %d - not implemented\n", format
);
688 ggo_format
|= GGO_BITMAP
;
692 buflen
= GetGlyphOutlineW(physDev
->hdc
, glyph
, ggo_format
, &gm
, 0, NULL
,
694 if(buflen
== GDI_ERROR
) {
695 if(format
!= AA_None
) {
697 entry
->aa_default
= AA_None
;
698 ggo_format
&= ~WINE_GGO_GRAY16_BITMAP
;
699 ggo_format
|= GGO_BITMAP
;
700 buflen
= GetGlyphOutlineW(physDev
->hdc
, glyph
, ggo_format
, &gm
, 0, NULL
,
703 if(buflen
== GDI_ERROR
) {
704 ERR("GetGlyphOutlineW failed\n");
707 TRACE("Turning off antialiasing for this monochrome font\n");
710 if(formatEntry
->glyphset
== 0 && X11DRV_XRender_Installed
) {
714 pf
.direct
.alphaMask
= 0xff;
718 ERR("aa = %d - not implemented\n", format
);
721 pf
.direct
.alphaMask
= 1;
725 pf
.type
= PictTypeDirect
;
729 formatEntry
->font_format
= pXRenderFindFormat(gdi_display
,
736 formatEntry
->glyphset
= pXRenderCreateGlyphSet(gdi_display
, formatEntry
->font_format
);
741 buf
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, buflen
);
742 GetGlyphOutlineW(physDev
->hdc
, glyph
, ggo_format
, &gm
, buflen
, buf
, NULL
);
743 formatEntry
->realized
[glyph
] = TRUE
;
745 TRACE("buflen = %d. Got metrics: %dx%d adv=%d,%d origin=%ld,%ld\n",
747 gm
.gmBlackBoxX
, gm
.gmBlackBoxY
, gm
.gmCellIncX
, gm
.gmCellIncY
,
748 gm
.gmptGlyphOrigin
.x
, gm
.gmptGlyphOrigin
.y
);
750 gi
.width
= gm
.gmBlackBoxX
;
751 gi
.height
= gm
.gmBlackBoxY
;
752 gi
.x
= -gm
.gmptGlyphOrigin
.x
;
753 gi
.y
= gm
.gmptGlyphOrigin
.y
;
754 gi
.xOff
= gm
.gmCellIncX
;
755 gi
.yOff
= gm
.gmCellIncY
;
757 if(TRACE_ON(xrender
)) {
762 if(format
== AA_None
) {
763 pitch
= ((gi
.width
+ 31) / 32) * 4;
764 for(i
= 0; i
< gi
.height
; i
++) {
765 line
= (unsigned char*) buf
+ i
* pitch
;
767 for(j
= 0; j
< pitch
* 8; j
++) {
768 strcat(output
, (line
[j
/ 8] & (1 << (7 - (j
% 8)))) ? "#" : " ");
770 strcat(output
, "\n");
774 static const char blks
[] = " .:;!o*#";
778 pitch
= ((gi
.width
+ 3) / 4) * 4;
779 for(i
= 0; i
< gi
.height
; i
++) {
780 line
= (unsigned char*) buf
+ i
* pitch
;
782 for(j
= 0; j
< pitch
; j
++) {
783 str
[0] = blks
[line
[j
] >> 5];
786 strcat(output
, "\n");
792 if(formatEntry
->glyphset
) {
793 if(format
== AA_None
&& BitmapBitOrder(gdi_display
) != MSBFirst
) {
794 unsigned char *byte
= (unsigned char*) buf
, c
;
800 /* magic to flip bit order */
801 c
= ((c
<< 1) & 0xaa) | ((c
>> 1) & 0x55);
802 c
= ((c
<< 2) & 0xcc) | ((c
>> 2) & 0x33);
803 c
= ((c
<< 4) & 0xf0) | ((c
>> 4) & 0x0f);
810 pXRenderAddGlyphs(gdi_display
, formatEntry
->glyphset
, &gid
, &gi
, 1,
813 HeapFree(GetProcessHeap(), 0, buf
);
815 formatEntry
->bitmaps
[glyph
] = buf
;
816 memcpy(&formatEntry
->gis
[glyph
], &gi
, sizeof(gi
));
821 static void SharpGlyphMono(X11DRV_PDEVICE
*physDev
, INT x
, INT y
,
822 void *bitmap
, XGlyphInfo
*gi
)
824 unsigned char *srcLine
= bitmap
, *src
;
825 unsigned char bits
, bitsMask
;
826 int width
= gi
->width
;
827 int stride
= ((width
+ 31) & ~31) >> 3;
828 int height
= gi
->height
;
832 TRACE("%d, %d\n", x
, y
);
841 bitsMask
= 0x80; /* FreeType is always MSB first */
855 bitsMask
= bitsMask
>> 1;
861 } while (bits
& bitsMask
);
862 XFillRectangle (gdi_display
, physDev
->drawable
,
863 physDev
->gc
, xspan
, y
, lenspan
, 1);
875 bitsMask
= bitsMask
>> 1;
881 } while (!(bits
& bitsMask
));
888 static void SharpGlyphGray(X11DRV_PDEVICE
*physDev
, INT x
, INT y
,
889 void *bitmap
, XGlyphInfo
*gi
)
891 unsigned char *srcLine
= bitmap
, *src
, bits
;
892 int width
= gi
->width
;
893 int stride
= ((width
+ 3) & ~3);
894 int height
= gi
->height
;
919 } while (bits
>= 0x80);
920 XFillRectangle (gdi_display
, physDev
->drawable
,
921 physDev
->gc
, xspan
, y
, lenspan
, 1);
934 } while (bits
< 0x80);
942 static void ExamineBitfield (DWORD mask
, int *shift
, int *len
)
947 while ((mask
& 1) == 0)
953 while ((mask
& 1) == 1)
962 static DWORD
GetField (DWORD pixel
, int shift
, int len
)
964 pixel
= pixel
& (((1 << (len
)) - 1) << shift
);
965 pixel
= pixel
<< (32 - (shift
+ len
)) >> 24;
968 pixel
|= (pixel
>> len
);
975 static DWORD
PutField (DWORD pixel
, int shift
, int len
)
977 shift
= shift
- (8 - len
);
979 pixel
&= (((1 << len
) - 1) << (8 - len
));
987 static void SmoothGlyphGray(XImage
*image
, int x
, int y
, void *bitmap
, XGlyphInfo
*gi
,
993 BYTE
*maskLine
, *mask
, m
;
998 BYTE src_r
, src_g
, src_b
;
1003 height
= gi
->height
;
1005 maskLine
= (unsigned char *) bitmap
;
1006 maskStride
= (width
+ 3) & ~3;
1008 ExamineBitfield (image
->red_mask
, &r_shift
, &r_len
);
1009 ExamineBitfield (image
->green_mask
, &g_shift
, &g_len
);
1010 ExamineBitfield (image
->blue_mask
, &b_shift
, &b_len
);
1012 src_r
= GetField(color
, r_shift
, r_len
);
1013 src_g
= GetField(color
, g_shift
, g_len
);
1014 src_b
= GetField(color
, b_shift
, b_len
);
1016 for(; height
--; y
++)
1019 maskLine
+= maskStride
;
1024 if(y
>= image
->height
) break;
1028 if(tx
>= image
->width
) break;
1031 if(tx
< 0) continue;
1034 XPutPixel (image
, tx
, y
, color
);
1039 pixel
= XGetPixel (image
, tx
, y
);
1041 r
= GetField(pixel
, r_shift
, r_len
);
1042 r
= ((BYTE
)~m
* (WORD
)r
+ (BYTE
)m
* (WORD
)src_r
) >> 8;
1043 g
= GetField(pixel
, g_shift
, g_len
);
1044 g
= ((BYTE
)~m
* (WORD
)g
+ (BYTE
)m
* (WORD
)src_g
) >> 8;
1045 b
= GetField(pixel
, b_shift
, b_len
);
1046 b
= ((BYTE
)~m
* (WORD
)b
+ (BYTE
)m
* (WORD
)src_b
) >> 8;
1048 pixel
= (PutField (r
, r_shift
, r_len
) |
1049 PutField (g
, g_shift
, g_len
) |
1050 PutField (b
, b_shift
, b_len
));
1051 XPutPixel (image
, tx
, y
, pixel
);
1057 static int XRenderErrorHandler(Display
*dpy
, XErrorEvent
*event
, void *arg
)
1062 /***********************************************************************
1063 * X11DRV_XRender_ExtTextOut
1065 BOOL
X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE
*physDev
, INT x
, INT y
, UINT flags
,
1066 const RECT
*lprect
, LPCWSTR wstr
, UINT count
,
1072 int render_op
= PictOpOver
;
1073 gsCacheEntry
*entry
;
1074 gsCacheEntryFormat
*formatEntry
;
1076 HDC hdc
= physDev
->hdc
;
1077 int textPixel
, backgroundPixel
;
1078 HRGN saved_region
= 0;
1079 BOOL disable_antialias
= FALSE
;
1080 AA_Type antialias
= AA_None
;
1083 double cosEsc
, sinEsc
;
1086 /* Do we need to disable antialiasing because of palette mode? */
1087 if( !physDev
->bitmap
|| GetObjectW( physDev
->bitmap
->hbitmap
, sizeof(bmp
), &bmp
) != sizeof(bmp
) ) {
1088 TRACE("bitmap is not a DIB\n");
1090 else if (bmp
.dsBmih
.biBitCount
<= 8) {
1091 TRACE("Disabling antialiasing\n");
1092 disable_antialias
= TRUE
;
1095 xgcval
.function
= GXcopy
;
1096 xgcval
.background
= physDev
->backgroundPixel
;
1097 xgcval
.fill_style
= FillSolid
;
1099 XChangeGC( gdi_display
, physDev
->gc
, GCFunction
| GCBackground
| GCFillStyle
, &xgcval
);
1100 wine_tsx11_unlock();
1102 X11DRV_LockDIBSection( physDev
, DIB_Status_GdiMod
, FALSE
);
1104 if(physDev
->depth
== 1) {
1105 if((physDev
->textPixel
& 0xffffff) == 0) {
1107 backgroundPixel
= 1;
1110 backgroundPixel
= 0;
1113 textPixel
= physDev
->textPixel
;
1114 backgroundPixel
= physDev
->backgroundPixel
;
1117 if(flags
& ETO_OPAQUE
)
1120 XSetForeground( gdi_display
, physDev
->gc
, backgroundPixel
);
1121 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
1122 physDev
->org
.x
+ lprect
->left
, physDev
->org
.y
+ lprect
->top
,
1123 lprect
->right
- lprect
->left
, lprect
->bottom
- lprect
->top
);
1124 wine_tsx11_unlock();
1134 GetObjectW(GetCurrentObject(physDev
->hdc
, OBJ_FONT
), sizeof(lf
), &lf
);
1135 if(lf
.lfEscapement
!= 0) {
1136 cosEsc
= cos(lf
.lfEscapement
* M_PI
/ 1800);
1137 sinEsc
= sin(lf
.lfEscapement
* M_PI
/ 1800);
1143 if (flags
& ETO_CLIPPED
)
1147 clip_region
= CreateRectRgnIndirect( lprect
);
1148 /* make a copy of the current device region */
1149 saved_region
= CreateRectRgn( 0, 0, 0, 0 );
1150 CombineRgn( saved_region
, physDev
->region
, 0, RGN_COPY
);
1151 X11DRV_SetDeviceClipping( physDev
, saved_region
, clip_region
);
1152 DeleteObject( clip_region
);
1155 if(X11DRV_XRender_Installed
) {
1156 if(!physDev
->xrender
->pict
) {
1157 XRenderPictureAttributes pa
;
1158 pa
.subwindow_mode
= IncludeInferiors
;
1161 physDev
->xrender
->pict
= pXRenderCreatePicture(gdi_display
,
1163 (physDev
->depth
== 1) ?
1164 mono_format
: screen_format
,
1165 CPSubwindowMode
, &pa
);
1166 wine_tsx11_unlock();
1168 TRACE("allocing pict = %lx dc = %p drawable = %08lx\n",
1169 physDev
->xrender
->pict
, hdc
, physDev
->drawable
);
1171 TRACE("using existing pict = %lx dc = %p drawable = %08lx\n",
1172 physDev
->xrender
->pict
, hdc
, physDev
->drawable
);
1175 if ((data
= X11DRV_GetRegionData( physDev
->region
, 0 )))
1178 pXRenderSetPictureClipRectangles( gdi_display
, physDev
->xrender
->pict
,
1179 physDev
->org
.x
, physDev
->org
.y
,
1180 (XRectangle
*)data
->Buffer
, data
->rdh
.nCount
);
1181 wine_tsx11_unlock();
1182 HeapFree( GetProcessHeap(), 0, data
);
1186 if(X11DRV_XRender_Installed
) {
1187 /* Create a 1x1 pixmap to tile over the font mask */
1188 if(!physDev
->xrender
->tile_xpm
) {
1189 XRenderPictureAttributes pa
;
1191 XRenderPictFormat
*format
= (physDev
->depth
== 1) ? mono_format
: screen_format
;
1193 physDev
->xrender
->tile_xpm
= XCreatePixmap(gdi_display
,
1198 physDev
->xrender
->tile_pict
= pXRenderCreatePicture(gdi_display
,
1199 physDev
->xrender
->tile_xpm
,
1202 wine_tsx11_unlock();
1203 TRACE("Created pixmap of depth %d\n", format
->depth
);
1204 /* init lastTextColor to something different from textPixel */
1205 physDev
->xrender
->lastTextColor
= ~physDev
->textPixel
;
1209 if(physDev
->textPixel
!= physDev
->xrender
->lastTextColor
) {
1210 if(physDev
->depth
!= 1) {
1211 /* Map 0 -- 0xff onto 0 -- 0xffff */
1216 ExamineBitfield (visual
->red_mask
, &r_shift
, &r_len
);
1217 ExamineBitfield (visual
->green_mask
, &g_shift
, &g_len
);
1218 ExamineBitfield (visual
->blue_mask
, &b_shift
, &b_len
);
1220 col
.red
= GetField(physDev
->textPixel
, r_shift
, r_len
);
1221 col
.red
|= col
.red
<< 8;
1222 col
.green
= GetField(physDev
->textPixel
, g_shift
, g_len
);
1223 col
.green
|= col
.green
<< 8;
1224 col
.blue
= GetField(physDev
->textPixel
, b_shift
, b_len
);
1225 col
.blue
|= col
.blue
<< 8;
1227 } else { /* for a 1bpp bitmap we always need a 1 in the tile */
1228 col
.red
= col
.green
= col
.blue
= 0;
1232 pXRenderFillRectangle(gdi_display
, PictOpSrc
,
1233 physDev
->xrender
->tile_pict
,
1235 wine_tsx11_unlock();
1236 physDev
->xrender
->lastTextColor
= physDev
->textPixel
;
1239 /* FIXME the mapping of Text/BkColor onto 1 or 0 needs investigation.
1241 if((physDev
->depth
== 1) && (textPixel
== 0))
1242 render_op
= PictOpOutReverse
; /* This gives us 'black' text */
1245 EnterCriticalSection(&xrender_cs
);
1246 entry
= glyphsetCache
+ physDev
->xrender
->cache_index
;
1247 if( disable_antialias
== FALSE
)
1248 antialias
= entry
->aa_default
;
1249 formatEntry
= entry
->format
[antialias
];
1251 for(idx
= 0; idx
< count
; idx
++) {
1252 if( !formatEntry
) {
1253 UploadGlyph(physDev
, wstr
[idx
], antialias
);
1254 formatEntry
= entry
->format
[antialias
];
1255 } else if( wstr
[idx
] >= formatEntry
->nrealized
|| formatEntry
->realized
[wstr
[idx
]] == FALSE
) {
1256 UploadGlyph(physDev
, wstr
[idx
], antialias
);
1259 assert(formatEntry
);
1261 TRACE("Writing %s at %ld,%ld\n", debugstr_wn(wstr
,count
),
1262 physDev
->org
.x
+ x
, physDev
->org
.y
+ y
);
1264 if(X11DRV_XRender_Installed
) {
1267 pXRenderCompositeString16(gdi_display
, render_op
,
1268 physDev
->xrender
->tile_pict
,
1269 physDev
->xrender
->pict
,
1270 formatEntry
->font_format
, formatEntry
->glyphset
,
1271 0, 0, physDev
->org
.x
+ x
, physDev
->org
.y
+ y
,
1274 INT offset
= 0, xoff
= 0, yoff
= 0;
1275 for(idx
= 0; idx
< count
; idx
++) {
1276 pXRenderCompositeString16(gdi_display
, render_op
,
1277 physDev
->xrender
->tile_pict
,
1278 physDev
->xrender
->pict
,
1279 formatEntry
->font_format
, formatEntry
->glyphset
,
1280 0, 0, physDev
->org
.x
+ x
+ xoff
,
1281 physDev
->org
.y
+ y
+ yoff
,
1283 offset
+= lpDx
[idx
];
1284 xoff
= offset
* cosEsc
;
1285 yoff
= offset
* -sinEsc
;
1288 wine_tsx11_unlock();
1291 INT offset
= 0, xoff
= 0, yoff
= 0;
1293 XSetForeground( gdi_display
, physDev
->gc
, textPixel
);
1295 if(antialias
== AA_None
) {
1296 for(idx
= 0; idx
< count
; idx
++) {
1297 SharpGlyphMono(physDev
, physDev
->org
.x
+ x
+ xoff
,
1298 physDev
->org
.y
+ y
+ yoff
,
1299 formatEntry
->bitmaps
[wstr
[idx
]],
1300 &formatEntry
->gis
[wstr
[idx
]]);
1302 offset
+= lpDx
[idx
];
1303 xoff
= offset
* cosEsc
;
1304 yoff
= offset
* -sinEsc
;
1306 xoff
+= formatEntry
->gis
[wstr
[idx
]].xOff
;
1307 yoff
+= formatEntry
->gis
[wstr
[idx
]].yOff
;
1310 } else if(physDev
->depth
== 1) {
1311 for(idx
= 0; idx
< count
; idx
++) {
1312 SharpGlyphGray(physDev
, physDev
->org
.x
+ x
+ xoff
,
1313 physDev
->org
.y
+ y
+ yoff
,
1314 formatEntry
->bitmaps
[wstr
[idx
]],
1315 &formatEntry
->gis
[wstr
[idx
]]);
1317 offset
+= lpDx
[idx
];
1318 xoff
= offset
* cosEsc
;
1319 yoff
= offset
* -sinEsc
;
1321 xoff
+= formatEntry
->gis
[wstr
[idx
]].xOff
;
1322 yoff
+= formatEntry
->gis
[wstr
[idx
]].yOff
;
1328 unsigned int w
, h
, dummy_uint
;
1329 Window dummy_window
;
1331 int image_x
, image_y
, image_off_x
, image_off_y
, image_w
, image_h
;
1332 RECT extents
= {0, 0, 0, 0};
1336 XGetGeometry(gdi_display
, physDev
->drawable
, &dummy_window
, &dummy_int
, &dummy_int
,
1337 &w
, &h
, &dummy_uint
, &dummy_uint
);
1338 TRACE("drawable %dx%d\n", w
, h
);
1340 for(idx
= 0; idx
< count
; idx
++) {
1341 if(extents
.left
> cur
.x
- formatEntry
->gis
[wstr
[idx
]].x
)
1342 extents
.left
= cur
.x
- formatEntry
->gis
[wstr
[idx
]].x
;
1343 if(extents
.top
> cur
.y
- formatEntry
->gis
[wstr
[idx
]].y
)
1344 extents
.top
= cur
.y
- formatEntry
->gis
[wstr
[idx
]].y
;
1345 if(extents
.right
< cur
.x
- formatEntry
->gis
[wstr
[idx
]].x
+ formatEntry
->gis
[wstr
[idx
]].width
)
1346 extents
.right
= cur
.x
- formatEntry
->gis
[wstr
[idx
]].x
+ formatEntry
->gis
[wstr
[idx
]].width
;
1347 if(extents
.bottom
< cur
.y
- formatEntry
->gis
[wstr
[idx
]].y
+ formatEntry
->gis
[wstr
[idx
]].height
)
1348 extents
.bottom
= cur
.y
- formatEntry
->gis
[wstr
[idx
]].y
+ formatEntry
->gis
[wstr
[idx
]].height
;
1350 offset
+= lpDx
[idx
];
1351 cur
.x
= offset
* cosEsc
;
1352 cur
.y
= offset
* -sinEsc
;
1354 cur
.x
+= formatEntry
->gis
[wstr
[idx
]].xOff
;
1355 cur
.y
+= formatEntry
->gis
[wstr
[idx
]].yOff
;
1358 TRACE("glyph extents %ld,%ld - %ld,%ld drawable x,y %ld,%ld\n", extents
.left
, extents
.top
,
1359 extents
.right
, extents
.bottom
, physDev
->org
.x
+ x
, physDev
->org
.y
+ y
);
1361 if(physDev
->org
.x
+ x
+ extents
.left
>= 0) {
1362 image_x
= physDev
->org
.x
+ x
+ extents
.left
;
1366 image_off_x
= physDev
->org
.x
+ x
+ extents
.left
;
1368 if(physDev
->org
.y
+ y
+ extents
.top
>= 0) {
1369 image_y
= physDev
->org
.y
+ y
+ extents
.top
;
1373 image_off_y
= physDev
->org
.y
+ y
+ extents
.top
;
1375 if(physDev
->org
.x
+ x
+ extents
.right
< w
)
1376 image_w
= physDev
->org
.x
+ x
+ extents
.right
- image_x
;
1378 image_w
= w
- image_x
;
1379 if(physDev
->org
.y
+ y
+ extents
.bottom
< h
)
1380 image_h
= physDev
->org
.y
+ y
+ extents
.bottom
- image_y
;
1382 image_h
= h
- image_y
;
1384 if(image_w
<= 0 || image_h
<= 0) goto no_image
;
1386 X11DRV_expect_error(gdi_display
, XRenderErrorHandler
, NULL
);
1387 image
= XGetImage(gdi_display
, physDev
->drawable
,
1388 image_x
, image_y
, image_w
, image_h
,
1389 AllPlanes
, ZPixmap
);
1390 X11DRV_check_error();
1392 TRACE("XGetImage(%p, %x, %d, %d, %d, %d, %lx, %x) depth = %d rets %p\n",
1393 gdi_display
, (int)physDev
->drawable
, image_x
, image_y
,
1394 image_w
, image_h
, AllPlanes
, ZPixmap
,
1395 physDev
->depth
, image
);
1397 Pixmap xpm
= XCreatePixmap(gdi_display
, physDev
->drawable
, image_w
, image_h
,
1402 gcv
.graphics_exposures
= False
;
1403 gc
= XCreateGC(gdi_display
, xpm
, GCGraphicsExposures
, &gcv
);
1404 XCopyArea(gdi_display
, physDev
->drawable
, xpm
, gc
, image_x
, image_y
,
1405 image_w
, image_h
, 0, 0);
1406 XFreeGC(gdi_display
, gc
);
1407 X11DRV_expect_error(gdi_display
, XRenderErrorHandler
, NULL
);
1408 image
= XGetImage(gdi_display
, xpm
, 0, 0, image_w
, image_h
, AllPlanes
,
1410 X11DRV_check_error();
1411 XFreePixmap(gdi_display
, xpm
);
1413 if(!image
) goto no_image
;
1415 image
->red_mask
= visual
->red_mask
;
1416 image
->green_mask
= visual
->green_mask
;
1417 image
->blue_mask
= visual
->blue_mask
;
1419 offset
= xoff
= yoff
= 0;
1420 for(idx
= 0; idx
< count
; idx
++) {
1421 SmoothGlyphGray(image
, xoff
+ image_off_x
- extents
.left
,
1422 yoff
+ image_off_y
- extents
.top
,
1423 formatEntry
->bitmaps
[wstr
[idx
]],
1424 &formatEntry
->gis
[wstr
[idx
]],
1425 physDev
->textPixel
);
1427 offset
+= lpDx
[idx
];
1428 xoff
= offset
* cosEsc
;
1429 yoff
= offset
* -sinEsc
;
1431 xoff
+= formatEntry
->gis
[wstr
[idx
]].xOff
;
1432 yoff
+= formatEntry
->gis
[wstr
[idx
]].yOff
;
1435 XPutImage(gdi_display
, physDev
->drawable
, physDev
->gc
, image
, 0, 0,
1436 image_x
, image_y
, image_w
, image_h
);
1437 XDestroyImage(image
);
1440 wine_tsx11_unlock();
1442 LeaveCriticalSection(&xrender_cs
);
1444 if (flags
& ETO_CLIPPED
)
1446 /* restore the device region */
1447 X11DRV_SetDeviceClipping( physDev
, saved_region
, 0 );
1448 DeleteObject( saved_region
);
1454 X11DRV_UnlockDIBSection( physDev
, TRUE
);
1458 /******************************************************************************
1459 * AlphaBlend (x11drv.@)
1461 BOOL
X11DRV_AlphaBlend(X11DRV_PDEVICE
*devDst
, INT xDst
, INT yDst
, INT widthDst
, INT heightDst
,
1462 X11DRV_PDEVICE
*devSrc
, INT xSrc
, INT ySrc
, INT widthSrc
, INT heightSrc
,
1463 BLENDFUNCTION blendfn
)
1465 XRenderPictureAttributes pa
;
1466 XRenderPictFormat
*src_format
;
1467 XRenderPictFormat argb32_templ
= {
1469 PictTypeDirect
, /* type */
1472 16, /* direct.red */
1473 0xff, /* direct.redMask */
1474 8, /* direct.green */
1475 0xff, /* direct.greenMask */
1476 0, /* direct.blue */
1477 0xff, /* direct.blueMask */
1478 24, /* direct.alpha */
1479 0xff, /* direct.alphaMask */
1483 unsigned long argb32_templ_mask
=
1489 PictFormatGreenMask
|
1491 PictFormatBlueMask
|
1493 PictFormatAlphaMask
;
1495 Picture dst_pict
, src_pict
;
1501 BYTE
*dstbits
, *data
;
1504 BOOL top_down
= FALSE
;
1507 if(!X11DRV_XRender_Installed
) {
1508 FIXME("Unable to AlphaBlend without Xrender\n");
1513 pts
[1].x
= xDst
+ widthDst
;
1514 pts
[1].y
= yDst
+ heightDst
;
1515 LPtoDP(devDst
->hdc
, pts
, 2);
1518 widthDst
= pts
[1].x
- pts
[0].x
;
1519 heightDst
= pts
[1].y
- pts
[0].y
;
1523 pts
[1].x
= xSrc
+ widthSrc
;
1524 pts
[1].y
= ySrc
+ heightSrc
;
1525 LPtoDP(devSrc
->hdc
, pts
, 2);
1528 widthSrc
= pts
[1].x
- pts
[0].x
;
1529 heightSrc
= pts
[1].y
- pts
[0].y
;
1531 #ifndef HAVE_XRENDERSETPICTURETRANSFORM
1532 if(widthDst
!= widthSrc
|| heightDst
!= heightSrc
)
1534 if(!pXRenderSetPictureTransform
)
1537 FIXME("Unable to Stretch, XRenderSetPictureTransform is currently required\n");
1541 if (!devSrc
->bitmap
|| GetObjectW( devSrc
->bitmap
->hbitmap
, sizeof(dib
), &dib
) != sizeof(dib
))
1543 FIXME("not a dibsection\n");
1547 if(dib
.dsBm
.bmBitsPixel
!= 32) {
1548 FIXME("not a 32 bpp dibsection\n");
1551 dstbits
= data
= HeapAlloc(GetProcessHeap(), 0, heightSrc
* widthSrc
* 4);
1553 if(dib
.dsBmih
.biHeight
< 0) { /* top-down dib */
1555 dstbits
+= widthSrc
* (heightSrc
- 1) * 4;
1561 y
= dib
.dsBmih
.biHeight
- ySrc
- 1;
1564 for(; y
> y2
; y
--) {
1565 memcpy(dstbits
, (char *)dib
.dsBm
.bmBits
+ y
* dib
.dsBm
.bmWidthBytes
+ xSrc
* 4,
1567 dstbits
+= (top_down
? -1 : 1) * widthSrc
* 4;
1571 image
= XCreateImage(gdi_display
, visual
, 32, ZPixmap
, 0,
1572 (char*) data
, widthSrc
, heightSrc
, 32, widthSrc
* 4);
1575 Avoid using XRenderFindStandardFormat as older libraries don't have it
1576 src_format = pXRenderFindStandardFormat(gdi_display, PictStandardARGB32);
1578 src_format
= pXRenderFindFormat(gdi_display
, argb32_templ_mask
, &argb32_templ
, 0);
1580 TRACE("src_format %p\n", src_format
);
1582 pa
.subwindow_mode
= IncludeInferiors
;
1584 /* FIXME use devDst->xrender->pict ? */
1585 dst_pict
= pXRenderCreatePicture(gdi_display
,
1587 (devDst
->depth
== 1) ?
1588 mono_format
: screen_format
,
1589 CPSubwindowMode
, &pa
);
1590 TRACE("dst_pict %08lx\n", dst_pict
);
1591 TRACE("src_drawable = %08lx\n", devSrc
->drawable
);
1592 xpm
= XCreatePixmap(gdi_display
,
1594 widthSrc
, heightSrc
, 32);
1595 gcv
.graphics_exposures
= False
;
1596 gc
= XCreateGC(gdi_display
, xpm
, GCGraphicsExposures
, &gcv
);
1597 TRACE("xpm = %08lx\n", xpm
);
1598 XPutImage(gdi_display
, xpm
, gc
, image
, 0, 0, 0, 0, widthSrc
, heightSrc
);
1600 src_pict
= pXRenderCreatePicture(gdi_display
,
1602 CPSubwindowMode
, &pa
);
1603 TRACE("src_pict %08lx\n", src_pict
);
1605 if ((rgndata
= X11DRV_GetRegionData( devDst
->region
, 0 )))
1607 pXRenderSetPictureClipRectangles( gdi_display
, dst_pict
,
1608 devDst
->org
.x
, devDst
->org
.y
,
1609 (XRectangle
*)rgndata
->Buffer
,
1610 rgndata
->rdh
.nCount
);
1611 HeapFree( GetProcessHeap(), 0, rgndata
);
1614 #ifdef HAVE_XRENDERSETPICTURETRANSFORM
1615 if(widthDst
!= widthSrc
|| heightDst
!= heightSrc
) {
1616 double xscale
= widthSrc
/(double)widthDst
;
1617 double yscale
= heightSrc
/(double)heightDst
;
1618 XTransform xform
= {{
1619 { XDoubleToFixed(xscale
), XDoubleToFixed(0), XDoubleToFixed(0) },
1620 { XDoubleToFixed(0), XDoubleToFixed(yscale
), XDoubleToFixed(0) },
1621 { XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1) }
1623 pXRenderSetPictureTransform(gdi_display
, src_pict
, &xform
);
1626 pXRenderComposite(gdi_display
, PictOpOver
, src_pict
, 0, dst_pict
,
1628 xDst
+ devDst
->org
.x
, yDst
+ devDst
->org
.y
, widthDst
, heightDst
);
1631 pXRenderFreePicture(gdi_display
, src_pict
);
1632 XFreePixmap(gdi_display
, xpm
);
1633 XFreeGC(gdi_display
, gc
);
1634 pXRenderFreePicture(gdi_display
, dst_pict
);
1636 XDestroyImage(image
);
1638 wine_tsx11_unlock();
1639 HeapFree(GetProcessHeap(), 0, data
);
1643 #else /* HAVE_X11_EXTENSIONS_XRENDER_H */
1645 void X11DRV_XRender_Init(void)
1647 TRACE("XRender support not compiled in.\n");
1651 void X11DRV_XRender_Finalize(void)
1655 BOOL
X11DRV_XRender_SelectFont(X11DRV_PDEVICE
*physDev
, HFONT hfont
)
1661 void X11DRV_XRender_DeleteDC(X11DRV_PDEVICE
*physDev
)
1667 BOOL
X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE
*physDev
, INT x
, INT y
, UINT flags
,
1668 const RECT
*lprect
, LPCWSTR wstr
, UINT count
,
1675 void X11DRV_XRender_UpdateDrawable(X11DRV_PDEVICE
*physDev
)
1681 /******************************************************************************
1682 * AlphaBlend (x11drv.@)
1684 BOOL
X11DRV_AlphaBlend(X11DRV_PDEVICE
*devDst
, INT xDst
, INT yDst
, INT widthDst
, INT heightDst
,
1685 X11DRV_PDEVICE
*devSrc
, INT xSrc
, INT ySrc
, INT widthSrc
, INT heightSrc
,
1686 BLENDFUNCTION blendfn
)
1688 FIXME("not supported - XRENDER headers were missing at compile time\n");
1692 #endif /* HAVE_X11_EXTENSIONS_XRENDER_H */