mshtml: Turn several constants and variables into static constants.
[wine.git] / dlls / d2d1 / d2d1_private.h
blob5f451b22d99bb8fd59f3d35e3dfda787ec6abe9a
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_2.h"
29 #ifdef D2D1_INIT_GUID
30 #include "initguid.h"
31 #endif
32 #include "dwrite_2.h"
34 enum d2d_brush_type
36 D2D_BRUSH_TYPE_SOLID,
37 D2D_BRUSH_TYPE_LINEAR,
38 D2D_BRUSH_TYPE_RADIAL,
39 D2D_BRUSH_TYPE_BITMAP,
40 D2D_BRUSH_TYPE_COUNT,
43 enum d2d_shape_type
45 D2D_SHAPE_TYPE_OUTLINE,
46 D2D_SHAPE_TYPE_BEZIER_OUTLINE,
47 D2D_SHAPE_TYPE_TRIANGLE,
48 D2D_SHAPE_TYPE_BEZIER,
49 D2D_SHAPE_TYPE_COUNT,
52 struct d2d_settings
54 unsigned int max_version_factory;
56 extern struct d2d_settings d2d_settings DECLSPEC_HIDDEN;
58 struct d2d_clip_stack
60 D2D1_RECT_F *stack;
61 size_t size;
62 size_t count;
65 struct d2d_error_state
67 HRESULT code;
68 D2D1_TAG tag1, tag2;
71 struct d2d_shape_resources
73 ID3D10InputLayout *il;
74 ID3D10VertexShader *vs;
77 struct d2d_brush_cb
79 enum d2d_brush_type type;
80 float opacity;
81 unsigned int pad[2];
82 union
84 struct
86 D2D1_COLOR_F colour;
87 } solid;
88 struct
90 D2D1_POINT_2F start;
91 D2D1_POINT_2F end;
92 unsigned int stop_count;
93 } linear;
94 struct
96 D2D1_POINT_2F centre;
97 D2D1_POINT_2F offset;
98 D2D1_POINT_2F ra;
99 D2D1_POINT_2F rb;
100 unsigned int stop_count;
101 float pad[3];
102 } radial;
103 struct
105 float _11, _21, _31, pad;
106 float _12, _22, _32;
107 BOOL ignore_alpha;
108 } bitmap;
109 } u;
112 struct d2d_ps_cb
114 BOOL outline;
115 BOOL pad[3];
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;
131 LONG refcount;
133 IUnknown *outer_unknown;
134 const struct d2d_device_context_ops *ops;
136 ID2D1Factory *factory;
137 ID2D1Device *device;
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;
143 ID3D10Buffer *ib;
144 unsigned int vb_stride;
145 ID3D10Buffer *vb;
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;
171 LONG refcount;
173 IDXGISurface *dxgi_surface;
174 ID2D1RenderTarget *dxgi_target;
175 IUnknown *dxgi_inner;
176 ID3D10Texture2D *readback_texture;
177 IWICBitmap *bitmap;
179 unsigned int width;
180 unsigned int height;
181 unsigned int bpp;
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;
190 LONG refcount;
192 IDXGISurface1 *dxgi_surface;
193 D2D1_PIXEL_FORMAT pixel_format;
194 ID3D10Device1 *d3d_device;
195 ID2D1RenderTarget *dxgi_target;
196 IUnknown *dxgi_inner;
198 RECT dst_rect;
199 HDC hdc;
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;
208 LONG refcount;
210 ID2D1RenderTarget *dxgi_target;
211 IUnknown *dxgi_inner;
212 IDXGISwapChain *swapchain;
213 UINT sync_interval;
214 HWND hwnd;
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;
224 LONG refcount;
226 ID2D1RenderTarget *dxgi_target;
227 IUnknown *dxgi_inner;
228 ID2D1Bitmap *bitmap;
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;
236 struct d2d_gradient
238 ID2D1GradientStopCollection ID2D1GradientStopCollection_iface;
239 LONG refcount;
241 ID2D1Factory *factory;
242 ID3D10ShaderResourceView *view;
243 D2D1_GRADIENT_STOP *stops;
244 UINT32 stop_count;
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;
251 struct d2d_brush
253 ID2D1Brush ID2D1Brush_iface;
254 LONG refcount;
256 ID2D1Factory *factory;
257 float opacity;
258 D2D1_MATRIX_3X2_F transform;
260 enum d2d_brush_type type;
261 union
263 struct
265 D2D1_COLOR_F color;
266 } solid;
267 struct
269 struct d2d_gradient *gradient;
270 D2D1_POINT_2F start;
271 D2D1_POINT_2F end;
272 } linear;
273 struct
275 struct d2d_gradient *gradient;
276 D2D1_POINT_2F centre;
277 D2D1_POINT_2F offset;
278 D2D1_POINT_2F radius;
279 } radial;
280 struct
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;
287 } bitmap;
288 } u;
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;
310 LONG refcount;
312 ID2D1Factory *factory;
313 D2D1_STROKE_STYLE_PROPERTIES desc;
314 float *dashes;
315 UINT32 dash_count;
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;
321 struct d2d_layer
323 ID2D1Layer ID2D1Layer_iface;
324 LONG refcount;
326 ID2D1Factory *factory;
327 D2D1_SIZE_F size;
330 HRESULT d2d_layer_create(ID2D1Factory *factory, const D2D1_SIZE_F *size, struct d2d_layer **layer) DECLSPEC_HIDDEN;
332 struct d2d_mesh
334 ID2D1Mesh ID2D1Mesh_iface;
335 LONG refcount;
337 ID2D1Factory *factory;
340 HRESULT d2d_mesh_create(ID2D1Factory *factory, struct d2d_mesh **mesh) DECLSPEC_HIDDEN;
342 struct d2d_bitmap
344 ID2D1Bitmap1 ID2D1Bitmap1_iface;
345 LONG refcount;
347 ID2D1Factory *factory;
348 ID3D10ShaderResourceView *view;
349 ID3D10RenderTargetView *rtv;
350 IDXGISurface *surface;
351 D2D1_SIZE_U pixel_size;
352 D2D1_PIXEL_FORMAT format;
353 float dpi_x;
354 float dpi_y;
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;
369 LONG refcount;
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;
392 struct
394 float u, v, sign;
395 } texcoord;
398 struct d2d_face
400 UINT16 v[3];
403 struct d2d_vec4
405 float x, y, z, w;
408 struct d2d_outline_vertex
410 D2D1_POINT_2F position;
411 D2D1_POINT_2F prev;
412 D2D1_POINT_2F next;
415 struct d2d_bezier_outline_vertex
417 D2D1_POINT_2F position;
418 D2D1_POINT_2F p0, p1, p2;
419 D2D1_POINT_2F prev, next;
422 struct d2d_geometry
424 ID2D1Geometry ID2D1Geometry_iface;
425 LONG refcount;
427 ID2D1Factory *factory;
429 D2D_MATRIX_3X2_F transform;
431 struct
433 D2D1_POINT_2F *vertices;
434 size_t vertex_count;
436 struct d2d_face *faces;
437 size_t faces_size;
438 size_t face_count;
440 struct d2d_bezier_vertex *bezier_vertices;
441 size_t bezier_vertex_count;
442 } fill;
444 struct
446 struct d2d_outline_vertex *vertices;
447 size_t vertices_size;
448 size_t vertex_count;
450 struct d2d_face *faces;
451 size_t faces_size;
452 size_t face_count;
454 struct d2d_bezier_outline_vertex *beziers;
455 size_t beziers_size;
456 size_t bezier_count;
458 struct d2d_face *bezier_faces;
459 size_t bezier_faces_size;
460 size_t bezier_face_count;
461 } outline;
463 union
465 struct
467 ID2D1GeometrySink ID2D1GeometrySink_iface;
469 struct d2d_figure *figures;
470 size_t figures_size;
471 size_t figure_count;
473 enum d2d_geometry_state state;
474 D2D1_FILL_MODE fill_mode;
475 UINT32 segment_count;
477 D2D1_RECT_F bounds;
478 } path;
479 struct
481 D2D1_RECT_F rect;
482 } rectangle;
483 struct
485 ID2D1Geometry *src_geometry;
486 D2D_MATRIX_3X2_F transform;
487 } transformed;
488 } u;
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;
498 struct d2d_device
500 ID2D1Device ID2D1Device_iface;
501 LONG refcount;
502 ID2D1Factory1 *factory;
503 IDXGIDevice *dxgi_device;
506 void d2d_device_init(struct d2d_device *device, ID2D1Factory1 *factory, IDXGIDevice *dxgi_device) DECLSPEC_HIDDEN;
508 struct d2d_effect
510 ID2D1Effect ID2D1Effect_iface;
511 LONG refcount;
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;
519 void *new_elements;
521 if (count <= *capacity)
522 return TRUE;
524 max_capacity = ~(SIZE_T)0 / size;
525 if (count > max_capacity)
526 return FALSE;
528 new_capacity = max(4, *capacity);
529 while (new_capacity < count && new_capacity <= max_capacity / 2)
530 new_capacity *= 2;
531 if (new_capacity < count)
532 new_capacity = max_capacity;
534 if (!(new_elements = heap_realloc(*elements, new_capacity * size)))
535 return FALSE;
537 *elements = new_elements;
538 *capacity = new_capacity;
539 return TRUE;
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;
559 if (d == 0.0f)
560 return FALSE;
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;
568 return TRUE;
571 static inline void d2d_point_set(D2D1_POINT_2F *dst, float x, float y)
573 dst->x = x;
574 dst->y = 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)
595 dst->top = point->y;
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)
602 if (!point)
603 return "(null)";
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 */