Repository: xbmc/xbmc
File: xbmc/windowing/gbm/DRMAtomic.cpp (C++)

Code before:
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "DRMAtomic.h"

#include "ServiceBroker.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "utils/log.h"

#include <errno.h>
#include <string.h>

#include <drm_fourcc.h>
#include <drm_mode.h>
#include <unistd.h>

using namespace KODI::WINDOWING::GBM;
bool CDRMAtomic::SetScalingFilter(struct drm_object *object, const char *name, const char *type) {
  uint32_t w_scale_factor;
  uint32_t h_scale_factor;
  for (uint32_t i = 0; i < object->props->count_props; i++)
      if (!strcmp(object->props_info[i]->name, name))
         for (int j = 0; j < object->props_info[i]->count_enums; j++)
             if (!strcmp(object->props_info[i]->enums[j].name, type)){
                if (AddProperty(object, name, m_gui_plane->props_info[i]->enums[j].value)){
                   CLog::Log(LOGINFO, "CDRMAtomic::%s, m_width[%d] x m_height[%d]", __FUNCTION__,m_width, m_height);
                   w_scale_factor = m_mode->hdisplay / m_width;
                   h_scale_factor =  m_mode->vdisplay / m_height;
                   AddProperty(object, "CRTC_W", (w_scale_factor * m_width));
                   AddProperty(object, "CRTC_H", (h_scale_factor * m_height));
                   return true;
                }
             }
  return false;
}

void CDRMAtomic::DrmAtomicCommit(int fb_id, int flags, bool rendered, bool videoLayer)
{
  uint32_t blob_id;

  if (flags & DRM_MODE_ATOMIC_ALLOW_MODESET)
  {
    if (!AddProperty(m_connector, "CRTC_ID", m_crtc->crtc->crtc_id))
    {
      return;
    }


Review comment (suggestion):
please use `CDRMUtils::SupportsProperty`. You may also want to use `CDRMUtils::SupportsPropertyAndValue`

Code after:
 *  SPDX-License-Identifier: GPL-2.0-or-later
 *  See LICENSES/README.md for more information.
 */

#include "DRMAtomic.h"

#include "ServiceBroker.h"
#include "guilib/GUIComponent.h"
#include "guilib/GUIWindowManager.h"
#include "settings/Settings.h"
#include "settings/SettingsComponent.h"
#include "settings/lib/Setting.h"
#include "utils/log.h"

#include <errno.h>
#include <string.h>

#include <drm_fourcc.h>
#include <drm_mode.h>
#include <unistd.h>

using namespace KODI::WINDOWING::GBM;

const std::string CDRMAtomic::SETTING_VIDEOSCREEN_HW_SCALING_FILTER = "videoscreen.hwscalingfilter";

enum drm_scaling_filter
{
  DRM_SCALING_FILTER_DEFAULT,
  DRM_SCALING_FILTER_NEAREST_NEIGHBOR,
};

uint32_t CDRMAtomic::GetScalingFilterType(const char* type)
{
  if (!strcmp(type, "Nearest Neighbor"))
    return DRM_SCALING_FILTER_NEAREST_NEIGHBOR;
  else
    return DRM_SCALING_FILTER_DEFAULT;
}

uint32_t CDRMAtomic::GetScalingFactor(uint32_t srcWidth,
                                      uint32_t srcHeight,
                                      uint32_t destWidth,
                                      uint32_t destHeight)
{
  uint32_t factor_W = destWidth / srcWidth;
  uint32_t factor_H = destHeight / srcHeight;
  if (factor_W != factor_H)
    return (factor_W < factor_H) ? factor_W : factor_H;
  return factor_W;
}