2017-10-11 03:09:04 +02:00
|
|
|
#include <cmath>
|
|
|
|
#include <cstring>
|
|
|
|
#include <cstdlib>
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
#include "com_private_data.h"
|
2017-10-11 03:09:04 +02:00
|
|
|
|
|
|
|
namespace dxvk {
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
ComPrivateDataEntry::ComPrivateDataEntry() { }
|
|
|
|
ComPrivateDataEntry::ComPrivateDataEntry(
|
2017-10-11 03:09:04 +02:00
|
|
|
REFGUID guid,
|
|
|
|
UINT size,
|
|
|
|
const void* data)
|
|
|
|
: m_guid(guid),
|
|
|
|
m_size(size),
|
|
|
|
m_data(std::malloc(size)) {
|
|
|
|
std::memcpy(m_data, data, size);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
ComPrivateDataEntry::ComPrivateDataEntry(
|
2017-10-11 03:09:04 +02:00
|
|
|
REFGUID guid,
|
|
|
|
const IUnknown* iface)
|
|
|
|
: m_guid (guid),
|
|
|
|
m_iface (const_cast<IUnknown*>(iface)) {
|
|
|
|
m_iface->AddRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
ComPrivateDataEntry::~ComPrivateDataEntry() {
|
2017-10-11 03:09:04 +02:00
|
|
|
this->destroy();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
ComPrivateDataEntry::ComPrivateDataEntry(ComPrivateDataEntry&& other)
|
2017-10-11 03:09:04 +02:00
|
|
|
: m_guid (other.m_guid),
|
|
|
|
m_size (other.m_size),
|
|
|
|
m_data (other.m_data),
|
|
|
|
m_iface (other.m_iface) {
|
|
|
|
other.m_guid = __uuidof(IUnknown);
|
|
|
|
other.m_size = 0;
|
|
|
|
other.m_data = nullptr;
|
|
|
|
other.m_iface = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
ComPrivateDataEntry& ComPrivateDataEntry::operator = (ComPrivateDataEntry&& other) {
|
2017-10-11 03:09:04 +02:00
|
|
|
this->destroy();
|
|
|
|
this->m_guid = other.m_guid;
|
|
|
|
this->m_size = other.m_size;
|
|
|
|
this->m_data = other.m_data;
|
|
|
|
this->m_iface = other.m_iface;
|
|
|
|
|
|
|
|
other.m_guid = __uuidof(IUnknown);
|
|
|
|
other.m_size = 0;
|
|
|
|
other.m_data = nullptr;
|
|
|
|
other.m_iface = nullptr;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
HRESULT ComPrivateDataEntry::get(UINT& size, void* data) const {
|
2017-10-11 03:09:04 +02:00
|
|
|
if (size != 0 && data == nullptr)
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
|
|
|
|
const UINT minSize = m_iface != nullptr
|
|
|
|
? sizeof(IUnknown*)
|
|
|
|
: m_size;
|
|
|
|
|
|
|
|
const HRESULT result = size < minSize
|
|
|
|
? DXGI_ERROR_MORE_DATA
|
|
|
|
: S_OK;
|
|
|
|
|
|
|
|
if (size >= minSize) {
|
|
|
|
if (m_iface != nullptr) {
|
|
|
|
m_iface->AddRef();
|
|
|
|
std::memcpy(data, &m_iface, minSize);
|
|
|
|
} else {
|
|
|
|
std::memcpy(data, m_data, minSize);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
size = minSize;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
void ComPrivateDataEntry::destroy() {
|
2017-10-11 03:09:04 +02:00
|
|
|
if (m_data != nullptr)
|
|
|
|
std::free(m_data);
|
|
|
|
if (m_iface != nullptr)
|
|
|
|
m_iface->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
HRESULT ComPrivateData::setData(
|
2017-10-11 03:09:04 +02:00
|
|
|
REFGUID guid,
|
|
|
|
UINT size,
|
|
|
|
const void* data) {
|
2017-10-11 09:41:19 +02:00
|
|
|
this->insertEntry(ComPrivateDataEntry(guid, size, data));
|
2017-10-11 03:09:04 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
HRESULT ComPrivateData::setInterface(
|
2017-10-11 03:09:04 +02:00
|
|
|
REFGUID guid,
|
|
|
|
const IUnknown* iface) {
|
2017-10-11 09:41:19 +02:00
|
|
|
this->insertEntry(ComPrivateDataEntry(guid, iface));
|
2017-10-11 03:09:04 +02:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
HRESULT ComPrivateData::getData(
|
2017-10-11 03:09:04 +02:00
|
|
|
REFGUID guid,
|
|
|
|
UINT* size,
|
|
|
|
void* data) {
|
|
|
|
if (size == nullptr)
|
|
|
|
return DXGI_ERROR_INVALID_CALL;
|
|
|
|
|
|
|
|
auto entry = this->findEntry(guid);
|
|
|
|
|
|
|
|
if (entry == nullptr)
|
|
|
|
return DXGI_ERROR_NOT_FOUND;
|
|
|
|
|
|
|
|
return entry->get(*size, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
ComPrivateDataEntry* ComPrivateData::findEntry(REFGUID guid) {
|
|
|
|
for (ComPrivateDataEntry& e : m_entries) {
|
2017-10-11 03:09:04 +02:00
|
|
|
if (e.hasGuid(guid))
|
|
|
|
return &e;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-10-11 09:41:19 +02:00
|
|
|
void ComPrivateData::insertEntry(ComPrivateDataEntry&& entry) {
|
|
|
|
ComPrivateDataEntry srcEntry = std::move(entry);
|
|
|
|
ComPrivateDataEntry* dstEntry = this->findEntry(srcEntry.guid());
|
2017-10-11 03:09:04 +02:00
|
|
|
|
|
|
|
if (dstEntry != nullptr)
|
|
|
|
*dstEntry = std::move(srcEntry);
|
|
|
|
else
|
|
|
|
m_entries.push_back(std::move(srcEntry));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|