~ubuntu-branches/ubuntu/saucy/wine1.4/saucy-proposed

« back to all changes in this revision

Viewing changes to dlls/ddraw/tests/ddraw4.c

  • Committer: Package Import Robot
  • Author(s): Scott Ritchie
  • Date: 2012-03-04 19:51:50 UTC
  • mfrom: (1.1.5)
  • Revision ID: package-import@ubuntu.com-20120304195150-2lmdcr1d09y4xnqf
Tags: 1.4~rc6-0ubuntu1
* New upstream release
  - Bug fixes only, we are in code freeze.
* debian/control: 
  - explicitly depend on libncurses5 (LP: #938310)
  - bump breaks/replaces to packages before rc6

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
#include <limits.h>
22
22
#include "d3d.h"
23
23
 
 
24
struct vec2
 
25
{
 
26
    float x, y;
 
27
};
 
28
 
24
29
struct vec3
25
30
{
26
31
    float x, y, z;
1310
1315
    IDirectDraw4_Release(ddraw);
1311
1316
}
1312
1317
 
1313
 
static LONG get_refcount(IUnknown *test_iface)
 
1318
static ULONG get_refcount(IUnknown *test_iface)
1314
1319
{
1315
1320
    IUnknown_AddRef(test_iface);
1316
1321
    return IUnknown_Release(test_iface);
1321
1326
    IDirectDraw4 *ddraw;
1322
1327
    IDirect3D3 *d3d;
1323
1328
    HRESULT hr, old_d3d_ref;
1324
 
    LONG ref;
 
1329
    ULONG ref;
1325
1330
    IDirect3DViewport *viewport;
1326
1331
    IDirect3DViewport2 *viewport2;
1327
1332
    IDirect3DViewport3 *viewport3;
1346
1351
    hr = IDirect3D3_CreateViewport(d3d, &viewport3, NULL);
1347
1352
    ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
1348
1353
    ref = get_refcount((IUnknown *)viewport3);
1349
 
    ok(ref == 1, "Initial IDirect3DViewport3 refcount is %d\n", ref);
 
1354
    ok(ref == 1, "Initial IDirect3DViewport3 refcount is %u\n", ref);
1350
1355
    ref = get_refcount((IUnknown *)d3d);
1351
 
    ok(ref == old_d3d_ref, "IDirect3D3 refcount is %d\n", ref);
 
1356
    ok(ref == old_d3d_ref, "IDirect3D3 refcount is %u\n", ref);
1352
1357
 
1353
1358
    gamma = (IDirectDrawGammaControl *)0xdeadbeef;
1354
1359
    hr = IDirect3DViewport2_QueryInterface(viewport3, &IID_IDirectDrawGammaControl, (void **)&gamma);
1362
1367
    if (viewport)
1363
1368
    {
1364
1369
        ref = get_refcount((IUnknown *)viewport);
1365
 
        ok(ref == 2, "IDirect3DViewport refcount is %d\n", ref);
 
1370
        ok(ref == 2, "IDirect3DViewport refcount is %u\n", ref);
1366
1371
        ref = get_refcount((IUnknown *)viewport3);
1367
 
        ok(ref == 2, "IDirect3DViewport3 refcount is %d\n", ref);
 
1372
        ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1368
1373
        IDirect3DViewport_Release(viewport);
1369
1374
        viewport = NULL;
1370
1375
    }
1374
1379
    if (viewport2)
1375
1380
    {
1376
1381
        ref = get_refcount((IUnknown *)viewport2);
1377
 
        ok(ref == 2, "IDirect3DViewport2 refcount is %d\n", ref);
 
1382
        ok(ref == 2, "IDirect3DViewport2 refcount is %u\n", ref);
1378
1383
        ref = get_refcount((IUnknown *)viewport3);
1379
 
        ok(ref == 2, "IDirect3DViewport3 refcount is %d\n", ref);
 
1384
        ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1380
1385
        IDirect3DViewport3_Release(viewport2);
1381
1386
    }
1382
1387
 
1383
 
    hr = IDirect3DViewport3_QueryInterface(viewport2, &IID_IUnknown, (void **)&unknown);
 
1388
    hr = IDirect3DViewport3_QueryInterface(viewport3, &IID_IUnknown, (void **)&unknown);
1384
1389
    ok(SUCCEEDED(hr), "Failed to QI IUnknown, hr %#x.\n", hr);
1385
1390
    if (unknown)
1386
1391
    {
1387
1392
        ref = get_refcount((IUnknown *)viewport3);
1388
 
        ok(ref == 2, "IDirect3DViewport3 refcount is %d\n", ref);
 
1393
        ok(ref == 2, "IDirect3DViewport3 refcount is %u\n", ref);
1389
1394
        ref = get_refcount(unknown);
1390
 
        ok(ref == 2, "IUnknown refcount is %d\n", ref);
 
1395
        ok(ref == 2, "IUnknown refcount is %u\n", ref);
1391
1396
        IUnknown_Release(unknown);
1392
1397
    }
1393
1398
 
1490
1495
    DestroyWindow(window);
1491
1496
}
1492
1497
 
 
1498
static void test_ck_rgba(void)
 
1499
{
 
1500
    static D3DRECT clear_rect = {{0}, {0}, {640}, {480}};
 
1501
    static struct
 
1502
    {
 
1503
        struct vec4 position;
 
1504
        struct vec2 texcoord;
 
1505
    }
 
1506
    tquad[] =
 
1507
    {
 
1508
        {{  0.0f, 480.0f, 0.25f, 1.0f}, {0.0f, 0.0f}},
 
1509
        {{  0.0f,   0.0f, 0.25f, 1.0f}, {0.0f, 1.0f}},
 
1510
        {{640.0f, 480.0f, 0.25f, 1.0f}, {1.0f, 0.0f}},
 
1511
        {{640.0f,   0.0f, 0.25f, 1.0f}, {1.0f, 1.0f}},
 
1512
        {{  0.0f, 480.0f, 0.75f, 1.0f}, {0.0f, 0.0f}},
 
1513
        {{  0.0f,   0.0f, 0.75f, 1.0f}, {0.0f, 1.0f}},
 
1514
        {{640.0f, 480.0f, 0.75f, 1.0f}, {1.0f, 0.0f}},
 
1515
        {{640.0f,   0.0f, 0.75f, 1.0f}, {1.0f, 1.0f}},
 
1516
    };
 
1517
    static const struct
 
1518
    {
 
1519
        D3DCOLOR fill_color;
 
1520
        BOOL color_key;
 
1521
        BOOL blend;
 
1522
        D3DCOLOR result1;
 
1523
        D3DCOLOR result2;
 
1524
    }
 
1525
    tests[] =
 
1526
    {
 
1527
        {0xff00ff00, TRUE,  TRUE,  0x00ff0000, 0x000000ff},
 
1528
        {0xff00ff00, TRUE,  FALSE, 0x00ff0000, 0x000000ff},
 
1529
        {0xff00ff00, FALSE, TRUE,  0x0000ff00, 0x0000ff00},
 
1530
        {0xff00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
 
1531
        {0x7f00ff00, TRUE,  TRUE,  0x00807f00, 0x00807f00},
 
1532
        {0x7f00ff00, TRUE,  FALSE, 0x0000ff00, 0x0000ff00},
 
1533
        {0x7f00ff00, FALSE, TRUE,  0x00807f00, 0x00807f00},
 
1534
        {0x7f00ff00, FALSE, FALSE, 0x0000ff00, 0x0000ff00},
 
1535
    };
 
1536
 
 
1537
    IDirectDrawSurface4 *surface;
 
1538
    IDirect3DViewport3 *viewport;
 
1539
    DDSURFACEDESC2 surface_desc;
 
1540
    IDirect3DTexture2 *texture;
 
1541
    IDirect3DDevice3 *device;
 
1542
    IDirectDrawSurface4 *rt;
 
1543
    IDirectDraw4 *ddraw;
 
1544
    D3DVIEWPORT2 vp;
 
1545
    IDirect3D3 *d3d;
 
1546
    D3DCOLOR color;
 
1547
    HWND window;
 
1548
    DDBLTFX fx;
 
1549
    HRESULT hr;
 
1550
    UINT i;
 
1551
 
 
1552
    window = CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW,
 
1553
            0, 0, 640, 480, 0, 0, 0, 0);
 
1554
    if (!(device = create_device(window, DDSCL_NORMAL)))
 
1555
    {
 
1556
        skip("Failed to create D3D device, skipping test.\n");
 
1557
        DestroyWindow(window);
 
1558
        return;
 
1559
    }
 
1560
 
 
1561
    hr = IDirect3DDevice3_GetDirect3D(device, &d3d);
 
1562
    ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
 
1563
 
 
1564
    hr = IDirect3D3_CreateViewport(d3d, &viewport, NULL);
 
1565
    ok(SUCCEEDED(hr), "Failed to create viewport, hr %#x.\n", hr);
 
1566
    hr = IDirect3DDevice3_AddViewport(device, viewport);
 
1567
    ok(SUCCEEDED(hr), "Failed to add viewport, hr %#x.\n", hr);
 
1568
    memset(&vp, 0, sizeof(vp));
 
1569
    vp.dwSize = sizeof(vp);
 
1570
    vp.dwX = 0;
 
1571
    vp.dwY = 0;
 
1572
    vp.dwWidth = 640;
 
1573
    vp.dwHeight = 480;
 
1574
    vp.dvClipX = -1.0f;
 
1575
    vp.dvClipY =  1.0f;
 
1576
    vp.dvClipWidth = 2.0f;
 
1577
    vp.dvClipHeight = 2.0f;
 
1578
    vp.dvMinZ = 0.0f;
 
1579
    vp.dvMaxZ = 1.0f;
 
1580
    hr = IDirect3DViewport3_SetViewport2(viewport, &vp);
 
1581
    ok(SUCCEEDED(hr), "Failed to set viewport data, hr %#x.\n", hr);
 
1582
    hr = IDirect3DDevice3_SetCurrentViewport(device, viewport);
 
1583
    ok(SUCCEEDED(hr), "Failed to set current viewport, hr %#x.\n", hr);
 
1584
    hr = IDirect3D3_QueryInterface(d3d, &IID_IDirectDraw4, (void **)&ddraw);
 
1585
    ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
 
1586
 
 
1587
    IDirect3D3_Release(d3d);
 
1588
 
 
1589
    memset(&surface_desc, 0, sizeof(surface_desc));
 
1590
    surface_desc.dwSize = sizeof(surface_desc);
 
1591
    surface_desc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT | DDSD_PIXELFORMAT | DDSD_CKSRCBLT;
 
1592
    surface_desc.ddsCaps.dwCaps = DDSCAPS_TEXTURE;
 
1593
    surface_desc.dwWidth = 256;
 
1594
    surface_desc.dwHeight = 256;
 
1595
    U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
 
1596
    U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB | DDPF_ALPHAPIXELS;
 
1597
    U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
 
1598
    U2(U4(surface_desc).ddpfPixelFormat).dwRBitMask = 0x00ff0000;
 
1599
    U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
 
1600
    U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
 
1601
    U5(U4(surface_desc).ddpfPixelFormat).dwRGBAlphaBitMask = 0xff000000;
 
1602
    surface_desc.ddckCKSrcBlt.dwColorSpaceLowValue = 0xff00ff00;
 
1603
    surface_desc.ddckCKSrcBlt.dwColorSpaceHighValue = 0xff00ff00;
 
1604
    hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
 
1605
    ok(SUCCEEDED(hr), "Failed to create destination surface, hr %#x.\n", hr);
 
1606
    hr = IDirectDrawSurface4_QueryInterface(surface, &IID_IDirect3DTexture2, (void **)&texture);
 
1607
    ok(SUCCEEDED(hr), "Failed to get texture interface, hr %#x.\n", hr);
 
1608
 
 
1609
    hr = IDirect3DDevice3_SetTexture(device, 0, texture);
 
1610
    ok(SUCCEEDED(hr), "Failed to set texture, hr %#x.\n", hr);
 
1611
    hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA);
 
1612
    ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
 
1613
    hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA);
 
1614
    ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
 
1615
 
 
1616
    hr = IDirect3DDevice3_GetRenderTarget(device, &rt);
 
1617
    ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
 
1618
 
 
1619
    for (i = 0; i < sizeof(tests) / sizeof(*tests); ++i)
 
1620
    {
 
1621
        hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_COLORKEYENABLE, tests[i].color_key);
 
1622
        ok(SUCCEEDED(hr), "Failed to enable color keying, hr %#x.\n", hr);
 
1623
        hr = IDirect3DDevice3_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, tests[i].blend);
 
1624
        ok(SUCCEEDED(hr), "Failed to enable alpha blending, hr %#x.\n", hr);
 
1625
 
 
1626
        memset(&fx, 0, sizeof(fx));
 
1627
        fx.dwSize = sizeof(fx);
 
1628
        U5(fx).dwFillColor = tests[i].fill_color;
 
1629
        hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
 
1630
        ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
 
1631
 
 
1632
        hr = IDirect3DViewport3_Clear2(viewport, 1, &clear_rect,
 
1633
                D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, 0xffff0000, 1.0f, 0);
 
1634
        ok(SUCCEEDED(hr), "Failed to clear viewport, hr %#x.\n", hr);
 
1635
        hr = IDirect3DDevice3_BeginScene(device);
 
1636
        ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
 
1637
        hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[0], 4, 0);
 
1638
        ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
 
1639
        hr = IDirect3DDevice3_EndScene(device);
 
1640
        ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
 
1641
 
 
1642
        color = get_surface_color(rt, 320, 240);
 
1643
        if (i == 2)
 
1644
            todo_wine ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
 
1645
                    tests[i].result1, i, color);
 
1646
        else
 
1647
            ok(compare_color(color, tests[i].result1, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
 
1648
                    tests[i].result1, i, color);
 
1649
 
 
1650
        U5(fx).dwFillColor = 0xff0000ff;
 
1651
        hr = IDirectDrawSurface4_Blt(surface, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &fx);
 
1652
        ok(SUCCEEDED(hr), "Failed to fill texture, hr %#x.\n", hr);
 
1653
 
 
1654
        hr = IDirect3DDevice3_BeginScene(device);
 
1655
        ok(SUCCEEDED(hr), "Failed to begin scene, hr %#x.\n", hr);
 
1656
        hr = IDirect3DDevice3_DrawPrimitive(device, D3DPT_TRIANGLESTRIP, D3DFVF_XYZRHW | D3DFVF_TEX1, &tquad[4], 4, 0);
 
1657
        ok(SUCCEEDED(hr), "Failed to draw, hr %#x.\n", hr);
 
1658
        hr = IDirect3DDevice3_EndScene(device);
 
1659
        ok(SUCCEEDED(hr), "Failed to end scene, hr %#x.\n", hr);
 
1660
 
 
1661
        /* This tests that fragments that are masked out by the color key are
 
1662
         * discarded, instead of just fully transparent. */
 
1663
        color = get_surface_color(rt, 320, 240);
 
1664
        if (i == 2)
 
1665
            todo_wine ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
 
1666
                    tests[i].result2, i, color);
 
1667
        else
 
1668
            ok(compare_color(color, tests[i].result2, 1), "Expected color 0x%08x for test %u, got 0x%08x.\n",
 
1669
                    tests[i].result2, i, color);
 
1670
    }
 
1671
 
 
1672
    IDirectDrawSurface4_Release(rt);
 
1673
    IDirect3DTexture2_Release(texture);
 
1674
    IDirectDrawSurface4_Release(surface);
 
1675
    hr = IDirect3DDevice3_DeleteViewport(device, viewport);
 
1676
    ok(SUCCEEDED(hr), "Failed to delete viewport, hr %#x.\n", hr);
 
1677
    IDirect3DViewport3_Release(viewport);
 
1678
    IDirectDraw4_Release(ddraw);
 
1679
    IDirect3DDevice3_Release(device);
 
1680
    DestroyWindow(window);
 
1681
}
 
1682
 
1493
1683
START_TEST(ddraw4)
1494
1684
{
1495
1685
    test_process_vertices();
1502
1692
    test_texture_load_ckey();
1503
1693
    test_viewport_interfaces();
1504
1694
    test_zenable();
 
1695
    test_ck_rgba();
1505
1696
}