-- v2: d2d1: Add a test for D2D1CreateDeviceContext(). d2d1: Implement D2D1CreateDeviceContext().
From: Dmitry Timoshkov dmitry@baikal.ru
Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- dlls/d2d1/d2d1.spec | 2 +- dlls/d2d1/factory.c | 22 ++++++++++++++++++++++ include/d2d1_1.idl | 2 ++ 3 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/dlls/d2d1/d2d1.spec b/dlls/d2d1/d2d1.spec index b44d7114044..693f2828c74 100644 --- a/dlls/d2d1/d2d1.spec +++ b/dlls/d2d1/d2d1.spec @@ -5,7 +5,7 @@ @ stdcall D2D1InvertMatrix(ptr) @ stdcall D2D1ConvertColorSpace(long long ptr) @ stdcall D2D1CreateDevice(ptr ptr ptr) -@ stub D2D1CreateDeviceContext +@ stdcall D2D1CreateDeviceContext(ptr ptr ptr) @ stdcall D2D1SinCos(float ptr ptr) @ stdcall D2D1Tan(float) @ stdcall D2D1Vec3Length(float float float) diff --git a/dlls/d2d1/factory.c b/dlls/d2d1/factory.c index 62cbeeb51dd..80c147638cd 100644 --- a/dlls/d2d1/factory.c +++ b/dlls/d2d1/factory.c @@ -1510,6 +1510,28 @@ HRESULT WINAPI D2D1CreateDevice(IDXGIDevice *dxgi_device, return hr; }
+HRESULT WINAPI D2D1CreateDeviceContext(IDXGISurface *dxgi_surface, + const D2D1_CREATION_PROPERTIES *properties, ID2D1DeviceContext **context) +{ + IDXGIDevice *dxgi_device; + ID2D1Device *device; + HRESULT hr; + + TRACE("dxgi_surface %p, properties %p, context %p.\n", dxgi_surface, properties, context); + + if (FAILED(hr = IDXGISurface_GetDevice(dxgi_surface, &IID_IDXGIDevice, (void **)&dxgi_device))) + return hr; + + if (SUCCEEDED(hr = D2D1CreateDevice(dxgi_device, properties, &device))) + { + hr = ID2D1Device_CreateDeviceContext(device, properties ? properties->options : D2D1_DEVICE_CONTEXT_OPTIONS_NONE, context); + ID2D1Device_Release(device); + } + + IDXGIDevice_Release(dxgi_device); + return hr; +} + void WINAPI D2D1SinCos(float angle, float *s, float *c) { TRACE("angle %.8e, s %p, c %p.\n", angle, s, c); diff --git a/include/d2d1_1.idl b/include/d2d1_1.idl index 5560f24a38e..ea46fa956eb 100644 --- a/include/d2d1_1.idl +++ b/include/d2d1_1.idl @@ -976,6 +976,8 @@ interface ID2D1Multithread : IUnknown
[local] HRESULT __stdcall D2D1CreateDevice(IDXGIDevice *dxgi_device, const D2D1_CREATION_PROPERTIES *creation_properties, ID2D1Device **device); +[local] HRESULT __stdcall D2D1CreateDeviceContext(IDXGISurface *dxgi_surface, + const D2D1_CREATION_PROPERTIES *creation_properties, ID2D1DeviceContext **context); [local] void __stdcall D2D1SinCos(float angle, float *s, float *c); [local] float __stdcall D2D1Tan(float angle); [local] float __stdcall D2D1Vec3Length(float x, float y, float z);
From: Dmitry Timoshkov dmitry@baikal.ru
Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- dlls/d2d1/tests/d2d1.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+)
diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index f83dcd8f075..14a986b019c 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -294,6 +294,7 @@ static const char test_ps_code[] =
static HRESULT (WINAPI *pD2D1CreateDevice)(IDXGIDevice *dxgi_device, const D2D1_CREATION_PROPERTIES *properties, ID2D1Device **device); +static HRESULT (WINAPI *pD2D1CreateDeviceContext)(IDXGISurface *,const D2D1_CREATION_PROPERTIES *,ID2D1DeviceContext **); static void (WINAPI *pD2D1SinCos)(float angle, float *s, float *c); static float (WINAPI *pD2D1Tan)(float angle); static float (WINAPI *pD2D1Vec3Length)(float x, float y, float z); @@ -9383,6 +9384,33 @@ static void test_create_device(BOOL d3d11) release_test_context(&ctx); }
+static void test_create_device_context(BOOL d3d11) +{ + D2D1_CREATION_PROPERTIES properties = {0}; + struct d2d1_test_context ctx; + ID2D1DeviceContext *context; + HRESULT hr; + + if (!pD2D1CreateDeviceContext) + { + win_skip("D2D1CreateDeviceContext() is unavailable.\n"); + return; + } + + if (!init_test_context(&ctx, d3d11)) + return; + + hr = pD2D1CreateDeviceContext(ctx.surface, NULL, &context); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ID2D1DeviceContext_Release(context); + + hr = pD2D1CreateDeviceContext(ctx.surface, &properties, &context); + ok(hr == S_OK, "Got unexpected hr %#lx.\n", hr); + ID2D1DeviceContext_Release(context); + + release_test_context(&ctx); +} + #define check_rt_bitmap_surface(r, s, o) check_rt_bitmap_surface_(__LINE__, r, s, o) static void check_rt_bitmap_surface_(unsigned int line, ID2D1RenderTarget *rt, BOOL has_surface, DWORD options) { @@ -16220,6 +16248,7 @@ START_TEST(d2d1) char **argv;
pD2D1CreateDevice = (void *)GetProcAddress(d2d1_dll, "D2D1CreateDevice"); + pD2D1CreateDeviceContext = (void *)GetProcAddress(d2d1_dll, "D2D1CreateDeviceContext"); pD2D1SinCos = (void *)GetProcAddress(d2d1_dll, "D2D1SinCos"); pD2D1Tan = (void *)GetProcAddress(d2d1_dll, "D2D1Tan"); pD2D1Vec3Length = (void *)GetProcAddress(d2d1_dll, "D2D1Vec3Length"); @@ -16275,6 +16304,7 @@ START_TEST(d2d1) queue_test(test_layer); queue_test(test_bezier_intersect); queue_test(test_create_device); + queue_test(test_create_device_context); queue_test(test_bitmap_surface); queue_test(test_device_context); queue_d3d10_test(test_invert_matrix);
On Wed Oct 1 16:50:52 2025 +0000, Dmitry Timoshkov wrote:
changed this line in [version 2 of the diff](/wine/wine/-/merge_requests/9084/diffs?diff_id=213716&start_sha=5c933d42ef7066322f48a2c0d894cb1ebd8425bb#68516ee7cd35fa9ee2d7cab4fb7ee1903040ba30_1522_1522)
Thanks, it makes sense.
This merge request was approved by Nikolay Sivov.