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 * X11DRV_SetDeviceClipping
191 void CDECL
X11DRV_SetDeviceClipping( X11DRV_PDEVICE
*physDev
, HRGN vis_rgn
, HRGN clip_rgn
)
195 CombineRgn( physDev
->region
, vis_rgn
, clip_rgn
, clip_rgn
? RGN_AND
: RGN_COPY
);
196 if (!(data
= X11DRV_GetRegionData( physDev
->region
, 0 ))) return;
199 XSetClipRectangles( gdi_display
, physDev
->gc
, physDev
->dc_rect
.left
, physDev
->dc_rect
.top
,
200 (XRectangle
*)data
->Buffer
, data
->rdh
.nCount
, YXBanded
);
203 if (physDev
->xrender
) X11DRV_XRender_SetDeviceClipping(physDev
, data
);
205 HeapFree( GetProcessHeap(), 0, data
);
209 /***********************************************************************
210 * X11DRV_SetupGCForPatBlt
212 * Setup the GC for a PatBlt operation using current brush.
213 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
214 * Return FALSE if brush is BS_NULL, TRUE otherwise.
216 BOOL
X11DRV_SetupGCForPatBlt( X11DRV_PDEVICE
*physDev
, GC gc
, BOOL fMapColors
)
223 if (physDev
->brush
.style
== BS_NULL
) return FALSE
;
224 if (physDev
->brush
.pixel
== -1)
226 /* Special case used for monochrome pattern brushes.
227 * We need to swap foreground and background because
228 * Windows does it the wrong way...
230 val
.foreground
= physDev
->backgroundPixel
;
231 val
.background
= physDev
->textPixel
;
235 val
.foreground
= physDev
->brush
.pixel
;
236 val
.background
= physDev
->backgroundPixel
;
238 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
240 val
.foreground
= X11DRV_PALETTE_XPixelToPalette
[val
.foreground
];
241 val
.background
= X11DRV_PALETTE_XPixelToPalette
[val
.background
];
244 val
.function
= X11DRV_XROPfunction
[GetROP2(physDev
->hdc
)-1];
246 ** Let's replace GXinvert by GXxor with (black xor white)
247 ** This solves the selection color and leak problems in excel
248 ** FIXME : Let's do that only if we work with X-pixels, not with Win-pixels
250 if (val
.function
== GXinvert
)
252 val
.foreground
= (WhitePixel( gdi_display
, DefaultScreen(gdi_display
) ) ^
253 BlackPixel( gdi_display
, DefaultScreen(gdi_display
) ));
254 val
.function
= GXxor
;
256 val
.fill_style
= physDev
->brush
.fillStyle
;
257 switch(val
.fill_style
)
260 case FillOpaqueStippled
:
261 if (GetBkMode(physDev
->hdc
)==OPAQUE
) val
.fill_style
= FillOpaqueStippled
;
262 val
.stipple
= physDev
->brush
.pixmap
;
267 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
272 pixmap
= XCreatePixmap( gdi_display
, root_window
, 8, 8, physDev
->depth
);
273 image
= XGetImage( gdi_display
, physDev
->brush
.pixmap
, 0, 0, 8, 8,
274 AllPlanes
, ZPixmap
);
275 for (y
= 0; y
< 8; y
++)
276 for (x
= 0; x
< 8; x
++)
277 XPutPixel( image
, x
, y
,
278 X11DRV_PALETTE_XPixelToPalette
[XGetPixel( image
, x
, y
)] );
279 XPutImage( gdi_display
, pixmap
, gc
, image
, 0, 0, 0, 0, 8, 8 );
280 XDestroyImage( image
);
284 else val
.tile
= physDev
->brush
.pixmap
;
292 GetBrushOrgEx( physDev
->hdc
, &pt
);
293 val
.ts_x_origin
= physDev
->dc_rect
.left
+ pt
.x
;
294 val
.ts_y_origin
= physDev
->dc_rect
.top
+ pt
.y
;
295 val
.fill_rule
= (GetPolyFillMode(physDev
->hdc
) == WINDING
) ? WindingRule
: EvenOddRule
;
297 XChangeGC( gdi_display
, gc
,
298 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
299 GCFillRule
| GCTileStipXOrigin
| GCTileStipYOrigin
| mask
,
301 if (pixmap
) XFreePixmap( gdi_display
, pixmap
);
307 /***********************************************************************
308 * X11DRV_SetupGCForBrush
310 * Setup physDev->gc for drawing operations using current brush.
311 * Return FALSE if brush is BS_NULL, TRUE otherwise.
313 BOOL
X11DRV_SetupGCForBrush( X11DRV_PDEVICE
*physDev
)
315 return X11DRV_SetupGCForPatBlt( physDev
, physDev
->gc
, FALSE
);
319 /***********************************************************************
320 * X11DRV_SetupGCForPen
322 * Setup physDev->gc for drawing operations using current pen.
323 * Return FALSE if pen is PS_NULL, TRUE otherwise.
325 static BOOL
X11DRV_SetupGCForPen( X11DRV_PDEVICE
*physDev
)
328 UINT rop2
= GetROP2(physDev
->hdc
);
330 if (physDev
->pen
.style
== PS_NULL
) return FALSE
;
335 val
.foreground
= BlackPixel( gdi_display
, DefaultScreen(gdi_display
) );
336 val
.function
= GXcopy
;
339 val
.foreground
= WhitePixel( gdi_display
, DefaultScreen(gdi_display
) );
340 val
.function
= GXcopy
;
343 val
.foreground
= physDev
->pen
.pixel
;
344 /* It is very unlikely someone wants to XOR with 0 */
345 /* This fixes the rubber-drawings in paintbrush */
346 if (val
.foreground
== 0)
347 val
.foreground
= (WhitePixel( gdi_display
, DefaultScreen(gdi_display
) ) ^
348 BlackPixel( gdi_display
, DefaultScreen(gdi_display
) ));
349 val
.function
= GXxor
;
352 val
.foreground
= physDev
->pen
.pixel
;
353 val
.function
= X11DRV_XROPfunction
[rop2
-1];
355 val
.background
= physDev
->backgroundPixel
;
356 val
.fill_style
= FillSolid
;
357 val
.line_width
= physDev
->pen
.width
;
358 if (val
.line_width
<= 1) {
359 val
.cap_style
= CapNotLast
;
361 switch (physDev
->pen
.endcap
)
363 case PS_ENDCAP_SQUARE
:
364 val
.cap_style
= CapProjecting
;
367 val
.cap_style
= CapButt
;
369 case PS_ENDCAP_ROUND
:
371 val
.cap_style
= CapRound
;
374 switch (physDev
->pen
.linejoin
)
377 val
.join_style
= JoinBevel
;
380 val
.join_style
= JoinMiter
;
384 val
.join_style
= JoinRound
;
387 if (physDev
->pen
.dash_len
)
388 val
.line_style
= ((GetBkMode(physDev
->hdc
) == OPAQUE
) && (!physDev
->pen
.ext
))
389 ? LineDoubleDash
: LineOnOffDash
;
391 val
.line_style
= LineSolid
;
394 if (physDev
->pen
.dash_len
)
395 XSetDashes( gdi_display
, physDev
->gc
, 0, physDev
->pen
.dashes
, physDev
->pen
.dash_len
);
396 XChangeGC( gdi_display
, physDev
->gc
,
397 GCFunction
| GCForeground
| GCBackground
| GCLineWidth
|
398 GCLineStyle
| GCCapStyle
| GCJoinStyle
| GCFillStyle
, &val
);
404 /***********************************************************************
405 * X11DRV_SetupGCForText
407 * Setup physDev->gc for text drawing operations.
408 * Return FALSE if the font is null, TRUE otherwise.
410 BOOL
X11DRV_SetupGCForText( X11DRV_PDEVICE
*physDev
)
412 XFontStruct
* xfs
= XFONT_GetFontStruct( physDev
->font
);
418 val
.function
= GXcopy
; /* Text is always GXcopy */
419 val
.foreground
= physDev
->textPixel
;
420 val
.background
= physDev
->backgroundPixel
;
421 val
.fill_style
= FillSolid
;
425 XChangeGC( gdi_display
, physDev
->gc
,
426 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
431 WARN("Physical font failure\n" );
435 /***********************************************************************
438 * Performs a world-to-viewport transformation on the specified width.
440 INT
X11DRV_XWStoDS( X11DRV_PDEVICE
*physDev
, INT width
)
448 LPtoDP( physDev
->hdc
, pt
, 2 );
449 return pt
[1].x
- pt
[0].x
;
452 /***********************************************************************
455 * Performs a world-to-viewport transformation on the specified height.
457 INT
X11DRV_YWStoDS( X11DRV_PDEVICE
*physDev
, INT height
)
465 LPtoDP( physDev
->hdc
, pt
, 2 );
466 return pt
[1].y
- pt
[0].y
;
469 /***********************************************************************
473 X11DRV_LineTo( X11DRV_PDEVICE
*physDev
, INT x
, INT y
)
477 if (X11DRV_SetupGCForPen( physDev
)) {
478 /* Update the pixmap from the DIB section */
479 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
481 GetCurrentPositionEx( physDev
->hdc
, &pt
[0] );
484 LPtoDP( physDev
->hdc
, pt
, 2 );
487 XDrawLine(gdi_display
, physDev
->drawable
, physDev
->gc
,
488 physDev
->dc_rect
.left
+ pt
[0].x
, physDev
->dc_rect
.top
+ pt
[0].y
,
489 physDev
->dc_rect
.left
+ pt
[1].x
, physDev
->dc_rect
.top
+ pt
[1].y
);
492 /* Update the DIBSection from the pixmap */
493 X11DRV_UnlockDIBSection(physDev
, TRUE
);
500 /***********************************************************************
503 * Helper functions for Arc(), Chord() and Pie().
504 * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
508 X11DRV_DrawArc( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
,
509 INT bottom
, INT xstart
, INT ystart
,
510 INT xend
, INT yend
, INT lines
)
512 INT xcenter
, ycenter
, istart_angle
, idiff_angle
;
514 double start_angle
, end_angle
;
518 RECT rc
= get_device_rect( physDev
->hdc
, left
, top
, right
, bottom
);
524 LPtoDP(physDev
->hdc
, &start
, 1);
525 LPtoDP(physDev
->hdc
, &end
, 1);
527 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)
528 ||(lines
&& ((rc
.right
-rc
.left
==1)||(rc
.bottom
-rc
.top
==1)))) return TRUE
;
530 if (GetArcDirection( physDev
->hdc
) == AD_CLOCKWISE
)
531 { POINT tmp
= start
; start
= end
; end
= tmp
; }
533 oldwidth
= width
= physDev
->pen
.width
;
534 if (!width
) width
= 1;
535 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
537 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
539 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
540 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
541 rc
.left
+= width
/ 2;
542 rc
.right
-= (width
- 1) / 2;
544 rc
.bottom
-= (width
- 1) / 2;
546 if(width
== 0) width
= 1; /* more accurate */
547 physDev
->pen
.width
= width
;
549 xcenter
= (rc
.right
+ rc
.left
) / 2;
550 ycenter
= (rc
.bottom
+ rc
.top
) / 2;
551 start_angle
= atan2( (double)(ycenter
-start
.y
)*(rc
.right
-rc
.left
),
552 (double)(start
.x
-xcenter
)*(rc
.bottom
-rc
.top
) );
553 end_angle
= atan2( (double)(ycenter
-end
.y
)*(rc
.right
-rc
.left
),
554 (double)(end
.x
-xcenter
)*(rc
.bottom
-rc
.top
) );
555 if ((start
.x
==end
.x
)&&(start
.y
==end
.y
))
556 { /* A lazy program delivers xstart=xend=ystart=yend=0) */
560 else /* notorious cases */
561 if ((start_angle
== PI
)&&( end_angle
<0))
564 if ((end_angle
== PI
)&&( start_angle
<0))
566 istart_angle
= (INT
)(start_angle
* 180 * 64 / PI
+ 0.5);
567 idiff_angle
= (INT
)((end_angle
- start_angle
) * 180 * 64 / PI
+ 0.5);
568 if (idiff_angle
<= 0) idiff_angle
+= 360 * 64;
570 /* Update the pixmap from the DIB section */
571 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
573 /* Fill arc with brush if Chord() or Pie() */
575 if ((lines
> 0) && X11DRV_SetupGCForBrush( physDev
)) {
577 XSetArcMode( gdi_display
, physDev
->gc
, (lines
==1) ? ArcChord
: ArcPieSlice
);
578 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
579 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
580 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, istart_angle
, idiff_angle
);
585 /* Draw arc and lines */
587 if (X11DRV_SetupGCForPen( physDev
))
590 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
591 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
592 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, istart_angle
, idiff_angle
);
594 /* use the truncated values */
595 start_angle
=(double)istart_angle
*PI
/64./180.;
596 end_angle
=(double)(istart_angle
+idiff_angle
)*PI
/64./180.;
597 /* calculate the endpoints and round correctly */
598 points
[0].x
= (int) floor(physDev
->dc_rect
.left
+ (rc
.right
+rc
.left
)/2.0 +
599 cos(start_angle
) * (rc
.right
-rc
.left
-width
*2+2) / 2. + 0.5);
600 points
[0].y
= (int) floor(physDev
->dc_rect
.top
+ (rc
.top
+rc
.bottom
)/2.0 -
601 sin(start_angle
) * (rc
.bottom
-rc
.top
-width
*2+2) / 2. + 0.5);
602 points
[1].x
= (int) floor(physDev
->dc_rect
.left
+ (rc
.right
+rc
.left
)/2.0 +
603 cos(end_angle
) * (rc
.right
-rc
.left
-width
*2+2) / 2. + 0.5);
604 points
[1].y
= (int) floor(physDev
->dc_rect
.top
+ (rc
.top
+rc
.bottom
)/2.0 -
605 sin(end_angle
) * (rc
.bottom
-rc
.top
-width
*2+2) / 2. + 0.5);
607 /* OK, this stuff is optimized for Xfree86
608 * which is probably the server most used by
609 * wine users. Other X servers will not
610 * display correctly. (eXceed for instance)
611 * so if you feel you must make changes, make sure that
612 * you either use Xfree86 or separate your changes
613 * from these (compile switch or whatever)
617 points
[3] = points
[1];
618 points
[1].x
= physDev
->dc_rect
.left
+ xcenter
;
619 points
[1].y
= physDev
->dc_rect
.top
+ ycenter
;
620 points
[2] = points
[1];
621 dx1
=points
[1].x
-points
[0].x
;
622 dy1
=points
[1].y
-points
[0].y
;
623 if(((rc
.top
-rc
.bottom
) | -2) == -2)
624 if(dy1
>0) points
[1].y
--;
626 if (((-dx1
)*64)<=ABS(dy1
)*37) points
[0].x
--;
627 if(((-dx1
*9))<(dy1
*16)) points
[0].y
--;
628 if( dy1
<0 && ((dx1
*9)) < (dy1
*16)) points
[0].y
--;
630 if(dy1
< 0) points
[0].y
--;
631 if(((rc
.right
-rc
.left
) | -2) == -2) points
[1].x
--;
633 dx1
=points
[3].x
-points
[2].x
;
634 dy1
=points
[3].y
-points
[2].y
;
635 if(((rc
.top
-rc
.bottom
) | -2 ) == -2)
636 if(dy1
< 0) points
[2].y
--;
638 if( dy1
>0) points
[3].y
--;
639 if(((rc
.right
-rc
.left
) | -2) == -2 ) points
[2].x
--;
642 if( dx1
* 64 < dy1
* -37 ) points
[3].x
--;
646 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
647 points
, lines
+1, CoordModeOrigin
);
653 /* Update the DIBSection of the pixmap */
654 X11DRV_UnlockDIBSection(physDev
, update
);
656 physDev
->pen
.width
= oldwidth
;
661 /***********************************************************************
665 X11DRV_Arc( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
666 INT xstart
, INT ystart
, INT xend
, INT yend
)
668 return X11DRV_DrawArc( physDev
, left
, top
, right
, bottom
,
669 xstart
, ystart
, xend
, yend
, 0 );
673 /***********************************************************************
677 X11DRV_Pie( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
678 INT xstart
, INT ystart
, INT xend
, INT yend
)
680 return X11DRV_DrawArc( physDev
, left
, top
, right
, bottom
,
681 xstart
, ystart
, xend
, yend
, 2 );
684 /***********************************************************************
688 X11DRV_Chord( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
689 INT xstart
, INT ystart
, INT xend
, INT yend
)
691 return X11DRV_DrawArc( physDev
, left
, top
, right
, bottom
,
692 xstart
, ystart
, xend
, yend
, 1 );
696 /***********************************************************************
700 X11DRV_Ellipse( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
)
704 RECT rc
= get_device_rect( physDev
->hdc
, left
, top
, right
, bottom
);
706 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)) return TRUE
;
708 oldwidth
= width
= physDev
->pen
.width
;
709 if (!width
) width
= 1;
710 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
712 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
714 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
715 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
716 rc
.left
+= width
/ 2;
717 rc
.right
-= (width
- 1) / 2;
719 rc
.bottom
-= (width
- 1) / 2;
721 if(width
== 0) width
= 1; /* more accurate */
722 physDev
->pen
.width
= width
;
724 /* Update the pixmap from the DIB section */
725 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
727 if (X11DRV_SetupGCForBrush( physDev
))
730 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
731 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
732 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, 0, 360*64 );
736 if (X11DRV_SetupGCForPen( physDev
))
739 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
740 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
741 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, 0, 360*64 );
746 /* Update the DIBSection from the pixmap */
747 X11DRV_UnlockDIBSection(physDev
, update
);
749 physDev
->pen
.width
= oldwidth
;
754 /***********************************************************************
758 X11DRV_Rectangle(X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
)
760 INT width
, oldwidth
, oldjoinstyle
;
762 RECT rc
= get_device_rect( physDev
->hdc
, left
, top
, right
, bottom
);
764 TRACE("(%d %d %d %d)\n", left
, top
, right
, bottom
);
766 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)) return TRUE
;
768 oldwidth
= width
= physDev
->pen
.width
;
769 if (!width
) width
= 1;
770 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
772 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
774 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
775 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
776 rc
.left
+= width
/ 2;
777 rc
.right
-= (width
- 1) / 2;
779 rc
.bottom
-= (width
- 1) / 2;
781 if(width
== 1) width
= 0;
782 physDev
->pen
.width
= width
;
783 oldjoinstyle
= physDev
->pen
.linejoin
;
784 if(physDev
->pen
.type
!= PS_GEOMETRIC
)
785 physDev
->pen
.linejoin
= PS_JOIN_MITER
;
787 /* Update the pixmap from the DIB section */
788 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
790 if ((rc
.right
> rc
.left
+ width
) && (rc
.bottom
> rc
.top
+ width
))
792 if (X11DRV_SetupGCForBrush( physDev
))
795 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
796 physDev
->dc_rect
.left
+ rc
.left
+ (width
+ 1) / 2,
797 physDev
->dc_rect
.top
+ rc
.top
+ (width
+ 1) / 2,
798 rc
.right
-rc
.left
-width
-1, rc
.bottom
-rc
.top
-width
-1);
803 if (X11DRV_SetupGCForPen( physDev
))
806 XDrawRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
807 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
808 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1 );
813 /* Update the DIBSection from the pixmap */
814 X11DRV_UnlockDIBSection(physDev
, update
);
816 physDev
->pen
.width
= oldwidth
;
817 physDev
->pen
.linejoin
= oldjoinstyle
;
821 /***********************************************************************
825 X11DRV_RoundRect( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
,
826 INT bottom
, INT ell_width
, INT ell_height
)
828 INT width
, oldwidth
, oldendcap
;
831 RECT rc
= get_device_rect( physDev
->hdc
, left
, top
, right
, bottom
);
833 TRACE("(%d %d %d %d %d %d\n",
834 left
, top
, right
, bottom
, ell_width
, ell_height
);
836 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
))
839 /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
840 called with width/height < 0 */
841 pts
[0].x
= pts
[0].y
= 0;
842 pts
[1].x
= ell_width
;
843 pts
[1].y
= ell_height
;
844 LPtoDP(physDev
->hdc
, pts
, 2);
845 ell_width
= max(abs( pts
[1].x
- pts
[0].x
), 1);
846 ell_height
= max(abs( pts
[1].y
- pts
[0].y
), 1);
848 oldwidth
= width
= physDev
->pen
.width
;
849 oldendcap
= physDev
->pen
.endcap
;
850 if (!width
) width
= 1;
851 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
853 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
855 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
856 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
857 rc
.left
+= width
/ 2;
858 rc
.right
-= (width
- 1) / 2;
860 rc
.bottom
-= (width
- 1) / 2;
862 if(width
== 0) width
= 1;
863 physDev
->pen
.width
= width
;
864 physDev
->pen
.endcap
= PS_ENDCAP_SQUARE
;
866 /* Update the pixmap from the DIB section */
867 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
869 if (X11DRV_SetupGCForBrush( physDev
))
872 if (ell_width
> (rc
.right
-rc
.left
) )
873 if (ell_height
> (rc
.bottom
-rc
.top
) )
874 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
875 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
876 rc
.right
- rc
.left
- 1, rc
.bottom
- rc
.top
- 1,
879 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
880 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
881 rc
.right
- rc
.left
- 1, ell_height
, 0, 180 * 64 );
882 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
883 physDev
->dc_rect
.left
+ rc
.left
,
884 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
885 rc
.right
- rc
.left
- 1, ell_height
, 180 * 64,
888 else if (ell_height
> (rc
.bottom
-rc
.top
) ){
889 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
890 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
891 ell_width
, rc
.bottom
- rc
.top
- 1, 90 * 64, 180 * 64 );
892 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
893 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1, physDev
->dc_rect
.top
+ rc
.top
,
894 ell_width
, rc
.bottom
- rc
.top
- 1, 270 * 64, 180 * 64 );
896 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
897 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
898 ell_width
, ell_height
, 90 * 64, 90 * 64 );
899 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
900 physDev
->dc_rect
.left
+ rc
.left
,
901 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
902 ell_width
, ell_height
, 180 * 64, 90 * 64 );
903 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
904 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1,
905 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
906 ell_width
, ell_height
, 270 * 64, 90 * 64 );
907 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
908 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1,
909 physDev
->dc_rect
.top
+ rc
.top
,
910 ell_width
, ell_height
, 0, 90 * 64 );
912 if (ell_width
< rc
.right
- rc
.left
)
914 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
915 physDev
->dc_rect
.left
+ rc
.left
+ (ell_width
+ 1) / 2,
916 physDev
->dc_rect
.top
+ rc
.top
+ 1,
917 rc
.right
- rc
.left
- ell_width
- 1,
918 (ell_height
+ 1) / 2 - 1);
919 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
920 physDev
->dc_rect
.left
+ rc
.left
+ (ell_width
+ 1) / 2,
921 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
) / 2 - 1,
922 rc
.right
- rc
.left
- ell_width
- 1,
925 if (ell_height
< rc
.bottom
- rc
.top
)
927 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
928 physDev
->dc_rect
.left
+ rc
.left
+ 1,
929 physDev
->dc_rect
.top
+ rc
.top
+ (ell_height
+ 1) / 2,
930 rc
.right
- rc
.left
- 2,
931 rc
.bottom
- rc
.top
- ell_height
- 1);
936 /* FIXME: this could be done with on X call
937 * more efficient and probably more correct
938 * on any X server: XDrawArcs will draw
939 * straight horizontal and vertical lines
940 * if width or height are zero.
942 * BTW this stuff is optimized for an Xfree86 server
943 * read the comments inside the X11DRV_DrawArc function
945 if (X11DRV_SetupGCForPen( physDev
))
948 if (ell_width
> (rc
.right
-rc
.left
) )
949 if (ell_height
> (rc
.bottom
-rc
.top
) )
950 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
951 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
952 rc
.right
- rc
.left
- 1, rc
.bottom
- rc
.top
- 1, 0 , 360 * 64 );
954 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
955 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
956 rc
.right
- rc
.left
- 1, ell_height
- 1, 0 , 180 * 64 );
957 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
958 physDev
->dc_rect
.left
+ rc
.left
,
959 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
960 rc
.right
- rc
.left
- 1, ell_height
- 1, 180 * 64 , 180 * 64 );
962 else if (ell_height
> (rc
.bottom
-rc
.top
) ){
963 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
964 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
965 ell_width
- 1 , rc
.bottom
- rc
.top
- 1, 90 * 64 , 180 * 64 );
966 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
967 physDev
->dc_rect
.left
+ rc
.right
- ell_width
,
968 physDev
->dc_rect
.top
+ rc
.top
,
969 ell_width
- 1 , rc
.bottom
- rc
.top
- 1, 270 * 64 , 180 * 64 );
971 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
972 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
973 ell_width
- 1, ell_height
- 1, 90 * 64, 90 * 64 );
974 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
975 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
976 ell_width
- 1, ell_height
- 1, 180 * 64, 90 * 64 );
977 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
978 physDev
->dc_rect
.left
+ rc
.right
- ell_width
,
979 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
980 ell_width
- 1, ell_height
- 1, 270 * 64, 90 * 64 );
981 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
982 physDev
->dc_rect
.left
+ rc
.right
- ell_width
, physDev
->dc_rect
.top
+ rc
.top
,
983 ell_width
- 1, ell_height
- 1, 0, 90 * 64 );
985 if (ell_width
< rc
.right
- rc
.left
)
987 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
988 physDev
->dc_rect
.left
+ rc
.left
+ ell_width
/ 2,
989 physDev
->dc_rect
.top
+ rc
.top
,
990 physDev
->dc_rect
.left
+ rc
.right
- (ell_width
+1) / 2,
991 physDev
->dc_rect
.top
+ rc
.top
);
992 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
993 physDev
->dc_rect
.left
+ rc
.left
+ ell_width
/ 2 ,
994 physDev
->dc_rect
.top
+ rc
.bottom
- 1,
995 physDev
->dc_rect
.left
+ rc
.right
- (ell_width
+1)/ 2,
996 physDev
->dc_rect
.top
+ rc
.bottom
- 1);
998 if (ell_height
< rc
.bottom
- rc
.top
)
1000 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
1001 physDev
->dc_rect
.left
+ rc
.right
- 1,
1002 physDev
->dc_rect
.top
+ rc
.top
+ ell_height
/ 2,
1003 physDev
->dc_rect
.left
+ rc
.right
- 1,
1004 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
+1) / 2);
1005 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
1006 physDev
->dc_rect
.left
+ rc
.left
,
1007 physDev
->dc_rect
.top
+ rc
.top
+ ell_height
/ 2,
1008 physDev
->dc_rect
.left
+ rc
.left
,
1009 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
+1) / 2);
1011 wine_tsx11_unlock();
1014 /* Update the DIBSection from the pixmap */
1015 X11DRV_UnlockDIBSection(physDev
, update
);
1017 physDev
->pen
.width
= oldwidth
;
1018 physDev
->pen
.endcap
= oldendcap
;
1023 /***********************************************************************
1027 X11DRV_SetPixel( X11DRV_PDEVICE
*physDev
, INT x
, INT y
, COLORREF color
)
1029 unsigned long pixel
;
1034 LPtoDP( physDev
->hdc
, &pt
, 1 );
1035 pixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1037 /* Update the pixmap from the DIB section */
1038 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1040 /* inefficient but simple... */
1042 XSetForeground( gdi_display
, physDev
->gc
, pixel
);
1043 XSetFunction( gdi_display
, physDev
->gc
, GXcopy
);
1044 XDrawPoint( gdi_display
, physDev
->drawable
, physDev
->gc
,
1045 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
);
1046 wine_tsx11_unlock();
1048 /* Update the DIBSection from the pixmap */
1049 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1051 return X11DRV_PALETTE_ToLogical(physDev
, pixel
);
1055 /***********************************************************************
1059 X11DRV_GetPixel( X11DRV_PDEVICE
*physDev
, INT x
, INT y
)
1061 static Pixmap pixmap
= 0;
1065 BOOL memdc
= (GetObjectType(physDev
->hdc
) == OBJ_MEMDC
);
1069 LPtoDP( physDev
->hdc
, &pt
, 1 );
1071 /* Update the pixmap from the DIB section */
1072 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1077 image
= XGetImage( gdi_display
, physDev
->drawable
,
1078 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
,
1079 1, 1, AllPlanes
, ZPixmap
);
1083 /* If we are reading from the screen, use a temporary copy */
1084 /* to avoid a BadMatch error */
1085 if (!pixmap
) pixmap
= XCreatePixmap( gdi_display
, root_window
,
1086 1, 1, physDev
->depth
);
1087 XCopyArea( gdi_display
, physDev
->drawable
, pixmap
, get_bitmap_gc(physDev
->depth
),
1088 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
, 1, 1, 0, 0 );
1089 image
= XGetImage( gdi_display
, pixmap
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
1091 pixel
= XGetPixel( image
, 0, 0 );
1092 XDestroyImage( image
);
1093 wine_tsx11_unlock();
1095 /* Update the DIBSection from the pixmap */
1096 X11DRV_UnlockDIBSection(physDev
, FALSE
);
1097 if( physDev
->depth
> 1)
1098 pixel
= X11DRV_PALETTE_ToLogical(physDev
, pixel
);
1100 /* monochrome bitmaps return black or white */
1101 if( pixel
) pixel
= 0xffffff;
1107 /***********************************************************************
1111 X11DRV_PaintRgn( X11DRV_PDEVICE
*physDev
, HRGN hrgn
)
1113 if (X11DRV_SetupGCForBrush( physDev
))
1117 RGNDATA
*data
= X11DRV_GetRegionData( hrgn
, physDev
->hdc
);
1119 if (!data
) return FALSE
;
1120 rect
= (XRectangle
*)data
->Buffer
;
1121 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
1123 rect
[i
].x
+= physDev
->dc_rect
.left
;
1124 rect
[i
].y
+= physDev
->dc_rect
.top
;
1127 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1129 XFillRectangles( gdi_display
, physDev
->drawable
, physDev
->gc
, rect
, data
->rdh
.nCount
);
1130 wine_tsx11_unlock();
1131 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1132 HeapFree( GetProcessHeap(), 0, data
);
1137 /**********************************************************************
1141 X11DRV_Polyline( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, INT count
)
1146 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * count
)))
1148 WARN("No memory to convert POINTs to XPoints!\n");
1151 for (i
= 0; i
< count
; i
++)
1154 LPtoDP(physDev
->hdc
, &tmp
, 1);
1155 points
[i
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1156 points
[i
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1159 if (X11DRV_SetupGCForPen ( physDev
))
1161 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1163 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1164 points
, count
, CoordModeOrigin
);
1165 wine_tsx11_unlock();
1166 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1169 HeapFree( GetProcessHeap(), 0, points
);
1174 /**********************************************************************
1178 X11DRV_Polygon( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, INT count
)
1182 BOOL update
= FALSE
;
1184 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * (count
+1) )))
1186 WARN("No memory to convert POINTs to XPoints!\n");
1189 for (i
= 0; i
< count
; i
++)
1192 LPtoDP(physDev
->hdc
, &tmp
, 1);
1193 points
[i
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1194 points
[i
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1196 points
[count
] = points
[0];
1198 /* Update the pixmap from the DIB section */
1199 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1201 if (X11DRV_SetupGCForBrush( physDev
))
1204 XFillPolygon( gdi_display
, physDev
->drawable
, physDev
->gc
,
1205 points
, count
+1, Complex
, CoordModeOrigin
);
1206 wine_tsx11_unlock();
1209 if (X11DRV_SetupGCForPen ( physDev
))
1212 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1213 points
, count
+1, CoordModeOrigin
);
1214 wine_tsx11_unlock();
1218 /* Update the DIBSection from the pixmap */
1219 X11DRV_UnlockDIBSection(physDev
, update
);
1221 HeapFree( GetProcessHeap(), 0, points
);
1226 /**********************************************************************
1227 * X11DRV_PolyPolygon
1230 X11DRV_PolyPolygon( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, const INT
* counts
, UINT polygons
)
1234 /* FIXME: The points should be converted to device coords before */
1235 /* creating the region. */
1237 hrgn
= CreatePolyPolygonRgn( pt
, counts
, polygons
, GetPolyFillMode( physDev
->hdc
) );
1238 X11DRV_PaintRgn( physDev
, hrgn
);
1239 DeleteObject( hrgn
);
1241 /* Draw the outline of the polygons */
1243 if (X11DRV_SetupGCForPen ( physDev
))
1249 /* Update the pixmap from the DIB section */
1250 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1252 for (i
= 0; i
< polygons
; i
++) if (counts
[i
] > max
) max
= counts
[i
];
1253 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * (max
+1) )))
1255 WARN("No memory to convert POINTs to XPoints!\n");
1258 for (i
= 0; i
< polygons
; i
++)
1260 for (j
= 0; j
< counts
[i
]; j
++)
1263 LPtoDP(physDev
->hdc
, &tmp
, 1);
1264 points
[j
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1265 points
[j
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1268 points
[j
] = points
[0];
1270 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1271 points
, j
+ 1, CoordModeOrigin
);
1272 wine_tsx11_unlock();
1275 /* Update the DIBSection of the dc's bitmap */
1276 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1278 HeapFree( GetProcessHeap(), 0, points
);
1284 /**********************************************************************
1285 * X11DRV_PolyPolyline
1288 X11DRV_PolyPolyline( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, const DWORD
* counts
, DWORD polylines
)
1290 if (X11DRV_SetupGCForPen ( physDev
))
1292 unsigned int i
, j
, max
= 0;
1295 /* Update the pixmap from the DIB section */
1296 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1298 for (i
= 0; i
< polylines
; i
++) if (counts
[i
] > max
) max
= counts
[i
];
1299 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * max
)))
1301 WARN("No memory to convert POINTs to XPoints!\n");
1304 for (i
= 0; i
< polylines
; i
++)
1306 for (j
= 0; j
< counts
[i
]; j
++)
1309 LPtoDP(physDev
->hdc
, &tmp
, 1);
1310 points
[j
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1311 points
[j
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1315 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1316 points
, j
, CoordModeOrigin
);
1317 wine_tsx11_unlock();
1320 /* Update the DIBSection of the dc's bitmap */
1321 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1323 HeapFree( GetProcessHeap(), 0, points
);
1329 /**********************************************************************
1330 * X11DRV_InternalFloodFill
1332 * Internal helper function for flood fill.
1333 * (xorg,yorg) is the origin of the X image relative to the drawable.
1334 * (x,y) is relative to the origin of the X image.
1336 static void X11DRV_InternalFloodFill(XImage
*image
, X11DRV_PDEVICE
*physDev
,
1339 unsigned long pixel
, WORD fillType
)
1343 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1344 (XGetPixel(image,x,y) != pixel) : \
1345 (XGetPixel(image,x,y) == pixel))
1347 if (!TO_FLOOD(x
,y
)) return;
1349 /* Find left and right boundaries */
1352 while ((left
> 0) && TO_FLOOD( left
-1, y
)) left
--;
1353 while ((right
< image
->width
) && TO_FLOOD( right
, y
)) right
++;
1354 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
1355 xOrg
+ left
, yOrg
+ y
, right
-left
, 1 );
1357 /* Set the pixels of this line so we don't fill it again */
1359 for (x
= left
; x
< right
; x
++)
1361 if (fillType
== FLOODFILLBORDER
) XPutPixel( image
, x
, y
, pixel
);
1362 else XPutPixel( image
, x
, y
, ~pixel
);
1365 /* Fill the line above */
1372 while ((x
< right
) && !TO_FLOOD(x
,y
)) x
++;
1373 if (x
>= right
) break;
1374 while ((x
< right
) && TO_FLOOD(x
,y
)) x
++;
1375 X11DRV_InternalFloodFill(image
, physDev
, x
-1, y
,
1376 xOrg
, yOrg
, pixel
, fillType
);
1380 /* Fill the line below */
1382 if ((y
+= 2) < image
->height
)
1387 while ((x
< right
) && !TO_FLOOD(x
,y
)) x
++;
1388 if (x
>= right
) break;
1389 while ((x
< right
) && TO_FLOOD(x
,y
)) x
++;
1390 X11DRV_InternalFloodFill(image
, physDev
, x
-1, y
,
1391 xOrg
, yOrg
, pixel
, fillType
);
1398 static int ExtFloodFillXGetImageErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
1400 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
1403 /**********************************************************************
1404 * X11DRV_ExtFloodFill
1407 X11DRV_ExtFloodFill( X11DRV_PDEVICE
*physDev
, INT x
, INT y
, COLORREF color
,
1414 TRACE("X11DRV_ExtFloodFill %d,%d %06x %d\n", x
, y
, color
, fillType
);
1418 LPtoDP( physDev
->hdc
, &pt
, 1 );
1419 if (!PtInRegion( physDev
->region
, pt
.x
, pt
.y
)) return FALSE
;
1420 GetRgnBox( physDev
->region
, &rect
);
1422 X11DRV_expect_error( gdi_display
, ExtFloodFillXGetImageErrorHandler
, NULL
);
1423 image
= XGetImage( gdi_display
, physDev
->drawable
,
1424 physDev
->dc_rect
.left
+ rect
.left
, physDev
->dc_rect
.top
+ rect
.top
,
1425 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1426 AllPlanes
, ZPixmap
);
1427 if(X11DRV_check_error()) image
= NULL
;
1428 if (!image
) return FALSE
;
1430 if (X11DRV_SetupGCForBrush( physDev
))
1432 unsigned long pixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1434 /* Update the pixmap from the DIB section */
1435 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1437 /* ROP mode is always GXcopy for flood-fill */
1439 XSetFunction( gdi_display
, physDev
->gc
, GXcopy
);
1440 X11DRV_InternalFloodFill(image
, physDev
,
1443 physDev
->dc_rect
.left
+ rect
.left
,
1444 physDev
->dc_rect
.top
+ rect
.top
,
1446 wine_tsx11_unlock();
1447 /* Update the DIBSection of the dc's bitmap */
1448 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1452 XDestroyImage( image
);
1453 wine_tsx11_unlock();
1457 /**********************************************************************
1461 X11DRV_SetBkColor( X11DRV_PDEVICE
*physDev
, COLORREF color
)
1463 physDev
->backgroundPixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1467 /**********************************************************************
1468 * X11DRV_SetTextColor
1471 X11DRV_SetTextColor( X11DRV_PDEVICE
*physDev
, COLORREF color
)
1473 physDev
->textPixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1478 static unsigned char *get_icm_profile( unsigned long *size
)
1482 unsigned long count
, remaining
;
1483 unsigned char *profile
, *ret
= NULL
;
1486 XGetWindowProperty( gdi_display
, DefaultRootWindow(gdi_display
),
1487 x11drv_atom(_ICC_PROFILE
), 0, ~0UL, False
, AnyPropertyType
,
1488 &type
, &format
, &count
, &remaining
, &profile
);
1489 *size
= get_property_size( format
, count
);
1490 if (format
&& count
)
1492 if ((ret
= HeapAlloc( GetProcessHeap(), 0, *size
))) memcpy( ret
, profile
, *size
);
1495 wine_tsx11_unlock();
1501 unsigned int unknown
[6];
1502 unsigned int state
[5];
1503 unsigned int count
[2];
1504 unsigned char buffer
[64];
1507 extern void WINAPI
A_SHAInit( sha_ctx
* );
1508 extern void WINAPI
A_SHAUpdate( sha_ctx
*, const unsigned char *, unsigned int );
1509 extern void WINAPI
A_SHAFinal( sha_ctx
*, unsigned char * );
1511 /***********************************************************************
1512 * GetICMProfile (X11DRV.@)
1514 BOOL CDECL
X11DRV_GetICMProfile( X11DRV_PDEVICE
*physDev
, LPDWORD size
, LPWSTR filename
)
1516 static const WCHAR path
[] =
1517 {'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s',
1518 '\\','c','o','l','o','r','\\',0};
1519 static const WCHAR srgb
[] =
1520 {'s','R','G','B',' ','C','o','l','o','r',' ','S','p','a','c','e',' ',
1521 'P','r','o','f','i','l','e','.','i','c','m',0};
1522 static const WCHAR mntr
[] =
1523 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1524 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t',
1525 'V','e','r','s','i','o','n','\\','I','C','M','\\','m','n','t','r',0};
1528 DWORD required
, len
;
1529 WCHAR profile
[MAX_PATH
], fullname
[2*MAX_PATH
+ sizeof(path
)/sizeof(WCHAR
)];
1530 unsigned char *buffer
;
1531 unsigned long buflen
;
1533 if (!size
) return FALSE
;
1535 GetSystemDirectoryW( fullname
, MAX_PATH
);
1536 strcatW( fullname
, path
);
1538 len
= sizeof(profile
)/sizeof(WCHAR
);
1539 if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE
, mntr
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
) &&
1540 !RegEnumValueW( hkey
, 0, profile
, &len
, NULL
, NULL
, NULL
, NULL
)) /* FIXME handle multiple values */
1542 strcatW( fullname
, profile
);
1543 RegCloseKey( hkey
);
1545 else if ((buffer
= get_icm_profile( &buflen
)))
1547 static const WCHAR fmt
[] = {'%','0','2','x',0};
1548 static const WCHAR icm
[] = {'.','i','c','m',0};
1550 unsigned char sha1sum
[20];
1556 A_SHAUpdate( &ctx
, buffer
, buflen
);
1557 A_SHAFinal( &ctx
, sha1sum
);
1559 for (i
= 0; i
< sizeof(sha1sum
); i
++) sprintfW( &profile
[i
* 2], fmt
, sha1sum
[i
] );
1560 memcpy( &profile
[i
* 2], icm
, sizeof(icm
) );
1562 strcatW( fullname
, profile
);
1563 file
= CreateFileW( fullname
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, 0, 0 );
1564 if (file
!= INVALID_HANDLE_VALUE
)
1568 if (!WriteFile( file
, buffer
, buflen
, &written
, NULL
) || written
!= buflen
)
1569 ERR( "Unable to write color profile\n" );
1570 CloseHandle( file
);
1572 HeapFree( GetProcessHeap(), 0, buffer
);
1574 else strcatW( fullname
, srgb
);
1576 required
= strlenW( fullname
) + 1;
1577 if (*size
< required
)
1580 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1585 strcpyW( filename
, fullname
);
1586 if (GetFileAttributesW( filename
) == INVALID_FILE_ATTRIBUTES
)
1587 WARN( "color profile not found\n" );