d3dcompiler: Allow D3DCompile2() to succeed with null output shader blob pointer.
[wine.git] / dlls / winex11.drv / pen.c
blob3baf6a0a74e09e89076015270b9224b4155b74d3
1 /*
2 * X11DRV pen objects
4 * Copyright 1993 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #if 0
22 #pragma makedep unix
23 #endif
25 #include "config.h"
27 #include "x11drv.h"
30 static DWORD get_user_dashes( char *res, const DWORD *style, DWORD len )
32 DWORD i, pos, dashes[MAX_DASHLEN];
34 len = min( len, MAX_DASHLEN );
35 memcpy( dashes, style, len * sizeof(DWORD) );
36 for (i = pos = 0; i < len; i++)
38 if (!dashes[i]) /* get rid of 0 entry */
40 if (i < len - 1)
42 i++;
43 if (pos) dashes[pos - 1] += dashes[i];
44 else dashes[len - 1] += dashes[i];
46 else if (pos)
48 dashes[0] += dashes[pos - 1];
49 pos--;
52 else dashes[pos++] = dashes[i];
54 for (i = 0; i < pos; i++) res[i] = (char)min( dashes[i], 255 );
55 return pos;
58 /***********************************************************************
59 * SelectPen (X11DRV.@)
61 HPEN CDECL X11DRV_SelectPen( PHYSDEV dev, HPEN hpen, const struct brush_pattern *pattern )
63 static const char PEN_dash[] = { 16,8 };
64 static const char PEN_dot[] = { 4,4 };
65 static const char PEN_dashdot[] = { 12,8,4,8 };
66 static const char PEN_dashdotdot[] = { 12,4,4,4,4,4 };
67 static const char PEN_alternate[] = { 1,1 };
68 static const char EXTPEN_dash[] = { 3,1 };
69 static const char EXTPEN_dot[] = { 1,1 };
70 static const char EXTPEN_dashdot[] = { 3,1,1,1 };
71 static const char EXTPEN_dashdotdot[] = { 3,1,1,1,1,1 };
72 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
73 LOGPEN logpen;
74 int i;
75 EXTLOGPEN *elp = NULL;
77 if (!NtGdiExtGetObjectW( hpen, sizeof(logpen), &logpen ))
79 /* must be an extended pen */
80 INT size = NtGdiExtGetObjectW( hpen, 0, NULL );
82 if (!size) return 0;
84 physDev->pen.ext = 1;
85 elp = malloc( size );
87 NtGdiExtGetObjectW( hpen, size, elp );
88 logpen.lopnStyle = elp->elpPenStyle;
89 logpen.lopnWidth.x = elp->elpWidth;
90 logpen.lopnWidth.y = 0;
91 logpen.lopnColor = elp->elpColor;
93 else
94 physDev->pen.ext = 0;
96 physDev->pen.style = logpen.lopnStyle & PS_STYLE_MASK;
97 physDev->pen.type = logpen.lopnStyle & PS_TYPE_MASK;
98 physDev->pen.endcap = logpen.lopnStyle & PS_ENDCAP_MASK;
99 physDev->pen.linejoin = logpen.lopnStyle & PS_JOIN_MASK;
101 physDev->pen.width = logpen.lopnWidth.x;
102 if ((logpen.lopnStyle & PS_GEOMETRIC) || (physDev->pen.width >= 1))
104 physDev->pen.width = X11DRV_XWStoDS( dev->hdc, physDev->pen.width );
105 if (physDev->pen.width < 0) physDev->pen.width = -physDev->pen.width;
108 if (physDev->pen.width == 1) physDev->pen.width = 0; /* Faster */
109 if (hpen == GetStockObject( DC_PEN ))
110 NtGdiGetDCDword( dev->hdc, NtGdiGetDCPenColor, &logpen.lopnColor );
111 physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, logpen.lopnColor );
112 switch(logpen.lopnStyle & PS_STYLE_MASK)
114 case PS_DASH:
115 physDev->pen.dash_len = ARRAY_SIZE( PEN_dash );
116 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dash : PEN_dash,
117 physDev->pen.dash_len);
118 break;
119 case PS_DOT:
120 physDev->pen.dash_len = ARRAY_SIZE( PEN_dot );
121 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dot : PEN_dot,
122 physDev->pen.dash_len);
123 break;
124 case PS_DASHDOT:
125 physDev->pen.dash_len = ARRAY_SIZE( PEN_dashdot );
126 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dashdot : PEN_dashdot,
127 physDev->pen.dash_len);
128 break;
129 case PS_DASHDOTDOT:
130 physDev->pen.dash_len = ARRAY_SIZE( PEN_dashdotdot );
131 memcpy(physDev->pen.dashes, physDev->pen.ext ? EXTPEN_dashdotdot : PEN_dashdotdot,
132 physDev->pen.dash_len);
133 break;
134 case PS_ALTERNATE:
135 physDev->pen.dash_len = ARRAY_SIZE( PEN_alternate );
136 memcpy(physDev->pen.dashes, PEN_alternate, physDev->pen.dash_len);
137 break;
138 case PS_USERSTYLE:
139 physDev->pen.dash_len = get_user_dashes( physDev->pen.dashes,
140 elp->elpStyleEntry, elp->elpNumEntries );
141 break;
142 default:
143 physDev->pen.dash_len = 0;
144 break;
146 if(physDev->pen.ext && physDev->pen.dash_len && physDev->pen.width &&
147 (logpen.lopnStyle & PS_STYLE_MASK) != PS_USERSTYLE &&
148 (logpen.lopnStyle & PS_STYLE_MASK) != PS_ALTERNATE)
149 for(i = 0; i < physDev->pen.dash_len; i++)
150 physDev->pen.dashes[i] = (char)min( physDev->pen.dashes[i] * physDev->pen.width, 255 );
152 free( elp );
154 return hpen;
158 /***********************************************************************
159 * SetDCPenColor (X11DRV.@)
161 COLORREF CDECL X11DRV_SetDCPenColor( PHYSDEV dev, COLORREF crColor )
163 X11DRV_PDEVICE *physDev = get_x11drv_dev( dev );
165 if (NtGdiGetDCObject( dev->hdc, NTGDI_OBJ_PEN ) == GetStockObject( DC_PEN ))
166 physDev->pen.pixel = X11DRV_PALETTE_ToPhysical( physDev, crColor );
168 return crColor;