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] );
418 if(antialias && plfsz->lf.lfQuality != NONANTIALIASED_QUALITY)
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 );
1016 BOOL disable_antialias = FALSE;
1017 AA_Type antialias = AA_None;
1020 /* Do we need to disable antialiasing because of palette mode? */
1021 HBITMAP hBitmap = GetCurrentObject( physDev->hdc, OBJ_BITMAP );
1022 if( GetObjectW( hBitmap, sizeof(bmp), &bmp ) != sizeof(bmp) ) {
1023 TRACE("bitmap is not a DIB\n");
1025 else if (bmp.dsBmih.biBitCount <= 8) {
1026 TRACE("Disabling antialiasing\n");
1027 disable_antialias = TRUE;
1030 TRACE("%p, %d, %d, %08x, %p, %s, %d, %p)\n", hdc, x, y, flags,
1031 lprect, debugstr_wn(wstr, count), count, lpDx);
1033 if(flags & ETO_GLYPH_INDEX)
1034 glyphs = (const WORD*)wstr;
1036 glyphs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
1037 GetGlyphIndicesW(hdc, wstr, count, (WORD*)glyphs, 0);
1041 TRACE("rect: %ld,%ld - %ld,%ld\n", lprect->left, lprect->top, lprect->right,
1043 TRACE("align = %x bkmode = %x mapmode = %x\n", align, GetBkMode(hdc), GetMapMode(hdc));
1045 if(align & TA_UPDATECP)
1047 GetCurrentPositionEx( hdc, &pt );
1052 GetTextMetricsW(hdc, &tm);
1053 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
1055 if(!(tm.tmPitchAndFamily & TMPF_VECTOR)) /* Non-scalable fonts shouldn't be rotated */
1056 lf.lfEscapement = 0;
1058 if(lf.lfEscapement != 0) {
1059 cosEsc = cos(lf.lfEscapement * M_PI / 1800);
1060 sinEsc = sin(lf.lfEscapement * M_PI / 1800);
1066 if(flags & (ETO_CLIPPED | ETO_OPAQUE)) {
1068 if(flags & ETO_CLIPPED) goto done;
1069 GetTextExtentPointI(hdc, glyphs, count, &sz);
1070 done_extents = TRUE;
1073 rc.right = x + sz.cx;
1074 rc.bottom = y + sz.cy;
1079 LPtoDP(hdc, (POINT*)&rc, 2);
1081 if(rc.left > rc.right) {INT tmp = rc.left; rc.left = rc.right; rc.right = tmp;}
1082 if(rc.top > rc.bottom) {INT tmp = rc.top; rc.top = rc.bottom; rc.bottom = tmp;}
1085 xgcval.function = GXcopy;
1086 xgcval.background = physDev->backgroundPixel;
1087 xgcval.fill_style = FillSolid;
1089 XChangeGC( gdi_display, physDev->gc, GCFunction | GCBackground | GCFillStyle, &xgcval );
1090 wine_tsx11_unlock();
1092 X11DRV_LockDIBSection( physDev, DIB_Status_GdiMod, FALSE );
1094 if(physDev->depth == 1) {
1095 if((physDev->textPixel & 0xffffff) == 0) {
1097 backgroundPixel = 1;
1100 backgroundPixel = 0;
1103 textPixel = physDev->textPixel;
1104 backgroundPixel = physDev->backgroundPixel;
1107 if(flags & ETO_OPAQUE) {
1109 XSetForeground( gdi_display, physDev->gc, backgroundPixel );
1110 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
1111 physDev->org.x + rc.left, physDev->org.y + rc.top,
1112 rc.right - rc.left, rc.bottom - rc.top );
1113 wine_tsx11_unlock();
1123 LPtoDP(hdc, &pt, 1);
1127 TRACE("real x,y %d,%d\n", x, y);
1129 char_extra = GetTextCharacterExtra(hdc);
1130 if(char_extra || breakExtra) {
1133 deltas = HeapAlloc(GetProcessHeap(), 0, count * sizeof(INT));
1134 for(i = 0; i < count; i++) {
1136 deltas[i] = lpDx[i] + char_extra;
1138 GetTextExtentPointI(hdc, glyphs + i, 1, &tmpsz);
1139 deltas[i] = tmpsz.cx;
1142 if (breakExtra && wstr[i] == tm.tmBreakChar) {
1143 deltas[i] = deltas[i] + breakExtra;
1147 deltas = (INT*)lpDx;
1151 for(idx = 0; idx < count; idx++)
1152 width += deltas[idx];
1155 GetTextExtentPointI(hdc, glyphs, count, &sz);
1156 done_extents = TRUE;
1160 width = X11DRV_XWStoDS(physDev, width);
1161 xwidth = width * cosEsc;
1162 ywidth = width * sinEsc;
1164 tm.tmAscent = abs(X11DRV_YWStoDS(physDev, tm.tmAscent));
1165 tm.tmDescent = abs(X11DRV_YWStoDS(physDev, tm.tmDescent));
1166 switch( align & (TA_LEFT | TA_RIGHT | TA_CENTER) ) {
1168 if (align & TA_UPDATECP) {
1171 DPtoLP(hdc, &pt, 1);
1172 MoveToEx(hdc, pt.x, pt.y, NULL);
1184 if (align & TA_UPDATECP) {
1187 DPtoLP(hdc, &pt, 1);
1188 MoveToEx(hdc, pt.x, pt.y, NULL);
1193 switch( align & (TA_TOP | TA_BOTTOM | TA_BASELINE) ) {
1195 y += tm.tmAscent * cosEsc;
1196 x += tm.tmAscent * sinEsc;
1200 y -= tm.tmDescent * cosEsc;
1201 x -= tm.tmDescent * sinEsc;
1208 if (flags & ETO_CLIPPED)
1211 RECT clip_rect = *lprect;
1213 LPtoDP( hdc, (POINT *)&clip_rect, 2 );
1214 clip_region = CreateRectRgnIndirect( &clip_rect );
1215 /* make a copy of the current device region */
1216 saved_region = CreateRectRgn( 0, 0, 0, 0 );
1217 CombineRgn( saved_region, physDev->region, 0, RGN_COPY );
1218 X11DRV_SetDeviceClipping( physDev, saved_region, clip_region );
1219 DeleteObject( clip_region );
1222 if(X11DRV_XRender_Installed) {
1223 if(!physDev->xrender->pict) {
1224 XRenderPictureAttributes pa;
1225 pa.subwindow_mode = IncludeInferiors;
1228 physDev->xrender->pict = pXRenderCreatePicture(gdi_display,
1230 (physDev->depth == 1) ?
1231 mono_format : screen_format,
1232 CPSubwindowMode, &pa);
1233 wine_tsx11_unlock();
1235 TRACE("allocing pict = %lx dc = %p drawable = %08lx\n",
1236 physDev->xrender->pict, hdc, physDev->drawable);
1238 TRACE("using existing pict = %lx dc = %p drawable = %08lx\n",
1239 physDev->xrender->pict, hdc, physDev->drawable);
1242 if ((data = X11DRV_GetRegionData( physDev->region, 0 )))
1245 pXRenderSetPictureClipRectangles( gdi_display, physDev->xrender->pict,
1246 physDev->org.x, physDev->org.y,
1247 (XRectangle *)data->Buffer, data->rdh.nCount );
1248 wine_tsx11_unlock();
1249 HeapFree( GetProcessHeap(), 0, data );
1253 if(GetBkMode(hdc) != TRANSPARENT) {
1254 if(!((flags & ETO_CLIPPED) && (flags & ETO_OPAQUE))) {
1255 if(!(flags & ETO_OPAQUE) || x < rc.left || x + width >= rc.right ||
1256 y - tm.tmAscent < rc.top || y + tm.tmDescent >= rc.bottom) {
1258 XSetForeground( gdi_display, physDev->gc, backgroundPixel );
1259 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
1260 physDev->org.x + x, physDev->org.y + y - tm.tmAscent,
1261 width, tm.tmAscent + tm.tmDescent );
1262 wine_tsx11_unlock();
1267 if(X11DRV_XRender_Installed) {
1268 /* Create a 1x1 pixmap to tile over the font mask */
1269 if(!physDev->xrender->tile_xpm) {
1270 XRenderPictureAttributes pa;
1272 XRenderPictFormat *format = (physDev->depth == 1) ? mono_format : screen_format;
1274 physDev->xrender->tile_xpm = XCreatePixmap(gdi_display,
1279 physDev->xrender->tile_pict = pXRenderCreatePicture(gdi_display,
1280 physDev->xrender->tile_xpm,
1283 wine_tsx11_unlock();
1284 TRACE("Created pixmap of depth %d\n", format->depth);
1285 /* init lastTextColor to something different from textPixel */
1286 physDev->xrender->lastTextColor = ~physDev->textPixel;
1290 if(physDev->textPixel != physDev->xrender->lastTextColor) {
1291 if(physDev->depth != 1) {
1292 /* Map 0 -- 0xff onto 0 -- 0xffff */
1297 ExamineBitfield (visual->red_mask, &r_shift, &r_len );
1298 ExamineBitfield (visual->green_mask, &g_shift, &g_len);
1299 ExamineBitfield (visual->blue_mask, &b_shift, &b_len);
1301 col.red = GetField(physDev->textPixel, r_shift, r_len);
1302 col.red |= col.red << 8;
1303 col.green = GetField(physDev->textPixel, g_shift, g_len);
1304 col.green |= col.green << 8;
1305 col.blue = GetField(physDev->textPixel, b_shift, b_len);
1306 col.blue |= col.blue << 8;
1308 } else { /* for a 1bpp bitmap we always need a 1 in the tile */
1309 col.red = col.green = col.blue = 0;
1313 pXRenderFillRectangle(gdi_display, PictOpSrc,
1314 physDev->xrender->tile_pict,
1316 wine_tsx11_unlock();
1317 physDev->xrender->lastTextColor = physDev->textPixel;
1320 /* FIXME the mapping of Text/BkColor onto 1 or 0 needs investigation.
1322 if((physDev->depth == 1) && (textPixel == 0))
1323 render_op = PictOpOutReverse; /* This gives us 'black' text */
1326 EnterCriticalSection(&xrender_cs);
1327 entry = glyphsetCache + physDev->xrender->cache_index;
1328 if( disable_antialias == FALSE )
1329 antialias = entry->aa_default;
1330 formatEntry = entry->format[antialias];
1332 for(idx = 0; idx < count; idx++) {
1333 if( !formatEntry ) {
1334 UploadGlyph(physDev, glyphs[idx], antialias);
1335 formatEntry = entry->format[antialias];
1336 } else if( glyphs[idx] >= formatEntry->nrealized || formatEntry->realized[glyphs[idx]] == FALSE) {
1337 UploadGlyph(physDev, glyphs[idx], antialias);
1340 assert(formatEntry);
1342 TRACE("Writing %s at %ld,%ld\n", debugstr_wn(wstr,count),
1343 physDev->org.x + x, physDev->org.y + y);
1345 if(X11DRV_XRender_Installed) {
1348 pXRenderCompositeString16(gdi_display, render_op,
1349 physDev->xrender->tile_pict,
1350 physDev->xrender->pict,
1351 formatEntry->font_format, formatEntry->glyphset,
1352 0, 0, physDev->org.x + x, physDev->org.y + y,
1356 INT offset = 0, xoff = 0, yoff = 0;
1357 for(idx = 0; idx < count; idx++) {
1358 pXRenderCompositeString16(gdi_display, render_op,
1359 physDev->xrender->tile_pict,
1360 physDev->xrender->pict,
1361 formatEntry->font_format, formatEntry->glyphset,
1362 0, 0, physDev->org.x + x + xoff,
1363 physDev->org.y + y + yoff,
1365 offset += X11DRV_XWStoDS(physDev, deltas[idx]);
1366 xoff = offset * cosEsc;
1367 yoff = offset * -sinEsc;
1370 wine_tsx11_unlock();
1373 INT offset = 0, xoff = 0, yoff = 0;
1375 XSetForeground( gdi_display, physDev->gc, textPixel );
1377 if(antialias == AA_None) {
1378 for(idx = 0; idx < count; idx++) {
1379 SharpGlyphMono(physDev, physDev->org.x + x + xoff,
1380 physDev->org.y + y + yoff,
1381 formatEntry->bitmaps[glyphs[idx]],
1382 &formatEntry->gis[glyphs[idx]]);
1384 offset += X11DRV_XWStoDS(physDev, deltas[idx]);
1385 xoff = offset * cosEsc;
1386 yoff = offset * -sinEsc;
1389 xoff += formatEntry->gis[glyphs[idx]].xOff;
1390 yoff += formatEntry->gis[glyphs[idx]].yOff;
1393 } else if(physDev->depth == 1) {
1394 for(idx = 0; idx < count; idx++) {
1395 SharpGlyphGray(physDev, physDev->org.x + x + xoff,
1396 physDev->org.y + y + yoff,
1397 formatEntry->bitmaps[glyphs[idx]],
1398 &formatEntry->gis[glyphs[idx]]);
1400 offset += X11DRV_XWStoDS(physDev, deltas[idx]);
1401 xoff = offset * cosEsc;
1402 yoff = offset * -sinEsc;
1405 xoff += formatEntry->gis[glyphs[idx]].xOff;
1406 yoff += formatEntry->gis[glyphs[idx]].yOff;
1412 unsigned int w, h, dummy_uint;
1413 Window dummy_window;
1415 int image_x, image_y, image_off_x, image_off_y, image_w, image_h;
1416 RECT extents = {0, 0, 0, 0};
1420 XGetGeometry(gdi_display, physDev->drawable, &dummy_window, &dummy_int, &dummy_int,
1421 &w, &h, &dummy_uint, &dummy_uint);
1422 TRACE("drawable %dx%d\n", w, h);
1424 for(idx = 0; idx < count; idx++) {
1425 if(extents.left > cur.x - formatEntry->gis[glyphs[idx]].x)
1426 extents.left = cur.x - formatEntry->gis[glyphs[idx]].x;
1427 if(extents.top > cur.y - formatEntry->gis[glyphs[idx]].y)
1428 extents.top = cur.y - formatEntry->gis[glyphs[idx]].y;
1429 if(extents.right < cur.x - formatEntry->gis[glyphs[idx]].x + formatEntry->gis[glyphs[idx]].width)
1430 extents.right = cur.x - formatEntry->gis[glyphs[idx]].x + formatEntry->gis[glyphs[idx]].width;
1431 if(extents.bottom < cur.y - formatEntry->gis[glyphs[idx]].y + formatEntry->gis[glyphs[idx]].height)
1432 extents.bottom = cur.y - formatEntry->gis[glyphs[idx]].y + formatEntry->gis[glyphs[idx]].height;
1434 offset += X11DRV_XWStoDS(physDev, deltas[idx]);
1435 cur.x = offset * cosEsc;
1436 cur.y = offset * -sinEsc;
1438 cur.x += formatEntry->gis[glyphs[idx]].xOff;
1439 cur.y += formatEntry->gis[glyphs[idx]].yOff;
1442 TRACE("glyph extents %ld,%ld - %ld,%ld drawable x,y %ld,%ld\n", extents.left, extents.top,
1443 extents.right, extents.bottom, physDev->org.x + x, physDev->org.y + y);
1445 if(physDev->org.x + x + extents.left >= 0) {
1446 image_x = physDev->org.x + x + extents.left;
1450 image_off_x = physDev->org.x + x + extents.left;
1452 if(physDev->org.y + y + extents.top >= 0) {
1453 image_y = physDev->org.y + y + extents.top;
1457 image_off_y = physDev->org.y + y + extents.top;
1459 if(physDev->org.x + x + extents.right < w)
1460 image_w = physDev->org.x + x + extents.right - image_x;
1462 image_w = w - image_x;
1463 if(physDev->org.y + y + extents.bottom < h)
1464 image_h = physDev->org.y + y + extents.bottom - image_y;
1466 image_h = h - image_y;
1468 if(image_w <= 0 || image_h <= 0) goto no_image;
1470 X11DRV_expect_error(gdi_display, XRenderErrorHandler, NULL);
1471 image = XGetImage(gdi_display, physDev->drawable,
1472 image_x, image_y, image_w, image_h,
1473 AllPlanes, ZPixmap);
1474 X11DRV_check_error();
1476 TRACE("XGetImage(%p, %x, %d, %d, %d, %d, %lx, %x) depth = %d rets %p\n",
1477 gdi_display, (int)physDev->drawable, image_x, image_y,
1478 image_w, image_h, AllPlanes, ZPixmap,
1479 physDev->depth, image);
1481 Pixmap xpm = XCreatePixmap(gdi_display, physDev->drawable, image_w, image_h,
1486 gcv.graphics_exposures = False;
1487 gc = XCreateGC(gdi_display, xpm, GCGraphicsExposures, &gcv);
1488 XCopyArea(gdi_display, physDev->drawable, xpm, gc, image_x, image_y,
1489 image_w, image_h, 0, 0);
1490 XFreeGC(gdi_display, gc);
1491 X11DRV_expect_error(gdi_display, XRenderErrorHandler, NULL);
1492 image = XGetImage(gdi_display, xpm, 0, 0, image_w, image_h, AllPlanes,
1494 X11DRV_check_error();
1495 XFreePixmap(gdi_display, xpm);
1497 if(!image) goto no_image;
1499 image->red_mask = visual->red_mask;
1500 image->green_mask = visual->green_mask;
1501 image->blue_mask = visual->blue_mask;
1503 offset = xoff = yoff = 0;
1504 for(idx = 0; idx < count; idx++) {
1505 SmoothGlyphGray(image, xoff + image_off_x - extents.left,
1506 yoff + image_off_y - extents.top,
1507 formatEntry->bitmaps[glyphs[idx]],
1508 &formatEntry->gis[glyphs[idx]],
1509 physDev->textPixel);
1511 offset += X11DRV_XWStoDS(physDev, deltas[idx]);
1512 xoff = offset * cosEsc;
1513 yoff = offset * -sinEsc;
1515 xoff += formatEntry->gis[glyphs[idx]].xOff;
1516 yoff += formatEntry->gis[glyphs[idx]].yOff;
1520 XPutImage(gdi_display, physDev->drawable, physDev->gc, image, 0, 0,
1521 image_x, image_y, image_w, image_h);
1522 XDestroyImage(image);
1525 wine_tsx11_unlock();
1527 LeaveCriticalSection(&xrender_cs);
1529 if (lf.lfUnderline || lf.lfStrikeOut) {
1530 int underlinePos, strikeoutPos;
1531 int underlineWidth, strikeoutWidth;
1532 UINT nMetricsSize = GetOutlineTextMetricsW(hdc, 0, NULL);
1533 OUTLINETEXTMETRICW* otm = NULL;
1537 underlineWidth = tm.tmAscent / 20 + 1;
1538 strikeoutPos = tm.tmAscent / 2;
1539 strikeoutWidth = underlineWidth;
1541 otm = HeapAlloc(GetProcessHeap(), 0, nMetricsSize);
1542 if (!otm) goto done_unlock;
1544 GetOutlineTextMetricsW(hdc, nMetricsSize, otm);
1545 underlinePos = otm->otmsUnderscorePosition;
1546 underlineWidth = otm->otmsUnderscoreSize;
1547 strikeoutPos = otm->otmsStrikeoutPosition;
1548 strikeoutWidth = otm->otmsStrikeoutSize;
1552 XSetForeground( gdi_display, physDev->gc, physDev->textPixel );
1554 if (lf.lfUnderline) {
1555 underlinePos = X11DRV_YWStoDS(physDev, underlinePos);
1556 underlineWidth = X11DRV_YWStoDS(physDev, underlineWidth);
1558 XSetLineAttributes( gdi_display, physDev->gc, underlineWidth,
1559 LineSolid, CapProjecting, JoinBevel );
1560 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
1561 physDev->org.x + x - underlinePos * sinEsc,
1562 physDev->org.y + y - underlinePos * cosEsc,
1563 physDev->org.x + x + width * cosEsc - underlinePos * sinEsc,
1564 physDev->org.y + y - width * sinEsc - underlinePos * cosEsc );
1567 if (lf.lfStrikeOut) {
1568 strikeoutPos = X11DRV_YWStoDS(physDev, strikeoutPos);
1569 strikeoutWidth = X11DRV_YWStoDS(physDev, strikeoutWidth);
1571 XSetLineAttributes( gdi_display, physDev->gc, strikeoutWidth,
1572 LineSolid, CapProjecting, JoinBevel );
1573 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
1574 physDev->org.x + x - strikeoutPos * sinEsc,
1575 physDev->org.y + y - strikeoutPos * cosEsc,
1576 physDev->org.x + x + width * cosEsc - strikeoutPos * sinEsc,
1577 physDev->org.y + y - width * sinEsc - strikeoutPos * cosEsc);
1579 wine_tsx11_unlock();
1580 HeapFree(GetProcessHeap(), 0, otm);
1583 if(deltas && deltas != lpDx)
1584 HeapFree(GetProcessHeap(), 0, deltas);
1586 if (flags & ETO_CLIPPED)
1588 /* restore the device region */
1589 X11DRV_SetDeviceClipping( physDev, saved_region, 0 );
1590 DeleteObject( saved_region );
1596 X11DRV_UnlockDIBSection( physDev, TRUE );
1598 if(glyphs != wstr) HeapFree(GetProcessHeap(), 0, (WORD*)glyphs);
1602 BOOL X11DRV_AlphaBlend(X11DRV_PDEVICE *devDst, INT xDst, INT yDst, INT widthDst, INT heightDst,
1603 X11DRV_PDEVICE *devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc,
1604 BLENDFUNCTION blendfn)
1606 XRenderPictureAttributes pa;
1607 XRenderPictFormat *src_format;
1608 Picture dst_pict, src_pict;
1615 char *dstbits, *data;
1618 BOOL top_down = FALSE;
1620 if(!X11DRV_XRender_Installed) {
1621 FIXME("Unable to AlphaBlend without Xrender\n");
1626 pts[1].x = xDst + widthDst;
1627 pts[1].y = yDst + heightDst;
1628 LPtoDP(devDst->hdc, pts, 2);
1631 widthDst = pts[1].x - pts[0].x;
1632 heightDst = pts[1].y - pts[0].y;
1636 pts[1].x = xSrc + widthSrc;
1637 pts[1].y = ySrc + heightSrc;
1638 LPtoDP(devSrc->hdc, pts, 2);
1641 widthSrc = pts[1].x - pts[0].x;
1642 heightSrc = pts[1].y - pts[0].y;
1644 #ifndef HAVE_XRENDERSETPICTURETRANSFORM
1645 if(widthDst != widthSrc || heightDst != heightSrc)
1647 if(!pXRenderSetPictureTransform)
1650 FIXME("Unable to Stretch, XRenderSetPictureTransform is currently required\n");
1654 hBitmap = GetCurrentObject( devSrc->hdc, OBJ_BITMAP );
1655 bmp = (BITMAPOBJ *)GDI_GetObjPtr( hBitmap, BITMAP_MAGIC );
1656 if(!bmp || !bmp->dib) {
1657 FIXME("not a dibsection\n");
1658 GDI_ReleaseObj( hBitmap );
1662 if(bmp->dib->dsBm.bmBitsPixel != 32) {
1663 FIXME("not a 32 bpp dibsection\n");
1664 GDI_ReleaseObj( hBitmap );
1667 dstbits = data = HeapAlloc(GetProcessHeap(), 0, heightSrc * widthSrc * 4);
1669 if(bmp->dib->dsBmih.biHeight < 0) { /* top-down dib */
1671 dstbits += widthSrc * (heightSrc - 1) * 4;
1673 for(y = ySrc + heightSrc - 1; y >= ySrc; y--) {
1674 memcpy(dstbits, (char *)bmp->dib->dsBm.bmBits + y * bmp->dib->dsBm.bmWidthBytes + xSrc * 4,
1676 dstbits += (top_down ? -1 : 1) * widthSrc * 4;
1680 image = XCreateImage(gdi_display, visual, 32, ZPixmap, 0,
1681 data, widthSrc, heightSrc, 32, widthSrc * 4);
1683 src_format = pXRenderFindStandardFormat(gdi_display, PictStandardARGB32);
1686 TRACE("src_format %p\n", src_format);
1688 pa.subwindow_mode = IncludeInferiors;
1690 /* FIXME use devDst->xrender->pict ? */
1691 dst_pict = pXRenderCreatePicture(gdi_display,
1693 (devDst->depth == 1) ?
1694 mono_format : screen_format,
1695 CPSubwindowMode, &pa);
1696 TRACE("dst_pict %08lx\n", dst_pict);
1697 TRACE("src_drawable = %08lx\n", devSrc->drawable);
1698 xpm = XCreatePixmap(gdi_display,
1700 widthSrc, heightSrc, 32);
1701 gcv.graphics_exposures = False;
1702 gc = XCreateGC(gdi_display, xpm, GCGraphicsExposures, &gcv);
1703 TRACE("xpm = %08lx\n", xpm);
1704 XPutImage(gdi_display, xpm, gc, image, 0, 0, 0, 0, widthSrc, heightSrc);
1706 src_pict = pXRenderCreatePicture(gdi_display,
1708 CPSubwindowMode, &pa);
1709 TRACE("src_pict %08lx\n", src_pict);
1711 #ifdef HAVE_XRENDERSETPICTURETRANSFORM
1712 if(widthDst != widthSrc || heightDst != heightSrc) {
1713 double xscale = widthSrc/(double)widthDst;
1714 double yscale = heightSrc/(double)heightDst;
1715 XTransform xform = {{
1716 { XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(0) },
1717 { XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(0) },
1718 { XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1) }
1720 pXRenderSetPictureTransform(gdi_display, src_pict, &xform);
1723 pXRenderComposite(gdi_display, PictOpOver, src_pict, 0, dst_pict,
1725 xDst + devDst->org.x, yDst + devDst->org.y, widthDst, heightDst);
1728 pXRenderFreePicture(gdi_display, src_pict);
1729 XFreePixmap(gdi_display, xpm);
1730 XFreeGC(gdi_display, gc);
1731 pXRenderFreePicture(gdi_display, dst_pict);
1733 XDestroyImage(image);
1735 wine_tsx11_unlock();
1736 HeapFree(GetProcessHeap(), 0, data);
1737 GDI_ReleaseObj( hBitmap );
1741 #else /* HAVE_X11_EXTENSIONS_XRENDER_H */
1743 void X11DRV_XRender_Init(void)
1745 TRACE("XRender support not compiled in.\n");
1749 void X11DRV_XRender_Finalize(void)
1753 BOOL X11DRV_XRender_SelectFont(X11DRV_PDEVICE *physDev, HFONT hfont)
1759 void X11DRV_XRender_DeleteDC(X11DRV_PDEVICE *physDev)
1765 BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flags,
1766 const RECT *lprect, LPCWSTR wstr, UINT count,
1767 const INT *lpDx, INT breakExtra )
1773 void X11DRV_XRender_UpdateDrawable(X11DRV_PDEVICE *physDev)
1779 BOOL X11DRV_AlphaBlend(X11DRV_PDEVICE *devDst, INT xDst, INT yDst, INT widthDst, INT heightDst,
1780 X11DRV_PDEVICE *devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc,
1781 BLENDFUNCTION blendfn)
1783 FIXME("not supported - XRENDER headers were missing at compile time\n");
1787 #endif /* HAVE_X11_EXTENSIONS_XRENDER_H */