static BOOL compare_surface(IDXGISurface *surface, const char *ref_sha1) { D3D10_MAPPED_TEXTURE2D mapped_texture; D3D10_TEXTURE2D_DESC texture_desc; DXGI_SURFACE_DESC surface_desc; ID3D10Resource *src_resource; ID3D10Texture2D *texture; ID3D10Device *device; HRESULT hr; BOOL ret; hr = IDXGISurface_GetDevice(surface, &IID_ID3D10Device, (void **)&device); ok(SUCCEEDED(hr), "Failed to get device, hr %#x.\n", hr); hr = IDXGISurface_QueryInterface(surface, &IID_ID3D10Resource, (void **)&src_resource); ok(SUCCEEDED(hr), "Failed to query resource interface, hr %#x.\n", hr); hr = IDXGISurface_GetDesc(surface, &surface_desc); ok(SUCCEEDED(hr), "Failed to get surface desc, hr %#x.\n", hr); texture_desc.Width = surface_desc.Width; texture_desc.Height = surface_desc.Height; texture_desc.MipLevels = 1; texture_desc.ArraySize = 1; texture_desc.Format = surface_desc.Format; texture_desc.SampleDesc = surface_desc.SampleDesc; texture_desc.Usage = D3D10_USAGE_STAGING; texture_desc.BindFlags = 0; texture_desc.CPUAccessFlags = D3D10_CPU_ACCESS_READ; texture_desc.MiscFlags = 0; hr = ID3D10Device_CreateTexture2D(device, &texture_desc, NULL, &texture); ok(SUCCEEDED(hr), "Failed to create texture, hr %#x.\n", hr); ID3D10Device_CopyResource(device, (ID3D10Resource *)texture, src_resource); hr = ID3D10Texture2D_Map(texture, 0, D3D10_MAP_READ, 0, &mapped_texture); ok(SUCCEEDED(hr), "Failed to map texture, hr %#x.\n", hr); ret = compare_sha1(mapped_texture.pData, mapped_texture.RowPitch, 4, texture_desc.Width, texture_desc.Height, ref_sha1); ID3D10Texture2D_Unmap(texture, 0); ID3D10Texture2D_Release(texture); ID3D10Resource_Release(src_resource); ID3D10Device_Release(device); return ret; }
HRESULT d2d_bitmap_init_shared(struct d2d_bitmap *bitmap, struct d2d_d3d_render_target *render_target, REFIID iid, void *data, const D2D1_BITMAP_PROPERTIES *desc) { if (IsEqualGUID(iid, &IID_ID2D1Bitmap)) { struct d2d_bitmap *src_impl = unsafe_impl_from_ID2D1Bitmap(data); D2D1_BITMAP_PROPERTIES d; ID3D10Device *device; if (src_impl->factory != render_target->factory) return D2DERR_WRONG_FACTORY; ID3D10ShaderResourceView_GetDevice(src_impl->view, &device); ID3D10Device_Release(device); if (device != render_target->device) return D2DERR_UNSUPPORTED_OPERATION; if (!desc) { d.pixelFormat = src_impl->format; d.dpiX = src_impl->dpi_x; d.dpiY = src_impl->dpi_y; desc = &d; } if (!format_supported(&desc->pixelFormat)) { WARN("Tried to create bitmap with unsupported format {%#x / %#x}.\n", desc->pixelFormat.format, desc->pixelFormat.alphaMode); return D2DERR_UNSUPPORTED_PIXEL_FORMAT; } d2d_bitmap_init(bitmap, render_target->factory, src_impl->view, src_impl->pixel_size, desc); return S_OK; } WARN("Unhandled interface %s.\n", debugstr_guid(iid)); return E_INVALIDARG; }
static void test_create_device(void) { ID3D10Device *device; unsigned int i; HRESULT hr; if (FAILED(hr = D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &device))) { skip("Failed to create HAL device.\n"); return; } ID3D10Device_Release(device); for (i = 0; i < 100; ++i) { if (i == D3D10_SDK_VERSION) continue; hr = D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, i, &device); ok(hr == E_INVALIDARG, "Got unexpected hr %#x for SDK version %#x.\n", hr, i); } }
static IDXGIDevice *create_device(void) { IDXGIDevice *dxgi_device; ID3D10Device *device; HRESULT hr; if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0, D3D10_SDK_VERSION, &device))) goto success; if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_WARP, NULL, 0, D3D10_SDK_VERSION, &device))) goto success; if (SUCCEEDED(D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_REFERENCE, NULL, 0, D3D10_SDK_VERSION, &device))) goto success; return NULL; success: hr = ID3D10Device_QueryInterface(device, &IID_IDXGIDevice, (void **)&dxgi_device); ok(SUCCEEDED(hr), "Created device does not implement IDXGIDevice\n"); ID3D10Device_Release(device); return dxgi_device; }
static void test_create_blend_state(void) { static const D3D10_BLEND_DESC1 desc_conversion_tests[] = { { FALSE, FALSE, { { FALSE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD }, }, }, { FALSE, TRUE, { { TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, { FALSE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_RED }, { TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, { FALSE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_GREEN }, { TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, { TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, { TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, { TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, }, }, { FALSE, TRUE, { { TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, { TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_SUBTRACT, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, { TRUE, D3D10_BLEND_ZERO, D3D10_BLEND_ONE, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, { TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ZERO, D3D10_BLEND_ONE, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, { TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ONE, D3D10_BLEND_OP_MAX, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, { TRUE, D3D10_BLEND_ONE, D3D10_BLEND_ONE, D3D10_BLEND_OP_MIN, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, { FALSE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, { FALSE, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_BLEND_ONE, D3D10_BLEND_ZERO, D3D10_BLEND_OP_ADD, D3D10_COLOR_WRITE_ENABLE_ALL }, }, }, }; ID3D10BlendState1 *blend_state1, *blend_state2; D3D10_BLEND_DESC1 desc, obtained_desc; ID3D10BlendState *d3d10_blend_state; D3D10_BLEND_DESC d3d10_blend_desc; ULONG refcount, expected_refcount; ID3D10Device1 *device; ID3D10Device *tmp; unsigned int i, j; IUnknown *iface; HRESULT hr; if (!(device = create_device(NULL))) { skip("Failed to create device.\n"); return; } hr = ID3D10Device1_CreateBlendState1(device, NULL, &blend_state1); ok(hr == E_INVALIDARG, "Got unexpected hr %#x.\n", hr); memset(&desc, 0, sizeof(desc)); desc.AlphaToCoverageEnable = FALSE; desc.IndependentBlendEnable = FALSE; desc.RenderTarget[0].BlendEnable = FALSE; desc.RenderTarget[0].SrcBlend = D3D10_BLEND_ONE; desc.RenderTarget[0].DestBlend = D3D10_BLEND_ZERO; desc.RenderTarget[0].BlendOp = D3D10_BLEND_OP_ADD; desc.RenderTarget[0].SrcBlendAlpha = D3D10_BLEND_ONE; desc.RenderTarget[0].DestBlendAlpha = D3D10_BLEND_ZERO; desc.RenderTarget[0].BlendOpAlpha = D3D10_BLEND_OP_ADD; desc.RenderTarget[0].RenderTargetWriteMask = D3D10_COLOR_WRITE_ENABLE_ALL; expected_refcount = get_refcount((IUnknown *)device) + 1; hr = ID3D10Device1_CreateBlendState1(device, &desc, &blend_state1); ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr); hr = ID3D10Device1_CreateBlendState1(device, &desc, &blend_state2); ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr); ok(blend_state1 == blend_state2, "Got different blend state objects.\n"); refcount = get_refcount((IUnknown *)device); ok(refcount >= expected_refcount, "Got unexpected refcount %u, expected >= %u.\n", refcount, expected_refcount); tmp = NULL; expected_refcount = refcount + 1; ID3D10BlendState1_GetDevice(blend_state1, &tmp); ok(tmp == (ID3D10Device *)device, "Got unexpected device %p, expected %p.\n", tmp, device); refcount = get_refcount((IUnknown *)device); ok(refcount == expected_refcount, "Got unexpected refcount %u, expected %u.\n", refcount, expected_refcount); ID3D10Device_Release(tmp); ID3D10BlendState1_GetDesc1(blend_state1, &obtained_desc); ok(obtained_desc.AlphaToCoverageEnable == FALSE, "Got unexpected alpha to coverage enable %#x.\n", obtained_desc.AlphaToCoverageEnable); ok(obtained_desc.IndependentBlendEnable == FALSE, "Got unexpected independent blend enable %#x.\n", obtained_desc.IndependentBlendEnable); for (i = 0; i < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; ++i) { ok(obtained_desc.RenderTarget[i].BlendEnable == FALSE, "Got unexpected blend enable %#x for render target %u.\n", obtained_desc.RenderTarget[i].BlendEnable, i); ok(obtained_desc.RenderTarget[i].SrcBlend == D3D10_BLEND_ONE, "Got unexpected src blend %u for render target %u.\n", obtained_desc.RenderTarget[i].SrcBlend, i); ok(obtained_desc.RenderTarget[i].DestBlend == D3D10_BLEND_ZERO, "Got unexpected dest blend %u for render target %u.\n", obtained_desc.RenderTarget[i].DestBlend, i); ok(obtained_desc.RenderTarget[i].BlendOp == D3D10_BLEND_OP_ADD, "Got unexpected blend op %u for render target %u.\n", obtained_desc.RenderTarget[i].BlendOp, i); ok(obtained_desc.RenderTarget[i].SrcBlendAlpha == D3D10_BLEND_ONE, "Got unexpected src blend alpha %u for render target %u.\n", obtained_desc.RenderTarget[i].SrcBlendAlpha, i); ok(obtained_desc.RenderTarget[i].DestBlendAlpha == D3D10_BLEND_ZERO, "Got unexpected dest blend alpha %u for render target %u.\n", obtained_desc.RenderTarget[i].DestBlendAlpha, i); ok(obtained_desc.RenderTarget[i].BlendOpAlpha == D3D10_BLEND_OP_ADD, "Got unexpected blend op alpha %u for render target %u.\n", obtained_desc.RenderTarget[i].BlendOpAlpha, i); ok(obtained_desc.RenderTarget[i].RenderTargetWriteMask == D3D10_COLOR_WRITE_ENABLE_ALL, "Got unexpected render target write mask %#x for render target %u.\n", obtained_desc.RenderTarget[0].RenderTargetWriteMask, i); } hr = ID3D10BlendState1_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&iface); ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n"); IUnknown_Release(iface); hr = ID3D10BlendState1_QueryInterface(blend_state1, &IID_ID3D11BlendState, (void **)&iface); ok(SUCCEEDED(hr) || broken(hr == E_NOINTERFACE) /* Not available on all Windows versions. */, "Blend state should implement ID3D11BlendState.\n"); if (SUCCEEDED(hr)) IUnknown_Release(iface); refcount = ID3D10BlendState1_Release(blend_state1); ok(refcount == 1, "Got unexpected refcount %u.\n", refcount); refcount = ID3D10BlendState1_Release(blend_state2); ok(!refcount, "Blend state has %u references left.\n", refcount); for (i = 0; i < sizeof(desc_conversion_tests) / sizeof(*desc_conversion_tests); ++i) { const D3D10_BLEND_DESC1 *current_desc = &desc_conversion_tests[i]; hr = ID3D10Device1_CreateBlendState1(device, current_desc, &blend_state1); ok(SUCCEEDED(hr), "Failed to create blend state, hr %#x.\n", hr); hr = ID3D10BlendState1_QueryInterface(blend_state1, &IID_ID3D10BlendState, (void **)&d3d10_blend_state); ok(SUCCEEDED(hr), "Blend state should implement ID3D10BlendState.\n"); ID3D10BlendState_GetDesc(d3d10_blend_state, &d3d10_blend_desc); ok(d3d10_blend_desc.AlphaToCoverageEnable == current_desc->AlphaToCoverageEnable, "Got unexpected alpha to coverage enable %#x for test %u.\n", d3d10_blend_desc.AlphaToCoverageEnable, i); ok(d3d10_blend_desc.SrcBlend == current_desc->RenderTarget[0].SrcBlend, "Got unexpected src blend %u for test %u.\n", d3d10_blend_desc.SrcBlend, i); ok(d3d10_blend_desc.DestBlend == current_desc->RenderTarget[0].DestBlend, "Got unexpected dest blend %u for test %u.\n", d3d10_blend_desc.DestBlend, i); ok(d3d10_blend_desc.BlendOp == current_desc->RenderTarget[0].BlendOp, "Got unexpected blend op %u for test %u.\n", d3d10_blend_desc.BlendOp, i); ok(d3d10_blend_desc.SrcBlendAlpha == current_desc->RenderTarget[0].SrcBlendAlpha, "Got unexpected src blend alpha %u for test %u.\n", d3d10_blend_desc.SrcBlendAlpha, i); ok(d3d10_blend_desc.DestBlendAlpha == current_desc->RenderTarget[0].DestBlendAlpha, "Got unexpected dest blend alpha %u for test %u.\n", d3d10_blend_desc.DestBlendAlpha, i); ok(d3d10_blend_desc.BlendOpAlpha == current_desc->RenderTarget[0].BlendOpAlpha, "Got unexpected blend op alpha %u for test %u.\n", d3d10_blend_desc.BlendOpAlpha, i); for (j = 0; j < D3D10_SIMULTANEOUS_RENDER_TARGET_COUNT; j++) { unsigned int k = current_desc->IndependentBlendEnable ? j : 0; ok(d3d10_blend_desc.BlendEnable[j] == current_desc->RenderTarget[k].BlendEnable, "Got unexpected blend enable %#x for test %u, render target %u.\n", d3d10_blend_desc.BlendEnable[j], i, j); ok(d3d10_blend_desc.RenderTargetWriteMask[j] == current_desc->RenderTarget[k].RenderTargetWriteMask, "Got unexpected render target write mask %#x for test %u, render target %u.\n", d3d10_blend_desc.RenderTargetWriteMask[j], i, j); } ID3D10BlendState_Release(d3d10_blend_state); refcount = ID3D10BlendState1_Release(blend_state1); ok(!refcount, "Got unexpected refcount %u.\n", refcount); } refcount = ID3D10Device1_Release(device); ok(!refcount, "Device has %u references left.\n", refcount); }
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 HRESULT d2d_wic_render_target_present(IUnknown *outer_unknown) { struct d2d_wic_render_target *render_target = impl_from_IUnknown(outer_unknown); D3D10_MAPPED_TEXTURE2D mapped_texture; ID3D10Resource *src_resource; IWICBitmapLock *bitmap_lock; UINT dst_size, dst_pitch; ID3D10Device *device; WICRect dst_rect; BYTE *src, *dst; unsigned int i; HRESULT hr; if (FAILED(hr = IDXGISurface_QueryInterface(render_target->dxgi_surface, &IID_ID3D10Resource, (void **)&src_resource))) { ERR("Failed to get source resource interface, hr %#x.\n", hr); goto end; } ID3D10Texture2D_GetDevice(render_target->readback_texture, &device); ID3D10Device_CopyResource(device, (ID3D10Resource *)render_target->readback_texture, src_resource); ID3D10Device_Release(device); ID3D10Resource_Release(src_resource); dst_rect.X = 0; dst_rect.Y = 0; dst_rect.Width = render_target->width; dst_rect.Height = render_target->height; if (FAILED(hr = IWICBitmap_Lock(render_target->bitmap, &dst_rect, WICBitmapLockWrite, &bitmap_lock))) { ERR("Failed to lock destination bitmap, hr %#x.\n", hr); goto end; } if (FAILED(hr = IWICBitmapLock_GetDataPointer(bitmap_lock, &dst_size, &dst))) { ERR("Failed to get data pointer, hr %#x.\n", hr); IWICBitmapLock_Release(bitmap_lock); goto end; } if (FAILED(hr = IWICBitmapLock_GetStride(bitmap_lock, &dst_pitch))) { ERR("Failed to get stride, hr %#x.\n", hr); IWICBitmapLock_Release(bitmap_lock); goto end; } if (FAILED(hr = ID3D10Texture2D_Map(render_target->readback_texture, 0, D3D10_MAP_READ, 0, &mapped_texture))) { ERR("Failed to map readback texture, hr %#x.\n", hr); IWICBitmapLock_Release(bitmap_lock); goto end; } src = mapped_texture.pData; for (i = 0; i < render_target->height; ++i) { memcpy(dst, src, render_target->bpp * render_target->width); src += mapped_texture.RowPitch; dst += dst_pitch; } ID3D10Texture2D_Unmap(render_target->readback_texture, 0); IWICBitmapLock_Release(bitmap_lock); end: return S_OK; }
HRESULT WINAPI D3D10CreateDeviceAndSwapChain(IDXGIAdapter *adapter, D3D10_DRIVER_TYPE driver_type, HMODULE swrast, UINT flags, UINT sdk_version, DXGI_SWAP_CHAIN_DESC *swapchain_desc, IDXGISwapChain **swapchain, ID3D10Device **device) { IDXGIDevice *dxgi_device; IDXGIFactory *factory; HRESULT hr; TRACE("adapter %p, driver_type %s, swrast %p, flags %#x, sdk_version %d,\n" "\tswapchain_desc %p, swapchain %p, device %p\n", adapter, debug_d3d10_driver_type(driver_type), swrast, flags, sdk_version, swapchain_desc, swapchain, device); hr = D3D10CreateDevice(adapter, driver_type, swrast, flags, sdk_version, device); if (FAILED(hr)) { WARN("Failed to create a device, returning %#x\n", hr); *device = NULL; return hr; } TRACE("Created ID3D10Device %p\n", *device); hr = ID3D10Device_QueryInterface(*device, &IID_IDXGIDevice, (void **)&dxgi_device); if (FAILED(hr)) { ERR("Failed to get a dxgi device from the d3d10 device, returning %#x\n", hr); ID3D10Device_Release(*device); *device = NULL; return hr; } hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter); IDXGIDevice_Release(dxgi_device); if (FAILED(hr)) { ERR("Failed to get the device adapter, returning %#x\n", hr); ID3D10Device_Release(*device); *device = NULL; return hr; } hr = IDXGIAdapter_GetParent(adapter, &IID_IDXGIFactory, (void **)&factory); IDXGIAdapter_Release(adapter); if (FAILED(hr)) { ERR("Failed to get the adapter factory, returning %#x\n", hr); ID3D10Device_Release(*device); *device = NULL; return hr; } hr = IDXGIFactory_CreateSwapChain(factory, (IUnknown *)*device, swapchain_desc, swapchain); IDXGIFactory_Release(factory); if (FAILED(hr)) { ID3D10Device_Release(*device); *device = NULL; WARN("Failed to create a swapchain, returning %#x\n", hr); return hr; } TRACE("Created IDXGISwapChain %p\n", *swapchain); return S_OK; }