static void test_create_shader_resource_view(void) { D3D10_SHADER_RESOURCE_VIEW_DESC1 srv_desc; D3D10_TEXTURE2D_DESC texture_desc; ULONG refcount, expected_refcount; ID3D10ShaderResourceView1 *srview; D3D10_BUFFER_DESC buffer_desc; ID3D10Texture2D *texture; ID3D10Device *tmp_device; ID3D10Device1 *device; ID3D10Buffer *buffer; IUnknown *iface; HRESULT hr; if (!(device = create_device(NULL))) { skip("Failed to create device.\n"); return; } buffer_desc.ByteWidth = 1024; buffer_desc.Usage = D3D10_USAGE_DEFAULT; buffer_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; buffer_desc.CPUAccessFlags = 0; buffer_desc.MiscFlags = 0; hr = ID3D10Device1_CreateBuffer(device, &buffer_desc, NULL, &buffer); ok(SUCCEEDED(hr), "Failed to create a buffer, hr %#x\n", hr); hr = ID3D10Device1_CreateShaderResourceView1(device, (ID3D10Resource *)buffer, NULL, &srview); ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); srv_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT; srv_desc.ViewDimension = D3D10_1_SRV_DIMENSION_BUFFER; U(srv_desc).Buffer.ElementOffset = 0; U(srv_desc).Buffer.ElementWidth = 64; expected_refcount = get_refcount((IUnknown *)device) + 1; hr = ID3D10Device1_CreateShaderResourceView1(device, (ID3D10Resource *)buffer, &srv_desc, &srview); ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr); refcount = get_refcount((IUnknown *)device); ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount); tmp_device = NULL; expected_refcount = refcount + 1; ID3D10ShaderResourceView1_GetDevice(srview, &tmp_device); ok(tmp_device == (ID3D10Device *)device, "Got unexpected device %p, expected %p.\n", tmp_device, device); refcount = get_refcount((IUnknown *)device); ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount); ID3D10Device_Release(tmp_device); hr = ID3D10ShaderResourceView1_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface); ok(SUCCEEDED(hr), "Shader resource view should implement ID3D10ShaderResourceView.\n"); IUnknown_Release(iface); hr = ID3D10ShaderResourceView1_QueryInterface(srview, &IID_ID3D11ShaderResourceView, (void **)&iface); ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */, "Shader resource view should implement ID3D11ShaderResourceView.\n"); if (SUCCEEDED(hr)) IUnknown_Release(iface); ID3D10ShaderResourceView1_Release(srview); ID3D10Buffer_Release(buffer); texture_desc.Width = 512; texture_desc.Height = 512; texture_desc.MipLevels = 0; texture_desc.ArraySize = 1; texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; texture_desc.SampleDesc.Count = 1; texture_desc.SampleDesc.Quality = 0; texture_desc.Usage = D3D10_USAGE_DEFAULT; texture_desc.BindFlags = D3D10_BIND_SHADER_RESOURCE; texture_desc.CPUAccessFlags = 0; texture_desc.MiscFlags = 0; hr = ID3D10Device1_CreateTexture2D(device, &texture_desc, NULL, &texture); ok(SUCCEEDED(hr), "Failed to create a 2d texture, hr %#x\n", hr); hr = ID3D10Device1_CreateShaderResourceView1(device, (ID3D10Resource *)texture, NULL, &srview); ok(SUCCEEDED(hr), "Failed to create a shader resource view, hr %#x\n", hr); ID3D10ShaderResourceView1_GetDesc1(srview, &srv_desc); ok(srv_desc.Format == texture_desc.Format, "Got unexpected format %#x.\n", srv_desc.Format); ok(srv_desc.ViewDimension == D3D10_1_SRV_DIMENSION_TEXTURE2D, "Got unexpected view dimension %#x.\n", srv_desc.ViewDimension); ok(U(srv_desc).Texture2D.MostDetailedMip == 0, "Got unexpected MostDetailedMip %u.\n", U(srv_desc).Texture2D.MostDetailedMip); ok(U(srv_desc).Texture2D.MipLevels == 10, "Got unexpected MipLevels %u.\n", U(srv_desc).Texture2D.MipLevels); hr = ID3D10ShaderResourceView1_QueryInterface(srview, &IID_ID3D10ShaderResourceView, (void **)&iface); ok(SUCCEEDED(hr), "Shader resource view should implement ID3D10ShaderResourceView.\n"); IUnknown_Release(iface); hr = ID3D10ShaderResourceView1_QueryInterface(srview, &IID_ID3D11ShaderResourceView, (void **)&iface); ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */, "Shader resource view should implement ID3D11ShaderResourceView.\n"); if (SUCCEEDED(hr)) IUnknown_Release(iface); ID3D10ShaderResourceView1_Release(srview); ID3D10Texture2D_Release(texture); refcount = ID3D10Device1_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); }
static void test_getdc(void) { struct device_desc device_desc; D3D10_TEXTURE2D_DESC desc; ID3D10Texture2D *texture; IDXGISurface1 *surface1; ID3D10Device1 *device; ULONG refcount; HRESULT hr; HDC dc; device_desc.feature_level = D3D10_FEATURE_LEVEL_10_1; device_desc.flags = D3D10_CREATE_DEVICE_BGRA_SUPPORT; if (!(device = create_device(&device_desc))) { skip("Failed to create device.\n"); return; } /* Without D3D10_RESOURCE_MISC_GDI_COMPATIBLE. */ desc.Width = 512; desc.Height = 512; desc.MipLevels = 1; desc.ArraySize = 1; desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; desc.SampleDesc.Count = 1; desc.SampleDesc.Quality = 0; desc.Usage = D3D10_USAGE_DEFAULT; desc.BindFlags = D3D10_BIND_RENDER_TARGET; desc.CPUAccessFlags = 0; desc.MiscFlags = 0; hr = ID3D10Device1_CreateTexture2D(device, &desc, NULL, &texture); ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr); hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface1); ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr); hr = IDXGISurface1_GetDC(surface1, FALSE, &dc); todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr); IDXGISurface1_Release(surface1); ID3D10Texture2D_Release(texture); desc.MiscFlags = D3D10_RESOURCE_MISC_GDI_COMPATIBLE; hr = ID3D10Device1_CreateTexture2D(device, &desc, NULL, &texture); ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr); hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface1, (void**)&surface1); ok(SUCCEEDED(hr), "Failed to get IDXGISurface1 interface, hr %#x.\n", hr); hr = IDXGISurface1_ReleaseDC(surface1, NULL); todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr); hr = IDXGISurface1_GetDC(surface1, FALSE, &dc); todo_wine ok(SUCCEEDED(hr), "Failed to get DC, hr %#x.\n", hr); /* One more time. */ dc = (HDC)0xdeadbeef; hr = IDXGISurface1_GetDC(surface1, FALSE, &dc); todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr); ok(dc == (HDC)0xdeadbeef, "Got unexpected dc %p.\n", dc); hr = IDXGISurface1_ReleaseDC(surface1, NULL); todo_wine ok(SUCCEEDED(hr), "Failed to release DC, hr %#x.\n", hr); hr = IDXGISurface1_ReleaseDC(surface1, NULL); todo_wine ok(hr == DXGI_ERROR_INVALID_CALL, "Got unexpected hr %#x.\n", hr); IDXGISurface1_Release(surface1); ID3D10Texture2D_Release(texture); refcount = ID3D10Device1_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); }
HRESULT d2d_wic_render_target_init(struct d2d_wic_render_target *render_target, ID2D1Factory1 *factory, ID3D10Device1 *d3d_device, IWICBitmap *bitmap, const D2D1_RENDER_TARGET_PROPERTIES *desc) { D3D10_TEXTURE2D_DESC texture_desc; ID3D10Texture2D *texture; IDXGIDevice *dxgi_device; ID2D1Device *device; HRESULT hr; render_target->IUnknown_iface.lpVtbl = &d2d_wic_render_target_vtbl; if (FAILED(hr = IWICBitmap_GetSize(bitmap, &render_target->width, &render_target->height))) { WARN("Failed to get bitmap dimensions, hr %#x.\n", hr); return hr; } texture_desc.Width = render_target->width; texture_desc.Height = render_target->height; texture_desc.MipLevels = 1; texture_desc.ArraySize = 1; texture_desc.Format = desc->pixelFormat.format; if (texture_desc.Format == DXGI_FORMAT_UNKNOWN) { WICPixelFormatGUID bitmap_format; if (FAILED(hr = IWICBitmap_GetPixelFormat(bitmap, &bitmap_format))) { WARN("Failed to get bitmap format, hr %#x.\n", hr); return hr; } if (IsEqualGUID(&bitmap_format, &GUID_WICPixelFormat32bppPBGRA) || IsEqualGUID(&bitmap_format, &GUID_WICPixelFormat32bppBGR)) { texture_desc.Format = DXGI_FORMAT_B8G8R8A8_UNORM; } else { WARN("Unsupported WIC bitmap format %s.\n", debugstr_guid(&bitmap_format)); return D2DERR_UNSUPPORTED_PIXEL_FORMAT; } } switch (texture_desc.Format) { case DXGI_FORMAT_B8G8R8A8_UNORM: render_target->bpp = 4; break; default: FIXME("Unhandled format %#x.\n", texture_desc.Format); return D2DERR_UNSUPPORTED_PIXEL_FORMAT; } texture_desc.SampleDesc.Count = 1; texture_desc.SampleDesc.Quality = 0; texture_desc.Usage = D3D10_USAGE_DEFAULT; texture_desc.BindFlags = D3D10_BIND_RENDER_TARGET | D3D10_BIND_SHADER_RESOURCE; texture_desc.CPUAccessFlags = 0; texture_desc.MiscFlags = desc->usage & D2D1_RENDER_TARGET_USAGE_GDI_COMPATIBLE ? D3D10_RESOURCE_MISC_GDI_COMPATIBLE : 0; if (FAILED(hr = ID3D10Device1_CreateTexture2D(d3d_device, &texture_desc, NULL, &texture))) { WARN("Failed to create texture, hr %#x.\n", hr); return hr; } hr = ID3D10Texture2D_QueryInterface(texture, &IID_IDXGISurface, (void **)&render_target->dxgi_surface); ID3D10Texture2D_Release(texture); if (FAILED(hr)) { WARN("Failed to get DXGI surface interface, hr %#x.\n", hr); return hr; } texture_desc.Usage = D3D10_USAGE_STAGING; texture_desc.BindFlags = 0; texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; texture_desc.MiscFlags = 0; if (FAILED(hr = ID3D10Device1_CreateTexture2D(d3d_device, &texture_desc, NULL, &render_target->readback_texture))) { WARN("Failed to create readback texture, hr %#x.\n", hr); IDXGISurface_Release(render_target->dxgi_surface); return hr; } if (FAILED(hr = ID3D10Device1_QueryInterface(d3d_device, &IID_IDXGIDevice, (void **)&dxgi_device))) { WARN("Failed to get DXGI device, hr %#x.\n", hr); IDXGISurface_Release(render_target->dxgi_surface); return hr; } hr = ID2D1Factory1_CreateDevice(factory, dxgi_device, &device); IDXGIDevice_Release(dxgi_device); if (FAILED(hr)) { WARN("Failed to create D2D device, hr %#x.\n", hr); IDXGISurface_Release(render_target->dxgi_surface); return hr; } hr = d2d_d3d_create_render_target(device, render_target->dxgi_surface, &render_target->IUnknown_iface, &d2d_wic_render_target_ops, desc, (void **)&render_target->dxgi_inner); ID2D1Device_Release(device); if (FAILED(hr)) { WARN("Failed to create DXGI surface render target, hr %#x.\n", hr); ID3D10Texture2D_Release(render_target->readback_texture); IDXGISurface_Release(render_target->dxgi_surface); return hr; } if (FAILED(hr = IUnknown_QueryInterface(render_target->dxgi_inner, &IID_ID2D1RenderTarget, (void **)&render_target->dxgi_target))) { WARN("Failed to retrieve ID2D1RenderTarget interface, hr %#x.\n", hr); IUnknown_Release(render_target->dxgi_inner); ID3D10Texture2D_Release(render_target->readback_texture); IDXGISurface_Release(render_target->dxgi_surface); return hr; } render_target->bitmap = bitmap; IWICBitmap_AddRef(bitmap); return S_OK; }