d2d1: Implement radial gradient brushes.
[wine.git] / dlls / d2d1 / d2d1_private.h
blob98298f892adec557a42d49aad52a6ce6ca05391e
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"
24 #include <assert.h>
25 #include <limits.h>
26 #define COBJMACROS
27 #include "d2d1.h"
28 #ifdef D2D1_INIT_GUID
29 #include "initguid.h"
30 #endif
31 #include "dwrite_2.h"
33 #ifndef ARRAY_SIZE
34 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
35 #endif
37 enum d2d_brush_type
39 D2D_BRUSH_TYPE_SOLID,
40 D2D_BRUSH_TYPE_LINEAR,
41 D2D_BRUSH_TYPE_RADIAL,
42 D2D_BRUSH_TYPE_BITMAP,
43 D2D_BRUSH_TYPE_COUNT,
46 enum d2d_shape_type
48 D2D_SHAPE_TYPE_OUTLINE,
49 D2D_SHAPE_TYPE_BEZIER_OUTLINE,
50 D2D_SHAPE_TYPE_TRIANGLE,
51 D2D_SHAPE_TYPE_BEZIER,
52 D2D_SHAPE_TYPE_COUNT,
55 struct d2d_clip_stack
57 D2D1_RECT_F *stack;
58 unsigned int size;
59 unsigned int count;
62 struct d2d_error_state
64 HRESULT code;
65 D2D1_TAG tag1, tag2;
68 struct d2d_shape_resources
70 ID3D10InputLayout *il;
71 ID3D10VertexShader *vs;
74 struct d2d_brush_cb
76 enum d2d_brush_type type;
77 float opacity;
78 unsigned int pad[2];
79 union
81 struct
83 D2D1_COLOR_F colour;
84 } solid;
85 struct
87 D2D1_POINT_2F start;
88 D2D1_POINT_2F end;
89 unsigned int stop_count;
90 } linear;
91 struct
93 D2D1_POINT_2F centre;
94 D2D1_POINT_2F offset;
95 D2D1_POINT_2F ra;
96 D2D1_POINT_2F rb;
97 unsigned int stop_count;
98 float pad[3];
99 } radial;
100 struct
102 float _11, _21, _31, pad;
103 float _12, _22, _32;
104 BOOL ignore_alpha;
105 } bitmap;
106 } u;
109 struct d2d_ps_cb
111 BOOL outline;
112 BOOL pad[3];
113 struct d2d_brush_cb colour_brush;
114 struct d2d_brush_cb opacity_brush;
117 struct d2d_d3d_render_target
119 ID2D1RenderTarget ID2D1RenderTarget_iface;
120 ID2D1GdiInteropRenderTarget ID2D1GdiInteropRenderTarget_iface;
121 IDWriteTextRenderer IDWriteTextRenderer_iface;
122 LONG refcount;
124 IUnknown *outer_unknown;
126 ID2D1Factory *factory;
127 ID3D10Device *device;
128 ID3D10RenderTargetView *view;
129 ID3D10StateBlock *stateblock;
130 struct d2d_shape_resources shape_resources[D2D_SHAPE_TYPE_COUNT];
131 ID3D10PixelShader *ps;
132 ID3D10Buffer *ib;
133 unsigned int vb_stride;
134 ID3D10Buffer *vb;
135 ID3D10RasterizerState *rs;
136 ID3D10BlendState *bs;
138 struct d2d_error_state error;
139 D2D1_DRAWING_STATE_DESCRIPTION drawing_state;
140 IDWriteRenderingParams *text_rendering_params;
141 IDWriteRenderingParams *default_text_rendering_params;
143 D2D1_RENDER_TARGET_PROPERTIES desc;
144 D2D1_SIZE_U pixel_size;
145 struct d2d_clip_stack clip_stack;
148 HRESULT d2d_d3d_create_render_target(ID2D1Factory *factory, IDXGISurface *surface, IUnknown *outer_unknown,
149 const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target) DECLSPEC_HIDDEN;
150 HRESULT d2d_d3d_render_target_create_rtv(ID2D1RenderTarget *render_target, IDXGISurface1 *surface) DECLSPEC_HIDDEN;
152 struct d2d_wic_render_target
154 ID2D1RenderTarget ID2D1RenderTarget_iface;
155 LONG refcount;
157 IDXGISurface *dxgi_surface;
158 ID2D1RenderTarget *dxgi_target;
159 ID3D10Texture2D *readback_texture;
160 IWICBitmap *bitmap;
162 unsigned int width;
163 unsigned int height;
164 unsigned int bpp;
167 HRESULT d2d_wic_render_target_init(struct d2d_wic_render_target *render_target, ID2D1Factory *factory,
168 ID3D10Device1 *device, IWICBitmap *bitmap, const D2D1_RENDER_TARGET_PROPERTIES *desc) DECLSPEC_HIDDEN;
170 struct d2d_dc_render_target
172 ID2D1DCRenderTarget ID2D1DCRenderTarget_iface;
173 LONG refcount;
175 IDXGISurface1 *dxgi_surface;
176 ID2D1RenderTarget *dxgi_target;
178 RECT dst_rect;
179 HDC hdc;
182 HRESULT d2d_dc_render_target_init(struct d2d_dc_render_target *render_target, ID2D1Factory *factory,
183 ID3D10Device1 *device, const D2D1_RENDER_TARGET_PROPERTIES *desc) DECLSPEC_HIDDEN;
185 struct d2d_hwnd_render_target
187 ID2D1HwndRenderTarget ID2D1HwndRenderTarget_iface;
188 LONG refcount;
190 ID2D1RenderTarget *dxgi_target;
191 IDXGISwapChain *swapchain;
192 UINT sync_interval;
193 HWND hwnd;
196 HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target, ID2D1Factory *factory,
197 ID3D10Device1 *device, const D2D1_RENDER_TARGET_PROPERTIES *desc,
198 const D2D1_HWND_RENDER_TARGET_PROPERTIES *hwnd_desc) DECLSPEC_HIDDEN;
200 struct d2d_bitmap_render_target
202 ID2D1BitmapRenderTarget ID2D1BitmapRenderTarget_iface;
203 LONG refcount;
205 ID2D1RenderTarget *dxgi_target;
206 ID2D1Bitmap *bitmap;
209 HRESULT d2d_bitmap_render_target_init(struct d2d_bitmap_render_target *render_target,
210 const struct d2d_d3d_render_target *parent_target, const D2D1_SIZE_F *size,
211 const D2D1_SIZE_U *pixel_size, const D2D1_PIXEL_FORMAT *format,
212 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options) DECLSPEC_HIDDEN;
214 struct d2d_gradient
216 ID2D1GradientStopCollection ID2D1GradientStopCollection_iface;
217 LONG refcount;
219 ID2D1Factory *factory;
220 ID3D10ShaderResourceView *view;
221 D2D1_GRADIENT_STOP *stops;
222 UINT32 stop_count;
225 HRESULT d2d_gradient_create(ID2D1Factory *factory, ID3D10Device *device, const D2D1_GRADIENT_STOP *stops,
226 UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode,
227 struct d2d_gradient **gradient) DECLSPEC_HIDDEN;
229 struct d2d_brush
231 ID2D1Brush ID2D1Brush_iface;
232 LONG refcount;
234 ID2D1Factory *factory;
235 float opacity;
236 D2D1_MATRIX_3X2_F transform;
238 enum d2d_brush_type type;
239 union
241 struct
243 D2D1_COLOR_F color;
244 } solid;
245 struct
247 struct d2d_gradient *gradient;
248 D2D1_POINT_2F start;
249 D2D1_POINT_2F end;
250 } linear;
251 struct
253 struct d2d_gradient *gradient;
254 D2D1_POINT_2F centre;
255 D2D1_POINT_2F offset;
256 D2D1_POINT_2F radius;
257 } radial;
258 struct
260 struct d2d_bitmap *bitmap;
261 D2D1_EXTEND_MODE extend_mode_x;
262 D2D1_EXTEND_MODE extend_mode_y;
263 D2D1_BITMAP_INTERPOLATION_MODE interpolation_mode;
264 ID3D10SamplerState *sampler_state;
265 } bitmap;
266 } u;
269 HRESULT d2d_solid_color_brush_create(ID2D1Factory *factory, const D2D1_COLOR_F *color,
270 const D2D1_BRUSH_PROPERTIES *desc, struct d2d_brush **brush) DECLSPEC_HIDDEN;
271 HRESULT d2d_linear_gradient_brush_create(ID2D1Factory *factory,
272 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
273 ID2D1GradientStopCollection *gradient, struct d2d_brush **brush) DECLSPEC_HIDDEN;
274 HRESULT d2d_radial_gradient_brush_create(ID2D1Factory *factory,
275 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES *gradient_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
276 ID2D1GradientStopCollection *gradient, struct d2d_brush **brush) DECLSPEC_HIDDEN;
277 HRESULT d2d_bitmap_brush_create(ID2D1Factory *factory, ID2D1Bitmap *bitmap,
278 const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
279 struct d2d_brush **brush) DECLSPEC_HIDDEN;
280 void d2d_brush_bind_resources(struct d2d_brush *brush, ID3D10Device *device, unsigned int brush_idx) DECLSPEC_HIDDEN;
281 HRESULT d2d_brush_get_ps_cb(struct d2d_brush *brush, struct d2d_brush *opacity_brush, BOOL outline,
282 struct d2d_d3d_render_target *render_target, ID3D10Buffer **ps_cb) DECLSPEC_HIDDEN;
283 struct d2d_brush *unsafe_impl_from_ID2D1Brush(ID2D1Brush *iface) DECLSPEC_HIDDEN;
285 struct d2d_stroke_style
287 ID2D1StrokeStyle ID2D1StrokeStyle_iface;
288 LONG refcount;
290 ID2D1Factory *factory;
291 D2D1_STROKE_STYLE_PROPERTIES desc;
292 float *dashes;
293 UINT32 dash_count;
296 HRESULT d2d_stroke_style_init(struct d2d_stroke_style *style, ID2D1Factory *factory,
297 const D2D1_STROKE_STYLE_PROPERTIES *desc, const float *dashes, UINT32 dash_count) DECLSPEC_HIDDEN;
299 struct d2d_layer
301 ID2D1Layer ID2D1Layer_iface;
302 LONG refcount;
304 ID2D1Factory *factory;
305 D2D1_SIZE_F size;
308 HRESULT d2d_layer_create(ID2D1Factory *factory, const D2D1_SIZE_F *size, struct d2d_layer **layer) DECLSPEC_HIDDEN;
310 struct d2d_mesh
312 ID2D1Mesh ID2D1Mesh_iface;
313 LONG refcount;
315 ID2D1Factory *factory;
318 HRESULT d2d_mesh_create(ID2D1Factory *factory, struct d2d_mesh **mesh) DECLSPEC_HIDDEN;
320 struct d2d_bitmap
322 ID2D1Bitmap ID2D1Bitmap_iface;
323 LONG refcount;
325 ID2D1Factory *factory;
326 ID3D10ShaderResourceView *view;
327 D2D1_SIZE_U pixel_size;
328 D2D1_PIXEL_FORMAT format;
329 float dpi_x;
330 float dpi_y;
333 HRESULT d2d_bitmap_create(ID2D1Factory *factory, ID3D10Device *device, D2D1_SIZE_U size, const void *src_data,
334 UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN;
335 HRESULT d2d_bitmap_create_shared(ID2D1RenderTarget *render_target, ID3D10Device *device, REFIID iid, void *data,
336 const D2D1_BITMAP_PROPERTIES *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN;
337 HRESULT d2d_bitmap_create_from_wic_bitmap(ID2D1Factory *factory, ID3D10Device *device, IWICBitmapSource *bitmap_source,
338 const D2D1_BITMAP_PROPERTIES *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN;
339 struct d2d_bitmap *unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap *iface) DECLSPEC_HIDDEN;
341 struct d2d_state_block
343 ID2D1DrawingStateBlock ID2D1DrawingStateBlock_iface;
344 LONG refcount;
346 ID2D1Factory *factory;
347 D2D1_DRAWING_STATE_DESCRIPTION drawing_state;
348 IDWriteRenderingParams *text_rendering_params;
351 void d2d_state_block_init(struct d2d_state_block *state_block, ID2D1Factory *factory,
352 const D2D1_DRAWING_STATE_DESCRIPTION *desc, IDWriteRenderingParams *text_rendering_params) DECLSPEC_HIDDEN;
353 struct d2d_state_block *unsafe_impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStateBlock *iface) DECLSPEC_HIDDEN;
355 enum d2d_geometry_state
357 D2D_GEOMETRY_STATE_INITIAL = 0,
358 D2D_GEOMETRY_STATE_ERROR,
359 D2D_GEOMETRY_STATE_OPEN,
360 D2D_GEOMETRY_STATE_CLOSED,
361 D2D_GEOMETRY_STATE_FIGURE,
364 struct d2d_bezier_vertex
366 D2D1_POINT_2F position;
367 struct
369 float u, v, sign;
370 } texcoord;
373 struct d2d_face
375 UINT16 v[3];
378 struct d2d_vec4
380 float x, y, z, w;
383 struct d2d_outline_vertex
385 D2D1_POINT_2F position;
386 D2D1_POINT_2F prev;
387 D2D1_POINT_2F next;
390 struct d2d_bezier_outline_vertex
392 D2D1_POINT_2F position;
393 D2D1_POINT_2F p0, p1, p2;
394 D2D1_POINT_2F prev, next;
397 struct d2d_geometry
399 ID2D1Geometry ID2D1Geometry_iface;
400 LONG refcount;
402 ID2D1Factory *factory;
404 D2D_MATRIX_3X2_F transform;
406 struct
408 D2D1_POINT_2F *vertices;
409 size_t vertex_count;
411 struct d2d_face *faces;
412 size_t faces_size;
413 size_t face_count;
415 struct d2d_bezier_vertex *bezier_vertices;
416 size_t bezier_vertex_count;
417 } fill;
419 struct
421 struct d2d_outline_vertex *vertices;
422 size_t vertices_size;
423 size_t vertex_count;
425 struct d2d_face *faces;
426 size_t faces_size;
427 size_t face_count;
429 struct d2d_bezier_outline_vertex *beziers;
430 size_t beziers_size;
431 size_t bezier_count;
433 struct d2d_face *bezier_faces;
434 size_t bezier_faces_size;
435 size_t bezier_face_count;
436 } outline;
438 union
440 struct
442 ID2D1GeometrySink ID2D1GeometrySink_iface;
444 struct d2d_figure *figures;
445 size_t figures_size;
446 size_t figure_count;
448 enum d2d_geometry_state state;
449 D2D1_FILL_MODE fill_mode;
450 UINT32 segment_count;
452 D2D1_RECT_F bounds;
453 } path;
454 struct
456 D2D1_RECT_F rect;
457 } rectangle;
458 struct
460 ID2D1Geometry *src_geometry;
461 D2D_MATRIX_3X2_F transform;
462 } transformed;
463 } u;
466 void d2d_path_geometry_init(struct d2d_geometry *geometry, ID2D1Factory *factory) DECLSPEC_HIDDEN;
467 HRESULT d2d_rectangle_geometry_init(struct d2d_geometry *geometry,
468 ID2D1Factory *factory, const D2D1_RECT_F *rect) DECLSPEC_HIDDEN;
469 void d2d_transformed_geometry_init(struct d2d_geometry *geometry, ID2D1Factory *factory,
470 ID2D1Geometry *src_geometry, const D2D_MATRIX_3X2_F *transform) DECLSPEC_HIDDEN;
471 struct d2d_geometry *unsafe_impl_from_ID2D1Geometry(ID2D1Geometry *iface) DECLSPEC_HIDDEN;
473 static inline void d2d_matrix_multiply(D2D_MATRIX_3X2_F *a, const D2D_MATRIX_3X2_F *b)
475 D2D_MATRIX_3X2_F tmp = *a;
477 a->_11 = tmp._11 * b->_11 + tmp._12 * b->_21;
478 a->_12 = tmp._11 * b->_12 + tmp._12 * b->_22;
479 a->_21 = tmp._21 * b->_11 + tmp._22 * b->_21;
480 a->_22 = tmp._21 * b->_12 + tmp._22 * b->_22;
481 a->_31 = tmp._31 * b->_11 + tmp._32 * b->_21 + b->_31;
482 a->_32 = tmp._31 * b->_12 + tmp._32 * b->_22 + b->_32;
485 /* Dst must be different from src. */
486 static inline BOOL d2d_matrix_invert(D2D_MATRIX_3X2_F *dst, const D2D_MATRIX_3X2_F *src)
488 float d = src->_11 * src->_22 - src->_21 * src->_12;
490 if (d == 0.0f)
491 return FALSE;
492 dst->_11 = src->_22 / d;
493 dst->_21 = -src->_21 / d;
494 dst->_31 = (src->_21 * src->_32 - src->_31 * src->_22) / d;
495 dst->_12 = -src->_12 / d;
496 dst->_22 = src->_11 / d;
497 dst->_32 = -(src->_11 * src->_32 - src->_31 * src->_12) / d;
499 return TRUE;
502 static inline void d2d_point_set(D2D1_POINT_2F *dst, float x, float y)
504 dst->x = x;
505 dst->y = y;
508 static inline float d2d_point_dot(const D2D1_POINT_2F *p0, const D2D1_POINT_2F *p1)
510 return p0->x * p1->x + p0->y * p1->y;
513 static inline void d2d_point_transform(D2D1_POINT_2F *dst, const D2D1_MATRIX_3X2_F *matrix, float x, float y)
515 dst->x = x * matrix->_11 + y * matrix->_21 + matrix->_31;
516 dst->y = x * matrix->_12 + y * matrix->_22 + matrix->_32;
519 static inline void d2d_rect_expand(D2D1_RECT_F *dst, const D2D1_POINT_2F *point)
521 if (point->x < dst->left)
522 dst->left = point->x;
523 if (point->x > dst->right)
524 dst->right = point->x;
525 if (point->y < dst->top)
526 dst->top = point->y;
527 if (point->y > dst->bottom)
528 dst->bottom = point->y;
531 static inline const char *debug_d2d_rect_f(const D2D1_RECT_F *rect)
533 if (!rect) return "(null)";
534 return wine_dbg_sprintf("(%.8e,%.8e)-(%.8e,%.8e)", rect->left, rect->top, rect->right, rect->bottom );
537 #endif /* __WINE_D2D1_PRIVATE_H */