mstask: Improve stubs for ITask::GetTaskFlags and ITask::GetFlags.
[wine.git] / dlls / d2d1 / hwnd_render_target.c
blob04d33536a6eb7c9bed7397b5f22554d933213d40
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 void render_target_present(struct d2d_hwnd_render_target *render_target)
29 HRESULT hr;
31 if (FAILED(hr = IDXGISwapChain_Present(render_target->swapchain, render_target->sync_interval, 0)))
32 WARN("Present failed, %#x.\n", hr);
35 static inline struct d2d_hwnd_render_target *impl_from_ID2D1HwndRenderTarget(ID2D1HwndRenderTarget *iface)
37 return CONTAINING_RECORD(iface, struct d2d_hwnd_render_target, ID2D1HwndRenderTarget_iface);
40 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_QueryInterface(ID2D1HwndRenderTarget *iface,
41 REFIID iid, void **out)
43 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
45 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
47 if (IsEqualGUID(iid, &IID_ID2D1HwndRenderTarget)
48 || IsEqualGUID(iid, &IID_ID2D1RenderTarget)
49 || IsEqualGUID(iid, &IID_ID2D1Resource)
50 || IsEqualGUID(iid, &IID_IUnknown))
52 ID2D1HwndRenderTarget_AddRef(iface);
53 *out = iface;
54 return S_OK;
56 else if (IsEqualGUID(iid, &IID_ID2D1GdiInteropRenderTarget))
57 return ID2D1RenderTarget_QueryInterface(render_target->dxgi_target, iid, out);
59 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
61 *out = NULL;
62 return E_NOINTERFACE;
65 static ULONG STDMETHODCALLTYPE d2d_hwnd_render_target_AddRef(ID2D1HwndRenderTarget *iface)
67 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
68 ULONG refcount = InterlockedIncrement(&render_target->refcount);
70 TRACE("%p increasing refcount to %u.\n", iface, refcount);
72 return refcount;
75 static ULONG STDMETHODCALLTYPE d2d_hwnd_render_target_Release(ID2D1HwndRenderTarget *iface)
77 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
78 ULONG refcount = InterlockedDecrement(&render_target->refcount);
80 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
82 if (!refcount)
84 ID2D1RenderTarget_Release(render_target->dxgi_target);
85 IDXGISwapChain_Release(render_target->swapchain);
86 heap_free(render_target);
89 return refcount;
92 static void STDMETHODCALLTYPE d2d_hwnd_render_target_GetFactory(ID2D1HwndRenderTarget *iface, ID2D1Factory **factory)
94 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
96 TRACE("iface %p, factory %p.\n", iface, factory);
98 ID2D1RenderTarget_GetFactory(render_target->dxgi_target, factory);
101 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateBitmap(ID2D1HwndRenderTarget *iface,
102 D2D1_SIZE_U size, const void *src_data, UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
104 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
106 TRACE("iface %p, size {%u, %u}, src_data %p, pitch %u, desc %p, bitmap %p.\n",
107 iface, size.width, size.height, src_data, pitch, desc, bitmap);
109 return ID2D1RenderTarget_CreateBitmap(render_target->dxgi_target, size, src_data, pitch, desc, bitmap);
112 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateBitmapFromWicBitmap(ID2D1HwndRenderTarget *iface,
113 IWICBitmapSource *bitmap_source, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
115 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
117 TRACE("iface %p, bitmap_source %p, desc %p, bitmap %p.\n",
118 iface, bitmap_source, desc, bitmap);
120 return ID2D1RenderTarget_CreateBitmapFromWicBitmap(render_target->dxgi_target, bitmap_source, desc, bitmap);
123 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateSharedBitmap(ID2D1HwndRenderTarget *iface,
124 REFIID iid, void *data, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
126 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
128 TRACE("iface %p, iid %s, data %p, desc %p, bitmap %p.\n",
129 iface, debugstr_guid(iid), data, desc, bitmap);
131 return ID2D1RenderTarget_CreateSharedBitmap(render_target->dxgi_target, iid, data, desc, bitmap);
134 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateBitmapBrush(ID2D1HwndRenderTarget *iface,
135 ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc,
136 const D2D1_BRUSH_PROPERTIES *brush_desc, ID2D1BitmapBrush **brush)
138 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
140 TRACE("iface %p, bitmap %p, bitmap_brush_desc %p, brush_desc %p, brush %p.\n",
141 iface, bitmap, bitmap_brush_desc, brush_desc, brush);
143 return ID2D1RenderTarget_CreateBitmapBrush(render_target->dxgi_target,
144 bitmap, bitmap_brush_desc, brush_desc, brush);
147 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateSolidColorBrush(ID2D1HwndRenderTarget *iface,
148 const D2D1_COLOR_F *color, const D2D1_BRUSH_PROPERTIES *desc, ID2D1SolidColorBrush **brush)
150 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
152 TRACE("iface %p, color %p, desc %p, brush %p.\n", iface, color, desc, brush);
154 return ID2D1RenderTarget_CreateSolidColorBrush(render_target->dxgi_target, color, desc, brush);
157 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateGradientStopCollection(ID2D1HwndRenderTarget *iface,
158 const D2D1_GRADIENT_STOP *stops, UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode,
159 ID2D1GradientStopCollection **gradient)
161 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
163 TRACE("iface %p, stops %p, stop_count %u, gamma %#x, extend_mode %#x, gradient %p.\n",
164 iface, stops, stop_count, gamma, extend_mode, gradient);
166 return ID2D1RenderTarget_CreateGradientStopCollection(render_target->dxgi_target,
167 stops, stop_count, gamma, extend_mode, gradient);
170 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateLinearGradientBrush(ID2D1HwndRenderTarget *iface,
171 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
172 ID2D1GradientStopCollection *gradient, ID2D1LinearGradientBrush **brush)
174 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
176 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
177 iface, gradient_brush_desc, brush_desc, gradient, brush);
179 return ID2D1RenderTarget_CreateLinearGradientBrush(render_target->dxgi_target,
180 gradient_brush_desc, brush_desc, gradient, brush);
183 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateRadialGradientBrush(ID2D1HwndRenderTarget *iface,
184 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
185 ID2D1GradientStopCollection *gradient, ID2D1RadialGradientBrush **brush)
187 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
189 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
190 iface, gradient_brush_desc, brush_desc, gradient, brush);
192 return ID2D1RenderTarget_CreateRadialGradientBrush(render_target->dxgi_target,
193 gradient_brush_desc, brush_desc, gradient, brush);
196 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateCompatibleRenderTarget(ID2D1HwndRenderTarget *iface,
197 const D2D1_SIZE_F *size, const D2D1_SIZE_U *pixel_size, const D2D1_PIXEL_FORMAT *format,
198 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options, ID2D1BitmapRenderTarget **render_target)
200 struct d2d_hwnd_render_target *rt = impl_from_ID2D1HwndRenderTarget(iface);
202 TRACE("iface %p, size %p, pixel_size %p, format %p, options %#x, render_target %p,\n",
203 iface, size, pixel_size, format, options, render_target);
205 return ID2D1RenderTarget_CreateCompatibleRenderTarget(rt->dxgi_target,
206 size, pixel_size, format, options, render_target);
209 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateLayer(ID2D1HwndRenderTarget *iface,
210 const D2D1_SIZE_F *size, ID2D1Layer **layer)
212 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
214 TRACE("iface %p, size %p, layer %p.\n", iface, size, layer);
216 return ID2D1RenderTarget_CreateLayer(render_target->dxgi_target, size, layer);
219 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_CreateMesh(ID2D1HwndRenderTarget *iface, ID2D1Mesh **mesh)
221 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
223 TRACE("iface %p, mesh %p.\n", iface, mesh);
225 return ID2D1RenderTarget_CreateMesh(render_target->dxgi_target, mesh);
228 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawLine(ID2D1HwndRenderTarget *iface,
229 D2D1_POINT_2F p0, D2D1_POINT_2F p1, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
231 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
233 TRACE("iface %p, p0 {%.8e, %.8e}, p1 {%.8e, %.8e}, brush %p, stroke_width %.8e, stroke_style %p.\n",
234 iface, p0.x, p0.y, p1.x, p1.y, brush, stroke_width, stroke_style);
236 ID2D1RenderTarget_DrawLine(render_target->dxgi_target, p0, p1, brush, stroke_width, stroke_style);
239 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawRectangle(ID2D1HwndRenderTarget *iface,
240 const D2D1_RECT_F *rect, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
242 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
244 TRACE("iface %p, rect %s, brush %p, stroke_width %.8e, stroke_style %p.\n",
245 iface, debug_d2d_rect_f(rect), brush, stroke_width, stroke_style);
247 ID2D1RenderTarget_DrawRectangle(render_target->dxgi_target, rect, brush, stroke_width, stroke_style);
250 static void STDMETHODCALLTYPE d2d_hwnd_render_target_FillRectangle(ID2D1HwndRenderTarget *iface,
251 const D2D1_RECT_F *rect, ID2D1Brush *brush)
253 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
255 TRACE("iface %p, rect %s, brush %p.\n", iface, debug_d2d_rect_f(rect), brush);
257 ID2D1RenderTarget_FillRectangle(render_target->dxgi_target, rect, brush);
260 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawRoundedRectangle(ID2D1HwndRenderTarget *iface,
261 const D2D1_ROUNDED_RECT *rect, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
263 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
265 TRACE("iface %p, rect %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
266 iface, rect, brush, stroke_width, stroke_style);
268 ID2D1RenderTarget_DrawRoundedRectangle(render_target->dxgi_target, rect, brush, stroke_width, stroke_style);
271 static void STDMETHODCALLTYPE d2d_hwnd_render_target_FillRoundedRectangle(ID2D1HwndRenderTarget *iface,
272 const D2D1_ROUNDED_RECT *rect, ID2D1Brush *brush)
274 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
276 TRACE("iface %p, rect %p, brush %p.\n", iface, rect, brush);
278 ID2D1RenderTarget_FillRoundedRectangle(render_target->dxgi_target, rect, brush);
281 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawEllipse(ID2D1HwndRenderTarget *iface,
282 const D2D1_ELLIPSE *ellipse, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
284 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
286 TRACE("iface %p, ellipse %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
287 iface, ellipse, brush, stroke_width, stroke_style);
289 ID2D1RenderTarget_DrawEllipse(render_target->dxgi_target, ellipse, brush, stroke_width, stroke_style);
292 static void STDMETHODCALLTYPE d2d_hwnd_render_target_FillEllipse(ID2D1HwndRenderTarget *iface,
293 const D2D1_ELLIPSE *ellipse, ID2D1Brush *brush)
295 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
297 TRACE("iface %p, ellipse %p, brush %p.\n", iface, ellipse, brush);
299 ID2D1RenderTarget_FillEllipse(render_target->dxgi_target, ellipse, brush);
302 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawGeometry(ID2D1HwndRenderTarget *iface,
303 ID2D1Geometry *geometry, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
305 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
307 TRACE("iface %p, geometry %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
308 iface, geometry, brush, stroke_width, stroke_style);
310 ID2D1RenderTarget_DrawGeometry(render_target->dxgi_target, geometry, brush, stroke_width, stroke_style);
313 static void STDMETHODCALLTYPE d2d_hwnd_render_target_FillGeometry(ID2D1HwndRenderTarget *iface,
314 ID2D1Geometry *geometry, ID2D1Brush *brush, ID2D1Brush *opacity_brush)
316 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
318 TRACE("iface %p, geometry %p, brush %p, opacity_brush %p.\n", iface, geometry, brush, opacity_brush);
320 ID2D1RenderTarget_FillGeometry(render_target->dxgi_target, geometry, brush, opacity_brush);
323 static void STDMETHODCALLTYPE d2d_hwnd_render_target_FillMesh(ID2D1HwndRenderTarget *iface,
324 ID2D1Mesh *mesh, ID2D1Brush *brush)
326 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
328 TRACE("iface %p, mesh %p, brush %p.\n", iface, mesh, brush);
330 ID2D1RenderTarget_FillMesh(render_target->dxgi_target, mesh, brush);
333 static void STDMETHODCALLTYPE d2d_hwnd_render_target_FillOpacityMask(ID2D1HwndRenderTarget *iface,
334 ID2D1Bitmap *mask, ID2D1Brush *brush, D2D1_OPACITY_MASK_CONTENT content,
335 const D2D1_RECT_F *dst_rect, const D2D1_RECT_F *src_rect)
337 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
339 TRACE("iface %p, mask %p, brush %p, content %#x, dst_rect %s, src_rect %s.\n",
340 iface, mask, brush, content, debug_d2d_rect_f(dst_rect), debug_d2d_rect_f(src_rect));
342 ID2D1RenderTarget_FillOpacityMask(render_target->dxgi_target,
343 mask, brush, content, dst_rect, src_rect);
346 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawBitmap(ID2D1HwndRenderTarget *iface,
347 ID2D1Bitmap *bitmap, const D2D1_RECT_F *dst_rect, float opacity,
348 D2D1_BITMAP_INTERPOLATION_MODE interpolation_mode, const D2D1_RECT_F *src_rect)
350 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
352 TRACE("iface %p, bitmap %p, dst_rect %s, opacity %.8e, interpolation_mode %#x, src_rect %s.\n",
353 iface, bitmap, debug_d2d_rect_f(dst_rect), opacity, interpolation_mode, debug_d2d_rect_f(src_rect));
355 ID2D1RenderTarget_DrawBitmap(render_target->dxgi_target,
356 bitmap, dst_rect, opacity, interpolation_mode, src_rect);
359 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawText(ID2D1HwndRenderTarget *iface,
360 const WCHAR *string, UINT32 string_len, IDWriteTextFormat *text_format, const D2D1_RECT_F *layout_rect,
361 ID2D1Brush *brush, D2D1_DRAW_TEXT_OPTIONS options, DWRITE_MEASURING_MODE measuring_mode)
363 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
365 TRACE("iface %p, string %s, string_len %u, text_format %p, layout_rect %s, "
366 "brush %p, options %#x, measuring_mode %#x.\n",
367 iface, debugstr_wn(string, string_len), string_len, text_format, debug_d2d_rect_f(layout_rect),
368 brush, options, measuring_mode);
370 ID2D1RenderTarget_DrawText(render_target->dxgi_target, string, string_len,
371 text_format, layout_rect, brush, options, measuring_mode);
374 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawTextLayout(ID2D1HwndRenderTarget *iface,
375 D2D1_POINT_2F origin, IDWriteTextLayout *layout, ID2D1Brush *brush, D2D1_DRAW_TEXT_OPTIONS options)
377 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
379 TRACE("iface %p, origin {%.8e, %.8e}, layout %p, brush %p, options %#x.\n",
380 iface, origin.x, origin.y, layout, brush, options);
382 ID2D1RenderTarget_DrawTextLayout(render_target->dxgi_target, origin, layout, brush, options);
385 static void STDMETHODCALLTYPE d2d_hwnd_render_target_DrawGlyphRun(ID2D1HwndRenderTarget *iface,
386 D2D1_POINT_2F baseline_origin, const DWRITE_GLYPH_RUN *glyph_run, ID2D1Brush *brush,
387 DWRITE_MEASURING_MODE measuring_mode)
389 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
391 TRACE("iface %p, baseline_origin {%.8e, %.8e}, glyph_run %p, brush %p, measuring_mode %#x.\n",
392 iface, baseline_origin.x, baseline_origin.y, glyph_run, brush, measuring_mode);
394 ID2D1RenderTarget_DrawGlyphRun(render_target->dxgi_target,
395 baseline_origin, glyph_run, brush, measuring_mode);
398 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetTransform(ID2D1HwndRenderTarget *iface,
399 const D2D1_MATRIX_3X2_F *transform)
401 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
403 TRACE("iface %p, transform %p.\n", iface, transform);
405 ID2D1RenderTarget_SetTransform(render_target->dxgi_target, transform);
408 static void STDMETHODCALLTYPE d2d_hwnd_render_target_GetTransform(ID2D1HwndRenderTarget *iface,
409 D2D1_MATRIX_3X2_F *transform)
411 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
413 TRACE("iface %p, transform %p.\n", iface, transform);
415 ID2D1RenderTarget_GetTransform(render_target->dxgi_target, transform);
418 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetAntialiasMode(ID2D1HwndRenderTarget *iface,
419 D2D1_ANTIALIAS_MODE antialias_mode)
421 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
423 TRACE("iface %p, antialias_mode %#x.\n", iface, antialias_mode);
425 ID2D1RenderTarget_SetAntialiasMode(render_target->dxgi_target, antialias_mode);
428 static D2D1_ANTIALIAS_MODE STDMETHODCALLTYPE d2d_hwnd_render_target_GetAntialiasMode(ID2D1HwndRenderTarget *iface)
430 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
432 TRACE("iface %p.\n", iface);
434 return ID2D1RenderTarget_GetAntialiasMode(render_target->dxgi_target);
437 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetTextAntialiasMode(ID2D1HwndRenderTarget *iface,
438 D2D1_TEXT_ANTIALIAS_MODE antialias_mode)
440 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
442 TRACE("iface %p, antialias_mode %#x.\n", iface, antialias_mode);
444 ID2D1RenderTarget_SetTextAntialiasMode(render_target->dxgi_target, antialias_mode);
447 static D2D1_TEXT_ANTIALIAS_MODE STDMETHODCALLTYPE d2d_hwnd_render_target_GetTextAntialiasMode(
448 ID2D1HwndRenderTarget *iface)
450 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
452 TRACE("iface %p.\n", iface);
454 return ID2D1RenderTarget_GetTextAntialiasMode(render_target->dxgi_target);
457 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetTextRenderingParams(ID2D1HwndRenderTarget *iface,
458 IDWriteRenderingParams *text_rendering_params)
460 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
462 TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
464 ID2D1RenderTarget_SetTextRenderingParams(render_target->dxgi_target, text_rendering_params);
467 static void STDMETHODCALLTYPE d2d_hwnd_render_target_GetTextRenderingParams(ID2D1HwndRenderTarget *iface,
468 IDWriteRenderingParams **text_rendering_params)
470 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
472 TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
474 ID2D1RenderTarget_GetTextRenderingParams(render_target->dxgi_target, text_rendering_params);
477 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetTags(ID2D1HwndRenderTarget *iface, D2D1_TAG tag1, D2D1_TAG tag2)
479 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
481 TRACE("iface %p, tag1 %s, tag2 %s.\n", iface, wine_dbgstr_longlong(tag1), wine_dbgstr_longlong(tag2));
483 ID2D1RenderTarget_SetTags(render_target->dxgi_target, tag1, tag2);
486 static void STDMETHODCALLTYPE d2d_hwnd_render_target_GetTags(ID2D1HwndRenderTarget *iface, D2D1_TAG *tag1,
487 D2D1_TAG *tag2)
489 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
491 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
493 ID2D1RenderTarget_GetTags(render_target->dxgi_target, tag1, tag2);
496 static void STDMETHODCALLTYPE d2d_hwnd_render_target_PushLayer(ID2D1HwndRenderTarget *iface,
497 const D2D1_LAYER_PARAMETERS *layer_parameters, ID2D1Layer *layer)
499 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
501 TRACE("iface %p, layer_parameters %p, layer %p.\n", iface, layer_parameters, layer);
503 ID2D1RenderTarget_PushLayer(render_target->dxgi_target, layer_parameters, layer);
506 static void STDMETHODCALLTYPE d2d_hwnd_render_target_PopLayer(ID2D1HwndRenderTarget *iface)
508 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
510 TRACE("iface %p.\n", iface);
512 ID2D1RenderTarget_PopLayer(render_target->dxgi_target);
515 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_Flush(ID2D1HwndRenderTarget *iface, D2D1_TAG *tag1,
516 D2D1_TAG *tag2)
518 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
519 HRESULT hr;
521 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
523 hr = ID2D1RenderTarget_Flush(render_target->dxgi_target, tag1, tag2);
524 render_target_present(render_target);
526 return hr;
529 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SaveDrawingState(ID2D1HwndRenderTarget *iface,
530 ID2D1DrawingStateBlock *state_block)
532 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
534 TRACE("iface %p, state_block %p.\n", iface, state_block);
536 ID2D1RenderTarget_SaveDrawingState(render_target->dxgi_target, state_block);
539 static void STDMETHODCALLTYPE d2d_hwnd_render_target_RestoreDrawingState(ID2D1HwndRenderTarget *iface,
540 ID2D1DrawingStateBlock *state_block)
542 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
544 TRACE("iface %p, state_block %p.\n", iface, state_block);
546 ID2D1RenderTarget_RestoreDrawingState(render_target->dxgi_target, state_block);
549 static void STDMETHODCALLTYPE d2d_hwnd_render_target_PushAxisAlignedClip(ID2D1HwndRenderTarget *iface,
550 const D2D1_RECT_F *clip_rect, D2D1_ANTIALIAS_MODE antialias_mode)
552 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
554 TRACE("iface %p, clip_rect %s, antialias_mode %#x.\n", iface, debug_d2d_rect_f(clip_rect), antialias_mode);
556 ID2D1RenderTarget_PushAxisAlignedClip(render_target->dxgi_target, clip_rect, antialias_mode);
559 static void STDMETHODCALLTYPE d2d_hwnd_render_target_PopAxisAlignedClip(ID2D1HwndRenderTarget *iface)
561 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
563 TRACE("iface %p.\n", iface);
565 ID2D1RenderTarget_PopAxisAlignedClip(render_target->dxgi_target);
568 static void STDMETHODCALLTYPE d2d_hwnd_render_target_Clear(ID2D1HwndRenderTarget *iface, const D2D1_COLOR_F *color)
570 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
572 TRACE("iface %p, color %p.\n", iface, color);
574 ID2D1RenderTarget_Clear(render_target->dxgi_target, color);
577 static void STDMETHODCALLTYPE d2d_hwnd_render_target_BeginDraw(ID2D1HwndRenderTarget *iface)
579 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
581 TRACE("iface %p.\n", iface);
583 ID2D1RenderTarget_BeginDraw(render_target->dxgi_target);
586 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_EndDraw(ID2D1HwndRenderTarget *iface,
587 D2D1_TAG *tag1, D2D1_TAG *tag2)
589 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
590 HRESULT hr;
592 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
594 hr = ID2D1RenderTarget_EndDraw(render_target->dxgi_target, tag1, tag2);
595 render_target_present(render_target);
597 return hr;
600 static D2D1_PIXEL_FORMAT * STDMETHODCALLTYPE d2d_hwnd_render_target_GetPixelFormat(ID2D1HwndRenderTarget *iface,
601 D2D1_PIXEL_FORMAT *format)
603 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
605 TRACE("iface %p, format %p.\n", iface, format);
607 *format = ID2D1RenderTarget_GetPixelFormat(render_target->dxgi_target);
608 return format;
611 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetDpi(ID2D1HwndRenderTarget *iface, float dpi_x, float dpi_y)
613 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
615 TRACE("iface %p, dpi_x %.8e, dpi_y %.8e.\n", iface, dpi_x, dpi_y);
617 ID2D1RenderTarget_SetDpi(render_target->dxgi_target, dpi_x, dpi_y);
620 static void STDMETHODCALLTYPE d2d_hwnd_render_target_GetDpi(ID2D1HwndRenderTarget *iface, float *dpi_x, float *dpi_y)
622 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
624 TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface, dpi_x, dpi_y);
626 ID2D1RenderTarget_GetDpi(render_target->dxgi_target, dpi_x, dpi_y);
629 static D2D1_SIZE_F * STDMETHODCALLTYPE d2d_hwnd_render_target_GetSize(ID2D1HwndRenderTarget *iface, D2D1_SIZE_F *size)
631 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
633 TRACE("iface %p, size %p.\n", iface, size);
635 *size = ID2D1RenderTarget_GetSize(render_target->dxgi_target);
636 return size;
639 static D2D1_SIZE_U * STDMETHODCALLTYPE d2d_hwnd_render_target_GetPixelSize(ID2D1HwndRenderTarget *iface,
640 D2D1_SIZE_U *pixel_size)
642 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
644 TRACE("iface %p, pixel_size %p.\n", iface, pixel_size);
646 *pixel_size = ID2D1RenderTarget_GetPixelSize(render_target->dxgi_target);
647 return pixel_size;
650 static UINT32 STDMETHODCALLTYPE d2d_hwnd_render_target_GetMaximumBitmapSize(ID2D1HwndRenderTarget *iface)
652 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
654 TRACE("iface %p.\n", iface);
656 return ID2D1RenderTarget_GetMaximumBitmapSize(render_target->dxgi_target);
659 static BOOL STDMETHODCALLTYPE d2d_hwnd_render_target_IsSupported(ID2D1HwndRenderTarget *iface,
660 const D2D1_RENDER_TARGET_PROPERTIES *desc)
662 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
664 TRACE("iface %p, desc %p.\n", iface, desc);
666 return ID2D1RenderTarget_IsSupported(render_target->dxgi_target, desc);
669 static D2D1_WINDOW_STATE STDMETHODCALLTYPE d2d_hwnd_render_target_CheckWindowState(ID2D1HwndRenderTarget *iface)
671 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
673 TRACE("iface %p.\n", iface);
675 return IDXGISwapChain_Present(render_target->swapchain, render_target->sync_interval, DXGI_PRESENT_TEST) ==
676 DXGI_STATUS_OCCLUDED ? D2D1_WINDOW_STATE_OCCLUDED : D2D1_WINDOW_STATE_NONE;
679 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_Resize(ID2D1HwndRenderTarget *iface, const D2D1_SIZE_U *size)
681 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
682 IDXGISurface1 *dxgi_surface;
683 HRESULT hr;
685 TRACE("iface %p, width %u, height %u.\n", iface, size->width, size->height);
687 d2d_d3d_render_target_create_rtv(render_target->dxgi_target, NULL);
689 if (SUCCEEDED(hr = IDXGISwapChain_ResizeBuffers(render_target->swapchain, 1, size->width, size->height,
690 DXGI_FORMAT_UNKNOWN, 0)))
692 if (FAILED(hr = IDXGISwapChain_GetBuffer(render_target->swapchain, 0, &IID_IDXGISurface1,
693 (void **)&dxgi_surface)))
695 WARN("Failed to get buffer, hr %#x.\n", hr);
696 return hr;
699 hr = d2d_d3d_render_target_create_rtv(render_target->dxgi_target, dxgi_surface);
700 IDXGISurface1_Release(dxgi_surface);
703 return hr;
706 static HWND STDMETHODCALLTYPE d2d_hwnd_render_target_GetHwnd(ID2D1HwndRenderTarget *iface)
708 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
710 TRACE("iface %p.\n", iface);
712 return render_target->hwnd;
715 static const struct ID2D1HwndRenderTargetVtbl d2d_hwnd_render_target_vtbl =
717 d2d_hwnd_render_target_QueryInterface,
718 d2d_hwnd_render_target_AddRef,
719 d2d_hwnd_render_target_Release,
720 d2d_hwnd_render_target_GetFactory,
721 d2d_hwnd_render_target_CreateBitmap,
722 d2d_hwnd_render_target_CreateBitmapFromWicBitmap,
723 d2d_hwnd_render_target_CreateSharedBitmap,
724 d2d_hwnd_render_target_CreateBitmapBrush,
725 d2d_hwnd_render_target_CreateSolidColorBrush,
726 d2d_hwnd_render_target_CreateGradientStopCollection,
727 d2d_hwnd_render_target_CreateLinearGradientBrush,
728 d2d_hwnd_render_target_CreateRadialGradientBrush,
729 d2d_hwnd_render_target_CreateCompatibleRenderTarget,
730 d2d_hwnd_render_target_CreateLayer,
731 d2d_hwnd_render_target_CreateMesh,
732 d2d_hwnd_render_target_DrawLine,
733 d2d_hwnd_render_target_DrawRectangle,
734 d2d_hwnd_render_target_FillRectangle,
735 d2d_hwnd_render_target_DrawRoundedRectangle,
736 d2d_hwnd_render_target_FillRoundedRectangle,
737 d2d_hwnd_render_target_DrawEllipse,
738 d2d_hwnd_render_target_FillEllipse,
739 d2d_hwnd_render_target_DrawGeometry,
740 d2d_hwnd_render_target_FillGeometry,
741 d2d_hwnd_render_target_FillMesh,
742 d2d_hwnd_render_target_FillOpacityMask,
743 d2d_hwnd_render_target_DrawBitmap,
744 d2d_hwnd_render_target_DrawText,
745 d2d_hwnd_render_target_DrawTextLayout,
746 d2d_hwnd_render_target_DrawGlyphRun,
747 d2d_hwnd_render_target_SetTransform,
748 d2d_hwnd_render_target_GetTransform,
749 d2d_hwnd_render_target_SetAntialiasMode,
750 d2d_hwnd_render_target_GetAntialiasMode,
751 d2d_hwnd_render_target_SetTextAntialiasMode,
752 d2d_hwnd_render_target_GetTextAntialiasMode,
753 d2d_hwnd_render_target_SetTextRenderingParams,
754 d2d_hwnd_render_target_GetTextRenderingParams,
755 d2d_hwnd_render_target_SetTags,
756 d2d_hwnd_render_target_GetTags,
757 d2d_hwnd_render_target_PushLayer,
758 d2d_hwnd_render_target_PopLayer,
759 d2d_hwnd_render_target_Flush,
760 d2d_hwnd_render_target_SaveDrawingState,
761 d2d_hwnd_render_target_RestoreDrawingState,
762 d2d_hwnd_render_target_PushAxisAlignedClip,
763 d2d_hwnd_render_target_PopAxisAlignedClip,
764 d2d_hwnd_render_target_Clear,
765 d2d_hwnd_render_target_BeginDraw,
766 d2d_hwnd_render_target_EndDraw,
767 d2d_hwnd_render_target_GetPixelFormat,
768 d2d_hwnd_render_target_SetDpi,
769 d2d_hwnd_render_target_GetDpi,
770 d2d_hwnd_render_target_GetSize,
771 d2d_hwnd_render_target_GetPixelSize,
772 d2d_hwnd_render_target_GetMaximumBitmapSize,
773 d2d_hwnd_render_target_IsSupported,
774 d2d_hwnd_render_target_CheckWindowState,
775 d2d_hwnd_render_target_Resize,
776 d2d_hwnd_render_target_GetHwnd
779 HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target, ID2D1Factory *factory,
780 ID3D10Device1 *device, const D2D1_RENDER_TARGET_PROPERTIES *desc,
781 const D2D1_HWND_RENDER_TARGET_PROPERTIES *hwnd_rt_desc)
783 D2D1_RENDER_TARGET_PROPERTIES dxgi_rt_desc;
784 DXGI_SWAP_CHAIN_DESC swapchain_desc;
785 IDXGIAdapter *dxgi_adapter;
786 IDXGIFactory *dxgi_factory;
787 IDXGISurface *dxgi_surface;
788 IDXGIDevice *dxgi_device;
789 HRESULT hr;
791 if (!IsWindow(hwnd_rt_desc->hwnd))
792 return HRESULT_FROM_WIN32(ERROR_INVALID_WINDOW_HANDLE);
794 render_target->ID2D1HwndRenderTarget_iface.lpVtbl = &d2d_hwnd_render_target_vtbl;
795 render_target->refcount = 1;
796 render_target->hwnd = hwnd_rt_desc->hwnd;
797 render_target->sync_interval = hwnd_rt_desc->presentOptions & D2D1_PRESENT_OPTIONS_IMMEDIATELY ? 0 : 1;
799 if (FAILED(hr = ID3D10Device1_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device)))
801 WARN("Failed to get IDXGIDevice interface, hr %#x.\n", hr);
802 return hr;
805 hr = IDXGIDevice_GetAdapter(dxgi_device, &dxgi_adapter);
806 IDXGIDevice_Release(dxgi_device);
807 if (FAILED(hr))
809 WARN("Failed to get IDXGIAdapter interface, hr %#x.\n", hr);
810 return hr;
813 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&dxgi_factory);
814 IDXGIAdapter_Release(dxgi_adapter);
815 if (FAILED(hr))
817 WARN("Failed to get IDXGIFactory interface, hr %#x.\n", hr);
818 return hr;
821 dxgi_rt_desc = *desc;
822 if (dxgi_rt_desc.dpiX == 0.0f && dxgi_rt_desc.dpiY == 0.0f)
823 ID2D1Factory_GetDesktopDpi(factory, &dxgi_rt_desc.dpiX, &dxgi_rt_desc.dpiY);
825 if (dxgi_rt_desc.pixelFormat.format == DXGI_FORMAT_UNKNOWN)
827 dxgi_rt_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
828 dxgi_rt_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE;
831 swapchain_desc.BufferDesc.Width = hwnd_rt_desc->pixelSize.width;
832 swapchain_desc.BufferDesc.Height = hwnd_rt_desc->pixelSize.height;
833 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
834 swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
835 swapchain_desc.BufferDesc.Format = dxgi_rt_desc.pixelFormat.format;
836 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
837 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
838 swapchain_desc.SampleDesc.Count = 1;
839 swapchain_desc.SampleDesc.Quality = 0;
840 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
841 swapchain_desc.BufferCount = 1;
842 swapchain_desc.OutputWindow = hwnd_rt_desc->hwnd;
843 swapchain_desc.Windowed = TRUE;
844 swapchain_desc.SwapEffect = hwnd_rt_desc->presentOptions & D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS ?
845 DXGI_SWAP_EFFECT_SEQUENTIAL : DXGI_SWAP_EFFECT_DISCARD;
846 swapchain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE;
848 hr = IDXGIFactory_CreateSwapChain(dxgi_factory, (IUnknown *)device, &swapchain_desc, &render_target->swapchain);
849 IDXGIFactory_Release(dxgi_factory);
850 if (FAILED(hr))
852 WARN("Failed to create a swapchain, hr %#x.\n", hr);
853 return hr;
856 if (FAILED(hr = IDXGISwapChain_GetBuffer(render_target->swapchain, 0, &IID_IDXGISurface, (void **)&dxgi_surface)))
858 WARN("Failed to get buffer, hr %#x.\n", hr);
859 IDXGISwapChain_Release(render_target->swapchain);
860 return hr;
863 render_target->ID2D1HwndRenderTarget_iface.lpVtbl = &d2d_hwnd_render_target_vtbl;
864 hr = d2d_d3d_create_render_target(factory, dxgi_surface, (IUnknown *)&render_target->ID2D1HwndRenderTarget_iface,
865 &dxgi_rt_desc, &render_target->dxgi_target);
866 IDXGISurface_Release(dxgi_surface);
867 if (FAILED(hr))
869 WARN("Failed to create DXGI surface render target, hr %#x.\n", hr);
870 IDXGISwapChain_Release(render_target->swapchain);
871 return hr;
874 return S_OK;