Wine-devel
Threads by month
- ----- 2026 -----
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2003 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2002 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2001 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
May 2019
- 96 participants
- 789 discussions
07 May '19
Signed-off-by: Dmitry Timoshkov <dmitry(a)baikal.ru>
---
dlls/mshtml/htmlstylesheet.c | 187 ++++++++++++++++++++++++++++++++++-
dlls/mshtml/mshtml_private.h | 2 +
2 files changed, 187 insertions(+), 2 deletions(-)
diff --git a/dlls/mshtml/htmlstylesheet.c b/dlls/mshtml/htmlstylesheet.c
index b0e024cfed..19289eb2e9 100644
--- a/dlls/mshtml/htmlstylesheet.c
+++ b/dlls/mshtml/htmlstylesheet.c
@@ -59,6 +59,176 @@ struct HTMLStyleSheetRulesCollection {
nsIDOMCSSRuleList *nslist;
};
+struct HTMLStyleSheetRule {
+ DispatchEx dispex;
+ IHTMLStyleSheetRule IHTMLStyleSheetRule_iface;
+
+ LONG ref;
+
+ nsIDOMCSSRule *nsstylesheetrule;
+};
+
+static inline HTMLStyleSheetRule *impl_from_IHTMLStyleSheetRule(IHTMLStyleSheetRule *iface)
+{
+ return CONTAINING_RECORD(iface, HTMLStyleSheetRule, IHTMLStyleSheetRule_iface);
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_QueryInterface(IHTMLStyleSheetRule *iface,
+ REFIID riid, void **ppv)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+
+ TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
+
+ if (IsEqualGUID(&IID_IUnknown, riid))
+ *ppv = &This->IHTMLStyleSheetRule_iface;
+ else if (IsEqualGUID(&IID_IHTMLStyleSheetRule, riid))
+ *ppv = &This->IHTMLStyleSheetRule_iface;
+ else if (dispex_query_interface(&This->dispex, riid, ppv))
+ return *ppv ? S_OK : E_NOINTERFACE;
+ else
+ {
+ *ppv = NULL;
+ FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
+ return E_NOINTERFACE;
+ }
+
+ IUnknown_AddRef((IUnknown *)*ppv);
+ return S_OK;
+}
+
+static ULONG WINAPI HTMLStyleSheetRule_AddRef(IHTMLStyleSheetRule *iface)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ LONG ref = InterlockedIncrement(&This->ref);
+
+ TRACE("(%p) ref=%d\n", This, ref);
+
+ return ref;
+}
+
+static ULONG WINAPI HTMLStyleSheetRule_Release(IHTMLStyleSheetRule *iface)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ LONG ref = InterlockedDecrement(&This->ref);
+
+ TRACE("(%p) ref=%d\n", This, ref);
+
+ if(!ref) {
+ release_dispex(&This->dispex);
+ if(This->nsstylesheetrule)
+ nsIDOMCSSRule_Release(This->nsstylesheetrule);
+ heap_free(This);
+ }
+
+ return ref;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_GetTypeInfoCount(
+ IHTMLStyleSheetRule *iface, UINT *pctinfo)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_GetTypeInfo(IHTMLStyleSheetRule *iface,
+ UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_GetIDsOfNames(IHTMLStyleSheetRule *iface,
+ REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
+ lcid, rgDispId);
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_Invoke(IHTMLStyleSheetRule *iface,
+ DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
+ VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
+ pDispParams, pVarResult, pExcepInfo, puArgErr);
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_put_selectorText(IHTMLStyleSheetRule *iface, BSTR v)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ FIXME("(%p)->(%s)\n", This, debugstr_w(v));
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_get_selectorText(IHTMLStyleSheetRule *iface, BSTR *p)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ FIXME("(%p)->(%p)\n", This, p);
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_get_style(IHTMLStyleSheetRule *iface, IHTMLRuleStyle **p)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ FIXME("(%p)->(%p)\n", This, p);
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_get_readOnly(IHTMLStyleSheetRule *iface, VARIANT_BOOL *p)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ FIXME("(%p)->(%p)\n", This, p);
+ return E_NOTIMPL;
+}
+
+static const IHTMLStyleSheetRuleVtbl HTMLStyleSheetRuleVtbl = {
+ HTMLStyleSheetRule_QueryInterface,
+ HTMLStyleSheetRule_AddRef,
+ HTMLStyleSheetRule_Release,
+ HTMLStyleSheetRule_GetTypeInfoCount,
+ HTMLStyleSheetRule_GetTypeInfo,
+ HTMLStyleSheetRule_GetIDsOfNames,
+ HTMLStyleSheetRule_Invoke,
+ HTMLStyleSheetRule_put_selectorText,
+ HTMLStyleSheetRule_get_selectorText,
+ HTMLStyleSheetRule_get_style,
+ HTMLStyleSheetRule_get_readOnly
+};
+
+static const tid_t HTMLStyleSheetRule_iface_tids[] = {
+ IHTMLStyleSheetRule_tid,
+ 0
+};
+static dispex_static_data_t HTMLStyleSheetRule_dispex = {
+ NULL,
+ DispHTMLStyleSheetRule_tid,
+ HTMLStyleSheetRule_iface_tids
+};
+
+static IHTMLStyleSheetRule *HTMLStyleSheetRule_Create(nsIDOMCSSRule *nsstylesheetrule)
+{
+ HTMLStyleSheetRule *ret = heap_alloc(sizeof(*ret));
+ nsresult nsres;
+
+ ret->IHTMLStyleSheetRule_iface.lpVtbl = &HTMLStyleSheetRuleVtbl;
+ ret->ref = 1;
+ ret->nsstylesheetrule = NULL;
+
+ init_dispex(&ret->dispex, (IUnknown *)&ret->IHTMLStyleSheetRule_iface, &HTMLStyleSheetRule_dispex);
+
+ if (nsstylesheetrule)
+ {
+ nsres = nsIDOMCSSRule_QueryInterface(nsstylesheetrule, &IID_nsIDOMCSSRule,
+ (void **)&ret->nsstylesheetrule);
+ if (NS_FAILED(nsres))
+ ERR("Could not get nsIDOMCSSRule interface: %08x\n", nsres);
+ }
+
+ return &ret->IHTMLStyleSheetRule_iface;
+}
+
static inline HTMLStyleSheetRulesCollection *impl_from_IHTMLStyleSheetRulesCollection(IHTMLStyleSheetRulesCollection *iface)
{
return CONTAINING_RECORD(iface, HTMLStyleSheetRulesCollection, IHTMLStyleSheetRulesCollection_iface);
@@ -169,8 +339,21 @@ static HRESULT WINAPI HTMLStyleSheetRulesCollection_item(IHTMLStyleSheetRulesCol
LONG index, IHTMLStyleSheetRule **ppHTMLStyleSheetRule)
{
HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
- FIXME("(%p)->(%d %p)\n", This, index, ppHTMLStyleSheetRule);
- return E_NOTIMPL;
+ nsIDOMCSSRule *nsstylesheetrule;
+ nsresult nsres;
+
+ TRACE("(%p)->(%d %p)\n", This, index, ppHTMLStyleSheetRule);
+
+ nsres = nsIDOMCSSRuleList_Item(This->nslist, index, &nsstylesheetrule);
+ if (NS_FAILED(nsres) || !nsstylesheetrule)
+ {
+ WARN("Item failed: %08x\n", nsres);
+ *ppHTMLStyleSheetRule = NULL;
+ return E_INVALIDARG;
+ }
+
+ *ppHTMLStyleSheetRule = HTMLStyleSheetRule_Create(nsstylesheetrule);
+ return S_OK;
}
static const IHTMLStyleSheetRulesCollectionVtbl HTMLStyleSheetRulesCollectionVtbl = {
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index f4bbe76ff0..5b94d075cb 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -121,6 +121,7 @@ typedef struct EventTarget EventTarget;
XDIID(DispHTMLStyle) \
XDIID(DispHTMLStyleElement) \
XDIID(DispHTMLStyleSheet) \
+ XDIID(DispHTMLStyleSheetRule) \
XDIID(DispHTMLStyleSheetRulesCollection) \
XDIID(DispHTMLStyleSheetsCollection) \
XDIID(DispHTMLTable) \
@@ -230,6 +231,7 @@ typedef struct EventTarget EventTarget;
XIID(IHTMLStyle6) \
XIID(IHTMLStyleElement) \
XIID(IHTMLStyleSheet) \
+ XIID(IHTMLStyleSheetRule) \
XIID(IHTMLStyleSheetRulesCollection) \
XIID(IHTMLStyleSheetsCollection) \
XIID(IHTMLTable) \
--
2.20.1
2
1
07 May '19
Signed-off-by: Dmitry Timoshkov <dmitry(a)baikal.ru>
---
dlls/mshtml/htmlstylesheet.c | 188 ++++++++++++++++++++++++++++++++++-
dlls/mshtml/mshtml_private.h | 2 +
2 files changed, 188 insertions(+), 2 deletions(-)
diff --git a/dlls/mshtml/htmlstylesheet.c b/dlls/mshtml/htmlstylesheet.c
index b0e024cfed..e2e08a7eef 100644
--- a/dlls/mshtml/htmlstylesheet.c
+++ b/dlls/mshtml/htmlstylesheet.c
@@ -59,6 +59,176 @@ struct HTMLStyleSheetRulesCollection {
nsIDOMCSSRuleList *nslist;
};
+struct HTMLStyleSheetRule {
+ DispatchEx dispex;
+ IHTMLStyleSheetRule IHTMLStyleSheetRule_iface;
+
+ LONG ref;
+
+ nsIDOMCSSRule *nsstylesheetrule;
+};
+
+static inline HTMLStyleSheetRule *impl_from_IHTMLStyleSheetRule(IHTMLStyleSheetRule *iface)
+{
+ return CONTAINING_RECORD(iface, HTMLStyleSheetRule, IHTMLStyleSheetRule_iface);
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_QueryInterface(IHTMLStyleSheetRule *iface,
+ REFIID riid, void **ppv)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+
+ TRACE("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
+
+ if (IsEqualGUID(&IID_IUnknown, riid))
+ *ppv = &This->IHTMLStyleSheetRule_iface;
+ else if (IsEqualGUID(&IID_IHTMLStyleSheetRule, riid))
+ *ppv = &This->IHTMLStyleSheetRule_iface;
+ else if (dispex_query_interface(&This->dispex, riid, ppv))
+ return *ppv ? S_OK : E_NOINTERFACE;
+ else
+ {
+ *ppv = NULL;
+ FIXME("(%p)->(%s %p)\n", This, debugstr_mshtml_guid(riid), ppv);
+ return E_NOINTERFACE;
+ }
+
+ IUnknown_AddRef((IUnknown *)*ppv);
+ return S_OK;
+}
+
+static ULONG WINAPI HTMLStyleSheetRule_AddRef(IHTMLStyleSheetRule *iface)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ LONG ref = InterlockedIncrement(&This->ref);
+
+ TRACE("(%p) ref=%d\n", This, ref);
+
+ return ref;
+}
+
+static ULONG WINAPI HTMLStyleSheetRule_Release(IHTMLStyleSheetRule *iface)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ LONG ref = InterlockedDecrement(&This->ref);
+
+ TRACE("(%p) ref=%d\n", This, ref);
+
+ if(!ref) {
+ release_dispex(&This->dispex);
+ if(This->nsstylesheetrule)
+ nsIDOMCSSRule_Release(This->nsstylesheetrule);
+ heap_free(This);
+ }
+
+ return ref;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_GetTypeInfoCount(
+ IHTMLStyleSheetRule *iface, UINT *pctinfo)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ return IDispatchEx_GetTypeInfoCount(&This->dispex.IDispatchEx_iface, pctinfo);
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_GetTypeInfo(IHTMLStyleSheetRule *iface,
+ UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ return IDispatchEx_GetTypeInfo(&This->dispex.IDispatchEx_iface, iTInfo, lcid, ppTInfo);
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_GetIDsOfNames(IHTMLStyleSheetRule *iface,
+ REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ return IDispatchEx_GetIDsOfNames(&This->dispex.IDispatchEx_iface, riid, rgszNames, cNames,
+ lcid, rgDispId);
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_Invoke(IHTMLStyleSheetRule *iface,
+ DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams,
+ VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ return IDispatchEx_Invoke(&This->dispex.IDispatchEx_iface, dispIdMember, riid, lcid, wFlags,
+ pDispParams, pVarResult, pExcepInfo, puArgErr);
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_put_selectorText(IHTMLStyleSheetRule *iface, BSTR v)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ FIXME("(%p)->(%s)\n", This, debugstr_w(v));
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_get_selectorText(IHTMLStyleSheetRule *iface, BSTR *p)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ FIXME("(%p)->(%p)\n", This, p);
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_get_style(IHTMLStyleSheetRule *iface, IHTMLRuleStyle **p)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ FIXME("(%p)->(%p)\n", This, p);
+ return E_NOTIMPL;
+}
+
+static HRESULT WINAPI HTMLStyleSheetRule_get_readOnly(IHTMLStyleSheetRule *iface, VARIANT_BOOL *p)
+{
+ HTMLStyleSheetRule *This = impl_from_IHTMLStyleSheetRule(iface);
+ FIXME("(%p)->(%p)\n", This, p);
+ return E_NOTIMPL;
+}
+
+static const IHTMLStyleSheetRuleVtbl HTMLStyleSheetRuleVtbl = {
+ HTMLStyleSheetRule_QueryInterface,
+ HTMLStyleSheetRule_AddRef,
+ HTMLStyleSheetRule_Release,
+ HTMLStyleSheetRule_GetTypeInfoCount,
+ HTMLStyleSheetRule_GetTypeInfo,
+ HTMLStyleSheetRule_GetIDsOfNames,
+ HTMLStyleSheetRule_Invoke,
+ HTMLStyleSheetRule_put_selectorText,
+ HTMLStyleSheetRule_get_selectorText,
+ HTMLStyleSheetRule_get_style,
+ HTMLStyleSheetRule_get_readOnly
+};
+
+static const tid_t HTMLStyleSheetRule_iface_tids[] = {
+ IHTMLStyleSheetRule_tid,
+ 0
+};
+static dispex_static_data_t HTMLStyleSheetRule_dispex = {
+ NULL,
+ DispHTMLStyleSheetRule_tid,
+ HTMLStyleSheetRule_iface_tids
+};
+
+static IHTMLStyleSheetRule *HTMLStyleSheetRule_Create(nsIDOMCSSRule *nsstylesheetrule)
+{
+ HTMLStyleSheetRule *ret = heap_alloc(sizeof(*ret));
+ nsresult nsres;
+
+ ret->IHTMLStyleSheetRule_iface.lpVtbl = &HTMLStyleSheetRuleVtbl;
+ ret->ref = 1;
+ ret->nsstylesheetrule = NULL;
+
+ init_dispex(&ret->dispex, (IUnknown *)&ret->IHTMLStyleSheetRule_iface, &HTMLStyleSheetRule_dispex);
+
+ if (nsstylesheetrule)
+ {
+ nsres = nsIDOMCSSRule_QueryInterface(nsstylesheetrule, &IID_nsIDOMCSSRule,
+ (void **)&ret->nsstylesheetrule);
+ if (NS_FAILED(nsres))
+ ERR("Could not get nsIDOMCSSRule interface: %08x\n", nsres);
+ }
+
+ return &ret->IHTMLStyleSheetRule_iface;
+}
+
static inline HTMLStyleSheetRulesCollection *impl_from_IHTMLStyleSheetRulesCollection(IHTMLStyleSheetRulesCollection *iface)
{
return CONTAINING_RECORD(iface, HTMLStyleSheetRulesCollection, IHTMLStyleSheetRulesCollection_iface);
@@ -169,8 +339,22 @@ static HRESULT WINAPI HTMLStyleSheetRulesCollection_item(IHTMLStyleSheetRulesCol
LONG index, IHTMLStyleSheetRule **ppHTMLStyleSheetRule)
{
HTMLStyleSheetRulesCollection *This = impl_from_IHTMLStyleSheetRulesCollection(iface);
- FIXME("(%p)->(%d %p)\n", This, index, ppHTMLStyleSheetRule);
- return E_NOTIMPL;
+ nsIDOMCSSRule *nsstylesheetrule;
+ nsresult nsres;
+
+ TRACE("(%p)->(%d %p)\n", This, index, ppHTMLStyleSheetRule);
+
+ nsres = nsIDOMCSSRuleList_Item(This->nslist, index, &nsstylesheetrule);
+ if (NS_FAILED(nsres) || !nsstylesheetrule)
+ {
+ WARN("Item failed: %08x\n", nsres);
+ /* The function returns S_OK even if the element is not found */
+ *ppHTMLStyleSheetRule = NULL;
+ }
+ else
+ *ppHTMLStyleSheetRule = HTMLStyleSheetRule_Create(nsstylesheetrule);
+
+ return S_OK;
}
static const IHTMLStyleSheetRulesCollectionVtbl HTMLStyleSheetRulesCollectionVtbl = {
diff --git a/dlls/mshtml/mshtml_private.h b/dlls/mshtml/mshtml_private.h
index f4bbe76ff0..5b94d075cb 100644
--- a/dlls/mshtml/mshtml_private.h
+++ b/dlls/mshtml/mshtml_private.h
@@ -121,6 +121,7 @@ typedef struct EventTarget EventTarget;
XDIID(DispHTMLStyle) \
XDIID(DispHTMLStyleElement) \
XDIID(DispHTMLStyleSheet) \
+ XDIID(DispHTMLStyleSheetRule) \
XDIID(DispHTMLStyleSheetRulesCollection) \
XDIID(DispHTMLStyleSheetsCollection) \
XDIID(DispHTMLTable) \
@@ -230,6 +231,7 @@ typedef struct EventTarget EventTarget;
XIID(IHTMLStyle6) \
XIID(IHTMLStyleElement) \
XIID(IHTMLStyleSheet) \
+ XIID(IHTMLStyleSheetRule) \
XIID(IHTMLStyleSheetRulesCollection) \
XIID(IHTMLStyleSheetsCollection) \
XIID(IHTMLTable) \
--
2.20.1
2
2
[PATCH v3 1/2] mspatcha: Implement ApplyPatchToFile and related functions.
by Conor McCarthy 07 May '19
by Conor McCarthy 07 May '19
07 May '19
This can patch non-executables and 64-bit executable files, but patching of 32-bit executables
is not supported. They are subject to special processing which alters PE relocations to match
with those in the old file to improve compression. To reverse this, the meaning of the decoding
data must be interpreted. Details, including where to find that data in the patch file, are
included in pa19.c. Interleaved decompression of large files is also not supported.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=12501
Signed-off-by: Conor McCarthy <conor.mccarthy.444(a)gmail.com>
---
dlls/mspatcha/Makefile.in | 4 +-
dlls/mspatcha/lzxd_dec.c | 776 ++++++++++++++++++++++++++++++
dlls/mspatcha/lzxd_dec.h | 27 ++
dlls/mspatcha/mspatcha.spec | 28 +-
dlls/mspatcha/mspatcha_main.c | 247 ++++++++--
dlls/mspatcha/pa19.c | 1060 +++++++++++++++++++++++++++++++++++++++++
dlls/mspatcha/pa19.h | 52 ++
include/patchapi.h | 73 +++
8 files changed, 2223 insertions(+), 44 deletions(-)
create mode 100755 dlls/mspatcha/lzxd_dec.c
create mode 100755 dlls/mspatcha/lzxd_dec.h
create mode 100755 dlls/mspatcha/pa19.c
create mode 100755 dlls/mspatcha/pa19.h
diff --git a/dlls/mspatcha/Makefile.in b/dlls/mspatcha/Makefile.in
index bd0da7d..34cf719 100644
--- a/dlls/mspatcha/Makefile.in
+++ b/dlls/mspatcha/Makefile.in
@@ -2,6 +2,8 @@ MODULE = mspatcha.dll
IMPORTLIB = mspatcha
C_SRCS = \
- mspatcha_main.c
+ mspatcha_main.c \
+ pa19.c \
+ lzxd_dec.c
RC_SRCS = version.rc
diff --git a/dlls/mspatcha/lzxd_dec.c b/dlls/mspatcha/lzxd_dec.c
new file mode 100755
index 0000000..b391467
--- /dev/null
+++ b/dlls/mspatcha/lzxd_dec.c
@@ -0,0 +1,776 @@
+/*
+ * LZXD decoder
+ *
+ * Copyright 2019 Conor McCarthy
+ *
+ * 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
+ *
+ * TODO
+ * - Implememnt interleaved decoding
+ */
+
+#include "config.h"
+
+#include <stdarg.h>
+#include <stdlib.h>
+#include <assert.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wine/debug.h"
+
+#include "patchapi.h"
+
+#include "lzxd_dec.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(mspatcha);
+
+
+#define ELEM_SIZE 2
+#define MAX_CODE_LEN 16
+#define MAX_ALIGN_CODE_LEN 7
+#define PRE_LEN_BITS 4
+#define MAX_PRE_CODE_LEN ((1 << PRE_LEN_BITS) - 1)
+#define MAIN_TABLE_SIZE (1 << MAX_CODE_LEN)
+#define ALIGN_TABLE_SIZE (1 << MAX_ALIGN_CODE_LEN)
+#define HUFF_ERROR 0xFFFF
+#define REP_COUNT 3
+#define MAX_POS_SLOTS 290
+#define ALIGN_CODE_COUNT 8
+#define PRE_LEN_CODE_COUNT 20
+#define MAIN_CODE_COUNT(slots) (256 + 8 * (slots))
+#define MAX_MAIN_CODES MAIN_CODE_COUNT(MAX_POS_SLOTS)
+#define LEN_CODE_COUNT 249
+#define MAX_CHUNK_UNCOMPRESSED_SIZE 0x8000
+#define E8_TRANSFORM_LIMIT_BITS 30
+#define E8_TRANSFORM_DEAD_ZONE 10
+
+#define my_min(a, b) ((a) < (b) ? (a) : (b))
+
+struct LZXD_dec {
+ /* use byte pointers instead of uint16 for simplicity on uncompressed
+ * chunks, and the stream is not 16-bit aligned anyway */
+ const BYTE *stream_buf;
+ /* the next word to load into the bit cache */
+ const BYTE *src;
+ /* location of the next chunk size field */
+ const BYTE *chunk_end;
+ /* position in the output where the maximum allowed decompressed chunk size is reached */
+ size_t uncomp_chunk_end;
+ /* end of the input */
+ const BYTE *stream_end;
+ /* bit cache */
+ UINT32 bits;
+ /* number of unused bits in the cache starting from bit 0 */
+ unsigned bit_pos;
+ /* number of padding bits added trying to read at the chunk end */
+ unsigned tail_bits;
+ /* repeat matches */
+ size_t reps[REP_COUNT];
+ /* distance slot count is required for loading code lengths */
+ unsigned dist_slot_count;
+ /* huffman code lengths */
+ BYTE align_lengths[ALIGN_CODE_COUNT];
+ BYTE main_lengths[MAX_MAIN_CODES];
+ BYTE len_lengths[LEN_CODE_COUNT];
+ UINT16 align_table[ALIGN_TABLE_SIZE];
+ UINT16 main_table[MAIN_TABLE_SIZE];
+ UINT16 len_table[MAIN_TABLE_SIZE];
+};
+
+/* PA19 container format is unaligned, so the LZXD stream is not aligned either.
+ * None of this is super optimized but it's fast enough for installer work.
+ */
+static inline UINT16 read_uint16(struct LZXD_dec *dec)
+{
+ /* bounds check was done before calling */
+ UINT16 u = dec->src[0] | (dec->src[1] << 8);
+ dec->src += ELEM_SIZE;
+ return u;
+}
+
+/* load the next chunk size, reset bit_pos and set up limits
+ */
+static int init_chunk(struct LZXD_dec *dec, size_t index, size_t buf_limit)
+{
+ UINT32 chunk_size;
+
+ if (dec->src + ELEM_SIZE > dec->stream_end)
+ return -1;
+
+ /* error if tail padding bits were decoded as input */
+ if (dec->bit_pos < dec->tail_bits)
+ return -1;
+
+ chunk_size = read_uint16(dec);
+
+ dec->chunk_end = dec->src + chunk_size;
+ if (dec->chunk_end > dec->stream_end)
+ return -1;
+
+ dec->bit_pos = 0;
+ dec->tail_bits = 0;
+
+ dec->uncomp_chunk_end = my_min(buf_limit, index + MAX_CHUNK_UNCOMPRESSED_SIZE);
+
+ return 0;
+}
+
+/* ensure at least 17 bits are loaded but do not advance
+ */
+static inline void prime_bits(struct LZXD_dec *dec)
+{
+ while (dec->bit_pos < 17)
+ {
+ if (dec->src + ELEM_SIZE <= dec->chunk_end)
+ {
+ dec->bits = (dec->bits << 16) | read_uint16(dec);
+ }
+ else
+ {
+ /* Need to pad at the end of the chunk to decode the last codes.
+ In an error state, 0xFFFF sends the decoder down the right
+ side of the huffman tree to error out sooner. */
+ dec->bits = (dec->bits << 16) | 0xFFFF;
+ dec->tail_bits += 16;
+ }
+ dec->bit_pos += 16;
+ }
+}
+
+/* read and advance n bits
+ */
+static inline UINT32 read_bits(struct LZXD_dec *dec, unsigned n)
+{
+ UINT32 bits;
+
+ dec->bit_pos -= n;
+ bits = dec->bits >> dec->bit_pos;
+ bits &= ((1 << n) - 1);
+
+ while (dec->bit_pos < 17)
+ {
+ if (dec->src + ELEM_SIZE <= dec->chunk_end)
+ {
+ dec->bits = (dec->bits << 16) | read_uint16(dec);
+ }
+ else
+ {
+ /* tail padding */
+ dec->bits = (dec->bits << 16) | 0xFFFF;
+ dec->tail_bits += 16;
+ }
+ dec->bit_pos += 16;
+ }
+
+ return bits;
+}
+
+/* read n bits but do not advance
+ */
+static inline UINT32 peek_bits(struct LZXD_dec *dec, unsigned n)
+{
+ UINT32 bits = dec->bits >> (dec->bit_pos - n);
+ return bits & ((1 << n) - 1);
+}
+
+static inline void advance_bits(struct LZXD_dec *dec, unsigned length)
+{
+ dec->bit_pos -= length;
+ prime_bits(dec);
+}
+
+/* read a 16-bit aligned UINT32
+ */
+static UINT32 read_uint32(struct LZXD_dec *dec)
+{
+ UINT32 u = 0;
+ unsigned n = 0;
+
+ assert((dec->bit_pos & 0xF) == 0);
+
+ while (dec->bit_pos)
+ {
+ dec->bit_pos -= 16;
+ u |= ((dec->bits >> dec->bit_pos) & 0xFFFF) << n;
+ n += 16;
+ }
+ while (n < 32 && dec->src + ELEM_SIZE <= dec->chunk_end)
+ {
+ u |= read_uint16(dec) << n;
+ n += 16;
+ }
+
+ return u;
+}
+
+static int make_huffman_codes(unsigned *codes, const BYTE *lengths, unsigned count)
+{
+ unsigned len_count[MAX_CODE_LEN + 1];
+ unsigned next_code[MAX_CODE_LEN + 1];
+ unsigned i;
+ unsigned code = 0;
+
+ memset(len_count, 0, sizeof(len_count));
+ for (i = 0; i < count; ++i)
+ ++len_count[lengths[i]];
+ len_count[0] = 0;
+
+ for (i = 1; i <= MAX_CODE_LEN; ++i)
+ {
+ code = (code + len_count[i - 1]) << 1;
+ next_code[i] = code;
+ }
+ for (i = 0; i < count; i++)
+ {
+ unsigned len = lengths[i];
+ if (len)
+ {
+ /* test for bad code tree */
+ if (next_code[len] >= (1U << len))
+ return -1;
+
+ codes[i] = next_code[len];
+ ++next_code[len];
+ }
+ }
+ return 0;
+}
+
+void make_decode_table(UINT16 *table, const unsigned *codes,
+ const BYTE *lengths, unsigned max_len, unsigned count)
+{
+ const size_t table_size = (size_t)1 << max_len;
+ size_t i;
+
+ for (i = 0; i < table_size; i++)
+ table[i] = HUFF_ERROR;
+
+ for (i = 0; i < count; i++) if (lengths[i])
+ {
+ BYTE diff = (BYTE)max_len - lengths[i];
+ size_t n = codes[i] << diff;
+ size_t end = n + ((size_t)1 << diff);
+ for (; n < end; ++n)
+ table[n] = (UINT16)i;
+ }
+}
+
+#define ret_if_failed(r_) do { int err_ = r_; if(err_) return err_; } while(0)
+
+static int decode_lengths(struct LZXD_dec *dec,
+ BYTE *lengths, unsigned index, unsigned count)
+{
+ unsigned codes[PRE_LEN_CODE_COUNT];
+ BYTE pre_lens[PRE_LEN_CODE_COUNT];
+ size_t i;
+ unsigned repeats = 1;
+
+ for (i = 0; i < PRE_LEN_CODE_COUNT; ++i)
+ pre_lens[i] = (BYTE)read_bits(dec, PRE_LEN_BITS);
+
+ ret_if_failed(make_huffman_codes(codes, pre_lens, PRE_LEN_CODE_COUNT));
+ make_decode_table(dec->main_table, codes, pre_lens, MAX_PRE_CODE_LEN, PRE_LEN_CODE_COUNT);
+
+ while (index < count)
+ {
+ UINT32 bits = peek_bits(dec, MAX_PRE_CODE_LEN);
+ UINT16 sym = dec->main_table[bits];
+ if (sym == HUFF_ERROR)
+ return -1;
+ advance_bits(dec, pre_lens[sym]);
+
+ if (sym < 17)
+ {
+ sym = (lengths[index] + 17 - sym) % 17;
+ do
+ {
+ lengths[index] = (BYTE)sym;
+ ++index;
+ --repeats;
+ } while (repeats && index < count);
+
+ repeats = 1;
+ }
+ else if (sym < 19)
+ {
+ unsigned zeros;
+
+ sym -= 13;
+ zeros = read_bits(dec, sym) + (1 << sym) - 12;
+ do
+ {
+ lengths[index] = 0;
+ ++index;
+ --zeros;
+ } while (zeros && index < count);
+ }
+ else
+ {
+ /* the repeat count applies to the next symbol */
+ repeats = 4 + read_bits(dec, 1);
+ }
+ }
+ return 0;
+}
+
+/* distance decoder for block_type == 1
+ */
+static size_t decode_dist_verbatim(struct LZXD_dec *dec, unsigned dist_slot)
+{
+ size_t dist;
+ unsigned footer_bits = 17;
+
+ if (dist_slot < 38)
+ {
+ footer_bits = (dist_slot >> 1) - 1;
+ dist = ((size_t)2 + (dist_slot & 1)) << footer_bits;
+ }
+ else
+ {
+ dist = ((size_t)1 << 19) + ((size_t)1 << 17) * (dist_slot - 38);
+ }
+ return dist + read_bits(dec, footer_bits);
+}
+
+/* distance decoder for block_type == 2
+ */
+static size_t decode_dist_aligned(struct LZXD_dec *dec, unsigned dist_slot)
+{
+ size_t dist;
+ unsigned footer_bits = 17;
+
+ if (dist_slot < 38)
+ {
+ footer_bits = (dist_slot >> 1) - 1;
+ dist = ((size_t)2 + (dist_slot & 1)) << footer_bits;
+ }
+ else
+ {
+ dist = ((size_t)1 << 19) + ((size_t)1 << 17) * (dist_slot - 38);
+ }
+ if (footer_bits >= 3)
+ {
+ UINT32 bits;
+ UINT16 sym;
+
+ footer_bits -= 3;
+ if (footer_bits)
+ dist += read_bits(dec, footer_bits) << 3;
+
+ bits = peek_bits(dec, MAX_ALIGN_CODE_LEN);
+ sym = dec->align_table[bits];
+ if (sym == HUFF_ERROR)
+ return ~(size_t)0;
+ advance_bits(dec, dec->align_lengths[sym]);
+
+ dist += sym;
+ }
+ else
+ {
+ dist += read_bits(dec, footer_bits);
+ }
+ return dist;
+}
+
+static inline void align_16_or_maybe_advance_anyway(struct LZXD_dec *dec)
+{
+ dec->bit_pos &= 0x30;
+ /* The specification requires 16 bits of zero padding in some cases where the stream is already aligned, but
+ * the logic behind the choice to pad any particular block is undefined (it's a feature!). Fortunately it
+ * seems always to coincide with a bit_pos of 0x20, but 0x20 doesn't always mean padding, so we test for zero
+ * too. A remote chance of failure may still exist but I've never seen one occur. */
+ if (dec->bit_pos == 0x20 && (dec->bits >> 16) == 0)
+ dec->bit_pos = 0x10;
+}
+
+static int copy_uncompressed(struct LZXD_dec *dec, BYTE *base, size_t *index_ptr, size_t buf_limit, UINT32 block_size)
+{
+ size_t index = *index_ptr;
+ size_t end = index + block_size;
+ size_t realign;
+
+ if (end > buf_limit)
+ return -1;
+ /* save the current alignment */
+ realign = (dec->src - dec->stream_buf) & 1;
+
+ while (dec->src < dec->stream_end)
+ {
+ /* now treat the input as an unaligned byte stream */
+ size_t to_copy = my_min(end - index, dec->uncomp_chunk_end - index);
+ to_copy = my_min(to_copy, (size_t)(dec->stream_end - dec->src));
+
+ memcpy(base + index, dec->src, to_copy);
+ index += to_copy;
+ dec->src += to_copy;
+
+ if (index == end)
+ {
+ /* realign at the end of the block */
+ dec->src += ((dec->src - dec->stream_buf) & 1) ^ realign;
+ /* fill the bit cache for block header decoding */
+ prime_bits(dec);
+ break;
+ }
+ /* chunk sizes are also unaligned */
+ ret_if_failed(init_chunk(dec, index, buf_limit));
+ }
+ *index_ptr = index;
+ return 0;
+}
+
+static int prime_next_chunk(struct LZXD_dec *dec, size_t index, size_t buf_limit)
+{
+ if (dec->src < dec->chunk_end)
+ return -1;
+ ret_if_failed(init_chunk(dec, index, buf_limit));
+ prime_bits(dec);
+ return 0;
+}
+
+#define MAX_LONG_MATCH_CODE_LEN 3
+#define LONG_MATCH_TABLE_SIZE (1 << MAX_LONG_MATCH_CODE_LEN)
+
+struct long_match {
+ BYTE code_len;
+ unsigned extra_bits;
+ unsigned base;
+};
+
+static const struct long_match long_match_table[LONG_MATCH_TABLE_SIZE] = {
+ {1, 8, 0x101},
+ {1, 8, 0x101},
+ {1, 8, 0x101},
+ {1, 8, 0x101},
+ {2, 10, 0x201},
+ {2, 10, 0x201},
+ {3, 12, 0x601},
+ {3, 15, 0x101}
+};
+
+static int decode_lzxd_block(struct LZXD_dec *dec, BYTE *base, size_t predef_size, size_t *index_ptr, size_t buf_limit)
+{
+ unsigned codes[MAX_MAIN_CODES];
+ unsigned main_code_count;
+ UINT32 block_type;
+ UINT32 block_size;
+ size_t i;
+ size_t block_limit;
+ size_t index = *index_ptr;
+ size_t (*dist_decoder)(struct LZXD_dec *dec, unsigned dist_slot);
+
+ if (index >= dec->uncomp_chunk_end && prime_next_chunk(dec, index, buf_limit))
+ return -1;
+
+ block_type = read_bits(dec, 3);
+
+ /* check for invalid block types */
+ if (block_type == 0 || block_type > 3)
+ return -1;
+
+ block_size = read_bits(dec, 8);
+ block_size = (block_size << 8) | read_bits(dec, 8);
+ block_size = (block_size << 8) | read_bits(dec, 8);
+
+ if (block_type == 3)
+ {
+ /* uncompressed block */
+ align_16_or_maybe_advance_anyway(dec);
+ /* must have run out of coffee at the office */
+ for (i = 0; i < REP_COUNT; ++i)
+ {
+ dec->reps[i] = read_uint32(dec);
+ if (dec->reps[i] == 0)
+ return -1;
+ }
+ /* copy the block to output */
+ return copy_uncompressed(dec, base, index_ptr, buf_limit, block_size);
+ }
+ else if (block_type == 2)
+ {
+ /* distance alignment decoder will be used */
+ for (i = 0; i < ALIGN_CODE_COUNT; ++i)
+ dec->align_lengths[i] = read_bits(dec, 3);
+ }
+
+ main_code_count = MAIN_CODE_COUNT(dec->dist_slot_count);
+ ret_if_failed(decode_lengths(dec, dec->main_lengths, 0, 256));
+ ret_if_failed(decode_lengths(dec, dec->main_lengths, 256, main_code_count));
+ ret_if_failed(decode_lengths(dec, dec->len_lengths, 0, LEN_CODE_COUNT));
+
+ dist_decoder = (block_type == 2) ? decode_dist_aligned : decode_dist_verbatim;
+
+ if (block_type == 2)
+ {
+ ret_if_failed(make_huffman_codes(codes, dec->align_lengths, ALIGN_CODE_COUNT));
+ make_decode_table(dec->align_table, codes, dec->align_lengths, MAX_ALIGN_CODE_LEN, ALIGN_CODE_COUNT);
+ }
+
+ ret_if_failed(make_huffman_codes(codes, dec->main_lengths, main_code_count));
+ make_decode_table(dec->main_table, codes, dec->main_lengths, MAX_CODE_LEN, main_code_count);
+
+ ret_if_failed(make_huffman_codes(codes, dec->len_lengths, LEN_CODE_COUNT));
+ make_decode_table(dec->len_table, codes, dec->len_lengths, MAX_CODE_LEN, LEN_CODE_COUNT);
+
+ block_limit = my_min(buf_limit, index + block_size);
+
+ while (index < block_limit)
+ {
+ UINT32 bits;
+ UINT16 sym;
+
+ if (index >= dec->uncomp_chunk_end && prime_next_chunk(dec, index, buf_limit))
+ return -1;
+
+ bits = peek_bits(dec, MAX_CODE_LEN);
+ sym = dec->main_table[bits];
+ if (sym == HUFF_ERROR)
+ return -1;
+ advance_bits(dec, dec->main_lengths[sym]);
+
+ if (sym < 256)
+ {
+ /* literal */
+ base[index] = (BYTE)sym;
+ ++index;
+ }
+ else {
+ size_t length;
+ size_t dist;
+ size_t end;
+ unsigned dist_slot;
+
+ sym -= 256;
+ length = (sym & 7) + 2;
+ dist_slot = sym >> 3;
+
+ if (length == 9)
+ {
+ /* extra length bits */
+ bits = peek_bits(dec, MAX_CODE_LEN);
+ sym = dec->len_table[bits];
+ if (sym == HUFF_ERROR)
+ return -1;
+ advance_bits(dec, dec->len_lengths[sym]);
+
+ length += sym;
+ }
+ dist = dist_slot;
+ if (dist_slot > 3)
+ {
+ /* extra distance bits */
+ dist = dist_decoder(dec, dist_slot);
+ if (dist == ~(size_t)0)
+ return -1;
+ }
+ if (length == 257)
+ {
+ /* extra-long match length */
+ bits = peek_bits(dec, MAX_LONG_MATCH_CODE_LEN);
+ advance_bits(dec, long_match_table[bits].code_len);
+
+ length = long_match_table[bits].base;
+ length += read_bits(dec, long_match_table[bits].extra_bits);
+ }
+ if (dist < 3)
+ {
+ /* repeat match */
+ size_t rep = dist;
+ dist = dec->reps[dist];
+ dec->reps[rep] = dec->reps[0];
+ }
+ else
+ {
+ dist -= REP_COUNT - 1;
+ dec->reps[2] = dec->reps[1];
+ dec->reps[1] = dec->reps[0];
+ }
+ dec->reps[0] = dist;
+
+ while (dist > index && length && index < block_limit)
+ {
+ /* undocumented: the encoder assumes an imaginary buffer
+ * of zeros exists before the start of the real buffer */
+ base[index] = 0;
+ ++index;
+ --length;
+ }
+
+ end = my_min(index + length, block_limit);
+ while (index < end)
+ {
+ base[index] = base[index - dist];
+ ++index;
+ }
+ }
+ }
+ /* error if tail padding bits were decoded as input */
+ if (dec->bit_pos < dec->tail_bits)
+ return -1;
+
+ *index_ptr = index;
+ return 0;
+}
+
+static void reverse_e8_transform(BYTE *decode_buf, ptrdiff_t len, ptrdiff_t e8_file_size)
+{
+ ptrdiff_t limit = my_min((ptrdiff_t)1 << E8_TRANSFORM_LIMIT_BITS, len);
+ ptrdiff_t i;
+
+ for (i = 0; i < limit; )
+ {
+ ptrdiff_t end = my_min(i + MAX_CHUNK_UNCOMPRESSED_SIZE - E8_TRANSFORM_DEAD_ZONE,
+ limit - E8_TRANSFORM_DEAD_ZONE);
+ ptrdiff_t next = i + MAX_CHUNK_UNCOMPRESSED_SIZE;
+
+ for (; i < end; ++i)
+ {
+ if (decode_buf[i] == 0xE8)
+ {
+ ptrdiff_t delta;
+ ptrdiff_t value = (ptrdiff_t)decode_buf[i + 1] |
+ decode_buf[i + 2] << 8 |
+ decode_buf[i + 3] << 16 |
+ decode_buf[i + 4] << 24;
+
+ if (value >= -i && value < e8_file_size)
+ {
+ if (value >= 0)
+ delta = value - i;
+ else
+ delta = value + e8_file_size;
+
+ decode_buf[i + 1] = (BYTE)delta;
+ decode_buf[i + 2] = (BYTE)(delta >> 8);
+ decode_buf[i + 3] = (BYTE)(delta >> 16);
+ decode_buf[i + 4] = (BYTE)(delta >> 24);
+ }
+ i += 4;
+ }
+ }
+ i = next;
+ }
+}
+
+DWORD decode_lzxd_stream(const BYTE *src, const size_t input_size,
+ BYTE *dst, const size_t output_size,
+ const size_t predef_size,
+ DWORD large_window,
+ PPATCH_PROGRESS_CALLBACK progress_fn,
+ PVOID progress_ctx)
+{
+ struct LZXD_dec *dec;
+ const BYTE *end = src + input_size;
+ size_t buf_size = predef_size + output_size;
+ UINT32 e8;
+ UINT32 e8_file_size = 0;
+ DWORD err = ERROR_SUCCESS;
+
+ TRACE("decoding stream of size %u to size %u, starting at %u\n",
+ (unsigned)input_size, (unsigned)output_size, (unsigned)predef_size);
+
+ if (input_size == 0)
+ return (output_size == 0) ? ERROR_SUCCESS : ERROR_PATCH_CORRUPT;
+
+ if (progress_fn != NULL && !progress_fn(progress_ctx, 0, (ULONG)output_size))
+ return ERROR_CANCELLED;
+
+ dec = malloc(sizeof(*dec));
+ if (dec == NULL)
+ return ERROR_OUTOFMEMORY;
+
+ memset(dec->main_lengths, 0, sizeof(dec->main_lengths));
+ memset(dec->len_lengths, 0, sizeof(dec->len_lengths));
+ dec->reps[0] = 1;
+ dec->reps[1] = 1;
+ dec->reps[2] = 1;
+
+ /* apparently the window size is not recorded and must be deduced from the file sizes */
+ {
+ unsigned max_window = large_window ? MAX_LARGE_WINDOW : MAX_NORMAL_WINDOW;
+ size_t window = (size_t)1 << 17;
+ /* round up the old file size per the lzxd spec - correctness verified by fuzz tests */
+ size_t total = (predef_size + 0x7FFF) & ~0x7FFF;
+ unsigned delta;
+
+ total += output_size;
+ dec->dist_slot_count = 34;
+ while (window < total && window < ((size_t)1 << 19))
+ {
+ dec->dist_slot_count += 2;
+ window <<= 1;
+ }
+ delta = 4;
+ while (window < total && window < max_window)
+ {
+ dec->dist_slot_count += delta;
+ delta <<= 1;
+ window <<= 1;
+ }
+ TRACE("setting window to 0x%X\n", (unsigned)window);
+ }
+
+ dec->bit_pos = 0;
+ dec->tail_bits = 0;
+ dec->stream_buf = src;
+ dec->src = src;
+ dec->stream_end = end;
+ dec->chunk_end = dec->src;
+
+ /* load the first chunk size and set the end pointer */
+ if(init_chunk(dec, predef_size, buf_size))
+ {
+ err = ERROR_PATCH_DECODE_FAILURE;
+ goto free_dec;
+ }
+
+ /* fill the bit cache */
+ prime_bits(dec);
+
+ e8 = read_bits(dec, 1);
+ if (e8)
+ {
+ /* E8 transform was used */
+ e8_file_size = read_bits(dec, 16) << 16;
+ e8_file_size |= read_bits(dec, 16);
+ TRACE("E8 transform detected; file size %u\n", e8_file_size);
+ }
+
+ {
+ size_t index = predef_size;
+ while (dec->src < dec->stream_end && index < buf_size)
+ {
+ if (decode_lzxd_block(dec, dst, predef_size, &index, buf_size))
+ {
+ err = ERROR_PATCH_DECODE_FAILURE;
+ goto free_dec;
+ }
+ if (progress_fn != NULL && !progress_fn(progress_ctx, (ULONG)(index - predef_size), (ULONG)output_size))
+ {
+ err = ERROR_CANCELLED;
+ goto free_dec;
+ }
+ }
+ }
+
+ if (e8)
+ reverse_e8_transform(dst + predef_size, output_size, e8_file_size);
+
+free_dec:
+ free(dec);
+
+ return err;
+}
diff --git a/dlls/mspatcha/lzxd_dec.h b/dlls/mspatcha/lzxd_dec.h
new file mode 100755
index 0000000..a7923cd
--- /dev/null
+++ b/dlls/mspatcha/lzxd_dec.h
@@ -0,0 +1,27 @@
+/*
+ * Copyright 2019 Conor McCarthy
+ *
+ * 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
+ */
+
+#define MAX_NORMAL_WINDOW (8U << 20)
+#define MAX_LARGE_WINDOW (32U << 20)
+
+DWORD decode_lzxd_stream(const BYTE *src, const size_t input_size,
+ BYTE *dst, const size_t output_size,
+ const size_t predef_size,
+ DWORD large_window,
+ PPATCH_PROGRESS_CALLBACK progress_fn,
+ PVOID progress_ctx);
diff --git a/dlls/mspatcha/mspatcha.spec b/dlls/mspatcha/mspatcha.spec
index cc8ca94..8c014b9 100644
--- a/dlls/mspatcha/mspatcha.spec
+++ b/dlls/mspatcha/mspatcha.spec
@@ -1,12 +1,16 @@
-1 stdcall ApplyPatchToFileA(str str str long)
-2 stub ApplyPatchToFileByHandles
-3 stub ApplyPatchToFileByHandlesEx
-4 stub ApplyPatchToFileExA
-5 stub ApplyPatchToFileExW
-6 stdcall ApplyPatchToFileW(wstr wstr wstr long)
-7 stdcall GetFilePatchSignatureA(str long ptr long ptr long ptr long ptr)
-8 stub GetFilePatchSignatureByHandle
-9 stdcall GetFilePatchSignatureW(wstr long ptr long ptr long ptr long ptr)
-10 stub TestApplyPatchToFileA
-11 stub TestApplyPatchToFileByHandles
-12 stub TestApplyPatchToFileW
+@ stdcall ApplyPatchToFileA(str str str long)
+@ stdcall ApplyPatchToFileByBuffers(ptr long ptr long ptr long ptr ptr long ptr ptr)
+@ stdcall ApplyPatchToFileByHandles(ptr ptr ptr long)
+@ stdcall ApplyPatchToFileByHandlesEx(ptr ptr ptr long ptr ptr)
+@ stdcall ApplyPatchToFileExA(str str str long ptr ptr)
+@ stdcall ApplyPatchToFileExW(wstr wstr wstr long ptr ptr)
+@ stdcall ApplyPatchToFileW(wstr wstr wstr long)
+@ stdcall GetFilePatchSignatureA(str long ptr long ptr long ptr long str)
+@ stdcall GetFilePatchSignatureByBuffer(ptr long long ptr long ptr long ptr long str)
+@ stdcall GetFilePatchSignatureByHandle(ptr long ptr long ptr long ptr long str)
+@ stdcall GetFilePatchSignatureW(wstr long ptr long ptr long ptr long wstr)
+@ stdcall NormalizeFileForPatchSignature(ptr long long ptr long long long ptr long ptr)
+@ stdcall TestApplyPatchToFileA(str str long)
+@ stdcall TestApplyPatchToFileByBuffers(ptr long ptr long ptr long)
+@ stdcall TestApplyPatchToFileByHandles(ptr ptr long)
+@ stdcall TestApplyPatchToFileW(wstr wstr long)
diff --git a/dlls/mspatcha/mspatcha_main.c b/dlls/mspatcha/mspatcha_main.c
index f78b8ab..3a311bc 100644
--- a/dlls/mspatcha/mspatcha_main.c
+++ b/dlls/mspatcha/mspatcha_main.c
@@ -2,6 +2,7 @@
* PatchAPI
*
* Copyright 2011 David Hedberg for CodeWeavers
+ * Copyright 2019 Conor McCarthy (implementations)
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -16,6 +17,31 @@
* 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
+ *
+ *
+ * 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
+ *
+ * TODO
+ * - Special processing of 32-bit executables is not supported, so this
+ * version cannot patch 32-bit .exe and .dll files. See pa19.c for details.
+ * - Implement interleaved decoding when PATCH_OPTION_INTERLEAVE_FILES was
+ * used or the old file exceeds the lzxd window size.
+ * - APPLY_OPTION_FAIL_IF_CLOSE is ignored. Normalization of 32-bit PE files
+ * is required for checking this.
+ * - GetFilePatchSignature* and NormalizeFileForPatchSignature require a
+ * solution to the above 32-bit exe problem.
*/
#include "config.h"
@@ -28,6 +54,8 @@
#include "patchapi.h"
#include "wine/debug.h"
+#include "pa19.h"
+
WINE_DEFAULT_DEBUG_CHANNEL(mspatcha);
/*****************************************************
@@ -49,79 +77,236 @@ BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
return TRUE;
}
-static inline WCHAR *strdupAW( const char *src )
+static WCHAR *strdupAW(const char *src)
{
WCHAR *dst = NULL;
if (src)
{
- int len = MultiByteToWideChar( CP_ACP, 0, src, -1, NULL, 0 );
- if ((dst = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) )))
- MultiByteToWideChar( CP_ACP, 0, src, -1, dst, len );
+ int len = MultiByteToWideChar(CP_ACP, 0, src, -1, NULL, 0);
+ if ((dst = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR))))
+ MultiByteToWideChar(CP_ACP, 0, src, -1, dst, len);
}
return dst;
}
/*****************************************************
- * ApplyPatchToFileA (MSPATCHA.1)
+ * TestApplyPatchToFileA (MSPATCHA.@)
*/
-BOOL WINAPI ApplyPatchToFileA(LPCSTR patch_file, LPCSTR old_file, LPCSTR new_file, ULONG apply_flags)
+BOOL WINAPI TestApplyPatchToFileA(LPCSTR patch_file, LPCSTR old_file, ULONG apply_flags)
{
BOOL ret;
- WCHAR *patch_fileW, *new_fileW, *old_fileW = NULL;
+ WCHAR *patch_fileW, *old_fileW = NULL;
- if (!(patch_fileW = strdupAW( patch_file ))) return FALSE;
- if (old_file && !(old_fileW = strdupAW( old_file )))
+ if (!(patch_fileW = strdupAW(patch_file))) return FALSE;
+ if (old_file && !(old_fileW = strdupAW(old_file)))
{
- HeapFree( GetProcessHeap(), 0, patch_fileW );
+ HeapFree(GetProcessHeap(), 0, patch_fileW);
return FALSE;
}
- if (!(new_fileW = strdupAW( new_file )))
+ ret = apply_patch_to_file(patch_fileW, old_fileW, NULL, apply_flags, NULL, NULL, TRUE);
+ HeapFree(GetProcessHeap(), 0, patch_fileW);
+ if(old_fileW)
+ HeapFree(GetProcessHeap(), 0, old_fileW);
+ return ret;
+}
+
+BOOL WINAPI TestApplyPatchToFileW(LPCWSTR patch_file_name, LPCWSTR old_file_name, ULONG apply_option_flags)
+{
+ return apply_patch_to_file(patch_file_name, old_file_name, NULL, apply_option_flags, NULL, NULL, TRUE);
+}
+
+BOOL WINAPI TestApplyPatchToFileByHandles(HANDLE patch_file_hndl, HANDLE old_file_hndl, ULONG apply_option_flags)
+{
+ return apply_patch_to_file_by_handles(patch_file_hndl, old_file_hndl, NULL,
+ apply_option_flags, NULL, NULL, TRUE);
+}
+
+BOOL WINAPI TestApplyPatchToFileByBuffers(BYTE *patch_file_buf, ULONG patch_file_size,
+ BYTE *old_file_buf, ULONG old_file_size,
+ ULONG* new_file_size,
+ ULONG apply_option_flags)
+{
+ /* preserve last error on success as per windows */
+ DWORD last = GetLastError();
+
+ DWORD err = apply_patch_to_file_by_buffers(patch_file_buf, patch_file_size,
+ old_file_buf, old_file_size,
+ NULL, 0, new_file_size, NULL,
+ apply_option_flags,
+ NULL, NULL,
+ TRUE);
+
+ SetLastError(err == ERROR_SUCCESS ? last : err);
+
+ return err == ERROR_SUCCESS;
+}
+
+/*****************************************************
+ * ApplyPatchToFileExA (MSPATCHA.@)
+ */
+BOOL WINAPI ApplyPatchToFileExA(LPCSTR patch_file, LPCSTR old_file, LPCSTR new_file, ULONG apply_flags,
+ PPATCH_PROGRESS_CALLBACK progress_fn, PVOID progress_ctx)
+{
+ BOOL ret = FALSE;
+ WCHAR *patch_fileW, *new_fileW, *old_fileW = NULL;
+
+ if (!(patch_fileW = strdupAW(patch_file))) return FALSE;
+ if (old_file && !(old_fileW = strdupAW(old_file)))
{
- HeapFree( GetProcessHeap(), 0, patch_fileW );
- HeapFree( GetProcessHeap(), 0, old_fileW );
+ HeapFree(GetProcessHeap(), 0, patch_fileW);
return FALSE;
}
- ret = ApplyPatchToFileW( patch_fileW, old_fileW, new_fileW, apply_flags );
- HeapFree( GetProcessHeap(), 0, patch_fileW );
- HeapFree( GetProcessHeap(), 0, old_fileW );
- HeapFree( GetProcessHeap(), 0, new_fileW );
+ if (!(new_fileW = strdupAW(new_file)))
+ {
+ goto free_wstrs;
+ }
+ ret = apply_patch_to_file(patch_fileW, old_fileW, new_fileW, apply_flags, progress_fn, progress_ctx, FALSE);
+ HeapFree(GetProcessHeap(), 0, new_fileW);
+free_wstrs:
+ HeapFree(GetProcessHeap(), 0, patch_fileW);
+ if(old_fileW)
+ HeapFree(GetProcessHeap(), 0, old_fileW);
return ret;
}
/*****************************************************
- * ApplyPatchToFileW (MSPATCHA.6)
+ * ApplyPatchToFileA (MSPATCHA.@)
*/
-BOOL WINAPI ApplyPatchToFileW(LPCWSTR patch_file, LPCWSTR old_file, LPCWSTR new_file, ULONG apply_flags)
+BOOL WINAPI ApplyPatchToFileA(LPCSTR patch_file, LPCSTR old_file, LPCSTR new_file, ULONG apply_flags)
{
- FIXME("stub - %s, %s, %s, %08x\n", debugstr_w(patch_file), debugstr_w(old_file),
- debugstr_w(new_file), apply_flags);
+ return ApplyPatchToFileExA(patch_file, old_file, new_file, apply_flags, NULL, NULL);
+}
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
- return FALSE;
+/*****************************************************
+ * ApplyPatchToFileW (MSPATCHA.@)
+ */
+BOOL WINAPI ApplyPatchToFileW(LPCWSTR patch_file_name, LPCWSTR old_file_name, LPCWSTR new_file_name,
+ ULONG apply_option_flags)
+{
+ return apply_patch_to_file(patch_file_name, old_file_name, new_file_name, apply_option_flags,
+ NULL, NULL, FALSE);
+}
+
+/*****************************************************
+ * ApplyPatchToFileByHandles (MSPATCHA.@)
+ */
+BOOL WINAPI ApplyPatchToFileByHandles(HANDLE patch_file_hndl, HANDLE old_file_hndl, HANDLE new_file_hndl,
+ ULONG apply_option_flags)
+{
+ return apply_patch_to_file_by_handles(patch_file_hndl, old_file_hndl, new_file_hndl,
+ apply_option_flags, NULL, NULL, FALSE);
+}
+
+/*****************************************************
+ * ApplyPatchToFileExW (MSPATCHA.@)
+ */
+BOOL WINAPI ApplyPatchToFileExW(LPCWSTR patch_file_name, LPCWSTR old_file_name, LPCWSTR new_file_name,
+ ULONG apply_option_flags,
+ PPATCH_PROGRESS_CALLBACK progress_fn, PVOID progress_ctx)
+{
+ return apply_patch_to_file(patch_file_name, old_file_name, new_file_name, apply_option_flags,
+ progress_fn, progress_ctx, FALSE);
}
/*****************************************************
- * GetFilePatchSignatureA (MSPATCHA.7)
+ * ApplyPatchToFileByHandlesEx (MSPATCHA.@)
+ */
+BOOL WINAPI ApplyPatchToFileByHandlesEx(HANDLE patch_file_hndl, HANDLE old_file_hndl, HANDLE new_file_hndl,
+ ULONG apply_option_flags,
+ PPATCH_PROGRESS_CALLBACK progress_fn,
+ PVOID progress_ctx)
+{
+ return apply_patch_to_file_by_handles(patch_file_hndl, old_file_hndl, new_file_hndl,
+ apply_option_flags, progress_fn, progress_ctx, FALSE);
+}
+
+/*****************************************************
+ * ApplyPatchToFileByBuffers (MSPATCHA.@)
+ */
+BOOL WINAPI ApplyPatchToFileByBuffers(PBYTE patch_file_view, ULONG patch_file_size,
+ PBYTE old_file_view, ULONG old_file_size,
+ PBYTE* new_file_buf, ULONG new_file_buf_size, ULONG* new_file_size,
+ FILETIME* new_file_time,
+ ULONG apply_option_flags,
+ PPATCH_PROGRESS_CALLBACK progress_fn, PVOID progress_ctx)
+{
+ /* preserve last error on success as per windows */
+ DWORD last = GetLastError();
+
+ DWORD err = apply_patch_to_file_by_buffers(patch_file_view, patch_file_size,
+ old_file_view, old_file_size,
+ new_file_buf, new_file_buf_size, new_file_size, new_file_time,
+ apply_option_flags,
+ progress_fn, progress_ctx,
+ FALSE);
+
+ SetLastError(err == ERROR_SUCCESS ? last : err);
+
+ return err == ERROR_SUCCESS;
+}
+
+/*****************************************************
+ * GetFilePatchSignatureA (MSPATCHA.@)
*/
BOOL WINAPI GetFilePatchSignatureA(LPCSTR filename, ULONG flags, PVOID data, ULONG ignore_range_count,
- PPATCH_IGNORE_RANGE ignore_range, ULONG retain_range_count,
- PPATCH_RETAIN_RANGE retain_range, ULONG bufsize, LPSTR buffer)
+ PPATCH_IGNORE_RANGE ignore_range, ULONG retain_range_count,
+ PPATCH_RETAIN_RANGE retain_range, ULONG bufsize, LPSTR buffer)
{
FIXME("stub - %s, %x, %p, %u, %p, %u, %p, %u, %p\n", debugstr_a(filename), flags, data,
- ignore_range_count, ignore_range, retain_range_count, retain_range, bufsize, buffer);
+ ignore_range_count, ignore_range, retain_range_count, retain_range, bufsize, buffer);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
/*****************************************************
- * GetFilePatchSignatureW (MSPATCHA.9)
+ * GetFilePatchSignatureW (MSPATCHA.@)
*/
BOOL WINAPI GetFilePatchSignatureW(LPCWSTR filename, ULONG flags, PVOID data, ULONG ignore_range_count,
- PPATCH_IGNORE_RANGE ignore_range, ULONG retain_range_count,
- PPATCH_RETAIN_RANGE retain_range, ULONG bufsize, LPWSTR buffer)
+ PPATCH_IGNORE_RANGE ignore_range, ULONG retain_range_count,
+ PPATCH_RETAIN_RANGE retain_range, ULONG bufsize, LPWSTR buffer)
{
FIXME("stub - %s, %x, %p, %u, %p, %u, %p, %u, %p\n", debugstr_w(filename), flags, data,
- ignore_range_count, ignore_range, retain_range_count, retain_range, bufsize, buffer);
+ ignore_range_count, ignore_range, retain_range_count, retain_range, bufsize, buffer);
+ SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ return FALSE;
+}
+
+/*****************************************************
+ * GetFilePatchSignatureByHandle (MSPATCHA.@)
+ */
+BOOL WINAPI GetFilePatchSignatureByHandle(HANDLE handle, ULONG flags, PVOID options, ULONG ignore_range_count,
+ PPATCH_IGNORE_RANGE ignore_range, ULONG retain_range_count,
+ PPATCH_RETAIN_RANGE retain_range, ULONG bufsize, LPSTR buffer)
+{
+ FIXME("stub - %p, %x, %p, %u, %p, %u, %p, %u, %p\n", handle, flags, options,
+ ignore_range_count, ignore_range, retain_range_count, retain_range, bufsize, buffer);
+ SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ return FALSE;
+}
+
+/*****************************************************
+ * GetFilePatchSignatureByBuffer (MSPATCHA.@)
+ */
+BOOL WINAPI GetFilePatchSignatureByBuffer(PBYTE file_buf, ULONG file_size, ULONG flags, PVOID options,
+ ULONG ignore_range_count, PPATCH_IGNORE_RANGE ignore_range,
+ ULONG retain_range_count, PPATCH_RETAIN_RANGE retain_range,
+ ULONG bufsize, LPSTR buffer)
+{
+ FIXME("stub - %p, %u, %x, %p, %u, %p, %u, %p, %u, %p\n", file_buf, file_size, flags, options,
+ ignore_range_count, ignore_range, retain_range_count, retain_range, bufsize, buffer);
SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
return FALSE;
}
+
+/*****************************************************
+ * NormalizeFileForPatchSignature (MSPATCHA.@)
+ */
+INT WINAPI NormalizeFileForPatchSignature(PVOID file_buffer, ULONG file_size, ULONG flags, PATCH_OPTION_DATA *options,
+ ULONG new_coff_base, ULONG new_coff_time, ULONG ignore_range_count, PPATCH_IGNORE_RANGE ignore_range,
+ ULONG retain_range_count, PPATCH_RETAIN_RANGE retain_range)
+{
+ FIXME("stub - %p, %u, %x, %p, %u, %u, %u, %p, %u, %p\n", file_buffer, file_size, flags, options, new_coff_base,
+ new_coff_time, ignore_range_count, ignore_range, retain_range_count, retain_range);
+ SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
+ return 0;
+}
diff --git a/dlls/mspatcha/pa19.c b/dlls/mspatcha/pa19.c
new file mode 100755
index 0000000..1c20fc1
--- /dev/null
+++ b/dlls/mspatcha/pa19.c
@@ -0,0 +1,1060 @@
+/*
+ * PatchAPI PA19 file handlers
+ *
+ * Copyright 2019 Conor McCarthy
+ *
+ * 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
+ *
+ *
+ * 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
+ *
+ * TODO
+ * - Normalization of 32-bit PE executable files and reversal of special
+ * processing of these executables is not implemented.
+ * Without normalization, old files cannot be validated for patching. The
+ * function NormalizeFileForPatchSignature() in Windows could be used to work
+ * out exactly how normalization works.
+ * Most/all of the special processing seems to be relocation of targets for
+ * some jump/call instructions to match more of the old file and improve
+ * compression. Patching of 64-bit exes works because mspatchc.dll does not
+ * implement special processing of them. In 32-bit patches, the variable
+ * named here 'unknown_count' seems to indicate presence of data related to
+ * reversing the processing. The changes that must be reversed occur at some,
+ * but not all, of the positions listed in the PE .reloc table.
+ */
+
+#include "config.h"
+
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include "windef.h"
+#include "winbase.h"
+#include "wine/debug.h"
+
+#include "patchapi.h"
+
+#include "pa19.h"
+#include "lzxd_dec.h"
+
+WINE_DEFAULT_DEBUG_CHANNEL(mspatcha);
+
+#define PA19_FILE_MAGIC 0x39314150
+#define PATCH_OPTION_EXTRA_FLAGS 0x80000000
+
+#define my_max(a, b) ((a) > (b) ? (a) : (b))
+#define my_min(a, b) ((a) < (b) ? (a) : (b))
+
+
+/* The CRC32 code is copyright (C) 1986 Gary S. Brown and was placed in the
+ * public domain.
+ * CRC polynomial 0xedb88320
+ */
+static const UINT32 CRC_table[256] =
+{
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
+ 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
+ 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
+ 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
+ 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
+ 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
+ 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
+ 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+ 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
+ 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
+ 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
+ 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
+ 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+ 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
+ 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
+ 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
+ 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
+ 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+ 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
+ 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
+ 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
+ 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
+};
+
+static UINT32 compute_crc32(UINT32 crc, const BYTE *pData, INT_PTR iLen)
+{
+ crc ^= 0xFFFFFFFF;
+
+ while (iLen > 0) {
+ crc = CRC_table[(crc ^ *pData) & 0xFF] ^ (crc >> 8);
+ pData++;
+ iLen--;
+ }
+ return crc ^ 0xFFFFFFFF;
+}
+
+static UINT32 compute_zero_crc32(UINT32 crc, INT_PTR iLen)
+{
+ crc ^= 0xFFFFFFFF;
+
+ while (iLen > 0)
+ {
+ crc = CRC_table[crc & 0xFF] ^ (crc >> 8);
+ iLen--;
+ }
+ return crc ^ 0xFFFFFFFF;
+}
+
+
+/***********************************************************************************
+ * PatchAPI PA19 file header
+ *
+ * BYTE magic[4];
+ * UINT32 options;
+ * UINT32 options_2; (present if PATCH_OPTION_EXTRA_FLAGS set)
+ * UINT32 timestamp; (if PATCH_OPTION_NO_TIMESTAMP is SET in options)
+ * UVLI rebase; (present if PATCH_OPTION_NO_REBASE is not set; used on 32-bit executables)
+ * UVLI unpatched_size;
+ * UINT32 crc32_patched;
+ * BYTE input_file_count;
+ *
+ * For each source file:
+ * SVLI (patched_size - unpatched_size);
+ * UINT32 crc32_unpatched;
+ * BYTE ignore_range_count;
+ * For each ignore range:
+ * SVLI OffsetInOldFile;
+ * UVLI LengthInBytes;
+ * BYTE retain_range_count;
+ * For each retain range:
+ * SVLI (OffsetInOldFile - (prevOffsetInOldFile + prevLengthInBytes));
+ * SVLI (OffsetInNewFile - OffsetInOldFile);
+ * UVLI LengthInBytes;
+ * UVLI unknown_count; (a count of pairs of values related to the reversal of special
+ * processing done to improve compression of 32-bit executables)
+ * UVLI interleave_count; (present only if PATCH_OPTION_INTERLEAVE_FILES is set in options)
+ * UVLI interleave_values[interleave_count * 3 - 1];
+ * UVLI lzxd_input_size;
+ *
+ * For each source file:
+ * UINT16 lzxd_block[lzxd_input_size / 2]; (NOT always 16-bit aligned)
+ *
+ * UINT32 crc_hack; (rounds out the entire file crc32 to 0)
+*/
+
+
+#define MAX_RANGES 255
+
+struct input_file_info {
+ size_t input_size;
+ DWORD crc32;
+ BYTE ignore_range_count;
+ BYTE retain_range_count;
+ PATCH_IGNORE_RANGE ignore_table[MAX_RANGES];
+ PATCH_RETAIN_RANGE retain_table[MAX_RANGES];
+ size_t unknown_count;
+ size_t stream_size;
+ const BYTE *stream_start;
+ int next_i;
+ int next_r;
+};
+
+struct patch_file_header {
+ DWORD flags;
+ DWORD timestamp;
+ size_t patched_size;
+ DWORD patched_crc32;
+ unsigned input_file_count;
+ struct input_file_info *file_table;
+ const BYTE *src;
+ const BYTE *end;
+ DWORD err;
+};
+
+
+/* Currently supported options. Some such as PATCH_OPTION_FAIL_IF_BIGGER don't
+ * affect decoding but can get recorded in the patch file anyway */
+#define PATCH_OPTION_SUPPORTED_FLAGS ( \
+ PATCH_OPTION_USE_LZX_A \
+ | PATCH_OPTION_USE_LZX_B \
+ | PATCH_OPTION_USE_LZX_LARGE \
+ | PATCH_OPTION_NO_BINDFIX \
+ | PATCH_OPTION_NO_LOCKFIX \
+ | PATCH_OPTION_NO_REBASE \
+ | PATCH_OPTION_FAIL_IF_SAME_FILE \
+ | PATCH_OPTION_FAIL_IF_BIGGER \
+ | PATCH_OPTION_NO_CHECKSUM \
+ | PATCH_OPTION_NO_RESTIMEFIX \
+ | PATCH_OPTION_NO_TIMESTAMP \
+ | PATCH_OPTION_EXTRA_FLAGS)
+
+
+/* read a byte-aligned little-endian UINT32 from input and set error if eof
+ */
+static inline UINT32 read_raw_uint32(struct patch_file_header *ph)
+{
+ const BYTE *src = ph->src;
+
+ ph->src += 4;
+ if (ph->src > ph->end)
+ {
+ ph->err = ERROR_PATCH_CORRUPT;
+ return 0;
+ }
+ return src[0]
+ | (src[1] << 8)
+ | (src[2] << 16)
+ | (src[3] << 24);
+}
+
+/* Read a variable-length integer from a sequence of bytes terminated by
+ * a value with bit 7 set. Set error if invalid or eof */
+static UINT64 read_uvli(struct patch_file_header *ph)
+{
+ const BYTE *vli = ph->src;
+ UINT64 n;
+ ptrdiff_t i;
+ ptrdiff_t limit = my_min(ph->end - vli, 9);
+
+ if (ph->src >= ph->end)
+ {
+ ph->err = ERROR_PATCH_CORRUPT;
+ return 0;
+ }
+
+ n = vli[0] & 0x7F;
+ for (i = 1; i < limit && vli[i - 1] < 0x80; ++i)
+ n += (UINT64)(vli[i] & 0x7F) << (7 * i);
+
+ if (vli[i - 1] < 0x80)
+ {
+ TRACE("exceeded maximum vli size\n");
+ ph->err = ERROR_PATCH_CORRUPT;
+ return 0;
+ }
+
+ ph->src += i;
+
+ return n;
+}
+
+/* Signed variant of the above. First byte sign flag is 0x40.
+ */
+static INT64 read_svli(struct patch_file_header *ph)
+{
+ const BYTE *vli = ph->src;
+ INT64 n;
+ ptrdiff_t i;
+ ptrdiff_t limit = my_min(ph->end - vli, 9);
+
+ if (ph->src >= ph->end)
+ {
+ ph->err = ERROR_PATCH_CORRUPT;
+ return 0;
+ }
+
+ n = vli[0] & 0x3F;
+ for (i = 1; i < limit && vli[i - 1] < 0x80; ++i)
+ n += (INT64)(vli[i] & 0x7F) << (7 * i - 1);
+
+ if (vli[i - 1] < 0x80)
+ {
+ TRACE("exceeded maximum vli size\n");
+ ph->err = ERROR_PATCH_CORRUPT;
+ return 0;
+ }
+
+ if (vli[0] & 0x40)
+ n = -n;
+
+ ph->src += i;
+
+ return n;
+}
+
+static int compare_ignored_range(const void *a, const void *b)
+{
+ LONG delta = ((PATCH_IGNORE_RANGE*)a)->OffsetInOldFile - ((PATCH_IGNORE_RANGE*)b)->OffsetInOldFile;
+ if (delta > 0)
+ return 1;
+ if (delta < 0)
+ return -1;
+ return 0;
+}
+
+static int compare_retained_range_old(const void *a, const void *b)
+{
+ LONG delta = ((PATCH_RETAIN_RANGE*)a)->OffsetInOldFile - ((PATCH_RETAIN_RANGE*)b)->OffsetInOldFile;
+ if (delta > 0)
+ return 1;
+ if (delta < 0)
+ return -1;
+ return 0;
+}
+
+static int compare_retained_range_new(const void *a, const void *b)
+{
+ LONG delta = ((PATCH_RETAIN_RANGE*)a)->OffsetInNewFile - ((PATCH_RETAIN_RANGE*)b)->OffsetInNewFile;
+ if (delta > 0)
+ return 1;
+ if (delta < 0)
+ return -1;
+ return 0;
+}
+
+static int read_header(struct patch_file_header *ph, const BYTE *buf, size_t size)
+{
+ unsigned fileno;
+
+ ph->src = buf;
+ ph->end = buf + size;
+
+ ph->file_table = NULL;
+ ph->err = ERROR_SUCCESS;
+
+ if (read_raw_uint32(ph) != PA19_FILE_MAGIC)
+ {
+ TRACE("no PA19 signature\n");
+ ph->err = ERROR_PATCH_CORRUPT;
+ return -1;
+ }
+
+ ph->flags = read_raw_uint32(ph);
+ if ((ph->flags & PATCH_OPTION_SUPPORTED_FLAGS) != ph->flags)
+ {
+ FIXME("unsupported option flag(s): 0x%08x\n", ph->flags & ~PATCH_OPTION_SUPPORTED_FLAGS);
+ ph->err = ERROR_PATCH_PACKAGE_UNSUPPORTED;
+ return -1;
+ }
+
+ /* additional 32-bit flag field */
+ if (ph->flags & PATCH_OPTION_EXTRA_FLAGS)
+ {
+ TRACE("skipping extra flag field\n");
+ (void)read_raw_uint32(ph);
+ }
+
+ /* the meaning of PATCH_OPTION_NO_TIMESTAMP is inverted for decoding */
+ if(ph->flags & PATCH_OPTION_NO_TIMESTAMP)
+ ph->timestamp = read_raw_uint32(ph);
+
+ /* not sure what this value is for but it seems to have no effect on output */
+ if (!(ph->flags & PATCH_OPTION_NO_REBASE))
+ {
+ TRACE("skipping rebase field\n");
+ (void)read_uvli(ph);
+ }
+
+ ph->patched_size = (size_t)read_uvli(ph);
+ TRACE("patched file size will be %u\n", (unsigned)ph->patched_size);
+ ph->patched_crc32 = read_raw_uint32(ph);
+
+ ph->input_file_count = *ph->src;
+ ++ph->src;
+ TRACE("patch supports %u old file(s)\n", ph->input_file_count);
+ /* if no old file used, input_file_count is still 1 */
+ if (ph->input_file_count == 0)
+ {
+ ph->err = ERROR_PATCH_CORRUPT;
+ return -1;
+ }
+
+ if (ph->err != ERROR_SUCCESS)
+ return -1;
+
+ ph->file_table = calloc(ph->input_file_count, sizeof(struct input_file_info));
+ if (ph->file_table == NULL)
+ {
+ ph->err = ERROR_OUTOFMEMORY;
+ return -1;
+ }
+
+ for (fileno = 0; fileno < ph->input_file_count; ++fileno) {
+ struct input_file_info *fi = ph->file_table + fileno;
+ ptrdiff_t delta;
+ unsigned i;
+
+ delta = (ptrdiff_t)read_svli(ph);
+ fi->input_size = ph->patched_size + delta;
+
+ fi->crc32 = read_raw_uint32(ph);
+
+ fi->ignore_range_count = *ph->src;
+ ++ph->src;
+ TRACE("found %u range(s) to ignore\n", fi->ignore_range_count);
+
+ for (i = 0; i < fi->ignore_range_count; ++i) {
+ PATCH_IGNORE_RANGE *ir = fi->ignore_table + i;
+
+ ir->OffsetInOldFile = (LONG)read_svli(ph);
+ ir->LengthInBytes = (ULONG)read_uvli(ph);
+
+ if (i != 0)
+ {
+ ir->OffsetInOldFile += fi->ignore_table[i - 1].OffsetInOldFile
+ + fi->ignore_table[i - 1].LengthInBytes;
+ }
+ if (ir->OffsetInOldFile > fi->input_size
+ || ir->OffsetInOldFile + ir->LengthInBytes > fi->input_size
+ || ir->LengthInBytes > fi->input_size)
+ {
+ ph->err = ERROR_PATCH_CORRUPT;
+ return -1;
+ }
+ }
+
+ fi->retain_range_count = *ph->src;
+ ++ph->src;
+ TRACE("found %u range(s) to retain\n", fi->retain_range_count);
+
+ for (i = 0; i < fi->retain_range_count; ++i) {
+ PATCH_RETAIN_RANGE *rr = fi->retain_table + i;
+
+ rr->OffsetInOldFile = (LONG)read_svli(ph);
+ if (i != 0)
+ rr->OffsetInOldFile +=
+ fi->retain_table[i - 1].OffsetInOldFile + fi->retain_table[i - 1].LengthInBytes;
+
+ rr->OffsetInNewFile = rr->OffsetInOldFile + (LONG)read_svli(ph);
+ rr->LengthInBytes = (ULONG)read_uvli(ph);
+
+ if (rr->OffsetInOldFile > fi->input_size
+ || rr->OffsetInOldFile + rr->LengthInBytes > fi->input_size
+ || rr->OffsetInNewFile > ph->patched_size
+ || rr->OffsetInNewFile + rr->LengthInBytes > ph->patched_size
+ || rr->LengthInBytes > ph->patched_size)
+ {
+ ph->err = ERROR_PATCH_CORRUPT;
+ return -1;
+ }
+
+ /* ranges in new file must be equal and in the same order for all source files */
+ if (fileno != 0)
+ {
+ PATCH_RETAIN_RANGE *rr_0 = ph->file_table[0].retain_table + i;
+ if (rr->OffsetInNewFile != rr_0->OffsetInNewFile
+ || rr->LengthInBytes != rr_0->LengthInBytes)
+ {
+ ph->err = ERROR_PATCH_CORRUPT;
+ return -1;
+ }
+ }
+ }
+
+ fi->unknown_count = (size_t)read_uvli(ph);
+ if (fi->unknown_count)
+ {
+ FIXME("special processing of 32-bit executables not implemented.\n");
+ ph->err = ERROR_PATCH_PACKAGE_UNSUPPORTED;
+ return -1;
+ }
+ fi->stream_size = (size_t)read_uvli(ph);
+ }
+
+ for (fileno = 0; fileno < ph->input_file_count; ++fileno)
+ {
+ struct input_file_info *fi = ph->file_table + fileno;
+
+ qsort(fi->ignore_table, fi->ignore_range_count, sizeof(fi->ignore_table[0]), compare_ignored_range);
+ qsort(fi->retain_table, fi->retain_range_count, sizeof(fi->retain_table[0]), compare_retained_range_old);
+
+ fi->stream_start = ph->src;
+ ph->src += fi->stream_size;
+ }
+
+ /* skip the crc adjustment field */
+ ph->src = my_min(ph->src + 4, ph->end);
+
+ {
+ UINT32 crc = compute_crc32(0, buf, ph->src - buf) ^ 0xFFFFFFFF;
+ if (crc != 0)
+ {
+ TRACE("patch file crc32 failed\n");
+ if (ph->src < ph->end)
+ FIXME("probable header parsing error\n");
+ ph->err = ERROR_PATCH_CORRUPT;
+ }
+ }
+
+ return (ph->err == ERROR_SUCCESS) ? 0 : -1;
+}
+
+static void free_header(struct patch_file_header *ph)
+{
+ free(ph->file_table);
+}
+
+#define TICKS_PER_SEC 10000000
+#define SEC_TO_UNIX_EPOCH 11644473600LL
+
+static void posix_time_to_file_time(ULONG timestamp, FILETIME *ft)
+{
+ UINT64 ticks = ((UINT64)timestamp + SEC_TO_UNIX_EPOCH) * TICKS_PER_SEC;
+ ft->dwLowDateTime = (DWORD)ticks;
+ ft->dwHighDateTime = (DWORD)(ticks >> 32);
+}
+
+/* Get the next range to ignore in the old file.
+ * fi->next_i must be initialized before use */
+static ULONG next_ignored_range(const struct input_file_info *fi, size_t index, ULONG old_file_size, ULONG *end)
+{
+ ULONG start = old_file_size;
+ *end = old_file_size;
+ /* if patching is unnecessary, the ignored ranges are skipped during crc calc */
+ if (fi->next_i < fi->ignore_range_count && fi->stream_size != 0)
+ {
+ start = fi->ignore_table[fi->next_i].OffsetInOldFile;
+ *end = my_max(start + fi->ignore_table[fi->next_i].LengthInBytes, index);
+ start = my_max(start, index);
+ }
+ return start;
+}
+
+/* Get the next range to retain from the old file.
+ * fi->next_r must be initialized before use */
+static ULONG next_retained_range_old(const struct input_file_info *fi, size_t index, ULONG old_file_size, ULONG *end)
+{
+ ULONG start = old_file_size;
+ *end = old_file_size;
+ if (fi->next_r < fi->retain_range_count)
+ {
+ start = fi->retain_table[fi->next_r].OffsetInOldFile;
+ *end = my_max(start + fi->retain_table[fi->next_r].LengthInBytes, index);
+ start = my_max(start, index);
+ }
+ return start;
+}
+
+/* Get the next range to retain in the new file.
+ * fi->next_r must be initialized before use */
+static ULONG next_retained_range_new(const struct input_file_info *fi, size_t index, ULONG new_file_size, ULONG *end)
+{
+ ULONG start = new_file_size;
+ *end = new_file_size;
+ if (fi->next_r < fi->retain_range_count)
+ {
+ start = fi->retain_table[fi->next_r].OffsetInNewFile;
+ *end = my_max(start + fi->retain_table[fi->next_r].LengthInBytes, index);
+ start = my_max(start, index);
+ }
+ return start;
+}
+
+/* Find the next range in the old file which must be assumed zero-filled during crc32 calc
+ */
+static ULONG next_zeroed_range(struct input_file_info *fi, size_t index, ULONG old_file_size, ULONG *end)
+{
+ ULONG start = old_file_size;
+ ULONG end_i;
+ ULONG start_i;
+ ULONG end_r;
+ ULONG start_r;
+
+ *end = old_file_size;
+
+ start_i = next_ignored_range(fi, index, old_file_size, &end_i);
+ start_r = next_retained_range_old(fi, index, old_file_size, &end_r);
+
+ if (start_i < start_r)
+ {
+ start = start_i;
+ *end = end_i;
+ ++fi->next_i;
+ }
+ else
+ {
+ start = start_r;
+ *end = end_r;
+ ++fi->next_r;
+ }
+ return start;
+}
+
+/* Use the crc32 of the input file to match the file with an entry in the patch file table
+ */
+struct input_file_info *find_matching_old_file(const struct patch_file_header *ph, const BYTE *old_file_view, ULONG old_file_size)
+{
+ unsigned i;
+
+ for (i = 0; i < ph->input_file_count; ++i)
+ {
+ DWORD crc32 = 0;
+ ULONG index;
+
+ if (ph->file_table[i].input_size != old_file_size)
+ continue;
+
+ ph->file_table[i].next_i = 0;
+ for (index = 0; index < old_file_size; )
+ {
+ ULONG end;
+ ULONG start = next_zeroed_range(ph->file_table + i, index, old_file_size, &end);
+ crc32 = compute_crc32(crc32, old_file_view + index, start - index);
+ crc32 = compute_zero_crc32(crc32, end - start);
+ index = end;
+ }
+ if (ph->file_table[i].crc32 == crc32)
+ return ph->file_table + i;
+ }
+ return NULL;
+}
+
+/* Zero-fill ignored ranges in the old file data for decoder matching
+ */
+static void zero_fill_ignored_ranges(BYTE *old_file_buf, const struct input_file_info *fi)
+{
+ size_t i;
+ for (i = 0; i < fi->ignore_range_count; ++i)
+ {
+ memset(old_file_buf + fi->ignore_table[i].OffsetInOldFile,
+ 0,
+ fi->ignore_table[i].LengthInBytes);
+ }
+}
+
+/* Zero-fill retained ranges in the old file data for decoder matching
+ */
+static void zero_fill_retained_ranges(BYTE *old_file_buf, BYTE *new_file_buf, const struct input_file_info *fi)
+{
+ size_t i;
+ for (i = 0; i < fi->retain_range_count; ++i)
+ {
+ memset(old_file_buf + fi->retain_table[i].OffsetInOldFile,
+ 0,
+ fi->retain_table[i].LengthInBytes);
+ }
+}
+
+/* Copy the retained ranges to the new file buffer
+ */
+static void apply_retained_ranges(const BYTE *old_file_buf, BYTE *new_file_buf, const struct input_file_info *fi)
+{
+ size_t i;
+
+ if (old_file_buf == NULL)
+ return;
+
+ for (i = 0; i < fi->retain_range_count; ++i)
+ {
+ memcpy(new_file_buf + fi->retain_table[i].OffsetInNewFile,
+ old_file_buf + fi->retain_table[i].OffsetInOldFile,
+ fi->retain_table[i].LengthInBytes);
+ }
+}
+
+/* Compute the crc32 for the new file, assuming zero for the retained ranges
+ */
+static DWORD compute_target_crc32(struct input_file_info *fi, const BYTE *new_file_buf, ULONG new_file_size)
+{
+ DWORD crc32 = 0;
+ ULONG index;
+
+ qsort(fi->retain_table, fi->retain_range_count, sizeof(fi->retain_table[0]), compare_retained_range_new);
+ fi->next_r = 0;
+
+ for (index = 0; index < new_file_size; )
+ {
+ ULONG end;
+ ULONG start = next_retained_range_new(fi, index, new_file_size, &end);
+ ++fi->next_r;
+ crc32 = compute_crc32(crc32, new_file_buf + index, start - index);
+ crc32 = compute_zero_crc32(crc32, end - start);
+ index = end;
+ }
+ return crc32;
+}
+
+DWORD apply_patch_to_file_by_buffers(const BYTE *patch_file_view, const ULONG patch_file_size,
+ const BYTE *old_file_view, ULONG old_file_size,
+ BYTE **pnew_file_buf, const ULONG new_file_buf_size, ULONG *new_file_size,
+ FILETIME *new_file_time,
+ const ULONG apply_option_flags,
+ PATCH_PROGRESS_CALLBACK *progress_fn, void *progress_ctx,
+ const BOOL test_header_only)
+{
+ DWORD err = ERROR_SUCCESS;
+ struct input_file_info *file_info;
+ struct patch_file_header ph;
+ size_t buf_size;
+ BYTE *new_file_buf = NULL;
+ BYTE *decode_buf = NULL;
+
+ if (pnew_file_buf == NULL)
+ {
+ if (!test_header_only && !(apply_option_flags & APPLY_OPTION_TEST_ONLY))
+ return ERROR_INVALID_PARAMETER;
+ }
+ else
+ {
+ new_file_buf = *pnew_file_buf;
+ }
+
+ if (old_file_view == NULL)
+ old_file_size = 0;
+
+ if (read_header(&ph, patch_file_view, patch_file_size))
+ {
+ err = ph.err;
+ goto free_patch_header;
+ }
+
+ if (new_file_size != NULL)
+ *new_file_size = (ULONG)ph.patched_size;
+
+ if (new_file_buf != NULL && new_file_buf_size < ph.patched_size)
+ {
+ err = ERROR_INSUFFICIENT_BUFFER;
+ goto free_patch_header;
+ }
+
+ file_info = find_matching_old_file(&ph, old_file_view, old_file_size);
+ if (file_info == NULL)
+ {
+ err = ERROR_PATCH_WRONG_FILE;
+ goto free_patch_header;
+ }
+ if (file_info->input_size != old_file_size)
+ {
+ err = ERROR_PATCH_CORRUPT;
+ goto free_patch_header;
+ }
+ if (file_info->stream_size == 0 && (apply_option_flags & APPLY_OPTION_FAIL_IF_EXACT))
+ {
+ err = ERROR_PATCH_NOT_NECESSARY;
+ goto free_patch_header;
+ }
+ if (file_info->stream_size != 0
+ && file_info->input_size > ((ph.flags & PATCH_OPTION_USE_LZX_LARGE) ? MAX_LARGE_WINDOW : MAX_NORMAL_WINDOW))
+ {
+ /* interleaved by default but not the same as PATCH_OPTION_INTERLEAVE_FILES */
+ FIXME("interleaved LZXD decompression is not supported.\n");
+ err = ERROR_PATCH_PACKAGE_UNSUPPORTED;
+ goto free_patch_header;
+ }
+
+ if (test_header_only)
+ goto free_patch_header;
+
+ /* missing lzxd stream means it's a header test extract */
+ if (file_info->stream_start + file_info->stream_size > ph.end)
+ {
+ err = ERROR_PATCH_NOT_AVAILABLE;
+ goto free_patch_header;
+ }
+
+ buf_size = old_file_size + ph.patched_size;
+ decode_buf = new_file_buf;
+ if (new_file_buf == NULL || new_file_buf_size < buf_size)
+ {
+ /* decode_buf must have room for both files, so allocate a new buffer if
+ * necessary. This will be returned to the caller if new_file_buf == NULL */
+ decode_buf = VirtualAlloc(NULL, buf_size, MEM_COMMIT, PAGE_READWRITE);
+ if (decode_buf == NULL)
+ {
+ err = GetLastError();
+ goto free_patch_header;
+ }
+ }
+
+ if (old_file_view != NULL)
+ memcpy(decode_buf, old_file_view, file_info->input_size);
+
+ zero_fill_ignored_ranges(decode_buf, file_info);
+ zero_fill_retained_ranges(decode_buf, decode_buf + file_info->input_size, file_info);
+
+ if (file_info->stream_size != 0)
+ {
+ err = decode_lzxd_stream(file_info->stream_start, file_info->stream_size,
+ decode_buf, ph.patched_size, file_info->input_size,
+ ph.flags & PATCH_OPTION_USE_LZX_LARGE,
+ progress_fn, progress_ctx);
+ }
+ else if (file_info->input_size == ph.patched_size)
+ {
+ /* files are identical so copy old to new. copying is avoidable but rare */
+ memcpy(decode_buf + file_info->input_size, decode_buf, ph.patched_size);
+ }
+ else
+ {
+ err = ERROR_PATCH_CORRUPT;
+ goto free_decode_buf;
+ }
+
+ if(err != ERROR_SUCCESS)
+ {
+ if (err == ERROR_PATCH_DECODE_FAILURE)
+ FIXME("decode failure: data corruption or bug.\n");
+ goto free_decode_buf;
+ }
+
+ apply_retained_ranges(old_file_view, decode_buf + file_info->input_size, file_info);
+
+ if (ph.patched_crc32 != compute_target_crc32(file_info, decode_buf + file_info->input_size, ph.patched_size))
+ {
+ err = ERROR_PATCH_CORRUPT;
+ goto free_decode_buf;
+ }
+
+ /* retained ranges must be ignored for this test */
+ if ((apply_option_flags & APPLY_OPTION_FAIL_IF_EXACT)
+ && file_info->input_size == ph.patched_size
+ && memcmp(decode_buf, decode_buf + file_info->input_size, ph.patched_size) == 0)
+ {
+ err = ERROR_PATCH_NOT_NECESSARY;
+ goto free_decode_buf;
+ }
+
+ if (!(apply_option_flags & APPLY_OPTION_TEST_ONLY))
+ {
+ if (new_file_buf == NULL)
+ {
+ /* caller will VirtualFree the buffer */
+ new_file_buf = decode_buf;
+ *pnew_file_buf = new_file_buf;
+ }
+ memmove(new_file_buf, decode_buf + old_file_size, ph.patched_size);
+ }
+
+ if (new_file_time != NULL)
+ {
+ new_file_time->dwLowDateTime = 0;
+ new_file_time->dwHighDateTime = 0;
+
+ /* the meaning of PATCH_OPTION_NO_TIMESTAMP is inverted for decoding */
+ if (ph.flags & PATCH_OPTION_NO_TIMESTAMP)
+ posix_time_to_file_time(ph.timestamp, new_file_time);
+ }
+
+free_decode_buf:
+ if(decode_buf != NULL && decode_buf != new_file_buf)
+ VirtualFree(decode_buf, 0, MEM_RELEASE);
+
+free_patch_header:
+ free_header(&ph);
+
+ return err;
+}
+
+BOOL apply_patch_to_file_by_handles(HANDLE patch_file_hndl, HANDLE old_file_hndl, HANDLE new_file_hndl,
+ const ULONG apply_option_flags,
+ PATCH_PROGRESS_CALLBACK *progress_fn, void *progress_ctx,
+ const BOOL test_header_only)
+{
+ LARGE_INTEGER patch_size;
+ LARGE_INTEGER old_size;
+ HANDLE patch_map;
+ HANDLE old_map = NULL;
+ BYTE *patch_buf;
+ const BYTE *old_buf = NULL;
+ BYTE *new_buf = NULL;
+ ULONG new_size;
+ FILETIME new_time;
+ BOOL res = FALSE;
+ DWORD err = ERROR_SUCCESS;
+
+ /* truncate the output file if required, or set the handle to invalid */
+ if (test_header_only || (apply_option_flags & APPLY_OPTION_TEST_ONLY))
+ {
+ new_file_hndl = INVALID_HANDLE_VALUE;
+ }
+ else if (SetFilePointer(new_file_hndl, 0, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER
+ || !SetEndOfFile(new_file_hndl))
+ {
+ err = GetLastError();
+ return FALSE;
+ }
+
+ if (patch_file_hndl == INVALID_HANDLE_VALUE)
+ {
+ SetLastError(ERROR_INVALID_HANDLE);
+ return FALSE;
+ }
+
+ old_size.QuadPart = 0;
+ if (!GetFileSizeEx(patch_file_hndl, &patch_size)
+ || (old_file_hndl != INVALID_HANDLE_VALUE && !GetFileSizeEx(old_file_hndl, &old_size)))
+ {
+ /* Last error set by API */
+ return FALSE;
+ }
+
+ patch_map = CreateFileMappingW(patch_file_hndl, NULL, PAGE_READONLY, 0, 0, NULL);
+ if (patch_map == NULL)
+ {
+ /* Last error set by API */
+ return FALSE;
+ }
+
+ if (old_file_hndl != INVALID_HANDLE_VALUE)
+ {
+ old_map = CreateFileMappingW(old_file_hndl, NULL, PAGE_READONLY, 0, 0, NULL);
+ if (old_map == NULL)
+ {
+ err = GetLastError();
+ goto close_patch_map;
+ }
+ }
+
+ patch_buf = MapViewOfFile(patch_map, FILE_MAP_READ, 0, 0, (SIZE_T)patch_size.QuadPart);
+ if (patch_buf == NULL)
+ {
+ err = GetLastError();
+ goto close_old_map;
+ }
+
+ if (old_size.QuadPart)
+ {
+ old_buf = MapViewOfFile(old_map, FILE_MAP_READ, 0, 0, (SIZE_T)old_size.QuadPart);
+ if (old_buf == NULL)
+ {
+ err = GetLastError();
+ goto unmap_patch_buf;
+ }
+ }
+
+ err = apply_patch_to_file_by_buffers(patch_buf, (ULONG)patch_size.QuadPart,
+ old_buf, (ULONG)old_size.QuadPart,
+ &new_buf, 0, &new_size,
+ &new_time,
+ apply_option_flags, progress_fn, progress_ctx,
+ test_header_only);
+
+ if(err)
+ goto free_new_buf;
+
+ res = TRUE;
+
+ if(new_file_hndl != INVALID_HANDLE_VALUE)
+ {
+ DWORD Written = 0;
+ res = WriteFile(new_file_hndl, new_buf, new_size, &Written, NULL);
+
+ if (!res)
+ err = GetLastError();
+ else if (new_time.dwLowDateTime || new_time.dwHighDateTime)
+ SetFileTime(new_file_hndl, &new_time, NULL, &new_time);
+ }
+
+free_new_buf:
+ if (new_buf != NULL)
+ VirtualFree(new_buf, 0, MEM_RELEASE);
+
+ if (old_buf != NULL)
+ UnmapViewOfFile(old_buf);
+
+unmap_patch_buf:
+ UnmapViewOfFile(patch_buf);
+
+close_old_map:
+ if (old_map != NULL)
+ CloseHandle(old_map);
+
+close_patch_map:
+ CloseHandle(patch_map);
+
+ SetLastError(err);
+
+ return res;
+}
+
+BOOL apply_patch_to_file(LPCWSTR patch_file_name, LPCWSTR old_file_name, LPCWSTR new_file_name,
+ const ULONG apply_option_flags,
+ PATCH_PROGRESS_CALLBACK *progress_fn, void *progress_ctx,
+ const BOOL test_header_only)
+{
+ HANDLE patch_hndl;
+ HANDLE old_hndl = INVALID_HANDLE_VALUE;
+ HANDLE new_hndl = INVALID_HANDLE_VALUE;
+ BOOL res = FALSE;
+ DWORD err = ERROR_SUCCESS;
+
+ patch_hndl = CreateFileW(patch_file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+ if (patch_hndl == INVALID_HANDLE_VALUE)
+ {
+ /* last error set by CreateFileW */
+ return FALSE;
+ }
+
+ if (old_file_name != NULL)
+ {
+ old_hndl = CreateFileW(old_file_name, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
+ if (old_hndl == INVALID_HANDLE_VALUE)
+ {
+ err = GetLastError();
+ goto close_patch_file;
+ }
+ }
+
+ if (!test_header_only && !(apply_option_flags & APPLY_OPTION_TEST_ONLY))
+ {
+ new_hndl = CreateFileW(new_file_name, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);
+ if (new_hndl == INVALID_HANDLE_VALUE)
+ {
+ err = GetLastError();
+ goto close_old_file;
+ }
+ }
+
+ res = apply_patch_to_file_by_handles(patch_hndl, old_hndl, new_hndl, apply_option_flags, progress_fn, progress_ctx, test_header_only);
+ if(!res)
+ err = GetLastError();
+
+ if (new_hndl != INVALID_HANDLE_VALUE)
+ {
+ CloseHandle(new_hndl);
+ if (!res)
+ DeleteFileW(new_file_name);
+ }
+
+close_old_file:
+ if (old_hndl != INVALID_HANDLE_VALUE)
+ CloseHandle(old_hndl);
+
+close_patch_file:
+ CloseHandle(patch_hndl);
+
+ /* set last error even on success as per windows */
+ SetLastError(err);
+
+ return res;
+}
diff --git a/dlls/mspatcha/pa19.h b/dlls/mspatcha/pa19.h
new file mode 100755
index 0000000..9a9d0f3
--- /dev/null
+++ b/dlls/mspatcha/pa19.h
@@ -0,0 +1,52 @@
+/*
+ * PatchAPI PA19 file format handlers
+ *
+ * Copyright 2019 Conor McCarthy
+ *
+ * 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
+ *
+ *
+ * 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
+ */
+
+DWORD apply_patch_to_file_by_buffers(const BYTE *patch_file_view, const ULONG patch_file_size,
+ const BYTE *old_file_view, ULONG old_file_size,
+ BYTE **new_file_buf, const ULONG new_file_buf_size, ULONG *new_file_size,
+ FILETIME *new_file_time,
+ const ULONG apply_option_flags,
+ PATCH_PROGRESS_CALLBACK *progress_fn, void *progress_ctx,
+ const BOOL test_header_only);
+
+BOOL apply_patch_to_file_by_handles(HANDLE patch_file_hndl, HANDLE old_file_hndl, HANDLE new_file_hndl,
+ const ULONG apply_option_flags,
+ PATCH_PROGRESS_CALLBACK *progress_fn, void *progress_ctx,
+ const BOOL test_header_only);
+
+BOOL apply_patch_to_file(LPCWSTR patch_file_name, LPCWSTR old_file_name, LPCWSTR new_file_name,
+ const ULONG apply_option_flags,
+ PATCH_PROGRESS_CALLBACK *progress_fn, void *progress_ctx,
+ const BOOL test_header_only);
diff --git a/include/patchapi.h b/include/patchapi.h
index 5adaf0a..1ccdf9d 100644
--- a/include/patchapi.h
+++ b/include/patchapi.h
@@ -1,5 +1,6 @@
/*
* Copyright 2011 Hans Leidekker for CodeWeavers
+ * Copyright 2019 Conor McCarthy
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -23,11 +24,33 @@
extern "C" {
#endif
+#define PATCH_OPTION_USE_LZX_A 0x00000001
+#define PATCH_OPTION_USE_LZX_B 0x00000002
+#define PATCH_OPTION_USE_LZX_LARGE 0x00000004 /* raise maximum window from 8 -> 32 Mb */
+
+#define PATCH_OPTION_NO_BINDFIX 0x00010000
+#define PATCH_OPTION_NO_LOCKFIX 0x00020000
+#define PATCH_OPTION_NO_REBASE 0x00040000
+#define PATCH_OPTION_FAIL_IF_SAME_FILE 0x00080000
+#define PATCH_OPTION_FAIL_IF_BIGGER 0x00100000
+#define PATCH_OPTION_NO_CHECKSUM 0x00200000
+#define PATCH_OPTION_NO_RESTIMEFIX 0x00400000
+#define PATCH_OPTION_NO_TIMESTAMP 0x00800000
+#define PATCH_OPTION_INTERLEAVE_FILES 0x40000000
+#define PATCH_OPTION_RESERVED1 0x80000000
+
#define APPLY_OPTION_FAIL_IF_EXACT 0x00000001
#define APPLY_OPTION_FAIL_IF_CLOSE 0x00000002
#define APPLY_OPTION_TEST_ONLY 0x00000004
#define APPLY_OPTION_VALID_FLAGS 0x00000007
+#define ERROR_PATCH_DECODE_FAILURE 0xC00E4101
+#define ERROR_PATCH_CORRUPT 0xC00E4102
+#define ERROR_PATCH_NEWER_FORMAT 0xC00E4103
+#define ERROR_PATCH_WRONG_FILE 0xC00E4104
+#define ERROR_PATCH_NOT_NECESSARY 0xC00E4105
+#define ERROR_PATCH_NOT_AVAILABLE 0xC00E4106
+
typedef struct _PATCH_IGNORE_RANGE
{
ULONG OffsetInOldFile;
@@ -41,16 +64,66 @@ typedef struct _PATCH_RETAIN_RANGE
ULONG OffsetInNewFile;
} PATCH_RETAIN_RANGE, *PPATCH_RETAIN_RANGE;
+typedef struct _PATCH_INTERLEAVE_MAP {
+ ULONG CountRanges;
+ struct {
+ ULONG OldOffset;
+ ULONG OldLength;
+ ULONG NewLength;
+ } Range[1];
+} PATCH_INTERLEAVE_MAP, *PPATCH_INTERLEAVE_MAP;
+
+typedef BOOL(CALLBACK PATCH_SYMLOAD_CALLBACK)(ULONG, LPCSTR, ULONG, ULONG, ULONG, ULONG, ULONG, PVOID);
+
+typedef PATCH_SYMLOAD_CALLBACK *PPATCH_SYMLOAD_CALLBACK;
+
+typedef struct _PATCH_OPTION_DATA {
+ ULONG SizeOfThisStruct;
+ ULONG SymbolOptionFlags;
+ LPCSTR NewFileSymbolPath;
+ LPCSTR *OldFileSymbolPathArray;
+ ULONG ExtendedOptionFlags;
+ PPATCH_SYMLOAD_CALLBACK SymLoadCallback;
+ PVOID SymLoadContext;
+ PPATCH_INTERLEAVE_MAP* InterleaveMapArray;
+ ULONG MaxLzxWindowSize;
+} PATCH_OPTION_DATA, *PPATCH_OPTION_DATA;
+
+typedef BOOL (CALLBACK PATCH_PROGRESS_CALLBACK)(PVOID, ULONG, ULONG);
+
+typedef PATCH_PROGRESS_CALLBACK *PPATCH_PROGRESS_CALLBACK;
+
BOOL WINAPI ApplyPatchToFileA(LPCSTR,LPCSTR,LPCSTR,ULONG);
BOOL WINAPI ApplyPatchToFileW(LPCWSTR,LPCWSTR,LPCWSTR,ULONG);
#define ApplyPatchToFile WINELIB_NAME_AW(ApplyPatchToFile)
+BOOL WINAPI ApplyPatchToFileByHandles(HANDLE, HANDLE, HANDLE, ULONG);
+BOOL WINAPI ApplyPatchToFileExA(LPCSTR, LPCSTR, LPCSTR, ULONG, PPATCH_PROGRESS_CALLBACK, PVOID);
+BOOL WINAPI ApplyPatchToFileExW(LPCWSTR, LPCWSTR, LPCWSTR, ULONG, PPATCH_PROGRESS_CALLBACK, PVOID);
+#define ApplyPatchToFileEx WINELIB_NAME_AW(ApplyPatchToFileEx)
+BOOL WINAPI ApplyPatchToFileByHandlesEx(HANDLE, HANDLE, HANDLE, ULONG, PPATCH_PROGRESS_CALLBACK, PVOID);
+BOOL WINAPI ApplyPatchToFileByBuffers(PBYTE, ULONG, PBYTE, ULONG, PBYTE*, ULONG, ULONG*, FILETIME*, ULONG,
+ PPATCH_PROGRESS_CALLBACK, PVOID);
+
+BOOL WINAPI TestApplyPatchToFileA(LPCSTR, LPCSTR, ULONG);
+BOOL WINAPI TestApplyPatchToFileW(LPCWSTR, LPCWSTR, ULONG);
+#define TestApplyPatchToFile WINELIB_NAME_AW(TestApplyPatchToFile)
+BOOL WINAPI TestApplyPatchToFileByHandles(HANDLE, HANDLE, ULONG);
+BOOL WINAPI TestApplyPatchToFileByBuffers(PBYTE, ULONG, PBYTE, ULONG, ULONG*, ULONG);
+
BOOL WINAPI GetFilePatchSignatureA(LPCSTR, ULONG, PVOID, ULONG, PPATCH_IGNORE_RANGE, ULONG,
PPATCH_RETAIN_RANGE, ULONG, LPSTR);
BOOL WINAPI GetFilePatchSignatureW(LPCWSTR, ULONG, PVOID, ULONG, PPATCH_IGNORE_RANGE, ULONG,
PPATCH_RETAIN_RANGE, ULONG, LPWSTR);
#define GetFilePatchSignature WINELIB_NAME_AW(GetFilePatchSignature)
+BOOL WINAPI GetFilePatchSignatureByHandle(HANDLE, ULONG, PVOID, ULONG, PPATCH_IGNORE_RANGE,
+ ULONG, PPATCH_RETAIN_RANGE, ULONG, LPSTR);
+BOOL WINAPI GetFilePatchSignatureByBuffer(PBYTE, ULONG, ULONG, PVOID, ULONG, PPATCH_IGNORE_RANGE, ULONG,
+ PPATCH_RETAIN_RANGE, ULONG, LPSTR);
+INT WINAPI NormalizeFileForPatchSignature(PVOID, ULONG, ULONG, PATCH_OPTION_DATA*, ULONG,
+ ULONG, ULONG, PPATCH_IGNORE_RANGE, ULONG, PPATCH_RETAIN_RANGE);
+
#ifdef __cplusplus
}
#endif
--
2.7.4
3
4
[PATCH 6/6] wined3d: Pass a wined3d_context_gl structure to context_bind_texture().
by Henri Verbeet 07 May '19
by Henri Verbeet 07 May '19
07 May '19
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/wined3d/context.c | 28 ++++++++++++++--------------
dlls/wined3d/state.c | 3 ++-
dlls/wined3d/surface.c | 18 +++++++++++-------
dlls/wined3d/texture.c | 5 +++--
dlls/wined3d/view.c | 16 +++++++++++-----
dlls/wined3d/wined3d_private.h | 3 ++-
6 files changed, 43 insertions(+), 30 deletions(-)
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 5cc0c57a514..9aa78f591a7 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -2528,22 +2528,20 @@ void context_bind_bo(struct wined3d_context *context, GLenum binding, GLuint nam
GL_EXTCALL(glBindBuffer(binding, name));
}
-void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint name)
+void wined3d_context_gl_bind_texture(struct wined3d_context_gl *context_gl, GLenum target, GLuint name)
{
- const struct wined3d_dummy_textures *textures = &wined3d_device_gl(context->device)->dummy_textures;
- const struct wined3d_gl_info *gl_info = context->gl_info;
- DWORD unit = context->active_texture;
- DWORD old_texture_type = context->texture_type[unit];
+ const struct wined3d_dummy_textures *textures = &wined3d_device_gl(context_gl->c.device)->dummy_textures;
+ const struct wined3d_gl_info *gl_info = context_gl->c.gl_info;
+ GLenum old_texture_type;
+ unsigned int unit;
if (name)
- {
gl_info->gl_ops.gl.p_glBindTexture(target, name);
- }
else
- {
target = GL_NONE;
- }
+ unit = context_gl->c.active_texture;
+ old_texture_type = context_gl->c.texture_type[unit];
if (old_texture_type != target)
{
switch (old_texture_type)
@@ -2588,7 +2586,7 @@ void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint
ERR("Unexpected texture target %#x.\n", old_texture_type);
}
- context->texture_type[unit] = target;
+ context_gl->c.texture_type[unit] = target;
}
checkGLcall("bind texture");
@@ -5558,6 +5556,7 @@ void context_draw_shaded_quad(struct wined3d_context *context, struct wined3d_te
unsigned int sub_resource_idx, const RECT *src_rect, const RECT *dst_rect,
enum wined3d_texture_filter_type filter)
{
+ struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
const struct wined3d_gl_info *gl_info = context->gl_info;
struct wined3d_blt_info info;
unsigned int level, w, h, i;
@@ -5572,7 +5571,7 @@ void context_draw_shaded_quad(struct wined3d_context *context, struct wined3d_te
texture2d_get_blt_info(texture_gl, sub_resource_idx, src_rect, &info);
level = sub_resource_idx % texture_gl->t.level_count;
- context_bind_texture(context, info.bind_target, texture_gl->texture_rgb.name);
+ wined3d_context_gl_bind_texture(context_gl, info.bind_target, texture_gl->texture_rgb.name);
apply_texture_blit_state(gl_info, &texture_gl->texture_rgb, info.bind_target, level, filter);
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MAX_LEVEL, level);
@@ -5635,7 +5634,7 @@ void context_draw_shaded_quad(struct wined3d_context *context, struct wined3d_te
checkGLcall("draw");
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MAX_LEVEL, texture_gl->t.level_count - 1);
- context_bind_texture(context, info.bind_target, 0);
+ wined3d_context_gl_bind_texture(context_gl, info.bind_target, 0);
}
/* Context activation is done by the caller. */
@@ -5643,6 +5642,7 @@ void context_draw_textured_quad(struct wined3d_context *context, struct wined3d_
unsigned int sub_resource_idx, const RECT *src_rect, const RECT *dst_rect,
enum wined3d_texture_filter_type filter)
{
+ struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
const struct wined3d_gl_info *gl_info = context->gl_info;
struct wined3d_blt_info info;
unsigned int level;
@@ -5653,7 +5653,7 @@ void context_draw_textured_quad(struct wined3d_context *context, struct wined3d_
checkGLcall("glEnable(bind_target)");
level = sub_resource_idx % texture_gl->t.level_count;
- context_bind_texture(context, info.bind_target, texture_gl->texture_rgb.name);
+ wined3d_context_gl_bind_texture(context_gl, info.bind_target, texture_gl->texture_rgb.name);
apply_texture_blit_state(gl_info, &texture_gl->texture_rgb, info.bind_target, level, filter);
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MAX_LEVEL, level);
gl_info->gl_ops.gl.p_glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
@@ -5675,5 +5675,5 @@ void context_draw_textured_quad(struct wined3d_context *context, struct wined3d_
gl_info->gl_ops.gl.p_glEnd();
gl_info->gl_ops.gl.p_glTexParameteri(info.bind_target, GL_TEXTURE_MAX_LEVEL, texture_gl->t.level_count - 1);
- context_bind_texture(context, info.bind_target, 0);
+ wined3d_context_gl_bind_texture(context_gl, info.bind_target, 0);
}
diff --git a/dlls/wined3d/state.c b/dlls/wined3d/state.c
index d995fe89b0a..f2ae39e565b 100644
--- a/dlls/wined3d/state.c
+++ b/dlls/wined3d/state.c
@@ -3596,6 +3596,7 @@ static void wined3d_sampler_desc_from_sampler_states(struct wined3d_sampler_desc
* texture states. */
static void sampler(struct wined3d_context *context, const struct wined3d_state *state, DWORD state_id)
{
+ struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
DWORD sampler_idx = state_id - STATE_SAMPLER(0);
DWORD mapped_stage = context->tex_unit_map[sampler_idx];
const struct wined3d_gl_info *gl_info = context->gl_info;
@@ -3653,7 +3654,7 @@ static void sampler(struct wined3d_context *context, const struct wined3d_state
}
else
{
- context_bind_texture(context, GL_NONE, 0);
+ wined3d_context_gl_bind_texture(context_gl, GL_NONE, 0);
if (gl_info->supported[ARB_SAMPLER_OBJECTS])
{
GL_EXTCALL(glBindSampler(mapped_stage, 0));
diff --git a/dlls/wined3d/surface.c b/dlls/wined3d/surface.c
index 48ca35bb3b3..2c5ea75ebbb 100644
--- a/dlls/wined3d/surface.c
+++ b/dlls/wined3d/surface.c
@@ -888,6 +888,7 @@ static void fb_copy_to_texture_direct(struct wined3d_texture_gl *dst_texture, un
struct wined3d_device *device = dst_texture->t.resource.device;
unsigned int src_height, src_level, dst_level;
const struct wined3d_gl_info *gl_info;
+ struct wined3d_context_gl *context_gl;
float xrel, yrel;
struct wined3d_context *context;
BOOL upsidedown = FALSE;
@@ -905,12 +906,13 @@ static void fb_copy_to_texture_direct(struct wined3d_texture_gl *dst_texture, un
}
context = context_acquire(device, &src_texture->t, src_sub_resource_idx);
+ context_gl = wined3d_context_gl(context);
gl_info = context->gl_info;
context_apply_blit_state(context, device);
wined3d_texture_load(&dst_texture->t, context, FALSE);
/* Bind the target texture */
- context_bind_texture(context, dst_texture->target, dst_texture->texture_rgb.name);
+ wined3d_context_gl_bind_texture(context_gl, dst_texture->target, dst_texture->texture_rgb.name);
if (wined3d_resource_is_offscreen(&src_texture->t.resource))
{
TRACE("Reading from an offscreen target\n");
@@ -1008,6 +1010,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_texture_gl *dst_texture,
GLuint src, backup = 0;
float left, right, top, bottom; /* Texture coordinates */
const struct wined3d_gl_info *gl_info;
+ struct wined3d_context_gl *context_gl;
struct wined3d_context *context;
GLenum drawBuffer = GL_BACK;
GLenum offscreen_buffer;
@@ -1023,6 +1026,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_texture_gl *dst_texture,
/* Activate the Proper context for reading from the source surface, set it up for blitting */
context = context_acquire(device, &src_texture->t, src_sub_resource_idx);
+ context_gl = wined3d_context_gl(context);
gl_info = context->gl_info;
context_apply_ffp_blit_state(context, device);
wined3d_texture_load(&dst_texture->t, context, FALSE);
@@ -1060,7 +1064,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_texture_gl *dst_texture,
{
gl_info->gl_ops.gl.p_glGenTextures(1, &backup);
checkGLcall("glGenTextures");
- context_bind_texture(context, GL_TEXTURE_2D, backup);
+ wined3d_context_gl_bind_texture(context_gl, GL_TEXTURE_2D, backup);
texture_target = GL_TEXTURE_2D;
}
else
@@ -1069,7 +1073,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_texture_gl *dst_texture,
* we are reading from the back buffer, the backup can be used as source texture
*/
texture_target = src_target;
- context_bind_texture(context, texture_target, src_texture->texture_rgb.name);
+ wined3d_context_gl_bind_texture(context_gl, texture_target, src_texture->texture_rgb.name);
gl_info->gl_ops.gl.p_glEnable(texture_target);
checkGLcall("glEnable(texture_target)");
@@ -1121,7 +1125,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_texture_gl *dst_texture,
gl_info->gl_ops.gl.p_glGenTextures(1, &src);
checkGLcall("glGenTextures(1, &src)");
- context_bind_texture(context, GL_TEXTURE_2D, src);
+ wined3d_context_gl_bind_texture(context_gl, GL_TEXTURE_2D, src);
/* TODO: Only copy the part that will be read. Use src_rect->left,
* src_rect->bottom as origin, but with the width watch out for power
@@ -1204,7 +1208,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_texture_gl *dst_texture,
}
/* Now read the stretched and upside down image into the destination texture */
- context_bind_texture(context, texture_target, dst_texture->texture_rgb.name);
+ wined3d_context_gl_bind_texture(context_gl, texture_target, dst_texture->texture_rgb.name);
gl_info->gl_ops.gl.p_glCopyTexSubImage2D(texture_target,
0,
dst_rect.left, dst_rect.top, /* xoffset, yoffset */
@@ -1223,7 +1227,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_texture_gl *dst_texture,
gl_info->gl_ops.gl.p_glEnable(GL_TEXTURE_2D);
texture_target = GL_TEXTURE_2D;
}
- context_bind_texture(context, GL_TEXTURE_2D, backup);
+ wined3d_context_gl_bind_texture(context_gl, GL_TEXTURE_2D, backup);
}
else
{
@@ -1233,7 +1237,7 @@ static void fb_copy_to_texture_hwstretch(struct wined3d_texture_gl *dst_texture,
gl_info->gl_ops.gl.p_glEnable(src_target);
texture_target = src_target;
}
- context_bind_texture(context, src_target, src_texture->texture_rgb.name);
+ wined3d_context_gl_bind_texture(context_gl, src_target, src_texture->texture_rgb.name);
}
gl_info->gl_ops.gl.p_glBegin(GL_QUADS);
diff --git a/dlls/wined3d/texture.c b/dlls/wined3d/texture.c
index 949492063d2..b72b8415388 100644
--- a/dlls/wined3d/texture.c
+++ b/dlls/wined3d/texture.c
@@ -928,6 +928,7 @@ void wined3d_gl_texture_swizzle_from_color_fixup(GLint swizzle[4], struct color_
void wined3d_texture_gl_bind(struct wined3d_texture_gl *texture_gl,
struct wined3d_context *context, BOOL srgb)
{
+ struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
const struct wined3d_format *format = texture_gl->t.resource.format;
const struct color_fixup_desc fixup = format->color_fixup;
const struct wined3d_gl_info *gl_info = context->gl_info;
@@ -950,7 +951,7 @@ void wined3d_texture_gl_bind(struct wined3d_texture_gl *texture_gl,
if (gl_tex->name)
{
- context_bind_texture(context, target, gl_tex->name);
+ wined3d_context_gl_bind_texture(context_gl, target, gl_tex->name);
return;
}
@@ -986,7 +987,7 @@ void wined3d_texture_gl_bind(struct wined3d_texture_gl *texture_gl,
gl_tex->base_level = 0;
wined3d_texture_set_dirty(&texture_gl->t);
- context_bind_texture(context, target, gl_tex->name);
+ wined3d_context_gl_bind_texture(context_gl, target, gl_tex->name);
/* For a new texture we have to set the texture levels after binding the
* texture. Beware that texture rectangles do not support mipmapping, but
diff --git a/dlls/wined3d/view.c b/dlls/wined3d/view.c
index 0cfadf7329b..7815e3963a1 100644
--- a/dlls/wined3d/view.c
+++ b/dlls/wined3d/view.c
@@ -172,6 +172,7 @@ static void create_texture_view(struct wined3d_gl_view *view, GLenum view_target
const struct wined3d_format_gl *view_format_gl;
unsigned int level_idx, layer_idx, layer_count;
const struct wined3d_gl_info *gl_info;
+ struct wined3d_context_gl *context_gl;
struct wined3d_context *context;
GLuint texture_name;
@@ -179,6 +180,7 @@ static void create_texture_view(struct wined3d_gl_view *view, GLenum view_target
view->target = view_target;
context = context_acquire(texture_gl->t.resource.device, NULL, 0);
+ context_gl = wined3d_context_gl(context);
gl_info = context->gl_info;
if (!gl_info->supported[ARB_TEXTURE_VIEW])
@@ -218,7 +220,7 @@ static void create_texture_view(struct wined3d_gl_view *view, GLenum view_target
return;
}
- context_bind_texture(context, view->target, view->name);
+ wined3d_context_gl_bind_texture(context_gl, view->target, view->name);
gl_info->gl_ops.gl.p_glTexParameteriv(view->target, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
gl_info->gl_ops.gl.p_glTexParameteri(view->target, GL_DEPTH_STENCIL_TEXTURE_MODE, GL_STENCIL_INDEX);
checkGLcall("initialize stencil view");
@@ -230,7 +232,7 @@ static void create_texture_view(struct wined3d_gl_view *view, GLenum view_target
{
GLint swizzle[4];
- context_bind_texture(context, view->target, view->name);
+ wined3d_context_gl_bind_texture(context_gl, view->target, view->name);
wined3d_gl_texture_swizzle_from_color_fixup(swizzle, view_format->color_fixup);
gl_info->gl_ops.gl.p_glTexParameteriv(view->target, GL_TEXTURE_SWIZZLE_RGBA, swizzle);
checkGLcall("set format swizzle");
@@ -246,6 +248,7 @@ static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_c
struct wined3d_buffer *buffer, const struct wined3d_format *view_format,
unsigned int offset, unsigned int size)
{
+ struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
const struct wined3d_gl_info *gl_info = context->gl_info;
const struct wined3d_format_gl *view_format_gl;
@@ -268,7 +271,7 @@ static void create_buffer_texture(struct wined3d_gl_view *view, struct wined3d_c
view->target = GL_TEXTURE_BUFFER;
gl_info->gl_ops.gl.p_glGenTextures(1, &view->name);
- context_bind_texture(context, GL_TEXTURE_BUFFER, view->name);
+ wined3d_context_gl_bind_texture(context_gl, GL_TEXTURE_BUFFER, view->name);
if (gl_info->supported[ARB_TEXTURE_BUFFER_RANGE])
{
GL_EXTCALL(glTexBufferRange(GL_TEXTURE_BUFFER, view_format_gl->internal,
@@ -827,6 +830,7 @@ HRESULT CDECL wined3d_shader_resource_view_create(const struct wined3d_view_desc
void wined3d_shader_resource_view_gl_bind(struct wined3d_shader_resource_view_gl *view_gl,
unsigned int unit, struct wined3d_sampler *sampler, struct wined3d_context *context)
{
+ struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
const struct wined3d_gl_info *gl_info = context->gl_info;
struct wined3d_texture_gl *texture_gl;
@@ -834,7 +838,7 @@ void wined3d_shader_resource_view_gl_bind(struct wined3d_shader_resource_view_gl
if (view_gl->gl_view.name)
{
- context_bind_texture(context, view_gl->gl_view.target, view_gl->gl_view.name);
+ wined3d_context_gl_bind_texture(context_gl, view_gl->gl_view.target, view_gl->gl_view.name);
wined3d_sampler_bind(sampler, unit, NULL, context);
return;
}
@@ -854,6 +858,8 @@ void wined3d_shader_resource_view_gl_bind(struct wined3d_shader_resource_view_gl
static void shader_resource_view_gl_bind_and_dirtify(struct wined3d_shader_resource_view_gl *view_gl,
struct wined3d_context *context)
{
+ struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
+
if (context->active_texture < ARRAY_SIZE(context->rev_tex_unit_map))
{
DWORD active_sampler = context->rev_tex_unit_map[context->active_texture];
@@ -865,7 +871,7 @@ static void shader_resource_view_gl_bind_and_dirtify(struct wined3d_shader_resou
context_invalidate_compute_state(context, STATE_COMPUTE_SHADER_RESOURCE_BINDING);
context_invalidate_state(context, STATE_GRAPHICS_SHADER_RESOURCE_BINDING);
- context_bind_texture(context, view_gl->gl_view.target, view_gl->gl_view.name);
+ wined3d_context_gl_bind_texture(context_gl, view_gl->gl_view.target, view_gl->gl_view.name);
}
void shader_resource_view_generate_mipmaps(struct wined3d_shader_resource_view *view)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 3934fba4acd..5151a684706 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2044,6 +2044,8 @@ static inline struct wined3d_context_gl *wined3d_context_gl(struct wined3d_conte
return CONTAINING_RECORD(context, struct wined3d_context_gl, c);
}
+void wined3d_context_gl_bind_texture(struct wined3d_context_gl *context_gl,
+ GLenum target, GLuint name) DECLSPEC_HIDDEN;
void wined3d_context_gl_cleanup(struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl,
struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
@@ -2203,7 +2205,6 @@ void context_active_texture(struct wined3d_context *context, const struct wined3
unsigned int unit) DECLSPEC_HIDDEN;
void context_bind_bo(struct wined3d_context *context, GLenum binding, GLuint name) DECLSPEC_HIDDEN;
void context_bind_dummy_textures(const struct wined3d_context *context) DECLSPEC_HIDDEN;
-void context_bind_texture(struct wined3d_context *context, GLenum target, GLuint name) DECLSPEC_HIDDEN;
void context_check_fbo_status(const struct wined3d_context *context, GLenum target) DECLSPEC_HIDDEN;
void context_copy_bo_address(struct wined3d_context *context,
const struct wined3d_bo_address *dst, GLenum dst_binding,
--
2.11.0
1
0
[PATCH 5/6] wined3d: Make the adapter responsible for context destruction and allocation.
by Henri Verbeet 07 May '19
by Henri Verbeet 07 May '19
07 May '19
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/wined3d/adapter_gl.c | 48 ++++++++++++++-
dlls/wined3d/adapter_vk.c | 28 ++++++++-
dlls/wined3d/context.c | 132 +++++++++++++++++++----------------------
dlls/wined3d/directx.c | 30 +++++++++-
dlls/wined3d/wined3d_private.h | 16 ++++-
5 files changed, 176 insertions(+), 78 deletions(-)
diff --git a/dlls/wined3d/adapter_gl.c b/dlls/wined3d/adapter_gl.c
index 972d051a6b2..be21fd8f349 100644
--- a/dlls/wined3d/adapter_gl.c
+++ b/dlls/wined3d/adapter_gl.c
@@ -4273,6 +4273,51 @@ static void adapter_gl_destroy_device(struct wined3d_device *device)
heap_free(device_gl);
}
+static HRESULT adapter_gl_create_context(struct wined3d_swapchain *swapchain, struct wined3d_context **context)
+{
+ struct wined3d_context_gl *context_gl;
+
+ TRACE("swapchain %p, context %p.\n", swapchain, context);
+
+ if (!(context_gl = heap_alloc_zero(sizeof(*context_gl))))
+ return E_OUTOFMEMORY;
+
+ if (FAILED(wined3d_context_gl_init(context_gl, swapchain)))
+ {
+ WARN("Failed to initialise context.\n");
+ heap_free(context_gl);
+ return E_FAIL;
+ }
+
+ TRACE("Created context %p.\n", context_gl);
+ *context = &context_gl->c;
+
+ return WINED3D_OK;
+}
+
+static void adapter_gl_destroy_context(struct wined3d_context *context)
+{
+ struct wined3d_context_gl *context_gl = wined3d_context_gl(context);
+
+ if (context_gl->c.current && context_gl->c.tid != GetCurrentThreadId())
+ {
+ struct wined3d_gl_info *gl_info;
+
+ /* Make a copy of gl_info for wined3d_context_gl_cleanup() use, the
+ * one in wined3d_adapter may go away in the meantime. */
+ gl_info = heap_alloc(sizeof(*gl_info));
+ *gl_info = *context_gl->c.gl_info;
+ context_gl->c.gl_info = gl_info;
+ context_gl->c.destroyed = 1;
+
+ return;
+ }
+
+ wined3d_context_gl_cleanup(context_gl);
+ TlsSetValue(context_get_tls_idx(), NULL);
+ heap_free(context_gl);
+}
+
static void adapter_gl_get_wined3d_caps(const struct wined3d_adapter *adapter, struct wined3d_caps *caps)
{
const struct wined3d_d3d_info *d3d_info = &adapter->d3d_info;
@@ -4558,7 +4603,8 @@ static const struct wined3d_adapter_ops wined3d_adapter_gl_ops =
adapter_gl_destroy,
adapter_gl_create_device,
adapter_gl_destroy_device,
- wined3d_adapter_gl_create_context,
+ adapter_gl_create_context,
+ adapter_gl_destroy_context,
adapter_gl_get_wined3d_caps,
adapter_gl_check_format,
adapter_gl_init_3d,
diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c
index d6438945361..4ef142384cd 100644
--- a/dlls/wined3d/adapter_vk.c
+++ b/dlls/wined3d/adapter_vk.c
@@ -288,9 +288,32 @@ static void adapter_vk_destroy_device(struct wined3d_device *device)
heap_free(device_vk);
}
-static BOOL adapter_vk_create_context(struct wined3d_context *context)
+static HRESULT adapter_vk_create_context(struct wined3d_swapchain *swapchain, struct wined3d_context **context)
{
- return TRUE;
+ struct wined3d_context *context_vk;
+
+ TRACE("swapchain %p, context %p.\n", swapchain, context);
+
+ if (!(context_vk = heap_alloc_zero(sizeof(*context_vk))))
+ return E_OUTOFMEMORY;
+
+ if (FAILED(wined3d_context_vk_init(context_vk, swapchain)))
+ {
+ WARN("Failed to initialise context.\n");
+ heap_free(context_vk);
+ return E_FAIL;
+ }
+
+ TRACE("Created context %p.\n", context_vk);
+ *context = context_vk;
+
+ return WINED3D_OK;
+}
+
+static void adapter_vk_destroy_context(struct wined3d_context *context)
+{
+ wined3d_context_cleanup(context);
+ heap_free(context);
}
static void adapter_vk_get_wined3d_caps(const struct wined3d_adapter *adapter, struct wined3d_caps *caps)
@@ -416,6 +439,7 @@ static const struct wined3d_adapter_ops wined3d_adapter_vk_ops =
adapter_vk_create_device,
adapter_vk_destroy_device,
adapter_vk_create_context,
+ adapter_vk_destroy_context,
adapter_vk_get_wined3d_caps,
adapter_vk_check_format,
adapter_vk_init_3d,
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index fdf7f9ccc65..5cc0c57a514 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -1312,7 +1312,7 @@ static void context_update_window(struct wined3d_context *context)
}
}
-static void wined3d_context_cleanup(struct wined3d_context *context)
+void wined3d_context_cleanup(struct wined3d_context *context)
{
struct wined3d_pipeline_statistics_query *pipeline_statistics_query;
const struct wined3d_gl_info *gl_info = context->gl_info;
@@ -1482,32 +1482,11 @@ static void wined3d_context_cleanup(struct wined3d_context *context)
heap_free(context->texture_type);
}
-static void wined3d_context_gl_cleanup(struct wined3d_context_gl *context_gl)
+void wined3d_context_gl_cleanup(struct wined3d_context_gl *context_gl)
{
wined3d_context_cleanup(&context_gl->c);
}
-static void wined3d_context_gl_destroy(struct wined3d_context_gl *context_gl)
-{
- if (context_gl->c.current && context_gl->c.tid != GetCurrentThreadId())
- {
- struct wined3d_gl_info *gl_info;
-
- /* Make a copy of gl_info for wined3d_context_gl_cleanup() use, the
- * one in wined3d_adapter may go away in the meantime. */
- gl_info = heap_alloc(sizeof(*gl_info));
- *gl_info = *context_gl->c.gl_info;
- context_gl->c.gl_info = gl_info;
- context_gl->c.destroyed = 1;
-
- return;
- }
-
- wined3d_context_gl_cleanup(context_gl);
- TlsSetValue(wined3d_context_tls_idx, NULL);
- heap_free(context_gl);
-}
-
DWORD context_get_tls_idx(void)
{
return wined3d_context_tls_idx;
@@ -1965,56 +1944,34 @@ static BOOL wined3d_context_init(struct wined3d_context *context, struct wined3d
return TRUE;
}
-struct wined3d_context *context_create(struct wined3d_swapchain *swapchain)
+HRESULT wined3d_context_no3d_init(struct wined3d_context *context_no3d, struct wined3d_swapchain *swapchain)
{
- struct wined3d_device *device = swapchain->device;
- struct wined3d_context_gl *context_gl;
- struct wined3d_context *context;
-
- TRACE("swapchain %p.\n", swapchain);
-
- wined3d_from_cs(device->cs);
-
- if (!(context_gl = heap_alloc_zero(sizeof(*context_gl))))
- return NULL;
- context = &context_gl->c;
+ TRACE("context_no3d %p, swapchain %p.\n", context_no3d, swapchain);
- if (!(wined3d_context_init(context, swapchain)))
- {
- heap_free(context_gl);
- return NULL;
- }
- if (!(device->adapter->adapter_ops->adapter_create_context(context)))
- {
- wined3d_release_dc(context->win_handle, context->hdc);
- heap_free(context_gl);
- return NULL;
- }
-
- if (!device_context_add(device, context))
- {
- ERR("Failed to add the newly created context to the context list\n");
- wined3d_context_gl_destroy(context_gl);
- return NULL;
- }
-
- TRACE("Created context %p.\n", context);
+ if (!wined3d_context_init(context_no3d, swapchain))
+ return E_FAIL;
- return context;
+ return WINED3D_OK;
}
-BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context)
+HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl, struct wined3d_swapchain *swapchain)
{
- struct wined3d_swapchain *swapchain = context->swapchain;
const struct wined3d_format *color_format, *ds_format;
- struct wined3d_device *device = context->device;
+ struct wined3d_context *context = &context_gl->c;
const struct wined3d_d3d_info *d3d_info;
const struct wined3d_gl_info *gl_info;
struct wined3d_resource *target;
unsigned int target_bind_flags;
+ struct wined3d_device *device;
HGLRC ctx, share_ctx;
unsigned int i;
+ TRACE("context_gl %p, swapchain %p.\n", context_gl, swapchain);
+
+ if (!wined3d_context_init(&context_gl->c, swapchain))
+ return E_FAIL;
+
+ device = context->device;
gl_info = context->gl_info;
d3d_info = context->d3d_info;
@@ -2031,7 +1988,7 @@ BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context)
if (base + WINED3D_MAX_FRAGMENT_SAMPLERS > ARRAY_SIZE(context->rev_tex_unit_map))
{
ERR("Unexpected texture unit base index %u.\n", base);
- return FALSE;
+ return E_FAIL;
}
for (i = 0; i < min(count, WINED3D_MAX_FRAGMENT_SAMPLERS); ++i)
{
@@ -2043,7 +2000,7 @@ BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context)
if (base + WINED3D_MAX_VERTEX_SAMPLERS > ARRAY_SIZE(context->rev_tex_unit_map))
{
ERR("Unexpected texture unit base index %u.\n", base);
- return FALSE;
+ return E_FAIL;
}
for (i = 0; i < min(count, WINED3D_MAX_VERTEX_SAMPLERS); ++i)
{
@@ -2054,7 +2011,7 @@ BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context)
if (!(context->texture_type = heap_calloc(gl_info->limits.combined_samplers,
sizeof(*context->texture_type))))
- return FALSE;
+ return E_FAIL;
target = &context->current_rt.texture->resource;
target_bind_flags = target->bind_flags;
@@ -2128,7 +2085,7 @@ BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context)
}
if (!context->pixel_format)
- return FALSE;
+ return E_FAIL;
context_enter(context);
@@ -2137,7 +2094,7 @@ BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context)
ERR("Failed to set pixel format %d on device context %p.\n", context->pixel_format, context->hdc);
context_release(context);
heap_free(context->texture_type);
- return FALSE;
+ return E_FAIL;
}
share_ctx = device->context_count ? device->contexts[0]->glCtx : NULL;
@@ -2147,7 +2104,7 @@ BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context)
{
context_release(context);
heap_free(context->texture_type);
- return FALSE;
+ return E_FAIL;
}
}
else
@@ -2157,7 +2114,7 @@ BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context)
ERR("Failed to create a WGL context.\n");
context_release(context);
heap_free(context->texture_type);
- return FALSE;
+ return E_FAIL;
}
if (share_ctx && !wglShareLists(share_ctx, ctx))
@@ -2167,7 +2124,7 @@ BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context)
if (!wglDeleteContext(ctx))
ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError());
heap_free(context->texture_type);
- return FALSE;
+ return E_FAIL;
}
}
@@ -2187,7 +2144,7 @@ BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context)
if (!wglDeleteContext(ctx))
ERR("wglDeleteContext(%p) failed, last error %#x.\n", ctx, GetLastError());
heap_free(context->texture_type);
- return FALSE;
+ return E_FAIL;
}
if (context_debug_output_enabled(gl_info))
@@ -2330,7 +2287,42 @@ BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context)
gl_info->gl_ops.gl.p_glScissor(0, 0, 0, 0);
checkGLcall("glScissor");
- return TRUE;
+ return WINED3D_OK;
+}
+
+HRESULT wined3d_context_vk_init(struct wined3d_context *context_vk, struct wined3d_swapchain *swapchain)
+{
+ TRACE("context_vk %p, swapchain %p.\n", context_vk, swapchain);
+
+ if (!wined3d_context_init(context_vk, swapchain))
+ return E_FAIL;
+
+ return WINED3D_OK;
+}
+
+struct wined3d_context *context_create(struct wined3d_swapchain *swapchain)
+{
+ struct wined3d_device *device = swapchain->device;
+ struct wined3d_context *context;
+ HRESULT hr;
+
+ TRACE("swapchain %p.\n", swapchain);
+
+ wined3d_from_cs(device->cs);
+
+ if (FAILED(hr = device->adapter->adapter_ops->adapter_create_context(swapchain, &context)))
+ return NULL;
+
+ if (!device_context_add(device, context))
+ {
+ ERR("Failed to add the newly created context to the context list.\n");
+ device->adapter->adapter_ops->adapter_destroy_context(context);
+ return NULL;
+ }
+
+ TRACE("Created context %p.\n", context);
+
+ return context;
}
void wined3d_context_destroy(struct wined3d_context *context)
@@ -2355,7 +2347,7 @@ void wined3d_context_destroy(struct wined3d_context *context)
device_context_remove(device, context);
- wined3d_context_gl_destroy(wined3d_context_gl(context));
+ device->adapter->adapter_ops->adapter_destroy_context(context);
}
const DWORD *context_get_tex_unit_mapping(const struct wined3d_context *context,
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index 7e6ac823e5a..6fc5c7bf8bf 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -2255,9 +2255,32 @@ static void adapter_no3d_destroy_device(struct wined3d_device *device)
heap_free(device);
}
-static BOOL wined3d_adapter_no3d_create_context(struct wined3d_context *context)
+static HRESULT adapter_no3d_create_context(struct wined3d_swapchain *swapchain, struct wined3d_context **context)
{
- return TRUE;
+ struct wined3d_context *context_no3d;
+
+ TRACE("swapchain %p, context %p.\n", swapchain, context);
+
+ if (!(context_no3d = heap_alloc_zero(sizeof(*context_no3d))))
+ return E_OUTOFMEMORY;
+
+ if (FAILED(wined3d_context_no3d_init(context_no3d, swapchain)))
+ {
+ WARN("Failed to initialise context.\n");
+ heap_free(context_no3d);
+ return E_FAIL;
+ }
+
+ TRACE("Created context %p.\n", context_no3d);
+ *context = context_no3d;
+
+ return WINED3D_OK;
+}
+
+static void adapter_no3d_destroy_context(struct wined3d_context *context)
+{
+ wined3d_context_cleanup(context);
+ heap_free(context);
}
static void adapter_no3d_get_wined3d_caps(const struct wined3d_adapter *adapter, struct wined3d_caps *caps)
@@ -2296,7 +2319,8 @@ static const struct wined3d_adapter_ops wined3d_adapter_no3d_ops =
adapter_no3d_destroy,
adapter_no3d_create_device,
adapter_no3d_destroy_device,
- wined3d_adapter_no3d_create_context,
+ adapter_no3d_create_context,
+ adapter_no3d_destroy_context,
adapter_no3d_get_wined3d_caps,
adapter_no3d_check_format,
adapter_no3d_init_3d,
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index 1eec960c045..3934fba4acd 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2029,6 +2029,11 @@ struct wined3d_context
unsigned int scissor_rect_count;
};
+void wined3d_context_cleanup(struct wined3d_context *context) DECLSPEC_HIDDEN;
+
+HRESULT wined3d_context_no3d_init(struct wined3d_context *context_no3d,
+ struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
+
struct wined3d_context_gl
{
struct wined3d_context c;
@@ -2039,12 +2044,19 @@ static inline struct wined3d_context_gl *wined3d_context_gl(struct wined3d_conte
return CONTAINING_RECORD(context, struct wined3d_context_gl, c);
}
+void wined3d_context_gl_cleanup(struct wined3d_context_gl *context_gl) DECLSPEC_HIDDEN;
+HRESULT wined3d_context_gl_init(struct wined3d_context_gl *context_gl,
+ struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
+
struct wined3d_fb_state
{
struct wined3d_rendertarget_view *render_targets[MAX_RENDER_TARGET_VIEWS];
struct wined3d_rendertarget_view *depth_stencil;
};
+HRESULT wined3d_context_vk_init(struct wined3d_context *context_vk,
+ struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
+
typedef void (*APPLYSTATEFUNC)(struct wined3d_context *ctx, const struct wined3d_state *state, DWORD state_id);
struct wined3d_state_entry
@@ -2710,7 +2722,8 @@ struct wined3d_adapter_ops
BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count,
struct wined3d_device_parent *device_parent, struct wined3d_device **device);
void (*adapter_destroy_device)(struct wined3d_device *device);
- BOOL (*adapter_create_context)(struct wined3d_context *context);
+ HRESULT (*adapter_create_context)(struct wined3d_swapchain *swapchain, struct wined3d_context **context);
+ void (*adapter_destroy_context)(struct wined3d_context *context);
void (*adapter_get_wined3d_caps)(const struct wined3d_adapter *adapter, struct wined3d_caps *caps);
BOOL (*adapter_check_format)(const struct wined3d_adapter *adapter,
const struct wined3d_format *adapter_format, const struct wined3d_format *rt_format,
@@ -2769,7 +2782,6 @@ static inline const struct wined3d_adapter_gl *wined3d_adapter_gl_const(const st
struct wined3d_adapter *wined3d_adapter_gl_create(unsigned int ordinal,
unsigned int wined3d_creation_flags) DECLSPEC_HIDDEN;
-BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context) DECLSPEC_HIDDEN;
struct wined3d_adapter_vk
{
--
2.11.0
1
0
[PATCH 4/6] wined3d: Determine the ORM_BACKBUFFER depth/stencil format in wined3d_adapter_gl_create_context().
by Henri Verbeet 07 May '19
by Henri Verbeet 07 May '19
07 May '19
Instead of in wined3d_swapchain_cs_init().
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/wined3d/adapter_vk.c | 2 +-
dlls/wined3d/context.c | 90 ++++++++++++++++++++++++++++--------------
dlls/wined3d/directx.c | 3 +-
dlls/wined3d/swapchain.c | 27 +------------
dlls/wined3d/wined3d_private.h | 8 ++--
5 files changed, 67 insertions(+), 63 deletions(-)
diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c
index 7177e384fa2..d6438945361 100644
--- a/dlls/wined3d/adapter_vk.c
+++ b/dlls/wined3d/adapter_vk.c
@@ -288,7 +288,7 @@ static void adapter_vk_destroy_device(struct wined3d_device *device)
heap_free(device_vk);
}
-static BOOL adapter_vk_create_context(struct wined3d_context *context, const struct wined3d_format *ds_format)
+static BOOL adapter_vk_create_context(struct wined3d_context *context)
{
return TRUE;
}
diff --git a/dlls/wined3d/context.c b/dlls/wined3d/context.c
index 0defbcc25a9..fdf7f9ccc65 100644
--- a/dlls/wined3d/context.c
+++ b/dlls/wined3d/context.c
@@ -1965,7 +1965,7 @@ static BOOL wined3d_context_init(struct wined3d_context *context, struct wined3d
return TRUE;
}
-struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, const struct wined3d_format *ds_format)
+struct wined3d_context *context_create(struct wined3d_swapchain *swapchain)
{
struct wined3d_device *device = swapchain->device;
struct wined3d_context_gl *context_gl;
@@ -1984,7 +1984,7 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, cons
heap_free(context_gl);
return NULL;
}
- if (!(device->adapter->adapter_ops->adapter_create_context(context, ds_format)))
+ if (!(device->adapter->adapter_ops->adapter_create_context(context)))
{
wined3d_release_dc(context->win_handle, context->hdc);
heap_free(context_gl);
@@ -2003,15 +2003,15 @@ struct wined3d_context *context_create(struct wined3d_swapchain *swapchain, cons
return context;
}
-BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context, const struct wined3d_format *ds_format)
+BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context)
{
+ struct wined3d_swapchain *swapchain = context->swapchain;
+ const struct wined3d_format *color_format, *ds_format;
struct wined3d_device *device = context->device;
- const struct wined3d_format *color_format;
const struct wined3d_d3d_info *d3d_info;
const struct wined3d_gl_info *gl_info;
struct wined3d_resource *target;
unsigned int target_bind_flags;
- BOOL aux_buffers = FALSE;
HGLRC ctx, share_ctx;
unsigned int i;
@@ -2057,47 +2057,77 @@ BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context, const st
return FALSE;
target = &context->current_rt.texture->resource;
- color_format = target->format;
target_bind_flags = target->bind_flags;
- /* In case of ORM_BACKBUFFER, make sure to request an alpha component for
- * X4R4G4B4/X8R8G8B8 as we might need it for the backbuffer. */
if (wined3d_settings.offscreen_rendering_mode == ORM_BACKBUFFER)
{
- aux_buffers = TRUE;
+ static const enum wined3d_format_id ds_formats[] =
+ {
+ WINED3DFMT_D24_UNORM_S8_UINT,
+ WINED3DFMT_D32_UNORM,
+ WINED3DFMT_R24_UNORM_X8_TYPELESS,
+ WINED3DFMT_D16_UNORM,
+ WINED3DFMT_S1_UINT_D15_UNORM,
+ };
+
+ color_format = target->format;
+ /* In case of ORM_BACKBUFFER, make sure to request an alpha component for
+ * X4R4G4B4/X8R8G8B8 as we might need it for the backbuffer. */
if (color_format->id == WINED3DFMT_B4G4R4X4_UNORM)
color_format = wined3d_get_format(device->adapter, WINED3DFMT_B4G4R4A4_UNORM, target_bind_flags);
else if (color_format->id == WINED3DFMT_B8G8R8X8_UNORM)
color_format = wined3d_get_format(device->adapter, WINED3DFMT_B8G8R8A8_UNORM, target_bind_flags);
- }
- /* DirectDraw supports 8bit paletted render targets and these are used by
- * old games like StarCraft and C&C. Most modern hardware doesn't support
- * 8bit natively so we perform some form of 8bit -> 32bit conversion. The
- * conversion (ab)uses the alpha component for storing the palette index.
- * For this reason we require a format with 8bit alpha, so request
- * A8R8G8B8. */
- if (color_format->id == WINED3DFMT_P8_UINT)
- color_format = wined3d_get_format(device->adapter, WINED3DFMT_B8G8R8A8_UNORM, target_bind_flags);
+ /* DirectDraw supports 8bit paletted render targets and these are used by
+ * old games like StarCraft and C&C. Most modern hardware doesn't support
+ * 8bit natively so we perform some form of 8bit -> 32bit conversion. The
+ * conversion (ab)uses the alpha component for storing the palette index.
+ * For this reason we require a format with 8bit alpha, so request
+ * A8R8G8B8. */
+ if (color_format->id == WINED3DFMT_P8_UINT)
+ color_format = wined3d_get_format(device->adapter, WINED3DFMT_B8G8R8A8_UNORM, target_bind_flags);
+
+ /* Try to find a pixel format which matches our requirements. */
+ if (!swapchain->ds_format)
+ {
+ for (i = 0; i < ARRAY_SIZE(ds_formats); ++i)
+ {
+ ds_format = wined3d_get_format(device->adapter, ds_formats[i], WINED3D_BIND_DEPTH_STENCIL);
+ if ((context->pixel_format = context_choose_pixel_format(device,
+ context->hdc, color_format, ds_format, TRUE)))
+ {
+ swapchain->ds_format = ds_format;
+ break;
+ }
- /* When using FBOs for off-screen rendering, we only use the drawable for
- * presentation blits, and don't do any rendering to it. That means we
- * don't need depth or stencil buffers, and can mostly ignore the render
- * target format. This wouldn't necessarily be quite correct for 10bpc
- * display modes, but we don't currently support those.
- * Using the same format regardless of the color/depth/stencil targets
- * makes it much less likely that different wined3d instances will set
- * conflicting pixel formats. */
- if (wined3d_settings.offscreen_rendering_mode != ORM_BACKBUFFER)
+ TRACE("Depth stencil format %s is not supported, trying next format.\n",
+ debug_d3dformat(ds_format->id));
+ }
+ }
+ else
+ {
+ context->pixel_format = context_choose_pixel_format(device,
+ context->hdc, color_format, swapchain->ds_format, TRUE);
+ }
+ }
+ else
{
+ /* When using FBOs for off-screen rendering, we only use the drawable for
+ * presentation blits, and don't do any rendering to it. That means we
+ * don't need depth or stencil buffers, and can mostly ignore the render
+ * target format. This wouldn't necessarily be quite correct for 10bpc
+ * display modes, but we don't currently support those.
+ * Using the same format regardless of the color/depth/stencil targets
+ * makes it much less likely that different wined3d instances will set
+ * conflicting pixel formats. */
color_format = wined3d_get_format(device->adapter, WINED3DFMT_B8G8R8A8_UNORM, target_bind_flags);
ds_format = wined3d_get_format(device->adapter, WINED3DFMT_UNKNOWN, WINED3D_BIND_DEPTH_STENCIL);
+ context->pixel_format = context_choose_pixel_format(device,
+ context->hdc, color_format, ds_format, FALSE);
}
- /* Try to find a pixel format which matches our requirements. */
- if (!(context->pixel_format = context_choose_pixel_format(device,
- context->hdc, color_format, ds_format, aux_buffers)))
+ if (!context->pixel_format)
return FALSE;
context_enter(context);
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index d4aefadc29e..7e6ac823e5a 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -2255,8 +2255,7 @@ static void adapter_no3d_destroy_device(struct wined3d_device *device)
heap_free(device);
}
-static BOOL wined3d_adapter_no3d_create_context(struct wined3d_context *context,
- const struct wined3d_format *ds_format)
+static BOOL wined3d_adapter_no3d_create_context(struct wined3d_context *context)
{
return TRUE;
}
diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c
index 7210682c45f..f47c1a44297 100644
--- a/dlls/wined3d/swapchain.c
+++ b/dlls/wined3d/swapchain.c
@@ -720,31 +720,8 @@ static void wined3d_swapchain_apply_sample_count_override(const struct wined3d_s
static void wined3d_swapchain_cs_init(void *object)
{
struct wined3d_swapchain *swapchain = object;
- const struct wined3d_adapter *adapter;
- unsigned int i;
-
- static const enum wined3d_format_id formats[] =
- {
- WINED3DFMT_D24_UNORM_S8_UINT,
- WINED3DFMT_D32_UNORM,
- WINED3DFMT_R24_UNORM_X8_TYPELESS,
- WINED3DFMT_D16_UNORM,
- WINED3DFMT_S1_UINT_D15_UNORM,
- };
-
- adapter = swapchain->device->adapter;
-
- /* Without ORM_FBO, switching the depth/stencil format is hard. Always
- * request a depth/stencil buffer in the likely case it's needed later. */
- for (i = 0; i < ARRAY_SIZE(formats); ++i)
- {
- swapchain->ds_format = wined3d_get_format(adapter, formats[i], WINED3D_BIND_DEPTH_STENCIL);
- if ((swapchain->context[0] = context_create(swapchain, swapchain->ds_format)))
- break;
- TRACE("Depth stencil format %s is not supported, trying next format.\n", debug_d3dformat(formats[i]));
- }
- if (!swapchain->context[0])
+ if (!(swapchain->context[0] = context_create(swapchain)))
{
WARN("Failed to create context.\n");
return;
@@ -1085,7 +1062,7 @@ static struct wined3d_context *swapchain_create_context(struct wined3d_swapchain
TRACE("Creating a new context for swapchain %p, thread %u.\n", swapchain, GetCurrentThreadId());
- if (!(ctx = context_create(swapchain, swapchain->ds_format)))
+ if (!(ctx = context_create(swapchain)))
{
ERR("Failed to create a new context for the swapchain\n");
return NULL;
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index ddd5b8d0951..1eec960c045 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2196,8 +2196,7 @@ void context_check_fbo_status(const struct wined3d_context *context, GLenum targ
void context_copy_bo_address(struct wined3d_context *context,
const struct wined3d_bo_address *dst, GLenum dst_binding,
const struct wined3d_bo_address *src, GLenum src_binding, size_t size) DECLSPEC_HIDDEN;
-struct wined3d_context *context_create(struct wined3d_swapchain *swapchain,
- const struct wined3d_format *ds_format) DECLSPEC_HIDDEN;
+struct wined3d_context *context_create(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN;
HGLRC context_create_wgl_attribs(const struct wined3d_gl_info *gl_info, HDC hdc, HGLRC share_ctx) DECLSPEC_HIDDEN;
void wined3d_context_destroy(struct wined3d_context *context) DECLSPEC_HIDDEN;
void context_draw_shaded_quad(struct wined3d_context *context, struct wined3d_texture_gl *texture_gl,
@@ -2711,7 +2710,7 @@ struct wined3d_adapter_ops
BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count,
struct wined3d_device_parent *device_parent, struct wined3d_device **device);
void (*adapter_destroy_device)(struct wined3d_device *device);
- BOOL (*adapter_create_context)(struct wined3d_context *context, const struct wined3d_format *ds_format);
+ BOOL (*adapter_create_context)(struct wined3d_context *context);
void (*adapter_get_wined3d_caps)(const struct wined3d_adapter *adapter, struct wined3d_caps *caps);
BOOL (*adapter_check_format)(const struct wined3d_adapter *adapter,
const struct wined3d_format *adapter_format, const struct wined3d_format *rt_format,
@@ -2770,8 +2769,7 @@ static inline const struct wined3d_adapter_gl *wined3d_adapter_gl_const(const st
struct wined3d_adapter *wined3d_adapter_gl_create(unsigned int ordinal,
unsigned int wined3d_creation_flags) DECLSPEC_HIDDEN;
-BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context,
- const struct wined3d_format *ds_format) DECLSPEC_HIDDEN;
+BOOL wined3d_adapter_gl_create_context(struct wined3d_context *context) DECLSPEC_HIDDEN;
struct wined3d_adapter_vk
{
--
2.11.0
1
0
[PATCH 3/6] wined3d: Make the adapter responsible for initialising and de-initialising 3D.
by Henri Verbeet 07 May '19
by Henri Verbeet 07 May '19
07 May '19
From: Józef Kucia <jkucia(a)codeweavers.com>
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/wined3d/adapter_gl.c | 34 ++++++++++++++++++++++----
dlls/wined3d/adapter_vk.c | 14 +++++++++++
dlls/wined3d/device.c | 54 +++++++-----------------------------------
dlls/wined3d/directx.c | 22 +++++++++++++++++
dlls/wined3d/wined3d_private.h | 4 ++++
5 files changed, 77 insertions(+), 51 deletions(-)
diff --git a/dlls/wined3d/adapter_gl.c b/dlls/wined3d/adapter_gl.c
index cedd012c89d..972d051a6b2 100644
--- a/dlls/wined3d/adapter_gl.c
+++ b/dlls/wined3d/adapter_gl.c
@@ -4233,6 +4233,15 @@ static void wined3d_adapter_init_fb_cfgs(struct wined3d_adapter_gl *adapter_gl,
}
}
+static void adapter_gl_destroy(struct wined3d_adapter *adapter)
+{
+ struct wined3d_adapter_gl *adapter_gl = wined3d_adapter_gl(adapter);
+
+ heap_free(adapter_gl->pixel_formats);
+ wined3d_adapter_cleanup(adapter);
+ heap_free(adapter_gl);
+}
+
static HRESULT adapter_gl_create_device(struct wined3d *wined3d, const struct wined3d_adapter *adapter,
enum wined3d_device_type device_type, HWND focus_window, unsigned int flags, BYTE surface_alignment,
const enum wined3d_feature_level *levels, unsigned int level_count,
@@ -4522,13 +4531,26 @@ static BOOL adapter_gl_check_format(const struct wined3d_adapter *adapter,
return FALSE;
}
-static void adapter_gl_destroy(struct wined3d_adapter *adapter)
+static HRESULT adapter_gl_init_3d(struct wined3d_device *device)
{
- struct wined3d_adapter_gl *adapter_gl = wined3d_adapter_gl(adapter);
+ TRACE("device %p.\n", device);
- heap_free(adapter_gl->pixel_formats);
- wined3d_adapter_cleanup(adapter);
- heap_free(adapter_gl);
+ wined3d_cs_init_object(device->cs, wined3d_device_create_primary_opengl_context_cs, device);
+ wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
+ if (!device->swapchains[0]->num_contexts)
+ return E_FAIL;
+
+ device->d3d_initialized = TRUE;
+
+ return WINED3D_OK;
+}
+
+static void adapter_gl_uninit_3d(struct wined3d_device *device)
+{
+ TRACE("device %p.\n", device);
+
+ wined3d_cs_destroy_object(device->cs, wined3d_device_delete_opengl_contexts_cs, device);
+ wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
}
static const struct wined3d_adapter_ops wined3d_adapter_gl_ops =
@@ -4539,6 +4561,8 @@ static const struct wined3d_adapter_ops wined3d_adapter_gl_ops =
wined3d_adapter_gl_create_context,
adapter_gl_get_wined3d_caps,
adapter_gl_check_format,
+ adapter_gl_init_3d,
+ adapter_gl_uninit_3d,
};
static BOOL wined3d_adapter_gl_init(struct wined3d_adapter_gl *adapter_gl,
diff --git a/dlls/wined3d/adapter_vk.c b/dlls/wined3d/adapter_vk.c
index da53edd953a..7177e384fa2 100644
--- a/dlls/wined3d/adapter_vk.c
+++ b/dlls/wined3d/adapter_vk.c
@@ -398,6 +398,18 @@ static BOOL adapter_vk_check_format(const struct wined3d_adapter *adapter,
return TRUE;
}
+static HRESULT adapter_vk_init_3d(struct wined3d_device *device)
+{
+ TRACE("device %p.\n", device);
+
+ return WINED3D_OK;
+}
+
+static void adapter_vk_uninit_3d(struct wined3d_device *device)
+{
+ TRACE("device %p.\n", device);
+}
+
static const struct wined3d_adapter_ops wined3d_adapter_vk_ops =
{
adapter_vk_destroy,
@@ -406,6 +418,8 @@ static const struct wined3d_adapter_ops wined3d_adapter_vk_ops =
adapter_vk_create_context,
adapter_vk_get_wined3d_caps,
adapter_vk_check_format,
+ adapter_vk_init_3d,
+ adapter_vk_uninit_3d,
};
static unsigned int wined3d_get_wine_vk_version(void)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index dcf05f054f5..eac6442804f 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1009,7 +1009,7 @@ static void device_init_swapchain_state(struct wined3d_device *device, struct wi
wined3d_device_set_depth_stencil_view(device, ds_enable ? device->auto_depth_stencil_view : NULL);
}
-static void wined3d_device_delete_opengl_contexts_cs(void *object)
+void wined3d_device_delete_opengl_contexts_cs(void *object)
{
struct wined3d_resource *resource, *cursor;
struct wined3d_device *device = object;
@@ -1043,13 +1043,7 @@ static void wined3d_device_delete_opengl_contexts_cs(void *object)
}
}
-static void wined3d_device_delete_opengl_contexts(struct wined3d_device *device)
-{
- wined3d_cs_destroy_object(device->cs, wined3d_device_delete_opengl_contexts_cs, device);
- wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
-}
-
-static void wined3d_device_create_primary_opengl_context_cs(void *object)
+void wined3d_device_create_primary_opengl_context_cs(void *object)
{
struct wined3d_device *device = object;
struct wined3d_swapchain *swapchain;
@@ -1084,16 +1078,6 @@ static void wined3d_device_create_primary_opengl_context_cs(void *object)
context_release(context);
}
-static HRESULT wined3d_device_create_primary_opengl_context(struct wined3d_device *device)
-{
- wined3d_cs_init_object(device->cs, wined3d_device_create_primary_opengl_context_cs, device);
- wined3d_cs_finish(device->cs, WINED3D_CS_QUEUE_DEFAULT);
- if (!device->swapchains[0]->num_contexts)
- return E_FAIL;
-
- return WINED3D_OK;
-}
-
HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device, struct wined3d_swapchain *swapchain)
{
static const struct wined3d_color black = {0.0f, 0.0f, 0.0f, 0.0f};
@@ -1136,24 +1120,8 @@ HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device, str
device->swapchains[0] = swapchain;
memset(device->fb.render_targets, 0, sizeof(device->fb.render_targets));
- if (device->wined3d->flags & WINED3D_NO3D)
- {
- if (!(device->blitter = wined3d_cpu_blitter_create()))
- {
- ERR("Failed to create CPU blitter.\n");
- heap_free(device->swapchains);
- device->swapchain_count = 0;
- hr = E_FAIL;
- goto err_out;
- }
- }
- else
- {
- if (FAILED(hr = wined3d_device_create_primary_opengl_context(device)))
- goto err_out;
-
- device->d3d_initialized = TRUE;
- }
+ if (FAILED(hr = device->adapter->adapter_ops->adapter_init_3d(device)))
+ goto err_out;
device_init_swapchain_state(device, swapchain);
@@ -1231,10 +1199,7 @@ void wined3d_device_uninit_3d(struct wined3d_device *device)
wine_rb_clear(&device->samplers, device_free_sampler, NULL);
- if (no3d)
- device->blitter->ops->blitter_destroy(device->blitter, NULL);
- else
- wined3d_device_delete_opengl_contexts(device);
+ device->adapter->adapter_ops->adapter_uninit_3d(device);
if ((view = device->fb.depth_stencil))
{
@@ -5066,7 +5031,7 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
state_cleanup(&device->state);
if (device->d3d_initialized)
- wined3d_device_delete_opengl_contexts(device);
+ device->adapter->adapter_ops->adapter_uninit_3d(device);
memset(&device->state, 0, sizeof(device->state));
state_init(&device->state, &device->fb, &device->adapter->d3d_info, WINED3D_STATE_INIT_DEFAULT);
@@ -5097,11 +5062,8 @@ HRESULT CDECL wined3d_device_reset(struct wined3d_device *device,
wined3d_cs_emit_set_scissor_rects(device->cs, 1, state->scissor_rects);
}
- if (device->d3d_initialized)
- {
- if (reset_state)
- hr = wined3d_device_create_primary_opengl_context(device);
- }
+ if (device->d3d_initialized && reset_state)
+ hr = device->adapter->adapter_ops->adapter_init_3d(device);
/* All done. There is no need to reload resources or shaders, this will happen automatically on the
* first use
diff --git a/dlls/wined3d/directx.c b/dlls/wined3d/directx.c
index c909e5185a1..d4aefadc29e 100644
--- a/dlls/wined3d/directx.c
+++ b/dlls/wined3d/directx.c
@@ -2272,6 +2272,26 @@ static BOOL adapter_no3d_check_format(const struct wined3d_adapter *adapter,
return TRUE;
}
+static HRESULT adapter_no3d_init_3d(struct wined3d_device *device)
+{
+ TRACE("device %p.\n", device);
+
+ if (!(device->blitter = wined3d_cpu_blitter_create()))
+ {
+ ERR("Failed to create CPU blitter.\n");
+ return E_FAIL;
+ }
+
+ return WINED3D_OK;
+}
+
+static void adapter_no3d_uninit_3d(struct wined3d_device *device)
+{
+ TRACE("device %p.\n", device);
+
+ device->blitter->ops->blitter_destroy(device->blitter, NULL);
+}
+
static const struct wined3d_adapter_ops wined3d_adapter_no3d_ops =
{
adapter_no3d_destroy,
@@ -2280,6 +2300,8 @@ static const struct wined3d_adapter_ops wined3d_adapter_no3d_ops =
wined3d_adapter_no3d_create_context,
adapter_no3d_get_wined3d_caps,
adapter_no3d_check_format,
+ adapter_no3d_init_3d,
+ adapter_no3d_uninit_3d,
};
static void wined3d_adapter_no3d_init_d3d_info(struct wined3d_adapter *adapter, unsigned int wined3d_creation_flags)
diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h
index fbcda94537e..ddd5b8d0951 100644
--- a/dlls/wined3d/wined3d_private.h
+++ b/dlls/wined3d/wined3d_private.h
@@ -2716,6 +2716,8 @@ struct wined3d_adapter_ops
BOOL (*adapter_check_format)(const struct wined3d_adapter *adapter,
const struct wined3d_format *adapter_format, const struct wined3d_format *rt_format,
const struct wined3d_format *ds_format);
+ HRESULT (*adapter_init_3d)(struct wined3d_device *device);
+ void (*adapter_uninit_3d)(struct wined3d_device *device);
};
/* The adapter structure */
@@ -3190,6 +3192,8 @@ void device_clear_render_targets(struct wined3d_device *device, UINT rt_count, c
const struct wined3d_color *color, float depth, DWORD stencil) DECLSPEC_HIDDEN;
BOOL device_context_add(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
void device_context_remove(struct wined3d_device *device, struct wined3d_context *context) DECLSPEC_HIDDEN;
+void wined3d_device_create_primary_opengl_context_cs(void *object) DECLSPEC_HIDDEN;
+void wined3d_device_delete_opengl_contexts_cs(void *object) DECLSPEC_HIDDEN;
HRESULT wined3d_device_init(struct wined3d_device *device, struct wined3d *wined3d,
unsigned int adapter_idx, enum wined3d_device_type device_type, HWND focus_window, unsigned int flags,
BYTE surface_alignment, const enum wined3d_feature_level *levels, unsigned int level_count,
--
2.11.0
1
0
[PATCH 2/6] wined3d: Share more swapchain setup with the "no3d" adapter in wined3d_device_set_implicit_swapchain().
by Henri Verbeet 07 May '19
by Henri Verbeet 07 May '19
07 May '19
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/wined3d/device.c | 27 ++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index b2dbb403932..dcf05f054f5 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1151,23 +1151,24 @@ HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device, str
{
if (FAILED(hr = wined3d_device_create_primary_opengl_context(device)))
goto err_out;
- device_init_swapchain_state(device, swapchain);
- TRACE("All defaults now set up.\n");
+ device->d3d_initialized = TRUE;
+ }
- /* Clear the screen */
- if (device->back_buffer_view)
- clear_flags |= WINED3DCLEAR_TARGET;
- if (swapchain_desc->enable_auto_depth_stencil)
- clear_flags |= WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL;
- if (clear_flags)
- wined3d_device_clear(device, 0, NULL, clear_flags, &black, 1.0f, 0);
+ device_init_swapchain_state(device, swapchain);
- device->d3d_initialized = TRUE;
+ TRACE("All defaults now set up.\n");
- if (wined3d_settings.logo)
- device_load_logo(device, wined3d_settings.logo);
- }
+ /* Clear the screen. */
+ if (device->back_buffer_view)
+ clear_flags |= WINED3DCLEAR_TARGET;
+ if (swapchain_desc->enable_auto_depth_stencil)
+ clear_flags |= WINED3DCLEAR_ZBUFFER | WINED3DCLEAR_STENCIL;
+ if (clear_flags)
+ wined3d_device_clear(device, 0, NULL, clear_flags, &black, 1.0f, 0);
+
+ if (wined3d_settings.logo)
+ device_load_logo(device, wined3d_settings.logo);
return WINED3D_OK;
--
2.11.0
1
0
[PATCH 1/6] wined3d: Get rid of a redundant initialisation in wined3d_device_set_implicit_swapchain().
by Henri Verbeet 07 May '19
by Henri Verbeet 07 May '19
07 May '19
Signed-off-by: Henri Verbeet <hverbeet(a)codeweavers.com>
---
dlls/wined3d/device.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/dlls/wined3d/device.c b/dlls/wined3d/device.c
index a27251c86e3..b2dbb403932 100644
--- a/dlls/wined3d/device.c
+++ b/dlls/wined3d/device.c
@@ -1153,8 +1153,6 @@ HRESULT wined3d_device_set_implicit_swapchain(struct wined3d_device *device, str
goto err_out;
device_init_swapchain_state(device, swapchain);
- device->contexts[0]->last_was_rhw = 0;
-
TRACE("All defaults now set up.\n");
/* Clear the screen */
--
2.11.0
1
0
[PATCH 4/4] d3d11: Report format support more accurately based on feature level.
by Józef Kucia 07 May '19
by Józef Kucia 07 May '19
07 May '19
Our partial stub for CheckFormatSupport() is still quite inaccurate. For
example, we might report SHADER_SAMPLE support for UINT formats. In the long
term, wined3d should probably return the format support flags directly.
Unfortunately, the current wined3d interface shared with d3d9 isn't well
suited for returning fine-grained format support flags.
Signed-off-by: Józef Kucia <jkucia(a)codeweavers.com>
---
dlls/d3d10core/tests/d3d10core.c | 20 ++++++++++++++++--
dlls/d3d11/device.c | 13 +++++++++---
dlls/d3d11/tests/d3d11.c | 35 ++++++++++++++++++++++++++++++--
3 files changed, 61 insertions(+), 7 deletions(-)
diff --git a/dlls/d3d10core/tests/d3d10core.c b/dlls/d3d10core/tests/d3d10core.c
index 32f943704af8..ecf1f3814726 100644
--- a/dlls/d3d10core/tests/d3d10core.c
+++ b/dlls/d3d10core/tests/d3d10core.c
@@ -13390,7 +13390,7 @@ static void check_format_support(const unsigned int *format_support,
}
}
-static void test_required_format_support(void)
+static void test_format_support(void)
{
unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
ID3D10Device *device;
@@ -13425,6 +13425,22 @@ static void test_required_format_support(void)
format, hr, format_support[format]);
}
+ for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
+ {
+ ok(!(format_support[format] & D3D10_FORMAT_SUPPORT_SHADER_GATHER),
+ "Unexpected SHADER_GATHER for format %#x.\n", format);
+ ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON),
+ "Unexpected SHADER_GATHER_COMPARISON for format %#x.\n", format);
+ }
+
+ ok(format_support[DXGI_FORMAT_R8G8B8A8_UNORM] & D3D10_FORMAT_SUPPORT_SHADER_SAMPLE,
+ "SHADER_SAMPLE is not supported for R8G8B8A8_UNORM.\n");
+ todo_wine
+ ok(!(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D10_FORMAT_SUPPORT_SHADER_SAMPLE),
+ "SHADER_SAMPLE is supported for R32G32B32A32_UINT.\n");
+ ok(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D10_FORMAT_SUPPORT_SHADER_LOAD,
+ "SHADER_LOAD is not supported for R32G32B32A32_UINT.\n");
+
check_format_support(format_support, index_buffers, ARRAY_SIZE(index_buffers),
D3D10_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
@@ -18057,7 +18073,7 @@ START_TEST(d3d10core)
queue_test(test_index_buffer_offset);
queue_test(test_face_culling);
queue_test(test_line_antialiasing_blending);
- queue_test(test_required_format_support);
+ queue_test(test_format_support);
queue_test(test_ddy);
queue_test(test_shader_input_registers_limits);
queue_test(test_unbind_shader_resource_view);
diff --git a/dlls/d3d11/device.c b/dlls/d3d11/device.c
index 751afc132112..31292e9ddff8 100644
--- a/dlls/d3d11/device.c
+++ b/dlls/d3d11/device.c
@@ -3378,6 +3378,7 @@ static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *
struct d3d_device *device = impl_from_ID3D11Device2(iface);
struct wined3d_device_creation_parameters params;
enum wined3d_format_id wined3d_format;
+ D3D_FEATURE_LEVEL feature_level;
struct wined3d *wined3d;
unsigned int i;
@@ -3410,6 +3411,7 @@ static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *
*format_support = 0;
wined3d_mutex_lock();
+ feature_level = device->feature_level;
wined3d = wined3d_device_get_wined3d(device->wined3d_device);
wined3d_device_get_creation_parameters(device->wined3d_device, ¶ms);
for (i = 0; i < ARRAY_SIZE(flag_mapping); ++i)
@@ -3434,12 +3436,17 @@ static HRESULT STDMETHODCALLTYPE d3d11_device_CheckFormatSupport(ID3D11Device2 *
{
*format_support |= D3D11_FORMAT_SUPPORT_SHADER_LOAD;
*format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE;
- *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER;
+
+ if (feature_level >= D3D_FEATURE_LEVEL_10_1)
+ *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER;
if (*format_support & D3D11_FORMAT_SUPPORT_DEPTH_STENCIL)
{
- *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
- *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON;
+ if (feature_level >= D3D_FEATURE_LEVEL_10_0)
+ *format_support |= D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON;
+
+ if (feature_level >= D3D_FEATURE_LEVEL_10_1)
+ *format_support |= D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON;
}
}
diff --git a/dlls/d3d11/tests/d3d11.c b/dlls/d3d11/tests/d3d11.c
index 5b56a04c54bb..e8c2f649f80b 100644
--- a/dlls/d3d11/tests/d3d11.c
+++ b/dlls/d3d11/tests/d3d11.c
@@ -18425,7 +18425,7 @@ static void check_format_support(const unsigned int *format_support, D3D_FEATURE
}
}
-static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
+static void test_format_support(const D3D_FEATURE_LEVEL feature_level)
{
unsigned int format_support[DXGI_FORMAT_B4G4R4A4_UNORM + 1];
struct device_desc device_desc;
@@ -18463,6 +18463,37 @@ static void test_required_format_support(const D3D_FEATURE_LEVEL feature_level)
format, hr, format_support[format]);
}
+ for (format = DXGI_FORMAT_UNKNOWN; format <= DXGI_FORMAT_B4G4R4A4_UNORM; ++format)
+ {
+ if (feature_level < D3D_FEATURE_LEVEL_10_0)
+ {
+ /* SHADER_SAMPLE_COMPARISON is never advertised as supported on feature level 9. */
+ ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE_COMPARISON),
+ "Unexpected SHADER_SAMPLE_COMPARISON for format %#x, feature level %#x.\n",
+ format, feature_level);
+ }
+ if (feature_level < D3D_FEATURE_LEVEL_10_1)
+ {
+ ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER),
+ "Unexpected SHADER_GATHER for format %#x, feature level %#x.\n",
+ format, feature_level);
+ ok(!(format_support[format] & D3D11_FORMAT_SUPPORT_SHADER_GATHER_COMPARISON),
+ "Unexpected SHADER_GATHER_COMPARISON for format %#x, feature level %#x.\n",
+ format, feature_level);
+ }
+ }
+
+ ok(format_support[DXGI_FORMAT_R8G8B8A8_UNORM] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE,
+ "SHADER_SAMPLE is not supported for R8G8B8A8_UNORM.\n");
+ todo_wine
+ ok(!(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_SAMPLE),
+ "SHADER_SAMPLE is supported for R32G32B32A32_UINT.\n");
+ if (feature_level >= D3D_FEATURE_LEVEL_10_0)
+ {
+ ok(format_support[DXGI_FORMAT_R32G32B32A32_UINT] & D3D11_FORMAT_SUPPORT_SHADER_LOAD,
+ "SHADER_LOAD is not supported for R32G32B32A32_UINT.\n");
+ }
+
check_format_support(format_support, feature_level,
index_buffers, ARRAY_SIZE(index_buffers),
D3D11_FORMAT_SUPPORT_IA_INDEX_BUFFER, "index buffer");
@@ -29365,7 +29396,7 @@ START_TEST(d3d11)
queue_test(test_index_buffer_offset);
queue_test(test_face_culling);
queue_test(test_line_antialiasing_blending);
- queue_for_each_feature_level(test_required_format_support);
+ queue_for_each_feature_level(test_format_support);
queue_for_each_9_x_feature_level(test_fl9_draw);
queue_test(test_ddy);
queue_test(test_shader_input_registers_limits);
--
2.21.0
3
2