[WinRenderer] Added support of rotated videos.
authorAnton Fedchin <afedchin@ruswizards.com>
Wed, 30 Dec 2015 13:55:12 +0000 (16:55 +0300)
committerAnton Fedchin <afedchin@ruswizards.com>
Wed, 30 Dec 2015 13:55:12 +0000 (16:55 +0300)
xbmc/cores/VideoRenderers/DXVAHD.cpp
xbmc/cores/VideoRenderers/DXVAHD.h
xbmc/cores/VideoRenderers/WinRenderer.cpp

index 470669c..472fdf0 100644 (file)
@@ -569,7 +569,7 @@ ID3D11VideoProcessorInputView* CProcessorHD::GetInputView(ID3D11View* view)
   return inputView;
 }
 
-bool CProcessorHD::Render(CRect src, CRect dst, ID3D11Resource* target, ID3D11View** views, DWORD flags, UINT frameIdx)
+bool CProcessorHD::Render(CRect src, CRect dst, ID3D11Resource* target, ID3D11View** views, DWORD flags, UINT frameIdx, UINT rotation)
 {
   HRESULT hr;
   CSingleLock lock(m_section);
@@ -714,6 +714,8 @@ bool CProcessorHD::Render(CRect src, CRect dst, ID3D11Resource* target, ID3D11Vi
                                              , 0, 100, 50);
   ApplyFilter(D3D11_VIDEO_PROCESSOR_FILTER_CONTRAST, CMediaSettings::GetInstance().GetCurrentVideoSettings().m_Contrast
                                              , 0, 100, 50);
+  // Rotation
+  m_pVideoContext->VideoProcessorSetStreamRotation(m_pVideoProcessor, DEFAULT_STREAM_INDEX, (rotation != 0), (D3D11_VIDEO_PROCESSOR_ROTATION)(rotation / 90));
 
   //
   // Create Output View of Output Surfaces.
index 154668f..802f96f 100644 (file)
@@ -51,7 +51,7 @@ public:
   virtual bool           Open(UINT width, UINT height, unsigned int flags, unsigned int format, unsigned int extended_format);
   virtual void           Close();
   virtual CRenderPicture *Convert(DVDVideoPicture* picture);
-  virtual bool           Render(CRect src, CRect dst, ID3D11Resource* target, ID3D11View **views, DWORD flags, UINT frameIdx);
+  virtual bool           Render(CRect src, CRect dst, ID3D11Resource* target, ID3D11View **views, DWORD flags, UINT frameIdx, UINT rotation);
   virtual unsigned       Size() { if (m_pVideoProcessor) return m_size; return 0; }
   virtual unsigned       PastRefs() { return m_max_back_refs; }
   virtual void           ApplySupportedFormats(std::vector<ERenderFormat> * formats);
index 2721189..4821b9b 100644 (file)
@@ -235,6 +235,7 @@ bool CWinRenderer::Configure(unsigned int width, unsigned int height, unsigned i
   m_iFlags = flags;
   m_format = format;
   m_extended_format = extended_format;
+  m_renderOrientation = orientation;
 
   // calculate the input frame aspect ratio
   CalculateFrameAspectRatio(d_width, d_height);
@@ -777,12 +778,12 @@ void CWinRenderer::ScaleGUIShader()
   unsigned int contrast   = (unsigned int)(CMediaSettings::GetInstance().GetCurrentVideoSettings().m_Contrast *.01f * 255.0f); // we have to divide by two here/multiply by two later
   unsigned int brightness = (unsigned int)(CMediaSettings::GetInstance().GetCurrentVideoSettings().m_Brightness * .01f * 255.0f);
 
-  CRect tu = { m_sourceRect.x1 / srcWidth, m_sourceRect.y1 / srcHeight, m_sourceRect.x2 / srcWidth, m_sourceRect.y2 / srcHeight };
-
   g_Windowing.GetGUIShader()->SetSampler(m_TextureFilter);
+  CRect tu = { m_sourceRect.x1 / srcWidth, m_sourceRect.y1 / srcHeight, m_sourceRect.x2 / srcWidth, m_sourceRect.y2 / srcHeight };
+  CRect destRect = CRect(m_rotatedDestCoords[0], m_rotatedDestCoords[2]);
 
   // pass contrast and brightness as diffuse color elements (see shader code)
-  CD3DTexture::DrawQuad(m_destRect, D3DCOLOR_ARGB(255, contrast, brightness, 255), &m_SWTarget, &tu,
+  CD3DTexture::DrawQuad(destRect, D3DCOLOR_ARGB(255, contrast, brightness, 255), &m_SWTarget, &tu,
                        !cbcontrol ? SHADER_METHOD_RENDER_VIDEO : SHADER_METHOD_RENDER_VIDEO_CONTROL);
 }
 
@@ -811,7 +812,32 @@ void CWinRenderer::Stage1()
   ID3D11RenderTargetView *oldRTView = nullptr; ID3D11DepthStencilView* oldDSView = nullptr;
   pContext->OMGetRenderTargets(1, &oldRTView, &oldDSView);
   // select destination rectangle 
-  CRect destRect = m_bUseHQScaler ? m_sourceRect : g_graphicsContext.StereoCorrection(m_destRect);
+  CRect destRect;
+  if (m_bUseHQScaler)
+  {
+    if (m_renderOrientation > 0)
+    {
+      // we need to rotate source coordinates for HQ scaller 
+      // so we using ReorderDrawPoints with source coords.
+
+      // save coords
+      CRect oldDest = m_destRect;
+      saveRotatedCoords();
+
+      m_destRect = m_sourceRect;
+      ReorderDrawPoints();
+      // get rotated coords
+      destRect = CRect(m_rotatedDestCoords[0], m_rotatedDestCoords[2]);
+
+      // restore coords
+      restoreRotatedCoords();
+      m_destRect = oldDest;
+    }
+    else
+      destRect = m_sourceRect;
+  }
+  else
+    destRect = g_graphicsContext.StereoCorrection(CRect(m_rotatedDestCoords[0], m_rotatedDestCoords[2]));
   // select target view 
   ID3D11RenderTargetView* pRTView = m_bUseHQScaler ? m_IntermediateTarget.GetRenderTarget() : oldRTView;
   // change destination for HQ scallers
@@ -909,7 +935,7 @@ void CWinRenderer::RenderProcessor(DWORD flags)
       break;
   }
 
-  m_processor->Render(m_sourceRect, destRect, m_IntermediateTarget.Get(), views, flags, image->frameIdx);
+  m_processor->Render(m_sourceRect, destRect, m_IntermediateTarget.Get(), views, flags, image->frameIdx, m_renderOrientation);
   
   if (m_bUseHQScaler)
   {
@@ -1046,6 +1072,7 @@ bool CWinRenderer::Supports(ERENDERFEATURE feature)
       feature == RENDERFEATURE_ZOOM            ||
       feature == RENDERFEATURE_VERTICAL_SHIFT  ||
       feature == RENDERFEATURE_PIXEL_RATIO     ||
+      feature == RENDERFEATURE_ROTATION        ||
       feature == RENDERFEATURE_POSTPROCESS)
     return true;