2 * Functions to use the XRender extension
4 * Copyright 2001 Huw D M Davies for CodeWeavers
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/port.h"
31 #include "wine/unicode.h"
32 #include "wine/debug.h"
34 BOOL X11DRV_XRender_Installed = FALSE;
35 WINE_DEFAULT_DEBUG_CHANNEL(xrender);
37 #ifdef HAVE_X11_EXTENSIONS_XRENDER_H
40 #include <X11/extensions/Xrender.h>
42 static XRenderPictFormat *screen_format; /* format of screen */
43 static XRenderPictFormat *mono_format; /* format of mono bitmap */
48 XFORM xform; /* this is dum as we don't care about offsets */
52 #define INITIAL_REALIZED_BUF_SIZE 128
59 XRenderPictFormat *font_format;
68 gsCacheEntry *cacheEntry;
72 COLORREF lastTextColor;
76 static gsCacheEntry *glyphsetCache = NULL;
77 static DWORD glyphsetCacheSize = 0;
78 static INT lastfree = -1;
81 #define INIT_CACHE_SIZE 10
83 static int antialias = 1;
85 static void *xrender_handle;
87 #define MAKE_FUNCPTR(f) static typeof(f) * p##f;
88 MAKE_FUNCPTR(XRenderAddGlyphs)
89 MAKE_FUNCPTR(XRenderCompositeString8)
90 MAKE_FUNCPTR(XRenderCompositeString16)
91 MAKE_FUNCPTR(XRenderCompositeString32)
92 MAKE_FUNCPTR(XRenderCreateGlyphSet)
93 MAKE_FUNCPTR(XRenderCreatePicture)
94 MAKE_FUNCPTR(XRenderFillRectangle)
95 MAKE_FUNCPTR(XRenderFindFormat)
96 MAKE_FUNCPTR(XRenderFindVisualFormat)
97 MAKE_FUNCPTR(XRenderFreeGlyphSet)
98 MAKE_FUNCPTR(XRenderFreePicture)
99 MAKE_FUNCPTR(XRenderSetPictureClipRectangles)
100 MAKE_FUNCPTR(XRenderQueryExtension)
103 /***********************************************************************
104 * X11DRV_XRender_Init
106 * Let's see if our XServer has the extension available
109 void X11DRV_XRender_Init(void)
111 int error_base, event_base, i;
112 XRenderPictFormat pf;
114 /* FIXME: should find correct soname at compile time */
115 if (!wine_dlopen("libX11.so", RTLD_NOW|RTLD_GLOBAL, NULL, 0)) return;
116 if (!wine_dlopen("libXext.so", RTLD_NOW|RTLD_GLOBAL, NULL, 0)) return;
117 xrender_handle = wine_dlopen("libXrender.so", RTLD_NOW, NULL, 0);
118 if(!xrender_handle) return;
120 #define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(xrender_handle, #f, NULL, 0)) == NULL) goto sym_not_found;
121 LOAD_FUNCPTR(XRenderAddGlyphs)
122 LOAD_FUNCPTR(XRenderCompositeString8)
123 LOAD_FUNCPTR(XRenderCompositeString16)
124 LOAD_FUNCPTR(XRenderCompositeString32)
125 LOAD_FUNCPTR(XRenderCreateGlyphSet)
126 LOAD_FUNCPTR(XRenderCreatePicture)
127 LOAD_FUNCPTR(XRenderFillRectangle)
128 LOAD_FUNCPTR(XRenderFindFormat)
129 LOAD_FUNCPTR(XRenderFindVisualFormat)
130 LOAD_FUNCPTR(XRenderFreeGlyphSet)
131 LOAD_FUNCPTR(XRenderFreePicture)
132 LOAD_FUNCPTR(XRenderSetPictureClipRectangles)
133 LOAD_FUNCPTR(XRenderQueryExtension)
137 if(pXRenderQueryExtension(gdi_display, &event_base, &error_base)) {
138 X11DRV_XRender_Installed = TRUE;
139 TRACE("Xrender is up and running error_base = %d\n", error_base);
140 screen_format = pXRenderFindVisualFormat(gdi_display, visual);
141 if(!screen_format) { /* This fails in buggy versions of libXrender.so */
144 "Wine has detected that you probably have a buggy version\n"
145 "of libXrender.so . Because of this client side font rendering\n"
146 "will be disabled. Please upgrade this library.\n");
147 X11DRV_XRender_Installed = FALSE;
150 pf.type = PictTypeDirect;
153 pf.direct.alphaMask = 1;
154 mono_format = pXRenderFindFormat(gdi_display, PictFormatType |
155 PictFormatDepth | PictFormatAlpha |
156 PictFormatAlphaMask, &pf, 0);
159 ERR("mono_format == NULL?\n");
160 X11DRV_XRender_Installed = FALSE;
163 glyphsetCache = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
164 sizeof(*glyphsetCache) * INIT_CACHE_SIZE);
166 glyphsetCacheSize = INIT_CACHE_SIZE;
168 for(i = 0; i < INIT_CACHE_SIZE; i++) {
169 glyphsetCache[i].next = i + 1;
170 glyphsetCache[i].count = -1;
172 glyphsetCache[i-1].next = -1;
174 TRACE("Xrender is not available on this server\n");
180 wine_dlclose(xrender_handle, NULL, 0);
181 xrender_handle = NULL;
184 static BOOL fontcmp(LFANDSIZE *p1, LFANDSIZE *p2)
186 if(p1->hash != p2->hash) return TRUE;
187 if(memcmp(&p1->xform, &p2->xform, sizeof(p1->xform))) return TRUE;
188 if(memcmp(&p1->lf, &p2->lf, offsetof(LOGFONTW, lfFaceName))) return TRUE;
189 return strcmpW(p1->lf.lfFaceName, p2->lf.lfFaceName);
193 static void walk_cache(void)
197 for(i=mru; i >= 0; i = glyphsetCache[i].next)
198 TRACE("item %d\n", i);
202 static gsCacheEntry *LookupEntry(LFANDSIZE *plfsz)
206 for(i = mru; i >= 0; i = glyphsetCache[i].next) {
208 if(glyphsetCache[i].count == -1) { /* reached free list so stop */
213 if(!fontcmp(&glyphsetCache[i].lfsz, plfsz)) {
214 glyphsetCache[i].count++;
216 glyphsetCache[prev_i].next = glyphsetCache[i].next;
217 glyphsetCache[i].next = mru;
220 TRACE("found font in cache %d\n", i);
221 return glyphsetCache + i;
225 TRACE("font not in cache\n");
229 static gsCacheEntry *AllocEntry(void)
231 int best = -1, prev_best = -1, i, prev_i = -1;
234 assert(glyphsetCache[lastfree].count == -1);
235 glyphsetCache[lastfree].count = 1;
237 lastfree = glyphsetCache[lastfree].next;
239 glyphsetCache[best].next = mru;
242 TRACE("empty space at %d, next lastfree = %d\n", mru, lastfree);
243 return glyphsetCache + mru;
246 for(i = mru; i >= 0; i = glyphsetCache[i].next) {
247 if(glyphsetCache[i].count == 0) {
255 TRACE("freeing unused glyphset at cache %d\n", best);
257 pXRenderFreeGlyphSet(gdi_display, glyphsetCache[best].glyphset);
259 glyphsetCache[best].glyphset = 0;
260 if(glyphsetCache[best].nrealized) { /* do we really want to do this? */
261 HeapFree(GetProcessHeap(), 0, glyphsetCache[best].realized);
262 glyphsetCache[best].realized = NULL;
263 glyphsetCache[best].nrealized = 0;
265 glyphsetCache[best].count = 1;
267 glyphsetCache[prev_best].next = glyphsetCache[best].next;
268 glyphsetCache[best].next = mru;
273 return glyphsetCache + mru;
276 TRACE("Growing cache\n");
277 glyphsetCache = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
279 (glyphsetCacheSize + INIT_CACHE_SIZE)
280 * sizeof(*glyphsetCache));
281 for(best = i = glyphsetCacheSize; i < glyphsetCacheSize + INIT_CACHE_SIZE;
283 glyphsetCache[i].next = i + 1;
284 glyphsetCache[i].count = -1;
286 glyphsetCache[i-1].next = -1;
287 glyphsetCacheSize += INIT_CACHE_SIZE;
289 lastfree = glyphsetCache[best].next;
290 glyphsetCache[best].count = 1;
291 glyphsetCache[best].next = mru;
293 TRACE("new free cache slot at %d\n", mru);
294 return glyphsetCache + mru;
297 static gsCacheEntry *GetCacheEntry(LFANDSIZE *plfsz)
299 XRenderPictFormat pf;
302 if((ret = LookupEntry(plfsz)) != NULL) return ret;
306 assert(ret->nrealized == 0);
309 if(antialias && abs(plfsz->lf.lfHeight) > 16) {
311 pf.direct.alphaMask = 0xff;
314 pf.direct.alphaMask = 1;
316 pf.type = PictTypeDirect;
320 ret->font_format = pXRenderFindFormat(gdi_display,
327 ret->glyphset = pXRenderCreateGlyphSet(gdi_display, ret->font_format);
332 static void dec_ref_cache(gsCacheEntry *entry)
334 TRACE("dec'ing entry %d to %d\n", entry - glyphsetCache, entry->count - 1);
335 assert(entry->count > 0);
339 static void lfsz_calc_hash(LFANDSIZE *plfsz)
341 DWORD hash = 0, *ptr;
344 for(ptr = (DWORD*)&plfsz->xform; ptr < (DWORD*)(&plfsz->xform + 1); ptr++)
346 for(i = 0, ptr = (DWORD*)&plfsz->lf; i < 7; i++, ptr++)
348 for(i = 0, ptr = (DWORD*)&plfsz->lf.lfFaceName; i < LF_FACESIZE/2; i++, ptr++) {
349 WCHAR *pwc = (WCHAR *)ptr;
359 /***********************************************************************
360 * X11DRV_XRender_Finalize
362 void X11DRV_XRender_Finalize(void)
364 FIXME("Free cached glyphsets\n");
365 if (xrender_handle) wine_dlclose(xrender_handle, NULL, 0);
366 xrender_handle = NULL;
370 /***********************************************************************
371 * X11DRV_XRender_SelectFont
373 BOOL X11DRV_XRender_SelectFont(X11DRV_PDEVICE *physDev, HFONT hfont)
377 GetObjectW(hfont, sizeof(lfsz.lf), &lfsz.lf);
378 TRACE("h=%ld w=%ld weight=%ld it=%d charset=%d name=%s\n",
379 lfsz.lf.lfHeight, lfsz.lf.lfWidth, lfsz.lf.lfWeight,
380 lfsz.lf.lfItalic, lfsz.lf.lfCharSet, debugstr_w(lfsz.lf.lfFaceName));
381 lfsz.xform = physDev->dc->xformWorld2Vport;
382 lfsz_calc_hash(&lfsz);
384 if(!physDev->xrender)
385 physDev->xrender = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
386 sizeof(*physDev->xrender));
388 else if(physDev->xrender->cacheEntry)
389 dec_ref_cache(physDev->xrender->cacheEntry);
390 physDev->xrender->cacheEntry = GetCacheEntry(&lfsz);
394 /***********************************************************************
395 * X11DRV_XRender_DeleteDC
397 void X11DRV_XRender_DeleteDC(X11DRV_PDEVICE *physDev)
400 if(physDev->xrender->tile_pict)
401 pXRenderFreePicture(gdi_display, physDev->xrender->tile_pict);
403 if(physDev->xrender->tile_xpm)
404 XFreePixmap(gdi_display, physDev->xrender->tile_xpm);
406 if(physDev->xrender->pict) {
407 TRACE("freeing pict = %lx dc = %p\n", physDev->xrender->pict, physDev->dc);
408 pXRenderFreePicture(gdi_display, physDev->xrender->pict);
412 if(physDev->xrender->cacheEntry)
413 dec_ref_cache(physDev->xrender->cacheEntry);
415 HeapFree(GetProcessHeap(), 0, physDev->xrender);
416 physDev->xrender = NULL;
420 /***********************************************************************
421 * X11DRV_XRender_UpdateDrawable
423 * This gets called from X11DRV_SetDrawable and deletes the pict when the
424 * drawable changes. However at the moment we delete the pict at the end of
425 * every ExtTextOut so this is basically a NOP.
427 void X11DRV_XRender_UpdateDrawable(X11DRV_PDEVICE *physDev)
429 if(physDev->xrender->pict) {
430 TRACE("freeing pict %08lx from dc %p\n", physDev->xrender->pict, physDev->dc);
432 pXRenderFreePicture(gdi_display, physDev->xrender->pict);
435 physDev->xrender->pict = 0;
439 static BOOL UploadGlyph(X11DRV_PDEVICE *physDev, int glyph)
446 gsCacheEntry *entry = physDev->xrender->cacheEntry;
447 UINT ggo_format = GGO_GLYPH_INDEX;
450 if(entry->nrealized <= glyph) {
451 entry->nrealized = (glyph / 128 + 1) * 128;
452 entry->realized = HeapReAlloc(GetProcessHeap(),
455 entry->nrealized * sizeof(BOOL));
457 entry->realized[glyph] = TRUE;
459 if(entry->font_format->depth == 8) {
461 ggo_format |= WINE_GGO_GRAY16_BITMAP;
464 ggo_format |= GGO_BITMAP;
467 buflen = GetGlyphOutlineW(physDev->hdc, glyph, ggo_format, &gm, 0, NULL,
469 if(buflen == GDI_ERROR)
472 buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buflen);
473 GetGlyphOutlineW(physDev->hdc, glyph, ggo_format, &gm, buflen, buf, NULL);
475 TRACE("buflen = %d. Got metrics: %dx%d adv=%d,%d origin=%ld,%ld\n",
477 gm.gmBlackBoxX, gm.gmBlackBoxY, gm.gmCellIncX, gm.gmCellIncY,
478 gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
480 gi.width = gm.gmBlackBoxX;
481 gi.height = gm.gmBlackBoxY;
482 gi.x = -gm.gmptGlyphOrigin.x;
483 gi.y = gm.gmptGlyphOrigin.y;
484 gi.xOff = gm.gmCellIncX;
485 gi.yOff = gm.gmCellIncY;
487 if(TRACE_ON(xrender)) {
493 pitch = ((gi.width + 31) / 32) * 4;
494 for(i = 0; i < gi.height; i++) {
495 line = buf + i * pitch;
497 for(j = 0; j < pitch * 8; j++) {
498 strcat(output, (line[j / 8] & (1 << (7 - (j % 8)))) ? "#" : " ");
500 strcat(output, "\n");
504 char blks[] = " .:;!o*#";
508 pitch = ((gi.width + 3) / 4) * 4;
509 for(i = 0; i < gi.height; i++) {
510 line = buf + i * pitch;
512 for(j = 0; j < pitch; j++) {
513 str[0] = blks[line[j] >> 5];
516 strcat(output, "\n");
522 if(!aa && BitmapBitOrder(gdi_display) != MSBFirst) {
523 unsigned char *byte = buf, c;
529 /* magic to flip bit order */
530 c = ((c << 1) & 0xaa) | ((c >> 1) & 0x55);
531 c = ((c << 2) & 0xcc) | ((c >> 2) & 0x33);
532 c = ((c << 4) & 0xf0) | ((c >> 4) & 0x0f);
539 pXRenderAddGlyphs(gdi_display, entry->glyphset, &gid, &gi, 1,
542 HeapFree(GetProcessHeap(), 0, buf);
546 /***********************************************************************
547 * X11DRV_XRender_ExtTextOut
549 BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flags,
550 const RECT *lprect, LPCWSTR wstr, UINT count,
560 BOOL done_extents = FALSE;
561 INT width, xwidth, ywidth;
562 double cosEsc, sinEsc;
565 int render_op = PictOpOver;
567 HDC hdc = physDev->hdc;
568 DC *dc = physDev->dc;
570 TRACE("%04x, %d, %d, %08x, %p, %s, %d, %p)\n", hdc, x, y, flags,
571 lprect, debugstr_wn(wstr, count), count, lpDx);
573 if(flags & ETO_GLYPH_INDEX)
574 glyphs = (LPWORD)wstr;
576 glyphs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
577 GetGlyphIndicesW(hdc, wstr, count, glyphs, 0);
581 TRACE("rect: %d,%d - %d,%d\n", lprect->left, lprect->top, lprect->right,
583 TRACE("align = %x bkmode = %x mapmode = %x\n", dc->textAlign, GetBkMode(hdc), dc->MapMode);
585 if(dc->textAlign & TA_UPDATECP) {
590 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
591 if(lf.lfEscapement != 0) {
592 cosEsc = cos(lf.lfEscapement * M_PI / 1800);
593 sinEsc = sin(lf.lfEscapement * M_PI / 1800);
599 if(flags & (ETO_CLIPPED | ETO_OPAQUE)) {
601 if(flags & ETO_CLIPPED) return FALSE;
602 GetTextExtentPointI(hdc, glyphs, count, &sz);
606 rc.right = x + sz.cx;
607 rc.bottom = y + sz.cy;
612 rc.left = INTERNAL_XWPTODP(dc, rc.left, rc.top);
613 rc.top = INTERNAL_YWPTODP(dc, rc.left, rc.top);
614 rc.right = INTERNAL_XWPTODP(dc, rc.right, rc.bottom);
615 rc.bottom = INTERNAL_YWPTODP(dc, rc.right, rc.bottom);
617 if(rc.left > rc.right) {INT tmp = rc.left; rc.left = rc.right; rc.right = tmp;}
618 if(rc.top > rc.bottom) {INT tmp = rc.top; rc.top = rc.bottom; rc.bottom = tmp;}
621 xgcval.function = GXcopy;
622 xgcval.background = physDev->backgroundPixel;
623 xgcval.fill_style = FillSolid;
624 TSXChangeGC( gdi_display, physDev->gc,
625 GCFunction | GCBackground | GCFillStyle, &xgcval );
627 X11DRV_LockDIBSection( physDev, DIB_Status_GdiMod, FALSE );
629 if(flags & ETO_OPAQUE) {
630 TSXSetForeground( gdi_display, physDev->gc, physDev->backgroundPixel );
631 TSXFillRectangle( gdi_display, physDev->drawable, physDev->gc,
632 dc->DCOrgX + rc.left, dc->DCOrgY + rc.top,
633 rc.right - rc.left, rc.bottom - rc.top );
637 X11DRV_UnlockDIBSection( physDev, TRUE );
641 x = INTERNAL_XWPTODP( dc, x, y );
642 y = INTERNAL_YWPTODP( dc, x, y );
644 TRACE("real x,y %d,%d\n", x, y);
648 for(idx = 0; idx < count; idx++)
652 GetTextExtentPointI(hdc, glyphs, count, &sz);
657 width = INTERNAL_XWSTODS(dc, width);
658 xwidth = width * cosEsc;
659 ywidth = width * sinEsc;
661 GetTextMetricsW(hdc, &tm);
663 tm.tmAscent = INTERNAL_YWSTODS(dc, tm.tmAscent);
664 tm.tmDescent = INTERNAL_YWSTODS(dc, tm.tmDescent);
665 switch( dc->textAlign & (TA_LEFT | TA_RIGHT | TA_CENTER) ) {
667 if (dc->textAlign & TA_UPDATECP) {
668 dc->CursPosX = INTERNAL_XDPTOWP( dc, x + xwidth, y - ywidth );
669 dc->CursPosY = INTERNAL_YDPTOWP( dc, x + xwidth, y - ywidth );
681 if (dc->textAlign & TA_UPDATECP) {
682 dc->CursPosX = INTERNAL_XDPTOWP( dc, x + xwidth, y - ywidth );
683 dc->CursPosY = INTERNAL_YDPTOWP( dc, x + xwidth, y - ywidth );
688 switch( dc->textAlign & (TA_TOP | TA_BOTTOM | TA_BASELINE) ) {
690 y += tm.tmAscent * cosEsc;
691 x += tm.tmAscent * sinEsc;
695 y -= tm.tmDescent * cosEsc;
696 x -= tm.tmDescent * sinEsc;
703 if (flags & ETO_CLIPPED)
706 CLIPPING_IntersectVisRect( dc, rc.left, rc.top, rc.right,
712 if(!physDev->xrender->pict) {
713 XRenderPictureAttributes pa;
714 pa.subwindow_mode = IncludeInferiors;
717 physDev->xrender->pict = pXRenderCreatePicture(gdi_display,
719 (dc->bitsPerPixel == 1) ?
720 mono_format : screen_format,
721 CPSubwindowMode, &pa);
724 TRACE("allocing pict = %lx dc = %p drawable = %08lx\n", physDev->xrender->pict, dc, physDev->drawable);
726 TRACE("using existing pict = %lx dc = %p\n", physDev->xrender->pict, dc);
729 obj = (RGNOBJ *) GDI_GetObjPtr(dc->hGCClipRgn, REGION_MAGIC);
732 ERR("Rgn is 0. Please report this.\n");
736 if (obj->rgn->numRects > 0)
739 RECT *pRect = obj->rgn->rects;
740 RECT *pEndRect = obj->rgn->rects + obj->rgn->numRects;
742 pXrect = HeapAlloc( GetProcessHeap(), 0,
743 sizeof(*pXrect) * obj->rgn->numRects );
746 WARN("Can't alloc buffer\n");
747 GDI_ReleaseObj( dc->hGCClipRgn );
751 for(pXr = pXrect; pRect < pEndRect; pRect++, pXr++)
753 pXr->x = pRect->left;
755 pXr->width = pRect->right - pRect->left;
756 pXr->height = pRect->bottom - pRect->top;
757 TRACE("Adding clip rect %d,%d - %d,%d\n", pRect->left, pRect->top,
758 pRect->right, pRect->bottom);
762 TRACE("no clip rgn\n");
767 pXRenderSetPictureClipRectangles( gdi_display, physDev->xrender->pict,
768 0, 0, pXrect, obj->rgn->numRects );
772 HeapFree( GetProcessHeap(), 0, pXrect );
774 GDI_ReleaseObj( dc->hGCClipRgn );
776 if(GetBkMode(hdc) != TRANSPARENT) {
777 if(!((flags & ETO_CLIPPED) && (flags & ETO_OPAQUE))) {
778 if(!(flags & ETO_OPAQUE) || x < rc.left || x + width >= rc.right ||
779 y - tm.tmAscent < rc.top || y + tm.tmDescent >= rc.bottom) {
780 TSXSetForeground( gdi_display, physDev->gc, physDev->backgroundPixel );
781 TSXFillRectangle( gdi_display, physDev->drawable, physDev->gc,
782 dc->DCOrgX + x, dc->DCOrgY + y - tm.tmAscent,
783 width, tm.tmAscent + tm.tmDescent );
788 /* Create a 1x1 pixmap to tile over the font mask */
789 if(!physDev->xrender->tile_xpm) {
790 XRenderPictureAttributes pa;
792 XRenderPictFormat *format = (dc->bitsPerPixel == 1) ? mono_format : screen_format;
794 physDev->xrender->tile_xpm = XCreatePixmap(gdi_display,
799 physDev->xrender->tile_pict = pXRenderCreatePicture(gdi_display,
800 physDev->xrender->tile_xpm,
804 TRACE("Created pixmap of depth %d\n", format->depth);
805 /* init lastTextColor to something different from dc->textColor */
806 physDev->xrender->lastTextColor = ~dc->textColor;
810 if(dc->textColor != physDev->xrender->lastTextColor) {
811 if(dc->bitsPerPixel != 1) {
812 /* Map 0 -- 0xff onto 0 -- 0xffff */
813 col.red = GetRValue(dc->textColor);
814 col.red |= col.red << 8;
815 col.green = GetGValue(dc->textColor);
816 col.green |= col.green << 8;
817 col.blue = GetBValue(dc->textColor);
818 col.blue |= col.blue << 8;
820 } else { /* for a 1bpp bitmap we always need a 1 in the tile */
821 col.red = col.green = col.blue = 0;
825 pXRenderFillRectangle(gdi_display, PictOpSrc,
826 physDev->xrender->tile_pict,
829 physDev->xrender->lastTextColor = dc->textColor;
832 /* FIXME the mapping of Text/BkColor onto 1 or 0 needs investigation.
834 if((dc->bitsPerPixel == 1) && ((dc->textColor & 0xffffff) == 0))
835 render_op = PictOpOutReverse; /* This gives us 'black' text */
837 for(idx = 0; idx < count; idx++) {
838 if(glyphs[idx] >= physDev->xrender->cacheEntry->nrealized ||
839 physDev->xrender->cacheEntry->realized[glyphs[idx]] == FALSE) {
840 UploadGlyph(physDev, glyphs[idx]);
845 TRACE("Writing %s at %d,%d\n", debugstr_wn(wstr,count), dc->DCOrgX + x,
850 pXRenderCompositeString16(gdi_display, render_op,
851 physDev->xrender->tile_pict,
852 physDev->xrender->pict,
853 physDev->xrender->cacheEntry->font_format,
854 physDev->xrender->cacheEntry->glyphset,
855 0, 0, dc->DCOrgX + x, dc->DCOrgY + y,
859 INT offset = 0, xoff = 0, yoff = 0;
860 for(idx = 0; idx < count; idx++) {
861 pXRenderCompositeString16(gdi_display, render_op,
862 physDev->xrender->tile_pict,
863 physDev->xrender->pict,
864 physDev->xrender->cacheEntry->font_format,
865 physDev->xrender->cacheEntry->glyphset,
866 0, 0, dc->DCOrgX + x + xoff,
867 dc->DCOrgY + y + yoff,
869 offset += INTERNAL_XWSTODS(dc, lpDx[idx]);
870 xoff = offset * cosEsc;
871 yoff = offset * -sinEsc;
875 if(physDev->xrender->pict) {
876 pXRenderFreePicture(gdi_display, physDev->xrender->pict);
878 physDev->xrender->pict = 0;
881 if (flags & ETO_CLIPPED)
882 RestoreVisRgn16( hdc );
884 X11DRV_UnlockDIBSection( physDev, TRUE );
885 if(glyphs != wstr) HeapFree(GetProcessHeap(), 0, glyphs);
889 #else /* HAVE_X11_EXTENSIONS_XRENDER_H */
891 void X11DRV_XRender_Init(void)
893 TRACE("XRender support not compiled in.\n");
897 void X11DRV_XRender_Finalize(void)
901 BOOL X11DRV_XRender_SelectFont(X11DRV_PDEVICE *physDev, HFONT hfont)
907 void X11DRV_XRender_DeleteDC(X11DRV_PDEVICE *physDev)
913 BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flags,
914 const RECT *lprect, LPCWSTR wstr, UINT count,
921 void X11DRV_XRender_UpdateDrawable(X11DRV_PDEVICE *physDev)
927 #endif /* HAVE_X11_EXTENSIONS_XRENDER_H */