d3dcompiler_43/tests: Fix the spelling of a couple of ok() messages.
[wine/zf.git] / dlls / d2d1 / hwnd_render_target.c
blob625f101eaa73a0e35406e7d1d5bbfcf28e148d1b
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_hwnd_render_target *impl_from_IUnknown(IUnknown *iface)
26 return CONTAINING_RECORD(iface, struct d2d_hwnd_render_target, ID2D1HwndRenderTarget_iface);
29 static HRESULT d2d_hwnd_render_target_present(IUnknown *outer_unknown)
31 struct d2d_hwnd_render_target *render_target = impl_from_IUnknown(outer_unknown);
32 HRESULT hr;
34 if (FAILED(hr = IDXGISwapChain_Present(render_target->swapchain, render_target->sync_interval, 0)))
35 WARN("Present failed, %#x.\n", hr);
37 return S_OK;
40 static inline struct d2d_hwnd_render_target *impl_from_ID2D1HwndRenderTarget(ID2D1HwndRenderTarget *iface)
42 return CONTAINING_RECORD(iface, struct d2d_hwnd_render_target, ID2D1HwndRenderTarget_iface);
45 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_QueryInterface(ID2D1HwndRenderTarget *iface,
46 REFIID iid, void **out)
48 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
50 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
52 if (IsEqualGUID(iid, &IID_ID2D1HwndRenderTarget)
53 || IsEqualGUID(iid, &IID_ID2D1RenderTarget)
54 || IsEqualGUID(iid, &IID_ID2D1Resource)
55 || IsEqualGUID(iid, &IID_IUnknown))
57 ID2D1HwndRenderTarget_AddRef(iface);
58 *out = iface;
59 return S_OK;
62 return IUnknown_QueryInterface(render_target->dxgi_inner, iid, out);
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 IUnknown_Release(render_target->dxgi_inner);
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 %s, p1 %s, brush %p, stroke_width %.8e, stroke_style %p.\n",
234 iface, debug_d2d_point_2f(&p0), debug_d2d_point_2f(&p1), 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 %s, layout %p, brush %p, options %#x.\n",
380 iface, debug_d2d_point_2f(&origin), 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 %s, glyph_run %p, brush %p, measuring_mode %#x.\n",
392 iface, debug_d2d_point_2f(&baseline_origin), 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);
520 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
522 return ID2D1RenderTarget_Flush(render_target->dxgi_target, tag1, tag2);
525 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SaveDrawingState(ID2D1HwndRenderTarget *iface,
526 ID2D1DrawingStateBlock *state_block)
528 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
530 TRACE("iface %p, state_block %p.\n", iface, state_block);
532 ID2D1RenderTarget_SaveDrawingState(render_target->dxgi_target, state_block);
535 static void STDMETHODCALLTYPE d2d_hwnd_render_target_RestoreDrawingState(ID2D1HwndRenderTarget *iface,
536 ID2D1DrawingStateBlock *state_block)
538 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
540 TRACE("iface %p, state_block %p.\n", iface, state_block);
542 ID2D1RenderTarget_RestoreDrawingState(render_target->dxgi_target, state_block);
545 static void STDMETHODCALLTYPE d2d_hwnd_render_target_PushAxisAlignedClip(ID2D1HwndRenderTarget *iface,
546 const D2D1_RECT_F *clip_rect, D2D1_ANTIALIAS_MODE antialias_mode)
548 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
550 TRACE("iface %p, clip_rect %s, antialias_mode %#x.\n", iface, debug_d2d_rect_f(clip_rect), antialias_mode);
552 ID2D1RenderTarget_PushAxisAlignedClip(render_target->dxgi_target, clip_rect, antialias_mode);
555 static void STDMETHODCALLTYPE d2d_hwnd_render_target_PopAxisAlignedClip(ID2D1HwndRenderTarget *iface)
557 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
559 TRACE("iface %p.\n", iface);
561 ID2D1RenderTarget_PopAxisAlignedClip(render_target->dxgi_target);
564 static void STDMETHODCALLTYPE d2d_hwnd_render_target_Clear(ID2D1HwndRenderTarget *iface, const D2D1_COLOR_F *color)
566 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
568 TRACE("iface %p, color %p.\n", iface, color);
570 ID2D1RenderTarget_Clear(render_target->dxgi_target, color);
573 static void STDMETHODCALLTYPE d2d_hwnd_render_target_BeginDraw(ID2D1HwndRenderTarget *iface)
575 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
577 TRACE("iface %p.\n", iface);
579 ID2D1RenderTarget_BeginDraw(render_target->dxgi_target);
582 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_EndDraw(ID2D1HwndRenderTarget *iface,
583 D2D1_TAG *tag1, D2D1_TAG *tag2)
585 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
587 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
589 return ID2D1RenderTarget_EndDraw(render_target->dxgi_target, tag1, tag2);
592 static D2D1_PIXEL_FORMAT * STDMETHODCALLTYPE d2d_hwnd_render_target_GetPixelFormat(ID2D1HwndRenderTarget *iface,
593 D2D1_PIXEL_FORMAT *format)
595 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
597 TRACE("iface %p, format %p.\n", iface, format);
599 *format = ID2D1RenderTarget_GetPixelFormat(render_target->dxgi_target);
600 return format;
603 static void STDMETHODCALLTYPE d2d_hwnd_render_target_SetDpi(ID2D1HwndRenderTarget *iface, float dpi_x, float dpi_y)
605 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
607 TRACE("iface %p, dpi_x %.8e, dpi_y %.8e.\n", iface, dpi_x, dpi_y);
609 ID2D1RenderTarget_SetDpi(render_target->dxgi_target, dpi_x, dpi_y);
612 static void STDMETHODCALLTYPE d2d_hwnd_render_target_GetDpi(ID2D1HwndRenderTarget *iface, float *dpi_x, float *dpi_y)
614 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
616 TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface, dpi_x, dpi_y);
618 ID2D1RenderTarget_GetDpi(render_target->dxgi_target, dpi_x, dpi_y);
621 static D2D1_SIZE_F * STDMETHODCALLTYPE d2d_hwnd_render_target_GetSize(ID2D1HwndRenderTarget *iface, D2D1_SIZE_F *size)
623 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
625 TRACE("iface %p, size %p.\n", iface, size);
627 *size = ID2D1RenderTarget_GetSize(render_target->dxgi_target);
628 return size;
631 static D2D1_SIZE_U * STDMETHODCALLTYPE d2d_hwnd_render_target_GetPixelSize(ID2D1HwndRenderTarget *iface,
632 D2D1_SIZE_U *pixel_size)
634 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
636 TRACE("iface %p, pixel_size %p.\n", iface, pixel_size);
638 *pixel_size = ID2D1RenderTarget_GetPixelSize(render_target->dxgi_target);
639 return pixel_size;
642 static UINT32 STDMETHODCALLTYPE d2d_hwnd_render_target_GetMaximumBitmapSize(ID2D1HwndRenderTarget *iface)
644 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
646 TRACE("iface %p.\n", iface);
648 return ID2D1RenderTarget_GetMaximumBitmapSize(render_target->dxgi_target);
651 static BOOL STDMETHODCALLTYPE d2d_hwnd_render_target_IsSupported(ID2D1HwndRenderTarget *iface,
652 const D2D1_RENDER_TARGET_PROPERTIES *desc)
654 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
656 TRACE("iface %p, desc %p.\n", iface, desc);
658 return ID2D1RenderTarget_IsSupported(render_target->dxgi_target, desc);
661 static D2D1_WINDOW_STATE STDMETHODCALLTYPE d2d_hwnd_render_target_CheckWindowState(ID2D1HwndRenderTarget *iface)
663 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
665 TRACE("iface %p.\n", iface);
667 return IDXGISwapChain_Present(render_target->swapchain, render_target->sync_interval, DXGI_PRESENT_TEST) ==
668 DXGI_STATUS_OCCLUDED ? D2D1_WINDOW_STATE_OCCLUDED : D2D1_WINDOW_STATE_NONE;
671 static HRESULT STDMETHODCALLTYPE d2d_hwnd_render_target_Resize(ID2D1HwndRenderTarget *iface, const D2D1_SIZE_U *size)
673 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
674 IDXGISurface1 *dxgi_surface;
675 ID2D1DeviceContext *context;
676 ID2D1Bitmap1 *bitmap;
677 HRESULT hr;
679 TRACE("iface %p, width %u, height %u.\n", iface, size->width, size->height);
681 ID2D1RenderTarget_QueryInterface(render_target->dxgi_target, &IID_ID2D1DeviceContext, (void **)&context);
682 ID2D1DeviceContext_SetTarget(context, NULL);
684 if (SUCCEEDED(hr = IDXGISwapChain_ResizeBuffers(render_target->swapchain, 1, size->width, size->height,
685 DXGI_FORMAT_UNKNOWN, 0)))
687 if (FAILED(hr = IDXGISwapChain_GetBuffer(render_target->swapchain, 0, &IID_IDXGISurface1,
688 (void **)&dxgi_surface)))
690 WARN("Failed to get buffer, hr %#x.\n", hr);
691 ID2D1DeviceContext_Release(context);
692 return hr;
695 hr = ID2D1DeviceContext_CreateBitmapFromDxgiSurface(context, (IDXGISurface *)dxgi_surface, NULL, &bitmap);
696 IDXGISurface1_Release(dxgi_surface);
697 if (FAILED(hr))
699 WARN("Failed to create target bitmap, hr %#x.\n", hr);
700 ID2D1DeviceContext_Release(context);
701 return hr;
704 ID2D1DeviceContext_SetTarget(context, (ID2D1Image *)bitmap);
705 ID2D1Bitmap1_Release(bitmap);
708 ID2D1DeviceContext_Release(context);
710 return hr;
713 static HWND STDMETHODCALLTYPE d2d_hwnd_render_target_GetHwnd(ID2D1HwndRenderTarget *iface)
715 struct d2d_hwnd_render_target *render_target = impl_from_ID2D1HwndRenderTarget(iface);
717 TRACE("iface %p.\n", iface);
719 return render_target->hwnd;
722 static const struct ID2D1HwndRenderTargetVtbl d2d_hwnd_render_target_vtbl =
724 d2d_hwnd_render_target_QueryInterface,
725 d2d_hwnd_render_target_AddRef,
726 d2d_hwnd_render_target_Release,
727 d2d_hwnd_render_target_GetFactory,
728 d2d_hwnd_render_target_CreateBitmap,
729 d2d_hwnd_render_target_CreateBitmapFromWicBitmap,
730 d2d_hwnd_render_target_CreateSharedBitmap,
731 d2d_hwnd_render_target_CreateBitmapBrush,
732 d2d_hwnd_render_target_CreateSolidColorBrush,
733 d2d_hwnd_render_target_CreateGradientStopCollection,
734 d2d_hwnd_render_target_CreateLinearGradientBrush,
735 d2d_hwnd_render_target_CreateRadialGradientBrush,
736 d2d_hwnd_render_target_CreateCompatibleRenderTarget,
737 d2d_hwnd_render_target_CreateLayer,
738 d2d_hwnd_render_target_CreateMesh,
739 d2d_hwnd_render_target_DrawLine,
740 d2d_hwnd_render_target_DrawRectangle,
741 d2d_hwnd_render_target_FillRectangle,
742 d2d_hwnd_render_target_DrawRoundedRectangle,
743 d2d_hwnd_render_target_FillRoundedRectangle,
744 d2d_hwnd_render_target_DrawEllipse,
745 d2d_hwnd_render_target_FillEllipse,
746 d2d_hwnd_render_target_DrawGeometry,
747 d2d_hwnd_render_target_FillGeometry,
748 d2d_hwnd_render_target_FillMesh,
749 d2d_hwnd_render_target_FillOpacityMask,
750 d2d_hwnd_render_target_DrawBitmap,
751 d2d_hwnd_render_target_DrawText,
752 d2d_hwnd_render_target_DrawTextLayout,
753 d2d_hwnd_render_target_DrawGlyphRun,
754 d2d_hwnd_render_target_SetTransform,
755 d2d_hwnd_render_target_GetTransform,
756 d2d_hwnd_render_target_SetAntialiasMode,
757 d2d_hwnd_render_target_GetAntialiasMode,
758 d2d_hwnd_render_target_SetTextAntialiasMode,
759 d2d_hwnd_render_target_GetTextAntialiasMode,
760 d2d_hwnd_render_target_SetTextRenderingParams,
761 d2d_hwnd_render_target_GetTextRenderingParams,
762 d2d_hwnd_render_target_SetTags,
763 d2d_hwnd_render_target_GetTags,
764 d2d_hwnd_render_target_PushLayer,
765 d2d_hwnd_render_target_PopLayer,
766 d2d_hwnd_render_target_Flush,
767 d2d_hwnd_render_target_SaveDrawingState,
768 d2d_hwnd_render_target_RestoreDrawingState,
769 d2d_hwnd_render_target_PushAxisAlignedClip,
770 d2d_hwnd_render_target_PopAxisAlignedClip,
771 d2d_hwnd_render_target_Clear,
772 d2d_hwnd_render_target_BeginDraw,
773 d2d_hwnd_render_target_EndDraw,
774 d2d_hwnd_render_target_GetPixelFormat,
775 d2d_hwnd_render_target_SetDpi,
776 d2d_hwnd_render_target_GetDpi,
777 d2d_hwnd_render_target_GetSize,
778 d2d_hwnd_render_target_GetPixelSize,
779 d2d_hwnd_render_target_GetMaximumBitmapSize,
780 d2d_hwnd_render_target_IsSupported,
781 d2d_hwnd_render_target_CheckWindowState,
782 d2d_hwnd_render_target_Resize,
783 d2d_hwnd_render_target_GetHwnd
786 static const struct d2d_device_context_ops d2d_hwnd_render_target_ops =
788 d2d_hwnd_render_target_present,
791 HRESULT d2d_hwnd_render_target_init(struct d2d_hwnd_render_target *render_target, ID2D1Factory1 *factory,
792 ID3D10Device1 *d3d_device, const D2D1_RENDER_TARGET_PROPERTIES *desc,
793 const D2D1_HWND_RENDER_TARGET_PROPERTIES *hwnd_rt_desc)
795 D2D1_RENDER_TARGET_PROPERTIES dxgi_rt_desc;
796 DXGI_SWAP_CHAIN_DESC swapchain_desc;
797 IDXGIAdapter *dxgi_adapter;
798 IDXGIFactory *dxgi_factory;
799 IDXGISurface *dxgi_surface;
800 IDXGIDevice *dxgi_device;
801 ID2D1Device *device;
802 HRESULT hr;
804 if (!IsWindow(hwnd_rt_desc->hwnd))
805 return HRESULT_FROM_WIN32(ERROR_INVALID_WINDOW_HANDLE);
807 render_target->ID2D1HwndRenderTarget_iface.lpVtbl = &d2d_hwnd_render_target_vtbl;
808 render_target->hwnd = hwnd_rt_desc->hwnd;
809 render_target->sync_interval = hwnd_rt_desc->presentOptions & D2D1_PRESENT_OPTIONS_IMMEDIATELY ? 0 : 1;
811 if (FAILED(hr = ID3D10Device1_QueryInterface(d3d_device, &IID_IDXGIDevice, (void **)&dxgi_device)))
813 WARN("Failed to get IDXGIDevice interface, hr %#x.\n", hr);
814 return hr;
817 hr = IDXGIDevice_GetAdapter(dxgi_device, &dxgi_adapter);
818 IDXGIDevice_Release(dxgi_device);
819 if (FAILED(hr))
821 WARN("Failed to get IDXGIAdapter interface, hr %#x.\n", hr);
822 return hr;
825 hr = IDXGIAdapter_GetParent(dxgi_adapter, &IID_IDXGIFactory, (void **)&dxgi_factory);
826 IDXGIAdapter_Release(dxgi_adapter);
827 if (FAILED(hr))
829 WARN("Failed to get IDXGIFactory interface, hr %#x.\n", hr);
830 return hr;
833 dxgi_rt_desc = *desc;
834 if (dxgi_rt_desc.dpiX == 0.0f && dxgi_rt_desc.dpiY == 0.0f)
835 ID2D1Factory1_GetDesktopDpi(factory, &dxgi_rt_desc.dpiX, &dxgi_rt_desc.dpiY);
837 if (dxgi_rt_desc.pixelFormat.format == DXGI_FORMAT_UNKNOWN)
839 dxgi_rt_desc.pixelFormat.format = DXGI_FORMAT_B8G8R8A8_UNORM;
840 dxgi_rt_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE;
843 swapchain_desc.BufferDesc.Width = hwnd_rt_desc->pixelSize.width;
844 swapchain_desc.BufferDesc.Height = hwnd_rt_desc->pixelSize.height;
845 swapchain_desc.BufferDesc.RefreshRate.Numerator = 60;
846 swapchain_desc.BufferDesc.RefreshRate.Denominator = 1;
847 swapchain_desc.BufferDesc.Format = dxgi_rt_desc.pixelFormat.format;
848 swapchain_desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
849 swapchain_desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
850 swapchain_desc.SampleDesc.Count = 1;
851 swapchain_desc.SampleDesc.Quality = 0;
852 swapchain_desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
853 swapchain_desc.BufferCount = 1;
854 swapchain_desc.OutputWindow = hwnd_rt_desc->hwnd;
855 swapchain_desc.Windowed = TRUE;
856 swapchain_desc.SwapEffect = hwnd_rt_desc->presentOptions & D2D1_PRESENT_OPTIONS_RETAIN_CONTENTS ?
857 DXGI_SWAP_EFFECT_SEQUENTIAL : DXGI_SWAP_EFFECT_DISCARD;
858 swapchain_desc.Flags = DXGI_SWAP_CHAIN_FLAG_GDI_COMPATIBLE;
860 hr = IDXGIFactory_CreateSwapChain(dxgi_factory, (IUnknown *)d3d_device, &swapchain_desc, &render_target->swapchain);
861 IDXGIFactory_Release(dxgi_factory);
862 if (FAILED(hr))
864 WARN("Failed to create a swapchain, hr %#x.\n", hr);
865 return hr;
868 if (FAILED(hr = IDXGISwapChain_GetBuffer(render_target->swapchain, 0, &IID_IDXGISurface, (void **)&dxgi_surface)))
870 WARN("Failed to get buffer, hr %#x.\n", hr);
871 IDXGISwapChain_Release(render_target->swapchain);
872 return hr;
875 render_target->ID2D1HwndRenderTarget_iface.lpVtbl = &d2d_hwnd_render_target_vtbl;
877 if (FAILED(hr = IDXGISurface_GetDevice(dxgi_surface, &IID_IDXGIDevice, (void **)&dxgi_device)))
879 WARN("Failed to get DXGI device, hr %#X.\n", hr);
880 IDXGISurface_Release(dxgi_surface);
881 IDXGISwapChain_Release(render_target->swapchain);
882 return hr;
885 hr = ID2D1Factory1_CreateDevice(factory, dxgi_device, &device);
886 IDXGIDevice_Release(dxgi_device);
887 if (FAILED(hr))
889 WARN("Failed to create D2D device, hr %#X.\n", hr);
890 IDXGISurface_Release(dxgi_surface);
891 IDXGISwapChain_Release(render_target->swapchain);
892 return hr;
895 hr = d2d_d3d_create_render_target(device, dxgi_surface,
896 (IUnknown *)&render_target->ID2D1HwndRenderTarget_iface, &d2d_hwnd_render_target_ops,
897 &dxgi_rt_desc, (void **)&render_target->dxgi_inner);
898 IDXGISurface_Release(dxgi_surface);
899 ID2D1Device_Release(device);
900 if (FAILED(hr))
902 WARN("Failed to create DXGI surface render target, hr %#x.\n", hr);
903 IDXGISwapChain_Release(render_target->swapchain);
904 return hr;
907 if (FAILED(hr = IUnknown_QueryInterface(render_target->dxgi_inner,
908 &IID_ID2D1RenderTarget, (void **)&render_target->dxgi_target)))
910 WARN("Failed to retrieve ID2D1RenderTarget interface, hr %#x.\n", hr);
911 IUnknown_Release(render_target->dxgi_inner);
912 IDXGISwapChain_Release(render_target->swapchain);
913 return hr;
916 return S_OK;