2 * $Id: SubPicAllocatorPresenterImpl.cpp 2786 2010-12-17 16:42:55Z XhmikosR $
5 * (C) 2006-2010 see AUTHORS
7 * This Program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This Program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Make; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
20 * http://www.gnu.org/copyleft/gpl.html
25 #include "SubPicAllocatorPresenterImpl.h"
26 #include "../DSUtil/DSUtil.h"
28 CSubPicAllocatorPresenterImpl::CSubPicAllocatorPresenterImpl(HWND hWnd
, HRESULT
& hr
, CString
*_pError
)
29 : CUnknown(NAME("CSubPicAllocatorPresenterImpl"), NULL
)
31 , m_NativeVideoSize(0, 0), m_AspectRatio(0, 0)
32 , m_VideoRect(0, 0, 0, 0), m_WindowRect(0, 0, 0, 0)
34 , m_rtSubtitleDelay(0)
35 , m_bDeviceResetRequested(false)
36 , m_bPendingResetDevice(false)
38 if(!IsWindow(m_hWnd
)) {
41 *_pError
+= "Invalid window handle in ISubPicAllocatorPresenterImpl\n";
45 GetWindowRect(m_hWnd
, &m_WindowRect
);
46 SetVideoAngle(Vector(), false);
50 CSubPicAllocatorPresenterImpl::~CSubPicAllocatorPresenterImpl()
54 STDMETHODIMP
CSubPicAllocatorPresenterImpl::NonDelegatingQueryInterface(REFIID riid
, void** ppv
)
57 QI(ISubPicAllocatorPresenter
)
58 QI(ISubPicAllocatorPresenter2
)
59 __super::NonDelegatingQueryInterface(riid
, ppv
);
62 void CSubPicAllocatorPresenterImpl::AlphaBltSubPic(CSize size
, SubPicDesc
* pTarget
)
64 CComPtr
<ISubPic
> pSubPic
;
65 if(m_pSubPicQueue
->LookupSubPic(m_rtNow
, &pSubPic
)) {
66 CRect rcSource
, rcDest
;
67 if (SUCCEEDED (pSubPic
->GetSourceAndDest(&size
, rcSource
, rcDest
))) {
68 pSubPic
->AlphaBlt(rcSource
, rcDest
, pTarget
);
71 pSubPic->GetDesc(spd);
73 if(spd.w > 0 && spd.h > 0)
76 pSubPic->GetDirtyRect(r);
82 r.left * size.cx / spd.w,
83 r.top * size.cy / spd.h,
84 r.right * size.cx / spd.w,
85 r.bottom * size.cy / spd.h);
87 pSubPic->AlphaBlt(r, rDstText, pTarget);
93 // ISubPicAllocatorPresenter
95 STDMETHODIMP_(SIZE
) CSubPicAllocatorPresenterImpl::GetVideoSize(bool fCorrectAR
)
97 CSize
VideoSize(GetVisibleVideoSize());
99 if(fCorrectAR
&& m_AspectRatio
.cx
> 0 && m_AspectRatio
.cy
> 0) {
100 VideoSize
.cx
= (LONGLONG(VideoSize
.cy
)*LONGLONG(m_AspectRatio
.cx
))/LONGLONG(m_AspectRatio
.cy
);
106 STDMETHODIMP_(void) CSubPicAllocatorPresenterImpl::SetPosition(RECT w
, RECT v
)
108 bool fWindowPosChanged
= !!(m_WindowRect
!= w
);
109 bool fWindowSizeChanged
= !!(m_WindowRect
.Size() != CRect(w
).Size());
113 bool fVideoRectChanged
= !!(m_VideoRect
!= v
);
117 if(fWindowSizeChanged
|| fVideoRectChanged
) {
119 m_pAllocator
->SetCurSize(m_WindowRect
.Size());
120 m_pAllocator
->SetCurVidRect(m_VideoRect
);
124 m_pSubPicQueue
->Invalidate();
128 if(fWindowPosChanged
|| fVideoRectChanged
) {
129 Paint(fWindowSizeChanged
|| fVideoRectChanged
);
133 STDMETHODIMP_(void) CSubPicAllocatorPresenterImpl::SetTime(REFERENCE_TIME rtNow
)
136 if(m_rtNow <= rtNow && rtNow <= m_rtNow + 1000000)
139 m_rtNow
= rtNow
- m_rtSubtitleDelay
;
142 m_pSubPicQueue
->SetTime(m_rtNow
);
146 STDMETHODIMP_(void) CSubPicAllocatorPresenterImpl::SetSubtitleDelay(int delay_ms
)
148 m_rtSubtitleDelay
= delay_ms
*10000i64
;
151 STDMETHODIMP_(int) CSubPicAllocatorPresenterImpl::GetSubtitleDelay()
153 return (m_rtSubtitleDelay
/10000);
156 STDMETHODIMP_(double) CSubPicAllocatorPresenterImpl::GetFPS()
161 STDMETHODIMP_(void) CSubPicAllocatorPresenterImpl::SetSubPicProvider(ISubPicProvider
* pSubPicProvider
)
163 m_SubPicProvider
= pSubPicProvider
;
166 m_pSubPicQueue
->SetSubPicProvider(pSubPicProvider
);
170 STDMETHODIMP_(void) CSubPicAllocatorPresenterImpl::Invalidate(REFERENCE_TIME rtInvalidate
)
173 m_pSubPicQueue
->Invalidate(rtInvalidate
);
179 void CSubPicAllocatorPresenterImpl::Transform(CRect r
, Vector v
[4])
181 v
[0] = Vector(r
.left
, r
.top
, 0);
182 v
[1] = Vector(r
.right
, r
.top
, 0);
183 v
[2] = Vector(r
.left
, r
.bottom
, 0);
184 v
[3] = Vector(r
.right
, r
.bottom
, 0);
186 Vector
center(r
.CenterPoint().x
, r
.CenterPoint().y
, 0);
187 int l
= (int)(Vector(r
.Size().cx
, r
.Size().cy
, 0).Length()*1.5f
)+1;
189 for(int i
= 0; i
< 4; i
++)
191 v
[i
] = m_xform
<< (v
[i
] - center
);
192 v
[i
].z
= v
[i
].z
/ l
+ 0.5f
;
199 STDMETHODIMP
CSubPicAllocatorPresenterImpl::SetVideoAngle(Vector v
, bool fRepaint
)
201 m_xform
= XForm(Ray(Vector(0, 0, 0), v
), Vector(1, 1, 1), false);