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"
36 #include "wine/library.h"
37 #include "wine/unicode.h"
38 #include "wine/debug.h"
40 static BOOL X11DRV_XRender_Installed = FALSE;
41 int using_client_side_fonts = FALSE;
43 WINE_DEFAULT_DEBUG_CHANNEL(xrender);
45 #ifdef HAVE_X11_EXTENSIONS_XRENDER_H
48 #include <X11/extensions/Xrender.h>
50 /* Older version of the Xrender headers don't define these */
51 #ifndef PictStandardARGB32
53 #define PictStandardARGB32 0
54 XRenderPictFormat * XRenderFindStandardFormat (Display *dpy, int format);
58 static XRenderPictFormat *screen_format; /* format of screen */
59 static XRenderPictFormat *mono_format; /* format of mono bitmap */
64 SIZE devsize; /* size in device coords */
68 #define INITIAL_REALIZED_BUF_SIZE 128
70 typedef enum { AA_None = 0, AA_Grey, AA_RGB, AA_BGR, AA_VRGB, AA_VBGR, AA_MAXVALUE } AA_Type;
75 XRenderPictFormat *font_format;
86 gsCacheEntryFormat * format[AA_MAXVALUE];
97 COLORREF lastTextColor;
101 static gsCacheEntry *glyphsetCache = NULL;
102 static DWORD glyphsetCacheSize = 0;
103 static INT lastfree = -1;
106 #define INIT_CACHE_SIZE 10
108 static int antialias = 1;
110 /* some default values just in case */
111 #ifndef SONAME_LIBX11
112 #define SONAME_LIBX11 "libX11.so"
114 #ifndef SONAME_LIBXEXT
115 #define SONAME_LIBXEXT "libXext.so"
117 #ifndef SONAME_LIBXRENDER
118 #define SONAME_LIBXRENDER "libXrender.so"
121 static void *xrender_handle;
123 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
124 MAKE_FUNCPTR(XRenderAddGlyphs)
125 MAKE_FUNCPTR(XRenderComposite)
126 MAKE_FUNCPTR(XRenderCompositeString8)
127 MAKE_FUNCPTR(XRenderCompositeString16)
128 MAKE_FUNCPTR(XRenderCompositeString32)
129 MAKE_FUNCPTR(XRenderCreateGlyphSet)
130 MAKE_FUNCPTR(XRenderCreatePicture)
131 MAKE_FUNCPTR(XRenderFillRectangle)
132 MAKE_FUNCPTR(XRenderFindFormat)
133 MAKE_FUNCPTR(XRenderFindStandardFormat)
134 MAKE_FUNCPTR(XRenderFindVisualFormat)
135 MAKE_FUNCPTR(XRenderFreeGlyphSet)
136 MAKE_FUNCPTR(XRenderFreePicture)
137 MAKE_FUNCPTR(XRenderSetPictureClipRectangles)
138 #ifdef HAVE_XRENDERSETPICTURETRANSFORM
139 MAKE_FUNCPTR(XRenderSetPictureTransform)
141 MAKE_FUNCPTR(XRenderQueryExtension)
144 static CRITICAL_SECTION xrender_cs;
145 static CRITICAL_SECTION_DEBUG critsect_debug =
148 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
149 0, 0, { 0, (DWORD)(__FILE__ ": xrender_cs") }
151 static CRITICAL_SECTION xrender_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
154 /***********************************************************************
155 * X11DRV_XRender_Init
157 * Let's see if our XServer has the extension available
160 void X11DRV_XRender_Init(void)
162 int error_base, event_base, i;
163 XRenderPictFormat pf;
165 if (client_side_with_render &&
166 wine_dlopen(SONAME_LIBX11, RTLD_NOW|RTLD_GLOBAL, NULL, 0) &&
167 wine_dlopen(SONAME_LIBXEXT, RTLD_NOW|RTLD_GLOBAL, NULL, 0) &&
168 (xrender_handle = wine_dlopen(SONAME_LIBXRENDER, RTLD_NOW, NULL, 0)))
171 #define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(xrender_handle, #f, NULL, 0)) == NULL) goto sym_not_found;
172 LOAD_FUNCPTR(XRenderAddGlyphs)
173 LOAD_FUNCPTR(XRenderComposite)
174 LOAD_FUNCPTR(XRenderCompositeString8)
175 LOAD_FUNCPTR(XRenderCompositeString16)
176 LOAD_FUNCPTR(XRenderCompositeString32)
177 LOAD_FUNCPTR(XRenderCreateGlyphSet)
178 LOAD_FUNCPTR(XRenderCreatePicture)
179 LOAD_FUNCPTR(XRenderFillRectangle)
180 LOAD_FUNCPTR(XRenderFindFormat)
181 LOAD_FUNCPTR(XRenderFindStandardFormat)
182 LOAD_FUNCPTR(XRenderFindVisualFormat)
183 LOAD_FUNCPTR(XRenderFreeGlyphSet)
184 LOAD_FUNCPTR(XRenderFreePicture)
185 LOAD_FUNCPTR(XRenderSetPictureClipRectangles)
186 LOAD_FUNCPTR(XRenderQueryExtension)
188 #ifdef HAVE_XRENDERSETPICTURETRANSFORM
189 #define LOAD_OPTIONAL_FUNCPTR(f) p##f = wine_dlsym(xrender_handle, #f, NULL, 0);
190 LOAD_OPTIONAL_FUNCPTR(XRenderSetPictureTransform)
191 #undef LOAD_OPTIONAL_FUNCPTR
196 if(pXRenderQueryExtension(gdi_display, &event_base, &error_base)) {
197 X11DRV_XRender_Installed = TRUE;
198 TRACE("Xrender is up and running error_base = %d\n", error_base);
199 screen_format = pXRenderFindVisualFormat(gdi_display, visual);
200 if(!screen_format) { /* This fails in buggy versions of libXrender.so */
203 "Wine has detected that you probably have a buggy version\n"
204 "of libXrender.so . Because of this client side font rendering\n"
205 "will be disabled. Please upgrade this library.\n");
206 X11DRV_XRender_Installed = FALSE;
209 pf.type = PictTypeDirect;
212 pf.direct.alphaMask = 1;
213 mono_format = pXRenderFindFormat(gdi_display, PictFormatType |
214 PictFormatDepth | PictFormatAlpha |
215 PictFormatAlphaMask, &pf, 0);
217 ERR("mono_format == NULL?\n");
218 X11DRV_XRender_Installed = FALSE;
225 if(X11DRV_XRender_Installed || client_side_with_core)
227 glyphsetCache = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
228 sizeof(*glyphsetCache) * INIT_CACHE_SIZE);
230 glyphsetCacheSize = INIT_CACHE_SIZE;
232 for(i = 0; i < INIT_CACHE_SIZE; i++) {
233 glyphsetCache[i].next = i + 1;
234 glyphsetCache[i].count = -1;
236 glyphsetCache[i-1].next = -1;
237 using_client_side_fonts = 1;
239 if(!X11DRV_XRender_Installed) {
240 TRACE("Xrender is not available on your XServer, client side rendering with the core protocol instead.\n");
241 if(screen_depth <= 8 || !client_side_antialias_with_core)
244 if(screen_depth <= 8 || !client_side_antialias_with_render)
248 else TRACE("Using X11 core fonts\n");
251 static BOOL fontcmp(LFANDSIZE *p1, LFANDSIZE *p2)
253 if(p1->hash != p2->hash) return TRUE;
254 if(memcmp(&p1->devsize, &p2->devsize, sizeof(p1->devsize))) return TRUE;
255 if(memcmp(&p1->lf, &p2->lf, offsetof(LOGFONTW, lfFaceName))) return TRUE;
256 return strcmpW(p1->lf.lfFaceName, p2->lf.lfFaceName);
260 static void walk_cache(void)
264 EnterCriticalSection(&xrender_cs);
265 for(i=mru; i >= 0; i = glyphsetCache[i].next)
266 TRACE("item %d\n", i);
267 LeaveCriticalSection(&xrender_cs);
271 static int LookupEntry(LFANDSIZE *plfsz)
275 for(i = mru; i >= 0; i = glyphsetCache[i].next) {
277 if(glyphsetCache[i].count == -1) { /* reached free list so stop */
282 if(!fontcmp(&glyphsetCache[i].lfsz, plfsz)) {
283 glyphsetCache[i].count++;
285 glyphsetCache[prev_i].next = glyphsetCache[i].next;
286 glyphsetCache[i].next = mru;
289 TRACE("found font in cache %d\n", i);
294 TRACE("font not in cache\n");
298 static void FreeEntry(int entry)
302 for(format = 0; format < AA_MAXVALUE; format++) {
303 gsCacheEntryFormat * formatEntry;
305 if( !glyphsetCache[entry].format[format] )
308 formatEntry = glyphsetCache[entry].format[format];
310 if(formatEntry->glyphset) {
312 pXRenderFreeGlyphSet(gdi_display, formatEntry->glyphset);
314 formatEntry->glyphset = 0;
316 if(formatEntry->nrealized) {
317 HeapFree(GetProcessHeap(), 0, formatEntry->realized);
318 formatEntry->realized = NULL;
319 if(formatEntry->bitmaps) {
320 for(i = 0; i < formatEntry->nrealized; i++)
321 if(formatEntry->bitmaps[i])
322 HeapFree(GetProcessHeap(), 0, formatEntry->bitmaps[i]);
323 HeapFree(GetProcessHeap(), 0, formatEntry->bitmaps);
324 formatEntry->bitmaps = NULL;
325 HeapFree(GetProcessHeap(), 0, formatEntry->gis);
326 formatEntry->gis = NULL;
328 formatEntry->nrealized = 0;
331 HeapFree(GetProcessHeap(), 0, formatEntry);
332 glyphsetCache[entry].format[format] = NULL;
336 static int AllocEntry(void)
338 int best = -1, prev_best = -1, i, prev_i = -1;
341 assert(glyphsetCache[lastfree].count == -1);
342 glyphsetCache[lastfree].count = 1;
344 lastfree = glyphsetCache[lastfree].next;
346 glyphsetCache[best].next = mru;
349 TRACE("empty space at %d, next lastfree = %d\n", mru, lastfree);
353 for(i = mru; i >= 0; i = glyphsetCache[i].next) {
354 if(glyphsetCache[i].count == 0) {
362 TRACE("freeing unused glyphset at cache %d\n", best);
364 glyphsetCache[best].count = 1;
366 glyphsetCache[prev_best].next = glyphsetCache[best].next;
367 glyphsetCache[best].next = mru;
375 TRACE("Growing cache\n");
378 glyphsetCache = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
380 (glyphsetCacheSize + INIT_CACHE_SIZE)
381 * sizeof(*glyphsetCache));
383 glyphsetCache = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
384 (glyphsetCacheSize + INIT_CACHE_SIZE)
385 * sizeof(*glyphsetCache));
387 for(best = i = glyphsetCacheSize; i < glyphsetCacheSize + INIT_CACHE_SIZE;
389 glyphsetCache[i].next = i + 1;
390 glyphsetCache[i].count = -1;
392 glyphsetCache[i-1].next = -1;
393 glyphsetCacheSize += INIT_CACHE_SIZE;
395 lastfree = glyphsetCache[best].next;
396 glyphsetCache[best].count = 1;
397 glyphsetCache[best].next = mru;
399 TRACE("new free cache slot at %d\n", mru);
403 static int GetCacheEntry(LFANDSIZE *plfsz)
409 if((ret = LookupEntry(plfsz)) != -1) return ret;
412 entry = glyphsetCache + ret;
413 entry->lfsz = *plfsz;
414 for( format = 0; format < AA_MAXVALUE; format++ ) {
415 assert( !entry->format[format] );
419 entry->aa_default = AA_Grey;
421 entry->aa_default = AA_None;
426 static void dec_ref_cache(int index)
429 TRACE("dec'ing entry %d to %d\n", index, glyphsetCache[index].count - 1);
430 assert(glyphsetCache[index].count > 0);
431 glyphsetCache[index].count--;
434 static void lfsz_calc_hash(LFANDSIZE *plfsz)
436 DWORD hash = 0, *ptr;
439 hash ^= plfsz->devsize.cx;
440 hash ^= plfsz->devsize.cy;
441 for(i = 0, ptr = (DWORD*)&plfsz->lf; i < 7; i++, ptr++)
443 for(i = 0, ptr = (DWORD*)&plfsz->lf.lfFaceName; i < LF_FACESIZE/2; i++, ptr++) {
444 WCHAR *pwc = (WCHAR *)ptr;
454 /***********************************************************************
455 * X11DRV_XRender_Finalize
457 void X11DRV_XRender_Finalize(void)
461 EnterCriticalSection(&xrender_cs);
462 for(i = mru; i >= 0; i = glyphsetCache[i].next)
464 LeaveCriticalSection(&xrender_cs);
468 /***********************************************************************
469 * X11DRV_XRender_SelectFont
471 BOOL X11DRV_XRender_SelectFont(X11DRV_PDEVICE *physDev, HFONT hfont)
475 GetObjectW(hfont, sizeof(lfsz.lf), &lfsz.lf);
476 TRACE("h=%ld w=%ld weight=%ld it=%d charset=%d name=%s\n",
477 lfsz.lf.lfHeight, lfsz.lf.lfWidth, lfsz.lf.lfWeight,
478 lfsz.lf.lfItalic, lfsz.lf.lfCharSet, debugstr_w(lfsz.lf.lfFaceName));
479 lfsz.devsize.cx = X11DRV_XWStoDS( physDev, lfsz.lf.lfWidth );
480 lfsz.devsize.cy = X11DRV_YWStoDS( physDev, lfsz.lf.lfHeight );
481 lfsz_calc_hash(&lfsz);
483 EnterCriticalSection(&xrender_cs);
484 if(!physDev->xrender) {
485 physDev->xrender = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
486 sizeof(*physDev->xrender));
487 physDev->xrender->cache_index = -1;
489 else if(physDev->xrender->cache_index != -1)
490 dec_ref_cache(physDev->xrender->cache_index);
491 physDev->xrender->cache_index = GetCacheEntry(&lfsz);
492 LeaveCriticalSection(&xrender_cs);
496 /***********************************************************************
497 * X11DRV_XRender_DeleteDC
499 void X11DRV_XRender_DeleteDC(X11DRV_PDEVICE *physDev)
502 if(physDev->xrender->tile_pict)
503 pXRenderFreePicture(gdi_display, physDev->xrender->tile_pict);
505 if(physDev->xrender->tile_xpm)
506 XFreePixmap(gdi_display, physDev->xrender->tile_xpm);
508 if(physDev->xrender->pict) {
509 TRACE("freeing pict = %lx dc = %p\n", physDev->xrender->pict, physDev->hdc);
510 pXRenderFreePicture(gdi_display, physDev->xrender->pict);
514 EnterCriticalSection(&xrender_cs);
515 if(physDev->xrender->cache_index != -1)
516 dec_ref_cache(physDev->xrender->cache_index);
517 LeaveCriticalSection(&xrender_cs);
519 HeapFree(GetProcessHeap(), 0, physDev->xrender);
520 physDev->xrender = NULL;
524 /***********************************************************************
525 * X11DRV_XRender_UpdateDrawable
527 * This gets called from X11DRV_SetDrawable and X11DRV_SelectBitmap.
528 * It deletes the pict when the drawable changes.
530 void X11DRV_XRender_UpdateDrawable(X11DRV_PDEVICE *physDev)
532 if(physDev->xrender->pict) {
533 TRACE("freeing pict %08lx from dc %p drawable %08lx\n", physDev->xrender->pict,
534 physDev->hdc, physDev->drawable);
537 pXRenderFreePicture(gdi_display, physDev->xrender->pict);
540 physDev->xrender->pict = 0;
544 /************************************************************************
547 * Helper to ExtTextOut. Must be called inside xrender_cs
549 static BOOL UploadGlyph(X11DRV_PDEVICE *physDev, int glyph, AA_Type format)
556 gsCacheEntry *entry = glyphsetCache + physDev->xrender->cache_index;
557 gsCacheEntryFormat *formatEntry;
558 UINT ggo_format = GGO_GLYPH_INDEX;
559 XRenderPictFormat pf;
561 /* If there is nothing for the current type, we create the entry. */
562 if( !entry->format[format] ) {
563 entry->format[format] = HeapAlloc(GetProcessHeap(),
565 sizeof(gsCacheEntryFormat));
567 formatEntry = entry->format[format];
569 if(formatEntry->nrealized <= glyph) {
570 formatEntry->nrealized = (glyph / 128 + 1) * 128;
572 if (formatEntry->realized)
573 formatEntry->realized = HeapReAlloc(GetProcessHeap(),
575 formatEntry->realized,
576 formatEntry->nrealized * sizeof(BOOL));
578 formatEntry->realized = HeapAlloc(GetProcessHeap(),
580 formatEntry->nrealized * sizeof(BOOL));
582 if(!X11DRV_XRender_Installed) {
583 if (formatEntry->bitmaps)
584 formatEntry->bitmaps = HeapReAlloc(GetProcessHeap(),
586 formatEntry->bitmaps,
587 formatEntry->nrealized * sizeof(formatEntry->bitmaps[0]));
589 formatEntry->bitmaps = HeapAlloc(GetProcessHeap(),
591 formatEntry->nrealized * sizeof(formatEntry->bitmaps[0]));
593 if (formatEntry->gis)
594 formatEntry->gis = HeapReAlloc(GetProcessHeap(),
597 formatEntry->nrealized * sizeof(formatEntry->gis[0]));
599 formatEntry->gis = HeapAlloc(GetProcessHeap(),
601 formatEntry->nrealized * sizeof(formatEntry->gis[0]));
607 ggo_format |= WINE_GGO_GRAY16_BITMAP;
611 ERR("aa = %d - not implemented\n", format);
613 ggo_format |= GGO_BITMAP;
617 buflen = GetGlyphOutlineW(physDev->hdc, glyph, ggo_format, &gm, 0, NULL,
619 if(buflen == GDI_ERROR) {
620 if(format != AA_None) {
622 entry->aa_default = AA_None;
623 ggo_format &= ~WINE_GGO_GRAY16_BITMAP;
624 ggo_format |= GGO_BITMAP;
625 buflen = GetGlyphOutlineW(physDev->hdc, glyph, ggo_format, &gm, 0, NULL,
628 if(buflen == GDI_ERROR) {
629 ERR("GetGlyphOutlineW failed\n");
632 TRACE("Turning off antialiasing for this monochrome font\n");
635 if(formatEntry->glyphset == 0 && X11DRV_XRender_Installed) {
639 pf.direct.alphaMask = 0xff;
643 ERR("aa = %d - not implemented\n", format);
646 pf.direct.alphaMask = 1;
650 pf.type = PictTypeDirect;
654 formatEntry->font_format = pXRenderFindFormat(gdi_display,
661 formatEntry->glyphset = pXRenderCreateGlyphSet(gdi_display, formatEntry->font_format);
666 buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buflen);
667 GetGlyphOutlineW(physDev->hdc, glyph, ggo_format, &gm, buflen, buf, NULL);
668 formatEntry->realized[glyph] = TRUE;
670 TRACE("buflen = %d. Got metrics: %dx%d adv=%d,%d origin=%ld,%ld\n",
672 gm.gmBlackBoxX, gm.gmBlackBoxY, gm.gmCellIncX, gm.gmCellIncY,
673 gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
675 gi.width = gm.gmBlackBoxX;
676 gi.height = gm.gmBlackBoxY;
677 gi.x = -gm.gmptGlyphOrigin.x;
678 gi.y = gm.gmptGlyphOrigin.y;
679 gi.xOff = gm.gmCellIncX;
680 gi.yOff = gm.gmCellIncY;
682 if(TRACE_ON(xrender)) {
687 if(format == AA_None) {
688 pitch = ((gi.width + 31) / 32) * 4;
689 for(i = 0; i < gi.height; i++) {
690 line = buf + i * pitch;
692 for(j = 0; j < pitch * 8; j++) {
693 strcat(output, (line[j / 8] & (1 << (7 - (j % 8)))) ? "#" : " ");
695 strcat(output, "\n");
699 static const char blks[] = " .:;!o*#";
703 pitch = ((gi.width + 3) / 4) * 4;
704 for(i = 0; i < gi.height; i++) {
705 line = buf + i * pitch;
707 for(j = 0; j < pitch; j++) {
708 str[0] = blks[line[j] >> 5];
711 strcat(output, "\n");
717 if(formatEntry->glyphset) {
718 if(format == AA_None && BitmapBitOrder(gdi_display) != MSBFirst) {
719 unsigned char *byte = buf, c;
725 /* magic to flip bit order */
726 c = ((c << 1) & 0xaa) | ((c >> 1) & 0x55);
727 c = ((c << 2) & 0xcc) | ((c >> 2) & 0x33);
728 c = ((c << 4) & 0xf0) | ((c >> 4) & 0x0f);
735 pXRenderAddGlyphs(gdi_display, formatEntry->glyphset, &gid, &gi, 1,
738 HeapFree(GetProcessHeap(), 0, buf);
740 formatEntry->bitmaps[glyph] = buf;
741 memcpy(&formatEntry->gis[glyph], &gi, sizeof(gi));
746 static void SharpGlyphMono(X11DRV_PDEVICE *physDev, INT x, INT y,
747 void *bitmap, XGlyphInfo *gi)
749 unsigned char *srcLine = bitmap, *src;
750 unsigned char bits, bitsMask;
751 int width = gi->width;
752 int stride = ((width + 31) & ~31) >> 3;
753 int height = gi->height;
757 TRACE("%d, %d\n", x, y);
766 bitsMask = 0x80; /* FreeType is always MSB first */
780 bitsMask = bitsMask >> 1;
786 } while (bits & bitsMask);
787 XFillRectangle (gdi_display, physDev->drawable,
788 physDev->gc, xspan, y, lenspan, 1);
800 bitsMask = bitsMask >> 1;
806 } while (!(bits & bitsMask));
813 static void SharpGlyphGray(X11DRV_PDEVICE *physDev, INT x, INT y,
814 void *bitmap, XGlyphInfo *gi)
816 unsigned char *srcLine = bitmap, *src, bits;
817 int width = gi->width;
818 int stride = ((width + 3) & ~3);
819 int height = gi->height;
844 } while (bits >= 0x80);
845 XFillRectangle (gdi_display, physDev->drawable,
846 physDev->gc, xspan, y, lenspan, 1);
859 } while (bits < 0x80);
867 static void ExamineBitfield (DWORD mask, int *shift, int *len)
872 while ((mask & 1) == 0)
878 while ((mask & 1) == 1)
887 static DWORD GetField (DWORD pixel, int shift, int len)
889 pixel = pixel & (((1 << (len)) - 1) << shift);
890 pixel = pixel << (32 - (shift + len)) >> 24;
893 pixel |= (pixel >> len);
900 static DWORD PutField (DWORD pixel, int shift, int len)
902 shift = shift - (8 - len);
904 pixel &= (((1 << len) - 1) << (8 - len));
912 static void SmoothGlyphGray(XImage *image, int x, int y, void *bitmap, XGlyphInfo *gi,
918 BYTE *maskLine, *mask, m;
923 BYTE src_r, src_g, src_b;
930 maskLine = (unsigned char *) bitmap;
931 maskStride = (width + 3) & ~3;
933 ExamineBitfield (image->red_mask, &r_shift, &r_len);
934 ExamineBitfield (image->green_mask, &g_shift, &g_len);
935 ExamineBitfield (image->blue_mask, &b_shift, &b_len);
937 src_r = GetField(color, r_shift, r_len);
938 src_g = GetField(color, g_shift, g_len);
939 src_b = GetField(color, b_shift, b_len);
944 maskLine += maskStride;
949 if(y >= image->height) break;
953 if(tx >= image->width) break;
959 XPutPixel (image, tx, y, color);
964 pixel = XGetPixel (image, tx, y);
966 r = GetField(pixel, r_shift, r_len);
967 r = ((BYTE)~m * (WORD)r + (BYTE)m * (WORD)src_r) >> 8;
968 g = GetField(pixel, g_shift, g_len);
969 g = ((BYTE)~m * (WORD)g + (BYTE)m * (WORD)src_g) >> 8;
970 b = GetField(pixel, b_shift, b_len);
971 b = ((BYTE)~m * (WORD)b + (BYTE)m * (WORD)src_b) >> 8;
973 pixel = (PutField (r, r_shift, r_len) |
974 PutField (g, g_shift, g_len) |
975 PutField (b, b_shift, b_len));
976 XPutPixel (image, tx, y, pixel);
982 static int XRenderErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
987 /***********************************************************************
988 * X11DRV_XRender_ExtTextOut
990 BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flags,
991 const RECT *lprect, LPCWSTR wstr, UINT count,
992 const INT *lpDx, INT breakExtra )
1000 BOOL done_extents = FALSE;
1001 INT width, xwidth, ywidth;
1002 double cosEsc, sinEsc;
1005 int render_op = PictOpOver;
1008 gsCacheEntry *entry;
1009 gsCacheEntryFormat *formatEntry;
1011 HDC hdc = physDev->hdc;
1012 int textPixel, backgroundPixel;
1013 INT *deltas = NULL, char_extra;
1014 HRGN saved_region = 0;
1015 UINT align = GetTextAlign( hdc );
1017 TRACE("%p, %d, %d, %08x, %p, %s, %d, %p)\n", hdc, x, y, flags,
1018 lprect, debugstr_wn(wstr, count), count, lpDx);
1020 if(flags & ETO_GLYPH_INDEX)
1021 glyphs = (const WORD*)wstr;
1023 glyphs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
1024 GetGlyphIndicesW(hdc, wstr, count, (WORD*)glyphs, 0);
1028 TRACE("rect: %ld,%ld - %ld,%ld\n", lprect->left, lprect->top, lprect->right,
1030 TRACE("align = %x bkmode = %x mapmode = %x\n", align, GetBkMode(hdc), GetMapMode(hdc));
1032 if(align & TA_UPDATECP)
1034 GetCurrentPositionEx( hdc, &pt );
1039 GetTextMetricsW(hdc, &tm);
1040 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
1042 if(!(tm.tmPitchAndFamily & TMPF_VECTOR)) /* Non-scalable fonts shouldn't be rotated */
1043 lf.lfEscapement = 0;
1045 if(lf.lfEscapement != 0) {
1046 cosEsc = cos(lf.lfEscapement * M_PI / 1800);
1047 sinEsc = sin(lf.lfEscapement * M_PI / 1800);
1053 if(flags & (ETO_CLIPPED | ETO_OPAQUE)) {
1055 if(flags & ETO_CLIPPED) return FALSE;
1056 GetTextExtentPointI(hdc, glyphs, count, &sz);
1057 done_extents = TRUE;
1060 rc.right = x + sz.cx;
1061 rc.bottom = y + sz.cy;
1066 LPtoDP(hdc, (POINT*)&rc, 2);
1068 if(rc.left > rc.right) {INT tmp = rc.left; rc.left = rc.right; rc.right = tmp;}
1069 if(rc.top > rc.bottom) {INT tmp = rc.top; rc.top = rc.bottom; rc.bottom = tmp;}
1072 xgcval.function = GXcopy;
1073 xgcval.background = physDev->backgroundPixel;
1074 xgcval.fill_style = FillSolid;
1076 XChangeGC( gdi_display, physDev->gc, GCFunction | GCBackground | GCFillStyle, &xgcval );
1077 wine_tsx11_unlock();
1079 X11DRV_LockDIBSection( physDev, DIB_Status_GdiMod, FALSE );
1081 if(physDev->depth == 1) {
1082 if((physDev->textPixel & 0xffffff) == 0) {
1084 backgroundPixel = 1;
1087 backgroundPixel = 0;
1090 textPixel = physDev->textPixel;
1091 backgroundPixel = physDev->backgroundPixel;
1094 if(flags & ETO_OPAQUE) {
1096 XSetForeground( gdi_display, physDev->gc, backgroundPixel );
1097 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
1098 physDev->org.x + rc.left, physDev->org.y + rc.top,
1099 rc.right - rc.left, rc.bottom - rc.top );
1100 wine_tsx11_unlock();
1110 LPtoDP(hdc, &pt, 1);
1114 TRACE("real x,y %d,%d\n", x, y);
1116 if((char_extra = GetTextCharacterExtra(hdc)) != 0) {
1119 deltas = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT));
1120 for(i = 0; i < count; i++) {
1122 deltas[i] = lpDx[i] + char_extra;
1124 GetTextExtentPointI(hdc, glyphs + i, 1, &tmpsz);
1125 deltas[i] = tmpsz.cx;
1129 deltas = (INT*)lpDx;
1133 for(idx = 0; idx < count; idx++)
1134 width += deltas[idx];
1137 GetTextExtentPointI(hdc, glyphs, count, &sz);
1138 done_extents = TRUE;
1142 width = X11DRV_XWStoDS(physDev, width);
1143 xwidth = width * cosEsc;
1144 ywidth = width * sinEsc;
1146 tm.tmAscent = abs(X11DRV_YWStoDS(physDev, tm.tmAscent));
1147 tm.tmDescent = abs(X11DRV_YWStoDS(physDev, tm.tmDescent));
1148 switch( align & (TA_LEFT | TA_RIGHT | TA_CENTER) ) {
1150 if (align & TA_UPDATECP) {
1153 DPtoLP(hdc, &pt, 1);
1154 MoveToEx(hdc, pt.x, pt.y, NULL);
1166 if (align & TA_UPDATECP) {
1169 DPtoLP(hdc, &pt, 1);
1170 MoveToEx(hdc, pt.x, pt.y, NULL);
1175 switch( align & (TA_TOP | TA_BOTTOM | TA_BASELINE) ) {
1177 y += tm.tmAscent * cosEsc;
1178 x += tm.tmAscent * sinEsc;
1182 y -= tm.tmDescent * cosEsc;
1183 x -= tm.tmDescent * sinEsc;
1190 if (flags & ETO_CLIPPED)
1193 RECT clip_rect = *lprect;
1195 LPtoDP( hdc, (POINT *)&clip_rect, 2 );
1196 clip_region = CreateRectRgnIndirect( &clip_rect );
1197 /* make a copy of the current device region */
1198 saved_region = CreateRectRgn( 0, 0, 0, 0 );
1199 CombineRgn( saved_region, physDev->region, 0, RGN_COPY );
1200 X11DRV_SetDeviceClipping( physDev, saved_region, clip_region );
1201 DeleteObject( clip_region );
1204 if(X11DRV_XRender_Installed) {
1205 if(!physDev->xrender->pict) {
1206 XRenderPictureAttributes pa;
1207 pa.subwindow_mode = IncludeInferiors;
1210 physDev->xrender->pict = pXRenderCreatePicture(gdi_display,
1212 (physDev->depth == 1) ?
1213 mono_format : screen_format,
1214 CPSubwindowMode, &pa);
1215 wine_tsx11_unlock();
1217 TRACE("allocing pict = %lx dc = %p drawable = %08lx\n",
1218 physDev->xrender->pict, hdc, physDev->drawable);
1220 TRACE("using existing pict = %lx dc = %p drawable = %08lx\n",
1221 physDev->xrender->pict, hdc, physDev->drawable);
1224 if ((data = X11DRV_GetRegionData( physDev->region, 0 )))
1227 pXRenderSetPictureClipRectangles( gdi_display, physDev->xrender->pict,
1228 physDev->org.x, physDev->org.y,
1229 (XRectangle *)data->Buffer, data->rdh.nCount );
1230 wine_tsx11_unlock();
1231 HeapFree( GetProcessHeap(), 0, data );
1235 if(GetBkMode(hdc) != TRANSPARENT) {
1236 if(!((flags & ETO_CLIPPED) && (flags & ETO_OPAQUE))) {
1237 if(!(flags & ETO_OPAQUE) || x < rc.left || x + width >= rc.right ||
1238 y - tm.tmAscent < rc.top || y + tm.tmDescent >= rc.bottom) {
1240 XSetForeground( gdi_display, physDev->gc, backgroundPixel );
1241 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
1242 physDev->org.x + x, physDev->org.y + y - tm.tmAscent,
1243 width, tm.tmAscent + tm.tmDescent );
1244 wine_tsx11_unlock();
1249 if(X11DRV_XRender_Installed) {
1250 /* Create a 1x1 pixmap to tile over the font mask */
1251 if(!physDev->xrender->tile_xpm) {
1252 XRenderPictureAttributes pa;
1254 XRenderPictFormat *format = (physDev->depth == 1) ? mono_format : screen_format;
1256 physDev->xrender->tile_xpm = XCreatePixmap(gdi_display,
1261 physDev->xrender->tile_pict = pXRenderCreatePicture(gdi_display,
1262 physDev->xrender->tile_xpm,
1265 wine_tsx11_unlock();
1266 TRACE("Created pixmap of depth %d\n", format->depth);
1267 /* init lastTextColor to something different from textPixel */
1268 physDev->xrender->lastTextColor = ~physDev->textPixel;
1272 if(physDev->textPixel != physDev->xrender->lastTextColor) {
1273 if(physDev->depth != 1) {
1274 /* Map 0 -- 0xff onto 0 -- 0xffff */
1279 ExamineBitfield (visual->red_mask, &r_shift, &r_len );
1280 ExamineBitfield (visual->green_mask, &g_shift, &g_len);
1281 ExamineBitfield (visual->blue_mask, &b_shift, &b_len);
1283 col.red = GetField(physDev->textPixel, r_shift, r_len);
1284 col.red |= col.red << 8;
1285 col.green = GetField(physDev->textPixel, g_shift, g_len);
1286 col.green |= col.green << 8;
1287 col.blue = GetField(physDev->textPixel, b_shift, b_len);
1288 col.blue |= col.blue << 8;
1290 } else { /* for a 1bpp bitmap we always need a 1 in the tile */
1291 col.red = col.green = col.blue = 0;
1295 pXRenderFillRectangle(gdi_display, PictOpSrc,
1296 physDev->xrender->tile_pict,
1298 wine_tsx11_unlock();
1299 physDev->xrender->lastTextColor = physDev->textPixel;
1302 /* FIXME the mapping of Text/BkColor onto 1 or 0 needs investigation.
1304 if((physDev->depth == 1) && (textPixel == 0))
1305 render_op = PictOpOutReverse; /* This gives us 'black' text */
1308 EnterCriticalSection(&xrender_cs);
1309 entry = glyphsetCache + physDev->xrender->cache_index;
1310 formatEntry = entry->format[entry->aa_default];
1312 for(idx = 0; idx < count; idx++) {
1313 if( !formatEntry ) {
1314 UploadGlyph(physDev, glyphs[idx], entry->aa_default);
1315 formatEntry = entry->format[entry->aa_default];
1316 } else if( glyphs[idx] >= formatEntry->nrealized || formatEntry->realized[glyphs[idx]] == FALSE) {
1317 UploadGlyph(physDev, glyphs[idx], entry->aa_default);
1320 assert(formatEntry);
1322 TRACE("Writing %s at %ld,%ld\n", debugstr_wn(wstr,count),
1323 physDev->org.x + x, physDev->org.y + y);
1325 if(X11DRV_XRender_Installed) {
1328 pXRenderCompositeString16(gdi_display, render_op,
1329 physDev->xrender->tile_pict,
1330 physDev->xrender->pict,
1331 formatEntry->font_format, formatEntry->glyphset,
1332 0, 0, physDev->org.x + x, physDev->org.y + y,
1336 INT offset = 0, xoff = 0, yoff = 0;
1337 for(idx = 0; idx < count; idx++) {
1338 pXRenderCompositeString16(gdi_display, render_op,
1339 physDev->xrender->tile_pict,
1340 physDev->xrender->pict,
1341 formatEntry->font_format, formatEntry->glyphset,
1342 0, 0, physDev->org.x + x + xoff,
1343 physDev->org.y + y + yoff,
1345 offset += X11DRV_XWStoDS(physDev, deltas[idx]);
1346 xoff = offset * cosEsc;
1347 yoff = offset * -sinEsc;
1350 wine_tsx11_unlock();
1353 INT offset = 0, xoff = 0, yoff = 0;
1355 XSetForeground( gdi_display, physDev->gc, textPixel );
1357 if(entry->aa_default == AA_None) {
1358 for(idx = 0; idx < count; idx++) {
1359 SharpGlyphMono(physDev, physDev->org.x + x + xoff,
1360 physDev->org.y + y + yoff,
1361 formatEntry->bitmaps[glyphs[idx]],
1362 &formatEntry->gis[glyphs[idx]]);
1364 offset += X11DRV_XWStoDS(physDev, deltas[idx]);
1365 xoff = offset * cosEsc;
1366 yoff = offset * -sinEsc;
1369 xoff += formatEntry->gis[glyphs[idx]].xOff;
1370 yoff += formatEntry->gis[glyphs[idx]].yOff;
1373 } else if(physDev->depth == 1) {
1374 for(idx = 0; idx < count; idx++) {
1375 SharpGlyphGray(physDev, physDev->org.x + x + xoff,
1376 physDev->org.y + y + yoff,
1377 formatEntry->bitmaps[glyphs[idx]],
1378 &formatEntry->gis[glyphs[idx]]);
1380 offset += X11DRV_XWStoDS(physDev, deltas[idx]);
1381 xoff = offset * cosEsc;
1382 yoff = offset * -sinEsc;
1385 xoff += formatEntry->gis[glyphs[idx]].xOff;
1386 yoff += formatEntry->gis[glyphs[idx]].yOff;
1392 unsigned int w, h, dummy_uint;
1393 Window dummy_window;
1395 int image_x, image_y, image_off_x, image_off_y, image_w, image_h;
1396 RECT extents = {0, 0, 0, 0};
1400 XGetGeometry(gdi_display, physDev->drawable, &dummy_window, &dummy_int, &dummy_int,
1401 &w, &h, &dummy_uint, &dummy_uint);
1402 TRACE("drawable %dx%d\n", w, h);
1404 for(idx = 0; idx < count; idx++) {
1405 if(extents.left > cur.x - formatEntry->gis[glyphs[idx]].x)
1406 extents.left = cur.x - formatEntry->gis[glyphs[idx]].x;
1407 if(extents.top > cur.y - formatEntry->gis[glyphs[idx]].y)
1408 extents.top = cur.y - formatEntry->gis[glyphs[idx]].y;
1409 if(extents.right < cur.x - formatEntry->gis[glyphs[idx]].x + formatEntry->gis[glyphs[idx]].width)
1410 extents.right = cur.x - formatEntry->gis[glyphs[idx]].x + formatEntry->gis[glyphs[idx]].width;
1411 if(extents.bottom < cur.y - formatEntry->gis[glyphs[idx]].y + formatEntry->gis[glyphs[idx]].height)
1412 extents.bottom = cur.y - formatEntry->gis[glyphs[idx]].y + formatEntry->gis[glyphs[idx]].height;
1414 offset += X11DRV_XWStoDS(physDev, deltas[idx]);
1415 cur.x = offset * cosEsc;
1416 cur.y = offset * -sinEsc;
1418 cur.x += formatEntry->gis[glyphs[idx]].xOff;
1419 cur.y += formatEntry->gis[glyphs[idx]].yOff;
1422 TRACE("glyph extents %ld,%ld - %ld,%ld drawable x,y %ld,%ld\n", extents.left, extents.top,
1423 extents.right, extents.bottom, physDev->org.x + x, physDev->org.y + y);
1425 if(physDev->org.x + x + extents.left >= 0) {
1426 image_x = physDev->org.x + x + extents.left;
1430 image_off_x = physDev->org.x + x + extents.left;
1432 if(physDev->org.y + y + extents.top >= 0) {
1433 image_y = physDev->org.y + y + extents.top;
1437 image_off_y = physDev->org.y + y + extents.top;
1439 if(physDev->org.x + x + extents.right < w)
1440 image_w = physDev->org.x + x + extents.right - image_x;
1442 image_w = w - image_x;
1443 if(physDev->org.y + y + extents.bottom < h)
1444 image_h = physDev->org.y + y + extents.bottom - image_y;
1446 image_h = h - image_y;
1448 if(image_w <= 0 || image_h <= 0) goto no_image;
1450 X11DRV_expect_error(gdi_display, XRenderErrorHandler, NULL);
1451 image = XGetImage(gdi_display, physDev->drawable,
1452 image_x, image_y, image_w, image_h,
1453 AllPlanes, ZPixmap);
1454 X11DRV_check_error();
1456 TRACE("XGetImage(%p, %x, %d, %d, %d, %d, %lx, %x) depth = %d rets %p\n",
1457 gdi_display, (int)physDev->drawable, image_x, image_y,
1458 image_w, image_h, AllPlanes, ZPixmap,
1459 physDev->depth, image);
1461 Pixmap xpm = XCreatePixmap(gdi_display, physDev->drawable, image_w, image_h,
1466 gcv.graphics_exposures = False;
1467 gc = XCreateGC(gdi_display, xpm, GCGraphicsExposures, &gcv);
1468 XCopyArea(gdi_display, physDev->drawable, xpm, gc, image_x, image_y,
1469 image_w, image_h, 0, 0);
1470 XFreeGC(gdi_display, gc);
1471 X11DRV_expect_error(gdi_display, XRenderErrorHandler, NULL);
1472 image = XGetImage(gdi_display, xpm, 0, 0, image_w, image_h, AllPlanes,
1474 X11DRV_check_error();
1475 XFreePixmap(gdi_display, xpm);
1477 if(!image) goto no_image;
1479 image->red_mask = visual->red_mask;
1480 image->green_mask = visual->green_mask;
1481 image->blue_mask = visual->blue_mask;
1483 offset = xoff = yoff = 0;
1484 for(idx = 0; idx < count; idx++) {
1485 SmoothGlyphGray(image, xoff + image_off_x - extents.left,
1486 yoff + image_off_y - extents.top,
1487 formatEntry->bitmaps[glyphs[idx]],
1488 &formatEntry->gis[glyphs[idx]],
1489 physDev->textPixel);
1491 offset += X11DRV_XWStoDS(physDev, deltas[idx]);
1492 xoff = offset * cosEsc;
1493 yoff = offset * -sinEsc;
1495 xoff += formatEntry->gis[glyphs[idx]].xOff;
1496 yoff += formatEntry->gis[glyphs[idx]].yOff;
1500 XPutImage(gdi_display, physDev->drawable, physDev->gc, image, 0, 0,
1501 image_x, image_y, image_w, image_h);
1502 XDestroyImage(image);
1505 wine_tsx11_unlock();
1507 LeaveCriticalSection(&xrender_cs);
1509 if (lf.lfUnderline || lf.lfStrikeOut) {
1510 int underlinePos, strikeoutPos;
1511 int underlineWidth, strikeoutWidth;
1512 UINT nMetricsSize = GetOutlineTextMetricsW(hdc, 0, NULL);
1513 OUTLINETEXTMETRICW* otm = NULL;
1517 underlineWidth = tm.tmAscent / 20 + 1;
1518 strikeoutPos = tm.tmAscent / 2;
1519 strikeoutWidth = underlineWidth;
1521 otm = HeapAlloc(GetProcessHeap(), 0, nMetricsSize);
1522 if (!otm) goto done;
1524 GetOutlineTextMetricsW(hdc, nMetricsSize, otm);
1525 underlinePos = otm->otmsUnderscorePosition;
1526 underlineWidth = otm->otmsUnderscoreSize;
1527 strikeoutPos = otm->otmsStrikeoutPosition;
1528 strikeoutWidth = otm->otmsStrikeoutSize;
1532 XSetForeground( gdi_display, physDev->gc, physDev->textPixel );
1534 if (lf.lfUnderline) {
1535 underlinePos = X11DRV_YWStoDS(physDev, underlinePos);
1536 underlineWidth = X11DRV_YWStoDS(physDev, underlineWidth);
1538 XSetLineAttributes( gdi_display, physDev->gc, underlineWidth,
1539 LineSolid, CapProjecting, JoinBevel );
1540 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
1541 physDev->org.x + x - underlinePos * sinEsc,
1542 physDev->org.y + y - underlinePos * cosEsc,
1543 physDev->org.x + x + width * cosEsc - underlinePos * sinEsc,
1544 physDev->org.y + y - width * sinEsc - underlinePos * cosEsc );
1547 if (lf.lfStrikeOut) {
1548 strikeoutPos = X11DRV_YWStoDS(physDev, strikeoutPos);
1549 strikeoutWidth = X11DRV_YWStoDS(physDev, strikeoutWidth);
1551 XSetLineAttributes( gdi_display, physDev->gc, strikeoutWidth,
1552 LineSolid, CapProjecting, JoinBevel );
1553 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
1554 physDev->org.x + x - strikeoutPos * sinEsc,
1555 physDev->org.y + y - strikeoutPos * cosEsc,
1556 physDev->org.x + x + width * cosEsc - strikeoutPos * sinEsc,
1557 physDev->org.y + y - width * sinEsc - strikeoutPos * cosEsc);
1559 wine_tsx11_unlock();
1560 HeapFree(GetProcessHeap(), 0, otm);
1563 if(deltas && deltas != lpDx)
1564 HeapFree(GetProcessHeap(), 0, deltas);
1566 if (flags & ETO_CLIPPED)
1568 /* restore the device region */
1569 X11DRV_SetDeviceClipping( physDev, saved_region, 0 );
1570 DeleteObject( saved_region );
1576 X11DRV_UnlockDIBSection( physDev, TRUE );
1577 if(glyphs != wstr) HeapFree(GetProcessHeap(), 0, (WORD*)glyphs);
1581 BOOL X11DRV_AlphaBlend(X11DRV_PDEVICE *devDst, INT xDst, INT yDst, INT widthDst, INT heightDst,
1582 X11DRV_PDEVICE *devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc,
1583 BLENDFUNCTION blendfn)
1585 XRenderPictureAttributes pa;
1586 XRenderPictFormat *src_format;
1587 Picture dst_pict, src_pict;
1594 char *dstbits, *data;
1597 BOOL top_down = FALSE;
1599 if(!X11DRV_XRender_Installed) {
1600 FIXME("Unable to AlphaBlend without Xrender\n");
1605 pts[1].x = xDst + widthDst;
1606 pts[1].y = yDst + heightDst;
1607 LPtoDP(devDst->hdc, pts, 2);
1610 widthDst = pts[1].x - pts[0].x;
1611 heightDst = pts[1].y - pts[0].y;
1615 pts[1].x = xSrc + widthSrc;
1616 pts[1].y = ySrc + heightSrc;
1617 LPtoDP(devSrc->hdc, pts, 2);
1620 widthSrc = pts[1].x - pts[0].x;
1621 heightSrc = pts[1].y - pts[0].y;
1623 #ifndef HAVE_XRENDERSETPICTURETRANSFORM
1624 if(widthDst != widthSrc || heightDst != heightSrc)
1626 if(!pXRenderSetPictureTransform)
1629 FIXME("Unable to Stretch, XRenderSetPictureTransform is currently required\n");
1633 hBitmap = GetCurrentObject( devSrc->hdc, OBJ_BITMAP );
1634 bmp = (BITMAPOBJ *)GDI_GetObjPtr( hBitmap, BITMAP_MAGIC );
1635 if(!bmp || !bmp->dib) {
1636 FIXME("not a dibsection\n");
1637 GDI_ReleaseObj( hBitmap );
1641 if(bmp->dib->dsBm.bmBitsPixel != 32) {
1642 FIXME("not a 32 bpp dibsection\n");
1643 GDI_ReleaseObj( hBitmap );
1646 dstbits = data = HeapAlloc(GetProcessHeap(), 0, heightSrc * widthSrc * 4);
1648 if(bmp->dib->dsBmih.biHeight < 0) { /* top-down dib */
1650 dstbits += widthSrc * (heightSrc - 1) * 4;
1652 for(y = ySrc + heightSrc - 1; y >= ySrc; y--) {
1653 memcpy(dstbits, (char *)bmp->dib->dsBm.bmBits + y * bmp->dib->dsBm.bmWidthBytes + xSrc * 4,
1655 dstbits += (top_down ? -1 : 1) * widthSrc * 4;
1659 image = XCreateImage(gdi_display, visual, 32, ZPixmap, 0,
1660 data, widthSrc, heightSrc, 32, widthSrc * 4);
1662 src_format = pXRenderFindStandardFormat(gdi_display, PictStandardARGB32);
1665 TRACE("src_format %p\n", src_format);
1667 pa.subwindow_mode = IncludeInferiors;
1669 /* FIXME use devDst->xrender->pict ? */
1670 dst_pict = pXRenderCreatePicture(gdi_display,
1672 (devDst->depth == 1) ?
1673 mono_format : screen_format,
1674 CPSubwindowMode, &pa);
1675 TRACE("dst_pict %08lx\n", dst_pict);
1676 TRACE("src_drawable = %08lx\n", devSrc->drawable);
1677 xpm = XCreatePixmap(gdi_display,
1679 widthSrc, heightSrc, 32);
1680 gcv.graphics_exposures = False;
1681 gc = XCreateGC(gdi_display, xpm, GCGraphicsExposures, &gcv);
1682 TRACE("xpm = %08lx\n", xpm);
1683 XPutImage(gdi_display, xpm, gc, image, 0, 0, 0, 0, widthSrc, heightSrc);
1685 src_pict = pXRenderCreatePicture(gdi_display,
1687 CPSubwindowMode, &pa);
1688 TRACE("src_pict %08lx\n", src_pict);
1690 #ifdef HAVE_XRENDERSETPICTURETRANSFORM
1691 if(widthDst != widthSrc || heightDst != heightSrc) {
1692 double xscale = widthSrc/(double)widthDst;
1693 double yscale = heightSrc/(double)heightDst;
1694 XTransform xform = {{
1695 { XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0) },
1696 { XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0) },
1697 { XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1) }
1699 pXRenderSetPictureTransform(gdi_display, src_pict, &xform);
1702 pXRenderComposite(gdi_display, PictOpOver, src_pict, 0, dst_pict,
1704 xDst + devDst->org.x, yDst + devDst->org.y, widthDst, heightDst);
1707 pXRenderFreePicture(gdi_display, src_pict);
1708 XFreePixmap(gdi_display, xpm);
1709 XFreeGC(gdi_display, gc);
1710 pXRenderFreePicture(gdi_display, dst_pict);
1712 XDestroyImage(image);
1714 wine_tsx11_unlock();
1715 HeapFree(GetProcessHeap(), 0, data);
1716 GDI_ReleaseObj( hBitmap );
1720 #else /* HAVE_X11_EXTENSIONS_XRENDER_H */
1722 void X11DRV_XRender_Init(void)
1724 TRACE("XRender support not compiled in.\n");
1728 void X11DRV_XRender_Finalize(void)
1732 BOOL X11DRV_XRender_SelectFont(X11DRV_PDEVICE *physDev, HFONT hfont)
1738 void X11DRV_XRender_DeleteDC(X11DRV_PDEVICE *physDev)
1744 BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flags,
1745 const RECT *lprect, LPCWSTR wstr, UINT count,
1746 const INT *lpDx, INT breakExtra )
1752 void X11DRV_XRender_UpdateDrawable(X11DRV_PDEVICE *physDev)
1758 BOOL X11DRV_AlphaBlend(X11DRV_PDEVICE *devDst, INT xDst, INT yDst, INT widthDst, INT heightDst,
1759 X11DRV_PDEVICE *devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc,
1760 BLENDFUNCTION blendfn)
1762 FIXME("not supported - XRENDER headers were missing at compile time\n");
1766 #endif /* HAVE_X11_EXTENSIONS_XRENDER_H */