makefiles: Generate rules for installing IDL include files.
[wine.git] / dlls / d2d1 / wic_render_target.c
blob07a19ee3b88ff5c67fbe42fe6674849b54590771
1 /*
2 * Copyright 2014 Henri Verbeet for CodeWeavers
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2.1 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 #include "config.h"
20 #include "wine/port.h"
22 #include "d2d1_private.h"
23 #include "initguid.h"
24 #include "wincodec.h"
26 WINE_DEFAULT_DEBUG_CHANNEL(d2d);
28 static void sync_bitmap(struct d2d_wic_render_target *render_target)
30 D3D10_MAPPED_TEXTURE2D mapped_texture;
31 ID3D10Resource *src_resource;
32 IWICBitmapLock *bitmap_lock;
33 UINT dst_size, dst_pitch;
34 ID3D10Device *device;
35 WICRect dst_rect;
36 BYTE *src, *dst;
37 unsigned int i;
38 HRESULT hr;
40 if (FAILED(hr = IDXGISurface_QueryInterface(render_target->dxgi_surface,
41 &IID_ID3D10Resource, (void **)&src_resource)))
43 ERR("Failed to get source resource interface, hr %#x.\n", hr);
44 return;
47 ID3D10Texture2D_GetDevice(render_target->readback_texture, &device);
48 ID3D10Device_CopyResource(device, (ID3D10Resource *)render_target->readback_texture, src_resource);
49 ID3D10Device_Release(device);
50 ID3D10Resource_Release(src_resource);
52 dst_rect.X = 0;
53 dst_rect.Y = 0;
54 dst_rect.Width = render_target->width;
55 dst_rect.Height = render_target->height;
56 if (FAILED(hr = IWICBitmap_Lock(render_target->bitmap, &dst_rect, WICBitmapLockWrite, &bitmap_lock)))
58 ERR("Failed to lock destination bitmap, hr %#x.\n", hr);
59 return;
62 if (FAILED(hr = IWICBitmapLock_GetDataPointer(bitmap_lock, &dst_size, &dst)))
64 ERR("Failed to get data pointer, hr %#x.\n", hr);
65 IWICBitmapLock_Release(bitmap_lock);
66 return;
69 if (FAILED(hr = IWICBitmapLock_GetStride(bitmap_lock, &dst_pitch)))
71 ERR("Failed to get stride, hr %#x.\n", hr);
72 IWICBitmapLock_Release(bitmap_lock);
73 return;
76 if (FAILED(hr = ID3D10Texture2D_Map(render_target->readback_texture, 0, D3D10_MAP_READ, 0, &mapped_texture)))
78 ERR("Failed to map readback texture, hr %#x.\n", hr);
79 IWICBitmapLock_Release(bitmap_lock);
80 return;
83 src = mapped_texture.pData;
85 for (i = 0; i < render_target->height; ++i)
87 memcpy(dst, src, render_target->bpp * render_target->width);
88 src += mapped_texture.RowPitch;
89 dst += dst_pitch;
92 ID3D10Texture2D_Unmap(render_target->readback_texture, 0);
93 IWICBitmapLock_Release(bitmap_lock);
96 static inline struct d2d_wic_render_target *impl_from_ID2D1RenderTarget(ID2D1RenderTarget *iface)
98 return CONTAINING_RECORD(iface, struct d2d_wic_render_target, ID2D1RenderTarget_iface);
101 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_QueryInterface(ID2D1RenderTarget *iface, REFIID iid, void **out)
103 TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
105 if (IsEqualGUID(iid, &IID_ID2D1RenderTarget)
106 || IsEqualGUID(iid, &IID_ID2D1Resource)
107 || IsEqualGUID(iid, &IID_IUnknown))
109 ID2D1RenderTarget_AddRef(iface);
110 *out = iface;
111 return S_OK;
114 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
116 *out = NULL;
117 return E_NOINTERFACE;
120 static ULONG STDMETHODCALLTYPE d2d_wic_render_target_AddRef(ID2D1RenderTarget *iface)
122 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
123 ULONG refcount = InterlockedIncrement(&render_target->refcount);
125 TRACE("%p increasing refcount to %u.\n", iface, refcount);
127 return refcount;
130 static ULONG STDMETHODCALLTYPE d2d_wic_render_target_Release(ID2D1RenderTarget *iface)
132 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
133 ULONG refcount = InterlockedDecrement(&render_target->refcount);
135 TRACE("%p decreasing refcount to %u.\n", iface, refcount);
137 if (!refcount)
139 IWICBitmap_Release(render_target->bitmap);
140 ID3D10Texture2D_Release(render_target->readback_texture);
141 ID2D1RenderTarget_Release(render_target->dxgi_target);
142 IDXGISurface_Release(render_target->dxgi_surface);
143 HeapFree(GetProcessHeap(), 0, render_target);
146 return refcount;
149 static void STDMETHODCALLTYPE d2d_wic_render_target_GetFactory(ID2D1RenderTarget *iface, ID2D1Factory **factory)
151 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
153 TRACE("iface %p, factory %p.\n", iface, factory);
155 ID2D1RenderTarget_GetFactory(render_target->dxgi_target, factory);
158 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_CreateBitmap(ID2D1RenderTarget *iface,
159 D2D1_SIZE_U size, const void *src_data, UINT32 pitch, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
161 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
163 TRACE("iface %p, size {%u, %u}, src_data %p, pitch %u, desc %p, bitmap %p.\n",
164 iface, size.width, size.height, src_data, pitch, desc, bitmap);
166 return ID2D1RenderTarget_CreateBitmap(render_target->dxgi_target, size, src_data, pitch, desc, bitmap);
169 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_CreateBitmapFromWicBitmap(ID2D1RenderTarget *iface,
170 IWICBitmapSource *bitmap_source, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
172 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
174 TRACE("iface %p, bitmap_source %p, desc %p, bitmap %p.\n",
175 iface, bitmap_source, desc, bitmap);
177 return ID2D1RenderTarget_CreateBitmapFromWicBitmap(render_target->dxgi_target, bitmap_source, desc, bitmap);
180 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_CreateSharedBitmap(ID2D1RenderTarget *iface,
181 REFIID iid, void *data, const D2D1_BITMAP_PROPERTIES *desc, ID2D1Bitmap **bitmap)
183 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
185 TRACE("iface %p, iid %s, data %p, desc %p, bitmap %p.\n",
186 iface, debugstr_guid(iid), data, desc, bitmap);
188 return ID2D1RenderTarget_CreateSharedBitmap(render_target->dxgi_target, iid, data, desc, bitmap);
191 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_CreateBitmapBrush(ID2D1RenderTarget *iface,
192 ID2D1Bitmap *bitmap, const D2D1_BITMAP_BRUSH_PROPERTIES *bitmap_brush_desc,
193 const D2D1_BRUSH_PROPERTIES *brush_desc, ID2D1BitmapBrush **brush)
195 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
197 TRACE("iface %p, bitmap %p, bitmap_brush_desc %p, brush_desc %p, brush %p.\n",
198 iface, bitmap, bitmap_brush_desc, brush_desc, brush);
200 return ID2D1RenderTarget_CreateBitmapBrush(render_target->dxgi_target,
201 bitmap, bitmap_brush_desc, brush_desc, brush);
204 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_CreateSolidColorBrush(ID2D1RenderTarget *iface,
205 const D2D1_COLOR_F *color, const D2D1_BRUSH_PROPERTIES *desc, ID2D1SolidColorBrush **brush)
207 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
209 TRACE("iface %p, color %p, desc %p, brush %p.\n", iface, color, desc, brush);
211 return ID2D1RenderTarget_CreateSolidColorBrush(render_target->dxgi_target, color, desc, brush);
214 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_CreateGradientStopCollection(ID2D1RenderTarget *iface,
215 const D2D1_GRADIENT_STOP *stops, UINT32 stop_count, D2D1_GAMMA gamma, D2D1_EXTEND_MODE extend_mode,
216 ID2D1GradientStopCollection **gradient)
218 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
220 TRACE("iface %p, stops %p, stop_count %u, gamma %#x, extend_mode %#x, gradient %p.\n",
221 iface, stops, stop_count, gamma, extend_mode, gradient);
223 return ID2D1RenderTarget_CreateGradientStopCollection(render_target->dxgi_target,
224 stops, stop_count, gamma, extend_mode, gradient);
227 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_CreateLinearGradientBrush(ID2D1RenderTarget *iface,
228 const D2D1_LINEAR_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
229 ID2D1GradientStopCollection *gradient, ID2D1LinearGradientBrush **brush)
231 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
233 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
234 iface, gradient_brush_desc, brush_desc, gradient, brush);
236 return ID2D1RenderTarget_CreateLinearGradientBrush(render_target->dxgi_target,
237 gradient_brush_desc, brush_desc, gradient, brush);
240 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_CreateRadialGradientBrush(ID2D1RenderTarget *iface,
241 const D2D1_RADIAL_GRADIENT_BRUSH_PROPERTIES *gradient_brush_desc, const D2D1_BRUSH_PROPERTIES *brush_desc,
242 ID2D1GradientStopCollection *gradient, ID2D1RadialGradientBrush **brush)
244 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
246 TRACE("iface %p, gradient_brush_desc %p, brush_desc %p, gradient %p, brush %p.\n",
247 iface, gradient_brush_desc, brush_desc, gradient, brush);
249 return ID2D1RenderTarget_CreateRadialGradientBrush(render_target->dxgi_target,
250 gradient_brush_desc, brush_desc, gradient, brush);
253 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_CreateCompatibleRenderTarget(ID2D1RenderTarget *iface,
254 const D2D1_SIZE_F *size, const D2D1_SIZE_U *pixel_size, const D2D1_PIXEL_FORMAT *format,
255 D2D1_COMPATIBLE_RENDER_TARGET_OPTIONS options, ID2D1BitmapRenderTarget **render_target)
257 struct d2d_wic_render_target *rt = impl_from_ID2D1RenderTarget(iface);
259 TRACE("iface %p, size %p, pixel_size %p, format %p, options %#x, render_target %p,\n",
260 iface, size, pixel_size, format, options, render_target);
262 return ID2D1RenderTarget_CreateCompatibleRenderTarget(rt->dxgi_target,
263 size, pixel_size, format, options, render_target);
266 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_CreateLayer(ID2D1RenderTarget *iface,
267 const D2D1_SIZE_F *size, ID2D1Layer **layer)
269 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
271 TRACE("iface %p, size %p, layer %p.\n", iface, size, layer);
273 return ID2D1RenderTarget_CreateLayer(render_target->dxgi_target, size, layer);
276 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_CreateMesh(ID2D1RenderTarget *iface, ID2D1Mesh **mesh)
278 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
280 TRACE("iface %p, mesh %p.\n", iface, mesh);
282 return ID2D1RenderTarget_CreateMesh(render_target->dxgi_target, mesh);
285 static void STDMETHODCALLTYPE d2d_wic_render_target_DrawLine(ID2D1RenderTarget *iface,
286 D2D1_POINT_2F p0, D2D1_POINT_2F p1, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
288 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
290 TRACE("iface %p, p0 {%.8e, %.8e}, p1 {%.8e, %.8e}, brush %p, stroke_width %.8e, stroke_style %p.\n",
291 iface, p0.x, p0.y, p1.x, p1.y, brush, stroke_width, stroke_style);
293 ID2D1RenderTarget_DrawLine(render_target->dxgi_target, p0, p1, brush, stroke_width, stroke_style);
296 static void STDMETHODCALLTYPE d2d_wic_render_target_DrawRectangle(ID2D1RenderTarget *iface,
297 const D2D1_RECT_F *rect, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
299 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
301 TRACE("iface %p, rect %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
302 iface, rect, brush, stroke_width, stroke_style);
304 ID2D1RenderTarget_DrawRectangle(render_target->dxgi_target, rect, brush, stroke_width, stroke_style);
307 static void STDMETHODCALLTYPE d2d_wic_render_target_FillRectangle(ID2D1RenderTarget *iface,
308 const D2D1_RECT_F *rect, ID2D1Brush *brush)
310 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
312 TRACE("iface %p, rect %p, brush %p.\n", iface, rect, brush);
314 ID2D1RenderTarget_FillRectangle(render_target->dxgi_target, rect, brush);
317 static void STDMETHODCALLTYPE d2d_wic_render_target_DrawRoundedRectangle(ID2D1RenderTarget *iface,
318 const D2D1_ROUNDED_RECT *rect, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
320 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
322 TRACE("iface %p, rect %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
323 iface, rect, brush, stroke_width, stroke_style);
325 ID2D1RenderTarget_DrawRoundedRectangle(render_target->dxgi_target, rect, brush, stroke_width, stroke_style);
328 static void STDMETHODCALLTYPE d2d_wic_render_target_FillRoundedRectangle(ID2D1RenderTarget *iface,
329 const D2D1_ROUNDED_RECT *rect, ID2D1Brush *brush)
331 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
333 TRACE("iface %p, rect %p, brush %p.\n", iface, rect, brush);
335 ID2D1RenderTarget_FillRoundedRectangle(render_target->dxgi_target, rect, brush);
338 static void STDMETHODCALLTYPE d2d_wic_render_target_DrawEllipse(ID2D1RenderTarget *iface,
339 const D2D1_ELLIPSE *ellipse, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
341 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
343 TRACE("iface %p, ellipse %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
344 iface, ellipse, brush, stroke_width, stroke_style);
346 ID2D1RenderTarget_DrawEllipse(render_target->dxgi_target, ellipse, brush, stroke_width, stroke_style);
349 static void STDMETHODCALLTYPE d2d_wic_render_target_FillEllipse(ID2D1RenderTarget *iface,
350 const D2D1_ELLIPSE *ellipse, ID2D1Brush *brush)
352 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
354 TRACE("iface %p, ellipse %p, brush %p.\n", iface, ellipse, brush);
356 ID2D1RenderTarget_FillEllipse(render_target->dxgi_target, ellipse, brush);
359 static void STDMETHODCALLTYPE d2d_wic_render_target_DrawGeometry(ID2D1RenderTarget *iface,
360 ID2D1Geometry *geometry, ID2D1Brush *brush, float stroke_width, ID2D1StrokeStyle *stroke_style)
362 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
364 TRACE("iface %p, geometry %p, brush %p, stroke_width %.8e, stroke_style %p.\n",
365 iface, geometry, brush, stroke_width, stroke_style);
367 ID2D1RenderTarget_DrawGeometry(render_target->dxgi_target, geometry, brush, stroke_width, stroke_style);
370 static void STDMETHODCALLTYPE d2d_wic_render_target_FillGeometry(ID2D1RenderTarget *iface,
371 ID2D1Geometry *geometry, ID2D1Brush *brush, ID2D1Brush *opacity_brush)
373 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
375 TRACE("iface %p, geometry %p, brush %p, opacity_brush %p.\n", iface, geometry, brush, opacity_brush);
377 ID2D1RenderTarget_FillGeometry(render_target->dxgi_target, geometry, brush, opacity_brush);
380 static void STDMETHODCALLTYPE d2d_wic_render_target_FillMesh(ID2D1RenderTarget *iface,
381 ID2D1Mesh *mesh, ID2D1Brush *brush)
383 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
385 TRACE("iface %p, mesh %p, brush %p.\n", iface, mesh, brush);
387 ID2D1RenderTarget_FillMesh(render_target->dxgi_target, mesh, brush);
390 static void STDMETHODCALLTYPE d2d_wic_render_target_FillOpacityMask(ID2D1RenderTarget *iface,
391 ID2D1Bitmap *mask, ID2D1Brush *brush, D2D1_OPACITY_MASK_CONTENT content,
392 const D2D1_RECT_F *dst_rect, const D2D1_RECT_F *src_rect)
394 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
396 TRACE("iface %p, mask %p, brush %p, content %#x, dst_rect %p, src_rect %p.\n",
397 iface, mask, brush, content, dst_rect, src_rect);
399 ID2D1RenderTarget_FillOpacityMask(render_target->dxgi_target,
400 mask, brush, content, dst_rect, src_rect);
403 static void STDMETHODCALLTYPE d2d_wic_render_target_DrawBitmap(ID2D1RenderTarget *iface,
404 ID2D1Bitmap *bitmap, const D2D1_RECT_F *dst_rect, float opacity,
405 D2D1_BITMAP_INTERPOLATION_MODE interpolation_mode, const D2D1_RECT_F *src_rect)
407 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
409 TRACE("iface %p, bitmap %p, dst_rect %p, opacity %.8e, interpolation_mode %#x, src_rect %p.\n",
410 iface, bitmap, dst_rect, opacity, interpolation_mode, src_rect);
412 ID2D1RenderTarget_DrawBitmap(render_target->dxgi_target,
413 bitmap, dst_rect, opacity, interpolation_mode, src_rect);
416 static void STDMETHODCALLTYPE d2d_wic_render_target_DrawText(ID2D1RenderTarget *iface,
417 const WCHAR *string, UINT32 string_len, IDWriteTextFormat *text_format, const D2D1_RECT_F *layout_rect,
418 ID2D1Brush *brush, D2D1_DRAW_TEXT_OPTIONS options, DWRITE_MEASURING_MODE measuring_mode)
420 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
422 TRACE("iface %p, string %s, string_len %u, text_format %p, layout_rect %p, "
423 "brush %p, options %#x, measuring_mode %#x.\n",
424 iface, debugstr_wn(string, string_len), string_len, text_format, layout_rect,
425 brush, options, measuring_mode);
427 ID2D1RenderTarget_DrawText(render_target->dxgi_target, string, string_len,
428 text_format, layout_rect, brush, options, measuring_mode);
431 static void STDMETHODCALLTYPE d2d_wic_render_target_DrawTextLayout(ID2D1RenderTarget *iface,
432 D2D1_POINT_2F origin, IDWriteTextLayout *layout, ID2D1Brush *brush, D2D1_DRAW_TEXT_OPTIONS options)
434 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
436 TRACE("iface %p, origin {%.8e, %.8e}, layout %p, brush %p, options %#x.\n",
437 iface, origin.x, origin.y, layout, brush, options);
439 ID2D1RenderTarget_DrawTextLayout(render_target->dxgi_target, origin, layout, brush, options);
442 static void STDMETHODCALLTYPE d2d_wic_render_target_DrawGlyphRun(ID2D1RenderTarget *iface,
443 D2D1_POINT_2F baseline_origin, const DWRITE_GLYPH_RUN *glyph_run, ID2D1Brush *brush,
444 DWRITE_MEASURING_MODE measuring_mode)
446 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
448 TRACE("iface %p, baseline_origin {%.8e, %.8e}, glyph_run %p, brush %p, measuring_mode %#x.\n",
449 iface, baseline_origin.x, baseline_origin.y, glyph_run, brush, measuring_mode);
451 ID2D1RenderTarget_DrawGlyphRun(render_target->dxgi_target,
452 baseline_origin, glyph_run, brush, measuring_mode);
455 static void STDMETHODCALLTYPE d2d_wic_render_target_SetTransform(ID2D1RenderTarget *iface,
456 const D2D1_MATRIX_3X2_F *transform)
458 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
460 TRACE("iface %p, transform %p.\n", iface, transform);
462 ID2D1RenderTarget_SetTransform(render_target->dxgi_target, transform);
465 static void STDMETHODCALLTYPE d2d_wic_render_target_GetTransform(ID2D1RenderTarget *iface,
466 D2D1_MATRIX_3X2_F *transform)
468 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
470 TRACE("iface %p, transform %p.\n", iface, transform);
472 ID2D1RenderTarget_GetTransform(render_target->dxgi_target, transform);
475 static void STDMETHODCALLTYPE d2d_wic_render_target_SetAntialiasMode(ID2D1RenderTarget *iface,
476 D2D1_ANTIALIAS_MODE antialias_mode)
478 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
480 TRACE("iface %p, antialias_mode %#x.\n", iface, antialias_mode);
482 ID2D1RenderTarget_SetAntialiasMode(render_target->dxgi_target, antialias_mode);
485 static D2D1_ANTIALIAS_MODE STDMETHODCALLTYPE d2d_wic_render_target_GetAntialiasMode(ID2D1RenderTarget *iface)
487 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
489 TRACE("iface %p.\n", iface);
491 return ID2D1RenderTarget_GetAntialiasMode(render_target->dxgi_target);
494 static void STDMETHODCALLTYPE d2d_wic_render_target_SetTextAntialiasMode(ID2D1RenderTarget *iface,
495 D2D1_TEXT_ANTIALIAS_MODE antialias_mode)
497 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
499 TRACE("iface %p, antialias_mode %#x.\n", iface, antialias_mode);
501 ID2D1RenderTarget_SetTextAntialiasMode(render_target->dxgi_target, antialias_mode);
504 static D2D1_TEXT_ANTIALIAS_MODE STDMETHODCALLTYPE d2d_wic_render_target_GetTextAntialiasMode(ID2D1RenderTarget *iface)
506 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
508 TRACE("iface %p.\n", iface);
510 return ID2D1RenderTarget_GetTextAntialiasMode(render_target->dxgi_target);
513 static void STDMETHODCALLTYPE d2d_wic_render_target_SetTextRenderingParams(ID2D1RenderTarget *iface,
514 IDWriteRenderingParams *text_rendering_params)
516 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
518 TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
520 ID2D1RenderTarget_SetTextRenderingParams(render_target->dxgi_target, text_rendering_params);
523 static void STDMETHODCALLTYPE d2d_wic_render_target_GetTextRenderingParams(ID2D1RenderTarget *iface,
524 IDWriteRenderingParams **text_rendering_params)
526 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
528 TRACE("iface %p, text_rendering_params %p.\n", iface, text_rendering_params);
530 ID2D1RenderTarget_GetTextRenderingParams(render_target->dxgi_target, text_rendering_params);
533 static void STDMETHODCALLTYPE d2d_wic_render_target_SetTags(ID2D1RenderTarget *iface, D2D1_TAG tag1, D2D1_TAG tag2)
535 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
537 TRACE("iface %p, tag1 %s, tag2 %s.\n", iface, wine_dbgstr_longlong(tag1), wine_dbgstr_longlong(tag2));
539 ID2D1RenderTarget_SetTags(render_target->dxgi_target, tag1, tag2);
542 static void STDMETHODCALLTYPE d2d_wic_render_target_GetTags(ID2D1RenderTarget *iface, D2D1_TAG *tag1, D2D1_TAG *tag2)
544 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
546 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
548 ID2D1RenderTarget_GetTags(render_target->dxgi_target, tag1, tag2);
551 static void STDMETHODCALLTYPE d2d_wic_render_target_PushLayer(ID2D1RenderTarget *iface,
552 const D2D1_LAYER_PARAMETERS *layer_parameters, ID2D1Layer *layer)
554 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
556 TRACE("iface %p, layer_parameters %p, layer %p.\n", iface, layer_parameters, layer);
558 ID2D1RenderTarget_PushLayer(render_target->dxgi_target, layer_parameters, layer);
561 static void STDMETHODCALLTYPE d2d_wic_render_target_PopLayer(ID2D1RenderTarget *iface)
563 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
565 TRACE("iface %p.\n", iface);
567 ID2D1RenderTarget_PopLayer(render_target->dxgi_target);
570 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_Flush(ID2D1RenderTarget *iface, D2D1_TAG *tag1, D2D1_TAG *tag2)
572 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
573 HRESULT hr;
575 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
577 hr = ID2D1RenderTarget_Flush(render_target->dxgi_target, tag1, tag2);
578 sync_bitmap(render_target);
580 return hr;
583 static void STDMETHODCALLTYPE d2d_wic_render_target_SaveDrawingState(ID2D1RenderTarget *iface,
584 ID2D1DrawingStateBlock *state_block)
586 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
588 TRACE("iface %p, state_block %p.\n", iface, state_block);
590 ID2D1RenderTarget_SaveDrawingState(render_target->dxgi_target, state_block);
593 static void STDMETHODCALLTYPE d2d_wic_render_target_RestoreDrawingState(ID2D1RenderTarget *iface,
594 ID2D1DrawingStateBlock *state_block)
596 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
598 TRACE("iface %p, state_block %p.\n", iface, state_block);
600 ID2D1RenderTarget_RestoreDrawingState(render_target->dxgi_target, state_block);
603 static void STDMETHODCALLTYPE d2d_wic_render_target_PushAxisAlignedClip(ID2D1RenderTarget *iface,
604 const D2D1_RECT_F *clip_rect, D2D1_ANTIALIAS_MODE antialias_mode)
606 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
608 TRACE("iface %p, clip_rect %p, antialias_mode %#x.\n", iface, clip_rect, antialias_mode);
610 ID2D1RenderTarget_PushAxisAlignedClip(render_target->dxgi_target, clip_rect, antialias_mode);
613 static void STDMETHODCALLTYPE d2d_wic_render_target_PopAxisAlignedClip(ID2D1RenderTarget *iface)
615 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
617 TRACE("iface %p.\n", iface);
619 ID2D1RenderTarget_PopAxisAlignedClip(render_target->dxgi_target);
622 static void STDMETHODCALLTYPE d2d_wic_render_target_Clear(ID2D1RenderTarget *iface, const D2D1_COLOR_F *color)
624 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
626 TRACE("iface %p, color %p.\n", iface, color);
628 ID2D1RenderTarget_Clear(render_target->dxgi_target, color);
631 static void STDMETHODCALLTYPE d2d_wic_render_target_BeginDraw(ID2D1RenderTarget *iface)
633 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
635 TRACE("iface %p.\n", iface);
637 ID2D1RenderTarget_BeginDraw(render_target->dxgi_target);
640 static HRESULT STDMETHODCALLTYPE d2d_wic_render_target_EndDraw(ID2D1RenderTarget *iface,
641 D2D1_TAG *tag1, D2D1_TAG *tag2)
643 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
644 HRESULT hr;
646 TRACE("iface %p, tag1 %p, tag2 %p.\n", iface, tag1, tag2);
648 hr = ID2D1RenderTarget_EndDraw(render_target->dxgi_target, tag1, tag2);
649 sync_bitmap(render_target);
651 return hr;
654 static D2D1_PIXEL_FORMAT * STDMETHODCALLTYPE d2d_wic_render_target_GetPixelFormat(ID2D1RenderTarget *iface,
655 D2D1_PIXEL_FORMAT *format)
657 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
659 TRACE("iface %p, format %p.\n", iface, format);
661 *format = ID2D1RenderTarget_GetPixelFormat(render_target->dxgi_target);
662 return format;
665 static void STDMETHODCALLTYPE d2d_wic_render_target_SetDpi(ID2D1RenderTarget *iface, float dpi_x, float dpi_y)
667 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
669 TRACE("iface %p, dpi_x %.8e, dpi_y %.8e.\n", iface, dpi_x, dpi_y);
671 ID2D1RenderTarget_SetDpi(render_target->dxgi_target, dpi_x, dpi_y);
674 static void STDMETHODCALLTYPE d2d_wic_render_target_GetDpi(ID2D1RenderTarget *iface, float *dpi_x, float *dpi_y)
676 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
678 TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface, dpi_x, dpi_y);
680 ID2D1RenderTarget_GetDpi(render_target->dxgi_target, dpi_x, dpi_y);
683 static D2D1_SIZE_F * STDMETHODCALLTYPE d2d_wic_render_target_GetSize(ID2D1RenderTarget *iface, D2D1_SIZE_F *size)
685 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
687 TRACE("iface %p, size %p.\n", iface, size);
689 *size = ID2D1RenderTarget_GetSize(render_target->dxgi_target);
690 return size;
693 static D2D1_SIZE_U * STDMETHODCALLTYPE d2d_wic_render_target_GetPixelSize(ID2D1RenderTarget *iface,
694 D2D1_SIZE_U *pixel_size)
696 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
698 TRACE("iface %p, pixel_size %p.\n", iface, pixel_size);
700 *pixel_size = ID2D1RenderTarget_GetPixelSize(render_target->dxgi_target);
701 return pixel_size;
704 static UINT32 STDMETHODCALLTYPE d2d_wic_render_target_GetMaximumBitmapSize(ID2D1RenderTarget *iface)
706 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
708 TRACE("iface %p.\n", iface);
710 return ID2D1RenderTarget_GetMaximumBitmapSize(render_target->dxgi_target);
713 static BOOL STDMETHODCALLTYPE d2d_wic_render_target_IsSupported(ID2D1RenderTarget *iface,
714 const D2D1_RENDER_TARGET_PROPERTIES *desc)
716 struct d2d_wic_render_target *render_target = impl_from_ID2D1RenderTarget(iface);
718 TRACE("iface %p, desc %p.\n", iface, desc);
720 return ID2D1RenderTarget_IsSupported(render_target->dxgi_target, desc);
723 static const struct ID2D1RenderTargetVtbl d2d_wic_render_target_vtbl =
725 d2d_wic_render_target_QueryInterface,
726 d2d_wic_render_target_AddRef,
727 d2d_wic_render_target_Release,
728 d2d_wic_render_target_GetFactory,
729 d2d_wic_render_target_CreateBitmap,
730 d2d_wic_render_target_CreateBitmapFromWicBitmap,
731 d2d_wic_render_target_CreateSharedBitmap,
732 d2d_wic_render_target_CreateBitmapBrush,
733 d2d_wic_render_target_CreateSolidColorBrush,
734 d2d_wic_render_target_CreateGradientStopCollection,
735 d2d_wic_render_target_CreateLinearGradientBrush,
736 d2d_wic_render_target_CreateRadialGradientBrush,
737 d2d_wic_render_target_CreateCompatibleRenderTarget,
738 d2d_wic_render_target_CreateLayer,
739 d2d_wic_render_target_CreateMesh,
740 d2d_wic_render_target_DrawLine,
741 d2d_wic_render_target_DrawRectangle,
742 d2d_wic_render_target_FillRectangle,
743 d2d_wic_render_target_DrawRoundedRectangle,
744 d2d_wic_render_target_FillRoundedRectangle,
745 d2d_wic_render_target_DrawEllipse,
746 d2d_wic_render_target_FillEllipse,
747 d2d_wic_render_target_DrawGeometry,
748 d2d_wic_render_target_FillGeometry,
749 d2d_wic_render_target_FillMesh,
750 d2d_wic_render_target_FillOpacityMask,
751 d2d_wic_render_target_DrawBitmap,
752 d2d_wic_render_target_DrawText,
753 d2d_wic_render_target_DrawTextLayout,
754 d2d_wic_render_target_DrawGlyphRun,
755 d2d_wic_render_target_SetTransform,
756 d2d_wic_render_target_GetTransform,
757 d2d_wic_render_target_SetAntialiasMode,
758 d2d_wic_render_target_GetAntialiasMode,
759 d2d_wic_render_target_SetTextAntialiasMode,
760 d2d_wic_render_target_GetTextAntialiasMode,
761 d2d_wic_render_target_SetTextRenderingParams,
762 d2d_wic_render_target_GetTextRenderingParams,
763 d2d_wic_render_target_SetTags,
764 d2d_wic_render_target_GetTags,
765 d2d_wic_render_target_PushLayer,
766 d2d_wic_render_target_PopLayer,
767 d2d_wic_render_target_Flush,
768 d2d_wic_render_target_SaveDrawingState,
769 d2d_wic_render_target_RestoreDrawingState,
770 d2d_wic_render_target_PushAxisAlignedClip,
771 d2d_wic_render_target_PopAxisAlignedClip,
772 d2d_wic_render_target_Clear,
773 d2d_wic_render_target_BeginDraw,
774 d2d_wic_render_target_EndDraw,
775 d2d_wic_render_target_GetPixelFormat,
776 d2d_wic_render_target_SetDpi,
777 d2d_wic_render_target_GetDpi,
778 d2d_wic_render_target_GetSize,
779 d2d_wic_render_target_GetPixelSize,
780 d2d_wic_render_target_GetMaximumBitmapSize,
781 d2d_wic_render_target_IsSupported,
784 HRESULT d2d_wic_render_target_init(struct d2d_wic_render_target *render_target, ID2D1Factory *factory,
785 ID3D10Device1 *device, IWICBitmap *bitmap, const D2D1_RENDER_TARGET_PROPERTIES *desc)
787 D3D10_TEXTURE2D_DESC texture_desc;
788 ID3D10Texture2D *texture;
789 HRESULT hr;
791 render_target->ID2D1RenderTarget_iface.lpVtbl = &d2d_wic_render_target_vtbl;
792 render_target->refcount = 1;
794 if (FAILED(hr = IWICBitmap_GetSize(bitmap, &render_target->width, &render_target->height)))
796 WARN("Failed to get bitmap dimensions, hr %#x.\n", hr);
797 return hr;
800 texture_desc.Width = render_target->width;
801 texture_desc.Height = render_target->height;
802 texture_desc.MipLevels = 1;
803 texture_desc.ArraySize = 1;
805 texture_desc.Format = desc->pixelFormat.format;
806 if (texture_desc.Format == DXGI_FORMAT_UNKNOWN)
808 WICPixelFormatGUID bitmap_format;
810 if (FAILED(hr = IWICBitmap_GetPixelFormat(bitmap, &bitmap_format)))
812 WARN("Failed to get bitmap format, hr %#x.\n", hr);
813 return hr;
816 if (IsEqualGUID(&bitmap_format, &GUID_WICPixelFormat32bppPBGRA)
817 || IsEqualGUID(&bitmap_format, &GUID_WICPixelFormat32bppBGR))
819 texture_desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM;
821 else
823 WARN("Unsupported WIC bitmap format %s.\n", debugstr_guid(&bitmap_format));
824 return D2DERR_UNSUPPORTED_PIXEL_FORMAT;
828 switch (texture_desc.Format)
830 case DXGI_FORMAT_B8G8R8A8_UNORM:
831 render_target->bpp = 4;
832 break;
834 default:
835 FIXME("Unhandled format %#x.\n", texture_desc.Format);
836 return D2DERR_UNSUPPORTED_PIXEL_FORMAT;
839 texture_desc.SampleDesc.Count = 1;
840 texture_desc.SampleDesc.Quality = 0;
841 texture_desc.Usage = D3D10_USAGE_DEFAULT;
842 texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE;
843 texture_desc.CPUAccessFlags = 0;
844 texture_desc.MiscFlags = 0;
846 if (FAILED(hr = ID3D10Device1_CreateTexture2D(device, &texture_desc, NULL, &texture)))
848 WARN("Failed to create texture, hr %#x.\n", hr);
849 return hr;
852 hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&render_target->dxgi_surface);
853 ID3D10Texture2D_Release(texture);
854 if (FAILED(hr))
856 WARN("Failed to get DXGI surface interface, hr %#x.\n", hr);
857 return hr;
860 texture_desc.Usage = D3D10_USAGE_STAGING;
861 texture_desc.BindFlags = 0;
862 texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ;
864 if (FAILED(hr = ID3D10Device1_CreateTexture2D(device, &texture_desc, NULL, &render_target->readback_texture)))
866 WARN("Failed to create readback texture, hr %#x.\n", hr);
867 IDXGISurface_Release(render_target->dxgi_surface);
868 return hr;
871 if (FAILED(hr = ID2D1Factory_CreateDxgiSurfaceRenderTarget(factory,
872 render_target->dxgi_surface, desc, &render_target->dxgi_target)))
874 WARN("Failed to create DXGI surface render target, hr %#x.\n", hr);
875 ID3D10Texture2D_Release(render_target->readback_texture);
876 IDXGISurface_Release(render_target->dxgi_surface);
877 return hr;
880 render_target->bitmap = bitmap;
881 IWICBitmap_AddRef(bitmap);
883 return S_OK;