Skip to content

Commit

Permalink
Move CropSource to WIN32Util
Browse files Browse the repository at this point in the history
  • Loading branch information
CrystalP authored and CrystalP committed Oct 5, 2011
1 parent d53cb41 commit a1c9d92
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 39 deletions.
4 changes: 2 additions & 2 deletions xbmc/cores/VideoRenderers/VideoShaders/WinVideoFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include <map>
#include "ConvolutionKernels.h"
#include "YUV2RGBShader.h"
#include "../WinRenderer.h"
#include "win32/WIN32Util.h"

CYUV2RGBMatrix::CYUV2RGBMatrix()
{
Expand Down Expand Up @@ -736,7 +736,7 @@ void CConvolutionShaderSeparable::PrepareParameters(unsigned int sourceWidth, un
// Alter rectangles the destination rectangle exceeds the intermediate target width when zooming and causes artifacts.
// Work on the parameters rather than the members to avoid disturbing the parameter change detection the next time the function is called
CRect tgtRect(0, 0, destWidth, destHeight);
CWinRenderer::CropSource(sourceRect, destRect, tgtRect);
CWIN32Util::CropSource(sourceRect, destRect, tgtRect);

// Manipulate the coordinates to work only on the active parts of the textures,
// and therefore avoid the need to clear surfaces/render targets
Expand Down
36 changes: 2 additions & 34 deletions xbmc/cores/VideoRenderers/WinRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "DllSwScale.h"
#include "guilib/LocalizeStrings.h"
#include "dialogs/GUIDialogKaiToast.h"
#include "win32/WIN32Util.h"

typedef struct {
RenderMethod method;
Expand Down Expand Up @@ -634,39 +635,6 @@ void CWinRenderer::UpdateVideoFilter()
}
}

// Adjust the src rectangle so that the dst is always contained in the target rectangle.
void CWinRenderer::CropSource(CRect& src, CRect& dst, CRect target)
{
if(dst.x1 < target.x1)
{
src.x1 -= (dst.x1 - target.x1)
* (src.x2 - src.x1)
/ (dst.x2 - dst.x1);
dst.x1 = target.x1;
}
if(dst.y1 < target.y1)
{
src.y1 -= (dst.y1 - target.y1)
* (src.y2 - src.y1)
/ (dst.y2 - dst.y1);
dst.y1 = target.y1;
}
if(dst.x2 > target.x2)
{
src.x2 -= (dst.x2 - target.x2)
* (src.x2 - src.x1)
/ (dst.x2 - dst.x1);
dst.x2 = target.x2;
}
if(dst.y2 > target.y2)
{
src.y2 -= (dst.y2 - target.y2)
* (src.y2 - src.y1)
/ (dst.y2 - dst.y1);
dst.y2 = target.y2;
}
}

void CWinRenderer::Render(DWORD flags)
{
if (m_renderMethod == RENDER_DXVA)
Expand Down Expand Up @@ -779,7 +747,7 @@ void CWinRenderer::ScaleStretchRect()
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);
CWIN32Util::CropSource(sourceRect, destRect, tgtRect);
RECT srcRect = { sourceRect.x1, sourceRect.y1, sourceRect.x2, sourceRect.y2 };
IDirect3DSurface9* source;
Expand Down
2 changes: 0 additions & 2 deletions xbmc/cores/VideoRenderers/WinRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,6 @@ class CWinRenderer : public CBaseRenderer

virtual unsigned int GetProcessorSize() { return m_processor.Size(); }

static void CropSource(CRect& src, CRect& dst, CRect target);

protected:
virtual void Render(DWORD flags);
void RenderSW();
Expand Down
3 changes: 2 additions & 1 deletion xbmc/cores/dvdplayer/DVDCodecs/Video/DXVA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "utils/AutoPtrHandle.h"
#include "settings/AdvancedSettings.h"
#include "cores/VideoRenderers/RenderManager.h"
#include "win32/WIN32Util.h"

#define ALLOW_ADDING_SURFACES 0

Expand Down Expand Up @@ -1440,7 +1441,7 @@ bool CProcessor::Render(CRect src, CRect dst, IDirect3DSurface9* target, REFEREN
D3DSURFACE_DESC desc;
CHECK(target->GetDesc(&desc));
CRect rectTarget(0, 0, desc.Width, desc.Height);
CWinRenderer::CropSource(src, dst, rectTarget);
CWIN32Util::CropSource(src, dst, rectTarget);
RECT sourceRECT = { src.x1, src.y1, src.x2, src.y2 };
RECT dstRECT = { dst.x1, dst.y1, dst.x2, dst.y2 };

Expand Down
33 changes: 33 additions & 0 deletions xbmc/win32/WIN32Util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,6 +1421,39 @@ bool CWIN32Util::GetFocussedProcess(CStdString &strProcessFile)
return true;
}

// Adjust the src rectangle so that the dst is always contained in the target rectangle.
void CWIN32Util::CropSource(CRect& src, CRect& dst, CRect target)
{
if(dst.x1 < target.x1)
{
src.x1 -= (dst.x1 - target.x1)
* (src.x2 - src.x1)
/ (dst.x2 - dst.x1);
dst.x1 = target.x1;
}
if(dst.y1 < target.y1)
{
src.y1 -= (dst.y1 - target.y1)
* (src.y2 - src.y1)
/ (dst.y2 - dst.y1);
dst.y1 = target.y1;
}
if(dst.x2 > target.x2)
{
src.x2 -= (dst.x2 - target.x2)
* (src.x2 - src.x1)
/ (dst.x2 - dst.x1);
dst.x2 = target.x2;
}
if(dst.y2 > target.y2)
{
src.y2 -= (dst.y2 - target.y2)
* (src.y2 - src.y1)
/ (dst.y2 - dst.y1);
dst.y2 = target.y2;
}
}

void CWinIdleTimer::StartZero()
{
SetThreadExecutionState(ES_SYSTEM_REQUIRED);
Expand Down
2 changes: 2 additions & 0 deletions xbmc/win32/WIN32Util.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#endif
#include "MediaSource.h"
#include "utils/Stopwatch.h"
#include "guilib/Geometry.h"

enum Drive_Types
{
Expand Down Expand Up @@ -80,6 +81,7 @@ class CWIN32Util
static bool GetCrystalHDLibraryPath(CStdString &strPath);

static bool GetFocussedProcess(CStdString &strProcessFile);
static void CropSource(CRect& src, CRect& dst, CRect target);

private:
#if _MSC_VER > 1400
Expand Down

0 comments on commit a1c9d92

Please sign in to comment.