From 862f859dc9a78e9907817e65b71fe57c5741720e Mon Sep 17 00:00:00 2001 From: Chris Tallon Date: Sun, 21 May 2006 16:32:36 +0000 Subject: [PATCH] Windows port --- dsallocator.cc | 135 +++++++++++++++++++++++++++++++++++++++++++++++++ dsallocator.h | 72 ++++++++++++++++++++++++++ 2 files changed, 207 insertions(+) create mode 100644 dsallocator.cc create mode 100644 dsallocator.h diff --git a/dsallocator.cc b/dsallocator.cc new file mode 100644 index 0000000..713d280 --- /dev/null +++ b/dsallocator.cc @@ -0,0 +1,135 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#include "osdwin.h" +#include "dsallocator.h" + + +DsAllocator::DsAllocator() { + CAutoLock locked(&objCritSec); + surfallocnotify=NULL; + refcount=1; + + + +} + +DsAllocator::~DsAllocator() { + CAutoLock locked(&objCritSec); + CleanupSurfaces(); + +} + +void DsAllocator::CleanupSurfaces() { + for (int i=0;iRelease(); + surfaces[i]=NULL; + } +} + +HRESULT STDMETHODCALLTYPE DsAllocator::InitializeDevice(DWORD_PTR userid,VMR9AllocationInfo* allocinf,DWORD*numbuf){ + CAutoLock locked(&objCritSec); + if (!surfallocnotify) return S_FALSE; + CleanupSurfaces(); + + surfaces.resize(*numbuf); + return surfallocnotify->AllocateSurfaceHelper(allocinf,numbuf,&surfaces.at(0)); +} + +void DsAllocator::LostDevice() { + CAutoLock locked(&objCritSec); + if (!surfallocnotify) return ; + CleanupSurfaces(); + IDirect3DDevice9 *d3ddev; + d3ddev=((OsdWin*)Osd::getInstance())->getD3dDev(); + HMONITOR hmon=((OsdWin*)Osd::getInstance())->getD3d()->GetAdapterMonitor(D3DADAPTER_DEFAULT); + surfallocnotify->ChangeD3DDevice(d3ddev,hmon); + +} + +HRESULT STDMETHODCALLTYPE DsAllocator::TerminateDevice(DWORD_PTR userid){ + CAutoLock locked(&objCritSec); + CleanupSurfaces(); + return S_OK; //Do nothing +} +HRESULT STDMETHODCALLTYPE DsAllocator::GetSurface(DWORD_PTR userid,DWORD surfindex,DWORD surfflags, IDirect3DSurface9** surf) +{ + if (surfindex>=surfaces.size()) return E_FAIL; + if (surf==NULL) return E_POINTER; + + CAutoLock locked(&objCritSec); + surfaces[surfindex]->AddRef(); + *surf=surfaces[surfindex]; + return S_OK; +} +HRESULT STDMETHODCALLTYPE DsAllocator::AdviseNotify(IVMRSurfaceAllocatorNotify9* allnoty){ + CAutoLock locked(&objCritSec); + surfallocnotify=allnoty; + IDirect3DDevice9 *d3ddev; + //OK lets set the direct3d object from the osd + d3ddev=((OsdWin*)Osd::getInstance())->getD3dDev(); + HMONITOR hmon=((OsdWin*)Osd::getInstance())->getD3d()->GetAdapterMonitor(D3DADAPTER_DEFAULT); + return surfallocnotify->SetD3DDevice(d3ddev,hmon); +} + + +HRESULT STDMETHODCALLTYPE DsAllocator::StartPresenting(DWORD_PTR userid){ + ((OsdWin*)Osd::getInstance())->setExternalDriving(this); + return S_OK; +} +HRESULT STDMETHODCALLTYPE DsAllocator::StopPresenting(DWORD_PTR userid){ + ((OsdWin*)Osd::getInstance())->setExternalDriving(NULL); + return S_OK; +} + +HRESULT STDMETHODCALLTYPE DsAllocator::PresentImage(DWORD_PTR userid,VMR9PresentationInfo* presinf){ + ((OsdWin*)Osd::getInstance())->RenderDS(presinf->lpSurf); //render and return + return S_OK; + +} + +HRESULT STDMETHODCALLTYPE DsAllocator::QueryInterface(REFIID refiid,void ** obj){ + if (obj==NULL) return E_POINTER; + + if (refiid==IID_IVMRSurfaceAllocator9) { + *obj=static_cast(this); + AddRef(); + return S_OK; + } else if (refiid==IID_IVMRImagePresenter9) { + *obj=static_cast(this); + AddRef(); + return S_OK; + } + return E_NOINTERFACE; +} + +ULONG STDMETHODCALLTYPE DsAllocator::AddRef(){ + return InterlockedIncrement(&refcount); +} + +ULONG STDMETHODCALLTYPE DsAllocator::Release(){ + ULONG ref=0; + ref=InterlockedDecrement(&refcount); + if (ref==NULL) { + delete this; //Commit suicide + } + return ref; +} + + diff --git a/dsallocator.h b/dsallocator.h new file mode 100644 index 0000000..52b08cb --- /dev/null +++ b/dsallocator.h @@ -0,0 +1,72 @@ +/* + Copyright 2004-2005 Chris Tallon + + This file is part of VOMP. + + VOMP is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + VOMP is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with VOMP; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +#ifndef DSALLOCATOR_H +#define DSALLOCATOR_H + +#include +using namespace std; +#include +#include +#include +#include + + + + +class DsAllocator: public IVMRSurfaceAllocator9, IVMRImagePresenter9 { +public: + DsAllocator(); + virtual ~DsAllocator(); + + virtual HRESULT STDMETHODCALLTYPE StartPresenting(DWORD_PTR userid); + virtual HRESULT STDMETHODCALLTYPE StopPresenting(DWORD_PTR userid); + virtual HRESULT STDMETHODCALLTYPE PresentImage(DWORD_PTR userid,VMR9PresentationInfo* presinf); + + virtual HRESULT STDMETHODCALLTYPE InitializeDevice(DWORD_PTR userid, + VMR9AllocationInfo* allocinf,DWORD* numbuf); + virtual HRESULT STDMETHODCALLTYPE TerminateDevice(DWORD_PTR userid); + virtual HRESULT STDMETHODCALLTYPE GetSurface(DWORD_PTR userid,DWORD surfindex,DWORD surfflags, IDirect3DSurface9** surf); + virtual HRESULT STDMETHODCALLTYPE AdviseNotify(IVMRSurfaceAllocatorNotify9* allnoty); + + + virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID refiid,void ** obj); + virtual ULONG STDMETHODCALLTYPE AddRef(); + virtual ULONG STDMETHODCALLTYPE Release(); + + void LostDevice(); + +protected: + + vector surfaces; + CCritSec objCritSec; + IVMRSurfaceAllocatorNotify9* surfallocnotify; + void CleanupSurfaces(); + LONG refcount; + + +}; + + + + + + + +#endif -- 2.39.5