]> git.vomp.tv Git - vompclient.git/blob - dsallocator.cc
Vogel Media Player 2008-11-28
[vompclient.git] / dsallocator.cc
1 /*
2     Copyright 2004-2005 Chris Tallon
3
4     This file is part of VOMP.
5
6     VOMP is free software; you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation; either version 2 of the License, or
9     (at your option) any later version.
10
11     VOMP is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with VOMP; if not, write to the Free Software
18     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
19 */
20 #include "osdwin.h"
21 #include "dsallocator.h"
22
23
24 DsAllocator::DsAllocator() {
25         surfallocnotify=NULL;
26         refcount=1;
27         
28
29
30 }
31
32 DsAllocator::~DsAllocator() {
33         CleanupSurfaces();
34
35 }
36
37 void DsAllocator::CleanupSurfaces() {
38         for (int i=0;i<surfaces.size();i++) {
39                 if (surfaces[i]!=NULL) surfaces[i]->Release();
40                 surfaces[i]=NULL;
41         }
42 }
43
44 HRESULT STDMETHODCALLTYPE DsAllocator::InitializeDevice(DWORD_PTR userid,VMR9AllocationInfo* allocinf,DWORD*numbuf){
45         if (!surfallocnotify) return S_FALSE;
46         Lock();
47         CleanupSurfaces();
48
49         surfaces.resize(*numbuf);
50         HRESULT hres= surfallocnotify->AllocateSurfaceHelper(allocinf,numbuf,&surfaces.at(0));
51         Unlock();
52         return hres;
53 }
54
55 void DsAllocator::LostDevice(IDirect3DDevice9 *d3ddev, IDirect3D9* d3d) {
56         if (!surfallocnotify) return ;
57         Lock();
58         CleanupSurfaces();
59 //      d3ddev=((OsdWin*)Osd::getInstance())->getD3dDev();
60         HMONITOR hmon=d3d->GetAdapterMonitor(D3DADAPTER_DEFAULT);
61         surfallocnotify->ChangeD3DDevice(d3ddev,hmon);
62         Unlock();
63
64 }
65
66 HRESULT STDMETHODCALLTYPE DsAllocator::TerminateDevice(DWORD_PTR userid){
67         Lock();
68         CleanupSurfaces();
69         Unlock();
70         return S_OK; //Do nothing
71 }
72 HRESULT STDMETHODCALLTYPE DsAllocator::GetSurface(DWORD_PTR userid,DWORD surfindex,DWORD surfflags, IDirect3DSurface9** surf)
73 {
74         if (surfindex>=surfaces.size()) return E_FAIL;
75         if (surf==NULL) return E_POINTER;
76
77         Lock();
78         surfaces[surfindex]->AddRef();
79         *surf=surfaces[surfindex];
80         Unlock();
81         return S_OK;
82 }
83 HRESULT STDMETHODCALLTYPE DsAllocator::AdviseNotify(IVMRSurfaceAllocatorNotify9* allnoty){
84         Lock();
85         surfallocnotify=allnoty;
86         IDirect3DDevice9 *d3ddev;
87         //OK lets set the direct3d object from the osd
88         d3ddev=((OsdWin*)Osd::getInstance())->getD3dDev();
89         HMONITOR hmon=((OsdWin*)Osd::getInstance())->getD3d()->GetAdapterMonitor(D3DADAPTER_DEFAULT);
90         HRESULT hres=surfallocnotify->SetD3DDevice(d3ddev,hmon);
91         Unlock();
92         return hres;
93 }
94
95
96 HRESULT STDMETHODCALLTYPE DsAllocator::StartPresenting(DWORD_PTR userid){
97         ((OsdWin*)Osd::getInstance())->setExternalDriving(this);
98         return S_OK;
99 }
100 HRESULT STDMETHODCALLTYPE DsAllocator::StopPresenting(DWORD_PTR userid){
101         ((OsdWin*)Osd::getInstance())->setExternalDriving(NULL);
102         return S_OK;
103 }
104
105 HRESULT STDMETHODCALLTYPE DsAllocator::PresentImage(DWORD_PTR userid,VMR9PresentationInfo* presinf){
106         ((OsdWin*)Osd::getInstance())->RenderDS(presinf->lpSurf); //render and return
107         return S_OK;
108
109 }
110
111 HRESULT STDMETHODCALLTYPE DsAllocator::QueryInterface(REFIID refiid,void ** obj){
112         if (obj==NULL) return E_POINTER;
113
114         if (refiid==IID_IVMRSurfaceAllocator9) {
115                  *obj=static_cast<IVMRSurfaceAllocator9*>(this);
116                  AddRef();
117                  return S_OK;
118         } else if (refiid==IID_IVMRImagePresenter9) {
119                 *obj=static_cast<IVMRImagePresenter9*>(this);
120                 AddRef();
121                 return S_OK;
122         }
123         return E_NOINTERFACE;
124 }
125
126 ULONG STDMETHODCALLTYPE  DsAllocator::AddRef(){
127         return InterlockedIncrement(&refcount);
128 }
129
130 ULONG STDMETHODCALLTYPE DsAllocator::Release(){
131         ULONG ref=0;
132         ref=InterlockedDecrement(&refcount);
133         if (ref==NULL) {
134                 delete this; //Commit suicide
135         }
136         return ref;
137 }
138
139