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
20 #include "wine/port.h"
22 #include "d2d1_private.h"
25 WINE_DEFAULT_DEBUG_CHANNEL(d2d
);
27 static inline struct d2d_bitmap
*impl_from_ID2D1Bitmap1(ID2D1Bitmap1
*iface
)
29 return CONTAINING_RECORD(iface
, struct d2d_bitmap
, ID2D1Bitmap1_iface
);
32 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_QueryInterface(ID2D1Bitmap1
*iface
, REFIID iid
, void **out
)
34 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
36 if (IsEqualGUID(iid
, &IID_ID2D1Bitmap1
)
37 || IsEqualGUID(iid
, &IID_ID2D1Bitmap
)
38 || IsEqualGUID(iid
, &IID_ID2D1Image
)
39 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
40 || IsEqualGUID(iid
, &IID_IUnknown
))
42 ID2D1Bitmap1_AddRef(iface
);
47 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
53 static ULONG STDMETHODCALLTYPE
d2d_bitmap_AddRef(ID2D1Bitmap1
*iface
)
55 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
56 ULONG refcount
= InterlockedIncrement(&bitmap
->refcount
);
58 TRACE("%p increasing refcount to %u.\n", iface
, refcount
);
63 static ULONG STDMETHODCALLTYPE
d2d_bitmap_Release(ID2D1Bitmap1
*iface
)
65 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
66 ULONG refcount
= InterlockedDecrement(&bitmap
->refcount
);
68 TRACE("%p decreasing refcount to %u.\n", iface
, refcount
);
72 ID3D10ShaderResourceView_Release(bitmap
->view
);
74 ID3D10RenderTargetView_Release(bitmap
->rtv
);
76 IDXGISurface_Release(bitmap
->surface
);
77 ID2D1Factory_Release(bitmap
->factory
);
84 static void STDMETHODCALLTYPE
d2d_bitmap_GetFactory(ID2D1Bitmap1
*iface
, ID2D1Factory
**factory
)
86 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
88 TRACE("iface %p, factory %p.\n", iface
, factory
);
90 ID2D1Factory_AddRef(*factory
= bitmap
->factory
);
93 static D2D1_SIZE_F
* STDMETHODCALLTYPE
d2d_bitmap_GetSize(ID2D1Bitmap1
*iface
, D2D1_SIZE_F
*size
)
95 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
97 TRACE("iface %p, size %p.\n", iface
, size
);
99 size
->width
= bitmap
->pixel_size
.width
/ (bitmap
->dpi_x
/ 96.0f
);
100 size
->height
= bitmap
->pixel_size
.height
/ (bitmap
->dpi_y
/ 96.0f
);
104 static D2D1_SIZE_U
* STDMETHODCALLTYPE
d2d_bitmap_GetPixelSize(ID2D1Bitmap1
*iface
, D2D1_SIZE_U
*pixel_size
)
106 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
108 TRACE("iface %p, pixel_size %p.\n", iface
, pixel_size
);
110 *pixel_size
= bitmap
->pixel_size
;
114 static D2D1_PIXEL_FORMAT
* STDMETHODCALLTYPE
d2d_bitmap_GetPixelFormat(ID2D1Bitmap1
*iface
, D2D1_PIXEL_FORMAT
*format
)
116 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
118 TRACE("iface %p, format %p.\n", iface
, format
);
120 *format
= bitmap
->format
;
124 static void STDMETHODCALLTYPE
d2d_bitmap_GetDpi(ID2D1Bitmap1
*iface
, float *dpi_x
, float *dpi_y
)
126 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
128 TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface
, dpi_x
, dpi_y
);
130 *dpi_x
= bitmap
->dpi_x
;
131 *dpi_y
= bitmap
->dpi_y
;
134 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_CopyFromBitmap(ID2D1Bitmap1
*iface
,
135 const D2D1_POINT_2U
*dst_point
, ID2D1Bitmap
*bitmap
, const D2D1_RECT_U
*src_rect
)
137 FIXME("iface %p, dst_point %p, bitmap %p, src_rect %p stub!\n", iface
, dst_point
, bitmap
, src_rect
);
142 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_CopyFromRenderTarget(ID2D1Bitmap1
*iface
,
143 const D2D1_POINT_2U
*dst_point
, ID2D1RenderTarget
*render_target
, const D2D1_RECT_U
*src_rect
)
145 FIXME("iface %p, dst_point %p, render_target %p, src_rect %p stub!\n", iface
, dst_point
, render_target
, src_rect
);
150 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_CopyFromMemory(ID2D1Bitmap1
*iface
,
151 const D2D1_RECT_U
*dst_rect
, const void *src_data
, UINT32 pitch
)
153 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
154 ID3D10Device
*device
;
158 TRACE("iface %p, dst_rect %p, src_data %p, pitch %u.\n", iface
, dst_rect
, src_data
, pitch
);
162 box
.left
= dst_rect
->left
;
163 box
.top
= dst_rect
->top
;
165 box
.right
= dst_rect
->right
;
166 box
.bottom
= dst_rect
->bottom
;
170 ID3D10ShaderResourceView_GetResource(bitmap
->view
, &dst
);
171 ID3D10ShaderResourceView_GetDevice(bitmap
->view
, &device
);
172 ID3D10Device_UpdateSubresource(device
, dst
, 0, dst_rect
? &box
: NULL
, src_data
, pitch
, 0);
173 ID3D10Device_Release(device
);
174 ID3D10Resource_Release(dst
);
179 static void STDMETHODCALLTYPE
d2d_bitmap_GetColorContext(ID2D1Bitmap1
*iface
, ID2D1ColorContext
**context
)
181 FIXME("iface %p, context %p stub!\n", iface
, context
);
184 static D2D1_BITMAP_OPTIONS STDMETHODCALLTYPE
d2d_bitmap_GetOptions(ID2D1Bitmap1
*iface
)
186 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
188 TRACE("iface %p.\n", iface
);
190 return bitmap
->options
;
193 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_GetSurface(ID2D1Bitmap1
*iface
, IDXGISurface
**surface
)
195 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
197 TRACE("iface %p, surface %p.\n", iface
, surface
);
199 *surface
= bitmap
->surface
;
201 IDXGISurface_AddRef(*surface
);
203 return *surface
? S_OK
: D2DERR_INVALID_CALL
;
206 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_Map(ID2D1Bitmap1
*iface
, D2D1_MAP_OPTIONS options
,
207 D2D1_MAPPED_RECT
*mapped_rect
)
209 FIXME("iface %p, options %#x, mapped_rect %p stub!\n", iface
, options
, mapped_rect
);
214 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_Unmap(ID2D1Bitmap1
*iface
)
216 FIXME("iface %p stub!\n", iface
);
221 static const struct ID2D1Bitmap1Vtbl d2d_bitmap_vtbl
=
223 d2d_bitmap_QueryInterface
,
226 d2d_bitmap_GetFactory
,
228 d2d_bitmap_GetPixelSize
,
229 d2d_bitmap_GetPixelFormat
,
231 d2d_bitmap_CopyFromBitmap
,
232 d2d_bitmap_CopyFromRenderTarget
,
233 d2d_bitmap_CopyFromMemory
,
234 d2d_bitmap_GetColorContext
,
235 d2d_bitmap_GetOptions
,
236 d2d_bitmap_GetSurface
,
241 static BOOL
format_supported(const D2D1_PIXEL_FORMAT
*format
)
245 static const D2D1_PIXEL_FORMAT supported_formats
[] =
247 {DXGI_FORMAT_R32G32B32A32_FLOAT
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
248 {DXGI_FORMAT_R32G32B32A32_FLOAT
, D2D1_ALPHA_MODE_IGNORE
},
249 {DXGI_FORMAT_R16G16B16A16_FLOAT
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
250 {DXGI_FORMAT_R16G16B16A16_FLOAT
, D2D1_ALPHA_MODE_IGNORE
},
251 {DXGI_FORMAT_R16G16B16A16_UNORM
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
252 {DXGI_FORMAT_R16G16B16A16_UNORM
, D2D1_ALPHA_MODE_IGNORE
},
253 {DXGI_FORMAT_R8G8B8A8_UNORM
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
254 {DXGI_FORMAT_R8G8B8A8_UNORM
, D2D1_ALPHA_MODE_IGNORE
},
255 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
256 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
, D2D1_ALPHA_MODE_IGNORE
},
257 {DXGI_FORMAT_A8_UNORM
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
258 {DXGI_FORMAT_A8_UNORM
, D2D1_ALPHA_MODE_STRAIGHT
},
259 {DXGI_FORMAT_B8G8R8A8_UNORM
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
260 {DXGI_FORMAT_B8G8R8A8_UNORM
, D2D1_ALPHA_MODE_IGNORE
},
261 {DXGI_FORMAT_B8G8R8X8_UNORM
, D2D1_ALPHA_MODE_IGNORE
},
262 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
263 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB
, D2D1_ALPHA_MODE_IGNORE
},
266 for (i
= 0; i
< ARRAY_SIZE(supported_formats
); ++i
)
268 if (supported_formats
[i
].format
== format
->format
269 && supported_formats
[i
].alphaMode
== format
->alphaMode
)
276 static void d2d_bitmap_init(struct d2d_bitmap
*bitmap
, struct d2d_device_context
*context
,
277 ID3D10ShaderResourceView
*view
, D2D1_SIZE_U size
, const D2D1_BITMAP_PROPERTIES1
*desc
)
279 ID3D10Resource
*resource
;
280 ID3D10Device
*d3d_device
;
283 bitmap
->ID2D1Bitmap1_iface
.lpVtbl
= &d2d_bitmap_vtbl
;
284 bitmap
->refcount
= 1;
285 ID2D1Factory_AddRef(bitmap
->factory
= context
->factory
);
286 ID3D10ShaderResourceView_AddRef(bitmap
->view
= view
);
287 bitmap
->pixel_size
= size
;
288 bitmap
->format
= desc
->pixelFormat
;
289 bitmap
->dpi_x
= desc
->dpiX
;
290 bitmap
->dpi_y
= desc
->dpiY
;
291 bitmap
->options
= desc
->bitmapOptions
;
293 ID3D10ShaderResourceView_GetResource(bitmap
->view
, &resource
);
295 if (d2d_device_context_is_dxgi_target(context
))
296 ID3D10Resource_QueryInterface(resource
, &IID_IDXGISurface
, (void **)&bitmap
->surface
);
298 if (bitmap
->options
& D2D1_BITMAP_OPTIONS_TARGET
)
300 ID3D10Resource_GetDevice(resource
, &d3d_device
);
301 if (FAILED(hr
= ID3D10Device_CreateRenderTargetView(d3d_device
, resource
, NULL
, &bitmap
->rtv
)))
302 WARN("Failed to create rtv, hr %#x.\n", hr
);
303 ID3D10Device_Release(d3d_device
);
306 ID3D10Resource_Release(resource
);
308 if (bitmap
->dpi_x
== 0.0f
&& bitmap
->dpi_y
== 0.0f
)
310 bitmap
->dpi_x
= 96.0f
;
311 bitmap
->dpi_y
= 96.0f
;
315 HRESULT
d2d_bitmap_create(struct d2d_device_context
*context
, D2D1_SIZE_U size
, const void *src_data
,
316 UINT32 pitch
, const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
)
318 D3D10_SUBRESOURCE_DATA resource_data
;
319 D3D10_TEXTURE2D_DESC texture_desc
;
320 ID3D10ShaderResourceView
*view
;
321 ID3D10Texture2D
*texture
;
324 if (!format_supported(&desc
->pixelFormat
))
326 WARN("Tried to create bitmap with unsupported format {%#x / %#x}.\n",
327 desc
->pixelFormat
.format
, desc
->pixelFormat
.alphaMode
);
328 return D2DERR_UNSUPPORTED_PIXEL_FORMAT
;
331 texture_desc
.Width
= size
.width
;
332 texture_desc
.Height
= size
.height
;
333 if (!texture_desc
.Width
|| !texture_desc
.Height
)
334 texture_desc
.Width
= texture_desc
.Height
= 1;
335 texture_desc
.MipLevels
= 1;
336 texture_desc
.ArraySize
= 1;
337 texture_desc
.Format
= desc
->pixelFormat
.format
;
338 texture_desc
.SampleDesc
.Count
= 1;
339 texture_desc
.SampleDesc
.Quality
= 0;
340 texture_desc
.Usage
= D3D10_USAGE_DEFAULT
;
341 texture_desc
.BindFlags
= 0;
342 if (desc
->bitmapOptions
& D2D1_BITMAP_OPTIONS_TARGET
)
343 texture_desc
.BindFlags
|= D3D10_BIND_RENDER_TARGET
;
344 if (!(desc
->bitmapOptions
& D2D1_BITMAP_OPTIONS_CANNOT_DRAW
))
345 texture_desc
.BindFlags
|= D3D10_BIND_SHADER_RESOURCE
;
346 texture_desc
.CPUAccessFlags
= 0;
347 texture_desc
.MiscFlags
= 0;
348 if (desc
->bitmapOptions
& D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE
)
349 texture_desc
.MiscFlags
|= D3D10_RESOURCE_MISC_GDI_COMPATIBLE
;
351 resource_data
.pSysMem
= src_data
;
352 resource_data
.SysMemPitch
= pitch
;
354 if (FAILED(hr
= ID3D10Device_CreateTexture2D(context
->d3d_device
, &texture_desc
,
355 src_data
? &resource_data
: NULL
, &texture
)))
357 ERR("Failed to create texture, hr %#x.\n", hr
);
361 hr
= ID3D10Device_CreateShaderResourceView(context
->d3d_device
, (ID3D10Resource
*)texture
, NULL
, &view
);
362 ID3D10Texture2D_Release(texture
);
365 ERR("Failed to create view, hr %#x.\n", hr
);
369 if ((*bitmap
= heap_alloc_zero(sizeof(**bitmap
))))
371 d2d_bitmap_init(*bitmap
, context
, view
, size
, desc
);
372 TRACE("Created bitmap %p.\n", *bitmap
);
375 ID3D10ShaderResourceView_Release(view
);
377 return *bitmap
? S_OK
: E_OUTOFMEMORY
;
380 HRESULT
d2d_bitmap_create_shared(struct d2d_device_context
*context
, REFIID iid
, void *data
,
381 const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
)
383 D2D1_BITMAP_PROPERTIES1 d
;
385 if (IsEqualGUID(iid
, &IID_ID2D1Bitmap
))
387 struct d2d_bitmap
*src_impl
= unsafe_impl_from_ID2D1Bitmap(data
);
388 ID3D10Device
*device
;
391 if (src_impl
->factory
!= context
->factory
)
393 hr
= D2DERR_WRONG_FACTORY
;
397 ID3D10ShaderResourceView_GetDevice(src_impl
->view
, &device
);
398 ID3D10Device_Release(device
);
399 if (device
!= context
->d3d_device
)
401 hr
= D2DERR_UNSUPPORTED_OPERATION
;
407 d
.pixelFormat
= src_impl
->format
;
408 d
.dpiX
= src_impl
->dpi_x
;
409 d
.dpiY
= src_impl
->dpi_y
;
410 d
.bitmapOptions
= src_impl
->options
;
411 d
.colorContext
= NULL
;
415 if (!format_supported(&desc
->pixelFormat
))
417 WARN("Tried to create bitmap with unsupported format {%#x / %#x}.\n",
418 desc
->pixelFormat
.format
, desc
->pixelFormat
.alphaMode
);
419 hr
= D2DERR_UNSUPPORTED_PIXEL_FORMAT
;
423 if (!(*bitmap
= heap_alloc_zero(sizeof(**bitmap
))))
429 d2d_bitmap_init(*bitmap
, context
, src_impl
->view
, src_impl
->pixel_size
, desc
);
430 TRACE("Created bitmap %p.\n", *bitmap
);
436 if (IsEqualGUID(iid
, &IID_IDXGISurface
) || IsEqualGUID(iid
, &IID_IDXGISurface1
))
438 ID3D10ShaderResourceView
*view
;
439 DXGI_SURFACE_DESC surface_desc
;
440 IDXGISurface
*surface
= data
;
441 ID3D10Resource
*resource
;
442 D2D1_SIZE_U pixel_size
;
443 ID3D10Device
*device
;
446 if (FAILED(IDXGISurface_QueryInterface(surface
, &IID_ID3D10Resource
, (void **)&resource
)))
448 WARN("Failed to get d3d resource from dxgi surface.\n");
452 ID3D10Resource_GetDevice(resource
, &device
);
453 ID3D10Device_Release(device
);
454 if (device
!= context
->d3d_device
)
456 ID3D10Resource_Release(resource
);
457 return D2DERR_UNSUPPORTED_OPERATION
;
460 hr
= ID3D10Device_CreateShaderResourceView(context
->d3d_device
, resource
, NULL
, &view
);
461 ID3D10Resource_Release(resource
);
464 WARN("Failed to create shader resource view, hr %#x.\n", hr
);
468 if (!(*bitmap
= heap_alloc_zero(sizeof(**bitmap
))))
470 ID3D10ShaderResourceView_Release(view
);
471 return E_OUTOFMEMORY
;
475 if (FAILED(hr
= IDXGISurface_GetDesc(surface
, &surface_desc
)))
477 WARN("Failed to get surface desc, hr %#x.\n", hr
);
478 ID3D10ShaderResourceView_Release(view
);
484 memset(&d
, 0, sizeof(d
));
485 d
.pixelFormat
.format
= surface_desc
.Format
;
490 if (d
.pixelFormat
.format
== DXGI_FORMAT_UNKNOWN
)
491 d
.pixelFormat
.format
= surface_desc
.Format
;
494 if (d
.dpiX
== 0.0f
|| d
.dpiY
== 0.0f
)
497 d
.dpiX
= context
->desc
.dpiX
;
499 d
.dpiY
= context
->desc
.dpiY
;
502 pixel_size
.width
= surface_desc
.Width
;
503 pixel_size
.height
= surface_desc
.Height
;
505 d2d_bitmap_init(*bitmap
, context
, view
, pixel_size
, &d
);
506 ID3D10ShaderResourceView_Release(view
);
507 TRACE("Created bitmap %p.\n", *bitmap
);
512 WARN("Unhandled interface %s.\n", debugstr_guid(iid
));
517 HRESULT
d2d_bitmap_create_from_wic_bitmap(struct d2d_device_context
*context
, IWICBitmapSource
*bitmap_source
,
518 const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
)
520 const D2D1_PIXEL_FORMAT
*d2d_format
;
521 D2D1_BITMAP_PROPERTIES1 bitmap_desc
;
522 WICPixelFormatGUID wic_format
;
523 unsigned int bpp
, data_size
;
533 const WICPixelFormatGUID
*wic
;
534 D2D1_PIXEL_FORMAT d2d
;
538 {&GUID_WICPixelFormat32bppPBGRA
, {DXGI_FORMAT_B8G8R8A8_UNORM
, D2D1_ALPHA_MODE_PREMULTIPLIED
}},
539 {&GUID_WICPixelFormat32bppBGR
, {DXGI_FORMAT_B8G8R8A8_UNORM
, D2D1_ALPHA_MODE_IGNORE
}},
542 if (FAILED(hr
= IWICBitmapSource_GetSize(bitmap_source
, &size
.width
, &size
.height
)))
544 WARN("Failed to get bitmap size, hr %#x.\n", hr
);
550 bitmap_desc
.pixelFormat
.format
= DXGI_FORMAT_UNKNOWN
;
551 bitmap_desc
.pixelFormat
.alphaMode
= D2D1_ALPHA_MODE_UNKNOWN
;
552 bitmap_desc
.dpiX
= 0.0f
;
553 bitmap_desc
.dpiY
= 0.0f
;
554 bitmap_desc
.bitmapOptions
= 0;
555 bitmap_desc
.colorContext
= NULL
;
562 if (FAILED(hr
= IWICBitmapSource_GetPixelFormat(bitmap_source
, &wic_format
)))
564 WARN("Failed to get bitmap format, hr %#x.\n", hr
);
568 for (i
= 0, d2d_format
= NULL
; i
< ARRAY_SIZE(format_lookup
); ++i
)
570 if (IsEqualGUID(&wic_format
, format_lookup
[i
].wic
))
572 d2d_format
= &format_lookup
[i
].d2d
;
579 WARN("Unsupported WIC bitmap format %s.\n", debugstr_guid(&wic_format
));
580 return D2DERR_UNSUPPORTED_PIXEL_FORMAT
;
583 if (bitmap_desc
.pixelFormat
.format
== DXGI_FORMAT_UNKNOWN
)
584 bitmap_desc
.pixelFormat
.format
= d2d_format
->format
;
585 if (bitmap_desc
.pixelFormat
.alphaMode
== D2D1_ALPHA_MODE_UNKNOWN
)
586 bitmap_desc
.pixelFormat
.alphaMode
= d2d_format
->alphaMode
;
588 switch (bitmap_desc
.pixelFormat
.format
)
590 case DXGI_FORMAT_B8G8R8A8_UNORM
:
595 FIXME("Unhandled format %#x.\n", bitmap_desc
.pixelFormat
.format
);
596 return D2DERR_UNSUPPORTED_PIXEL_FORMAT
;
599 pitch
= ((bpp
* size
.width
) + 15) & ~15;
600 if (pitch
/ bpp
< size
.width
)
601 return E_OUTOFMEMORY
;
602 if (!(data
= heap_calloc(size
.height
, pitch
)))
603 return E_OUTOFMEMORY
;
604 data_size
= size
.height
* pitch
;
608 rect
.Width
= size
.width
;
609 rect
.Height
= size
.height
;
610 if (FAILED(hr
= IWICBitmapSource_CopyPixels(bitmap_source
, &rect
, pitch
, data_size
, data
)))
612 WARN("Failed to copy bitmap pixels, hr %#x.\n", hr
);
617 hr
= d2d_bitmap_create(context
, size
, data
, pitch
, &bitmap_desc
, bitmap
);
624 struct d2d_bitmap
*unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap
*iface
)
628 assert(iface
->lpVtbl
== (ID2D1BitmapVtbl
*)&d2d_bitmap_vtbl
);
629 return CONTAINING_RECORD(iface
, struct d2d_bitmap
, ID2D1Bitmap1_iface
);