Repository: xbmc/xbmc
File: xbmc/cores/RetroPlayer/shaders/ShaderPreset.cpp (C++)

Code before:
  if (m_pShaders.empty())
    return false;

  // Each pass except the last one must have its own texture and the opposite is also true
  if (m_pShaders.size() != m_pShaderTextures.size() + 1)
    return updateFailed("A shader or texture failed to init");

  m_bPresetNeedsUpdate = false;
  return true;
}

void CShaderPreset::UpdateViewPort()
{
  CRect viewPort;
  m_context.GetViewPort(viewPort);
  UpdateViewPort(viewPort);
}

void CShaderPreset::UpdateViewPort(CRect viewPort)
{
  const float2 currentViewPortSize = {viewPort.Width(), viewPort.Height()};
  if (currentViewPortSize != m_outputSize)
  {
    m_outputSize = currentViewPortSize;
    m_bPresetNeedsUpdate = true;
    Update();
  }
}

void CShaderPreset::UpdateMVPs()
{
  for (std::unique_ptr<IShader>& videoShader : m_pShaders)
    videoShader->UpdateMVP();
}

void CShaderPreset::PrepareParameters(const CPoint dest[],
                                      IShaderTexture& source,
                                      IShaderTexture& target)
{
  if (m_dest[0] != dest[0] || m_dest[1] != dest[1] || m_dest[2] != dest[2] ||
      m_dest[3] != dest[3] || target.GetWidth() != m_outputSize.x ||
      target.GetHeight() != m_outputSize.y)
  {
    for (size_t i = 0; i < 4; ++i)
      m_dest[i] = dest[i];

    m_outputSize = {target.GetWidth(), target.GetHeight()};

    // Update projection matrix and update video shaders
    UpdateMVPs();
    UpdateViewPort();

Review comment (bug):
I have removed this, because it is not needed here, it is going to be updated directly from the _RenderUpdate()_. Also, the _Update()_ can fail here, but the return value is not handled.

Code after:
  if (m_pShaders.empty())
    return false;

  // Each pass except the last one must have its own texture and the opposite is also true
  if (m_pShaders.size() != m_pShaderTextures.size() + 1)
    return updateFailed("A shader or texture failed to init");

  m_bPresetNeedsUpdate = false;
  return true;
}

void CShaderPreset::UpdateViewPort(CRect viewPort)
{
  const float2 currentViewPortSize = {viewPort.Width(), viewPort.Height()};
  if (currentViewPortSize != m_outputSize)
  {
    m_outputSize = currentViewPortSize;
    m_bPresetNeedsUpdate = true;
  }
}

void CShaderPreset::UpdateMVPs()
{
  for (std::unique_ptr<IShader>& videoShader : m_pShaders)
    videoShader->UpdateMVP();
}

void CShaderPreset::PrepareParameters(const CPoint dest[],
                                      IShaderTexture& source,
                                      IShaderTexture& target)
{
  if (m_dest[0] != dest[0] || m_dest[1] != dest[1] || m_dest[2] != dest[2] || m_dest[3] != dest[3])
  {
    for (size_t i = 0; i < 4; ++i)
      m_dest[i] = dest[i];
  }

  const unsigned int numPasses = static_cast<unsigned int>(m_pShaders.size());

  // Prepare parameters for all shader passes
  for (unsigned int shaderIdx = 0; shaderIdx < numPasses; ++shaderIdx)
  {
    std::unique_ptr<IShader>& videoShader = m_pShaders[shaderIdx];
    videoShader->PrepareParameters(m_dest, source, m_pShaderTextures, m_pShaders,
                                   static_cast<uint64_t>(m_frameCount));
  }
}

void CShaderPreset::DisposeShaders()
{
  m_pShaders.clear();