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 %u.\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 %u.\n", iface
, refcount
);
67 heap_free(gradient
->stops
);
68 ID3D10ShaderResourceView_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
, ID3D10Device
*device
, const D2D1_GRADIENT_STOP
*stops
,
131 UINT32 stop_count
, D2D1_GAMMA gamma
, D2D1_EXTEND_MODE extend_mode
, struct d2d_gradient
**gradient
)
133 D3D10_SHADER_RESOURCE_VIEW_DESC srv_desc
;
134 D3D10_SUBRESOURCE_DATA buffer_data
;
135 ID3D10ShaderResourceView
*view
;
136 D3D10_BUFFER_DESC buffer_desc
;
137 struct d2d_vec4
*data
;
138 ID3D10Buffer
*buffer
;
142 if (!(data
= heap_calloc(stop_count
, 2 * sizeof(*data
))))
144 ERR("Failed to allocate data.\n");
145 return E_OUTOFMEMORY
;
148 for (i
= 0; i
< stop_count
; ++i
)
150 data
[i
* 2].x
= stops
[i
].position
;
151 data
[i
* 2 + 1].x
= stops
[i
].color
.r
;
152 data
[i
* 2 + 1].y
= stops
[i
].color
.g
;
153 data
[i
* 2 + 1].z
= stops
[i
].color
.b
;
154 data
[i
* 2 + 1].w
= stops
[i
].color
.a
;
157 buffer_desc
.ByteWidth
= 2 * stop_count
* sizeof(*data
);
158 buffer_desc
.Usage
= D3D10_USAGE_DEFAULT
;
159 buffer_desc
.BindFlags
= D3D10_BIND_SHADER_RESOURCE
;
160 buffer_desc
.CPUAccessFlags
= 0;
161 buffer_desc
.MiscFlags
= 0;
163 buffer_data
.pSysMem
= data
;
164 buffer_data
.SysMemPitch
= 0;
165 buffer_data
.SysMemSlicePitch
= 0;
167 hr
= ID3D10Device_CreateBuffer(device
, &buffer_desc
, &buffer_data
, &buffer
);
171 ERR("Failed to create buffer, hr %#x.\n", hr
);
175 srv_desc
.Format
= DXGI_FORMAT_R32G32B32A32_FLOAT
;
176 srv_desc
.ViewDimension
= D3D10_SRV_DIMENSION_BUFFER
;
177 srv_desc
.Buffer
.ElementOffset
= 0;
178 srv_desc
.Buffer
.ElementWidth
= 2 * stop_count
;
180 hr
= ID3D10Device_CreateShaderResourceView(device
, (ID3D10Resource
*)buffer
, &srv_desc
, &view
);
181 ID3D10Buffer_Release(buffer
);
184 ERR("Failed to create view, hr %#x.\n", hr
);
188 if (!(*gradient
= heap_alloc_zero(sizeof(**gradient
))))
190 ID3D10ShaderResourceView_Release(view
);
191 return E_OUTOFMEMORY
;
194 if (gamma
!= D2D1_GAMMA_2_2
)
195 FIXME("Ignoring gamma %#x.\n", gamma
);
196 if (extend_mode
!= D2D1_EXTEND_MODE_CLAMP
)
197 FIXME("Ignoring extend mode %#x.\n", extend_mode
);
199 (*gradient
)->ID2D1GradientStopCollection_iface
.lpVtbl
= &d2d_gradient_vtbl
;
200 (*gradient
)->refcount
= 1;
201 ID2D1Factory_AddRef((*gradient
)->factory
= factory
);
202 (*gradient
)->view
= view
;
204 (*gradient
)->stop_count
= stop_count
;
205 if (!((*gradient
)->stops
= heap_calloc(stop_count
, sizeof(*stops
))))
207 ID3D10ShaderResourceView_Release(view
);
208 heap_free(*gradient
);
209 return E_OUTOFMEMORY
;
211 memcpy((*gradient
)->stops
, stops
, stop_count
* sizeof(*stops
));
213 TRACE("Created gradient %p.\n", *gradient
);
217 static struct d2d_gradient
*unsafe_impl_from_ID2D1GradientStopCollection(ID2D1GradientStopCollection
*iface
)
221 assert(iface
->lpVtbl
== &d2d_gradient_vtbl
);
222 return CONTAINING_RECORD(iface
, struct d2d_gradient
, ID2D1GradientStopCollection_iface
);
225 static void d2d_gradient_bind(struct d2d_gradient
*gradient
, ID3D10Device
*device
, unsigned int brush_idx
)
227 ID3D10Device_PSSetShaderResources(device
, 2 + brush_idx
, 1, &gradient
->view
);
230 static void d2d_brush_destroy(struct d2d_brush
*brush
)
232 ID2D1Factory_Release(brush
->factory
);
236 static void d2d_brush_init(struct d2d_brush
*brush
, ID2D1Factory
*factory
,
237 enum d2d_brush_type type
, const D2D1_BRUSH_PROPERTIES
*desc
, const struct ID2D1BrushVtbl
*vtbl
)
239 static const D2D1_MATRIX_3X2_F identity
=
246 brush
->ID2D1Brush_iface
.lpVtbl
= vtbl
;
248 ID2D1Factory_AddRef(brush
->factory
= factory
);
249 brush
->opacity
= desc
? desc
->opacity
: 1.0f
;
250 brush
->transform
= desc
? desc
->transform
: identity
;
254 static inline struct d2d_brush
*impl_from_ID2D1SolidColorBrush(ID2D1SolidColorBrush
*iface
)
256 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
259 static HRESULT STDMETHODCALLTYPE
d2d_solid_color_brush_QueryInterface(ID2D1SolidColorBrush
*iface
,
260 REFIID iid
, void **out
)
262 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
264 if (IsEqualGUID(iid
, &IID_ID2D1SolidColorBrush
)
265 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
266 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
267 || IsEqualGUID(iid
, &IID_IUnknown
))
269 ID2D1SolidColorBrush_AddRef(iface
);
274 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
277 return E_NOINTERFACE
;
280 static ULONG STDMETHODCALLTYPE
d2d_solid_color_brush_AddRef(ID2D1SolidColorBrush
*iface
)
282 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
283 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
285 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
290 static ULONG STDMETHODCALLTYPE
d2d_solid_color_brush_Release(ID2D1SolidColorBrush
*iface
)
292 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
293 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
295 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
298 d2d_brush_destroy(brush
);
303 static void STDMETHODCALLTYPE
d2d_solid_color_brush_GetFactory(ID2D1SolidColorBrush
*iface
, ID2D1Factory
**factory
)
305 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
307 TRACE("iface %p, factory %p.\n", iface
, factory
);
309 ID2D1Factory_AddRef(*factory
= brush
->factory
);
312 static void STDMETHODCALLTYPE
d2d_solid_color_brush_SetOpacity(ID2D1SolidColorBrush
*iface
, float opacity
)
314 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
316 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
318 brush
->opacity
= opacity
;
321 static void STDMETHODCALLTYPE
d2d_solid_color_brush_SetTransform(ID2D1SolidColorBrush
*iface
,
322 const D2D1_MATRIX_3X2_F
*transform
)
324 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
326 TRACE("iface %p, transform %p.\n", iface
, transform
);
328 brush
->transform
= *transform
;
331 static float STDMETHODCALLTYPE
d2d_solid_color_brush_GetOpacity(ID2D1SolidColorBrush
*iface
)
333 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
335 TRACE("iface %p.\n", iface
);
337 return brush
->opacity
;
340 static void STDMETHODCALLTYPE
d2d_solid_color_brush_GetTransform(ID2D1SolidColorBrush
*iface
,
341 D2D1_MATRIX_3X2_F
*transform
)
343 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
345 TRACE("iface %p, transform %p.\n", iface
, transform
);
347 *transform
= brush
->transform
;
350 static void STDMETHODCALLTYPE
d2d_solid_color_brush_SetColor(ID2D1SolidColorBrush
*iface
, const D2D1_COLOR_F
*color
)
352 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
354 TRACE("iface %p, color %p.\n", iface
, color
);
356 brush
->u
.solid
.color
= *color
;
359 static D2D1_COLOR_F
* STDMETHODCALLTYPE
d2d_solid_color_brush_GetColor(ID2D1SolidColorBrush
*iface
, D2D1_COLOR_F
*color
)
361 struct d2d_brush
*brush
= impl_from_ID2D1SolidColorBrush(iface
);
363 TRACE("iface %p, color %p.\n", iface
, color
);
365 *color
= brush
->u
.solid
.color
;
369 static const struct ID2D1SolidColorBrushVtbl d2d_solid_color_brush_vtbl
=
371 d2d_solid_color_brush_QueryInterface
,
372 d2d_solid_color_brush_AddRef
,
373 d2d_solid_color_brush_Release
,
374 d2d_solid_color_brush_GetFactory
,
375 d2d_solid_color_brush_SetOpacity
,
376 d2d_solid_color_brush_SetTransform
,
377 d2d_solid_color_brush_GetOpacity
,
378 d2d_solid_color_brush_GetTransform
,
379 d2d_solid_color_brush_SetColor
,
380 d2d_solid_color_brush_GetColor
,
383 HRESULT
d2d_solid_color_brush_create(ID2D1Factory
*factory
, const D2D1_COLOR_F
*color
,
384 const D2D1_BRUSH_PROPERTIES
*desc
, struct d2d_brush
**brush
)
386 if (!(*brush
= heap_alloc_zero(sizeof(**brush
))))
387 return E_OUTOFMEMORY
;
389 d2d_brush_init(*brush
, factory
, D2D_BRUSH_TYPE_SOLID
, desc
,
390 (ID2D1BrushVtbl
*)&d2d_solid_color_brush_vtbl
);
391 (*brush
)->u
.solid
.color
= *color
;
393 TRACE("Created brush %p.\n", *brush
);
397 static inline struct d2d_brush
*impl_from_ID2D1LinearGradientBrush(ID2D1LinearGradientBrush
*iface
)
399 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
402 static HRESULT STDMETHODCALLTYPE
d2d_linear_gradient_brush_QueryInterface(ID2D1LinearGradientBrush
*iface
,
403 REFIID iid
, void **out
)
405 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
407 if (IsEqualGUID(iid
, &IID_ID2D1LinearGradientBrush
)
408 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
409 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
410 || IsEqualGUID(iid
, &IID_IUnknown
))
412 ID2D1LinearGradientBrush_AddRef(iface
);
417 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
420 return E_NOINTERFACE
;
423 static ULONG STDMETHODCALLTYPE
d2d_linear_gradient_brush_AddRef(ID2D1LinearGradientBrush
*iface
)
425 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
426 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
428 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
433 static ULONG STDMETHODCALLTYPE
d2d_linear_gradient_brush_Release(ID2D1LinearGradientBrush
*iface
)
435 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
436 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
438 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
442 ID2D1GradientStopCollection_Release(&brush
->u
.linear
.gradient
->ID2D1GradientStopCollection_iface
);
443 d2d_brush_destroy(brush
);
449 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetFactory(ID2D1LinearGradientBrush
*iface
,
450 ID2D1Factory
**factory
)
452 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
454 TRACE("iface %p, factory %p.\n", iface
, factory
);
456 ID2D1Factory_AddRef(*factory
= brush
->factory
);
459 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_SetOpacity(ID2D1LinearGradientBrush
*iface
, float opacity
)
461 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
463 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
465 brush
->opacity
= opacity
;
468 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_SetTransform(ID2D1LinearGradientBrush
*iface
,
469 const D2D1_MATRIX_3X2_F
*transform
)
471 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
473 TRACE("iface %p, transform %p.\n", iface
, transform
);
475 brush
->transform
= *transform
;
478 static float STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetOpacity(ID2D1LinearGradientBrush
*iface
)
480 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
482 TRACE("iface %p.\n", iface
);
484 return brush
->opacity
;
487 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetTransform(ID2D1LinearGradientBrush
*iface
,
488 D2D1_MATRIX_3X2_F
*transform
)
490 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
492 TRACE("iface %p, transform %p.\n", iface
, transform
);
494 *transform
= brush
->transform
;
497 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_SetStartPoint(ID2D1LinearGradientBrush
*iface
,
498 D2D1_POINT_2F start_point
)
500 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
502 TRACE("iface %p, start_point %s.\n", iface
, debug_d2d_point_2f(&start_point
));
504 brush
->u
.linear
.start
= start_point
;
507 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_SetEndPoint(ID2D1LinearGradientBrush
*iface
,
508 D2D1_POINT_2F end_point
)
510 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
512 TRACE("iface %p, end_point %s.\n", iface
, debug_d2d_point_2f(&end_point
));
514 brush
->u
.linear
.end
= end_point
;
517 static D2D1_POINT_2F
* STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetStartPoint(ID2D1LinearGradientBrush
*iface
,
518 D2D1_POINT_2F
*point
)
520 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
522 TRACE("iface %p, point %p.\n", iface
, point
);
524 *point
= brush
->u
.linear
.start
;
528 static D2D1_POINT_2F
* STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetEndPoint(ID2D1LinearGradientBrush
*iface
,
529 D2D1_POINT_2F
*point
)
531 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
533 TRACE("iface %p, point %p.\n", iface
, point
);
535 *point
= brush
->u
.linear
.end
;
539 static void STDMETHODCALLTYPE
d2d_linear_gradient_brush_GetGradientStopCollection(ID2D1LinearGradientBrush
*iface
,
540 ID2D1GradientStopCollection
**gradient
)
542 struct d2d_brush
*brush
= impl_from_ID2D1LinearGradientBrush(iface
);
544 TRACE("iface %p, gradient %p.\n", iface
, gradient
);
546 ID2D1GradientStopCollection_AddRef(*gradient
= &brush
->u
.linear
.gradient
->ID2D1GradientStopCollection_iface
);
549 static const struct ID2D1LinearGradientBrushVtbl d2d_linear_gradient_brush_vtbl
=
551 d2d_linear_gradient_brush_QueryInterface
,
552 d2d_linear_gradient_brush_AddRef
,
553 d2d_linear_gradient_brush_Release
,
554 d2d_linear_gradient_brush_GetFactory
,
555 d2d_linear_gradient_brush_SetOpacity
,
556 d2d_linear_gradient_brush_SetTransform
,
557 d2d_linear_gradient_brush_GetOpacity
,
558 d2d_linear_gradient_brush_GetTransform
,
559 d2d_linear_gradient_brush_SetStartPoint
,
560 d2d_linear_gradient_brush_SetEndPoint
,
561 d2d_linear_gradient_brush_GetStartPoint
,
562 d2d_linear_gradient_brush_GetEndPoint
,
563 d2d_linear_gradient_brush_GetGradientStopCollection
,
566 HRESULT
d2d_linear_gradient_brush_create(ID2D1Factory
*factory
,
567 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES
*gradient_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
568 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
)
570 if (!(*brush
= heap_alloc_zero(sizeof(**brush
))))
571 return E_OUTOFMEMORY
;
573 d2d_brush_init(*brush
, factory
, D2D_BRUSH_TYPE_LINEAR
, brush_desc
,
574 (ID2D1BrushVtbl
*)&d2d_linear_gradient_brush_vtbl
);
575 (*brush
)->u
.linear
.gradient
= unsafe_impl_from_ID2D1GradientStopCollection(gradient
);
576 ID2D1GradientStopCollection_AddRef(&(*brush
)->u
.linear
.gradient
->ID2D1GradientStopCollection_iface
);
577 (*brush
)->u
.linear
.start
= gradient_brush_desc
->startPoint
;
578 (*brush
)->u
.linear
.end
= gradient_brush_desc
->endPoint
;
580 TRACE("Created brush %p.\n", *brush
);
584 static inline struct d2d_brush
*impl_from_ID2D1RadialGradientBrush(ID2D1RadialGradientBrush
*iface
)
586 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
589 static HRESULT STDMETHODCALLTYPE
d2d_radial_gradient_brush_QueryInterface(ID2D1RadialGradientBrush
*iface
,
590 REFIID iid
, void **out
)
592 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
594 if (IsEqualGUID(iid
, &IID_ID2D1RadialGradientBrush
)
595 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
596 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
597 || IsEqualGUID(iid
, &IID_IUnknown
))
599 ID2D1RadialGradientBrush_AddRef(iface
);
604 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
607 return E_NOINTERFACE
;
610 static ULONG STDMETHODCALLTYPE
d2d_radial_gradient_brush_AddRef(ID2D1RadialGradientBrush
*iface
)
612 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
613 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
615 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
620 static ULONG STDMETHODCALLTYPE
d2d_radial_gradient_brush_Release(ID2D1RadialGradientBrush
*iface
)
622 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
623 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
625 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
629 ID2D1GradientStopCollection_Release(&brush
->u
.radial
.gradient
->ID2D1GradientStopCollection_iface
);
630 d2d_brush_destroy(brush
);
636 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetFactory(ID2D1RadialGradientBrush
*iface
,
637 ID2D1Factory
**factory
)
639 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
641 TRACE("iface %p, factory %p.\n", iface
, factory
);
643 ID2D1Factory_AddRef(*factory
= brush
->factory
);
646 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetOpacity(ID2D1RadialGradientBrush
*iface
, float opacity
)
648 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
650 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
652 brush
->opacity
= opacity
;
655 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetTransform(ID2D1RadialGradientBrush
*iface
,
656 const D2D1_MATRIX_3X2_F
*transform
)
658 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
660 TRACE("iface %p, transform %p.\n", iface
, transform
);
662 brush
->transform
= *transform
;
665 static float STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetOpacity(ID2D1RadialGradientBrush
*iface
)
667 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
669 TRACE("iface %p.\n", iface
);
671 return brush
->opacity
;
674 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetTransform(ID2D1RadialGradientBrush
*iface
,
675 D2D1_MATRIX_3X2_F
*transform
)
677 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
679 TRACE("iface %p, transform %p.\n", iface
, transform
);
681 *transform
= brush
->transform
;
684 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetCenter(ID2D1RadialGradientBrush
*iface
,
685 D2D1_POINT_2F centre
)
687 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
689 TRACE("iface %p, centre %s.\n", iface
, debug_d2d_point_2f(¢re
));
691 brush
->u
.radial
.centre
= centre
;
694 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetGradientOriginOffset(ID2D1RadialGradientBrush
*iface
,
695 D2D1_POINT_2F offset
)
697 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
699 TRACE("iface %p, offset %s.\n", iface
, debug_d2d_point_2f(&offset
));
701 brush
->u
.radial
.offset
= offset
;
704 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetRadiusX(ID2D1RadialGradientBrush
*iface
, float radius
)
706 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
708 TRACE("iface %p, radius %.8e.\n", iface
, radius
);
710 brush
->u
.radial
.radius
.x
= radius
;
713 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_SetRadiusY(ID2D1RadialGradientBrush
*iface
, float radius
)
715 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
717 TRACE("iface %p, radius %.8e.\n", iface
, radius
);
719 brush
->u
.radial
.radius
.y
= radius
;
722 static D2D1_POINT_2F
* STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetCenter(ID2D1RadialGradientBrush
*iface
,
723 D2D1_POINT_2F
*centre
)
725 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
727 TRACE("iface %p, centre %p.\n", iface
, centre
);
729 *centre
= brush
->u
.radial
.centre
;
733 static D2D1_POINT_2F
* STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetGradientOriginOffset(
734 ID2D1RadialGradientBrush
*iface
, D2D1_POINT_2F
*offset
)
736 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
738 TRACE("iface %p, offset %p.\n", iface
, offset
);
740 *offset
= brush
->u
.radial
.offset
;
744 static float STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetRadiusX(ID2D1RadialGradientBrush
*iface
)
746 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
748 TRACE("iface %p.\n", iface
);
750 return brush
->u
.radial
.radius
.x
;
753 static float STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetRadiusY(ID2D1RadialGradientBrush
*iface
)
755 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
757 TRACE("iface %p.\n", iface
);
759 return brush
->u
.radial
.radius
.y
;
762 static void STDMETHODCALLTYPE
d2d_radial_gradient_brush_GetGradientStopCollection(ID2D1RadialGradientBrush
*iface
,
763 ID2D1GradientStopCollection
**gradient
)
765 struct d2d_brush
*brush
= impl_from_ID2D1RadialGradientBrush(iface
);
767 TRACE("iface %p, gradient %p.\n", iface
, gradient
);
769 ID2D1GradientStopCollection_AddRef(*gradient
= &brush
->u
.radial
.gradient
->ID2D1GradientStopCollection_iface
);
772 static const struct ID2D1RadialGradientBrushVtbl d2d_radial_gradient_brush_vtbl
=
774 d2d_radial_gradient_brush_QueryInterface
,
775 d2d_radial_gradient_brush_AddRef
,
776 d2d_radial_gradient_brush_Release
,
777 d2d_radial_gradient_brush_GetFactory
,
778 d2d_radial_gradient_brush_SetOpacity
,
779 d2d_radial_gradient_brush_SetTransform
,
780 d2d_radial_gradient_brush_GetOpacity
,
781 d2d_radial_gradient_brush_GetTransform
,
782 d2d_radial_gradient_brush_SetCenter
,
783 d2d_radial_gradient_brush_SetGradientOriginOffset
,
784 d2d_radial_gradient_brush_SetRadiusX
,
785 d2d_radial_gradient_brush_SetRadiusY
,
786 d2d_radial_gradient_brush_GetCenter
,
787 d2d_radial_gradient_brush_GetGradientOriginOffset
,
788 d2d_radial_gradient_brush_GetRadiusX
,
789 d2d_radial_gradient_brush_GetRadiusY
,
790 d2d_radial_gradient_brush_GetGradientStopCollection
,
793 HRESULT
d2d_radial_gradient_brush_create(ID2D1Factory
*factory
,
794 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES
*gradient_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
795 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
)
799 if (!(b
= heap_alloc_zero(sizeof(*b
))))
800 return E_OUTOFMEMORY
;
802 d2d_brush_init(b
, factory
, D2D_BRUSH_TYPE_RADIAL
, brush_desc
, (ID2D1BrushVtbl
*)&d2d_radial_gradient_brush_vtbl
);
803 b
->u
.radial
.gradient
= unsafe_impl_from_ID2D1GradientStopCollection(gradient
);
804 ID2D1GradientStopCollection_AddRef(&b
->u
.radial
.gradient
->ID2D1GradientStopCollection_iface
);
805 b
->u
.radial
.centre
= gradient_desc
->center
;
806 b
->u
.radial
.offset
= gradient_desc
->gradientOriginOffset
;
807 b
->u
.radial
.radius
.x
= gradient_desc
->radiusX
;
808 b
->u
.radial
.radius
.y
= gradient_desc
->radiusY
;
810 TRACE("Created brush %p.\n", b
);
816 static inline struct d2d_brush
*impl_from_ID2D1BitmapBrush1(ID2D1BitmapBrush1
*iface
)
818 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
821 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_brush_QueryInterface(ID2D1BitmapBrush1
*iface
,
822 REFIID iid
, void **out
)
824 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
826 if (IsEqualGUID(iid
, &IID_ID2D1BitmapBrush1
)
827 || IsEqualGUID(iid
, &IID_ID2D1BitmapBrush
)
828 || IsEqualGUID(iid
, &IID_ID2D1Brush
)
829 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
830 || IsEqualGUID(iid
, &IID_IUnknown
))
832 ID2D1BitmapBrush1_AddRef(iface
);
837 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
840 return E_NOINTERFACE
;
843 static ULONG STDMETHODCALLTYPE
d2d_bitmap_brush_AddRef(ID2D1BitmapBrush1
*iface
)
845 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
846 ULONG refcount
= InterlockedIncrement(&brush
->refcount
);
848 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
853 static ULONG STDMETHODCALLTYPE
d2d_bitmap_brush_Release(ID2D1BitmapBrush1
*iface
)
855 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
856 ULONG refcount
= InterlockedDecrement(&brush
->refcount
);
858 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
862 if (brush
->u
.bitmap
.sampler_state
)
863 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
864 if (brush
->u
.bitmap
.bitmap
)
865 ID2D1Bitmap1_Release(&brush
->u
.bitmap
.bitmap
->ID2D1Bitmap1_iface
);
866 d2d_brush_destroy(brush
);
872 static void STDMETHODCALLTYPE
d2d_bitmap_brush_GetFactory(ID2D1BitmapBrush1
*iface
,
873 ID2D1Factory
**factory
)
875 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
877 TRACE("iface %p, factory %p.\n", iface
, factory
);
879 ID2D1Factory_AddRef(*factory
= brush
->factory
);
882 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetOpacity(ID2D1BitmapBrush1
*iface
, float opacity
)
884 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
886 TRACE("iface %p, opacity %.8e.\n", iface
, opacity
);
888 brush
->opacity
= opacity
;
891 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetTransform(ID2D1BitmapBrush1
*iface
,
892 const D2D1_MATRIX_3X2_F
*transform
)
894 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
896 TRACE("iface %p, transform %p.\n", iface
, transform
);
898 brush
->transform
= *transform
;
901 static float STDMETHODCALLTYPE
d2d_bitmap_brush_GetOpacity(ID2D1BitmapBrush1
*iface
)
903 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
905 TRACE("iface %p.\n", iface
);
907 return brush
->opacity
;
910 static void STDMETHODCALLTYPE
d2d_bitmap_brush_GetTransform(ID2D1BitmapBrush1
*iface
,
911 D2D1_MATRIX_3X2_F
*transform
)
913 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
915 TRACE("iface %p, transform %p.\n", iface
, transform
);
917 *transform
= brush
->transform
;
920 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetExtendModeX(ID2D1BitmapBrush1
*iface
, D2D1_EXTEND_MODE mode
)
922 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
924 TRACE("iface %p, mode %#x.\n", iface
, mode
);
926 brush
->u
.bitmap
.extend_mode_x
= mode
;
927 if (brush
->u
.bitmap
.sampler_state
)
929 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
930 brush
->u
.bitmap
.sampler_state
= NULL
;
934 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetExtendModeY(ID2D1BitmapBrush1
*iface
, D2D1_EXTEND_MODE mode
)
936 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
938 TRACE("iface %p, mode %#x.\n", iface
, mode
);
940 brush
->u
.bitmap
.extend_mode_y
= mode
;
941 if (brush
->u
.bitmap
.sampler_state
)
943 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
944 brush
->u
.bitmap
.sampler_state
= NULL
;
948 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetInterpolationMode(ID2D1BitmapBrush1
*iface
,
949 D2D1_BITMAP_INTERPOLATION_MODE mode
)
951 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
953 TRACE("iface %p, mode %#x.\n", iface
, mode
);
957 case D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR
:
958 case D2D1_BITMAP_INTERPOLATION_MODE_LINEAR
:
961 WARN("Unknown interpolation mode %#x.\n", mode
);
965 brush
->u
.bitmap
.interpolation_mode
= d2d1_1_interp_mode_from_d2d1(mode
);
966 if (brush
->u
.bitmap
.sampler_state
)
968 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
969 brush
->u
.bitmap
.sampler_state
= NULL
;
973 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetBitmap(ID2D1BitmapBrush1
*iface
, ID2D1Bitmap
*bitmap
)
975 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
977 TRACE("iface %p, bitmap %p.\n", iface
, bitmap
);
980 ID2D1Bitmap_AddRef(bitmap
);
981 if (brush
->u
.bitmap
.bitmap
)
982 ID2D1Bitmap1_Release(&brush
->u
.bitmap
.bitmap
->ID2D1Bitmap1_iface
);
983 brush
->u
.bitmap
.bitmap
= unsafe_impl_from_ID2D1Bitmap(bitmap
);
986 static D2D1_EXTEND_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetExtendModeX(ID2D1BitmapBrush1
*iface
)
988 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
990 TRACE("iface %p.\n", iface
);
992 return brush
->u
.bitmap
.extend_mode_x
;
995 static D2D1_EXTEND_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetExtendModeY(ID2D1BitmapBrush1
*iface
)
997 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
999 TRACE("iface %p.\n", iface
);
1001 return brush
->u
.bitmap
.extend_mode_y
;
1004 static D2D1_BITMAP_INTERPOLATION_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetInterpolationMode(ID2D1BitmapBrush1
*iface
)
1006 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
1008 TRACE("iface %p.\n", iface
);
1010 switch (brush
->u
.bitmap
.interpolation_mode
)
1012 case D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR
:
1013 return D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR
;
1014 case D2D1_INTERPOLATION_MODE_LINEAR
:
1016 return D2D1_BITMAP_INTERPOLATION_MODE_LINEAR
;
1020 static void STDMETHODCALLTYPE
d2d_bitmap_brush_GetBitmap(ID2D1BitmapBrush1
*iface
, ID2D1Bitmap
**bitmap
)
1022 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
1024 TRACE("iface %p, bitmap %p.\n", iface
, bitmap
);
1026 if ((*bitmap
= (ID2D1Bitmap
*)&brush
->u
.bitmap
.bitmap
->ID2D1Bitmap1_iface
))
1027 ID2D1Bitmap_AddRef(*bitmap
);
1030 static void STDMETHODCALLTYPE
d2d_bitmap_brush_SetInterpolationMode1(ID2D1BitmapBrush1
*iface
,
1031 D2D1_INTERPOLATION_MODE mode
)
1033 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
1035 TRACE("iface %p, mode %#x.\n", iface
, mode
);
1039 case D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR
:
1040 case D2D1_INTERPOLATION_MODE_LINEAR
:
1042 case D2D1_INTERPOLATION_MODE_CUBIC
:
1043 case D2D1_INTERPOLATION_MODE_MULTI_SAMPLE_LINEAR
:
1044 case D2D1_INTERPOLATION_MODE_ANISOTROPIC
:
1045 case D2D1_INTERPOLATION_MODE_HIGH_QUALITY_CUBIC
:
1046 FIXME("Unhandled interpolation mode %#x.\n", mode
);
1049 WARN("Unknown interpolation mode %#x.\n", mode
);
1053 brush
->u
.bitmap
.interpolation_mode
= mode
;
1054 if (brush
->u
.bitmap
.sampler_state
)
1056 ID3D10SamplerState_Release(brush
->u
.bitmap
.sampler_state
);
1057 brush
->u
.bitmap
.sampler_state
= NULL
;
1061 static D2D1_INTERPOLATION_MODE STDMETHODCALLTYPE
d2d_bitmap_brush_GetInterpolationMode1(ID2D1BitmapBrush1
*iface
)
1063 struct d2d_brush
*brush
= impl_from_ID2D1BitmapBrush1(iface
);
1065 TRACE("iface %p.\n", iface
);
1067 return brush
->u
.bitmap
.interpolation_mode
;
1070 static const struct ID2D1BitmapBrush1Vtbl d2d_bitmap_brush_vtbl
=
1072 d2d_bitmap_brush_QueryInterface
,
1073 d2d_bitmap_brush_AddRef
,
1074 d2d_bitmap_brush_Release
,
1075 d2d_bitmap_brush_GetFactory
,
1076 d2d_bitmap_brush_SetOpacity
,
1077 d2d_bitmap_brush_SetTransform
,
1078 d2d_bitmap_brush_GetOpacity
,
1079 d2d_bitmap_brush_GetTransform
,
1080 d2d_bitmap_brush_SetExtendModeX
,
1081 d2d_bitmap_brush_SetExtendModeY
,
1082 d2d_bitmap_brush_SetInterpolationMode
,
1083 d2d_bitmap_brush_SetBitmap
,
1084 d2d_bitmap_brush_GetExtendModeX
,
1085 d2d_bitmap_brush_GetExtendModeY
,
1086 d2d_bitmap_brush_GetInterpolationMode
,
1087 d2d_bitmap_brush_GetBitmap
,
1088 d2d_bitmap_brush_SetInterpolationMode1
,
1089 d2d_bitmap_brush_GetInterpolationMode1
,
1092 HRESULT
d2d_bitmap_brush_create(ID2D1Factory
*factory
, ID2D1Bitmap
*bitmap
,
1093 const D2D1_BITMAP_BRUSH_PROPERTIES1
*bitmap_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
1094 struct d2d_brush
**brush
)
1096 if (!(*brush
= heap_alloc_zero(sizeof(**brush
))))
1097 return E_OUTOFMEMORY
;
1099 d2d_brush_init(*brush
, factory
, D2D_BRUSH_TYPE_BITMAP
,
1100 brush_desc
, (ID2D1BrushVtbl
*)&d2d_bitmap_brush_vtbl
);
1101 if (((*brush
)->u
.bitmap
.bitmap
= unsafe_impl_from_ID2D1Bitmap(bitmap
)))
1102 ID2D1Bitmap1_AddRef(&(*brush
)->u
.bitmap
.bitmap
->ID2D1Bitmap1_iface
);
1103 if (bitmap_brush_desc
)
1105 (*brush
)->u
.bitmap
.extend_mode_x
= bitmap_brush_desc
->extendModeX
;
1106 (*brush
)->u
.bitmap
.extend_mode_y
= bitmap_brush_desc
->extendModeY
;
1107 (*brush
)->u
.bitmap
.interpolation_mode
= bitmap_brush_desc
->interpolationMode
;
1111 (*brush
)->u
.bitmap
.extend_mode_x
= D2D1_EXTEND_MODE_CLAMP
;
1112 (*brush
)->u
.bitmap
.extend_mode_y
= D2D1_EXTEND_MODE_CLAMP
;
1113 (*brush
)->u
.bitmap
.interpolation_mode
= D2D1_INTERPOLATION_MODE_LINEAR
;
1116 TRACE("Created brush %p.\n", *brush
);
1120 struct d2d_brush
*unsafe_impl_from_ID2D1Brush(ID2D1Brush
*iface
)
1124 assert(iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_solid_color_brush_vtbl
1125 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_linear_gradient_brush_vtbl
1126 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_radial_gradient_brush_vtbl
1127 || iface
->lpVtbl
== (const ID2D1BrushVtbl
*)&d2d_bitmap_brush_vtbl
);
1128 return CONTAINING_RECORD(iface
, struct d2d_brush
, ID2D1Brush_iface
);
1131 static D3D10_TEXTURE_ADDRESS_MODE
texture_address_mode_from_extend_mode(D2D1_EXTEND_MODE mode
)
1135 case D2D1_EXTEND_MODE_CLAMP
:
1136 return D3D10_TEXTURE_ADDRESS_CLAMP
;
1137 case D2D1_EXTEND_MODE_WRAP
:
1138 return D3D10_TEXTURE_ADDRESS_WRAP
;
1139 case D2D1_EXTEND_MODE_MIRROR
:
1140 return D3D10_TEXTURE_ADDRESS_MIRROR
;
1142 FIXME("Unhandled extend mode %#x.\n", mode
);
1143 return D3D10_TEXTURE_ADDRESS_CLAMP
;
1147 static BOOL
d2d_brush_fill_cb(const struct d2d_brush
*brush
,
1148 const struct d2d_device_context
*render_target
, struct d2d_brush_cb
*cb
)
1150 float theta
, sin_theta
, cos_theta
;
1151 float dpi_scale
, d
, s1
, s2
, t
, u
;
1152 struct d2d_bitmap
*bitmap
;
1153 D2D1_POINT_2F v_p
, v_q
;
1154 D2D1_COLOR_F
*colour
;
1159 cb
->type
= D2D_BRUSH_TYPE_COUNT
;
1163 cb
->type
= brush
->type
;
1164 cb
->opacity
= brush
->opacity
;
1166 switch (brush
->type
)
1168 case D2D_BRUSH_TYPE_SOLID
:
1169 colour
= &cb
->u
.solid
.colour
;
1171 *colour
= brush
->u
.solid
.color
;
1172 colour
->r
*= colour
->a
;
1173 colour
->g
*= colour
->a
;
1174 colour
->b
*= colour
->a
;
1178 case D2D_BRUSH_TYPE_LINEAR
:
1179 b
= brush
->transform
;
1180 d2d_point_transform(&cb
->u
.linear
.start
, &b
, brush
->u
.linear
.start
.x
, brush
->u
.linear
.start
.y
);
1181 d2d_point_transform(&cb
->u
.linear
.end
, &b
, brush
->u
.linear
.end
.x
, brush
->u
.linear
.end
.y
);
1182 cb
->u
.linear
.stop_count
= brush
->u
.linear
.gradient
->stop_count
;
1186 case D2D_BRUSH_TYPE_RADIAL
:
1187 b
= brush
->transform
;
1188 d2d_point_transform(&cb
->u
.radial
.centre
, &b
, brush
->u
.radial
.centre
.x
, brush
->u
.radial
.centre
.y
);
1189 b
._31
= b
._32
= 0.0f
;
1190 d2d_point_transform(&cb
->u
.radial
.offset
, &b
, brush
->u
.radial
.offset
.x
, brush
->u
.radial
.offset
.y
);
1192 /* After a transformation, the axes of the ellipse are no longer
1193 * necessarily orthogonal, but they are conjugate diameters.
1198 * = ⎡cos(θ) -sin(θ)⎤⎡σ₁ 0 ⎤⎡cos(φ) -sin(φ)⎤
1199 * ⎣sin(θ) cos(θ)⎦⎣0 σ₂⎦⎣sin(φ) cos(φ)⎦
1201 * a' = [σ₁· cos(θ) σ₁·sin(θ)]
1202 * b' = [σ₂·-sin(θ) σ₂·cos(θ)] */
1204 d2d_point_set(&v_p
, brush
->u
.radial
.radius
.x
* b
._11
, brush
->u
.radial
.radius
.y
* b
._21
);
1205 d2d_point_set(&v_q
, brush
->u
.radial
.radius
.x
* b
._12
, brush
->u
.radial
.radius
.y
* b
._22
);
1207 t
= 0.5f
* d2d_point_dot(&v_p
, &v_p
);
1208 u
= 0.5f
* d2d_point_dot(&v_q
, &v_q
);
1212 u
= d2d_point_dot(&v_p
, &v_q
);
1213 s2
= sqrtf(t
* t
+ u
* u
);
1215 theta
= 0.5f
* atan2(u
, t
);
1216 sin_theta
= sinf(theta
);
1217 cos_theta
= cosf(theta
);
1220 d2d_point_set(&cb
->u
.radial
.ra
, t
* cos_theta
, t
* sin_theta
);
1222 d2d_point_set(&cb
->u
.radial
.rb
, t
* -sin_theta
, t
* cos_theta
);
1224 cb
->u
.radial
.stop_count
= brush
->u
.linear
.gradient
->stop_count
;
1228 case D2D_BRUSH_TYPE_BITMAP
:
1229 bitmap
= brush
->u
.bitmap
.bitmap
;
1231 /* Scale for bitmap size and dpi. */
1232 b
= brush
->transform
;
1233 dpi_scale
= bitmap
->pixel_size
.width
* (96.0f
/ bitmap
->dpi_x
);
1236 dpi_scale
= bitmap
->pixel_size
.height
* (96.0f
/ bitmap
->dpi_y
);
1240 /* Invert the matrix. (Because the matrix is applied to the
1241 * sampling coordinates. I.e., to scale the bitmap by 2 we need to
1242 * divide the coordinates by 2.) */
1243 d
= b
._11
* b
._22
- b
._21
* b
._12
;
1246 cb
->u
.bitmap
._11
= b
._22
/ d
;
1247 cb
->u
.bitmap
._21
= -b
._21
/ d
;
1248 cb
->u
.bitmap
._31
= (b
._21
* b
._32
- b
._31
* b
._22
) / d
;
1249 cb
->u
.bitmap
._12
= -b
._12
/ d
;
1250 cb
->u
.bitmap
._22
= b
._11
/ d
;
1251 cb
->u
.bitmap
._32
= -(b
._11
* b
._32
- b
._31
* b
._12
) / d
;
1254 cb
->u
.bitmap
.ignore_alpha
= bitmap
->format
.alphaMode
== D2D1_ALPHA_MODE_IGNORE
;
1259 FIXME("Unhandled brush type %#x.\n", brush
->type
);
1264 HRESULT
d2d_brush_get_ps_cb(struct d2d_brush
*brush
, struct d2d_brush
*opacity_brush
,
1265 BOOL outline
, BOOL is_arc
, struct d2d_device_context
*render_target
, ID3D10Buffer
**ps_cb
)
1267 D3D10_SUBRESOURCE_DATA buffer_data
;
1268 struct d2d_ps_cb cb_data
= {0};
1269 D3D10_BUFFER_DESC buffer_desc
;
1272 cb_data
.outline
= outline
;
1273 cb_data
.is_arc
= is_arc
;
1274 if (!d2d_brush_fill_cb(brush
, render_target
, &cb_data
.colour_brush
))
1276 if (!d2d_brush_fill_cb(opacity_brush
, render_target
, &cb_data
.opacity_brush
))
1279 buffer_desc
.ByteWidth
= sizeof(cb_data
);
1280 buffer_desc
.Usage
= D3D10_USAGE_DEFAULT
;
1281 buffer_desc
.BindFlags
= D3D10_BIND_CONSTANT_BUFFER
;
1282 buffer_desc
.CPUAccessFlags
= 0;
1283 buffer_desc
.MiscFlags
= 0;
1285 buffer_data
.pSysMem
= &cb_data
;
1286 buffer_data
.SysMemPitch
= 0;
1287 buffer_data
.SysMemSlicePitch
= 0;
1289 if (FAILED(hr
= ID3D10Device_CreateBuffer(render_target
->d3d_device
, &buffer_desc
, &buffer_data
, ps_cb
)))
1290 ERR("Failed to create constant buffer, hr %#x.\n", hr
);
1295 static void d2d_brush_bind_bitmap(struct d2d_brush
*brush
, ID3D10Device
*device
, unsigned int brush_idx
)
1299 ID3D10Device_PSSetShaderResources(device
, brush_idx
, 1, &brush
->u
.bitmap
.bitmap
->srv
);
1300 if (!brush
->u
.bitmap
.sampler_state
)
1302 D3D10_SAMPLER_DESC sampler_desc
;
1304 if (brush
->u
.bitmap
.interpolation_mode
== D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR
)
1305 sampler_desc
.Filter
= D3D10_FILTER_MIN_MAG_MIP_POINT
;
1307 sampler_desc
.Filter
= D3D10_FILTER_MIN_MAG_MIP_LINEAR
;
1308 sampler_desc
.AddressU
= texture_address_mode_from_extend_mode(brush
->u
.bitmap
.extend_mode_x
);
1309 sampler_desc
.AddressV
= texture_address_mode_from_extend_mode(brush
->u
.bitmap
.extend_mode_y
);
1310 sampler_desc
.AddressW
= D3D10_TEXTURE_ADDRESS_CLAMP
;
1311 sampler_desc
.MipLODBias
= 0.0f
;
1312 sampler_desc
.MaxAnisotropy
= 0;
1313 sampler_desc
.ComparisonFunc
= D3D10_COMPARISON_NEVER
;
1314 sampler_desc
.BorderColor
[0] = 0.0f
;
1315 sampler_desc
.BorderColor
[1] = 0.0f
;
1316 sampler_desc
.BorderColor
[2] = 0.0f
;
1317 sampler_desc
.BorderColor
[3] = 0.0f
;
1318 sampler_desc
.MinLOD
= 0.0f
;
1319 sampler_desc
.MaxLOD
= 0.0f
;
1321 if (FAILED(hr
= ID3D10Device_CreateSamplerState(device
,
1322 &sampler_desc
, &brush
->u
.bitmap
.sampler_state
)))
1323 ERR("Failed to create sampler state, hr %#x.\n", hr
);
1325 ID3D10Device_PSSetSamplers(device
, brush_idx
, 1, &brush
->u
.bitmap
.sampler_state
);
1328 void d2d_brush_bind_resources(struct d2d_brush
*brush
, ID3D10Device
*device
, unsigned int brush_idx
)
1330 switch (brush
->type
)
1332 case D2D_BRUSH_TYPE_SOLID
:
1335 case D2D_BRUSH_TYPE_LINEAR
:
1336 d2d_gradient_bind(brush
->u
.linear
.gradient
, device
, brush_idx
);
1339 case D2D_BRUSH_TYPE_RADIAL
:
1340 d2d_gradient_bind(brush
->u
.radial
.gradient
, device
, brush_idx
);
1343 case D2D_BRUSH_TYPE_BITMAP
:
1344 d2d_brush_bind_bitmap(brush
, device
, brush_idx
);
1348 FIXME("Unhandled brush type %#x.\n", brush
->type
);