windowscodecs: Implement SetResolution for BMP frame encoder.
[wine] / dlls / dxgi / tests / device.c
1 /*
2  * Copyright 2008 Henri Verbeet for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #define COBJMACROS
20 #include "initguid.h"
21 #include "d3d10.h"
22 #include "wine/test.h"
23
24 HRESULT WINAPI DXGID3D10CreateDevice(HMODULE d3d10core, IDXGIFactory *factory,
25         IDXGIAdapter *adapter, UINT flags, DWORD arg5, void **device);
26
27 static IDXGIDevice *create_device(HMODULE d3d10core)
28 {
29     IDXGIDevice *dxgi_device = NULL;
30     IDXGIFactory *factory = NULL;
31     IDXGIAdapter *adapter = NULL;
32     IUnknown *device = NULL;
33     HRESULT hr;
34
35     hr = CreateDXGIFactory(&IID_IDXGIFactory, (void *)&factory);
36     if (FAILED(hr)) goto cleanup;
37
38     hr = IDXGIFactory_EnumAdapters(factory, 0, &adapter);
39     ok(SUCCEEDED(hr), "EnumAdapters failed, hr %#x\n", hr);
40     if (FAILED(hr)) goto cleanup;
41
42     hr = DXGID3D10CreateDevice(d3d10core, factory, adapter, 0, 0, (void **)&device);
43     if (FAILED(hr))
44     {
45         HMODULE d3d10ref;
46
47         trace("Failed to create a HW device, trying REF\n");
48         IDXGIAdapter_Release(adapter);
49         adapter = NULL;
50
51         d3d10ref = LoadLibraryA("d3d10ref.dll");
52         if (!d3d10ref)
53         {
54             trace("d3d10ref.dll not available, unable to create a REF device\n");
55             goto cleanup;
56         }
57
58         hr = IDXGIFactory_CreateSoftwareAdapter(factory, d3d10ref, &adapter);
59         FreeLibrary(d3d10ref);
60         ok(SUCCEEDED(hr), "CreateSoftwareAdapter failed, hr %#x\n", hr);
61         if (FAILED(hr)) goto cleanup;
62
63         hr = DXGID3D10CreateDevice(d3d10core, factory, adapter, 0, 0, (void **)&device);
64         ok(SUCCEEDED(hr), "Failed to create a REF device, hr %#x\n", hr);
65         if (FAILED(hr)) goto cleanup;
66     }
67
68     hr = IUnknown_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device);
69     ok(SUCCEEDED(hr), "Created device does not implement IDXGIDevice\n");
70     IUnknown_Release(device);
71
72 cleanup:
73     if (adapter) IDXGIAdapter_Release(adapter);
74     if (factory) IDXGIFactory_Release(factory);
75
76     return dxgi_device;
77 }
78
79 static void test_device_interfaces(IDXGIDevice *device)
80 {
81     IUnknown *obj;
82     HRESULT hr;
83
84     if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_IUnknown, (void **)&obj)))
85         IUnknown_Release(obj);
86     ok(SUCCEEDED(hr), "IDXGIDevice does not implement IUnknown\n");
87
88     if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_IDXGIObject, (void **)&obj)))
89         IUnknown_Release(obj);
90     ok(SUCCEEDED(hr), "IDXGIDevice does not implement IDXGIObject\n");
91
92     if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_IDXGIDevice, (void **)&obj)))
93         IUnknown_Release(obj);
94     ok(SUCCEEDED(hr), "IDXGIDevice does not implement IDXGIDevice\n");
95
96     if (SUCCEEDED(hr = IDXGIDevice_QueryInterface(device, &IID_ID3D10Device, (void **)&obj)))
97         IUnknown_Release(obj);
98     ok(SUCCEEDED(hr), "IDXGIDevice does not implement ID3D10Device\n");
99 }
100
101 static void test_create_surface(IDXGIDevice *device)
102 {
103     ID3D10Texture2D *texture;
104     IDXGISurface *surface;
105     DXGI_SURFACE_DESC desc;
106     HRESULT hr;
107
108     desc.Width = 512;
109     desc.Height = 512;
110     desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
111     desc.SampleDesc.Count = 1;
112     desc.SampleDesc.Quality = 0;
113
114     hr = IDXGIDevice_CreateSurface(device, &desc, 1, DXGI_USAGE_RENDER_TARGET_OUTPUT, NULL, &surface);
115     ok(SUCCEEDED(hr), "Failed to create a dxgi surface, hr %#x\n", hr);
116
117     hr = IDXGISurface_QueryInterface(surface, &IID_ID3D10Texture2D, (void **)&texture);
118     ok(SUCCEEDED(hr), "Surface should implement ID3D10Texture2D\n");
119     if (SUCCEEDED(hr)) ID3D10Texture2D_Release(texture);
120
121     IDXGISurface_Release(surface);
122 }
123
124 START_TEST(device)
125 {
126     HMODULE d3d10core = LoadLibraryA("d3d10core.dll");
127     IDXGIDevice *device;
128     ULONG refcount;
129
130     if (!d3d10core)
131     {
132         win_skip("d3d10core.dll not available, skipping tests\n");
133         return;
134     }
135
136     device = create_device(d3d10core);
137     if (!device)
138     {
139         skip("Failed to create device, skipping tests\n");
140         FreeLibrary(d3d10core);
141         return;
142     }
143
144     test_device_interfaces(device);
145     test_create_surface(device);
146
147     refcount = IDXGIDevice_Release(device);
148     ok(!refcount, "Device has %u references left\n", refcount);
149     FreeLibrary(d3d10core);
150 }