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 LPtoDP( hdc
, (POINT
*)&rect
, 2 );
86 if (GetLayout( hdc
) & LAYOUT_RTL
)
89 rect
.left
= rect
.right
+ 1;
92 if (rect
.left
> rect
.right
)
95 rect
.left
= rect
.right
;
98 if (rect
.top
> rect
.bottom
)
101 rect
.top
= rect
.bottom
;
107 /***********************************************************************
108 * X11DRV_GetRegionData
110 * Calls GetRegionData on the given region and converts the rectangle
111 * array to XRectangle format. The returned buffer must be freed by
112 * caller using HeapFree(GetProcessHeap(),...).
113 * If hdc_lptodp is not 0, the rectangles are converted through LPtoDP.
115 RGNDATA
*X11DRV_GetRegionData( HRGN hrgn
, HDC hdc_lptodp
)
123 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return NULL
;
124 if (sizeof(XRectangle
) > sizeof(RECT
))
126 /* add extra size for XRectangle array */
127 int count
= (size
- sizeof(RGNDATAHEADER
)) / sizeof(RECT
);
128 size
+= count
* (sizeof(XRectangle
) - sizeof(RECT
));
130 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return NULL
;
131 if (!GetRegionData( hrgn
, size
, data
))
133 HeapFree( GetProcessHeap(), 0, data
);
137 rect
= (RECT
*)data
->Buffer
;
138 xrect
= (XRectangle
*)data
->Buffer
;
139 if (hdc_lptodp
) /* map to device coordinates */
141 LPtoDP( hdc_lptodp
, (POINT
*)rect
, data
->rdh
.nCount
* 2 );
142 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
144 if (rect
[i
].right
< rect
[i
].left
)
146 INT tmp
= rect
[i
].right
;
147 rect
[i
].right
= rect
[i
].left
;
150 if (rect
[i
].bottom
< rect
[i
].top
)
152 INT tmp
= rect
[i
].bottom
;
153 rect
[i
].bottom
= rect
[i
].top
;
159 if (sizeof(XRectangle
) > sizeof(RECT
))
162 /* need to start from the end */
163 for (j
= data
->rdh
.nCount
-1; j
>= 0; j
--)
166 xrect
[j
].x
= max( min( tmp
.left
, SHRT_MAX
), SHRT_MIN
);
167 xrect
[j
].y
= max( min( tmp
.top
, SHRT_MAX
), SHRT_MIN
);
168 xrect
[j
].width
= max( min( tmp
.right
- xrect
[j
].x
, USHRT_MAX
), 0);
169 xrect
[j
].height
= max( min( tmp
.bottom
- xrect
[j
].y
, USHRT_MAX
), 0);
174 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
177 xrect
[i
].x
= max( min( tmp
.left
, SHRT_MAX
), SHRT_MIN
);
178 xrect
[i
].y
= max( min( tmp
.top
, SHRT_MAX
), SHRT_MIN
);
179 xrect
[i
].width
= max( min( tmp
.right
- xrect
[i
].x
, USHRT_MAX
), 0);
180 xrect
[i
].height
= max( min( tmp
.bottom
- xrect
[i
].y
, USHRT_MAX
), 0);
187 /***********************************************************************
188 * X11DRV_SetDeviceClipping
190 void CDECL
X11DRV_SetDeviceClipping( X11DRV_PDEVICE
*physDev
, HRGN vis_rgn
, HRGN clip_rgn
)
194 CombineRgn( physDev
->region
, vis_rgn
, clip_rgn
, clip_rgn
? RGN_AND
: RGN_COPY
);
195 if (!(data
= X11DRV_GetRegionData( physDev
->region
, 0 ))) return;
198 XSetClipRectangles( gdi_display
, physDev
->gc
, physDev
->dc_rect
.left
, physDev
->dc_rect
.top
,
199 (XRectangle
*)data
->Buffer
, data
->rdh
.nCount
, YXBanded
);
202 if (physDev
->xrender
) X11DRV_XRender_SetDeviceClipping(physDev
, data
);
204 HeapFree( GetProcessHeap(), 0, data
);
208 /***********************************************************************
209 * X11DRV_SetupGCForPatBlt
211 * Setup the GC for a PatBlt operation using current brush.
212 * If fMapColors is TRUE, X pixels are mapped to Windows colors.
213 * Return FALSE if brush is BS_NULL, TRUE otherwise.
215 BOOL
X11DRV_SetupGCForPatBlt( X11DRV_PDEVICE
*physDev
, GC gc
, BOOL fMapColors
)
222 if (physDev
->brush
.style
== BS_NULL
) return FALSE
;
223 if (physDev
->brush
.pixel
== -1)
225 /* Special case used for monochrome pattern brushes.
226 * We need to swap foreground and background because
227 * Windows does it the wrong way...
229 val
.foreground
= physDev
->backgroundPixel
;
230 val
.background
= physDev
->textPixel
;
234 val
.foreground
= physDev
->brush
.pixel
;
235 val
.background
= physDev
->backgroundPixel
;
237 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
239 val
.foreground
= X11DRV_PALETTE_XPixelToPalette
[val
.foreground
];
240 val
.background
= X11DRV_PALETTE_XPixelToPalette
[val
.background
];
243 val
.function
= X11DRV_XROPfunction
[GetROP2(physDev
->hdc
)-1];
245 ** Let's replace GXinvert by GXxor with (black xor white)
246 ** This solves the selection color and leak problems in excel
247 ** FIXME : Let's do that only if we work with X-pixels, not with Win-pixels
249 if (val
.function
== GXinvert
)
251 val
.foreground
= (WhitePixel( gdi_display
, DefaultScreen(gdi_display
) ) ^
252 BlackPixel( gdi_display
, DefaultScreen(gdi_display
) ));
253 val
.function
= GXxor
;
255 val
.fill_style
= physDev
->brush
.fillStyle
;
256 switch(val
.fill_style
)
259 case FillOpaqueStippled
:
260 if (GetBkMode(physDev
->hdc
)==OPAQUE
) val
.fill_style
= FillOpaqueStippled
;
261 val
.stipple
= physDev
->brush
.pixmap
;
266 if (fMapColors
&& X11DRV_PALETTE_XPixelToPalette
)
271 pixmap
= XCreatePixmap( gdi_display
, root_window
, 8, 8, physDev
->depth
);
272 image
= XGetImage( gdi_display
, physDev
->brush
.pixmap
, 0, 0, 8, 8,
273 AllPlanes
, ZPixmap
);
274 for (y
= 0; y
< 8; y
++)
275 for (x
= 0; x
< 8; x
++)
276 XPutPixel( image
, x
, y
,
277 X11DRV_PALETTE_XPixelToPalette
[XGetPixel( image
, x
, y
)] );
278 XPutImage( gdi_display
, pixmap
, gc
, image
, 0, 0, 0, 0, 8, 8 );
279 XDestroyImage( image
);
283 else val
.tile
= physDev
->brush
.pixmap
;
291 GetBrushOrgEx( physDev
->hdc
, &pt
);
292 val
.ts_x_origin
= physDev
->dc_rect
.left
+ pt
.x
;
293 val
.ts_y_origin
= physDev
->dc_rect
.top
+ pt
.y
;
294 val
.fill_rule
= (GetPolyFillMode(physDev
->hdc
) == WINDING
) ? WindingRule
: EvenOddRule
;
296 XChangeGC( gdi_display
, gc
,
297 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
298 GCFillRule
| GCTileStipXOrigin
| GCTileStipYOrigin
| mask
,
300 if (pixmap
) XFreePixmap( gdi_display
, pixmap
);
306 /***********************************************************************
307 * X11DRV_SetupGCForBrush
309 * Setup physDev->gc for drawing operations using current brush.
310 * Return FALSE if brush is BS_NULL, TRUE otherwise.
312 BOOL
X11DRV_SetupGCForBrush( X11DRV_PDEVICE
*physDev
)
314 return X11DRV_SetupGCForPatBlt( physDev
, physDev
->gc
, FALSE
);
318 /***********************************************************************
319 * X11DRV_SetupGCForPen
321 * Setup physDev->gc for drawing operations using current pen.
322 * Return FALSE if pen is PS_NULL, TRUE otherwise.
324 static BOOL
X11DRV_SetupGCForPen( X11DRV_PDEVICE
*physDev
)
327 UINT rop2
= GetROP2(physDev
->hdc
);
329 if (physDev
->pen
.style
== PS_NULL
) return FALSE
;
334 val
.foreground
= BlackPixel( gdi_display
, DefaultScreen(gdi_display
) );
335 val
.function
= GXcopy
;
338 val
.foreground
= WhitePixel( gdi_display
, DefaultScreen(gdi_display
) );
339 val
.function
= GXcopy
;
342 val
.foreground
= physDev
->pen
.pixel
;
343 /* It is very unlikely someone wants to XOR with 0 */
344 /* This fixes the rubber-drawings in paintbrush */
345 if (val
.foreground
== 0)
346 val
.foreground
= (WhitePixel( gdi_display
, DefaultScreen(gdi_display
) ) ^
347 BlackPixel( gdi_display
, DefaultScreen(gdi_display
) ));
348 val
.function
= GXxor
;
351 val
.foreground
= physDev
->pen
.pixel
;
352 val
.function
= X11DRV_XROPfunction
[rop2
-1];
354 val
.background
= physDev
->backgroundPixel
;
355 val
.fill_style
= FillSolid
;
356 val
.line_width
= physDev
->pen
.width
;
357 if (val
.line_width
<= 1) {
358 val
.cap_style
= CapNotLast
;
360 switch (physDev
->pen
.endcap
)
362 case PS_ENDCAP_SQUARE
:
363 val
.cap_style
= CapProjecting
;
366 val
.cap_style
= CapButt
;
368 case PS_ENDCAP_ROUND
:
370 val
.cap_style
= CapRound
;
373 switch (physDev
->pen
.linejoin
)
376 val
.join_style
= JoinBevel
;
379 val
.join_style
= JoinMiter
;
383 val
.join_style
= JoinRound
;
386 if (physDev
->pen
.dash_len
)
387 val
.line_style
= ((GetBkMode(physDev
->hdc
) == OPAQUE
) && (!physDev
->pen
.ext
))
388 ? LineDoubleDash
: LineOnOffDash
;
390 val
.line_style
= LineSolid
;
393 if (physDev
->pen
.dash_len
)
394 XSetDashes( gdi_display
, physDev
->gc
, 0, physDev
->pen
.dashes
, physDev
->pen
.dash_len
);
395 XChangeGC( gdi_display
, physDev
->gc
,
396 GCFunction
| GCForeground
| GCBackground
| GCLineWidth
|
397 GCLineStyle
| GCCapStyle
| GCJoinStyle
| GCFillStyle
, &val
);
403 /***********************************************************************
404 * X11DRV_SetupGCForText
406 * Setup physDev->gc for text drawing operations.
407 * Return FALSE if the font is null, TRUE otherwise.
409 BOOL
X11DRV_SetupGCForText( X11DRV_PDEVICE
*physDev
)
411 XFontStruct
* xfs
= XFONT_GetFontStruct( physDev
->font
);
417 val
.function
= GXcopy
; /* Text is always GXcopy */
418 val
.foreground
= physDev
->textPixel
;
419 val
.background
= physDev
->backgroundPixel
;
420 val
.fill_style
= FillSolid
;
424 XChangeGC( gdi_display
, physDev
->gc
,
425 GCFunction
| GCForeground
| GCBackground
| GCFillStyle
|
430 WARN("Physical font failure\n" );
434 /***********************************************************************
437 * Performs a world-to-viewport transformation on the specified width.
439 INT
X11DRV_XWStoDS( X11DRV_PDEVICE
*physDev
, INT width
)
447 LPtoDP( physDev
->hdc
, pt
, 2 );
448 return pt
[1].x
- pt
[0].x
;
451 /***********************************************************************
454 * Performs a world-to-viewport transformation on the specified height.
456 INT
X11DRV_YWStoDS( X11DRV_PDEVICE
*physDev
, INT height
)
464 LPtoDP( physDev
->hdc
, pt
, 2 );
465 return pt
[1].y
- pt
[0].y
;
468 /***********************************************************************
472 X11DRV_LineTo( X11DRV_PDEVICE
*physDev
, INT x
, INT y
)
476 if (X11DRV_SetupGCForPen( physDev
)) {
477 /* Update the pixmap from the DIB section */
478 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
480 GetCurrentPositionEx( physDev
->hdc
, &pt
[0] );
483 LPtoDP( physDev
->hdc
, pt
, 2 );
486 XDrawLine(gdi_display
, physDev
->drawable
, physDev
->gc
,
487 physDev
->dc_rect
.left
+ pt
[0].x
, physDev
->dc_rect
.top
+ pt
[0].y
,
488 physDev
->dc_rect
.left
+ pt
[1].x
, physDev
->dc_rect
.top
+ pt
[1].y
);
491 /* Update the DIBSection from the pixmap */
492 X11DRV_UnlockDIBSection(physDev
, TRUE
);
499 /***********************************************************************
502 * Helper functions for Arc(), Chord() and Pie().
503 * 'lines' is the number of lines to draw: 0 for Arc, 1 for Chord, 2 for Pie.
507 X11DRV_DrawArc( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
,
508 INT bottom
, INT xstart
, INT ystart
,
509 INT xend
, INT yend
, INT lines
)
511 INT xcenter
, ycenter
, istart_angle
, idiff_angle
;
513 double start_angle
, end_angle
;
517 RECT rc
= get_device_rect( physDev
->hdc
, left
, top
, right
, bottom
);
523 LPtoDP(physDev
->hdc
, &start
, 1);
524 LPtoDP(physDev
->hdc
, &end
, 1);
526 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)
527 ||(lines
&& ((rc
.right
-rc
.left
==1)||(rc
.bottom
-rc
.top
==1)))) return TRUE
;
529 if (GetArcDirection( physDev
->hdc
) == AD_CLOCKWISE
)
530 { POINT tmp
= start
; start
= end
; end
= tmp
; }
532 oldwidth
= width
= physDev
->pen
.width
;
533 if (!width
) width
= 1;
534 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
536 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
538 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
539 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
540 rc
.left
+= width
/ 2;
541 rc
.right
-= (width
- 1) / 2;
543 rc
.bottom
-= (width
- 1) / 2;
545 if(width
== 0) width
= 1; /* more accurate */
546 physDev
->pen
.width
= width
;
548 xcenter
= (rc
.right
+ rc
.left
) / 2;
549 ycenter
= (rc
.bottom
+ rc
.top
) / 2;
550 start_angle
= atan2( (double)(ycenter
-start
.y
)*(rc
.right
-rc
.left
),
551 (double)(start
.x
-xcenter
)*(rc
.bottom
-rc
.top
) );
552 end_angle
= atan2( (double)(ycenter
-end
.y
)*(rc
.right
-rc
.left
),
553 (double)(end
.x
-xcenter
)*(rc
.bottom
-rc
.top
) );
554 if ((start
.x
==end
.x
)&&(start
.y
==end
.y
))
555 { /* A lazy program delivers xstart=xend=ystart=yend=0) */
559 else /* notorious cases */
560 if ((start_angle
== PI
)&&( end_angle
<0))
563 if ((end_angle
== PI
)&&( start_angle
<0))
565 istart_angle
= (INT
)(start_angle
* 180 * 64 / PI
+ 0.5);
566 idiff_angle
= (INT
)((end_angle
- start_angle
) * 180 * 64 / PI
+ 0.5);
567 if (idiff_angle
<= 0) idiff_angle
+= 360 * 64;
569 /* Update the pixmap from the DIB section */
570 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
572 /* Fill arc with brush if Chord() or Pie() */
574 if ((lines
> 0) && X11DRV_SetupGCForBrush( physDev
)) {
576 XSetArcMode( gdi_display
, physDev
->gc
, (lines
==1) ? ArcChord
: ArcPieSlice
);
577 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
578 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
579 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, istart_angle
, idiff_angle
);
584 /* Draw arc and lines */
586 if (X11DRV_SetupGCForPen( physDev
))
589 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
590 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
591 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, istart_angle
, idiff_angle
);
593 /* use the truncated values */
594 start_angle
=(double)istart_angle
*PI
/64./180.;
595 end_angle
=(double)(istart_angle
+idiff_angle
)*PI
/64./180.;
596 /* calculate the endpoints and round correctly */
597 points
[0].x
= (int) floor(physDev
->dc_rect
.left
+ (rc
.right
+rc
.left
)/2.0 +
598 cos(start_angle
) * (rc
.right
-rc
.left
-width
*2+2) / 2. + 0.5);
599 points
[0].y
= (int) floor(physDev
->dc_rect
.top
+ (rc
.top
+rc
.bottom
)/2.0 -
600 sin(start_angle
) * (rc
.bottom
-rc
.top
-width
*2+2) / 2. + 0.5);
601 points
[1].x
= (int) floor(physDev
->dc_rect
.left
+ (rc
.right
+rc
.left
)/2.0 +
602 cos(end_angle
) * (rc
.right
-rc
.left
-width
*2+2) / 2. + 0.5);
603 points
[1].y
= (int) floor(physDev
->dc_rect
.top
+ (rc
.top
+rc
.bottom
)/2.0 -
604 sin(end_angle
) * (rc
.bottom
-rc
.top
-width
*2+2) / 2. + 0.5);
606 /* OK, this stuff is optimized for Xfree86
607 * which is probably the server most used by
608 * wine users. Other X servers will not
609 * display correctly. (eXceed for instance)
610 * so if you feel you must make changes, make sure that
611 * you either use Xfree86 or separate your changes
612 * from these (compile switch or whatever)
616 points
[3] = points
[1];
617 points
[1].x
= physDev
->dc_rect
.left
+ xcenter
;
618 points
[1].y
= physDev
->dc_rect
.top
+ ycenter
;
619 points
[2] = points
[1];
620 dx1
=points
[1].x
-points
[0].x
;
621 dy1
=points
[1].y
-points
[0].y
;
622 if(((rc
.top
-rc
.bottom
) | -2) == -2)
623 if(dy1
>0) points
[1].y
--;
625 if (((-dx1
)*64)<=ABS(dy1
)*37) points
[0].x
--;
626 if(((-dx1
*9))<(dy1
*16)) points
[0].y
--;
627 if( dy1
<0 && ((dx1
*9)) < (dy1
*16)) points
[0].y
--;
629 if(dy1
< 0) points
[0].y
--;
630 if(((rc
.right
-rc
.left
) | -2) == -2) points
[1].x
--;
632 dx1
=points
[3].x
-points
[2].x
;
633 dy1
=points
[3].y
-points
[2].y
;
634 if(((rc
.top
-rc
.bottom
) | -2 ) == -2)
635 if(dy1
< 0) points
[2].y
--;
637 if( dy1
>0) points
[3].y
--;
638 if(((rc
.right
-rc
.left
) | -2) == -2 ) points
[2].x
--;
641 if( dx1
* 64 < dy1
* -37 ) points
[3].x
--;
645 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
646 points
, lines
+1, CoordModeOrigin
);
652 /* Update the DIBSection of the pixmap */
653 X11DRV_UnlockDIBSection(physDev
, update
);
655 physDev
->pen
.width
= oldwidth
;
660 /***********************************************************************
664 X11DRV_Arc( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
665 INT xstart
, INT ystart
, INT xend
, INT yend
)
667 return X11DRV_DrawArc( physDev
, left
, top
, right
, bottom
,
668 xstart
, ystart
, xend
, yend
, 0 );
672 /***********************************************************************
676 X11DRV_Pie( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
677 INT xstart
, INT ystart
, INT xend
, INT yend
)
679 return X11DRV_DrawArc( physDev
, left
, top
, right
, bottom
,
680 xstart
, ystart
, xend
, yend
, 2 );
683 /***********************************************************************
687 X11DRV_Chord( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
,
688 INT xstart
, INT ystart
, INT xend
, INT yend
)
690 return X11DRV_DrawArc( physDev
, left
, top
, right
, bottom
,
691 xstart
, ystart
, xend
, yend
, 1 );
695 /***********************************************************************
699 X11DRV_Ellipse( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
)
703 RECT rc
= get_device_rect( physDev
->hdc
, left
, top
, right
, bottom
);
705 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)) return TRUE
;
707 oldwidth
= width
= physDev
->pen
.width
;
708 if (!width
) width
= 1;
709 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
711 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
713 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
714 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
715 rc
.left
+= width
/ 2;
716 rc
.right
-= (width
- 1) / 2;
718 rc
.bottom
-= (width
- 1) / 2;
720 if(width
== 0) width
= 1; /* more accurate */
721 physDev
->pen
.width
= width
;
723 /* Update the pixmap from the DIB section */
724 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
726 if (X11DRV_SetupGCForBrush( physDev
))
729 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
730 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
731 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, 0, 360*64 );
735 if (X11DRV_SetupGCForPen( physDev
))
738 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
739 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
740 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1, 0, 360*64 );
745 /* Update the DIBSection from the pixmap */
746 X11DRV_UnlockDIBSection(physDev
, update
);
748 physDev
->pen
.width
= oldwidth
;
753 /***********************************************************************
757 X11DRV_Rectangle(X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
, INT bottom
)
759 INT width
, oldwidth
, oldjoinstyle
;
761 RECT rc
= get_device_rect( physDev
->hdc
, left
, top
, right
, bottom
);
763 TRACE("(%d %d %d %d)\n", left
, top
, right
, bottom
);
765 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
)) return TRUE
;
767 oldwidth
= width
= physDev
->pen
.width
;
768 if (!width
) width
= 1;
769 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
771 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
773 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
774 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
775 rc
.left
+= width
/ 2;
776 rc
.right
-= (width
- 1) / 2;
778 rc
.bottom
-= (width
- 1) / 2;
780 if(width
== 1) width
= 0;
781 physDev
->pen
.width
= width
;
782 oldjoinstyle
= physDev
->pen
.linejoin
;
783 if(physDev
->pen
.type
!= PS_GEOMETRIC
)
784 physDev
->pen
.linejoin
= PS_JOIN_MITER
;
786 /* Update the pixmap from the DIB section */
787 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
789 if ((rc
.right
> rc
.left
+ width
) && (rc
.bottom
> rc
.top
+ width
))
791 if (X11DRV_SetupGCForBrush( physDev
))
794 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
795 physDev
->dc_rect
.left
+ rc
.left
+ (width
+ 1) / 2,
796 physDev
->dc_rect
.top
+ rc
.top
+ (width
+ 1) / 2,
797 rc
.right
-rc
.left
-width
-1, rc
.bottom
-rc
.top
-width
-1);
802 if (X11DRV_SetupGCForPen( physDev
))
805 XDrawRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
806 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
807 rc
.right
-rc
.left
-1, rc
.bottom
-rc
.top
-1 );
812 /* Update the DIBSection from the pixmap */
813 X11DRV_UnlockDIBSection(physDev
, update
);
815 physDev
->pen
.width
= oldwidth
;
816 physDev
->pen
.linejoin
= oldjoinstyle
;
820 /***********************************************************************
824 X11DRV_RoundRect( X11DRV_PDEVICE
*physDev
, INT left
, INT top
, INT right
,
825 INT bottom
, INT ell_width
, INT ell_height
)
827 INT width
, oldwidth
, oldendcap
;
830 RECT rc
= get_device_rect( physDev
->hdc
, left
, top
, right
, bottom
);
832 TRACE("(%d %d %d %d %d %d\n",
833 left
, top
, right
, bottom
, ell_width
, ell_height
);
835 if ((rc
.left
== rc
.right
) || (rc
.top
== rc
.bottom
))
838 /* Make sure ell_width and ell_height are >= 1 otherwise XDrawArc gets
839 called with width/height < 0 */
840 pts
[0].x
= pts
[0].y
= 0;
841 pts
[1].x
= ell_width
;
842 pts
[1].y
= ell_height
;
843 LPtoDP(physDev
->hdc
, pts
, 2);
844 ell_width
= max(abs( pts
[1].x
- pts
[0].x
), 1);
845 ell_height
= max(abs( pts
[1].y
- pts
[0].y
), 1);
847 oldwidth
= width
= physDev
->pen
.width
;
848 oldendcap
= physDev
->pen
.endcap
;
849 if (!width
) width
= 1;
850 if(physDev
->pen
.style
== PS_NULL
) width
= 0;
852 if ((physDev
->pen
.style
== PS_INSIDEFRAME
))
854 if (2*width
> (rc
.right
-rc
.left
)) width
=(rc
.right
-rc
.left
+ 1)/2;
855 if (2*width
> (rc
.bottom
-rc
.top
)) width
=(rc
.bottom
-rc
.top
+ 1)/2;
856 rc
.left
+= width
/ 2;
857 rc
.right
-= (width
- 1) / 2;
859 rc
.bottom
-= (width
- 1) / 2;
861 if(width
== 0) width
= 1;
862 physDev
->pen
.width
= width
;
863 physDev
->pen
.endcap
= PS_ENDCAP_SQUARE
;
865 /* Update the pixmap from the DIB section */
866 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
868 if (X11DRV_SetupGCForBrush( physDev
))
871 if (ell_width
> (rc
.right
-rc
.left
) )
872 if (ell_height
> (rc
.bottom
-rc
.top
) )
873 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
874 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
875 rc
.right
- rc
.left
- 1, rc
.bottom
- rc
.top
- 1,
878 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
879 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
880 rc
.right
- rc
.left
- 1, ell_height
, 0, 180 * 64 );
881 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
882 physDev
->dc_rect
.left
+ rc
.left
,
883 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
884 rc
.right
- rc
.left
- 1, ell_height
, 180 * 64,
887 else if (ell_height
> (rc
.bottom
-rc
.top
) ){
888 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
889 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
890 ell_width
, rc
.bottom
- rc
.top
- 1, 90 * 64, 180 * 64 );
891 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
892 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1, physDev
->dc_rect
.top
+ rc
.top
,
893 ell_width
, rc
.bottom
- rc
.top
- 1, 270 * 64, 180 * 64 );
895 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
896 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
897 ell_width
, ell_height
, 90 * 64, 90 * 64 );
898 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
899 physDev
->dc_rect
.left
+ rc
.left
,
900 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
901 ell_width
, ell_height
, 180 * 64, 90 * 64 );
902 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
903 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1,
904 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
- 1,
905 ell_width
, ell_height
, 270 * 64, 90 * 64 );
906 XFillArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
907 physDev
->dc_rect
.left
+ rc
.right
- ell_width
- 1,
908 physDev
->dc_rect
.top
+ rc
.top
,
909 ell_width
, ell_height
, 0, 90 * 64 );
911 if (ell_width
< rc
.right
- rc
.left
)
913 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
914 physDev
->dc_rect
.left
+ rc
.left
+ (ell_width
+ 1) / 2,
915 physDev
->dc_rect
.top
+ rc
.top
+ 1,
916 rc
.right
- rc
.left
- ell_width
- 1,
917 (ell_height
+ 1) / 2 - 1);
918 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
919 physDev
->dc_rect
.left
+ rc
.left
+ (ell_width
+ 1) / 2,
920 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
) / 2 - 1,
921 rc
.right
- rc
.left
- ell_width
- 1,
924 if (ell_height
< rc
.bottom
- rc
.top
)
926 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
927 physDev
->dc_rect
.left
+ rc
.left
+ 1,
928 physDev
->dc_rect
.top
+ rc
.top
+ (ell_height
+ 1) / 2,
929 rc
.right
- rc
.left
- 2,
930 rc
.bottom
- rc
.top
- ell_height
- 1);
935 /* FIXME: this could be done with on X call
936 * more efficient and probably more correct
937 * on any X server: XDrawArcs will draw
938 * straight horizontal and vertical lines
939 * if width or height are zero.
941 * BTW this stuff is optimized for an Xfree86 server
942 * read the comments inside the X11DRV_DrawArc function
944 if (X11DRV_SetupGCForPen( physDev
))
947 if (ell_width
> (rc
.right
-rc
.left
) )
948 if (ell_height
> (rc
.bottom
-rc
.top
) )
949 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
950 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
951 rc
.right
- rc
.left
- 1, rc
.bottom
- rc
.top
- 1, 0 , 360 * 64 );
953 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
954 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
955 rc
.right
- rc
.left
- 1, ell_height
- 1, 0 , 180 * 64 );
956 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
957 physDev
->dc_rect
.left
+ rc
.left
,
958 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
959 rc
.right
- rc
.left
- 1, ell_height
- 1, 180 * 64 , 180 * 64 );
961 else if (ell_height
> (rc
.bottom
-rc
.top
) ){
962 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
963 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
964 ell_width
- 1 , rc
.bottom
- rc
.top
- 1, 90 * 64 , 180 * 64 );
965 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
966 physDev
->dc_rect
.left
+ rc
.right
- ell_width
,
967 physDev
->dc_rect
.top
+ rc
.top
,
968 ell_width
- 1 , rc
.bottom
- rc
.top
- 1, 270 * 64 , 180 * 64 );
970 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
971 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.top
,
972 ell_width
- 1, ell_height
- 1, 90 * 64, 90 * 64 );
973 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
974 physDev
->dc_rect
.left
+ rc
.left
, physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
975 ell_width
- 1, ell_height
- 1, 180 * 64, 90 * 64 );
976 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
977 physDev
->dc_rect
.left
+ rc
.right
- ell_width
,
978 physDev
->dc_rect
.top
+ rc
.bottom
- ell_height
,
979 ell_width
- 1, ell_height
- 1, 270 * 64, 90 * 64 );
980 XDrawArc( gdi_display
, physDev
->drawable
, physDev
->gc
,
981 physDev
->dc_rect
.left
+ rc
.right
- ell_width
, physDev
->dc_rect
.top
+ rc
.top
,
982 ell_width
- 1, ell_height
- 1, 0, 90 * 64 );
984 if (ell_width
< rc
.right
- rc
.left
)
986 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
987 physDev
->dc_rect
.left
+ rc
.left
+ ell_width
/ 2,
988 physDev
->dc_rect
.top
+ rc
.top
,
989 physDev
->dc_rect
.left
+ rc
.right
- (ell_width
+1) / 2,
990 physDev
->dc_rect
.top
+ rc
.top
);
991 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
992 physDev
->dc_rect
.left
+ rc
.left
+ ell_width
/ 2 ,
993 physDev
->dc_rect
.top
+ rc
.bottom
- 1,
994 physDev
->dc_rect
.left
+ rc
.right
- (ell_width
+1)/ 2,
995 physDev
->dc_rect
.top
+ rc
.bottom
- 1);
997 if (ell_height
< rc
.bottom
- rc
.top
)
999 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
1000 physDev
->dc_rect
.left
+ rc
.right
- 1,
1001 physDev
->dc_rect
.top
+ rc
.top
+ ell_height
/ 2,
1002 physDev
->dc_rect
.left
+ rc
.right
- 1,
1003 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
+1) / 2);
1004 XDrawLine( gdi_display
, physDev
->drawable
, physDev
->gc
,
1005 physDev
->dc_rect
.left
+ rc
.left
,
1006 physDev
->dc_rect
.top
+ rc
.top
+ ell_height
/ 2,
1007 physDev
->dc_rect
.left
+ rc
.left
,
1008 physDev
->dc_rect
.top
+ rc
.bottom
- (ell_height
+1) / 2);
1010 wine_tsx11_unlock();
1013 /* Update the DIBSection from the pixmap */
1014 X11DRV_UnlockDIBSection(physDev
, update
);
1016 physDev
->pen
.width
= oldwidth
;
1017 physDev
->pen
.endcap
= oldendcap
;
1022 /***********************************************************************
1026 X11DRV_SetPixel( X11DRV_PDEVICE
*physDev
, INT x
, INT y
, COLORREF color
)
1028 unsigned long pixel
;
1033 LPtoDP( physDev
->hdc
, &pt
, 1 );
1034 pixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1036 /* Update the pixmap from the DIB section */
1037 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1039 /* inefficient but simple... */
1041 XSetForeground( gdi_display
, physDev
->gc
, pixel
);
1042 XSetFunction( gdi_display
, physDev
->gc
, GXcopy
);
1043 XDrawPoint( gdi_display
, physDev
->drawable
, physDev
->gc
,
1044 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
);
1045 wine_tsx11_unlock();
1047 /* Update the DIBSection from the pixmap */
1048 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1050 return X11DRV_PALETTE_ToLogical(physDev
, pixel
);
1054 /***********************************************************************
1058 X11DRV_GetPixel( X11DRV_PDEVICE
*physDev
, INT x
, INT y
)
1060 static Pixmap pixmap
= 0;
1064 BOOL memdc
= (GetObjectType(physDev
->hdc
) == OBJ_MEMDC
);
1068 LPtoDP( physDev
->hdc
, &pt
, 1 );
1070 /* Update the pixmap from the DIB section */
1071 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1076 image
= XGetImage( gdi_display
, physDev
->drawable
,
1077 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
,
1078 1, 1, AllPlanes
, ZPixmap
);
1082 /* If we are reading from the screen, use a temporary copy */
1083 /* to avoid a BadMatch error */
1084 if (!pixmap
) pixmap
= XCreatePixmap( gdi_display
, root_window
,
1085 1, 1, physDev
->depth
);
1086 XCopyArea( gdi_display
, physDev
->drawable
, pixmap
, get_bitmap_gc(physDev
->depth
),
1087 physDev
->dc_rect
.left
+ pt
.x
, physDev
->dc_rect
.top
+ pt
.y
, 1, 1, 0, 0 );
1088 image
= XGetImage( gdi_display
, pixmap
, 0, 0, 1, 1, AllPlanes
, ZPixmap
);
1090 pixel
= XGetPixel( image
, 0, 0 );
1091 XDestroyImage( image
);
1092 wine_tsx11_unlock();
1094 /* Update the DIBSection from the pixmap */
1095 X11DRV_UnlockDIBSection(physDev
, FALSE
);
1096 if( physDev
->depth
> 1)
1097 pixel
= X11DRV_PALETTE_ToLogical(physDev
, pixel
);
1099 /* monochrome bitmaps return black or white */
1100 if( pixel
) pixel
= 0xffffff;
1106 /***********************************************************************
1110 X11DRV_PaintRgn( X11DRV_PDEVICE
*physDev
, HRGN hrgn
)
1112 if (X11DRV_SetupGCForBrush( physDev
))
1116 RGNDATA
*data
= X11DRV_GetRegionData( hrgn
, physDev
->hdc
);
1118 if (!data
) return FALSE
;
1119 rect
= (XRectangle
*)data
->Buffer
;
1120 for (i
= 0; i
< data
->rdh
.nCount
; i
++)
1122 rect
[i
].x
+= physDev
->dc_rect
.left
;
1123 rect
[i
].y
+= physDev
->dc_rect
.top
;
1126 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1128 XFillRectangles( gdi_display
, physDev
->drawable
, physDev
->gc
, rect
, data
->rdh
.nCount
);
1129 wine_tsx11_unlock();
1130 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1131 HeapFree( GetProcessHeap(), 0, data
);
1136 /**********************************************************************
1140 X11DRV_Polyline( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, INT count
)
1145 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * count
)))
1147 WARN("No memory to convert POINTs to XPoints!\n");
1150 for (i
= 0; i
< count
; i
++)
1153 LPtoDP(physDev
->hdc
, &tmp
, 1);
1154 points
[i
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1155 points
[i
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1158 if (X11DRV_SetupGCForPen ( physDev
))
1160 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1162 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1163 points
, count
, CoordModeOrigin
);
1164 wine_tsx11_unlock();
1165 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1168 HeapFree( GetProcessHeap(), 0, points
);
1173 /**********************************************************************
1177 X11DRV_Polygon( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, INT count
)
1181 BOOL update
= FALSE
;
1183 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * (count
+1) )))
1185 WARN("No memory to convert POINTs to XPoints!\n");
1188 for (i
= 0; i
< count
; i
++)
1191 LPtoDP(physDev
->hdc
, &tmp
, 1);
1192 points
[i
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1193 points
[i
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1195 points
[count
] = points
[0];
1197 /* Update the pixmap from the DIB section */
1198 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1200 if (X11DRV_SetupGCForBrush( physDev
))
1203 XFillPolygon( gdi_display
, physDev
->drawable
, physDev
->gc
,
1204 points
, count
+1, Complex
, CoordModeOrigin
);
1205 wine_tsx11_unlock();
1208 if (X11DRV_SetupGCForPen ( physDev
))
1211 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1212 points
, count
+1, CoordModeOrigin
);
1213 wine_tsx11_unlock();
1217 /* Update the DIBSection from the pixmap */
1218 X11DRV_UnlockDIBSection(physDev
, update
);
1220 HeapFree( GetProcessHeap(), 0, points
);
1225 /**********************************************************************
1226 * X11DRV_PolyPolygon
1229 X11DRV_PolyPolygon( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, const INT
* counts
, UINT polygons
)
1233 /* FIXME: The points should be converted to device coords before */
1234 /* creating the region. */
1236 hrgn
= CreatePolyPolygonRgn( pt
, counts
, polygons
, GetPolyFillMode( physDev
->hdc
) );
1237 X11DRV_PaintRgn( physDev
, hrgn
);
1238 DeleteObject( hrgn
);
1240 /* Draw the outline of the polygons */
1242 if (X11DRV_SetupGCForPen ( physDev
))
1248 /* Update the pixmap from the DIB section */
1249 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1251 for (i
= 0; i
< polygons
; i
++) if (counts
[i
] > max
) max
= counts
[i
];
1252 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * (max
+1) )))
1254 WARN("No memory to convert POINTs to XPoints!\n");
1257 for (i
= 0; i
< polygons
; i
++)
1259 for (j
= 0; j
< counts
[i
]; j
++)
1262 LPtoDP(physDev
->hdc
, &tmp
, 1);
1263 points
[j
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1264 points
[j
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1267 points
[j
] = points
[0];
1269 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1270 points
, j
+ 1, CoordModeOrigin
);
1271 wine_tsx11_unlock();
1274 /* Update the DIBSection of the dc's bitmap */
1275 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1277 HeapFree( GetProcessHeap(), 0, points
);
1283 /**********************************************************************
1284 * X11DRV_PolyPolyline
1287 X11DRV_PolyPolyline( X11DRV_PDEVICE
*physDev
, const POINT
* pt
, const DWORD
* counts
, DWORD polylines
)
1289 if (X11DRV_SetupGCForPen ( physDev
))
1291 unsigned int i
, j
, max
= 0;
1294 /* Update the pixmap from the DIB section */
1295 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1297 for (i
= 0; i
< polylines
; i
++) if (counts
[i
] > max
) max
= counts
[i
];
1298 if (!(points
= HeapAlloc( GetProcessHeap(), 0, sizeof(XPoint
) * max
)))
1300 WARN("No memory to convert POINTs to XPoints!\n");
1303 for (i
= 0; i
< polylines
; i
++)
1305 for (j
= 0; j
< counts
[i
]; j
++)
1308 LPtoDP(physDev
->hdc
, &tmp
, 1);
1309 points
[j
].x
= physDev
->dc_rect
.left
+ tmp
.x
;
1310 points
[j
].y
= physDev
->dc_rect
.top
+ tmp
.y
;
1314 XDrawLines( gdi_display
, physDev
->drawable
, physDev
->gc
,
1315 points
, j
, CoordModeOrigin
);
1316 wine_tsx11_unlock();
1319 /* Update the DIBSection of the dc's bitmap */
1320 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1322 HeapFree( GetProcessHeap(), 0, points
);
1328 /**********************************************************************
1329 * X11DRV_InternalFloodFill
1331 * Internal helper function for flood fill.
1332 * (xorg,yorg) is the origin of the X image relative to the drawable.
1333 * (x,y) is relative to the origin of the X image.
1335 static void X11DRV_InternalFloodFill(XImage
*image
, X11DRV_PDEVICE
*physDev
,
1338 unsigned long pixel
, WORD fillType
)
1342 #define TO_FLOOD(x,y) ((fillType == FLOODFILLBORDER) ? \
1343 (XGetPixel(image,x,y) != pixel) : \
1344 (XGetPixel(image,x,y) == pixel))
1346 if (!TO_FLOOD(x
,y
)) return;
1348 /* Find left and right boundaries */
1351 while ((left
> 0) && TO_FLOOD( left
-1, y
)) left
--;
1352 while ((right
< image
->width
) && TO_FLOOD( right
, y
)) right
++;
1353 XFillRectangle( gdi_display
, physDev
->drawable
, physDev
->gc
,
1354 xOrg
+ left
, yOrg
+ y
, right
-left
, 1 );
1356 /* Set the pixels of this line so we don't fill it again */
1358 for (x
= left
; x
< right
; x
++)
1360 if (fillType
== FLOODFILLBORDER
) XPutPixel( image
, x
, y
, pixel
);
1361 else XPutPixel( image
, x
, y
, ~pixel
);
1364 /* Fill the line above */
1371 while ((x
< right
) && !TO_FLOOD(x
,y
)) x
++;
1372 if (x
>= right
) break;
1373 while ((x
< right
) && TO_FLOOD(x
,y
)) x
++;
1374 X11DRV_InternalFloodFill(image
, physDev
, x
-1, y
,
1375 xOrg
, yOrg
, pixel
, fillType
);
1379 /* Fill the line below */
1381 if ((y
+= 2) < image
->height
)
1386 while ((x
< right
) && !TO_FLOOD(x
,y
)) x
++;
1387 if (x
>= right
) break;
1388 while ((x
< right
) && TO_FLOOD(x
,y
)) x
++;
1389 X11DRV_InternalFloodFill(image
, physDev
, x
-1, y
,
1390 xOrg
, yOrg
, pixel
, fillType
);
1397 static int ExtFloodFillXGetImageErrorHandler( Display
*dpy
, XErrorEvent
*event
, void *arg
)
1399 return (event
->request_code
== X_GetImage
&& event
->error_code
== BadMatch
);
1402 /**********************************************************************
1403 * X11DRV_ExtFloodFill
1406 X11DRV_ExtFloodFill( X11DRV_PDEVICE
*physDev
, INT x
, INT y
, COLORREF color
,
1413 TRACE("X11DRV_ExtFloodFill %d,%d %06x %d\n", x
, y
, color
, fillType
);
1417 LPtoDP( physDev
->hdc
, &pt
, 1 );
1418 if (!PtInRegion( physDev
->region
, pt
.x
, pt
.y
)) return FALSE
;
1419 GetRgnBox( physDev
->region
, &rect
);
1421 X11DRV_expect_error( gdi_display
, ExtFloodFillXGetImageErrorHandler
, NULL
);
1422 image
= XGetImage( gdi_display
, physDev
->drawable
,
1423 physDev
->dc_rect
.left
+ rect
.left
, physDev
->dc_rect
.top
+ rect
.top
,
1424 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
1425 AllPlanes
, ZPixmap
);
1426 if(X11DRV_check_error()) image
= NULL
;
1427 if (!image
) return FALSE
;
1429 if (X11DRV_SetupGCForBrush( physDev
))
1431 unsigned long pixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1433 /* Update the pixmap from the DIB section */
1434 X11DRV_LockDIBSection(physDev
, DIB_Status_GdiMod
);
1436 /* ROP mode is always GXcopy for flood-fill */
1438 XSetFunction( gdi_display
, physDev
->gc
, GXcopy
);
1439 X11DRV_InternalFloodFill(image
, physDev
,
1442 physDev
->dc_rect
.left
+ rect
.left
,
1443 physDev
->dc_rect
.top
+ rect
.top
,
1445 wine_tsx11_unlock();
1446 /* Update the DIBSection of the dc's bitmap */
1447 X11DRV_UnlockDIBSection(physDev
, TRUE
);
1451 XDestroyImage( image
);
1452 wine_tsx11_unlock();
1456 /**********************************************************************
1460 X11DRV_SetBkColor( X11DRV_PDEVICE
*physDev
, COLORREF color
)
1462 physDev
->backgroundPixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1466 /**********************************************************************
1467 * X11DRV_SetTextColor
1470 X11DRV_SetTextColor( X11DRV_PDEVICE
*physDev
, COLORREF color
)
1472 physDev
->textPixel
= X11DRV_PALETTE_ToPhysical( physDev
, color
);
1477 static unsigned char *get_icm_profile( unsigned long *size
)
1481 unsigned long count
, remaining
;
1482 unsigned char *profile
, *ret
= NULL
;
1485 XGetWindowProperty( gdi_display
, DefaultRootWindow(gdi_display
),
1486 x11drv_atom(_ICC_PROFILE
), 0, ~0UL, False
, AnyPropertyType
,
1487 &type
, &format
, &count
, &remaining
, &profile
);
1488 *size
= get_property_size( format
, count
);
1489 if (format
&& count
)
1491 if ((ret
= HeapAlloc( GetProcessHeap(), 0, *size
))) memcpy( ret
, profile
, *size
);
1494 wine_tsx11_unlock();
1500 unsigned int unknown
[6];
1501 unsigned int state
[5];
1502 unsigned int count
[2];
1503 unsigned char buffer
[64];
1506 extern void WINAPI
A_SHAInit( sha_ctx
* );
1507 extern void WINAPI
A_SHAUpdate( sha_ctx
*, const unsigned char *, unsigned int );
1508 extern void WINAPI
A_SHAFinal( sha_ctx
*, unsigned char * );
1510 /***********************************************************************
1511 * GetICMProfile (X11DRV.@)
1513 BOOL CDECL
X11DRV_GetICMProfile( X11DRV_PDEVICE
*physDev
, LPDWORD size
, LPWSTR filename
)
1515 static const WCHAR path
[] =
1516 {'\\','s','p','o','o','l','\\','d','r','i','v','e','r','s',
1517 '\\','c','o','l','o','r','\\',0};
1518 static const WCHAR srgb
[] =
1519 {'s','R','G','B',' ','C','o','l','o','r',' ','S','p','a','c','e',' ',
1520 'P','r','o','f','i','l','e','.','i','c','m',0};
1521 static const WCHAR mntr
[] =
1522 {'S','o','f','t','w','a','r','e','\\','M','i','c','r','o','s','o','f','t','\\',
1523 'W','i','n','d','o','w','s',' ','N','T','\\','C','u','r','r','e','n','t',
1524 'V','e','r','s','i','o','n','\\','I','C','M','\\','m','n','t','r',0};
1527 DWORD required
, len
;
1528 WCHAR profile
[MAX_PATH
], fullname
[2*MAX_PATH
+ sizeof(path
)/sizeof(WCHAR
)];
1529 unsigned char *buffer
;
1530 unsigned long buflen
;
1532 if (!size
) return FALSE
;
1534 GetSystemDirectoryW( fullname
, MAX_PATH
);
1535 strcatW( fullname
, path
);
1537 len
= sizeof(profile
)/sizeof(WCHAR
);
1538 if (!RegCreateKeyExW( HKEY_LOCAL_MACHINE
, mntr
, 0, NULL
, 0, KEY_ALL_ACCESS
, NULL
, &hkey
, NULL
) &&
1539 !RegEnumValueW( hkey
, 0, profile
, &len
, NULL
, NULL
, NULL
, NULL
)) /* FIXME handle multiple values */
1541 strcatW( fullname
, profile
);
1542 RegCloseKey( hkey
);
1544 else if ((buffer
= get_icm_profile( &buflen
)))
1546 static const WCHAR fmt
[] = {'%','0','2','x',0};
1547 static const WCHAR icm
[] = {'.','i','c','m',0};
1549 unsigned char sha1sum
[20];
1555 A_SHAUpdate( &ctx
, buffer
, buflen
);
1556 A_SHAFinal( &ctx
, sha1sum
);
1558 for (i
= 0; i
< sizeof(sha1sum
); i
++) sprintfW( &profile
[i
* 2], fmt
, sha1sum
[i
] );
1559 memcpy( &profile
[i
* 2], icm
, sizeof(icm
) );
1561 strcatW( fullname
, profile
);
1562 file
= CreateFileW( fullname
, GENERIC_WRITE
, 0, NULL
, CREATE_NEW
, 0, 0 );
1563 if (file
!= INVALID_HANDLE_VALUE
)
1567 if (!WriteFile( file
, buffer
, buflen
, &written
, NULL
) || written
!= buflen
)
1568 ERR( "Unable to write color profile\n" );
1569 CloseHandle( file
);
1571 HeapFree( GetProcessHeap(), 0, buffer
);
1573 else strcatW( fullname
, srgb
);
1575 required
= strlenW( fullname
) + 1;
1576 if (*size
< required
)
1579 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1584 strcpyW( filename
, fullname
);
1585 if (GetFileAttributesW( filename
) == INVALID_FILE_ATTRIBUTES
)
1586 WARN( "color profile not found\n" );