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 #ifndef __WINE_D2D1_PRIVATE_H
20 #define __WINE_D2D1_PRIVATE_H
22 #include "wine/debug.h"
23 #include "wine/heap.h"
39 D2D_BRUSH_TYPE_LINEAR
,
40 D2D_BRUSH_TYPE_RADIAL
,
41 D2D_BRUSH_TYPE_BITMAP
,
47 D2D_SHAPE_TYPE_OUTLINE
,
48 D2D_SHAPE_TYPE_BEZIER_OUTLINE
,
49 D2D_SHAPE_TYPE_ARC_OUTLINE
,
50 D2D_SHAPE_TYPE_TRIANGLE
,
57 unsigned int max_version_factory
;
59 extern struct d2d_settings d2d_settings DECLSPEC_HIDDEN
;
68 struct d2d_error_state
74 struct d2d_shape_resources
76 ID3D10InputLayout
*il
;
77 ID3D10VertexShader
*vs
;
82 enum d2d_brush_type type
;
95 unsigned int stop_count
;
100 D2D1_POINT_2F offset
;
103 unsigned int stop_count
;
108 float _11
, _21
, _31
, pad
;
120 struct d2d_brush_cb colour_brush
;
121 struct d2d_brush_cb opacity_brush
;
133 float _11
, _21
, _31
, pad0
;
134 float _12
, _22
, _32
, stroke_width
;
135 } transform_geometry
;
136 struct d2d_vec4 transform_rtx
;
137 struct d2d_vec4 transform_rty
;
140 struct d2d_device_context_ops
142 HRESULT (*device_context_present
)(IUnknown
*outer_unknown
);
145 enum d2d_device_context_sampler_limits
147 D2D_SAMPLER_INTERPOLATION_MODE_COUNT
= 2,
148 D2D_SAMPLER_EXTEND_MODE_COUNT
= 3,
151 struct d2d_device_context
153 ID2D1DeviceContext ID2D1DeviceContext_iface
;
154 ID2D1GdiInteropRenderTarget ID2D1GdiInteropRenderTarget_iface
;
155 IDWriteTextRenderer IDWriteTextRenderer_iface
;
156 IUnknown IUnknown_iface
;
159 IUnknown
*outer_unknown
;
160 const struct d2d_device_context_ops
*ops
;
162 ID2D1Factory
*factory
;
164 ID3D10Device
*d3d_device
;
165 struct d2d_bitmap
*target
;
166 ID3D10StateBlock
*stateblock
;
167 struct d2d_shape_resources shape_resources
[D2D_SHAPE_TYPE_COUNT
];
169 ID3D10PixelShader
*ps
;
172 unsigned int vb_stride
;
174 ID3D10RasterizerState
*rs
;
175 ID3D10BlendState
*bs
;
176 ID3D10SamplerState
*sampler_states
177 [D2D_SAMPLER_INTERPOLATION_MODE_COUNT
]
178 [D2D_SAMPLER_EXTEND_MODE_COUNT
]
179 [D2D_SAMPLER_EXTEND_MODE_COUNT
];
181 struct d2d_error_state error
;
182 D2D1_DRAWING_STATE_DESCRIPTION1 drawing_state
;
183 IDWriteRenderingParams
*text_rendering_params
;
184 IDWriteRenderingParams
*default_text_rendering_params
;
186 D2D1_RENDER_TARGET_PROPERTIES desc
;
187 D2D1_SIZE_U pixel_size
;
188 struct d2d_clip_stack clip_stack
;
191 HRESULT
d2d_d3d_create_render_target(ID2D1Device
*device
, IDXGISurface
*surface
, IUnknown
*outer_unknown
,
192 const struct d2d_device_context_ops
*ops
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
,
193 void **render_target
) DECLSPEC_HIDDEN
;
195 static inline BOOL
d2d_device_context_is_dxgi_target(const struct d2d_device_context
*context
)
197 return !context
->ops
;
200 struct d2d_wic_render_target
202 IUnknown IUnknown_iface
;
205 IDXGISurface
*dxgi_surface
;
206 ID2D1RenderTarget
*dxgi_target
;
207 IUnknown
*dxgi_inner
;
208 ID3D10Texture2D
*readback_texture
;
216 HRESULT
d2d_wic_render_target_init(struct d2d_wic_render_target
*render_target
, ID2D1Factory1
*factory
,
217 ID3D10Device1
*d3d_device
, IWICBitmap
*bitmap
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
) DECLSPEC_HIDDEN
;
219 struct d2d_dc_render_target
221 ID2D1DCRenderTarget ID2D1DCRenderTarget_iface
;
224 IDXGISurface1
*dxgi_surface
;
225 D2D1_PIXEL_FORMAT pixel_format
;
226 ID3D10Device1
*d3d_device
;
227 ID2D1RenderTarget
*dxgi_target
;
228 IUnknown
*dxgi_inner
;
234 HRESULT
d2d_dc_render_target_init(struct d2d_dc_render_target
*render_target
, ID2D1Factory1
*factory
,
235 ID3D10Device1
*d3d_device
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
) DECLSPEC_HIDDEN
;
237 struct d2d_hwnd_render_target
239 ID2D1HwndRenderTarget ID2D1HwndRenderTarget_iface
;
242 ID2D1RenderTarget
*dxgi_target
;
243 IUnknown
*dxgi_inner
;
244 IDXGISwapChain
*swapchain
;
249 HRESULT
d2d_hwnd_render_target_init(struct d2d_hwnd_render_target
*render_target
, ID2D1Factory1
*factory
,
250 ID3D10Device1
*d3d_device
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
,
251 const D2D1_HWND_RENDER_TARGET_PROPERTIES
*hwnd_desc
) DECLSPEC_HIDDEN
;
253 struct d2d_bitmap_render_target
255 ID2D1BitmapRenderTarget ID2D1BitmapRenderTarget_iface
;
258 ID2D1RenderTarget
*dxgi_target
;
259 IUnknown
*dxgi_inner
;
263 HRESULT
d2d_bitmap_render_target_init(struct d2d_bitmap_render_target
*render_target
,
264 const struct d2d_device_context
*parent_target
, const D2D1_SIZE_F
*size
,
265 const D2D1_SIZE_U
*pixel_size
, const D2D1_PIXEL_FORMAT
*format
,
266 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options
) DECLSPEC_HIDDEN
;
270 ID2D1GradientStopCollection ID2D1GradientStopCollection_iface
;
273 ID2D1Factory
*factory
;
274 ID3D10ShaderResourceView
*view
;
275 D2D1_GRADIENT_STOP
*stops
;
279 HRESULT
d2d_gradient_create(ID2D1Factory
*factory
, ID3D10Device
*device
, const D2D1_GRADIENT_STOP
*stops
,
280 UINT32 stop_count
, D2D1_GAMMA gamma
, D2D1_EXTEND_MODE extend_mode
,
281 struct d2d_gradient
**gradient
) DECLSPEC_HIDDEN
;
285 ID2D1Brush ID2D1Brush_iface
;
288 ID2D1Factory
*factory
;
290 D2D1_MATRIX_3X2_F transform
;
292 enum d2d_brush_type type
;
301 struct d2d_gradient
*gradient
;
307 struct d2d_gradient
*gradient
;
308 D2D1_POINT_2F centre
;
309 D2D1_POINT_2F offset
;
310 D2D1_POINT_2F radius
;
314 struct d2d_bitmap
*bitmap
;
315 D2D1_EXTEND_MODE extend_mode_x
;
316 D2D1_EXTEND_MODE extend_mode_y
;
317 D2D1_INTERPOLATION_MODE interpolation_mode
;
322 HRESULT
d2d_solid_color_brush_create(ID2D1Factory
*factory
, const D2D1_COLOR_F
*color
,
323 const D2D1_BRUSH_PROPERTIES
*desc
, struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
324 HRESULT
d2d_linear_gradient_brush_create(ID2D1Factory
*factory
,
325 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES
*gradient_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
326 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
327 HRESULT
d2d_radial_gradient_brush_create(ID2D1Factory
*factory
,
328 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES
*gradient_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
329 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
330 HRESULT
d2d_bitmap_brush_create(ID2D1Factory
*factory
, ID2D1Bitmap
*bitmap
,
331 const D2D1_BITMAP_BRUSH_PROPERTIES1
*bitmap_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
332 struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
333 void d2d_brush_bind_resources(struct d2d_brush
*brush
, struct d2d_device_context
*context
,
334 unsigned int brush_idx
) DECLSPEC_HIDDEN
;
335 BOOL
d2d_brush_fill_cb(const struct d2d_brush
*brush
, struct d2d_brush_cb
*cb
) DECLSPEC_HIDDEN
;
336 struct d2d_brush
*unsafe_impl_from_ID2D1Brush(ID2D1Brush
*iface
) DECLSPEC_HIDDEN
;
338 struct d2d_stroke_style
340 ID2D1StrokeStyle ID2D1StrokeStyle_iface
;
343 ID2D1Factory
*factory
;
344 D2D1_STROKE_STYLE_PROPERTIES desc
;
349 HRESULT
d2d_stroke_style_init(struct d2d_stroke_style
*style
, ID2D1Factory
*factory
,
350 const D2D1_STROKE_STYLE_PROPERTIES
*desc
, const float *dashes
, UINT32 dash_count
) DECLSPEC_HIDDEN
;
354 ID2D1Layer ID2D1Layer_iface
;
357 ID2D1Factory
*factory
;
361 HRESULT
d2d_layer_create(ID2D1Factory
*factory
, const D2D1_SIZE_F
*size
, struct d2d_layer
**layer
) DECLSPEC_HIDDEN
;
365 ID2D1Mesh ID2D1Mesh_iface
;
368 ID2D1Factory
*factory
;
371 HRESULT
d2d_mesh_create(ID2D1Factory
*factory
, struct d2d_mesh
**mesh
) DECLSPEC_HIDDEN
;
375 ID2D1Bitmap1 ID2D1Bitmap1_iface
;
378 ID2D1Factory
*factory
;
379 ID3D10ShaderResourceView
*srv
;
380 ID3D10RenderTargetView
*rtv
;
381 IDXGISurface
*surface
;
382 ID3D10Resource
*resource
;
383 D2D1_SIZE_U pixel_size
;
384 D2D1_PIXEL_FORMAT format
;
387 D2D1_BITMAP_OPTIONS options
;
390 HRESULT
d2d_bitmap_create(struct d2d_device_context
*context
, D2D1_SIZE_U size
, const void *src_data
,
391 UINT32 pitch
, const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
) DECLSPEC_HIDDEN
;
392 HRESULT
d2d_bitmap_create_shared(struct d2d_device_context
*context
, REFIID iid
, void *data
,
393 const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
) DECLSPEC_HIDDEN
;
394 HRESULT
d2d_bitmap_create_from_wic_bitmap(struct d2d_device_context
*context
, IWICBitmapSource
*bitmap_source
,
395 const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
) DECLSPEC_HIDDEN
;
396 struct d2d_bitmap
*unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap
*iface
) DECLSPEC_HIDDEN
;
398 struct d2d_state_block
400 ID2D1DrawingStateBlock1 ID2D1DrawingStateBlock1_iface
;
403 ID2D1Factory
*factory
;
404 D2D1_DRAWING_STATE_DESCRIPTION1 drawing_state
;
405 IDWriteRenderingParams
*text_rendering_params
;
408 void d2d_state_block_init(struct d2d_state_block
*state_block
, ID2D1Factory
*factory
,
409 const D2D1_DRAWING_STATE_DESCRIPTION1
*desc
, IDWriteRenderingParams
*text_rendering_params
) DECLSPEC_HIDDEN
;
410 struct d2d_state_block
*unsafe_impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStateBlock
*iface
) DECLSPEC_HIDDEN
;
412 enum d2d_geometry_state
414 D2D_GEOMETRY_STATE_INITIAL
= 0,
415 D2D_GEOMETRY_STATE_ERROR
,
416 D2D_GEOMETRY_STATE_OPEN
,
417 D2D_GEOMETRY_STATE_CLOSED
,
418 D2D_GEOMETRY_STATE_FIGURE
,
421 struct d2d_curve_vertex
423 D2D1_POINT_2F position
;
435 struct d2d_outline_vertex
437 D2D1_POINT_2F position
;
442 struct d2d_curve_outline_vertex
444 D2D1_POINT_2F position
;
445 D2D1_POINT_2F p0
, p1
, p2
;
446 D2D1_POINT_2F prev
, next
;
451 ID2D1Geometry ID2D1Geometry_iface
;
454 ID2D1Factory
*factory
;
456 D2D_MATRIX_3X2_F transform
;
460 D2D1_POINT_2F
*vertices
;
463 struct d2d_face
*faces
;
467 struct d2d_curve_vertex
*bezier_vertices
;
468 size_t bezier_vertices_size
;
469 size_t bezier_vertex_count
;
471 struct d2d_curve_vertex
*arc_vertices
;
472 size_t arc_vertices_size
;
473 size_t arc_vertex_count
;
478 struct d2d_outline_vertex
*vertices
;
479 size_t vertices_size
;
482 struct d2d_face
*faces
;
486 struct d2d_curve_outline_vertex
*beziers
;
490 struct d2d_face
*bezier_faces
;
491 size_t bezier_faces_size
;
492 size_t bezier_face_count
;
494 struct d2d_curve_outline_vertex
*arcs
;
498 struct d2d_face
*arc_faces
;
499 size_t arc_faces_size
;
500 size_t arc_face_count
;
507 D2D1_ELLIPSE ellipse
;
511 ID2D1GeometrySink ID2D1GeometrySink_iface
;
513 struct d2d_figure
*figures
;
517 enum d2d_geometry_state state
;
518 D2D1_FILL_MODE fill_mode
;
519 UINT32 segment_count
;
529 D2D1_ROUNDED_RECT rounded_rect
;
533 ID2D1Geometry
*src_geometry
;
534 D2D_MATRIX_3X2_F transform
;
538 ID2D1Geometry
**src_geometries
;
539 UINT32 geometry_count
;
540 D2D1_FILL_MODE fill_mode
;
545 HRESULT
d2d_ellipse_geometry_init(struct d2d_geometry
*geometry
,
546 ID2D1Factory
*factory
, const D2D1_ELLIPSE
*ellipse
) DECLSPEC_HIDDEN
;
547 void d2d_path_geometry_init(struct d2d_geometry
*geometry
, ID2D1Factory
*factory
) DECLSPEC_HIDDEN
;
548 HRESULT
d2d_rectangle_geometry_init(struct d2d_geometry
*geometry
,
549 ID2D1Factory
*factory
, const D2D1_RECT_F
*rect
) DECLSPEC_HIDDEN
;
550 HRESULT
d2d_rounded_rectangle_geometry_init(struct d2d_geometry
*geometry
,
551 ID2D1Factory
*factory
, const D2D1_ROUNDED_RECT
*rounded_rect
) DECLSPEC_HIDDEN
;
552 void d2d_transformed_geometry_init(struct d2d_geometry
*geometry
, ID2D1Factory
*factory
,
553 ID2D1Geometry
*src_geometry
, const D2D_MATRIX_3X2_F
*transform
) DECLSPEC_HIDDEN
;
554 HRESULT
d2d_geometry_group_init(struct d2d_geometry
*geometry
, ID2D1Factory
*factory
,
555 D2D1_FILL_MODE fill_mode
, ID2D1Geometry
**src_geometries
, unsigned int geometry_count
) DECLSPEC_HIDDEN
;
556 struct d2d_geometry
*unsafe_impl_from_ID2D1Geometry(ID2D1Geometry
*iface
) DECLSPEC_HIDDEN
;
560 ID2D1Device ID2D1Device_iface
;
562 ID2D1Factory1
*factory
;
563 IDXGIDevice
*dxgi_device
;
566 void d2d_device_init(struct d2d_device
*device
, ID2D1Factory1
*factory
, IDXGIDevice
*dxgi_device
) DECLSPEC_HIDDEN
;
570 ID2D1Effect ID2D1Effect_iface
;
574 void d2d_effect_init(struct d2d_effect
*effect
) DECLSPEC_HIDDEN
;
576 static inline BOOL
d2d_array_reserve(void **elements
, size_t *capacity
, size_t count
, size_t size
)
578 size_t new_capacity
, max_capacity
;
581 if (count
<= *capacity
)
584 max_capacity
= ~(SIZE_T
)0 / size
;
585 if (count
> max_capacity
)
588 new_capacity
= max(4, *capacity
);
589 while (new_capacity
< count
&& new_capacity
<= max_capacity
/ 2)
591 if (new_capacity
< count
)
592 new_capacity
= max_capacity
;
594 if (!(new_elements
= heap_realloc(*elements
, new_capacity
* size
)))
597 *elements
= new_elements
;
598 *capacity
= new_capacity
;
602 static inline void d2d_matrix_multiply(D2D_MATRIX_3X2_F
*a
, const D2D_MATRIX_3X2_F
*b
)
604 D2D_MATRIX_3X2_F tmp
= *a
;
606 a
->_11
= tmp
._11
* b
->_11
+ tmp
._12
* b
->_21
;
607 a
->_12
= tmp
._11
* b
->_12
+ tmp
._12
* b
->_22
;
608 a
->_21
= tmp
._21
* b
->_11
+ tmp
._22
* b
->_21
;
609 a
->_22
= tmp
._21
* b
->_12
+ tmp
._22
* b
->_22
;
610 a
->_31
= tmp
._31
* b
->_11
+ tmp
._32
* b
->_21
+ b
->_31
;
611 a
->_32
= tmp
._31
* b
->_12
+ tmp
._32
* b
->_22
+ b
->_32
;
614 /* Dst must be different from src. */
615 static inline BOOL
d2d_matrix_invert(D2D_MATRIX_3X2_F
*dst
, const D2D_MATRIX_3X2_F
*src
)
617 float d
= src
->_11
* src
->_22
- src
->_21
* src
->_12
;
621 dst
->_11
= src
->_22
/ d
;
622 dst
->_21
= -src
->_21
/ d
;
623 dst
->_31
= (src
->_21
* src
->_32
- src
->_31
* src
->_22
) / d
;
624 dst
->_12
= -src
->_12
/ d
;
625 dst
->_22
= src
->_11
/ d
;
626 dst
->_32
= -(src
->_11
* src
->_32
- src
->_31
* src
->_12
) / d
;
631 static inline void d2d_point_set(D2D1_POINT_2F
*dst
, float x
, float y
)
637 static inline float d2d_point_dot(const D2D1_POINT_2F
*p0
, const D2D1_POINT_2F
*p1
)
639 return p0
->x
* p1
->x
+ p0
->y
* p1
->y
;
642 static inline void d2d_point_transform(D2D1_POINT_2F
*dst
, const D2D1_MATRIX_3X2_F
*matrix
, float x
, float y
)
644 dst
->x
= x
* matrix
->_11
+ y
* matrix
->_21
+ matrix
->_31
;
645 dst
->y
= x
* matrix
->_12
+ y
* matrix
->_22
+ matrix
->_32
;
648 static inline void d2d_rect_expand(D2D1_RECT_F
*dst
, const D2D1_POINT_2F
*point
)
650 if (point
->x
< dst
->left
)
651 dst
->left
= point
->x
;
652 if (point
->x
> dst
->right
)
653 dst
->right
= point
->x
;
654 if (point
->y
< dst
->top
)
656 if (point
->y
> dst
->bottom
)
657 dst
->bottom
= point
->y
;
660 static inline D2D1_INTERPOLATION_MODE
d2d1_1_interp_mode_from_d2d1(D2D1_BITMAP_INTERPOLATION_MODE mode
)
662 return (D2D1_INTERPOLATION_MODE
)mode
;
665 static inline const char *debug_d2d_color_f(const D2D1_COLOR_F
*colour
)
669 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}", colour
->r
, colour
->g
, colour
->b
, colour
->a
);
672 static inline const char *debug_d2d_point_2f(const D2D1_POINT_2F
*point
)
676 return wine_dbg_sprintf("{%.8e, %.8e}", point
->x
, point
->y
);
679 static inline const char *debug_d2d_rect_f(const D2D1_RECT_F
*rect
)
683 return wine_dbg_sprintf("(%.8e, %.8e)-(%.8e, %.8e)", rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
686 static inline const char *debug_d2d_rounded_rect(const D2D1_ROUNDED_RECT
*rounded_rect
)
690 return wine_dbg_sprintf("(%.8e, %.8e)-(%.8e, %.8e)[%.8e, %.8e]", rounded_rect
->rect
.left
, rounded_rect
->rect
.top
,
691 rounded_rect
->rect
.right
, rounded_rect
->rect
.bottom
, rounded_rect
->radiusX
, rounded_rect
->radiusY
);
694 static inline const char *debug_d2d_ellipse(const D2D1_ELLIPSE
*ellipse
)
698 return wine_dbg_sprintf("(%.8e, %.8e)[%.8e, %.8e]",
699 ellipse
->point
.x
, ellipse
->point
.y
, ellipse
->radiusX
, ellipse
->radiusY
);
702 #endif /* __WINE_D2D1_PRIVATE_H */