https://bugs.winehq.org/show_bug.cgi?id=44052
Signed-off-by: Lucian Poston lucian.poston@gmail.com --- dlls/d2d1/tests/Makefile.in | 2 +- dlls/d2d1/tests/d2d1.c | 145 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 1 deletion(-)
diff --git a/dlls/d2d1/tests/Makefile.in b/dlls/d2d1/tests/Makefile.in index 91ede7888a..5eeb815e07 100644 --- a/dlls/d2d1/tests/Makefile.in +++ b/dlls/d2d1/tests/Makefile.in @@ -1,5 +1,5 @@ TESTDLL = d2d1.dll -IMPORTS = d2d1 d3d10_1 dwrite dxguid uuid user32 advapi32 ole32 gdi32 +IMPORTS = d2d1 d3d10_1 d3d11 dwrite dxguid uuid user32 advapi32 ole32 gdi32
C_SRCS = \ d2d1.c diff --git a/dlls/d2d1/tests/d2d1.c b/dlls/d2d1/tests/d2d1.c index a0f22128fa..9c7c875b74 100644 --- a/dlls/d2d1/tests/d2d1.c +++ b/dlls/d2d1/tests/d2d1.c @@ -20,6 +20,8 @@ #include <limits.h> #include <math.h> #include "d2d1.h" +#include "d2d1_1.h" +#include "d3d11.h" #include "wincrypt.h" #include "wine/test.h" #include "initguid.h" @@ -609,6 +611,37 @@ static BOOL compare_figure(IDXGISurface *surface, unsigned int x, unsigned int y return diff <= max_diff; }
+static ID3D11Device *create_d11device(ID3D11DeviceContext **outContext) +{ + ID3D11Device *device; + ID3D11DeviceContext *context; + D3D_FEATURE_LEVEL feature_level = D3D_FEATURE_LEVEL_10_0; + + if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, + D3D11_CREATE_DEVICE_BGRA_SUPPORT, &feature_level, + 1, D3D11_SDK_VERSION, &device, NULL, &context))) + { + if (outContext) *outContext = context; + return device; + } + if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_WARP, NULL, + D3D11_CREATE_DEVICE_BGRA_SUPPORT, &feature_level, + 1, D3D11_SDK_VERSION, &device, NULL, &context))) + { + if (outContext) *outContext = context; + return device; + } + if (SUCCEEDED(D3D11CreateDevice(NULL, D3D_DRIVER_TYPE_REFERENCE, NULL, + D3D11_CREATE_DEVICE_BGRA_SUPPORT, &feature_level, + 1, D3D11_SDK_VERSION, &device, NULL, &context))) + { + if (outContext) *outContext = context; + return device; + } + + return NULL; +} + static ID3D10Device1 *create_device(void) { ID3D10Device1 *device; @@ -636,6 +669,47 @@ static HWND create_window(void) 0, 0, r.right - r.left, r.bottom - r.top, NULL, NULL, NULL, NULL); }
+static IDXGISwapChain *create_swapchain_d3d11(ID3D11Device *device, HWND window, BOOL windowed) +{ + IDXGISwapChain *swapchain; + DXGI_SWAP_CHAIN_DESC desc; + IDXGIDevice *dxgi_device; + IDXGIAdapter *adapter; + IDXGIFactory *factory; + HRESULT hr; + + hr = ID3D11Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device); + ok(SUCCEEDED(hr), "Failed to get DXGI device, hr %#x.\n", hr); + hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter); + ok(SUCCEEDED(hr), "Failed to get adapter, hr %#x.\n", hr); + IDXGIDevice_Release(dxgi_device); + hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory); + ok(SUCCEEDED(hr), "Failed to get factory, hr %#x.\n", hr); + IDXGIAdapter_Release(adapter); + + desc.BufferDesc.Width = 640; + desc.BufferDesc.Height = 480; + desc.BufferDesc.RefreshRate.Numerator = 60; + desc.BufferDesc.RefreshRate.Denominator = 1; + desc.BufferDesc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; + desc.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED; + desc.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED; + desc.SampleDesc.Count = 1; + desc.SampleDesc.Quality = 0; + desc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT; + desc.BufferCount = 1; + desc.OutputWindow = window; + desc.Windowed = windowed; + desc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD; + desc.Flags = 0; + + hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)device, &desc, &swapchain); + ok(SUCCEEDED(hr), "Failed to create swapchain, hr %#x.\n", hr); + IDXGIFactory_Release(factory); + + return swapchain; +} + static IDXGISwapChain *create_swapchain(ID3D10Device1 *device, HWND window, BOOL windowed) { IDXGISwapChain *swapchain; @@ -4625,6 +4699,76 @@ todo_wine DestroyWindow(window); }
+static void test_draw_text_layout_with_ID2D1Factory1(void) +{ + HRESULT hr; + ID2D1Factory1 *factory; + ID2D1Device *device; + ID3D11Device *d3d11_device; + IDXGIDevice *dxgi_device; + ID2D1DeviceContext *context; + IDXGISurface *dxgi_surface; + ID2D1Bitmap1 *bitmap; + D2D1_BITMAP_PROPERTIES1 bitmap_properties; + IDXGISwapChain *swapchain; + HWND window; + ID2D1SolidColorBrush *brush; + D2D1_COLOR_F c; + D2D1_RECT_F r; + c.r = .5; c.g = .5; c.b = .5; c.a = .5; + r.top = 10; r.left = 10; r.bottom = 90; r.right = 90; + + if (!(d3d11_device = create_d11device(NULL))) + { + skip("Failed to create device, skipping test.\n"); + return; + } + + window = create_window(); + swapchain = create_swapchain_d3d11(d3d11_device, window, TRUE); + hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGISurface, (void **)&dxgi_surface); + ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr); + + hr = D2D1CreateFactory(D2D1_FACTORY_TYPE_SINGLE_THREADED, + &IID_ID2D1Factory1, NULL, (void**)&factory); + ok(SUCCEEDED(hr), "Failed to create factory, hr %#x.\n", hr); + hr = ID3D11Device_QueryInterface(d3d11_device, &IID_IDXGIDevice, + (void**)&dxgi_device); + ok(SUCCEEDED(hr), "Failed to create dxgi_device, hr %#x.\n", hr); + hr = ID2D1Factory1_CreateDevice(factory, dxgi_device, &device); + ok(SUCCEEDED(hr), "Failed to create device, hr %#x.\n", hr); + hr = ID2D1Device_CreateDeviceContext(device, + D2D1_DEVICE_CONTEXT_OPTIONS_NONE, &context); + ok(SUCCEEDED(hr), "Failed to create device context, hr %#x.\n", hr); + bitmap_properties.pixelFormat.format = DXGI_FORMAT_UNKNOWN; + bitmap_properties.pixelFormat.alphaMode = D2D1_ALPHA_MODE_IGNORE; + bitmap_properties.dpiX = 96.0; + bitmap_properties.dpiY = 96.0; + bitmap_properties.bitmapOptions = D2D1_BITMAP_OPTIONS_TARGET | D2D1_BITMAP_OPTIONS_CANNOT_DRAW; + hr = ID2D1DeviceContext_CreateBitmapFromDxgiSurface(context, dxgi_surface, + &bitmap_properties, &bitmap); + ok(SUCCEEDED(hr), "Failed to create bitmap, hr %#x.\n", hr); + ID2D1DeviceContext_SetTarget(context, (ID2D1Image *)bitmap); + ID2D1DeviceContext_CreateSolidColorBrush(context, &c, NULL, &brush); + ID2D1DeviceContext_BeginDraw(context); + ID2D1DeviceContext_DrawRectangle(context, &r, (ID2D1Brush *)brush, 1.0f, NULL); + hr = ID2D1DeviceContext_EndDraw(context, NULL, NULL); + ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr); + hr = IDXGISwapChain_Present(swapchain, 0, 0); + ok(SUCCEEDED(hr), "Failed to present image, hr %#x.\n", hr); + + ID2D1SolidColorBrush_Release(brush); + DestroyWindow(window); + IDXGISwapChain_Release(swapchain); + ID2D1Bitmap1_Release(bitmap); + IDXGISurface_Release(dxgi_surface); + ID2D1DeviceContext_Release(context); + IDXGIDevice_Release(dxgi_device); + ID3D11Device_Release(d3d11_device); + ID2D1Device_Release(device); + ID2D1Factory1_Release(factory); +} + static void create_target_dibsection(HDC hdc, UINT32 width, UINT32 height) { char bmibuf[FIELD_OFFSET(BITMAPINFO, bmiColors[256])]; @@ -6402,6 +6546,7 @@ START_TEST(d2d1) test_opacity_brush(); test_create_target(); test_draw_text_layout(); + test_draw_text_layout_with_ID2D1Factory1(); test_dc_target(); test_hwnd_target(); test_bitmap_target();