xrender.c 72.6 KB
Newer Older
1 2 3
/*
 * Functions to use the XRender extension
 *
4
 * Copyright 2001, 2002 Huw D M Davies for CodeWeavers
5
 * Copyright 2009 Roderick Colenbrander
6 7 8
 *
 * Some parts also:
 * Copyright 2000 Keith Packard, member of The XFree86 Project, Inc.
9 10 11 12 13 14 15 16 17 18 19 20 21
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
22
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 24
 */
#include "config.h"
25 26 27
#include "wine/port.h"

#include <assert.h>
28
#include <stdarg.h>
29 30
#include <string.h>
#include <stdlib.h>
31

32
#include "windef.h"
33
#include "winbase.h"
34
#include "x11drv.h"
35
#include "winternl.h"
36
#include "wine/library.h"
37
#include "wine/unicode.h"
38
#include "wine/debug.h"
39

40 41
int using_client_side_fonts = FALSE;

42
WINE_DEFAULT_DEBUG_CHANNEL(xrender);
43

44
#ifdef SONAME_LIBXRENDER
45

46 47
static BOOL X11DRV_XRender_Installed = FALSE;

48
#include <X11/Xlib.h>
49
#include <X11/extensions/Xrender.h>
50

51 52 53 54 55 56
#ifndef RepeatNone  /* added in 0.10 */
#define RepeatNone    0
#define RepeatNormal  1
#define RepeatPad     2
#define RepeatReflect 3
#endif
57

58
#define MAX_FORMATS 10
59 60 61
typedef enum wine_xrformat
{
  WXR_FORMAT_MONO,
62
  WXR_FORMAT_GRAY,
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
  WXR_FORMAT_X1R5G5B5,
  WXR_FORMAT_X1B5G5R5,
  WXR_FORMAT_R5G6B5,
  WXR_FORMAT_B5G6R5,
  WXR_FORMAT_R8G8B8,
  WXR_FORMAT_B8G8R8,
  WXR_FORMAT_A8R8G8B8,
  WXR_FORMAT_X8R8G8B8,
} WXRFormat;

typedef struct wine_xrender_format_template
{
    WXRFormat wxr_format;
    unsigned int depth;
    unsigned int alpha;
    unsigned int alphaMask;
    unsigned int red;
    unsigned int redMask;
    unsigned int green;
    unsigned int greenMask;
    unsigned int blue;
    unsigned int blueMask;
} WineXRenderFormatTemplate;

static const WineXRenderFormatTemplate wxr_formats_template[] =
{
    /* Format               depth   alpha   mask    red     mask    green   mask    blue    mask*/
    {WXR_FORMAT_MONO,       1,      0,      0x01,   0,      0,      0,      0,      0,      0       },
91
    {WXR_FORMAT_GRAY,       8,      0,      0xff,   0,      0,      0,      0,      0,      0       },
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
    {WXR_FORMAT_X1R5G5B5,   16,     0,      0,      10,     0x1f,   5,      0x1f,   0,      0x1f    },
    {WXR_FORMAT_X1B5G5R5,   16,     0,      0,      0,      0x1f,   5,      0x1f,   10,     0x1f    },
    {WXR_FORMAT_R5G6B5,     16,     0,      0,      11,     0x1f,   5,      0x3f,   0,      0x1f    },
    {WXR_FORMAT_B5G6R5,     16,     0,      0,      0,      0x1f,   5,      0x3f,   11,     0x1f    },
    {WXR_FORMAT_R8G8B8,     24,     0,      0,      16,     0xff,   8,      0xff,   0,      0xff    },
    {WXR_FORMAT_B8G8R8,     24,     0,      0,      0,      0xff,   8,      0xff,   16,     0xff    },
    {WXR_FORMAT_A8R8G8B8,   32,     24,     0xff,   16,     0xff,   8,      0xff,   0,      0xff    },
    {WXR_FORMAT_X8R8G8B8,   32,     0,      0,      16,     0xff,   8,      0xff,   0,      0xff    }
};

typedef struct wine_xrender_format
{
    WXRFormat               format;
    XRenderPictFormat       *pict_format;
} WineXRenderFormat;

static WineXRenderFormat wxr_formats[MAX_FORMATS];
static int WineXRenderFormatsListSize = 0;
static WineXRenderFormat *default_format = NULL;
111 112 113

typedef struct
{
114
    LOGFONTW lf;
115
    XFORM    xform;
116 117
    SIZE     devsize;  /* size in device coords */
    DWORD    hash;
118 119 120 121
} LFANDSIZE;

#define INITIAL_REALIZED_BUF_SIZE 128

122
typedef enum { AA_None = 0, AA_Grey, AA_RGB, AA_BGR, AA_VRGB, AA_VBGR, AA_MAXVALUE } AA_Type;
123 124 125

typedef struct
{
126
    GlyphSet glyphset;
127
    const WineXRenderFormat *font_format;
128 129 130 131
    int nrealized;
    BOOL *realized;
    void **bitmaps;
    XGlyphInfo *gis;
132 133 134 135 136 137 138
} gsCacheEntryFormat;

typedef struct
{
    LFANDSIZE lfsz;
    AA_Type aa_default;
    gsCacheEntryFormat * format[AA_MAXVALUE];
139
    INT count;
140
    INT next;
141 142
} gsCacheEntry;

143
struct xrender_info
144
{
145
    int                cache_index;
146
    Picture            pict;
147
    Picture            pict_src;
148
    const WineXRenderFormat *format;
149 150 151 152 153 154 155 156 157 158 159
};

static gsCacheEntry *glyphsetCache = NULL;
static DWORD glyphsetCacheSize = 0;
static INT lastfree = -1;
static INT mru = -1;

#define INIT_CACHE_SIZE 10

static int antialias = 1;

160 161 162 163
static void *xrender_handle;

#define MAKE_FUNCPTR(f) static typeof(f) * p##f;
MAKE_FUNCPTR(XRenderAddGlyphs)
164
MAKE_FUNCPTR(XRenderComposite)
165 166 167
MAKE_FUNCPTR(XRenderCompositeString8)
MAKE_FUNCPTR(XRenderCompositeString16)
MAKE_FUNCPTR(XRenderCompositeString32)
168
MAKE_FUNCPTR(XRenderCompositeText16)
169 170 171 172 173 174 175 176
MAKE_FUNCPTR(XRenderCreateGlyphSet)
MAKE_FUNCPTR(XRenderCreatePicture)
MAKE_FUNCPTR(XRenderFillRectangle)
MAKE_FUNCPTR(XRenderFindFormat)
MAKE_FUNCPTR(XRenderFindVisualFormat)
MAKE_FUNCPTR(XRenderFreeGlyphSet)
MAKE_FUNCPTR(XRenderFreePicture)
MAKE_FUNCPTR(XRenderSetPictureClipRectangles)
177 178 179
#ifdef HAVE_XRENDERSETPICTURETRANSFORM
MAKE_FUNCPTR(XRenderSetPictureTransform)
#endif
180 181 182
MAKE_FUNCPTR(XRenderQueryExtension)
#undef MAKE_FUNCPTR

183 184 185 186 187
static CRITICAL_SECTION xrender_cs;
static CRITICAL_SECTION_DEBUG critsect_debug =
{
    0, 0, &xrender_cs,
    { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
188
      0, 0, { (DWORD_PTR)(__FILE__ ": xrender_cs") }
189 190
};
static CRITICAL_SECTION xrender_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
191

192 193 194 195 196 197 198 199 200 201 202 203 204
#define MS_MAKE_TAG( _x1, _x2, _x3, _x4 ) \
          ( ( (ULONG)_x4 << 24 ) |     \
            ( (ULONG)_x3 << 16 ) |     \
            ( (ULONG)_x2 <<  8 ) |     \
              (ULONG)_x1         )

#define MS_GASP_TAG MS_MAKE_TAG('g', 'a', 's', 'p')

#define GASP_GRIDFIT 0x01
#define GASP_DOGRAY  0x02

#ifdef WORDS_BIGENDIAN
#define get_be_word(x) (x)
205
#define NATIVE_BYTE_ORDER MSBFirst
206 207
#else
#define get_be_word(x) RtlUshortByteSwap(x)
208
#define NATIVE_BYTE_ORDER LSBFirst
209
#endif
210

211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
static BOOL get_xrender_template(const WineXRenderFormatTemplate *fmt, XRenderPictFormat *templ, unsigned long *mask)
{
    templ->id = 0;
    templ->type = PictTypeDirect;
    templ->depth = fmt->depth;
    templ->direct.alpha = fmt->alpha;
    templ->direct.alphaMask = fmt->alphaMask;
    templ->direct.red = fmt->red;
    templ->direct.redMask = fmt->redMask;
    templ->direct.green = fmt->green;
    templ->direct.greenMask = fmt->greenMask;
    templ->direct.blue = fmt->blue;
    templ->direct.blueMask = fmt->blueMask;
    templ->colormap = 0;

    *mask = PictFormatType | PictFormatDepth | PictFormatAlpha | PictFormatAlphaMask | PictFormatRed | PictFormatRedMask | PictFormatGreen | PictFormatGreenMask | PictFormatBlue | PictFormatBlueMask;

    return TRUE;
}

static BOOL is_wxrformat_compatible_with_default_visual(const WineXRenderFormatTemplate *fmt)
{
    if(fmt->depth != screen_depth)
        return FALSE;
    if( (fmt->redMask << fmt->red) != visual->red_mask)
        return FALSE;
    if( (fmt->greenMask << fmt->green) != visual->green_mask)
        return FALSE;
    if( (fmt->blueMask << fmt->blue) != visual->blue_mask)
        return FALSE;

    /* We never select a default ARGB visual */
    if(fmt->alphaMask)
        return FALSE;

    return TRUE;
}

static int load_xrender_formats(void)
{
    unsigned int i;
    for(i = 0; i < (sizeof(wxr_formats_template) / sizeof(wxr_formats_template[0])); i++)
    {
        XRenderPictFormat templ, *pict_format;

        if(is_wxrformat_compatible_with_default_visual(&wxr_formats_template[i]))
        {
            wine_tsx11_lock();
            pict_format = pXRenderFindVisualFormat(gdi_display, visual);
            if(!pict_format)
            {
                /* Xrender doesn't like DirectColor visuals, try to find a TrueColor one instead */
                if (visual->class == DirectColor)
                {
                    XVisualInfo info;
                    if (XMatchVisualInfo( gdi_display, DefaultScreen(gdi_display),
                                          screen_depth, TrueColor, &info ))
                    {
                        pict_format = pXRenderFindVisualFormat(gdi_display, info.visual);
                        if (pict_format) visual = info.visual;
                    }
                }
            }
            wine_tsx11_unlock();

            if(pict_format)
            {
                wxr_formats[WineXRenderFormatsListSize].format = wxr_formats_template[i].wxr_format;
                wxr_formats[WineXRenderFormatsListSize].pict_format = pict_format;
                default_format = &wxr_formats[WineXRenderFormatsListSize];
                WineXRenderFormatsListSize++;
                TRACE("Loaded pict_format with id=%#lx for wxr_format=%#x\n", pict_format->id, wxr_formats_template[i].wxr_format);
            }
        }
        else
        {
            unsigned long mask = 0;
            get_xrender_template(&wxr_formats_template[i], &templ, &mask);

            wine_tsx11_lock();
            pict_format = pXRenderFindFormat(gdi_display, mask, &templ, 0);
            wine_tsx11_unlock();

            if(pict_format)
            {
                wxr_formats[WineXRenderFormatsListSize].format = wxr_formats_template[i].wxr_format;
                wxr_formats[WineXRenderFormatsListSize].pict_format = pict_format;
                WineXRenderFormatsListSize++;
                TRACE("Loaded pict_format with id=%#lx for wxr_format=%#x\n", pict_format->id, wxr_formats_template[i].wxr_format);
            }
        }
    }
    return WineXRenderFormatsListSize;
}

306 307 308 309 310 311 312 313
/***********************************************************************
 *   X11DRV_XRender_Init
 *
 * Let's see if our XServer has the extension available
 *
 */
void X11DRV_XRender_Init(void)
{
314
    int event_base, i;
315

316 317 318 319 320
    if (client_side_with_render &&
	wine_dlopen(SONAME_LIBX11, RTLD_NOW|RTLD_GLOBAL, NULL, 0) &&
	wine_dlopen(SONAME_LIBXEXT, RTLD_NOW|RTLD_GLOBAL, NULL, 0) && 
	(xrender_handle = wine_dlopen(SONAME_LIBXRENDER, RTLD_NOW, NULL, 0)))
    {
321 322 323

#define LOAD_FUNCPTR(f) if((p##f = wine_dlsym(xrender_handle, #f, NULL, 0)) == NULL) goto sym_not_found;
LOAD_FUNCPTR(XRenderAddGlyphs)
324
LOAD_FUNCPTR(XRenderComposite)
325 326 327
LOAD_FUNCPTR(XRenderCompositeString8)
LOAD_FUNCPTR(XRenderCompositeString16)
LOAD_FUNCPTR(XRenderCompositeString32)
328
LOAD_FUNCPTR(XRenderCompositeText16)
329 330 331 332 333 334 335 336 337 338
LOAD_FUNCPTR(XRenderCreateGlyphSet)
LOAD_FUNCPTR(XRenderCreatePicture)
LOAD_FUNCPTR(XRenderFillRectangle)
LOAD_FUNCPTR(XRenderFindFormat)
LOAD_FUNCPTR(XRenderFindVisualFormat)
LOAD_FUNCPTR(XRenderFreeGlyphSet)
LOAD_FUNCPTR(XRenderFreePicture)
LOAD_FUNCPTR(XRenderSetPictureClipRectangles)
LOAD_FUNCPTR(XRenderQueryExtension)
#undef LOAD_FUNCPTR
339 340 341 342 343 344
#ifdef HAVE_XRENDERSETPICTURETRANSFORM
#define LOAD_OPTIONAL_FUNCPTR(f) p##f = wine_dlsym(xrender_handle, #f, NULL, 0);
LOAD_OPTIONAL_FUNCPTR(XRenderSetPictureTransform)
#undef LOAD_OPTIONAL_FUNCPTR
#endif

345
        wine_tsx11_lock();
346 347 348
        X11DRV_XRender_Installed = pXRenderQueryExtension(gdi_display, &event_base, &xrender_error_base);
        wine_tsx11_unlock();
        if(X11DRV_XRender_Installed) {
349
            TRACE("Xrender is up and running error_base = %d\n", xrender_error_base);
350
            if(!load_xrender_formats()) /* This fails in buggy versions of libXrender.so */
351
            {
352 353 354 355 356 357 358 359
                wine_tsx11_unlock();
                WINE_MESSAGE(
                    "Wine has detected that you probably have a buggy version\n"
                    "of libXrender.so .  Because of this client side font rendering\n"
                    "will be disabled.  Please upgrade this library.\n");
                X11DRV_XRender_Installed = FALSE;
                return;
            }
360

361 362 363 364
            if (!visual->red_mask || !visual->green_mask || !visual->blue_mask) {
                WARN("one or more of the colour masks are 0, disabling XRENDER. Try running in 16-bit mode or higher.\n");
                X11DRV_XRender_Installed = FALSE;
            }
365 366 367 368 369 370
        }
    }

sym_not_found:
    if(X11DRV_XRender_Installed || client_side_with_core)
    {
371 372 373 374 375 376 377 378 379 380
	glyphsetCache = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
				  sizeof(*glyphsetCache) * INIT_CACHE_SIZE);

	glyphsetCacheSize = INIT_CACHE_SIZE;
	lastfree = 0;
	for(i = 0; i < INIT_CACHE_SIZE; i++) {
	  glyphsetCache[i].next = i + 1;
	  glyphsetCache[i].count = -1;
	}
	glyphsetCache[i-1].next = -1;
381
	using_client_side_fonts = 1;
382

383 384 385 386 387 388 389 390 391 392
	if(!X11DRV_XRender_Installed) {
	    TRACE("Xrender is not available on your XServer, client side rendering with the core protocol instead.\n");
	    if(screen_depth <= 8 || !client_side_antialias_with_core)
	        antialias = 0;
	} else {
	    if(screen_depth <= 8 || !client_side_antialias_with_render)
	        antialias = 0;
	}
    }
    else TRACE("Using X11 core fonts\n");
393 394
}

395
/* Helper function to convert from a color packed in a 32-bit integer to a XRenderColor */
396
static void get_xrender_color(const WineXRenderFormat *wxr_format, int src_color, XRenderColor *dst_color)
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
{
    XRenderPictFormat *pf = wxr_format->pict_format;

    if(pf->direct.redMask)
        dst_color->red = ((src_color >> pf->direct.red) & pf->direct.redMask) * 65535/pf->direct.redMask;
    else
       dst_color->red = 0;

    if(pf->direct.greenMask)
        dst_color->green = ((src_color >> pf->direct.green) & pf->direct.greenMask) * 65535/pf->direct.greenMask;
    else
        dst_color->green = 0;

    if(pf->direct.blueMask)
        dst_color->blue = ((src_color >> pf->direct.blue) & pf->direct.blueMask) * 65535/pf->direct.blueMask;
    else
        dst_color->blue = 0;

    dst_color->alpha = 0xffff;
}

418
static const WineXRenderFormat *get_xrender_format(WXRFormat format)
419 420 421 422 423 424 425 426 427 428 429 430 431
{
    int i;
    for(i=0; i<WineXRenderFormatsListSize; i++)
    {
        if(wxr_formats[i].format == format)
        {
            TRACE("Returning wxr_format=%#x\n", format);
            return &wxr_formats[i];
        }
    }
    return NULL;
}

432
static const WineXRenderFormat *get_xrender_format_from_color_shifts(int depth, ColorShifts *shifts)
433
{
434 435 436 437
    int redMask, greenMask, blueMask;
    unsigned int i;

    if(depth == 1)
438
        return get_xrender_format(WXR_FORMAT_MONO);
439

440
    /* physDevs of a depth <=8, don't have color_shifts set and XRender can't handle those except for 1-bit */
441
    if(!shifts)
442 443
        return default_format;

444 445 446
    redMask   = shifts->physicalRed.max << shifts->physicalRed.shift;
    greenMask = shifts->physicalGreen.max << shifts->physicalGreen.shift;
    blueMask  = shifts->physicalBlue.max << shifts->physicalBlue.shift;
447

448 449 450 451 452 453 454
    /* Try to locate a format which matches the specification of the dibsection. */
    for(i = 0; i < (sizeof(wxr_formats_template) / sizeof(wxr_formats_template[0])); i++)
    {
        if( depth     == wxr_formats_template[i].depth &&
            redMask   == (wxr_formats_template[i].redMask << wxr_formats_template[i].red) &&
            greenMask == (wxr_formats_template[i].greenMask << wxr_formats_template[i].green) &&
            blueMask  == (wxr_formats_template[i].blueMask << wxr_formats_template[i].blue) )
455

456 457 458 459 460
        {
            /* When we reach this stage the format was found in our template table but this doesn't mean that
            * the Xserver also supports this format (e.g. its depth might be too low). The call below verifies that.
            */
            return get_xrender_format(wxr_formats_template[i].wxr_format);
461 462
        }
    }
463 464 465

    /* This should not happen because when we reach 'shifts' must have been set and we only allows shifts which are backed by X */
    ERR("No XRender format found!\n");
466
    return NULL;
467 468
}

469 470 471 472 473 474 475 476 477 478 479 480 481 482
/* Set the x/y scaling and x/y offsets in the transformation matrix of the source picture */
static void set_xrender_transformation(Picture src_pict, float xscale, float yscale, int xoffset, int yoffset)
{
#ifdef HAVE_XRENDERSETPICTURETRANSFORM
    XTransform xform = {{
        { XDoubleToFixed(xscale), XDoubleToFixed(0), XDoubleToFixed(xoffset) },
        { XDoubleToFixed(0), XDoubleToFixed(yscale), XDoubleToFixed(yoffset) },
        { XDoubleToFixed(0), XDoubleToFixed(0), XDoubleToFixed(1) }
    }};

    pXRenderSetPictureTransform(gdi_display, src_pict, &xform);
#endif
}

483
static struct xrender_info *get_xrender_info(X11DRV_PDEVICE *physDev)
484
{
485 486 487
    if(!physDev->xrender)
    {
        physDev->xrender = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*physDev->xrender));
488

489 490 491 492 493 494 495 496 497
        if(!physDev->xrender)
        {
            ERR("Unable to allocate XRENDERINFO!\n");
            return NULL;
        }
        physDev->xrender->cache_index = -1;
    }
    if (!physDev->xrender->format)
        physDev->xrender->format = get_xrender_format_from_color_shifts(physDev->depth, physDev->color_shifts);
498

499
    return physDev->xrender;
500 501 502 503 504 505 506
}

static Picture get_xrender_picture(X11DRV_PDEVICE *physDev)
{
    struct xrender_info *info = get_xrender_info(physDev);
    if (!info) return 0;

507
    if (!info->pict && info->format)
508
    {
509
        XRenderPictureAttributes pa;
510
        RGNDATA *clip = X11DRV_GetRegionData( physDev->region, 0 );
511 512 513 514 515

        wine_tsx11_lock();
        pa.subwindow_mode = IncludeInferiors;
        info->pict = pXRenderCreatePicture(gdi_display, physDev->drawable, info->format->pict_format,
                                           CPSubwindowMode, &pa);
516 517 518 519
        if (info->pict && clip)
            pXRenderSetPictureClipRectangles( gdi_display, info->pict,
                                              physDev->dc_rect.left, physDev->dc_rect.top,
                                              (XRectangle *)clip->Buffer, clip->rdh.nCount );
520
        wine_tsx11_unlock();
521
        TRACE("Allocing pict=%lx dc=%p drawable=%08lx\n", info->pict, physDev->hdc, physDev->drawable);
522
        HeapFree( GetProcessHeap(), 0, clip );
523 524 525 526 527
    }

    return info->pict;
}

528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
static Picture get_xrender_picture_source(X11DRV_PDEVICE *physDev)
{
    struct xrender_info *info = get_xrender_info(physDev);
    if (!info) return 0;

    if (!info->pict_src && info->format)
    {
        XRenderPictureAttributes pa;

        wine_tsx11_lock();
        pa.subwindow_mode = IncludeInferiors;
        info->pict_src = pXRenderCreatePicture(gdi_display, physDev->drawable, info->format->pict_format,
                                               CPSubwindowMode, &pa);
        wine_tsx11_unlock();

        TRACE("Allocing pict_src=%lx dc=%p drawable=%08lx\n", info->pict_src, physDev->hdc, physDev->drawable);
    }

    return info->pict_src;
}

549 550 551
static BOOL fontcmp(LFANDSIZE *p1, LFANDSIZE *p2)
{
  if(p1->hash != p2->hash) return TRUE;
552
  if(memcmp(&p1->devsize, &p2->devsize, sizeof(p1->devsize))) return TRUE;
553
  if(memcmp(&p1->xform, &p2->xform, sizeof(p1->xform))) return TRUE;
554
  if(memcmp(&p1->lf, &p2->lf, offsetof(LOGFONTW, lfFaceName))) return TRUE;
555
  return strcmpiW(p1->lf.lfFaceName, p2->lf.lfFaceName);
556 557
}

558
#if 0
559 560 561 562
static void walk_cache(void)
{
  int i;

563
  EnterCriticalSection(&xrender_cs);
564 565
  for(i=mru; i >= 0; i = glyphsetCache[i].next)
    TRACE("item %d\n", i);
566
  LeaveCriticalSection(&xrender_cs);
567
}
568
#endif
569

570
static int LookupEntry(LFANDSIZE *plfsz)
571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
{
  int i, prev_i = -1;

  for(i = mru; i >= 0; i = glyphsetCache[i].next) {
    TRACE("%d\n", i);
    if(glyphsetCache[i].count == -1) { /* reached free list so stop */
      i = -1;
      break;
    }

    if(!fontcmp(&glyphsetCache[i].lfsz, plfsz)) {
      glyphsetCache[i].count++;
      if(prev_i >= 0) {
	glyphsetCache[prev_i].next = glyphsetCache[i].next;
	glyphsetCache[i].next = mru;
	mru = i;
      }
      TRACE("found font in cache %d\n", i);
589
      return i;
590 591 592 593
    }
    prev_i = i;
  }
  TRACE("font not in cache\n");
594
  return -1;
595 596
}

597 598
static void FreeEntry(int entry)
{
599 600 601 602
    int i, format;
  
    for(format = 0; format < AA_MAXVALUE; format++) {
        gsCacheEntryFormat * formatEntry;
603

604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619
        if( !glyphsetCache[entry].format[format] )
            continue;

        formatEntry = glyphsetCache[entry].format[format];

        if(formatEntry->glyphset) {
            wine_tsx11_lock();
            pXRenderFreeGlyphSet(gdi_display, formatEntry->glyphset);
            wine_tsx11_unlock();
            formatEntry->glyphset = 0;
        }
        if(formatEntry->nrealized) {
            HeapFree(GetProcessHeap(), 0, formatEntry->realized);
            formatEntry->realized = NULL;
            if(formatEntry->bitmaps) {
                for(i = 0; i < formatEntry->nrealized; i++)
620
                    HeapFree(GetProcessHeap(), 0, formatEntry->bitmaps[i]);
621 622 623
                HeapFree(GetProcessHeap(), 0, formatEntry->bitmaps);
                formatEntry->bitmaps = NULL;
            }
624 625
            HeapFree(GetProcessHeap(), 0, formatEntry->gis);
            formatEntry->gis = NULL;
626 627 628 629 630
            formatEntry->nrealized = 0;
        }

        HeapFree(GetProcessHeap(), 0, formatEntry);
        glyphsetCache[entry].format[format] = NULL;
631 632 633
    }
}

634
static int AllocEntry(void)
635 636 637 638 639 640 641
{
  int best = -1, prev_best = -1, i, prev_i = -1;

  if(lastfree >= 0) {
    assert(glyphsetCache[lastfree].count == -1);
    glyphsetCache[lastfree].count = 1;
    best = lastfree;
642
    lastfree = glyphsetCache[lastfree].next;
643 644 645 646 647
    assert(best != mru);
    glyphsetCache[best].next = mru;
    mru = best;

    TRACE("empty space at %d, next lastfree = %d\n", mru, lastfree);
648
    return mru;
649 650 651 652 653 654 655 656 657 658 659 660
  }

  for(i = mru; i >= 0; i = glyphsetCache[i].next) {
    if(glyphsetCache[i].count == 0) {
      best = i;
      prev_best = prev_i;
    }
    prev_i = i;
  }

  if(best >= 0) {
    TRACE("freeing unused glyphset at cache %d\n", best);
661
    FreeEntry(best);
662 663 664 665 666 667 668 669
    glyphsetCache[best].count = 1;
    if(prev_best >= 0) {
      glyphsetCache[prev_best].next = glyphsetCache[best].next;
      glyphsetCache[best].next = mru;
      mru = best;
    } else {
      assert(mru == best);
    }
670
    return mru;
671 672 673
  }

  TRACE("Growing cache\n");
674 675 676
  
  if (glyphsetCache)
    glyphsetCache = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
677 678 679
			      glyphsetCache,
			      (glyphsetCacheSize + INIT_CACHE_SIZE)
			      * sizeof(*glyphsetCache));
680 681 682 683 684
  else
    glyphsetCache = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
			      (glyphsetCacheSize + INIT_CACHE_SIZE)
			      * sizeof(*glyphsetCache));

685 686 687 688 689 690 691 692 693 694 695 696 697
  for(best = i = glyphsetCacheSize; i < glyphsetCacheSize + INIT_CACHE_SIZE;
      i++) {
    glyphsetCache[i].next = i + 1;
    glyphsetCache[i].count = -1;
  }
  glyphsetCache[i-1].next = -1;
  glyphsetCacheSize += INIT_CACHE_SIZE;

  lastfree = glyphsetCache[best].next;
  glyphsetCache[best].count = 1;
  glyphsetCache[best].next = mru;
  mru = best;
  TRACE("new free cache slot at %d\n", mru);
698
  return mru;
699
}
700

701 702 703
static BOOL get_gasp_flags(X11DRV_PDEVICE *physDev, WORD *flags)
{
    DWORD size;
704
    WORD *gasp, *buffer;
705 706 707 708 709 710 711 712 713 714
    WORD num_recs;
    DWORD ppem;
    TEXTMETRICW tm;

    *flags = 0;

    size = GetFontData(physDev->hdc, MS_GASP_TAG,  0, NULL, 0);
    if(size == GDI_ERROR)
        return FALSE;

715
    gasp = buffer = HeapAlloc(GetProcessHeap(), 0, size);
716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
    GetFontData(physDev->hdc, MS_GASP_TAG,  0, gasp, size);

    GetTextMetricsW(physDev->hdc, &tm);
    ppem = abs(X11DRV_YWStoDS(physDev, tm.tmAscent + tm.tmDescent - tm.tmInternalLeading));

    gasp++;
    num_recs = get_be_word(*gasp);
    gasp++;
    while(num_recs--)
    {
        *flags = get_be_word(*(gasp + 1));
        if(ppem <= get_be_word(*gasp))
            break;
        gasp += 2;
    }
731
    TRACE("got flags %04x for ppem %d\n", *flags, ppem);
732

733
    HeapFree(GetProcessHeap(), 0, buffer);
734 735 736
    return TRUE;
}

737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
static AA_Type get_antialias_type( X11DRV_PDEVICE *physDev, BOOL subpixel, BOOL hinter)
{
    AA_Type ret;
    WORD flags;
    UINT font_smoothing_type, font_smoothing_orientation;

    if (X11DRV_XRender_Installed && subpixel &&
        SystemParametersInfoW( SPI_GETFONTSMOOTHINGTYPE, 0, &font_smoothing_type, 0) &&
        font_smoothing_type == FE_FONTSMOOTHINGCLEARTYPE)
    {
        if ( SystemParametersInfoW( SPI_GETFONTSMOOTHINGORIENTATION, 0,
                                    &font_smoothing_orientation, 0) &&
             font_smoothing_orientation == FE_FONTSMOOTHINGORIENTATIONBGR)
        {
            ret = AA_BGR;
        }
        else
            ret = AA_RGB;
        /*FIXME
          If the monitor is in portrait mode, ClearType is disabled in the MS Windows (MSDN).
          But, Wine's subpixel rendering can support the portrait mode.
         */
    }
    else if (!hinter || !get_gasp_flags(physDev, &flags) || flags & GASP_DOGRAY)
        ret = AA_Grey;
    else
        ret = AA_None;

    return ret;
}

768
static int GetCacheEntry(X11DRV_PDEVICE *physDev, LFANDSIZE *plfsz)
769
{
770
    int ret;
771
    int format;
772
    gsCacheEntry *entry;
773
    static int hinter = -1;
774
    static int subpixel = -1;
775
    BOOL font_smoothing;
776

777 778 779 780 781
    if((ret = LookupEntry(plfsz)) != -1) return ret;

    ret = AllocEntry();
    entry = glyphsetCache + ret;
    entry->lfsz = *plfsz;
782 783 784
    for( format = 0; format < AA_MAXVALUE; format++ ) {
        assert( !entry->format[format] );
    }
785

786
    if(antialias && plfsz->lf.lfQuality != NONANTIALIASED_QUALITY)
787
    {
788
        if(hinter == -1 || subpixel == -1)
789 790 791 792
        {
            RASTERIZER_STATUS status;
            GetRasterizerCaps(&status, sizeof(status));
            hinter = status.wFlags & WINE_TT_HINTER_ENABLED;
793
            subpixel = status.wFlags & WINE_TT_SUBPIXEL_RENDERING_ENABLED;
794
        }
795

796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817
        switch (plfsz->lf.lfQuality)
        {
            case ANTIALIASED_QUALITY:
                entry->aa_default = get_antialias_type( physDev, FALSE, hinter );
                break;
            case CLEARTYPE_QUALITY:
            case CLEARTYPE_NATURAL_QUALITY:
                entry->aa_default = get_antialias_type( physDev, subpixel, hinter );
                break;
            case DEFAULT_QUALITY:
            case DRAFT_QUALITY:
            case PROOF_QUALITY:
            default:
                if ( SystemParametersInfoW( SPI_GETFONTSMOOTHING, 0, &font_smoothing, 0) &&
                     font_smoothing)
                {
                    entry->aa_default = get_antialias_type( physDev, subpixel, hinter );
                }
                else
                    entry->aa_default = AA_None;
                break;
        }
818
    }
819
    else
820
        entry->aa_default = AA_None;
821 822

    return ret;
823 824
}

825
static void dec_ref_cache(int index)
826
{
827 828 829 830
    assert(index >= 0);
    TRACE("dec'ing entry %d to %d\n", index, glyphsetCache[index].count - 1);
    assert(glyphsetCache[index].count > 0);
    glyphsetCache[index].count--;
831 832 833 834
}

static void lfsz_calc_hash(LFANDSIZE *plfsz)
{
835 836
  DWORD hash = 0, *ptr, two_chars;
  WORD *pwc;
837 838
  int i;

839 840
  hash ^= plfsz->devsize.cx;
  hash ^= plfsz->devsize.cy;
841 842
  for(i = 0, ptr = (DWORD*)&plfsz->xform; i < sizeof(XFORM)/sizeof(DWORD); i++, ptr++)
    hash ^= *ptr;
843 844
  for(i = 0, ptr = (DWORD*)&plfsz->lf; i < 7; i++, ptr++)
    hash ^= *ptr;
845
  for(i = 0, ptr = (DWORD*)plfsz->lf.lfFaceName; i < LF_FACESIZE/2; i++, ptr++) {
846 847
    two_chars = *ptr;
    pwc = (WCHAR *)&two_chars;
848
    if(!*pwc) break;
849
    *pwc = toupperW(*pwc);
850
    pwc++;
851 852
    *pwc = toupperW(*pwc);
    hash ^= two_chars;
853 854 855 856 857 858 859 860 861 862 863
    if(!*pwc) break;
  }
  plfsz->hash = hash;
  return;
}

/***********************************************************************
 *   X11DRV_XRender_Finalize
 */
void X11DRV_XRender_Finalize(void)
{
864 865 866 867 868 869
    int i;

    EnterCriticalSection(&xrender_cs);
    for(i = mru; i >= 0; i = glyphsetCache[i].next)
	FreeEntry(i);
    LeaveCriticalSection(&xrender_cs);
870 871 872 873 874 875
}


/***********************************************************************
 *   X11DRV_XRender_SelectFont
 */
876
BOOL X11DRV_XRender_SelectFont(X11DRV_PDEVICE *physDev, HFONT hfont)
877 878
{
    LFANDSIZE lfsz;
879
    struct xrender_info *info;
880 881

    GetObjectW(hfont, sizeof(lfsz.lf), &lfsz.lf);
882
    TRACE("h=%d w=%d weight=%d it=%d charset=%d name=%s\n",
883 884
	  lfsz.lf.lfHeight, lfsz.lf.lfWidth, lfsz.lf.lfWeight,
	  lfsz.lf.lfItalic, lfsz.lf.lfCharSet, debugstr_w(lfsz.lf.lfFaceName));
885
    lfsz.lf.lfWidth = abs( lfsz.lf.lfWidth );
886 887
    lfsz.devsize.cx = X11DRV_XWStoDS( physDev, lfsz.lf.lfWidth );
    lfsz.devsize.cy = X11DRV_YWStoDS( physDev, lfsz.lf.lfHeight );
888
    GetWorldTransform( physDev->hdc, &lfsz.xform );
889 890
    lfsz_calc_hash(&lfsz);

891 892 893
    info = get_xrender_info(physDev);
    if (!info) return 0;

894
    EnterCriticalSection(&xrender_cs);
895 896 897
    if(info->cache_index != -1)
        dec_ref_cache(info->cache_index);
    info->cache_index = GetCacheEntry(physDev, &lfsz);
898
    LeaveCriticalSection(&xrender_cs);
899 900 901
    return 0;
}

902 903 904 905 906 907 908 909 910 911 912 913 914 915 916
/***********************************************************************
*   X11DRV_XRender_SetDeviceClipping
*/
void X11DRV_XRender_SetDeviceClipping(X11DRV_PDEVICE *physDev, const RGNDATA *data)
{
    if (physDev->xrender->pict)
    {
        wine_tsx11_lock();
        pXRenderSetPictureClipRectangles( gdi_display, physDev->xrender->pict,
                                          physDev->dc_rect.left, physDev->dc_rect.top,
                                          (XRectangle *)data->Buffer, data->rdh.nCount );
        wine_tsx11_unlock();
    }
}

917 918 919
/***********************************************************************
 *   X11DRV_XRender_DeleteDC
 */
920
void X11DRV_XRender_DeleteDC(X11DRV_PDEVICE *physDev)
921
{
922
    X11DRV_XRender_UpdateDrawable(physDev);
923

924 925 926 927
    EnterCriticalSection(&xrender_cs);
    if(physDev->xrender->cache_index != -1)
        dec_ref_cache(physDev->xrender->cache_index);
    LeaveCriticalSection(&xrender_cs);
928

929 930 931 932 933
    HeapFree(GetProcessHeap(), 0, physDev->xrender);
    physDev->xrender = NULL;
    return;
}

934 935
BOOL X11DRV_XRender_SetPhysBitmapDepth(X_PHYSBITMAP *physBitmap, const DIBSECTION *dib)
{
936
    const WineXRenderFormat *fmt;
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960
    ColorShifts shifts;

    /* When XRender is not around we can only use the screen_depth and when needed we perform depth conversion
     * in software. Further we also return the screen depth for paletted formats or TrueColor formats with a low
     * number of bits because XRender can't handle paletted formats and 8-bit TrueColor does not exist for XRender. */
    if(!X11DRV_XRender_Installed || dib->dsBm.bmBitsPixel <= 8)
        return FALSE;

    X11DRV_PALETTE_ComputeColorShifts(&shifts, dib->dsBitfields[0], dib->dsBitfields[1], dib->dsBitfields[2]);

    /* Common formats should be in our picture format table. */
    fmt = get_xrender_format_from_color_shifts(dib->dsBm.bmBitsPixel, &shifts);
    if(fmt)
    {
        physBitmap->pixmap_depth = fmt->pict_format->depth;
        physBitmap->trueColor = TRUE;
        physBitmap->pixmap_color_shifts = shifts;
        return TRUE;
    }
    TRACE("Unhandled dibsection format bpp=%d, redMask=%x, greenMask=%x, blueMask=%x\n",
          dib->dsBm.bmBitsPixel, dib->dsBitfields[0], dib->dsBitfields[1], dib->dsBitfields[2]);
    return FALSE;
}

961 962 963
/***********************************************************************
 *   X11DRV_XRender_UpdateDrawable
 *
964
 * Deletes the pict and tile when the drawable changes.
965
 */
966
void X11DRV_XRender_UpdateDrawable(X11DRV_PDEVICE *physDev)
967
{
968
    struct xrender_info *info = physDev->xrender;
969

970
    if (info->pict || info->pict_src)
971
    {
972 973 974 975 976 977 978 979 980 981 982 983 984 985 986
        wine_tsx11_lock();
        XFlush( gdi_display );
        if (info->pict)
        {
            TRACE("freeing pict = %lx dc = %p\n", info->pict, physDev->hdc);
            pXRenderFreePicture(gdi_display, info->pict);
            info->pict = 0;
        }
        if(info->pict_src)
        {
            TRACE("freeing pict = %lx dc = %p\n", info->pict_src, physDev->hdc);
            pXRenderFreePicture(gdi_display, info->pict_src);
            info->pict_src = 0;
        }
        wine_tsx11_unlock();
987
    }
988

989
    info->format = NULL;
990 991
}

992 993 994 995 996
/************************************************************************
 *   UploadGlyph
 *
 * Helper to ExtTextOut.  Must be called inside xrender_cs
 */
997
static BOOL UploadGlyph(X11DRV_PDEVICE *physDev, int glyph, AA_Type format)
998
{
999
    unsigned int buflen;
1000 1001 1002 1003
    char *buf;
    Glyph gid;
    GLYPHMETRICS gm;
    XGlyphInfo gi;
1004
    gsCacheEntry *entry = glyphsetCache + physDev->xrender->cache_index;
1005
    gsCacheEntryFormat *formatEntry;
1006
    UINT ggo_format = GGO_GLYPH_INDEX;
1007
    WXRFormat wxr_format;
1008
    static const char zero[4];
1009
    static const MAT2 identity = { {0,1},{0,0},{0,0},{0,1} };
1010

1011 1012 1013 1014
    switch(format) {
    case AA_Grey:
	ggo_format |= WINE_GGO_GRAY16_BITMAP;
	break;
1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026
    case AA_RGB:
	ggo_format |= WINE_GGO_HRGB_BITMAP;
	break;
    case AA_BGR:
	ggo_format |= WINE_GGO_HBGR_BITMAP;
	break;
    case AA_VRGB:
	ggo_format |= WINE_GGO_VRGB_BITMAP;
	break;
    case AA_VBGR:
	ggo_format |= WINE_GGO_VBGR_BITMAP;
	break;
1027 1028 1029 1030 1031 1032 1033 1034

    default:
        ERR("aa = %d - not implemented\n", format);
    case AA_None:
        ggo_format |= GGO_BITMAP;
	break;
    }

1035
    buflen = GetGlyphOutlineW(physDev->hdc, glyph, ggo_format, &gm, 0, NULL, &identity);
1036 1037 1038 1039
    if(buflen == GDI_ERROR) {
        if(format != AA_None) {
            format = AA_None;
            entry->aa_default = AA_None;
1040
            ggo_format = GGO_GLYPH_INDEX | GGO_BITMAP;
1041
            buflen = GetGlyphOutlineW(physDev->hdc, glyph, ggo_format, &gm, 0, NULL, &identity);
1042 1043
        }
        if(buflen == GDI_ERROR) {
1044
            WARN("GetGlyphOutlineW failed\n");
1045 1046 1047 1048 1049
            return FALSE;
        }
        TRACE("Turning off antialiasing for this monochrome font\n");
    }

1050 1051 1052 1053 1054 1055 1056
    /* If there is nothing for the current type, we create the entry. */
    if( !entry->format[format] ) {
        entry->format[format] = HeapAlloc(GetProcessHeap(),
                                          HEAP_ZERO_MEMORY,
                                          sizeof(gsCacheEntryFormat));
    }
    formatEntry = entry->format[format];
1057

1058 1059 1060 1061 1062
    if(formatEntry->nrealized <= glyph) {
        formatEntry->nrealized = (glyph / 128 + 1) * 128;

	if (formatEntry->realized)
	    formatEntry->realized = HeapReAlloc(GetProcessHeap(),
1063
				      HEAP_ZERO_MEMORY,
1064 1065
				      formatEntry->realized,
				      formatEntry->nrealized * sizeof(BOOL));
1066
	else
1067
	    formatEntry->realized = HeapAlloc(GetProcessHeap(),
1068
				      HEAP_ZERO_MEMORY,
1069
				      formatEntry->nrealized * sizeof(BOOL));
1070

1071
	if(!X11DRV_XRender_Installed) {
1072 1073
	  if (formatEntry->bitmaps)
	    formatEntry->bitmaps = HeapReAlloc(GetProcessHeap(),
1074
				      HEAP_ZERO_MEMORY,
1075 1076
				      formatEntry->bitmaps,
				      formatEntry->nrealized * sizeof(formatEntry->bitmaps[0]));
1077
	  else
1078
	    formatEntry->bitmaps = HeapAlloc(GetProcessHeap(),
1079
				      HEAP_ZERO_MEMORY,
1080
				      formatEntry->nrealized * sizeof(formatEntry->bitmaps[0]));
1081 1082
        }
        if (formatEntry->gis)
1083
	    formatEntry->gis = HeapReAlloc(GetProcessHeap(),
1084
				   HEAP_ZERO_MEMORY,
1085 1086
				   formatEntry->gis,
				   formatEntry->nrealized * sizeof(formatEntry->gis[0]));
1087
        else
1088
	    formatEntry->gis = HeapAlloc(GetProcessHeap(),
1089
				   HEAP_ZERO_MEMORY,
1090
                                   formatEntry->nrealized * sizeof(formatEntry->gis[0]));
1091 1092
    }

1093

1094 1095
    if(formatEntry->glyphset == 0 && X11DRV_XRender_Installed) {
        switch(format) {
1096 1097 1098
            case AA_Grey:
                wxr_format = WXR_FORMAT_GRAY;
                break;
1099

1100 1101 1102 1103 1104 1105
            case AA_RGB:
            case AA_BGR:
            case AA_VRGB:
            case AA_VBGR:
                wxr_format = WXR_FORMAT_A8R8G8B8;
                break;
1106

1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
            default:
                ERR("aa = %d - not implemented\n", format);
            case AA_None:
                wxr_format = WXR_FORMAT_MONO;
                break;
        }

        wine_tsx11_lock();
        formatEntry->font_format = get_xrender_format(wxr_format);
        formatEntry->glyphset = pXRenderCreateGlyphSet(gdi_display, formatEntry->font_format->pict_format);
        wine_tsx11_unlock();
1118 1119
    }

1120 1121

    buf = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, buflen);
1122
    GetGlyphOutlineW(physDev->hdc, glyph, ggo_format, &gm, buflen, buf, &identity);
1123
    formatEntry->realized[glyph] = TRUE;
1124

1125
    TRACE("buflen = %d. Got metrics: %dx%d adv=%d,%d origin=%d,%d\n",
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141
	  buflen,
	  gm.gmBlackBoxX, gm.gmBlackBoxY, gm.gmCellIncX, gm.gmCellIncY,
	  gm.gmptGlyphOrigin.x, gm.gmptGlyphOrigin.y);

    gi.width = gm.gmBlackBoxX;
    gi.height = gm.gmBlackBoxY;
    gi.x = -gm.gmptGlyphOrigin.x;
    gi.y = gm.gmptGlyphOrigin.y;
    gi.xOff = gm.gmCellIncX;
    gi.yOff = gm.gmCellIncY;

    if(TRACE_ON(xrender)) {
        int pitch, i, j;
	char output[300];
	unsigned char *line;

1142
	if(format == AA_None) {
1143 1144
	    pitch = ((gi.width + 31) / 32) * 4;
	    for(i = 0; i < gi.height; i++) {
1145
	        line = (unsigned char*) buf + i * pitch;
1146 1147 1148 1149
		output[0] = '\0';
		for(j = 0; j < pitch * 8; j++) {
	            strcat(output, (line[j / 8] & (1 << (7 - (j % 8)))) ? "#" : " ");
		}
1150
		TRACE("%s\n", output);
1151 1152
	    }
	} else {
1153
	    static const char blks[] = " .:;!o*#";
1154 1155 1156 1157 1158
	    char str[2];

	    str[1] = '\0';
	    pitch = ((gi.width + 3) / 4) * 4;
	    for(i = 0; i < gi.height; i++) {
1159
	        line = (unsigned char*) buf + i * pitch;
1160 1161 1162 1163 1164
		output[0] = '\0';
		for(j = 0; j < pitch; j++) {
		    str[0] = blks[line[j] >> 5];
		    strcat(output, str);
		}
1165
		TRACE("%s\n", output);
1166 1167 1168 1169
	    }
	}
    }

1170

1171 1172
    if(formatEntry->glyphset) {
        if(format == AA_None && BitmapBitOrder(gdi_display) != MSBFirst) {
1173
	    unsigned char *byte = (unsigned char*) buf, c;
1174
	    int i = buflen;
1175

1176 1177
	    while(i--) {
	        c = *byte;
1178

1179 1180 1181 1182
		/* magic to flip bit order */
		c = ((c << 1) & 0xaa) | ((c >> 1) & 0x55);
		c = ((c << 2) & 0xcc) | ((c >> 2) & 0x33);
		c = ((c << 4) & 0xf0) | ((c >> 4) & 0x0f);
1183

1184 1185
		*byte++ = c;
	    }
1186
	}
1187 1188 1189 1190 1191 1192
        else if ( format != AA_Grey &&
                  ImageByteOrder (gdi_display) != NATIVE_BYTE_ORDER)
        {
            unsigned int i, *data = (unsigned int *)buf;
            for (i = buflen / sizeof(int); i; i--, data++) *data = RtlUlongByteSwap(*data);
        }
1193
	gid = glyph;
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204

        /*
          XRenderCompositeText seems to ignore 0x0 glyphs when
          AA_None, which means we lose the advance width of glyphs
          like the space.  We'll pretend that such glyphs are 1x1
          bitmaps.
        */

        if(buflen == 0)
            gi.width = gi.height = 1;

1205
        wine_tsx11_lock();
1206
	pXRenderAddGlyphs(gdi_display, formatEntry->glyphset, &gid, &gi, 1,
1207
                          buflen ? buf : zero, buflen ? buflen : sizeof(zero));
1208 1209 1210
	wine_tsx11_unlock();
	HeapFree(GetProcessHeap(), 0, buf);
    } else {
1211
        formatEntry->bitmaps[glyph] = buf;
1212
    }
1213

1214
    formatEntry->gis[glyph] = gi;
1215

1216 1217 1218
    return TRUE;
}

1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385
static void SharpGlyphMono(X11DRV_PDEVICE *physDev, INT x, INT y,
			    void *bitmap, XGlyphInfo *gi)
{
    unsigned char   *srcLine = bitmap, *src;
    unsigned char   bits, bitsMask;
    int             width = gi->width;
    int             stride = ((width + 31) & ~31) >> 3;
    int             height = gi->height;
    int             w;
    int             xspan, lenspan;

    TRACE("%d, %d\n", x, y);
    x -= gi->x;
    y -= gi->y;
    while (height--)
    {
        src = srcLine;
        srcLine += stride;
        w = width;
        
        bitsMask = 0x80;    /* FreeType is always MSB first */
        bits = *src++;
        
        xspan = x;
        while (w)
        {
            if (bits & bitsMask)
            {
                lenspan = 0;
                do
                {
                    lenspan++;
                    if (lenspan == w)
                        break;
                    bitsMask = bitsMask >> 1;
                    if (!bitsMask)
                    {
                        bits = *src++;
                        bitsMask = 0x80;
                    }
                } while (bits & bitsMask);
                XFillRectangle (gdi_display, physDev->drawable, 
                                physDev->gc, xspan, y, lenspan, 1);
                xspan += lenspan;
                w -= lenspan;
            }
            else
            {
                do
                {
                    w--;
                    xspan++;
                    if (!w)
                        break;
                    bitsMask = bitsMask >> 1;
                    if (!bitsMask)
                    {
                        bits = *src++;
                        bitsMask = 0x80;
                    }
                } while (!(bits & bitsMask));
            }
        }
        y++;
    }
}

static void SharpGlyphGray(X11DRV_PDEVICE *physDev, INT x, INT y,
			    void *bitmap, XGlyphInfo *gi)
{
    unsigned char   *srcLine = bitmap, *src, bits;
    int             width = gi->width;
    int             stride = ((width + 3) & ~3);
    int             height = gi->height;
    int             w;
    int             xspan, lenspan;

    x -= gi->x;
    y -= gi->y;
    while (height--)
    {
        src = srcLine;
        srcLine += stride;
        w = width;
        
        bits = *src++;
        xspan = x;
        while (w)
        {
            if (bits >= 0x80)
            {
                lenspan = 0;
                do
                {
                    lenspan++;
                    if (lenspan == w)
                        break;
                    bits = *src++;
                } while (bits >= 0x80);
                XFillRectangle (gdi_display, physDev->drawable, 
                                physDev->gc, xspan, y, lenspan, 1);
                xspan += lenspan;
                w -= lenspan;
            }
            else
            {
                do
                {
                    w--;
                    xspan++;
                    if (!w)
                        break;
                    bits = *src++;
                } while (bits < 0x80);
            }
        }
        y++;
    }
}


static void ExamineBitfield (DWORD mask, int *shift, int *len)
{
    int s, l;

    s = 0;
    while ((mask & 1) == 0)
    {
        mask >>= 1;
        s++;
    }
    l = 0;
    while ((mask & 1) == 1)
    {
        mask >>= 1;
        l++;
    }
    *shift = s;
    *len = l;
}

static DWORD GetField (DWORD pixel, int shift, int len)
{
    pixel = pixel & (((1 << (len)) - 1) << shift);
    pixel = pixel << (32 - (shift + len)) >> 24;
    while (len < 8)
    {
        pixel |= (pixel >> len);
        len <<= 1;
    }
    return pixel;
}


static DWORD PutField (DWORD pixel, int shift, int len)
{
    shift = shift - (8 - len);
    if (len <= 8)
        pixel &= (((1 << len) - 1) << (8 - len));
    if (shift < 0)
        pixel >>= -shift;
    else
        pixel <<= shift;
    return pixel;
}

static void SmoothGlyphGray(XImage *image, int x, int y, void *bitmap, XGlyphInfo *gi,
1386
			    int color)
1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402
{
    int             r_shift, r_len;
    int             g_shift, g_len;
    int             b_shift, b_len;
    BYTE            *maskLine, *mask, m;
    int             maskStride;
    DWORD           pixel;
    int             width, height;
    int             w, tx;
    BYTE            src_r, src_g, src_b;

    x -= gi->x;
    y -= gi->y;
    width = gi->width;
    height = gi->height;

1403
    maskLine = bitmap;
1404 1405 1406 1407 1408
    maskStride = (width + 3) & ~3;

    ExamineBitfield (image->red_mask, &r_shift, &r_len);
    ExamineBitfield (image->green_mask, &g_shift, &g_len);
    ExamineBitfield (image->blue_mask, &b_shift, &b_len);
1409 1410 1411 1412 1413

    src_r = GetField(color, r_shift, r_len);
    src_g = GetField(color, g_shift, g_len);
    src_b = GetField(color, b_shift, b_len);
    
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431
    for(; height--; y++)
    {
        mask = maskLine;
        maskLine += maskStride;
        w = width;
        tx = x;

	if(y < 0) continue;
	if(y >= image->height) break;

        for(; w--; tx++)
        {
	    if(tx >= image->width) break;

            m = *mask++;
	    if(tx < 0) continue;

	    if (m == 0xff)
1432
		XPutPixel (image, tx, y, color);
1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454
	    else if (m)
	    {
	        BYTE r, g, b;

		pixel = XGetPixel (image, tx, y);

		r = GetField(pixel, r_shift, r_len);
		r = ((BYTE)~m * (WORD)r + (BYTE)m * (WORD)src_r) >> 8;
		g = GetField(pixel, g_shift, g_len);
		g = ((BYTE)~m * (WORD)g + (BYTE)m * (WORD)src_g) >> 8;
		b = GetField(pixel, b_shift, b_len);
		b = ((BYTE)~m * (WORD)b + (BYTE)m * (WORD)src_b) >> 8;

		pixel = (PutField (r, r_shift, r_len) |
			 PutField (g, g_shift, g_len) |
			 PutField (b, b_shift, b_len));
		XPutPixel (image, tx, y, pixel);
	    }
        }
    }
}

1455 1456 1457
/*************************************************************
 *                 get_tile_pict
 *
Austin English's avatar
Austin English committed
1458
 * Returns an appropriate Picture for tiling the text colour.
1459 1460
 * Call and use result within the xrender_cs
 */
1461
static Picture get_tile_pict(const WineXRenderFormat *wxr_format, int text_pixel)
1462 1463 1464 1465 1466 1467
{
    static struct
    {
        Pixmap xpm;
        Picture pict;
        int current_color;
1468
    } tiles[MAX_FORMATS], *tile;
1469 1470
    XRenderColor col;

1471
    tile = &tiles[wxr_format->format];
1472 1473 1474 1475 1476 1477

    if(!tile->xpm)
    {
        XRenderPictureAttributes pa;

        wine_tsx11_lock();
1478
        tile->xpm = XCreatePixmap(gdi_display, root_window, 1, 1, wxr_format->pict_format->depth);
1479

1480
        pa.repeat = RepeatNormal;
1481
        tile->pict = pXRenderCreatePicture(gdi_display, tile->xpm, wxr_format->pict_format, CPRepeat, &pa);
1482 1483 1484 1485 1486
        wine_tsx11_unlock();

        /* init current_color to something different from text_pixel */
        tile->current_color = ~text_pixel;

1487
        if(wxr_format->format == WXR_FORMAT_MONO)
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497
        {
            /* for a 1bpp bitmap we always need a 1 in the tile */
            col.red = col.green = col.blue = 0;
            col.alpha = 0xffff;
            wine_tsx11_lock();
            pXRenderFillRectangle(gdi_display, PictOpSrc, tile->pict, &col, 0, 0, 1, 1);
            wine_tsx11_unlock();
        }
    }

1498
    if(text_pixel != tile->current_color && wxr_format->format != WXR_FORMAT_MONO)
1499
    {
1500
        get_xrender_color(wxr_format, text_pixel, &col);
1501 1502 1503 1504 1505 1506 1507 1508
        wine_tsx11_lock();
        pXRenderFillRectangle(gdi_display, PictOpSrc, tile->pict, &col, 0, 0, 1, 1);
        wine_tsx11_unlock();
        tile->current_color = text_pixel;
    }
    return tile->pict;
}

1509 1510 1511 1512 1513
static int XRenderErrorHandler(Display *dpy, XErrorEvent *event, void *arg)
{
    return 1;
}

1514 1515 1516
/***********************************************************************
 *   X11DRV_XRender_ExtTextOut
 */
1517
BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flags,
1518
				const RECT *lprect, LPCWSTR wstr, UINT count,
1519
				const INT *lpDx )
1520 1521
{
    XGCValues xgcval;
1522
    gsCacheEntry *entry;
1523
    gsCacheEntryFormat *formatEntry;
1524
    BOOL retv = FALSE;
1525
    int textPixel, backgroundPixel;
1526
    HRGN saved_region = 0;
1527
    BOOL disable_antialias = FALSE;
1528
    AA_Type aa_type = AA_None;
1529
    DIBSECTION bmp;
1530 1531 1532
    unsigned int idx;
    double cosEsc, sinEsc;
    LOGFONTW lf;
1533
    const WineXRenderFormat *dst_format = get_xrender_format_from_color_shifts(physDev->depth, physDev->color_shifts);
1534
    Picture tile_pict = 0;
1535 1536

    /* Do we need to disable antialiasing because of palette mode? */
1537
    if( !physDev->bitmap || GetObjectW( physDev->bitmap->hbitmap, sizeof(bmp), &bmp ) != sizeof(bmp) ) {
1538 1539 1540 1541 1542 1543
        TRACE("bitmap is not a DIB\n");
    }
    else if (bmp.dsBmih.biBitCount <= 8) {
        TRACE("Disabling antialiasing\n");
        disable_antialias = TRUE;
    }
1544 1545 1546 1547

    xgcval.function = GXcopy;
    xgcval.background = physDev->backgroundPixel;
    xgcval.fill_style = FillSolid;
1548 1549 1550
    wine_tsx11_lock();
    XChangeGC( gdi_display, physDev->gc, GCFunction | GCBackground | GCFillStyle, &xgcval );
    wine_tsx11_unlock();
1551

1552
    X11DRV_LockDIBSection( physDev, DIB_Status_GdiMod );
1553

1554
    if(physDev->depth == 1) {
1555
        if((physDev->textPixel & 0xffffff) == 0) {
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566
	    textPixel = 0;
	    backgroundPixel = 1;
	} else {
	    textPixel = 1;
	    backgroundPixel = 0;
	}
    } else {
        textPixel = physDev->textPixel;
	backgroundPixel = physDev->backgroundPixel;
    }

1567 1568
    if(flags & ETO_OPAQUE)
    {
1569 1570 1571
        wine_tsx11_lock();
        XSetForeground( gdi_display, physDev->gc, backgroundPixel );
        XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
1572
                        physDev->dc_rect.left + lprect->left, physDev->dc_rect.top + lprect->top,
1573
                        lprect->right - lprect->left, lprect->bottom - lprect->top );
1574
        wine_tsx11_unlock();
1575 1576
    }

1577 1578 1579
    if(count == 0)
    {
	retv = TRUE;
1580
        goto done_unlock;
1581 1582
    }

1583 1584 1585 1586 1587
    
    GetObjectW(GetCurrentObject(physDev->hdc, OBJ_FONT), sizeof(lf), &lf);
    if(lf.lfEscapement != 0) {
        cosEsc = cos(lf.lfEscapement * M_PI / 1800);
        sinEsc = sin(lf.lfEscapement * M_PI / 1800);
1588
    } else {
1589 1590
        cosEsc = 1;
        sinEsc = 0;
1591 1592 1593 1594
    }

    if (flags & ETO_CLIPPED)
    {
1595 1596
        HRGN clip_region;

1597
        clip_region = CreateRectRgnIndirect( lprect );
1598 1599 1600 1601 1602
        /* make a copy of the current device region */
        saved_region = CreateRectRgn( 0, 0, 0, 0 );
        CombineRgn( saved_region, physDev->region, 0, RGN_COPY );
        X11DRV_SetDeviceClipping( physDev, saved_region, clip_region );
        DeleteObject( clip_region );
1603 1604
    }

1605 1606
    EnterCriticalSection(&xrender_cs);

1607
    entry = glyphsetCache + physDev->xrender->cache_index;
1608
    if( disable_antialias == FALSE )
1609 1610
        aa_type = entry->aa_default;
    formatEntry = entry->format[aa_type];
1611

1612
    for(idx = 0; idx < count; idx++) {
1613
        if( !formatEntry ) {
1614
	    UploadGlyph(physDev, wstr[idx], aa_type);
1615 1616
            /* re-evaluate antialias since aa_default may have changed */
            if( disable_antialias == FALSE )
1617 1618
                aa_type = entry->aa_default;
            formatEntry = entry->format[aa_type];
1619
        } else if( wstr[idx] >= formatEntry->nrealized || formatEntry->realized[wstr[idx]] == FALSE) {
1620
	    UploadGlyph(physDev, wstr[idx], aa_type);
1621 1622
	}
    }
1623 1624 1625 1626 1627 1628
    if (!formatEntry)
    {
        WARN("could not upload requested glyphs\n");
        LeaveCriticalSection(&xrender_cs);
        goto done_unlock;
    }
1629

1630
    TRACE("Writing %s at %d,%d\n", debugstr_wn(wstr,count),
1631
          physDev->dc_rect.left + x, physDev->dc_rect.top + y);
1632

1633 1634 1635 1636 1637
    if(X11DRV_XRender_Installed)
    {
        XGlyphElt16 *elts = HeapAlloc(GetProcessHeap(), 0, sizeof(XGlyphElt16) * count);
        INT offset = 0;
        POINT desired, current;
1638
        int render_op = PictOpOver;
1639 1640
        Picture pict = get_xrender_picture(physDev);

1641 1642 1643 1644 1645 1646 1647 1648
        /* There's a bug in XRenderCompositeText that ignores the xDst and yDst parameters.
           So we pass zeros to the function and move to our starting position using the first
           element of the elts array. */

        desired.x = physDev->dc_rect.left + x;
        desired.y = physDev->dc_rect.top + y;
        current.x = current.y = 0;

1649
        tile_pict = get_tile_pict(dst_format, physDev->textPixel);
1650 1651 1652

	/* FIXME the mapping of Text/BkColor onto 1 or 0 needs investigation.
	 */
1653
	if((dst_format->format == WXR_FORMAT_MONO) && (textPixel == 0))
1654 1655
	    render_op = PictOpOutReverse; /* This gives us 'black' text */

1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679
        for(idx = 0; idx < count; idx++)
        {
            elts[idx].glyphset = formatEntry->glyphset;
            elts[idx].chars = wstr + idx;
            elts[idx].nchars = 1;
            elts[idx].xOff = desired.x - current.x;
            elts[idx].yOff = desired.y - current.y;

            current.x += (elts[idx].xOff + formatEntry->gis[wstr[idx]].xOff);
            current.y += (elts[idx].yOff + formatEntry->gis[wstr[idx]].yOff);

            if(!lpDx)
            {
                desired.x += formatEntry->gis[wstr[idx]].xOff;
                desired.y += formatEntry->gis[wstr[idx]].yOff;
            }
            else
            {
                offset += lpDx[idx];
                desired.x = physDev->dc_rect.left + x + offset * cosEsc;
                desired.y = physDev->dc_rect.top  + y - offset * sinEsc;
            }
        }
        wine_tsx11_lock();
1680 1681
        /* Make sure we don't have any transforms set from a previous call */
        set_xrender_transformation(pict, 1, 1, 0, 0);
1682
        pXRenderCompositeText16(gdi_display, render_op,
1683
                                tile_pict,
1684
                                pict,
1685
                                formatEntry->font_format->pict_format,
1686 1687 1688
                                0, 0, 0, 0, elts, count);
        wine_tsx11_unlock();
        HeapFree(GetProcessHeap(), 0, elts);
1689
    } else {
1690
        INT offset = 0, xoff = 0, yoff = 0;
1691 1692 1693
        wine_tsx11_lock();
	XSetForeground( gdi_display, physDev->gc, textPixel );

1694 1695 1696 1697 1698 1699 1700 1701 1702
        if(aa_type == AA_None || physDev->depth == 1)
        {
            void (* sharp_glyph_fn)(X11DRV_PDEVICE *, INT, INT, void *, XGlyphInfo *);

            if(aa_type == AA_None)
                sharp_glyph_fn = SharpGlyphMono;
            else
                sharp_glyph_fn = SharpGlyphGray;

1703
	    for(idx = 0; idx < count; idx++) {
1704
	        sharp_glyph_fn(physDev, physDev->dc_rect.left + x + xoff,
1705
			       physDev->dc_rect.top + y + yoff,
1706 1707 1708 1709
			       formatEntry->bitmaps[wstr[idx]],
			       &formatEntry->gis[wstr[idx]]);
		if(lpDx) {
		    offset += lpDx[idx];
1710 1711 1712
		    xoff = offset * cosEsc;
		    yoff = offset * -sinEsc;
		} else {
1713 1714
		    xoff += formatEntry->gis[wstr[idx]].xOff;
		    yoff += formatEntry->gis[wstr[idx]].yOff;
1715 1716 1717 1718 1719 1720 1721
		}
	    }
	} else {
	    XImage *image;
	    int image_x, image_y, image_off_x, image_off_y, image_w, image_h;
	    RECT extents = {0, 0, 0, 0};
	    POINT cur = {0, 0};
1722 1723 1724
            int w = physDev->drawable_rect.right - physDev->drawable_rect.left;
            int h = physDev->drawable_rect.bottom - physDev->drawable_rect.top;

1725 1726 1727
	    TRACE("drawable %dx%d\n", w, h);

	    for(idx = 0; idx < count; idx++) {
1728 1729 1730 1731 1732 1733 1734 1735 1736 1737
	        if(extents.left > cur.x - formatEntry->gis[wstr[idx]].x)
		    extents.left = cur.x - formatEntry->gis[wstr[idx]].x;
		if(extents.top > cur.y - formatEntry->gis[wstr[idx]].y)
		    extents.top = cur.y - formatEntry->gis[wstr[idx]].y;
		if(extents.right < cur.x - formatEntry->gis[wstr[idx]].x + formatEntry->gis[wstr[idx]].width)
		    extents.right = cur.x - formatEntry->gis[wstr[idx]].x + formatEntry->gis[wstr[idx]].width;
		if(extents.bottom < cur.y - formatEntry->gis[wstr[idx]].y + formatEntry->gis[wstr[idx]].height)
		    extents.bottom = cur.y - formatEntry->gis[wstr[idx]].y + formatEntry->gis[wstr[idx]].height;
		if(lpDx) {
		    offset += lpDx[idx];
1738 1739 1740
		    cur.x = offset * cosEsc;
		    cur.y = offset * -sinEsc;
		} else {
1741 1742
		    cur.x += formatEntry->gis[wstr[idx]].xOff;
		    cur.y += formatEntry->gis[wstr[idx]].yOff;
1743 1744
		}
	    }
1745
	    TRACE("glyph extents %d,%d - %d,%d drawable x,y %d,%d\n", extents.left, extents.top,
1746
		  extents.right, extents.bottom, physDev->dc_rect.left + x, physDev->dc_rect.top + y);
1747

1748 1749
	    if(physDev->dc_rect.left + x + extents.left >= 0) {
	        image_x = physDev->dc_rect.left + x + extents.left;
1750 1751 1752
		image_off_x = 0;
	    } else {
	        image_x = 0;
1753
		image_off_x = physDev->dc_rect.left + x + extents.left;
1754
	    }
1755 1756
	    if(physDev->dc_rect.top + y + extents.top >= 0) {
	        image_y = physDev->dc_rect.top + y + extents.top;
1757 1758 1759
		image_off_y = 0;
	    } else {
	        image_y = 0;
1760
		image_off_y = physDev->dc_rect.top + y + extents.top;
1761
	    }
1762 1763
	    if(physDev->dc_rect.left + x + extents.right < w)
	        image_w = physDev->dc_rect.left + x + extents.right - image_x;
1764 1765
	    else
	        image_w = w - image_x;
1766 1767
	    if(physDev->dc_rect.top + y + extents.bottom < h)
	        image_h = physDev->dc_rect.top + y + extents.bottom - image_y;
1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781
	    else
	        image_h = h - image_y;

	    if(image_w <= 0 || image_h <= 0) goto no_image;

	    X11DRV_expect_error(gdi_display, XRenderErrorHandler, NULL);
	    image = XGetImage(gdi_display, physDev->drawable,
			      image_x, image_y, image_w, image_h,
			      AllPlanes, ZPixmap);
	    X11DRV_check_error();

	    TRACE("XGetImage(%p, %x, %d, %d, %d, %d, %lx, %x) depth = %d rets %p\n",
		  gdi_display, (int)physDev->drawable, image_x, image_y,
		  image_w, image_h, AllPlanes, ZPixmap,
1782
		  physDev->depth, image);
1783
	    if(!image) {
1784
	        Pixmap xpm = XCreatePixmap(gdi_display, root_window, image_w, image_h,
1785
					   physDev->depth);
1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809
		GC gc;
		XGCValues gcv;

		gcv.graphics_exposures = False;
		gc = XCreateGC(gdi_display, xpm, GCGraphicsExposures, &gcv);
		XCopyArea(gdi_display, physDev->drawable, xpm, gc, image_x, image_y,
			  image_w, image_h, 0, 0);
		XFreeGC(gdi_display, gc);
		X11DRV_expect_error(gdi_display, XRenderErrorHandler, NULL);
		image = XGetImage(gdi_display, xpm, 0, 0, image_w, image_h, AllPlanes,
				  ZPixmap);
		X11DRV_check_error();
		XFreePixmap(gdi_display, xpm);
	    }
	    if(!image) goto no_image;

	    image->red_mask = visual->red_mask;
	    image->green_mask = visual->green_mask;
	    image->blue_mask = visual->blue_mask;

	    offset = xoff = yoff = 0;
	    for(idx = 0; idx < count; idx++) {
	        SmoothGlyphGray(image, xoff + image_off_x - extents.left,
				yoff + image_off_y - extents.top,
1810 1811
				formatEntry->bitmaps[wstr[idx]],
				&formatEntry->gis[wstr[idx]],
1812
				physDev->textPixel);
1813 1814
		if(lpDx) {
		    offset += lpDx[idx];
1815 1816 1817
		    xoff = offset * cosEsc;
		    yoff = offset * -sinEsc;
		} else {
1818 1819
		    xoff += formatEntry->gis[wstr[idx]].xOff;
		    yoff += formatEntry->gis[wstr[idx]].yOff;
1820 1821 1822 1823 1824
		}
	    }
	    XPutImage(gdi_display, physDev->drawable, physDev->gc, image, 0, 0,
		      image_x, image_y, image_w, image_h);
	    XDestroyImage(image);
1825
	}
1826
    no_image:
1827
	wine_tsx11_unlock();
1828
    }
1829 1830
    LeaveCriticalSection(&xrender_cs);

1831
    if (flags & ETO_CLIPPED)
1832 1833 1834 1835 1836
    {
        /* restore the device region */
        X11DRV_SetDeviceClipping( physDev, saved_region, 0 );
        DeleteObject( saved_region );
    }
1837

1838 1839
    retv = TRUE;

1840
done_unlock:
1841
    X11DRV_UnlockDIBSection( physDev, TRUE );
1842
    return retv;
1843 1844
}

1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879
/* Helper function for (stretched) blitting using xrender */
static void xrender_blit(Picture src_pict, Picture mask_pict, Picture dst_pict, int x_src, int y_src, float xscale, float yscale, int width, int height)
{
    /* Further down a transformation matrix is used for stretching and mirroring the source data.
     * xscale/yscale contain the scaling factors for the width and height. In case of mirroring
     * we also need a x- and y-offset because without the pixels will be in the wrong quadrant of the x-y plane.
     */
    int x_offset = (xscale<0) ? width : 0;
    int y_offset = (yscale<0) ? height : 0;

    /* When we need to scale we perform scaling and source_x / source_y translation using a transformation matrix.
     * This is needed because XRender is inaccurate in combination with scaled source coordinates passed to XRenderComposite.
     * In all other cases we do use XRenderComposite for translation as it is faster than using a transformation matrix. */
    if(xscale != 1.0 || yscale != 1.0)
    {
        /* When we are using a mask, 'src_pict' contains a 1x1 picture for tiling, the actual source data is in mask_pict */
        if(mask_pict)
            set_xrender_transformation(mask_pict, xscale, yscale, x_offset, y_offset);
        else
            set_xrender_transformation(src_pict, xscale, yscale, x_src + x_offset, y_src + y_offset);

        pXRenderComposite(gdi_display, PictOpSrc, src_pict, mask_pict, dst_pict, 0, 0, 0, 0, 0, 0, width, height);
    }
    else
    {
        /* When we are using a mask, 'src_pict' contains a 1x1 picture for tiling, the actual source data is in mask_pict */
        if(mask_pict)
            set_xrender_transformation(mask_pict, 1, 1, 0, 0);
        else
            set_xrender_transformation(src_pict, 1, 1, 0, 0);

        pXRenderComposite(gdi_display, PictOpSrc, src_pict, mask_pict, dst_pict, x_src, y_src, 0, 0, 0, 0, width, height);
    }
}

1880 1881 1882
/******************************************************************************
 * AlphaBlend         (x11drv.@)
 */
1883 1884 1885
BOOL CDECL X11DRV_AlphaBlend(X11DRV_PDEVICE *devDst, INT xDst, INT yDst, INT widthDst, INT heightDst,
                             X11DRV_PDEVICE *devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc,
                             BLENDFUNCTION blendfn)
1886 1887 1888 1889
{
    XRenderPictureAttributes pa;
    Picture dst_pict, src_pict;
    Pixmap xpm;
1890
    DIBSECTION dib;
1891 1892 1893
    XImage *image;
    GC gc;
    XGCValues gcv;
1894
    DWORD *dstbits, *data;
1895
    int y, y2;
1896
    POINT pts[2];
1897
    BOOL top_down = FALSE;
1898
    const WineXRenderFormat *src_format;
1899
    int repeat_src;
1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923

    if(!X11DRV_XRender_Installed) {
        FIXME("Unable to AlphaBlend without Xrender\n");
        return FALSE;
    }
    pts[0].x = xDst;
    pts[0].y = yDst;
    pts[1].x = xDst + widthDst;
    pts[1].y = yDst + heightDst;
    LPtoDP(devDst->hdc, pts, 2);
    xDst      = pts[0].x;
    yDst      = pts[0].y;
    widthDst  = pts[1].x - pts[0].x;
    heightDst = pts[1].y - pts[0].y;

    pts[0].x = xSrc;
    pts[0].y = ySrc;
    pts[1].x = xSrc + widthSrc;
    pts[1].y = ySrc + heightSrc;
    LPtoDP(devSrc->hdc, pts, 2);
    xSrc      = pts[0].x;
    ySrc      = pts[0].y;
    widthSrc  = pts[1].x - pts[0].x;
    heightSrc = pts[1].y - pts[0].y;
1924
    if (!widthDst || !heightDst || !widthSrc || !heightSrc) return TRUE;
1925

1926
#ifndef HAVE_XRENDERSETPICTURETRANSFORM
1927
    if(widthDst != widthSrc || heightDst != heightSrc)
1928
#else
1929
    if(!pXRenderSetPictureTransform)
1930 1931 1932
#endif
    {
        FIXME("Unable to Stretch, XRenderSetPictureTransform is currently required\n");
1933 1934 1935
        return FALSE;
    }

1936
    if (!devSrc->bitmap || GetObjectW( devSrc->bitmap->hbitmap, sizeof(dib), &dib ) != sizeof(dib))
1937
    {
1938 1939 1940 1941 1942 1943
        static BOOL out = FALSE;
        if (!out)
        {
            FIXME("not a dibsection\n");
            out = TRUE;
        }
1944 1945 1946
        return FALSE;
    }

1947 1948 1949 1950
    /* If the source is a 1x1 bitmap, tiling is equivalent to stretching, but
        tiling is much faster. Therefore, we do no stretching in this case. */
    repeat_src = dib.dsBmih.biWidth == 1 && abs(dib.dsBmih.biHeight) == 1;

1951 1952 1953 1954 1955 1956 1957 1958
    if (xSrc < 0 || ySrc < 0 || widthSrc < 0 || heightSrc < 0 || xSrc + widthSrc > dib.dsBmih.biWidth
        || ySrc + heightSrc > abs(dib.dsBmih.biHeight))
    {
        WARN("Invalid src coords: (%d,%d), size %dx%d\n", xSrc, ySrc, widthSrc, heightSrc);
        SetLastError(ERROR_INVALID_PARAMETER);
        return FALSE;
    }

1959
    if(dib.dsBm.bmBitsPixel != 32) {
1960 1961 1962 1963
        FIXME("not a 32 bpp dibsection\n");
        return FALSE;
    }
    dstbits = data = HeapAlloc(GetProcessHeap(), 0, heightSrc * widthSrc * 4);
1964

1965
    if(dib.dsBmih.biHeight < 0) { /* top-down dib */
1966
        top_down = TRUE;
1967
        dstbits += widthSrc * (heightSrc - 1);
1968
        y2 = ySrc;
1969
        y = y2 + heightSrc - 1;
1970
    }
1971 1972 1973
    else
    {
        y = dib.dsBmih.biHeight - ySrc - 1;
1974
        y2 = y - heightSrc + 1;
1975
    }
1976 1977 1978

    if (blendfn.AlphaFormat & AC_SRC_ALPHA)
    {
1979 1980 1981 1982 1983 1984 1985 1986 1987 1988
        if (blendfn.SourceConstantAlpha == 0xff)
        {
            for (; y >= y2; y--)
            {
                memcpy(dstbits, (char *)dib.dsBm.bmBits + y * dib.dsBm.bmWidthBytes + xSrc * 4,
                       widthSrc * 4);
                dstbits += (top_down ? -1 : 1) * widthSrc;
            }
        }
        else
1989
        {
1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007
            /* SourceConstantAlpha combined with source alpha */
            for (; y >= y2; y--)
            {
                int x;
                DWORD *srcbits = (DWORD *)((char *)dib.dsBm.bmBits + y * dib.dsBm.bmWidthBytes) + xSrc;
                for (x = 0; x < widthSrc; x++)
                {
                    DWORD argb = *srcbits++;
                    BYTE *s = (BYTE *) &argb;
                    s[0] = (s[0] * blendfn.SourceConstantAlpha) / 255;
                    s[1] = (s[1] * blendfn.SourceConstantAlpha) / 255;
                    s[2] = (s[2] * blendfn.SourceConstantAlpha) / 255;
                    s[3] = (s[3] * blendfn.SourceConstantAlpha) / 255;
                    *dstbits++ = argb;
                }
                if (top_down)  /* we traversed the row forward so we should go back by two rows */
                    dstbits -= 2 * widthSrc;
            }
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027
        }
    }
    else
    {
        DWORD source_alpha = (DWORD)blendfn.SourceConstantAlpha << 24;
        int x;

        for(; y >= y2; y--)
        {
            DWORD *srcbits = (DWORD *)((char *)dib.dsBm.bmBits + y * dib.dsBm.bmWidthBytes) + xSrc;
            for (x = 0; x < widthSrc; x++)
            {
                DWORD argb = *srcbits++;
                argb = (argb & 0xffffff) | source_alpha;
                *dstbits++ = argb;
            }
            if (top_down)  /* we traversed the row forward so we should go back by two rows */
                dstbits -= 2 * widthSrc;
        }

2028 2029
    }

2030
    dst_pict = get_xrender_picture(devDst);
2031

2032
    wine_tsx11_lock();
2033
    src_format = get_xrender_format(WXR_FORMAT_A8R8G8B8);
2034
    TRACE("src_format %p\n", src_format);
2035 2036 2037
    if(!src_format)
    {
        WARN("Unable to find a picture format supporting alpha, make sure X is running at 24-bit\n");
2038 2039
        wine_tsx11_unlock();
        HeapFree(GetProcessHeap(), 0, data);
2040 2041
        return FALSE;
    }
2042

2043 2044 2045
    image = XCreateImage(gdi_display, visual, 32, ZPixmap, 0,
                         (char*) data, widthSrc, heightSrc, 32, widthSrc * 4);

2046 2047
    TRACE("src_drawable = %08lx\n", devSrc->drawable);
    xpm = XCreatePixmap(gdi_display,
2048
                        root_window,
2049 2050 2051 2052 2053 2054
                        widthSrc, heightSrc, 32);
    gcv.graphics_exposures = False;
    gc = XCreateGC(gdi_display, xpm, GCGraphicsExposures, &gcv);
    TRACE("xpm = %08lx\n", xpm);
    XPutImage(gdi_display, xpm, gc, image, 0, 0, 0, 0, widthSrc, heightSrc);

2055 2056
    pa.subwindow_mode = IncludeInferiors;
    pa.repeat = repeat_src ? RepeatNormal : RepeatNone;
2057
    src_pict = pXRenderCreatePicture(gdi_display,
2058
                                     xpm, src_format->pict_format,
2059
                                     CPSubwindowMode|CPRepeat, &pa);
2060 2061
    TRACE("src_pict %08lx\n", src_pict);

2062 2063 2064
    /* Make sure we ALWAYS set the transformation matrix even if we don't need to scale. The reason is
     * that later on we want to reuse pictures (it can bring a lot of extra performance) and each time
     * a different transformation matrix might have been used. */
2065 2066 2067 2068
    if (repeat_src)
        set_xrender_transformation(src_pict, 1.0, 1.0, 0, 0);
    else
        set_xrender_transformation(src_pict, widthSrc/(double)widthDst, heightSrc/(double)heightDst, 0, 0);
2069
    pXRenderComposite(gdi_display, PictOpOver, src_pict, 0, dst_pict,
2070
                      0, 0, 0, 0,
2071
                      xDst + devDst->dc_rect.left, yDst + devDst->dc_rect.top, widthDst, heightDst);
2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084


    pXRenderFreePicture(gdi_display, src_pict);
    XFreePixmap(gdi_display, xpm);
    XFreeGC(gdi_display, gc);
    image->data = NULL;
    XDestroyImage(image);

    wine_tsx11_unlock();
    HeapFree(GetProcessHeap(), 0, data);
    return TRUE;
}

2085 2086 2087 2088
void X11DRV_XRender_CopyBrush(X11DRV_PDEVICE *physDev, X_PHYSBITMAP *physBitmap, int width, int height)
{
    /* At depths >1, the depth of physBitmap and physDev might not be the same e.g. the physbitmap might be a 16-bit DIB while the physdev uses 24-bit */
    int depth = physBitmap->pixmap_depth == 1 ? 1 : physDev->depth;
2089 2090
    const WineXRenderFormat *src_format = get_xrender_format_from_color_shifts(physBitmap->pixmap_depth, &physBitmap->pixmap_color_shifts);
    const WineXRenderFormat *dst_format = get_xrender_format_from_color_shifts(physDev->depth, physDev->color_shifts);
2091 2092 2093 2094

    wine_tsx11_lock();
    physDev->brush.pixmap = XCreatePixmap(gdi_display, root_window, width, height, depth);

2095
    /* Use XCopyArea when the physBitmap and brush.pixmap have the same format. */
2096 2097
    if( (physBitmap->pixmap_depth == 1) || (!X11DRV_XRender_Installed && physDev->depth == physBitmap->pixmap_depth) ||
        (src_format->format == dst_format->format) )
2098 2099 2100 2101
    {
        XCopyArea( gdi_display, physBitmap->pixmap, physDev->brush.pixmap,
                   get_bitmap_gc(physBitmap->pixmap_depth), 0, 0, width, height, 0, 0 );
    }
2102
    else /* We need depth conversion */
2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118
    {
        Picture src_pict, dst_pict;
        XRenderPictureAttributes pa;
        pa.subwindow_mode = IncludeInferiors;
        pa.repeat = RepeatNone;

        src_pict = pXRenderCreatePicture(gdi_display, physBitmap->pixmap, src_format->pict_format, CPSubwindowMode|CPRepeat, &pa);
        dst_pict = pXRenderCreatePicture(gdi_display, physDev->brush.pixmap, dst_format->pict_format, CPSubwindowMode|CPRepeat, &pa);

        xrender_blit(src_pict, 0, dst_pict, 0, 0, 1.0, 1.0, width, height);
        pXRenderFreePicture(gdi_display, src_pict);
        pXRenderFreePicture(gdi_display, dst_pict);
    }
    wine_tsx11_unlock();
}

2119 2120 2121 2122 2123 2124 2125 2126 2127
BOOL X11DRV_XRender_GetSrcAreaStretch(X11DRV_PDEVICE *physDevSrc, X11DRV_PDEVICE *physDevDst,
                                      Pixmap pixmap, GC gc,
                                      INT widthSrc, INT heightSrc,
                                      INT widthDst, INT heightDst,
                                      RECT *visRectSrc, RECT *visRectDst )
{
    BOOL stretch = (widthSrc != widthDst) || (heightSrc != heightDst);
    int width = visRectDst->right - visRectDst->left;
    int height = visRectDst->bottom - visRectDst->top;
2128 2129
    int x_src = physDevSrc->dc_rect.left + visRectSrc->left;
    int y_src = physDevSrc->dc_rect.top + visRectSrc->top;
2130
    struct xrender_info *src_info = get_xrender_info(physDevSrc);
2131
    const WineXRenderFormat *dst_format = get_xrender_format_from_color_shifts(physDevDst->depth, physDevDst->color_shifts);
2132 2133 2134 2135 2136 2137 2138 2139 2140
    Picture src_pict=0, dst_pict=0, mask_pict=0;

    double xscale = widthSrc/(double)widthDst;
    double yscale = heightSrc/(double)heightDst;

    XRenderPictureAttributes pa;
    pa.subwindow_mode = IncludeInferiors;
    pa.repeat = RepeatNone;

2141 2142
    TRACE("src depth=%d widthSrc=%d heightSrc=%d xSrc=%d ySrc=%d\n", physDevSrc->depth, widthSrc, heightSrc, x_src, y_src);
    TRACE("dst depth=%d widthDst=%d heightDst=%d\n", physDevDst->depth, widthDst, heightDst);
2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157

    if(!X11DRV_XRender_Installed)
    {
        TRACE("Not using XRender since it is not available or disabled\n");
        return FALSE;
    }

    /* XRender can't handle palettes, so abort */
    if(X11DRV_PALETTE_XPixelToPalette)
        return FALSE;

    /* XRender is of no use in this case */
    if((physDevDst->depth == 1) && (physDevSrc->depth > 1))
        return FALSE;

2158 2159
    /* Just use traditional X copy when the formats match and we don't need stretching */
    if((src_info->format->format == dst_format->format) && !stretch)
2160 2161 2162
    {
        TRACE("Source and destination depth match and no stretching needed falling back to XCopyArea\n");
        wine_tsx11_lock();
2163
        XCopyArea( gdi_display, physDevSrc->drawable, pixmap, gc, x_src, y_src, width, height, 0, 0);
2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174
        wine_tsx11_unlock();
        return TRUE;
    }

    /* mono -> color */
    if(physDevSrc->depth == 1)
    {
        XRenderColor col;
        get_xrender_color(dst_format, physDevDst->textPixel, &col);

        /* We use the source drawable as a mask */
2175
        mask_pict = get_xrender_picture_source(physDevSrc);
2176 2177

        /* Use backgroundPixel as the foreground color */
2178
        EnterCriticalSection( &xrender_cs );
2179 2180 2181
        src_pict = get_tile_pict(dst_format, physDevDst->backgroundPixel);

        /* Create a destination picture and fill it with textPixel color as the background color */
2182
        wine_tsx11_lock();
2183 2184 2185
        dst_pict = pXRenderCreatePicture(gdi_display, pixmap, dst_format->pict_format, CPSubwindowMode|CPRepeat, &pa);
        pXRenderFillRectangle(gdi_display, PictOpSrc, dst_pict, &col, 0, 0, width, height);

2186
        xrender_blit(src_pict, mask_pict, dst_pict, x_src, y_src, xscale, yscale, width, height);
2187 2188 2189

        if(dst_pict) pXRenderFreePicture(gdi_display, dst_pict);
        wine_tsx11_unlock();
2190
        LeaveCriticalSection( &xrender_cs );
2191 2192 2193
    }
    else /* color -> color but with different depths */
    {
2194
        src_pict = get_xrender_picture_source(physDevSrc);
2195

2196
        wine_tsx11_lock();
2197 2198 2199 2200
        dst_pict = pXRenderCreatePicture(gdi_display,
                                          pixmap, dst_format->pict_format,
                                          CPSubwindowMode|CPRepeat, &pa);

2201
        xrender_blit(src_pict, 0, dst_pict, x_src, y_src, xscale, yscale, width, height);
2202 2203 2204 2205 2206 2207 2208

        if(dst_pict) pXRenderFreePicture(gdi_display, dst_pict);
        wine_tsx11_unlock();
    }
    return TRUE;
}

2209
#else /* SONAME_LIBXRENDER */
2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220

void X11DRV_XRender_Init(void)
{
    TRACE("XRender support not compiled in.\n");
    return;
}

void X11DRV_XRender_Finalize(void)
{
}

2221
BOOL X11DRV_XRender_SelectFont(X11DRV_PDEVICE *physDev, HFONT hfont)
2222 2223 2224 2225 2226
{
  assert(0);
  return FALSE;
}

2227
void X11DRV_XRender_DeleteDC(X11DRV_PDEVICE *physDev)
2228 2229 2230 2231 2232
{
  assert(0);
  return;
}

2233
void X11DRV_XRender_SetDeviceClipping(X11DRV_PDEVICE *physDev, const RGNDATA *data)
2234 2235 2236 2237 2238
{
    assert(0);
    return;
}

2239
BOOL X11DRV_XRender_ExtTextOut( X11DRV_PDEVICE *physDev, INT x, INT y, UINT flags,
2240
				const RECT *lprect, LPCWSTR wstr, UINT count,
2241
				const INT *lpDx )
2242 2243 2244 2245 2246
{
  assert(0);
  return FALSE;
}

2247
void X11DRV_XRender_UpdateDrawable(X11DRV_PDEVICE *physDev)
2248 2249 2250 2251 2252
{
  assert(0);
  return;
}

2253 2254 2255
/******************************************************************************
 * AlphaBlend         (x11drv.@)
 */
2256 2257
BOOL X11DRV_AlphaBlend(X11DRV_PDEVICE *devDst, INT xDst, INT yDst, INT widthDst, INT heightDst,
                       X11DRV_PDEVICE *devSrc, INT xSrc, INT ySrc, INT widthSrc, INT heightSrc,
2258
                       BLENDFUNCTION blendfn)
2259 2260 2261 2262 2263
{
  FIXME("not supported - XRENDER headers were missing at compile time\n");
  return FALSE;
}

2264 2265 2266 2267 2268 2269 2270 2271 2272 2273
void X11DRV_XRender_CopyBrush(X11DRV_PDEVICE *physDev, X_PHYSBITMAP *physBitmap, int width, int height)
{
    wine_tsx11_lock();
    physDev->brush.pixmap = XCreatePixmap(gdi_display, root_window, width, height, physBitmap->pixmap_depth);

    XCopyArea( gdi_display, physBitmap->pixmap, physDev->brush.pixmap,
               get_bitmap_gc(physBitmap->pixmap_depth), 0, 0, width, height, 0, 0 );
    wine_tsx11_unlock();
}

2274 2275 2276 2277 2278
BOOL X11DRV_XRender_SetPhysBitmapDepth(X_PHYSBITMAP *physBitmap, const DIBSECTION *dib)
{
    return FALSE;
}

2279 2280 2281 2282
BOOL X11DRV_XRender_GetSrcAreaStretch(X11DRV_PDEVICE *physDevSrc, X11DRV_PDEVICE *physDevDst,
                                      Pixmap pixmap, GC gc,
                                      INT widthSrc, INT heightSrc,
                                      INT widthDst, INT heightDst,
2283
                                      RECT *visRectSrc, RECT *visRectDst )
2284 2285 2286
{
    return FALSE;
}
2287
#endif /* SONAME_LIBXRENDER */