Do not clip source rectangle even by visible region for bitblts.
[wine] / graphics / x11drv / init.c
1 /*
2  * X11 graphics driver initialisation functions
3  *
4  * Copyright 1996 Alexandre Julliard
5  */
6
7 #include <string.h>
8 #include "x11drv.h"
9 #include "color.h"
10 #include "bitmap.h"
11
12
13 static BOOL32 X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
14                                LPCSTR output, const DEVMODE16* initData );
15 static BOOL32 X11DRV_DeleteDC( DC *dc );
16
17 static INT32 X11DRV_Escape( DC *dc, INT32 nEscape, INT32 cbInput,
18                             SEGPTR lpInData, SEGPTR lpOutData );
19
20 static const DC_FUNCTIONS X11DRV_Funcs =
21 {
22     X11DRV_Arc,                      /* pArc */
23     X11DRV_BitBlt,                   /* pBitBlt */
24     X11DRV_Chord,                    /* pChord */
25     X11DRV_CreateDC,                 /* pCreateDC */
26     X11DRV_DeleteDC,                 /* pDeleteDC */
27     NULL,                            /* pDeleteObject */
28     X11DRV_Ellipse,                  /* pEllipse */
29     X11DRV_EnumDeviceFonts,          /* pEnumDeviceFonts */
30     X11DRV_Escape,                   /* pEscape */
31     NULL,                            /* pExcludeClipRect */
32     NULL,                            /* pExcludeVisRect */
33     X11DRV_ExtFloodFill,             /* pExtFloodFill */
34     X11DRV_ExtTextOut,               /* pExtTextOut */
35     X11DRV_GetCharWidth,             /* pGetCharWidth */
36     X11DRV_GetPixel,                 /* pGetPixel */
37     X11DRV_GetTextExtentPoint,       /* pGetTextExtentPoint */
38     X11DRV_GetTextMetrics,           /* pGetTextMetrics */
39     NULL,                            /* pIntersectClipRect */
40     NULL,                            /* pIntersectVisRect */
41     X11DRV_LineTo,                   /* pLineTo */
42     X11DRV_MoveToEx,                 /* pMoveToEx */
43     NULL,                            /* pOffsetClipRgn */
44     NULL,                            /* pOffsetViewportOrg (optional) */
45     NULL,                            /* pOffsetWindowOrg (optional) */
46     X11DRV_PaintRgn,                 /* pPaintRgn */
47     X11DRV_PatBlt,                   /* pPatBlt */
48     X11DRV_Pie,                      /* pPie */
49     X11DRV_PolyPolygon,              /* pPolyPolygon */
50     X11DRV_PolyPolyline,             /* pPolyPolyline */
51     X11DRV_Polygon,                  /* pPolygon */
52     X11DRV_Polyline,                 /* pPolyline */
53     X11DRV_PolyBezier,               /* pPolyBezier */
54     NULL,                            /* pRealizePalette */
55     X11DRV_Rectangle,                /* pRectangle */
56     NULL,                            /* pRestoreDC */
57     X11DRV_RoundRect,                /* pRoundRect */
58     NULL,                            /* pSaveDC */
59     NULL,                            /* pScaleViewportExt (optional) */
60     NULL,                            /* pScaleWindowExt (optional) */
61     NULL,                            /* pSelectClipRgn */
62     X11DRV_SelectObject,             /* pSelectObject */
63     NULL,                            /* pSelectPalette */
64     X11DRV_SetBkColor,               /* pSetBkColor */
65     NULL,                            /* pSetBkMode */
66     X11DRV_SetDeviceClipping,        /* pSetDeviceClipping */
67     NULL,                            /* pSetDIBitsToDevice */
68     NULL,                            /* pSetMapMode (optional) */
69     NULL,                            /* pSetMapperFlags */
70     X11DRV_SetPixel,                 /* pSetPixel */
71     NULL,                            /* pSetPolyFillMode */
72     NULL,                            /* pSetROP2 */
73     NULL,                            /* pSetRelAbs */
74     NULL,                            /* pSetStretchBltMode */
75     NULL,                            /* pSetTextAlign */
76     NULL,                            /* pSetTextCharacterExtra */
77     X11DRV_SetTextColor,             /* pSetTextColor */
78     NULL,                            /* pSetTextJustification */
79     NULL,                            /* pSetViewportExt (optional) */
80     NULL,                            /* pSetViewportOrg (optional) */
81     NULL,                            /* pSetWindowExt (optional) */
82     NULL,                            /* pSetWindowOrg (optional) */
83     X11DRV_StretchBlt,               /* pStretchBlt */
84     NULL                             /* pStretchDIBits */
85 };
86
87 static DeviceCaps X11DRV_DevCaps = {
88 /* version */           0, 
89 /* technology */        DT_RASDISPLAY,
90 /* size, resolution */  0, 0, 0, 0, 0, 
91 /* device objects */    1, 16 + 6, 16, 0, 0, 100, 0,    
92 /* curve caps */        CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES |
93                         CC_WIDE | CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT,
94 /* line caps */         LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
95                         LC_STYLED | LC_WIDESTYLED | LC_INTERIORS,
96 /* polygon caps */      PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON |
97                         PC_SCANLINE | PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS,
98 /* text caps */         0,
99 /* regions */           CP_REGION,
100 /* raster caps */       RC_BITBLT | RC_BANDING | RC_SCALING | RC_BITMAP64 |
101                         RC_DI_BITMAP | RC_DIBTODEV | RC_BIGFONT | RC_STRETCHBLT | RC_STRETCHDIB | RC_DEVBITS,
102 /* aspects */           36, 36, 51,
103 /* pad1 */              { 0 },
104 /* log pixels */        0, 0, 
105 /* pad2 */              { 0 },
106 /* palette size */      0,
107 /* ..etc */             0, 0 };
108
109 /**********************************************************************
110  *           X11DRV_Init
111  */
112 BOOL32 X11DRV_Init(void)
113 {
114     /* FIXME: colormap management should be merged with the X11DRV */
115
116     if( !COLOR_Init() ) return FALSE;
117
118     /* Finish up device caps */
119
120 #if 0
121     TRACE(x11drv, "Height = %-4i pxl, %-4i mm, Width  = %-4i pxl, %-4i mm\n",
122           HeightOfScreen(screen), HeightMMOfScreen(screen),
123           WidthOfScreen(screen), WidthMMOfScreen(screen) );
124 #endif
125
126     X11DRV_DevCaps.version = 0x300;
127     X11DRV_DevCaps.horzSize = WidthMMOfScreen(screen) * screenWidth / WidthOfScreen(screen);
128     X11DRV_DevCaps.vertSize = HeightMMOfScreen(screen) * screenHeight / HeightOfScreen(screen);
129     X11DRV_DevCaps.horzRes = screenWidth;
130     X11DRV_DevCaps.vertRes = screenHeight;
131     X11DRV_DevCaps.bitsPixel = screenDepth;
132
133     if( COLOR_GetSystemPaletteFlags() & COLOR_VIRTUAL ) 
134         X11DRV_DevCaps.sizePalette = 0;
135     else
136     {
137         X11DRV_DevCaps.rasterCaps |= RC_PALETTE;
138         X11DRV_DevCaps.sizePalette = DefaultVisual(display,DefaultScreen(display))->map_entries;
139     }
140  
141     /* Resolution will be adjusted during the font init */
142
143     X11DRV_DevCaps.logPixelsX = (int)(X11DRV_DevCaps.horzRes * 25.4 / X11DRV_DevCaps.horzSize);
144     X11DRV_DevCaps.logPixelsY = (int)(X11DRV_DevCaps.vertRes * 25.4 / X11DRV_DevCaps.vertSize);
145
146     /* Create default bitmap */
147
148     if (!X11DRV_BITMAP_Init()) return FALSE;
149
150     /* Initialize brush dithering */
151
152     if (!X11DRV_BRUSH_Init()) return FALSE;
153
154     /* Initialize fonts and text caps */
155
156     if (!X11DRV_FONT_Init( &X11DRV_DevCaps )) return FALSE;
157
158     return DRIVER_RegisterDriver( "DISPLAY", &X11DRV_Funcs );
159 }
160
161 /**********************************************************************
162  *           X11DRV_CreateDC
163  */
164 static BOOL32 X11DRV_CreateDC( DC *dc, LPCSTR driver, LPCSTR device,
165                                LPCSTR output, const DEVMODE16* initData )
166 {
167     X11DRV_PDEVICE *physDev;
168
169     physDev = &dc->u.x;  /* for now */
170
171     memset( physDev, 0, sizeof(*physDev) );
172     dc->physDev        = physDev;
173     dc->w.devCaps      = &X11DRV_DevCaps;
174     if (dc->w.flags & DC_MEMORY)
175     {
176         BITMAPOBJ *bmp = (BITMAPOBJ *) GDI_GetObjPtr( dc->w.hBitmap,
177                                                       BITMAP_MAGIC );
178         physDev->drawable  = bmp->pixmap;
179         physDev->gc        = TSXCreateGC( display, physDev->drawable, 0, NULL );
180         dc->w.bitsPerPixel = bmp->bitmap.bmBitsPixel;
181
182         dc->w.totalExtent.left   = 0;
183         dc->w.totalExtent.top    = 0;
184         dc->w.totalExtent.right  = bmp->bitmap.bmWidth;
185         dc->w.totalExtent.bottom = bmp->bitmap.bmHeight;
186         dc->w.hVisRgn            = CreateRectRgnIndirect32( &dc->w.totalExtent );
187
188         GDI_HEAP_UNLOCK( dc->w.hBitmap );
189     }
190     else
191     {
192         physDev->drawable  = rootWindow;
193         physDev->gc        = TSXCreateGC( display, physDev->drawable, 0, NULL );
194         dc->w.bitsPerPixel = screenDepth;
195
196         dc->w.totalExtent.left   = 0;
197         dc->w.totalExtent.top    = 0;
198         dc->w.totalExtent.right  = screenWidth;
199         dc->w.totalExtent.bottom = screenHeight;
200         dc->w.hVisRgn            = CreateRectRgnIndirect32( &dc->w.totalExtent );
201     }
202
203     if (!dc->w.hVisRgn)
204     {
205         TSXFreeGC( display, physDev->gc );
206         return FALSE;
207     }
208
209     TSXSetGraphicsExposures( display, physDev->gc, False );
210     TSXSetSubwindowMode( display, physDev->gc, IncludeInferiors );
211
212     return TRUE;
213 }
214
215
216 /**********************************************************************
217  *           X11DRV_DeleteDC
218  */
219 static BOOL32 X11DRV_DeleteDC( DC *dc )
220 {
221     X11DRV_PDEVICE *physDev = (X11DRV_PDEVICE *)dc->physDev;
222     TSXFreeGC( display, physDev->gc );
223     return TRUE;
224 }
225
226 /**********************************************************************
227  *           X11DRV_Escape
228  */
229 static INT32 X11DRV_Escape( DC *dc, INT32 nEscape, INT32 cbInput,
230                             SEGPTR lpInData, SEGPTR lpOutData )
231 {
232     switch( nEscape )
233     {
234         case GETSCALINGFACTOR:
235              if( lpOutData )
236              {
237                  LPPOINT16 lppt = (LPPOINT16)PTR_SEG_TO_LIN(lpOutData);
238                  lppt->x = lppt->y = 0; /* no device scaling */
239                  return 1;
240              }
241              break;
242     }
243     return 0;
244 }
245