2014-09-16 10:44:13 +02:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Henri Verbeet for CodeWeavers
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "d2d1_private.h"
|
2016-03-29 20:30:38 +02:00
|
|
|
#include "wincodec.h"
|
2014-09-16 10:44:13 +02:00
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(d2d);
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static inline struct d2d_bitmap *impl_from_ID2D1Bitmap1(ID2D1Bitmap1 *iface)
|
2014-09-16 10:44:13 +02:00
|
|
|
{
|
2018-05-23 13:44:12 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct d2d_bitmap, ID2D1Bitmap1_iface);
|
2014-09-16 10:44:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d2d_bitmap_QueryInterface(ID2D1Bitmap1 *iface, REFIID iid, void **out)
|
2014-09-16 10:44:13 +02:00
|
|
|
{
|
|
|
|
TRACE("iface %p, iid %s, out %p.\n", iface, debugstr_guid(iid), out);
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
if (IsEqualGUID(iid, &IID_ID2D1Bitmap1)
|
|
|
|
|| IsEqualGUID(iid, &IID_ID2D1Bitmap)
|
2017-11-22 15:21:05 +01:00
|
|
|
|| IsEqualGUID(iid, &IID_ID2D1Image)
|
2014-09-16 10:44:13 +02:00
|
|
|
|| IsEqualGUID(iid, &IID_ID2D1Resource)
|
|
|
|
|| IsEqualGUID(iid, &IID_IUnknown))
|
|
|
|
{
|
2018-05-23 13:44:12 +02:00
|
|
|
ID2D1Bitmap1_AddRef(iface);
|
2014-09-16 10:44:13 +02:00
|
|
|
*out = iface;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE.\n", debugstr_guid(iid));
|
|
|
|
|
|
|
|
*out = NULL;
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static ULONG STDMETHODCALLTYPE d2d_bitmap_AddRef(ID2D1Bitmap1 *iface)
|
2014-09-16 10:44:13 +02:00
|
|
|
{
|
2018-05-23 13:44:12 +02:00
|
|
|
struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface);
|
2014-09-16 10:44:13 +02:00
|
|
|
ULONG refcount = InterlockedIncrement(&bitmap->refcount);
|
|
|
|
|
2022-02-01 19:23:14 +01:00
|
|
|
TRACE("%p increasing refcount to %lu.\n", iface, refcount);
|
2014-09-16 10:44:13 +02:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static ULONG STDMETHODCALLTYPE d2d_bitmap_Release(ID2D1Bitmap1 *iface)
|
2014-09-16 10:44:13 +02:00
|
|
|
{
|
2018-05-23 13:44:12 +02:00
|
|
|
struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface);
|
2014-09-16 10:44:13 +02:00
|
|
|
ULONG refcount = InterlockedDecrement(&bitmap->refcount);
|
|
|
|
|
2022-02-01 19:23:14 +01:00
|
|
|
TRACE("%p decreasing refcount to %lu.\n", iface, refcount);
|
2014-09-16 10:44:13 +02:00
|
|
|
|
|
|
|
if (!refcount)
|
2015-02-06 09:57:01 +01:00
|
|
|
{
|
2019-09-25 21:05:57 +02:00
|
|
|
if (bitmap->srv)
|
2021-06-28 09:17:37 +02:00
|
|
|
ID3D11ShaderResourceView_Release(bitmap->srv);
|
2018-09-29 01:02:06 +02:00
|
|
|
if (bitmap->rtv)
|
2021-06-28 09:17:37 +02:00
|
|
|
ID3D11RenderTargetView_Release(bitmap->rtv);
|
2018-09-16 17:51:19 +02:00
|
|
|
if (bitmap->surface)
|
|
|
|
IDXGISurface_Release(bitmap->surface);
|
2021-06-28 09:17:37 +02:00
|
|
|
ID3D11Resource_Release(bitmap->resource);
|
2015-08-04 08:53:25 +02:00
|
|
|
ID2D1Factory_Release(bitmap->factory);
|
2018-01-30 13:24:39 +01:00
|
|
|
heap_free(bitmap);
|
2015-02-06 09:57:01 +01:00
|
|
|
}
|
2014-09-16 10:44:13 +02:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static void STDMETHODCALLTYPE d2d_bitmap_GetFactory(ID2D1Bitmap1 *iface, ID2D1Factory **factory)
|
2014-09-16 10:44:13 +02:00
|
|
|
{
|
2018-05-23 13:44:12 +02:00
|
|
|
struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface);
|
2015-08-04 08:53:25 +02:00
|
|
|
|
|
|
|
TRACE("iface %p, factory %p.\n", iface, factory);
|
2014-09-16 10:44:13 +02:00
|
|
|
|
2015-08-04 08:53:25 +02:00
|
|
|
ID2D1Factory_AddRef(*factory = bitmap->factory);
|
2014-09-16 10:44:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static D2D1_SIZE_F * STDMETHODCALLTYPE d2d_bitmap_GetSize(ID2D1Bitmap1 *iface, D2D1_SIZE_F *size)
|
2014-09-16 10:44:13 +02:00
|
|
|
{
|
2018-05-23 13:44:12 +02:00
|
|
|
struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface);
|
2015-02-06 09:57:00 +01:00
|
|
|
|
|
|
|
TRACE("iface %p, size %p.\n", iface, size);
|
2014-09-16 10:44:13 +02:00
|
|
|
|
2015-02-06 09:57:00 +01:00
|
|
|
size->width = bitmap->pixel_size.width / (bitmap->dpi_x / 96.0f);
|
|
|
|
size->height = bitmap->pixel_size.height / (bitmap->dpi_y / 96.0f);
|
2014-09-16 10:44:13 +02:00
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static D2D1_SIZE_U * STDMETHODCALLTYPE d2d_bitmap_GetPixelSize(ID2D1Bitmap1 *iface, D2D1_SIZE_U *pixel_size)
|
2014-09-16 10:44:13 +02:00
|
|
|
{
|
2018-05-23 13:44:12 +02:00
|
|
|
struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface);
|
2015-02-06 09:56:58 +01:00
|
|
|
|
|
|
|
TRACE("iface %p, pixel_size %p.\n", iface, pixel_size);
|
2014-09-16 10:44:13 +02:00
|
|
|
|
2015-02-06 09:56:58 +01:00
|
|
|
*pixel_size = bitmap->pixel_size;
|
2014-09-16 10:44:13 +02:00
|
|
|
return pixel_size;
|
|
|
|
}
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static D2D1_PIXEL_FORMAT * STDMETHODCALLTYPE d2d_bitmap_GetPixelFormat(ID2D1Bitmap1 *iface, D2D1_PIXEL_FORMAT *format)
|
2014-09-16 10:44:13 +02:00
|
|
|
{
|
2018-05-23 13:44:12 +02:00
|
|
|
struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface);
|
2015-07-29 11:36:19 +02:00
|
|
|
|
|
|
|
TRACE("iface %p, format %p.\n", iface, format);
|
2014-09-16 10:44:13 +02:00
|
|
|
|
2015-07-29 11:36:19 +02:00
|
|
|
*format = bitmap->format;
|
2014-09-16 10:44:13 +02:00
|
|
|
return format;
|
|
|
|
}
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static void STDMETHODCALLTYPE d2d_bitmap_GetDpi(ID2D1Bitmap1 *iface, float *dpi_x, float *dpi_y)
|
2014-09-16 10:44:13 +02:00
|
|
|
{
|
2018-05-23 13:44:12 +02:00
|
|
|
struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface);
|
2015-02-06 09:56:59 +01:00
|
|
|
|
|
|
|
TRACE("iface %p, dpi_x %p, dpi_y %p.\n", iface, dpi_x, dpi_y);
|
2014-09-16 10:44:13 +02:00
|
|
|
|
2015-02-06 09:56:59 +01:00
|
|
|
*dpi_x = bitmap->dpi_x;
|
|
|
|
*dpi_y = bitmap->dpi_y;
|
2014-09-16 10:44:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d2d_bitmap_CopyFromBitmap(ID2D1Bitmap1 *iface,
|
2014-09-16 10:44:13 +02:00
|
|
|
const D2D1_POINT_2U *dst_point, ID2D1Bitmap *bitmap, const D2D1_RECT_U *src_rect)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, dst_point %p, bitmap %p, src_rect %p stub!\n", iface, dst_point, bitmap, src_rect);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d2d_bitmap_CopyFromRenderTarget(ID2D1Bitmap1 *iface,
|
2014-09-16 10:44:13 +02:00
|
|
|
const D2D1_POINT_2U *dst_point, ID2D1RenderTarget *render_target, const D2D1_RECT_U *src_rect)
|
|
|
|
{
|
2014-09-28 23:51:59 +02:00
|
|
|
FIXME("iface %p, dst_point %p, render_target %p, src_rect %p stub!\n", iface, dst_point, render_target, src_rect);
|
2014-09-16 10:44:13 +02:00
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE d2d_bitmap_CopyFromMemory(ID2D1Bitmap1 *iface,
|
2014-09-16 10:44:13 +02:00
|
|
|
const D2D1_RECT_U *dst_rect, const void *src_data, UINT32 pitch)
|
|
|
|
{
|
2018-05-23 13:44:12 +02:00
|
|
|
struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface);
|
2021-06-21 09:57:45 +02:00
|
|
|
ID3D11DeviceContext *context;
|
|
|
|
ID3D11Device *device;
|
|
|
|
D3D11_BOX box;
|
2014-09-16 10:44:13 +02:00
|
|
|
|
2015-08-18 11:24:12 +02:00
|
|
|
TRACE("iface %p, dst_rect %p, src_data %p, pitch %u.\n", iface, dst_rect, src_data, pitch);
|
|
|
|
|
|
|
|
if (dst_rect)
|
|
|
|
{
|
|
|
|
box.left = dst_rect->left;
|
|
|
|
box.top = dst_rect->top;
|
|
|
|
box.front = 0;
|
|
|
|
box.right = dst_rect->right;
|
|
|
|
box.bottom = dst_rect->bottom;
|
|
|
|
box.back = 1;
|
|
|
|
}
|
|
|
|
|
2021-06-28 09:17:37 +02:00
|
|
|
ID3D11Resource_GetDevice(bitmap->resource, &device);
|
2021-06-21 09:57:45 +02:00
|
|
|
ID3D11Device_GetImmediateContext(device, &context);
|
2021-06-28 09:17:37 +02:00
|
|
|
ID3D11DeviceContext_UpdateSubresource(context, bitmap->resource, 0, dst_rect ? &box : NULL, src_data, pitch, 0);
|
2021-06-21 09:57:45 +02:00
|
|
|
ID3D11DeviceContext_Release(context);
|
|
|
|
ID3D11Device_Release(device);
|
2015-08-18 11:24:12 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2014-09-16 10:44:13 +02:00
|
|
|
}
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
static void STDMETHODCALLTYPE d2d_bitmap_GetColorContext(ID2D1Bitmap1 *iface, ID2D1ColorContext **context)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, context %p stub!\n", iface, context);
|
|
|
|
}
|
|
|
|
|
|
|
|
static D2D1_BITMAP_OPTIONS STDMETHODCALLTYPE d2d_bitmap_GetOptions(ID2D1Bitmap1 *iface)
|
|
|
|
{
|
2018-09-13 18:16:47 +02:00
|
|
|
struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface);
|
|
|
|
|
|
|
|
TRACE("iface %p.\n", iface);
|
2018-05-23 13:44:12 +02:00
|
|
|
|
2018-09-13 18:16:47 +02:00
|
|
|
return bitmap->options;
|
2018-05-23 13:44:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d2d_bitmap_GetSurface(ID2D1Bitmap1 *iface, IDXGISurface **surface)
|
|
|
|
{
|
2018-09-16 17:51:19 +02:00
|
|
|
struct d2d_bitmap *bitmap = impl_from_ID2D1Bitmap1(iface);
|
2018-05-23 13:44:12 +02:00
|
|
|
|
2018-09-16 17:51:19 +02:00
|
|
|
TRACE("iface %p, surface %p.\n", iface, surface);
|
|
|
|
|
|
|
|
*surface = bitmap->surface;
|
|
|
|
if (*surface)
|
|
|
|
IDXGISurface_AddRef(*surface);
|
|
|
|
|
|
|
|
return *surface ? S_OK : D2DERR_INVALID_CALL;
|
2018-05-23 13:44:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d2d_bitmap_Map(ID2D1Bitmap1 *iface, D2D1_MAP_OPTIONS options,
|
|
|
|
D2D1_MAPPED_RECT *mapped_rect)
|
|
|
|
{
|
|
|
|
FIXME("iface %p, options %#x, mapped_rect %p stub!\n", iface, options, mapped_rect);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE d2d_bitmap_Unmap(ID2D1Bitmap1 *iface)
|
|
|
|
{
|
|
|
|
FIXME("iface %p stub!\n", iface);
|
|
|
|
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct ID2D1Bitmap1Vtbl d2d_bitmap_vtbl =
|
2014-09-16 10:44:13 +02:00
|
|
|
{
|
|
|
|
d2d_bitmap_QueryInterface,
|
|
|
|
d2d_bitmap_AddRef,
|
|
|
|
d2d_bitmap_Release,
|
|
|
|
d2d_bitmap_GetFactory,
|
|
|
|
d2d_bitmap_GetSize,
|
|
|
|
d2d_bitmap_GetPixelSize,
|
|
|
|
d2d_bitmap_GetPixelFormat,
|
|
|
|
d2d_bitmap_GetDpi,
|
|
|
|
d2d_bitmap_CopyFromBitmap,
|
|
|
|
d2d_bitmap_CopyFromRenderTarget,
|
|
|
|
d2d_bitmap_CopyFromMemory,
|
2018-05-23 13:44:12 +02:00
|
|
|
d2d_bitmap_GetColorContext,
|
|
|
|
d2d_bitmap_GetOptions,
|
|
|
|
d2d_bitmap_GetSurface,
|
|
|
|
d2d_bitmap_Map,
|
|
|
|
d2d_bitmap_Unmap,
|
2014-09-16 10:44:13 +02:00
|
|
|
};
|
|
|
|
|
2015-08-04 08:53:27 +02:00
|
|
|
static BOOL format_supported(const D2D1_PIXEL_FORMAT *format)
|
2014-09-16 10:44:13 +02:00
|
|
|
{
|
2015-07-29 11:36:18 +02:00
|
|
|
unsigned int i;
|
2015-02-06 09:57:01 +01:00
|
|
|
|
2015-07-29 11:36:18 +02:00
|
|
|
static const D2D1_PIXEL_FORMAT supported_formats[] =
|
|
|
|
{
|
|
|
|
{DXGI_FORMAT_R32G32B32A32_FLOAT, D2D1_ALPHA_MODE_PREMULTIPLIED},
|
|
|
|
{DXGI_FORMAT_R32G32B32A32_FLOAT, D2D1_ALPHA_MODE_IGNORE },
|
|
|
|
{DXGI_FORMAT_R16G16B16A16_FLOAT, D2D1_ALPHA_MODE_PREMULTIPLIED},
|
|
|
|
{DXGI_FORMAT_R16G16B16A16_FLOAT, D2D1_ALPHA_MODE_IGNORE },
|
|
|
|
{DXGI_FORMAT_R16G16B16A16_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED},
|
|
|
|
{DXGI_FORMAT_R16G16B16A16_UNORM, D2D1_ALPHA_MODE_IGNORE },
|
|
|
|
{DXGI_FORMAT_R8G8B8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED},
|
|
|
|
{DXGI_FORMAT_R8G8B8A8_UNORM, D2D1_ALPHA_MODE_IGNORE },
|
|
|
|
{DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D2D1_ALPHA_MODE_PREMULTIPLIED},
|
|
|
|
{DXGI_FORMAT_R8G8B8A8_UNORM_SRGB, D2D1_ALPHA_MODE_IGNORE },
|
|
|
|
{DXGI_FORMAT_A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED},
|
|
|
|
{DXGI_FORMAT_A8_UNORM, D2D1_ALPHA_MODE_STRAIGHT },
|
|
|
|
{DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED},
|
|
|
|
{DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE },
|
|
|
|
{DXGI_FORMAT_B8G8R8X8_UNORM, D2D1_ALPHA_MODE_IGNORE },
|
|
|
|
{DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D2D1_ALPHA_MODE_PREMULTIPLIED},
|
|
|
|
{DXGI_FORMAT_B8G8R8A8_UNORM_SRGB, D2D1_ALPHA_MODE_IGNORE },
|
|
|
|
};
|
|
|
|
|
2017-07-07 17:15:14 +02:00
|
|
|
for (i = 0; i < ARRAY_SIZE(supported_formats); ++i)
|
2015-07-29 11:36:18 +02:00
|
|
|
{
|
2015-08-04 08:53:27 +02:00
|
|
|
if (supported_formats[i].format == format->format
|
|
|
|
&& supported_formats[i].alphaMode == format->alphaMode)
|
|
|
|
return TRUE;
|
2015-07-29 11:36:18 +02:00
|
|
|
}
|
|
|
|
|
2015-08-04 08:53:27 +02:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2018-09-16 17:51:19 +02:00
|
|
|
static void d2d_bitmap_init(struct d2d_bitmap *bitmap, struct d2d_device_context *context,
|
2021-06-24 09:35:32 +02:00
|
|
|
ID3D11Resource *resource, D2D1_SIZE_U size, const D2D1_BITMAP_PROPERTIES1 *desc)
|
2015-08-04 08:53:27 +02:00
|
|
|
{
|
2021-06-21 09:57:46 +02:00
|
|
|
ID3D11Device *d3d_device;
|
2018-09-29 01:02:06 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2018-05-23 13:44:12 +02:00
|
|
|
bitmap->ID2D1Bitmap1_iface.lpVtbl = &d2d_bitmap_vtbl;
|
2015-08-04 08:53:27 +02:00
|
|
|
bitmap->refcount = 1;
|
2018-09-16 17:51:19 +02:00
|
|
|
ID2D1Factory_AddRef(bitmap->factory = context->factory);
|
2021-06-28 09:17:37 +02:00
|
|
|
ID3D11Resource_AddRef(bitmap->resource = resource);
|
2015-08-04 08:53:27 +02:00
|
|
|
bitmap->pixel_size = size;
|
|
|
|
bitmap->format = desc->pixelFormat;
|
|
|
|
bitmap->dpi_x = desc->dpiX;
|
|
|
|
bitmap->dpi_y = desc->dpiY;
|
2018-09-13 18:16:47 +02:00
|
|
|
bitmap->options = desc->bitmapOptions;
|
2018-09-16 17:51:19 +02:00
|
|
|
|
2018-09-29 01:02:06 +02:00
|
|
|
if (d2d_device_context_is_dxgi_target(context))
|
2021-06-21 09:57:46 +02:00
|
|
|
ID3D11Resource_QueryInterface(resource, &IID_IDXGISurface, (void **)&bitmap->surface);
|
2018-09-29 01:02:06 +02:00
|
|
|
|
2021-06-21 09:57:46 +02:00
|
|
|
ID3D11Resource_GetDevice(resource, &d3d_device);
|
2018-09-29 01:02:06 +02:00
|
|
|
if (bitmap->options & D2D1_BITMAP_OPTIONS_TARGET)
|
|
|
|
{
|
2021-06-28 09:17:37 +02:00
|
|
|
if (FAILED(hr = ID3D11Device_CreateRenderTargetView(d3d_device, resource, NULL, &bitmap->rtv)))
|
2022-02-01 19:23:14 +01:00
|
|
|
WARN("Failed to create RTV, hr %#lx.\n", hr);
|
2018-09-16 17:51:19 +02:00
|
|
|
}
|
2015-08-04 08:53:27 +02:00
|
|
|
|
2019-09-25 21:05:57 +02:00
|
|
|
if (!(bitmap->options & D2D1_BITMAP_OPTIONS_CANNOT_DRAW))
|
|
|
|
{
|
2021-06-28 09:17:37 +02:00
|
|
|
if (FAILED(hr = ID3D11Device_CreateShaderResourceView(d3d_device, resource, NULL, &bitmap->srv)))
|
2022-02-01 19:23:14 +01:00
|
|
|
WARN("Failed to create SRV, hr %#lx.\n", hr);
|
2019-09-25 21:05:57 +02:00
|
|
|
}
|
2021-06-21 09:57:46 +02:00
|
|
|
ID3D11Device_Release(d3d_device);
|
2018-09-29 01:02:06 +02:00
|
|
|
|
2015-08-04 08:53:27 +02:00
|
|
|
if (bitmap->dpi_x == 0.0f && bitmap->dpi_y == 0.0f)
|
|
|
|
{
|
|
|
|
bitmap->dpi_x = 96.0f;
|
|
|
|
bitmap->dpi_y = 96.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 17:51:19 +02:00
|
|
|
HRESULT d2d_bitmap_create(struct d2d_device_context *context, D2D1_SIZE_U size, const void *src_data,
|
2018-09-13 18:16:47 +02:00
|
|
|
UINT32 pitch, const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap)
|
2015-08-04 08:53:27 +02:00
|
|
|
{
|
2021-06-21 09:57:48 +02:00
|
|
|
D3D11_SUBRESOURCE_DATA resource_data;
|
2019-10-24 16:10:48 +02:00
|
|
|
D2D1_BITMAP_PROPERTIES1 bitmap_desc;
|
2021-06-21 09:57:48 +02:00
|
|
|
D3D11_TEXTURE2D_DESC texture_desc;
|
|
|
|
ID3D11Texture2D *texture;
|
2015-08-04 08:53:27 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
if (!format_supported(&desc->pixelFormat))
|
2015-07-29 11:36:18 +02:00
|
|
|
{
|
|
|
|
WARN("Tried to create bitmap with unsupported format {%#x / %#x}.\n",
|
|
|
|
desc->pixelFormat.format, desc->pixelFormat.alphaMode);
|
|
|
|
return D2DERR_UNSUPPORTED_PIXEL_FORMAT;
|
|
|
|
}
|
|
|
|
|
2019-10-24 16:10:48 +02:00
|
|
|
if (desc->dpiX == 0.0f && desc->dpiY == 0.0f)
|
|
|
|
{
|
|
|
|
bitmap_desc = *desc;
|
|
|
|
bitmap_desc.dpiX = context->desc.dpiX;
|
|
|
|
bitmap_desc.dpiY = context->desc.dpiY;
|
|
|
|
desc = &bitmap_desc;
|
|
|
|
}
|
|
|
|
else if (desc->dpiX <= 0.0f || desc->dpiY <= 0.0f)
|
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2015-02-06 09:57:01 +01:00
|
|
|
texture_desc.Width = size.width;
|
|
|
|
texture_desc.Height = size.height;
|
2018-09-29 01:02:04 +02:00
|
|
|
if (!texture_desc.Width || !texture_desc.Height)
|
|
|
|
texture_desc.Width = texture_desc.Height = 1;
|
2015-02-06 09:57:01 +01:00
|
|
|
texture_desc.MipLevels = 1;
|
|
|
|
texture_desc.ArraySize = 1;
|
|
|
|
texture_desc.Format = desc->pixelFormat.format;
|
|
|
|
texture_desc.SampleDesc.Count = 1;
|
|
|
|
texture_desc.SampleDesc.Quality = 0;
|
2021-06-21 09:57:48 +02:00
|
|
|
texture_desc.Usage = D3D11_USAGE_DEFAULT;
|
2018-10-02 08:33:06 +02:00
|
|
|
texture_desc.BindFlags = 0;
|
|
|
|
if (desc->bitmapOptions & D2D1_BITMAP_OPTIONS_TARGET)
|
2021-06-21 09:57:48 +02:00
|
|
|
texture_desc.BindFlags |= D3D11_BIND_RENDER_TARGET;
|
2018-10-02 08:33:06 +02:00
|
|
|
if (!(desc->bitmapOptions & D2D1_BITMAP_OPTIONS_CANNOT_DRAW))
|
2021-06-21 09:57:48 +02:00
|
|
|
texture_desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
|
2015-02-06 09:57:01 +01:00
|
|
|
texture_desc.CPUAccessFlags = 0;
|
|
|
|
texture_desc.MiscFlags = 0;
|
2018-10-02 08:33:07 +02:00
|
|
|
if (desc->bitmapOptions & D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE)
|
2021-06-21 09:57:48 +02:00
|
|
|
texture_desc.MiscFlags |= D3D11_RESOURCE_MISC_GDI_COMPATIBLE;
|
2015-02-06 09:57:01 +01:00
|
|
|
|
|
|
|
resource_data.pSysMem = src_data;
|
|
|
|
resource_data.SysMemPitch = pitch;
|
|
|
|
|
2021-06-28 09:17:37 +02:00
|
|
|
if (FAILED(hr = ID3D11Device1_CreateTexture2D(context->d3d_device, &texture_desc,
|
2015-07-30 11:10:58 +02:00
|
|
|
src_data ? &resource_data : NULL, &texture)))
|
2015-02-06 09:57:01 +01:00
|
|
|
{
|
2022-02-01 19:23:14 +01:00
|
|
|
ERR("Failed to create texture, hr %#lx.\n", hr);
|
2015-02-06 09:57:01 +01:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2018-01-30 13:24:39 +01:00
|
|
|
if ((*bitmap = heap_alloc_zero(sizeof(**bitmap))))
|
2016-03-29 20:30:38 +02:00
|
|
|
{
|
2021-06-24 09:35:32 +02:00
|
|
|
d2d_bitmap_init(*bitmap, context, (ID3D11Resource *)texture, size, desc);
|
2016-03-29 20:30:38 +02:00
|
|
|
TRACE("Created bitmap %p.\n", *bitmap);
|
|
|
|
}
|
2021-06-21 09:57:48 +02:00
|
|
|
ID3D11Texture2D_Release(texture);
|
2015-02-06 09:56:59 +01:00
|
|
|
|
2016-03-29 20:30:38 +02:00
|
|
|
return *bitmap ? S_OK : E_OUTOFMEMORY;
|
2015-08-04 08:53:27 +02:00
|
|
|
}
|
|
|
|
|
2018-09-16 17:51:19 +02:00
|
|
|
HRESULT d2d_bitmap_create_shared(struct d2d_device_context *context, REFIID iid, void *data,
|
|
|
|
const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap)
|
2015-08-04 08:53:27 +02:00
|
|
|
{
|
2018-09-13 18:16:47 +02:00
|
|
|
D2D1_BITMAP_PROPERTIES1 d;
|
2016-10-10 16:12:39 +02:00
|
|
|
|
2015-08-04 08:53:27 +02:00
|
|
|
if (IsEqualGUID(iid, &IID_ID2D1Bitmap))
|
2015-02-06 09:56:59 +01:00
|
|
|
{
|
2015-08-04 08:53:27 +02:00
|
|
|
struct d2d_bitmap *src_impl = unsafe_impl_from_ID2D1Bitmap(data);
|
2021-06-24 09:35:31 +02:00
|
|
|
ID3D11Device *device;
|
2016-10-10 16:12:39 +02:00
|
|
|
HRESULT hr = S_OK;
|
2015-08-04 08:53:27 +02:00
|
|
|
|
2018-09-16 17:51:19 +02:00
|
|
|
if (src_impl->factory != context->factory)
|
2016-10-10 16:12:39 +02:00
|
|
|
{
|
|
|
|
hr = D2DERR_WRONG_FACTORY;
|
|
|
|
goto failed;
|
|
|
|
}
|
2015-08-04 08:53:27 +02:00
|
|
|
|
2021-06-28 09:17:37 +02:00
|
|
|
ID3D11Resource_GetDevice(src_impl->resource, &device);
|
2021-06-24 09:35:31 +02:00
|
|
|
ID3D11Device_Release(device);
|
2021-06-28 09:17:37 +02:00
|
|
|
if (device != (ID3D11Device *)context->d3d_device)
|
2016-10-10 16:12:39 +02:00
|
|
|
{
|
|
|
|
hr = D2DERR_UNSUPPORTED_OPERATION;
|
|
|
|
goto failed;
|
|
|
|
}
|
2015-08-04 08:53:27 +02:00
|
|
|
|
|
|
|
if (!desc)
|
|
|
|
{
|
|
|
|
d.pixelFormat = src_impl->format;
|
|
|
|
d.dpiX = src_impl->dpi_x;
|
|
|
|
d.dpiY = src_impl->dpi_y;
|
2018-09-13 18:16:47 +02:00
|
|
|
d.bitmapOptions = src_impl->options;
|
|
|
|
d.colorContext = NULL;
|
2015-08-04 08:53:27 +02:00
|
|
|
desc = &d;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!format_supported(&desc->pixelFormat))
|
|
|
|
{
|
|
|
|
WARN("Tried to create bitmap with unsupported format {%#x / %#x}.\n",
|
|
|
|
desc->pixelFormat.format, desc->pixelFormat.alphaMode);
|
2016-10-10 16:12:39 +02:00
|
|
|
hr = D2DERR_UNSUPPORTED_PIXEL_FORMAT;
|
|
|
|
goto failed;
|
2015-08-04 08:53:27 +02:00
|
|
|
}
|
|
|
|
|
2018-01-30 13:24:39 +01:00
|
|
|
if (!(*bitmap = heap_alloc_zero(sizeof(**bitmap))))
|
2016-10-10 16:12:39 +02:00
|
|
|
{
|
|
|
|
hr = E_OUTOFMEMORY;
|
|
|
|
goto failed;
|
|
|
|
}
|
2016-03-29 20:30:38 +02:00
|
|
|
|
2021-06-28 09:17:37 +02:00
|
|
|
d2d_bitmap_init(*bitmap, context, src_impl->resource, src_impl->pixel_size, desc);
|
2016-03-29 20:30:38 +02:00
|
|
|
TRACE("Created bitmap %p.\n", *bitmap);
|
2015-08-04 08:53:27 +02:00
|
|
|
|
2016-10-10 16:12:39 +02:00
|
|
|
failed:
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (IsEqualGUID(iid, &IID_IDXGISurface) || IsEqualGUID(iid, &IID_IDXGISurface1))
|
|
|
|
{
|
|
|
|
DXGI_SURFACE_DESC surface_desc;
|
|
|
|
IDXGISurface *surface = data;
|
2021-06-24 09:35:31 +02:00
|
|
|
ID3D11Resource *resource;
|
2016-10-10 16:12:39 +02:00
|
|
|
D2D1_SIZE_U pixel_size;
|
2021-06-24 09:35:31 +02:00
|
|
|
ID3D11Device *device;
|
2016-10-10 16:12:39 +02:00
|
|
|
HRESULT hr;
|
|
|
|
|
2021-06-24 09:35:31 +02:00
|
|
|
if (FAILED(IDXGISurface_QueryInterface(surface, &IID_ID3D11Resource, (void **)&resource)))
|
2016-10-10 16:12:39 +02:00
|
|
|
{
|
|
|
|
WARN("Failed to get d3d resource from dxgi surface.\n");
|
|
|
|
return E_FAIL;
|
|
|
|
}
|
|
|
|
|
2021-06-24 09:35:31 +02:00
|
|
|
ID3D11Resource_GetDevice(resource, &device);
|
|
|
|
ID3D11Device_Release(device);
|
2021-06-28 09:17:37 +02:00
|
|
|
if (device != (ID3D11Device *)context->d3d_device)
|
2021-06-24 09:35:31 +02:00
|
|
|
{
|
2021-06-24 09:35:32 +02:00
|
|
|
ID3D11Resource_Release(resource);
|
2016-10-10 16:12:39 +02:00
|
|
|
return D2DERR_UNSUPPORTED_OPERATION;
|
|
|
|
}
|
|
|
|
|
2018-01-30 13:24:39 +01:00
|
|
|
if (!(*bitmap = heap_alloc_zero(sizeof(**bitmap))))
|
2016-10-10 16:12:39 +02:00
|
|
|
{
|
2021-06-24 09:35:32 +02:00
|
|
|
ID3D11Resource_Release(resource);
|
2016-10-10 16:12:39 +02:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
|
2018-09-13 18:16:47 +02:00
|
|
|
|
|
|
|
if (FAILED(hr = IDXGISurface_GetDesc(surface, &surface_desc)))
|
|
|
|
{
|
2022-02-01 19:23:14 +01:00
|
|
|
WARN("Failed to get surface desc, hr %#lx.\n", hr);
|
2021-06-24 09:35:32 +02:00
|
|
|
ID3D11Resource_Release(resource);
|
2018-09-13 18:16:47 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!desc)
|
|
|
|
{
|
|
|
|
memset(&d, 0, sizeof(d));
|
|
|
|
d.pixelFormat.format = surface_desc.Format;
|
|
|
|
}
|
|
|
|
else
|
2018-09-26 02:34:48 +02:00
|
|
|
{
|
2018-09-13 18:16:47 +02:00
|
|
|
d = *desc;
|
2018-09-26 02:34:48 +02:00
|
|
|
if (d.pixelFormat.format == DXGI_FORMAT_UNKNOWN)
|
|
|
|
d.pixelFormat.format = surface_desc.Format;
|
|
|
|
}
|
2018-09-13 18:16:47 +02:00
|
|
|
|
2016-10-10 16:12:39 +02:00
|
|
|
if (d.dpiX == 0.0f || d.dpiY == 0.0f)
|
|
|
|
{
|
|
|
|
if (d.dpiX == 0.0f)
|
2018-09-16 17:51:19 +02:00
|
|
|
d.dpiX = context->desc.dpiX;
|
2016-10-10 16:12:39 +02:00
|
|
|
if (d.dpiY == 0.0f)
|
2018-09-16 17:51:19 +02:00
|
|
|
d.dpiY = context->desc.dpiY;
|
2016-10-10 16:12:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pixel_size.width = surface_desc.Width;
|
|
|
|
pixel_size.height = surface_desc.Height;
|
|
|
|
|
2021-06-24 09:35:32 +02:00
|
|
|
d2d_bitmap_init(*bitmap, context, resource, pixel_size, &d);
|
|
|
|
ID3D11Resource_Release(resource);
|
2016-10-10 16:12:39 +02:00
|
|
|
TRACE("Created bitmap %p.\n", *bitmap);
|
|
|
|
|
2015-08-04 08:53:27 +02:00
|
|
|
return S_OK;
|
2015-02-06 09:56:59 +01:00
|
|
|
}
|
2015-02-06 09:57:01 +01:00
|
|
|
|
2015-08-04 08:53:27 +02:00
|
|
|
WARN("Unhandled interface %s.\n", debugstr_guid(iid));
|
|
|
|
|
|
|
|
return E_INVALIDARG;
|
2015-02-06 09:57:01 +01:00
|
|
|
}
|
|
|
|
|
2018-09-16 17:51:19 +02:00
|
|
|
HRESULT d2d_bitmap_create_from_wic_bitmap(struct d2d_device_context *context, IWICBitmapSource *bitmap_source,
|
2018-09-13 18:16:47 +02:00
|
|
|
const D2D1_BITMAP_PROPERTIES1 *desc, struct d2d_bitmap **bitmap)
|
2016-03-29 20:30:38 +02:00
|
|
|
{
|
|
|
|
const D2D1_PIXEL_FORMAT *d2d_format;
|
2018-09-13 18:16:47 +02:00
|
|
|
D2D1_BITMAP_PROPERTIES1 bitmap_desc;
|
2016-03-29 20:30:38 +02:00
|
|
|
WICPixelFormatGUID wic_format;
|
|
|
|
unsigned int bpp, data_size;
|
|
|
|
D2D1_SIZE_U size;
|
|
|
|
unsigned int i;
|
|
|
|
WICRect rect;
|
|
|
|
UINT32 pitch;
|
|
|
|
HRESULT hr;
|
|
|
|
void *data;
|
|
|
|
|
|
|
|
static const struct
|
|
|
|
{
|
|
|
|
const WICPixelFormatGUID *wic;
|
|
|
|
D2D1_PIXEL_FORMAT d2d;
|
|
|
|
}
|
|
|
|
format_lookup[] =
|
|
|
|
{
|
|
|
|
{&GUID_WICPixelFormat32bppPBGRA, {DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED}},
|
2020-03-11 17:40:43 +01:00
|
|
|
{&GUID_WICPixelFormat32bppPRGBA, {DXGI_FORMAT_R8G8B8A8_UNORM, D2D1_ALPHA_MODE_PREMULTIPLIED}},
|
2016-03-29 20:30:38 +02:00
|
|
|
{&GUID_WICPixelFormat32bppBGR, {DXGI_FORMAT_B8G8R8A8_UNORM, D2D1_ALPHA_MODE_IGNORE}},
|
|
|
|
};
|
|
|
|
|
|
|
|
if (FAILED(hr = IWICBitmapSource_GetSize(bitmap_source, &size.width, &size.height)))
|
|
|
|
{
|
2022-02-01 19:23:14 +01:00
|
|
|
WARN("Failed to get bitmap size, hr %#lx.\n", hr);
|
2016-03-29 20:30:38 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!desc)
|
|
|
|
{
|
|
|
|
bitmap_desc.pixelFormat.format = DXGI_FORMAT_UNKNOWN;
|
|
|
|
bitmap_desc.pixelFormat.alphaMode = D2D1_ALPHA_MODE_UNKNOWN;
|
|
|
|
bitmap_desc.dpiX = 0.0f;
|
|
|
|
bitmap_desc.dpiY = 0.0f;
|
2018-09-13 18:16:47 +02:00
|
|
|
bitmap_desc.bitmapOptions = 0;
|
|
|
|
bitmap_desc.colorContext = NULL;
|
2016-03-29 20:30:38 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bitmap_desc = *desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (FAILED(hr = IWICBitmapSource_GetPixelFormat(bitmap_source, &wic_format)))
|
|
|
|
{
|
2022-02-01 19:23:14 +01:00
|
|
|
WARN("Failed to get bitmap format, hr %#lx.\n", hr);
|
2016-03-29 20:30:38 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-07-07 17:15:14 +02:00
|
|
|
for (i = 0, d2d_format = NULL; i < ARRAY_SIZE(format_lookup); ++i)
|
2016-03-29 20:30:38 +02:00
|
|
|
{
|
|
|
|
if (IsEqualGUID(&wic_format, format_lookup[i].wic))
|
|
|
|
{
|
|
|
|
d2d_format = &format_lookup[i].d2d;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!d2d_format)
|
|
|
|
{
|
|
|
|
WARN("Unsupported WIC bitmap format %s.\n", debugstr_guid(&wic_format));
|
|
|
|
return D2DERR_UNSUPPORTED_PIXEL_FORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bitmap_desc.pixelFormat.format == DXGI_FORMAT_UNKNOWN)
|
|
|
|
bitmap_desc.pixelFormat.format = d2d_format->format;
|
|
|
|
if (bitmap_desc.pixelFormat.alphaMode == D2D1_ALPHA_MODE_UNKNOWN)
|
|
|
|
bitmap_desc.pixelFormat.alphaMode = d2d_format->alphaMode;
|
|
|
|
|
|
|
|
switch (bitmap_desc.pixelFormat.format)
|
|
|
|
{
|
|
|
|
case DXGI_FORMAT_B8G8R8A8_UNORM:
|
2020-03-11 17:40:43 +01:00
|
|
|
case DXGI_FORMAT_R8G8B8A8_UNORM:
|
2016-03-29 20:30:38 +02:00
|
|
|
bpp = 4;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
FIXME("Unhandled format %#x.\n", bitmap_desc.pixelFormat.format);
|
|
|
|
return D2DERR_UNSUPPORTED_PIXEL_FORMAT;
|
|
|
|
}
|
|
|
|
|
|
|
|
pitch = ((bpp * size.width) + 15) & ~15;
|
2018-01-31 16:19:40 +01:00
|
|
|
if (pitch / bpp < size.width)
|
2016-03-29 20:30:38 +02:00
|
|
|
return E_OUTOFMEMORY;
|
2018-02-01 00:37:35 +01:00
|
|
|
if (!(data = heap_calloc(size.height, pitch)))
|
2018-01-31 16:19:40 +01:00
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
data_size = size.height * pitch;
|
2016-03-29 20:30:38 +02:00
|
|
|
|
|
|
|
rect.X = 0;
|
|
|
|
rect.Y = 0;
|
|
|
|
rect.Width = size.width;
|
|
|
|
rect.Height = size.height;
|
|
|
|
if (FAILED(hr = IWICBitmapSource_CopyPixels(bitmap_source, &rect, pitch, data_size, data)))
|
|
|
|
{
|
2022-02-01 19:23:14 +01:00
|
|
|
WARN("Failed to copy bitmap pixels, hr %#lx.\n", hr);
|
2018-01-30 13:24:39 +01:00
|
|
|
heap_free(data);
|
2016-03-29 20:30:38 +02:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2018-09-16 17:51:19 +02:00
|
|
|
hr = d2d_bitmap_create(context, size, data, pitch, &bitmap_desc, bitmap);
|
2016-03-29 20:30:38 +02:00
|
|
|
|
2018-01-30 13:24:39 +01:00
|
|
|
heap_free(data);
|
2016-03-29 20:30:38 +02:00
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2015-02-06 09:57:01 +01:00
|
|
|
struct d2d_bitmap *unsafe_impl_from_ID2D1Bitmap(ID2D1Bitmap *iface)
|
|
|
|
{
|
|
|
|
if (!iface)
|
|
|
|
return NULL;
|
2018-05-23 13:44:12 +02:00
|
|
|
assert(iface->lpVtbl == (ID2D1BitmapVtbl *)&d2d_bitmap_vtbl);
|
|
|
|
return CONTAINING_RECORD(iface, struct d2d_bitmap, ID2D1Bitmap1_iface);
|
2014-09-16 10:44:13 +02:00
|
|
|
}
|