d2d1: Create shader resource views for gradient stop collections.
[wine.git] / dlls / d2d1 / d2d1_private.h
blobefb504adeb7dd499504e8081bbf2a2b5457602f3
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_BITMAP,
42 D2D_BRUSH_TYPE_COUNT,
45 enum d2d_shape_type
47 D2D_SHAPE_TYPE_OUTLINE,
48 D2D_SHAPE_TYPE_BEZIER_OUTLINE,
49 D2D_SHAPE_TYPE_TRIANGLE,
50 D2D_SHAPE_TYPE_BEZIER,
51 D2D_SHAPE_TYPE_COUNT,
54 struct d2d_clip_stack
56 D2D1_RECT_F *stack;
57 unsigned int size;
58 unsigned int count;
61 struct d2d_error_state
63 HRESULT code;
64 D2D1_TAG tag1, tag2;
67 struct d2d_shape_resources
69 ID3D10InputLayout *il;
70 ID3D10VertexShader *vs;
73 struct d2d_brush_cb
75 enum d2d_brush_type type;
76 float opacity;
77 unsigned int pad[2];
78 union
80 struct
82 D2D1_COLOR_F colour;
83 } solid;
84 struct
86 float _11, _21, _31, pad;
87 float _12, _22, _32;
88 BOOL ignore_alpha;
89 } bitmap;
90 } u;
93 struct d2d_ps_cb
95 BOOL outline;
96 BOOL pad[3];
97 struct d2d_brush_cb colour_brush;
98 struct d2d_brush_cb opacity_brush;
101 struct d2d_d3d_render_target
103 ID2D1RenderTarget ID2D1RenderTarget_iface;
104 ID2D1GdiInteropRenderTarget ID2D1GdiInteropRenderTarget_iface;
105 IDWriteTextRenderer IDWriteTextRenderer_iface;
106 LONG refcount;
108 IUnknown *outer_unknown;
110 ID2D1Factory *factory;
111 ID3D10Device *device;
112 ID3D10RenderTargetView *view;
113 ID3D10StateBlock *stateblock;
114 struct d2d_shape_resources shape_resources[D2D_SHAPE_TYPE_COUNT];
115 ID3D10PixelShader *ps;
116 ID3D10Buffer *ib;
117 unsigned int vb_stride;
118 ID3D10Buffer *vb;
119 ID3D10RasterizerState *rs;
120 ID3D10BlendState *bs;
122 struct d2d_error_state error;
123 D2D1_DRAWING_STATE_DESCRIPTION drawing_state;
124 IDWriteRenderingParams *text_rendering_params;
125 IDWriteRenderingParams *default_text_rendering_params;
127 D2D1_RENDER_TARGET_PROPERTIES desc;
128 D2D1_SIZE_U pixel_size;
129 struct d2d_clip_stack clip_stack;
132 HRESULT d2d_d3d_create_render_target(ID2D1Factory *factory, IDXGISurface *surface, IUnknown *outer_unknown,
133 const D2D1_RENDER_TARGET_PROPERTIES *desc, ID2D1RenderTarget **render_target) DECLSPEC_HIDDEN;
134 HRESULT d2d_d3d_render_target_create_rtv(ID2D1RenderTarget *render_target, IDXGISurface1 *surface) DECLSPEC_HIDDEN;
136 struct d2d_wic_render_target
138 ID2D1RenderTarget ID2D1RenderTarget_iface;
139 LONG refcount;
141 IDXGISurface *dxgi_surface;
142 ID2D1RenderTarget *dxgi_target;
143 ID3D10Texture2D *readback_texture;
144 IWICBitmap *bitmap;
146 unsigned int width;
147 unsigned int height;
148 unsigned int bpp;
151 HRESULT d2d_wic_render_target_init(struct d2d_wic_render_target *render_target, ID2D1Factory *factory,
152 ID3D10Device1 *device, IWICBitmap *bitmap, const D2D1_RENDER_TARGET_PROPERTIES *desc) DECLSPEC_HIDDEN;
154 struct d2d_dc_render_target
156 ID2D1DCRenderTarget ID2D1DCRenderTarget_iface;
157 LONG refcount;
159 IDXGISurface1 *dxgi_surface;
160 ID2D1RenderTarget *dxgi_target;
162 RECT dst_rect;
163 HDC hdc;
166 HRESULT d2d_dc_render_target_init(struct d2d_dc_render_target *render_target, ID2D1Factory *factory,
167 ID3D10Device1 *device, const D2D1_RENDER_TARGET_PROPERTIES *desc) DECLSPEC_HIDDEN;
169 struct d2d_hwnd_render_target
171 ID2D1HwndRenderTarget ID2D1HwndRenderTarget_iface;
172 LONG refcount;
174 ID2D1RenderTarget *dxgi_target;
175 IDXGISwapChain *swapchain;
176 UINT sync_interval;
177 HWND hwnd;
180 HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target, ID2D1Factory *factory,
181 ID3D10Device1 *device, const D2D1_RENDER_TARGET_PROPERTIES *desc,
182 const D2D1_HWND_RENDER_TARGET_PROPERTIES *hwnd_desc) DECLSPEC_HIDDEN;
184 struct d2d_bitmap_render_target
186 ID2D1BitmapRenderTarget ID2D1BitmapRenderTarget_iface;
187 LONG refcount;
189 ID2D1RenderTarget *dxgi_target;
190 ID2D1Bitmap *bitmap;
193 HRESULT d2d_bitmap_render_target_init(struct d2d_bitmap_render_target *render_target,
194 const struct d2d_d3d_render_target *parent_target, const D2D1_SIZE_F *size,
195 const D2D1_SIZE_U *pixel_size, const D2D1_PIXEL_FORMAT *format,
196 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options) DECLSPEC_HIDDEN;
198 struct d2d_gradient
200 ID2D1GradientStopCollection ID2D1GradientStopCollection_iface;
201 LONG refcount;
203 ID2D1Factory *factory;
204 ID3D10ShaderResourceView *view;
205 D2D1_GRADIENT_STOP *stops;
206 UINT32 stop_count;
209 HRESULT d2d_gradient_create(ID2D1Factory *factory, ID3D10Device *device, const D2D1_GRADIENT_STOP *stops,
210 UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode,
211 struct d2d_gradient **gradient) DECLSPEC_HIDDEN;
213 struct d2d_brush
215 ID2D1Brush ID2D1Brush_iface;
216 LONG refcount;
218 ID2D1Factory *factory;
219 float opacity;
220 D2D1_MATRIX_3X2_F transform;
222 enum d2d_brush_type type;
223 union
225 struct
227 D2D1_COLOR_F color;
228 } solid;
229 struct
231 struct d2d_bitmap *bitmap;
232 D2D1_EXTEND_MODE extend_mode_x;
233 D2D1_EXTEND_MODE extend_mode_y;
234 D2D1_BITMAP_INTERPOLATION_MODE interpolation_mode;
235 ID3D10SamplerState *sampler_state;
236 } bitmap;
237 struct
239 D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES desc;
240 ID2D1GradientStopCollection *gradient;
241 } linear;
242 } u;
245 HRESULT d2d_solid_color_brush_create(ID2D1Factory *factory, const D2D1_COLOR_F *color,
246 const D2D1_BRUSH_PROPERTIES *desc, struct d2d_brush **brush) DECLSPEC_HIDDEN;
247 HRESULT d2d_linear_gradient_brush_create(ID2D1Factory *factory, const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc,
248 const D2D1_BRUSH_PROPERTIES *brush_desc, ID2D1GradientStopCollection *gradient,
249 struct d2d_brush **brush) DECLSPEC_HIDDEN;
250 HRESULT d2d_bitmap_brush_create(ID2D1Factory *factory, ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc,
251 const D2D1_BRUSH_PROPERTIES *brush_desc, struct d2d_brush **brush) DECLSPEC_HIDDEN;
252 void d2d_brush_bind_resources(struct d2d_brush *brush, ID3D10Device *device, unsigned int brush_idx) DECLSPEC_HIDDEN;
253 HRESULT d2d_brush_get_ps_cb(struct d2d_brush *brush, struct d2d_brush *opacity_brush, BOOL outline,
254 struct d2d_d3d_render_target *render_target, ID3D10Buffer **ps_cb) DECLSPEC_HIDDEN;
255 struct d2d_brush *unsafe_impl_from_ID2D1Brush(ID2D1Brush *iface) DECLSPEC_HIDDEN;
257 struct d2d_stroke_style
259 ID2D1StrokeStyle ID2D1StrokeStyle_iface;
260 LONG refcount;
262 ID2D1Factory *factory;
263 D2D1_STROKE_STYLE_PROPERTIES desc;
264 float *dashes;
265 UINT32 dash_count;
268 HRESULT d2d_stroke_style_init(struct d2d_stroke_style *style, ID2D1Factory *factory,
269 const D2D1_STROKE_STYLE_PROPERTIES *desc, const float *dashes, UINT32 dash_count) DECLSPEC_HIDDEN;
271 struct d2d_layer
273 ID2D1Layer ID2D1Layer_iface;
274 LONG refcount;
276 ID2D1Factory *factory;
277 D2D1_SIZE_F size;
280 HRESULT d2d_layer_create(ID2D1Factory *factory, const D2D1_SIZE_F *size, struct d2d_layer **layer) DECLSPEC_HIDDEN;
282 struct d2d_mesh
284 ID2D1Mesh ID2D1Mesh_iface;
285 LONG refcount;
287 ID2D1Factory *factory;
290 HRESULT d2d_mesh_create(ID2D1Factory *factory, struct d2d_mesh **mesh) DECLSPEC_HIDDEN;
292 struct d2d_bitmap
294 ID2D1Bitmap ID2D1Bitmap_iface;
295 LONG refcount;
297 ID2D1Factory *factory;
298 ID3D10ShaderResourceView *view;
299 D2D1_SIZE_U pixel_size;
300 D2D1_PIXEL_FORMAT format;
301 float dpi_x;
302 float dpi_y;
305 HRESULT d2d_bitmap_create(ID2D1Factory *factory, ID3D10Device *device, D2D1_SIZE_U size, const void *src_data,
306 UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN;
307 HRESULT d2d_bitmap_create_shared(ID2D1RenderTarget *render_target, ID3D10Device *device, REFIID iid, void *data,
308 const D2D1_BITMAP_PROPERTIES *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN;
309 HRESULT d2d_bitmap_create_from_wic_bitmap(ID2D1Factory *factory, ID3D10Device *device, IWICBitmapSource *bitmap_source,
310 const D2D1_BITMAP_PROPERTIES *desc, struct d2d_bitmap **bitmap) DECLSPEC_HIDDEN;
311 struct d2d_bitmap *unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap *iface) DECLSPEC_HIDDEN;
313 struct d2d_state_block
315 ID2D1DrawingStateBlock ID2D1DrawingStateBlock_iface;
316 LONG refcount;
318 ID2D1Factory *factory;
319 D2D1_DRAWING_STATE_DESCRIPTION drawing_state;
320 IDWriteRenderingParams *text_rendering_params;
323 void d2d_state_block_init(struct d2d_state_block *state_block, ID2D1Factory *factory,
324 const D2D1_DRAWING_STATE_DESCRIPTION *desc, IDWriteRenderingParams *text_rendering_params) DECLSPEC_HIDDEN;
325 struct d2d_state_block *unsafe_impl_from_ID2D1DrawingStateBlock(ID2D1DrawingStateBlock *iface) DECLSPEC_HIDDEN;
327 enum d2d_geometry_state
329 D2D_GEOMETRY_STATE_INITIAL = 0,
330 D2D_GEOMETRY_STATE_ERROR,
331 D2D_GEOMETRY_STATE_OPEN,
332 D2D_GEOMETRY_STATE_CLOSED,
333 D2D_GEOMETRY_STATE_FIGURE,
336 struct d2d_bezier_vertex
338 D2D1_POINT_2F position;
339 struct
341 float u, v, sign;
342 } texcoord;
345 struct d2d_face
347 UINT16 v[3];
350 struct d2d_vec4
352 float x, y, z, w;
355 struct d2d_outline_vertex
357 D2D1_POINT_2F position;
358 D2D1_POINT_2F prev;
359 D2D1_POINT_2F next;
362 struct d2d_bezier_outline_vertex
364 D2D1_POINT_2F position;
365 D2D1_POINT_2F p0, p1, p2;
366 D2D1_POINT_2F prev, next;
369 struct d2d_geometry
371 ID2D1Geometry ID2D1Geometry_iface;
372 LONG refcount;
374 ID2D1Factory *factory;
376 D2D_MATRIX_3X2_F transform;
378 struct
380 D2D1_POINT_2F *vertices;
381 size_t vertex_count;
383 struct d2d_face *faces;
384 size_t faces_size;
385 size_t face_count;
387 struct d2d_bezier_vertex *bezier_vertices;
388 size_t bezier_vertex_count;
389 } fill;
391 struct
393 struct d2d_outline_vertex *vertices;
394 size_t vertices_size;
395 size_t vertex_count;
397 struct d2d_face *faces;
398 size_t faces_size;
399 size_t face_count;
401 struct d2d_bezier_outline_vertex *beziers;
402 size_t beziers_size;
403 size_t bezier_count;
405 struct d2d_face *bezier_faces;
406 size_t bezier_faces_size;
407 size_t bezier_face_count;
408 } outline;
410 union
412 struct
414 ID2D1GeometrySink ID2D1GeometrySink_iface;
416 struct d2d_figure *figures;
417 size_t figures_size;
418 size_t figure_count;
420 enum d2d_geometry_state state;
421 D2D1_FILL_MODE fill_mode;
422 UINT32 segment_count;
424 D2D1_RECT_F bounds;
425 } path;
426 struct
428 D2D1_RECT_F rect;
429 } rectangle;
430 struct
432 ID2D1Geometry *src_geometry;
433 D2D_MATRIX_3X2_F transform;
434 } transformed;
435 } u;
438 void d2d_path_geometry_init(struct d2d_geometry *geometry, ID2D1Factory *factory) DECLSPEC_HIDDEN;
439 HRESULT d2d_rectangle_geometry_init(struct d2d_geometry *geometry,
440 ID2D1Factory *factory, const D2D1_RECT_F *rect) DECLSPEC_HIDDEN;
441 void d2d_transformed_geometry_init(struct d2d_geometry *geometry, ID2D1Factory *factory,
442 ID2D1Geometry *src_geometry, const D2D_MATRIX_3X2_F *transform) DECLSPEC_HIDDEN;
443 struct d2d_geometry *unsafe_impl_from_ID2D1Geometry(ID2D1Geometry *iface) DECLSPEC_HIDDEN;
445 static inline void d2d_matrix_multiply(D2D_MATRIX_3X2_F *a, const D2D_MATRIX_3X2_F *b)
447 D2D_MATRIX_3X2_F tmp = *a;
449 a->_11 = tmp._11 * b->_11 + tmp._12 * b->_21;
450 a->_12 = tmp._11 * b->_12 + tmp._12 * b->_22;
451 a->_21 = tmp._21 * b->_11 + tmp._22 * b->_21;
452 a->_22 = tmp._21 * b->_12 + tmp._22 * b->_22;
453 a->_31 = tmp._31 * b->_11 + tmp._32 * b->_21 + b->_31;
454 a->_32 = tmp._31 * b->_12 + tmp._32 * b->_22 + b->_32;
457 /* Dst must be different from src. */
458 static inline BOOL d2d_matrix_invert(D2D_MATRIX_3X2_F *dst, const D2D_MATRIX_3X2_F *src)
460 float d = src->_11 * src->_22 - src->_21 * src->_12;
462 if (d == 0.0f)
463 return FALSE;
464 dst->_11 = src->_22 / d;
465 dst->_21 = -src->_21 / d;
466 dst->_31 = (src->_21 * src->_32 - src->_31 * src->_22) / d;
467 dst->_12 = -src->_12 / d;
468 dst->_22 = src->_11 / d;
469 dst->_32 = -(src->_11 * src->_32 - src->_31 * src->_12) / d;
471 return TRUE;
474 static inline void d2d_point_set(D2D1_POINT_2F *dst, float x, float y)
476 dst->x = x;
477 dst->y = y;
480 static inline void d2d_point_transform(D2D1_POINT_2F *dst, const D2D1_MATRIX_3X2_F *matrix, float x, float y)
482 dst->x = x * matrix->_11 + y * matrix->_21 + matrix->_31;
483 dst->y = x * matrix->_12 + y * matrix->_22 + matrix->_32;
486 static inline void d2d_rect_expand(D2D1_RECT_F *dst, const D2D1_POINT_2F *point)
488 if (point->x < dst->left)
489 dst->left = point->x;
490 if (point->x > dst->right)
491 dst->right = point->x;
492 if (point->y < dst->top)
493 dst->top = point->y;
494 if (point->y > dst->bottom)
495 dst->bottom = point->y;
498 static inline const char *debug_d2d_rect_f(const D2D1_RECT_F *rect)
500 if (!rect) return "(null)";
501 return wine_dbg_sprintf("(%.8e,%.8e)-(%.8e,%.8e)", rect->left, rect->top, rect->right, rect->bottom );
504 #endif /* __WINE_D2D1_PRIVATE_H */