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
;
124 struct d2d_device_context_ops
126 HRESULT (*device_context_present
)(IUnknown
*outer_unknown
);
129 struct d2d_device_context
131 ID2D1DeviceContext ID2D1DeviceContext_iface
;
132 ID2D1GdiInteropRenderTarget ID2D1GdiInteropRenderTarget_iface
;
133 IDWriteTextRenderer IDWriteTextRenderer_iface
;
134 IUnknown IUnknown_iface
;
137 IUnknown
*outer_unknown
;
138 const struct d2d_device_context_ops
*ops
;
140 ID2D1Factory
*factory
;
142 ID3D10Device
*d3d_device
;
143 struct d2d_bitmap
*target
;
144 ID3D10StateBlock
*stateblock
;
145 struct d2d_shape_resources shape_resources
[D2D_SHAPE_TYPE_COUNT
];
146 ID3D10PixelShader
*ps
;
148 unsigned int vb_stride
;
150 ID3D10RasterizerState
*rs
;
151 ID3D10BlendState
*bs
;
153 struct d2d_error_state error
;
154 D2D1_DRAWING_STATE_DESCRIPTION1 drawing_state
;
155 IDWriteRenderingParams
*text_rendering_params
;
156 IDWriteRenderingParams
*default_text_rendering_params
;
158 D2D1_RENDER_TARGET_PROPERTIES desc
;
159 D2D1_SIZE_U pixel_size
;
160 struct d2d_clip_stack clip_stack
;
163 HRESULT
d2d_d3d_create_render_target(ID2D1Device
*device
, IDXGISurface
*surface
, IUnknown
*outer_unknown
,
164 const struct d2d_device_context_ops
*ops
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
,
165 void **render_target
) DECLSPEC_HIDDEN
;
167 static inline BOOL
d2d_device_context_is_dxgi_target(const struct d2d_device_context
*context
)
169 return !context
->ops
;
172 struct d2d_wic_render_target
174 IUnknown IUnknown_iface
;
177 IDXGISurface
*dxgi_surface
;
178 ID2D1RenderTarget
*dxgi_target
;
179 IUnknown
*dxgi_inner
;
180 ID3D10Texture2D
*readback_texture
;
188 HRESULT
d2d_wic_render_target_init(struct d2d_wic_render_target
*render_target
, ID2D1Factory1
*factory
,
189 ID3D10Device1
*d3d_device
, IWICBitmap
*bitmap
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
) DECLSPEC_HIDDEN
;
191 struct d2d_dc_render_target
193 ID2D1DCRenderTarget ID2D1DCRenderTarget_iface
;
196 IDXGISurface1
*dxgi_surface
;
197 D2D1_PIXEL_FORMAT pixel_format
;
198 ID3D10Device1
*d3d_device
;
199 ID2D1RenderTarget
*dxgi_target
;
200 IUnknown
*dxgi_inner
;
206 HRESULT
d2d_dc_render_target_init(struct d2d_dc_render_target
*render_target
, ID2D1Factory1
*factory
,
207 ID3D10Device1
*d3d_device
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
) DECLSPEC_HIDDEN
;
209 struct d2d_hwnd_render_target
211 ID2D1HwndRenderTarget ID2D1HwndRenderTarget_iface
;
214 ID2D1RenderTarget
*dxgi_target
;
215 IUnknown
*dxgi_inner
;
216 IDXGISwapChain
*swapchain
;
221 HRESULT
d2d_hwnd_render_target_init(struct d2d_hwnd_render_target
*render_target
, ID2D1Factory1
*factory
,
222 ID3D10Device1
*d3d_device
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
,
223 const D2D1_HWND_RENDER_TARGET_PROPERTIES
*hwnd_desc
) DECLSPEC_HIDDEN
;
225 struct d2d_bitmap_render_target
227 ID2D1BitmapRenderTarget ID2D1BitmapRenderTarget_iface
;
230 ID2D1RenderTarget
*dxgi_target
;
231 IUnknown
*dxgi_inner
;
235 HRESULT
d2d_bitmap_render_target_init(struct d2d_bitmap_render_target
*render_target
,
236 const struct d2d_device_context
*parent_target
, const D2D1_SIZE_F
*size
,
237 const D2D1_SIZE_U
*pixel_size
, const D2D1_PIXEL_FORMAT
*format
,
238 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options
) DECLSPEC_HIDDEN
;
242 ID2D1GradientStopCollection ID2D1GradientStopCollection_iface
;
245 ID2D1Factory
*factory
;
246 ID3D10ShaderResourceView
*view
;
247 D2D1_GRADIENT_STOP
*stops
;
251 HRESULT
d2d_gradient_create(ID2D1Factory
*factory
, ID3D10Device
*device
, const D2D1_GRADIENT_STOP
*stops
,
252 UINT32 stop_count
, D2D1_GAMMA gamma
, D2D1_EXTEND_MODE extend_mode
,
253 struct d2d_gradient
**gradient
) DECLSPEC_HIDDEN
;
257 ID2D1Brush ID2D1Brush_iface
;
260 ID2D1Factory
*factory
;
262 D2D1_MATRIX_3X2_F transform
;
264 enum d2d_brush_type type
;
273 struct d2d_gradient
*gradient
;
279 struct d2d_gradient
*gradient
;
280 D2D1_POINT_2F centre
;
281 D2D1_POINT_2F offset
;
282 D2D1_POINT_2F radius
;
286 struct d2d_bitmap
*bitmap
;
287 D2D1_EXTEND_MODE extend_mode_x
;
288 D2D1_EXTEND_MODE extend_mode_y
;
289 D2D1_INTERPOLATION_MODE interpolation_mode
;
290 ID3D10SamplerState
*sampler_state
;
295 HRESULT
d2d_solid_color_brush_create(ID2D1Factory
*factory
, const D2D1_COLOR_F
*color
,
296 const D2D1_BRUSH_PROPERTIES
*desc
, struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
297 HRESULT
d2d_linear_gradient_brush_create(ID2D1Factory
*factory
,
298 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES
*gradient_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
299 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
300 HRESULT
d2d_radial_gradient_brush_create(ID2D1Factory
*factory
,
301 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES
*gradient_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
302 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
303 HRESULT
d2d_bitmap_brush_create(ID2D1Factory
*factory
, ID2D1Bitmap
*bitmap
,
304 const D2D1_BITMAP_BRUSH_PROPERTIES1
*bitmap_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
305 struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
306 void d2d_brush_bind_resources(struct d2d_brush
*brush
, ID3D10Device
*device
, unsigned int brush_idx
) DECLSPEC_HIDDEN
;
307 HRESULT
d2d_brush_get_ps_cb(struct d2d_brush
*brush
, struct d2d_brush
*opacity_brush
, BOOL outline
, BOOL is_arc
,
308 struct d2d_device_context
*render_target
, ID3D10Buffer
**ps_cb
) DECLSPEC_HIDDEN
;
309 struct d2d_brush
*unsafe_impl_from_ID2D1Brush(ID2D1Brush
*iface
) DECLSPEC_HIDDEN
;
311 struct d2d_stroke_style
313 ID2D1StrokeStyle ID2D1StrokeStyle_iface
;
316 ID2D1Factory
*factory
;
317 D2D1_STROKE_STYLE_PROPERTIES desc
;
322 HRESULT
d2d_stroke_style_init(struct d2d_stroke_style
*style
, ID2D1Factory
*factory
,
323 const D2D1_STROKE_STYLE_PROPERTIES
*desc
, const float *dashes
, UINT32 dash_count
) DECLSPEC_HIDDEN
;
327 ID2D1Layer ID2D1Layer_iface
;
330 ID2D1Factory
*factory
;
334 HRESULT
d2d_layer_create(ID2D1Factory
*factory
, const D2D1_SIZE_F
*size
, struct d2d_layer
**layer
) DECLSPEC_HIDDEN
;
338 ID2D1Mesh ID2D1Mesh_iface
;
341 ID2D1Factory
*factory
;
344 HRESULT
d2d_mesh_create(ID2D1Factory
*factory
, struct d2d_mesh
**mesh
) DECLSPEC_HIDDEN
;
348 ID2D1Bitmap1 ID2D1Bitmap1_iface
;
351 ID2D1Factory
*factory
;
352 ID3D10ShaderResourceView
*srv
;
353 ID3D10RenderTargetView
*rtv
;
354 IDXGISurface
*surface
;
355 ID3D10Resource
*resource
;
356 D2D1_SIZE_U pixel_size
;
357 D2D1_PIXEL_FORMAT format
;
360 D2D1_BITMAP_OPTIONS options
;
363 HRESULT
d2d_bitmap_create(struct d2d_device_context
*context
, D2D1_SIZE_U size
, const void *src_data
,
364 UINT32 pitch
, const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
) DECLSPEC_HIDDEN
;
365 HRESULT
d2d_bitmap_create_shared(struct d2d_device_context
*context
, REFIID iid
, void *data
,
366 const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
) DECLSPEC_HIDDEN
;
367 HRESULT
d2d_bitmap_create_from_wic_bitmap(struct d2d_device_context
*context
, IWICBitmapSource
*bitmap_source
,
368 const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
) DECLSPEC_HIDDEN
;
369 struct d2d_bitmap
*unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap
*iface
) DECLSPEC_HIDDEN
;
371 struct d2d_state_block
373 ID2D1DrawingStateBlock1 ID2D1DrawingStateBlock1_iface
;
376 ID2D1Factory
*factory
;
377 D2D1_DRAWING_STATE_DESCRIPTION1 drawing_state
;
378 IDWriteRenderingParams
*text_rendering_params
;
381 void d2d_state_block_init(struct d2d_state_block
*state_block
, ID2D1Factory
*factory
,
382 const D2D1_DRAWING_STATE_DESCRIPTION1
*desc
, IDWriteRenderingParams
*text_rendering_params
) DECLSPEC_HIDDEN
;
383 struct d2d_state_block
*unsafe_impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStateBlock
*iface
) DECLSPEC_HIDDEN
;
385 enum d2d_geometry_state
387 D2D_GEOMETRY_STATE_INITIAL
= 0,
388 D2D_GEOMETRY_STATE_ERROR
,
389 D2D_GEOMETRY_STATE_OPEN
,
390 D2D_GEOMETRY_STATE_CLOSED
,
391 D2D_GEOMETRY_STATE_FIGURE
,
394 struct d2d_curve_vertex
396 D2D1_POINT_2F position
;
413 struct d2d_outline_vertex
415 D2D1_POINT_2F position
;
420 struct d2d_curve_outline_vertex
422 D2D1_POINT_2F position
;
423 D2D1_POINT_2F p0
, p1
, p2
;
424 D2D1_POINT_2F prev
, next
;
429 ID2D1Geometry ID2D1Geometry_iface
;
432 ID2D1Factory
*factory
;
434 D2D_MATRIX_3X2_F transform
;
438 D2D1_POINT_2F
*vertices
;
441 struct d2d_face
*faces
;
445 struct d2d_curve_vertex
*bezier_vertices
;
446 size_t bezier_vertices_size
;
447 size_t bezier_vertex_count
;
449 struct d2d_curve_vertex
*arc_vertices
;
450 size_t arc_vertices_size
;
451 size_t arc_vertex_count
;
456 struct d2d_outline_vertex
*vertices
;
457 size_t vertices_size
;
460 struct d2d_face
*faces
;
464 struct d2d_curve_outline_vertex
*beziers
;
468 struct d2d_face
*bezier_faces
;
469 size_t bezier_faces_size
;
470 size_t bezier_face_count
;
472 struct d2d_curve_outline_vertex
*arcs
;
476 struct d2d_face
*arc_faces
;
477 size_t arc_faces_size
;
478 size_t arc_face_count
;
485 D2D1_ELLIPSE ellipse
;
489 ID2D1GeometrySink ID2D1GeometrySink_iface
;
491 struct d2d_figure
*figures
;
495 enum d2d_geometry_state state
;
496 D2D1_FILL_MODE fill_mode
;
497 UINT32 segment_count
;
507 D2D1_ROUNDED_RECT rounded_rect
;
511 ID2D1Geometry
*src_geometry
;
512 D2D_MATRIX_3X2_F transform
;
516 ID2D1Geometry
**src_geometries
;
517 UINT32 geometry_count
;
518 D2D1_FILL_MODE fill_mode
;
523 HRESULT
d2d_ellipse_geometry_init(struct d2d_geometry
*geometry
,
524 ID2D1Factory
*factory
, const D2D1_ELLIPSE
*ellipse
) DECLSPEC_HIDDEN
;
525 void d2d_path_geometry_init(struct d2d_geometry
*geometry
, ID2D1Factory
*factory
) DECLSPEC_HIDDEN
;
526 HRESULT
d2d_rectangle_geometry_init(struct d2d_geometry
*geometry
,
527 ID2D1Factory
*factory
, const D2D1_RECT_F
*rect
) DECLSPEC_HIDDEN
;
528 HRESULT
d2d_rounded_rectangle_geometry_init(struct d2d_geometry
*geometry
,
529 ID2D1Factory
*factory
, const D2D1_ROUNDED_RECT
*rounded_rect
) DECLSPEC_HIDDEN
;
530 void d2d_transformed_geometry_init(struct d2d_geometry
*geometry
, ID2D1Factory
*factory
,
531 ID2D1Geometry
*src_geometry
, const D2D_MATRIX_3X2_F
*transform
) DECLSPEC_HIDDEN
;
532 HRESULT
d2d_geometry_group_init(struct d2d_geometry
*geometry
, ID2D1Factory
*factory
,
533 D2D1_FILL_MODE fill_mode
, ID2D1Geometry
**src_geometries
, unsigned int geometry_count
) DECLSPEC_HIDDEN
;
534 struct d2d_geometry
*unsafe_impl_from_ID2D1Geometry(ID2D1Geometry
*iface
) DECLSPEC_HIDDEN
;
538 ID2D1Device ID2D1Device_iface
;
540 ID2D1Factory1
*factory
;
541 IDXGIDevice
*dxgi_device
;
544 void d2d_device_init(struct d2d_device
*device
, ID2D1Factory1
*factory
, IDXGIDevice
*dxgi_device
) DECLSPEC_HIDDEN
;
548 ID2D1Effect ID2D1Effect_iface
;
552 void d2d_effect_init(struct d2d_effect
*effect
) DECLSPEC_HIDDEN
;
554 static inline BOOL
d2d_array_reserve(void **elements
, size_t *capacity
, size_t count
, size_t size
)
556 size_t new_capacity
, max_capacity
;
559 if (count
<= *capacity
)
562 max_capacity
= ~(SIZE_T
)0 / size
;
563 if (count
> max_capacity
)
566 new_capacity
= max(4, *capacity
);
567 while (new_capacity
< count
&& new_capacity
<= max_capacity
/ 2)
569 if (new_capacity
< count
)
570 new_capacity
= max_capacity
;
572 if (!(new_elements
= heap_realloc(*elements
, new_capacity
* size
)))
575 *elements
= new_elements
;
576 *capacity
= new_capacity
;
580 static inline void d2d_matrix_multiply(D2D_MATRIX_3X2_F
*a
, const D2D_MATRIX_3X2_F
*b
)
582 D2D_MATRIX_3X2_F tmp
= *a
;
584 a
->_11
= tmp
._11
* b
->_11
+ tmp
._12
* b
->_21
;
585 a
->_12
= tmp
._11
* b
->_12
+ tmp
._12
* b
->_22
;
586 a
->_21
= tmp
._21
* b
->_11
+ tmp
._22
* b
->_21
;
587 a
->_22
= tmp
._21
* b
->_12
+ tmp
._22
* b
->_22
;
588 a
->_31
= tmp
._31
* b
->_11
+ tmp
._32
* b
->_21
+ b
->_31
;
589 a
->_32
= tmp
._31
* b
->_12
+ tmp
._32
* b
->_22
+ b
->_32
;
592 /* Dst must be different from src. */
593 static inline BOOL
d2d_matrix_invert(D2D_MATRIX_3X2_F
*dst
, const D2D_MATRIX_3X2_F
*src
)
595 float d
= src
->_11
* src
->_22
- src
->_21
* src
->_12
;
599 dst
->_11
= src
->_22
/ d
;
600 dst
->_21
= -src
->_21
/ d
;
601 dst
->_31
= (src
->_21
* src
->_32
- src
->_31
* src
->_22
) / d
;
602 dst
->_12
= -src
->_12
/ d
;
603 dst
->_22
= src
->_11
/ d
;
604 dst
->_32
= -(src
->_11
* src
->_32
- src
->_31
* src
->_12
) / d
;
609 static inline void d2d_point_set(D2D1_POINT_2F
*dst
, float x
, float y
)
615 static inline float d2d_point_dot(const D2D1_POINT_2F
*p0
, const D2D1_POINT_2F
*p1
)
617 return p0
->x
* p1
->x
+ p0
->y
* p1
->y
;
620 static inline void d2d_point_transform(D2D1_POINT_2F
*dst
, const D2D1_MATRIX_3X2_F
*matrix
, float x
, float y
)
622 dst
->x
= x
* matrix
->_11
+ y
* matrix
->_21
+ matrix
->_31
;
623 dst
->y
= x
* matrix
->_12
+ y
* matrix
->_22
+ matrix
->_32
;
626 static inline void d2d_rect_expand(D2D1_RECT_F
*dst
, const D2D1_POINT_2F
*point
)
628 if (point
->x
< dst
->left
)
629 dst
->left
= point
->x
;
630 if (point
->x
> dst
->right
)
631 dst
->right
= point
->x
;
632 if (point
->y
< dst
->top
)
634 if (point
->y
> dst
->bottom
)
635 dst
->bottom
= point
->y
;
638 static inline D2D1_INTERPOLATION_MODE
d2d1_1_interp_mode_from_d2d1(D2D1_BITMAP_INTERPOLATION_MODE mode
)
640 return (D2D1_INTERPOLATION_MODE
)mode
;
643 static inline const char *debug_d2d_color_f(const D2D1_COLOR_F
*colour
)
647 return wine_dbg_sprintf("{%.8e, %.8e, %.8e, %.8e}", colour
->r
, colour
->g
, colour
->b
, colour
->a
);
650 static inline const char *debug_d2d_point_2f(const D2D1_POINT_2F
*point
)
654 return wine_dbg_sprintf("{%.8e, %.8e}", point
->x
, point
->y
);
657 static inline const char *debug_d2d_rect_f(const D2D1_RECT_F
*rect
)
661 return wine_dbg_sprintf("(%.8e, %.8e)-(%.8e, %.8e)", rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
664 static inline const char *debug_d2d_rounded_rect(const D2D1_ROUNDED_RECT
*rounded_rect
)
668 return wine_dbg_sprintf("(%.8e, %.8e)-(%.8e, %.8e)[%.8e, %.8e]", rounded_rect
->rect
.left
, rounded_rect
->rect
.top
,
669 rounded_rect
->rect
.right
, rounded_rect
->rect
.bottom
, rounded_rect
->radiusX
, rounded_rect
->radiusY
);
672 static inline const char *debug_d2d_ellipse(const D2D1_ELLIPSE
*ellipse
)
676 return wine_dbg_sprintf("(%.8e, %.8e)[%.8e, %.8e]",
677 ellipse
->point
.x
, ellipse
->point
.y
, ellipse
->radiusX
, ellipse
->radiusY
);
680 #endif /* __WINE_D2D1_PRIVATE_H */