comctl32/tests: Avoid a structure initialization warning.
[wine.git] / dlls / d2d1 / hwnd_render_target.c
blobd0b969593387244b8c2aeed4a1bd29f18039ba69
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 "config.h"
21 #include "wine/port.h"
23 #include "d2d1_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d2d);
27 static inline struct d2d_hwnd_render_target *impl_from_IUnknown(IUnknown *iface)
29 return CONTAINING_RECORD(iface, struct d2d_hwnd_render_target, ID2D1HwndRenderTarget_iface);
32 static HRESULT d2d_hwnd_render_target_present(IUnknown *outer_unknown)
34 struct d2d_hwnd_render_target *render_target = impl_from_IUnknown(outer_unknown);
35 HRESULT hr;
37 if (FAILED(hr = IDXGISwapChain_Present(render_target->swapchain, render_target->sync_interval, 0)))
38 WARN("Present failed, %#x.\n", hr);
40 return S_OK;
43 static inline struct d2d_hwnd_render_target *impl_from_ID2D1HwndRenderTarget(ID2D1HwndRenderTarget *iface)
45 return CONTAINING_RECORD(iface, struct d2d_hwnd_render_target, ID2D1HwndRenderTarget_iface);
48 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_QueryInterface(ID2D1HwndRenderTarget *iface,
49 REFIID iid, void **out)
51 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
53 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
55 if (IsEqualGUID(iid, &IID_ID2D1HwndRenderTarget)
56 || IsEqualGUID(iid, &IID_ID2D1RenderTarget)
57 || IsEqualGUID(iid, &IID_ID2D1Resource)
58 || IsEqualGUID(iid, &IID_IUnknown))
60 ID2D1HwndRenderTarget_AddRef(iface);
61 *out = iface;
62 return S_OK;
65 return IUnknown_QueryInterface(render_target->dxgi_inner, iid, out);
68 static ULONG STDMETHODCALLTYPE d2d_hwnd_render_target_AddRef(ID2D1HwndRenderTarget *iface)
70 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
71 ULONG refcount = InterlockedIncrement(&render_target->refcount);
73 TRACE("%p increasing refcount to %u.\n", iface, refcount);
75 return refcount;
78 static ULONG STDMETHODCALLTYPE d2d_hwnd_render_target_Release(ID2D1HwndRenderTarget *iface)
80 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
81 ULONG refcount = InterlockedDecrement(&render_target->refcount);
83 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
85 if (!refcount)
87 IUnknown_Release(render_target->dxgi_inner);
88 IDXGISwapChain_Release(render_target->swapchain);
89 heap_free(render_target);
92 return refcount;
95 static void STDMETHODCALLTYPE d2d_hwnd_render_target_GetFactory(ID2D1HwndRenderTarget *iface, ID2D1Factory **factory)
97 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
99 TRACE("iface %p, factory %p.\n", iface, factory);
101 ID2D1RenderTarget_GetFactory(render_target->dxgi_target, factory);
104 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateBitmap(ID2D1HwndRenderTarget *iface,
105 D2D1_SIZE_U size, const void *src_data, UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
107 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
109 TRACE("iface %p, size {%u, %u}, src_data %p, pitch %u, desc %p, bitmap %p.\n",
110 iface, size.width, size.height, src_data, pitch, desc, bitmap);
112 return ID2D1RenderTarget_CreateBitmap(render_target->dxgi_target, size, src_data, pitch, desc, bitmap);
115 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateBitmapFromWicBitmap(ID2D1HwndRenderTarget *iface,
116 IWICBitmapSource *bitmap_source, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
118 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
120 TRACE("iface %p, bitmap_source %p, desc %p, bitmap %p.\n",
121 iface, bitmap_source, desc, bitmap);
123 return ID2D1RenderTarget_CreateBitmapFromWicBitmap(render_target->dxgi_target, bitmap_source, desc, bitmap);
126 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateSharedBitmap(ID2D1HwndRenderTarget *iface,
127 REFIID iid, void *data, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
129 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
131 TRACE("iface %p, iid %s, data %p, desc %p, bitmap %p.\n",
132 iface, debugstr_guid(iid), data, desc, bitmap);
134 return ID2D1RenderTarget_CreateSharedBitmap(render_target->dxgi_target, iid, data, desc, bitmap);
137 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateBitmapBrush(ID2D1HwndRenderTarget *iface,
138 ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc,
139 const D2D1_BRUSH_PROPERTIES *brush_desc, ID2D1BitmapBrush **brush)
141 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
143 TRACE("iface %p, bitmap %p, bitmap_brush_desc %p, brush_desc %p, brush %p.\n",
144 iface, bitmap, bitmap_brush_desc, brush_desc, brush);
146 return ID2D1RenderTarget_CreateBitmapBrush(render_target->dxgi_target,
147 bitmap, bitmap_brush_desc, brush_desc, brush);
150 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateSolidColorBrush(ID2D1HwndRenderTarget *iface,
151 const D2D1_COLOR_F *color, const D2D1_BRUSH_PROPERTIES *desc, ID2D1SolidColorBrush **brush)
153 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
155 TRACE("iface %p, color %p, desc %p, brush %p.\n", iface, color, desc, brush);
157 return ID2D1RenderTarget_CreateSolidColorBrush(render_target->dxgi_target, color, desc, brush);
160 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateGradientStopCollection(ID2D1HwndRenderTarget *iface,
161 const D2D1_GRADIENT_STOP *stops, UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode,
162 ID2D1GradientStopCollection **gradient)
164 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
166 TRACE("iface %p, stops %p, stop_count %u, gamma %#x, extend_mode %#x, gradient %p.\n",
167 iface, stops, stop_count, gamma, extend_mode, gradient);
169 return ID2D1RenderTarget_CreateGradientStopCollection(render_target->dxgi_target,
170 stops, stop_count, gamma, extend_mode, gradient);
173 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateLinearGradientBrush(ID2D1HwndRenderTarget *iface,
174 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
175 ID2D1GradientStopCollection *gradient, ID2D1LinearGradientBrush **brush)
177 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
179 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
180 iface, gradient_brush_desc, brush_desc, gradient, brush);
182 return ID2D1RenderTarget_CreateLinearGradientBrush(render_target->dxgi_target,
183 gradient_brush_desc, brush_desc, gradient, brush);
186 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateRadialGradientBrush(ID2D1HwndRenderTarget *iface,
187 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
188 ID2D1GradientStopCollection *gradient, ID2D1RadialGradientBrush **brush)
190 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(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_CreateRadialGradientBrush(render_target->dxgi_target,
196 gradient_brush_desc, brush_desc, gradient, brush);
199 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateCompatibleRenderTarget(ID2D1HwndRenderTarget *iface,
200 const D2D1_SIZE_F *size, const D2D1_SIZE_U *pixel_size, const D2D1_PIXEL_FORMAT *format,
201 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options, ID2D1BitmapRenderTarget **render_target)
203 struct d2d_hwnd_render_target *rt = impl_from_ID2D1HwndRenderTarget(iface);
205 TRACE("iface %p, size %p, pixel_size %p, format %p, options %#x, render_target %p,\n",
206 iface, size, pixel_size, format, options, render_target);
208 return ID2D1RenderTarget_CreateCompatibleRenderTarget(rt->dxgi_target,
209 size, pixel_size, format, options, render_target);
212 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateLayer(ID2D1HwndRenderTarget *iface,
213 const D2D1_SIZE_F *size, ID2D1Layer **layer)
215 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
217 TRACE("iface %p, size %p, layer %p.\n", iface, size, layer);
219 return ID2D1RenderTarget_CreateLayer(render_target->dxgi_target, size, layer);
222 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateMesh(ID2D1HwndRenderTarget *iface, ID2D1Mesh **mesh)
224 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
226 TRACE("iface %p, mesh %p.\n", iface, mesh);
228 return ID2D1RenderTarget_CreateMesh(render_target->dxgi_target, mesh);
231 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawLine(ID2D1HwndRenderTarget *iface,
232 D2D1_POINT_2F p0, D2D1_POINT_2F p1, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
234 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
236 TRACE("iface %p, p0 %s, p1 %s, brush %p, stroke_width %.8e, stroke_style %p.\n",
237 iface, debug_d2d_point_2f(&p0), debug_d2d_point_2f(&p1), brush, stroke_width, stroke_style);
239 ID2D1RenderTarget_DrawLine(render_target->dxgi_target, p0, p1, brush, stroke_width, stroke_style);
242 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawRectangle(ID2D1HwndRenderTarget *iface,
243 const D2D1_RECT_F *rect, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
245 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
247 TRACE("iface %p, rect %s, brush %p, stroke_width %.8e, stroke_style %p.\n",
248 iface, debug_d2d_rect_f(rect), brush, stroke_width, stroke_style);
250 ID2D1RenderTarget_DrawRectangle(render_target->dxgi_target, rect, brush, stroke_width, stroke_style);
253 static void STDMETHODCALLTYPE d2d_hwnd_render_target_FillRectangle(ID2D1HwndRenderTarget *iface,
254 const D2D1_RECT_F *rect, ID2D1Brush *brush)
256 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
258 TRACE("iface %p, rect %s, brush %p.\n", iface, debug_d2d_rect_f(rect), brush);
260 ID2D1RenderTarget_FillRectangle(render_target->dxgi_target, rect, brush);
263 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawRoundedRectangle(ID2D1HwndRenderTarget *iface,
264 const D2D1_ROUNDED_RECT *rect, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
266 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
268 TRACE("iface %p, rect %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
269 iface, rect, brush, stroke_width, stroke_style);
271 ID2D1RenderTarget_DrawRoundedRectangle(render_target->dxgi_target, rect, brush, stroke_width, stroke_style);
274 static void STDMETHODCALLTYPE d2d_hwnd_render_target_FillRoundedRectangle(ID2D1HwndRenderTarget *iface,
275 const D2D1_ROUNDED_RECT *rect, ID2D1Brush *brush)
277 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
279 TRACE("iface %p, rect %p, brush %p.\n", iface, rect, brush);
281 ID2D1RenderTarget_FillRoundedRectangle(render_target->dxgi_target, rect, brush);
284 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawEllipse(ID2D1HwndRenderTarget *iface,
285 const D2D1_ELLIPSE *ellipse, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
287 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
289 TRACE("iface %p, ellipse %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
290 iface, ellipse, brush, stroke_width, stroke_style);
292 ID2D1RenderTarget_DrawEllipse(render_target->dxgi_target, ellipse, brush, stroke_width, stroke_style);
295 static void STDMETHODCALLTYPE d2d_hwnd_render_target_FillEllipse(ID2D1HwndRenderTarget *iface,
296 const D2D1_ELLIPSE *ellipse, ID2D1Brush *brush)
298 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
300 TRACE("iface %p, ellipse %p, brush %p.\n", iface, ellipse, brush);
302 ID2D1RenderTarget_FillEllipse(render_target->dxgi_target, ellipse, brush);
305 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawGeometry(ID2D1HwndRenderTarget *iface,
306 ID2D1Geometry *geometry, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
308 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
310 TRACE("iface %p, geometry %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
311 iface, geometry, brush, stroke_width, stroke_style);
313 ID2D1RenderTarget_DrawGeometry(render_target->dxgi_target, geometry, brush, stroke_width, stroke_style);
316 static void STDMETHODCALLTYPE d2d_hwnd_render_target_FillGeometry(ID2D1HwndRenderTarget *iface,
317 ID2D1Geometry *geometry, ID2D1Brush *brush, ID2D1Brush *opacity_brush)
319 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
321 TRACE("iface %p, geometry %p, brush %p, opacity_brush %p.\n", iface, geometry, brush, opacity_brush);
323 ID2D1RenderTarget_FillGeometry(render_target->dxgi_target, geometry, brush, opacity_brush);
326 static void STDMETHODCALLTYPE d2d_hwnd_render_target_FillMesh(ID2D1HwndRenderTarget *iface,
327 ID2D1Mesh *mesh, ID2D1Brush *brush)
329 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
331 TRACE("iface %p, mesh %p, brush %p.\n", iface, mesh, brush);
333 ID2D1RenderTarget_FillMesh(render_target->dxgi_target, mesh, brush);
336 static void STDMETHODCALLTYPE d2d_hwnd_render_target_FillOpacityMask(ID2D1HwndRenderTarget *iface,
337 ID2D1Bitmap *mask, ID2D1Brush *brush, D2D1_OPACITY_MASK_CONTENT content,
338 const D2D1_RECT_F *dst_rect, const D2D1_RECT_F *src_rect)
340 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
342 TRACE("iface %p, mask %p, brush %p, content %#x, dst_rect %s, src_rect %s.\n",
343 iface, mask, brush, content, debug_d2d_rect_f(dst_rect), debug_d2d_rect_f(src_rect));
345 ID2D1RenderTarget_FillOpacityMask(render_target->dxgi_target,
346 mask, brush, content, dst_rect, src_rect);
349 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawBitmap(ID2D1HwndRenderTarget *iface,
350 ID2D1Bitmap *bitmap, const D2D1_RECT_F *dst_rect, float opacity,
351 D2D1_BITMAP_INTERPOLATION_MODE interpolation_mode, const D2D1_RECT_F *src_rect)
353 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
355 TRACE("iface %p, bitmap %p, dst_rect %s, opacity %.8e, interpolation_mode %#x, src_rect %s.\n",
356 iface, bitmap, debug_d2d_rect_f(dst_rect), opacity, interpolation_mode, debug_d2d_rect_f(src_rect));
358 ID2D1RenderTarget_DrawBitmap(render_target->dxgi_target,
359 bitmap, dst_rect, opacity, interpolation_mode, src_rect);
362 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawText(ID2D1HwndRenderTarget *iface,
363 const WCHAR *string, UINT32 string_len, IDWriteTextFormat *text_format, const D2D1_RECT_F *layout_rect,
364 ID2D1Brush *brush, D2D1_DRAW_TEXT_OPTIONS options, DWRITE_MEASURING_MODE measuring_mode)
366 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
368 TRACE("iface %p, string %s, string_len %u, text_format %p, layout_rect %s, "
369 "brush %p, options %#x, measuring_mode %#x.\n",
370 iface, debugstr_wn(string, string_len), string_len, text_format, debug_d2d_rect_f(layout_rect),
371 brush, options, measuring_mode);
373 ID2D1RenderTarget_DrawText(render_target->dxgi_target, string, string_len,
374 text_format, layout_rect, brush, options, measuring_mode);
377 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawTextLayout(ID2D1HwndRenderTarget *iface,
378 D2D1_POINT_2F origin, IDWriteTextLayout *layout, ID2D1Brush *brush, D2D1_DRAW_TEXT_OPTIONS options)
380 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
382 TRACE("iface %p, origin %s, layout %p, brush %p, options %#x.\n",
383 iface, debug_d2d_point_2f(&origin), layout, brush, options);
385 ID2D1RenderTarget_DrawTextLayout(render_target->dxgi_target, origin, layout, brush, options);
388 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawGlyphRun(ID2D1HwndRenderTarget *iface,
389 D2D1_POINT_2F baseline_origin, const DWRITE_GLYPH_RUN *glyph_run, ID2D1Brush *brush,
390 DWRITE_MEASURING_MODE measuring_mode)
392 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
394 TRACE("iface %p, baseline_origin %s, glyph_run %p, brush %p, measuring_mode %#x.\n",
395 iface, debug_d2d_point_2f(&baseline_origin), glyph_run, brush, measuring_mode);
397 ID2D1RenderTarget_DrawGlyphRun(render_target->dxgi_target,
398 baseline_origin, glyph_run, brush, measuring_mode);
401 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetTransform(ID2D1HwndRenderTarget *iface,
402 const D2D1_MATRIX_3X2_F *transform)
404 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
406 TRACE("iface %p, transform %p.\n", iface, transform);
408 ID2D1RenderTarget_SetTransform(render_target->dxgi_target, transform);
411 static void STDMETHODCALLTYPE d2d_hwnd_render_target_GetTransform(ID2D1HwndRenderTarget *iface,
412 D2D1_MATRIX_3X2_F *transform)
414 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
416 TRACE("iface %p, transform %p.\n", iface, transform);
418 ID2D1RenderTarget_GetTransform(render_target->dxgi_target, transform);
421 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetAntialiasMode(ID2D1HwndRenderTarget *iface,
422 D2D1_ANTIALIAS_MODE antialias_mode)
424 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
426 TRACE("iface %p, antialias_mode %#x.\n", iface, antialias_mode);
428 ID2D1RenderTarget_SetAntialiasMode(render_target->dxgi_target, antialias_mode);
431 static D2D1_ANTIALIAS_MODE STDMETHODCALLTYPE d2d_hwnd_render_target_GetAntialiasMode(ID2D1HwndRenderTarget *iface)
433 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
435 TRACE("iface %p.\n", iface);
437 return ID2D1RenderTarget_GetAntialiasMode(render_target->dxgi_target);
440 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetTextAntialiasMode(ID2D1HwndRenderTarget *iface,
441 D2D1_TEXT_ANTIALIAS_MODE antialias_mode)
443 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
445 TRACE("iface %p, antialias_mode %#x.\n", iface, antialias_mode);
447 ID2D1RenderTarget_SetTextAntialiasMode(render_target->dxgi_target, antialias_mode);
450 static D2D1_TEXT_ANTIALIAS_MODE STDMETHODCALLTYPE d2d_hwnd_render_target_GetTextAntialiasMode(
451 ID2D1HwndRenderTarget *iface)
453 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
455 TRACE("iface %p.\n", iface);
457 return ID2D1RenderTarget_GetTextAntialiasMode(render_target->dxgi_target);
460 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetTextRenderingParams(ID2D1HwndRenderTarget *iface,
461 IDWriteRenderingParams *text_rendering_params)
463 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
465 TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
467 ID2D1RenderTarget_SetTextRenderingParams(render_target->dxgi_target, text_rendering_params);
470 static void STDMETHODCALLTYPE d2d_hwnd_render_target_GetTextRenderingParams(ID2D1HwndRenderTarget *iface,
471 IDWriteRenderingParams **text_rendering_params)
473 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
475 TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
477 ID2D1RenderTarget_GetTextRenderingParams(render_target->dxgi_target, text_rendering_params);
480 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetTags(ID2D1HwndRenderTarget *iface, D2D1_TAG tag1, D2D1_TAG tag2)
482 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
484 TRACE("iface %p, tag1 %s, tag2 %s.\n", iface, wine_dbgstr_longlong(tag1), wine_dbgstr_longlong(tag2));
486 ID2D1RenderTarget_SetTags(render_target->dxgi_target, tag1, tag2);
489 static void STDMETHODCALLTYPE d2d_hwnd_render_target_GetTags(ID2D1HwndRenderTarget *iface, D2D1_TAG *tag1,
490 D2D1_TAG *tag2)
492 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
494 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
496 ID2D1RenderTarget_GetTags(render_target->dxgi_target, tag1, tag2);
499 static void STDMETHODCALLTYPE d2d_hwnd_render_target_PushLayer(ID2D1HwndRenderTarget *iface,
500 const D2D1_LAYER_PARAMETERS *layer_parameters, ID2D1Layer *layer)
502 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
504 TRACE("iface %p, layer_parameters %p, layer %p.\n", iface, layer_parameters, layer);
506 ID2D1RenderTarget_PushLayer(render_target->dxgi_target, layer_parameters, layer);
509 static void STDMETHODCALLTYPE d2d_hwnd_render_target_PopLayer(ID2D1HwndRenderTarget *iface)
511 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
513 TRACE("iface %p.\n", iface);
515 ID2D1RenderTarget_PopLayer(render_target->dxgi_target);
518 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_Flush(ID2D1HwndRenderTarget *iface, D2D1_TAG *tag1,
519 D2D1_TAG *tag2)
521 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
523 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
525 return ID2D1RenderTarget_Flush(render_target->dxgi_target, tag1, tag2);
528 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SaveDrawingState(ID2D1HwndRenderTarget *iface,
529 ID2D1DrawingStateBlock *state_block)
531 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
533 TRACE("iface %p, state_block %p.\n", iface, state_block);
535 ID2D1RenderTarget_SaveDrawingState(render_target->dxgi_target, state_block);
538 static void STDMETHODCALLTYPE d2d_hwnd_render_target_RestoreDrawingState(ID2D1HwndRenderTarget *iface,
539 ID2D1DrawingStateBlock *state_block)
541 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
543 TRACE("iface %p, state_block %p.\n", iface, state_block);
545 ID2D1RenderTarget_RestoreDrawingState(render_target->dxgi_target, state_block);
548 static void STDMETHODCALLTYPE d2d_hwnd_render_target_PushAxisAlignedClip(ID2D1HwndRenderTarget *iface,
549 const D2D1_RECT_F *clip_rect, D2D1_ANTIALIAS_MODE antialias_mode)
551 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
553 TRACE("iface %p, clip_rect %s, antialias_mode %#x.\n", iface, debug_d2d_rect_f(clip_rect), antialias_mode);
555 ID2D1RenderTarget_PushAxisAlignedClip(render_target->dxgi_target, clip_rect, antialias_mode);
558 static void STDMETHODCALLTYPE d2d_hwnd_render_target_PopAxisAlignedClip(ID2D1HwndRenderTarget *iface)
560 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
562 TRACE("iface %p.\n", iface);
564 ID2D1RenderTarget_PopAxisAlignedClip(render_target->dxgi_target);
567 static void STDMETHODCALLTYPE d2d_hwnd_render_target_Clear(ID2D1HwndRenderTarget *iface, const D2D1_COLOR_F *color)
569 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
571 TRACE("iface %p, color %p.\n", iface, color);
573 ID2D1RenderTarget_Clear(render_target->dxgi_target, color);
576 static void STDMETHODCALLTYPE d2d_hwnd_render_target_BeginDraw(ID2D1HwndRenderTarget *iface)
578 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
580 TRACE("iface %p.\n", iface);
582 ID2D1RenderTarget_BeginDraw(render_target->dxgi_target);
585 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_EndDraw(ID2D1HwndRenderTarget *iface,
586 D2D1_TAG *tag1, D2D1_TAG *tag2)
588 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
590 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
592 return ID2D1RenderTarget_EndDraw(render_target->dxgi_target, tag1, tag2);
595 static D2D1_PIXEL_FORMAT * STDMETHODCALLTYPE d2d_hwnd_render_target_GetPixelFormat(ID2D1HwndRenderTarget *iface,
596 D2D1_PIXEL_FORMAT *format)
598 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
600 TRACE("iface %p, format %p.\n", iface, format);
602 *format = ID2D1RenderTarget_GetPixelFormat(render_target->dxgi_target);
603 return format;
606 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetDpi(ID2D1HwndRenderTarget *iface, float dpi_x, float dpi_y)
608 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
610 TRACE("iface %p, dpi_x %.8e, dpi_y %.8e.\n", iface, dpi_x, dpi_y);
612 ID2D1RenderTarget_SetDpi(render_target->dxgi_target, dpi_x, dpi_y);
615 static void STDMETHODCALLTYPE d2d_hwnd_render_target_GetDpi(ID2D1HwndRenderTarget *iface, float *dpi_x, float *dpi_y)
617 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
619 TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface, dpi_x, dpi_y);
621 ID2D1RenderTarget_GetDpi(render_target->dxgi_target, dpi_x, dpi_y);
624 static D2D1_SIZE_F * STDMETHODCALLTYPE d2d_hwnd_render_target_GetSize(ID2D1HwndRenderTarget *iface, D2D1_SIZE_F *size)
626 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
628 TRACE("iface %p, size %p.\n", iface, size);
630 *size = ID2D1RenderTarget_GetSize(render_target->dxgi_target);
631 return size;
634 static D2D1_SIZE_U * STDMETHODCALLTYPE d2d_hwnd_render_target_GetPixelSize(ID2D1HwndRenderTarget *iface,
635 D2D1_SIZE_U *pixel_size)
637 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
639 TRACE("iface %p, pixel_size %p.\n", iface, pixel_size);
641 *pixel_size = ID2D1RenderTarget_GetPixelSize(render_target->dxgi_target);
642 return pixel_size;
645 static UINT32 STDMETHODCALLTYPE d2d_hwnd_render_target_GetMaximumBitmapSize(ID2D1HwndRenderTarget *iface)
647 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
649 TRACE("iface %p.\n", iface);
651 return ID2D1RenderTarget_GetMaximumBitmapSize(render_target->dxgi_target);
654 static BOOL STDMETHODCALLTYPE d2d_hwnd_render_target_IsSupported(ID2D1HwndRenderTarget *iface,
655 const D2D1_RENDER_TARGET_PROPERTIES *desc)
657 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
659 TRACE("iface %p, desc %p.\n", iface, desc);
661 return ID2D1RenderTarget_IsSupported(render_target->dxgi_target, desc);
664 static D2D1_WINDOW_STATE STDMETHODCALLTYPE d2d_hwnd_render_target_CheckWindowState(ID2D1HwndRenderTarget *iface)
666 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
668 TRACE("iface %p.\n", iface);
670 return IDXGISwapChain_Present(render_target->swapchain, render_target->sync_interval, DXGI_PRESENT_TEST) ==
671 DXGI_STATUS_OCCLUDED ? D2D1_WINDOW_STATE_OCCLUDED : D2D1_WINDOW_STATE_NONE;
674 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_Resize(ID2D1HwndRenderTarget *iface, const D2D1_SIZE_U *size)
676 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
677 IDXGISurface1 *dxgi_surface;
678 ID2D1DeviceContext *context;
679 ID2D1Bitmap1 *bitmap;
680 HRESULT hr;
682 TRACE("iface %p, width %u, height %u.\n", iface, size->width, size->height);
684 ID2D1RenderTarget_QueryInterface(render_target->dxgi_target, &IID_ID2D1DeviceContext, (void **)&context);
685 ID2D1DeviceContext_SetTarget(context, NULL);
687 if (SUCCEEDED(hr = IDXGISwapChain_ResizeBuffers(render_target->swapchain, 1, size->width, size->height,
688 DXGI_FORMAT_UNKNOWN, 0)))
690 if (FAILED(hr = IDXGISwapChain_GetBuffer(render_target->swapchain, 0, &IID_IDXGISurface1,
691 (void **)&dxgi_surface)))
693 WARN("Failed to get buffer, hr %#x.\n", hr);
694 ID2D1DeviceContext_Release(context);
695 return hr;
698 hr = ID2D1DeviceContext_CreateBitmapFromDxgiSurface(context, (IDXGISurface *)dxgi_surface, NULL, &bitmap);
699 IDXGISurface1_Release(dxgi_surface);
700 if (FAILED(hr))
702 WARN("Failed to create target bitmap, hr %#x.\n", hr);
703 ID2D1DeviceContext_Release(context);
704 return hr;
707 ID2D1DeviceContext_SetTarget(context, (ID2D1Image *)bitmap);
708 ID2D1Bitmap1_Release(bitmap);
711 ID2D1DeviceContext_Release(context);
713 return hr;
716 static HWND STDMETHODCALLTYPE d2d_hwnd_render_target_GetHwnd(ID2D1HwndRenderTarget *iface)
718 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
720 TRACE("iface %p.\n", iface);
722 return render_target->hwnd;
725 static const struct ID2D1HwndRenderTargetVtbl d2d_hwnd_render_target_vtbl =
727 d2d_hwnd_render_target_QueryInterface,
728 d2d_hwnd_render_target_AddRef,
729 d2d_hwnd_render_target_Release,
730 d2d_hwnd_render_target_GetFactory,
731 d2d_hwnd_render_target_CreateBitmap,
732 d2d_hwnd_render_target_CreateBitmapFromWicBitmap,
733 d2d_hwnd_render_target_CreateSharedBitmap,
734 d2d_hwnd_render_target_CreateBitmapBrush,
735 d2d_hwnd_render_target_CreateSolidColorBrush,
736 d2d_hwnd_render_target_CreateGradientStopCollection,
737 d2d_hwnd_render_target_CreateLinearGradientBrush,
738 d2d_hwnd_render_target_CreateRadialGradientBrush,
739 d2d_hwnd_render_target_CreateCompatibleRenderTarget,
740 d2d_hwnd_render_target_CreateLayer,
741 d2d_hwnd_render_target_CreateMesh,
742 d2d_hwnd_render_target_DrawLine,
743 d2d_hwnd_render_target_DrawRectangle,
744 d2d_hwnd_render_target_FillRectangle,
745 d2d_hwnd_render_target_DrawRoundedRectangle,
746 d2d_hwnd_render_target_FillRoundedRectangle,
747 d2d_hwnd_render_target_DrawEllipse,
748 d2d_hwnd_render_target_FillEllipse,
749 d2d_hwnd_render_target_DrawGeometry,
750 d2d_hwnd_render_target_FillGeometry,
751 d2d_hwnd_render_target_FillMesh,
752 d2d_hwnd_render_target_FillOpacityMask,
753 d2d_hwnd_render_target_DrawBitmap,
754 d2d_hwnd_render_target_DrawText,
755 d2d_hwnd_render_target_DrawTextLayout,
756 d2d_hwnd_render_target_DrawGlyphRun,
757 d2d_hwnd_render_target_SetTransform,
758 d2d_hwnd_render_target_GetTransform,
759 d2d_hwnd_render_target_SetAntialiasMode,
760 d2d_hwnd_render_target_GetAntialiasMode,
761 d2d_hwnd_render_target_SetTextAntialiasMode,
762 d2d_hwnd_render_target_GetTextAntialiasMode,
763 d2d_hwnd_render_target_SetTextRenderingParams,
764 d2d_hwnd_render_target_GetTextRenderingParams,
765 d2d_hwnd_render_target_SetTags,
766 d2d_hwnd_render_target_GetTags,
767 d2d_hwnd_render_target_PushLayer,
768 d2d_hwnd_render_target_PopLayer,
769 d2d_hwnd_render_target_Flush,
770 d2d_hwnd_render_target_SaveDrawingState,
771 d2d_hwnd_render_target_RestoreDrawingState,
772 d2d_hwnd_render_target_PushAxisAlignedClip,
773 d2d_hwnd_render_target_PopAxisAlignedClip,
774 d2d_hwnd_render_target_Clear,
775 d2d_hwnd_render_target_BeginDraw,
776 d2d_hwnd_render_target_EndDraw,
777 d2d_hwnd_render_target_GetPixelFormat,
778 d2d_hwnd_render_target_SetDpi,
779 d2d_hwnd_render_target_GetDpi,
780 d2d_hwnd_render_target_GetSize,
781 d2d_hwnd_render_target_GetPixelSize,
782 d2d_hwnd_render_target_GetMaximumBitmapSize,
783 d2d_hwnd_render_target_IsSupported,
784 d2d_hwnd_render_target_CheckWindowState,
785 d2d_hwnd_render_target_Resize,
786 d2d_hwnd_render_target_GetHwnd
789 static const struct d2d_device_context_ops d2d_hwnd_render_target_ops =
791 d2d_hwnd_render_target_present,
794 HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target, ID2D1Factory1 *factory,
795 ID3D10Device1 *d3d_device, const D2D1_RENDER_TARGET_PROPERTIES *desc,
796 const D2D1_HWND_RENDER_TARGET_PROPERTIES *hwnd_rt_desc)
798 D2D1_RENDER_TARGET_PROPERTIES dxgi_rt_desc;
799 DXGI_SWAP_CHAIN_DESC swapchain_desc;
800 IDXGIAdapter *dxgi_adapter;
801 IDXGIFactory *dxgi_factory;
802 IDXGISurface *dxgi_surface;
803 IDXGIDevice *dxgi_device;
804 ID2D1Device *device;
805 HRESULT hr;
807 if (!IsWindow(hwnd_rt_desc->hwnd))
808 return HRESULT_FROM_WIN32(ERROR_INVALID_WINDOW_HANDLE);
810 render_target->ID2D1HwndRenderTarget_iface.lpVtbl = &d2d_hwnd_render_target_vtbl;
811 render_target->hwnd = hwnd_rt_desc->hwnd;
812 render_target->sync_interval = hwnd_rt_desc->presentOptions & D2D1_PRESENT_OPTIONS_IMMEDIATELY ? 0 : 1;
814 if (FAILED(hr = ID3D10Device1_QueryInterface(d3d_device, &IID_IDXGIDevice, (void **)&dxgi_device)))
816 WARN("Failed to get IDXGIDevice interface, hr %#x.\n", hr);
817 return hr;
820 hr = IDXGIDevice_GetAdapter(dxgi_device, &dxgi_adapter);
821 IDXGIDevice_Release(dxgi_device);
822 if (FAILED(hr))
824 WARN("Failed to get IDXGIAdapter interface, hr %#x.\n", hr);
825 return hr;
828 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&dxgi_factory);
829 IDXGIAdapter_Release(dxgi_adapter);
830 if (FAILED(hr))
832 WARN("Failed to get IDXGIFactory interface, hr %#x.\n", hr);
833 return hr;
836 dxgi_rt_desc = *desc;
837 if (dxgi_rt_desc.dpiX == 0.0f && dxgi_rt_desc.dpiY == 0.0f)
838 ID2D1Factory1_GetDesktopDpi(factory, &dxgi_rt_desc.dpiX, &dxgi_rt_desc.dpiY);
840 if (dxgi_rt_desc.pixelFormat.format == DXGI_FORMAT_UNKNOWN)
842 dxgi_rt_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
843 dxgi_rt_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE;
846 swapchain_desc.BufferDesc.Width = hwnd_rt_desc->pixelSize.width;
847 swapchain_desc.BufferDesc.Height = hwnd_rt_desc->pixelSize.height;
848 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
849 swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
850 swapchain_desc.BufferDesc.Format = dxgi_rt_desc.pixelFormat.format;
851 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
852 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
853 swapchain_desc.SampleDesc.Count = 1;
854 swapchain_desc.SampleDesc.Quality = 0;
855 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
856 swapchain_desc.BufferCount = 1;
857 swapchain_desc.OutputWindow = hwnd_rt_desc->hwnd;
858 swapchain_desc.Windowed = TRUE;
859 swapchain_desc.SwapEffect = hwnd_rt_desc->presentOptions & D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS ?
860 DXGI_SWAP_EFFECT_SEQUENTIAL : DXGI_SWAP_EFFECT_DISCARD;
861 swapchain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE;
863 hr = IDXGIFactory_CreateSwapChain(dxgi_factory, (IUnknown *)d3d_device, &swapchain_desc, &render_target->swapchain);
864 IDXGIFactory_Release(dxgi_factory);
865 if (FAILED(hr))
867 WARN("Failed to create a swapchain, hr %#x.\n", hr);
868 return hr;
871 if (FAILED(hr = IDXGISwapChain_GetBuffer(render_target->swapchain, 0, &IID_IDXGISurface, (void **)&dxgi_surface)))
873 WARN("Failed to get buffer, hr %#x.\n", hr);
874 IDXGISwapChain_Release(render_target->swapchain);
875 return hr;
878 render_target->ID2D1HwndRenderTarget_iface.lpVtbl = &d2d_hwnd_render_target_vtbl;
880 if (FAILED(hr = IDXGISurface_GetDevice(dxgi_surface, &IID_IDXGIDevice, (void **)&dxgi_device)))
882 WARN("Failed to get DXGI device, hr %#X.\n", hr);
883 IDXGISurface_Release(dxgi_surface);
884 IDXGISwapChain_Release(render_target->swapchain);
885 return hr;
888 hr = ID2D1Factory1_CreateDevice(factory, dxgi_device, &device);
889 IDXGIDevice_Release(dxgi_device);
890 if (FAILED(hr))
892 WARN("Failed to create D2D device, hr %#X.\n", hr);
893 IDXGISurface_Release(dxgi_surface);
894 IDXGISwapChain_Release(render_target->swapchain);
895 return hr;
898 hr = d2d_d3d_create_render_target(device, dxgi_surface,
899 (IUnknown *)&render_target->ID2D1HwndRenderTarget_iface, &d2d_hwnd_render_target_ops,
900 &dxgi_rt_desc, (void **)&render_target->dxgi_inner);
901 IDXGISurface_Release(dxgi_surface);
902 ID2D1Device_Release(device);
903 if (FAILED(hr))
905 WARN("Failed to create DXGI surface render target, hr %#x.\n", hr);
906 IDXGISwapChain_Release(render_target->swapchain);
907 return hr;
910 if (FAILED(hr = IUnknown_QueryInterface(render_target->dxgi_inner,
911 &IID_ID2D1RenderTarget, (void **)&render_target->dxgi_target)))
913 WARN("Failed to retrieve ID2D1RenderTarget interface, hr %#x.\n", hr);
914 IUnknown_Release(render_target->dxgi_inner);
915 IDXGISwapChain_Release(render_target->swapchain);
916 return hr;
919 return S_OK;