[PATCH 3/6] d3drm: Implement IDirect3DRM*_CreateTexture. (v5)

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


v5: Avoid redundant d3drm_validate_image call.

Signed-off-by: Aaryaman Vasishta <jem456.vasishta at gmail.com>
---
 dlls/d3drm/d3drm.c       | 35 +++++++++++++---------
 dlls/d3drm/tests/d3drm.c | 77 ++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 93 insertions(+), 19 deletions(-)

diff --git a/dlls/d3drm/d3drm.c b/dlls/d3drm/d3drm.c
index 2b428ef..96f23a5 100644
--- a/dlls/d3drm/d3drm.c
+++ b/dlls/d3drm/d3drm.c
@@ -195,17 +195,19 @@ static HRESULT WINAPI d3drm1_CreateAnimationSet(IDirect3DRM *iface, IDirect3DRMA
 static HRESULT WINAPI d3drm1_CreateTexture(IDirect3DRM *iface,
         D3DRMIMAGE *image, IDirect3DRMTexture **texture)
 {
-    struct d3drm_texture *object;
+    struct d3drm *d3drm = impl_from_IDirect3DRM(iface);
+    IDirect3DRMTexture3 *texture3;
     HRESULT hr;
 
-    FIXME("iface %p, image %p, texture %p partial stub.\n", iface, image, texture);
+    TRACE("iface %p, image %p, texture %p.\n", iface, image, texture);
 
-    if (FAILED(hr = d3drm_texture_create(&object)))
+    if (FAILED(hr = IDirect3DRM3_CreateTexture(&d3drm->IDirect3DRM3_iface, image, &texture3)))
         return hr;
 
-    *texture = &object->IDirect3DRMTexture_iface;
+    hr = IDirect3DRMTexture3_QueryInterface(texture3, &IID_IDirect3DRMTexture, (void **)texture);
+    IDirect3DRMTexture3_Release(texture3);
 
-    return D3DRM_OK;
+    return hr;
 }
 
 static HRESULT WINAPI d3drm1_CreateLight(IDirect3DRM *iface,
@@ -661,17 +663,19 @@ static HRESULT WINAPI d3drm2_CreateAnimationSet(IDirect3DRM2 *iface, IDirect3DRM
 static HRESULT WINAPI d3drm2_CreateTexture(IDirect3DRM2 *iface,
         D3DRMIMAGE *image, IDirect3DRMTexture2 **texture)
 {
-    struct d3drm_texture *object;
+    struct d3drm *d3drm = impl_from_IDirect3DRM2(iface);
+    IDirect3DRMTexture3 *texture3;
     HRESULT hr;
 
-    FIXME("iface %p, image %p, texture %p partial stub.\n", iface, image, texture);
+    TRACE("iface %p, image %p, texture %p.\n", iface, image, texture);
 
-    if (FAILED(hr = d3drm_texture_create(&object)))
+    if (FAILED(hr = IDirect3DRM3_CreateTexture(&d3drm->IDirect3DRM3_iface, image, &texture3)))
         return hr;
 
-    *texture = &object->IDirect3DRMTexture2_iface;
+    hr = IDirect3DRMTexture3_QueryInterface(texture3, &IID_IDirect3DRMTexture2, (void **)texture);
+    IDirect3DRMTexture3_Release(texture3);
 
-    return D3DRM_OK;
+    return hr;
 }
 
 static HRESULT WINAPI d3drm2_CreateLight(IDirect3DRM2 *iface,
@@ -1152,15 +1156,18 @@ static HRESULT WINAPI d3drm3_CreateAnimationSet(IDirect3DRM3 *iface, IDirect3DRM
 static HRESULT WINAPI d3drm3_CreateTexture(IDirect3DRM3 *iface,
         D3DRMIMAGE *image, IDirect3DRMTexture3 **texture)
 {
-    struct d3drm_texture *object;
     HRESULT hr;
 
-    FIXME("iface %p, image %p, texture %p partial stub.\n", iface, image, texture);
+    TRACE("iface %p, image %p, texture %p.\n", iface, image, texture);
 
-    if (FAILED(hr = d3drm_texture_create(&object)))
+    if (FAILED(hr = IDirect3DRM3_CreateObject(iface, &CLSID_CDirect3DRMTexture, NULL, &IID_IDirect3DRMTexture3, (void **)texture)))
         return hr;
 
-    *texture = &object->IDirect3DRMTexture3_iface;
+    if (FAILED(hr = IDirect3DRMTexture3_InitFromImage(*texture, image)))
+    {
+        IDirect3DRMTexture3_Release(*texture);
+        return D3DRMERR_BADVALUE;
+    }
 
     return D3DRM_OK;
 }
diff --git a/dlls/d3drm/tests/d3drm.c b/dlls/d3drm/tests/d3drm.c
index 1f57058..309e56b 100644
--- a/dlls/d3drm/tests/d3drm.c
+++ b/dlls/d3drm/tests/d3drm.c
@@ -1725,11 +1725,75 @@ static void test_Texture(void)
     hr = IDirect3DRM_QueryInterface(d3drm1, &IID_IDirect3DRM3, (void **)&d3drm3);
     ok(SUCCEEDED(hr), "Cannot get IDirect3DRM3 interface (hr = %x).\n", hr);
 
+    /* Tests for validation of D3DRMIMAGE struct */
+    hr = IDirect3DRM_CreateTexture(d3drm1, &testimg, &texture1);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %x)\n", hr);
+    hr = IDirect3DRM2_CreateTexture(d3drm2, &testimg, &texture2);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %x)\n", hr);
+    hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %x)\n", hr);
+    IDirect3DRMTexture_Release(texture1);
+    IDirect3DRMTexture2_Release(texture2);
+    IDirect3DRMTexture3_Release(texture3);
+
+    testimg.rgb = 0;
+    testimg.palette = (void *)0xdeadbeef;
+    testimg.palette_size = 0x39;
+    hr = IDirect3DRM_CreateTexture(d3drm1, &testimg, &texture1);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (hr = %x)\n", hr);
+    hr = IDirect3DRM2_CreateTexture(d3drm2, &testimg, &texture2);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %x)\n", hr);
+    hr = IDirect3DRM3_CreateTexture(d3drm3, &testimg, &texture3);
+    ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %x)\n", hr);
+    IDirect3DRMTexture_Release(texture1);
+    IDirect3DRMTexture2_Release(texture2);
+    IDirect3DRMTexture3_Release(texture3);
+
+    initimg.rgb = 0;
+    hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    initimg.rgb = 1;
+    initimg.red_mask = 0;
+    hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    initimg.red_mask = 0x000000ff;
+    initimg.green_mask = 0;
+    hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    initimg.green_mask = 0x0000ff00;
+    initimg.blue_mask = 0;
+    hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    initimg.blue_mask = 0x00ff0000;
+    initimg.buffer1 = NULL;
+    hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+    hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
+    ok(hr == D3DRMERR_BADVALUE, "Expected hr == D3DRMERR_BADVALUE, got %x.\n", hr);
+
     initimg.buffer1 = &pixel;
     hr = IDirect3DRM_CreateTexture(d3drm1, &initimg, &texture1);
     ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture interface (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);
@@ -1737,7 +1801,7 @@ static void test_Texture(void)
     hr = IDirect3DRM2_CreateTexture(d3drm2, &initimg, &texture2);
     ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture2 interface (hr = %x)\n", hr);
     ref2 = get_refcount((IUnknown *)d3drm1);
-    todo_wine ok(ref2 > ref1 + 1, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
+    ok(ref2 > ref1 + 1, "expected ref2 > (ref1 + 1), 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);
@@ -1745,7 +1809,7 @@ static void test_Texture(void)
     hr = IDirect3DRM3_CreateTexture(d3drm3, &initimg, &texture3);
     ok(SUCCEEDED(hr), "Cannot get IDirect3DRMTexture3 interface (hr = %x)\n", hr);
     ref2 = get_refcount((IUnknown *)d3drm1);
-    todo_wine ok(ref2 > ref1 + 2, "expected ref2 > ref1, got ref1 = %u , ref2 = %u.\n", ref1, ref2);
+    ok(ref2 > ref1 + 2, "expected ref2 > (ref1 + 2), 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);
@@ -1803,7 +1867,7 @@ static void test_Texture(void)
 
     IDirect3DRMTexture_Release(texture1);
     ref2 = get_refcount((IUnknown *)d3drm1);
-    todo_wine ok(ref2 - 2 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
+    ok(ref2 - 2 == ref1, "expected (ref2 - 2) == 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);
@@ -1827,7 +1891,7 @@ static void test_Texture(void)
 
     IDirect3DRMTexture2_Release(texture2);
     ref2 = get_refcount((IUnknown *)d3drm1);
-    todo_wine ok(ref2 - 1 == ref1, "expected ref2 == ref1, got ref1 = %u, ref2 = %u.\n", ref1, ref2);
+    ok(ref2 - 1 == ref1, "expected (ref2 - 1) == 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);
@@ -1860,6 +1924,9 @@ static void test_Texture(void)
     /* InitFromImage tests */
 
     /* Tests for validation of D3DRMIMAGE struct */
+    testimg.rgb = 1;
+    testimg.palette = NULL;
+    testimg.palette_size = 0;
     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);
-- 
2.3.2 (Apple Git-55)




More information about the wine-patches mailing list