2 * Copyright 2014 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "wine/port.h"
22 #include "d2d1_private.h"
24 WINE_DEFAULT_DEBUG_CHANNEL(d2d
);
26 static inline struct d2d_gradient
*impl_from_ID2D1GradientStopCollection(ID2D1GradientStopCollection
*iface
)
28 return CONTAINING_RECORD(iface
, struct d2d_gradient
, ID2D1GradientStopCollection_iface
);
31 static HRESULT STDMETHODCALLTYPE
d2d_gradient_QueryInterface(ID2D1GradientStopCollection
*iface
,
32 REFIID iid
, void **out
)
34 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
36 if (IsEqualGUID(iid
, &IID_ID2D1GradientStopCollection
)
37 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
38 || IsEqualGUID(iid
, &IID_IUnknown
))
40 ID2D1GradientStopCollection_AddRef(iface
);
45 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
51 static ULONG STDMETHODCALLTYPE
d2d_gradient_AddRef(ID2D1GradientStopCollection
*iface
)
53 struct d2d_gradient
*gradient
= impl_from_ID2D1GradientStopCollection(iface
);
54 ULONG refcount
= InterlockedIncrement(&gradient
->refcount
);
56 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
61 static ULONG STDMETHODCALLTYPE
d2d_gradient_Release(ID2D1GradientStopCollection
*iface
)
63 struct d2d_gradient
*gradient
= impl_from_ID2D1GradientStopCollection(iface
);
64 ULONG refcount
= InterlockedDecrement(&gradient
->refcount
);
66 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
70 heap_free(gradient
->stops
);
71 ID3D10ShaderResourceView_Release(gradient
->view
);
72 ID2D1Factory_Release(gradient
->factory
);
79 static void STDMETHODCALLTYPE
d2d_gradient_GetFactory(ID2D1GradientStopCollection
*iface
, ID2D1Factory
**factory
)
81 struct d2d_gradient
*gradient
= impl_from_ID2D1GradientStopCollection(iface
);
83 TRACE("iface %p, factory %p.\n", iface
, factory
);
85 ID2D1Factory_AddRef(*factory
= gradient
->factory
);
88 static UINT32 STDMETHODCALLTYPE
d2d_gradient_GetGradientStopCount(ID2D1GradientStopCollection
*iface
)
90 struct d2d_gradient
*gradient
= impl_from_ID2D1GradientStopCollection(iface
);
92 TRACE("iface %p.\n", iface
);
94 return gradient
->stop_count
;
97 static void STDMETHODCALLTYPE
d2d_gradient_GetGradientStops(ID2D1GradientStopCollection
*iface
,
98 D2D1_GRADIENT_STOP
*stops
, UINT32 stop_count
)
100 struct d2d_gradient
*gradient
= impl_from_ID2D1GradientStopCollection(iface
);
102 TRACE("iface %p, stops %p, stop_count %u.\n", iface
, stops
, stop_count
);
104 memcpy(stops
, gradient
->stops
, min(gradient
->stop_count
, stop_count
) * sizeof(*stops
));
107 static D2D1_GAMMA STDMETHODCALLTYPE
d2d_gradient_GetColorInterpolationGamma(ID2D1GradientStopCollection
*iface
)
109 FIXME("iface %p stub!\n", iface
);
111 return D2D1_GAMMA_1_0
;
114 static D2D1_EXTEND_MODE STDMETHODCALLTYPE
d2d_gradient_GetExtendMode(ID2D1GradientStopCollection
*iface
)
116 FIXME("iface %p stub!\n", iface
);
118 return D2D1_EXTEND_MODE_CLAMP
;
121 static const struct ID2D1GradientStopCollectionVtbl d2d_gradient_vtbl
=
123 d2d_gradient_QueryInterface
,
125 d2d_gradient_Release
,
126 d2d_gradient_GetFactory
,
127 d2d_gradient_GetGradientStopCount
,
128 d2d_gradient_GetGradientStops
,
129 d2d_gradient_GetColorInterpolationGamma
,
130 d2d_gradient_GetExtendMode
,
133 HRESULT
d2d_gradient_create(ID2D1Factory
*factory
, ID3D10Device
*device
, const D2D1_GRADIENT_STOP
*stops
,
134 UINT32 stop_count
, D2D1_GAMMA gamma
, D2D1_EXTEND_MODE extend_mode
, struct d2d_gradient
**gradient
)
136 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc
;
137 D3D10_SUBRESOURCE_DATA buffer_data
;
138 ID3D10ShaderResourceView
*view
;
139 D3D10_BUFFER_DESC buffer_desc
;
140 struct d2d_vec4
*data
;
141 ID3D10Buffer
*buffer
;
145 if (!(data
= heap_calloc(stop_count
, 2 * sizeof(*data
))))
147 ERR("Failed to allocate data.\n");
148 return E_OUTOFMEMORY
;
151 for (i
= 0; i
< stop_count
; ++i
)
153 data
[i
* 2].x
= stops
[i
].position
;
154 data
[i
* 2 + 1].x
= stops
[i
].color
.r
;
155 data
[i
* 2 + 1].y
= stops
[i
].color
.g
;
156 data
[i
* 2 + 1].z
= stops
[i
].color
.b
;
157 data
[i
* 2 + 1].w
= stops
[i
].color
.a
;
160 buffer_desc
.ByteWidth
= 2 * stop_count
* sizeof(*data
);
161 buffer_desc
.Usage
= D3D10_USAGE_DEFAULT
;
162 buffer_desc
.BindFlags
= D3D10_BIND_SHADER_RESOURCE
;
163 buffer_desc
.CPUAccessFlags
= 0;
164 buffer_desc
.MiscFlags
= 0;
166 buffer_data
.pSysMem
= data
;
167 buffer_data
.SysMemPitch
= 0;
168 buffer_data
.SysMemSlicePitch
= 0;
170 hr
= ID3D10Device_CreateBuffer(device
, &buffer_desc
, &buffer_data
, &buffer
);
174 ERR("Failed to create buffer, hr %#x.\n", hr
);
178 srv_desc
.Format
= DXGI_FORMAT_R32G32B32A32_FLOAT
;
179 srv_desc
.ViewDimension
= D3D10_SRV_DIMENSION_BUFFER
;
180 srv_desc
.Buffer
.ElementOffset
= 0;
181 srv_desc
.Buffer
.ElementWidth
= 2 * stop_count
;
183 hr
= ID3D10Device_CreateShaderResourceView(device
, (ID3D10Resource
*)buffer
, &srv_desc
, &view
);
184 ID3D10Buffer_Release(buffer
);
187 ERR("Failed to create view, hr %#x.\n", hr
);
191 if (!(*gradient
= heap_alloc_zero(sizeof(**gradient
))))
193 ID3D10ShaderResourceView_Release(view
);
194 return E_OUTOFMEMORY
;
197 if (gamma
!= D2D1_GAMMA_2_2
)
198 FIXME("Ignoring gamma %#x.\n", gamma
);
199 if (extend_mode
!= D2D1_EXTEND_MODE_CLAMP
)
200 FIXME("Ignoring extend mode %#x.\n", extend_mode
);
202 (*gradient
)->ID2D1GradientStopCollection_iface
.lpVtbl
= &d2d_gradient_vtbl
;
203 (*gradient
)->refcount
= 1;
204 ID2D1Factory_AddRef((*gradient
)->factory
= factory
);
205 (*gradient
)->view
= view
;
207 (*gradient
)->stop_count
= stop_count
;
208 if (!((*gradient
)->stops
= heap_calloc(stop_count
, sizeof(*stops
))))
210 ID3D10ShaderResourceView_Release(view
);
211 heap_free(*gradient
);
212 return E_OUTOFMEMORY
;
214 memcpy((*gradient
)->stops
, stops
, stop_count
* sizeof(*stops
));
216 TRACE("Created gradient %p.\n", *gradient
);
220 static struct d2d_gradient
*unsafe_impl_from_ID2D1GradientStopCollection(ID2D1GradientStopCollection
*iface
)
224 assert(iface
->lpVtbl
== &d2d_gradient_vtbl
);
225 return CONTAINING_RECORD(iface
, struct d2d_gradient
, ID2D1GradientStopCollection_iface
);
228 static void d2d_gradient_bind(struct d2d_gradient
*gradient
, ID3D10Device
*device
, unsigned int brush_idx
)
230 ID3D10Device_PSSetShaderResources(device
, 2 + brush_idx
, 1, &gradient
->view
);
233 static void d2d_brush_destroy(struct d2d_brush
*brush
)
235 ID2D1Factory_Release(brush
->factory
);
239 static void d2d_brush_init(struct d2d_brush
*brush
, ID2D1Factory
*factory
,
240 enum d2d_brush_type type
, const D2D1_BRUSH_PROPERTIES
*desc
, const struct ID2D1BrushVtbl
*vtbl
)
242 static const D2D1_MATRIX_3X2_F identity
=
249 brush
->ID2D1Brush_iface
.lpVtbl
= vtbl
;
251 ID2D1Factory_AddRef(brush
->factory
= factory
);
252 brush
->opacity
= desc
? desc
->opacity
: 1.0f
;
253 brush
->transform
= desc
? desc
->transform
: identity
;
257 static inline struct d2d_brush
*impl_from_ID2D1SolidColorBrush(ID2D1SolidColorBrush
*iface
)
259 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
262 static HRESULT STDMETHODCALLTYPE
d2d_solid_color_brush_QueryInterface(ID2D1SolidColorBrush
*iface
,
263 REFIID iid
, void **out
)
265 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
267 if (IsEqualGUID(iid
, &IID_ID2D1SolidColorBrush
)
268 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
269 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
270 || IsEqualGUID(iid
, &IID_IUnknown
))
272 ID2D1SolidColorBrush_AddRef(iface
);
277 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
280 return E_NOINTERFACE
;
283 static ULONG STDMETHODCALLTYPE
d2d_solid_color_brush_AddRef(ID2D1SolidColorBrush
*iface
)
285 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
286 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
288 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
293 static ULONG STDMETHODCALLTYPE
d2d_solid_color_brush_Release(ID2D1SolidColorBrush
*iface
)
295 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
296 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
298 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
301 d2d_brush_destroy(brush
);
306 static void STDMETHODCALLTYPE
d2d_solid_color_brush_GetFactory(ID2D1SolidColorBrush
*iface
, ID2D1Factory
**factory
)
308 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
310 TRACE("iface %p, factory %p.\n", iface
, factory
);
312 ID2D1Factory_AddRef(*factory
= brush
->factory
);
315 static void STDMETHODCALLTYPE
d2d_solid_color_brush_SetOpacity(ID2D1SolidColorBrush
*iface
, float opacity
)
317 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
319 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
321 brush
->opacity
= opacity
;
324 static void STDMETHODCALLTYPE
d2d_solid_color_brush_SetTransform(ID2D1SolidColorBrush
*iface
,
325 const D2D1_MATRIX_3X2_F
*transform
)
327 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
329 TRACE("iface %p, transform %p.\n", iface
, transform
);
331 brush
->transform
= *transform
;
334 static float STDMETHODCALLTYPE
d2d_solid_color_brush_GetOpacity(ID2D1SolidColorBrush
*iface
)
336 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
338 TRACE("iface %p.\n", iface
);
340 return brush
->opacity
;
343 static void STDMETHODCALLTYPE
d2d_solid_color_brush_GetTransform(ID2D1SolidColorBrush
*iface
,
344 D2D1_MATRIX_3X2_F
*transform
)
346 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
348 TRACE("iface %p, transform %p.\n", iface
, transform
);
350 *transform
= brush
->transform
;
353 static void STDMETHODCALLTYPE
d2d_solid_color_brush_SetColor(ID2D1SolidColorBrush
*iface
, const D2D1_COLOR_F
*color
)
355 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
357 TRACE("iface %p, color %p.\n", iface
, color
);
359 brush
->u
.solid
.color
= *color
;
362 static D2D1_COLOR_F
* STDMETHODCALLTYPE
d2d_solid_color_brush_GetColor(ID2D1SolidColorBrush
*iface
, D2D1_COLOR_F
*color
)
364 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
366 TRACE("iface %p, color %p.\n", iface
, color
);
368 *color
= brush
->u
.solid
.color
;
372 static const struct ID2D1SolidColorBrushVtbl d2d_solid_color_brush_vtbl
=
374 d2d_solid_color_brush_QueryInterface
,
375 d2d_solid_color_brush_AddRef
,
376 d2d_solid_color_brush_Release
,
377 d2d_solid_color_brush_GetFactory
,
378 d2d_solid_color_brush_SetOpacity
,
379 d2d_solid_color_brush_SetTransform
,
380 d2d_solid_color_brush_GetOpacity
,
381 d2d_solid_color_brush_GetTransform
,
382 d2d_solid_color_brush_SetColor
,
383 d2d_solid_color_brush_GetColor
,
386 HRESULT
d2d_solid_color_brush_create(ID2D1Factory
*factory
, const D2D1_COLOR_F
*color
,
387 const D2D1_BRUSH_PROPERTIES
*desc
, struct d2d_brush
**brush
)
389 if (!(*brush
= heap_alloc_zero(sizeof(**brush
))))
390 return E_OUTOFMEMORY
;
392 d2d_brush_init(*brush
, factory
, D2D_BRUSH_TYPE_SOLID
, desc
,
393 (ID2D1BrushVtbl
*)&d2d_solid_color_brush_vtbl
);
394 (*brush
)->u
.solid
.color
= *color
;
396 TRACE("Created brush %p.\n", *brush
);
400 static inline struct d2d_brush
*impl_from_ID2D1LinearGradientBrush(ID2D1LinearGradientBrush
*iface
)
402 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
405 static HRESULT STDMETHODCALLTYPE
d2d_linear_gradient_brush_QueryInterface(ID2D1LinearGradientBrush
*iface
,
406 REFIID iid
, void **out
)
408 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
410 if (IsEqualGUID(iid
, &IID_ID2D1LinearGradientBrush
)
411 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
412 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
413 || IsEqualGUID(iid
, &IID_IUnknown
))
415 ID2D1LinearGradientBrush_AddRef(iface
);
420 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
423 return E_NOINTERFACE
;
426 static ULONG STDMETHODCALLTYPE
d2d_linear_gradient_brush_AddRef(ID2D1LinearGradientBrush
*iface
)
428 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
429 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
431 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
436 static ULONG STDMETHODCALLTYPE
d2d_linear_gradient_brush_Release(ID2D1LinearGradientBrush
*iface
)
438 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
439 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
441 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
445 ID2D1GradientStopCollection_Release(&brush
->u
.linear
.gradient
->ID2D1GradientStopCollection_iface
);
446 d2d_brush_destroy(brush
);
452 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetFactory(ID2D1LinearGradientBrush
*iface
,
453 ID2D1Factory
**factory
)
455 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
457 TRACE("iface %p, factory %p.\n", iface
, factory
);
459 ID2D1Factory_AddRef(*factory
= brush
->factory
);
462 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_SetOpacity(ID2D1LinearGradientBrush
*iface
, float opacity
)
464 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
466 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
468 brush
->opacity
= opacity
;
471 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_SetTransform(ID2D1LinearGradientBrush
*iface
,
472 const D2D1_MATRIX_3X2_F
*transform
)
474 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
476 TRACE("iface %p, transform %p.\n", iface
, transform
);
478 brush
->transform
= *transform
;
481 static float STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetOpacity(ID2D1LinearGradientBrush
*iface
)
483 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
485 TRACE("iface %p.\n", iface
);
487 return brush
->opacity
;
490 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetTransform(ID2D1LinearGradientBrush
*iface
,
491 D2D1_MATRIX_3X2_F
*transform
)
493 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
495 TRACE("iface %p, transform %p.\n", iface
, transform
);
497 *transform
= brush
->transform
;
500 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_SetStartPoint(ID2D1LinearGradientBrush
*iface
,
501 D2D1_POINT_2F start_point
)
503 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
505 TRACE("iface %p, start_point {%.8e, %.8e}.\n", iface
, start_point
.x
, start_point
.y
);
507 brush
->u
.linear
.start
= start_point
;
510 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_SetEndPoint(ID2D1LinearGradientBrush
*iface
,
511 D2D1_POINT_2F end_point
)
513 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
515 TRACE("iface %p, end_point {%.8e, %.8e}.\n", iface
, end_point
.x
, end_point
.y
);
517 brush
->u
.linear
.end
= end_point
;
520 static D2D1_POINT_2F
* STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetStartPoint(ID2D1LinearGradientBrush
*iface
,
521 D2D1_POINT_2F
*point
)
523 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
525 TRACE("iface %p, point %p.\n", iface
, point
);
527 *point
= brush
->u
.linear
.start
;
531 static D2D1_POINT_2F
* STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetEndPoint(ID2D1LinearGradientBrush
*iface
,
532 D2D1_POINT_2F
*point
)
534 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
536 TRACE("iface %p, point %p.\n", iface
, point
);
538 *point
= brush
->u
.linear
.end
;
542 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetGradientStopCollection(ID2D1LinearGradientBrush
*iface
,
543 ID2D1GradientStopCollection
**gradient
)
545 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
547 TRACE("iface %p, gradient %p.\n", iface
, gradient
);
549 ID2D1GradientStopCollection_AddRef(*gradient
= &brush
->u
.linear
.gradient
->ID2D1GradientStopCollection_iface
);
552 static const struct ID2D1LinearGradientBrushVtbl d2d_linear_gradient_brush_vtbl
=
554 d2d_linear_gradient_brush_QueryInterface
,
555 d2d_linear_gradient_brush_AddRef
,
556 d2d_linear_gradient_brush_Release
,
557 d2d_linear_gradient_brush_GetFactory
,
558 d2d_linear_gradient_brush_SetOpacity
,
559 d2d_linear_gradient_brush_SetTransform
,
560 d2d_linear_gradient_brush_GetOpacity
,
561 d2d_linear_gradient_brush_GetTransform
,
562 d2d_linear_gradient_brush_SetStartPoint
,
563 d2d_linear_gradient_brush_SetEndPoint
,
564 d2d_linear_gradient_brush_GetStartPoint
,
565 d2d_linear_gradient_brush_GetEndPoint
,
566 d2d_linear_gradient_brush_GetGradientStopCollection
,
569 HRESULT
d2d_linear_gradient_brush_create(ID2D1Factory
*factory
,
570 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES
*gradient_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
571 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
)
573 if (!(*brush
= heap_alloc_zero(sizeof(**brush
))))
574 return E_OUTOFMEMORY
;
576 d2d_brush_init(*brush
, factory
, D2D_BRUSH_TYPE_LINEAR
, brush_desc
,
577 (ID2D1BrushVtbl
*)&d2d_linear_gradient_brush_vtbl
);
578 (*brush
)->u
.linear
.gradient
= unsafe_impl_from_ID2D1GradientStopCollection(gradient
);
579 ID2D1GradientStopCollection_AddRef(&(*brush
)->u
.linear
.gradient
->ID2D1GradientStopCollection_iface
);
580 (*brush
)->u
.linear
.start
= gradient_brush_desc
->startPoint
;
581 (*brush
)->u
.linear
.end
= gradient_brush_desc
->endPoint
;
583 TRACE("Created brush %p.\n", *brush
);
587 static inline struct d2d_brush
*impl_from_ID2D1RadialGradientBrush(ID2D1RadialGradientBrush
*iface
)
589 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
592 static HRESULT STDMETHODCALLTYPE
d2d_radial_gradient_brush_QueryInterface(ID2D1RadialGradientBrush
*iface
,
593 REFIID iid
, void **out
)
595 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
597 if (IsEqualGUID(iid
, &IID_ID2D1RadialGradientBrush
)
598 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
599 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
600 || IsEqualGUID(iid
, &IID_IUnknown
))
602 ID2D1RadialGradientBrush_AddRef(iface
);
607 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
610 return E_NOINTERFACE
;
613 static ULONG STDMETHODCALLTYPE
d2d_radial_gradient_brush_AddRef(ID2D1RadialGradientBrush
*iface
)
615 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
616 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
618 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
623 static ULONG STDMETHODCALLTYPE
d2d_radial_gradient_brush_Release(ID2D1RadialGradientBrush
*iface
)
625 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
626 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
628 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
632 ID2D1GradientStopCollection_Release(&brush
->u
.radial
.gradient
->ID2D1GradientStopCollection_iface
);
633 d2d_brush_destroy(brush
);
639 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetFactory(ID2D1RadialGradientBrush
*iface
,
640 ID2D1Factory
**factory
)
642 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
644 TRACE("iface %p, factory %p.\n", iface
, factory
);
646 ID2D1Factory_AddRef(*factory
= brush
->factory
);
649 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetOpacity(ID2D1RadialGradientBrush
*iface
, float opacity
)
651 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
653 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
655 brush
->opacity
= opacity
;
658 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetTransform(ID2D1RadialGradientBrush
*iface
,
659 const D2D1_MATRIX_3X2_F
*transform
)
661 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
663 TRACE("iface %p, transform %p.\n", iface
, transform
);
665 brush
->transform
= *transform
;
668 static float STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetOpacity(ID2D1RadialGradientBrush
*iface
)
670 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
672 TRACE("iface %p.\n", iface
);
674 return brush
->opacity
;
677 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetTransform(ID2D1RadialGradientBrush
*iface
,
678 D2D1_MATRIX_3X2_F
*transform
)
680 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
682 TRACE("iface %p, transform %p.\n", iface
, transform
);
684 *transform
= brush
->transform
;
687 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetCenter(ID2D1RadialGradientBrush
*iface
,
688 D2D1_POINT_2F centre
)
690 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
692 TRACE("iface %p, centre {%.8e, %.8e}.\n", iface
, centre
.x
, centre
.y
);
694 brush
->u
.radial
.centre
= centre
;
697 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetGradientOriginOffset(ID2D1RadialGradientBrush
*iface
,
698 D2D1_POINT_2F offset
)
700 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
702 TRACE("iface %p, offset {%.8e, %.8e}.\n", iface
, offset
.x
, offset
.y
);
704 brush
->u
.radial
.offset
= offset
;
707 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetRadiusX(ID2D1RadialGradientBrush
*iface
, float radius
)
709 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
711 TRACE("iface %p, radius %.8e.\n", iface
, radius
);
713 brush
->u
.radial
.radius
.x
= radius
;
716 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetRadiusY(ID2D1RadialGradientBrush
*iface
, float radius
)
718 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
720 TRACE("iface %p, radius %.8e.\n", iface
, radius
);
722 brush
->u
.radial
.radius
.y
= radius
;
725 static D2D1_POINT_2F
* STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetCenter(ID2D1RadialGradientBrush
*iface
,
726 D2D1_POINT_2F
*centre
)
728 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
730 TRACE("iface %p, centre %p.\n", iface
, centre
);
732 *centre
= brush
->u
.radial
.centre
;
736 static D2D1_POINT_2F
* STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetGradientOriginOffset(
737 ID2D1RadialGradientBrush
*iface
, D2D1_POINT_2F
*offset
)
739 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
741 TRACE("iface %p, offset %p.\n", iface
, offset
);
743 *offset
= brush
->u
.radial
.offset
;
747 static float STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetRadiusX(ID2D1RadialGradientBrush
*iface
)
749 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
751 TRACE("iface %p.\n", iface
);
753 return brush
->u
.radial
.radius
.x
;
756 static float STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetRadiusY(ID2D1RadialGradientBrush
*iface
)
758 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
760 TRACE("iface %p.\n", iface
);
762 return brush
->u
.radial
.radius
.y
;
765 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetGradientStopCollection(ID2D1RadialGradientBrush
*iface
,
766 ID2D1GradientStopCollection
**gradient
)
768 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
770 TRACE("iface %p, gradient %p.\n", iface
, gradient
);
772 ID2D1GradientStopCollection_AddRef(*gradient
= &brush
->u
.radial
.gradient
->ID2D1GradientStopCollection_iface
);
775 static const struct ID2D1RadialGradientBrushVtbl d2d_radial_gradient_brush_vtbl
=
777 d2d_radial_gradient_brush_QueryInterface
,
778 d2d_radial_gradient_brush_AddRef
,
779 d2d_radial_gradient_brush_Release
,
780 d2d_radial_gradient_brush_GetFactory
,
781 d2d_radial_gradient_brush_SetOpacity
,
782 d2d_radial_gradient_brush_SetTransform
,
783 d2d_radial_gradient_brush_GetOpacity
,
784 d2d_radial_gradient_brush_GetTransform
,
785 d2d_radial_gradient_brush_SetCenter
,
786 d2d_radial_gradient_brush_SetGradientOriginOffset
,
787 d2d_radial_gradient_brush_SetRadiusX
,
788 d2d_radial_gradient_brush_SetRadiusY
,
789 d2d_radial_gradient_brush_GetCenter
,
790 d2d_radial_gradient_brush_GetGradientOriginOffset
,
791 d2d_radial_gradient_brush_GetRadiusX
,
792 d2d_radial_gradient_brush_GetRadiusY
,
793 d2d_radial_gradient_brush_GetGradientStopCollection
,
796 HRESULT
d2d_radial_gradient_brush_create(ID2D1Factory
*factory
,
797 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES
*gradient_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
798 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
)
802 if (!(b
= heap_alloc_zero(sizeof(*b
))))
803 return E_OUTOFMEMORY
;
805 d2d_brush_init(b
, factory
, D2D_BRUSH_TYPE_RADIAL
, brush_desc
, (ID2D1BrushVtbl
*)&d2d_radial_gradient_brush_vtbl
);
806 b
->u
.radial
.gradient
= unsafe_impl_from_ID2D1GradientStopCollection(gradient
);
807 ID2D1GradientStopCollection_AddRef(&b
->u
.radial
.gradient
->ID2D1GradientStopCollection_iface
);
808 b
->u
.radial
.centre
= gradient_desc
->center
;
809 b
->u
.radial
.offset
= gradient_desc
->gradientOriginOffset
;
810 b
->u
.radial
.radius
.x
= gradient_desc
->radiusX
;
811 b
->u
.radial
.radius
.y
= gradient_desc
->radiusY
;
813 TRACE("Created brush %p.\n", b
);
819 static inline struct d2d_brush
*impl_from_ID2D1BitmapBrush(ID2D1BitmapBrush
*iface
)
821 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
824 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_brush_QueryInterface(ID2D1BitmapBrush
*iface
,
825 REFIID iid
, void **out
)
827 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
829 if (IsEqualGUID(iid
, &IID_ID2D1BitmapBrush
)
830 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
831 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
832 || IsEqualGUID(iid
, &IID_IUnknown
))
834 ID2D1BitmapBrush_AddRef(iface
);
839 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
842 return E_NOINTERFACE
;
845 static ULONG STDMETHODCALLTYPE
d2d_bitmap_brush_AddRef(ID2D1BitmapBrush
*iface
)
847 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
848 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
850 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
855 static ULONG STDMETHODCALLTYPE
d2d_bitmap_brush_Release(ID2D1BitmapBrush
*iface
)
857 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
858 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
860 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
864 if (brush
->u
.bitmap
.sampler_state
)
865 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
866 if (brush
->u
.bitmap
.bitmap
)
867 ID2D1Bitmap_Release(&brush
->u
.bitmap
.bitmap
->ID2D1Bitmap_iface
);
868 d2d_brush_destroy(brush
);
874 static void STDMETHODCALLTYPE
d2d_bitmap_brush_GetFactory(ID2D1BitmapBrush
*iface
,
875 ID2D1Factory
**factory
)
877 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
879 TRACE("iface %p, factory %p.\n", iface
, factory
);
881 ID2D1Factory_AddRef(*factory
= brush
->factory
);
884 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetOpacity(ID2D1BitmapBrush
*iface
, float opacity
)
886 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
888 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
890 brush
->opacity
= opacity
;
893 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetTransform(ID2D1BitmapBrush
*iface
,
894 const D2D1_MATRIX_3X2_F
*transform
)
896 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
898 TRACE("iface %p, transform %p.\n", iface
, transform
);
900 brush
->transform
= *transform
;
903 static float STDMETHODCALLTYPE
d2d_bitmap_brush_GetOpacity(ID2D1BitmapBrush
*iface
)
905 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
907 TRACE("iface %p.\n", iface
);
909 return brush
->opacity
;
912 static void STDMETHODCALLTYPE
d2d_bitmap_brush_GetTransform(ID2D1BitmapBrush
*iface
,
913 D2D1_MATRIX_3X2_F
*transform
)
915 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
917 TRACE("iface %p, transform %p.\n", iface
, transform
);
919 *transform
= brush
->transform
;
922 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetExtendModeX(ID2D1BitmapBrush
*iface
, D2D1_EXTEND_MODE mode
)
924 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
926 TRACE("iface %p, mode %#x.\n", iface
, mode
);
928 brush
->u
.bitmap
.extend_mode_x
= mode
;
929 if (brush
->u
.bitmap
.sampler_state
)
931 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
932 brush
->u
.bitmap
.sampler_state
= NULL
;
936 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetExtendModeY(ID2D1BitmapBrush
*iface
, D2D1_EXTEND_MODE mode
)
938 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
940 TRACE("iface %p, mode %#x.\n", iface
, mode
);
942 brush
->u
.bitmap
.extend_mode_y
= mode
;
943 if (brush
->u
.bitmap
.sampler_state
)
945 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
946 brush
->u
.bitmap
.sampler_state
= NULL
;
950 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetInterpolationMode(ID2D1BitmapBrush
*iface
,
951 D2D1_BITMAP_INTERPOLATION_MODE mode
)
953 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
955 TRACE("iface %p, mode %#x.\n", iface
, mode
);
957 brush
->u
.bitmap
.interpolation_mode
= mode
;
958 if (brush
->u
.bitmap
.sampler_state
)
960 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
961 brush
->u
.bitmap
.sampler_state
= NULL
;
965 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetBitmap(ID2D1BitmapBrush
*iface
, ID2D1Bitmap
*bitmap
)
967 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
969 TRACE("iface %p, bitmap %p.\n", iface
, bitmap
);
972 ID2D1Bitmap_AddRef(bitmap
);
973 if (brush
->u
.bitmap
.bitmap
)
974 ID2D1Bitmap_Release(&brush
->u
.bitmap
.bitmap
->ID2D1Bitmap_iface
);
975 brush
->u
.bitmap
.bitmap
= unsafe_impl_from_ID2D1Bitmap(bitmap
);
978 static D2D1_EXTEND_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetExtendModeX(ID2D1BitmapBrush
*iface
)
980 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
982 TRACE("iface %p.\n", iface
);
984 return brush
->u
.bitmap
.extend_mode_x
;
987 static D2D1_EXTEND_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetExtendModeY(ID2D1BitmapBrush
*iface
)
989 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
991 TRACE("iface %p.\n", iface
);
993 return brush
->u
.bitmap
.extend_mode_y
;
996 static D2D1_BITMAP_INTERPOLATION_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetInterpolationMode(ID2D1BitmapBrush
*iface
)
998 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
1000 TRACE("iface %p.\n", iface
);
1002 return brush
->u
.bitmap
.interpolation_mode
;
1005 static void STDMETHODCALLTYPE
d2d_bitmap_brush_GetBitmap(ID2D1BitmapBrush
*iface
, ID2D1Bitmap
**bitmap
)
1007 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush(iface
);
1009 TRACE("iface %p, bitmap %p.\n", iface
, bitmap
);
1011 if ((*bitmap
= &brush
->u
.bitmap
.bitmap
->ID2D1Bitmap_iface
))
1012 ID2D1Bitmap_AddRef(*bitmap
);
1015 static const struct ID2D1BitmapBrushVtbl d2d_bitmap_brush_vtbl
=
1017 d2d_bitmap_brush_QueryInterface
,
1018 d2d_bitmap_brush_AddRef
,
1019 d2d_bitmap_brush_Release
,
1020 d2d_bitmap_brush_GetFactory
,
1021 d2d_bitmap_brush_SetOpacity
,
1022 d2d_bitmap_brush_SetTransform
,
1023 d2d_bitmap_brush_GetOpacity
,
1024 d2d_bitmap_brush_GetTransform
,
1025 d2d_bitmap_brush_SetExtendModeX
,
1026 d2d_bitmap_brush_SetExtendModeY
,
1027 d2d_bitmap_brush_SetInterpolationMode
,
1028 d2d_bitmap_brush_SetBitmap
,
1029 d2d_bitmap_brush_GetExtendModeX
,
1030 d2d_bitmap_brush_GetExtendModeY
,
1031 d2d_bitmap_brush_GetInterpolationMode
,
1032 d2d_bitmap_brush_GetBitmap
,
1035 HRESULT
d2d_bitmap_brush_create(ID2D1Factory
*factory
, ID2D1Bitmap
*bitmap
, const D2D1_BITMAP_BRUSH_PROPERTIES
*bitmap_brush_desc
,
1036 const D2D1_BRUSH_PROPERTIES
*brush_desc
, struct d2d_brush
**brush
)
1038 if (!(*brush
= heap_alloc_zero(sizeof(**brush
))))
1039 return E_OUTOFMEMORY
;
1041 d2d_brush_init(*brush
, factory
, D2D_BRUSH_TYPE_BITMAP
,
1042 brush_desc
, (ID2D1BrushVtbl
*)&d2d_bitmap_brush_vtbl
);
1043 if (((*brush
)->u
.bitmap
.bitmap
= unsafe_impl_from_ID2D1Bitmap(bitmap
)))
1044 ID2D1Bitmap_AddRef(&(*brush
)->u
.bitmap
.bitmap
->ID2D1Bitmap_iface
);
1045 if (bitmap_brush_desc
)
1047 (*brush
)->u
.bitmap
.extend_mode_x
= bitmap_brush_desc
->extendModeX
;
1048 (*brush
)->u
.bitmap
.extend_mode_y
= bitmap_brush_desc
->extendModeY
;
1049 (*brush
)->u
.bitmap
.interpolation_mode
= bitmap_brush_desc
->interpolationMode
;
1053 (*brush
)->u
.bitmap
.extend_mode_x
= D2D1_EXTEND_MODE_CLAMP
;
1054 (*brush
)->u
.bitmap
.extend_mode_y
= D2D1_EXTEND_MODE_CLAMP
;
1055 (*brush
)->u
.bitmap
.interpolation_mode
= D2D1_BITMAP_INTERPOLATION_MODE_LINEAR
;
1058 TRACE("Created brush %p.\n", *brush
);
1062 struct d2d_brush
*unsafe_impl_from_ID2D1Brush(ID2D1Brush
*iface
)
1066 assert(iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_solid_color_brush_vtbl
1067 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_linear_gradient_brush_vtbl
1068 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_radial_gradient_brush_vtbl
1069 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_bitmap_brush_vtbl
);
1070 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
1073 static D3D10_TEXTURE_ADDRESS_MODE
texture_address_mode_from_extend_mode(D2D1_EXTEND_MODE mode
)
1077 case D2D1_EXTEND_MODE_CLAMP
:
1078 return D3D10_TEXTURE_ADDRESS_CLAMP
;
1079 case D2D1_EXTEND_MODE_WRAP
:
1080 return D3D10_TEXTURE_ADDRESS_WRAP
;
1081 case D2D1_EXTEND_MODE_MIRROR
:
1082 return D3D10_TEXTURE_ADDRESS_MIRROR
;
1084 FIXME("Unhandled extend mode %#x.\n", mode
);
1085 return D3D10_TEXTURE_ADDRESS_CLAMP
;
1089 static BOOL
d2d_brush_fill_cb(const struct d2d_brush
*brush
,
1090 const struct d2d_d3d_render_target
*render_target
, struct d2d_brush_cb
*cb
)
1092 float theta
, sin_theta
, cos_theta
;
1093 float dpi_scale
, d
, s1
, s2
, t
, u
;
1094 struct d2d_bitmap
*bitmap
;
1095 D2D1_POINT_2F v_p
, v_q
;
1096 D2D1_COLOR_F
*colour
;
1101 cb
->type
= D2D_BRUSH_TYPE_COUNT
;
1105 cb
->type
= brush
->type
;
1106 cb
->opacity
= brush
->opacity
;
1108 switch (brush
->type
)
1110 case D2D_BRUSH_TYPE_SOLID
:
1111 colour
= &cb
->u
.solid
.colour
;
1113 *colour
= brush
->u
.solid
.color
;
1114 colour
->r
*= colour
->a
;
1115 colour
->g
*= colour
->a
;
1116 colour
->b
*= colour
->a
;
1120 case D2D_BRUSH_TYPE_LINEAR
:
1121 b
= brush
->transform
;
1122 d2d_point_transform(&cb
->u
.linear
.start
, &b
, brush
->u
.linear
.start
.x
, brush
->u
.linear
.start
.y
);
1123 d2d_point_transform(&cb
->u
.linear
.end
, &b
, brush
->u
.linear
.end
.x
, brush
->u
.linear
.end
.y
);
1124 cb
->u
.linear
.stop_count
= brush
->u
.linear
.gradient
->stop_count
;
1128 case D2D_BRUSH_TYPE_RADIAL
:
1129 b
= brush
->transform
;
1130 d2d_point_transform(&cb
->u
.radial
.centre
, &b
, brush
->u
.radial
.centre
.x
, brush
->u
.radial
.centre
.y
);
1131 b
._31
= b
._32
= 0.0f
;
1132 d2d_point_transform(&cb
->u
.radial
.offset
, &b
, brush
->u
.radial
.offset
.x
, brush
->u
.radial
.offset
.y
);
1134 /* After a transformation, the axes of the ellipse are no longer
1135 * necessarily orthogonal, but they are conjugate diameters.
1140 * = ⎡cos(θ) -sin(θ)⎤⎡σ₁ 0 ⎤⎡cos(φ) -sin(φ)⎤
1141 * ⎣sin(θ) cos(θ)⎦⎣0 σ₂⎦⎣sin(φ) cos(φ)⎦
1143 * a' = [σ₁· cos(θ) σ₁·sin(θ)]
1144 * b' = [σ₂·-sin(θ) σ₂·cos(θ)] */
1146 d2d_point_set(&v_p
, brush
->u
.radial
.radius
.x
* b
._11
, brush
->u
.radial
.radius
.y
* b
._21
);
1147 d2d_point_set(&v_q
, brush
->u
.radial
.radius
.x
* b
._12
, brush
->u
.radial
.radius
.y
* b
._22
);
1149 t
= 0.5f
* d2d_point_dot(&v_p
, &v_p
);
1150 u
= 0.5f
* d2d_point_dot(&v_q
, &v_q
);
1154 u
= d2d_point_dot(&v_p
, &v_q
);
1155 s2
= sqrtf(t
* t
+ u
* u
);
1157 theta
= 0.5f
* atan2(u
, t
);
1158 sin_theta
= sinf(theta
);
1159 cos_theta
= cosf(theta
);
1162 d2d_point_set(&cb
->u
.radial
.ra
, t
* cos_theta
, t
* sin_theta
);
1164 d2d_point_set(&cb
->u
.radial
.rb
, t
* -sin_theta
, t
* cos_theta
);
1166 cb
->u
.radial
.stop_count
= brush
->u
.linear
.gradient
->stop_count
;
1170 case D2D_BRUSH_TYPE_BITMAP
:
1171 bitmap
= brush
->u
.bitmap
.bitmap
;
1173 /* Scale for bitmap size and dpi. */
1174 b
= brush
->transform
;
1175 dpi_scale
= bitmap
->pixel_size
.width
* (96.0f
/ bitmap
->dpi_x
);
1178 dpi_scale
= bitmap
->pixel_size
.height
* (96.0f
/ bitmap
->dpi_y
);
1182 /* Invert the matrix. (Because the matrix is applied to the
1183 * sampling coordinates. I.e., to scale the bitmap by 2 we need to
1184 * divide the coordinates by 2.) */
1185 d
= b
._11
* b
._22
- b
._21
* b
._12
;
1188 cb
->u
.bitmap
._11
= b
._22
/ d
;
1189 cb
->u
.bitmap
._21
= -b
._21
/ d
;
1190 cb
->u
.bitmap
._31
= (b
._21
* b
._32
- b
._31
* b
._22
) / d
;
1191 cb
->u
.bitmap
._12
= -b
._12
/ d
;
1192 cb
->u
.bitmap
._22
= b
._11
/ d
;
1193 cb
->u
.bitmap
._32
= -(b
._11
* b
._32
- b
._31
* b
._12
) / d
;
1196 cb
->u
.bitmap
.ignore_alpha
= bitmap
->format
.alphaMode
== D2D1_ALPHA_MODE_IGNORE
;
1201 FIXME("Unhandled brush type %#x.\n", brush
->type
);
1206 HRESULT
d2d_brush_get_ps_cb(struct d2d_brush
*brush
, struct d2d_brush
*opacity_brush
,
1207 BOOL outline
, struct d2d_d3d_render_target
*render_target
, ID3D10Buffer
**ps_cb
)
1209 D3D10_SUBRESOURCE_DATA buffer_data
;
1210 struct d2d_ps_cb cb_data
= {0};
1211 D3D10_BUFFER_DESC buffer_desc
;
1214 cb_data
.outline
= outline
;
1215 if (!d2d_brush_fill_cb(brush
, render_target
, &cb_data
.colour_brush
))
1217 if (!d2d_brush_fill_cb(opacity_brush
, render_target
, &cb_data
.opacity_brush
))
1220 buffer_desc
.ByteWidth
= sizeof(cb_data
);
1221 buffer_desc
.Usage
= D3D10_USAGE_DEFAULT
;
1222 buffer_desc
.BindFlags
= D3D10_BIND_CONSTANT_BUFFER
;
1223 buffer_desc
.CPUAccessFlags
= 0;
1224 buffer_desc
.MiscFlags
= 0;
1226 buffer_data
.pSysMem
= &cb_data
;
1227 buffer_data
.SysMemPitch
= 0;
1228 buffer_data
.SysMemSlicePitch
= 0;
1230 if (FAILED(hr
= ID3D10Device_CreateBuffer(render_target
->device
, &buffer_desc
, &buffer_data
, ps_cb
)))
1231 ERR("Failed to create constant buffer, hr %#x.\n", hr
);
1236 static void d2d_brush_bind_bitmap(struct d2d_brush
*brush
, ID3D10Device
*device
, unsigned int brush_idx
)
1240 ID3D10Device_PSSetShaderResources(device
, brush_idx
, 1, &brush
->u
.bitmap
.bitmap
->view
);
1241 if (!brush
->u
.bitmap
.sampler_state
)
1243 D3D10_SAMPLER_DESC sampler_desc
;
1245 if (brush
->u
.bitmap
.interpolation_mode
== D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR
)
1246 sampler_desc
.Filter
= D3D10_FILTER_MIN_MAG_MIP_POINT
;
1248 sampler_desc
.Filter
= D3D10_FILTER_MIN_MAG_MIP_LINEAR
;
1249 sampler_desc
.AddressU
= texture_address_mode_from_extend_mode(brush
->u
.bitmap
.extend_mode_x
);
1250 sampler_desc
.AddressV
= texture_address_mode_from_extend_mode(brush
->u
.bitmap
.extend_mode_y
);
1251 sampler_desc
.AddressW
= D3D10_TEXTURE_ADDRESS_CLAMP
;
1252 sampler_desc
.MipLODBias
= 0.0f
;
1253 sampler_desc
.MaxAnisotropy
= 0;
1254 sampler_desc
.ComparisonFunc
= D3D10_COMPARISON_NEVER
;
1255 sampler_desc
.BorderColor
[0] = 0.0f
;
1256 sampler_desc
.BorderColor
[1] = 0.0f
;
1257 sampler_desc
.BorderColor
[2] = 0.0f
;
1258 sampler_desc
.BorderColor
[3] = 0.0f
;
1259 sampler_desc
.MinLOD
= 0.0f
;
1260 sampler_desc
.MaxLOD
= 0.0f
;
1262 if (FAILED(hr
= ID3D10Device_CreateSamplerState(device
,
1263 &sampler_desc
, &brush
->u
.bitmap
.sampler_state
)))
1264 ERR("Failed to create sampler state, hr %#x.\n", hr
);
1266 ID3D10Device_PSSetSamplers(device
, brush_idx
, 1, &brush
->u
.bitmap
.sampler_state
);
1269 void d2d_brush_bind_resources(struct d2d_brush
*brush
, ID3D10Device
*device
, unsigned int brush_idx
)
1271 switch (brush
->type
)
1273 case D2D_BRUSH_TYPE_SOLID
:
1276 case D2D_BRUSH_TYPE_LINEAR
:
1277 d2d_gradient_bind(brush
->u
.linear
.gradient
, device
, brush_idx
);
1280 case D2D_BRUSH_TYPE_RADIAL
:
1281 d2d_gradient_bind(brush
->u
.radial
.gradient
, device
, brush_idx
);
1284 case D2D_BRUSH_TYPE_BITMAP
:
1285 d2d_brush_bind_bitmap(brush
, device
, brush_idx
);
1289 FIXME("Unhandled brush type %#x.\n", brush
->type
);