Increase ParseScript cache from 30 to 90 seconds
[xy_vsfilter.git] / src / subpic / SubPicAllocatorPresenterImpl.cpp
blob8184c55bdad6f0f057c337de3e1c241f9a452b1d
1 /*
2 * $Id: SubPicAllocatorPresenterImpl.cpp 2786 2010-12-17 16:42:55Z XhmikosR $
4 * (C) 2003-2006 Gabest
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)
10 * any later version.
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
24 #include "stdafx.h"
25 #include "SubPicAllocatorPresenterImpl.h"
26 #include "../DSUtil/DSUtil.h"
28 CSubPicAllocatorPresenterImpl::CSubPicAllocatorPresenterImpl(HWND hWnd, HRESULT& hr, CString *_pError)
29 : CUnknown(NAME("CSubPicAllocatorPresenterImpl"), NULL)
30 , m_hWnd(hWnd)
31 , m_NativeVideoSize(0, 0), m_AspectRatio(0, 0)
32 , m_VideoRect(0, 0, 0, 0), m_WindowRect(0, 0, 0, 0)
33 , m_fps(25.0)
34 , m_rtSubtitleDelay(0)
35 , m_bDeviceResetRequested(false)
36 , m_bPendingResetDevice(false)
38 if(!IsWindow(m_hWnd)) {
39 hr = E_INVALIDARG;
40 if (_pError) {
41 *_pError += "Invalid window handle in ISubPicAllocatorPresenterImpl\n";
43 return;
45 GetWindowRect(m_hWnd, &m_WindowRect);
46 SetVideoAngle(Vector(), false);
47 hr = S_OK;
50 CSubPicAllocatorPresenterImpl::~CSubPicAllocatorPresenterImpl()
54 STDMETHODIMP CSubPicAllocatorPresenterImpl::NonDelegatingQueryInterface(REFIID riid, void** ppv)
56 return
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);
70 /* SubPicDesc spd;
71 pSubPic->GetDesc(spd);
73 if(spd.w > 0 && spd.h > 0)
75 CRect r;
76 pSubPic->GetDirtyRect(r);
78 // FIXME
79 r.DeflateRect(1, 1);
81 CRect rDstText(
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);
103 return(VideoSize);
106 STDMETHODIMP_(void) CSubPicAllocatorPresenterImpl::SetPosition(RECT w, RECT v)
108 bool fWindowPosChanged = !!(m_WindowRect != w);
109 bool fWindowSizeChanged = !!(m_WindowRect.Size() != CRect(w).Size());
111 m_WindowRect = w;
113 bool fVideoRectChanged = !!(m_VideoRect != v);
115 m_VideoRect = v;
117 if(fWindowSizeChanged || fVideoRectChanged) {
118 if(m_pAllocator) {
119 m_pAllocator->SetCurSize(m_WindowRect.Size());
120 m_pAllocator->SetCurVidRect(m_VideoRect);
123 if(m_pSubPicQueue) {
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)
137 return;
139 m_rtNow = rtNow - m_rtSubtitleDelay;
141 if(m_pSubPicQueue) {
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()
158 return(m_fps);
161 STDMETHODIMP_(void) CSubPicAllocatorPresenterImpl::SetSubPicProvider(ISubPicProvider* pSubPicProvider)
163 m_SubPicProvider = pSubPicProvider;
165 if(m_pSubPicQueue) {
166 m_pSubPicQueue->SetSubPicProvider(pSubPicProvider);
170 STDMETHODIMP_(void) CSubPicAllocatorPresenterImpl::Invalidate(REFERENCE_TIME rtInvalidate)
172 if(m_pSubPicQueue) {
173 m_pSubPicQueue->Invalidate(rtInvalidate);
177 #include <math.h>
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;
193 v[i].x /= v[i].z*2;
194 v[i].y /= v[i].z*2;
195 v[i] += center;
199 STDMETHODIMP CSubPicAllocatorPresenterImpl::SetVideoAngle(Vector v, bool fRepaint)
201 m_xform = XForm(Ray(Vector(0, 0, 0), v), Vector(1, 1, 1), false);
202 if(fRepaint) {
203 Paint(true);
205 return S_OK;