2 * X11 graphics driver graphics functions
4 * Copyright 1993,1994 Alexandre Julliard
5 * Copyright 1998 Huw Davies
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 * FIXME: only some of these functions obey the GM_ADVANCED
46 #include "wine/debug.h"
47 #include "wine/unicode.h"
49 WINE_DEFAULT_DEBUG_CHANNEL(graphics);
51 #define ABS(x) ((x)<0?(-(x)):(x))
53 /* ROP code to GC function conversion */
54 const int X11DRV_XROPfunction[16] =
56 GXclear, /* R2_BLACK */
57 GXnor, /* R2_NOTMERGEPEN */
58 GXandInverted, /* R2_MASKNOTPEN */
59 GXcopyInverted, /* R2_NOTCOPYPEN */
60 GXandReverse, /* R2_MASKPENNOT */
61 GXinvert, /* R2_NOT */
62 GXxor, /* R2_XORPEN */
63 GXnand, /* R2_NOTMASKPEN */
64 GXand, /* R2_MASKPEN */
65 GXequiv, /* R2_NOTXORPEN */
67 GXorInverted, /* R2_MERGENOTPEN */
68 GXcopy, /* R2_COPYPEN */
69 GXorReverse, /* R2_MERGEPENNOT */
70 GXor, /* R2_MERGEPEN */
75 /***********************************************************************
76 * X11DRV_GetRegionData
78 * Calls GetRegionData on the given region and converts the rectangle
79 * array to XRectangle format. The returned buffer must be freed by
80 * caller using HeapFree(GetProcessHeap(),...).
81 * If hdc_lptodp is not 0, the rectangles are converted through LPtoDP.
83 RGNDATA *X11DRV_GetRegionData( HRGN hrgn, HDC hdc_lptodp )
91 if (!(size = GetRegionData( hrgn, 0, NULL ))) return NULL;
92 if (sizeof(XRectangle) > sizeof(RECT))
94 /* add extra size for XRectangle array */
95 int count = (size - sizeof(RGNDATAHEADER)) / sizeof(RECT);
96 size += count * (sizeof(XRectangle) - sizeof(RECT));
98 if (!(data = HeapAlloc( GetProcessHeap(), 0, size ))) return NULL;
99 if (!GetRegionData( hrgn, size, data ))
101 HeapFree( GetProcessHeap(), 0, data );
105 rect = (RECT *)data->Buffer;
106 xrect = (XRectangle *)data->Buffer;
107 if (hdc_lptodp) /* map to device coordinates */
109 LPtoDP( hdc_lptodp, (POINT *)rect, data->rdh.nCount * 2 );
110 for (i = 0; i < data->rdh.nCount; i++)
112 if (rect[i].right < rect[i].left)
114 INT tmp = rect[i].right;
115 rect[i].right = rect[i].left;
118 if (rect[i].bottom < rect[i].top)
120 INT tmp = rect[i].bottom;
121 rect[i].bottom = rect[i].top;
127 if (sizeof(XRectangle) > sizeof(RECT))
130 /* need to start from the end */
131 for (j = data->rdh.nCount-1; j >= 0; j--)
134 xrect[j].x = tmp.left;
135 xrect[j].y = tmp.top;
136 xrect[j].width = tmp.right - tmp.left;
137 xrect[j].height = tmp.bottom - tmp.top;
142 for (i = 0; i < data->rdh.nCount; i++)
145 xrect[i].x = tmp.left;
146 xrect[i].y = tmp.top;
147 xrect[i].width = tmp.right - tmp.left;
148 xrect[i].height = tmp.bottom - tmp.top;
155 /***********************************************************************
156 * X11DRV_SetDeviceClipping
158 void CDECL X11DRV_SetDeviceClipping( X11DRV_PDEVICE *physDev, HRGN vis_rgn, HRGN clip_rgn )
162 CombineRgn( physDev->region, vis_rgn, clip_rgn, clip_rgn ? RGN_AND : RGN_COPY );
163 if (!(data = X11DRV_GetRegionData( physDev->region, 0 ))) return;
166 XSetClipRectangles( gdi_display, physDev->gc, physDev->dc_rect.left, physDev->dc_rect.top,
167 (XRectangle *)data->Buffer, data->rdh.nCount, YXBanded );
170 if (physDev->xrender) X11DRV_XRender_SetDeviceClipping(physDev, data);
172 HeapFree( GetProcessHeap(), 0, data );
176 /***********************************************************************
177 * X11DRV_SetupGCForPatBlt
179 * Setup the GC for a PatBlt operation using current brush.
180 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
181 * Return FALSE if brush is BS_NULL, TRUE otherwise.
183 BOOL X11DRV_SetupGCForPatBlt( X11DRV_PDEVICE *physDev, GC gc, BOOL fMapColors )
190 if (physDev->brush.style == BS_NULL) return FALSE;
191 if (physDev->brush.pixel == -1)
193 /* Special case used for monochrome pattern brushes.
194 * We need to swap foreground and background because
195 * Windows does it the wrong way...
197 val.foreground = physDev->backgroundPixel;
198 val.background = physDev->textPixel;
202 val.foreground = physDev->brush.pixel;
203 val.background = physDev->backgroundPixel;
205 if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
207 val.foreground = X11DRV_PALETTE_XPixelToPalette[val.foreground];
208 val.background = X11DRV_PALETTE_XPixelToPalette[val.background];
211 val.function = X11DRV_XROPfunction[GetROP2(physDev->hdc)-1];
213 ** Let's replace GXinvert by GXxor with (black xor white)
214 ** This solves the selection color and leak problems in excel
215 ** FIXME : Let's do that only if we work with X-pixels, not with Win-pixels
217 if (val.function == GXinvert)
219 val.foreground = (WhitePixel( gdi_display, DefaultScreen(gdi_display) ) ^
220 BlackPixel( gdi_display, DefaultScreen(gdi_display) ));
221 val.function = GXxor;
223 val.fill_style = physDev->brush.fillStyle;
224 switch(val.fill_style)
227 case FillOpaqueStippled:
228 if (GetBkMode(physDev->hdc)==OPAQUE) val.fill_style = FillOpaqueStippled;
229 val.stipple = physDev->brush.pixmap;
234 if (fMapColors && X11DRV_PALETTE_XPixelToPalette)
239 pixmap = XCreatePixmap( gdi_display, root_window, 8, 8, physDev->depth );
240 image = XGetImage( gdi_display, physDev->brush.pixmap, 0, 0, 8, 8,
241 AllPlanes, ZPixmap );
242 for (y = 0; y < 8; y++)
243 for (x = 0; x < 8; x++)
244 XPutPixel( image, x, y,
245 X11DRV_PALETTE_XPixelToPalette[XGetPixel( image, x, y)] );
246 XPutImage( gdi_display, pixmap, gc, image, 0, 0, 0, 0, 8, 8 );
247 XDestroyImage( image );
251 else val.tile = physDev->brush.pixmap;
259 GetBrushOrgEx( physDev->hdc, &pt );
260 val.ts_x_origin = physDev->dc_rect.left + pt.x;
261 val.ts_y_origin = physDev->dc_rect.top + pt.y;
262 val.fill_rule = (GetPolyFillMode(physDev->hdc) == WINDING) ? WindingRule : EvenOddRule;
264 XChangeGC( gdi_display, gc,
265 GCFunction | GCForeground | GCBackground | GCFillStyle |
266 GCFillRule | GCTileStipXOrigin | GCTileStipYOrigin | mask,
268 if (pixmap) XFreePixmap( gdi_display, pixmap );
274 /***********************************************************************
275 * X11DRV_SetupGCForBrush
277 * Setup physDev->gc for drawing operations using current brush.
278 * Return FALSE if brush is BS_NULL, TRUE otherwise.
280 BOOL X11DRV_SetupGCForBrush( X11DRV_PDEVICE *physDev )
282 return X11DRV_SetupGCForPatBlt( physDev, physDev->gc, FALSE );
286 /***********************************************************************
287 * X11DRV_SetupGCForPen
289 * Setup physDev->gc for drawing operations using current pen.
290 * Return FALSE if pen is PS_NULL, TRUE otherwise.
292 static BOOL X11DRV_SetupGCForPen( X11DRV_PDEVICE *physDev )
295 UINT rop2 = GetROP2(physDev->hdc);
297 if (physDev->pen.style == PS_NULL) return FALSE;
302 val.foreground = BlackPixel( gdi_display, DefaultScreen(gdi_display) );
303 val.function = GXcopy;
306 val.foreground = WhitePixel( gdi_display, DefaultScreen(gdi_display) );
307 val.function = GXcopy;
310 val.foreground = physDev->pen.pixel;
311 /* It is very unlikely someone wants to XOR with 0 */
312 /* This fixes the rubber-drawings in paintbrush */
313 if (val.foreground == 0)
314 val.foreground = (WhitePixel( gdi_display, DefaultScreen(gdi_display) ) ^
315 BlackPixel( gdi_display, DefaultScreen(gdi_display) ));
316 val.function = GXxor;
319 val.foreground = physDev->pen.pixel;
320 val.function = X11DRV_XROPfunction[rop2-1];
322 val.background = physDev->backgroundPixel;
323 val.fill_style = FillSolid;
324 val.line_width = physDev->pen.width;
325 if (val.line_width <= 1) {
326 val.cap_style = CapNotLast;
328 switch (physDev->pen.endcap)
330 case PS_ENDCAP_SQUARE:
331 val.cap_style = CapProjecting;
334 val.cap_style = CapButt;
336 case PS_ENDCAP_ROUND:
338 val.cap_style = CapRound;
341 switch (physDev->pen.linejoin)
344 val.join_style = JoinBevel;
347 val.join_style = JoinMiter;
351 val.join_style = JoinRound;
354 if (physDev->pen.dash_len)
355 val.line_style = ((GetBkMode(physDev->hdc) == OPAQUE) && (!physDev->pen.ext))
356 ? LineDoubleDash : LineOnOffDash;
358 val.line_style = LineSolid;
361 if (physDev->pen.dash_len)
362 XSetDashes( gdi_display, physDev->gc, 0, physDev->pen.dashes, physDev->pen.dash_len );
363 XChangeGC( gdi_display, physDev->gc,
364 GCFunction | GCForeground | GCBackground | GCLineWidth |
365 GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle, &val );
371 /***********************************************************************
372 * X11DRV_SetupGCForText
374 * Setup physDev->gc for text drawing operations.
375 * Return FALSE if the font is null, TRUE otherwise.
377 BOOL X11DRV_SetupGCForText( X11DRV_PDEVICE *physDev )
379 XFontStruct* xfs = XFONT_GetFontStruct( physDev->font );
385 val.function = GXcopy; /* Text is always GXcopy */
386 val.foreground = physDev->textPixel;
387 val.background = physDev->backgroundPixel;
388 val.fill_style = FillSolid;
392 XChangeGC( gdi_display, physDev->gc,
393 GCFunction | GCForeground | GCBackground | GCFillStyle |
398 WARN("Physical font failure\n" );
402 /***********************************************************************
405 * Performs a world-to-viewport transformation on the specified width.
407 INT X11DRV_XWStoDS( X11DRV_PDEVICE *physDev, INT width )
415 LPtoDP( physDev->hdc, pt, 2 );
416 return pt[1].x - pt[0].x;
419 /***********************************************************************
422 * Performs a world-to-viewport transformation on the specified height.
424 INT X11DRV_YWStoDS( X11DRV_PDEVICE *physDev, INT height )
432 LPtoDP( physDev->hdc, pt, 2 );
433 return pt[1].y - pt[0].y;
436 /***********************************************************************
440 X11DRV_LineTo( X11DRV_PDEVICE *physDev, INT x, INT y )
444 if (X11DRV_SetupGCForPen( physDev )) {
445 /* Update the pixmap from the DIB section */
446 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
448 GetCurrentPositionEx( physDev->hdc, &pt[0] );
451 LPtoDP( physDev->hdc, pt, 2 );
454 XDrawLine(gdi_display, physDev->drawable, physDev->gc,
455 physDev->dc_rect.left + pt[0].x, physDev->dc_rect.top + pt[0].y,
456 physDev->dc_rect.left + pt[1].x, physDev->dc_rect.top + pt[1].y );
459 /* Update the DIBSection from the pixmap */
460 X11DRV_UnlockDIBSection(physDev, TRUE);
467 /***********************************************************************
470 * Helper functions for Arc(), Chord() and Pie().
471 * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
475 X11DRV_DrawArc( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
476 INT bottom, INT xstart, INT ystart,
477 INT xend, INT yend, INT lines )
479 INT xcenter, ycenter, istart_angle, idiff_angle;
481 double start_angle, end_angle;
487 SetRect(&rc, left, top, right, bottom);
492 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
493 LPtoDP(physDev->hdc, &start, 1);
494 LPtoDP(physDev->hdc, &end, 1);
496 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
497 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
498 if ((rc.left == rc.right) || (rc.top == rc.bottom)
499 ||(lines && ((rc.right-rc.left==1)||(rc.bottom-rc.top==1)))) return TRUE;
501 if (GetArcDirection( physDev->hdc ) == AD_CLOCKWISE)
502 { POINT tmp = start; start = end; end = tmp; }
504 oldwidth = width = physDev->pen.width;
505 if (!width) width = 1;
506 if(physDev->pen.style == PS_NULL) width = 0;
508 if ((physDev->pen.style == PS_INSIDEFRAME))
510 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
511 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
512 rc.left += width / 2;
513 rc.right -= (width - 1) / 2;
515 rc.bottom -= (width - 1) / 2;
517 if(width == 0) width = 1; /* more accurate */
518 physDev->pen.width = width;
520 xcenter = (rc.right + rc.left) / 2;
521 ycenter = (rc.bottom + rc.top) / 2;
522 start_angle = atan2( (double)(ycenter-start.y)*(rc.right-rc.left),
523 (double)(start.x-xcenter)*(rc.bottom-rc.top) );
524 end_angle = atan2( (double)(ycenter-end.y)*(rc.right-rc.left),
525 (double)(end.x-xcenter)*(rc.bottom-rc.top) );
526 if ((start.x==end.x)&&(start.y==end.y))
527 { /* A lazy program delivers xstart=xend=ystart=yend=0) */
531 else /* notorious cases */
532 if ((start_angle == PI)&&( end_angle <0))
535 if ((end_angle == PI)&&( start_angle <0))
537 istart_angle = (INT)(start_angle * 180 * 64 / PI + 0.5);
538 idiff_angle = (INT)((end_angle - start_angle) * 180 * 64 / PI + 0.5);
539 if (idiff_angle <= 0) idiff_angle += 360 * 64;
541 /* Update the pixmap from the DIB section */
542 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
544 /* Fill arc with brush if Chord() or Pie() */
546 if ((lines > 0) && X11DRV_SetupGCForBrush( physDev )) {
548 XSetArcMode( gdi_display, physDev->gc, (lines==1) ? ArcChord : ArcPieSlice);
549 XFillArc( gdi_display, physDev->drawable, physDev->gc,
550 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
551 rc.right-rc.left-1, rc.bottom-rc.top-1, istart_angle, idiff_angle );
556 /* Draw arc and lines */
558 if (X11DRV_SetupGCForPen( physDev ))
561 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
562 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
563 rc.right-rc.left-1, rc.bottom-rc.top-1, istart_angle, idiff_angle );
565 /* use the truncated values */
566 start_angle=(double)istart_angle*PI/64./180.;
567 end_angle=(double)(istart_angle+idiff_angle)*PI/64./180.;
568 /* calculate the endpoints and round correctly */
569 points[0].x = (int) floor(physDev->dc_rect.left + (rc.right+rc.left)/2.0 +
570 cos(start_angle) * (rc.right-rc.left-width*2+2) / 2. + 0.5);
571 points[0].y = (int) floor(physDev->dc_rect.top + (rc.top+rc.bottom)/2.0 -
572 sin(start_angle) * (rc.bottom-rc.top-width*2+2) / 2. + 0.5);
573 points[1].x = (int) floor(physDev->dc_rect.left + (rc.right+rc.left)/2.0 +
574 cos(end_angle) * (rc.right-rc.left-width*2+2) / 2. + 0.5);
575 points[1].y = (int) floor(physDev->dc_rect.top + (rc.top+rc.bottom)/2.0 -
576 sin(end_angle) * (rc.bottom-rc.top-width*2+2) / 2. + 0.5);
578 /* OK, this stuff is optimized for Xfree86
579 * which is probably the server most used by
580 * wine users. Other X servers will not
581 * display correctly. (eXceed for instance)
582 * so if you feel you must make changes, make sure that
583 * you either use Xfree86 or separate your changes
584 * from these (compile switch or whatever)
588 points[3] = points[1];
589 points[1].x = physDev->dc_rect.left + xcenter;
590 points[1].y = physDev->dc_rect.top + ycenter;
591 points[2] = points[1];
592 dx1=points[1].x-points[0].x;
593 dy1=points[1].y-points[0].y;
594 if(((rc.top-rc.bottom) | -2) == -2)
595 if(dy1>0) points[1].y--;
597 if (((-dx1)*64)<=ABS(dy1)*37) points[0].x--;
598 if(((-dx1*9))<(dy1*16)) points[0].y--;
599 if( dy1<0 && ((dx1*9)) < (dy1*16)) points[0].y--;
601 if(dy1 < 0) points[0].y--;
602 if(((rc.right-rc.left) | -2) == -2) points[1].x--;
604 dx1=points[3].x-points[2].x;
605 dy1=points[3].y-points[2].y;
606 if(((rc.top-rc.bottom) | -2 ) == -2)
607 if(dy1 < 0) points[2].y--;
609 if( dy1>0) points[3].y--;
610 if(((rc.right-rc.left) | -2) == -2 ) points[2].x--;
613 if( dx1 * 64 < dy1 * -37 ) points[3].x--;
617 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
618 points, lines+1, CoordModeOrigin );
624 /* Update the DIBSection of the pixmap */
625 X11DRV_UnlockDIBSection(physDev, update);
627 physDev->pen.width = oldwidth;
632 /***********************************************************************
636 X11DRV_Arc( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
637 INT xstart, INT ystart, INT xend, INT yend )
639 return X11DRV_DrawArc( physDev, left, top, right, bottom,
640 xstart, ystart, xend, yend, 0 );
644 /***********************************************************************
648 X11DRV_Pie( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
649 INT xstart, INT ystart, INT xend, INT yend )
651 return X11DRV_DrawArc( physDev, left, top, right, bottom,
652 xstart, ystart, xend, yend, 2 );
655 /***********************************************************************
659 X11DRV_Chord( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom,
660 INT xstart, INT ystart, INT xend, INT yend )
662 return X11DRV_DrawArc( physDev, left, top, right, bottom,
663 xstart, ystart, xend, yend, 1 );
667 /***********************************************************************
671 X11DRV_Ellipse( X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom )
677 SetRect(&rc, left, top, right, bottom);
678 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
680 if ((rc.left == rc.right) || (rc.top == rc.bottom)) return TRUE;
682 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
683 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
685 oldwidth = width = physDev->pen.width;
686 if (!width) width = 1;
687 if(physDev->pen.style == PS_NULL) width = 0;
689 if ((physDev->pen.style == PS_INSIDEFRAME))
691 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
692 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
693 rc.left += width / 2;
694 rc.right -= (width - 1) / 2;
696 rc.bottom -= (width - 1) / 2;
698 if(width == 0) width = 1; /* more accurate */
699 physDev->pen.width = width;
701 /* Update the pixmap from the DIB section */
702 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
704 if (X11DRV_SetupGCForBrush( physDev ))
707 XFillArc( gdi_display, physDev->drawable, physDev->gc,
708 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
709 rc.right-rc.left-1, rc.bottom-rc.top-1, 0, 360*64 );
713 if (X11DRV_SetupGCForPen( physDev ))
716 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
717 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
718 rc.right-rc.left-1, rc.bottom-rc.top-1, 0, 360*64 );
723 /* Update the DIBSection from the pixmap */
724 X11DRV_UnlockDIBSection(physDev, update);
726 physDev->pen.width = oldwidth;
731 /***********************************************************************
735 X11DRV_Rectangle(X11DRV_PDEVICE *physDev, INT left, INT top, INT right, INT bottom)
737 INT width, oldwidth, oldjoinstyle;
741 TRACE("(%d %d %d %d)\n", left, top, right, bottom);
743 SetRect(&rc, left, top, right, bottom);
744 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
746 if ((rc.left == rc.right) || (rc.top == rc.bottom)) return TRUE;
748 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
749 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
751 oldwidth = width = physDev->pen.width;
752 if (!width) width = 1;
753 if(physDev->pen.style == PS_NULL) width = 0;
755 if ((physDev->pen.style == PS_INSIDEFRAME))
757 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
758 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
759 rc.left += width / 2;
760 rc.right -= (width - 1) / 2;
762 rc.bottom -= (width - 1) / 2;
764 if(width == 1) width = 0;
765 physDev->pen.width = width;
766 oldjoinstyle = physDev->pen.linejoin;
767 if(physDev->pen.type != PS_GEOMETRIC)
768 physDev->pen.linejoin = PS_JOIN_MITER;
770 /* Update the pixmap from the DIB section */
771 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
773 if ((rc.right > rc.left + width) && (rc.bottom > rc.top + width))
775 if (X11DRV_SetupGCForBrush( physDev ))
778 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
779 physDev->dc_rect.left + rc.left + (width + 1) / 2,
780 physDev->dc_rect.top + rc.top + (width + 1) / 2,
781 rc.right-rc.left-width-1, rc.bottom-rc.top-width-1);
786 if (X11DRV_SetupGCForPen( physDev ))
789 XDrawRectangle( gdi_display, physDev->drawable, physDev->gc,
790 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
791 rc.right-rc.left-1, rc.bottom-rc.top-1 );
796 /* Update the DIBSection from the pixmap */
797 X11DRV_UnlockDIBSection(physDev, update);
799 physDev->pen.width = oldwidth;
800 physDev->pen.linejoin = oldjoinstyle;
804 /***********************************************************************
808 X11DRV_RoundRect( X11DRV_PDEVICE *physDev, INT left, INT top, INT right,
809 INT bottom, INT ell_width, INT ell_height )
811 INT width, oldwidth, oldendcap;
816 TRACE("(%d %d %d %d %d %d\n",
817 left, top, right, bottom, ell_width, ell_height);
819 SetRect(&rc, left, top, right, bottom);
820 LPtoDP(physDev->hdc, (POINT*)&rc, 2);
822 if ((rc.left == rc.right) || (rc.top == rc.bottom))
825 /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
826 called with width/height < 0 */
827 pts[0].x = pts[0].y = 0;
828 pts[1].x = ell_width;
829 pts[1].y = ell_height;
830 LPtoDP(physDev->hdc, pts, 2);
831 ell_width = max(abs( pts[1].x - pts[0].x ), 1);
832 ell_height = max(abs( pts[1].y - pts[0].y ), 1);
834 /* Fix the coordinates */
836 if (rc.right < rc.left) { INT tmp = rc.right; rc.right = rc.left; rc.left = tmp; }
837 if (rc.bottom < rc.top) { INT tmp = rc.bottom; rc.bottom = rc.top; rc.top = tmp; }
839 oldwidth = width = physDev->pen.width;
840 oldendcap = physDev->pen.endcap;
841 if (!width) width = 1;
842 if(physDev->pen.style == PS_NULL) width = 0;
844 if ((physDev->pen.style == PS_INSIDEFRAME))
846 if (2*width > (rc.right-rc.left)) width=(rc.right-rc.left + 1)/2;
847 if (2*width > (rc.bottom-rc.top)) width=(rc.bottom-rc.top + 1)/2;
848 rc.left += width / 2;
849 rc.right -= (width - 1) / 2;
851 rc.bottom -= (width - 1) / 2;
853 if(width == 0) width = 1;
854 physDev->pen.width = width;
855 physDev->pen.endcap = PS_ENDCAP_SQUARE;
857 /* Update the pixmap from the DIB section */
858 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
860 if (X11DRV_SetupGCForBrush( physDev ))
863 if (ell_width > (rc.right-rc.left) )
864 if (ell_height > (rc.bottom-rc.top) )
865 XFillArc( gdi_display, physDev->drawable, physDev->gc,
866 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
867 rc.right - rc.left - 1, rc.bottom - rc.top - 1,
870 XFillArc( gdi_display, physDev->drawable, physDev->gc,
871 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
872 rc.right - rc.left - 1, ell_height, 0, 180 * 64 );
873 XFillArc( gdi_display, physDev->drawable, physDev->gc,
874 physDev->dc_rect.left + rc.left,
875 physDev->dc_rect.top + rc.bottom - ell_height - 1,
876 rc.right - rc.left - 1, ell_height, 180 * 64,
879 else if (ell_height > (rc.bottom-rc.top) ){
880 XFillArc( gdi_display, physDev->drawable, physDev->gc,
881 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
882 ell_width, rc.bottom - rc.top - 1, 90 * 64, 180 * 64 );
883 XFillArc( gdi_display, physDev->drawable, physDev->gc,
884 physDev->dc_rect.left + rc.right - ell_width - 1, physDev->dc_rect.top + rc.top,
885 ell_width, rc.bottom - rc.top - 1, 270 * 64, 180 * 64 );
887 XFillArc( gdi_display, physDev->drawable, physDev->gc,
888 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
889 ell_width, ell_height, 90 * 64, 90 * 64 );
890 XFillArc( gdi_display, physDev->drawable, physDev->gc,
891 physDev->dc_rect.left + rc.left,
892 physDev->dc_rect.top + rc.bottom - ell_height - 1,
893 ell_width, ell_height, 180 * 64, 90 * 64 );
894 XFillArc( gdi_display, physDev->drawable, physDev->gc,
895 physDev->dc_rect.left + rc.right - ell_width - 1,
896 physDev->dc_rect.top + rc.bottom - ell_height - 1,
897 ell_width, ell_height, 270 * 64, 90 * 64 );
898 XFillArc( gdi_display, physDev->drawable, physDev->gc,
899 physDev->dc_rect.left + rc.right - ell_width - 1,
900 physDev->dc_rect.top + rc.top,
901 ell_width, ell_height, 0, 90 * 64 );
903 if (ell_width < rc.right - rc.left)
905 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
906 physDev->dc_rect.left + rc.left + (ell_width + 1) / 2,
907 physDev->dc_rect.top + rc.top + 1,
908 rc.right - rc.left - ell_width - 1,
909 (ell_height + 1) / 2 - 1);
910 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
911 physDev->dc_rect.left + rc.left + (ell_width + 1) / 2,
912 physDev->dc_rect.top + rc.bottom - (ell_height) / 2 - 1,
913 rc.right - rc.left - ell_width - 1,
916 if (ell_height < rc.bottom - rc.top)
918 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
919 physDev->dc_rect.left + rc.left + 1,
920 physDev->dc_rect.top + rc.top + (ell_height + 1) / 2,
921 rc.right - rc.left - 2,
922 rc.bottom - rc.top - ell_height - 1);
927 /* FIXME: this could be done with on X call
928 * more efficient and probably more correct
929 * on any X server: XDrawArcs will draw
930 * straight horizontal and vertical lines
931 * if width or height are zero.
933 * BTW this stuff is optimized for an Xfree86 server
934 * read the comments inside the X11DRV_DrawArc function
936 if (X11DRV_SetupGCForPen( physDev ))
939 if (ell_width > (rc.right-rc.left) )
940 if (ell_height > (rc.bottom-rc.top) )
941 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
942 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
943 rc.right - rc.left - 1, rc.bottom - rc.top - 1, 0 , 360 * 64 );
945 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
946 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
947 rc.right - rc.left - 1, ell_height - 1, 0 , 180 * 64 );
948 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
949 physDev->dc_rect.left + rc.left,
950 physDev->dc_rect.top + rc.bottom - ell_height,
951 rc.right - rc.left - 1, ell_height - 1, 180 * 64 , 180 * 64 );
953 else if (ell_height > (rc.bottom-rc.top) ){
954 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
955 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
956 ell_width - 1 , rc.bottom - rc.top - 1, 90 * 64 , 180 * 64 );
957 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
958 physDev->dc_rect.left + rc.right - ell_width,
959 physDev->dc_rect.top + rc.top,
960 ell_width - 1 , rc.bottom - rc.top - 1, 270 * 64 , 180 * 64 );
962 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
963 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.top,
964 ell_width - 1, ell_height - 1, 90 * 64, 90 * 64 );
965 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
966 physDev->dc_rect.left + rc.left, physDev->dc_rect.top + rc.bottom - ell_height,
967 ell_width - 1, ell_height - 1, 180 * 64, 90 * 64 );
968 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
969 physDev->dc_rect.left + rc.right - ell_width,
970 physDev->dc_rect.top + rc.bottom - ell_height,
971 ell_width - 1, ell_height - 1, 270 * 64, 90 * 64 );
972 XDrawArc( gdi_display, physDev->drawable, physDev->gc,
973 physDev->dc_rect.left + rc.right - ell_width, physDev->dc_rect.top + rc.top,
974 ell_width - 1, ell_height - 1, 0, 90 * 64 );
976 if (ell_width < rc.right - rc.left)
978 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
979 physDev->dc_rect.left + rc.left + ell_width / 2,
980 physDev->dc_rect.top + rc.top,
981 physDev->dc_rect.left + rc.right - (ell_width+1) / 2,
982 physDev->dc_rect.top + rc.top);
983 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
984 physDev->dc_rect.left + rc.left + ell_width / 2 ,
985 physDev->dc_rect.top + rc.bottom - 1,
986 physDev->dc_rect.left + rc.right - (ell_width+1)/ 2,
987 physDev->dc_rect.top + rc.bottom - 1);
989 if (ell_height < rc.bottom - rc.top)
991 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
992 physDev->dc_rect.left + rc.right - 1,
993 physDev->dc_rect.top + rc.top + ell_height / 2,
994 physDev->dc_rect.left + rc.right - 1,
995 physDev->dc_rect.top + rc.bottom - (ell_height+1) / 2);
996 XDrawLine( gdi_display, physDev->drawable, physDev->gc,
997 physDev->dc_rect.left + rc.left,
998 physDev->dc_rect.top + rc.top + ell_height / 2,
999 physDev->dc_rect.left + rc.left,
1000 physDev->dc_rect.top + rc.bottom - (ell_height+1) / 2);
1002 wine_tsx11_unlock();
1005 /* Update the DIBSection from the pixmap */
1006 X11DRV_UnlockDIBSection(physDev, update);
1008 physDev->pen.width = oldwidth;
1009 physDev->pen.endcap = oldendcap;
1014 /***********************************************************************
1018 X11DRV_SetPixel( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color )
1020 unsigned long pixel;
1025 LPtoDP( physDev->hdc, &pt, 1 );
1026 pixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1028 /* Update the pixmap from the DIB section */
1029 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1031 /* inefficient but simple... */
1033 XSetForeground( gdi_display, physDev->gc, pixel );
1034 XSetFunction( gdi_display, physDev->gc, GXcopy );
1035 XDrawPoint( gdi_display, physDev->drawable, physDev->gc,
1036 physDev->dc_rect.left + pt.x, physDev->dc_rect.top + pt.y );
1037 wine_tsx11_unlock();
1039 /* Update the DIBSection from the pixmap */
1040 X11DRV_UnlockDIBSection(physDev, TRUE);
1042 return X11DRV_PALETTE_ToLogical(physDev, pixel);
1046 /***********************************************************************
1050 X11DRV_GetPixel( X11DRV_PDEVICE *physDev, INT x, INT y )
1052 static Pixmap pixmap = 0;
1056 BOOL memdc = (GetObjectType(physDev->hdc) == OBJ_MEMDC);
1060 LPtoDP( physDev->hdc, &pt, 1 );
1062 /* Update the pixmap from the DIB section */
1063 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1068 image = XGetImage( gdi_display, physDev->drawable,
1069 physDev->dc_rect.left + pt.x, physDev->dc_rect.top + pt.y,
1070 1, 1, AllPlanes, ZPixmap );
1074 /* If we are reading from the screen, use a temporary copy */
1075 /* to avoid a BadMatch error */
1076 if (!pixmap) pixmap = XCreatePixmap( gdi_display, root_window,
1077 1, 1, physDev->depth );
1078 XCopyArea( gdi_display, physDev->drawable, pixmap, get_bitmap_gc(physDev->depth),
1079 physDev->dc_rect.left + pt.x, physDev->dc_rect.top + pt.y, 1, 1, 0, 0 );
1080 image = XGetImage( gdi_display, pixmap, 0, 0, 1, 1, AllPlanes, ZPixmap );
1082 pixel = XGetPixel( image, 0, 0 );
1083 XDestroyImage( image );
1084 wine_tsx11_unlock();
1086 /* Update the DIBSection from the pixmap */
1087 X11DRV_UnlockDIBSection(physDev, FALSE);
1088 if( physDev->depth > 1)
1089 pixel = X11DRV_PALETTE_ToLogical(physDev, pixel);
1091 /* monochrome bitmaps return black or white */
1092 if( pixel) pixel = 0xffffff;
1098 /***********************************************************************
1102 X11DRV_PaintRgn( X11DRV_PDEVICE *physDev, HRGN hrgn )
1104 if (X11DRV_SetupGCForBrush( physDev ))
1108 RGNDATA *data = X11DRV_GetRegionData( hrgn, physDev->hdc );
1110 if (!data) return FALSE;
1111 rect = (XRectangle *)data->Buffer;
1112 for (i = 0; i < data->rdh.nCount; i++)
1114 rect[i].x += physDev->dc_rect.left;
1115 rect[i].y += physDev->dc_rect.top;
1118 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1120 XFillRectangles( gdi_display, physDev->drawable, physDev->gc, rect, data->rdh.nCount );
1121 wine_tsx11_unlock();
1122 X11DRV_UnlockDIBSection(physDev, TRUE);
1123 HeapFree( GetProcessHeap(), 0, data );
1128 /**********************************************************************
1132 X11DRV_Polyline( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
1137 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * count )))
1139 WARN("No memory to convert POINTs to XPoints!\n");
1142 for (i = 0; i < count; i++)
1145 LPtoDP(physDev->hdc, &tmp, 1);
1146 points[i].x = physDev->dc_rect.left + tmp.x;
1147 points[i].y = physDev->dc_rect.top + tmp.y;
1150 if (X11DRV_SetupGCForPen ( physDev ))
1152 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1154 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1155 points, count, CoordModeOrigin );
1156 wine_tsx11_unlock();
1157 X11DRV_UnlockDIBSection(physDev, TRUE);
1160 HeapFree( GetProcessHeap(), 0, points );
1165 /**********************************************************************
1169 X11DRV_Polygon( X11DRV_PDEVICE *physDev, const POINT* pt, INT count )
1173 BOOL update = FALSE;
1175 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (count+1) )))
1177 WARN("No memory to convert POINTs to XPoints!\n");
1180 for (i = 0; i < count; i++)
1183 LPtoDP(physDev->hdc, &tmp, 1);
1184 points[i].x = physDev->dc_rect.left + tmp.x;
1185 points[i].y = physDev->dc_rect.top + tmp.y;
1187 points[count] = points[0];
1189 /* Update the pixmap from the DIB section */
1190 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1192 if (X11DRV_SetupGCForBrush( physDev ))
1195 XFillPolygon( gdi_display, physDev->drawable, physDev->gc,
1196 points, count+1, Complex, CoordModeOrigin);
1197 wine_tsx11_unlock();
1200 if (X11DRV_SetupGCForPen ( physDev ))
1203 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1204 points, count+1, CoordModeOrigin );
1205 wine_tsx11_unlock();
1209 /* Update the DIBSection from the pixmap */
1210 X11DRV_UnlockDIBSection(physDev, update);
1212 HeapFree( GetProcessHeap(), 0, points );
1217 /**********************************************************************
1218 * X11DRV_PolyPolygon
1221 X11DRV_PolyPolygon( X11DRV_PDEVICE *physDev, const POINT* pt, const INT* counts, UINT polygons)
1225 /* FIXME: The points should be converted to device coords before */
1226 /* creating the region. */
1228 hrgn = CreatePolyPolygonRgn( pt, counts, polygons, GetPolyFillMode( physDev->hdc ) );
1229 X11DRV_PaintRgn( physDev, hrgn );
1230 DeleteObject( hrgn );
1232 /* Draw the outline of the polygons */
1234 if (X11DRV_SetupGCForPen ( physDev ))
1240 /* Update the pixmap from the DIB section */
1241 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1243 for (i = 0; i < polygons; i++) if (counts[i] > max) max = counts[i];
1244 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * (max+1) )))
1246 WARN("No memory to convert POINTs to XPoints!\n");
1249 for (i = 0; i < polygons; i++)
1251 for (j = 0; j < counts[i]; j++)
1254 LPtoDP(physDev->hdc, &tmp, 1);
1255 points[j].x = physDev->dc_rect.left + tmp.x;
1256 points[j].y = physDev->dc_rect.top + tmp.y;
1259 points[j] = points[0];
1261 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1262 points, j + 1, CoordModeOrigin );
1263 wine_tsx11_unlock();
1266 /* Update the DIBSection of the dc's bitmap */
1267 X11DRV_UnlockDIBSection(physDev, TRUE);
1269 HeapFree( GetProcessHeap(), 0, points );
1275 /**********************************************************************
1276 * X11DRV_PolyPolyline
1279 X11DRV_PolyPolyline( X11DRV_PDEVICE *physDev, const POINT* pt, const DWORD* counts, DWORD polylines )
1281 if (X11DRV_SetupGCForPen ( physDev ))
1283 unsigned int i, j, max = 0;
1286 /* Update the pixmap from the DIB section */
1287 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1289 for (i = 0; i < polylines; i++) if (counts[i] > max) max = counts[i];
1290 if (!(points = HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint) * max )))
1292 WARN("No memory to convert POINTs to XPoints!\n");
1295 for (i = 0; i < polylines; i++)
1297 for (j = 0; j < counts[i]; j++)
1300 LPtoDP(physDev->hdc, &tmp, 1);
1301 points[j].x = physDev->dc_rect.left + tmp.x;
1302 points[j].y = physDev->dc_rect.top + tmp.y;
1306 XDrawLines( gdi_display, physDev->drawable, physDev->gc,
1307 points, j, CoordModeOrigin );
1308 wine_tsx11_unlock();
1311 /* Update the DIBSection of the dc's bitmap */
1312 X11DRV_UnlockDIBSection(physDev, TRUE);
1314 HeapFree( GetProcessHeap(), 0, points );
1320 /**********************************************************************
1321 * X11DRV_InternalFloodFill
1323 * Internal helper function for flood fill.
1324 * (xorg,yorg) is the origin of the X image relative to the drawable.
1325 * (x,y) is relative to the origin of the X image.
1327 static void X11DRV_InternalFloodFill(XImage *image, X11DRV_PDEVICE *physDev,
1330 unsigned long pixel, WORD fillType )
1334 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1335 (XGetPixel(image,x,y) != pixel) : \
1336 (XGetPixel(image,x,y) == pixel))
1338 if (!TO_FLOOD(x,y)) return;
1340 /* Find left and right boundaries */
1343 while ((left > 0) && TO_FLOOD( left-1, y )) left--;
1344 while ((right < image->width) && TO_FLOOD( right, y )) right++;
1345 XFillRectangle( gdi_display, physDev->drawable, physDev->gc,
1346 xOrg + left, yOrg + y, right-left, 1 );
1348 /* Set the pixels of this line so we don't fill it again */
1350 for (x = left; x < right; x++)
1352 if (fillType == FLOODFILLBORDER) XPutPixel( image, x, y, pixel );
1353 else XPutPixel( image, x, y, ~pixel );
1356 /* Fill the line above */
1363 while ((x < right) && !TO_FLOOD(x,y)) x++;
1364 if (x >= right) break;
1365 while ((x < right) && TO_FLOOD(x,y)) x++;
1366 X11DRV_InternalFloodFill(image, physDev, x-1, y,
1367 xOrg, yOrg, pixel, fillType );
1371 /* Fill the line below */
1373 if ((y += 2) < image->height)
1378 while ((x < right) && !TO_FLOOD(x,y)) x++;
1379 if (x >= right) break;
1380 while ((x < right) && TO_FLOOD(x,y)) x++;
1381 X11DRV_InternalFloodFill(image, physDev, x-1, y,
1382 xOrg, yOrg, pixel, fillType );
1389 static int ExtFloodFillXGetImageErrorHandler( Display *dpy, XErrorEvent *event, void *arg )
1391 return (event->request_code == X_GetImage && event->error_code == BadMatch);
1394 /**********************************************************************
1395 * X11DRV_ExtFloodFill
1398 X11DRV_ExtFloodFill( X11DRV_PDEVICE *physDev, INT x, INT y, COLORREF color,
1405 TRACE("X11DRV_ExtFloodFill %d,%d %06x %d\n", x, y, color, fillType );
1409 LPtoDP( physDev->hdc, &pt, 1 );
1410 if (!PtInRegion( physDev->region, pt.x, pt.y )) return FALSE;
1411 GetRgnBox( physDev->region, &rect );
1413 X11DRV_expect_error( gdi_display, ExtFloodFillXGetImageErrorHandler, NULL );
1414 image = XGetImage( gdi_display, physDev->drawable,
1415 physDev->dc_rect.left + rect.left, physDev->dc_rect.top + rect.top,
1416 rect.right - rect.left, rect.bottom - rect.top,
1417 AllPlanes, ZPixmap );
1418 if(X11DRV_check_error()) image = NULL;
1419 if (!image) return FALSE;
1421 if (X11DRV_SetupGCForBrush( physDev ))
1423 unsigned long pixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1425 /* Update the pixmap from the DIB section */
1426 X11DRV_LockDIBSection(physDev, DIB_Status_GdiMod);
1428 /* ROP mode is always GXcopy for flood-fill */
1430 XSetFunction( gdi_display, physDev->gc, GXcopy );
1431 X11DRV_InternalFloodFill(image, physDev,
1434 physDev->dc_rect.left + rect.left,
1435 physDev->dc_rect.top + rect.top,
1437 wine_tsx11_unlock();
1438 /* Update the DIBSection of the dc's bitmap */
1439 X11DRV_UnlockDIBSection(physDev, TRUE);
1443 XDestroyImage( image );
1444 wine_tsx11_unlock();
1448 /**********************************************************************
1452 X11DRV_SetBkColor( X11DRV_PDEVICE *physDev, COLORREF color )
1454 physDev->backgroundPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1458 /**********************************************************************
1459 * X11DRV_SetTextColor
1462 X11DRV_SetTextColor( X11DRV_PDEVICE *physDev, COLORREF color )
1464 physDev->textPixel = X11DRV_PALETTE_ToPhysical( physDev, color );
1468 /***********************************************************************
1469 * GetDCOrgEx (X11DRV.@)
1471 BOOL CDECL X11DRV_GetDCOrgEx( X11DRV_PDEVICE *physDev, LPPOINT lpp )
1473 lpp->x = physDev->dc_rect.left + physDev->drawable_rect.left;
1474 lpp->y = physDev->dc_rect.top + physDev->drawable_rect.top;
1479 static unsigned char *get_icm_profile( unsigned long *size )
1483 unsigned long count, remaining;
1484 unsigned char *profile, *ret = NULL;
1487 XGetWindowProperty( gdi_display, DefaultRootWindow(gdi_display),
1488 x11drv_atom(_ICC_PROFILE), 0, ~0UL, False, AnyPropertyType,
1489 &type, &format, &count, &remaining, &profile );
1490 *size = get_property_size( format, count );
1491 if (format && count)
1493 if ((ret = HeapAlloc( GetProcessHeap(), 0, *size ))) memcpy( ret, profile, *size );
1496 wine_tsx11_unlock();
1502 unsigned int unknown[6];
1503 unsigned int state[5];
1504 unsigned int count[2];
1505 unsigned char buffer[64];
1508 extern void WINAPI A_SHAInit( sha_ctx * );
1509 extern void WINAPI A_SHAUpdate( sha_ctx *, const unsigned char *, unsigned int );
1510 extern void WINAPI A_SHAFinal( sha_ctx *, unsigned char * );
1512 /***********************************************************************
1513 * GetICMProfile (X11DRV.@)
1515 BOOL CDECL X11DRV_GetICMProfile( X11DRV_PDEVICE *physDev, LPDWORD size, LPWSTR filename )
1517 static const WCHAR path[] =
1518 {'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s',
1519 '\\','c','o','l','o','r','\\',0};
1520 static const WCHAR srgb[] =
1521 {'s','R','G','B',' ','C','o','l','o','r',' ','S','p','a','c','e',' ',
1522 'P','r','o','f','i','l','e','.','i','c','m',0};
1523 static const WCHAR mntr[] =
1524 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1525 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t',
1526 'V','e','r','s','i','o','n','\\','I','C','M','\\','m','n','t','r',0};
1529 DWORD required, len;
1530 WCHAR profile[MAX_PATH], fullname[2*MAX_PATH + sizeof(path)/sizeof(WCHAR)];
1531 unsigned char *buffer;
1532 unsigned long buflen;
1534 if (!size) return FALSE;
1536 GetSystemDirectoryW( fullname, MAX_PATH );
1537 strcatW( fullname, path );
1539 len = sizeof(profile)/sizeof(WCHAR);
1540 if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE, mntr, 0, NULL, 0, KEY_ALL_ACCESS, NULL, &hkey, NULL ) &&
1541 !RegEnumValueW( hkey, 0, profile, &len, NULL, NULL, NULL, NULL )) /* FIXME handle multiple values */
1543 strcatW( fullname, profile );
1544 RegCloseKey( hkey );
1546 else if ((buffer = get_icm_profile( &buflen )))
1548 static const WCHAR fmt[] = {'%','0','2','x',0};
1549 static const WCHAR icm[] = {'.','i','c','m',0};
1551 unsigned char sha1sum[20];
1557 A_SHAUpdate( &ctx, buffer, buflen );
1558 A_SHAFinal( &ctx, sha1sum );
1560 for (i = 0; i < sizeof(sha1sum); i++) sprintfW( &profile[i * 2], fmt, sha1sum[i] );
1561 memcpy( &profile[i * 2], icm, sizeof(icm) );
1563 strcatW( fullname, profile );
1564 file = CreateFileW( fullname, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, 0 );
1565 if (file != INVALID_HANDLE_VALUE)
1569 if (!WriteFile( file, buffer, buflen, &written, NULL ) || written != buflen)
1570 ERR( "Unable to write color profile\n" );
1571 CloseHandle( file );
1573 HeapFree( GetProcessHeap(), 0, buffer );
1575 else strcatW( fullname, srgb );
1577 required = strlenW( fullname ) + 1;
1578 if (*size < required)
1581 SetLastError( ERROR_INSUFFICIENT_BUFFER );
1586 strcpyW( filename, fullname );
1587 if (GetFileAttributesW( filename ) == INVALID_FILE_ATTRIBUTES)
1588 WARN( "color profile not found\n" );