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"
35 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
41 D2D_BRUSH_TYPE_LINEAR
,
42 D2D_BRUSH_TYPE_RADIAL
,
43 D2D_BRUSH_TYPE_BITMAP
,
49 D2D_SHAPE_TYPE_OUTLINE
,
50 D2D_SHAPE_TYPE_BEZIER_OUTLINE
,
51 D2D_SHAPE_TYPE_TRIANGLE
,
52 D2D_SHAPE_TYPE_BEZIER
,
58 unsigned int max_version_factory
;
60 extern struct d2d_settings d2d_settings DECLSPEC_HIDDEN
;
69 struct d2d_error_state
75 struct d2d_shape_resources
77 ID3D10InputLayout
*il
;
78 ID3D10VertexShader
*vs
;
83 enum d2d_brush_type type
;
96 unsigned int stop_count
;
100 D2D1_POINT_2F centre
;
101 D2D1_POINT_2F offset
;
104 unsigned int stop_count
;
109 float _11
, _21
, _31
, pad
;
120 struct d2d_brush_cb colour_brush
;
121 struct d2d_brush_cb opacity_brush
;
124 struct d2d_d3d_render_target
126 ID2D1RenderTarget ID2D1RenderTarget_iface
;
127 ID2D1GdiInteropRenderTarget ID2D1GdiInteropRenderTarget_iface
;
128 IDWriteTextRenderer IDWriteTextRenderer_iface
;
131 IUnknown
*outer_unknown
;
133 ID2D1Factory
*factory
;
134 ID3D10Device
*device
;
135 ID3D10RenderTargetView
*view
;
136 ID3D10StateBlock
*stateblock
;
137 struct d2d_shape_resources shape_resources
[D2D_SHAPE_TYPE_COUNT
];
138 ID3D10PixelShader
*ps
;
140 unsigned int vb_stride
;
142 ID3D10RasterizerState
*rs
;
143 ID3D10BlendState
*bs
;
145 struct d2d_error_state error
;
146 D2D1_DRAWING_STATE_DESCRIPTION drawing_state
;
147 IDWriteRenderingParams
*text_rendering_params
;
148 IDWriteRenderingParams
*default_text_rendering_params
;
150 D2D1_RENDER_TARGET_PROPERTIES desc
;
151 D2D1_SIZE_U pixel_size
;
152 struct d2d_clip_stack clip_stack
;
155 HRESULT
d2d_d3d_create_render_target(ID2D1Factory
*factory
, IDXGISurface
*surface
, IUnknown
*outer_unknown
,
156 const D2D1_RENDER_TARGET_PROPERTIES
*desc
, ID2D1RenderTarget
**render_target
) DECLSPEC_HIDDEN
;
157 HRESULT
d2d_d3d_render_target_create_rtv(ID2D1RenderTarget
*render_target
, IDXGISurface1
*surface
) DECLSPEC_HIDDEN
;
159 struct d2d_wic_render_target
161 ID2D1RenderTarget ID2D1RenderTarget_iface
;
164 IDXGISurface
*dxgi_surface
;
165 ID2D1RenderTarget
*dxgi_target
;
166 ID3D10Texture2D
*readback_texture
;
174 HRESULT
d2d_wic_render_target_init(struct d2d_wic_render_target
*render_target
, ID2D1Factory
*factory
,
175 ID3D10Device1
*device
, IWICBitmap
*bitmap
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
) DECLSPEC_HIDDEN
;
177 struct d2d_dc_render_target
179 ID2D1DCRenderTarget ID2D1DCRenderTarget_iface
;
182 IDXGISurface1
*dxgi_surface
;
183 ID2D1RenderTarget
*dxgi_target
;
189 HRESULT
d2d_dc_render_target_init(struct d2d_dc_render_target
*render_target
, ID2D1Factory
*factory
,
190 ID3D10Device1
*device
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
) DECLSPEC_HIDDEN
;
192 struct d2d_hwnd_render_target
194 ID2D1HwndRenderTarget ID2D1HwndRenderTarget_iface
;
197 ID2D1RenderTarget
*dxgi_target
;
198 IDXGISwapChain
*swapchain
;
203 HRESULT
d2d_hwnd_render_target_init(struct d2d_hwnd_render_target
*render_target
, ID2D1Factory
*factory
,
204 ID3D10Device1
*device
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
,
205 const D2D1_HWND_RENDER_TARGET_PROPERTIES
*hwnd_desc
) DECLSPEC_HIDDEN
;
207 struct d2d_bitmap_render_target
209 ID2D1BitmapRenderTarget ID2D1BitmapRenderTarget_iface
;
212 ID2D1RenderTarget
*dxgi_target
;
216 HRESULT
d2d_bitmap_render_target_init(struct d2d_bitmap_render_target
*render_target
,
217 const struct d2d_d3d_render_target
*parent_target
, const D2D1_SIZE_F
*size
,
218 const D2D1_SIZE_U
*pixel_size
, const D2D1_PIXEL_FORMAT
*format
,
219 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options
) DECLSPEC_HIDDEN
;
223 ID2D1GradientStopCollection ID2D1GradientStopCollection_iface
;
226 ID2D1Factory
*factory
;
227 ID3D10ShaderResourceView
*view
;
228 D2D1_GRADIENT_STOP
*stops
;
232 HRESULT
d2d_gradient_create(ID2D1Factory
*factory
, ID3D10Device
*device
, const D2D1_GRADIENT_STOP
*stops
,
233 UINT32 stop_count
, D2D1_GAMMA gamma
, D2D1_EXTEND_MODE extend_mode
,
234 struct d2d_gradient
**gradient
) DECLSPEC_HIDDEN
;
238 ID2D1Brush ID2D1Brush_iface
;
241 ID2D1Factory
*factory
;
243 D2D1_MATRIX_3X2_F transform
;
245 enum d2d_brush_type type
;
254 struct d2d_gradient
*gradient
;
260 struct d2d_gradient
*gradient
;
261 D2D1_POINT_2F centre
;
262 D2D1_POINT_2F offset
;
263 D2D1_POINT_2F radius
;
267 struct d2d_bitmap
*bitmap
;
268 D2D1_EXTEND_MODE extend_mode_x
;
269 D2D1_EXTEND_MODE extend_mode_y
;
270 D2D1_BITMAP_INTERPOLATION_MODE interpolation_mode
;
271 ID3D10SamplerState
*sampler_state
;
276 HRESULT
d2d_solid_color_brush_create(ID2D1Factory
*factory
, const D2D1_COLOR_F
*color
,
277 const D2D1_BRUSH_PROPERTIES
*desc
, struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
278 HRESULT
d2d_linear_gradient_brush_create(ID2D1Factory
*factory
,
279 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES
*gradient_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
280 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
281 HRESULT
d2d_radial_gradient_brush_create(ID2D1Factory
*factory
,
282 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES
*gradient_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
283 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
284 HRESULT
d2d_bitmap_brush_create(ID2D1Factory
*factory
, ID2D1Bitmap
*bitmap
,
285 const D2D1_BITMAP_BRUSH_PROPERTIES
*bitmap_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
286 struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
287 void d2d_brush_bind_resources(struct d2d_brush
*brush
, ID3D10Device
*device
, unsigned int brush_idx
) DECLSPEC_HIDDEN
;
288 HRESULT
d2d_brush_get_ps_cb(struct d2d_brush
*brush
, struct d2d_brush
*opacity_brush
, BOOL outline
,
289 struct d2d_d3d_render_target
*render_target
, ID3D10Buffer
**ps_cb
) DECLSPEC_HIDDEN
;
290 struct d2d_brush
*unsafe_impl_from_ID2D1Brush(ID2D1Brush
*iface
) DECLSPEC_HIDDEN
;
292 struct d2d_stroke_style
294 ID2D1StrokeStyle ID2D1StrokeStyle_iface
;
297 ID2D1Factory
*factory
;
298 D2D1_STROKE_STYLE_PROPERTIES desc
;
303 HRESULT
d2d_stroke_style_init(struct d2d_stroke_style
*style
, ID2D1Factory
*factory
,
304 const D2D1_STROKE_STYLE_PROPERTIES
*desc
, const float *dashes
, UINT32 dash_count
) DECLSPEC_HIDDEN
;
308 ID2D1Layer ID2D1Layer_iface
;
311 ID2D1Factory
*factory
;
315 HRESULT
d2d_layer_create(ID2D1Factory
*factory
, const D2D1_SIZE_F
*size
, struct d2d_layer
**layer
) DECLSPEC_HIDDEN
;
319 ID2D1Mesh ID2D1Mesh_iface
;
322 ID2D1Factory
*factory
;
325 HRESULT
d2d_mesh_create(ID2D1Factory
*factory
, struct d2d_mesh
**mesh
) DECLSPEC_HIDDEN
;
329 ID2D1Bitmap ID2D1Bitmap_iface
;
332 ID2D1Factory
*factory
;
333 ID3D10ShaderResourceView
*view
;
334 D2D1_SIZE_U pixel_size
;
335 D2D1_PIXEL_FORMAT format
;
340 HRESULT
d2d_bitmap_create(ID2D1Factory
*factory
, ID3D10Device
*device
, D2D1_SIZE_U size
, const void *src_data
,
341 UINT32 pitch
, const D2D1_BITMAP_PROPERTIES
*desc
, struct d2d_bitmap
**bitmap
) DECLSPEC_HIDDEN
;
342 HRESULT
d2d_bitmap_create_shared(ID2D1RenderTarget
*render_target
, ID3D10Device
*device
, REFIID iid
, void *data
,
343 const D2D1_BITMAP_PROPERTIES
*desc
, struct d2d_bitmap
**bitmap
) DECLSPEC_HIDDEN
;
344 HRESULT
d2d_bitmap_create_from_wic_bitmap(ID2D1Factory
*factory
, ID3D10Device
*device
, IWICBitmapSource
*bitmap_source
,
345 const D2D1_BITMAP_PROPERTIES
*desc
, struct d2d_bitmap
**bitmap
) DECLSPEC_HIDDEN
;
346 struct d2d_bitmap
*unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap
*iface
) DECLSPEC_HIDDEN
;
348 struct d2d_state_block
350 ID2D1DrawingStateBlock ID2D1DrawingStateBlock_iface
;
353 ID2D1Factory
*factory
;
354 D2D1_DRAWING_STATE_DESCRIPTION drawing_state
;
355 IDWriteRenderingParams
*text_rendering_params
;
358 void d2d_state_block_init(struct d2d_state_block
*state_block
, ID2D1Factory
*factory
,
359 const D2D1_DRAWING_STATE_DESCRIPTION
*desc
, IDWriteRenderingParams
*text_rendering_params
) DECLSPEC_HIDDEN
;
360 struct d2d_state_block
*unsafe_impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStateBlock
*iface
) DECLSPEC_HIDDEN
;
362 enum d2d_geometry_state
364 D2D_GEOMETRY_STATE_INITIAL
= 0,
365 D2D_GEOMETRY_STATE_ERROR
,
366 D2D_GEOMETRY_STATE_OPEN
,
367 D2D_GEOMETRY_STATE_CLOSED
,
368 D2D_GEOMETRY_STATE_FIGURE
,
371 struct d2d_bezier_vertex
373 D2D1_POINT_2F position
;
390 struct d2d_outline_vertex
392 D2D1_POINT_2F position
;
397 struct d2d_bezier_outline_vertex
399 D2D1_POINT_2F position
;
400 D2D1_POINT_2F p0
, p1
, p2
;
401 D2D1_POINT_2F prev
, next
;
406 ID2D1Geometry ID2D1Geometry_iface
;
409 ID2D1Factory
*factory
;
411 D2D_MATRIX_3X2_F transform
;
415 D2D1_POINT_2F
*vertices
;
418 struct d2d_face
*faces
;
422 struct d2d_bezier_vertex
*bezier_vertices
;
423 size_t bezier_vertex_count
;
428 struct d2d_outline_vertex
*vertices
;
429 size_t vertices_size
;
432 struct d2d_face
*faces
;
436 struct d2d_bezier_outline_vertex
*beziers
;
440 struct d2d_face
*bezier_faces
;
441 size_t bezier_faces_size
;
442 size_t bezier_face_count
;
449 ID2D1GeometrySink ID2D1GeometrySink_iface
;
451 struct d2d_figure
*figures
;
455 enum d2d_geometry_state state
;
456 D2D1_FILL_MODE fill_mode
;
457 UINT32 segment_count
;
467 ID2D1Geometry
*src_geometry
;
468 D2D_MATRIX_3X2_F transform
;
473 void d2d_path_geometry_init(struct d2d_geometry
*geometry
, ID2D1Factory
*factory
) DECLSPEC_HIDDEN
;
474 HRESULT
d2d_rectangle_geometry_init(struct d2d_geometry
*geometry
,
475 ID2D1Factory
*factory
, const D2D1_RECT_F
*rect
) DECLSPEC_HIDDEN
;
476 void d2d_transformed_geometry_init(struct d2d_geometry
*geometry
, ID2D1Factory
*factory
,
477 ID2D1Geometry
*src_geometry
, const D2D_MATRIX_3X2_F
*transform
) DECLSPEC_HIDDEN
;
478 struct d2d_geometry
*unsafe_impl_from_ID2D1Geometry(ID2D1Geometry
*iface
) DECLSPEC_HIDDEN
;
480 static inline BOOL
d2d_array_reserve(void **elements
, size_t *capacity
, size_t count
, size_t size
)
482 size_t new_capacity
, max_capacity
;
485 if (count
<= *capacity
)
488 max_capacity
= ~(SIZE_T
)0 / size
;
489 if (count
> max_capacity
)
492 new_capacity
= max(4, *capacity
);
493 while (new_capacity
< count
&& new_capacity
<= max_capacity
/ 2)
495 if (new_capacity
< count
)
496 new_capacity
= max_capacity
;
498 if (!(new_elements
= heap_realloc(*elements
, new_capacity
* size
)))
501 *elements
= new_elements
;
502 *capacity
= new_capacity
;
506 static inline void d2d_matrix_multiply(D2D_MATRIX_3X2_F
*a
, const D2D_MATRIX_3X2_F
*b
)
508 D2D_MATRIX_3X2_F tmp
= *a
;
510 a
->_11
= tmp
._11
* b
->_11
+ tmp
._12
* b
->_21
;
511 a
->_12
= tmp
._11
* b
->_12
+ tmp
._12
* b
->_22
;
512 a
->_21
= tmp
._21
* b
->_11
+ tmp
._22
* b
->_21
;
513 a
->_22
= tmp
._21
* b
->_12
+ tmp
._22
* b
->_22
;
514 a
->_31
= tmp
._31
* b
->_11
+ tmp
._32
* b
->_21
+ b
->_31
;
515 a
->_32
= tmp
._31
* b
->_12
+ tmp
._32
* b
->_22
+ b
->_32
;
518 /* Dst must be different from src. */
519 static inline BOOL
d2d_matrix_invert(D2D_MATRIX_3X2_F
*dst
, const D2D_MATRIX_3X2_F
*src
)
521 float d
= src
->_11
* src
->_22
- src
->_21
* src
->_12
;
525 dst
->_11
= src
->_22
/ d
;
526 dst
->_21
= -src
->_21
/ d
;
527 dst
->_31
= (src
->_21
* src
->_32
- src
->_31
* src
->_22
) / d
;
528 dst
->_12
= -src
->_12
/ d
;
529 dst
->_22
= src
->_11
/ d
;
530 dst
->_32
= -(src
->_11
* src
->_32
- src
->_31
* src
->_12
) / d
;
535 static inline void d2d_point_set(D2D1_POINT_2F
*dst
, float x
, float y
)
541 static inline float d2d_point_dot(const D2D1_POINT_2F
*p0
, const D2D1_POINT_2F
*p1
)
543 return p0
->x
* p1
->x
+ p0
->y
* p1
->y
;
546 static inline void d2d_point_transform(D2D1_POINT_2F
*dst
, const D2D1_MATRIX_3X2_F
*matrix
, float x
, float y
)
548 dst
->x
= x
* matrix
->_11
+ y
* matrix
->_21
+ matrix
->_31
;
549 dst
->y
= x
* matrix
->_12
+ y
* matrix
->_22
+ matrix
->_32
;
552 static inline void d2d_rect_expand(D2D1_RECT_F
*dst
, const D2D1_POINT_2F
*point
)
554 if (point
->x
< dst
->left
)
555 dst
->left
= point
->x
;
556 if (point
->x
> dst
->right
)
557 dst
->right
= point
->x
;
558 if (point
->y
< dst
->top
)
560 if (point
->y
> dst
->bottom
)
561 dst
->bottom
= point
->y
;
564 static inline const char *debug_d2d_rect_f(const D2D1_RECT_F
*rect
)
566 if (!rect
) return "(null)";
567 return wine_dbg_sprintf("(%.8e,%.8e)-(%.8e,%.8e)", rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
570 #endif /* __WINE_D2D1_PRIVATE_H */