/** @brief libvo Callback: Configre the Direct3D adapter. * @param width Movie source width * @param height Movie source height * @param d_width Screen (destination) width * @param d_height Screen (destination) height * @param options Options bitmap * @param title Window title * @param format Movie colorspace format (using MPlayer's * defines, e.g. IMGFMT_YUY2) * @return 0 on success, VO_ERROR on failure */ static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t options, char *title, uint32_t format) { priv->src_width = width; priv->src_height = height; /* w32_common framework call. Creates window on the screen with * the given coordinates. */ if (!vo_w32_config(d_width, d_height, options)) { mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Creating onscreen window failed.\n"); return VO_ERROR; } /* "config" may be called several times, so if this is not the first * call, we should destroy Direct3D adapter and surfaces before * calling configure_d3d, which will create them again. */ destroy_d3d_surfaces(); /* Destroy the D3D Device */ if (priv->d3d_device) IDirect3DDevice9_Release(priv->d3d_device); priv->d3d_device = NULL; if (!configure_d3d()) return VO_ERROR; return 0; /* Success */ }
static void test_create_line(IDirect3DDevice9* device) { HRESULT hr; LPD3DXLINE line = NULL; LPDIRECT3DDEVICE9 return_device; D3DXMATRIX world, identity, result; FLOAT r11, r12, r13, r14; ULONG ref; /* Arbitrary values for matrix tests. */ r11 = 0.1421; r12 = 0.2114; r13 = 0.8027; r14 = 0.4587; hr = D3DXCreateLine(NULL, &line); ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateLine(device, NULL); ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = D3DXCreateLine(device, &line); ok(hr == D3D_OK, "Got result %x, expected 0 (D3D_OK)\n", hr); if (FAILED(hr)) { return; } hr = ID3DXLine_GetDevice(line, NULL); ok(hr == D3DERR_INVALIDCALL, "Got result %x, expected %x (D3D_INVALIDCALL)\n", hr, D3DERR_INVALIDCALL); hr = ID3DXLine_GetDevice(line, &return_device); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); ok(return_device == device, "Expected line device %p, got %p\n", device, return_device); D3DXMatrixIdentity(&world); D3DXMatrixIdentity(&identity); S(U(world))._11 = r11; S(U(world))._12 = r12; S(U(world))._13 = r13; S(U(world))._14 = r14; hr = IDirect3DDevice9_SetTransform(device, D3DTS_WORLD, &world); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); hr = ID3DXLine_Begin(line); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); hr = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &result); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); expect_mat(&identity, &result); hr = ID3DXLine_End(line); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); hr = IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &result); ok(hr == D3D_OK, "Got result %x, expected %x (D3D_OK)\n", hr, D3D_OK); expect_mat(&world, &result); ref = IDirect3DDevice9_Release(return_device); ok(ref == 2, "Got %x references to device %p, expected 2\n", ref, return_device); ref = ID3DXLine_Release(line); ok(ref == 0, "Got %x references to line %p, expected 0\n", ref, line); }
void D3DCacheSystemShutdown(d3d_render_cache_system *pCacheSystem) { d3d_texture_cache_entry *pTexEntry; list_type list; d3d_render_cache *pRenderCache = NULL; // first free all textures for (list = pCacheSystem->textureCache.textureList; list != NULL; list = list->next) { pTexEntry = (d3d_texture_cache_entry *)list->data; if (pTexEntry->pTexture) IDirect3DDevice9_Release(pTexEntry->pTexture); } list_destroy(pCacheSystem->textureCache.textureList); // now destroy the vertex buffers for (list = pCacheSystem->renderCacheList; list != NULL; list = list->next) { pRenderCache = (d3d_render_cache *)list->data; if (pRenderCache) D3DCacheShutdown(pRenderCache); } list_destroy(pCacheSystem->renderCacheList); memset(pCacheSystem, 0, sizeof(d3d_render_cache_system)); }
/** * It releases a Direct3D device and its resources. */ static void D3dDestroyDevice(vlc_va_dxva2_t *va) { if (va->d3ddev) IDirect3DDevice9_Release(va->d3ddev); if (va->d3dobj) IDirect3D9_Release(va->d3dobj); }
void shutdownD3D9() { #ifdef __WIN32__ /* Free all resources */ if (gTexturePtr) IDirect3DTexture9_Release(gTexturePtr); gTexturePtr = NULL; if (gVShaderPtr) IDirect3DVertexShader9_Release(gVShaderPtr); gVShaderPtr = NULL; if (gPShaderPtr) IDirect3DPixelShader9_Release(gPShaderPtr); gPShaderPtr = NULL; if (gVertexBufferPtr) IDirect3DVertexBuffer9_Release(gVertexBufferPtr); gVertexBufferPtr = NULL; if (gIndexBufferPtr) IDirect3DIndexBuffer9_Release(gIndexBufferPtr); gIndexBufferPtr = NULL; if (gVertexDeclPtr) IDirect3DVertexDeclaration9_Release(gVertexDeclPtr); gVertexDeclPtr = NULL; if (gDevicePtr) IDirect3DDevice9_Release(gDevicePtr); gDevicePtr = NULL; if (gD3D9Ptr) IDirect3D9_Release(gD3D9Ptr); gD3D9Ptr = NULL; gDeviceBackBufferPtr = NULL; #endif }
static void D3D_DestroyRenderer(SDL_Renderer * renderer) { D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; if (data) { /* Release the render target */ if (data->defaultRenderTarget) { IDirect3DSurface9_Release(data->defaultRenderTarget); data->defaultRenderTarget = NULL; } if (data->currentRenderTarget != NULL) { IDirect3DSurface9_Release(data->currentRenderTarget); data->currentRenderTarget = NULL; } if (data->device) { IDirect3DDevice9_Release(data->device); } if (data->d3d) { IDirect3D9_Release(data->d3d); ID3DXMatrixStack_Release(data->matrixStack); SDL_UnloadObject(data->d3dDLL); } SDL_free(data); } SDL_free(renderer); }
/** \fn cleanup \brief cleanup all display dependant stuff, called again before switching zoom and at exit */ bool dxvaRender::cleanup() { ADM_info("D3D cleanup\n"); if(scaler) { delete scaler; scaler=NULL; } if(mySurface) { IDirect3DSurface9_Release(mySurface); mySurface=NULL; } if(myYV12Surface) { IDirect3DSurface9_Release(myYV12Surface); myYV12Surface=NULL; } #ifndef REUSE_DEVICE if(d3dDevice) { IDirect3DDevice9_Release(d3dDevice); d3dDevice=NULL; } #endif if(videoBuffer) { delete [] videoBuffer; videoBuffer=NULL; } return true; }
/** * It releases a Direct3D device and its resources. */ static void hb_d3d_destroy_device( hb_va_dxva2_t *dxva2 ) { if( dxva2->d3ddev ) IDirect3DDevice9_Release( dxva2->d3ddev ); if( dxva2->d3dobj ) IDirect3D9_Release( dxva2->d3dobj ); }
/** @brief Reconfigure the whole Direct3D. Called only * when the video adapter becomes uncooperative. * @return 1 on success, 0 on failure */ static int reconfigure_d3d(void) { mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>reconfigure_d3d called.\n"); /* Destroy the offscreen, OSD and backbuffer surfaces */ destroy_d3d_surfaces(); /* Destroy the D3D Device */ if (priv->d3d_device) IDirect3DDevice9_Release(priv->d3d_device); priv->d3d_device = NULL; /* Stop the whole Direct3D */ IDirect3D9_Release(priv->d3d_handle); /* Initialize Direct3D from the beginning */ priv->d3d_handle = priv->pDirect3DCreate9(D3D_SDK_VERSION); if (!priv->d3d_handle) { mp_msg(MSGT_VO, MSGL_ERR, "<vo_direct3d>Initializing Direct3D failed.\n"); return 0; } /* Configure Direct3D */ if (!configure_d3d()) return 0; return 1; }
static void dxva2_uninit(struct lavc_ctx *s) { DXVA2Context *ctx = s->hwdec_priv; if (!ctx) return; if (ctx->decoder) dxva2_destroy_decoder(s); if (ctx->decoder_service) IDirectXVideoDecoderService_Release(ctx->decoder_service); if (ctx->d3d9devmgr && ctx->deviceHandle != INVALID_HANDLE_VALUE) IDirect3DDeviceManager9_CloseDeviceHandle(ctx->d3d9devmgr, ctx->deviceHandle); if (ctx->d3d9devmgr) IDirect3DDeviceManager9_Release(ctx->d3d9devmgr); if (ctx->d3d9device) IDirect3DDevice9_Release(ctx->d3d9device); if (ctx->d3d9) IDirect3D9_Release(ctx->d3d9); if (ctx->d3dlib) FreeLibrary(ctx->d3dlib); if (ctx->dxva2lib) FreeLibrary(ctx->dxva2lib); av_freep(&s->avctx->hwaccel_context); talloc_free(ctx); s->hwdec_priv = NULL; }
static void dxva2_device_free(AVHWDeviceContext *ctx) { AVDXVA2DeviceContext *hwctx = ctx->hwctx; DXVA2DevicePriv *priv = ctx->user_opaque; if (hwctx->devmgr && priv->device_handle != INVALID_HANDLE_VALUE) IDirect3DDeviceManager9_CloseDeviceHandle(hwctx->devmgr, priv->device_handle); if (hwctx->devmgr) IDirect3DDeviceManager9_Release(hwctx->devmgr); if (priv->d3d9device) IDirect3DDevice9_Release(priv->d3d9device); if (priv->d3d9) IDirect3D9_Release(priv->d3d9); if (priv->d3dlib) FreeLibrary(priv->d3dlib); if (priv->dxva2lib) FreeLibrary(priv->dxva2lib); av_freep(&ctx->user_opaque); }
/** * It releases a Direct3D device and its resources. */ static void D3dDestroyDevice(vlc_va_t *va) { directx_sys_t *dx_sys = &va->sys->dx_sys; if (va->sys->d3dobj) IDirect3D9_Release(va->sys->d3dobj); if (dx_sys->d3ddev) IDirect3DDevice9_Release(dx_sys->d3ddev); }
void D3D9_ReleaseDevice(d3d9_device_t *d3d_dev) { if (d3d_dev->dev) { IDirect3DDevice9_Release(d3d_dev->dev); d3d_dev->dev = NULL; } }
ULONG STDMETHODCALLTYPE IDirect3DDevice9_Release_Hook(IDirect3DDevice9* This) { auto count = IDirect3DDevice9_Release_Orig(This); if (count == 1 && --IDirect3DDevice9_HookCount == 0) { UNHOOK(IDirect3DDevice9, This, EndScene); UNHOOK(IDirect3DDevice9, This, Release); count = IDirect3DDevice9_Release(This); } return count; }
void video_device_release_dx9(video_canvas_t *canvas) { if (canvas->d3dsurface) { IDirect3DSurface9_Release(canvas->d3dsurface); canvas->d3dsurface = NULL; } if (canvas->d3ddev) { IDirect3DDevice9_Release(canvas->d3ddev); canvas->d3ddev = NULL; } }
/** * It releases the Direct3D9 device and its resources. */ static void Direct3DClose(vout_display_t *vd) { vout_display_sys_t *sys = vd->sys; Direct3DDestroyResources(vd); if (sys->d3ddev) IDirect3DDevice9_Release(sys->d3ddev); sys->d3ddev = NULL; }
static void Close(vlc_object_t *obj) { filter_t *filter = (filter_t *)obj; filter_sys_t *sys = filter->p_sys; IDirect3DSurface9_Release( sys->hw_surface ); IDirectXVideoProcessor_Release( sys->processor ); IDirect3DDevice9_Release( sys->d3ddev ); FreeLibrary( sys->hdecoder_dll ); FreeLibrary( sys->d3d9_dll ); free(sys); }
static void D3D_DestroyRenderer(SDL_Renderer * renderer) { D3D_RenderData *data = (D3D_RenderData *) renderer->driverdata; if (data) { if (data->device) { IDirect3DDevice9_Release(data->device); } SDL_free(data); } SDL_free(renderer); }
static void test_qi_base_to_ex(void) { IDirect3D9 *d3d9 = pDirect3DCreate9(D3D_SDK_VERSION); IDirect3D9Ex *d3d9ex = (void *) 0xdeadbeef; IDirect3DDevice9 *device; IDirect3DDevice9Ex *deviceEx = (void *) 0xdeadbeef; HRESULT hr; HWND window = create_window(); D3DPRESENT_PARAMETERS present_parameters; if (!d3d9) { skip("Direct3D9 is not available\n"); return; } hr = IDirect3D9_QueryInterface(d3d9, &IID_IDirect3D9Ex, (void **) &d3d9ex); ok(hr == E_NOINTERFACE, "IDirect3D9::QueryInterface for IID_IDirect3D9Ex returned %08x, expected E_NOINTERFACE\n", hr); ok(d3d9ex == NULL, "QueryInterface returned interface %p, expected NULL\n", d3d9ex); if(d3d9ex) IDirect3D9Ex_Release(d3d9ex); memset(&present_parameters, 0, sizeof(present_parameters)); present_parameters.Windowed = TRUE; present_parameters.hDeviceWindow = window; present_parameters.SwapEffect = D3DSWAPEFFECT_COPY; present_parameters.BackBufferWidth = 640; present_parameters.BackBufferHeight = 480; present_parameters.EnableAutoDepthStencil = FALSE; present_parameters.AutoDepthStencilFormat = D3DFMT_D16; hr = IDirect3D9_CreateDevice(d3d9, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, present_parameters.hDeviceWindow, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &present_parameters, &device); if(FAILED(hr)) { skip("Failed to create a regular Direct3DDevice9, skipping QI tests\n"); goto out; } hr = IDirect3DDevice9_QueryInterface(device, &IID_IDirect3DDevice9Ex, (void **) &deviceEx); ok(hr == E_NOINTERFACE, "IDirect3D9Device::QueryInterface for IID_IDirect3DDevice9Ex returned %08x, expected E_NOINTERFACE\n", hr); ok(deviceEx == NULL, "QueryInterface returned interface %p, expected NULL\n", deviceEx); if(deviceEx) IDirect3DDevice9Ex_Release(deviceEx); IDirect3DDevice9_Release(device); out: IDirect3D9_Release(d3d9); DestroyWindow(window); }
static ULONG WINAPI ID3DXLineImpl_Release(ID3DXLine* iface) { ID3DXLineImpl *This = impl_from_ID3DXLine(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("(%p)->(): Release from %u\n", This, ref + 1); if (!ref) { IDirect3DDevice9_Release(This->device); HeapFree(GetProcessHeap(), 0, This); } return ref; }
static void test_setting_constants(void) { HWND wnd; IDirect3D9 *d3d; IDirect3DDevice9 *device; D3DPRESENT_PARAMETERS d3dpp; HRESULT hr; ULONG refcnt; /* Create the device to use for our tests */ wnd = CreateWindow("static", "d3dx9_test", 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL); d3d = Direct3DCreate9(D3D_SDK_VERSION); if (!wnd) { skip("Couldn't create application window\n"); return; } if (!d3d) { skip("Couldn't create IDirect3D9 object\n"); DestroyWindow(wnd); return; } ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = TRUE; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_MIXED_VERTEXPROCESSING, &d3dpp, &device); if (FAILED(hr)) { skip("Failed to create IDirect3DDevice9 object %#x\n", hr); IDirect3D9_Release(d3d); DestroyWindow(wnd); return; } test_setting_basic_table(device); test_setting_arrays_table(device); /* Release resources */ refcnt = IDirect3DDevice9_Release(device); ok(refcnt == 0, "The Direct3D device reference count was %u, should be 0\n", refcnt); refcnt = IDirect3D9_Release(d3d); ok(refcnt == 0, "The Direct3D object referenct count was %u, should be 0\n", refcnt); if (wnd) DestroyWindow(wnd); }
void d3dwin_close(){ if(fullscreen) ShowCursor(TRUE); if(device){ IDirect3DDevice9_EvictManagedResources(device); IDirect3DDevice9_Release(device); device = NULL; } if(direct3d){ IDirect3D9_Release(direct3d); direct3d = NULL; } if(win){ DestroyWindow(win); win = NULL; } UnregisterClass("d3d9", inst); }
/** @brief Uninitialize Direct3D and close the window. */ static void uninit_d3d(void) { mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>uninit_d3d called.\n"); destroy_d3d_surfaces(); /* Destroy the D3D Device */ if (priv->d3d_device) IDirect3DDevice9_Release(priv->d3d_device); priv->d3d_device = NULL; /* Stop the whole D3D. */ if (priv->d3d_handle) { mp_msg(MSGT_VO, MSGL_V, "<vo_direct3d>Stopping Direct3D.\n"); IDirect3D9_Release(priv->d3d_handle); } priv->d3d_handle = NULL; }
static ULONG WINAPI DirectXVideoProcessor_Release( IDirectXVideoProcessor *iface ) { DirectXVideoProcessorImpl *This = impl_from_IDirectXVideoProcessor(iface); ULONG refCount = InterlockedDecrement(&This->refCount); TRACE("(%p)->() Release from %d\n", This, refCount + 1); if (!refCount) { TRACE("Destroying\n"); IDirectXVideoProcessorService_Release(This->service); IDirect3DDevice9_Release(This->device); CoTaskMemFree(This); } return refCount; }
void d3d_device_free(LPDIRECT3DDEVICE dev, LPDIRECT3D pd3d) { if (dev) { #if defined(HAVE_D3D9) && !defined(__cplusplus) IDirect3DDevice9_Release(dev); #else dev->Release(); #endif } if (pd3d) { #if defined(HAVE_D3D9) && !defined(__cplusplus) IDirect3D9_Release(pd3d); #else pd3d->Release(); #endif } }
static BOOL create_video_service(HWND focus_window, REFIID riid, void **service) { IDirect3DDevice9 *device; IDirect3D9 *d3d9; HRESULT hr; d3d9 = Direct3DCreate9(D3D_SDK_VERSION); if (!d3d9) return FALSE; device = create_device(d3d9, focus_window); IDirect3D9_Release(d3d9); if(!device) return FALSE; hr = pDXVA2CreateVideoService(device, riid, service); IDirect3DDevice9_Release(device); if (hr) return FALSE; return TRUE; }
static ULONG WINAPI ID3DXFontImpl_Release(ID3DXFont *iface) { struct d3dx_font *This = impl_from_ID3DXFont(iface); ULONG ref = InterlockedDecrement(&This->ref); TRACE("%p decreasing refcount to %u\n", iface, ref); if (!ref) { if (This->texture) { IDirect3DTexture9_Release(This->texture); DeleteObject(This->bitmap); } DeleteObject(This->hfont); DeleteDC(This->hdc); IDirect3DDevice9_Release(This->device); HeapFree(GetProcessHeap(), 0, This); } return ref; }
//get the VMT and the hooking functions offsets void GetDevice9Methods() { IDirect3D9 *d3d9_ptr; IDirect3DDevice9* d3dDevice; DWORD* vtablePtr; D3DPRESENT_PARAMETERS d3dpp; static HMODULE d3d9_handle = 0; HWND hWnd = CreateWindowExA(0, "STATIC","dummy", 0, 0, 0, 0, 0, 0, 0, 0, 0); d3d9_handle = LoadLibraryA("d3d9.dll"); d3d9_ptr = Direct3DCreate9(D3D_SDK_VERSION); ZeroMemory(&d3dpp, sizeof(d3dpp)); d3dpp.Windowed = 1; d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD; IDirect3D9_CreateDevice(d3d9_ptr, 0, D3DDEVTYPE_HAL, hWnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &d3dDevice); vtablePtr = (DWORD*)(*((DWORD*)d3dDevice)); present9 = vtablePtr[17] - (DWORD)d3d9_handle; IDirect3DDevice9_Release(d3dDevice); IDirect3D9_Release(d3d9_ptr); FreeLibrary(d3d9_handle); CloseHandle(hWnd); }
static void gst_dx9screencapsrc_dispose (GObject * object) { GstDX9ScreenCapSrc *src = GST_DX9SCREENCAPSRC (object); if (src->surface) { GST_ERROR_OBJECT (object, "DX9 surface was not freed in _stop, freeing in _dispose!"); IDirect3DSurface9_Release (src->surface); src->surface = NULL; } if (src->d3d9_device) { IDirect3DDevice9_Release (src->d3d9_device); src->d3d9_device = NULL; } if (!IDirect3D9_Release (g_d3d9)) g_d3d9 = NULL; G_OBJECT_CLASS (parent_class)->dispose (object); }
static void dxva2_uninit(AVCodecContext *s) { HwAccelContext *hac = s->opaque; DXVA2Context *ctx = hac->hwaccel_ctx; hac->hwaccel_uninit = NULL; hac->hwaccel_get_buffer = NULL; hac->hwaccel_retrieve_data = NULL; if (ctx->decoder) dxva2_destroy_decoder(s); if (ctx->decoder_service) IDirectXVideoDecoderService_Release(ctx->decoder_service); if (ctx->d3d9devmgr && ctx->deviceHandle != INVALID_HANDLE_VALUE) IDirect3DDeviceManager9_CloseDeviceHandle(ctx->d3d9devmgr, ctx->deviceHandle); if (ctx->d3d9devmgr) IDirect3DDeviceManager9_Release(ctx->d3d9devmgr); if (ctx->d3d9device) IDirect3DDevice9_Release(ctx->d3d9device); if (ctx->d3d9) IDirect3D9_Release(ctx->d3d9); if (ctx->d3dlib) FreeLibrary(ctx->d3dlib); //if (ctx->dxva2lib) // FreeLibrary(ctx->dxva2lib); av_frame_free(&ctx->tmp_frame); av_freep(&hac->hwaccel_ctx); av_freep(&s->hwaccel_context); }