mstask: Implement ITask::DeleteTrigger().
[wine.git] / dlls / d2d1 / d2d1_private.h
blobdbfb83c249e27b3cb001d69524ac30b6df6deb21
1 /*
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"
25 #include <assert.h>
26 #include <limits.h>
27 #define COBJMACROS
28 #include "d2d1_1.h"
29 #ifdef D2D1_INIT_GUID
30 #include "initguid.h"
31 #endif
32 #include "dwrite_2.h"
34 #ifndef ARRAY_SIZE
35 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
36 #endif
38 enum d2d_brush_type
40 D2D_BRUSH_TYPE_SOLID,
41 D2D_BRUSH_TYPE_LINEAR,
42 D2D_BRUSH_TYPE_RADIAL,
43 D2D_BRUSH_TYPE_BITMAP,
44 D2D_BRUSH_TYPE_COUNT,
47 enum d2d_shape_type
49 D2D_SHAPE_TYPE_OUTLINE,
50 D2D_SHAPE_TYPE_BEZIER_OUTLINE,
51 D2D_SHAPE_TYPE_TRIANGLE,
52 D2D_SHAPE_TYPE_BEZIER,
53 D2D_SHAPE_TYPE_COUNT,
56 struct d2d_settings
58 unsigned int max_version_factory;
60 extern struct d2d_settings d2d_settings DECLSPEC_HIDDEN;
62 struct d2d_clip_stack
64 D2D1_RECT_F *stack;
65 size_t size;
66 size_t count;
69 struct d2d_error_state
71 HRESULT code;
72 D2D1_TAG tag1, tag2;
75 struct d2d_shape_resources
77 ID3D10InputLayout *il;
78 ID3D10VertexShader *vs;
81 struct d2d_brush_cb
83 enum d2d_brush_type type;
84 float opacity;
85 unsigned int pad[2];
86 union
88 struct
90 D2D1_COLOR_F colour;
91 } solid;
92 struct
94 D2D1_POINT_2F start;
95 D2D1_POINT_2F end;
96 unsigned int stop_count;
97 } linear;
98 struct
100 D2D1_POINT_2F centre;
101 D2D1_POINT_2F offset;
102 D2D1_POINT_2F ra;
103 D2D1_POINT_2F rb;
104 unsigned int stop_count;
105 float pad[3];
106 } radial;
107 struct
109 float _11, _21, _31, pad;
110 float _12, _22, _32;
111 BOOL ignore_alpha;
112 } bitmap;
113 } u;
116 struct d2d_ps_cb
118 BOOL outline;
119 BOOL pad[3];
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;
129 LONG refcount;
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;
139 ID3D10Buffer *ib;
140 unsigned int vb_stride;
141 ID3D10Buffer *vb;
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;
162 LONG refcount;
164 IDXGISurface *dxgi_surface;
165 ID2D1RenderTarget *dxgi_target;
166 ID3D10Texture2D *readback_texture;
167 IWICBitmap *bitmap;
169 unsigned int width;
170 unsigned int height;
171 unsigned int bpp;
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;
180 LONG refcount;
182 IDXGISurface1 *dxgi_surface;
183 ID2D1RenderTarget *dxgi_target;
185 RECT dst_rect;
186 HDC hdc;
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;
195 LONG refcount;
197 ID2D1RenderTarget *dxgi_target;
198 IDXGISwapChain *swapchain;
199 UINT sync_interval;
200 HWND hwnd;
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;
210 LONG refcount;
212 ID2D1RenderTarget *dxgi_target;
213 ID2D1Bitmap *bitmap;
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;
221 struct d2d_gradient
223 ID2D1GradientStopCollection ID2D1GradientStopCollection_iface;
224 LONG refcount;
226 ID2D1Factory *factory;
227 ID3D10ShaderResourceView *view;
228 D2D1_GRADIENT_STOP *stops;
229 UINT32 stop_count;
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;
236 struct d2d_brush
238 ID2D1Brush ID2D1Brush_iface;
239 LONG refcount;
241 ID2D1Factory *factory;
242 float opacity;
243 D2D1_MATRIX_3X2_F transform;
245 enum d2d_brush_type type;
246 union
248 struct
250 D2D1_COLOR_F color;
251 } solid;
252 struct
254 struct d2d_gradient *gradient;
255 D2D1_POINT_2F start;
256 D2D1_POINT_2F end;
257 } linear;
258 struct
260 struct d2d_gradient *gradient;
261 D2D1_POINT_2F centre;
262 D2D1_POINT_2F offset;
263 D2D1_POINT_2F radius;
264 } radial;
265 struct
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;
272 } bitmap;
273 } u;
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;
295 LONG refcount;
297 ID2D1Factory *factory;
298 D2D1_STROKE_STYLE_PROPERTIES desc;
299 float *dashes;
300 UINT32 dash_count;
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;
306 struct d2d_layer
308 ID2D1Layer ID2D1Layer_iface;
309 LONG refcount;
311 ID2D1Factory *factory;
312 D2D1_SIZE_F size;
315 HRESULT d2d_layer_create(ID2D1Factory *factory, const D2D1_SIZE_F *size, struct d2d_layer **layer) DECLSPEC_HIDDEN;
317 struct d2d_mesh
319 ID2D1Mesh ID2D1Mesh_iface;
320 LONG refcount;
322 ID2D1Factory *factory;
325 HRESULT d2d_mesh_create(ID2D1Factory *factory, struct d2d_mesh **mesh) DECLSPEC_HIDDEN;
327 struct d2d_bitmap
329 ID2D1Bitmap ID2D1Bitmap_iface;
330 LONG refcount;
332 ID2D1Factory *factory;
333 ID3D10ShaderResourceView *view;
334 D2D1_SIZE_U pixel_size;
335 D2D1_PIXEL_FORMAT format;
336 float dpi_x;
337 float dpi_y;
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;
351 LONG refcount;
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;
374 struct
376 float u, v, sign;
377 } texcoord;
380 struct d2d_face
382 UINT16 v[3];
385 struct d2d_vec4
387 float x, y, z, w;
390 struct d2d_outline_vertex
392 D2D1_POINT_2F position;
393 D2D1_POINT_2F prev;
394 D2D1_POINT_2F next;
397 struct d2d_bezier_outline_vertex
399 D2D1_POINT_2F position;
400 D2D1_POINT_2F p0, p1, p2;
401 D2D1_POINT_2F prev, next;
404 struct d2d_geometry
406 ID2D1Geometry ID2D1Geometry_iface;
407 LONG refcount;
409 ID2D1Factory *factory;
411 D2D_MATRIX_3X2_F transform;
413 struct
415 D2D1_POINT_2F *vertices;
416 size_t vertex_count;
418 struct d2d_face *faces;
419 size_t faces_size;
420 size_t face_count;
422 struct d2d_bezier_vertex *bezier_vertices;
423 size_t bezier_vertex_count;
424 } fill;
426 struct
428 struct d2d_outline_vertex *vertices;
429 size_t vertices_size;
430 size_t vertex_count;
432 struct d2d_face *faces;
433 size_t faces_size;
434 size_t face_count;
436 struct d2d_bezier_outline_vertex *beziers;
437 size_t beziers_size;
438 size_t bezier_count;
440 struct d2d_face *bezier_faces;
441 size_t bezier_faces_size;
442 size_t bezier_face_count;
443 } outline;
445 union
447 struct
449 ID2D1GeometrySink ID2D1GeometrySink_iface;
451 struct d2d_figure *figures;
452 size_t figures_size;
453 size_t figure_count;
455 enum d2d_geometry_state state;
456 D2D1_FILL_MODE fill_mode;
457 UINT32 segment_count;
459 D2D1_RECT_F bounds;
460 } path;
461 struct
463 D2D1_RECT_F rect;
464 } rectangle;
465 struct
467 ID2D1Geometry *src_geometry;
468 D2D_MATRIX_3X2_F transform;
469 } transformed;
470 } u;
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;
483 void *new_elements;
485 if (count <= *capacity)
486 return TRUE;
488 max_capacity = ~(SIZE_T)0 / size;
489 if (count > max_capacity)
490 return FALSE;
492 new_capacity = max(4, *capacity);
493 while (new_capacity < count && new_capacity <= max_capacity / 2)
494 new_capacity *= 2;
495 if (new_capacity < count)
496 new_capacity = max_capacity;
498 if (!(new_elements = heap_realloc(*elements, new_capacity * size)))
499 return FALSE;
501 *elements = new_elements;
502 *capacity = new_capacity;
503 return TRUE;
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;
523 if (d == 0.0f)
524 return FALSE;
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;
532 return TRUE;
535 static inline void d2d_point_set(D2D1_POINT_2F *dst, float x, float y)
537 dst->x = x;
538 dst->y = 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)
559 dst->top = point->y;
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 */