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
47 #include "wine/debug.h"
48 #include "wine/unicode.h"
50 WINE_DEFAULT_DEBUG_CHANNEL(graphics
);
52 #define ABS(x) ((x)<0?(-(x)):(x))
54 /* ROP code to GC function conversion */
55 const int X11DRV_XROPfunction
[16] =
57 GXclear
, /* R2_BLACK */
58 GXnor
, /* R2_NOTMERGEPEN */
59 GXandInverted
, /* R2_MASKNOTPEN */
60 GXcopyInverted
, /* R2_NOTCOPYPEN */
61 GXandReverse
, /* R2_MASKPENNOT */
62 GXinvert
, /* R2_NOT */
63 GXxor
, /* R2_XORPEN */
64 GXnand
, /* R2_NOTMASKPEN */
65 GXand
, /* R2_MASKPEN */
66 GXequiv
, /* R2_NOTXORPEN */
68 GXorInverted
, /* R2_MERGENOTPEN */
69 GXcopy
, /* R2_COPYPEN */
70 GXorReverse
, /* R2_MERGEPENNOT */
71 GXor
, /* R2_MERGEPEN */
76 /* get the rectangle in device coordinates, with optional mirroring */
77 static RECT
get_device_rect( HDC hdc
, int left
, int top
, int right
, int bottom
)
85 if (GetLayout( hdc
) & LAYOUT_RTL
)
87 /* shift the rectangle so that the right border is included after mirroring */
88 /* it would be more correct to do this after LPtoDP but that's not what Windows does */
92 LPtoDP( hdc
, (POINT
*)&rect
, 2 );
93 if (rect
.left
> rect
.right
)
96 rect
.left
= rect
.right
;
99 if (rect
.top
> rect
.bottom
)
102 rect
.top
= rect
.bottom
;
108 /***********************************************************************
109 * X11DRV_GetRegionData
111 * Calls GetRegionData on the given region and converts the rectangle
112 * array to XRectangle format. The returned buffer must be freed by
113 * caller using HeapFree(GetProcessHeap(),...).
114 * If hdc_lptodp is not 0, the rectangles are converted through LPtoDP.
116 RGNDATA
*X11DRV_GetRegionData( HRGN hrgn
, HDC hdc_lptodp
)
124 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return NULL
;
125 if (sizeof(XRectangle
) > sizeof(RECT
))
127 /* add extra size for XRectangle array */
128 int count
= (size
- sizeof(RGNDATAHEADER
)) / sizeof(RECT
);
129 size
+= count
* (sizeof(XRectangle
) - sizeof(RECT
));
131 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return NULL
;
132 if (!GetRegionData( hrgn
, size
, data
))
134 HeapFree( GetProcessHeap(), 0, data
);
138 rect
= (RECT
*)data
->Buffer
;
139 xrect
= (XRectangle
*)data
->Buffer
;
140 if (hdc_lptodp
) /* map to device coordinates */
142 LPtoDP( hdc_lptodp
, (POINT
*)rect
, data
->rdh
.nCount
* 2 );
143 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
145 if (rect
[i
].right
< rect
[i
].left
)
147 INT tmp
= rect
[i
].right
;
148 rect
[i
].right
= rect
[i
].left
;
151 if (rect
[i
].bottom
< rect
[i
].top
)
153 INT tmp
= rect
[i
].bottom
;
154 rect
[i
].bottom
= rect
[i
].top
;
160 if (sizeof(XRectangle
) > sizeof(RECT
))
163 /* need to start from the end */
164 for (j
= data
->rdh
.nCount
-1; j
>= 0; j
--)
167 xrect
[j
].x
= max( min( tmp
.left
, SHRT_MAX
), SHRT_MIN
);
168 xrect
[j
].y
= max( min( tmp
.top
, SHRT_MAX
), SHRT_MIN
);
169 xrect
[j
].width
= max( min( tmp
.right
- xrect
[j
].x
, USHRT_MAX
), 0);
170 xrect
[j
].height
= max( min( tmp
.bottom
- xrect
[j
].y
, USHRT_MAX
), 0);
175 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
178 xrect
[i
].x
= max( min( tmp
.left
, SHRT_MAX
), SHRT_MIN
);
179 xrect
[i
].y
= max( min( tmp
.top
, SHRT_MAX
), SHRT_MIN
);
180 xrect
[i
].width
= max( min( tmp
.right
- xrect
[i
].x
, USHRT_MAX
), 0);
181 xrect
[i
].height
= max( min( tmp
.bottom
- xrect
[i
].y
, USHRT_MAX
), 0);
188 /***********************************************************************
189 * update_x11_clipping
191 static void update_x11_clipping( X11DRV_PDEVICE
*physDev
, const RGNDATA
*data
)
194 XSetClipRectangles( gdi_display
, physDev
->gc
, physDev
->dc_rect
.left
, physDev
->dc_rect
.top
,
195 (XRectangle
*)data
->Buffer
, data
->rdh
.nCount
, YXBanded
);
200 /***********************************************************************
201 * add_extra_clipping_region
203 * Temporarily add a region to the current clipping region.
204 * The returned region must be restored with restore_clipping_region.
206 RGNDATA
*add_extra_clipping_region( X11DRV_PDEVICE
*dev
, HRGN rgn
)
211 if (!(ret
= X11DRV_GetRegionData( dev
->region
, 0 ))) return NULL
;
212 if (!(clip
= CreateRectRgn( 0, 0, 0, 0 )))
214 HeapFree( GetProcessHeap(), 0, ret
);
217 CombineRgn( clip
, dev
->region
, rgn
, RGN_AND
);
218 if ((data
= X11DRV_GetRegionData( clip
, 0 )))
220 update_x11_clipping( dev
, data
);
221 HeapFree( GetProcessHeap(), 0, data
);
223 DeleteObject( clip
);
228 /***********************************************************************
229 * restore_clipping_region
231 void restore_clipping_region( X11DRV_PDEVICE
*dev
, RGNDATA
*data
)
234 update_x11_clipping( dev
, data
);
235 HeapFree( GetProcessHeap(), 0, data
);
239 /***********************************************************************
240 * X11DRV_SetDeviceClipping
242 void X11DRV_SetDeviceClipping( PHYSDEV dev
, HRGN rgn
)
245 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
247 CombineRgn( physDev
->region
, rgn
, 0, RGN_COPY
);
249 if ((data
= X11DRV_GetRegionData( physDev
->region
, 0 ))) update_x11_clipping( physDev
, data
);
250 HeapFree( GetProcessHeap(), 0, data
);
254 /***********************************************************************
255 * X11DRV_SetupGCForPatBlt
257 * Setup the GC for a PatBlt operation using current brush.
258 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
259 * Return FALSE if brush is BS_NULL, TRUE otherwise.
261 BOOL
X11DRV_SetupGCForPatBlt( X11DRV_PDEVICE
*physDev
, GC gc
, BOOL fMapColors
)
268 if (physDev
->brush
.style
== BS_NULL
) return FALSE
;
269 if (physDev
->brush
.pixel
== -1)
271 /* Special case used for monochrome pattern brushes.
272 * We need to swap foreground and background because
273 * Windows does it the wrong way...
275 val
.foreground
= physDev
->backgroundPixel
;
276 val
.background
= physDev
->textPixel
;
280 val
.foreground
= physDev
->brush
.pixel
;
281 val
.background
= physDev
->backgroundPixel
;
283 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
285 val
.foreground
= X11DRV_PALETTE_XPixelToPalette
[val
.foreground
];
286 val
.background
= X11DRV_PALETTE_XPixelToPalette
[val
.background
];
289 val
.function
= X11DRV_XROPfunction
[GetROP2(physDev
->dev
.hdc
)-1];
291 ** Let's replace GXinvert by GXxor with (black xor white)
292 ** This solves the selection color and leak problems in excel
293 ** FIXME : Let's do that only if we work with X-pixels, not with Win-pixels
295 if (val
.function
== GXinvert
)
297 val
.foreground
= (WhitePixel( gdi_display
, DefaultScreen(gdi_display
) ) ^
298 BlackPixel( gdi_display
, DefaultScreen(gdi_display
) ));
299 val
.function
= GXxor
;
301 val
.fill_style
= physDev
->brush
.fillStyle
;
302 switch(val
.fill_style
)
305 case FillOpaqueStippled
:
306 if (GetBkMode(physDev
->dev
.hdc
)==OPAQUE
) val
.fill_style
= FillOpaqueStippled
;
307 val
.stipple
= physDev
->brush
.pixmap
;
312 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
317 pixmap
= XCreatePixmap( gdi_display
, root_window
, 8, 8, physDev
->depth
);
318 image
= XGetImage( gdi_display
, physDev
->brush
.pixmap
, 0, 0, 8, 8,
319 AllPlanes
, ZPixmap
);
320 for (y
= 0; y
< 8; y
++)
321 for (x
= 0; x
< 8; x
++)
322 XPutPixel( image
, x
, y
,
323 X11DRV_PALETTE_XPixelToPalette
[XGetPixel( image
, x
, y
)] );
324 XPutImage( gdi_display
, pixmap
, gc
, image
, 0, 0, 0, 0, 8, 8 );
325 XDestroyImage( image
);
329 else val
.tile
= physDev
->brush
.pixmap
;
337 GetBrushOrgEx( physDev
->dev
.hdc
, &pt
);
338 val
.ts_x_origin
= physDev
->dc_rect
.left
+ pt
.x
;
339 val
.ts_y_origin
= physDev
->dc_rect
.top
+ pt
.y
;
340 val
.fill_rule
= (GetPolyFillMode(physDev
->dev
.hdc
) == WINDING
) ? WindingRule
: EvenOddRule
;
342 XChangeGC( gdi_display
, gc
,
343 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
344 GCFillRule
| GCTileStipXOrigin
| GCTileStipYOrigin
| mask
,
346 if (pixmap
) XFreePixmap( gdi_display
, pixmap
);
352 /***********************************************************************
353 * X11DRV_SetupGCForBrush
355 * Setup physDev->gc for drawing operations using current brush.
356 * Return FALSE if brush is BS_NULL, TRUE otherwise.
358 BOOL
X11DRV_SetupGCForBrush( X11DRV_PDEVICE
*physDev
)
360 return X11DRV_SetupGCForPatBlt( physDev
, physDev
->gc
, FALSE
);
364 /***********************************************************************
365 * X11DRV_SetupGCForPen
367 * Setup physDev->gc for drawing operations using current pen.
368 * Return FALSE if pen is PS_NULL, TRUE otherwise.
370 static BOOL
X11DRV_SetupGCForPen( X11DRV_PDEVICE
*physDev
)
373 UINT rop2
= GetROP2(physDev
->dev
.hdc
);
375 if (physDev
->pen
.style
== PS_NULL
) return FALSE
;
380 val
.foreground
= BlackPixel( gdi_display
, DefaultScreen(gdi_display
) );
381 val
.function
= GXcopy
;
384 val
.foreground
= WhitePixel( gdi_display
, DefaultScreen(gdi_display
) );
385 val
.function
= GXcopy
;
388 val
.foreground
= physDev
->pen
.pixel
;
389 /* It is very unlikely someone wants to XOR with 0 */
390 /* This fixes the rubber-drawings in paintbrush */
391 if (val
.foreground
== 0)
392 val
.foreground
= (WhitePixel( gdi_display
, DefaultScreen(gdi_display
) ) ^
393 BlackPixel( gdi_display
, DefaultScreen(gdi_display
) ));
394 val
.function
= GXxor
;
397 val
.foreground
= physDev
->pen
.pixel
;
398 val
.function
= X11DRV_XROPfunction
[rop2
-1];
400 val
.background
= physDev
->backgroundPixel
;
401 val
.fill_style
= FillSolid
;
402 val
.line_width
= physDev
->pen
.width
;
403 if (val
.line_width
<= 1) {
404 val
.cap_style
= CapNotLast
;
406 switch (physDev
->pen
.endcap
)
408 case PS_ENDCAP_SQUARE
:
409 val
.cap_style
= CapProjecting
;
412 val
.cap_style
= CapButt
;
414 case PS_ENDCAP_ROUND
:
416 val
.cap_style
= CapRound
;
419 switch (physDev
->pen
.linejoin
)
422 val
.join_style
= JoinBevel
;
425 val
.join_style
= JoinMiter
;
429 val
.join_style
= JoinRound
;
432 if (physDev
->pen
.dash_len
)
433 val
.line_style
= ((GetBkMode(physDev
->dev
.hdc
) == OPAQUE
) && (!physDev
->pen
.ext
))
434 ? LineDoubleDash
: LineOnOffDash
;
436 val
.line_style
= LineSolid
;
439 if (physDev
->pen
.dash_len
)
440 XSetDashes( gdi_display
, physDev
->gc
, 0, physDev
->pen
.dashes
, physDev
->pen
.dash_len
);
441 XChangeGC( gdi_display
, physDev
->gc
,
442 GCFunction
| GCForeground
| GCBackground
| GCLineWidth
|
443 GCLineStyle
| GCCapStyle
| GCJoinStyle
| GCFillStyle
, &val
);
449 /***********************************************************************
450 * X11DRV_SetupGCForText
452 * Setup physDev->gc for text drawing operations.
453 * Return FALSE if the font is null, TRUE otherwise.
455 BOOL
X11DRV_SetupGCForText( X11DRV_PDEVICE
*physDev
)
457 XFontStruct
* xfs
= XFONT_GetFontStruct( physDev
->font
);
463 val
.function
= GXcopy
; /* Text is always GXcopy */
464 val
.foreground
= physDev
->textPixel
;
465 val
.background
= physDev
->backgroundPixel
;
466 val
.fill_style
= FillSolid
;
470 XChangeGC( gdi_display
, physDev
->gc
,
471 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
476 WARN("Physical font failure\n" );
480 /***********************************************************************
483 * Performs a world-to-viewport transformation on the specified width.
485 INT
X11DRV_XWStoDS( HDC hdc
, INT width
)
493 LPtoDP( hdc
, pt
, 2 );
494 return pt
[1].x
- pt
[0].x
;
497 /***********************************************************************
500 * Performs a world-to-viewport transformation on the specified height.
502 INT
X11DRV_YWStoDS( HDC hdc
, INT height
)
510 LPtoDP( hdc
, pt
, 2 );
511 return pt
[1].y
- pt
[0].y
;
514 /***********************************************************************
517 BOOL
X11DRV_LineTo( PHYSDEV dev
, INT x
, INT y
)
519 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
522 if (X11DRV_SetupGCForPen( physDev
)) {
523 /* Update the pixmap from the DIB section */
524 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
526 GetCurrentPositionEx( dev
->hdc
, &pt
[0] );
529 LPtoDP( dev
->hdc
, pt
, 2 );
532 XDrawLine(gdi_display
, physDev
->drawable
, physDev
->gc
,
533 physDev
->dc_rect
.left
+ pt
[0].x
, physDev
->dc_rect
.top
+ pt
[0].y
,
534 physDev
->dc_rect
.left
+ pt
[1].x
, physDev
->dc_rect
.top
+ pt
[1].y
);
537 /* Update the DIBSection from the pixmap */
538 X11DRV_UnlockDIBSection(physDev
, TRUE
);
545 /***********************************************************************
548 * Helper functions for Arc(), Chord() and Pie().
549 * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
552 static BOOL
X11DRV_DrawArc( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
553 INT xstart
, INT ystart
, INT xend
, INT yend
, INT lines
)
555 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
556 INT xcenter
, ycenter
, istart_angle
, idiff_angle
;
558 double start_angle
, end_angle
;
562 RECT rc
= get_device_rect( dev
->hdc
, left
, top
, right
, bottom
);
568 LPtoDP(dev
->hdc
, &start
, 1);
569 LPtoDP(dev
->hdc
, &end
, 1);
571 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)
572 ||(lines
&& ((rc
.right
-rc
.left
==1)||(rc
.bottom
-rc
.top
==1)))) return TRUE
;
574 if (GetArcDirection( dev
->hdc
) == AD_CLOCKWISE
)
575 { POINT tmp
= start
; start
= end
; end
= tmp
; }
577 oldwidth
= width
= physDev
->pen
.width
;
578 if (!width
) width
= 1;
579 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
581 if (physDev
->pen
.style
== PS_INSIDEFRAME
)
583 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
584 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
585 rc
.left
+= width
/ 2;
586 rc
.right
-= (width
- 1) / 2;
588 rc
.bottom
-= (width
- 1) / 2;
590 if(width
== 0) width
= 1; /* more accurate */
591 physDev
->pen
.width
= width
;
593 xcenter
= (rc
.right
+ rc
.left
) / 2;
594 ycenter
= (rc
.bottom
+ rc
.top
) / 2;
595 start_angle
= atan2( (double)(ycenter
-start
.y
)*(rc
.right
-rc
.left
),
596 (double)(start
.x
-xcenter
)*(rc
.bottom
-rc
.top
) );
597 end_angle
= atan2( (double)(ycenter
-end
.y
)*(rc
.right
-rc
.left
),
598 (double)(end
.x
-xcenter
)*(rc
.bottom
-rc
.top
) );
599 if ((start
.x
==end
.x
)&&(start
.y
==end
.y
))
600 { /* A lazy program delivers xstart=xend=ystart=yend=0) */
604 else /* notorious cases */
605 if ((start_angle
== PI
)&&( end_angle
<0))
608 if ((end_angle
== PI
)&&( start_angle
<0))
610 istart_angle
= (INT
)(start_angle
* 180 * 64 / PI
+ 0.5);
611 idiff_angle
= (INT
)((end_angle
- start_angle
) * 180 * 64 / PI
+ 0.5);
612 if (idiff_angle
<= 0) idiff_angle
+= 360 * 64;
614 /* Update the pixmap from the DIB section */
615 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
617 /* Fill arc with brush if Chord() or Pie() */
619 if ((lines
> 0) && X11DRV_SetupGCForBrush( physDev
)) {
621 XSetArcMode( gdi_display
, physDev
->gc
, (lines
==1) ? ArcChord
: ArcPieSlice
);
622 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
623 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
624 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, istart_angle
, idiff_angle
);
629 /* Draw arc and lines */
631 if (X11DRV_SetupGCForPen( physDev
))
634 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
635 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
636 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, istart_angle
, idiff_angle
);
638 /* use the truncated values */
639 start_angle
=(double)istart_angle
*PI
/64./180.;
640 end_angle
=(double)(istart_angle
+idiff_angle
)*PI
/64./180.;
641 /* calculate the endpoints and round correctly */
642 points
[0].x
= (int) floor(physDev
->dc_rect
.left
+ (rc
.right
+rc
.left
)/2.0 +
643 cos(start_angle
) * (rc
.right
-rc
.left
-width
*2+2) / 2. + 0.5);
644 points
[0].y
= (int) floor(physDev
->dc_rect
.top
+ (rc
.top
+rc
.bottom
)/2.0 -
645 sin(start_angle
) * (rc
.bottom
-rc
.top
-width
*2+2) / 2. + 0.5);
646 points
[1].x
= (int) floor(physDev
->dc_rect
.left
+ (rc
.right
+rc
.left
)/2.0 +
647 cos(end_angle
) * (rc
.right
-rc
.left
-width
*2+2) / 2. + 0.5);
648 points
[1].y
= (int) floor(physDev
->dc_rect
.top
+ (rc
.top
+rc
.bottom
)/2.0 -
649 sin(end_angle
) * (rc
.bottom
-rc
.top
-width
*2+2) / 2. + 0.5);
651 /* OK, this stuff is optimized for Xfree86
652 * which is probably the server most used by
653 * wine users. Other X servers will not
654 * display correctly. (eXceed for instance)
655 * so if you feel you must make changes, make sure that
656 * you either use Xfree86 or separate your changes
657 * from these (compile switch or whatever)
661 points
[3] = points
[1];
662 points
[1].x
= physDev
->dc_rect
.left
+ xcenter
;
663 points
[1].y
= physDev
->dc_rect
.top
+ ycenter
;
664 points
[2] = points
[1];
665 dx1
=points
[1].x
-points
[0].x
;
666 dy1
=points
[1].y
-points
[0].y
;
667 if(((rc
.top
-rc
.bottom
) | -2) == -2)
668 if(dy1
>0) points
[1].y
--;
670 if (((-dx1
)*64)<=ABS(dy1
)*37) points
[0].x
--;
671 if(((-dx1
*9))<(dy1
*16)) points
[0].y
--;
672 if( dy1
<0 && ((dx1
*9)) < (dy1
*16)) points
[0].y
--;
674 if(dy1
< 0) points
[0].y
--;
675 if(((rc
.right
-rc
.left
) | -2) == -2) points
[1].x
--;
677 dx1
=points
[3].x
-points
[2].x
;
678 dy1
=points
[3].y
-points
[2].y
;
679 if(((rc
.top
-rc
.bottom
) | -2 ) == -2)
680 if(dy1
< 0) points
[2].y
--;
682 if( dy1
>0) points
[3].y
--;
683 if(((rc
.right
-rc
.left
) | -2) == -2 ) points
[2].x
--;
686 if( dx1
* 64 < dy1
* -37 ) points
[3].x
--;
690 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
691 points
, lines
+1, CoordModeOrigin
);
697 /* Update the DIBSection of the pixmap */
698 X11DRV_UnlockDIBSection(physDev
, update
);
700 physDev
->pen
.width
= oldwidth
;
705 /***********************************************************************
708 BOOL
X11DRV_Arc( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
709 INT xstart
, INT ystart
, INT xend
, INT yend
)
711 return X11DRV_DrawArc( dev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
, 0 );
715 /***********************************************************************
718 BOOL
X11DRV_Pie( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
719 INT xstart
, INT ystart
, INT xend
, INT yend
)
721 return X11DRV_DrawArc( dev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
, 2 );
724 /***********************************************************************
727 BOOL
X11DRV_Chord( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
728 INT xstart
, INT ystart
, INT xend
, INT yend
)
730 return X11DRV_DrawArc( dev
, left
, top
, right
, bottom
, xstart
, ystart
, xend
, yend
, 1 );
734 /***********************************************************************
737 BOOL
X11DRV_Ellipse( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
739 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
742 RECT rc
= get_device_rect( dev
->hdc
, left
, top
, right
, bottom
);
744 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)) return TRUE
;
746 oldwidth
= width
= physDev
->pen
.width
;
747 if (!width
) width
= 1;
748 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
750 if (physDev
->pen
.style
== PS_INSIDEFRAME
)
752 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
753 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
754 rc
.left
+= width
/ 2;
755 rc
.right
-= (width
- 1) / 2;
757 rc
.bottom
-= (width
- 1) / 2;
759 if(width
== 0) width
= 1; /* more accurate */
760 physDev
->pen
.width
= width
;
762 /* Update the pixmap from the DIB section */
763 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
765 if (X11DRV_SetupGCForBrush( physDev
))
768 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
769 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
770 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, 0, 360*64 );
774 if (X11DRV_SetupGCForPen( physDev
))
777 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
778 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
779 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, 0, 360*64 );
784 /* Update the DIBSection from the pixmap */
785 X11DRV_UnlockDIBSection(physDev
, update
);
787 physDev
->pen
.width
= oldwidth
;
792 /***********************************************************************
795 BOOL
X11DRV_Rectangle(PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
)
797 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
798 INT width
, oldwidth
, oldjoinstyle
;
800 RECT rc
= get_device_rect( dev
->hdc
, left
, top
, right
, bottom
);
802 TRACE("(%d %d %d %d)\n", left
, top
, right
, bottom
);
804 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)) return TRUE
;
806 oldwidth
= width
= physDev
->pen
.width
;
807 if (!width
) width
= 1;
808 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
810 if (physDev
->pen
.style
== PS_INSIDEFRAME
)
812 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
813 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
814 rc
.left
+= width
/ 2;
815 rc
.right
-= (width
- 1) / 2;
817 rc
.bottom
-= (width
- 1) / 2;
819 if(width
== 1) width
= 0;
820 physDev
->pen
.width
= width
;
821 oldjoinstyle
= physDev
->pen
.linejoin
;
822 if(physDev
->pen
.type
!= PS_GEOMETRIC
)
823 physDev
->pen
.linejoin
= PS_JOIN_MITER
;
825 /* Update the pixmap from the DIB section */
826 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
828 if ((rc
.right
> rc
.left
+ width
) && (rc
.bottom
> rc
.top
+ width
))
830 if (X11DRV_SetupGCForBrush( physDev
))
833 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
834 physDev
->dc_rect
.left
+ rc
.left
+ (width
+ 1) / 2,
835 physDev
->dc_rect
.top
+ rc
.top
+ (width
+ 1) / 2,
836 rc
.right
-rc
.left
-width
-1, rc
.bottom
-rc
.top
-width
-1);
841 if (X11DRV_SetupGCForPen( physDev
))
844 XDrawRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
845 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
846 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1 );
851 /* Update the DIBSection from the pixmap */
852 X11DRV_UnlockDIBSection(physDev
, update
);
854 physDev
->pen
.width
= oldwidth
;
855 physDev
->pen
.linejoin
= oldjoinstyle
;
859 /***********************************************************************
862 BOOL
X11DRV_RoundRect( PHYSDEV dev
, INT left
, INT top
, INT right
, INT bottom
,
863 INT ell_width
, INT ell_height
)
865 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
866 INT width
, oldwidth
, oldendcap
;
869 RECT rc
= get_device_rect( dev
->hdc
, left
, top
, right
, bottom
);
871 TRACE("(%d %d %d %d %d %d\n",
872 left
, top
, right
, bottom
, ell_width
, ell_height
);
874 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
))
877 /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
878 called with width/height < 0 */
879 pts
[0].x
= pts
[0].y
= 0;
880 pts
[1].x
= ell_width
;
881 pts
[1].y
= ell_height
;
882 LPtoDP(dev
->hdc
, pts
, 2);
883 ell_width
= max(abs( pts
[1].x
- pts
[0].x
), 1);
884 ell_height
= max(abs( pts
[1].y
- pts
[0].y
), 1);
886 oldwidth
= width
= physDev
->pen
.width
;
887 oldendcap
= physDev
->pen
.endcap
;
888 if (!width
) width
= 1;
889 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
891 if (physDev
->pen
.style
== PS_INSIDEFRAME
)
893 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
894 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
895 rc
.left
+= width
/ 2;
896 rc
.right
-= (width
- 1) / 2;
898 rc
.bottom
-= (width
- 1) / 2;
900 if(width
== 0) width
= 1;
901 physDev
->pen
.width
= width
;
902 physDev
->pen
.endcap
= PS_ENDCAP_SQUARE
;
904 /* Update the pixmap from the DIB section */
905 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
907 if (X11DRV_SetupGCForBrush( physDev
))
910 if (ell_width
> (rc
.right
-rc
.left
) )
911 if (ell_height
> (rc
.bottom
-rc
.top
) )
912 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
913 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
914 rc
.right
- rc
.left
- 1, rc
.bottom
- rc
.top
- 1,
917 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
918 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
919 rc
.right
- rc
.left
- 1, ell_height
, 0, 180 * 64 );
920 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
921 physDev
->dc_rect
.left
+ rc
.left
,
922 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
923 rc
.right
- rc
.left
- 1, ell_height
, 180 * 64,
926 else if (ell_height
> (rc
.bottom
-rc
.top
) ){
927 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
928 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
929 ell_width
, rc
.bottom
- rc
.top
- 1, 90 * 64, 180 * 64 );
930 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
931 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1, physDev
->dc_rect
.top
+ rc
.top
,
932 ell_width
, rc
.bottom
- rc
.top
- 1, 270 * 64, 180 * 64 );
934 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
935 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
936 ell_width
, ell_height
, 90 * 64, 90 * 64 );
937 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
938 physDev
->dc_rect
.left
+ rc
.left
,
939 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
940 ell_width
, ell_height
, 180 * 64, 90 * 64 );
941 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
942 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1,
943 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
944 ell_width
, ell_height
, 270 * 64, 90 * 64 );
945 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
946 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1,
947 physDev
->dc_rect
.top
+ rc
.top
,
948 ell_width
, ell_height
, 0, 90 * 64 );
950 if (ell_width
< rc
.right
- rc
.left
)
952 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
953 physDev
->dc_rect
.left
+ rc
.left
+ (ell_width
+ 1) / 2,
954 physDev
->dc_rect
.top
+ rc
.top
+ 1,
955 rc
.right
- rc
.left
- ell_width
- 1,
956 (ell_height
+ 1) / 2 - 1);
957 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
958 physDev
->dc_rect
.left
+ rc
.left
+ (ell_width
+ 1) / 2,
959 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
) / 2 - 1,
960 rc
.right
- rc
.left
- ell_width
- 1,
963 if (ell_height
< rc
.bottom
- rc
.top
)
965 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
966 physDev
->dc_rect
.left
+ rc
.left
+ 1,
967 physDev
->dc_rect
.top
+ rc
.top
+ (ell_height
+ 1) / 2,
968 rc
.right
- rc
.left
- 2,
969 rc
.bottom
- rc
.top
- ell_height
- 1);
974 /* FIXME: this could be done with on X call
975 * more efficient and probably more correct
976 * on any X server: XDrawArcs will draw
977 * straight horizontal and vertical lines
978 * if width or height are zero.
980 * BTW this stuff is optimized for an Xfree86 server
981 * read the comments inside the X11DRV_DrawArc function
983 if (X11DRV_SetupGCForPen( physDev
))
986 if (ell_width
> (rc
.right
-rc
.left
) )
987 if (ell_height
> (rc
.bottom
-rc
.top
) )
988 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
989 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
990 rc
.right
- rc
.left
- 1, rc
.bottom
- rc
.top
- 1, 0 , 360 * 64 );
992 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
993 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
994 rc
.right
- rc
.left
- 1, ell_height
- 1, 0 , 180 * 64 );
995 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
996 physDev
->dc_rect
.left
+ rc
.left
,
997 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
998 rc
.right
- rc
.left
- 1, ell_height
- 1, 180 * 64 , 180 * 64 );
1000 else if (ell_height
> (rc
.bottom
-rc
.top
) ){
1001 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
1002 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
1003 ell_width
- 1 , rc
.bottom
- rc
.top
- 1, 90 * 64 , 180 * 64 );
1004 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
1005 physDev
->dc_rect
.left
+ rc
.right
- ell_width
,
1006 physDev
->dc_rect
.top
+ rc
.top
,
1007 ell_width
- 1 , rc
.bottom
- rc
.top
- 1, 270 * 64 , 180 * 64 );
1009 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
1010 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
1011 ell_width
- 1, ell_height
- 1, 90 * 64, 90 * 64 );
1012 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
1013 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
1014 ell_width
- 1, ell_height
- 1, 180 * 64, 90 * 64 );
1015 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
1016 physDev
->dc_rect
.left
+ rc
.right
- ell_width
,
1017 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
1018 ell_width
- 1, ell_height
- 1, 270 * 64, 90 * 64 );
1019 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
1020 physDev
->dc_rect
.left
+ rc
.right
- ell_width
, physDev
->dc_rect
.top
+ rc
.top
,
1021 ell_width
- 1, ell_height
- 1, 0, 90 * 64 );
1023 if (ell_width
< rc
.right
- rc
.left
)
1025 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
1026 physDev
->dc_rect
.left
+ rc
.left
+ ell_width
/ 2,
1027 physDev
->dc_rect
.top
+ rc
.top
,
1028 physDev
->dc_rect
.left
+ rc
.right
- (ell_width
+1) / 2,
1029 physDev
->dc_rect
.top
+ rc
.top
);
1030 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
1031 physDev
->dc_rect
.left
+ rc
.left
+ ell_width
/ 2 ,
1032 physDev
->dc_rect
.top
+ rc
.bottom
- 1,
1033 physDev
->dc_rect
.left
+ rc
.right
- (ell_width
+1)/ 2,
1034 physDev
->dc_rect
.top
+ rc
.bottom
- 1);
1036 if (ell_height
< rc
.bottom
- rc
.top
)
1038 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
1039 physDev
->dc_rect
.left
+ rc
.right
- 1,
1040 physDev
->dc_rect
.top
+ rc
.top
+ ell_height
/ 2,
1041 physDev
->dc_rect
.left
+ rc
.right
- 1,
1042 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
+1) / 2);
1043 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
1044 physDev
->dc_rect
.left
+ rc
.left
,
1045 physDev
->dc_rect
.top
+ rc
.top
+ ell_height
/ 2,
1046 physDev
->dc_rect
.left
+ rc
.left
,
1047 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
+1) / 2);
1049 wine_tsx11_unlock();
1052 /* Update the DIBSection from the pixmap */
1053 X11DRV_UnlockDIBSection(physDev
, update
);
1055 physDev
->pen
.width
= oldwidth
;
1056 physDev
->pen
.endcap
= oldendcap
;
1061 /***********************************************************************
1064 COLORREF
X11DRV_SetPixel( PHYSDEV dev
, INT x
, INT y
, COLORREF color
)
1066 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1067 unsigned long pixel
;
1072 LPtoDP( dev
->hdc
, &pt
, 1 );
1073 pixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1075 /* Update the pixmap from the DIB section */
1076 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1078 /* inefficient but simple... */
1080 XSetForeground( gdi_display
, physDev
->gc
, pixel
);
1081 XSetFunction( gdi_display
, physDev
->gc
, GXcopy
);
1082 XDrawPoint( gdi_display
, physDev
->drawable
, physDev
->gc
,
1083 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
);
1084 wine_tsx11_unlock();
1086 /* Update the DIBSection from the pixmap */
1087 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1089 return X11DRV_PALETTE_ToLogical(physDev
, pixel
);
1093 /***********************************************************************
1096 COLORREF
X11DRV_GetPixel( PHYSDEV dev
, INT x
, INT y
)
1098 static Pixmap pixmap
= 0;
1099 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1103 BOOL memdc
= (GetObjectType(dev
->hdc
) == OBJ_MEMDC
);
1107 LPtoDP( dev
->hdc
, &pt
, 1 );
1109 /* Update the pixmap from the DIB section */
1110 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1115 image
= XGetImage( gdi_display
, physDev
->drawable
,
1116 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
,
1117 1, 1, AllPlanes
, ZPixmap
);
1121 /* If we are reading from the screen, use a temporary copy */
1122 /* to avoid a BadMatch error */
1123 if (!pixmap
) pixmap
= XCreatePixmap( gdi_display
, root_window
,
1124 1, 1, physDev
->depth
);
1125 XCopyArea( gdi_display
, physDev
->drawable
, pixmap
, get_bitmap_gc(physDev
->depth
),
1126 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
, 1, 1, 0, 0 );
1127 image
= XGetImage( gdi_display
, pixmap
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
1129 pixel
= XGetPixel( image
, 0, 0 );
1130 XDestroyImage( image
);
1131 wine_tsx11_unlock();
1133 /* Update the DIBSection from the pixmap */
1134 X11DRV_UnlockDIBSection(physDev
, FALSE
);
1135 if( physDev
->depth
> 1)
1136 pixel
= X11DRV_PALETTE_ToLogical(physDev
, pixel
);
1138 /* monochrome bitmaps return black or white */
1139 if( pixel
) pixel
= 0xffffff;
1145 /***********************************************************************
1148 BOOL
X11DRV_PaintRgn( PHYSDEV dev
, HRGN hrgn
)
1150 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1152 if (X11DRV_SetupGCForBrush( physDev
))
1156 RGNDATA
*data
= X11DRV_GetRegionData( hrgn
, dev
->hdc
);
1158 if (!data
) return FALSE
;
1159 rect
= (XRectangle
*)data
->Buffer
;
1160 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
1162 rect
[i
].x
+= physDev
->dc_rect
.left
;
1163 rect
[i
].y
+= physDev
->dc_rect
.top
;
1166 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1168 XFillRectangles( gdi_display
, physDev
->drawable
, physDev
->gc
, rect
, data
->rdh
.nCount
);
1169 wine_tsx11_unlock();
1170 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1171 HeapFree( GetProcessHeap(), 0, data
);
1176 /**********************************************************************
1179 BOOL
X11DRV_Polyline( PHYSDEV dev
, const POINT
* pt
, INT count
)
1181 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1185 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * count
)))
1187 WARN("No memory to convert POINTs to XPoints!\n");
1190 for (i
= 0; i
< count
; i
++)
1193 LPtoDP(dev
->hdc
, &tmp
, 1);
1194 points
[i
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1195 points
[i
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1198 if (X11DRV_SetupGCForPen ( physDev
))
1200 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1202 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1203 points
, count
, CoordModeOrigin
);
1204 wine_tsx11_unlock();
1205 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1208 HeapFree( GetProcessHeap(), 0, points
);
1213 /**********************************************************************
1216 BOOL
X11DRV_Polygon( PHYSDEV dev
, const POINT
* pt
, INT count
)
1218 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1221 BOOL update
= FALSE
;
1223 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * (count
+1) )))
1225 WARN("No memory to convert POINTs to XPoints!\n");
1228 for (i
= 0; i
< count
; i
++)
1231 LPtoDP(dev
->hdc
, &tmp
, 1);
1232 points
[i
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1233 points
[i
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1235 points
[count
] = points
[0];
1237 /* Update the pixmap from the DIB section */
1238 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1240 if (X11DRV_SetupGCForBrush( physDev
))
1243 XFillPolygon( gdi_display
, physDev
->drawable
, physDev
->gc
,
1244 points
, count
+1, Complex
, CoordModeOrigin
);
1245 wine_tsx11_unlock();
1248 if (X11DRV_SetupGCForPen ( physDev
))
1251 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1252 points
, count
+1, CoordModeOrigin
);
1253 wine_tsx11_unlock();
1257 /* Update the DIBSection from the pixmap */
1258 X11DRV_UnlockDIBSection(physDev
, update
);
1260 HeapFree( GetProcessHeap(), 0, points
);
1265 /**********************************************************************
1266 * X11DRV_PolyPolygon
1268 BOOL
X11DRV_PolyPolygon( PHYSDEV dev
, const POINT
* pt
, const INT
* counts
, UINT polygons
)
1270 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1273 /* FIXME: The points should be converted to device coords before */
1274 /* creating the region. */
1276 hrgn
= CreatePolyPolygonRgn( pt
, counts
, polygons
, GetPolyFillMode( dev
->hdc
) );
1277 X11DRV_PaintRgn( dev
, hrgn
);
1278 DeleteObject( hrgn
);
1280 /* Draw the outline of the polygons */
1282 if (X11DRV_SetupGCForPen ( physDev
))
1288 /* Update the pixmap from the DIB section */
1289 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1291 for (i
= 0; i
< polygons
; i
++) if (counts
[i
] > max
) max
= counts
[i
];
1292 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * (max
+1) )))
1294 WARN("No memory to convert POINTs to XPoints!\n");
1297 for (i
= 0; i
< polygons
; i
++)
1299 for (j
= 0; j
< counts
[i
]; j
++)
1302 LPtoDP(dev
->hdc
, &tmp
, 1);
1303 points
[j
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1304 points
[j
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1307 points
[j
] = points
[0];
1309 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1310 points
, j
+ 1, CoordModeOrigin
);
1311 wine_tsx11_unlock();
1314 /* Update the DIBSection of the dc's bitmap */
1315 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1317 HeapFree( GetProcessHeap(), 0, points
);
1323 /**********************************************************************
1324 * X11DRV_PolyPolyline
1326 BOOL
X11DRV_PolyPolyline( PHYSDEV dev
, const POINT
* pt
, const DWORD
* counts
, DWORD polylines
)
1328 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1330 if (X11DRV_SetupGCForPen ( physDev
))
1332 unsigned int i
, j
, max
= 0;
1335 /* Update the pixmap from the DIB section */
1336 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1338 for (i
= 0; i
< polylines
; i
++) if (counts
[i
] > max
) max
= counts
[i
];
1339 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * max
)))
1341 WARN("No memory to convert POINTs to XPoints!\n");
1344 for (i
= 0; i
< polylines
; i
++)
1346 for (j
= 0; j
< counts
[i
]; j
++)
1349 LPtoDP(dev
->hdc
, &tmp
, 1);
1350 points
[j
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1351 points
[j
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1355 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1356 points
, j
, CoordModeOrigin
);
1357 wine_tsx11_unlock();
1360 /* Update the DIBSection of the dc's bitmap */
1361 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1363 HeapFree( GetProcessHeap(), 0, points
);
1369 /**********************************************************************
1370 * X11DRV_InternalFloodFill
1372 * Internal helper function for flood fill.
1373 * (xorg,yorg) is the origin of the X image relative to the drawable.
1374 * (x,y) is relative to the origin of the X image.
1376 static void X11DRV_InternalFloodFill(XImage
*image
, X11DRV_PDEVICE
*physDev
,
1379 unsigned long pixel
, WORD fillType
)
1383 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1384 (XGetPixel(image,x,y) != pixel) : \
1385 (XGetPixel(image,x,y) == pixel))
1387 if (!TO_FLOOD(x
,y
)) return;
1389 /* Find left and right boundaries */
1392 while ((left
> 0) && TO_FLOOD( left
-1, y
)) left
--;
1393 while ((right
< image
->width
) && TO_FLOOD( right
, y
)) right
++;
1394 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
1395 xOrg
+ left
, yOrg
+ y
, right
-left
, 1 );
1397 /* Set the pixels of this line so we don't fill it again */
1399 for (x
= left
; x
< right
; x
++)
1401 if (fillType
== FLOODFILLBORDER
) XPutPixel( image
, x
, y
, pixel
);
1402 else XPutPixel( image
, x
, y
, ~pixel
);
1405 /* Fill the line above */
1412 while ((x
< right
) && !TO_FLOOD(x
,y
)) x
++;
1413 if (x
>= right
) break;
1414 while ((x
< right
) && TO_FLOOD(x
,y
)) x
++;
1415 X11DRV_InternalFloodFill(image
, physDev
, x
-1, y
,
1416 xOrg
, yOrg
, pixel
, fillType
);
1420 /* Fill the line below */
1422 if ((y
+= 2) < image
->height
)
1427 while ((x
< right
) && !TO_FLOOD(x
,y
)) x
++;
1428 if (x
>= right
) break;
1429 while ((x
< right
) && TO_FLOOD(x
,y
)) x
++;
1430 X11DRV_InternalFloodFill(image
, physDev
, x
-1, y
,
1431 xOrg
, yOrg
, pixel
, fillType
);
1438 static int ExtFloodFillXGetImageErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
1440 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
1443 /**********************************************************************
1444 * X11DRV_ExtFloodFill
1446 BOOL
X11DRV_ExtFloodFill( PHYSDEV dev
, INT x
, INT y
, COLORREF color
, UINT fillType
)
1448 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1453 TRACE("X11DRV_ExtFloodFill %d,%d %06x %d\n", x
, y
, color
, fillType
);
1457 LPtoDP( dev
->hdc
, &pt
, 1 );
1458 if (!PtInRegion( physDev
->region
, pt
.x
, pt
.y
)) return FALSE
;
1459 GetRgnBox( physDev
->region
, &rect
);
1461 X11DRV_expect_error( gdi_display
, ExtFloodFillXGetImageErrorHandler
, NULL
);
1462 image
= XGetImage( gdi_display
, physDev
->drawable
,
1463 physDev
->dc_rect
.left
+ rect
.left
, physDev
->dc_rect
.top
+ rect
.top
,
1464 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1465 AllPlanes
, ZPixmap
);
1466 if(X11DRV_check_error()) image
= NULL
;
1467 if (!image
) return FALSE
;
1469 if (X11DRV_SetupGCForBrush( physDev
))
1471 unsigned long pixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1473 /* Update the pixmap from the DIB section */
1474 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1476 /* ROP mode is always GXcopy for flood-fill */
1478 XSetFunction( gdi_display
, physDev
->gc
, GXcopy
);
1479 X11DRV_InternalFloodFill(image
, physDev
,
1482 physDev
->dc_rect
.left
+ rect
.left
,
1483 physDev
->dc_rect
.top
+ rect
.top
,
1485 wine_tsx11_unlock();
1486 /* Update the DIBSection of the dc's bitmap */
1487 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1491 XDestroyImage( image
);
1492 wine_tsx11_unlock();
1496 /**********************************************************************
1497 * X11DRV_GradientFill
1499 BOOL
X11DRV_GradientFill( PHYSDEV dev
, TRIVERTEX
*vert_array
, ULONG nvert
,
1500 void *grad_array
, ULONG ngrad
, ULONG mode
)
1502 X11DRV_PDEVICE
*physdev
= get_x11drv_dev( dev
);
1503 const GRADIENT_RECT
*rect
= grad_array
;
1509 /* <= 16-bpp use dithering */
1510 if (physdev
->depth
<= 16) goto fallback
;
1514 case GRADIENT_FILL_RECT_H
:
1515 val
.function
= GXcopy
;
1516 val
.fill_style
= FillSolid
;
1518 val
.cap_style
= CapNotLast
;
1519 val
.line_style
= LineSolid
;
1521 XChangeGC( gdi_display
, physdev
->gc
,
1522 GCFunction
| GCLineWidth
| GCLineStyle
| GCCapStyle
| GCFillStyle
, &val
);
1523 wine_tsx11_unlock();
1525 X11DRV_LockDIBSection( physdev
, DIB_Status_GdiMod
);
1526 for (i
= 0; i
< ngrad
; i
++, rect
++)
1530 v
[0] = vert_array
[rect
->UpperLeft
];
1531 v
[1] = vert_array
[rect
->LowerRight
];
1536 LPtoDP( dev
->hdc
, pt
, 2 );
1537 dx
= pt
[1].x
- pt
[0].x
;
1539 if (dx
< 0) /* swap the colors */
1541 v
[0] = vert_array
[rect
->LowerRight
];
1542 v
[1] = vert_array
[rect
->UpperLeft
];
1545 for (x
= 0, pos
= min( pt
[0].x
, pt
[1].x
); x
< dx
; x
++, pos
++)
1547 COLORREF color
= RGB( (v
[0].Red
* (dx
- x
) + v
[1].Red
* x
) / dx
/ 256,
1548 (v
[0].Green
* (dx
- x
) + v
[1].Green
* x
) / dx
/ 256,
1549 (v
[0].Blue
* (dx
- x
) + v
[1].Blue
* x
) / dx
/ 256);
1551 XSetForeground( gdi_display
, physdev
->gc
, X11DRV_PALETTE_ToPhysical( physdev
, color
));
1552 XDrawLine( gdi_display
, physdev
->drawable
, physdev
->gc
,
1553 physdev
->dc_rect
.left
+ pos
, physdev
->dc_rect
.top
+ pt
[0].y
,
1554 physdev
->dc_rect
.left
+ pos
, physdev
->dc_rect
.top
+ pt
[1].y
);
1555 wine_tsx11_unlock();
1558 X11DRV_UnlockDIBSection( physdev
, TRUE
);
1561 case GRADIENT_FILL_RECT_V
:
1562 val
.function
= GXcopy
;
1563 val
.fill_style
= FillSolid
;
1565 val
.cap_style
= CapNotLast
;
1566 val
.line_style
= LineSolid
;
1568 XChangeGC( gdi_display
, physdev
->gc
,
1569 GCFunction
| GCLineWidth
| GCLineStyle
| GCCapStyle
| GCFillStyle
, &val
);
1570 wine_tsx11_unlock();
1572 X11DRV_LockDIBSection( physdev
, DIB_Status_GdiMod
);
1573 for (i
= 0; i
< ngrad
; i
++, rect
++)
1577 v
[0] = vert_array
[rect
->UpperLeft
];
1578 v
[1] = vert_array
[rect
->LowerRight
];
1583 LPtoDP( dev
->hdc
, pt
, 2 );
1584 dy
= pt
[1].y
- pt
[0].y
;
1586 if (dy
< 0) /* swap the colors */
1588 v
[0] = vert_array
[rect
->LowerRight
];
1589 v
[1] = vert_array
[rect
->UpperLeft
];
1592 for (y
= 0, pos
= min( pt
[0].y
, pt
[1].y
); y
< dy
; y
++, pos
++)
1594 COLORREF color
= RGB( (v
[0].Red
* (dy
- y
) + v
[1].Red
* y
) / dy
/ 256,
1595 (v
[0].Green
* (dy
- y
) + v
[1].Green
* y
) / dy
/ 256,
1596 (v
[0].Blue
* (dy
- y
) + v
[1].Blue
* y
) / dy
/ 256);
1598 XSetForeground( gdi_display
, physdev
->gc
, X11DRV_PALETTE_ToPhysical( physdev
, color
));
1599 XDrawLine( gdi_display
, physdev
->drawable
, physdev
->gc
,
1600 physdev
->dc_rect
.left
+ pt
[0].x
, physdev
->dc_rect
.top
+ pos
,
1601 physdev
->dc_rect
.left
+ pt
[1].x
, physdev
->dc_rect
.top
+ pos
);
1602 wine_tsx11_unlock();
1605 X11DRV_UnlockDIBSection( physdev
, TRUE
);
1610 dev
= GET_NEXT_PHYSDEV( dev
, pGradientFill
);
1611 return dev
->funcs
->pGradientFill( dev
, vert_array
, nvert
, grad_array
, ngrad
, mode
);
1614 /**********************************************************************
1617 COLORREF
X11DRV_SetBkColor( PHYSDEV dev
, COLORREF color
)
1619 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1621 physDev
->backgroundPixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1625 /**********************************************************************
1626 * X11DRV_SetTextColor
1628 COLORREF
X11DRV_SetTextColor( PHYSDEV dev
, COLORREF color
)
1630 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1632 physDev
->textPixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1637 static unsigned char *get_icm_profile( unsigned long *size
)
1641 unsigned long count
, remaining
;
1642 unsigned char *profile
, *ret
= NULL
;
1645 XGetWindowProperty( gdi_display
, DefaultRootWindow(gdi_display
),
1646 x11drv_atom(_ICC_PROFILE
), 0, ~0UL, False
, AnyPropertyType
,
1647 &type
, &format
, &count
, &remaining
, &profile
);
1648 *size
= get_property_size( format
, count
);
1649 if (format
&& count
)
1651 if ((ret
= HeapAlloc( GetProcessHeap(), 0, *size
))) memcpy( ret
, profile
, *size
);
1654 wine_tsx11_unlock();
1660 unsigned int unknown
[6];
1661 unsigned int state
[5];
1662 unsigned int count
[2];
1663 unsigned char buffer
[64];
1666 extern void WINAPI
A_SHAInit( sha_ctx
* );
1667 extern void WINAPI
A_SHAUpdate( sha_ctx
*, const unsigned char *, unsigned int );
1668 extern void WINAPI
A_SHAFinal( sha_ctx
*, unsigned char * );
1670 static const WCHAR mntr_key
[] =
1671 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1672 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t',
1673 'V','e','r','s','i','o','n','\\','I','C','M','\\','m','n','t','r',0};
1675 static const WCHAR color_path
[] =
1676 {'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s','\\','c','o','l','o','r','\\',0};
1678 /***********************************************************************
1679 * GetICMProfile (X11DRV.@)
1681 BOOL
X11DRV_GetICMProfile( PHYSDEV dev
, LPDWORD size
, LPWSTR filename
)
1683 static const WCHAR srgb
[] =
1684 {'s','R','G','B',' ','C','o','l','o','r',' ','S','p','a','c','e',' ',
1685 'P','r','o','f','i','l','e','.','i','c','m',0};
1687 DWORD required
, len
;
1688 WCHAR profile
[MAX_PATH
], fullname
[2*MAX_PATH
+ sizeof(color_path
)/sizeof(WCHAR
)];
1689 unsigned char *buffer
;
1690 unsigned long buflen
;
1692 if (!size
) return FALSE
;
1694 GetSystemDirectoryW( fullname
, MAX_PATH
);
1695 strcatW( fullname
, color_path
);
1697 len
= sizeof(profile
)/sizeof(WCHAR
);
1698 if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE
, mntr_key
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
) &&
1699 !RegEnumValueW( hkey
, 0, profile
, &len
, NULL
, NULL
, NULL
, NULL
)) /* FIXME handle multiple values */
1701 strcatW( fullname
, profile
);
1702 RegCloseKey( hkey
);
1704 else if ((buffer
= get_icm_profile( &buflen
)))
1706 static const WCHAR fmt
[] = {'%','0','2','x',0};
1707 static const WCHAR icm
[] = {'.','i','c','m',0};
1709 unsigned char sha1sum
[20];
1715 A_SHAUpdate( &ctx
, buffer
, buflen
);
1716 A_SHAFinal( &ctx
, sha1sum
);
1718 for (i
= 0; i
< sizeof(sha1sum
); i
++) sprintfW( &profile
[i
* 2], fmt
, sha1sum
[i
] );
1719 memcpy( &profile
[i
* 2], icm
, sizeof(icm
) );
1721 strcatW( fullname
, profile
);
1722 file
= CreateFileW( fullname
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, 0, 0 );
1723 if (file
!= INVALID_HANDLE_VALUE
)
1727 if (!WriteFile( file
, buffer
, buflen
, &written
, NULL
) || written
!= buflen
)
1728 ERR( "Unable to write color profile\n" );
1729 CloseHandle( file
);
1731 HeapFree( GetProcessHeap(), 0, buffer
);
1733 else strcatW( fullname
, srgb
);
1735 required
= strlenW( fullname
) + 1;
1736 if (*size
< required
)
1739 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1744 strcpyW( filename
, fullname
);
1745 if (GetFileAttributesW( filename
) == INVALID_FILE_ATTRIBUTES
)
1746 WARN( "color profile not found\n" );
1752 /***********************************************************************
1753 * EnumICMProfiles (X11DRV.@)
1755 INT
X11DRV_EnumICMProfiles( PHYSDEV dev
, ICMENUMPROCW proc
, LPARAM lparam
)
1757 X11DRV_PDEVICE
*physDev
= get_x11drv_dev( dev
);
1759 DWORD len_sysdir
, len_path
, len
, index
= 0;
1760 WCHAR sysdir
[MAX_PATH
], *profile
;
1764 TRACE("%p, %p, %ld\n", physDev
, proc
, lparam
);
1766 if (RegOpenKeyExW( HKEY_LOCAL_MACHINE
, mntr_key
, 0, KEY_ALL_ACCESS
, &hkey
))
1769 len_sysdir
= GetSystemDirectoryW( sysdir
, MAX_PATH
);
1770 len_path
= len_sysdir
+ sizeof(color_path
) / sizeof(color_path
[0]) - 1;
1774 if (!(profile
= HeapAlloc( GetProcessHeap(), 0, (len_path
+ len
) * sizeof(WCHAR
) )))
1776 RegCloseKey( hkey
);
1779 res
= RegEnumValueW( hkey
, index
, profile
+ len_path
, &len
, NULL
, NULL
, NULL
, NULL
);
1780 while (res
== ERROR_MORE_DATA
)
1783 HeapFree( GetProcessHeap(), 0, profile
);
1784 if (!(profile
= HeapAlloc( GetProcessHeap(), 0, (len_path
+ len
) * sizeof(WCHAR
) )))
1786 RegCloseKey( hkey
);
1789 res
= RegEnumValueW( hkey
, index
, profile
+ len_path
, &len
, NULL
, NULL
, NULL
, NULL
);
1791 if (res
!= ERROR_SUCCESS
)
1793 HeapFree( GetProcessHeap(), 0, profile
);
1796 memcpy( profile
, sysdir
, len_sysdir
* sizeof(WCHAR
) );
1797 memcpy( profile
+ len_sysdir
, color_path
, sizeof(color_path
) - sizeof(WCHAR
) );
1798 ret
= proc( profile
, lparam
);
1799 HeapFree( GetProcessHeap(), 0, profile
);
1803 RegCloseKey( hkey
);