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
20 #include "wine/port.h"
22 #include "d2d1_private.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d2d
);
28 static void sync_bitmap(struct d2d_wic_render_target
*render_target
)
30 D3D10_MAPPED_TEXTURE2D mapped_texture
;
31 ID3D10Resource
*src_resource
;
32 IWICBitmapLock
*bitmap_lock
;
33 UINT dst_size
, dst_pitch
;
40 if (FAILED(hr
= IDXGISurface_QueryInterface(render_target
->dxgi_surface
,
41 &IID_ID3D10Resource
, (void **)&src_resource
)))
43 ERR("Failed to get source resource interface, hr %#x.\n", hr
);
47 ID3D10Texture2D_GetDevice(render_target
->readback_texture
, &device
);
48 ID3D10Device_CopyResource(device
, (ID3D10Resource
*)render_target
->readback_texture
, src_resource
);
49 ID3D10Device_Release(device
);
50 ID3D10Resource_Release(src_resource
);
54 dst_rect
.Width
= render_target
->width
;
55 dst_rect
.Height
= render_target
->height
;
56 if (FAILED(hr
= IWICBitmap_Lock(render_target
->bitmap
, &dst_rect
, WICBitmapLockWrite
, &bitmap_lock
)))
58 ERR("Failed to lock destination bitmap, hr %#x.\n", hr
);
62 if (FAILED(hr
= IWICBitmapLock_GetDataPointer(bitmap_lock
, &dst_size
, &dst
)))
64 ERR("Failed to get data pointer, hr %#x.\n", hr
);
65 IWICBitmapLock_Release(bitmap_lock
);
69 if (FAILED(hr
= IWICBitmapLock_GetStride(bitmap_lock
, &dst_pitch
)))
71 ERR("Failed to get stride, hr %#x.\n", hr
);
72 IWICBitmapLock_Release(bitmap_lock
);
76 if (FAILED(hr
= ID3D10Texture2D_Map(render_target
->readback_texture
, 0, D3D10_MAP_READ
, 0, &mapped_texture
)))
78 ERR("Failed to map readback texture, hr %#x.\n", hr
);
79 IWICBitmapLock_Release(bitmap_lock
);
83 src
= mapped_texture
.pData
;
85 for (i
= 0; i
< render_target
->height
; ++i
)
87 memcpy(dst
, src
, render_target
->bpp
* render_target
->width
);
88 src
+= mapped_texture
.RowPitch
;
92 ID3D10Texture2D_Unmap(render_target
->readback_texture
, 0);
93 IWICBitmapLock_Release(bitmap_lock
);
96 static inline struct d2d_wic_render_target
*impl_from_ID2D1RenderTarget(ID2D1RenderTarget
*iface
)
98 return CONTAINING_RECORD(iface
, struct d2d_wic_render_target
, ID2D1RenderTarget_iface
);
101 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_QueryInterface(ID2D1RenderTarget
*iface
, REFIID iid
, void **out
)
103 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
105 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
107 if (IsEqualGUID(iid
, &IID_ID2D1RenderTarget
)
108 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
109 || IsEqualGUID(iid
, &IID_IUnknown
))
111 ID2D1RenderTarget_AddRef(iface
);
115 else if (IsEqualGUID(iid
, &IID_ID2D1GdiInteropRenderTarget
))
116 return ID2D1RenderTarget_QueryInterface(render_target
->dxgi_target
, iid
, out
);
118 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
121 return E_NOINTERFACE
;
124 static ULONG STDMETHODCALLTYPE
d2d_wic_render_target_AddRef(ID2D1RenderTarget
*iface
)
126 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
127 ULONG refcount
= InterlockedIncrement(&render_target
->refcount
);
129 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
134 static ULONG STDMETHODCALLTYPE
d2d_wic_render_target_Release(ID2D1RenderTarget
*iface
)
136 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
137 ULONG refcount
= InterlockedDecrement(&render_target
->refcount
);
139 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
143 IWICBitmap_Release(render_target
->bitmap
);
144 ID3D10Texture2D_Release(render_target
->readback_texture
);
145 ID2D1RenderTarget_Release(render_target
->dxgi_target
);
146 IDXGISurface_Release(render_target
->dxgi_surface
);
147 heap_free(render_target
);
153 static void STDMETHODCALLTYPE
d2d_wic_render_target_GetFactory(ID2D1RenderTarget
*iface
, ID2D1Factory
**factory
)
155 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
157 TRACE("iface %p, factory %p.\n", iface
, factory
);
159 ID2D1RenderTarget_GetFactory(render_target
->dxgi_target
, factory
);
162 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_CreateBitmap(ID2D1RenderTarget
*iface
,
163 D2D1_SIZE_U size
, const void *src_data
, UINT32 pitch
, const D2D1_BITMAP_PROPERTIES
*desc
, ID2D1Bitmap
**bitmap
)
165 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
167 TRACE("iface %p, size {%u, %u}, src_data %p, pitch %u, desc %p, bitmap %p.\n",
168 iface
, size
.width
, size
.height
, src_data
, pitch
, desc
, bitmap
);
170 return ID2D1RenderTarget_CreateBitmap(render_target
->dxgi_target
, size
, src_data
, pitch
, desc
, bitmap
);
173 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_CreateBitmapFromWicBitmap(ID2D1RenderTarget
*iface
,
174 IWICBitmapSource
*bitmap_source
, const D2D1_BITMAP_PROPERTIES
*desc
, ID2D1Bitmap
**bitmap
)
176 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
178 TRACE("iface %p, bitmap_source %p, desc %p, bitmap %p.\n",
179 iface
, bitmap_source
, desc
, bitmap
);
181 return ID2D1RenderTarget_CreateBitmapFromWicBitmap(render_target
->dxgi_target
, bitmap_source
, desc
, bitmap
);
184 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_CreateSharedBitmap(ID2D1RenderTarget
*iface
,
185 REFIID iid
, void *data
, const D2D1_BITMAP_PROPERTIES
*desc
, ID2D1Bitmap
**bitmap
)
187 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
189 TRACE("iface %p, iid %s, data %p, desc %p, bitmap %p.\n",
190 iface
, debugstr_guid(iid
), data
, desc
, bitmap
);
192 return ID2D1RenderTarget_CreateSharedBitmap(render_target
->dxgi_target
, iid
, data
, desc
, bitmap
);
195 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_CreateBitmapBrush(ID2D1RenderTarget
*iface
,
196 ID2D1Bitmap
*bitmap
, const D2D1_BITMAP_BRUSH_PROPERTIES
*bitmap_brush_desc
,
197 const D2D1_BRUSH_PROPERTIES
*brush_desc
, ID2D1BitmapBrush
**brush
)
199 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
201 TRACE("iface %p, bitmap %p, bitmap_brush_desc %p, brush_desc %p, brush %p.\n",
202 iface
, bitmap
, bitmap_brush_desc
, brush_desc
, brush
);
204 return ID2D1RenderTarget_CreateBitmapBrush(render_target
->dxgi_target
,
205 bitmap
, bitmap_brush_desc
, brush_desc
, brush
);
208 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_CreateSolidColorBrush(ID2D1RenderTarget
*iface
,
209 const D2D1_COLOR_F
*color
, const D2D1_BRUSH_PROPERTIES
*desc
, ID2D1SolidColorBrush
**brush
)
211 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
213 TRACE("iface %p, color %p, desc %p, brush %p.\n", iface
, color
, desc
, brush
);
215 return ID2D1RenderTarget_CreateSolidColorBrush(render_target
->dxgi_target
, color
, desc
, brush
);
218 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_CreateGradientStopCollection(ID2D1RenderTarget
*iface
,
219 const D2D1_GRADIENT_STOP
*stops
, UINT32 stop_count
, D2D1_GAMMA gamma
, D2D1_EXTEND_MODE extend_mode
,
220 ID2D1GradientStopCollection
**gradient
)
222 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
224 TRACE("iface %p, stops %p, stop_count %u, gamma %#x, extend_mode %#x, gradient %p.\n",
225 iface
, stops
, stop_count
, gamma
, extend_mode
, gradient
);
227 return ID2D1RenderTarget_CreateGradientStopCollection(render_target
->dxgi_target
,
228 stops
, stop_count
, gamma
, extend_mode
, gradient
);
231 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_CreateLinearGradientBrush(ID2D1RenderTarget
*iface
,
232 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES
*gradient_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
233 ID2D1GradientStopCollection
*gradient
, ID2D1LinearGradientBrush
**brush
)
235 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
237 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
238 iface
, gradient_brush_desc
, brush_desc
, gradient
, brush
);
240 return ID2D1RenderTarget_CreateLinearGradientBrush(render_target
->dxgi_target
,
241 gradient_brush_desc
, brush_desc
, gradient
, brush
);
244 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_CreateRadialGradientBrush(ID2D1RenderTarget
*iface
,
245 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES
*gradient_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
246 ID2D1GradientStopCollection
*gradient
, ID2D1RadialGradientBrush
**brush
)
248 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
250 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
251 iface
, gradient_brush_desc
, brush_desc
, gradient
, brush
);
253 return ID2D1RenderTarget_CreateRadialGradientBrush(render_target
->dxgi_target
,
254 gradient_brush_desc
, brush_desc
, gradient
, brush
);
257 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_CreateCompatibleRenderTarget(ID2D1RenderTarget
*iface
,
258 const D2D1_SIZE_F
*size
, const D2D1_SIZE_U
*pixel_size
, const D2D1_PIXEL_FORMAT
*format
,
259 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options
, ID2D1BitmapRenderTarget
**render_target
)
261 struct d2d_wic_render_target
*rt
= impl_from_ID2D1RenderTarget(iface
);
263 TRACE("iface %p, size %p, pixel_size %p, format %p, options %#x, render_target %p,\n",
264 iface
, size
, pixel_size
, format
, options
, render_target
);
266 return ID2D1RenderTarget_CreateCompatibleRenderTarget(rt
->dxgi_target
,
267 size
, pixel_size
, format
, options
, render_target
);
270 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_CreateLayer(ID2D1RenderTarget
*iface
,
271 const D2D1_SIZE_F
*size
, ID2D1Layer
**layer
)
273 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
275 TRACE("iface %p, size %p, layer %p.\n", iface
, size
, layer
);
277 return ID2D1RenderTarget_CreateLayer(render_target
->dxgi_target
, size
, layer
);
280 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_CreateMesh(ID2D1RenderTarget
*iface
, ID2D1Mesh
**mesh
)
282 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
284 TRACE("iface %p, mesh %p.\n", iface
, mesh
);
286 return ID2D1RenderTarget_CreateMesh(render_target
->dxgi_target
, mesh
);
289 static void STDMETHODCALLTYPE
d2d_wic_render_target_DrawLine(ID2D1RenderTarget
*iface
,
290 D2D1_POINT_2F p0
, D2D1_POINT_2F p1
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
292 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
294 TRACE("iface %p, p0 {%.8e, %.8e}, p1 {%.8e, %.8e}, brush %p, stroke_width %.8e, stroke_style %p.\n",
295 iface
, p0
.x
, p0
.y
, p1
.x
, p1
.y
, brush
, stroke_width
, stroke_style
);
297 ID2D1RenderTarget_DrawLine(render_target
->dxgi_target
, p0
, p1
, brush
, stroke_width
, stroke_style
);
300 static void STDMETHODCALLTYPE
d2d_wic_render_target_DrawRectangle(ID2D1RenderTarget
*iface
,
301 const D2D1_RECT_F
*rect
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
303 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
305 TRACE("iface %p, rect %s, brush %p, stroke_width %.8e, stroke_style %p.\n",
306 iface
, debug_d2d_rect_f(rect
), brush
, stroke_width
, stroke_style
);
308 ID2D1RenderTarget_DrawRectangle(render_target
->dxgi_target
, rect
, brush
, stroke_width
, stroke_style
);
311 static void STDMETHODCALLTYPE
d2d_wic_render_target_FillRectangle(ID2D1RenderTarget
*iface
,
312 const D2D1_RECT_F
*rect
, ID2D1Brush
*brush
)
314 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
316 TRACE("iface %p, rect %s, brush %p.\n", iface
, debug_d2d_rect_f(rect
), brush
);
318 ID2D1RenderTarget_FillRectangle(render_target
->dxgi_target
, rect
, brush
);
321 static void STDMETHODCALLTYPE
d2d_wic_render_target_DrawRoundedRectangle(ID2D1RenderTarget
*iface
,
322 const D2D1_ROUNDED_RECT
*rect
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
324 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
326 TRACE("iface %p, rect %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
327 iface
, rect
, brush
, stroke_width
, stroke_style
);
329 ID2D1RenderTarget_DrawRoundedRectangle(render_target
->dxgi_target
, rect
, brush
, stroke_width
, stroke_style
);
332 static void STDMETHODCALLTYPE
d2d_wic_render_target_FillRoundedRectangle(ID2D1RenderTarget
*iface
,
333 const D2D1_ROUNDED_RECT
*rect
, ID2D1Brush
*brush
)
335 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
337 TRACE("iface %p, rect %p, brush %p.\n", iface
, rect
, brush
);
339 ID2D1RenderTarget_FillRoundedRectangle(render_target
->dxgi_target
, rect
, brush
);
342 static void STDMETHODCALLTYPE
d2d_wic_render_target_DrawEllipse(ID2D1RenderTarget
*iface
,
343 const D2D1_ELLIPSE
*ellipse
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
345 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
347 TRACE("iface %p, ellipse %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
348 iface
, ellipse
, brush
, stroke_width
, stroke_style
);
350 ID2D1RenderTarget_DrawEllipse(render_target
->dxgi_target
, ellipse
, brush
, stroke_width
, stroke_style
);
353 static void STDMETHODCALLTYPE
d2d_wic_render_target_FillEllipse(ID2D1RenderTarget
*iface
,
354 const D2D1_ELLIPSE
*ellipse
, ID2D1Brush
*brush
)
356 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
358 TRACE("iface %p, ellipse %p, brush %p.\n", iface
, ellipse
, brush
);
360 ID2D1RenderTarget_FillEllipse(render_target
->dxgi_target
, ellipse
, brush
);
363 static void STDMETHODCALLTYPE
d2d_wic_render_target_DrawGeometry(ID2D1RenderTarget
*iface
,
364 ID2D1Geometry
*geometry
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
366 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
368 TRACE("iface %p, geometry %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
369 iface
, geometry
, brush
, stroke_width
, stroke_style
);
371 ID2D1RenderTarget_DrawGeometry(render_target
->dxgi_target
, geometry
, brush
, stroke_width
, stroke_style
);
374 static void STDMETHODCALLTYPE
d2d_wic_render_target_FillGeometry(ID2D1RenderTarget
*iface
,
375 ID2D1Geometry
*geometry
, ID2D1Brush
*brush
, ID2D1Brush
*opacity_brush
)
377 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
379 TRACE("iface %p, geometry %p, brush %p, opacity_brush %p.\n", iface
, geometry
, brush
, opacity_brush
);
381 ID2D1RenderTarget_FillGeometry(render_target
->dxgi_target
, geometry
, brush
, opacity_brush
);
384 static void STDMETHODCALLTYPE
d2d_wic_render_target_FillMesh(ID2D1RenderTarget
*iface
,
385 ID2D1Mesh
*mesh
, ID2D1Brush
*brush
)
387 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
389 TRACE("iface %p, mesh %p, brush %p.\n", iface
, mesh
, brush
);
391 ID2D1RenderTarget_FillMesh(render_target
->dxgi_target
, mesh
, brush
);
394 static void STDMETHODCALLTYPE
d2d_wic_render_target_FillOpacityMask(ID2D1RenderTarget
*iface
,
395 ID2D1Bitmap
*mask
, ID2D1Brush
*brush
, D2D1_OPACITY_MASK_CONTENT content
,
396 const D2D1_RECT_F
*dst_rect
, const D2D1_RECT_F
*src_rect
)
398 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
400 TRACE("iface %p, mask %p, brush %p, content %#x, dst_rect %s, src_rect %s.\n",
401 iface
, mask
, brush
, content
, debug_d2d_rect_f(dst_rect
), debug_d2d_rect_f(src_rect
));
403 ID2D1RenderTarget_FillOpacityMask(render_target
->dxgi_target
,
404 mask
, brush
, content
, dst_rect
, src_rect
);
407 static void STDMETHODCALLTYPE
d2d_wic_render_target_DrawBitmap(ID2D1RenderTarget
*iface
,
408 ID2D1Bitmap
*bitmap
, const D2D1_RECT_F
*dst_rect
, float opacity
,
409 D2D1_BITMAP_INTERPOLATION_MODE interpolation_mode
, const D2D1_RECT_F
*src_rect
)
411 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
413 TRACE("iface %p, bitmap %p, dst_rect %s, opacity %.8e, interpolation_mode %#x, src_rect %s.\n",
414 iface
, bitmap
, debug_d2d_rect_f(dst_rect
), opacity
, interpolation_mode
, debug_d2d_rect_f(src_rect
));
416 ID2D1RenderTarget_DrawBitmap(render_target
->dxgi_target
,
417 bitmap
, dst_rect
, opacity
, interpolation_mode
, src_rect
);
420 static void STDMETHODCALLTYPE
d2d_wic_render_target_DrawText(ID2D1RenderTarget
*iface
,
421 const WCHAR
*string
, UINT32 string_len
, IDWriteTextFormat
*text_format
, const D2D1_RECT_F
*layout_rect
,
422 ID2D1Brush
*brush
, D2D1_DRAW_TEXT_OPTIONS options
, DWRITE_MEASURING_MODE measuring_mode
)
424 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
426 TRACE("iface %p, string %s, string_len %u, text_format %p, layout_rect %s, "
427 "brush %p, options %#x, measuring_mode %#x.\n",
428 iface
, debugstr_wn(string
, string_len
), string_len
, text_format
, debug_d2d_rect_f(layout_rect
),
429 brush
, options
, measuring_mode
);
431 ID2D1RenderTarget_DrawText(render_target
->dxgi_target
, string
, string_len
,
432 text_format
, layout_rect
, brush
, options
, measuring_mode
);
435 static void STDMETHODCALLTYPE
d2d_wic_render_target_DrawTextLayout(ID2D1RenderTarget
*iface
,
436 D2D1_POINT_2F origin
, IDWriteTextLayout
*layout
, ID2D1Brush
*brush
, D2D1_DRAW_TEXT_OPTIONS options
)
438 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
440 TRACE("iface %p, origin {%.8e, %.8e}, layout %p, brush %p, options %#x.\n",
441 iface
, origin
.x
, origin
.y
, layout
, brush
, options
);
443 ID2D1RenderTarget_DrawTextLayout(render_target
->dxgi_target
, origin
, layout
, brush
, options
);
446 static void STDMETHODCALLTYPE
d2d_wic_render_target_DrawGlyphRun(ID2D1RenderTarget
*iface
,
447 D2D1_POINT_2F baseline_origin
, const DWRITE_GLYPH_RUN
*glyph_run
, ID2D1Brush
*brush
,
448 DWRITE_MEASURING_MODE measuring_mode
)
450 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
452 TRACE("iface %p, baseline_origin {%.8e, %.8e}, glyph_run %p, brush %p, measuring_mode %#x.\n",
453 iface
, baseline_origin
.x
, baseline_origin
.y
, glyph_run
, brush
, measuring_mode
);
455 ID2D1RenderTarget_DrawGlyphRun(render_target
->dxgi_target
,
456 baseline_origin
, glyph_run
, brush
, measuring_mode
);
459 static void STDMETHODCALLTYPE
d2d_wic_render_target_SetTransform(ID2D1RenderTarget
*iface
,
460 const D2D1_MATRIX_3X2_F
*transform
)
462 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
464 TRACE("iface %p, transform %p.\n", iface
, transform
);
466 ID2D1RenderTarget_SetTransform(render_target
->dxgi_target
, transform
);
469 static void STDMETHODCALLTYPE
d2d_wic_render_target_GetTransform(ID2D1RenderTarget
*iface
,
470 D2D1_MATRIX_3X2_F
*transform
)
472 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
474 TRACE("iface %p, transform %p.\n", iface
, transform
);
476 ID2D1RenderTarget_GetTransform(render_target
->dxgi_target
, transform
);
479 static void STDMETHODCALLTYPE
d2d_wic_render_target_SetAntialiasMode(ID2D1RenderTarget
*iface
,
480 D2D1_ANTIALIAS_MODE antialias_mode
)
482 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
484 TRACE("iface %p, antialias_mode %#x.\n", iface
, antialias_mode
);
486 ID2D1RenderTarget_SetAntialiasMode(render_target
->dxgi_target
, antialias_mode
);
489 static D2D1_ANTIALIAS_MODE STDMETHODCALLTYPE
d2d_wic_render_target_GetAntialiasMode(ID2D1RenderTarget
*iface
)
491 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
493 TRACE("iface %p.\n", iface
);
495 return ID2D1RenderTarget_GetAntialiasMode(render_target
->dxgi_target
);
498 static void STDMETHODCALLTYPE
d2d_wic_render_target_SetTextAntialiasMode(ID2D1RenderTarget
*iface
,
499 D2D1_TEXT_ANTIALIAS_MODE antialias_mode
)
501 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
503 TRACE("iface %p, antialias_mode %#x.\n", iface
, antialias_mode
);
505 ID2D1RenderTarget_SetTextAntialiasMode(render_target
->dxgi_target
, antialias_mode
);
508 static D2D1_TEXT_ANTIALIAS_MODE STDMETHODCALLTYPE
d2d_wic_render_target_GetTextAntialiasMode(ID2D1RenderTarget
*iface
)
510 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
512 TRACE("iface %p.\n", iface
);
514 return ID2D1RenderTarget_GetTextAntialiasMode(render_target
->dxgi_target
);
517 static void STDMETHODCALLTYPE
d2d_wic_render_target_SetTextRenderingParams(ID2D1RenderTarget
*iface
,
518 IDWriteRenderingParams
*text_rendering_params
)
520 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
522 TRACE("iface %p, text_rendering_params %p.\n", iface
, text_rendering_params
);
524 ID2D1RenderTarget_SetTextRenderingParams(render_target
->dxgi_target
, text_rendering_params
);
527 static void STDMETHODCALLTYPE
d2d_wic_render_target_GetTextRenderingParams(ID2D1RenderTarget
*iface
,
528 IDWriteRenderingParams
**text_rendering_params
)
530 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
532 TRACE("iface %p, text_rendering_params %p.\n", iface
, text_rendering_params
);
534 ID2D1RenderTarget_GetTextRenderingParams(render_target
->dxgi_target
, text_rendering_params
);
537 static void STDMETHODCALLTYPE
d2d_wic_render_target_SetTags(ID2D1RenderTarget
*iface
, D2D1_TAG tag1
, D2D1_TAG tag2
)
539 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
541 TRACE("iface %p, tag1 %s, tag2 %s.\n", iface
, wine_dbgstr_longlong(tag1
), wine_dbgstr_longlong(tag2
));
543 ID2D1RenderTarget_SetTags(render_target
->dxgi_target
, tag1
, tag2
);
546 static void STDMETHODCALLTYPE
d2d_wic_render_target_GetTags(ID2D1RenderTarget
*iface
, D2D1_TAG
*tag1
, D2D1_TAG
*tag2
)
548 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
550 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface
, tag1
, tag2
);
552 ID2D1RenderTarget_GetTags(render_target
->dxgi_target
, tag1
, tag2
);
555 static void STDMETHODCALLTYPE
d2d_wic_render_target_PushLayer(ID2D1RenderTarget
*iface
,
556 const D2D1_LAYER_PARAMETERS
*layer_parameters
, ID2D1Layer
*layer
)
558 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
560 TRACE("iface %p, layer_parameters %p, layer %p.\n", iface
, layer_parameters
, layer
);
562 ID2D1RenderTarget_PushLayer(render_target
->dxgi_target
, layer_parameters
, layer
);
565 static void STDMETHODCALLTYPE
d2d_wic_render_target_PopLayer(ID2D1RenderTarget
*iface
)
567 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
569 TRACE("iface %p.\n", iface
);
571 ID2D1RenderTarget_PopLayer(render_target
->dxgi_target
);
574 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_Flush(ID2D1RenderTarget
*iface
, D2D1_TAG
*tag1
, D2D1_TAG
*tag2
)
576 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
579 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface
, tag1
, tag2
);
581 hr
= ID2D1RenderTarget_Flush(render_target
->dxgi_target
, tag1
, tag2
);
582 sync_bitmap(render_target
);
587 static void STDMETHODCALLTYPE
d2d_wic_render_target_SaveDrawingState(ID2D1RenderTarget
*iface
,
588 ID2D1DrawingStateBlock
*state_block
)
590 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
592 TRACE("iface %p, state_block %p.\n", iface
, state_block
);
594 ID2D1RenderTarget_SaveDrawingState(render_target
->dxgi_target
, state_block
);
597 static void STDMETHODCALLTYPE
d2d_wic_render_target_RestoreDrawingState(ID2D1RenderTarget
*iface
,
598 ID2D1DrawingStateBlock
*state_block
)
600 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
602 TRACE("iface %p, state_block %p.\n", iface
, state_block
);
604 ID2D1RenderTarget_RestoreDrawingState(render_target
->dxgi_target
, state_block
);
607 static void STDMETHODCALLTYPE
d2d_wic_render_target_PushAxisAlignedClip(ID2D1RenderTarget
*iface
,
608 const D2D1_RECT_F
*clip_rect
, D2D1_ANTIALIAS_MODE antialias_mode
)
610 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
612 TRACE("iface %p, clip_rect %s, antialias_mode %#x.\n", iface
, debug_d2d_rect_f(clip_rect
), antialias_mode
);
614 ID2D1RenderTarget_PushAxisAlignedClip(render_target
->dxgi_target
, clip_rect
, antialias_mode
);
617 static void STDMETHODCALLTYPE
d2d_wic_render_target_PopAxisAlignedClip(ID2D1RenderTarget
*iface
)
619 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
621 TRACE("iface %p.\n", iface
);
623 ID2D1RenderTarget_PopAxisAlignedClip(render_target
->dxgi_target
);
626 static void STDMETHODCALLTYPE
d2d_wic_render_target_Clear(ID2D1RenderTarget
*iface
, const D2D1_COLOR_F
*color
)
628 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
630 TRACE("iface %p, color %p.\n", iface
, color
);
632 ID2D1RenderTarget_Clear(render_target
->dxgi_target
, color
);
635 static void STDMETHODCALLTYPE
d2d_wic_render_target_BeginDraw(ID2D1RenderTarget
*iface
)
637 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
639 TRACE("iface %p.\n", iface
);
641 ID2D1RenderTarget_BeginDraw(render_target
->dxgi_target
);
644 static HRESULT STDMETHODCALLTYPE
d2d_wic_render_target_EndDraw(ID2D1RenderTarget
*iface
,
645 D2D1_TAG
*tag1
, D2D1_TAG
*tag2
)
647 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
650 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface
, tag1
, tag2
);
652 hr
= ID2D1RenderTarget_EndDraw(render_target
->dxgi_target
, tag1
, tag2
);
653 sync_bitmap(render_target
);
658 static D2D1_PIXEL_FORMAT
* STDMETHODCALLTYPE
d2d_wic_render_target_GetPixelFormat(ID2D1RenderTarget
*iface
,
659 D2D1_PIXEL_FORMAT
*format
)
661 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
663 TRACE("iface %p, format %p.\n", iface
, format
);
665 *format
= ID2D1RenderTarget_GetPixelFormat(render_target
->dxgi_target
);
669 static void STDMETHODCALLTYPE
d2d_wic_render_target_SetDpi(ID2D1RenderTarget
*iface
, float dpi_x
, float dpi_y
)
671 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
673 TRACE("iface %p, dpi_x %.8e, dpi_y %.8e.\n", iface
, dpi_x
, dpi_y
);
675 ID2D1RenderTarget_SetDpi(render_target
->dxgi_target
, dpi_x
, dpi_y
);
678 static void STDMETHODCALLTYPE
d2d_wic_render_target_GetDpi(ID2D1RenderTarget
*iface
, float *dpi_x
, float *dpi_y
)
680 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
682 TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface
, dpi_x
, dpi_y
);
684 ID2D1RenderTarget_GetDpi(render_target
->dxgi_target
, dpi_x
, dpi_y
);
687 static D2D1_SIZE_F
* STDMETHODCALLTYPE
d2d_wic_render_target_GetSize(ID2D1RenderTarget
*iface
, D2D1_SIZE_F
*size
)
689 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
691 TRACE("iface %p, size %p.\n", iface
, size
);
693 *size
= ID2D1RenderTarget_GetSize(render_target
->dxgi_target
);
697 static D2D1_SIZE_U
* STDMETHODCALLTYPE
d2d_wic_render_target_GetPixelSize(ID2D1RenderTarget
*iface
,
698 D2D1_SIZE_U
*pixel_size
)
700 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
702 TRACE("iface %p, pixel_size %p.\n", iface
, pixel_size
);
704 *pixel_size
= ID2D1RenderTarget_GetPixelSize(render_target
->dxgi_target
);
708 static UINT32 STDMETHODCALLTYPE
d2d_wic_render_target_GetMaximumBitmapSize(ID2D1RenderTarget
*iface
)
710 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
712 TRACE("iface %p.\n", iface
);
714 return ID2D1RenderTarget_GetMaximumBitmapSize(render_target
->dxgi_target
);
717 static BOOL STDMETHODCALLTYPE
d2d_wic_render_target_IsSupported(ID2D1RenderTarget
*iface
,
718 const D2D1_RENDER_TARGET_PROPERTIES
*desc
)
720 struct d2d_wic_render_target
*render_target
= impl_from_ID2D1RenderTarget(iface
);
722 TRACE("iface %p, desc %p.\n", iface
, desc
);
724 return ID2D1RenderTarget_IsSupported(render_target
->dxgi_target
, desc
);
727 static const struct ID2D1RenderTargetVtbl d2d_wic_render_target_vtbl
=
729 d2d_wic_render_target_QueryInterface
,
730 d2d_wic_render_target_AddRef
,
731 d2d_wic_render_target_Release
,
732 d2d_wic_render_target_GetFactory
,
733 d2d_wic_render_target_CreateBitmap
,
734 d2d_wic_render_target_CreateBitmapFromWicBitmap
,
735 d2d_wic_render_target_CreateSharedBitmap
,
736 d2d_wic_render_target_CreateBitmapBrush
,
737 d2d_wic_render_target_CreateSolidColorBrush
,
738 d2d_wic_render_target_CreateGradientStopCollection
,
739 d2d_wic_render_target_CreateLinearGradientBrush
,
740 d2d_wic_render_target_CreateRadialGradientBrush
,
741 d2d_wic_render_target_CreateCompatibleRenderTarget
,
742 d2d_wic_render_target_CreateLayer
,
743 d2d_wic_render_target_CreateMesh
,
744 d2d_wic_render_target_DrawLine
,
745 d2d_wic_render_target_DrawRectangle
,
746 d2d_wic_render_target_FillRectangle
,
747 d2d_wic_render_target_DrawRoundedRectangle
,
748 d2d_wic_render_target_FillRoundedRectangle
,
749 d2d_wic_render_target_DrawEllipse
,
750 d2d_wic_render_target_FillEllipse
,
751 d2d_wic_render_target_DrawGeometry
,
752 d2d_wic_render_target_FillGeometry
,
753 d2d_wic_render_target_FillMesh
,
754 d2d_wic_render_target_FillOpacityMask
,
755 d2d_wic_render_target_DrawBitmap
,
756 d2d_wic_render_target_DrawText
,
757 d2d_wic_render_target_DrawTextLayout
,
758 d2d_wic_render_target_DrawGlyphRun
,
759 d2d_wic_render_target_SetTransform
,
760 d2d_wic_render_target_GetTransform
,
761 d2d_wic_render_target_SetAntialiasMode
,
762 d2d_wic_render_target_GetAntialiasMode
,
763 d2d_wic_render_target_SetTextAntialiasMode
,
764 d2d_wic_render_target_GetTextAntialiasMode
,
765 d2d_wic_render_target_SetTextRenderingParams
,
766 d2d_wic_render_target_GetTextRenderingParams
,
767 d2d_wic_render_target_SetTags
,
768 d2d_wic_render_target_GetTags
,
769 d2d_wic_render_target_PushLayer
,
770 d2d_wic_render_target_PopLayer
,
771 d2d_wic_render_target_Flush
,
772 d2d_wic_render_target_SaveDrawingState
,
773 d2d_wic_render_target_RestoreDrawingState
,
774 d2d_wic_render_target_PushAxisAlignedClip
,
775 d2d_wic_render_target_PopAxisAlignedClip
,
776 d2d_wic_render_target_Clear
,
777 d2d_wic_render_target_BeginDraw
,
778 d2d_wic_render_target_EndDraw
,
779 d2d_wic_render_target_GetPixelFormat
,
780 d2d_wic_render_target_SetDpi
,
781 d2d_wic_render_target_GetDpi
,
782 d2d_wic_render_target_GetSize
,
783 d2d_wic_render_target_GetPixelSize
,
784 d2d_wic_render_target_GetMaximumBitmapSize
,
785 d2d_wic_render_target_IsSupported
,
788 HRESULT
d2d_wic_render_target_init(struct d2d_wic_render_target
*render_target
, ID2D1Factory
*factory
,
789 ID3D10Device1
*device
, IWICBitmap
*bitmap
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
)
791 D3D10_TEXTURE2D_DESC texture_desc
;
792 ID3D10Texture2D
*texture
;
795 render_target
->ID2D1RenderTarget_iface
.lpVtbl
= &d2d_wic_render_target_vtbl
;
796 render_target
->refcount
= 1;
798 if (FAILED(hr
= IWICBitmap_GetSize(bitmap
, &render_target
->width
, &render_target
->height
)))
800 WARN("Failed to get bitmap dimensions, hr %#x.\n", hr
);
804 texture_desc
.Width
= render_target
->width
;
805 texture_desc
.Height
= render_target
->height
;
806 texture_desc
.MipLevels
= 1;
807 texture_desc
.ArraySize
= 1;
809 texture_desc
.Format
= desc
->pixelFormat
.format
;
810 if (texture_desc
.Format
== DXGI_FORMAT_UNKNOWN
)
812 WICPixelFormatGUID bitmap_format
;
814 if (FAILED(hr
= IWICBitmap_GetPixelFormat(bitmap
, &bitmap_format
)))
816 WARN("Failed to get bitmap format, hr %#x.\n", hr
);
820 if (IsEqualGUID(&bitmap_format
, &GUID_WICPixelFormat32bppPBGRA
)
821 || IsEqualGUID(&bitmap_format
, &GUID_WICPixelFormat32bppBGR
))
823 texture_desc
.Format
= DXGI_FORMAT_B8G8R8A8_UNORM
;
827 WARN("Unsupported WIC bitmap format %s.\n", debugstr_guid(&bitmap_format
));
828 return D2DERR_UNSUPPORTED_PIXEL_FORMAT
;
832 switch (texture_desc
.Format
)
834 case DXGI_FORMAT_B8G8R8A8_UNORM
:
835 render_target
->bpp
= 4;
839 FIXME("Unhandled format %#x.\n", texture_desc
.Format
);
840 return D2DERR_UNSUPPORTED_PIXEL_FORMAT
;
843 texture_desc
.SampleDesc
.Count
= 1;
844 texture_desc
.SampleDesc
.Quality
= 0;
845 texture_desc
.Usage
= D3D10_USAGE_DEFAULT
;
846 texture_desc
.BindFlags
= D3D10_BIND_RENDER_TARGET
| D3D10_BIND_SHADER_RESOURCE
;
847 texture_desc
.CPUAccessFlags
= 0;
848 texture_desc
.MiscFlags
= desc
->usage
& D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE
?
849 D3D10_RESOURCE_MISC_GDI_COMPATIBLE
: 0;
851 if (FAILED(hr
= ID3D10Device1_CreateTexture2D(device
, &texture_desc
, NULL
, &texture
)))
853 WARN("Failed to create texture, hr %#x.\n", hr
);
857 hr
= ID3D10Texture2D_QueryInterface(texture
, &IID_IDXGISurface
, (void **)&render_target
->dxgi_surface
);
858 ID3D10Texture2D_Release(texture
);
861 WARN("Failed to get DXGI surface interface, hr %#x.\n", hr
);
865 texture_desc
.Usage
= D3D10_USAGE_STAGING
;
866 texture_desc
.BindFlags
= 0;
867 texture_desc
.CPUAccessFlags
= D3D10_CPU_ACCESS_READ
;
868 texture_desc
.MiscFlags
= 0;
870 if (FAILED(hr
= ID3D10Device1_CreateTexture2D(device
, &texture_desc
, NULL
, &render_target
->readback_texture
)))
872 WARN("Failed to create readback texture, hr %#x.\n", hr
);
873 IDXGISurface_Release(render_target
->dxgi_surface
);
877 if (FAILED(hr
= d2d_d3d_create_render_target(factory
, render_target
->dxgi_surface
,
878 (IUnknown
*)&render_target
->ID2D1RenderTarget_iface
, desc
, &render_target
->dxgi_target
)))
880 WARN("Failed to create DXGI surface render target, hr %#x.\n", hr
);
881 ID3D10Texture2D_Release(render_target
->readback_texture
);
882 IDXGISurface_Release(render_target
->dxgi_surface
);
886 render_target
->bitmap
= bitmap
;
887 IWICBitmap_AddRef(bitmap
);