/* IDirect3DSurface9 IDirect3DResource9 Interface follow: */ static HRESULT WINAPI IDirect3DSurface9Impl_GetDevice(IDirect3DSurface9 *iface, IDirect3DDevice9 **device) { IDirect3DSurface9Impl *This = impl_from_IDirect3DSurface9(iface); TRACE("iface %p, device %p.\n", iface, device); if (This->forwardReference) { IDirect3DResource9 *resource; HRESULT hr; hr = IUnknown_QueryInterface(This->forwardReference, &IID_IDirect3DResource9, (void **)&resource); if (SUCCEEDED(hr)) { hr = IDirect3DResource9_GetDevice(resource, device); IDirect3DResource9_Release(resource); TRACE("Returning device %p.\n", *device); } return hr; } *device = (IDirect3DDevice9 *)This->parentDevice; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
HRESULT WINAPI D3DXCreateLine(LPDIRECT3DDEVICE9 device, LPD3DXLINE* line) { ID3DXLineImpl* object; TRACE("(%p, %p)\n", device, line); if (!device || !line) return D3DERR_INVALIDCALL; object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(ID3DXLineImpl)); if (!object) { ERR("Out of memory\n"); return E_OUTOFMEMORY; } object->ID3DXLine_iface.lpVtbl = &ID3DXLine_Vtbl; object->ref = 1; object->device = device; object->state = NULL; /* We only initialize it on Begin */ IDirect3DDevice9_AddRef(device); *line = &object->ID3DXLine_iface; return D3D_OK; }
// Special libmpv-specific pseudo extension for better behavior with OpenGL // fullscreen modes. This is needed with some drivers which do not allow the // libmpv DXVA code to create a new D3D device. static void* __stdcall MPGetNativeDisplay(const char* name) { QLOG_INFO() << "Asking for " << qPrintable(QString::fromUtf8((name))); if (strcmp(name, "IDirect3DDevice9") == 0) { QLOG_INFO() << "Returning device " << (void *)d3ddevice; IDirect3DDevice9_AddRef(d3ddevice); return (void *)d3ddevice; } return NULL; }
static HRESULT WINAPI d3d9_vertexbuffer_GetDevice(IDirect3DVertexBuffer9 *iface, IDirect3DDevice9 **device) { TRACE("iface %p, device %p.\n", iface, device); *device = (IDirect3DDevice9 *)((IDirect3DVertexBuffer9Impl *)iface)->parentDevice; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
HRESULT STDMETHODCALLTYPE IDirect3D9Ex_CreateDeviceEx_Hook(IDirect3D9Ex* This, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, D3DDISPLAYMODEEX* pFullscreenDisplayMode, IDirect3DDevice9Ex** ppReturnedDeviceInterface) { auto result = IDirect3D9Ex_CreateDeviceEx_Orig(This, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, pFullscreenDisplayMode, ppReturnedDeviceInterface); if (result == S_OK) { auto pDevice = reinterpret_cast<IDirect3DDevice9*>(*ppReturnedDeviceInterface); IDirect3DDevice9_HookCount++; IDirect3DDevice9_AddRef(pDevice); HOOK(IDirect3DDevice9, pDevice, EndScene); HOOK(IDirect3DDevice9, pDevice, Release); } return result; }
HRESULT STDMETHODCALLTYPE IDirect3D9_CreateDevice_Hook(IDirect3D9* This, UINT Adapter, D3DDEVTYPE DeviceType, HWND hFocusWindow, DWORD BehaviorFlags, D3DPRESENT_PARAMETERS* pPresentationParameters, IDirect3DDevice9** ppReturnedDeviceInterface) { auto result = IDirect3D9_CreateDevice_Orig(This, Adapter, DeviceType, hFocusWindow, BehaviorFlags, pPresentationParameters, ppReturnedDeviceInterface); if (result == S_OK) { auto pDevice = *ppReturnedDeviceInterface; IDirect3DDevice9_HookCount++; IDirect3DDevice9_AddRef(pDevice); HOOK(IDirect3DDevice9, pDevice, EndScene); HOOK(IDirect3DDevice9, pDevice, Release); } return result; }
static HRESULT WINAPI ID3DXFontImpl_GetDevice(ID3DXFont *iface, IDirect3DDevice9 **device) { struct d3dx_font *This = impl_from_ID3DXFont(iface); TRACE("iface %p, device %p\n", iface, device); if( !device ) return D3DERR_INVALIDCALL; *device = This->device; IDirect3DDevice9_AddRef(This->device); return D3D_OK; }
static HRESULT WINAPI ID3DXSpriteImpl_GetDevice(struct ID3DXSprite *iface, struct IDirect3DDevice9 **device) { ID3DXSpriteImpl *This = impl_from_ID3DXSprite(iface); TRACE("(%p)->(%p): relay\n", This, device); if(device==NULL) return D3DERR_INVALIDCALL; *device=This->device; IDirect3DDevice9_AddRef(This->device); return D3D_OK; }
static HRESULT WINAPI d3d9_vertexshader_GetDevice(IDirect3DVertexShader9 *iface, IDirect3DDevice9 **device) { IDirect3DVertexShader9Impl *shader = impl_from_IDirect3DVertexShader9(iface); TRACE("iface %p, device %p.\n", iface, device); *device = (IDirect3DDevice9 *)shader->parentDevice; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static HRESULT WINAPI d3d9_swapchain_GetDevice(IDirect3DSwapChain9Ex *iface, IDirect3DDevice9 **device) { struct d3d9_swapchain *swapchain = impl_from_IDirect3DSwapChain9Ex(iface); TRACE("iface %p, device %p.\n", iface, device); *device = (IDirect3DDevice9 *)swapchain->parent_device; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
/* IDirect3DStateBlock9 Interface follow: */ static HRESULT WINAPI IDirect3DStateBlock9Impl_GetDevice(IDirect3DStateBlock9 *iface, IDirect3DDevice9 **device) { IDirect3DStateBlock9Impl *This = (IDirect3DStateBlock9Impl *)iface; TRACE("iface %p, device %p.\n", iface, device); *device = (IDirect3DDevice9 *)This->parentDevice; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static HRESULT WINAPI d3d9_vertexbuffer_GetDevice(IDirect3DVertexBuffer9 *iface, IDirect3DDevice9 **device) { struct d3d9_vertexbuffer *buffer = impl_from_IDirect3DVertexBuffer9(iface); TRACE("iface %p, device %p.\n", iface, device); *device = (IDirect3DDevice9 *)buffer->parent_device; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static HRESULT WINAPI d3d9_texture_2d_GetDevice(IDirect3DTexture9 *iface, IDirect3DDevice9 **device) { struct d3d9_texture *texture = impl_from_IDirect3DTexture9(iface); TRACE("iface %p, device %p.\n", iface, device); *device = (IDirect3DDevice9 *)texture->parent_device; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static HRESULT WINAPI d3d9_query_GetDevice(IDirect3DQuery9 *iface, IDirect3DDevice9 **device) { struct d3d9_query *query = impl_from_IDirect3DQuery9(iface); TRACE("iface %p, device %p.\n", iface, device); *device = (IDirect3DDevice9 *)query->parent_device; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static HRESULT WINAPI d3d9_pixelshader_GetDevice(IDirect3DPixelShader9 *iface, IDirect3DDevice9 **device) { struct d3d9_pixelshader *shader = impl_from_IDirect3DPixelShader9(iface); TRACE("iface %p, device %p.\n", iface, device); *device = (IDirect3DDevice9 *)shader->parent_device; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
/*** ID3DXLine methods ***/ static HRESULT WINAPI ID3DXLineImpl_GetDevice(ID3DXLine* iface, LPDIRECT3DDEVICE9* device) { ID3DXLineImpl *This = impl_from_ID3DXLine(iface); TRACE ("(%p)->(%p): relay\n", This, device); if (device == NULL) return D3DERR_INVALIDCALL; *device = This->device; IDirect3DDevice9_AddRef(This->device); return D3D_OK; }
static HRESULT WINAPI d3d9_stateblock_GetDevice(IDirect3DStateBlock9 *iface, IDirect3DDevice9 **device) { struct d3d9_stateblock *stateblock = impl_from_IDirect3DStateBlock9(iface); TRACE("iface %p, device %p.\n", iface, device); *device = (IDirect3DDevice9 *)stateblock->parent_device; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static HRESULT WINAPI IDirect3DQuery9Impl_GetDevice(IDirect3DQuery9 *iface, IDirect3DDevice9 **device) { IDirect3DQuery9Impl *This = impl_from_IDirect3DQuery9(iface); TRACE("iface %p, device %p.\n", iface, device); *device = (IDirect3DDevice9 *)This->parentDevice; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
static HRESULT WINAPI d3d9_surface_GetDevice(IDirect3DSurface9 *iface, IDirect3DDevice9 **device) { struct d3d9_surface *surface = impl_from_IDirect3DSurface9(iface); TRACE("iface %p, device %p.\n", iface, device); if (surface->texture) return IDirect3DBaseTexture9_GetDevice(&surface->texture->IDirect3DBaseTexture9_iface, device); *device = (IDirect3DDevice9 *)surface->parent_device; IDirect3DDevice9_AddRef(*device); TRACE("Returning device %p.\n", *device); return D3D_OK; }
HRESULT D3D9_CreateDeviceExternal(IDirect3DDevice9 *dev, d3d9_handle_t *hd3d, HWND hwnd, const video_format_t *source, d3d9_device_t *out) { D3DDEVICE_CREATION_PARAMETERS params; HRESULT hr = IDirect3DDevice9_GetCreationParameters(dev, ¶ms); if (FAILED(hr)) return hr; out->dev = dev; out->owner = false; out->hwnd = hwnd; out->adapterId = params.AdapterOrdinal; ZeroMemory(&out->caps, sizeof(out->caps)); hr = IDirect3D9_GetDeviceCaps(hd3d->obj, out->adapterId, params.DeviceType, &out->caps); if (FAILED(hr)) return hr; if (D3D9_FillPresentationParameters(hd3d, source, out)) { return E_FAIL; } IDirect3DDevice9_AddRef(out->dev); return S_OK; }
HRESULT processor_software_create( IDirectXVideoProcessorService *processor_service, IDirect3DDevice9 *device, const DXVA2_VideoDesc *pVideoDesc, D3DFORMAT RenderTargetFormat, UINT MaxNumSubStreams, IDirectXVideoProcessor **processor ) { DirectXVideoProcessorImpl *software_processor; if (!processor_service || !pVideoDesc) return E_INVALIDARG; software_processor = CoTaskMemAlloc(sizeof(*software_processor)); if (!software_processor) return E_OUTOFMEMORY; software_processor->IDirectXVideoProcessor_iface.lpVtbl = &DirectXVideoProcessor_VTable; software_processor->refCount = 1; software_processor->service = processor_service; software_processor->device = device; IDirectXVideoProcessorService_AddRef(processor_service); IDirect3DDevice9_AddRef(device); *processor = &software_processor->IDirectXVideoProcessor_iface; return S_OK; }
/** * It creates a Direct3D device usable for DXVA 2 */ static int D3dCreateDevice(vlc_va_t *va) { vlc_va_sys_t *sys = va->sys; if (sys->dx_sys.d3ddev) { msg_Dbg(va, "Reusing Direct3D9 device"); IDirect3DDevice9_AddRef(sys->dx_sys.d3ddev); return VLC_SUCCESS; } /* */ LPDIRECT3D9 (WINAPI *Create9)(UINT SDKVersion); Create9 = (void *)GetProcAddress(sys->hd3d9_dll, "Direct3DCreate9"); if (!Create9) { msg_Err(va, "Cannot locate reference to Direct3DCreate9 ABI in DLL"); return VLC_EGENERIC; } /* */ LPDIRECT3D9 d3dobj; d3dobj = Create9(D3D_SDK_VERSION); if (!d3dobj) { msg_Err(va, "Direct3DCreate9 failed"); return VLC_EGENERIC; } sys->d3dobj = d3dobj; /* */ D3DADAPTER_IDENTIFIER9 *d3dai = &sys->d3dai; if (FAILED(IDirect3D9_GetAdapterIdentifier(sys->d3dobj, D3DADAPTER_DEFAULT, 0, d3dai))) { msg_Warn(va, "IDirect3D9_GetAdapterIdentifier failed"); ZeroMemory(d3dai, sizeof(*d3dai)); } /* */ D3DPRESENT_PARAMETERS d3dpp; ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Flags = D3DPRESENTFLAG_VIDEO; d3dpp.Windowed = TRUE; d3dpp.hDeviceWindow = NULL; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE; d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT; d3dpp.BackBufferCount = 0; /* FIXME what to put here */ d3dpp.BackBufferFormat = D3DFMT_X8R8G8B8; /* FIXME what to put here */ d3dpp.BackBufferWidth = 0; d3dpp.BackBufferHeight = 0; d3dpp.EnableAutoDepthStencil = FALSE; /* Direct3D needs a HWND to create a device, even without using ::Present this HWND is used to alert Direct3D when there's a change of focus window. For now, use GetDesktopWindow, as it looks harmless */ LPDIRECT3DDEVICE9 d3ddev; if (FAILED(IDirect3D9_CreateDevice(d3dobj, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, GetDesktopWindow(), D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED, &d3dpp, &d3ddev))) { msg_Err(va, "IDirect3D9_CreateDevice failed"); return VLC_EGENERIC; } sys->dx_sys.d3ddev = (IUnknown*) d3ddev; return VLC_SUCCESS; }
static void test_create_effect_and_pool(IDirect3DDevice9 *device) { HRESULT hr; ID3DXEffect *effect; ID3DXBaseEffect *base; ULONG count; IDirect3DDevice9 *device2; LPD3DXEFFECTSTATEMANAGER manager = (LPD3DXEFFECTSTATEMANAGER)0xdeadbeef; ID3DXEffectPool *pool = (ID3DXEffectPool *)0xdeadbeef, *pool2; hr = D3DXCreateEffect(NULL, effect_desc, sizeof(effect_desc), NULL, NULL, 0, NULL, NULL, NULL); ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateEffect(device, NULL, 0, NULL, NULL, 0, NULL, NULL, NULL); ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateEffect(device, effect_desc, 0, NULL, NULL, 0, NULL, NULL, NULL); ok(hr == E_FAIL, "Got result %x, expected %x (D3DXERR_INVALIDDATA)\n", hr, E_FAIL); hr = D3DXCreateEffect(device, effect_desc, sizeof(effect_desc), NULL, NULL, 0, NULL, NULL, NULL); ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr); hr = D3DXCreateEffect(device, effect_desc, sizeof(effect_desc), NULL, NULL, 0, NULL, &effect, NULL); ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr); hr = effect->lpVtbl->QueryInterface(effect, &IID_ID3DXBaseEffect, (void **)&base); ok(hr == E_NOINTERFACE, "QueryInterface failed, got %x, expected %x (E_NOINTERFACE)\n", hr, E_NOINTERFACE); hr = effect->lpVtbl->GetStateManager(effect, NULL); ok(hr == D3DERR_INVALIDCALL, "GetStateManager failed, got %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = effect->lpVtbl->GetStateManager(effect, &manager); ok(hr == D3D_OK, "GetStateManager failed, got %x, expected 0 (D3D_OK)\n", hr); ok(!manager, "GetStateManager failed, got %p\n", manager); /* this works, but it is not recommended! */ hr = effect->lpVtbl->SetStateManager(effect, (LPD3DXEFFECTSTATEMANAGER) device); ok(hr == D3D_OK, "SetStateManager failed, got %x, expected 0 (D3D_OK)\n", hr); hr = effect->lpVtbl->GetStateManager(effect, &manager); ok(hr == D3D_OK, "GetStateManager failed, got %x, expected 0 (D3D_OK)\n", hr); ok(manager != NULL, "GetStateManager failed\n"); IDirect3DDevice9_AddRef(device); count = IDirect3DDevice9_Release(device); ok(count == 4, "Release failed, got %u, expected 4\n", count); count = IUnknown_Release(manager); ok(count == 3, "Release failed, got %u, expected 3\n", count); hr = effect->lpVtbl->SetStateManager(effect, NULL); ok(hr == D3D_OK, "SetStateManager failed, got %x, expected 0 (D3D_OK)\n", hr); hr = effect->lpVtbl->GetPool(effect, &pool); ok(hr == D3D_OK, "GetPool failed, got %x, expected 0 (D3D_OK)\n", hr); ok(!pool, "GetPool failed, got %p\n", pool); hr = effect->lpVtbl->GetPool(effect, NULL); ok(hr == D3DERR_INVALIDCALL, "GetPool failed, got %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = effect->lpVtbl->GetDevice(effect, &device2); ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr); hr = effect->lpVtbl->GetDevice(effect, NULL); ok(hr == D3DERR_INVALIDCALL, "GetDevice failed, got %x, expected %x (D3DERR_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); count = IDirect3DDevice9_Release(device2); ok(count == 2, "Release failed, got %u, expected 2\n", count); count = effect->lpVtbl->Release(effect); ok(count == 0, "Release failed %u\n", count); hr = D3DXCreateEffectPool(NULL); ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateEffectPool(&pool); ok(hr == S_OK, "Got result %x, expected 0 (S_OK)\n", hr); count = pool->lpVtbl->Release(pool); ok(count == 0, "Release failed %u\n", count); hr = D3DXCreateEffectPool(&pool); ok(hr == S_OK, "Got result %x, expected 0 (S_OK)\n", hr); hr = D3DXCreateEffect(device, effect_desc, sizeof(effect_desc), NULL, NULL, 0, pool, NULL, NULL); ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr); hr = pool->lpVtbl->QueryInterface(pool, &IID_ID3DXEffectPool, (void **)&pool2); ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr); ok(pool == pool2, "Release failed, got %p, expected %p\n", pool2, pool); count = pool2->lpVtbl->Release(pool2); ok(count == 1, "Release failed, got %u, expected 1\n", count); hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9, (void **)&device2); ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr); count = IDirect3DDevice9_Release(device2); ok(count == 1, "Release failed, got %u, expected 1\n", count); hr = D3DXCreateEffect(device, effect_desc, sizeof(effect_desc), NULL, NULL, 0, pool, &effect, NULL); ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr); hr = effect->lpVtbl->GetPool(effect, &pool); ok(hr == D3D_OK, "GetPool failed, got %x, expected 0 (D3D_OK)\n", hr); ok(pool == pool2, "GetPool failed, got %p, expected %p\n", pool2, pool); count = pool2->lpVtbl->Release(pool2); ok(count == 2, "Release failed, got %u, expected 2\n", count); count = effect->lpVtbl->Release(effect); ok(count == 0, "Release failed %u\n", count); count = pool->lpVtbl->Release(pool); ok(count == 0, "Release failed %u\n", count); }
/*********************************************************************** * D3DXCreateFontIndirectW (D3DX9_36.@) */ HRESULT WINAPI D3DXCreateFontIndirectW(IDirect3DDevice9 *device, const D3DXFONT_DESCW *desc, ID3DXFont **font) { D3DDEVICE_CREATION_PARAMETERS cpars; D3DDISPLAYMODE mode; struct d3dx_font *object; IDirect3D9 *d3d; HRESULT hr; TRACE("(%p, %p, %p)\n", device, desc, font); if (!device || !desc || !font) return D3DERR_INVALIDCALL; TRACE("desc: %d %d %d %d %d %d %d %d %d %s\n", desc->Height, desc->Width, desc->Weight, desc->MipLevels, desc->Italic, desc->CharSet, desc->OutputPrecision, desc->Quality, desc->PitchAndFamily, debugstr_w(desc->FaceName)); /* The device MUST support D3DFMT_A8R8G8B8 */ IDirect3DDevice9_GetDirect3D(device, &d3d); IDirect3DDevice9_GetCreationParameters(device, &cpars); IDirect3DDevice9_GetDisplayMode(device, 0, &mode); hr = IDirect3D9_CheckDeviceFormat(d3d, cpars.AdapterOrdinal, cpars.DeviceType, mode.Format, 0, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8); if (FAILED(hr)) { IDirect3D9_Release(d3d); return D3DXERR_INVALIDDATA; } IDirect3D9_Release(d3d); object = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct d3dx_font)); if (!object) { *font = NULL; return E_OUTOFMEMORY; } object->ID3DXFont_iface.lpVtbl = &D3DXFont_Vtbl; object->ref = 1; object->device = device; object->desc = *desc; object->hdc = CreateCompatibleDC(NULL); if (!object->hdc) { HeapFree(GetProcessHeap(), 0, object); return D3DXERR_INVALIDDATA; } object->hfont = CreateFontW(desc->Height, desc->Width, 0, 0, desc->Weight, desc->Italic, FALSE, FALSE, desc->CharSet, desc->OutputPrecision, CLIP_DEFAULT_PRECIS, desc->Quality, desc->PitchAndFamily, desc->FaceName); if (!object->hfont) { DeleteDC(object->hdc); HeapFree(GetProcessHeap(), 0, object); return D3DXERR_INVALIDDATA; } SelectObject(object->hdc, object->hfont); SetTextColor(object->hdc, 0x00ffffff); SetBkColor(object->hdc, 0x00000000); IDirect3DDevice9_AddRef(device); *font = &object->ID3DXFont_iface; return D3D_OK; }