mfplay: Implement GetCharacteristics().
[wine/zf.git] / dlls / d2d1 / dc_render_target.c
blob47aa99697d73d4d78863e946cd5d91566322baa5
1 /*
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
20 #include "d2d1_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(d2d);
24 static inline struct d2d_dc_render_target *impl_from_IUnknown(IUnknown *iface)
26 return CONTAINING_RECORD(iface, struct d2d_dc_render_target, ID2D1DCRenderTarget_iface);
29 static HRESULT d2d_dc_render_target_present(IUnknown *outer_unknown)
31 struct d2d_dc_render_target *render_target = impl_from_IUnknown(outer_unknown);
32 const RECT *dst_rect = &render_target->dst_rect;
33 RECT empty_rect;
34 HDC src_hdc;
35 HRESULT hr;
37 if (!render_target->hdc)
38 return D2DERR_WRONG_STATE;
40 if (FAILED(hr = IDXGISurface1_GetDC(render_target->dxgi_surface, FALSE, &src_hdc)))
42 WARN("GetDC() failed, %#x.\n", hr);
43 return S_OK;
46 BitBlt(render_target->hdc, dst_rect->left, dst_rect->top, dst_rect->right - dst_rect->left,
47 dst_rect->bottom - dst_rect->top, src_hdc, 0, 0, SRCCOPY);
49 SetRectEmpty(&empty_rect);
50 IDXGISurface1_ReleaseDC(render_target->dxgi_surface, &empty_rect);
52 return S_OK;
55 static inline struct d2d_dc_render_target *impl_from_ID2D1DCRenderTarget(ID2D1DCRenderTarget *iface)
57 return CONTAINING_RECORD(iface, struct d2d_dc_render_target, ID2D1DCRenderTarget_iface);
60 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_QueryInterface(ID2D1DCRenderTarget *iface, REFIID iid, void **out)
62 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
64 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
66 if (IsEqualGUID(iid, &IID_ID2D1DCRenderTarget)
67 || IsEqualGUID(iid, &IID_ID2D1RenderTarget)
68 || IsEqualGUID(iid, &IID_ID2D1Resource)
69 || IsEqualGUID(iid, &IID_IUnknown))
71 ID2D1DCRenderTarget_AddRef(iface);
72 *out = iface;
73 return S_OK;
76 return IUnknown_QueryInterface(render_target->dxgi_inner, iid, out);
79 static ULONG STDMETHODCALLTYPE d2d_dc_render_target_AddRef(ID2D1DCRenderTarget *iface)
81 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
82 ULONG refcount = InterlockedIncrement(&render_target->refcount);
84 TRACE("%p increasing refcount to %u.\n", iface, refcount);
86 return refcount;
89 static ULONG STDMETHODCALLTYPE d2d_dc_render_target_Release(ID2D1DCRenderTarget *iface)
91 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
92 ULONG refcount = InterlockedDecrement(&render_target->refcount);
94 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
96 if (!refcount)
98 IUnknown_Release(render_target->dxgi_inner);
99 if (render_target->dxgi_surface)
100 IDXGISurface1_Release(render_target->dxgi_surface);
101 ID3D10Device1_Release(render_target->d3d_device);
102 heap_free(render_target);
105 return refcount;
108 static void STDMETHODCALLTYPE d2d_dc_render_target_GetFactory(ID2D1DCRenderTarget *iface, ID2D1Factory **factory)
110 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
112 TRACE("iface %p, factory %p.\n", iface, factory);
114 ID2D1RenderTarget_GetFactory(render_target->dxgi_target, factory);
117 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_CreateBitmap(ID2D1DCRenderTarget *iface,
118 D2D1_SIZE_U size, const void *src_data, UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
120 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
122 TRACE("iface %p, size {%u, %u}, src_data %p, pitch %u, desc %p, bitmap %p.\n",
123 iface, size.width, size.height, src_data, pitch, desc, bitmap);
125 return ID2D1RenderTarget_CreateBitmap(render_target->dxgi_target, size, src_data, pitch, desc, bitmap);
128 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_CreateBitmapFromWicBitmap(ID2D1DCRenderTarget *iface,
129 IWICBitmapSource *bitmap_source, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
131 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
133 TRACE("iface %p, bitmap_source %p, desc %p, bitmap %p.\n",
134 iface, bitmap_source, desc, bitmap);
136 return ID2D1RenderTarget_CreateBitmapFromWicBitmap(render_target->dxgi_target, bitmap_source, desc, bitmap);
139 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_CreateSharedBitmap(ID2D1DCRenderTarget *iface,
140 REFIID iid, void *data, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
142 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
144 TRACE("iface %p, iid %s, data %p, desc %p, bitmap %p.\n",
145 iface, debugstr_guid(iid), data, desc, bitmap);
147 return ID2D1RenderTarget_CreateSharedBitmap(render_target->dxgi_target, iid, data, desc, bitmap);
150 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_CreateBitmapBrush(ID2D1DCRenderTarget *iface,
151 ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc,
152 const D2D1_BRUSH_PROPERTIES *brush_desc, ID2D1BitmapBrush **brush)
154 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
156 TRACE("iface %p, bitmap %p, bitmap_brush_desc %p, brush_desc %p, brush %p.\n",
157 iface, bitmap, bitmap_brush_desc, brush_desc, brush);
159 return ID2D1RenderTarget_CreateBitmapBrush(render_target->dxgi_target,
160 bitmap, bitmap_brush_desc, brush_desc, brush);
163 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_CreateSolidColorBrush(ID2D1DCRenderTarget *iface,
164 const D2D1_COLOR_F *color, const D2D1_BRUSH_PROPERTIES *desc, ID2D1SolidColorBrush **brush)
166 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
168 TRACE("iface %p, color %p, desc %p, brush %p.\n", iface, color, desc, brush);
170 return ID2D1RenderTarget_CreateSolidColorBrush(render_target->dxgi_target, color, desc, brush);
173 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_CreateGradientStopCollection(ID2D1DCRenderTarget *iface,
174 const D2D1_GRADIENT_STOP *stops, UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode,
175 ID2D1GradientStopCollection **gradient)
177 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
179 TRACE("iface %p, stops %p, stop_count %u, gamma %#x, extend_mode %#x, gradient %p.\n",
180 iface, stops, stop_count, gamma, extend_mode, gradient);
182 return ID2D1RenderTarget_CreateGradientStopCollection(render_target->dxgi_target,
183 stops, stop_count, gamma, extend_mode, gradient);
186 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_CreateLinearGradientBrush(ID2D1DCRenderTarget *iface,
187 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
188 ID2D1GradientStopCollection *gradient, ID2D1LinearGradientBrush **brush)
190 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
192 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
193 iface, gradient_brush_desc, brush_desc, gradient, brush);
195 return ID2D1RenderTarget_CreateLinearGradientBrush(render_target->dxgi_target,
196 gradient_brush_desc, brush_desc, gradient, brush);
199 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_CreateRadialGradientBrush(ID2D1DCRenderTarget *iface,
200 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
201 ID2D1GradientStopCollection *gradient, ID2D1RadialGradientBrush **brush)
203 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
205 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
206 iface, gradient_brush_desc, brush_desc, gradient, brush);
208 return ID2D1RenderTarget_CreateRadialGradientBrush(render_target->dxgi_target,
209 gradient_brush_desc, brush_desc, gradient, brush);
212 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_CreateCompatibleRenderTarget(ID2D1DCRenderTarget *iface,
213 const D2D1_SIZE_F *size, const D2D1_SIZE_U *pixel_size, const D2D1_PIXEL_FORMAT *format,
214 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options, ID2D1BitmapRenderTarget **render_target)
216 struct d2d_dc_render_target *rt = impl_from_ID2D1DCRenderTarget(iface);
218 TRACE("iface %p, size %p, pixel_size %p, format %p, options %#x, render_target %p,\n",
219 iface, size, pixel_size, format, options, render_target);
221 return ID2D1RenderTarget_CreateCompatibleRenderTarget(rt->dxgi_target,
222 size, pixel_size, format, options, render_target);
225 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_CreateLayer(ID2D1DCRenderTarget *iface,
226 const D2D1_SIZE_F *size, ID2D1Layer **layer)
228 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
230 TRACE("iface %p, size %p, layer %p.\n", iface, size, layer);
232 return ID2D1RenderTarget_CreateLayer(render_target->dxgi_target, size, layer);
235 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_CreateMesh(ID2D1DCRenderTarget *iface, ID2D1Mesh **mesh)
237 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
239 TRACE("iface %p, mesh %p.\n", iface, mesh);
241 return ID2D1RenderTarget_CreateMesh(render_target->dxgi_target, mesh);
244 static void STDMETHODCALLTYPE d2d_dc_render_target_DrawLine(ID2D1DCRenderTarget *iface,
245 D2D1_POINT_2F p0, D2D1_POINT_2F p1, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
247 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
249 TRACE("iface %p, p0 %s, p1 %s, brush %p, stroke_width %.8e, stroke_style %p.\n",
250 iface, debug_d2d_point_2f(&p0), debug_d2d_point_2f(&p1), brush, stroke_width, stroke_style);
252 ID2D1RenderTarget_DrawLine(render_target->dxgi_target, p0, p1, brush, stroke_width, stroke_style);
255 static void STDMETHODCALLTYPE d2d_dc_render_target_DrawRectangle(ID2D1DCRenderTarget *iface,
256 const D2D1_RECT_F *rect, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
258 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
260 TRACE("iface %p, rect %s, brush %p, stroke_width %.8e, stroke_style %p.\n",
261 iface, debug_d2d_rect_f(rect), brush, stroke_width, stroke_style);
263 ID2D1RenderTarget_DrawRectangle(render_target->dxgi_target, rect, brush, stroke_width, stroke_style);
266 static void STDMETHODCALLTYPE d2d_dc_render_target_FillRectangle(ID2D1DCRenderTarget *iface,
267 const D2D1_RECT_F *rect, ID2D1Brush *brush)
269 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
271 TRACE("iface %p, rect %s, brush %p.\n", iface, debug_d2d_rect_f(rect), brush);
273 ID2D1RenderTarget_FillRectangle(render_target->dxgi_target, rect, brush);
276 static void STDMETHODCALLTYPE d2d_dc_render_target_DrawRoundedRectangle(ID2D1DCRenderTarget *iface,
277 const D2D1_ROUNDED_RECT *rect, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
279 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
281 TRACE("iface %p, rect %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
282 iface, rect, brush, stroke_width, stroke_style);
284 ID2D1RenderTarget_DrawRoundedRectangle(render_target->dxgi_target, rect, brush, stroke_width, stroke_style);
287 static void STDMETHODCALLTYPE d2d_dc_render_target_FillRoundedRectangle(ID2D1DCRenderTarget *iface,
288 const D2D1_ROUNDED_RECT *rect, ID2D1Brush *brush)
290 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
292 TRACE("iface %p, rect %p, brush %p.\n", iface, rect, brush);
294 ID2D1RenderTarget_FillRoundedRectangle(render_target->dxgi_target, rect, brush);
297 static void STDMETHODCALLTYPE d2d_dc_render_target_DrawEllipse(ID2D1DCRenderTarget *iface,
298 const D2D1_ELLIPSE *ellipse, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
300 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
302 TRACE("iface %p, ellipse %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
303 iface, ellipse, brush, stroke_width, stroke_style);
305 ID2D1RenderTarget_DrawEllipse(render_target->dxgi_target, ellipse, brush, stroke_width, stroke_style);
308 static void STDMETHODCALLTYPE d2d_dc_render_target_FillEllipse(ID2D1DCRenderTarget *iface,
309 const D2D1_ELLIPSE *ellipse, ID2D1Brush *brush)
311 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
313 TRACE("iface %p, ellipse %p, brush %p.\n", iface, ellipse, brush);
315 ID2D1RenderTarget_FillEllipse(render_target->dxgi_target, ellipse, brush);
318 static void STDMETHODCALLTYPE d2d_dc_render_target_DrawGeometry(ID2D1DCRenderTarget *iface,
319 ID2D1Geometry *geometry, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
321 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
323 TRACE("iface %p, geometry %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
324 iface, geometry, brush, stroke_width, stroke_style);
326 ID2D1RenderTarget_DrawGeometry(render_target->dxgi_target, geometry, brush, stroke_width, stroke_style);
329 static void STDMETHODCALLTYPE d2d_dc_render_target_FillGeometry(ID2D1DCRenderTarget *iface,
330 ID2D1Geometry *geometry, ID2D1Brush *brush, ID2D1Brush *opacity_brush)
332 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
334 TRACE("iface %p, geometry %p, brush %p, opacity_brush %p.\n", iface, geometry, brush, opacity_brush);
336 ID2D1RenderTarget_FillGeometry(render_target->dxgi_target, geometry, brush, opacity_brush);
339 static void STDMETHODCALLTYPE d2d_dc_render_target_FillMesh(ID2D1DCRenderTarget *iface,
340 ID2D1Mesh *mesh, ID2D1Brush *brush)
342 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
344 TRACE("iface %p, mesh %p, brush %p.\n", iface, mesh, brush);
346 ID2D1RenderTarget_FillMesh(render_target->dxgi_target, mesh, brush);
349 static void STDMETHODCALLTYPE d2d_dc_render_target_FillOpacityMask(ID2D1DCRenderTarget *iface,
350 ID2D1Bitmap *mask, ID2D1Brush *brush, D2D1_OPACITY_MASK_CONTENT content,
351 const D2D1_RECT_F *dst_rect, const D2D1_RECT_F *src_rect)
353 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
355 TRACE("iface %p, mask %p, brush %p, content %#x, dst_rect %s, src_rect %s.\n",
356 iface, mask, brush, content, debug_d2d_rect_f(dst_rect), debug_d2d_rect_f(src_rect));
358 ID2D1RenderTarget_FillOpacityMask(render_target->dxgi_target,
359 mask, brush, content, dst_rect, src_rect);
362 static void STDMETHODCALLTYPE d2d_dc_render_target_DrawBitmap(ID2D1DCRenderTarget *iface,
363 ID2D1Bitmap *bitmap, const D2D1_RECT_F *dst_rect, float opacity,
364 D2D1_BITMAP_INTERPOLATION_MODE interpolation_mode, const D2D1_RECT_F *src_rect)
366 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
368 TRACE("iface %p, bitmap %p, dst_rect %s, opacity %.8e, interpolation_mode %#x, src_rect %s.\n",
369 iface, bitmap, debug_d2d_rect_f(dst_rect), opacity, interpolation_mode, debug_d2d_rect_f(src_rect));
371 ID2D1RenderTarget_DrawBitmap(render_target->dxgi_target,
372 bitmap, dst_rect, opacity, interpolation_mode, src_rect);
375 static void STDMETHODCALLTYPE d2d_dc_render_target_DrawText(ID2D1DCRenderTarget *iface,
376 const WCHAR *string, UINT32 string_len, IDWriteTextFormat *text_format, const D2D1_RECT_F *layout_rect,
377 ID2D1Brush *brush, D2D1_DRAW_TEXT_OPTIONS options, DWRITE_MEASURING_MODE measuring_mode)
379 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
381 TRACE("iface %p, string %s, string_len %u, text_format %p, layout_rect %s, "
382 "brush %p, options %#x, measuring_mode %#x.\n",
383 iface, debugstr_wn(string, string_len), string_len, text_format, debug_d2d_rect_f(layout_rect),
384 brush, options, measuring_mode);
386 ID2D1RenderTarget_DrawText(render_target->dxgi_target, string, string_len,
387 text_format, layout_rect, brush, options, measuring_mode);
390 static void STDMETHODCALLTYPE d2d_dc_render_target_DrawTextLayout(ID2D1DCRenderTarget *iface,
391 D2D1_POINT_2F origin, IDWriteTextLayout *layout, ID2D1Brush *brush, D2D1_DRAW_TEXT_OPTIONS options)
393 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
395 TRACE("iface %p, origin %s, layout %p, brush %p, options %#x.\n",
396 iface, debug_d2d_point_2f(&origin), layout, brush, options);
398 ID2D1RenderTarget_DrawTextLayout(render_target->dxgi_target, origin, layout, brush, options);
401 static void STDMETHODCALLTYPE d2d_dc_render_target_DrawGlyphRun(ID2D1DCRenderTarget *iface,
402 D2D1_POINT_2F baseline_origin, const DWRITE_GLYPH_RUN *glyph_run, ID2D1Brush *brush,
403 DWRITE_MEASURING_MODE measuring_mode)
405 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
407 TRACE("iface %p, baseline_origin %s, glyph_run %p, brush %p, measuring_mode %#x.\n",
408 iface, debug_d2d_point_2f(&baseline_origin), glyph_run, brush, measuring_mode);
410 ID2D1RenderTarget_DrawGlyphRun(render_target->dxgi_target,
411 baseline_origin, glyph_run, brush, measuring_mode);
414 static void STDMETHODCALLTYPE d2d_dc_render_target_SetTransform(ID2D1DCRenderTarget *iface,
415 const D2D1_MATRIX_3X2_F *transform)
417 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
419 TRACE("iface %p, transform %p.\n", iface, transform);
421 ID2D1RenderTarget_SetTransform(render_target->dxgi_target, transform);
424 static void STDMETHODCALLTYPE d2d_dc_render_target_GetTransform(ID2D1DCRenderTarget *iface,
425 D2D1_MATRIX_3X2_F *transform)
427 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
429 TRACE("iface %p, transform %p.\n", iface, transform);
431 ID2D1RenderTarget_GetTransform(render_target->dxgi_target, transform);
434 static void STDMETHODCALLTYPE d2d_dc_render_target_SetAntialiasMode(ID2D1DCRenderTarget *iface,
435 D2D1_ANTIALIAS_MODE antialias_mode)
437 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
439 TRACE("iface %p, antialias_mode %#x.\n", iface, antialias_mode);
441 ID2D1RenderTarget_SetAntialiasMode(render_target->dxgi_target, antialias_mode);
444 static D2D1_ANTIALIAS_MODE STDMETHODCALLTYPE d2d_dc_render_target_GetAntialiasMode(ID2D1DCRenderTarget *iface)
446 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
448 TRACE("iface %p.\n", iface);
450 return ID2D1RenderTarget_GetAntialiasMode(render_target->dxgi_target);
453 static void STDMETHODCALLTYPE d2d_dc_render_target_SetTextAntialiasMode(ID2D1DCRenderTarget *iface,
454 D2D1_TEXT_ANTIALIAS_MODE antialias_mode)
456 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
458 TRACE("iface %p, antialias_mode %#x.\n", iface, antialias_mode);
460 ID2D1RenderTarget_SetTextAntialiasMode(render_target->dxgi_target, antialias_mode);
463 static D2D1_TEXT_ANTIALIAS_MODE STDMETHODCALLTYPE d2d_dc_render_target_GetTextAntialiasMode(ID2D1DCRenderTarget *iface)
465 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
467 TRACE("iface %p.\n", iface);
469 return ID2D1RenderTarget_GetTextAntialiasMode(render_target->dxgi_target);
472 static void STDMETHODCALLTYPE d2d_dc_render_target_SetTextRenderingParams(ID2D1DCRenderTarget *iface,
473 IDWriteRenderingParams *text_rendering_params)
475 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
477 TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
479 ID2D1RenderTarget_SetTextRenderingParams(render_target->dxgi_target, text_rendering_params);
482 static void STDMETHODCALLTYPE d2d_dc_render_target_GetTextRenderingParams(ID2D1DCRenderTarget *iface,
483 IDWriteRenderingParams **text_rendering_params)
485 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
487 TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
489 ID2D1RenderTarget_GetTextRenderingParams(render_target->dxgi_target, text_rendering_params);
492 static void STDMETHODCALLTYPE d2d_dc_render_target_SetTags(ID2D1DCRenderTarget *iface, D2D1_TAG tag1, D2D1_TAG tag2)
494 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
496 TRACE("iface %p, tag1 %s, tag2 %s.\n", iface, wine_dbgstr_longlong(tag1), wine_dbgstr_longlong(tag2));
498 ID2D1RenderTarget_SetTags(render_target->dxgi_target, tag1, tag2);
501 static void STDMETHODCALLTYPE d2d_dc_render_target_GetTags(ID2D1DCRenderTarget *iface, D2D1_TAG *tag1, D2D1_TAG *tag2)
503 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
505 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
507 ID2D1RenderTarget_GetTags(render_target->dxgi_target, tag1, tag2);
510 static void STDMETHODCALLTYPE d2d_dc_render_target_PushLayer(ID2D1DCRenderTarget *iface,
511 const D2D1_LAYER_PARAMETERS *layer_parameters, ID2D1Layer *layer)
513 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
515 TRACE("iface %p, layer_parameters %p, layer %p.\n", iface, layer_parameters, layer);
517 ID2D1RenderTarget_PushLayer(render_target->dxgi_target, layer_parameters, layer);
520 static void STDMETHODCALLTYPE d2d_dc_render_target_PopLayer(ID2D1DCRenderTarget *iface)
522 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
524 TRACE("iface %p.\n", iface);
526 ID2D1RenderTarget_PopLayer(render_target->dxgi_target);
529 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_Flush(ID2D1DCRenderTarget *iface, D2D1_TAG *tag1, D2D1_TAG *tag2)
531 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
533 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
535 return ID2D1RenderTarget_Flush(render_target->dxgi_target, tag1, tag2);
538 static void STDMETHODCALLTYPE d2d_dc_render_target_SaveDrawingState(ID2D1DCRenderTarget *iface,
539 ID2D1DrawingStateBlock *state_block)
541 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
543 TRACE("iface %p, state_block %p.\n", iface, state_block);
545 ID2D1RenderTarget_SaveDrawingState(render_target->dxgi_target, state_block);
548 static void STDMETHODCALLTYPE d2d_dc_render_target_RestoreDrawingState(ID2D1DCRenderTarget *iface,
549 ID2D1DrawingStateBlock *state_block)
551 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
553 TRACE("iface %p, state_block %p.\n", iface, state_block);
555 ID2D1RenderTarget_RestoreDrawingState(render_target->dxgi_target, state_block);
558 static void STDMETHODCALLTYPE d2d_dc_render_target_PushAxisAlignedClip(ID2D1DCRenderTarget *iface,
559 const D2D1_RECT_F *clip_rect, D2D1_ANTIALIAS_MODE antialias_mode)
561 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
563 TRACE("iface %p, clip_rect %s, antialias_mode %#x.\n", iface, debug_d2d_rect_f(clip_rect), antialias_mode);
565 ID2D1RenderTarget_PushAxisAlignedClip(render_target->dxgi_target, clip_rect, antialias_mode);
568 static void STDMETHODCALLTYPE d2d_dc_render_target_PopAxisAlignedClip(ID2D1DCRenderTarget *iface)
570 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
572 TRACE("iface %p.\n", iface);
574 ID2D1RenderTarget_PopAxisAlignedClip(render_target->dxgi_target);
577 static void STDMETHODCALLTYPE d2d_dc_render_target_Clear(ID2D1DCRenderTarget *iface, const D2D1_COLOR_F *color)
579 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
581 TRACE("iface %p, color %p.\n", iface, color);
583 ID2D1RenderTarget_Clear(render_target->dxgi_target, color);
586 static void STDMETHODCALLTYPE d2d_dc_render_target_BeginDraw(ID2D1DCRenderTarget *iface)
588 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
590 TRACE("iface %p.\n", iface);
592 ID2D1RenderTarget_BeginDraw(render_target->dxgi_target);
595 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_EndDraw(ID2D1DCRenderTarget *iface,
596 D2D1_TAG *tag1, D2D1_TAG *tag2)
598 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
600 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
602 return ID2D1RenderTarget_EndDraw(render_target->dxgi_target, tag1, tag2);
605 static D2D1_PIXEL_FORMAT * STDMETHODCALLTYPE d2d_dc_render_target_GetPixelFormat(ID2D1DCRenderTarget *iface,
606 D2D1_PIXEL_FORMAT *format)
608 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
610 TRACE("iface %p, format %p.\n", iface, format);
612 *format = ID2D1RenderTarget_GetPixelFormat(render_target->dxgi_target);
613 return format;
616 static void STDMETHODCALLTYPE d2d_dc_render_target_SetDpi(ID2D1DCRenderTarget *iface, float dpi_x, float dpi_y)
618 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
620 TRACE("iface %p, dpi_x %.8e, dpi_y %.8e.\n", iface, dpi_x, dpi_y);
622 ID2D1RenderTarget_SetDpi(render_target->dxgi_target, dpi_x, dpi_y);
625 static void STDMETHODCALLTYPE d2d_dc_render_target_GetDpi(ID2D1DCRenderTarget *iface, float *dpi_x, float *dpi_y)
627 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
629 TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface, dpi_x, dpi_y);
631 ID2D1RenderTarget_GetDpi(render_target->dxgi_target, dpi_x, dpi_y);
634 static D2D1_SIZE_F * STDMETHODCALLTYPE d2d_dc_render_target_GetSize(ID2D1DCRenderTarget *iface, D2D1_SIZE_F *size)
636 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
638 TRACE("iface %p, size %p.\n", iface, size);
640 if (render_target->hdc)
641 *size = ID2D1RenderTarget_GetSize(render_target->dxgi_target);
642 else
643 size->width = size->height = 0.0f;
645 return size;
648 static D2D1_SIZE_U * STDMETHODCALLTYPE d2d_dc_render_target_GetPixelSize(ID2D1DCRenderTarget *iface,
649 D2D1_SIZE_U *pixel_size)
651 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
653 TRACE("iface %p, pixel_size %p.\n", iface, pixel_size);
655 if (render_target->hdc)
656 *pixel_size = ID2D1RenderTarget_GetPixelSize(render_target->dxgi_target);
657 else
658 pixel_size->width = pixel_size->height = 0;
660 return pixel_size;
663 static UINT32 STDMETHODCALLTYPE d2d_dc_render_target_GetMaximumBitmapSize(ID2D1DCRenderTarget *iface)
665 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
667 TRACE("iface %p.\n", iface);
669 return ID2D1RenderTarget_GetMaximumBitmapSize(render_target->dxgi_target);
672 static BOOL STDMETHODCALLTYPE d2d_dc_render_target_IsSupported(ID2D1DCRenderTarget *iface,
673 const D2D1_RENDER_TARGET_PROPERTIES *desc)
675 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
677 TRACE("iface %p, desc %p.\n", iface, desc);
679 return ID2D1RenderTarget_IsSupported(render_target->dxgi_target, desc);
682 static HRESULT STDMETHODCALLTYPE d2d_dc_render_target_BindDC(ID2D1DCRenderTarget *iface,
683 const HDC hdc, const RECT *rect)
685 struct d2d_dc_render_target *render_target = impl_from_ID2D1DCRenderTarget(iface);
686 D2D1_BITMAP_PROPERTIES1 bitmap_desc;
687 struct d2d_bitmap *bitmap_impl;
688 IDXGISurface1 *dxgi_surface;
689 ID2D1DeviceContext *context;
690 D2D1_SIZE_U bitmap_size;
691 ID2D1Bitmap *bitmap;
692 HRESULT hr;
694 TRACE("iface %p, hdc %p, rect %s.\n", iface, hdc, wine_dbgstr_rect(rect));
696 if (!hdc)
697 return E_INVALIDARG;
699 /* Switch dxgi target to new surface. */
700 ID2D1RenderTarget_QueryInterface(render_target->dxgi_target, &IID_ID2D1DeviceContext, (void **)&context);
702 bitmap_size.width = rect->right - rect->left;
703 bitmap_size.height = rect->bottom - rect->top;
705 memset(&bitmap_desc, 0, sizeof(bitmap_desc));
706 bitmap_desc.pixelFormat = render_target->pixel_format;
707 bitmap_desc.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW |
708 D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE;
709 if (FAILED(hr = ID2D1DeviceContext_CreateBitmap(context, bitmap_size, NULL, 0, &bitmap_desc,
710 (ID2D1Bitmap1 **)&bitmap)))
712 WARN("Failed to create target bitmap, hr %#x.\n", hr);
713 ID2D1DeviceContext_Release(context);
714 return hr;
717 bitmap_impl = unsafe_impl_from_ID2D1Bitmap(bitmap);
718 ID3D10Resource_QueryInterface(bitmap_impl->resource, &IID_IDXGISurface1, (void **)&dxgi_surface);
720 ID2D1DeviceContext_SetTarget(context, (ID2D1Image *)bitmap);
721 ID2D1Bitmap_Release(bitmap);
722 ID2D1DeviceContext_Release(context);
724 if (render_target->dxgi_surface)
725 IDXGISurface1_Release(render_target->dxgi_surface);
726 render_target->dxgi_surface = dxgi_surface;
728 render_target->hdc = hdc;
729 render_target->dst_rect = *rect;
731 return hr;
734 static const struct ID2D1DCRenderTargetVtbl d2d_dc_render_target_vtbl =
736 d2d_dc_render_target_QueryInterface,
737 d2d_dc_render_target_AddRef,
738 d2d_dc_render_target_Release,
739 d2d_dc_render_target_GetFactory,
740 d2d_dc_render_target_CreateBitmap,
741 d2d_dc_render_target_CreateBitmapFromWicBitmap,
742 d2d_dc_render_target_CreateSharedBitmap,
743 d2d_dc_render_target_CreateBitmapBrush,
744 d2d_dc_render_target_CreateSolidColorBrush,
745 d2d_dc_render_target_CreateGradientStopCollection,
746 d2d_dc_render_target_CreateLinearGradientBrush,
747 d2d_dc_render_target_CreateRadialGradientBrush,
748 d2d_dc_render_target_CreateCompatibleRenderTarget,
749 d2d_dc_render_target_CreateLayer,
750 d2d_dc_render_target_CreateMesh,
751 d2d_dc_render_target_DrawLine,
752 d2d_dc_render_target_DrawRectangle,
753 d2d_dc_render_target_FillRectangle,
754 d2d_dc_render_target_DrawRoundedRectangle,
755 d2d_dc_render_target_FillRoundedRectangle,
756 d2d_dc_render_target_DrawEllipse,
757 d2d_dc_render_target_FillEllipse,
758 d2d_dc_render_target_DrawGeometry,
759 d2d_dc_render_target_FillGeometry,
760 d2d_dc_render_target_FillMesh,
761 d2d_dc_render_target_FillOpacityMask,
762 d2d_dc_render_target_DrawBitmap,
763 d2d_dc_render_target_DrawText,
764 d2d_dc_render_target_DrawTextLayout,
765 d2d_dc_render_target_DrawGlyphRun,
766 d2d_dc_render_target_SetTransform,
767 d2d_dc_render_target_GetTransform,
768 d2d_dc_render_target_SetAntialiasMode,
769 d2d_dc_render_target_GetAntialiasMode,
770 d2d_dc_render_target_SetTextAntialiasMode,
771 d2d_dc_render_target_GetTextAntialiasMode,
772 d2d_dc_render_target_SetTextRenderingParams,
773 d2d_dc_render_target_GetTextRenderingParams,
774 d2d_dc_render_target_SetTags,
775 d2d_dc_render_target_GetTags,
776 d2d_dc_render_target_PushLayer,
777 d2d_dc_render_target_PopLayer,
778 d2d_dc_render_target_Flush,
779 d2d_dc_render_target_SaveDrawingState,
780 d2d_dc_render_target_RestoreDrawingState,
781 d2d_dc_render_target_PushAxisAlignedClip,
782 d2d_dc_render_target_PopAxisAlignedClip,
783 d2d_dc_render_target_Clear,
784 d2d_dc_render_target_BeginDraw,
785 d2d_dc_render_target_EndDraw,
786 d2d_dc_render_target_GetPixelFormat,
787 d2d_dc_render_target_SetDpi,
788 d2d_dc_render_target_GetDpi,
789 d2d_dc_render_target_GetSize,
790 d2d_dc_render_target_GetPixelSize,
791 d2d_dc_render_target_GetMaximumBitmapSize,
792 d2d_dc_render_target_IsSupported,
793 d2d_dc_render_target_BindDC,
796 static const struct d2d_device_context_ops d2d_dc_render_target_ops =
798 d2d_dc_render_target_present,
801 HRESULT d2d_dc_render_target_init(struct d2d_dc_render_target *render_target, ID2D1Factory1 *factory,
802 ID3D10Device1 *d3d_device, const D2D1_RENDER_TARGET_PROPERTIES *desc)
804 IDXGIDevice *dxgi_device;
805 ID2D1Device *device;
806 HRESULT hr;
808 render_target->ID2D1DCRenderTarget_iface.lpVtbl = &d2d_dc_render_target_vtbl;
810 /* Set with BindDC(). */
811 SetRectEmpty(&render_target->dst_rect);
812 render_target->hdc = NULL;
814 render_target->pixel_format = desc->pixelFormat;
815 switch (desc->pixelFormat.format)
817 case DXGI_FORMAT_B8G8R8A8_UNORM:
818 if (desc->pixelFormat.alphaMode == D2D1_ALPHA_MODE_PREMULTIPLIED
819 || desc->pixelFormat.alphaMode == D2D1_ALPHA_MODE_IGNORE)
820 break;
822 default:
823 FIXME("Unhandled format %#x, alpha mode %u.\n", desc->pixelFormat.format, desc->pixelFormat.alphaMode);
824 return D2DERR_UNSUPPORTED_PIXEL_FORMAT;
827 if (FAILED(hr = ID3D10Device1_QueryInterface(d3d_device, &IID_IDXGIDevice, (void **)&dxgi_device)))
829 WARN("Failed to get DXGI device interface, hr %#x.\n", hr);
830 return hr;
833 hr = ID2D1Factory1_CreateDevice(factory, dxgi_device, &device);
834 IDXGIDevice_Release(dxgi_device);
835 if (FAILED(hr))
837 WARN("Failed to create D2D device, hr %#x.\n", hr);
838 return hr;
841 hr = d2d_d3d_create_render_target(device, NULL, (IUnknown *)&render_target->ID2D1DCRenderTarget_iface,
842 &d2d_dc_render_target_ops, desc, (void **)&render_target->dxgi_inner);
843 ID2D1Device_Release(device);
844 if (FAILED(hr))
846 WARN("Failed to create DXGI surface render target, hr %#x.\n", hr);
847 return hr;
850 if (FAILED(hr = IUnknown_QueryInterface(render_target->dxgi_inner,
851 &IID_ID2D1RenderTarget, (void **)&render_target->dxgi_target)))
853 WARN("Failed to retrieve ID2D1RenderTarget interface, hr %#x.\n", hr);
854 IUnknown_Release(render_target->dxgi_inner);
855 return hr;
858 render_target->d3d_device = d3d_device;
859 ID3D10Device1_AddRef(render_target->d3d_device);
861 return S_OK;