[xiph-commits] r16964 - trunk/oggdsf/src/lib/plugin/AxPlayer
cristianadam at svn.xiph.org
cristianadam at svn.xiph.org
Thu Mar 11 15:28:35 PST 2010
Author: cristianadam
Date: 2010-03-11 15:28:34 -0800 (Thu, 11 Mar 2010)
New Revision: 16964
Modified:
trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.cpp
trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.h
trunk/oggdsf/src/lib/plugin/AxPlayer/VideoTagBehavior.cpp
trunk/oggdsf/src/lib/plugin/AxPlayer/VideoTagBehavior.h
Log:
Performance improvements regarding VMR9 usage.
Modified: trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.cpp
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.cpp 2010-03-11 07:41:42 UTC (rev 16963)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.cpp 2010-03-11 23:28:34 UTC (rev 16964)
@@ -58,10 +58,11 @@
{
try
{
- CHECK_HR(GetDevice()->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &m_backBuffer));
-
- D3DSURFACE_DESC backBufferDesc;
- CHECK_HR(m_backBuffer->GetDesc(&backBufferDesc));
+ D3DDISPLAYMODE displayMode = {};
+ CHECK_HR(m_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode));
+
+ CHECK_HR(GetDevice()->CreateRenderTarget(videoSize.cx, videoSize.cy, displayMode.Format,
+ D3DMULTISAMPLE_NONE, 0, FALSE, &m_backBuffer, 0));
}
catch (const CAtlException& /*except*/)
{
@@ -82,14 +83,13 @@
CHECK_HR(m_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode));
// CreateDevice fails on 0x0 windows;
- MoveWindow(0, 0, displayMode.Width, displayMode.Height, false);
+ MoveWindow(0, 0, 1, 1, false);
D3DPRESENT_PARAMETERS presentParameters = {};
presentParameters.Windowed = TRUE;
presentParameters.hDeviceWindow = m_hWnd;
- presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
+ presentParameters.SwapEffect = D3DSWAPEFFECT_COPY;
presentParameters.BackBufferFormat = displayMode.Format;
- presentParameters.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
CHECK_HR(m_d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, m_hWnd,
D3DCREATE_MULTITHREADED | D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presentParameters, &m_direct3dDevice));
@@ -120,6 +120,31 @@
return m_direct3dDevice;
}
+CComPtr<IDirect3DSurface9>& DShowVideoPlayer::GetScalingSurface(const CSize &aSize)
+{
+ if (m_scalingBuffer && aSize != m_scalingSize)
+ {
+ LOG(logDEBUG3) << __FUNCTIONW__ << " Releasing old scaling surface";
+
+ m_scalingBuffer = 0;
+ }
+
+ if (!m_scalingBuffer)
+ {
+ LOG(logDEBUG3) << __FUNCTIONW__ << " Creating new scaling surface";
+
+ D3DDISPLAYMODE displayMode = {};
+ CHECK_HR(m_d3d->GetAdapterDisplayMode(D3DADAPTER_DEFAULT, &displayMode));
+
+ CHECK_HR(GetDevice()->CreateRenderTarget(aSize.cx, aSize.cy, displayMode.Format,
+ D3DMULTISAMPLE_NONE, 0, TRUE, &m_scalingBuffer, 0));
+
+ m_scalingSize = aSize;
+ }
+
+ return m_scalingBuffer;
+}
+
HRESULT DShowVideoPlayer::Draw(RECT rcBounds, RECT rcUpdate, LONG lDrawFlags, HDC hdc, LPVOID pvDrawObject)
{
CRect rect(rcBounds);
@@ -129,9 +154,13 @@
{
if (m_backBuffer)
{
- HDC backBufferDC;
- CHECK_HR(m_backBuffer->GetDC(&backBufferDC));
+ // Use a third buffer to scale the picture
+ CComPtr<IDirect3DSurface9> scaledSurface = GetScalingSurface(CSize(rect.Width(), rect.Height()));
+ CHECK_HR(GetDevice()->StretchRect(m_backBuffer, 0, scaledSurface, 0, m_textureFilterType));
+ HDC scalingBufferDC;
+ CHECK_HR(m_scalingBuffer->GetDC(&scalingBufferDC));
+
// Do not paint when the current displayed line is passing
// our rect, when it does and we draw we get tearing.
for(; ;)
@@ -149,7 +178,7 @@
break;
}
- if (rasterStatus.ScanLine >= (DWORD)rect.top && rasterStatus.ScanLine <= (DWORD)rect.bottom)
+ if (rasterStatus.ScanLine >= (DWORD)rcUpdate.top && rasterStatus.ScanLine <= (DWORD)rcUpdate.bottom)
{
Sleep(1);
continue;
@@ -158,12 +187,9 @@
break;
}
- ::BitBlt(hdc, rect.left, rect.top, rect.Width(), rect.Height(), backBufferDC, 0, 0, SRCCOPY);
+ ::BitBlt(hdc, rect.left, rect.top, rect.Width(), rect.Height(), scalingBufferDC, 0, 0, SRCCOPY);
- CHECK_HR(m_backBuffer->ReleaseDC(backBufferDC));
-
- m_width = rect.Width();
- m_height = rect.Height();
+ CHECK_HR(m_scalingBuffer->ReleaseDC(scalingBufferDC));
}
}
catch (const CAtlException& except)
@@ -349,8 +375,7 @@
return 0;
}
- CRect displayRect(0, 0, m_width, m_height);
- HRESULT hr = GetDevice()->StretchRect(frame->lpSurf, 0, m_backBuffer, &displayRect, m_textureFilterType);
+ HRESULT hr = GetDevice()->StretchRect(frame->lpSurf, 0, m_backBuffer, 0, D3DTEXF_NONE);
LOG(logDEBUG2) << __FUNCTIONW__ << " Start: " << ReferenceTime(frame->rtStart)
<< " End: " << ReferenceTime(frame->rtEnd) << " StretchRect result: 0x" << std::hex << hr;
Modified: trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.h
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.h 2010-03-11 07:41:42 UTC (rev 16963)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/DShowVideoPlayer.h 2010-03-11 23:28:34 UTC (rev 16964)
@@ -111,6 +111,8 @@
CComPtr<IDirect3D9> m_d3d;
CComPtr<IDirect3DDevice9> m_direct3dDevice;
CComPtr<IDirect3DSurface9> m_backBuffer;
+ CComPtr<IDirect3DSurface9> m_scalingBuffer;
+ CSize m_scalingSize;
int m_width;
int m_height;
Modified: trunk/oggdsf/src/lib/plugin/AxPlayer/VideoTagBehavior.cpp
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/VideoTagBehavior.cpp 2010-03-11 07:41:42 UTC (rev 16963)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/VideoTagBehavior.cpp 2010-03-11 23:28:34 UTC (rev 16964)
@@ -59,6 +59,8 @@
m_sizeExtent.cx = 0;
m_sizeExtent.cy = 0;
+ m_bWindowOnly = TRUE;
+
LOG(logDEBUG) << this << ": " << __FUNCTIONW__;
}
@@ -293,7 +295,13 @@
HRESULT __stdcall VideoTagBehavior::OnEmbeddedDraw(RECT rect, HDC hdc)
{
- HRESULT hr = m_videoPlayer.Draw(rect, rect, 0, hdc, 0);
+ CRect windowRect(0, 0, m_width, m_height);
+ if (m_hWnd != 0)
+ {
+ GetWindowRect(&windowRect);
+ }
+
+ HRESULT hr = m_videoPlayer.Draw(rect, windowRect, 0, hdc, 0);
return hr;
}
@@ -302,11 +310,17 @@
// This is called only in Quirks mode
m_standardsMode = false;
- HRESULT hr = m_videoPlayer.Draw(rcBounds, rcUpdate, lDrawFlags, hdc, pvDrawObject);
+ CRect windowRect(0, 0, m_width, m_height);
+ if (m_hWnd != 0)
+ {
+ GetWindowRect(&windowRect);
+ }
+
+ HRESULT hr = m_videoPlayer.Draw(rcBounds, windowRect, lDrawFlags, hdc, pvDrawObject);
return hr;
}
-HRESULT VideoTagBehavior::OnDraw(ATL_DRAWINFO& di)
+HRESULT VideoTagBehavior::OnDrawAdvanced(ATL_DRAWINFO& di)
{
RECT& rc = *(RECT*)di.prcBounds;
@@ -754,4 +768,9 @@
m_height = m_desiredVideoSize.cy;
m_width = static_cast<unsigned long>(m_desiredVideoSize.cy * aspectRatio);
}
+}
+
+LRESULT VideoTagBehavior::OnEraseBkgnd( UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/ )
+{
+ return FALSE;
}
\ No newline at end of file
Modified: trunk/oggdsf/src/lib/plugin/AxPlayer/VideoTagBehavior.h
===================================================================
--- trunk/oggdsf/src/lib/plugin/AxPlayer/VideoTagBehavior.h 2010-03-11 07:41:42 UTC (rev 16963)
+++ trunk/oggdsf/src/lib/plugin/AxPlayer/VideoTagBehavior.h 2010-03-11 23:28:34 UTC (rev 16964)
@@ -100,7 +100,7 @@
DWORD dwStyle = 0, DWORD dwExStyle = 0,
_U_MENUorID MenuOrID = 0U, LPVOID lpCreateParam = NULL);
- HRESULT OnDraw(ATL_DRAWINFO& di);
+ HRESULT OnDrawAdvanced(ATL_DRAWINFO& di);
DECLARE_REGISTRY_RESOURCEID(IDR_VIDEOTAGBEHAVIOR)
@@ -142,6 +142,7 @@
BEGIN_MSG_MAP(VideoTagBehavior)
MESSAGE_HANDLER(WM_LBUTTONDOWN, OnLButtonDown)
+ MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
CHAIN_MSG_MAP(CComControl<VideoTagBehavior>)
DEFAULT_REFLECTION_HANDLER()
END_MSG_MAP()
@@ -200,6 +201,7 @@
// ActiveX Windows Events, received only by the embedded control
LRESULT OnLButtonDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/);
+ LRESULT OnEraseBkgnd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM lParam, BOOL& /*bHandled*/);
// IEmbeddedAxEventsSink
virtual HRESULT __stdcall OnLeftButtonDown(LONG x, LONG y);
More information about the commits
mailing list