Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Change CropSource to take CRect arguments: multiplatform and float fo…

…r better accuracy on the calculations
  • Loading branch information...
commit 55a903c6eac1c97c06153deb34faed47b8c23195 1 parent 4f2c641
@CrystalP CrystalP authored
View
69 xbmc/cores/VideoRenderers/WinRenderer.cpp
@@ -635,35 +635,35 @@ void CWinRenderer::UpdateVideoFilter()
}
// Adjust the src rectangle so that the dst is always contained in the target rectangle.
-void CWinRenderer::CropSource(RECT& src, RECT& dst, RECT target)
+void CWinRenderer::CropSource(CRect& src, CRect& dst, CRect target)
{
- if(dst.left < target.left)
+ if(dst.x1 < target.x1)
{
- src.left -= (dst.left - target.left)
- * (src.right - src.left)
- / (dst.right - dst.left);
- dst.left = target.left;
+ src.x1 -= (dst.x1 - target.x1)
+ * (src.x2 - src.x1)
+ / (dst.x2 - dst.x1);
+ dst.x1 = target.x1;
}
- if(dst.top < target.top)
+ if(dst.y1 < target.y1)
{
- src.top -= (dst.top - target.top)
- * (src.bottom - src.top)
- / (dst.bottom - dst.top);
- dst.top = target.top;
+ src.y1 -= (dst.y1 - target.y1)
+ * (src.y2 - src.y1)
+ / (dst.y2 - dst.y1);
+ dst.y1 = target.y1;
}
- if(dst.right > target.right)
+ if(dst.x2 > target.x2)
{
- src.right -= (dst.right - target.right)
- * (src.right - src.left)
- / (dst.right - dst.left);
- dst.right = target.right;
+ src.x2 -= (dst.x2 - target.x2)
+ * (src.x2 - src.x1)
+ / (dst.x2 - dst.x1);
+ dst.x2 = target.x2;
}
- if(dst.bottom > target.bottom)
+ if(dst.y2 > target.y2)
{
- src.bottom -= (dst.bottom - target.bottom)
- * (src.bottom - src.top)
- / (dst.bottom - dst.top);
- dst.bottom = target.bottom;
+ src.y2 -= (dst.y2 - target.y2)
+ * (src.y2 - src.y1)
+ / (dst.y2 - dst.y1);
+ dst.y2 = target.y2;
}
}
@@ -770,24 +770,27 @@ void CWinRenderer::ScaleStretchRect()
// m_StretchRectSupported = true;
//}
- RECT srcRect = { m_sourceRect.x1, m_sourceRect.y1, m_sourceRect.x2, m_sourceRect.y2 };
+ CRect sourceRect = m_sourceRect;
+ CRect destRect = m_destRect;
+
+ D3DSURFACE_DESC desc;
+ if (FAILED(target->GetDesc(&desc)))
+ CLog::Log(LOGERROR, "CWinRenderer::Render - failed to get back buffer description");
+ CRect tgtRect(0, 0, desc.Width, desc.Height);
+
+ // Need to manipulate the coordinates since StretchRect doesn't accept off-screen coordinates.
+ CropSource(sourceRect, destRect, tgtRect);
+
+ RECT srcRect = { sourceRect.x1, sourceRect.y1, sourceRect.x2, sourceRect.y2 };
IDirect3DSurface9* source;
if(!m_SWTarget.GetSurfaceLevel(0, &source))
CLog::Log(LOGERROR, "CWinRenderer::Render - failed to get source");
- RECT dstRect = { m_destRect.x1, m_destRect.y1, m_destRect.x2, m_destRect.y2 };
+ RECT dstRect = { destRect.x1, destRect.y1, destRect.x2, destRect.y2 };
IDirect3DSurface9* target;
if(FAILED(g_Windowing.Get3DDevice()->GetRenderTarget(0, &target)))
CLog::Log(LOGERROR, "CWinRenderer::Render - failed to get back buffer");
- D3DSURFACE_DESC desc;
- if (FAILED(target->GetDesc(&desc)))
- CLog::Log(LOGERROR, "CWinRenderer::Render - failed to get back buffer description");
- RECT tgtRect = { 0, 0, desc.Width, desc.Height };
-
- // Need to manipulate the coordinates since StretchRect doesn't accept off-screen coordinates.
- CropSource(srcRect, dstRect, tgtRect);
-
HRESULT hr;
LPDIRECT3DDEVICE9 pD3DDevice = g_Windowing.Get3DDevice();
@@ -949,8 +952,6 @@ void CWinRenderer::RenderProcessor(DWORD flags)
{
CSingleLock lock(g_graphicsContext);
HRESULT hr;
- RECT sourceRect = { m_sourceRect.x1, m_sourceRect.y1, m_sourceRect.x2, m_sourceRect.y2 };
- RECT destRect = { m_destRect.x1, m_destRect.y1, m_destRect.x2, m_destRect.y2 };
DXVABuffer *image = (DXVABuffer*)m_VideoBuffers[m_iYV12RenderBuffer];
@@ -961,7 +962,7 @@ void CWinRenderer::RenderProcessor(DWORD flags)
return;
}
- m_processor.Render(sourceRect, destRect, target, image->id, flags);
+ m_processor.Render(m_sourceRect, m_destRect, target, image->id, flags);
target->Release();
}
View
2  xbmc/cores/VideoRenderers/WinRenderer.h
@@ -192,7 +192,7 @@ class CWinRenderer : public CBaseRenderer
virtual unsigned int GetProcessorSize() { return m_processor.Size(); }
- static void CropSource(RECT& src, RECT& dst, RECT target);
+ static void CropSource(CRect& src, CRect& dst, CRect target);
protected:
virtual void Render(DWORD flags);
View
15 xbmc/cores/dvdplayer/DVDCodecs/Video/DXVA.cpp
@@ -1395,7 +1395,7 @@ static DXVA2_Fixed32 ConvertRange(const DXVA2_ValueRange& range, int value, int
return range.DefaultValue;
}
-bool CProcessor::Render(RECT src, RECT dst, IDirect3DSurface9* target, REFERENCE_TIME time, DWORD flags)
+bool CProcessor::Render(CRect src, CRect dst, IDirect3DSurface9* target, REFERENCE_TIME time, DWORD flags)
{
CSingleLock lock(m_section);
@@ -1439,8 +1439,11 @@ bool CProcessor::Render(RECT src, RECT dst, IDirect3DSurface9* target, REFERENCE
D3DSURFACE_DESC desc;
CHECK(target->GetDesc(&desc));
- RECT recttarget = { 0, 0, desc.Width, desc.Height };
- CWinRenderer::CropSource(src, dst, recttarget);
+ CRect rectTarget(0, 0, desc.Width, desc.Height);
+ CWinRenderer::CropSource(src, dst, rectTarget);
+ RECT sourceRECT = { src.x1, src.y1, src.x2, src.y2 };
+ RECT dstRECT = { dst.x1, dst.y1, dst.x2, dst.y2 };
+
// How to prepare the samples array for VideoProcessBlt
// - always provide current picture + the number of forward and backward references required by the current processor.
@@ -1460,8 +1463,8 @@ bool CProcessor::Render(RECT src, RECT dst, IDirect3DSurface9* target, REFERENCE
{
DXVA2_VideoSample& vs = samp[(it->sample.Start - MinTime) / 2];
vs = it->sample;
- vs.SrcRect = src;
- vs.DstRect = dst;
+ vs.SrcRect = sourceRECT;
+ vs.DstRect = dstRECT;
if(vs.End == 0)
vs.End = vs.Start + 2;
@@ -1500,7 +1503,7 @@ bool CProcessor::Render(RECT src, RECT dst, IDirect3DSurface9* target, REFERENCE
blt.TargetFrame = time;
if (flags & RENDER_FLAG_FIELD1)
blt.TargetFrame += 1;
- blt.TargetRect = dst;
+ blt.TargetRect = dstRECT;
blt.ConstrictionSize.cx = 0;
blt.ConstrictionSize.cy = 0;
View
3  xbmc/cores/dvdplayer/DVDCodecs/Video/DXVA.h
@@ -29,6 +29,7 @@
#include <deque>
#include <vector>
#include "settings/VideoSettings.h"
+#include "guilib/Geometry.h"
namespace DXVA {
@@ -123,7 +124,7 @@ class CProcessor
bool Open(UINT width, UINT height, unsigned int flags, unsigned int format);
void Close();
REFERENCE_TIME Add(DVDVideoPicture* picture);
- bool Render(RECT src, RECT dst, IDirect3DSurface9* target, const REFERENCE_TIME time, DWORD flags);
+ bool Render(CRect src, CRect dst, IDirect3DSurface9* target, const REFERENCE_TIME time, DWORD flags);
unsigned Size() { if (m_service) return m_size; return 0; }
virtual void OnCreateDevice() {}
Please sign in to comment.
Something went wrong with that request. Please try again.