2 * Copyright 2014 Henri Verbeet for CodeWeavers
3 * Copyright 2016 Nikolay Sivov for CodeWeavers
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "wine/port.h"
23 #include "d2d1_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d2d
);
27 static inline struct d2d_bitmap_render_target
*impl_from_ID2D1BitmapRenderTarget(ID2D1BitmapRenderTarget
*iface
)
29 return CONTAINING_RECORD(iface
, struct d2d_bitmap_render_target
, ID2D1BitmapRenderTarget_iface
);
32 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_QueryInterface(ID2D1BitmapRenderTarget
*iface
,
33 REFIID iid
, void **out
)
35 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
37 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
39 if (IsEqualGUID(iid
, &IID_ID2D1BitmapRenderTarget
)
40 || IsEqualGUID(iid
, &IID_ID2D1RenderTarget
)
41 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
42 || IsEqualGUID(iid
, &IID_IUnknown
))
44 ID2D1BitmapRenderTarget_AddRef(iface
);
49 return IUnknown_QueryInterface(render_target
->dxgi_inner
, iid
, out
);
52 static ULONG STDMETHODCALLTYPE
d2d_bitmap_render_target_AddRef(ID2D1BitmapRenderTarget
*iface
)
54 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
55 ULONG refcount
= InterlockedIncrement(&render_target
->refcount
);
57 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
62 static ULONG STDMETHODCALLTYPE
d2d_bitmap_render_target_Release(ID2D1BitmapRenderTarget
*iface
)
64 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
65 ULONG refcount
= InterlockedDecrement(&render_target
->refcount
);
67 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
71 IUnknown_Release(render_target
->dxgi_inner
);
72 if (render_target
->bitmap
)
73 ID2D1Bitmap_Release(render_target
->bitmap
);
74 heap_free(render_target
);
80 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_GetFactory(ID2D1BitmapRenderTarget
*iface
,
81 ID2D1Factory
**factory
)
83 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
85 TRACE("iface %p, factory %p.\n", iface
, factory
);
87 ID2D1RenderTarget_GetFactory(render_target
->dxgi_target
, factory
);
90 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_CreateBitmap(ID2D1BitmapRenderTarget
*iface
,
91 D2D1_SIZE_U size
, const void *src_data
, UINT32 pitch
, const D2D1_BITMAP_PROPERTIES
*desc
, ID2D1Bitmap
**bitmap
)
93 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
95 TRACE("iface %p, size {%u, %u}, src_data %p, pitch %u, desc %p, bitmap %p.\n",
96 iface
, size
.width
, size
.height
, src_data
, pitch
, desc
, bitmap
);
98 return ID2D1RenderTarget_CreateBitmap(render_target
->dxgi_target
, size
, src_data
, pitch
, desc
, bitmap
);
101 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_CreateBitmapFromWicBitmap(ID2D1BitmapRenderTarget
*iface
,
102 IWICBitmapSource
*bitmap_source
, const D2D1_BITMAP_PROPERTIES
*desc
, ID2D1Bitmap
**bitmap
)
104 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
106 TRACE("iface %p, bitmap_source %p, desc %p, bitmap %p.\n",
107 iface
, bitmap_source
, desc
, bitmap
);
109 return ID2D1RenderTarget_CreateBitmapFromWicBitmap(render_target
->dxgi_target
, bitmap_source
, desc
, bitmap
);
112 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_CreateSharedBitmap(ID2D1BitmapRenderTarget
*iface
,
113 REFIID iid
, void *data
, const D2D1_BITMAP_PROPERTIES
*desc
, ID2D1Bitmap
**bitmap
)
115 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
117 TRACE("iface %p, iid %s, data %p, desc %p, bitmap %p.\n",
118 iface
, debugstr_guid(iid
), data
, desc
, bitmap
);
120 return ID2D1RenderTarget_CreateSharedBitmap(render_target
->dxgi_target
, iid
, data
, desc
, bitmap
);
123 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_CreateBitmapBrush(ID2D1BitmapRenderTarget
*iface
,
124 ID2D1Bitmap
*bitmap
, const D2D1_BITMAP_BRUSH_PROPERTIES
*bitmap_brush_desc
,
125 const D2D1_BRUSH_PROPERTIES
*brush_desc
, ID2D1BitmapBrush
**brush
)
127 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
129 TRACE("iface %p, bitmap %p, bitmap_brush_desc %p, brush_desc %p, brush %p.\n",
130 iface
, bitmap
, bitmap_brush_desc
, brush_desc
, brush
);
132 return ID2D1RenderTarget_CreateBitmapBrush(render_target
->dxgi_target
,
133 bitmap
, bitmap_brush_desc
, brush_desc
, brush
);
136 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_CreateSolidColorBrush(ID2D1BitmapRenderTarget
*iface
,
137 const D2D1_COLOR_F
*color
, const D2D1_BRUSH_PROPERTIES
*desc
, ID2D1SolidColorBrush
**brush
)
139 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
141 TRACE("iface %p, color %p, desc %p, brush %p.\n", iface
, color
, desc
, brush
);
143 return ID2D1RenderTarget_CreateSolidColorBrush(render_target
->dxgi_target
, color
, desc
, brush
);
146 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_CreateGradientStopCollection(ID2D1BitmapRenderTarget
*iface
,
147 const D2D1_GRADIENT_STOP
*stops
, UINT32 stop_count
, D2D1_GAMMA gamma
, D2D1_EXTEND_MODE extend_mode
,
148 ID2D1GradientStopCollection
**gradient
)
150 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
152 TRACE("iface %p, stops %p, stop_count %u, gamma %#x, extend_mode %#x, gradient %p.\n",
153 iface
, stops
, stop_count
, gamma
, extend_mode
, gradient
);
155 return ID2D1RenderTarget_CreateGradientStopCollection(render_target
->dxgi_target
,
156 stops
, stop_count
, gamma
, extend_mode
, gradient
);
159 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_CreateLinearGradientBrush(ID2D1BitmapRenderTarget
*iface
,
160 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES
*gradient_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
161 ID2D1GradientStopCollection
*gradient
, ID2D1LinearGradientBrush
**brush
)
163 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
165 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
166 iface
, gradient_brush_desc
, brush_desc
, gradient
, brush
);
168 return ID2D1RenderTarget_CreateLinearGradientBrush(render_target
->dxgi_target
,
169 gradient_brush_desc
, brush_desc
, gradient
, brush
);
172 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_CreateRadialGradientBrush(ID2D1BitmapRenderTarget
*iface
,
173 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES
*gradient_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
174 ID2D1GradientStopCollection
*gradient
, ID2D1RadialGradientBrush
**brush
)
176 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
178 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
179 iface
, gradient_brush_desc
, brush_desc
, gradient
, brush
);
181 return ID2D1RenderTarget_CreateRadialGradientBrush(render_target
->dxgi_target
,
182 gradient_brush_desc
, brush_desc
, gradient
, brush
);
185 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_CreateCompatibleRenderTarget(ID2D1BitmapRenderTarget
*iface
,
186 const D2D1_SIZE_F
*size
, const D2D1_SIZE_U
*pixel_size
, const D2D1_PIXEL_FORMAT
*format
,
187 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options
, ID2D1BitmapRenderTarget
**render_target
)
189 struct d2d_bitmap_render_target
*rt
= impl_from_ID2D1BitmapRenderTarget(iface
);
191 TRACE("iface %p, size %p, pixel_size %p, format %p, options %#x, render_target %p,\n",
192 iface
, size
, pixel_size
, format
, options
, render_target
);
194 return ID2D1RenderTarget_CreateCompatibleRenderTarget(rt
->dxgi_target
,
195 size
, pixel_size
, format
, options
, render_target
);
198 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_CreateLayer(ID2D1BitmapRenderTarget
*iface
,
199 const D2D1_SIZE_F
*size
, ID2D1Layer
**layer
)
201 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
203 TRACE("iface %p, size %p, layer %p.\n", iface
, size
, layer
);
205 return ID2D1RenderTarget_CreateLayer(render_target
->dxgi_target
, size
, layer
);
208 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_CreateMesh(ID2D1BitmapRenderTarget
*iface
, ID2D1Mesh
**mesh
)
210 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
212 TRACE("iface %p, mesh %p.\n", iface
, mesh
);
214 return ID2D1RenderTarget_CreateMesh(render_target
->dxgi_target
, mesh
);
217 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_DrawLine(ID2D1BitmapRenderTarget
*iface
,
218 D2D1_POINT_2F p0
, D2D1_POINT_2F p1
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
220 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
222 TRACE("iface %p, p0 %s, p1 %s, brush %p, stroke_width %.8e, stroke_style %p.\n",
223 iface
, debug_d2d_point_2f(&p0
), debug_d2d_point_2f(&p1
), brush
, stroke_width
, stroke_style
);
225 ID2D1RenderTarget_DrawLine(render_target
->dxgi_target
, p0
, p1
, brush
, stroke_width
, stroke_style
);
228 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_DrawRectangle(ID2D1BitmapRenderTarget
*iface
,
229 const D2D1_RECT_F
*rect
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
231 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
233 TRACE("iface %p, rect %s, brush %p, stroke_width %.8e, stroke_style %p.\n",
234 iface
, debug_d2d_rect_f(rect
), brush
, stroke_width
, stroke_style
);
236 ID2D1RenderTarget_DrawRectangle(render_target
->dxgi_target
, rect
, brush
, stroke_width
, stroke_style
);
239 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_FillRectangle(ID2D1BitmapRenderTarget
*iface
,
240 const D2D1_RECT_F
*rect
, ID2D1Brush
*brush
)
242 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
244 TRACE("iface %p, rect %s, brush %p.\n", iface
, debug_d2d_rect_f(rect
), brush
);
246 ID2D1RenderTarget_FillRectangle(render_target
->dxgi_target
, rect
, brush
);
249 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_DrawRoundedRectangle(ID2D1BitmapRenderTarget
*iface
,
250 const D2D1_ROUNDED_RECT
*rect
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
252 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
254 TRACE("iface %p, rect %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
255 iface
, rect
, brush
, stroke_width
, stroke_style
);
257 ID2D1RenderTarget_DrawRoundedRectangle(render_target
->dxgi_target
, rect
, brush
, stroke_width
, stroke_style
);
260 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_FillRoundedRectangle(ID2D1BitmapRenderTarget
*iface
,
261 const D2D1_ROUNDED_RECT
*rect
, ID2D1Brush
*brush
)
263 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
265 TRACE("iface %p, rect %p, brush %p.\n", iface
, rect
, brush
);
267 ID2D1RenderTarget_FillRoundedRectangle(render_target
->dxgi_target
, rect
, brush
);
270 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_DrawEllipse(ID2D1BitmapRenderTarget
*iface
,
271 const D2D1_ELLIPSE
*ellipse
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
273 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
275 TRACE("iface %p, ellipse %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
276 iface
, ellipse
, brush
, stroke_width
, stroke_style
);
278 ID2D1RenderTarget_DrawEllipse(render_target
->dxgi_target
, ellipse
, brush
, stroke_width
, stroke_style
);
281 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_FillEllipse(ID2D1BitmapRenderTarget
*iface
,
282 const D2D1_ELLIPSE
*ellipse
, ID2D1Brush
*brush
)
284 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
286 TRACE("iface %p, ellipse %p, brush %p.\n", iface
, ellipse
, brush
);
288 ID2D1RenderTarget_FillEllipse(render_target
->dxgi_target
, ellipse
, brush
);
291 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_DrawGeometry(ID2D1BitmapRenderTarget
*iface
,
292 ID2D1Geometry
*geometry
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
294 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
296 TRACE("iface %p, geometry %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
297 iface
, geometry
, brush
, stroke_width
, stroke_style
);
299 ID2D1RenderTarget_DrawGeometry(render_target
->dxgi_target
, geometry
, brush
, stroke_width
, stroke_style
);
302 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_FillGeometry(ID2D1BitmapRenderTarget
*iface
,
303 ID2D1Geometry
*geometry
, ID2D1Brush
*brush
, ID2D1Brush
*opacity_brush
)
305 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
307 TRACE("iface %p, geometry %p, brush %p, opacity_brush %p.\n", iface
, geometry
, brush
, opacity_brush
);
309 ID2D1RenderTarget_FillGeometry(render_target
->dxgi_target
, geometry
, brush
, opacity_brush
);
312 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_FillMesh(ID2D1BitmapRenderTarget
*iface
,
313 ID2D1Mesh
*mesh
, ID2D1Brush
*brush
)
315 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
317 TRACE("iface %p, mesh %p, brush %p.\n", iface
, mesh
, brush
);
319 ID2D1RenderTarget_FillMesh(render_target
->dxgi_target
, mesh
, brush
);
322 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_FillOpacityMask(ID2D1BitmapRenderTarget
*iface
,
323 ID2D1Bitmap
*mask
, ID2D1Brush
*brush
, D2D1_OPACITY_MASK_CONTENT content
,
324 const D2D1_RECT_F
*dst_rect
, const D2D1_RECT_F
*src_rect
)
326 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
328 TRACE("iface %p, mask %p, brush %p, content %#x, dst_rect %s, src_rect %s.\n",
329 iface
, mask
, brush
, content
, debug_d2d_rect_f(dst_rect
), debug_d2d_rect_f(src_rect
));
331 ID2D1RenderTarget_FillOpacityMask(render_target
->dxgi_target
,
332 mask
, brush
, content
, dst_rect
, src_rect
);
335 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_DrawBitmap(ID2D1BitmapRenderTarget
*iface
,
336 ID2D1Bitmap
*bitmap
, const D2D1_RECT_F
*dst_rect
, float opacity
,
337 D2D1_BITMAP_INTERPOLATION_MODE interpolation_mode
, const D2D1_RECT_F
*src_rect
)
339 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
341 TRACE("iface %p, bitmap %p, dst_rect %s, opacity %.8e, interpolation_mode %#x, src_rect %s.\n",
342 iface
, bitmap
, debug_d2d_rect_f(dst_rect
), opacity
, interpolation_mode
, debug_d2d_rect_f(src_rect
));
344 ID2D1RenderTarget_DrawBitmap(render_target
->dxgi_target
,
345 bitmap
, dst_rect
, opacity
, interpolation_mode
, src_rect
);
348 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_DrawText(ID2D1BitmapRenderTarget
*iface
,
349 const WCHAR
*string
, UINT32 string_len
, IDWriteTextFormat
*text_format
, const D2D1_RECT_F
*layout_rect
,
350 ID2D1Brush
*brush
, D2D1_DRAW_TEXT_OPTIONS options
, DWRITE_MEASURING_MODE measuring_mode
)
352 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
354 TRACE("iface %p, string %s, string_len %u, text_format %p, layout_rect %s, "
355 "brush %p, options %#x, measuring_mode %#x.\n",
356 iface
, debugstr_wn(string
, string_len
), string_len
, text_format
, debug_d2d_rect_f(layout_rect
),
357 brush
, options
, measuring_mode
);
359 ID2D1RenderTarget_DrawText(render_target
->dxgi_target
, string
, string_len
,
360 text_format
, layout_rect
, brush
, options
, measuring_mode
);
363 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_DrawTextLayout(ID2D1BitmapRenderTarget
*iface
,
364 D2D1_POINT_2F origin
, IDWriteTextLayout
*layout
, ID2D1Brush
*brush
, D2D1_DRAW_TEXT_OPTIONS options
)
366 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
368 TRACE("iface %p, origin %s, layout %p, brush %p, options %#x.\n",
369 iface
, debug_d2d_point_2f(&origin
), layout
, brush
, options
);
371 ID2D1RenderTarget_DrawTextLayout(render_target
->dxgi_target
, origin
, layout
, brush
, options
);
374 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_DrawGlyphRun(ID2D1BitmapRenderTarget
*iface
,
375 D2D1_POINT_2F baseline_origin
, const DWRITE_GLYPH_RUN
*glyph_run
, ID2D1Brush
*brush
,
376 DWRITE_MEASURING_MODE measuring_mode
)
378 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
380 TRACE("iface %p, baseline_origin %s, glyph_run %p, brush %p, measuring_mode %#x.\n",
381 iface
, debug_d2d_point_2f(&baseline_origin
), glyph_run
, brush
, measuring_mode
);
383 ID2D1RenderTarget_DrawGlyphRun(render_target
->dxgi_target
,
384 baseline_origin
, glyph_run
, brush
, measuring_mode
);
387 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_SetTransform(ID2D1BitmapRenderTarget
*iface
,
388 const D2D1_MATRIX_3X2_F
*transform
)
390 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
392 TRACE("iface %p, transform %p.\n", iface
, transform
);
394 ID2D1RenderTarget_SetTransform(render_target
->dxgi_target
, transform
);
397 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_GetTransform(ID2D1BitmapRenderTarget
*iface
,
398 D2D1_MATRIX_3X2_F
*transform
)
400 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
402 TRACE("iface %p, transform %p.\n", iface
, transform
);
404 ID2D1RenderTarget_GetTransform(render_target
->dxgi_target
, transform
);
407 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_SetAntialiasMode(ID2D1BitmapRenderTarget
*iface
,
408 D2D1_ANTIALIAS_MODE antialias_mode
)
410 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
412 TRACE("iface %p, antialias_mode %#x.\n", iface
, antialias_mode
);
414 ID2D1RenderTarget_SetAntialiasMode(render_target
->dxgi_target
, antialias_mode
);
417 static D2D1_ANTIALIAS_MODE STDMETHODCALLTYPE
d2d_bitmap_render_target_GetAntialiasMode(ID2D1BitmapRenderTarget
*iface
)
419 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
421 TRACE("iface %p.\n", iface
);
423 return ID2D1RenderTarget_GetAntialiasMode(render_target
->dxgi_target
);
426 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_SetTextAntialiasMode(ID2D1BitmapRenderTarget
*iface
,
427 D2D1_TEXT_ANTIALIAS_MODE antialias_mode
)
429 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
431 TRACE("iface %p, antialias_mode %#x.\n", iface
, antialias_mode
);
433 ID2D1RenderTarget_SetTextAntialiasMode(render_target
->dxgi_target
, antialias_mode
);
436 static D2D1_TEXT_ANTIALIAS_MODE STDMETHODCALLTYPE
d2d_bitmap_render_target_GetTextAntialiasMode(
437 ID2D1BitmapRenderTarget
*iface
)
439 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
441 TRACE("iface %p.\n", iface
);
443 return ID2D1RenderTarget_GetTextAntialiasMode(render_target
->dxgi_target
);
446 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_SetTextRenderingParams(ID2D1BitmapRenderTarget
*iface
,
447 IDWriteRenderingParams
*text_rendering_params
)
449 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
451 TRACE("iface %p, text_rendering_params %p.\n", iface
, text_rendering_params
);
453 ID2D1RenderTarget_SetTextRenderingParams(render_target
->dxgi_target
, text_rendering_params
);
456 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_GetTextRenderingParams(ID2D1BitmapRenderTarget
*iface
,
457 IDWriteRenderingParams
**text_rendering_params
)
459 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
461 TRACE("iface %p, text_rendering_params %p.\n", iface
, text_rendering_params
);
463 ID2D1RenderTarget_GetTextRenderingParams(render_target
->dxgi_target
, text_rendering_params
);
466 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_SetTags(ID2D1BitmapRenderTarget
*iface
, D2D1_TAG tag1
,
469 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
471 TRACE("iface %p, tag1 %s, tag2 %s.\n", iface
, wine_dbgstr_longlong(tag1
), wine_dbgstr_longlong(tag2
));
473 ID2D1RenderTarget_SetTags(render_target
->dxgi_target
, tag1
, tag2
);
476 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_GetTags(ID2D1BitmapRenderTarget
*iface
, D2D1_TAG
*tag1
,
479 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
481 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface
, tag1
, tag2
);
483 ID2D1RenderTarget_GetTags(render_target
->dxgi_target
, tag1
, tag2
);
486 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_PushLayer(ID2D1BitmapRenderTarget
*iface
,
487 const D2D1_LAYER_PARAMETERS
*layer_parameters
, ID2D1Layer
*layer
)
489 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
491 TRACE("iface %p, layer_parameters %p, layer %p.\n", iface
, layer_parameters
, layer
);
493 ID2D1RenderTarget_PushLayer(render_target
->dxgi_target
, layer_parameters
, layer
);
496 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_PopLayer(ID2D1BitmapRenderTarget
*iface
)
498 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
500 TRACE("iface %p.\n", iface
);
502 ID2D1RenderTarget_PopLayer(render_target
->dxgi_target
);
505 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_Flush(ID2D1BitmapRenderTarget
*iface
, D2D1_TAG
*tag1
,
508 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
510 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface
, tag1
, tag2
);
512 return ID2D1RenderTarget_Flush(render_target
->dxgi_target
, tag1
, tag2
);
515 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_SaveDrawingState(ID2D1BitmapRenderTarget
*iface
,
516 ID2D1DrawingStateBlock
*state_block
)
518 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
520 TRACE("iface %p, state_block %p.\n", iface
, state_block
);
522 ID2D1RenderTarget_SaveDrawingState(render_target
->dxgi_target
, state_block
);
525 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_RestoreDrawingState(ID2D1BitmapRenderTarget
*iface
,
526 ID2D1DrawingStateBlock
*state_block
)
528 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
530 TRACE("iface %p, state_block %p.\n", iface
, state_block
);
532 ID2D1RenderTarget_RestoreDrawingState(render_target
->dxgi_target
, state_block
);
535 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_PushAxisAlignedClip(ID2D1BitmapRenderTarget
*iface
,
536 const D2D1_RECT_F
*clip_rect
, D2D1_ANTIALIAS_MODE antialias_mode
)
538 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
540 TRACE("iface %p, clip_rect %s, antialias_mode %#x.\n", iface
, debug_d2d_rect_f(clip_rect
), antialias_mode
);
542 ID2D1RenderTarget_PushAxisAlignedClip(render_target
->dxgi_target
, clip_rect
, antialias_mode
);
545 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_PopAxisAlignedClip(ID2D1BitmapRenderTarget
*iface
)
547 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
549 TRACE("iface %p.\n", iface
);
551 ID2D1RenderTarget_PopAxisAlignedClip(render_target
->dxgi_target
);
554 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_Clear(ID2D1BitmapRenderTarget
*iface
, const D2D1_COLOR_F
*color
)
556 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
558 TRACE("iface %p, color %p.\n", iface
, color
);
560 ID2D1RenderTarget_Clear(render_target
->dxgi_target
, color
);
563 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_BeginDraw(ID2D1BitmapRenderTarget
*iface
)
565 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
567 TRACE("iface %p.\n", iface
);
569 ID2D1RenderTarget_BeginDraw(render_target
->dxgi_target
);
572 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_EndDraw(ID2D1BitmapRenderTarget
*iface
,
573 D2D1_TAG
*tag1
, D2D1_TAG
*tag2
)
575 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
577 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface
, tag1
, tag2
);
579 return ID2D1RenderTarget_EndDraw(render_target
->dxgi_target
, tag1
, tag2
);
582 static D2D1_PIXEL_FORMAT
* STDMETHODCALLTYPE
d2d_bitmap_render_target_GetPixelFormat(ID2D1BitmapRenderTarget
*iface
,
583 D2D1_PIXEL_FORMAT
*format
)
585 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
587 TRACE("iface %p, format %p.\n", iface
, format
);
589 *format
= ID2D1RenderTarget_GetPixelFormat(render_target
->dxgi_target
);
593 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_SetDpi(ID2D1BitmapRenderTarget
*iface
, float dpi_x
, float dpi_y
)
595 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
597 TRACE("iface %p, dpi_x %.8e, dpi_y %.8e.\n", iface
, dpi_x
, dpi_y
);
599 ID2D1RenderTarget_SetDpi(render_target
->dxgi_target
, dpi_x
, dpi_y
);
602 static void STDMETHODCALLTYPE
d2d_bitmap_render_target_GetDpi(ID2D1BitmapRenderTarget
*iface
,
603 float *dpi_x
, float *dpi_y
)
605 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
607 TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface
, dpi_x
, dpi_y
);
609 ID2D1RenderTarget_GetDpi(render_target
->dxgi_target
, dpi_x
, dpi_y
);
612 static D2D1_SIZE_F
* STDMETHODCALLTYPE
d2d_bitmap_render_target_GetSize(ID2D1BitmapRenderTarget
*iface
,
615 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
617 TRACE("iface %p, size %p.\n", iface
, size
);
619 *size
= ID2D1RenderTarget_GetSize(render_target
->dxgi_target
);
623 static D2D1_SIZE_U
* STDMETHODCALLTYPE
d2d_bitmap_render_target_GetPixelSize(ID2D1BitmapRenderTarget
*iface
,
624 D2D1_SIZE_U
*pixel_size
)
626 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
628 TRACE("iface %p, pixel_size %p.\n", iface
, pixel_size
);
630 *pixel_size
= ID2D1RenderTarget_GetPixelSize(render_target
->dxgi_target
);
634 static UINT32 STDMETHODCALLTYPE
d2d_bitmap_render_target_GetMaximumBitmapSize(ID2D1BitmapRenderTarget
*iface
)
636 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
638 TRACE("iface %p.\n", iface
);
640 return ID2D1RenderTarget_GetMaximumBitmapSize(render_target
->dxgi_target
);
643 static BOOL STDMETHODCALLTYPE
d2d_bitmap_render_target_IsSupported(ID2D1BitmapRenderTarget
*iface
,
644 const D2D1_RENDER_TARGET_PROPERTIES
*desc
)
646 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
648 TRACE("iface %p, desc %p.\n", iface
, desc
);
650 return ID2D1RenderTarget_IsSupported(render_target
->dxgi_target
, desc
);
653 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_render_target_GetBitmap(ID2D1BitmapRenderTarget
*iface
,
654 ID2D1Bitmap
**bitmap
)
656 struct d2d_bitmap_render_target
*render_target
= impl_from_ID2D1BitmapRenderTarget(iface
);
658 TRACE("iface %p, bitmap %p.\n", iface
, bitmap
);
660 ID2D1Bitmap_AddRef(*bitmap
= render_target
->bitmap
);
664 static const struct ID2D1BitmapRenderTargetVtbl d2d_bitmap_render_target_vtbl
=
666 d2d_bitmap_render_target_QueryInterface
,
667 d2d_bitmap_render_target_AddRef
,
668 d2d_bitmap_render_target_Release
,
669 d2d_bitmap_render_target_GetFactory
,
670 d2d_bitmap_render_target_CreateBitmap
,
671 d2d_bitmap_render_target_CreateBitmapFromWicBitmap
,
672 d2d_bitmap_render_target_CreateSharedBitmap
,
673 d2d_bitmap_render_target_CreateBitmapBrush
,
674 d2d_bitmap_render_target_CreateSolidColorBrush
,
675 d2d_bitmap_render_target_CreateGradientStopCollection
,
676 d2d_bitmap_render_target_CreateLinearGradientBrush
,
677 d2d_bitmap_render_target_CreateRadialGradientBrush
,
678 d2d_bitmap_render_target_CreateCompatibleRenderTarget
,
679 d2d_bitmap_render_target_CreateLayer
,
680 d2d_bitmap_render_target_CreateMesh
,
681 d2d_bitmap_render_target_DrawLine
,
682 d2d_bitmap_render_target_DrawRectangle
,
683 d2d_bitmap_render_target_FillRectangle
,
684 d2d_bitmap_render_target_DrawRoundedRectangle
,
685 d2d_bitmap_render_target_FillRoundedRectangle
,
686 d2d_bitmap_render_target_DrawEllipse
,
687 d2d_bitmap_render_target_FillEllipse
,
688 d2d_bitmap_render_target_DrawGeometry
,
689 d2d_bitmap_render_target_FillGeometry
,
690 d2d_bitmap_render_target_FillMesh
,
691 d2d_bitmap_render_target_FillOpacityMask
,
692 d2d_bitmap_render_target_DrawBitmap
,
693 d2d_bitmap_render_target_DrawText
,
694 d2d_bitmap_render_target_DrawTextLayout
,
695 d2d_bitmap_render_target_DrawGlyphRun
,
696 d2d_bitmap_render_target_SetTransform
,
697 d2d_bitmap_render_target_GetTransform
,
698 d2d_bitmap_render_target_SetAntialiasMode
,
699 d2d_bitmap_render_target_GetAntialiasMode
,
700 d2d_bitmap_render_target_SetTextAntialiasMode
,
701 d2d_bitmap_render_target_GetTextAntialiasMode
,
702 d2d_bitmap_render_target_SetTextRenderingParams
,
703 d2d_bitmap_render_target_GetTextRenderingParams
,
704 d2d_bitmap_render_target_SetTags
,
705 d2d_bitmap_render_target_GetTags
,
706 d2d_bitmap_render_target_PushLayer
,
707 d2d_bitmap_render_target_PopLayer
,
708 d2d_bitmap_render_target_Flush
,
709 d2d_bitmap_render_target_SaveDrawingState
,
710 d2d_bitmap_render_target_RestoreDrawingState
,
711 d2d_bitmap_render_target_PushAxisAlignedClip
,
712 d2d_bitmap_render_target_PopAxisAlignedClip
,
713 d2d_bitmap_render_target_Clear
,
714 d2d_bitmap_render_target_BeginDraw
,
715 d2d_bitmap_render_target_EndDraw
,
716 d2d_bitmap_render_target_GetPixelFormat
,
717 d2d_bitmap_render_target_SetDpi
,
718 d2d_bitmap_render_target_GetDpi
,
719 d2d_bitmap_render_target_GetSize
,
720 d2d_bitmap_render_target_GetPixelSize
,
721 d2d_bitmap_render_target_GetMaximumBitmapSize
,
722 d2d_bitmap_render_target_IsSupported
,
723 d2d_bitmap_render_target_GetBitmap
726 static const struct d2d_device_context_ops d2d_bitmap_render_target_ops
=
731 HRESULT
d2d_bitmap_render_target_init(struct d2d_bitmap_render_target
*render_target
,
732 const struct d2d_device_context
*parent_target
, const D2D1_SIZE_F
*size
,
733 const D2D1_SIZE_U
*pixel_size
, const D2D1_PIXEL_FORMAT
*pixel_format
,
734 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options
)
736 D2D1_RENDER_TARGET_PROPERTIES dxgi_rt_desc
;
737 D2D1_BITMAP_PROPERTIES1 bitmap_desc
;
738 ID2D1DeviceContext
*context
;
739 D2D1_SIZE_U bitmap_size
;
743 FIXME("Compatible target options are ignored, %#x.\n", options
);
745 render_target
->ID2D1BitmapRenderTarget_iface
.lpVtbl
= &d2d_bitmap_render_target_vtbl
;
747 dxgi_rt_desc
.type
= parent_target
->desc
.type
;
748 dxgi_rt_desc
.usage
= parent_target
->desc
.usage
;
749 dxgi_rt_desc
.minLevel
= parent_target
->desc
.minLevel
;
753 bitmap_size
.width
= pixel_size
->width
;
754 bitmap_size
.height
= pixel_size
->height
;
758 bitmap_size
.width
= ceilf((size
->width
* parent_target
->desc
.dpiX
) / 96.0f
);
759 bitmap_size
.height
= ceilf((size
->height
* parent_target
->desc
.dpiY
) / 96.0f
);
763 bitmap_size
.width
= parent_target
->pixel_size
.width
;
764 bitmap_size
.height
= parent_target
->pixel_size
.height
;
767 if (size
&& size
->width
!= 0.0f
&& size
->height
!= 0.0f
)
769 dxgi_rt_desc
.dpiX
= (bitmap_size
.width
* 96.0f
) / size
->width
;
770 dxgi_rt_desc
.dpiY
= (bitmap_size
.height
* 96.0f
) / size
->height
;
774 dxgi_rt_desc
.dpiX
= parent_target
->desc
.dpiX
;
775 dxgi_rt_desc
.dpiY
= parent_target
->desc
.dpiY
;
778 if (!pixel_format
|| pixel_format
->format
== DXGI_FORMAT_UNKNOWN
)
779 dxgi_rt_desc
.pixelFormat
.format
= parent_target
->desc
.pixelFormat
.format
;
781 dxgi_rt_desc
.pixelFormat
.format
= pixel_format
->format
;
783 if (!pixel_format
|| pixel_format
->alphaMode
== D2D1_ALPHA_MODE_UNKNOWN
)
784 dxgi_rt_desc
.pixelFormat
.alphaMode
= D2D1_ALPHA_MODE_PREMULTIPLIED
;
786 dxgi_rt_desc
.pixelFormat
.alphaMode
= pixel_format
->alphaMode
;
788 if (FAILED(hr
= d2d_d3d_create_render_target(parent_target
->device
, NULL
,
789 (IUnknown
*)&render_target
->ID2D1BitmapRenderTarget_iface
,
790 parent_target
->ops
? &d2d_bitmap_render_target_ops
: NULL
,
791 &dxgi_rt_desc
, (void **)&render_target
->dxgi_inner
)))
793 WARN("Failed to create DXGI surface render target, hr %#x.\n", hr
);
797 /* Note that we should be a little careful with the "dxgi_target"
798 * reference we get here. Because the object is aggregated, releasing the
799 * interface in any error paths below would end up calling
800 * d2d_bitmap_render_target_Release(). */
801 if (FAILED(hr
= IUnknown_QueryInterface(render_target
->dxgi_inner
,
802 &IID_ID2D1RenderTarget
, (void **)&render_target
->dxgi_target
)))
804 WARN("Failed to retrieve ID2D1RenderTarget interface, hr %#x.\n", hr
);
805 IUnknown_Release(render_target
->dxgi_inner
);
809 bitmap_desc
.pixelFormat
= dxgi_rt_desc
.pixelFormat
;
810 bitmap_desc
.dpiX
= dxgi_rt_desc
.dpiX
;
811 bitmap_desc
.dpiY
= dxgi_rt_desc
.dpiY
;
812 bitmap_desc
.bitmapOptions
= D2D1_BITMAP_OPTIONS_TARGET
;
813 bitmap_desc
.colorContext
= NULL
;
815 ID2D1RenderTarget_QueryInterface(render_target
->dxgi_target
, &IID_ID2D1DeviceContext
, (void **)&context
);
816 hr
= ID2D1DeviceContext_CreateBitmap(context
, bitmap_size
, NULL
, 0, &bitmap_desc
,
817 (ID2D1Bitmap1
**)&render_target
->bitmap
);
818 ID2D1DeviceContext_SetTarget(context
, (ID2D1Image
*)render_target
->bitmap
);
819 ID2D1DeviceContext_Release(context
);
822 WARN("Failed to create target bitmap, hr %#x.\n", hr
);
823 IUnknown_Release(render_target
->dxgi_inner
);