From: Piotr Caban piotr@codeweavers.com
Signed-off-by: Piotr Caban piotr@codeweavers.com --- dlls/d3dx10_43/async.c | 83 +++++++++++++++++++++++++++++++++++++- dlls/d3dx10_43/dxhelpers.h | 2 + dlls/d3dx10_43/texture.c | 41 ++++++++++--------- 3 files changed, 105 insertions(+), 21 deletions(-)
diff --git a/dlls/d3dx10_43/async.c b/dlls/d3dx10_43/async.c index f0c726944c0..9efe52f0792 100644 --- a/dlls/d3dx10_43/async.c +++ b/dlls/d3dx10_43/async.c @@ -16,6 +16,7 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA */
+#define COBJMACROS #include "d3d10_1.h" #include "d3dx10.h" #include "d3dcompiler.h" @@ -315,6 +316,68 @@ static ID3DX10DataProcessorVtbl texture_info_processor_vtbl = texture_info_processor_Destroy };
+struct texture_processor +{ + ID3DX10DataProcessor ID3DX10DataProcessor_iface; + ID3D10Device *device; + D3DX10_IMAGE_LOAD_INFO *info; + ID3D10Resource *texture; +}; + +static inline struct texture_processor *texture_processor_from_ID3DX10DataProcessor(ID3DX10DataProcessor *iface) +{ + return CONTAINING_RECORD(iface, struct texture_processor, ID3DX10DataProcessor_iface); +} + +static HRESULT WINAPI texture_processor_Process(ID3DX10DataProcessor *iface, void *data, SIZE_T size) +{ + struct texture_processor *processor = texture_processor_from_ID3DX10DataProcessor(iface); + + TRACE("iface %p, data %p, size %Iu.\n", iface, data, size); + + if (processor->texture) + { + FIXME("called multiple times\n"); + ID3D10Resource_Release(processor->texture); + processor->texture = NULL; + } + return create_texture(processor->device, data, size, processor->info, &processor->texture); +} + +static HRESULT WINAPI texture_processor_CreateDeviceObject(ID3DX10DataProcessor *iface, void **object) +{ + struct texture_processor *processor = texture_processor_from_ID3DX10DataProcessor(iface); + + TRACE("iface %p, object %p.\n", iface, object); + + if (!processor->texture) + return E_FAIL; + + *object = processor->texture; + ID3D10Resource_AddRef(processor->texture); + return S_OK; +} + +static HRESULT WINAPI texture_processor_Destroy(ID3DX10DataProcessor *iface) +{ + struct texture_processor *processor = texture_processor_from_ID3DX10DataProcessor(iface); + + TRACE("iface %p.\n", iface); + + if (processor->texture) + ID3D10Resource_Release(processor->texture); + ID3D10Device_Release(processor->device); + free(processor); + return S_OK; +} + +static ID3DX10DataProcessorVtbl texture_processor_vtbl = +{ + texture_processor_Process, + texture_processor_CreateDeviceObject, + texture_processor_Destroy +}; + HRESULT WINAPI D3DX10CompileFromMemory(const char *data, SIZE_T data_size, const char *filename, const D3D10_SHADER_MACRO *defines, ID3D10Include *include, const char *entry_point, const char *target, UINT sflags, UINT eflags, ID3DX10ThreadPump *pump, ID3D10Blob **shader, @@ -517,8 +580,24 @@ HRESULT WINAPI D3DX10CreateAsyncTextureInfoProcessor(D3DX10_IMAGE_INFO *info, ID HRESULT WINAPI D3DX10CreateAsyncTextureProcessor(ID3D10Device *device, D3DX10_IMAGE_LOAD_INFO *info, ID3DX10DataProcessor **processor) { - FIXME("device %p, info %p, processor %p stub!\n", device, info, processor); - return E_NOTIMPL; + struct texture_processor *object; + + TRACE("device %p, info %p, processor %p.\n", device, info, processor); + + if (!device || !processor) + return E_INVALIDARG; + + object = calloc(1, sizeof(*object)); + if (!object) + return E_OUTOFMEMORY; + + object->ID3DX10DataProcessor_iface.lpVtbl = &texture_processor_vtbl; + object->device = device; + ID3D10Device_AddRef(device); + object->info = info; + + *processor = &object->ID3DX10DataProcessor_iface; + return S_OK; }
HRESULT WINAPI D3DX10PreprocessShaderFromMemory(const char *data, SIZE_T data_size, const char *filename, diff --git a/dlls/d3dx10_43/dxhelpers.h b/dlls/d3dx10_43/dxhelpers.h index 82fe639c2ea..1ecbd9f7866 100644 --- a/dlls/d3dx10_43/dxhelpers.h +++ b/dlls/d3dx10_43/dxhelpers.h @@ -23,3 +23,5 @@ extern HRESULT load_resourceW(HMODULE module, const WCHAR *resource, void **data, DWORD *size) DECLSPEC_HIDDEN;
extern HRESULT get_image_info(const void *data, SIZE_T size, D3DX10_IMAGE_INFO *img_info) DECLSPEC_HIDDEN; +extern HRESULT create_texture(ID3D10Device *device, const void *data, SIZE_T size, + D3DX10_IMAGE_LOAD_INFO *load_info, ID3D10Resource **texture) DECLSPEC_HIDDEN; diff --git a/dlls/d3dx10_43/texture.c b/dlls/d3dx10_43/texture.c index d5066b9793b..0f4212b97ef 100644 --- a/dlls/d3dx10_43/texture.c +++ b/dlls/d3dx10_43/texture.c @@ -669,8 +669,8 @@ HRESULT WINAPI D3DX10CreateTextureFromResourceW(ID3D10Device *device, HMODULE mo return D3DX10CreateTextureFromMemory(device, buffer, size, load_info, pump, texture, hresult); }
-HRESULT WINAPI D3DX10CreateTextureFromMemory(ID3D10Device *device, const void *src_data, SIZE_T src_data_size, - D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult) +HRESULT create_texture(ID3D10Device *device, const void *data, SIZE_T size, + D3DX10_IMAGE_LOAD_INFO *load_info, ID3D10Resource **texture) { unsigned int frame_count, width, height, stride, frame_size; IWICFormatConverter *converter = NULL; @@ -689,29 +689,14 @@ HRESULT WINAPI D3DX10CreateTextureFromMemory(ID3D10Device *device, const void *s GUID src_format; HRESULT hr;
- TRACE("device %p, src_data %p, src_data_size %Iu, load_info %p, pump %p, texture %p, hresult %p.\n", - device, src_data, src_data_size, load_info, pump, texture, hresult); - - if (!device) - return E_INVALIDARG; - if (!src_data) - return E_FAIL; if (load_info) FIXME("load_info is ignored.\n"); - if (pump) - FIXME("Thread pump is not supported yet.\n");
- if (FAILED(D3DX10GetImageInfoFromMemory(src_data, src_data_size, NULL, &img_info, NULL))) - { - if (hresult) - *hresult = E_FAIL; + if (FAILED(D3DX10GetImageInfoFromMemory(data, size, NULL, &img_info, NULL))) return E_FAIL; - } if (img_info.MiscFlags & D3D10_RESOURCE_MISC_TEXTURECUBE) { FIXME("Cube map is not supported.\n"); - if (hresult) - *hresult = E_FAIL; return E_FAIL; }
@@ -719,7 +704,7 @@ HRESULT WINAPI D3DX10CreateTextureFromMemory(ID3D10Device *device, const void *s goto end; if (FAILED(hr = IWICImagingFactory_CreateStream(factory, &stream))) goto end; - if (FAILED(hr = IWICStream_InitializeFromMemory(stream, (BYTE *)src_data, src_data_size))) + if (FAILED(hr = IWICStream_InitializeFromMemory(stream, (BYTE *)data, size))) goto end; if (FAILED(hr = IWICImagingFactory_CreateDecoderFromStream(factory, (IStream *)stream, NULL, 0, &decoder))) goto end; @@ -822,7 +807,25 @@ end: IWICStream_Release(stream); if (factory) IWICImagingFactory_Release(factory); + return hr; +} + +HRESULT WINAPI D3DX10CreateTextureFromMemory(ID3D10Device *device, const void *src_data, SIZE_T src_data_size, + D3DX10_IMAGE_LOAD_INFO *load_info, ID3DX10ThreadPump *pump, ID3D10Resource **texture, HRESULT *hresult) +{ + HRESULT hr; + + TRACE("device %p, src_data %p, src_data_size %Iu, load_info %p, pump %p, texture %p, hresult %p.\n", + device, src_data, src_data_size, load_info, pump, texture, hresult); + + if (!device) + return E_INVALIDARG; + if (!src_data) + return E_FAIL; + if (pump) + FIXME("Thread pump is not supported yet.\n");
+ hr = create_texture(device, src_data, src_data_size, load_info, texture); if (hresult) *hresult = hr; return hr;