Added support for ResetDC.
[wine/wine64.git] / dlls / x11drv / xrender.c
blob327ad89f168c972ff7fbb7a0609ae301b9d0f955
1 /*
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
20 #include "config.h"
22 #include "winnt.h"
23 #include "x11drv.h"
24 #include "bitmap.h"
25 #include "wine/debug.h"
26 #include "region.h"
27 #include <string.h>
28 #include <stdlib.h>
29 #include "wine/unicode.h"
30 #include <assert.h>
32 BOOL X11DRV_XRender_Installed = FALSE;
33 WINE_DEFAULT_DEBUG_CHANNEL(xrender);
35 #ifdef HAVE_LIBXRENDER
37 #include "ts_xlib.h"
38 #include "ts_xrender.h"
40 static XRenderPictFormat *screen_format; /* format of screen */
41 static XRenderPictFormat *mono_format; /* format of mono bitmap */
43 typedef struct
45 LOGFONTW lf;
46 XFORM xform; /* this is dum as we don't care about offsets */
47 DWORD hash;
48 } LFANDSIZE;
50 #define INITIAL_REALIZED_BUF_SIZE 128
53 typedef struct
55 LFANDSIZE lfsz;
56 GlyphSet glyphset;
57 XRenderPictFormat *font_format;
58 int nrealized;
59 BOOL *realized;
60 UINT count;
61 INT next;
62 } gsCacheEntry;
64 struct tagXRENDERINFO
66 gsCacheEntry *cacheEntry;
67 Picture pict;
68 Picture tile_pict;
69 Pixmap tile_xpm;
70 COLORREF lastTextColor;
74 static gsCacheEntry *glyphsetCache = NULL;
75 static DWORD glyphsetCacheSize = 0;
76 static INT lastfree = -1;
77 static INT mru = -1;
79 #define INIT_CACHE_SIZE 10
81 static int antialias = 1;
83 /***********************************************************************
84 * X11DRV_XRender_Init
86 * Let's see if our XServer has the extension available
89 void X11DRV_XRender_Init(void)
91 int error_base, event_base, i;
92 XRenderPictFormat pf;
94 if(TSXRenderQueryExtension(gdi_display, &event_base, &error_base)) {
95 X11DRV_XRender_Installed = TRUE;
96 TRACE("Xrender is up and running error_base = %d\n", error_base);
97 screen_format = TSXRenderFindVisualFormat(gdi_display, visual);
98 pf.type = PictTypeDirect;
99 pf.depth = 1;
100 pf.direct.alpha = 0;
101 pf.direct.alphaMask = 1;
102 mono_format = TSXRenderFindFormat(gdi_display, PictFormatType |
103 PictFormatDepth | PictFormatAlpha |
104 PictFormatAlphaMask, &pf, 0);
106 glyphsetCache = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
107 sizeof(*glyphsetCache) * INIT_CACHE_SIZE);
109 glyphsetCacheSize = INIT_CACHE_SIZE;
110 lastfree = 0;
111 for(i = 0; i < INIT_CACHE_SIZE; i++) {
112 glyphsetCache[i].next = i + 1;
113 glyphsetCache[i].count = -1;
115 glyphsetCache[i-1].next = -1;
116 } else {
117 TRACE("Xrender is not available on this server\n");
119 return;
122 static BOOL fontcmp(LFANDSIZE *p1, LFANDSIZE *p2)
124 if(p1->hash != p2->hash) return TRUE;
125 if(memcmp(&p1->xform, &p2->xform, sizeof(p1->xform))) return TRUE;
126 if(memcmp(&p1->lf, &p2->lf, offsetof(LOGFONTW, lfFaceName))) return TRUE;
127 return strcmpW(p1->lf.lfFaceName, p2->lf.lfFaceName);
130 #if 0
131 static void walk_cache(void)
133 int i;
135 for(i=mru; i >= 0; i = glyphsetCache[i].next)
136 TRACE("item %d\n", i);
138 #endif
140 static gsCacheEntry *LookupEntry(LFANDSIZE *plfsz)
142 int i, prev_i = -1;
144 for(i = mru; i >= 0; i = glyphsetCache[i].next) {
145 TRACE("%d\n", i);
146 if(glyphsetCache[i].count == -1) { /* reached free list so stop */
147 i = -1;
148 break;
151 if(!fontcmp(&glyphsetCache[i].lfsz, plfsz)) {
152 glyphsetCache[i].count++;
153 if(prev_i >= 0) {
154 glyphsetCache[prev_i].next = glyphsetCache[i].next;
155 glyphsetCache[i].next = mru;
156 mru = i;
158 TRACE("found font in cache %d\n", i);
159 return glyphsetCache + i;
161 prev_i = i;
163 TRACE("font not in cache\n");
164 return NULL;
167 static gsCacheEntry *AllocEntry(void)
169 int best = -1, prev_best = -1, i, prev_i = -1;
171 if(lastfree >= 0) {
172 assert(glyphsetCache[lastfree].count == -1);
173 glyphsetCache[lastfree].count = 1;
174 best = lastfree;
175 lastfree = glyphsetCache[lastfree].next;
176 assert(best != mru);
177 glyphsetCache[best].next = mru;
178 mru = best;
180 TRACE("empty space at %d, next lastfree = %d\n", mru, lastfree);
181 return glyphsetCache + mru;
184 for(i = mru; i >= 0; i = glyphsetCache[i].next) {
185 if(glyphsetCache[i].count == 0) {
186 best = i;
187 prev_best = prev_i;
189 prev_i = i;
192 if(best >= 0) {
193 TRACE("freeing unused glyphset at cache %d\n", best);
194 TSXRenderFreeGlyphSet(gdi_display, glyphsetCache[best].glyphset);
195 glyphsetCache[best].glyphset = 0;
196 if(glyphsetCache[best].nrealized) { /* do we really want to do this? */
197 HeapFree(GetProcessHeap(), 0, glyphsetCache[best].realized);
198 glyphsetCache[best].realized = NULL;
199 glyphsetCache[best].nrealized = 0;
201 glyphsetCache[best].count = 1;
202 if(prev_best >= 0) {
203 glyphsetCache[prev_best].next = glyphsetCache[best].next;
204 glyphsetCache[best].next = mru;
205 mru = best;
206 } else {
207 assert(mru == best);
209 return glyphsetCache + mru;
212 TRACE("Growing cache\n");
213 glyphsetCache = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
214 glyphsetCache,
215 (glyphsetCacheSize + INIT_CACHE_SIZE)
216 * sizeof(*glyphsetCache));
217 for(best = i = glyphsetCacheSize; i < glyphsetCacheSize + INIT_CACHE_SIZE;
218 i++) {
219 glyphsetCache[i].next = i + 1;
220 glyphsetCache[i].count = -1;
222 glyphsetCache[i-1].next = -1;
223 glyphsetCacheSize += INIT_CACHE_SIZE;
225 lastfree = glyphsetCache[best].next;
226 glyphsetCache[best].count = 1;
227 glyphsetCache[best].next = mru;
228 mru = best;
229 TRACE("new free cache slot at %d\n", mru);
230 return glyphsetCache + mru;
233 static gsCacheEntry *GetCacheEntry(LFANDSIZE *plfsz)
235 XRenderPictFormat pf;
236 gsCacheEntry *ret;
238 if((ret = LookupEntry(plfsz)) != NULL) return ret;
240 ret = AllocEntry();
241 ret->lfsz = *plfsz;
242 assert(ret->nrealized == 0);
245 if(antialias && abs(plfsz->lf.lfHeight) > 16) {
246 pf.depth = 8;
247 pf.direct.alphaMask = 0xff;
248 } else {
249 pf.depth = 1;
250 pf.direct.alphaMask = 1;
252 pf.type = PictTypeDirect;
253 pf.direct.alpha = 0;
255 ret->font_format = TSXRenderFindFormat(gdi_display,
256 PictFormatType |
257 PictFormatDepth |
258 PictFormatAlpha |
259 PictFormatAlphaMask,
260 &pf, 0);
262 ret->glyphset = TSXRenderCreateGlyphSet(gdi_display, ret->font_format);
263 return ret;
266 static void dec_ref_cache(gsCacheEntry *entry)
268 TRACE("dec'ing entry %d to %d\n", entry - glyphsetCache, entry->count - 1);
269 assert(entry->count > 0);
270 entry->count--;
273 static void lfsz_calc_hash(LFANDSIZE *plfsz)
275 DWORD hash = 0, *ptr;
276 int i;
278 for(ptr = (DWORD*)&plfsz->xform; ptr < (DWORD*)(&plfsz->xform + 1); ptr++)
279 hash ^= *ptr;
280 for(i = 0, ptr = (DWORD*)&plfsz->lf; i < 7; i++, ptr++)
281 hash ^= *ptr;
282 for(i = 0, ptr = (DWORD*)&plfsz->lf.lfFaceName; i < LF_FACESIZE/2; i++, ptr++) {
283 WCHAR *pwc = (WCHAR *)ptr;
284 if(!*pwc) break;
285 hash ^= *ptr;
286 pwc++;
287 if(!*pwc) break;
289 plfsz->hash = hash;
290 return;
293 /***********************************************************************
294 * X11DRV_XRender_Finalize
296 void X11DRV_XRender_Finalize(void)
298 FIXME("Free cached glyphsets\n");
299 return;
303 /***********************************************************************
304 * X11DRV_XRender_SelectFont
306 BOOL X11DRV_XRender_SelectFont(X11DRV_PDEVICE *physDev, HFONT hfont)
308 LFANDSIZE lfsz;
310 GetObjectW(hfont, sizeof(lfsz.lf), &lfsz.lf);
311 TRACE("h=%ld w=%ld weight=%ld it=%d charset=%d name=%s\n",
312 lfsz.lf.lfHeight, lfsz.lf.lfWidth, lfsz.lf.lfWeight,
313 lfsz.lf.lfItalic, lfsz.lf.lfCharSet, debugstr_w(lfsz.lf.lfFaceName));
314 lfsz.xform = physDev->dc->xformWorld2Vport;
315 lfsz_calc_hash(&lfsz);
317 if(!physDev->xrender)
318 physDev->xrender = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
319 sizeof(*physDev->xrender));
321 else if(physDev->xrender->cacheEntry)
322 dec_ref_cache(physDev->xrender->cacheEntry);
323 physDev->xrender->cacheEntry = GetCacheEntry(&lfsz);
324 return 0;
327 /***********************************************************************
328 * X11DRV_XRender_DeleteDC
330 void X11DRV_XRender_DeleteDC(X11DRV_PDEVICE *physDev)
332 if(physDev->xrender->tile_pict)
333 TSXRenderFreePicture(gdi_display, physDev->xrender->tile_pict);
335 if(physDev->xrender->tile_xpm)
336 TSXFreePixmap(gdi_display, physDev->xrender->tile_xpm);
338 if(physDev->xrender->pict) {
339 TRACE("freeing pict = %lx dc = %p\n", physDev->xrender->pict, physDev->dc);
340 TSXRenderFreePicture(gdi_display, physDev->xrender->pict);
343 if(physDev->xrender->cacheEntry)
344 dec_ref_cache(physDev->xrender->cacheEntry);
346 HeapFree(GetProcessHeap(), 0, physDev->xrender);
347 physDev->xrender = NULL;
348 return;
351 /***********************************************************************
352 * X11DRV_XRender_UpdateDrawable
354 * This gets called from X11DRV_SetDrawable and deletes the pict when the
355 * drawable changes. However at the moment we delete the pict at the end of
356 * every ExtTextOut so this is basically a NOP.
358 void X11DRV_XRender_UpdateDrawable(X11DRV_PDEVICE *physDev)
360 if(physDev->xrender->pict) {
361 TRACE("freeing pict %08lx from dc %p\n", physDev->xrender->pict, physDev->dc);
362 TSXRenderFreePicture(gdi_display, physDev->xrender->pict);
364 physDev->xrender->pict = 0;
365 return;
368 static BOOL UploadGlyph(X11DRV_PDEVICE *physDev, int glyph)
370 int buflen;
371 char *buf;
372 Glyph gid;
373 GLYPHMETRICS gm;
374 XGlyphInfo gi;
375 gsCacheEntry *entry = physDev->xrender->cacheEntry;
376 UINT ggo_format = GGO_GLYPH_INDEX;
377 BOOL aa;
379 if(entry->nrealized <= glyph) {
380 entry->nrealized = (glyph / 128 + 1) * 128;
381 entry->realized = HeapReAlloc(GetProcessHeap(),
382 HEAP_ZERO_MEMORY,
383 entry->realized,
384 entry->nrealized * sizeof(BOOL));
386 entry->realized[glyph] = TRUE;
388 if(entry->font_format->depth == 8) {
389 aa = TRUE;
390 ggo_format |= WINE_GGO_GRAY16_BITMAP;
391 } else {
392 aa = FALSE;
393 ggo_format |= GGO_BITMAP;
396 buflen = GetGlyphOutlineW(physDev->hdc, glyph, ggo_format, &gm, 0, NULL,
397 NULL);
398 if(buflen == GDI_ERROR)
399 return FALSE;
401 buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buflen);
402 GetGlyphOutlineW(physDev->hdc, glyph, ggo_format, &gm, buflen, buf, NULL);
404 TRACE("buflen = %d. Got metrics: %dx%d adv=%d,%d origin=%ld,%ld\n",
405 buflen,
406 gm.gmBlackBoxX, gm.gmBlackBoxY, gm.gmCellIncX, gm.gmCellIncY,
407 gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);
409 gi.width = gm.gmBlackBoxX;
410 gi.height = gm.gmBlackBoxY;
411 gi.x = -gm.gmptGlyphOrigin.x;
412 gi.y = gm.gmptGlyphOrigin.y;
413 gi.xOff = gm.gmCellIncX;
414 gi.yOff = gm.gmCellIncY;
416 if(TRACE_ON(xrender)) {
417 int pitch, i, j;
418 char output[300];
419 unsigned char *line;
421 if(!aa) {
422 pitch = ((gi.width + 31) / 32) * 4;
423 for(i = 0; i < gi.height; i++) {
424 line = buf + i * pitch;
425 output[0] = '\0';
426 for(j = 0; j < pitch * 8; j++) {
427 strcat(output, (line[j / 8] & (1 << (7 - (j % 8)))) ? "#" : " ");
429 strcat(output, "\n");
430 TRACE(output);
432 } else {
433 char blks[] = " .:;!o*#";
434 char str[2];
436 str[1] = '\0';
437 pitch = ((gi.width + 3) / 4) * 4;
438 for(i = 0; i < gi.height; i++) {
439 line = buf + i * pitch;
440 output[0] = '\0';
441 for(j = 0; j < pitch; j++) {
442 str[0] = blks[line[j] >> 5];
443 strcat(output, str);
445 strcat(output, "\n");
446 TRACE(output);
451 if(!aa && BitmapBitOrder(gdi_display) != MSBFirst) {
452 unsigned char *byte = buf, c;
453 int i = buflen;
455 while(i--) {
456 c = *byte;
458 /* magic to flip bit order */
459 c = ((c << 1) & 0xaa) | ((c >> 1) & 0x55);
460 c = ((c << 2) & 0xcc) | ((c >> 2) & 0x33);
461 c = ((c << 4) & 0xf0) | ((c >> 4) & 0x0f);
463 *byte++ = c;
466 gid = glyph;
467 TSXRenderAddGlyphs(gdi_display, entry->glyphset, &gid, &gi, 1,
468 buf, buflen);
469 HeapFree(GetProcessHeap(), 0, buf);
470 return TRUE;
473 /***********************************************************************
474 * X11DRV_XRender_ExtTextOut
476 BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flags,
477 const RECT *lprect, LPCWSTR wstr, UINT count,
478 const INT *lpDx )
480 XRenderColor col;
481 int idx;
482 TEXTMETRICW tm;
483 RGNOBJ *obj;
484 XRectangle *pXrect;
485 SIZE sz;
486 RECT rc;
487 BOOL done_extents = FALSE;
488 INT width, xwidth, ywidth;
489 double cosEsc, sinEsc;
490 XGCValues xgcval;
491 LOGFONTW lf;
492 int render_op = PictOpOver;
493 WORD *glyphs;
494 HDC hdc = physDev->hdc;
495 DC *dc = physDev->dc;
497 TRACE("%04x, %d, %d, %08x, %p, %s, %d, %p)\n", hdc, x, y, flags,
498 lprect, debugstr_wn(wstr, count), count, lpDx);
500 if(flags & ETO_GLYPH_INDEX)
501 glyphs = (LPWORD)wstr;
502 else {
503 glyphs = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR));
504 GetGlyphIndicesW(hdc, wstr, count, glyphs, 0);
507 if(lprect)
508 TRACE("rect: %d,%d - %d,%d\n", lprect->left, lprect->top, lprect->right,
509 lprect->bottom);
510 TRACE("align = %x bkmode = %x mapmode = %x\n", dc->textAlign, GetBkMode(hdc), dc->MapMode);
512 if(dc->textAlign & TA_UPDATECP) {
513 x = dc->CursPosX;
514 y = dc->CursPosY;
517 GetObjectW(GetCurrentObject(hdc, OBJ_FONT), sizeof(lf), &lf);
518 if(lf.lfEscapement != 0) {
519 cosEsc = cos(lf.lfEscapement * M_PI / 1800);
520 sinEsc = sin(lf.lfEscapement * M_PI / 1800);
521 } else {
522 cosEsc = 1;
523 sinEsc = 0;
526 if(flags & (ETO_CLIPPED | ETO_OPAQUE)) {
527 if(!lprect) {
528 if(flags & ETO_CLIPPED) return FALSE;
529 GetTextExtentPointI(hdc, glyphs, count, &sz);
530 done_extents = TRUE;
531 rc.left = x;
532 rc.top = y;
533 rc.right = x + sz.cx;
534 rc.bottom = y + sz.cy;
535 } else {
536 rc = *lprect;
539 rc.left = INTERNAL_XWPTODP(dc, rc.left, rc.top);
540 rc.top = INTERNAL_YWPTODP(dc, rc.left, rc.top);
541 rc.right = INTERNAL_XWPTODP(dc, rc.right, rc.bottom);
542 rc.bottom = INTERNAL_YWPTODP(dc, rc.right, rc.bottom);
544 if(rc.left > rc.right) {INT tmp = rc.left; rc.left = rc.right; rc.right = tmp;}
545 if(rc.top > rc.bottom) {INT tmp = rc.top; rc.top = rc.bottom; rc.bottom = tmp;}
548 xgcval.function = GXcopy;
549 xgcval.background = physDev->backgroundPixel;
550 xgcval.fill_style = FillSolid;
551 TSXChangeGC( gdi_display, physDev->gc,
552 GCFunction | GCBackground | GCFillStyle, &xgcval );
554 X11DRV_LockDIBSection( physDev, DIB_Status_GdiMod, FALSE );
556 if(flags & ETO_OPAQUE) {
557 TSXSetForeground( gdi_display, physDev->gc, physDev->backgroundPixel );
558 TSXFillRectangle( gdi_display, physDev->drawable, physDev->gc,
559 dc->DCOrgX + rc.left, dc->DCOrgY + rc.top,
560 rc.right - rc.left, rc.bottom - rc.top );
563 if(count == 0) {
564 X11DRV_UnlockDIBSection( physDev, TRUE );
565 return TRUE;
568 x = INTERNAL_XWPTODP( dc, x, y );
569 y = INTERNAL_YWPTODP( dc, x, y );
571 TRACE("real x,y %d,%d\n", x, y);
573 if(lpDx) {
574 width = 0;
575 for(idx = 0; idx < count; idx++)
576 width += lpDx[idx];
577 } else {
578 if(!done_extents) {
579 GetTextExtentPointI(hdc, glyphs, count, &sz);
580 done_extents = TRUE;
582 width = sz.cx;
584 width = INTERNAL_XWSTODS(dc, width);
585 xwidth = width * cosEsc;
586 ywidth = width * sinEsc;
588 GetTextMetricsW(hdc, &tm);
590 tm.tmAscent = INTERNAL_YWSTODS(dc, tm.tmAscent);
591 tm.tmDescent = INTERNAL_YWSTODS(dc, tm.tmDescent);
592 switch( dc->textAlign & (TA_LEFT | TA_RIGHT | TA_CENTER) ) {
593 case TA_LEFT:
594 if (dc->textAlign & TA_UPDATECP) {
595 dc->CursPosX = INTERNAL_XDPTOWP( dc, x + xwidth, y - ywidth );
596 dc->CursPosY = INTERNAL_YDPTOWP( dc, x + xwidth, y - ywidth );
598 break;
600 case TA_CENTER:
601 x -= xwidth / 2;
602 y += ywidth / 2;
603 break;
605 case TA_RIGHT:
606 x -= xwidth;
607 y += ywidth;
608 if (dc->textAlign & TA_UPDATECP) {
609 dc->CursPosX = INTERNAL_XDPTOWP( dc, x + xwidth, y - ywidth );
610 dc->CursPosY = INTERNAL_YDPTOWP( dc, x + xwidth, y - ywidth );
612 break;
615 switch( dc->textAlign & (TA_TOP | TA_BOTTOM | TA_BASELINE) ) {
616 case TA_TOP:
617 y += tm.tmAscent * cosEsc;
618 x += tm.tmAscent * sinEsc;
619 break;
621 case TA_BOTTOM:
622 y -= tm.tmDescent * cosEsc;
623 x -= tm.tmDescent * sinEsc;
624 break;
626 case TA_BASELINE:
627 break;
630 if (flags & ETO_CLIPPED)
632 SaveVisRgn16( hdc );
633 CLIPPING_IntersectVisRect( dc, rc.left, rc.top, rc.right,
634 rc.bottom, FALSE );
639 if(!physDev->xrender->pict) {
640 XRenderPictureAttributes pa;
641 pa.subwindow_mode = IncludeInferiors;
643 physDev->xrender->pict =
644 TSXRenderCreatePicture(gdi_display,
645 physDev->drawable,
646 (dc->bitsPerPixel == 1) ?
647 mono_format : screen_format,
648 CPSubwindowMode, &pa);
650 TRACE("allocing pict = %lx dc = %p drawable = %08lx\n", physDev->xrender->pict, dc, physDev->drawable);
651 } else {
652 TRACE("using existing pict = %lx dc = %p\n", physDev->xrender->pict, dc);
655 obj = (RGNOBJ *) GDI_GetObjPtr(dc->hGCClipRgn, REGION_MAGIC);
656 if (!obj)
658 ERR("Rgn is 0. Please report this.\n");
659 return FALSE;
662 if (obj->rgn->numRects > 0)
664 XRectangle *pXr;
665 RECT *pRect = obj->rgn->rects;
666 RECT *pEndRect = obj->rgn->rects + obj->rgn->numRects;
668 pXrect = HeapAlloc( GetProcessHeap(), 0,
669 sizeof(*pXrect) * obj->rgn->numRects );
670 if(!pXrect)
672 WARN("Can't alloc buffer\n");
673 GDI_ReleaseObj( dc->hGCClipRgn );
674 return FALSE;
677 for(pXr = pXrect; pRect < pEndRect; pRect++, pXr++)
679 pXr->x = pRect->left;
680 pXr->y = pRect->top;
681 pXr->width = pRect->right - pRect->left;
682 pXr->height = pRect->bottom - pRect->top;
683 TRACE("Adding clip rect %d,%d - %d,%d\n", pRect->left, pRect->top,
684 pRect->right, pRect->bottom);
687 else {
688 TRACE("no clip rgn\n");
689 pXrect = NULL;
692 TSXRenderSetPictureClipRectangles( gdi_display, physDev->xrender->pict,
693 0, 0, pXrect, obj->rgn->numRects );
695 if(pXrect)
696 HeapFree( GetProcessHeap(), 0, pXrect );
698 GDI_ReleaseObj( dc->hGCClipRgn );
700 if(GetBkMode(hdc) != TRANSPARENT) {
701 if(!((flags & ETO_CLIPPED) && (flags & ETO_OPAQUE))) {
702 if(!(flags & ETO_OPAQUE) || x < rc.left || x + width >= rc.right ||
703 y - tm.tmAscent < rc.top || y + tm.tmDescent >= rc.bottom) {
704 TSXSetForeground( gdi_display, physDev->gc, physDev->backgroundPixel );
705 TSXFillRectangle( gdi_display, physDev->drawable, physDev->gc,
706 dc->DCOrgX + x, dc->DCOrgY + y - tm.tmAscent,
707 width, tm.tmAscent + tm.tmDescent );
712 /* Create a 1x1 pixmap to tile over the font mask */
713 if(!physDev->xrender->tile_xpm) {
714 XRenderPictureAttributes pa;
716 XRenderPictFormat *format = (dc->bitsPerPixel == 1) ? mono_format : screen_format;
717 physDev->xrender->tile_xpm = TSXCreatePixmap(gdi_display,
718 physDev->drawable,
719 1, 1,
720 format->depth);
721 pa.repeat = True;
722 physDev->xrender->tile_pict = TSXRenderCreatePicture(gdi_display,
723 physDev->xrender->tile_xpm,
724 format,
725 CPRepeat, &pa);
726 TRACE("Created pixmap of depth %d\n", format->depth);
727 /* init lastTextColor to something different from dc->textColor */
728 physDev->xrender->lastTextColor = ~dc->textColor;
732 if(dc->textColor != physDev->xrender->lastTextColor) {
733 if(dc->bitsPerPixel != 1) {
734 /* Map 0 -- 0xff onto 0 -- 0xffff */
735 col.red = GetRValue(dc->textColor);
736 col.red |= col.red << 8;
737 col.green = GetGValue(dc->textColor);
738 col.green |= col.green << 8;
739 col.blue = GetBValue(dc->textColor);
740 col.blue |= col.blue << 8;
741 col.alpha = 0x0;
742 } else { /* for a 1bpp bitmap we always need a 1 in the tile */
743 col.red = col.green = col.blue = 0;
744 col.alpha = 0xffff;
746 TSXRenderFillRectangle(gdi_display, PictOpSrc,
747 physDev->xrender->tile_pict,
748 &col, 0, 0, 1, 1);
749 physDev->xrender->lastTextColor = dc->textColor;
752 /* FIXME the mapping of Text/BkColor onto 1 or 0 needs investigation.
754 if((dc->bitsPerPixel == 1) && ((dc->textColor & 0xffffff) == 0))
755 render_op = PictOpOutReverse; /* This gives us 'black' text */
757 for(idx = 0; idx < count; idx++) {
758 if(glyphs[idx] >= physDev->xrender->cacheEntry->nrealized ||
759 physDev->xrender->cacheEntry->realized[glyphs[idx]] == FALSE) {
760 UploadGlyph(physDev, glyphs[idx]);
765 TRACE("Writing %s at %d,%d\n", debugstr_wn(wstr,count), dc->DCOrgX + x,
766 dc->DCOrgY + y);
767 if(!lpDx)
768 TSXRenderCompositeString16(gdi_display, render_op,
769 physDev->xrender->tile_pict,
770 physDev->xrender->pict,
771 physDev->xrender->cacheEntry->font_format,
772 physDev->xrender->cacheEntry->glyphset,
773 0, 0, dc->DCOrgX + x, dc->DCOrgY + y,
774 glyphs, count);
776 else {
777 INT offset = 0, xoff = 0, yoff = 0;
778 for(idx = 0; idx < count; idx++) {
779 TSXRenderCompositeString16(gdi_display, render_op,
780 physDev->xrender->tile_pict,
781 physDev->xrender->pict,
782 physDev->xrender->cacheEntry->font_format,
783 physDev->xrender->cacheEntry->glyphset,
784 0, 0, dc->DCOrgX + x + xoff,
785 dc->DCOrgY + y + yoff,
786 glyphs + idx, 1);
787 offset += INTERNAL_XWSTODS(dc, lpDx[idx]);
788 xoff = offset * cosEsc;
789 yoff = offset * -sinEsc;
793 if(physDev->xrender->pict) {
794 TSXRenderFreePicture(gdi_display, physDev->xrender->pict);
796 physDev->xrender->pict = 0;
799 if (flags & ETO_CLIPPED)
800 RestoreVisRgn16( hdc );
802 X11DRV_UnlockDIBSection( physDev, TRUE );
803 if(glyphs != wstr) HeapFree(GetProcessHeap(), 0, glyphs);
804 return TRUE;
807 #else /* #ifdef HAVE_LIBXRENDER */
809 void X11DRV_XRender_Init(void)
811 TRACE("XRender support not compiled in.\n");
812 return;
815 void X11DRV_XRender_Finalize(void)
817 assert(0);
818 return;
821 BOOL X11DRV_XRender_SelectFont(X11DRV_PDEVICE *physDev, HFONT hfont)
823 assert(0);
824 return FALSE;
827 void X11DRV_XRender_DeleteDC(X11DRV_PDEVICE *physDev)
829 assert(0);
830 return;
833 BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flags,
834 const RECT *lprect, LPCWSTR wstr, UINT count,
835 const INT *lpDx )
837 assert(0);
838 return FALSE;
841 void X11DRV_XRender_UpdateDrawable(X11DRV_PDEVICE *physDev)
843 assert(0);
844 return;
847 #endif