From: Nikolay Sivov Subject: [PATCH 4/4] d2d1: Implement CreateDeviceContext(). Message-Id: <20180926003450.32195-4-nsivov@codeweavers.com> Date: Wed, 26 Sep 2018 03:34:50 +0300 In-Reply-To: <20180926003450.32195-1-nsivov@codeweavers.com> References: <20180926003450.32195-1-nsivov@codeweavers.com> Signed-off-by: Nikolay Sivov --- dlls/d2d1/device.c | 23 +++++++++++++++++++++-- dlls/d2d1/tests/d2d1.c | 16 +++++++--------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/dlls/d2d1/device.c b/dlls/d2d1/device.c index 212e9c0df9..b1b719e2eb 100644 --- a/dlls/d2d1/device.c +++ b/dlls/d2d1/device.c @@ -3865,9 +3865,28 @@ static void WINAPI d2d_device_GetFactory(ID2D1Device *iface, ID2D1Factory **fact static HRESULT WINAPI d2d_device_CreateDeviceContext(ID2D1Device *iface, D2D1_DEVICE_CONTEXT_OPTIONS options, ID2D1DeviceContext **context) { - FIXME("iface %p, options %#x, context %p stub!\n", iface, options, context); + struct d2d_device_context *object; + HRESULT hr; - return E_NOTIMPL; + TRACE("iface %p, options %#x, context %p.\n", iface, options, context); + + if (options) + FIXME("Options are ignored %#x.\n", options); + + if (!(object = heap_alloc_zero(sizeof(*object)))) + return E_OUTOFMEMORY; + + if (FAILED(hr = d2d_device_context_init(object, iface, NULL, NULL))) + { + WARN("Failed to initialize device context, hr %#x.\n", hr); + heap_free(object); + return hr; + } + + TRACE("Created device context %p.\n", object); + *context = &object->ID2D1DeviceContext_iface; + + return S_OK; } static HRESULT WINAPI d2d_device_CreatePrintControl(ID2D1Device *iface, IWICImagingFactory *wic_factory, diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index c2e0ab2a08..e6320e51b0 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -6962,11 +6962,8 @@ static void test_bitmap_surface(void) ok(SUCCEEDED(hr), "Failed to get ID2D1Device, hr %#x.\n", hr); hr = ID2D1Device_CreateDeviceContext(device, D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &device_context); -todo_wine ok(SUCCEEDED(hr), "Failed to create device context, hr %#x.\n", hr); -if (SUCCEEDED(hr)) -{ for (i = 0; i < ARRAY_SIZE(bitmap_format_tests); ++i) { D2D1_PIXEL_FORMAT pixel_format; @@ -6976,9 +6973,10 @@ if (SUCCEEDED(hr)) bitmap_desc.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW; hr = ID2D1DeviceContext_CreateBitmapFromDxgiSurface(device_context, surface, &bitmap_desc, &bitmap); + todo_wine_if(FAILED(bitmap_format_tests[i].hr)) ok(hr == bitmap_format_tests[i].hr, "%u: unexpected hr %#x.\n", i, hr); - if (SUCCEEDED(hr)) + if (SUCCEEDED(bitmap_format_tests[i].hr)) { pixel_format = ID2D1Bitmap1_GetPixelFormat(bitmap); @@ -7005,7 +7003,7 @@ if (SUCCEEDED(hr)) ID2D1DeviceContext_Release(device_context); ID2D1Bitmap1_Release(bitmap); -} + ID2D1Device_Release(device); IDXGIDevice_Release(dxgi_device); IDXGISurface_Release(surface); @@ -7108,11 +7106,8 @@ static void test_device_context(void) IDXGIDevice_Release(dxgi_device); hr = ID2D1Device_CreateDeviceContext(device, D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &device_context); -todo_wine ok(SUCCEEDED(hr), "Failed to create device context, hr %#x.\n", hr); -if (SUCCEEDED(hr)) -{ ID2D1DeviceContext_GetDevice(device_context, &device2); ok(device2 == device, "Unexpected device instance.\n"); ID2D1Device_Release(device2); @@ -7190,6 +7185,7 @@ if (SUCCEEDED(hr)) ok(options == (D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW), "Unexpected bitmap options %#x.\n", options); hr = ID2D1Bitmap1_GetSurface(bitmap, &surface); +todo_wine ok(hr == E_FAIL, "Unexpected hr %#x.\n", hr); ID2D1Bitmap1_Release(bitmap); @@ -7238,6 +7234,7 @@ if (SUCCEEDED(hr)) hr = ID2D1DCRenderTarget_QueryInterface(dc_rt, &IID_ID2D1DeviceContext, (void **)&device_context); ok(SUCCEEDED(hr), "Failed to get device context interface, hr %#x.\n", hr); ID2D1DeviceContext_GetTarget(device_context, (ID2D1Image **)&bitmap); +todo_wine ok(bitmap == NULL, "Unexpected bitmap instance.\n"); hdc = CreateCompatibleDC(NULL); @@ -7251,6 +7248,7 @@ if (SUCCEEDED(hr)) ID2D1DeviceContext_GetTarget(device_context, (ID2D1Image **)&bitmap); options = ID2D1Bitmap1_GetOptions(bitmap); +todo_wine ok(options == (D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW | D2D1_BITMAP_OPTIONS_GDI_COMPATIBLE), "Unexpected bitmap options %#x.\n", options); hr = ID2D1Bitmap1_GetSurface(bitmap, &surface); @@ -7264,7 +7262,7 @@ if (SUCCEEDED(hr)) ID2D1DeviceContext_Release(device_context); ID2D1DCRenderTarget_Release(dc_rt); DeleteDC(hdc); -} + ID2D1Device_Release(device); ID2D1Factory1_Release(factory); ID3D10Device1_Release(d3d_device); -- 2.19.0