/
SubPicImpl.cpp
266 lines (215 loc) · 6.24 KB
/
SubPicImpl.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
/*
* $Id: SubPicImpl.cpp 2786 2010-12-17 16:42:55Z XhmikosR $
*
* (C) 2003-2006 Gabest
* (C) 2006-2010 see AUTHORS
*
* This Program 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, or (at your option)
* any later version.
*
* This Program 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 GNU Make; see the file COPYING. If not, write to
* the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
* http://www.gnu.org/copyleft/gpl.html
*
*/
#include "stdafx.h"
#include "SubPicImpl.h"
#include "../DSUtil/DSUtil.h"
//
// CSubPicImpl
//
CSubPicImpl::CSubPicImpl()
: CUnknown(NAME("CSubPicImpl"), NULL)
, m_rtStart(0), m_rtStop(0)
, m_rtSegmentStart(0), m_rtSegmentStop(0)
, m_rcDirty(0, 0, 0, 0), m_maxsize(0, 0), m_size(0, 0), m_vidrect(0, 0, 0, 0)
, m_VirtualTextureSize(0, 0), m_VirtualTextureTopLeft (0, 0)
{
}
STDMETHODIMP CSubPicImpl::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
return
QI(ISubPic)
__super::NonDelegatingQueryInterface(riid, ppv);
}
// ISubPic
STDMETHODIMP_(REFERENCE_TIME) CSubPicImpl::GetStart()
{
return(m_rtStart);
}
STDMETHODIMP_(REFERENCE_TIME) CSubPicImpl::GetStop()
{
return(m_rtStop);
}
STDMETHODIMP_(REFERENCE_TIME) CSubPicImpl::GetSegmentStart()
{
if (m_rtSegmentStart) {
return(m_rtSegmentStart);
}
return(m_rtStart);
}
STDMETHODIMP_(REFERENCE_TIME) CSubPicImpl::GetSegmentStop()
{
if (m_rtSegmentStop) {
return(m_rtSegmentStop);
}
return(m_rtStop);
}
STDMETHODIMP_(void) CSubPicImpl::SetSegmentStart(REFERENCE_TIME rtStart)
{
m_rtSegmentStart = rtStart;
}
STDMETHODIMP_(void) CSubPicImpl::SetSegmentStop(REFERENCE_TIME rtStop)
{
m_rtSegmentStop = rtStop;
}
STDMETHODIMP_(void) CSubPicImpl::SetStart(REFERENCE_TIME rtStart)
{
m_rtStart = rtStart;
}
STDMETHODIMP_(void) CSubPicImpl::SetStop(REFERENCE_TIME rtStop)
{
m_rtStop = rtStop;
}
STDMETHODIMP CSubPicImpl::CopyTo(ISubPic* pSubPic)
{
if(!pSubPic) {
return E_POINTER;
}
pSubPic->SetStart(m_rtStart);
pSubPic->SetStop(m_rtStop);
pSubPic->SetSegmentStart(m_rtSegmentStart);
pSubPic->SetSegmentStop(m_rtSegmentStop);
pSubPic->SetDirtyRect(m_rcDirty);
pSubPic->SetSize(m_size, m_vidrect);
pSubPic->SetVirtualTextureSize(m_VirtualTextureSize, m_VirtualTextureTopLeft);
return S_OK;
}
STDMETHODIMP CSubPicImpl::GetDirtyRect(RECT* pDirtyRect)
{
return pDirtyRect ? *pDirtyRect = m_rcDirty, S_OK : E_POINTER;
}
STDMETHODIMP CSubPicImpl::GetSourceAndDest(SIZE* pSize, RECT* pRcSource, RECT* pRcDest)
{
CheckPointer (pRcSource, E_POINTER);
CheckPointer (pRcDest, E_POINTER);
if(m_size.cx > 0 && m_size.cy > 0) {
CRect rcTemp = m_rcDirty;
// FIXME
rcTemp.DeflateRect(1, 1);
*pRcSource = rcTemp;
rcTemp.OffsetRect (m_VirtualTextureTopLeft);
*pRcDest = CRect (rcTemp.left * pSize->cx / m_VirtualTextureSize.cx,
rcTemp.top * pSize->cy / m_VirtualTextureSize.cy,
rcTemp.right * pSize->cx / m_VirtualTextureSize.cx,
rcTemp.bottom * pSize->cy / m_VirtualTextureSize.cy);
return S_OK;
} else {
return E_INVALIDARG;
}
}
STDMETHODIMP CSubPicImpl::SetDirtyRect(RECT* pDirtyRect)
{
return pDirtyRect ? m_rcDirty = *pDirtyRect, S_OK : E_POINTER;
}
STDMETHODIMP CSubPicImpl::GetMaxSize(SIZE* pMaxSize)
{
return pMaxSize ? *pMaxSize = m_maxsize, S_OK : E_POINTER;
}
STDMETHODIMP CSubPicImpl::SetSize(SIZE size, RECT vidrect)
{
m_size = size;
m_vidrect = vidrect;
if(m_size.cx > m_maxsize.cx) {
m_size.cy = MulDiv(m_size.cy, m_maxsize.cx, m_size.cx);
m_size.cx = m_maxsize.cx;
}
if(m_size.cy > m_maxsize.cy) {
m_size.cx = MulDiv(m_size.cx, m_maxsize.cy, m_size.cy);
m_size.cy = m_maxsize.cy;
}
if(m_size.cx != size.cx || m_size.cy != size.cy) {
m_vidrect.top = MulDiv(m_vidrect.top, m_size.cx, size.cx);
m_vidrect.bottom = MulDiv(m_vidrect.bottom, m_size.cx, size.cx);
m_vidrect.left = MulDiv(m_vidrect.left, m_size.cy, size.cy);
m_vidrect.right = MulDiv(m_vidrect.right, m_size.cy, size.cy);
}
m_VirtualTextureSize = m_size;
return S_OK;
}
STDMETHODIMP CSubPicImpl::SetVirtualTextureSize (const SIZE pSize, const POINT pTopLeft)
{
m_VirtualTextureSize.SetSize (pSize.cx, pSize.cy);
m_VirtualTextureTopLeft.SetPoint (pTopLeft.x, pTopLeft.y);
return S_OK;
}
//
// ISubPicAllocatorImpl
//
CSubPicAllocatorImpl::CSubPicAllocatorImpl(SIZE cursize, bool fDynamicWriteOnly, bool fPow2Textures)
: CUnknown(NAME("ISubPicAllocatorImpl"), NULL)
, m_cursize(cursize)
, m_fDynamicWriteOnly(fDynamicWriteOnly)
, m_fPow2Textures(fPow2Textures)
{
m_curvidrect = CRect(CPoint(0,0), m_cursize);
}
STDMETHODIMP CSubPicAllocatorImpl::NonDelegatingQueryInterface(REFIID riid, void** ppv)
{
return
QI(ISubPicAllocator)
__super::NonDelegatingQueryInterface(riid, ppv);
}
// ISubPicAllocator
STDMETHODIMP CSubPicAllocatorImpl::SetCurSize(SIZE cursize)
{
m_cursize = cursize;
return S_OK;
}
STDMETHODIMP CSubPicAllocatorImpl::SetCurVidRect(RECT curvidrect)
{
m_curvidrect = curvidrect;
return S_OK;
}
STDMETHODIMP CSubPicAllocatorImpl::GetStatic(ISubPic** ppSubPic)
{
if(!ppSubPic) {
return E_POINTER;
}
if(!m_pStatic) {
if(!Alloc(true, &m_pStatic) || !m_pStatic) {
return E_OUTOFMEMORY;
}
}
m_pStatic->SetSize(m_cursize, m_curvidrect);
(*ppSubPic = m_pStatic)->AddRef();
return S_OK;
}
STDMETHODIMP CSubPicAllocatorImpl::AllocDynamic(ISubPic** ppSubPic)
{
if(!ppSubPic) {
return E_POINTER;
}
if(!Alloc(false, ppSubPic) || !*ppSubPic) {
return E_OUTOFMEMORY;
}
(*ppSubPic)->SetSize(m_cursize, m_curvidrect);
return S_OK;
}
STDMETHODIMP_(bool) CSubPicAllocatorImpl::IsDynamicWriteOnly()
{
return(m_fDynamicWriteOnly);
}
STDMETHODIMP CSubPicAllocatorImpl::ChangeDevice(IUnknown* pDev)
{
m_pStatic = NULL;
return S_OK;
}