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 void sync_bitmap(struct d2d_dc_render_target
*render_target
)
29 const RECT
*dst_rect
= &render_target
->dst_rect
;
34 if (FAILED(hr
= IDXGISurface1_GetDC(render_target
->dxgi_surface
, FALSE
, &src_hdc
)))
36 WARN("GetDC() failed, %#x.\n", hr
);
40 BitBlt(render_target
->hdc
, dst_rect
->left
, dst_rect
->top
, dst_rect
->right
- dst_rect
->left
,
41 dst_rect
->bottom
- dst_rect
->top
, src_hdc
, 0, 0, SRCCOPY
);
43 SetRectEmpty(&empty_rect
);
44 IDXGISurface1_ReleaseDC(render_target
->dxgi_surface
, &empty_rect
);
47 static inline struct d2d_dc_render_target
*impl_from_ID2D1DCRenderTarget(ID2D1DCRenderTarget
*iface
)
49 return CONTAINING_RECORD(iface
, struct d2d_dc_render_target
, ID2D1DCRenderTarget_iface
);
52 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_QueryInterface(ID2D1DCRenderTarget
*iface
, REFIID iid
, void **out
)
54 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
56 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
58 if (IsEqualGUID(iid
, &IID_ID2D1DCRenderTarget
)
59 || IsEqualGUID(iid
, &IID_ID2D1RenderTarget
)
60 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
61 || IsEqualGUID(iid
, &IID_IUnknown
))
63 ID2D1DCRenderTarget_AddRef(iface
);
67 else if (IsEqualGUID(iid
, &IID_ID2D1GdiInteropRenderTarget
))
68 return ID2D1RenderTarget_QueryInterface(render_target
->dxgi_target
, iid
, out
);
70 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
76 static ULONG STDMETHODCALLTYPE
d2d_dc_render_target_AddRef(ID2D1DCRenderTarget
*iface
)
78 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
79 ULONG refcount
= InterlockedIncrement(&render_target
->refcount
);
81 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
86 static ULONG STDMETHODCALLTYPE
d2d_dc_render_target_Release(ID2D1DCRenderTarget
*iface
)
88 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
89 ULONG refcount
= InterlockedDecrement(&render_target
->refcount
);
91 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
95 ID2D1RenderTarget_Release(render_target
->dxgi_target
);
96 IDXGISurface1_Release(render_target
->dxgi_surface
);
97 HeapFree(GetProcessHeap(), 0, render_target
);
103 static void STDMETHODCALLTYPE
d2d_dc_render_target_GetFactory(ID2D1DCRenderTarget
*iface
, ID2D1Factory
**factory
)
105 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
107 TRACE("iface %p, factory %p.\n", iface
, factory
);
109 ID2D1RenderTarget_GetFactory(render_target
->dxgi_target
, factory
);
112 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_CreateBitmap(ID2D1DCRenderTarget
*iface
,
113 D2D1_SIZE_U size
, const void *src_data
, UINT32 pitch
, const D2D1_BITMAP_PROPERTIES
*desc
, ID2D1Bitmap
**bitmap
)
115 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
117 TRACE("iface %p, size {%u, %u}, src_data %p, pitch %u, desc %p, bitmap %p.\n",
118 iface
, size
.width
, size
.height
, src_data
, pitch
, desc
, bitmap
);
120 return ID2D1RenderTarget_CreateBitmap(render_target
->dxgi_target
, size
, src_data
, pitch
, desc
, bitmap
);
123 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_CreateBitmapFromWicBitmap(ID2D1DCRenderTarget
*iface
,
124 IWICBitmapSource
*bitmap_source
, const D2D1_BITMAP_PROPERTIES
*desc
, ID2D1Bitmap
**bitmap
)
126 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
128 TRACE("iface %p, bitmap_source %p, desc %p, bitmap %p.\n",
129 iface
, bitmap_source
, desc
, bitmap
);
131 return ID2D1RenderTarget_CreateBitmapFromWicBitmap(render_target
->dxgi_target
, bitmap_source
, desc
, bitmap
);
134 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_CreateSharedBitmap(ID2D1DCRenderTarget
*iface
,
135 REFIID iid
, void *data
, const D2D1_BITMAP_PROPERTIES
*desc
, ID2D1Bitmap
**bitmap
)
137 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
139 TRACE("iface %p, iid %s, data %p, desc %p, bitmap %p.\n",
140 iface
, debugstr_guid(iid
), data
, desc
, bitmap
);
142 return ID2D1RenderTarget_CreateSharedBitmap(render_target
->dxgi_target
, iid
, data
, desc
, bitmap
);
145 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_CreateBitmapBrush(ID2D1DCRenderTarget
*iface
,
146 ID2D1Bitmap
*bitmap
, const D2D1_BITMAP_BRUSH_PROPERTIES
*bitmap_brush_desc
,
147 const D2D1_BRUSH_PROPERTIES
*brush_desc
, ID2D1BitmapBrush
**brush
)
149 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
151 TRACE("iface %p, bitmap %p, bitmap_brush_desc %p, brush_desc %p, brush %p.\n",
152 iface
, bitmap
, bitmap_brush_desc
, brush_desc
, brush
);
154 return ID2D1RenderTarget_CreateBitmapBrush(render_target
->dxgi_target
,
155 bitmap
, bitmap_brush_desc
, brush_desc
, brush
);
158 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_CreateSolidColorBrush(ID2D1DCRenderTarget
*iface
,
159 const D2D1_COLOR_F
*color
, const D2D1_BRUSH_PROPERTIES
*desc
, ID2D1SolidColorBrush
**brush
)
161 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
163 TRACE("iface %p, color %p, desc %p, brush %p.\n", iface
, color
, desc
, brush
);
165 return ID2D1RenderTarget_CreateSolidColorBrush(render_target
->dxgi_target
, color
, desc
, brush
);
168 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_CreateGradientStopCollection(ID2D1DCRenderTarget
*iface
,
169 const D2D1_GRADIENT_STOP
*stops
, UINT32 stop_count
, D2D1_GAMMA gamma
, D2D1_EXTEND_MODE extend_mode
,
170 ID2D1GradientStopCollection
**gradient
)
172 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
174 TRACE("iface %p, stops %p, stop_count %u, gamma %#x, extend_mode %#x, gradient %p.\n",
175 iface
, stops
, stop_count
, gamma
, extend_mode
, gradient
);
177 return ID2D1RenderTarget_CreateGradientStopCollection(render_target
->dxgi_target
,
178 stops
, stop_count
, gamma
, extend_mode
, gradient
);
181 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_CreateLinearGradientBrush(ID2D1DCRenderTarget
*iface
,
182 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES
*gradient_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
183 ID2D1GradientStopCollection
*gradient
, ID2D1LinearGradientBrush
**brush
)
185 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
187 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
188 iface
, gradient_brush_desc
, brush_desc
, gradient
, brush
);
190 return ID2D1RenderTarget_CreateLinearGradientBrush(render_target
->dxgi_target
,
191 gradient_brush_desc
, brush_desc
, gradient
, brush
);
194 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_CreateRadialGradientBrush(ID2D1DCRenderTarget
*iface
,
195 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES
*gradient_brush_desc
, const D2D1_BRUSH_PROPERTIES
*brush_desc
,
196 ID2D1GradientStopCollection
*gradient
, ID2D1RadialGradientBrush
**brush
)
198 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
200 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
201 iface
, gradient_brush_desc
, brush_desc
, gradient
, brush
);
203 return ID2D1RenderTarget_CreateRadialGradientBrush(render_target
->dxgi_target
,
204 gradient_brush_desc
, brush_desc
, gradient
, brush
);
207 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_CreateCompatibleRenderTarget(ID2D1DCRenderTarget
*iface
,
208 const D2D1_SIZE_F
*size
, const D2D1_SIZE_U
*pixel_size
, const D2D1_PIXEL_FORMAT
*format
,
209 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options
, ID2D1BitmapRenderTarget
**render_target
)
211 struct d2d_dc_render_target
*rt
= impl_from_ID2D1DCRenderTarget(iface
);
213 TRACE("iface %p, size %p, pixel_size %p, format %p, options %#x, render_target %p,\n",
214 iface
, size
, pixel_size
, format
, options
, render_target
);
216 return ID2D1RenderTarget_CreateCompatibleRenderTarget(rt
->dxgi_target
,
217 size
, pixel_size
, format
, options
, render_target
);
220 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_CreateLayer(ID2D1DCRenderTarget
*iface
,
221 const D2D1_SIZE_F
*size
, ID2D1Layer
**layer
)
223 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
225 TRACE("iface %p, size %p, layer %p.\n", iface
, size
, layer
);
227 return ID2D1RenderTarget_CreateLayer(render_target
->dxgi_target
, size
, layer
);
230 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_CreateMesh(ID2D1DCRenderTarget
*iface
, ID2D1Mesh
**mesh
)
232 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
234 TRACE("iface %p, mesh %p.\n", iface
, mesh
);
236 return ID2D1RenderTarget_CreateMesh(render_target
->dxgi_target
, mesh
);
239 static void STDMETHODCALLTYPE
d2d_dc_render_target_DrawLine(ID2D1DCRenderTarget
*iface
,
240 D2D1_POINT_2F p0
, D2D1_POINT_2F p1
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
242 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
244 TRACE("iface %p, p0 {%.8e, %.8e}, p1 {%.8e, %.8e}, brush %p, stroke_width %.8e, stroke_style %p.\n",
245 iface
, p0
.x
, p0
.y
, p1
.x
, p1
.y
, brush
, stroke_width
, stroke_style
);
247 ID2D1RenderTarget_DrawLine(render_target
->dxgi_target
, p0
, p1
, brush
, stroke_width
, stroke_style
);
250 static void STDMETHODCALLTYPE
d2d_dc_render_target_DrawRectangle(ID2D1DCRenderTarget
*iface
,
251 const D2D1_RECT_F
*rect
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
253 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
255 TRACE("iface %p, rect %s, brush %p, stroke_width %.8e, stroke_style %p.\n",
256 iface
, debug_d2d_rect_f(rect
), brush
, stroke_width
, stroke_style
);
258 ID2D1RenderTarget_DrawRectangle(render_target
->dxgi_target
, rect
, brush
, stroke_width
, stroke_style
);
261 static void STDMETHODCALLTYPE
d2d_dc_render_target_FillRectangle(ID2D1DCRenderTarget
*iface
,
262 const D2D1_RECT_F
*rect
, ID2D1Brush
*brush
)
264 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
266 TRACE("iface %p, rect %s, brush %p.\n", iface
, debug_d2d_rect_f(rect
), brush
);
268 ID2D1RenderTarget_FillRectangle(render_target
->dxgi_target
, rect
, brush
);
271 static void STDMETHODCALLTYPE
d2d_dc_render_target_DrawRoundedRectangle(ID2D1DCRenderTarget
*iface
,
272 const D2D1_ROUNDED_RECT
*rect
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
274 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
276 TRACE("iface %p, rect %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
277 iface
, rect
, brush
, stroke_width
, stroke_style
);
279 ID2D1RenderTarget_DrawRoundedRectangle(render_target
->dxgi_target
, rect
, brush
, stroke_width
, stroke_style
);
282 static void STDMETHODCALLTYPE
d2d_dc_render_target_FillRoundedRectangle(ID2D1DCRenderTarget
*iface
,
283 const D2D1_ROUNDED_RECT
*rect
, ID2D1Brush
*brush
)
285 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
287 TRACE("iface %p, rect %p, brush %p.\n", iface
, rect
, brush
);
289 ID2D1RenderTarget_FillRoundedRectangle(render_target
->dxgi_target
, rect
, brush
);
292 static void STDMETHODCALLTYPE
d2d_dc_render_target_DrawEllipse(ID2D1DCRenderTarget
*iface
,
293 const D2D1_ELLIPSE
*ellipse
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
295 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
297 TRACE("iface %p, ellipse %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
298 iface
, ellipse
, brush
, stroke_width
, stroke_style
);
300 ID2D1RenderTarget_DrawEllipse(render_target
->dxgi_target
, ellipse
, brush
, stroke_width
, stroke_style
);
303 static void STDMETHODCALLTYPE
d2d_dc_render_target_FillEllipse(ID2D1DCRenderTarget
*iface
,
304 const D2D1_ELLIPSE
*ellipse
, ID2D1Brush
*brush
)
306 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
308 TRACE("iface %p, ellipse %p, brush %p.\n", iface
, ellipse
, brush
);
310 ID2D1RenderTarget_FillEllipse(render_target
->dxgi_target
, ellipse
, brush
);
313 static void STDMETHODCALLTYPE
d2d_dc_render_target_DrawGeometry(ID2D1DCRenderTarget
*iface
,
314 ID2D1Geometry
*geometry
, ID2D1Brush
*brush
, float stroke_width
, ID2D1StrokeStyle
*stroke_style
)
316 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
318 TRACE("iface %p, geometry %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
319 iface
, geometry
, brush
, stroke_width
, stroke_style
);
321 ID2D1RenderTarget_DrawGeometry(render_target
->dxgi_target
, geometry
, brush
, stroke_width
, stroke_style
);
324 static void STDMETHODCALLTYPE
d2d_dc_render_target_FillGeometry(ID2D1DCRenderTarget
*iface
,
325 ID2D1Geometry
*geometry
, ID2D1Brush
*brush
, ID2D1Brush
*opacity_brush
)
327 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
329 TRACE("iface %p, geometry %p, brush %p, opacity_brush %p.\n", iface
, geometry
, brush
, opacity_brush
);
331 ID2D1RenderTarget_FillGeometry(render_target
->dxgi_target
, geometry
, brush
, opacity_brush
);
334 static void STDMETHODCALLTYPE
d2d_dc_render_target_FillMesh(ID2D1DCRenderTarget
*iface
,
335 ID2D1Mesh
*mesh
, ID2D1Brush
*brush
)
337 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
339 TRACE("iface %p, mesh %p, brush %p.\n", iface
, mesh
, brush
);
341 ID2D1RenderTarget_FillMesh(render_target
->dxgi_target
, mesh
, brush
);
344 static void STDMETHODCALLTYPE
d2d_dc_render_target_FillOpacityMask(ID2D1DCRenderTarget
*iface
,
345 ID2D1Bitmap
*mask
, ID2D1Brush
*brush
, D2D1_OPACITY_MASK_CONTENT content
,
346 const D2D1_RECT_F
*dst_rect
, const D2D1_RECT_F
*src_rect
)
348 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
350 TRACE("iface %p, mask %p, brush %p, content %#x, dst_rect %s, src_rect %s.\n",
351 iface
, mask
, brush
, content
, debug_d2d_rect_f(dst_rect
), debug_d2d_rect_f(src_rect
));
353 ID2D1RenderTarget_FillOpacityMask(render_target
->dxgi_target
,
354 mask
, brush
, content
, dst_rect
, src_rect
);
357 static void STDMETHODCALLTYPE
d2d_dc_render_target_DrawBitmap(ID2D1DCRenderTarget
*iface
,
358 ID2D1Bitmap
*bitmap
, const D2D1_RECT_F
*dst_rect
, float opacity
,
359 D2D1_BITMAP_INTERPOLATION_MODE interpolation_mode
, const D2D1_RECT_F
*src_rect
)
361 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
363 TRACE("iface %p, bitmap %p, dst_rect %s, opacity %.8e, interpolation_mode %#x, src_rect %s.\n",
364 iface
, bitmap
, debug_d2d_rect_f(dst_rect
), opacity
, interpolation_mode
, debug_d2d_rect_f(src_rect
));
366 ID2D1RenderTarget_DrawBitmap(render_target
->dxgi_target
,
367 bitmap
, dst_rect
, opacity
, interpolation_mode
, src_rect
);
370 static void STDMETHODCALLTYPE
d2d_dc_render_target_DrawText(ID2D1DCRenderTarget
*iface
,
371 const WCHAR
*string
, UINT32 string_len
, IDWriteTextFormat
*text_format
, const D2D1_RECT_F
*layout_rect
,
372 ID2D1Brush
*brush
, D2D1_DRAW_TEXT_OPTIONS options
, DWRITE_MEASURING_MODE measuring_mode
)
374 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
376 TRACE("iface %p, string %s, string_len %u, text_format %p, layout_rect %s, "
377 "brush %p, options %#x, measuring_mode %#x.\n",
378 iface
, debugstr_wn(string
, string_len
), string_len
, text_format
, debug_d2d_rect_f(layout_rect
),
379 brush
, options
, measuring_mode
);
381 ID2D1RenderTarget_DrawText(render_target
->dxgi_target
, string
, string_len
,
382 text_format
, layout_rect
, brush
, options
, measuring_mode
);
385 static void STDMETHODCALLTYPE
d2d_dc_render_target_DrawTextLayout(ID2D1DCRenderTarget
*iface
,
386 D2D1_POINT_2F origin
, IDWriteTextLayout
*layout
, ID2D1Brush
*brush
, D2D1_DRAW_TEXT_OPTIONS options
)
388 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
390 TRACE("iface %p, origin {%.8e, %.8e}, layout %p, brush %p, options %#x.\n",
391 iface
, origin
.x
, origin
.y
, layout
, brush
, options
);
393 ID2D1RenderTarget_DrawTextLayout(render_target
->dxgi_target
, origin
, layout
, brush
, options
);
396 static void STDMETHODCALLTYPE
d2d_dc_render_target_DrawGlyphRun(ID2D1DCRenderTarget
*iface
,
397 D2D1_POINT_2F baseline_origin
, const DWRITE_GLYPH_RUN
*glyph_run
, ID2D1Brush
*brush
,
398 DWRITE_MEASURING_MODE measuring_mode
)
400 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
402 TRACE("iface %p, baseline_origin {%.8e, %.8e}, glyph_run %p, brush %p, measuring_mode %#x.\n",
403 iface
, baseline_origin
.x
, baseline_origin
.y
, glyph_run
, brush
, measuring_mode
);
405 ID2D1RenderTarget_DrawGlyphRun(render_target
->dxgi_target
,
406 baseline_origin
, glyph_run
, brush
, measuring_mode
);
409 static void STDMETHODCALLTYPE
d2d_dc_render_target_SetTransform(ID2D1DCRenderTarget
*iface
,
410 const D2D1_MATRIX_3X2_F
*transform
)
412 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
414 TRACE("iface %p, transform %p.\n", iface
, transform
);
416 ID2D1RenderTarget_SetTransform(render_target
->dxgi_target
, transform
);
419 static void STDMETHODCALLTYPE
d2d_dc_render_target_GetTransform(ID2D1DCRenderTarget
*iface
,
420 D2D1_MATRIX_3X2_F
*transform
)
422 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
424 TRACE("iface %p, transform %p.\n", iface
, transform
);
426 ID2D1RenderTarget_GetTransform(render_target
->dxgi_target
, transform
);
429 static void STDMETHODCALLTYPE
d2d_dc_render_target_SetAntialiasMode(ID2D1DCRenderTarget
*iface
,
430 D2D1_ANTIALIAS_MODE antialias_mode
)
432 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
434 TRACE("iface %p, antialias_mode %#x.\n", iface
, antialias_mode
);
436 ID2D1RenderTarget_SetAntialiasMode(render_target
->dxgi_target
, antialias_mode
);
439 static D2D1_ANTIALIAS_MODE STDMETHODCALLTYPE
d2d_dc_render_target_GetAntialiasMode(ID2D1DCRenderTarget
*iface
)
441 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
443 TRACE("iface %p.\n", iface
);
445 return ID2D1RenderTarget_GetAntialiasMode(render_target
->dxgi_target
);
448 static void STDMETHODCALLTYPE
d2d_dc_render_target_SetTextAntialiasMode(ID2D1DCRenderTarget
*iface
,
449 D2D1_TEXT_ANTIALIAS_MODE antialias_mode
)
451 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
453 TRACE("iface %p, antialias_mode %#x.\n", iface
, antialias_mode
);
455 ID2D1RenderTarget_SetTextAntialiasMode(render_target
->dxgi_target
, antialias_mode
);
458 static D2D1_TEXT_ANTIALIAS_MODE STDMETHODCALLTYPE
d2d_dc_render_target_GetTextAntialiasMode(ID2D1DCRenderTarget
*iface
)
460 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
462 TRACE("iface %p.\n", iface
);
464 return ID2D1RenderTarget_GetTextAntialiasMode(render_target
->dxgi_target
);
467 static void STDMETHODCALLTYPE
d2d_dc_render_target_SetTextRenderingParams(ID2D1DCRenderTarget
*iface
,
468 IDWriteRenderingParams
*text_rendering_params
)
470 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
472 TRACE("iface %p, text_rendering_params %p.\n", iface
, text_rendering_params
);
474 ID2D1RenderTarget_SetTextRenderingParams(render_target
->dxgi_target
, text_rendering_params
);
477 static void STDMETHODCALLTYPE
d2d_dc_render_target_GetTextRenderingParams(ID2D1DCRenderTarget
*iface
,
478 IDWriteRenderingParams
**text_rendering_params
)
480 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
482 TRACE("iface %p, text_rendering_params %p.\n", iface
, text_rendering_params
);
484 ID2D1RenderTarget_GetTextRenderingParams(render_target
->dxgi_target
, text_rendering_params
);
487 static void STDMETHODCALLTYPE
d2d_dc_render_target_SetTags(ID2D1DCRenderTarget
*iface
, D2D1_TAG tag1
, D2D1_TAG tag2
)
489 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
491 TRACE("iface %p, tag1 %s, tag2 %s.\n", iface
, wine_dbgstr_longlong(tag1
), wine_dbgstr_longlong(tag2
));
493 ID2D1RenderTarget_SetTags(render_target
->dxgi_target
, tag1
, tag2
);
496 static void STDMETHODCALLTYPE
d2d_dc_render_target_GetTags(ID2D1DCRenderTarget
*iface
, D2D1_TAG
*tag1
, D2D1_TAG
*tag2
)
498 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
500 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface
, tag1
, tag2
);
502 ID2D1RenderTarget_GetTags(render_target
->dxgi_target
, tag1
, tag2
);
505 static void STDMETHODCALLTYPE
d2d_dc_render_target_PushLayer(ID2D1DCRenderTarget
*iface
,
506 const D2D1_LAYER_PARAMETERS
*layer_parameters
, ID2D1Layer
*layer
)
508 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
510 TRACE("iface %p, layer_parameters %p, layer %p.\n", iface
, layer_parameters
, layer
);
512 ID2D1RenderTarget_PushLayer(render_target
->dxgi_target
, layer_parameters
, layer
);
515 static void STDMETHODCALLTYPE
d2d_dc_render_target_PopLayer(ID2D1DCRenderTarget
*iface
)
517 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
519 TRACE("iface %p.\n", iface
);
521 ID2D1RenderTarget_PopLayer(render_target
->dxgi_target
);
524 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_Flush(ID2D1DCRenderTarget
*iface
, D2D1_TAG
*tag1
, D2D1_TAG
*tag2
)
526 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
529 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface
, tag1
, tag2
);
531 hr
= ID2D1RenderTarget_Flush(render_target
->dxgi_target
, tag1
, tag2
);
532 sync_bitmap(render_target
);
537 static void STDMETHODCALLTYPE
d2d_dc_render_target_SaveDrawingState(ID2D1DCRenderTarget
*iface
,
538 ID2D1DrawingStateBlock
*state_block
)
540 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
542 TRACE("iface %p, state_block %p.\n", iface
, state_block
);
544 ID2D1RenderTarget_SaveDrawingState(render_target
->dxgi_target
, state_block
);
547 static void STDMETHODCALLTYPE
d2d_dc_render_target_RestoreDrawingState(ID2D1DCRenderTarget
*iface
,
548 ID2D1DrawingStateBlock
*state_block
)
550 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
552 TRACE("iface %p, state_block %p.\n", iface
, state_block
);
554 ID2D1RenderTarget_RestoreDrawingState(render_target
->dxgi_target
, state_block
);
557 static void STDMETHODCALLTYPE
d2d_dc_render_target_PushAxisAlignedClip(ID2D1DCRenderTarget
*iface
,
558 const D2D1_RECT_F
*clip_rect
, D2D1_ANTIALIAS_MODE antialias_mode
)
560 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
562 TRACE("iface %p, clip_rect %s, antialias_mode %#x.\n", iface
, debug_d2d_rect_f(clip_rect
), antialias_mode
);
564 ID2D1RenderTarget_PushAxisAlignedClip(render_target
->dxgi_target
, clip_rect
, antialias_mode
);
567 static void STDMETHODCALLTYPE
d2d_dc_render_target_PopAxisAlignedClip(ID2D1DCRenderTarget
*iface
)
569 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
571 TRACE("iface %p.\n", iface
);
573 ID2D1RenderTarget_PopAxisAlignedClip(render_target
->dxgi_target
);
576 static void STDMETHODCALLTYPE
d2d_dc_render_target_Clear(ID2D1DCRenderTarget
*iface
, const D2D1_COLOR_F
*color
)
578 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
580 TRACE("iface %p, color %p.\n", iface
, color
);
582 ID2D1RenderTarget_Clear(render_target
->dxgi_target
, color
);
585 static void STDMETHODCALLTYPE
d2d_dc_render_target_BeginDraw(ID2D1DCRenderTarget
*iface
)
587 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
589 TRACE("iface %p.\n", iface
);
591 ID2D1RenderTarget_BeginDraw(render_target
->dxgi_target
);
594 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_EndDraw(ID2D1DCRenderTarget
*iface
,
595 D2D1_TAG
*tag1
, D2D1_TAG
*tag2
)
597 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
600 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface
, tag1
, tag2
);
602 if (!render_target
->hdc
)
603 return D2DERR_WRONG_STATE
;
605 hr
= ID2D1RenderTarget_EndDraw(render_target
->dxgi_target
, tag1
, tag2
);
606 sync_bitmap(render_target
);
611 static D2D1_PIXEL_FORMAT
* STDMETHODCALLTYPE
d2d_dc_render_target_GetPixelFormat(ID2D1DCRenderTarget
*iface
,
612 D2D1_PIXEL_FORMAT
*format
)
614 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
616 TRACE("iface %p, format %p.\n", iface
, format
);
618 *format
= ID2D1RenderTarget_GetPixelFormat(render_target
->dxgi_target
);
622 static void STDMETHODCALLTYPE
d2d_dc_render_target_SetDpi(ID2D1DCRenderTarget
*iface
, float dpi_x
, float dpi_y
)
624 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
626 TRACE("iface %p, dpi_x %.8e, dpi_y %.8e.\n", iface
, dpi_x
, dpi_y
);
628 ID2D1RenderTarget_SetDpi(render_target
->dxgi_target
, dpi_x
, dpi_y
);
631 static void STDMETHODCALLTYPE
d2d_dc_render_target_GetDpi(ID2D1DCRenderTarget
*iface
, float *dpi_x
, float *dpi_y
)
633 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
635 TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface
, dpi_x
, dpi_y
);
637 ID2D1RenderTarget_GetDpi(render_target
->dxgi_target
, dpi_x
, dpi_y
);
640 static D2D1_SIZE_F
* STDMETHODCALLTYPE
d2d_dc_render_target_GetSize(ID2D1DCRenderTarget
*iface
, D2D1_SIZE_F
*size
)
642 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
644 TRACE("iface %p, size %p.\n", iface
, size
);
646 if (render_target
->hdc
)
647 *size
= ID2D1RenderTarget_GetSize(render_target
->dxgi_target
);
649 size
->width
= size
->height
= 0.0f
;
654 static D2D1_SIZE_U
* STDMETHODCALLTYPE
d2d_dc_render_target_GetPixelSize(ID2D1DCRenderTarget
*iface
,
655 D2D1_SIZE_U
*pixel_size
)
657 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
659 TRACE("iface %p, pixel_size %p.\n", iface
, pixel_size
);
661 if (render_target
->hdc
)
662 *pixel_size
= ID2D1RenderTarget_GetPixelSize(render_target
->dxgi_target
);
664 pixel_size
->width
= pixel_size
->height
= 0;
669 static UINT32 STDMETHODCALLTYPE
d2d_dc_render_target_GetMaximumBitmapSize(ID2D1DCRenderTarget
*iface
)
671 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
673 TRACE("iface %p.\n", iface
);
675 return ID2D1RenderTarget_GetMaximumBitmapSize(render_target
->dxgi_target
);
678 static BOOL STDMETHODCALLTYPE
d2d_dc_render_target_IsSupported(ID2D1DCRenderTarget
*iface
,
679 const D2D1_RENDER_TARGET_PROPERTIES
*desc
)
681 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
683 TRACE("iface %p, desc %p.\n", iface
, desc
);
685 return ID2D1RenderTarget_IsSupported(render_target
->dxgi_target
, desc
);
688 static HRESULT STDMETHODCALLTYPE
d2d_dc_render_target_BindDC(ID2D1DCRenderTarget
*iface
,
689 const HDC hdc
, const RECT
*rect
)
691 struct d2d_dc_render_target
*render_target
= impl_from_ID2D1DCRenderTarget(iface
);
692 D3D10_TEXTURE2D_DESC texture_desc
;
693 IDXGISurface1
*dxgi_surface
;
694 ID3D10Texture2D
*texture
;
695 ID3D10Device
*device
;
698 TRACE("iface %p, hdc %p, rect %s.\n", iface
, hdc
, wine_dbgstr_rect(rect
));
703 /* Recreate surface using specified size and original texture description. */
704 if (FAILED(hr
= IDXGISurface1_QueryInterface(render_target
->dxgi_surface
, &IID_ID3D10Texture2D
, (void **)&texture
)))
706 WARN("Failed to get texture interface, hr %#x.\n", hr
);
710 ID3D10Texture2D_GetDesc(texture
, &texture_desc
);
711 ID3D10Texture2D_Release(texture
);
712 texture_desc
.Width
= rect
->right
- rect
->left
;
713 texture_desc
.Height
= rect
->bottom
- rect
->top
;
715 if (FAILED(hr
= IDXGISurface1_GetDevice(render_target
->dxgi_surface
, &IID_ID3D10Device
, (void **)&device
)))
717 WARN("Failed to get device from dxgi surface, hr %#x.\n", hr
);
721 hr
= ID3D10Device_CreateTexture2D(device
, &texture_desc
, NULL
, &texture
);
722 ID3D10Device_Release(device
);
725 WARN("Failed to create texture, hr %#x.\n", hr
);
729 hr
= ID3D10Texture2D_QueryInterface(texture
, &IID_IDXGISurface1
, (void **)&dxgi_surface
);
730 ID3D10Texture2D_Release(texture
);
733 WARN("Failed to get surface interface from a texture, hr %#x.\n", hr
);
737 /* Switch dxgi target to new surface. */
738 if (FAILED(hr
= d2d_d3d_render_target_create_rtv(render_target
->dxgi_target
, dxgi_surface
)))
740 WARN("Failed to set new surface, hr %#x.\n", hr
);
741 IDXGISurface1_Release(dxgi_surface
);
745 IDXGISurface1_Release(render_target
->dxgi_surface
);
746 render_target
->dxgi_surface
= dxgi_surface
;
748 render_target
->hdc
= hdc
;
749 render_target
->dst_rect
= *rect
;
754 static const struct ID2D1DCRenderTargetVtbl d2d_dc_render_target_vtbl
=
756 d2d_dc_render_target_QueryInterface
,
757 d2d_dc_render_target_AddRef
,
758 d2d_dc_render_target_Release
,
759 d2d_dc_render_target_GetFactory
,
760 d2d_dc_render_target_CreateBitmap
,
761 d2d_dc_render_target_CreateBitmapFromWicBitmap
,
762 d2d_dc_render_target_CreateSharedBitmap
,
763 d2d_dc_render_target_CreateBitmapBrush
,
764 d2d_dc_render_target_CreateSolidColorBrush
,
765 d2d_dc_render_target_CreateGradientStopCollection
,
766 d2d_dc_render_target_CreateLinearGradientBrush
,
767 d2d_dc_render_target_CreateRadialGradientBrush
,
768 d2d_dc_render_target_CreateCompatibleRenderTarget
,
769 d2d_dc_render_target_CreateLayer
,
770 d2d_dc_render_target_CreateMesh
,
771 d2d_dc_render_target_DrawLine
,
772 d2d_dc_render_target_DrawRectangle
,
773 d2d_dc_render_target_FillRectangle
,
774 d2d_dc_render_target_DrawRoundedRectangle
,
775 d2d_dc_render_target_FillRoundedRectangle
,
776 d2d_dc_render_target_DrawEllipse
,
777 d2d_dc_render_target_FillEllipse
,
778 d2d_dc_render_target_DrawGeometry
,
779 d2d_dc_render_target_FillGeometry
,
780 d2d_dc_render_target_FillMesh
,
781 d2d_dc_render_target_FillOpacityMask
,
782 d2d_dc_render_target_DrawBitmap
,
783 d2d_dc_render_target_DrawText
,
784 d2d_dc_render_target_DrawTextLayout
,
785 d2d_dc_render_target_DrawGlyphRun
,
786 d2d_dc_render_target_SetTransform
,
787 d2d_dc_render_target_GetTransform
,
788 d2d_dc_render_target_SetAntialiasMode
,
789 d2d_dc_render_target_GetAntialiasMode
,
790 d2d_dc_render_target_SetTextAntialiasMode
,
791 d2d_dc_render_target_GetTextAntialiasMode
,
792 d2d_dc_render_target_SetTextRenderingParams
,
793 d2d_dc_render_target_GetTextRenderingParams
,
794 d2d_dc_render_target_SetTags
,
795 d2d_dc_render_target_GetTags
,
796 d2d_dc_render_target_PushLayer
,
797 d2d_dc_render_target_PopLayer
,
798 d2d_dc_render_target_Flush
,
799 d2d_dc_render_target_SaveDrawingState
,
800 d2d_dc_render_target_RestoreDrawingState
,
801 d2d_dc_render_target_PushAxisAlignedClip
,
802 d2d_dc_render_target_PopAxisAlignedClip
,
803 d2d_dc_render_target_Clear
,
804 d2d_dc_render_target_BeginDraw
,
805 d2d_dc_render_target_EndDraw
,
806 d2d_dc_render_target_GetPixelFormat
,
807 d2d_dc_render_target_SetDpi
,
808 d2d_dc_render_target_GetDpi
,
809 d2d_dc_render_target_GetSize
,
810 d2d_dc_render_target_GetPixelSize
,
811 d2d_dc_render_target_GetMaximumBitmapSize
,
812 d2d_dc_render_target_IsSupported
,
813 d2d_dc_render_target_BindDC
,
816 HRESULT
d2d_dc_render_target_init(struct d2d_dc_render_target
*render_target
, ID2D1Factory
*factory
,
817 ID3D10Device1
*device
, const D2D1_RENDER_TARGET_PROPERTIES
*desc
)
819 D3D10_TEXTURE2D_DESC texture_desc
;
820 ID3D10Texture2D
*texture
;
823 render_target
->ID2D1DCRenderTarget_iface
.lpVtbl
= &d2d_dc_render_target_vtbl
;
824 render_target
->refcount
= 1;
826 /* Set with BindDC(). */
827 SetRectEmpty(&render_target
->dst_rect
);
828 render_target
->hdc
= NULL
;
830 /* Dummy 1x1 texture, recreated on BindDC(). */
831 texture_desc
.Width
= 1;
832 texture_desc
.Height
= 1;
833 texture_desc
.MipLevels
= 1;
834 texture_desc
.ArraySize
= 1;
836 texture_desc
.Format
= desc
->pixelFormat
.format
;
837 switch (texture_desc
.Format
)
839 case DXGI_FORMAT_B8G8R8A8_UNORM
:
840 if (desc
->pixelFormat
.alphaMode
== D2D1_ALPHA_MODE_PREMULTIPLIED
841 || desc
->pixelFormat
.alphaMode
== D2D1_ALPHA_MODE_IGNORE
)
845 FIXME("Unhandled format %#x, alpha mode %u.\n", texture_desc
.Format
, desc
->pixelFormat
.alphaMode
);
846 return D2DERR_UNSUPPORTED_PIXEL_FORMAT
;
849 texture_desc
.SampleDesc
.Count
= 1;
850 texture_desc
.SampleDesc
.Quality
= 0;
851 texture_desc
.Usage
= D3D10_USAGE_DEFAULT
;
852 texture_desc
.BindFlags
= D3D10_BIND_RENDER_TARGET
| D3D10_BIND_SHADER_RESOURCE
;
853 texture_desc
.CPUAccessFlags
= 0;
854 texture_desc
.MiscFlags
= D3D10_RESOURCE_MISC_GDI_COMPATIBLE
;
856 if (FAILED(hr
= ID3D10Device1_CreateTexture2D(device
, &texture_desc
, NULL
, &texture
)))
858 WARN("Failed to create texture, hr %#x.\n", hr
);
862 hr
= ID3D10Texture2D_QueryInterface(texture
, &IID_IDXGISurface1
, (void **)&render_target
->dxgi_surface
);
863 ID3D10Texture2D_Release(texture
);
866 WARN("Failed to get DXGI surface interface, hr %#x.\n", hr
);
870 if (FAILED(hr
= d2d_d3d_create_render_target(factory
, (IDXGISurface
*)render_target
->dxgi_surface
,
871 (IUnknown
*)&render_target
->ID2D1DCRenderTarget_iface
, desc
, &render_target
->dxgi_target
)))
873 WARN("Failed to create DXGI surface render target, hr %#x.\n", hr
);
874 IDXGISurface1_Release(render_target
->dxgi_surface
);