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
19 #include "d2d1_private.h"
21 WINE_DEFAULT_DEBUG_CHANNEL(d2d
);
23 static inline struct d2d_gradient
*impl_from_ID2D1GradientStopCollection(ID2D1GradientStopCollection
*iface
)
25 return CONTAINING_RECORD(iface
, struct d2d_gradient
, ID2D1GradientStopCollection_iface
);
28 static HRESULT STDMETHODCALLTYPE
d2d_gradient_QueryInterface(ID2D1GradientStopCollection
*iface
,
29 REFIID iid
, void **out
)
31 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
33 if (IsEqualGUID(iid
, &IID_ID2D1GradientStopCollection
)
34 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
35 || IsEqualGUID(iid
, &IID_IUnknown
))
37 ID2D1GradientStopCollection_AddRef(iface
);
42 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
48 static ULONG STDMETHODCALLTYPE
d2d_gradient_AddRef(ID2D1GradientStopCollection
*iface
)
50 struct d2d_gradient
*gradient
= impl_from_ID2D1GradientStopCollection(iface
);
51 ULONG refcount
= InterlockedIncrement(&gradient
->refcount
);
53 TRACE("%p increasing refcount to %lu.\n", iface
, refcount
);
58 static ULONG STDMETHODCALLTYPE
d2d_gradient_Release(ID2D1GradientStopCollection
*iface
)
60 struct d2d_gradient
*gradient
= impl_from_ID2D1GradientStopCollection(iface
);
61 ULONG refcount
= InterlockedDecrement(&gradient
->refcount
);
63 TRACE("%p decreasing refcount to %lu.\n", iface
, refcount
);
67 free(gradient
->stops
);
68 ID3D11ShaderResourceView_Release(gradient
->view
);
69 ID2D1Factory_Release(gradient
->factory
);
76 static void STDMETHODCALLTYPE
d2d_gradient_GetFactory(ID2D1GradientStopCollection
*iface
, ID2D1Factory
**factory
)
78 struct d2d_gradient
*gradient
= impl_from_ID2D1GradientStopCollection(iface
);
80 TRACE("iface %p, factory %p.\n", iface
, factory
);
82 ID2D1Factory_AddRef(*factory
= gradient
->factory
);
85 static UINT32 STDMETHODCALLTYPE
d2d_gradient_GetGradientStopCount(ID2D1GradientStopCollection
*iface
)
87 struct d2d_gradient
*gradient
= impl_from_ID2D1GradientStopCollection(iface
);
89 TRACE("iface %p.\n", iface
);
91 return gradient
->stop_count
;
94 static void STDMETHODCALLTYPE
d2d_gradient_GetGradientStops(ID2D1GradientStopCollection
*iface
,
95 D2D1_GRADIENT_STOP
*stops
, UINT32 stop_count
)
97 struct d2d_gradient
*gradient
= impl_from_ID2D1GradientStopCollection(iface
);
99 TRACE("iface %p, stops %p, stop_count %u.\n", iface
, stops
, stop_count
);
101 memcpy(stops
, gradient
->stops
, min(gradient
->stop_count
, stop_count
) * sizeof(*stops
));
104 static D2D1_GAMMA STDMETHODCALLTYPE
d2d_gradient_GetColorInterpolationGamma(ID2D1GradientStopCollection
*iface
)
106 FIXME("iface %p stub!\n", iface
);
108 return D2D1_GAMMA_1_0
;
111 static D2D1_EXTEND_MODE STDMETHODCALLTYPE
d2d_gradient_GetExtendMode(ID2D1GradientStopCollection
*iface
)
113 FIXME("iface %p stub!\n", iface
);
115 return D2D1_EXTEND_MODE_CLAMP
;
118 static const struct ID2D1GradientStopCollectionVtbl d2d_gradient_vtbl
=
120 d2d_gradient_QueryInterface
,
122 d2d_gradient_Release
,
123 d2d_gradient_GetFactory
,
124 d2d_gradient_GetGradientStopCount
,
125 d2d_gradient_GetGradientStops
,
126 d2d_gradient_GetColorInterpolationGamma
,
127 d2d_gradient_GetExtendMode
,
130 HRESULT
d2d_gradient_create(ID2D1Factory
*factory
, ID3D11Device1
*device
, const D2D1_GRADIENT_STOP
*stops
,
131 UINT32 stop_count
, D2D1_GAMMA gamma
, D2D1_EXTEND_MODE extend_mode
, struct d2d_gradient
**out
)
133 D3D11_SHADER_RESOURCE_VIEW_DESC srv_desc
;
134 D3D11_SUBRESOURCE_DATA buffer_data
;
135 ID3D11ShaderResourceView
*view
;
136 struct d2d_gradient
*gradient
;
137 D3D11_BUFFER_DESC buffer_desc
;
138 struct d2d_vec4
*data
;
139 ID3D11Buffer
*buffer
;
144 if (!(data
= calloc(stop_count
, 2 * sizeof(*data
))))
146 ERR("Failed to allocate data.\n");
147 return E_OUTOFMEMORY
;
150 for (i
= 0; i
< stop_count
; ++i
)
152 data
[i
* 2].x
= stops
[i
].position
;
153 data
[i
* 2 + 1].x
= stops
[i
].color
.r
;
154 data
[i
* 2 + 1].y
= stops
[i
].color
.g
;
155 data
[i
* 2 + 1].z
= stops
[i
].color
.b
;
156 data
[i
* 2 + 1].w
= stops
[i
].color
.a
;
159 buffer_desc
.ByteWidth
= 2 * stop_count
* sizeof(*data
);
160 buffer_desc
.Usage
= D3D11_USAGE_DEFAULT
;
161 buffer_desc
.BindFlags
= D3D11_BIND_SHADER_RESOURCE
;
162 buffer_desc
.CPUAccessFlags
= 0;
163 buffer_desc
.MiscFlags
= 0;
165 buffer_data
.pSysMem
= data
;
166 buffer_data
.SysMemPitch
= 0;
167 buffer_data
.SysMemSlicePitch
= 0;
169 hr
= ID3D11Device1_CreateBuffer(device
, &buffer_desc
, &buffer_data
, &buffer
);
173 ERR("Failed to create buffer, hr %#lx.\n", hr
);
177 srv_desc
.Format
= DXGI_FORMAT_R32G32B32A32_FLOAT
;
178 srv_desc
.ViewDimension
= D3D11_SRV_DIMENSION_BUFFER
;
179 srv_desc
.Buffer
.ElementOffset
= 0;
180 srv_desc
.Buffer
.ElementWidth
= 2 * stop_count
;
182 hr
= ID3D11Device1_CreateShaderResourceView(device
, (ID3D11Resource
*)buffer
, &srv_desc
, &view
);
183 ID3D11Buffer_Release(buffer
);
186 ERR("Failed to create view, hr %#lx.\n", hr
);
190 if (!(gradient
= calloc(1, sizeof(*gradient
))))
192 ID3D11ShaderResourceView_Release(view
);
193 return E_OUTOFMEMORY
;
196 if (gamma
!= D2D1_GAMMA_2_2
)
197 FIXME("Ignoring gamma %#x.\n", gamma
);
198 if (extend_mode
!= D2D1_EXTEND_MODE_CLAMP
)
199 FIXME("Ignoring extend mode %#x.\n", extend_mode
);
201 gradient
->ID2D1GradientStopCollection_iface
.lpVtbl
= &d2d_gradient_vtbl
;
202 gradient
->refcount
= 1;
203 ID2D1Factory_AddRef(gradient
->factory
= factory
);
204 gradient
->view
= view
;
206 gradient
->stop_count
= stop_count
;
207 if (!(gradient
->stops
= calloc(stop_count
, sizeof(*stops
))))
209 ID3D11ShaderResourceView_Release(view
);
211 return E_OUTOFMEMORY
;
213 memcpy(gradient
->stops
, stops
, stop_count
* sizeof(*stops
));
215 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
, ID3D11Device1
*device
, unsigned int brush_idx
)
230 ID3D11DeviceContext
*context
;
231 ID3D11Device1_GetImmediateContext(device
, &context
);
232 ID3D11DeviceContext_PSSetShaderResources(context
, 2 + brush_idx
, 1, &gradient
->view
);
233 ID3D11DeviceContext_Release(context
);
236 static void d2d_brush_destroy(struct d2d_brush
*brush
)
238 ID2D1Factory_Release(brush
->factory
);
242 static void d2d_brush_init(struct d2d_brush
*brush
, ID2D1Factory
*factory
,
243 enum d2d_brush_type type
, const D2D1_BRUSH_PROPERTIES
*desc
, const struct ID2D1BrushVtbl
*vtbl
)
245 static const D2D1_MATRIX_3X2_F identity
=
252 brush
->ID2D1Brush_iface
.lpVtbl
= vtbl
;
254 ID2D1Factory_AddRef(brush
->factory
= factory
);
255 brush
->opacity
= desc
? desc
->opacity
: 1.0f
;
256 brush
->transform
= desc
? desc
->transform
: identity
;
260 static inline struct d2d_brush
*impl_from_ID2D1SolidColorBrush(ID2D1SolidColorBrush
*iface
)
262 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
265 static HRESULT STDMETHODCALLTYPE
d2d_solid_color_brush_QueryInterface(ID2D1SolidColorBrush
*iface
,
266 REFIID iid
, void **out
)
268 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
270 if (IsEqualGUID(iid
, &IID_ID2D1SolidColorBrush
)
271 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
272 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
273 || IsEqualGUID(iid
, &IID_IUnknown
))
275 ID2D1SolidColorBrush_AddRef(iface
);
280 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
283 return E_NOINTERFACE
;
286 static ULONG STDMETHODCALLTYPE
d2d_solid_color_brush_AddRef(ID2D1SolidColorBrush
*iface
)
288 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
289 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
291 TRACE("%p increasing refcount to %lu.\n", iface
, refcount
);
296 static ULONG STDMETHODCALLTYPE
d2d_solid_color_brush_Release(ID2D1SolidColorBrush
*iface
)
298 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
299 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
301 TRACE("%p decreasing refcount to %lu.\n", iface
, refcount
);
304 d2d_brush_destroy(brush
);
309 static void STDMETHODCALLTYPE
d2d_solid_color_brush_GetFactory(ID2D1SolidColorBrush
*iface
, ID2D1Factory
**factory
)
311 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
313 TRACE("iface %p, factory %p.\n", iface
, factory
);
315 ID2D1Factory_AddRef(*factory
= brush
->factory
);
318 static void STDMETHODCALLTYPE
d2d_solid_color_brush_SetOpacity(ID2D1SolidColorBrush
*iface
, float opacity
)
320 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
322 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
324 brush
->opacity
= opacity
;
327 static void STDMETHODCALLTYPE
d2d_solid_color_brush_SetTransform(ID2D1SolidColorBrush
*iface
,
328 const D2D1_MATRIX_3X2_F
*transform
)
330 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
332 TRACE("iface %p, transform %p.\n", iface
, transform
);
334 brush
->transform
= *transform
;
337 static float STDMETHODCALLTYPE
d2d_solid_color_brush_GetOpacity(ID2D1SolidColorBrush
*iface
)
339 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
341 TRACE("iface %p.\n", iface
);
343 return brush
->opacity
;
346 static void STDMETHODCALLTYPE
d2d_solid_color_brush_GetTransform(ID2D1SolidColorBrush
*iface
,
347 D2D1_MATRIX_3X2_F
*transform
)
349 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
351 TRACE("iface %p, transform %p.\n", iface
, transform
);
353 *transform
= brush
->transform
;
356 static void STDMETHODCALLTYPE
d2d_solid_color_brush_SetColor(ID2D1SolidColorBrush
*iface
, const D2D1_COLOR_F
*color
)
358 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
360 TRACE("iface %p, color %p.\n", iface
, color
);
362 brush
->u
.solid
.color
= *color
;
365 static D2D1_COLOR_F
* STDMETHODCALLTYPE
d2d_solid_color_brush_GetColor(ID2D1SolidColorBrush
*iface
, D2D1_COLOR_F
*color
)
367 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
369 TRACE("iface %p, color %p.\n", iface
, color
);
371 *color
= brush
->u
.solid
.color
;
375 static const struct ID2D1SolidColorBrushVtbl d2d_solid_color_brush_vtbl
=
377 d2d_solid_color_brush_QueryInterface
,
378 d2d_solid_color_brush_AddRef
,
379 d2d_solid_color_brush_Release
,
380 d2d_solid_color_brush_GetFactory
,
381 d2d_solid_color_brush_SetOpacity
,
382 d2d_solid_color_brush_SetTransform
,
383 d2d_solid_color_brush_GetOpacity
,
384 d2d_solid_color_brush_GetTransform
,
385 d2d_solid_color_brush_SetColor
,
386 d2d_solid_color_brush_GetColor
,
389 HRESULT
d2d_solid_color_brush_create(ID2D1Factory
*factory
, const D2D1_COLOR_F
*color
,
390 const D2D1_BRUSH_PROPERTIES
*desc
, struct d2d_brush
**brush
)
392 if (!(*brush
= calloc(1, sizeof(**brush
))))
393 return E_OUTOFMEMORY
;
395 d2d_brush_init(*brush
, factory
, D2D_BRUSH_TYPE_SOLID
, desc
,
396 (ID2D1BrushVtbl
*)&d2d_solid_color_brush_vtbl
);
397 (*brush
)->u
.solid
.color
= *color
;
399 TRACE("Created brush %p.\n", *brush
);
403 static inline struct d2d_brush
*impl_from_ID2D1LinearGradientBrush(ID2D1LinearGradientBrush
*iface
)
405 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
408 static HRESULT STDMETHODCALLTYPE
d2d_linear_gradient_brush_QueryInterface(ID2D1LinearGradientBrush
*iface
,
409 REFIID iid
, void **out
)
411 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
413 if (IsEqualGUID(iid
, &IID_ID2D1LinearGradientBrush
)
414 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
415 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
416 || IsEqualGUID(iid
, &IID_IUnknown
))
418 ID2D1LinearGradientBrush_AddRef(iface
);
423 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
426 return E_NOINTERFACE
;
429 static ULONG STDMETHODCALLTYPE
d2d_linear_gradient_brush_AddRef(ID2D1LinearGradientBrush
*iface
)
431 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
432 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
434 TRACE("%p increasing refcount to %lu.\n", iface
, refcount
);
439 static ULONG STDMETHODCALLTYPE
d2d_linear_gradient_brush_Release(ID2D1LinearGradientBrush
*iface
)
441 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
442 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
444 TRACE("%p decreasing refcount to %lu.\n", iface
, refcount
);
448 ID2D1GradientStopCollection_Release(&brush
->u
.linear
.gradient
->ID2D1GradientStopCollection_iface
);
449 d2d_brush_destroy(brush
);
455 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetFactory(ID2D1LinearGradientBrush
*iface
,
456 ID2D1Factory
**factory
)
458 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
460 TRACE("iface %p, factory %p.\n", iface
, factory
);
462 ID2D1Factory_AddRef(*factory
= brush
->factory
);
465 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_SetOpacity(ID2D1LinearGradientBrush
*iface
, float opacity
)
467 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
469 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
471 brush
->opacity
= opacity
;
474 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_SetTransform(ID2D1LinearGradientBrush
*iface
,
475 const D2D1_MATRIX_3X2_F
*transform
)
477 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
479 TRACE("iface %p, transform %p.\n", iface
, transform
);
481 brush
->transform
= *transform
;
484 static float STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetOpacity(ID2D1LinearGradientBrush
*iface
)
486 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
488 TRACE("iface %p.\n", iface
);
490 return brush
->opacity
;
493 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetTransform(ID2D1LinearGradientBrush
*iface
,
494 D2D1_MATRIX_3X2_F
*transform
)
496 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
498 TRACE("iface %p, transform %p.\n", iface
, transform
);
500 *transform
= brush
->transform
;
503 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_SetStartPoint(ID2D1LinearGradientBrush
*iface
,
504 D2D1_POINT_2F start_point
)
506 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
508 TRACE("iface %p, start_point %s.\n", iface
, debug_d2d_point_2f(&start_point
));
510 brush
->u
.linear
.start
= start_point
;
513 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_SetEndPoint(ID2D1LinearGradientBrush
*iface
,
514 D2D1_POINT_2F end_point
)
516 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
518 TRACE("iface %p, end_point %s.\n", iface
, debug_d2d_point_2f(&end_point
));
520 brush
->u
.linear
.end
= end_point
;
523 static D2D1_POINT_2F
* STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetStartPoint(ID2D1LinearGradientBrush
*iface
,
524 D2D1_POINT_2F
*point
)
526 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
528 TRACE("iface %p, point %p.\n", iface
, point
);
530 *point
= brush
->u
.linear
.start
;
534 static D2D1_POINT_2F
* STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetEndPoint(ID2D1LinearGradientBrush
*iface
,
535 D2D1_POINT_2F
*point
)
537 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
539 TRACE("iface %p, point %p.\n", iface
, point
);
541 *point
= brush
->u
.linear
.end
;
545 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetGradientStopCollection(ID2D1LinearGradientBrush
*iface
,
546 ID2D1GradientStopCollection
**gradient
)
548 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
550 TRACE("iface %p, gradient %p.\n", iface
, gradient
);
552 ID2D1GradientStopCollection_AddRef(*gradient
= &brush
->u
.linear
.gradient
->ID2D1GradientStopCollection_iface
);
555 static const struct ID2D1LinearGradientBrushVtbl d2d_linear_gradient_brush_vtbl
=
557 d2d_linear_gradient_brush_QueryInterface
,
558 d2d_linear_gradient_brush_AddRef
,
559 d2d_linear_gradient_brush_Release
,
560 d2d_linear_gradient_brush_GetFactory
,
561 d2d_linear_gradient_brush_SetOpacity
,
562 d2d_linear_gradient_brush_SetTransform
,
563 d2d_linear_gradient_brush_GetOpacity
,
564 d2d_linear_gradient_brush_GetTransform
,
565 d2d_linear_gradient_brush_SetStartPoint
,
566 d2d_linear_gradient_brush_SetEndPoint
,
567 d2d_linear_gradient_brush_GetStartPoint
,
568 d2d_linear_gradient_brush_GetEndPoint
,
569 d2d_linear_gradient_brush_GetGradientStopCollection
,
572 HRESULT
d2d_linear_gradient_brush_create(ID2D1Factory
*factory
,
573 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES
*gradient_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
574 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
)
576 if (!(*brush
= calloc(1, sizeof(**brush
))))
577 return E_OUTOFMEMORY
;
579 d2d_brush_init(*brush
, factory
, D2D_BRUSH_TYPE_LINEAR
, brush_desc
,
580 (ID2D1BrushVtbl
*)&d2d_linear_gradient_brush_vtbl
);
581 (*brush
)->u
.linear
.gradient
= unsafe_impl_from_ID2D1GradientStopCollection(gradient
);
582 ID2D1GradientStopCollection_AddRef(&(*brush
)->u
.linear
.gradient
->ID2D1GradientStopCollection_iface
);
583 (*brush
)->u
.linear
.start
= gradient_brush_desc
->startPoint
;
584 (*brush
)->u
.linear
.end
= gradient_brush_desc
->endPoint
;
586 TRACE("Created brush %p.\n", *brush
);
590 static inline struct d2d_brush
*impl_from_ID2D1RadialGradientBrush(ID2D1RadialGradientBrush
*iface
)
592 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
595 static HRESULT STDMETHODCALLTYPE
d2d_radial_gradient_brush_QueryInterface(ID2D1RadialGradientBrush
*iface
,
596 REFIID iid
, void **out
)
598 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
600 if (IsEqualGUID(iid
, &IID_ID2D1RadialGradientBrush
)
601 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
602 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
603 || IsEqualGUID(iid
, &IID_IUnknown
))
605 ID2D1RadialGradientBrush_AddRef(iface
);
610 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
613 return E_NOINTERFACE
;
616 static ULONG STDMETHODCALLTYPE
d2d_radial_gradient_brush_AddRef(ID2D1RadialGradientBrush
*iface
)
618 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
619 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
621 TRACE("%p increasing refcount to %lu.\n", iface
, refcount
);
626 static ULONG STDMETHODCALLTYPE
d2d_radial_gradient_brush_Release(ID2D1RadialGradientBrush
*iface
)
628 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
629 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
631 TRACE("%p decreasing refcount to %lu.\n", iface
, refcount
);
635 ID2D1GradientStopCollection_Release(&brush
->u
.radial
.gradient
->ID2D1GradientStopCollection_iface
);
636 d2d_brush_destroy(brush
);
642 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetFactory(ID2D1RadialGradientBrush
*iface
,
643 ID2D1Factory
**factory
)
645 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
647 TRACE("iface %p, factory %p.\n", iface
, factory
);
649 ID2D1Factory_AddRef(*factory
= brush
->factory
);
652 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetOpacity(ID2D1RadialGradientBrush
*iface
, float opacity
)
654 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
656 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
658 brush
->opacity
= opacity
;
661 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetTransform(ID2D1RadialGradientBrush
*iface
,
662 const D2D1_MATRIX_3X2_F
*transform
)
664 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
666 TRACE("iface %p, transform %p.\n", iface
, transform
);
668 brush
->transform
= *transform
;
671 static float STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetOpacity(ID2D1RadialGradientBrush
*iface
)
673 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
675 TRACE("iface %p.\n", iface
);
677 return brush
->opacity
;
680 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetTransform(ID2D1RadialGradientBrush
*iface
,
681 D2D1_MATRIX_3X2_F
*transform
)
683 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
685 TRACE("iface %p, transform %p.\n", iface
, transform
);
687 *transform
= brush
->transform
;
690 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetCenter(ID2D1RadialGradientBrush
*iface
,
691 D2D1_POINT_2F centre
)
693 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
695 TRACE("iface %p, centre %s.\n", iface
, debug_d2d_point_2f(¢re
));
697 brush
->u
.radial
.centre
= centre
;
700 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetGradientOriginOffset(ID2D1RadialGradientBrush
*iface
,
701 D2D1_POINT_2F offset
)
703 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
705 TRACE("iface %p, offset %s.\n", iface
, debug_d2d_point_2f(&offset
));
707 brush
->u
.radial
.offset
= offset
;
710 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetRadiusX(ID2D1RadialGradientBrush
*iface
, float radius
)
712 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
714 TRACE("iface %p, radius %.8e.\n", iface
, radius
);
716 brush
->u
.radial
.radius
.x
= radius
;
719 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetRadiusY(ID2D1RadialGradientBrush
*iface
, float radius
)
721 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
723 TRACE("iface %p, radius %.8e.\n", iface
, radius
);
725 brush
->u
.radial
.radius
.y
= radius
;
728 static D2D1_POINT_2F
* STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetCenter(ID2D1RadialGradientBrush
*iface
,
729 D2D1_POINT_2F
*centre
)
731 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
733 TRACE("iface %p, centre %p.\n", iface
, centre
);
735 *centre
= brush
->u
.radial
.centre
;
739 static D2D1_POINT_2F
* STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetGradientOriginOffset(
740 ID2D1RadialGradientBrush
*iface
, D2D1_POINT_2F
*offset
)
742 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
744 TRACE("iface %p, offset %p.\n", iface
, offset
);
746 *offset
= brush
->u
.radial
.offset
;
750 static float STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetRadiusX(ID2D1RadialGradientBrush
*iface
)
752 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
754 TRACE("iface %p.\n", iface
);
756 return brush
->u
.radial
.radius
.x
;
759 static float STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetRadiusY(ID2D1RadialGradientBrush
*iface
)
761 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
763 TRACE("iface %p.\n", iface
);
765 return brush
->u
.radial
.radius
.y
;
768 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetGradientStopCollection(ID2D1RadialGradientBrush
*iface
,
769 ID2D1GradientStopCollection
**gradient
)
771 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
773 TRACE("iface %p, gradient %p.\n", iface
, gradient
);
775 ID2D1GradientStopCollection_AddRef(*gradient
= &brush
->u
.radial
.gradient
->ID2D1GradientStopCollection_iface
);
778 static const struct ID2D1RadialGradientBrushVtbl d2d_radial_gradient_brush_vtbl
=
780 d2d_radial_gradient_brush_QueryInterface
,
781 d2d_radial_gradient_brush_AddRef
,
782 d2d_radial_gradient_brush_Release
,
783 d2d_radial_gradient_brush_GetFactory
,
784 d2d_radial_gradient_brush_SetOpacity
,
785 d2d_radial_gradient_brush_SetTransform
,
786 d2d_radial_gradient_brush_GetOpacity
,
787 d2d_radial_gradient_brush_GetTransform
,
788 d2d_radial_gradient_brush_SetCenter
,
789 d2d_radial_gradient_brush_SetGradientOriginOffset
,
790 d2d_radial_gradient_brush_SetRadiusX
,
791 d2d_radial_gradient_brush_SetRadiusY
,
792 d2d_radial_gradient_brush_GetCenter
,
793 d2d_radial_gradient_brush_GetGradientOriginOffset
,
794 d2d_radial_gradient_brush_GetRadiusX
,
795 d2d_radial_gradient_brush_GetRadiusY
,
796 d2d_radial_gradient_brush_GetGradientStopCollection
,
799 HRESULT
d2d_radial_gradient_brush_create(ID2D1Factory
*factory
,
800 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES
*gradient_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
801 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
)
805 if (!(b
= calloc(1, sizeof(*b
))))
806 return E_OUTOFMEMORY
;
808 d2d_brush_init(b
, factory
, D2D_BRUSH_TYPE_RADIAL
, brush_desc
, (ID2D1BrushVtbl
*)&d2d_radial_gradient_brush_vtbl
);
809 b
->u
.radial
.gradient
= unsafe_impl_from_ID2D1GradientStopCollection(gradient
);
810 ID2D1GradientStopCollection_AddRef(&b
->u
.radial
.gradient
->ID2D1GradientStopCollection_iface
);
811 b
->u
.radial
.centre
= gradient_desc
->center
;
812 b
->u
.radial
.offset
= gradient_desc
->gradientOriginOffset
;
813 b
->u
.radial
.radius
.x
= gradient_desc
->radiusX
;
814 b
->u
.radial
.radius
.y
= gradient_desc
->radiusY
;
816 TRACE("Created brush %p.\n", b
);
822 static inline struct d2d_brush
*impl_from_ID2D1BitmapBrush1(ID2D1BitmapBrush1
*iface
)
824 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
827 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_brush_QueryInterface(ID2D1BitmapBrush1
*iface
,
828 REFIID iid
, void **out
)
830 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
832 if (IsEqualGUID(iid
, &IID_ID2D1BitmapBrush1
)
833 || IsEqualGUID(iid
, &IID_ID2D1BitmapBrush
)
834 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
835 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
836 || IsEqualGUID(iid
, &IID_IUnknown
))
838 ID2D1BitmapBrush1_AddRef(iface
);
843 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
846 return E_NOINTERFACE
;
849 static ULONG STDMETHODCALLTYPE
d2d_bitmap_brush_AddRef(ID2D1BitmapBrush1
*iface
)
851 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
852 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
854 TRACE("%p increasing refcount to %lu.\n", iface
, refcount
);
859 static ULONG STDMETHODCALLTYPE
d2d_bitmap_brush_Release(ID2D1BitmapBrush1
*iface
)
861 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
862 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
864 TRACE("%p decreasing refcount to %lu.\n", iface
, refcount
);
868 if (brush
->u
.bitmap
.bitmap
)
869 ID2D1Bitmap1_Release(&brush
->u
.bitmap
.bitmap
->ID2D1Bitmap1_iface
);
870 d2d_brush_destroy(brush
);
876 static void STDMETHODCALLTYPE
d2d_bitmap_brush_GetFactory(ID2D1BitmapBrush1
*iface
,
877 ID2D1Factory
**factory
)
879 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
881 TRACE("iface %p, factory %p.\n", iface
, factory
);
883 ID2D1Factory_AddRef(*factory
= brush
->factory
);
886 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetOpacity(ID2D1BitmapBrush1
*iface
, float opacity
)
888 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
890 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
892 brush
->opacity
= opacity
;
895 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetTransform(ID2D1BitmapBrush1
*iface
,
896 const D2D1_MATRIX_3X2_F
*transform
)
898 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
900 TRACE("iface %p, transform %p.\n", iface
, transform
);
902 brush
->transform
= *transform
;
905 static float STDMETHODCALLTYPE
d2d_bitmap_brush_GetOpacity(ID2D1BitmapBrush1
*iface
)
907 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
909 TRACE("iface %p.\n", iface
);
911 return brush
->opacity
;
914 static void STDMETHODCALLTYPE
d2d_bitmap_brush_GetTransform(ID2D1BitmapBrush1
*iface
,
915 D2D1_MATRIX_3X2_F
*transform
)
917 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
919 TRACE("iface %p, transform %p.\n", iface
, transform
);
921 *transform
= brush
->transform
;
924 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetExtendModeX(ID2D1BitmapBrush1
*iface
, D2D1_EXTEND_MODE mode
)
926 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
928 TRACE("iface %p, mode %#x.\n", iface
, mode
);
930 brush
->u
.bitmap
.extend_mode_x
= mode
;
933 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetExtendModeY(ID2D1BitmapBrush1
*iface
, D2D1_EXTEND_MODE mode
)
935 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
937 TRACE("iface %p, mode %#x.\n", iface
, mode
);
939 brush
->u
.bitmap
.extend_mode_y
= mode
;
942 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetInterpolationMode(ID2D1BitmapBrush1
*iface
,
943 D2D1_BITMAP_INTERPOLATION_MODE mode
)
945 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
947 TRACE("iface %p, mode %#x.\n", iface
, mode
);
951 case D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR
:
952 case D2D1_BITMAP_INTERPOLATION_MODE_LINEAR
:
955 WARN("Unknown interpolation mode %#x.\n", mode
);
959 brush
->u
.bitmap
.interpolation_mode
= d2d1_1_interp_mode_from_d2d1(mode
);
962 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetBitmap(ID2D1BitmapBrush1
*iface
, ID2D1Bitmap
*bitmap
)
964 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
966 TRACE("iface %p, bitmap %p.\n", iface
, bitmap
);
969 ID2D1Bitmap_AddRef(bitmap
);
970 if (brush
->u
.bitmap
.bitmap
)
971 ID2D1Bitmap1_Release(&brush
->u
.bitmap
.bitmap
->ID2D1Bitmap1_iface
);
972 brush
->u
.bitmap
.bitmap
= unsafe_impl_from_ID2D1Bitmap(bitmap
);
975 static D2D1_EXTEND_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetExtendModeX(ID2D1BitmapBrush1
*iface
)
977 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
979 TRACE("iface %p.\n", iface
);
981 return brush
->u
.bitmap
.extend_mode_x
;
984 static D2D1_EXTEND_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetExtendModeY(ID2D1BitmapBrush1
*iface
)
986 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
988 TRACE("iface %p.\n", iface
);
990 return brush
->u
.bitmap
.extend_mode_y
;
993 static D2D1_BITMAP_INTERPOLATION_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetInterpolationMode(ID2D1BitmapBrush1
*iface
)
995 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
997 TRACE("iface %p.\n", iface
);
999 switch (brush
->u
.bitmap
.interpolation_mode
)
1001 case D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR
:
1002 return D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR
;
1003 case D2D1_INTERPOLATION_MODE_LINEAR
:
1005 return D2D1_BITMAP_INTERPOLATION_MODE_LINEAR
;
1009 static void STDMETHODCALLTYPE
d2d_bitmap_brush_GetBitmap(ID2D1BitmapBrush1
*iface
, ID2D1Bitmap
**bitmap
)
1011 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
1013 TRACE("iface %p, bitmap %p.\n", iface
, bitmap
);
1015 if ((*bitmap
= (ID2D1Bitmap
*)&brush
->u
.bitmap
.bitmap
->ID2D1Bitmap1_iface
))
1016 ID2D1Bitmap_AddRef(*bitmap
);
1019 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetInterpolationMode1(ID2D1BitmapBrush1
*iface
,
1020 D2D1_INTERPOLATION_MODE mode
)
1022 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
1024 TRACE("iface %p, mode %#x.\n", iface
, mode
);
1028 case D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR
:
1029 case D2D1_INTERPOLATION_MODE_LINEAR
:
1031 case D2D1_INTERPOLATION_MODE_CUBIC
:
1032 case D2D1_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR
:
1033 case D2D1_INTERPOLATION_MODE_ANISOTROPIC
:
1034 case D2D1_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC
:
1035 FIXME("Unhandled interpolation mode %#x.\n", mode
);
1038 WARN("Unknown interpolation mode %#x.\n", mode
);
1042 brush
->u
.bitmap
.interpolation_mode
= mode
;
1045 static D2D1_INTERPOLATION_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetInterpolationMode1(ID2D1BitmapBrush1
*iface
)
1047 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
1049 TRACE("iface %p.\n", iface
);
1051 return brush
->u
.bitmap
.interpolation_mode
;
1054 static const struct ID2D1BitmapBrush1Vtbl d2d_bitmap_brush_vtbl
=
1056 d2d_bitmap_brush_QueryInterface
,
1057 d2d_bitmap_brush_AddRef
,
1058 d2d_bitmap_brush_Release
,
1059 d2d_bitmap_brush_GetFactory
,
1060 d2d_bitmap_brush_SetOpacity
,
1061 d2d_bitmap_brush_SetTransform
,
1062 d2d_bitmap_brush_GetOpacity
,
1063 d2d_bitmap_brush_GetTransform
,
1064 d2d_bitmap_brush_SetExtendModeX
,
1065 d2d_bitmap_brush_SetExtendModeY
,
1066 d2d_bitmap_brush_SetInterpolationMode
,
1067 d2d_bitmap_brush_SetBitmap
,
1068 d2d_bitmap_brush_GetExtendModeX
,
1069 d2d_bitmap_brush_GetExtendModeY
,
1070 d2d_bitmap_brush_GetInterpolationMode
,
1071 d2d_bitmap_brush_GetBitmap
,
1072 d2d_bitmap_brush_SetInterpolationMode1
,
1073 d2d_bitmap_brush_GetInterpolationMode1
,
1076 HRESULT
d2d_bitmap_brush_create(ID2D1Factory
*factory
, ID2D1Bitmap
*bitmap
,
1077 const D2D1_BITMAP_BRUSH_PROPERTIES1
*bitmap_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
1078 struct d2d_brush
**brush
)
1080 if (!(*brush
= calloc(1, sizeof(**brush
))))
1081 return E_OUTOFMEMORY
;
1083 d2d_brush_init(*brush
, factory
, D2D_BRUSH_TYPE_BITMAP
,
1084 brush_desc
, (ID2D1BrushVtbl
*)&d2d_bitmap_brush_vtbl
);
1085 if (((*brush
)->u
.bitmap
.bitmap
= unsafe_impl_from_ID2D1Bitmap(bitmap
)))
1086 ID2D1Bitmap1_AddRef(&(*brush
)->u
.bitmap
.bitmap
->ID2D1Bitmap1_iface
);
1087 if (bitmap_brush_desc
)
1089 (*brush
)->u
.bitmap
.extend_mode_x
= bitmap_brush_desc
->extendModeX
;
1090 (*brush
)->u
.bitmap
.extend_mode_y
= bitmap_brush_desc
->extendModeY
;
1091 (*brush
)->u
.bitmap
.interpolation_mode
= bitmap_brush_desc
->interpolationMode
;
1095 (*brush
)->u
.bitmap
.extend_mode_x
= D2D1_EXTEND_MODE_CLAMP
;
1096 (*brush
)->u
.bitmap
.extend_mode_y
= D2D1_EXTEND_MODE_CLAMP
;
1097 (*brush
)->u
.bitmap
.interpolation_mode
= D2D1_INTERPOLATION_MODE_LINEAR
;
1100 TRACE("Created brush %p.\n", *brush
);
1104 static inline struct d2d_brush
*impl_from_ID2D1ImageBrush(ID2D1ImageBrush
*iface
)
1106 return CONTAINING_RECORD((ID2D1Brush
*)iface
, struct d2d_brush
, ID2D1Brush_iface
);
1109 static HRESULT STDMETHODCALLTYPE
d2d_image_brush_QueryInterface(ID2D1ImageBrush
*iface
,
1110 REFIID iid
, void **out
)
1112 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
1114 if (IsEqualGUID(iid
, &IID_ID2D1ImageBrush
)
1115 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
1116 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
1117 || IsEqualGUID(iid
, &IID_IUnknown
))
1119 ID2D1ImageBrush_AddRef(iface
);
1124 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
1127 return E_NOINTERFACE
;
1130 static ULONG STDMETHODCALLTYPE
d2d_image_brush_AddRef(ID2D1ImageBrush
*iface
)
1132 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1133 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
1135 TRACE("%p increasing refcount to %lu.\n", iface
, refcount
);
1140 static ULONG STDMETHODCALLTYPE
d2d_image_brush_Release(ID2D1ImageBrush
*iface
)
1142 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1143 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
1145 TRACE("%p decreasing refcount to %lu.\n", iface
, refcount
);
1149 if (brush
->u
.image
.image
)
1150 ID2D1Image_Release(brush
->u
.image
.image
);
1151 d2d_brush_destroy(brush
);
1157 static void STDMETHODCALLTYPE
d2d_image_brush_GetFactory(ID2D1ImageBrush
*iface
,
1158 ID2D1Factory
**factory
)
1160 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1162 TRACE("iface %p, factory %p.\n", iface
, factory
);
1164 ID2D1Factory_AddRef(*factory
= brush
->factory
);
1167 static void STDMETHODCALLTYPE
d2d_image_brush_SetOpacity(ID2D1ImageBrush
*iface
, float opacity
)
1169 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1171 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
1173 brush
->opacity
= opacity
;
1176 static void STDMETHODCALLTYPE
d2d_image_brush_SetTransform(ID2D1ImageBrush
*iface
,
1177 const D2D1_MATRIX_3X2_F
*transform
)
1179 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1181 TRACE("iface %p, transform %p.\n", iface
, transform
);
1183 brush
->transform
= *transform
;
1186 static float STDMETHODCALLTYPE
d2d_image_brush_GetOpacity(ID2D1ImageBrush
*iface
)
1188 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1190 TRACE("iface %p.\n", iface
);
1192 return brush
->opacity
;
1195 static void STDMETHODCALLTYPE
d2d_image_brush_GetTransform(ID2D1ImageBrush
*iface
,
1196 D2D1_MATRIX_3X2_F
*transform
)
1198 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1200 TRACE("iface %p, transform %p.\n", iface
, transform
);
1202 *transform
= brush
->transform
;
1205 static void STDMETHODCALLTYPE
d2d_image_brush_SetImage(ID2D1ImageBrush
*iface
, ID2D1Image
*image
)
1207 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1209 TRACE("iface %p, image %p.\n", iface
, image
);
1212 ID2D1Image_AddRef(image
);
1213 if (brush
->u
.image
.image
)
1214 ID2D1Image_Release(brush
->u
.image
.image
);
1215 brush
->u
.image
.image
= image
;
1218 static void STDMETHODCALLTYPE
d2d_image_brush_SetExtendModeX(ID2D1ImageBrush
*iface
, D2D1_EXTEND_MODE mode
)
1220 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1222 TRACE("iface %p, mode %#x.\n", iface
, mode
);
1224 brush
->u
.image
.extend_mode_x
= mode
;
1227 static void STDMETHODCALLTYPE
d2d_image_brush_SetExtendModeY(ID2D1ImageBrush
*iface
, D2D1_EXTEND_MODE mode
)
1229 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1231 TRACE("iface %p, mode %#x.\n", iface
, mode
);
1233 brush
->u
.image
.extend_mode_y
= mode
;
1236 static void STDMETHODCALLTYPE
d2d_image_brush_SetInterpolationMode(ID2D1ImageBrush
*iface
,
1237 D2D1_INTERPOLATION_MODE mode
)
1239 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1241 TRACE("iface %p, mode %#x.\n", iface
, mode
);
1243 brush
->u
.image
.interpolation_mode
= mode
;
1246 static void STDMETHODCALLTYPE
d2d_image_brush_SetSourceRectangle(ID2D1ImageBrush
*iface
, const D2D1_RECT_F
*rect
)
1248 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1250 TRACE("iface %p, rect %s.\n", iface
, debug_d2d_rect_f(rect
));
1252 brush
->u
.image
.source_rect
= *rect
;
1255 static void STDMETHODCALLTYPE
d2d_image_brush_GetImage(ID2D1ImageBrush
*iface
, ID2D1Image
**image
)
1257 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1259 TRACE("iface %p, image %p.\n", iface
, image
);
1261 if ((*image
= (ID2D1Image
*)brush
->u
.image
.image
))
1262 ID2D1Image_AddRef(*image
);
1265 static D2D1_EXTEND_MODE STDMETHODCALLTYPE
d2d_image_brush_GetExtendModeX(ID2D1ImageBrush
*iface
)
1267 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1269 TRACE("iface %p.\n", iface
);
1271 return brush
->u
.image
.extend_mode_x
;
1274 static D2D1_EXTEND_MODE STDMETHODCALLTYPE
d2d_image_brush_GetExtendModeY(ID2D1ImageBrush
*iface
)
1276 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1278 TRACE("iface %p.\n", iface
);
1280 return brush
->u
.image
.extend_mode_y
;
1283 static D2D1_INTERPOLATION_MODE STDMETHODCALLTYPE
d2d_image_brush_GetInterpolationMode(ID2D1ImageBrush
*iface
)
1285 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1287 TRACE("iface %p.\n", iface
);
1289 return brush
->u
.image
.interpolation_mode
;
1292 static void STDMETHODCALLTYPE
d2d_image_brush_GetSourceRectangle(ID2D1ImageBrush
*iface
, D2D1_RECT_F
*rect
)
1294 struct d2d_brush
*brush
= impl_from_ID2D1ImageBrush(iface
);
1296 TRACE("iface %p, rect %p.\n", iface
, rect
);
1298 *rect
= brush
->u
.image
.source_rect
;
1301 static const struct ID2D1ImageBrushVtbl d2d_image_brush_vtbl
=
1303 d2d_image_brush_QueryInterface
,
1304 d2d_image_brush_AddRef
,
1305 d2d_image_brush_Release
,
1306 d2d_image_brush_GetFactory
,
1307 d2d_image_brush_SetOpacity
,
1308 d2d_image_brush_SetTransform
,
1309 d2d_image_brush_GetOpacity
,
1310 d2d_image_brush_GetTransform
,
1311 d2d_image_brush_SetImage
,
1312 d2d_image_brush_SetExtendModeX
,
1313 d2d_image_brush_SetExtendModeY
,
1314 d2d_image_brush_SetInterpolationMode
,
1315 d2d_image_brush_SetSourceRectangle
,
1316 d2d_image_brush_GetImage
,
1317 d2d_image_brush_GetExtendModeX
,
1318 d2d_image_brush_GetExtendModeY
,
1319 d2d_image_brush_GetInterpolationMode
,
1320 d2d_image_brush_GetSourceRectangle
1323 HRESULT
d2d_image_brush_create(ID2D1Factory
*factory
, ID2D1Image
*image
,
1324 const D2D1_IMAGE_BRUSH_PROPERTIES
*image_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
1325 struct d2d_brush
**brush
)
1327 if (!(*brush
= calloc(1, sizeof(**brush
))))
1328 return E_OUTOFMEMORY
;
1330 d2d_brush_init(*brush
, factory
, D2D_BRUSH_TYPE_IMAGE
,
1331 brush_desc
, (ID2D1BrushVtbl
*)&d2d_image_brush_vtbl
);
1332 if (((*brush
)->u
.image
.image
= image
))
1333 ID2D1Image_AddRef((*brush
)->u
.image
.image
);
1335 (*brush
)->u
.image
.source_rect
= image_brush_desc
->sourceRectangle
;
1336 (*brush
)->u
.image
.extend_mode_x
= image_brush_desc
->extendModeX
;
1337 (*brush
)->u
.image
.extend_mode_y
= image_brush_desc
->extendModeY
;
1338 (*brush
)->u
.image
.interpolation_mode
= image_brush_desc
->interpolationMode
;
1340 TRACE("Created brush %p.\n", *brush
);
1344 struct d2d_brush
*unsafe_impl_from_ID2D1Brush(ID2D1Brush
*iface
)
1348 assert(iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_solid_color_brush_vtbl
1349 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_linear_gradient_brush_vtbl
1350 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_radial_gradient_brush_vtbl
1351 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_bitmap_brush_vtbl
1352 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_image_brush_vtbl
);
1353 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
1356 static D3D11_TEXTURE_ADDRESS_MODE
texture_address_mode_from_extend_mode(D2D1_EXTEND_MODE mode
)
1360 case D2D1_EXTEND_MODE_CLAMP
:
1361 return D3D11_TEXTURE_ADDRESS_CLAMP
;
1362 case D2D1_EXTEND_MODE_WRAP
:
1363 return D3D11_TEXTURE_ADDRESS_WRAP
;
1364 case D2D1_EXTEND_MODE_MIRROR
:
1365 return D3D11_TEXTURE_ADDRESS_MIRROR
;
1367 FIXME("Unhandled extend mode %#x.\n", mode
);
1368 return D3D11_TEXTURE_ADDRESS_CLAMP
;
1372 BOOL
d2d_brush_fill_cb(const struct d2d_brush
*brush
, struct d2d_brush_cb
*cb
)
1374 float theta
, sin_theta
, cos_theta
;
1375 float dpi_scale
, d
, s1
, s2
, t
, u
;
1376 struct d2d_bitmap
*bitmap
;
1377 D2D1_POINT_2F v_p
, v_q
;
1378 D2D1_COLOR_F
*colour
;
1383 cb
->type
= D2D_BRUSH_TYPE_COUNT
;
1387 cb
->type
= brush
->type
;
1388 cb
->opacity
= brush
->opacity
;
1390 switch (brush
->type
)
1392 case D2D_BRUSH_TYPE_SOLID
:
1393 colour
= &cb
->u
.solid
.colour
;
1395 *colour
= brush
->u
.solid
.color
;
1396 colour
->r
*= colour
->a
;
1397 colour
->g
*= colour
->a
;
1398 colour
->b
*= colour
->a
;
1402 case D2D_BRUSH_TYPE_LINEAR
:
1403 b
= brush
->transform
;
1404 d2d_point_transform(&cb
->u
.linear
.start
, &b
, brush
->u
.linear
.start
.x
, brush
->u
.linear
.start
.y
);
1405 d2d_point_transform(&cb
->u
.linear
.end
, &b
, brush
->u
.linear
.end
.x
, brush
->u
.linear
.end
.y
);
1406 cb
->u
.linear
.stop_count
= brush
->u
.linear
.gradient
->stop_count
;
1410 case D2D_BRUSH_TYPE_RADIAL
:
1411 b
= brush
->transform
;
1412 d2d_point_transform(&cb
->u
.radial
.centre
, &b
, brush
->u
.radial
.centre
.x
, brush
->u
.radial
.centre
.y
);
1413 b
._31
= b
._32
= 0.0f
;
1414 d2d_point_transform(&cb
->u
.radial
.offset
, &b
, brush
->u
.radial
.offset
.x
, brush
->u
.radial
.offset
.y
);
1416 /* After a transformation, the axes of the ellipse are no longer
1417 * necessarily orthogonal, but they are conjugate diameters.
1422 * = ⎡cos(θ) -sin(θ)⎤⎡σ₁ 0 ⎤⎡cos(φ) -sin(φ)⎤
1423 * ⎣sin(θ) cos(θ)⎦⎣0 σ₂⎦⎣sin(φ) cos(φ)⎦
1425 * a' = [σ₁· cos(θ) σ₁·sin(θ)]
1426 * b' = [σ₂·-sin(θ) σ₂·cos(θ)] */
1428 d2d_point_set(&v_p
, brush
->u
.radial
.radius
.x
* b
._11
, brush
->u
.radial
.radius
.y
* b
._21
);
1429 d2d_point_set(&v_q
, brush
->u
.radial
.radius
.x
* b
._12
, brush
->u
.radial
.radius
.y
* b
._22
);
1431 t
= 0.5f
* d2d_point_dot(&v_p
, &v_p
);
1432 u
= 0.5f
* d2d_point_dot(&v_q
, &v_q
);
1436 u
= d2d_point_dot(&v_p
, &v_q
);
1437 s2
= sqrtf(t
* t
+ u
* u
);
1439 theta
= 0.5f
* atan2(u
, t
);
1440 sin_theta
= sinf(theta
);
1441 cos_theta
= cosf(theta
);
1444 d2d_point_set(&cb
->u
.radial
.ra
, t
* cos_theta
, t
* sin_theta
);
1446 d2d_point_set(&cb
->u
.radial
.rb
, t
* -sin_theta
, t
* cos_theta
);
1448 cb
->u
.radial
.stop_count
= brush
->u
.linear
.gradient
->stop_count
;
1452 case D2D_BRUSH_TYPE_BITMAP
:
1453 case D2D_BRUSH_TYPE_IMAGE
:
1455 ID2D1Bitmap
*image_bitmap
= NULL
;
1457 if (brush
->type
== D2D_BRUSH_TYPE_BITMAP
)
1458 bitmap
= brush
->u
.bitmap
.bitmap
;
1461 if (FAILED(ID2D1Image_QueryInterface(brush
->u
.image
.image
, &IID_ID2D1Bitmap
, (void **)&image_bitmap
)))
1463 FIXME("Only image brushes with bitmaps are supported.\n");
1467 bitmap
= unsafe_impl_from_ID2D1Bitmap(image_bitmap
);
1468 cb
->type
= D2D_BRUSH_TYPE_BITMAP
;
1471 /* Scale for bitmap size and dpi. */
1472 b
= brush
->transform
;
1473 dpi_scale
= bitmap
->pixel_size
.width
* (96.0f
/ bitmap
->dpi_x
);
1476 dpi_scale
= bitmap
->pixel_size
.height
* (96.0f
/ bitmap
->dpi_y
);
1480 /* Invert the matrix. (Because the matrix is applied to the
1481 * sampling coordinates. I.e., to scale the bitmap by 2 we need to
1482 * divide the coordinates by 2.) */
1483 d
= b
._11
* b
._22
- b
._21
* b
._12
;
1486 cb
->u
.bitmap
._11
= b
._22
/ d
;
1487 cb
->u
.bitmap
._21
= -b
._21
/ d
;
1488 cb
->u
.bitmap
._31
= (b
._21
* b
._32
- b
._31
* b
._22
) / d
;
1489 cb
->u
.bitmap
._12
= -b
._12
/ d
;
1490 cb
->u
.bitmap
._22
= b
._11
/ d
;
1491 cb
->u
.bitmap
._32
= -(b
._11
* b
._32
- b
._31
* b
._12
) / d
;
1494 cb
->u
.bitmap
.ignore_alpha
= bitmap
->format
.alphaMode
== D2D1_ALPHA_MODE_IGNORE
;
1497 ID2D1Bitmap_Release(image_bitmap
);
1503 FIXME("Unhandled brush type %#x.\n", brush
->type
);
1508 static void d2d_brush_bind_bitmap(struct d2d_bitmap
*bitmap
, struct d2d_device_context
*context
,
1509 D2D1_EXTEND_MODE extend_mode_x
, D2D1_EXTEND_MODE extend_mode_y
,
1510 D2D1_INTERPOLATION_MODE interpolation_mode
, unsigned int brush_idx
)
1512 ID3D11SamplerState
**sampler_state
;
1513 ID3D11DeviceContext
*d3d_context
;
1516 ID3D11Device1_GetImmediateContext(context
->d3d_device
, &d3d_context
);
1517 ID3D11DeviceContext_PSSetShaderResources(d3d_context
, brush_idx
, 1, &bitmap
->srv
);
1519 sampler_state
= &context
->sampler_states
1520 [interpolation_mode
% D2D_SAMPLER_INTERPOLATION_MODE_COUNT
]
1521 [extend_mode_x
% D2D_SAMPLER_EXTEND_MODE_COUNT
]
1522 [extend_mode_y
% D2D_SAMPLER_EXTEND_MODE_COUNT
];
1524 if (!*sampler_state
)
1526 D3D11_SAMPLER_DESC sampler_desc
;
1528 if (interpolation_mode
== D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR
)
1529 sampler_desc
.Filter
= D3D11_FILTER_MIN_MAG_MIP_POINT
;
1531 sampler_desc
.Filter
= D3D11_FILTER_MIN_MAG_MIP_LINEAR
;
1532 sampler_desc
.AddressU
= texture_address_mode_from_extend_mode(extend_mode_x
);
1533 sampler_desc
.AddressV
= texture_address_mode_from_extend_mode(extend_mode_y
);
1534 sampler_desc
.AddressW
= D3D11_TEXTURE_ADDRESS_CLAMP
;
1535 sampler_desc
.MipLODBias
= 0.0f
;
1536 sampler_desc
.MaxAnisotropy
= 0;
1537 sampler_desc
.ComparisonFunc
= D3D11_COMPARISON_NEVER
;
1538 sampler_desc
.BorderColor
[0] = 0.0f
;
1539 sampler_desc
.BorderColor
[1] = 0.0f
;
1540 sampler_desc
.BorderColor
[2] = 0.0f
;
1541 sampler_desc
.BorderColor
[3] = 0.0f
;
1542 sampler_desc
.MinLOD
= 0.0f
;
1543 sampler_desc
.MaxLOD
= 0.0f
;
1545 if (FAILED(hr
= ID3D11Device1_CreateSamplerState(context
->d3d_device
, &sampler_desc
, sampler_state
)))
1546 ERR("Failed to create sampler state, hr %#lx.\n", hr
);
1549 ID3D11DeviceContext_PSSetSamplers(d3d_context
, brush_idx
, 1, sampler_state
);
1550 ID3D11DeviceContext_Release(d3d_context
);
1553 static void d2d_brush_bind_image(struct d2d_brush
*brush
, struct d2d_device_context
*context
,
1554 unsigned int brush_idx
)
1556 ID2D1Bitmap
*image_bitmap
;
1557 struct d2d_bitmap
*bitmap
;
1559 if (FAILED(ID2D1Image_QueryInterface(brush
->u
.image
.image
, &IID_ID2D1Bitmap
, (void **)&image_bitmap
)))
1561 FIXME("Only image brushes with bitmaps are supported.\n");
1565 bitmap
= unsafe_impl_from_ID2D1Bitmap(image_bitmap
);
1567 d2d_brush_bind_bitmap(bitmap
, context
, brush
->u
.image
.extend_mode_x
, brush
->u
.image
.extend_mode_y
,
1568 brush
->u
.image
.interpolation_mode
, brush_idx
);
1570 ID2D1Bitmap_Release(image_bitmap
);
1573 void d2d_brush_bind_resources(struct d2d_brush
*brush
, struct d2d_device_context
*context
, unsigned int brush_idx
)
1575 switch (brush
->type
)
1577 case D2D_BRUSH_TYPE_SOLID
:
1580 case D2D_BRUSH_TYPE_LINEAR
:
1581 d2d_gradient_bind(brush
->u
.linear
.gradient
, context
->d3d_device
, brush_idx
);
1584 case D2D_BRUSH_TYPE_RADIAL
:
1585 d2d_gradient_bind(brush
->u
.radial
.gradient
, context
->d3d_device
, brush_idx
);
1588 case D2D_BRUSH_TYPE_BITMAP
:
1589 d2d_brush_bind_bitmap(brush
->u
.bitmap
.bitmap
, context
, brush
->u
.bitmap
.extend_mode_x
,
1590 brush
->u
.bitmap
.extend_mode_y
, brush
->u
.bitmap
.interpolation_mode
, brush_idx
);
1593 case D2D_BRUSH_TYPE_IMAGE
:
1594 d2d_brush_bind_image(brush
, context
, brush_idx
);
1598 FIXME("Unhandled brush type %#x.\n", brush
->type
);