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 %s.\n", iface
, debug_d2d_point_2f(&start_point
));
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 %s.\n", iface
, debug_d2d_point_2f(&end_point
));
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 %s.\n", iface
, debug_d2d_point_2f(¢re
));
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 %s.\n", iface
, debug_d2d_point_2f(&offset
));
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_ID2D1BitmapBrush1(ID2D1BitmapBrush1
*iface
)
821 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
824 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_brush_QueryInterface(ID2D1BitmapBrush1
*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_ID2D1BitmapBrush1
)
830 || IsEqualGUID(iid
, &IID_ID2D1BitmapBrush
)
831 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
832 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
833 || IsEqualGUID(iid
, &IID_IUnknown
))
835 ID2D1BitmapBrush1_AddRef(iface
);
840 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
843 return E_NOINTERFACE
;
846 static ULONG STDMETHODCALLTYPE
d2d_bitmap_brush_AddRef(ID2D1BitmapBrush1
*iface
)
848 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
849 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
851 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
856 static ULONG STDMETHODCALLTYPE
d2d_bitmap_brush_Release(ID2D1BitmapBrush1
*iface
)
858 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
859 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
861 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
865 if (brush
->u
.bitmap
.sampler_state
)
866 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
867 if (brush
->u
.bitmap
.bitmap
)
868 ID2D1Bitmap1_Release(&brush
->u
.bitmap
.bitmap
->ID2D1Bitmap1_iface
);
869 d2d_brush_destroy(brush
);
875 static void STDMETHODCALLTYPE
d2d_bitmap_brush_GetFactory(ID2D1BitmapBrush1
*iface
,
876 ID2D1Factory
**factory
)
878 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
880 TRACE("iface %p, factory %p.\n", iface
, factory
);
882 ID2D1Factory_AddRef(*factory
= brush
->factory
);
885 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetOpacity(ID2D1BitmapBrush1
*iface
, float opacity
)
887 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
889 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
891 brush
->opacity
= opacity
;
894 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetTransform(ID2D1BitmapBrush1
*iface
,
895 const D2D1_MATRIX_3X2_F
*transform
)
897 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
899 TRACE("iface %p, transform %p.\n", iface
, transform
);
901 brush
->transform
= *transform
;
904 static float STDMETHODCALLTYPE
d2d_bitmap_brush_GetOpacity(ID2D1BitmapBrush1
*iface
)
906 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
908 TRACE("iface %p.\n", iface
);
910 return brush
->opacity
;
913 static void STDMETHODCALLTYPE
d2d_bitmap_brush_GetTransform(ID2D1BitmapBrush1
*iface
,
914 D2D1_MATRIX_3X2_F
*transform
)
916 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
918 TRACE("iface %p, transform %p.\n", iface
, transform
);
920 *transform
= brush
->transform
;
923 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetExtendModeX(ID2D1BitmapBrush1
*iface
, D2D1_EXTEND_MODE mode
)
925 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
927 TRACE("iface %p, mode %#x.\n", iface
, mode
);
929 brush
->u
.bitmap
.extend_mode_x
= mode
;
930 if (brush
->u
.bitmap
.sampler_state
)
932 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
933 brush
->u
.bitmap
.sampler_state
= NULL
;
937 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetExtendModeY(ID2D1BitmapBrush1
*iface
, D2D1_EXTEND_MODE mode
)
939 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
941 TRACE("iface %p, mode %#x.\n", iface
, mode
);
943 brush
->u
.bitmap
.extend_mode_y
= mode
;
944 if (brush
->u
.bitmap
.sampler_state
)
946 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
947 brush
->u
.bitmap
.sampler_state
= NULL
;
951 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetInterpolationMode(ID2D1BitmapBrush1
*iface
,
952 D2D1_BITMAP_INTERPOLATION_MODE mode
)
954 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
956 TRACE("iface %p, mode %#x.\n", iface
, mode
);
960 case D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR
:
961 case D2D1_BITMAP_INTERPOLATION_MODE_LINEAR
:
964 WARN("Unknown interpolation mode %#x.\n", mode
);
968 brush
->u
.bitmap
.interpolation_mode
= mode
;
969 if (brush
->u
.bitmap
.sampler_state
)
971 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
972 brush
->u
.bitmap
.sampler_state
= NULL
;
976 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetBitmap(ID2D1BitmapBrush1
*iface
, ID2D1Bitmap
*bitmap
)
978 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
980 TRACE("iface %p, bitmap %p.\n", iface
, bitmap
);
983 ID2D1Bitmap_AddRef(bitmap
);
984 if (brush
->u
.bitmap
.bitmap
)
985 ID2D1Bitmap1_Release(&brush
->u
.bitmap
.bitmap
->ID2D1Bitmap1_iface
);
986 brush
->u
.bitmap
.bitmap
= unsafe_impl_from_ID2D1Bitmap(bitmap
);
989 static D2D1_EXTEND_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetExtendModeX(ID2D1BitmapBrush1
*iface
)
991 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
993 TRACE("iface %p.\n", iface
);
995 return brush
->u
.bitmap
.extend_mode_x
;
998 static D2D1_EXTEND_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetExtendModeY(ID2D1BitmapBrush1
*iface
)
1000 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
1002 TRACE("iface %p.\n", iface
);
1004 return brush
->u
.bitmap
.extend_mode_y
;
1007 static D2D1_BITMAP_INTERPOLATION_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetInterpolationMode(ID2D1BitmapBrush1
*iface
)
1009 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
1011 TRACE("iface %p.\n", iface
);
1013 switch (brush
->u
.bitmap
.interpolation_mode
)
1015 case D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR
:
1016 case D2D1_INTERPOLATION_MODE_LINEAR
:
1017 return brush
->u
.bitmap
.interpolation_mode
;
1019 return D2D1_BITMAP_INTERPOLATION_MODE_LINEAR
;
1023 static void STDMETHODCALLTYPE
d2d_bitmap_brush_GetBitmap(ID2D1BitmapBrush1
*iface
, ID2D1Bitmap
**bitmap
)
1025 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
1027 TRACE("iface %p, bitmap %p.\n", iface
, bitmap
);
1029 if ((*bitmap
= (ID2D1Bitmap
*)&brush
->u
.bitmap
.bitmap
->ID2D1Bitmap1_iface
))
1030 ID2D1Bitmap_AddRef(*bitmap
);
1033 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetInterpolationMode1(ID2D1BitmapBrush1
*iface
,
1034 D2D1_INTERPOLATION_MODE mode
)
1036 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
1038 TRACE("iface %p, mode %#x.\n", iface
, mode
);
1042 case D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR
:
1043 case D2D1_INTERPOLATION_MODE_LINEAR
:
1045 case D2D1_INTERPOLATION_MODE_CUBIC
:
1046 case D2D1_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR
:
1047 case D2D1_INTERPOLATION_MODE_ANISOTROPIC
:
1048 case D2D1_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC
:
1049 FIXME("Unhandled interpolation mode %#x.\n", mode
);
1052 WARN("Unknown interpolation mode %#x.\n", mode
);
1056 brush
->u
.bitmap
.interpolation_mode
= mode
;
1057 if (brush
->u
.bitmap
.sampler_state
)
1059 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
1060 brush
->u
.bitmap
.sampler_state
= NULL
;
1064 static D2D1_INTERPOLATION_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetInterpolationMode1(ID2D1BitmapBrush1
*iface
)
1066 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
1068 TRACE("iface %p.\n", iface
);
1070 return brush
->u
.bitmap
.interpolation_mode
;
1073 static const struct ID2D1BitmapBrush1Vtbl d2d_bitmap_brush_vtbl
=
1075 d2d_bitmap_brush_QueryInterface
,
1076 d2d_bitmap_brush_AddRef
,
1077 d2d_bitmap_brush_Release
,
1078 d2d_bitmap_brush_GetFactory
,
1079 d2d_bitmap_brush_SetOpacity
,
1080 d2d_bitmap_brush_SetTransform
,
1081 d2d_bitmap_brush_GetOpacity
,
1082 d2d_bitmap_brush_GetTransform
,
1083 d2d_bitmap_brush_SetExtendModeX
,
1084 d2d_bitmap_brush_SetExtendModeY
,
1085 d2d_bitmap_brush_SetInterpolationMode
,
1086 d2d_bitmap_brush_SetBitmap
,
1087 d2d_bitmap_brush_GetExtendModeX
,
1088 d2d_bitmap_brush_GetExtendModeY
,
1089 d2d_bitmap_brush_GetInterpolationMode
,
1090 d2d_bitmap_brush_GetBitmap
,
1091 d2d_bitmap_brush_SetInterpolationMode1
,
1092 d2d_bitmap_brush_GetInterpolationMode1
,
1095 HRESULT
d2d_bitmap_brush_create(ID2D1Factory
*factory
, ID2D1Bitmap
*bitmap
,
1096 const D2D1_BITMAP_BRUSH_PROPERTIES1
*bitmap_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
1097 struct d2d_brush
**brush
)
1099 if (!(*brush
= heap_alloc_zero(sizeof(**brush
))))
1100 return E_OUTOFMEMORY
;
1102 d2d_brush_init(*brush
, factory
, D2D_BRUSH_TYPE_BITMAP
,
1103 brush_desc
, (ID2D1BrushVtbl
*)&d2d_bitmap_brush_vtbl
);
1104 if (((*brush
)->u
.bitmap
.bitmap
= unsafe_impl_from_ID2D1Bitmap(bitmap
)))
1105 ID2D1Bitmap1_AddRef(&(*brush
)->u
.bitmap
.bitmap
->ID2D1Bitmap1_iface
);
1106 if (bitmap_brush_desc
)
1108 (*brush
)->u
.bitmap
.extend_mode_x
= bitmap_brush_desc
->extendModeX
;
1109 (*brush
)->u
.bitmap
.extend_mode_y
= bitmap_brush_desc
->extendModeY
;
1110 (*brush
)->u
.bitmap
.interpolation_mode
= bitmap_brush_desc
->interpolationMode
;
1114 (*brush
)->u
.bitmap
.extend_mode_x
= D2D1_EXTEND_MODE_CLAMP
;
1115 (*brush
)->u
.bitmap
.extend_mode_y
= D2D1_EXTEND_MODE_CLAMP
;
1116 (*brush
)->u
.bitmap
.interpolation_mode
= D2D1_INTERPOLATION_MODE_LINEAR
;
1119 TRACE("Created brush %p.\n", *brush
);
1123 struct d2d_brush
*unsafe_impl_from_ID2D1Brush(ID2D1Brush
*iface
)
1127 assert(iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_solid_color_brush_vtbl
1128 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_linear_gradient_brush_vtbl
1129 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_radial_gradient_brush_vtbl
1130 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_bitmap_brush_vtbl
);
1131 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
1134 static D3D10_TEXTURE_ADDRESS_MODE
texture_address_mode_from_extend_mode(D2D1_EXTEND_MODE mode
)
1138 case D2D1_EXTEND_MODE_CLAMP
:
1139 return D3D10_TEXTURE_ADDRESS_CLAMP
;
1140 case D2D1_EXTEND_MODE_WRAP
:
1141 return D3D10_TEXTURE_ADDRESS_WRAP
;
1142 case D2D1_EXTEND_MODE_MIRROR
:
1143 return D3D10_TEXTURE_ADDRESS_MIRROR
;
1145 FIXME("Unhandled extend mode %#x.\n", mode
);
1146 return D3D10_TEXTURE_ADDRESS_CLAMP
;
1150 static BOOL
d2d_brush_fill_cb(const struct d2d_brush
*brush
,
1151 const struct d2d_device_context
*render_target
, struct d2d_brush_cb
*cb
)
1153 float theta
, sin_theta
, cos_theta
;
1154 float dpi_scale
, d
, s1
, s2
, t
, u
;
1155 struct d2d_bitmap
*bitmap
;
1156 D2D1_POINT_2F v_p
, v_q
;
1157 D2D1_COLOR_F
*colour
;
1162 cb
->type
= D2D_BRUSH_TYPE_COUNT
;
1166 cb
->type
= brush
->type
;
1167 cb
->opacity
= brush
->opacity
;
1169 switch (brush
->type
)
1171 case D2D_BRUSH_TYPE_SOLID
:
1172 colour
= &cb
->u
.solid
.colour
;
1174 *colour
= brush
->u
.solid
.color
;
1175 colour
->r
*= colour
->a
;
1176 colour
->g
*= colour
->a
;
1177 colour
->b
*= colour
->a
;
1181 case D2D_BRUSH_TYPE_LINEAR
:
1182 b
= brush
->transform
;
1183 d2d_point_transform(&cb
->u
.linear
.start
, &b
, brush
->u
.linear
.start
.x
, brush
->u
.linear
.start
.y
);
1184 d2d_point_transform(&cb
->u
.linear
.end
, &b
, brush
->u
.linear
.end
.x
, brush
->u
.linear
.end
.y
);
1185 cb
->u
.linear
.stop_count
= brush
->u
.linear
.gradient
->stop_count
;
1189 case D2D_BRUSH_TYPE_RADIAL
:
1190 b
= brush
->transform
;
1191 d2d_point_transform(&cb
->u
.radial
.centre
, &b
, brush
->u
.radial
.centre
.x
, brush
->u
.radial
.centre
.y
);
1192 b
._31
= b
._32
= 0.0f
;
1193 d2d_point_transform(&cb
->u
.radial
.offset
, &b
, brush
->u
.radial
.offset
.x
, brush
->u
.radial
.offset
.y
);
1195 /* After a transformation, the axes of the ellipse are no longer
1196 * necessarily orthogonal, but they are conjugate diameters.
1201 * = ⎡cos(θ) -sin(θ)⎤⎡σ₁ 0 ⎤⎡cos(φ) -sin(φ)⎤
1202 * ⎣sin(θ) cos(θ)⎦⎣0 σ₂⎦⎣sin(φ) cos(φ)⎦
1204 * a' = [σ₁· cos(θ) σ₁·sin(θ)]
1205 * b' = [σ₂·-sin(θ) σ₂·cos(θ)] */
1207 d2d_point_set(&v_p
, brush
->u
.radial
.radius
.x
* b
._11
, brush
->u
.radial
.radius
.y
* b
._21
);
1208 d2d_point_set(&v_q
, brush
->u
.radial
.radius
.x
* b
._12
, brush
->u
.radial
.radius
.y
* b
._22
);
1210 t
= 0.5f
* d2d_point_dot(&v_p
, &v_p
);
1211 u
= 0.5f
* d2d_point_dot(&v_q
, &v_q
);
1215 u
= d2d_point_dot(&v_p
, &v_q
);
1216 s2
= sqrtf(t
* t
+ u
* u
);
1218 theta
= 0.5f
* atan2(u
, t
);
1219 sin_theta
= sinf(theta
);
1220 cos_theta
= cosf(theta
);
1223 d2d_point_set(&cb
->u
.radial
.ra
, t
* cos_theta
, t
* sin_theta
);
1225 d2d_point_set(&cb
->u
.radial
.rb
, t
* -sin_theta
, t
* cos_theta
);
1227 cb
->u
.radial
.stop_count
= brush
->u
.linear
.gradient
->stop_count
;
1231 case D2D_BRUSH_TYPE_BITMAP
:
1232 bitmap
= brush
->u
.bitmap
.bitmap
;
1234 /* Scale for bitmap size and dpi. */
1235 b
= brush
->transform
;
1236 dpi_scale
= bitmap
->pixel_size
.width
* (96.0f
/ bitmap
->dpi_x
);
1239 dpi_scale
= bitmap
->pixel_size
.height
* (96.0f
/ bitmap
->dpi_y
);
1243 /* Invert the matrix. (Because the matrix is applied to the
1244 * sampling coordinates. I.e., to scale the bitmap by 2 we need to
1245 * divide the coordinates by 2.) */
1246 d
= b
._11
* b
._22
- b
._21
* b
._12
;
1249 cb
->u
.bitmap
._11
= b
._22
/ d
;
1250 cb
->u
.bitmap
._21
= -b
._21
/ d
;
1251 cb
->u
.bitmap
._31
= (b
._21
* b
._32
- b
._31
* b
._22
) / d
;
1252 cb
->u
.bitmap
._12
= -b
._12
/ d
;
1253 cb
->u
.bitmap
._22
= b
._11
/ d
;
1254 cb
->u
.bitmap
._32
= -(b
._11
* b
._32
- b
._31
* b
._12
) / d
;
1257 cb
->u
.bitmap
.ignore_alpha
= bitmap
->format
.alphaMode
== D2D1_ALPHA_MODE_IGNORE
;
1262 FIXME("Unhandled brush type %#x.\n", brush
->type
);
1267 HRESULT
d2d_brush_get_ps_cb(struct d2d_brush
*brush
, struct d2d_brush
*opacity_brush
,
1268 BOOL outline
, struct d2d_device_context
*render_target
, ID3D10Buffer
**ps_cb
)
1270 D3D10_SUBRESOURCE_DATA buffer_data
;
1271 struct d2d_ps_cb cb_data
= {0};
1272 D3D10_BUFFER_DESC buffer_desc
;
1275 cb_data
.outline
= outline
;
1276 if (!d2d_brush_fill_cb(brush
, render_target
, &cb_data
.colour_brush
))
1278 if (!d2d_brush_fill_cb(opacity_brush
, render_target
, &cb_data
.opacity_brush
))
1281 buffer_desc
.ByteWidth
= sizeof(cb_data
);
1282 buffer_desc
.Usage
= D3D10_USAGE_DEFAULT
;
1283 buffer_desc
.BindFlags
= D3D10_BIND_CONSTANT_BUFFER
;
1284 buffer_desc
.CPUAccessFlags
= 0;
1285 buffer_desc
.MiscFlags
= 0;
1287 buffer_data
.pSysMem
= &cb_data
;
1288 buffer_data
.SysMemPitch
= 0;
1289 buffer_data
.SysMemSlicePitch
= 0;
1291 if (FAILED(hr
= ID3D10Device_CreateBuffer(render_target
->d3d_device
, &buffer_desc
, &buffer_data
, ps_cb
)))
1292 ERR("Failed to create constant buffer, hr %#x.\n", hr
);
1297 static void d2d_brush_bind_bitmap(struct d2d_brush
*brush
, ID3D10Device
*device
, unsigned int brush_idx
)
1301 ID3D10Device_PSSetShaderResources(device
, brush_idx
, 1, &brush
->u
.bitmap
.bitmap
->view
);
1302 if (!brush
->u
.bitmap
.sampler_state
)
1304 D3D10_SAMPLER_DESC sampler_desc
;
1306 if (brush
->u
.bitmap
.interpolation_mode
== D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR
)
1307 sampler_desc
.Filter
= D3D10_FILTER_MIN_MAG_MIP_POINT
;
1309 sampler_desc
.Filter
= D3D10_FILTER_MIN_MAG_MIP_LINEAR
;
1310 sampler_desc
.AddressU
= texture_address_mode_from_extend_mode(brush
->u
.bitmap
.extend_mode_x
);
1311 sampler_desc
.AddressV
= texture_address_mode_from_extend_mode(brush
->u
.bitmap
.extend_mode_y
);
1312 sampler_desc
.AddressW
= D3D10_TEXTURE_ADDRESS_CLAMP
;
1313 sampler_desc
.MipLODBias
= 0.0f
;
1314 sampler_desc
.MaxAnisotropy
= 0;
1315 sampler_desc
.ComparisonFunc
= D3D10_COMPARISON_NEVER
;
1316 sampler_desc
.BorderColor
[0] = 0.0f
;
1317 sampler_desc
.BorderColor
[1] = 0.0f
;
1318 sampler_desc
.BorderColor
[2] = 0.0f
;
1319 sampler_desc
.BorderColor
[3] = 0.0f
;
1320 sampler_desc
.MinLOD
= 0.0f
;
1321 sampler_desc
.MaxLOD
= 0.0f
;
1323 if (FAILED(hr
= ID3D10Device_CreateSamplerState(device
,
1324 &sampler_desc
, &brush
->u
.bitmap
.sampler_state
)))
1325 ERR("Failed to create sampler state, hr %#x.\n", hr
);
1327 ID3D10Device_PSSetSamplers(device
, brush_idx
, 1, &brush
->u
.bitmap
.sampler_state
);
1330 void d2d_brush_bind_resources(struct d2d_brush
*brush
, ID3D10Device
*device
, unsigned int brush_idx
)
1332 switch (brush
->type
)
1334 case D2D_BRUSH_TYPE_SOLID
:
1337 case D2D_BRUSH_TYPE_LINEAR
:
1338 d2d_gradient_bind(brush
->u
.linear
.gradient
, device
, brush_idx
);
1341 case D2D_BRUSH_TYPE_RADIAL
:
1342 d2d_gradient_bind(brush
->u
.radial
.gradient
, device
, brush_idx
);
1345 case D2D_BRUSH_TYPE_BITMAP
:
1346 d2d_brush_bind_bitmap(brush
, device
, brush_idx
);
1350 FIXME("Unhandled brush type %#x.\n", brush
->type
);