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 "d2d1_private.h"
22 WINE_DEFAULT_DEBUG_CHANNEL(d2d
);
24 static inline struct d2d_bitmap
*impl_from_ID2D1Bitmap1(ID2D1Bitmap1
*iface
)
26 return CONTAINING_RECORD(iface
, struct d2d_bitmap
, ID2D1Bitmap1_iface
);
29 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_QueryInterface(ID2D1Bitmap1
*iface
, REFIID iid
, void **out
)
31 TRACE("iface %p, iid %s, out %p.\n", iface
, debugstr_guid(iid
), out
);
33 if (IsEqualGUID(iid
, &IID_ID2D1Bitmap1
)
34 || IsEqualGUID(iid
, &IID_ID2D1Bitmap
)
35 || IsEqualGUID(iid
, &IID_ID2D1Image
)
36 || IsEqualGUID(iid
, &IID_ID2D1Resource
)
37 || IsEqualGUID(iid
, &IID_IUnknown
))
39 ID2D1Bitmap1_AddRef(iface
);
44 WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid
));
50 static ULONG STDMETHODCALLTYPE
d2d_bitmap_AddRef(ID2D1Bitmap1
*iface
)
52 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
53 ULONG refcount
= InterlockedIncrement(&bitmap
->refcount
);
55 TRACE("%p increasing refcount to %lu.\n", iface
, refcount
);
60 static ULONG STDMETHODCALLTYPE
d2d_bitmap_Release(ID2D1Bitmap1
*iface
)
62 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
63 ULONG refcount
= InterlockedDecrement(&bitmap
->refcount
);
65 TRACE("%p decreasing refcount to %lu.\n", iface
, refcount
);
70 ID3D11ShaderResourceView_Release(bitmap
->srv
);
72 ID3D11RenderTargetView_Release(bitmap
->rtv
);
74 IDXGISurface_Release(bitmap
->surface
);
75 ID3D11Resource_Release(bitmap
->resource
);
76 ID2D1Factory_Release(bitmap
->factory
);
83 static void STDMETHODCALLTYPE
d2d_bitmap_GetFactory(ID2D1Bitmap1
*iface
, ID2D1Factory
**factory
)
85 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
87 TRACE("iface %p, factory %p.\n", iface
, factory
);
89 ID2D1Factory_AddRef(*factory
= bitmap
->factory
);
92 static D2D1_SIZE_F
* STDMETHODCALLTYPE
d2d_bitmap_GetSize(ID2D1Bitmap1
*iface
, D2D1_SIZE_F
*size
)
94 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
96 TRACE("iface %p, size %p.\n", iface
, size
);
98 size
->width
= bitmap
->pixel_size
.width
/ (bitmap
->dpi_x
/ 96.0f
);
99 size
->height
= bitmap
->pixel_size
.height
/ (bitmap
->dpi_y
/ 96.0f
);
103 static D2D1_SIZE_U
* STDMETHODCALLTYPE
d2d_bitmap_GetPixelSize(ID2D1Bitmap1
*iface
, D2D1_SIZE_U
*pixel_size
)
105 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
107 TRACE("iface %p, pixel_size %p.\n", iface
, pixel_size
);
109 *pixel_size
= bitmap
->pixel_size
;
113 static D2D1_PIXEL_FORMAT
* STDMETHODCALLTYPE
d2d_bitmap_GetPixelFormat(ID2D1Bitmap1
*iface
, D2D1_PIXEL_FORMAT
*format
)
115 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
117 TRACE("iface %p, format %p.\n", iface
, format
);
119 *format
= bitmap
->format
;
123 static void STDMETHODCALLTYPE
d2d_bitmap_GetDpi(ID2D1Bitmap1
*iface
, float *dpi_x
, float *dpi_y
)
125 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
127 TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface
, dpi_x
, dpi_y
);
129 *dpi_x
= bitmap
->dpi_x
;
130 *dpi_y
= bitmap
->dpi_y
;
133 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_CopyFromBitmap(ID2D1Bitmap1
*iface
,
134 const D2D1_POINT_2U
*dst_point
, ID2D1Bitmap
*bitmap
, const D2D1_RECT_U
*src_rect
)
136 struct d2d_bitmap
*src_bitmap
= unsafe_impl_from_ID2D1Bitmap(bitmap
);
137 struct d2d_bitmap
*dst_bitmap
= impl_from_ID2D1Bitmap1(iface
);
138 ID3D11DeviceContext
*context
;
139 ID3D11Device
*device
;
142 TRACE("iface %p, dst_point %p, bitmap %p, src_rect %p.\n", iface
, dst_point
, bitmap
, src_rect
);
146 box
.left
= src_rect
->left
;
147 box
.top
= src_rect
->top
;
149 box
.right
= src_rect
->right
;
150 box
.bottom
= src_rect
->bottom
;
154 ID3D11Resource_GetDevice(dst_bitmap
->resource
, &device
);
155 ID3D11Device_GetImmediateContext(device
, &context
);
156 ID3D11DeviceContext_CopySubresourceRegion(context
, dst_bitmap
->resource
, 0,
157 dst_point
? dst_point
->x
: 0, dst_point
? dst_point
->y
: 0, 0,
158 src_bitmap
->resource
, 0, src_rect
? &box
: NULL
);
159 ID3D11DeviceContext_Release(context
);
160 ID3D11Device_Release(device
);
165 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_CopyFromRenderTarget(ID2D1Bitmap1
*iface
,
166 const D2D1_POINT_2U
*dst_point
, ID2D1RenderTarget
*render_target
, const D2D1_RECT_U
*src_rect
)
168 FIXME("iface %p, dst_point %p, render_target %p, src_rect %p stub!\n", iface
, dst_point
, render_target
, src_rect
);
173 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_CopyFromMemory(ID2D1Bitmap1
*iface
,
174 const D2D1_RECT_U
*dst_rect
, const void *src_data
, UINT32 pitch
)
176 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
177 ID3D11DeviceContext
*context
;
178 ID3D11Device
*device
;
181 TRACE("iface %p, dst_rect %p, src_data %p, pitch %u.\n", iface
, dst_rect
, src_data
, pitch
);
185 box
.left
= dst_rect
->left
;
186 box
.top
= dst_rect
->top
;
188 box
.right
= dst_rect
->right
;
189 box
.bottom
= dst_rect
->bottom
;
193 ID3D11Resource_GetDevice(bitmap
->resource
, &device
);
194 ID3D11Device_GetImmediateContext(device
, &context
);
195 ID3D11DeviceContext_UpdateSubresource(context
, bitmap
->resource
, 0, dst_rect
? &box
: NULL
, src_data
, pitch
, 0);
196 ID3D11DeviceContext_Release(context
);
197 ID3D11Device_Release(device
);
202 static void STDMETHODCALLTYPE
d2d_bitmap_GetColorContext(ID2D1Bitmap1
*iface
, ID2D1ColorContext
**context
)
204 FIXME("iface %p, context %p stub!\n", iface
, context
);
207 static D2D1_BITMAP_OPTIONS STDMETHODCALLTYPE
d2d_bitmap_GetOptions(ID2D1Bitmap1
*iface
)
209 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
211 TRACE("iface %p.\n", iface
);
213 return bitmap
->options
;
216 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_GetSurface(ID2D1Bitmap1
*iface
, IDXGISurface
**surface
)
218 struct d2d_bitmap
*bitmap
= impl_from_ID2D1Bitmap1(iface
);
220 TRACE("iface %p, surface %p.\n", iface
, surface
);
222 *surface
= bitmap
->surface
;
224 IDXGISurface_AddRef(*surface
);
226 return *surface
? S_OK
: D2DERR_INVALID_CALL
;
229 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_Map(ID2D1Bitmap1
*iface
, D2D1_MAP_OPTIONS options
,
230 D2D1_MAPPED_RECT
*mapped_rect
)
232 FIXME("iface %p, options %#x, mapped_rect %p stub!\n", iface
, options
, mapped_rect
);
237 static HRESULT STDMETHODCALLTYPE
d2d_bitmap_Unmap(ID2D1Bitmap1
*iface
)
239 FIXME("iface %p stub!\n", iface
);
244 static const struct ID2D1Bitmap1Vtbl d2d_bitmap_vtbl
=
246 d2d_bitmap_QueryInterface
,
249 d2d_bitmap_GetFactory
,
251 d2d_bitmap_GetPixelSize
,
252 d2d_bitmap_GetPixelFormat
,
254 d2d_bitmap_CopyFromBitmap
,
255 d2d_bitmap_CopyFromRenderTarget
,
256 d2d_bitmap_CopyFromMemory
,
257 d2d_bitmap_GetColorContext
,
258 d2d_bitmap_GetOptions
,
259 d2d_bitmap_GetSurface
,
264 static BOOL
format_supported(const D2D1_PIXEL_FORMAT
*format
)
268 static const D2D1_PIXEL_FORMAT supported_formats
[] =
270 {DXGI_FORMAT_R32G32B32A32_FLOAT
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
271 {DXGI_FORMAT_R32G32B32A32_FLOAT
, D2D1_ALPHA_MODE_IGNORE
},
272 {DXGI_FORMAT_R16G16B16A16_FLOAT
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
273 {DXGI_FORMAT_R16G16B16A16_FLOAT
, D2D1_ALPHA_MODE_IGNORE
},
274 {DXGI_FORMAT_R16G16B16A16_UNORM
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
275 {DXGI_FORMAT_R16G16B16A16_UNORM
, D2D1_ALPHA_MODE_IGNORE
},
276 {DXGI_FORMAT_R8G8B8A8_UNORM
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
277 {DXGI_FORMAT_R8G8B8A8_UNORM
, D2D1_ALPHA_MODE_IGNORE
},
278 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
279 {DXGI_FORMAT_R8G8B8A8_UNORM_SRGB
, D2D1_ALPHA_MODE_IGNORE
},
280 {DXGI_FORMAT_A8_UNORM
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
281 {DXGI_FORMAT_A8_UNORM
, D2D1_ALPHA_MODE_STRAIGHT
},
282 {DXGI_FORMAT_B8G8R8A8_UNORM
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
283 {DXGI_FORMAT_B8G8R8A8_UNORM
, D2D1_ALPHA_MODE_IGNORE
},
284 {DXGI_FORMAT_B8G8R8X8_UNORM
, D2D1_ALPHA_MODE_IGNORE
},
285 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB
, D2D1_ALPHA_MODE_PREMULTIPLIED
},
286 {DXGI_FORMAT_B8G8R8A8_UNORM_SRGB
, D2D1_ALPHA_MODE_IGNORE
},
289 for (i
= 0; i
< ARRAY_SIZE(supported_formats
); ++i
)
291 if (supported_formats
[i
].format
== format
->format
292 && supported_formats
[i
].alphaMode
== format
->alphaMode
)
299 static void d2d_bitmap_init(struct d2d_bitmap
*bitmap
, struct d2d_device_context
*context
,
300 ID3D11Resource
*resource
, D2D1_SIZE_U size
, const D2D1_BITMAP_PROPERTIES1
*desc
)
302 ID3D11Device
*d3d_device
;
305 bitmap
->ID2D1Bitmap1_iface
.lpVtbl
= &d2d_bitmap_vtbl
;
306 bitmap
->refcount
= 1;
307 ID2D1Factory_AddRef(bitmap
->factory
= context
->factory
);
308 ID3D11Resource_AddRef(bitmap
->resource
= resource
);
309 bitmap
->pixel_size
= size
;
310 bitmap
->format
= desc
->pixelFormat
;
311 bitmap
->dpi_x
= desc
->dpiX
;
312 bitmap
->dpi_y
= desc
->dpiY
;
313 bitmap
->options
= desc
->bitmapOptions
;
315 if (d2d_device_context_is_dxgi_target(context
))
316 ID3D11Resource_QueryInterface(resource
, &IID_IDXGISurface
, (void **)&bitmap
->surface
);
318 ID3D11Resource_GetDevice(resource
, &d3d_device
);
319 if (bitmap
->options
& D2D1_BITMAP_OPTIONS_TARGET
)
321 if (FAILED(hr
= ID3D11Device_CreateRenderTargetView(d3d_device
, resource
, NULL
, &bitmap
->rtv
)))
322 WARN("Failed to create RTV, hr %#lx.\n", hr
);
325 if (!(bitmap
->options
& D2D1_BITMAP_OPTIONS_CANNOT_DRAW
))
327 if (FAILED(hr
= ID3D11Device_CreateShaderResourceView(d3d_device
, resource
, NULL
, &bitmap
->srv
)))
328 WARN("Failed to create SRV, hr %#lx.\n", hr
);
330 ID3D11Device_Release(d3d_device
);
332 if (bitmap
->dpi_x
== 0.0f
&& bitmap
->dpi_y
== 0.0f
)
334 bitmap
->dpi_x
= 96.0f
;
335 bitmap
->dpi_y
= 96.0f
;
339 HRESULT
d2d_bitmap_create(struct d2d_device_context
*context
, D2D1_SIZE_U size
, const void *src_data
,
340 UINT32 pitch
, const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
)
342 D3D11_SUBRESOURCE_DATA resource_data
;
343 D2D1_BITMAP_PROPERTIES1 bitmap_desc
;
344 D3D11_TEXTURE2D_DESC texture_desc
;
345 ID3D11Texture2D
*texture
;
348 if (!format_supported(&desc
->pixelFormat
))
350 WARN("Tried to create bitmap with unsupported format {%#x / %#x}.\n",
351 desc
->pixelFormat
.format
, desc
->pixelFormat
.alphaMode
);
352 return D2DERR_UNSUPPORTED_PIXEL_FORMAT
;
355 if (desc
->dpiX
== 0.0f
&& desc
->dpiY
== 0.0f
)
358 bitmap_desc
.dpiX
= context
->desc
.dpiX
;
359 bitmap_desc
.dpiY
= context
->desc
.dpiY
;
362 else if (desc
->dpiX
<= 0.0f
|| desc
->dpiY
<= 0.0f
)
367 texture_desc
.Width
= size
.width
;
368 texture_desc
.Height
= size
.height
;
369 if (!texture_desc
.Width
|| !texture_desc
.Height
)
370 texture_desc
.Width
= texture_desc
.Height
= 1;
371 texture_desc
.MipLevels
= 1;
372 texture_desc
.ArraySize
= 1;
373 texture_desc
.Format
= desc
->pixelFormat
.format
;
374 texture_desc
.SampleDesc
.Count
= 1;
375 texture_desc
.SampleDesc
.Quality
= 0;
376 texture_desc
.Usage
= D3D11_USAGE_DEFAULT
;
377 texture_desc
.BindFlags
= 0;
378 if (desc
->bitmapOptions
& D2D1_BITMAP_OPTIONS_TARGET
)
379 texture_desc
.BindFlags
|= D3D11_BIND_RENDER_TARGET
;
380 if (!(desc
->bitmapOptions
& D2D1_BITMAP_OPTIONS_CANNOT_DRAW
))
381 texture_desc
.BindFlags
|= D3D11_BIND_SHADER_RESOURCE
;
382 texture_desc
.CPUAccessFlags
= 0;
383 texture_desc
.MiscFlags
= 0;
384 if (desc
->bitmapOptions
& D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE
)
385 texture_desc
.MiscFlags
|= D3D11_RESOURCE_MISC_GDI_COMPATIBLE
;
387 resource_data
.pSysMem
= src_data
;
388 resource_data
.SysMemPitch
= pitch
;
390 if (FAILED(hr
= ID3D11Device1_CreateTexture2D(context
->d3d_device
, &texture_desc
,
391 src_data
? &resource_data
: NULL
, &texture
)))
393 ERR("Failed to create texture, hr %#lx.\n", hr
);
397 if ((*bitmap
= heap_alloc_zero(sizeof(**bitmap
))))
399 d2d_bitmap_init(*bitmap
, context
, (ID3D11Resource
*)texture
, size
, desc
);
400 TRACE("Created bitmap %p.\n", *bitmap
);
402 ID3D11Texture2D_Release(texture
);
404 return *bitmap
? S_OK
: E_OUTOFMEMORY
;
407 HRESULT
d2d_bitmap_create_shared(struct d2d_device_context
*context
, REFIID iid
, void *data
,
408 const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
)
410 D2D1_BITMAP_PROPERTIES1 d
;
412 if (IsEqualGUID(iid
, &IID_ID2D1Bitmap
))
414 struct d2d_bitmap
*src_impl
= unsafe_impl_from_ID2D1Bitmap(data
);
415 ID3D11Device
*device
;
418 if (src_impl
->factory
!= context
->factory
)
420 hr
= D2DERR_WRONG_FACTORY
;
424 ID3D11Resource_GetDevice(src_impl
->resource
, &device
);
425 ID3D11Device_Release(device
);
426 if (device
!= (ID3D11Device
*)context
->d3d_device
)
428 hr
= D2DERR_UNSUPPORTED_OPERATION
;
434 d
.pixelFormat
= src_impl
->format
;
435 d
.dpiX
= src_impl
->dpi_x
;
436 d
.dpiY
= src_impl
->dpi_y
;
437 d
.bitmapOptions
= src_impl
->options
;
438 d
.colorContext
= NULL
;
442 if (!format_supported(&desc
->pixelFormat
))
444 WARN("Tried to create bitmap with unsupported format {%#x / %#x}.\n",
445 desc
->pixelFormat
.format
, desc
->pixelFormat
.alphaMode
);
446 hr
= D2DERR_UNSUPPORTED_PIXEL_FORMAT
;
450 if (!(*bitmap
= heap_alloc_zero(sizeof(**bitmap
))))
456 d2d_bitmap_init(*bitmap
, context
, src_impl
->resource
, src_impl
->pixel_size
, desc
);
457 TRACE("Created bitmap %p.\n", *bitmap
);
463 if (IsEqualGUID(iid
, &IID_IDXGISurface
) || IsEqualGUID(iid
, &IID_IDXGISurface1
))
465 DXGI_SURFACE_DESC surface_desc
;
466 IDXGISurface
*surface
= data
;
467 ID3D11Resource
*resource
;
468 D2D1_SIZE_U pixel_size
;
469 ID3D11Device
*device
;
472 if (FAILED(IDXGISurface_QueryInterface(surface
, &IID_ID3D11Resource
, (void **)&resource
)))
474 WARN("Failed to get d3d resource from dxgi surface.\n");
478 ID3D11Resource_GetDevice(resource
, &device
);
479 ID3D11Device_Release(device
);
480 if (device
!= (ID3D11Device
*)context
->d3d_device
)
482 ID3D11Resource_Release(resource
);
483 return D2DERR_UNSUPPORTED_OPERATION
;
486 if (!(*bitmap
= heap_alloc_zero(sizeof(**bitmap
))))
488 ID3D11Resource_Release(resource
);
489 return E_OUTOFMEMORY
;
493 if (FAILED(hr
= IDXGISurface_GetDesc(surface
, &surface_desc
)))
495 WARN("Failed to get surface desc, hr %#lx.\n", hr
);
496 ID3D11Resource_Release(resource
);
502 memset(&d
, 0, sizeof(d
));
503 d
.pixelFormat
.format
= surface_desc
.Format
;
508 if (d
.pixelFormat
.format
== DXGI_FORMAT_UNKNOWN
)
509 d
.pixelFormat
.format
= surface_desc
.Format
;
512 if (d
.dpiX
== 0.0f
|| d
.dpiY
== 0.0f
)
515 d
.dpiX
= context
->desc
.dpiX
;
517 d
.dpiY
= context
->desc
.dpiY
;
520 pixel_size
.width
= surface_desc
.Width
;
521 pixel_size
.height
= surface_desc
.Height
;
523 d2d_bitmap_init(*bitmap
, context
, resource
, pixel_size
, &d
);
524 ID3D11Resource_Release(resource
);
525 TRACE("Created bitmap %p.\n", *bitmap
);
530 WARN("Unhandled interface %s.\n", debugstr_guid(iid
));
535 HRESULT
d2d_bitmap_create_from_wic_bitmap(struct d2d_device_context
*context
, IWICBitmapSource
*bitmap_source
,
536 const D2D1_BITMAP_PROPERTIES1
*desc
, struct d2d_bitmap
**bitmap
)
538 const D2D1_PIXEL_FORMAT
*d2d_format
;
539 D2D1_BITMAP_PROPERTIES1 bitmap_desc
;
540 WICPixelFormatGUID wic_format
;
541 unsigned int bpp
, data_size
;
551 const WICPixelFormatGUID
*wic
;
552 D2D1_PIXEL_FORMAT d2d
;
556 {&GUID_WICPixelFormat32bppPBGRA
, {DXGI_FORMAT_B8G8R8A8_UNORM
, D2D1_ALPHA_MODE_PREMULTIPLIED
}},
557 {&GUID_WICPixelFormat32bppPRGBA
, {DXGI_FORMAT_R8G8B8A8_UNORM
, D2D1_ALPHA_MODE_PREMULTIPLIED
}},
558 {&GUID_WICPixelFormat32bppBGR
, {DXGI_FORMAT_B8G8R8A8_UNORM
, D2D1_ALPHA_MODE_IGNORE
}},
561 if (FAILED(hr
= IWICBitmapSource_GetSize(bitmap_source
, &size
.width
, &size
.height
)))
563 WARN("Failed to get bitmap size, hr %#lx.\n", hr
);
569 bitmap_desc
.pixelFormat
.format
= DXGI_FORMAT_UNKNOWN
;
570 bitmap_desc
.pixelFormat
.alphaMode
= D2D1_ALPHA_MODE_UNKNOWN
;
571 bitmap_desc
.dpiX
= 0.0f
;
572 bitmap_desc
.dpiY
= 0.0f
;
573 bitmap_desc
.bitmapOptions
= 0;
574 bitmap_desc
.colorContext
= NULL
;
581 if (FAILED(hr
= IWICBitmapSource_GetPixelFormat(bitmap_source
, &wic_format
)))
583 WARN("Failed to get bitmap format, hr %#lx.\n", hr
);
587 for (i
= 0, d2d_format
= NULL
; i
< ARRAY_SIZE(format_lookup
); ++i
)
589 if (IsEqualGUID(&wic_format
, format_lookup
[i
].wic
))
591 d2d_format
= &format_lookup
[i
].d2d
;
598 WARN("Unsupported WIC bitmap format %s.\n", debugstr_guid(&wic_format
));
599 return D2DERR_UNSUPPORTED_PIXEL_FORMAT
;
602 if (bitmap_desc
.pixelFormat
.format
== DXGI_FORMAT_UNKNOWN
)
603 bitmap_desc
.pixelFormat
.format
= d2d_format
->format
;
604 if (bitmap_desc
.pixelFormat
.alphaMode
== D2D1_ALPHA_MODE_UNKNOWN
)
605 bitmap_desc
.pixelFormat
.alphaMode
= d2d_format
->alphaMode
;
607 switch (bitmap_desc
.pixelFormat
.format
)
609 case DXGI_FORMAT_B8G8R8A8_UNORM
:
610 case DXGI_FORMAT_R8G8B8A8_UNORM
:
615 FIXME("Unhandled format %#x.\n", bitmap_desc
.pixelFormat
.format
);
616 return D2DERR_UNSUPPORTED_PIXEL_FORMAT
;
619 pitch
= ((bpp
* size
.width
) + 15) & ~15;
620 if (pitch
/ bpp
< size
.width
)
621 return E_OUTOFMEMORY
;
622 if (!(data
= heap_calloc(size
.height
, pitch
)))
623 return E_OUTOFMEMORY
;
624 data_size
= size
.height
* pitch
;
628 rect
.Width
= size
.width
;
629 rect
.Height
= size
.height
;
630 if (FAILED(hr
= IWICBitmapSource_CopyPixels(bitmap_source
, &rect
, pitch
, data_size
, data
)))
632 WARN("Failed to copy bitmap pixels, hr %#lx.\n", hr
);
637 hr
= d2d_bitmap_create(context
, size
, data
, pitch
, &bitmap_desc
, bitmap
);
644 struct d2d_bitmap
*unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap
*iface
)
648 assert(iface
->lpVtbl
== (ID2D1BitmapVtbl
*)&d2d_bitmap_vtbl
);
649 return CONTAINING_RECORD(iface
, struct d2d_bitmap
, ID2D1Bitmap1_iface
);