[PATCH 2/6] d3drm: Implement IDirect3DRMTexture{2-3}_InitFromImage. (v5)

Aaryaman Vasishta jem456.vasishta at gmail.com
Wed May 11 14:19:17 CDT 2016


v5: Replace release of IDirect3DRM reference, remove redundant declarations.

Signed-off-by: Aaryaman Vasishta <jem456.vasishta at gmail.com>
---
 dlls/d3drm/d3drm.c         |   2 +
 dlls/d3drm/d3drm_private.h |   2 +
 dlls/d3drm/tests/d3drm.c   | 102 +++++++++++++++++++++++++++++++++++++++------
 dlls/d3drm/texture.c       |  40 ++++++++++++++++--
 4 files changed, 129 insertions(+), 17 deletions(-)

diff --git a/dlls/d3drm/d3drm.c b/dlls/d3drm/d3drm.c
index edb46df..2b428ef 100644
--- a/dlls/d3drm/d3drm.c
+++ b/dlls/d3drm/d3drm.c
@@ -1058,6 +1058,7 @@ static ULONG WINAPI d3drm3_Release(IDirect3DRM3 *iface)
 static HRESULT WINAPI d3drm3_CreateObject(IDirect3DRM3 *iface,
         REFCLSID clsid, IUnknown *outer, REFIID iid, void **out)
 {
+    struct d3drm *d3drm = impl_from_IDirect3DRM3(iface);
     IUnknown *object;
     HRESULT hr;
 
@@ -1088,6 +1089,7 @@ static HRESULT WINAPI d3drm3_CreateObject(IDirect3DRM3 *iface,
             *out = NULL;
             return hr;
         }
+        texture->d3drm = &d3drm->IDirect3DRM_iface;
         object = (IUnknown *)&texture->IDirect3DRMTexture3_iface;
     }
     else
diff --git a/dlls/d3drm/d3drm_private.h b/dlls/d3drm/d3drm_private.h
index 2eb8e4d..c2bae1ca 100644
--- a/dlls/d3drm/d3drm_private.h
+++ b/dlls/d3drm/d3drm_private.h
@@ -40,6 +40,8 @@ struct d3drm_texture
     IDirect3DRMTexture IDirect3DRMTexture_iface;
     IDirect3DRMTexture2 IDirect3DRMTexture2_iface;
     IDirect3DRMTexture3 IDirect3DRMTexture3_iface;
+    IDirect3DRM *d3drm;
+    D3DRMIMAGE *image;
 };
 
 void d3drm_object_init(struct d3drm_object *object) DECLSPEC_HIDDEN;
diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c
index 583dbec..1f57058 100644
--- a/dlls/d3drm/tests/d3drm.c
+++ b/dlls/d3drm/tests/d3drm.c
@@ -1705,6 +1705,11 @@ static void test_Texture(void)
         TRUE, 2 * sizeof(DWORD), NULL, NULL,
         0x000000ff, 0x0000ff00, 0x00ff0000, 0xff000000, 0, NULL
     }, *d3drm_img = NULL;
+    D3DRMIMAGE testimg = {
+        0, 0, 0, 0, 0,
+        TRUE, 0, (void *)0xcafebabe, NULL,
+        0x000000ff, 0x0000ff00, 0x00ff0000, 0, 0, NULL
+    };
     DWORD pixel[4] = { 20000, 30000, 10000, 0 };
     DWORD size;
     CHAR cname[64] = {0};
@@ -1853,22 +1858,95 @@ static void test_Texture(void)
     ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
 
     /* InitFromImage tests */
-    d3drm_img = NULL;
+
+    /* Tests for validation of D3DRMIMAGE struct */
+    hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2, (void **)&texture2);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %x).\n", hr);
+    hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3, (void **)&texture3);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %x).\n", hr);
+    hr = IDirect3DRMTexture2_InitFromImage(texture2, &testimg);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %x)\n", hr);
+    hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %x)\n", hr);
+    IDirect3DRMTexture2_Release(texture2);
+    IDirect3DRMTexture3_Release(texture3);
+
+    testimg.rgb = 0;
+    testimg.palette = (void *)0xdeadbeef;
+    testimg.palette_size = 0x39;
+    hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2, (void **)&texture2);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %x).\n", hr);
+    hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3, (void **)&texture3);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %x).\n", hr);
+    hr = IDirect3DRMTexture2_InitFromImage(texture2, &testimg);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %x)\n", hr);
+    hr = IDirect3DRMTexture3_InitFromImage(texture3, &testimg);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %x)\n", hr);
+    IDirect3DRMTexture2_Release(texture2);
+    IDirect3DRMTexture3_Release(texture3);
+
     hr = IDirect3DRM2_CreateObject(d3drm2, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture2, (void **)&texture2);
     ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %x).\n", hr);
     ref2 = get_refcount((IUnknown *)texture2);
     hr = IDirect3DRMTexture2_InitFromImage(texture2, NULL);
-    todo_wine ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
     ref3 = get_refcount((IUnknown *)texture2);
     ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
+
+    hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3, (void **)&texture3);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %x).\n", hr);
+    ref2 = get_refcount((IUnknown *)texture3);
+    hr = IDirect3DRMTexture3_InitFromImage(texture3, NULL);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    ref3 = get_refcount((IUnknown *)texture3);
+    ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
+
+    initimg.rgb = 0;
+    hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    initimg.rgb = 1;
+    initimg.red_mask = 0;
+    hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    initimg.red_mask = 0x000000ff;
+    initimg.green_mask = 0;
+    hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    initimg.green_mask = 0x0000ff00;
+    initimg.blue_mask = 0;
+    hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    initimg.blue_mask = 0x00ff0000;
+    initimg.buffer1 = NULL;
     hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
-    todo_wine ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 from image (hr = %x).\n", hr);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    initimg.buffer1 = &pixel;
+
+    d3drm_img = NULL;
+    hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
+    ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture2 from image (hr = %x).\n", hr);
     ref2 = get_refcount((IUnknown *)d3drm1);
-    todo_wine ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
+    ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
     ref3 = get_refcount((IUnknown *)d3drm2);
     ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
     ref4 = get_refcount((IUnknown *)d3drm3);
     ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
+
+    hr = IDirect3DRMTexture2_InitFromImage(texture2, &initimg);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    /* Release leaked reference to d3drm1 */
+    IDirect3DRM_Release(d3drm1);
+
     d3drm_img = IDirect3DRMTexture2_GetImage(texture2);
     todo_wine ok(!!d3drm_img, "Failed to get image.\n");
     todo_wine ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
@@ -1881,21 +1959,19 @@ static void test_Texture(void)
     ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u, ref4 = %u.\n", ref1, ref4);
 
     d3drm_img = NULL;
-    hr = IDirect3DRM3_CreateObject(d3drm3, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3, (void **)&texture3);
-    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %x).\n", hr);
-    ref2 = get_refcount((IUnknown *)texture3);
-    hr = IDirect3DRMTexture3_InitFromImage(texture3, NULL);
-    todo_wine ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
-    ref3 = get_refcount((IUnknown *)texture3);
-    ok(ref3 == ref2, "expected ref3 == ref2, got ref2 = %u , ref3 = %u.\n", ref2, ref3);
     hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
-    todo_wine ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 from image (hr = %x).\n", hr);
+    ok(SUCCEEDED(hr), "Cannot initialize IDirect3DRMTexture3 from image (hr = %x).\n", hr);
     ref2 = get_refcount((IUnknown *)d3drm1);
-    todo_wine ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
+    ok(ref2 > ref1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
     ref3 = get_refcount((IUnknown *)d3drm2);
     ok(ref3 == ref1, "expected ref3 == ref1, got ref1 = %u , ref3 = %u.\n", ref1, ref3);
     ref4 = get_refcount((IUnknown *)d3drm3);
     ok(ref4 == ref1, "expected ref4 == ref1, got ref1 = %u , ref4 = %u.\n", ref1, ref4);
+
+    hr = IDirect3DRMTexture3_InitFromImage(texture3, &initimg);
+    ok(hr == D3DRMERR_BADOBJECT, "Expected hr == D3DRMERR_BADOBJECT, got %x.\n", hr);
+    IDirect3DRM_Release(d3drm1);
+
     d3drm_img = IDirect3DRMTexture3_GetImage(texture3);
     todo_wine ok(!!d3drm_img, "Failed to get image.\n");
     todo_wine ok(d3drm_img == &initimg, "Expected image returned == %p, got %p.\n", &initimg, d3drm_img);
diff --git a/dlls/d3drm/texture.c b/dlls/d3drm/texture.c
index 98c6bdb..bf84e82 100644
--- a/dlls/d3drm/texture.c
+++ b/dlls/d3drm/texture.c
@@ -47,9 +47,26 @@ static inline struct d3drm_texture *impl_from_IDirect3DRMTexture3(IDirect3DRMTex
 void d3drm_texture_destroy(struct d3drm_texture *texture)
 {
     d3drm_object_cleanup((IDirect3DRMObject*)&texture->IDirect3DRMTexture3_iface, &texture->obj);
+    if (texture->image)
+        IDirect3DRM_Release(texture->d3drm);
     HeapFree(GetProcessHeap(), 0, texture);
 }
 
+BOOL d3drm_validate_image(D3DRMIMAGE *image)
+{
+    if (!image
+            || !image->red_mask
+            || !image->green_mask
+            || !image->blue_mask
+            || !image->buffer1
+            || !(image->rgb || (image->palette && image->palette_size)))
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
 static HRESULT WINAPI d3drm_texture1_QueryInterface(IDirect3DRMTexture *iface, REFIID riid, void **out)
 {
     struct d3drm_texture *texture = impl_from_IDirect3DRMTexture(iface);
@@ -618,9 +635,11 @@ static D3DCOLOR WINAPI d3drm_texture2_GetDecalTransparentColor(IDirect3DRMTextur
 
 static HRESULT WINAPI d3drm_texture2_InitFromImage(IDirect3DRMTexture2 *iface, D3DRMIMAGE *image)
 {
-    FIXME("iface %p, image %p stub!\n", iface, image);
+    struct d3drm_texture *texture = impl_from_IDirect3DRMTexture2(iface);
 
-    return E_NOTIMPL;
+    TRACE("iface %p, image %p.\n", iface, image);
+
+    return IDirect3DRMTexture3_InitFromImage(&texture->IDirect3DRMTexture3_iface, image);
 }
 
 static HRESULT WINAPI d3drm_texture2_InitFromResource2(IDirect3DRMTexture2 *iface,
@@ -945,9 +964,22 @@ static D3DCOLOR WINAPI d3drm_texture3_GetDecalTransparentColor(IDirect3DRMTextur
 
 static HRESULT WINAPI d3drm_texture3_InitFromImage(IDirect3DRMTexture3 *iface, D3DRMIMAGE *image)
 {
-    FIXME("iface %p, image %p stub!\n", iface, image);
+    struct d3drm_texture *texture = impl_from_IDirect3DRMTexture3(iface);
 
-    return E_NOTIMPL;
+    TRACE("iface %p, image %p.\n", iface, image);
+
+    if (!d3drm_validate_image(image))
+        return D3DRMERR_BADOBJECT;
+
+    /* d3drm intentionally leaks a reference to IDirect3DRM here if texture has already been initialized. */
+    IDirect3DRM_AddRef(texture->d3drm);
+
+    if (texture->image)
+        return D3DRMERR_BADOBJECT;
+
+    texture->image = image;
+
+    return D3DRM_OK;
 }
 
 static HRESULT WINAPI d3drm_texture3_InitFromResource2(IDirect3DRMTexture3 *iface,
-- 
2.3.2 (Apple Git-55)




More information about the wine-patches mailing list