Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add headless modesetting for linux gbm #14125

Merged
merged 1 commit into from
Jul 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions xbmc/windowing/gbm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@ set(SOURCES OptionalsReg.cpp
GBMUtils.cpp
DRMUtils.cpp
DRMLegacy.cpp
DRMAtomic.cpp)
DRMAtomic.cpp
OffScreenModeSetting.cpp)

set(HEADERS OptionalsReg.h
WinSystemGbm.h
GBMUtils.h
DRMUtils.h
DRMLegacy.h
DRMAtomic.h)
DRMAtomic.h
OffScreenModeSetting.h)

if(OPENGLES_FOUND)
list(APPEND SOURCES WinSystemGbmGLESContext.cpp)
Expand Down
2 changes: 1 addition & 1 deletion xbmc/windowing/gbm/DRMAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ void CDRMAtomic::FlipPage(struct gbm_bo *bo, bool rendered, bool videoLayer)

bool CDRMAtomic::InitDrm()
{
if (!CDRMUtils::OpenDrm())
if (!CDRMUtils::OpenDrm(true))
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion xbmc/windowing/gbm/DRMLegacy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ void CDRMLegacy::FlipPage(struct gbm_bo *bo, bool rendered, bool videoLayer)

bool CDRMLegacy::InitDrm()
{
if (!CDRMUtils::OpenDrm())
if (!CDRMUtils::OpenDrm(true))
{
return false;
}
Expand Down
21 changes: 14 additions & 7 deletions xbmc/windowing/gbm/DRMUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ bool CDRMUtils::FindPlanes()
return true;
}

bool CDRMUtils::OpenDrm()
bool CDRMUtils::OpenDrm(bool needConnector)
{
static constexpr const char *modules[] =
{
Expand Down Expand Up @@ -450,21 +450,28 @@ bool CDRMUtils::OpenDrm()
{
if(!GetResources())
{
drmClose(m_fd);
m_fd = -1;
continue;
}

if(!FindConnector())
if (needConnector)
{
continue;
if(!FindConnector())
{
drmClose(m_fd);
m_fd = -1;
continue;
}

drmModeFreeConnector(m_connector->connector);
m_connector->connector = nullptr;
FreeProperties(m_connector);
}

drmModeFreeResources(m_drm_resources);
m_drm_resources = nullptr;

drmModeFreeConnector(m_connector->connector);
m_connector->connector = nullptr;
FreeProperties(m_connector);

m_module = module;
m_device_path = device;

Expand Down
10 changes: 5 additions & 5 deletions xbmc/windowing/gbm/DRMUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,16 @@ class CDRMUtils
struct plane* GetOverlayPlane() const { return m_overlay_plane; }
struct crtc* GetCrtc() const { return m_crtc; }

RESOLUTION_INFO GetCurrentMode();
std::vector<RESOLUTION_INFO> GetModes();
bool SetMode(const RESOLUTION_INFO& res);
void WaitVBlank();
virtual RESOLUTION_INFO GetCurrentMode();
virtual std::vector<RESOLUTION_INFO> GetModes();
virtual bool SetMode(const RESOLUTION_INFO& res);
virtual void WaitVBlank();

virtual bool AddProperty(struct drm_object *object, const char *name, uint64_t value) { return false; }
virtual bool SetProperty(struct drm_object *object, const char *name, uint64_t value) { return false; }

protected:
bool OpenDrm();
bool OpenDrm(bool needConnector);
uint32_t GetPropertyId(struct drm_object *object, const char *name);
drm_fb* DrmFbGetFromBo(struct gbm_bo *bo);

Expand Down
42 changes: 42 additions & 0 deletions xbmc/windowing/gbm/OffScreenModeSetting.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#include "OffScreenModeSetting.h"

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

#include "utils/log.h"

bool COffScreenModeSetting::InitDrm()
{
if (!CDRMUtils::OpenDrm(false))
{
return false;
}

CLog::Log(LOGDEBUG, "COffScreenModeSetting::%s - initialized offscreen DRM", __FUNCTION__);
return true;
}

void COffScreenModeSetting::DestroyDrm()
{
close(m_fd);
m_fd = -1;
}

std::vector<RESOLUTION_INFO> COffScreenModeSetting::GetModes()
{
std::vector<RESOLUTION_INFO> resolutions;
resolutions.push_back(GetCurrentMode());
return resolutions;
}

RESOLUTION_INFO COffScreenModeSetting::GetCurrentMode()
{
RESOLUTION_INFO res;
res.iScreenWidth = DISPLAY_WIDTH;
res.iWidth = DISPLAY_WIDTH;
res.iScreenHeight = DISPLAY_HEIGHT;
res.iHeight = DISPLAY_HEIGHT;
res.fRefreshRate = DISPLAY_REFRESH;
res.iSubtitles = static_cast<int>(0.965 * res.iHeight);
res.fPixelRatio = 1.0f;
res.bFullScreen = true;
res.strId = "0";

return res;
}
49 changes: 49 additions & 0 deletions xbmc/windowing/gbm/OffScreenModeSetting.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright (C) 2005-2018 Team XBMC
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#pragma once

#include "DRMUtils.h"

#ifdef TARGET_POSIX
#include "platform/linux/XTimeUtils.h"
#endif

class COffScreenModeSetting : public CDRMUtils
{
public:
COffScreenModeSetting() = default;
~COffScreenModeSetting() { DestroyDrm(); };
void FlipPage(struct gbm_bo *bo, bool rendered, bool videoLayer) override {}
bool SetVideoMode(const RESOLUTION_INFO& res, struct gbm_bo *bo) override { return false; }
bool SetActive(bool active) override { return false; }
bool InitDrm() override;
void DestroyDrm() override;

RESOLUTION_INFO GetCurrentMode() override;
std::vector<RESOLUTION_INFO> GetModes() override;
bool SetMode(const RESOLUTION_INFO& res) override { return true; }
void WaitVBlank() override { Sleep(20); }

private:
const int DISPLAY_WIDTH = 1280;
const int DISPLAY_HEIGHT= 720;
const float DISPLAY_REFRESH = 50.0f;
};
10 changes: 9 additions & 1 deletion xbmc/windowing/gbm/WinSystemGbm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include "utils/StringUtils.h"
#include "DRMAtomic.h"
#include "DRMLegacy.h"
#include "OffScreenModeSetting.h"
#include "messaging/ApplicationMessenger.h"


Expand Down Expand Up @@ -95,7 +96,14 @@ bool CWinSystemGbm::InitWindowSystem()
{
CLog::Log(LOGERROR, "CWinSystemGbm::%s - failed to initialize Legacy DRM", __FUNCTION__);
m_DRM.reset();
return false;

m_DRM = std::make_shared<COffScreenModeSetting>();
if (!m_DRM->InitDrm())
{
CLog::Log(LOGERROR, "CWinSystemGbm::%s - failed to initialize off screen DRM", __FUNCTION__);
m_DRM.reset();
return false;
}
}
}

Expand Down