d2d1/tests: Add a test for ID2D1DrawingStateBlock.

This commit is contained in:
Henri Verbeet 2015-03-30 09:17:03 +02:00 committed by Alexandre Julliard
parent 59e641aa70
commit 7baf2a0f55
2 changed files with 217 additions and 1 deletions

View File

@ -1,5 +1,5 @@
TESTDLL = d2d1.dll TESTDLL = d2d1.dll
IMPORTS = d2d1 d3d10_1 dxguid uuid user32 advapi32 IMPORTS = d2d1 d3d10_1 dwrite dxguid uuid user32 advapi32
C_SRCS = \ C_SRCS = \
d2d1.c d2d1.c

View File

@ -20,6 +20,8 @@
#include "d2d1.h" #include "d2d1.h"
#include "wincrypt.h" #include "wincrypt.h"
#include "wine/test.h" #include "wine/test.h"
#include "initguid.h"
#include "dwrite.h"
static void set_point(D2D1_POINT_2F *point, float x, float y) static void set_point(D2D1_POINT_2F *point, float x, float y)
{ {
@ -331,7 +333,221 @@ static void test_clip(void)
DestroyWindow(window); DestroyWindow(window);
} }
static void test_state_block(void)
{
IDWriteRenderingParams *text_rendering_params1, *text_rendering_params2;
D2D1_DRAWING_STATE_DESCRIPTION drawing_state;
ID2D1DrawingStateBlock *state_block;
IDWriteFactory *dwrite_factory;
IDXGISwapChain *swapchain;
ID2D1RenderTarget *rt;
ID3D10Device1 *device;
IDXGISurface *surface;
ID2D1Factory *factory;
ULONG refcount;
HWND window;
HRESULT hr;
static const D2D1_MATRIX_3X2_F identity =
{
1.0f, 0.0f,
0.0f, 1.0f,
0.0f, 0.0f,
};
static const D2D1_MATRIX_3X2_F transform1 =
{
1.0f, 2.0f,
3.0f, 4.0f,
5.0f, 6.0f,
};
static const D2D1_MATRIX_3X2_F transform2 =
{
7.0f, 8.0f,
9.0f, 10.0f,
11.0f, 12.0f,
};
if (!(device = create_device()))
{
skip("Failed to create device, skipping tests.\n");
return;
}
window = CreateWindowA("static", "d2d1_test", WS_OVERLAPPEDWINDOW | WS_VISIBLE,
0, 0, 640, 480, NULL, NULL, NULL, NULL);
swapchain = create_swapchain(device, window, TRUE);
hr = IDXGISwapChain_GetBuffer(swapchain, 0, &IID_IDXGISurface, (void **)&surface);
ok(SUCCEEDED(hr), "Failed to get buffer, hr %#x.\n", hr);
rt = create_render_target(surface);
ok(!!rt, "Failed to create render target.\n");
ID2D1RenderTarget_GetFactory(rt, &factory);
hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, &IID_IDWriteFactory, (IUnknown **)&dwrite_factory);
ok(SUCCEEDED(hr), "Failed to create dwrite factory, hr %#x.\n", hr);
hr = IDWriteFactory_CreateRenderingParams(dwrite_factory, &text_rendering_params1);
ok(SUCCEEDED(hr), "Failed to create dwrite rendering params, hr %#x.\n", hr);
IDWriteFactory_Release(dwrite_factory);
drawing_state.antialiasMode = ID2D1RenderTarget_GetAntialiasMode(rt);
ok(drawing_state.antialiasMode == D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
"Got unexpected antialias mode %#x.\n", drawing_state.antialiasMode);
drawing_state.textAntialiasMode = ID2D1RenderTarget_GetTextAntialiasMode(rt);
ok(drawing_state.textAntialiasMode == D2D1_TEXT_ANTIALIAS_MODE_DEFAULT,
"Got unexpected text antialias mode %#x.\n", drawing_state.textAntialiasMode);
ID2D1RenderTarget_GetTags(rt, &drawing_state.tag1, &drawing_state.tag2);
ok(!drawing_state.tag1 && !drawing_state.tag2, "Got unexpected tags %08x%08x:%08x%08x.\n",
(unsigned int)(drawing_state.tag1 >> 32), (unsigned int)(drawing_state.tag1),
(unsigned int)(drawing_state.tag2 >> 32), (unsigned int)(drawing_state.tag2));
ID2D1RenderTarget_GetTransform(rt, &drawing_state.transform);
ok(!memcmp(&drawing_state.transform, &identity, sizeof(drawing_state.transform)),
"Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
drawing_state.transform._11, drawing_state.transform._12, drawing_state.transform._21,
drawing_state.transform._22, drawing_state.transform._31, drawing_state.transform._32);
ID2D1RenderTarget_GetTextRenderingParams(rt, &text_rendering_params2);
ok(!text_rendering_params2, "Got unexpected text rendering params %p.\n", text_rendering_params2);
hr = ID2D1Factory_CreateDrawingStateBlock(factory, NULL, NULL, &state_block);
ok(SUCCEEDED(hr), "Failed to create drawing state block, hr %#x\n", hr);
ID2D1DrawingStateBlock_GetDescription(state_block, &drawing_state);
ok(drawing_state.antialiasMode == D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
"Got unexpected antialias mode %#x.\n", drawing_state.antialiasMode);
ok(drawing_state.textAntialiasMode == D2D1_TEXT_ANTIALIAS_MODE_DEFAULT,
"Got unexpected text antialias mode %#x.\n", drawing_state.textAntialiasMode);
ok(!drawing_state.tag1 && !drawing_state.tag2, "Got unexpected tags %08x%08x:%08x%08x.\n",
(unsigned int)(drawing_state.tag1 >> 32), (unsigned int)(drawing_state.tag1),
(unsigned int)(drawing_state.tag2 >> 32), (unsigned int)(drawing_state.tag2));
ok(!memcmp(&drawing_state.transform, &identity, sizeof(drawing_state.transform)),
"Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
drawing_state.transform._11, drawing_state.transform._12, drawing_state.transform._21,
drawing_state.transform._22, drawing_state.transform._31, drawing_state.transform._32);
ID2D1DrawingStateBlock_GetTextRenderingParams(state_block, &text_rendering_params2);
ok(!text_rendering_params2, "Got unexpected text rendering params %p.\n", text_rendering_params2);
ID2D1DrawingStateBlock_Release(state_block);
drawing_state.antialiasMode = D2D1_ANTIALIAS_MODE_ALIASED;
drawing_state.textAntialiasMode = D2D1_TEXT_ANTIALIAS_MODE_ALIASED;
drawing_state.tag1 = 0xdead;
drawing_state.tag2 = 0xbeef;
drawing_state.transform = transform1;
hr = ID2D1Factory_CreateDrawingStateBlock(factory, &drawing_state, text_rendering_params1, &state_block);
ok(SUCCEEDED(hr), "Failed to create drawing state block, hr %#x\n", hr);
ID2D1DrawingStateBlock_GetDescription(state_block, &drawing_state);
ok(drawing_state.antialiasMode == D2D1_ANTIALIAS_MODE_ALIASED,
"Got unexpected antialias mode %#x.\n", drawing_state.antialiasMode);
ok(drawing_state.textAntialiasMode == D2D1_TEXT_ANTIALIAS_MODE_ALIASED,
"Got unexpected text antialias mode %#x.\n", drawing_state.textAntialiasMode);
ok(drawing_state.tag1 == 0xdead && drawing_state.tag2 == 0xbeef, "Got unexpected tags %08x%08x:%08x%08x.\n",
(unsigned int)(drawing_state.tag1 >> 32), (unsigned int)(drawing_state.tag1),
(unsigned int)(drawing_state.tag2 >> 32), (unsigned int)(drawing_state.tag2));
ok(!memcmp(&drawing_state.transform, &transform1, sizeof(drawing_state.transform)),
"Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
drawing_state.transform._11, drawing_state.transform._12, drawing_state.transform._21,
drawing_state.transform._22, drawing_state.transform._31, drawing_state.transform._32);
ID2D1DrawingStateBlock_GetTextRenderingParams(state_block, &text_rendering_params2);
ok(text_rendering_params2 == text_rendering_params1, "Got unexpected text rendering params %p, expected %p.\n",
text_rendering_params2, text_rendering_params1);
IDWriteRenderingParams_Release(text_rendering_params2);
ID2D1RenderTarget_RestoreDrawingState(rt, state_block);
drawing_state.antialiasMode = ID2D1RenderTarget_GetAntialiasMode(rt);
ok(drawing_state.antialiasMode == D2D1_ANTIALIAS_MODE_ALIASED,
"Got unexpected antialias mode %#x.\n", drawing_state.antialiasMode);
drawing_state.textAntialiasMode = ID2D1RenderTarget_GetTextAntialiasMode(rt);
ok(drawing_state.textAntialiasMode == D2D1_TEXT_ANTIALIAS_MODE_ALIASED,
"Got unexpected text antialias mode %#x.\n", drawing_state.textAntialiasMode);
ID2D1RenderTarget_GetTags(rt, &drawing_state.tag1, &drawing_state.tag2);
ok(drawing_state.tag1 == 0xdead && drawing_state.tag2 == 0xbeef, "Got unexpected tags %08x%08x:%08x%08x.\n",
(unsigned int)(drawing_state.tag1 >> 32), (unsigned int)(drawing_state.tag1),
(unsigned int)(drawing_state.tag2 >> 32), (unsigned int)(drawing_state.tag2));
ID2D1RenderTarget_GetTransform(rt, &drawing_state.transform);
ok(!memcmp(&drawing_state.transform, &transform1, sizeof(drawing_state.transform)),
"Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
drawing_state.transform._11, drawing_state.transform._12, drawing_state.transform._21,
drawing_state.transform._22, drawing_state.transform._31, drawing_state.transform._32);
ID2D1RenderTarget_GetTextRenderingParams(rt, &text_rendering_params2);
ok(text_rendering_params2 == text_rendering_params1, "Got unexpected text rendering params %p, expected %p.\n",
text_rendering_params2, text_rendering_params1);
IDWriteRenderingParams_Release(text_rendering_params2);
ID2D1RenderTarget_SetAntialiasMode(rt, D2D1_ANTIALIAS_MODE_PER_PRIMITIVE);
ID2D1RenderTarget_SetTextAntialiasMode(rt, D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE);
ID2D1RenderTarget_SetTags(rt, 1, 2);
ID2D1RenderTarget_SetTransform(rt, &transform2);
ID2D1RenderTarget_SetTextRenderingParams(rt, NULL);
drawing_state.antialiasMode = ID2D1RenderTarget_GetAntialiasMode(rt);
ok(drawing_state.antialiasMode == D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
"Got unexpected antialias mode %#x.\n", drawing_state.antialiasMode);
drawing_state.textAntialiasMode = ID2D1RenderTarget_GetTextAntialiasMode(rt);
ok(drawing_state.textAntialiasMode == D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE,
"Got unexpected text antialias mode %#x.\n", drawing_state.textAntialiasMode);
ID2D1RenderTarget_GetTags(rt, &drawing_state.tag1, &drawing_state.tag2);
ok(drawing_state.tag1 == 1 && drawing_state.tag2 == 2, "Got unexpected tags %08x%08x:%08x%08x.\n",
(unsigned int)(drawing_state.tag1 >> 32), (unsigned int)(drawing_state.tag1),
(unsigned int)(drawing_state.tag2 >> 32), (unsigned int)(drawing_state.tag2));
ID2D1RenderTarget_GetTransform(rt, &drawing_state.transform);
ok(!memcmp(&drawing_state.transform, &transform2, sizeof(drawing_state.transform)),
"Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
drawing_state.transform._11, drawing_state.transform._12, drawing_state.transform._21,
drawing_state.transform._22, drawing_state.transform._31, drawing_state.transform._32);
ID2D1RenderTarget_GetTextRenderingParams(rt, &text_rendering_params2);
ok(!text_rendering_params2, "Got unexpected text rendering params %p.\n", text_rendering_params2);
ID2D1RenderTarget_SaveDrawingState(rt, state_block);
ID2D1DrawingStateBlock_GetDescription(state_block, &drawing_state);
ok(drawing_state.antialiasMode == D2D1_ANTIALIAS_MODE_PER_PRIMITIVE,
"Got unexpected antialias mode %#x.\n", drawing_state.antialiasMode);
ok(drawing_state.textAntialiasMode == D2D1_TEXT_ANTIALIAS_MODE_GRAYSCALE,
"Got unexpected text antialias mode %#x.\n", drawing_state.textAntialiasMode);
ok(drawing_state.tag1 == 1 && drawing_state.tag2 == 2, "Got unexpected tags %08x%08x:%08x%08x.\n",
(unsigned int)(drawing_state.tag1 >> 32), (unsigned int)(drawing_state.tag1),
(unsigned int)(drawing_state.tag2 >> 32), (unsigned int)(drawing_state.tag2));
ok(!memcmp(&drawing_state.transform, &transform2, sizeof(drawing_state.transform)),
"Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
drawing_state.transform._11, drawing_state.transform._12, drawing_state.transform._21,
drawing_state.transform._22, drawing_state.transform._31, drawing_state.transform._32);
ID2D1DrawingStateBlock_GetTextRenderingParams(state_block, &text_rendering_params2);
ok(!text_rendering_params2, "Got unexpected text rendering params %p.\n", text_rendering_params2);
drawing_state.antialiasMode = D2D1_ANTIALIAS_MODE_ALIASED;
drawing_state.textAntialiasMode = D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE;
drawing_state.tag1 = 3;
drawing_state.tag2 = 4;
drawing_state.transform = transform1;
ID2D1DrawingStateBlock_SetDescription(state_block, &drawing_state);
ID2D1DrawingStateBlock_SetTextRenderingParams(state_block, text_rendering_params1);
ID2D1DrawingStateBlock_GetDescription(state_block, &drawing_state);
ok(drawing_state.antialiasMode == D2D1_ANTIALIAS_MODE_ALIASED,
"Got unexpected antialias mode %#x.\n", drawing_state.antialiasMode);
ok(drawing_state.textAntialiasMode == D2D1_TEXT_ANTIALIAS_MODE_CLEARTYPE,
"Got unexpected text antialias mode %#x.\n", drawing_state.textAntialiasMode);
ok(drawing_state.tag1 == 3 && drawing_state.tag2 == 4, "Got unexpected tags %08x%08x:%08x%08x.\n",
(unsigned int)(drawing_state.tag1 >> 32), (unsigned int)(drawing_state.tag1),
(unsigned int)(drawing_state.tag2 >> 32), (unsigned int)(drawing_state.tag2));
ok(!memcmp(&drawing_state.transform, &transform1, sizeof(drawing_state.transform)),
"Got unexpected matrix {%.8e, %.8e, %.8e, %.8e, %.8e, %.8e}.\n",
drawing_state.transform._11, drawing_state.transform._12, drawing_state.transform._21,
drawing_state.transform._22, drawing_state.transform._31, drawing_state.transform._32);
ID2D1DrawingStateBlock_GetTextRenderingParams(state_block, &text_rendering_params2);
ok(text_rendering_params2 == text_rendering_params1, "Got unexpected text rendering params %p, expected %p.\n",
text_rendering_params2, text_rendering_params1);
IDWriteRenderingParams_Release(text_rendering_params2);
ID2D1DrawingStateBlock_Release(state_block);
refcount = IDWriteRenderingParams_Release(text_rendering_params1);
ok(!refcount, "Rendering params %u references left.\n", refcount);
ID2D1Factory_Release(factory);
ID2D1RenderTarget_Release(rt);
IDXGISurface_Release(surface);
IDXGISwapChain_Release(swapchain);
ID3D10Device1_Release(device);
DestroyWindow(window);
}
START_TEST(d2d1) START_TEST(d2d1)
{ {
test_clip(); test_clip();
test_state_block();
} }