2009-01-15 09:58:44 +01:00
|
|
|
/*
|
|
|
|
* Copyright 2009 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 "config.h"
|
|
|
|
|
|
|
|
#include "dxgi_private.h"
|
|
|
|
|
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(dxgi);
|
|
|
|
|
2009-01-19 10:39:06 +01:00
|
|
|
/* Inner IUnknown methods */
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2012-04-19 20:44:59 +02:00
|
|
|
static inline struct dxgi_surface *impl_from_IUnknown(IUnknown *iface)
|
2009-01-19 10:39:06 +01:00
|
|
|
{
|
2012-04-19 20:44:59 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct dxgi_surface, IUnknown_iface);
|
2009-01-19 10:39:06 +01:00
|
|
|
}
|
|
|
|
|
2012-04-19 20:44:59 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_surface_inner_QueryInterface(IUnknown *iface, REFIID riid, void **out)
|
2009-01-15 09:58:44 +01:00
|
|
|
{
|
2012-04-19 20:44:59 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IUnknown(iface);
|
2009-01-19 10:39:06 +01:00
|
|
|
|
2012-04-19 20:44:59 +02:00
|
|
|
TRACE("iface %p, riid %s, out %p.\n", iface, debugstr_guid(riid), out);
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
if (IsEqualGUID(riid, &IID_IDXGISurface1)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDXGISurface)
|
2009-01-15 09:58:44 +01:00
|
|
|
|| IsEqualGUID(riid, &IID_IDXGIDeviceSubObject)
|
|
|
|
|| IsEqualGUID(riid, &IID_IDXGIObject)
|
|
|
|
|| IsEqualGUID(riid, &IID_IUnknown))
|
|
|
|
{
|
2016-03-29 08:36:59 +02:00
|
|
|
IDXGISurface1_AddRef(&surface->IDXGISurface1_iface);
|
|
|
|
*out = &surface->IDXGISurface1_iface;
|
2009-01-15 09:58:44 +01:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
WARN("%s not implemented, returning E_NOINTERFACE\n", debugstr_guid(riid));
|
|
|
|
|
2012-04-19 20:44:59 +02:00
|
|
|
*out = NULL;
|
2009-01-15 09:58:44 +01:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:06 +01:00
|
|
|
static ULONG STDMETHODCALLTYPE dxgi_surface_inner_AddRef(IUnknown *iface)
|
2009-01-15 09:58:44 +01:00
|
|
|
{
|
2012-04-19 20:44:59 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IUnknown(iface);
|
|
|
|
ULONG refcount = InterlockedIncrement(&surface->refcount);
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2012-04-19 20:44:59 +02:00
|
|
|
TRACE("%p increasing refcount to %u.\n", surface, refcount);
|
2009-01-15 09:58:44 +01:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:06 +01:00
|
|
|
static ULONG STDMETHODCALLTYPE dxgi_surface_inner_Release(IUnknown *iface)
|
2009-01-15 09:58:44 +01:00
|
|
|
{
|
2012-04-19 20:44:59 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IUnknown(iface);
|
|
|
|
ULONG refcount = InterlockedDecrement(&surface->refcount);
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2012-04-19 20:44:59 +02:00
|
|
|
TRACE("%p decreasing refcount to %u.\n", surface, refcount);
|
2009-01-15 09:58:44 +01:00
|
|
|
|
|
|
|
if (!refcount)
|
2015-02-17 10:15:37 +01:00
|
|
|
{
|
|
|
|
wined3d_private_store_cleanup(&surface->private_store);
|
2018-02-06 00:34:19 +01:00
|
|
|
heap_free(surface);
|
2015-02-17 10:15:37 +01:00
|
|
|
}
|
2009-01-15 09:58:44 +01:00
|
|
|
|
|
|
|
return refcount;
|
|
|
|
}
|
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
static inline struct dxgi_surface *impl_from_IDXGISurface1(IDXGISurface1 *iface)
|
2011-06-07 10:11:55 +02:00
|
|
|
{
|
2016-03-29 08:36:59 +02:00
|
|
|
return CONTAINING_RECORD(iface, struct dxgi_surface, IDXGISurface1_iface);
|
2011-06-07 10:11:55 +02:00
|
|
|
}
|
|
|
|
|
2009-01-19 10:39:06 +01:00
|
|
|
/* IUnknown methods */
|
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_surface_QueryInterface(IDXGISurface1 *iface, REFIID riid,
|
2011-06-07 10:11:55 +02:00
|
|
|
void **object)
|
2009-01-19 10:39:06 +01:00
|
|
|
{
|
2018-08-29 12:53:39 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
2009-01-19 10:39:06 +01:00
|
|
|
TRACE("Forwarding to outer IUnknown\n");
|
2018-08-29 12:53:39 +02:00
|
|
|
return IUnknown_QueryInterface(surface->outer_unknown, riid, object);
|
2009-01-19 10:39:06 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
static ULONG STDMETHODCALLTYPE dxgi_surface_AddRef(IDXGISurface1 *iface)
|
2009-01-19 10:39:06 +01:00
|
|
|
{
|
2018-08-29 12:53:39 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
2009-01-19 10:39:06 +01:00
|
|
|
TRACE("Forwarding to outer IUnknown\n");
|
2018-08-29 12:53:39 +02:00
|
|
|
return IUnknown_AddRef(surface->outer_unknown);
|
2009-01-19 10:39:06 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
static ULONG STDMETHODCALLTYPE dxgi_surface_Release(IDXGISurface1 *iface)
|
2009-01-19 10:39:06 +01:00
|
|
|
{
|
2018-08-29 12:53:39 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
2009-01-19 10:39:06 +01:00
|
|
|
TRACE("Forwarding to outer IUnknown\n");
|
2018-08-29 12:53:39 +02:00
|
|
|
return IUnknown_Release(surface->outer_unknown);
|
2009-01-19 10:39:06 +01:00
|
|
|
}
|
|
|
|
|
2009-01-15 09:58:44 +01:00
|
|
|
/* IDXGIObject methods */
|
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_surface_SetPrivateData(IDXGISurface1 *iface,
|
2009-01-15 09:58:44 +01:00
|
|
|
REFGUID guid, UINT data_size, const void *data)
|
|
|
|
{
|
2016-03-29 08:36:59 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2015-02-17 10:15:37 +01:00
|
|
|
TRACE("iface %p, guid %s, data_size %u, data %p.\n", iface, debugstr_guid(guid), data_size, data);
|
|
|
|
|
|
|
|
return dxgi_set_private_data(&surface->private_store, guid, data_size, data);
|
2009-01-15 09:58:44 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_surface_SetPrivateDataInterface(IDXGISurface1 *iface,
|
2009-01-15 09:58:44 +01:00
|
|
|
REFGUID guid, const IUnknown *object)
|
|
|
|
{
|
2016-03-29 08:36:59 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2015-02-17 10:15:38 +01:00
|
|
|
TRACE("iface %p, guid %s, object %p.\n", iface, debugstr_guid(guid), object);
|
|
|
|
|
|
|
|
return dxgi_set_private_data_interface(&surface->private_store, guid, object);
|
2009-01-15 09:58:44 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_surface_GetPrivateData(IDXGISurface1 *iface,
|
2009-01-15 09:58:44 +01:00
|
|
|
REFGUID guid, UINT *data_size, void *data)
|
|
|
|
{
|
2016-03-29 08:36:59 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
2015-02-17 10:15:39 +01:00
|
|
|
|
|
|
|
TRACE("iface %p, guid %s, data_size %p, data %p.\n", iface, debugstr_guid(guid), data_size, data);
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2015-02-17 10:15:39 +01:00
|
|
|
return dxgi_get_private_data(&surface->private_store, guid, data_size, data);
|
2009-01-15 09:58:44 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_surface_GetParent(IDXGISurface1 *iface, REFIID riid, void **parent)
|
2009-01-15 09:58:44 +01:00
|
|
|
{
|
2018-08-29 12:53:39 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2009-12-07 11:08:40 +01:00
|
|
|
TRACE("iface %p, riid %s, parent %p.\n", iface, debugstr_guid(riid), parent);
|
|
|
|
|
2018-08-29 12:53:39 +02:00
|
|
|
return IDXGIDevice_QueryInterface(surface->device, riid, parent);
|
2009-01-15 09:58:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGIDeviceSubObject methods */
|
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_surface_GetDevice(IDXGISurface1 *iface, REFIID riid, void **device)
|
2009-01-15 09:58:44 +01:00
|
|
|
{
|
2018-08-29 12:53:39 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2009-12-07 11:08:39 +01:00
|
|
|
TRACE("iface %p, riid %s, device %p.\n", iface, debugstr_guid(riid), device);
|
|
|
|
|
2018-08-29 12:53:39 +02:00
|
|
|
return IDXGIDevice_QueryInterface(surface->device, riid, device);
|
2009-01-15 09:58:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* IDXGISurface methods */
|
2016-03-29 08:36:59 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_surface_GetDesc(IDXGISurface1 *iface, DXGI_SURFACE_DESC *desc)
|
2009-01-15 09:58:44 +01:00
|
|
|
{
|
2016-03-29 08:36:59 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
2015-08-06 00:21:57 +02:00
|
|
|
struct wined3d_resource_desc wined3d_desc;
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2014-07-22 08:44:20 +02:00
|
|
|
TRACE("iface %p, desc %p.\n", iface, desc);
|
|
|
|
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_lock();
|
2016-09-01 11:42:54 +02:00
|
|
|
wined3d_resource_get_desc(wined3d_texture_get_resource(surface->wined3d_texture), &wined3d_desc);
|
2015-09-17 01:10:14 +02:00
|
|
|
wined3d_mutex_unlock();
|
2015-08-06 00:21:57 +02:00
|
|
|
desc->Width = wined3d_desc.width;
|
|
|
|
desc->Height = wined3d_desc.height;
|
|
|
|
desc->Format = dxgi_format_from_wined3dformat(wined3d_desc.format);
|
|
|
|
dxgi_sample_desc_from_wined3d(&desc->SampleDesc, wined3d_desc.multisample_type, wined3d_desc.multisample_quality);
|
2014-07-22 08:44:20 +02:00
|
|
|
|
|
|
|
return S_OK;
|
2009-01-15 09:58:44 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_surface_Map(IDXGISurface1 *iface, DXGI_MAPPED_RECT *mapped_rect, UINT flags)
|
2009-01-15 09:58:44 +01:00
|
|
|
{
|
2018-09-03 18:45:37 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
|
|
|
struct wined3d_map_desc wined3d_map_desc;
|
|
|
|
DWORD wined3d_map_flags = 0;
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
TRACE("iface %p, mapped_rect %p, flags %#x.\n", iface, mapped_rect, flags);
|
|
|
|
|
|
|
|
if (flags & DXGI_MAP_READ)
|
|
|
|
wined3d_map_flags |= WINED3D_MAP_READ;
|
|
|
|
if (flags & DXGI_MAP_WRITE)
|
|
|
|
wined3d_map_flags |= WINED3D_MAP_WRITE;
|
|
|
|
if (flags & DXGI_MAP_DISCARD)
|
|
|
|
wined3d_map_flags |= WINED3D_MAP_DISCARD;
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2018-09-03 18:45:37 +02:00
|
|
|
if (SUCCEEDED(hr = wined3d_resource_map(wined3d_texture_get_resource(surface->wined3d_texture), 0,
|
|
|
|
&wined3d_map_desc, NULL, wined3d_map_flags)))
|
|
|
|
{
|
|
|
|
mapped_rect->Pitch = wined3d_map_desc.row_pitch;
|
|
|
|
mapped_rect->pBits = wined3d_map_desc.data;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2009-01-15 09:58:44 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_surface_Unmap(IDXGISurface1 *iface)
|
2009-01-15 09:58:44 +01:00
|
|
|
{
|
2018-09-03 18:45:37 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
2009-01-15 09:58:44 +01:00
|
|
|
|
2018-09-03 18:45:37 +02:00
|
|
|
TRACE("iface %p.\n", iface);
|
|
|
|
wined3d_resource_unmap(wined3d_texture_get_resource(surface->wined3d_texture), 0);
|
|
|
|
return S_OK;
|
2009-01-15 09:58:44 +01:00
|
|
|
}
|
|
|
|
|
2016-03-29 08:36:59 +02:00
|
|
|
/* IDXGISurface1 methods */
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_surface_GetDC(IDXGISurface1 *iface, BOOL discard, HDC *hdc)
|
|
|
|
{
|
2016-09-08 12:26:52 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
|
|
|
HRESULT hr;
|
2016-03-29 08:36:59 +02:00
|
|
|
|
2016-09-08 12:26:52 +02:00
|
|
|
FIXME("iface %p, discard %d, hdc %p semi-stub!\n", iface, discard, hdc);
|
|
|
|
|
|
|
|
if (!hdc)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
|
|
|
hr = wined3d_texture_get_dc(surface->wined3d_texture, 0, hdc);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr))
|
|
|
|
surface->dc = *hdc;
|
|
|
|
|
|
|
|
return hr;
|
2016-03-29 08:36:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static HRESULT STDMETHODCALLTYPE dxgi_surface_ReleaseDC(IDXGISurface1 *iface, RECT *dirty_rect)
|
|
|
|
{
|
2016-09-08 12:26:52 +02:00
|
|
|
struct dxgi_surface *surface = impl_from_IDXGISurface1(iface);
|
|
|
|
HRESULT hr;
|
2016-03-29 08:36:59 +02:00
|
|
|
|
2016-09-08 12:26:52 +02:00
|
|
|
TRACE("iface %p, rect %s\n", iface, wine_dbgstr_rect(dirty_rect));
|
|
|
|
|
|
|
|
if (!IsRectEmpty(dirty_rect))
|
|
|
|
FIXME("dirty rectangle is ignored.\n");
|
|
|
|
|
|
|
|
wined3d_mutex_lock();
|
|
|
|
hr = wined3d_texture_release_dc(surface->wined3d_texture, 0, surface->dc);
|
|
|
|
wined3d_mutex_unlock();
|
|
|
|
|
|
|
|
return hr;
|
2016-03-29 08:36:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct IDXGISurface1Vtbl dxgi_surface_vtbl =
|
2009-01-15 09:58:44 +01:00
|
|
|
{
|
|
|
|
/* IUnknown methods */
|
|
|
|
dxgi_surface_QueryInterface,
|
|
|
|
dxgi_surface_AddRef,
|
|
|
|
dxgi_surface_Release,
|
|
|
|
/* IDXGIObject methods */
|
|
|
|
dxgi_surface_SetPrivateData,
|
|
|
|
dxgi_surface_SetPrivateDataInterface,
|
|
|
|
dxgi_surface_GetPrivateData,
|
|
|
|
dxgi_surface_GetParent,
|
|
|
|
/* IDXGIDeviceSubObject methods */
|
|
|
|
dxgi_surface_GetDevice,
|
|
|
|
/* IDXGISurface methods */
|
|
|
|
dxgi_surface_GetDesc,
|
|
|
|
dxgi_surface_Map,
|
|
|
|
dxgi_surface_Unmap,
|
2016-03-29 08:36:59 +02:00
|
|
|
/* IDXGISurface1 methods */
|
|
|
|
dxgi_surface_GetDC,
|
|
|
|
dxgi_surface_ReleaseDC,
|
2009-01-15 09:58:44 +01:00
|
|
|
};
|
2009-01-19 10:39:06 +01:00
|
|
|
|
2009-12-07 11:08:38 +01:00
|
|
|
static const struct IUnknownVtbl dxgi_surface_inner_unknown_vtbl =
|
2009-01-19 10:39:06 +01:00
|
|
|
{
|
|
|
|
/* IUnknown methods */
|
|
|
|
dxgi_surface_inner_QueryInterface,
|
|
|
|
dxgi_surface_inner_AddRef,
|
|
|
|
dxgi_surface_inner_Release,
|
|
|
|
};
|
2009-12-07 11:08:38 +01:00
|
|
|
|
2014-07-22 08:44:20 +02:00
|
|
|
HRESULT dxgi_surface_init(struct dxgi_surface *surface, IDXGIDevice *device,
|
2016-09-01 11:42:54 +02:00
|
|
|
IUnknown *outer, struct wined3d_texture *wined3d_texture)
|
2009-12-07 11:08:38 +01:00
|
|
|
{
|
2016-03-29 08:36:59 +02:00
|
|
|
surface->IDXGISurface1_iface.lpVtbl = &dxgi_surface_vtbl;
|
2012-04-19 20:44:59 +02:00
|
|
|
surface->IUnknown_iface.lpVtbl = &dxgi_surface_inner_unknown_vtbl;
|
2009-12-07 11:08:38 +01:00
|
|
|
surface->refcount = 1;
|
2015-02-17 10:15:37 +01:00
|
|
|
wined3d_private_store_init(&surface->private_store);
|
2012-04-19 20:44:59 +02:00
|
|
|
surface->outer_unknown = outer ? outer : &surface->IUnknown_iface;
|
2009-12-07 11:08:39 +01:00
|
|
|
surface->device = device;
|
2016-09-01 11:42:54 +02:00
|
|
|
surface->wined3d_texture = wined3d_texture;
|
2016-09-08 12:26:52 +02:00
|
|
|
surface->dc = NULL;
|
2009-12-07 11:08:38 +01:00
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|