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"
37 D2D_BRUSH_TYPE_LINEAR
,
38 D2D_BRUSH_TYPE_RADIAL
,
39 D2D_BRUSH_TYPE_BITMAP
,
45 D2D_SHAPE_TYPE_OUTLINE
,
46 D2D_SHAPE_TYPE_BEZIER_OUTLINE
,
47 D2D_SHAPE_TYPE_TRIANGLE
,
48 D2D_SHAPE_TYPE_BEZIER
,
54 unsigned int max_version_factory
;
56 extern struct d2d_settings d2d_settings DECLSPEC_HIDDEN
;
65 struct d2d_error_state
71 struct d2d_shape_resources
73 ID3D10InputLayout
*il
;
74 ID3D10VertexShader
*vs
;
79 enum d2d_brush_type type
;
92 unsigned int stop_count
;
100 unsigned int stop_count
;
105 float _11
, _21
, _31
, pad
;
116 struct d2d_brush_cb colour_brush
;
117 struct d2d_brush_cb opacity_brush
;
120 struct d2d_device_context_ops
122 HRESULT (*device_context_present
)(IUnknown
*outer_unknown
);
125 struct d2d_device_context
127 ID2D1DeviceContext ID2D1DeviceContext_iface
;
128 ID2D1GdiInteropRenderTarget ID2D1GdiInteropRenderTarget_iface
;
129 IDWriteTextRenderer IDWriteTextRenderer_iface
;
130 IUnknown IUnknown_iface
;
133 IUnknown
*outer_unknown
;
134 const struct d2d_device_context_ops
*ops
;
136 ID2D1Factory
*factory
;
138 ID3D10Device
*d3d_device
;
139 struct d2d_bitmap
*target
;
140 ID3D10StateBlock
*stateblock
;
141 struct d2d_shape_resources shape_resources
[D2D_SHAPE_TYPE_COUNT
];
142 ID3D10PixelShader
*ps
;
144 unsigned int vb_stride
;
146 ID3D10RasterizerState
*rs
;
147 ID3D10BlendState
*bs
;
149 struct d2d_error_state error
;
150 D2D1_DRAWING_STATE_DESCRIPTION1 drawing_state
;
151 IDWriteRenderingParams
*text_rendering_params
;
152 IDWriteRenderingParams
*default_text_rendering_params
;
154 D2D1_RENDER_TARGET_PROPERTIES desc
;
155 D2D1_SIZE_U pixel_size
;
156 struct d2d_clip_stack clip_stack
;
159 HRESULT
d2d_d3d_create_render_target(ID2D1Device
*device
, IDXGISurface
*surface
, IUnknown
*outer_unknown
,
160 const struct d2d_device_context_ops
*ops
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
,
161 void **render_target
) DECLSPEC_HIDDEN
;
163 static inline BOOL
d2d_device_context_is_dxgi_target(const struct d2d_device_context
*context
)
165 return !context
->ops
;
168 struct d2d_wic_render_target
170 IUnknown IUnknown_iface
;
173 IDXGISurface
*dxgi_surface
;
174 ID2D1RenderTarget
*dxgi_target
;
175 IUnknown
*dxgi_inner
;
176 ID3D10Texture2D
*readback_texture
;
184 HRESULT
d2d_wic_render_target_init(struct d2d_wic_render_target
*render_target
, ID2D1Factory1
*factory
,
185 ID3D10Device1
*d3d_device
, IWICBitmap
*bitmap
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
) DECLSPEC_HIDDEN
;
187 struct d2d_dc_render_target
189 ID2D1DCRenderTarget ID2D1DCRenderTarget_iface
;
192 IDXGISurface1
*dxgi_surface
;
193 D2D1_PIXEL_FORMAT pixel_format
;
194 ID3D10Device1
*d3d_device
;
195 ID2D1RenderTarget
*dxgi_target
;
196 IUnknown
*dxgi_inner
;
202 HRESULT
d2d_dc_render_target_init(struct d2d_dc_render_target
*render_target
, ID2D1Factory1
*factory
,
203 ID3D10Device1
*d3d_device
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
) DECLSPEC_HIDDEN
;
205 struct d2d_hwnd_render_target
207 ID2D1HwndRenderTarget ID2D1HwndRenderTarget_iface
;
210 ID2D1RenderTarget
*dxgi_target
;
211 IUnknown
*dxgi_inner
;
212 IDXGISwapChain
*swapchain
;
217 HRESULT
d2d_hwnd_render_target_init(struct d2d_hwnd_render_target
*render_target
, ID2D1Factory1
*factory
,
218 ID3D10Device1
*d3d_device
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
,
219 const D2D1_HWND_RENDER_TARGET_PROPERTIES
*hwnd_desc
) DECLSPEC_HIDDEN
;
221 struct d2d_bitmap_render_target
223 ID2D1BitmapRenderTarget ID2D1BitmapRenderTarget_iface
;
226 ID2D1RenderTarget
*dxgi_target
;
227 IUnknown
*dxgi_inner
;
231 HRESULT
d2d_bitmap_render_target_init(struct d2d_bitmap_render_target
*render_target
,
232 const struct d2d_device_context
*parent_target
, const D2D1_SIZE_F
*size
,
233 const D2D1_SIZE_U
*pixel_size
, const D2D1_PIXEL_FORMAT
*format
,
234 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options
) DECLSPEC_HIDDEN
;
238 ID2D1GradientStopCollection ID2D1GradientStopCollection_iface
;
241 ID2D1Factory
*factory
;
242 ID3D10ShaderResourceView
*view
;
243 D2D1_GRADIENT_STOP
*stops
;
247 HRESULT
d2d_gradient_create(ID2D1Factory
*factory
, ID3D10Device
*device
, const D2D1_GRADIENT_STOP
*stops
,
248 UINT32 stop_count
, D2D1_GAMMA gamma
, D2D1_EXTEND_MODE extend_mode
,
249 struct d2d_gradient
**gradient
) DECLSPEC_HIDDEN
;
253 ID2D1Brush ID2D1Brush_iface
;
256 ID2D1Factory
*factory
;
258 D2D1_MATRIX_3X2_F transform
;
260 enum d2d_brush_type type
;
269 struct d2d_gradient
*gradient
;
275 struct d2d_gradient
*gradient
;
276 D2D1_POINT_2F centre
;
277 D2D1_POINT_2F offset
;
278 D2D1_POINT_2F radius
;
282 struct d2d_bitmap
*bitmap
;
283 D2D1_EXTEND_MODE extend_mode_x
;
284 D2D1_EXTEND_MODE extend_mode_y
;
285 D2D1_INTERPOLATION_MODE interpolation_mode
;
286 ID3D10SamplerState
*sampler_state
;
291 HRESULT
d2d_solid_color_brush_create(ID2D1Factory
*factory
, const D2D1_COLOR_F
*color
,
292 const D2D1_BRUSH_PROPERTIES
*desc
, struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
293 HRESULT
d2d_linear_gradient_brush_create(ID2D1Factory
*factory
,
294 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES
*gradient_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
295 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
296 HRESULT
d2d_radial_gradient_brush_create(ID2D1Factory
*factory
,
297 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES
*gradient_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
298 ID2D1GradientStopCollection
*gradient
, struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
299 HRESULT
d2d_bitmap_brush_create(ID2D1Factory
*factory
, ID2D1Bitmap
*bitmap
,
300 const D2D1_BITMAP_BRUSH_PROPERTIES1
*bitmap_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
301 struct d2d_brush
**brush
) DECLSPEC_HIDDEN
;
302 void d2d_brush_bind_resources(struct d2d_brush
*brush
, ID3D10Device
*device
, unsigned int brush_idx
) DECLSPEC_HIDDEN
;
303 HRESULT
d2d_brush_get_ps_cb(struct d2d_brush
*brush
, struct d2d_brush
*opacity_brush
, BOOL outline
,
304 struct d2d_device_context
*render_target
, ID3D10Buffer
**ps_cb
) DECLSPEC_HIDDEN
;
305 struct d2d_brush
*unsafe_impl_from_ID2D1Brush(ID2D1Brush
*iface
) DECLSPEC_HIDDEN
;
307 struct d2d_stroke_style
309 ID2D1StrokeStyle ID2D1StrokeStyle_iface
;
312 ID2D1Factory
*factory
;
313 D2D1_STROKE_STYLE_PROPERTIES desc
;
318 HRESULT
d2d_stroke_style_init(struct d2d_stroke_style
*style
, ID2D1Factory
*factory
,
319 const D2D1_STROKE_STYLE_PROPERTIES
*desc
, const float *dashes
, UINT32 dash_count
) DECLSPEC_HIDDEN
;
323 ID2D1Layer ID2D1Layer_iface
;
326 ID2D1Factory
*factory
;
330 HRESULT
d2d_layer_create(ID2D1Factory
*factory
, const D2D1_SIZE_F
*size
, struct d2d_layer
**layer
) DECLSPEC_HIDDEN
;
334 ID2D1Mesh ID2D1Mesh_iface
;
337 ID2D1Factory
*factory
;
340 HRESULT
d2d_mesh_create(ID2D1Factory
*factory
, struct d2d_mesh
**mesh
) DECLSPEC_HIDDEN
;
344 ID2D1Bitmap1 ID2D1Bitmap1_iface
;
347 ID2D1Factory
*factory
;
348 ID3D10ShaderResourceView
*view
;
349 ID3D10RenderTargetView
*rtv
;
350 IDXGISurface
*surface
;
351 D2D1_SIZE_U pixel_size
;
352 D2D1_PIXEL_FORMAT format
;
355 D2D1_BITMAP_OPTIONS options
;
358 HRESULT
d2d_bitmap_create(struct d2d_device_context
*context
, D2D1_SIZE_U size
, const void *src_data
,
359 UINT32 pitch
, const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
) DECLSPEC_HIDDEN
;
360 HRESULT
d2d_bitmap_create_shared(struct d2d_device_context
*context
, REFIID iid
, void *data
,
361 const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
) DECLSPEC_HIDDEN
;
362 HRESULT
d2d_bitmap_create_from_wic_bitmap(struct d2d_device_context
*context
, IWICBitmapSource
*bitmap_source
,
363 const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
) DECLSPEC_HIDDEN
;
364 struct d2d_bitmap
*unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap
*iface
) DECLSPEC_HIDDEN
;
366 struct d2d_state_block
368 ID2D1DrawingStateBlock1 ID2D1DrawingStateBlock1_iface
;
371 ID2D1Factory
*factory
;
372 D2D1_DRAWING_STATE_DESCRIPTION1 drawing_state
;
373 IDWriteRenderingParams
*text_rendering_params
;
376 void d2d_state_block_init(struct d2d_state_block
*state_block
, ID2D1Factory
*factory
,
377 const D2D1_DRAWING_STATE_DESCRIPTION1
*desc
, IDWriteRenderingParams
*text_rendering_params
) DECLSPEC_HIDDEN
;
378 struct d2d_state_block
*unsafe_impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStateBlock
*iface
) DECLSPEC_HIDDEN
;
380 enum d2d_geometry_state
382 D2D_GEOMETRY_STATE_INITIAL
= 0,
383 D2D_GEOMETRY_STATE_ERROR
,
384 D2D_GEOMETRY_STATE_OPEN
,
385 D2D_GEOMETRY_STATE_CLOSED
,
386 D2D_GEOMETRY_STATE_FIGURE
,
389 struct d2d_bezier_vertex
391 D2D1_POINT_2F position
;
408 struct d2d_outline_vertex
410 D2D1_POINT_2F position
;
415 struct d2d_bezier_outline_vertex
417 D2D1_POINT_2F position
;
418 D2D1_POINT_2F p0
, p1
, p2
;
419 D2D1_POINT_2F prev
, next
;
424 ID2D1Geometry ID2D1Geometry_iface
;
427 ID2D1Factory
*factory
;
429 D2D_MATRIX_3X2_F transform
;
433 D2D1_POINT_2F
*vertices
;
436 struct d2d_face
*faces
;
440 struct d2d_bezier_vertex
*bezier_vertices
;
441 size_t bezier_vertex_count
;
446 struct d2d_outline_vertex
*vertices
;
447 size_t vertices_size
;
450 struct d2d_face
*faces
;
454 struct d2d_bezier_outline_vertex
*beziers
;
458 struct d2d_face
*bezier_faces
;
459 size_t bezier_faces_size
;
460 size_t bezier_face_count
;
467 ID2D1GeometrySink ID2D1GeometrySink_iface
;
469 struct d2d_figure
*figures
;
473 enum d2d_geometry_state state
;
474 D2D1_FILL_MODE fill_mode
;
475 UINT32 segment_count
;
485 ID2D1Geometry
*src_geometry
;
486 D2D_MATRIX_3X2_F transform
;
491 void d2d_path_geometry_init(struct d2d_geometry
*geometry
, ID2D1Factory
*factory
) DECLSPEC_HIDDEN
;
492 HRESULT
d2d_rectangle_geometry_init(struct d2d_geometry
*geometry
,
493 ID2D1Factory
*factory
, const D2D1_RECT_F
*rect
) DECLSPEC_HIDDEN
;
494 void d2d_transformed_geometry_init(struct d2d_geometry
*geometry
, ID2D1Factory
*factory
,
495 ID2D1Geometry
*src_geometry
, const D2D_MATRIX_3X2_F
*transform
) DECLSPEC_HIDDEN
;
496 struct d2d_geometry
*unsafe_impl_from_ID2D1Geometry(ID2D1Geometry
*iface
) DECLSPEC_HIDDEN
;
500 ID2D1Device ID2D1Device_iface
;
502 ID2D1Factory1
*factory
;
503 IDXGIDevice
*dxgi_device
;
506 void d2d_device_init(struct d2d_device
*device
, ID2D1Factory1
*factory
, IDXGIDevice
*dxgi_device
) DECLSPEC_HIDDEN
;
510 ID2D1Effect ID2D1Effect_iface
;
514 void d2d_effect_init(struct d2d_effect
*effect
) DECLSPEC_HIDDEN
;
516 static inline BOOL
d2d_array_reserve(void **elements
, size_t *capacity
, size_t count
, size_t size
)
518 size_t new_capacity
, max_capacity
;
521 if (count
<= *capacity
)
524 max_capacity
= ~(SIZE_T
)0 / size
;
525 if (count
> max_capacity
)
528 new_capacity
= max(4, *capacity
);
529 while (new_capacity
< count
&& new_capacity
<= max_capacity
/ 2)
531 if (new_capacity
< count
)
532 new_capacity
= max_capacity
;
534 if (!(new_elements
= heap_realloc(*elements
, new_capacity
* size
)))
537 *elements
= new_elements
;
538 *capacity
= new_capacity
;
542 static inline void d2d_matrix_multiply(D2D_MATRIX_3X2_F
*a
, const D2D_MATRIX_3X2_F
*b
)
544 D2D_MATRIX_3X2_F tmp
= *a
;
546 a
->_11
= tmp
._11
* b
->_11
+ tmp
._12
* b
->_21
;
547 a
->_12
= tmp
._11
* b
->_12
+ tmp
._12
* b
->_22
;
548 a
->_21
= tmp
._21
* b
->_11
+ tmp
._22
* b
->_21
;
549 a
->_22
= tmp
._21
* b
->_12
+ tmp
._22
* b
->_22
;
550 a
->_31
= tmp
._31
* b
->_11
+ tmp
._32
* b
->_21
+ b
->_31
;
551 a
->_32
= tmp
._31
* b
->_12
+ tmp
._32
* b
->_22
+ b
->_32
;
554 /* Dst must be different from src. */
555 static inline BOOL
d2d_matrix_invert(D2D_MATRIX_3X2_F
*dst
, const D2D_MATRIX_3X2_F
*src
)
557 float d
= src
->_11
* src
->_22
- src
->_21
* src
->_12
;
561 dst
->_11
= src
->_22
/ d
;
562 dst
->_21
= -src
->_21
/ d
;
563 dst
->_31
= (src
->_21
* src
->_32
- src
->_31
* src
->_22
) / d
;
564 dst
->_12
= -src
->_12
/ d
;
565 dst
->_22
= src
->_11
/ d
;
566 dst
->_32
= -(src
->_11
* src
->_32
- src
->_31
* src
->_12
) / d
;
571 static inline void d2d_point_set(D2D1_POINT_2F
*dst
, float x
, float y
)
577 static inline float d2d_point_dot(const D2D1_POINT_2F
*p0
, const D2D1_POINT_2F
*p1
)
579 return p0
->x
* p1
->x
+ p0
->y
* p1
->y
;
582 static inline void d2d_point_transform(D2D1_POINT_2F
*dst
, const D2D1_MATRIX_3X2_F
*matrix
, float x
, float y
)
584 dst
->x
= x
* matrix
->_11
+ y
* matrix
->_21
+ matrix
->_31
;
585 dst
->y
= x
* matrix
->_12
+ y
* matrix
->_22
+ matrix
->_32
;
588 static inline void d2d_rect_expand(D2D1_RECT_F
*dst
, const D2D1_POINT_2F
*point
)
590 if (point
->x
< dst
->left
)
591 dst
->left
= point
->x
;
592 if (point
->x
> dst
->right
)
593 dst
->right
= point
->x
;
594 if (point
->y
< dst
->top
)
596 if (point
->y
> dst
->bottom
)
597 dst
->bottom
= point
->y
;
600 static inline const char *debug_d2d_point_2f(const D2D1_POINT_2F
*point
)
604 return wine_dbg_sprintf("{%.8e, %.8e}", point
->x
, point
->y
);
607 static inline const char *debug_d2d_rect_f(const D2D1_RECT_F
*rect
)
609 if (!rect
) return "(null)";
610 return wine_dbg_sprintf("(%.8e,%.8e)-(%.8e,%.8e)", rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
613 #endif /* __WINE_D2D1_PRIVATE_H */