-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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 a hardware backlight interface and gui controls #14970
base: master
Are you sure you want to change the base?
Conversation
I see you're entered the realm of the GUI :) Still time constrained so I can't offer much feedback than that, but good job. Cool feature! |
xbmc/GUIInfoManager.cpp
Outdated
@@ -1645,7 +1645,9 @@ const infomap system_labels[] = {{ "hasnetwork", SYSTEM_ETHERNET_LINK_ACT | |||
{ "stereoscopicmode", SYSTEM_STEREOSCOPIC_MODE }, | |||
{ "hascms", SYSTEM_HAS_CMS }, | |||
{ "privacypolicy", SYSTEM_PRIVACY_POLICY }, | |||
{ "haspvraddon", SYSTEM_HAS_PVR_ADDON }}; | |||
{ "haspvraddon", SYSTEM_HAS_PVR_ADDON }, | |||
{ "hasbacklight", SYSTEM_HAS_BACKLIGHT }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing doxygen entry at the top of the map like all the others
xbmc/utils/SysfsUtils.h
Outdated
static int SetInt(const std::string& path, const int val); | ||
static int GetInt(const std::string& path, int& val); | ||
static bool SetString(const std::string& path, const std::string& value); | ||
static const std::string GetString(const std::string& path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why you return const std::string
and not std::string
?
Same for the const int
below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1; never return const
} | ||
|
||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make sure to call closedir
after you finished.
xbmc/utils/IBacklight.h
Outdated
static void Register(std::shared_ptr<IBacklight> backlight) { CServiceBroker::RegisterBacklight(backlight); } | ||
|
||
virtual bool SetBrightness(int brightness) = 0; | ||
virtual int GetBrightness() = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While the implementation actually hasn't even a member for it, I'd still make this
virtual int GetBrightness() const = 0;
Same for other Getters.
Please make sure the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of minors, but at the very least you have to split the commits differently so that they follow logically and you can bisect.
👍 for changing the SysfsUtils interface :-)
xbmc/utils/AMLUtils.cpp
Outdated
{ | ||
if (SysfsUtils::GetString("/sys/class/amhdmitx/amhdmitx0/disp_cap", valstr) < 0) | ||
std::string valstr = SysfsUtils::GetString("/sys/class/amhdmitx/amhdmitx0/disp_cap"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable redeclaration (curious that you didn't get a warning at least)
xbmc/utils/AMLUtils.cpp
Outdated
return false; | ||
|
||
if (SysfsUtils::GetString("/sys/class/amhdmitx/amhdmitx0/vesa_cap", vesastr) == 0) | ||
std::string vesastr = SysfsUtils::GetString("/sys/class/amhdmitx/amhdmitx0/vesa_cap"); | ||
if (vesastr.length() > 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
100% unimportant, but out of curiosity: Why not !vesastr.empty()
? (considering the check 4 lines above)
xbmc/utils/SysfsUtils.cpp
Outdated
if (write(fd, valstr.c_str(), valstr.size()) < 0) | ||
ret = -1; | ||
close(fd); | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you sure this is a good idea? Does the kernel interface guarantee that writing a value that already "seems" to be there never has any (desired) side-effect?
xbmc/utils/SysfsUtils.cpp
Outdated
#ifdef TARGET_WINDOWS_STORE | ||
#include <io.h> | ||
#endif | ||
static const unsigned int PAGESIZE = getpagesize(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace {}
instead of static
xbmc/utils/SysfsUtils.cpp
Outdated
int fd = open(path.c_str(), O_RDWR); | ||
if (fd < 0) | ||
{ | ||
CLog::Log(LOGERROR, "{}: error opening {}", __FUNCTION__, path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think with SetString: error opening xxxxx
the SetString:
prefix is not going to be especially helpful. Rather write something descriptive (sysfs utils or the like).
@@ -0,0 +1,47 @@ | |||
/* | |||
* Copyright (C) 2005-2018 Team Kodi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong year
@@ -0,0 +1,19 @@ | |||
/* | |||
* Copyright (C) 2005-2018 Team Kodi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong year
@@ -85,6 +85,20 @@ static int NotifyAll(const std::vector<std::string>& params) | |||
return 0; | |||
} | |||
|
|||
/*! \brief Set volume. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
volume
xbmc/utils/IBacklight.h
Outdated
class IBacklight | ||
{ | ||
public: | ||
static void Register(std::shared_ptr<IBacklight> backlight) { CServiceBroker::RegisterBacklight(backlight); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not completely sure what the purpose of this function is?
EDIT: to clarify, why is having this better than just calling CServiceBroker::RegisterBacklight
?
xbmc/platform/linux/CMakeLists.txt
Outdated
@@ -27,6 +25,11 @@ set(HEADERS Backlight.h | |||
XMemUtils.h | |||
XTimeUtils.h) | |||
|
|||
if(CORE_SYSTEM_NAME STREQUAL linux) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why shouldn't it be linux
in this directory?
@lrusak do you want to progress this, close it or backburner? |
I would still like to see this get merged in, I'll revisit it at some point |
this adds a new interface to be able to access a hardware backlight. this also adds the gui elements needed to show the backlight brightness change and to change it via the touch screen interface. this change is quite invasive but it is based off the way the volume control works. the backlight controls will not be show if no backlight has been register to CServiceBroker
this adds the keyboard backlight brightness keys to the libinput keyboard mapping.
this utility interacts with the kernel sysfs backlight control by querying the backlight device and matching it to the drm device.
add the linux backlight utility to gbm windowing.
|
||
virtual bool SetBrightness(int brightness) = 0; | ||
virtual int GetBrightness() const = 0; | ||
virtual int GetMaxBrightness() const = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int
is not very descriptive of what a brightness is, so could use some documentation. typing could also improve semantics. could I suggest a float in the range [0, 1]?
@@ -337,6 +337,9 @@ | |||
|
|||
#define ACTION_HDR_TOGGLE 260 //!< Toggle display HDR on/off | |||
|
|||
#define ACTION_BACKLIGHT_BRIGHTNESS_UP 251 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ID is a duplicate of ACTION_QUEUE_ITEM_NEXT
, you probably want 261
@@ -645,6 +653,10 @@ bool CSystemGUIInfo::GetBool(bool& value, const CGUIListItem *gitem, int context | |||
} | |||
break; | |||
} | |||
case SYSTEM_HAS_BACKLIGHT: | |||
std::shared_ptr<IBacklight> backlight = CServiceBroker::GetBacklight(); | |||
value = !!backlight; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe static_cast<bool>(backlight)
to be a little more explicit about what is going on here?
return CGUIDialog::OnMessage(message); | ||
} | ||
|
||
return false; // don't process anything other than what we need! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it just saddens me to see lengthy backlight logic added to CApplication. With your work, we now have a beautiful minimal file to add logic to. What if we move all backlight logic from CApplication into this file?
Glad to see you've revisited this. please, please, please don't increase the size of service broker. these are effectively globals (ok, singletons with global scope, so their lifetime is managed relative to just each other, yay?). let's get creative in how we can not nuke architecture. remember, architecture is not what you build, but what you restrict. Looking at the technical debt we've currently saddled service broken with, I see two promising options. Peripheral manager and power manager have something to do with backlight. Maybe we can use these. I'm not that familiar with power manager, but it seems less appropriate for backlight control. backlight changes are not always done from a power perspective. and from a high level, backlight is just responding to user input and controlling hardware. Power manager controls hardware too, but that seems like kind of a stretch. To use peripheral manager, there seems to be some overhead. this requires treating the display as a peripheral, so we need a class that might not be used for anything else. it doesn't make sense to "scan" for displays, because there can only ever be one (as distinct from monitors). I actually faced this with keyboards and mice and created a virtual "application" bus that has one keyboard and mouse per application. Scanning the "application" bus could also return a monitor/display. And we're in luck. All peripherals can see all actions. Maybe peripherals, made for hardware, is a good place for hardware backlight control? |
@@ -0,0 +1,71 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<window type="dialog" id="1110"> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
id="1110" is already in use, please use 1106 instead
@@ -0,0 +1,71 @@ | |||
<?xml version="1.0" encoding="UTF-8"?> | |||
<window type="dialog" id="1110"> | |||
<defaultcontrol>11</defaultcontrol> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
drop this line, there's no control with id="11" in this dialog
<width>120</width> | ||
<height>120</height> | ||
<label></label> | ||
<onclick>ActivateWindow(1110)</onclick> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change to 1106 here as well please
@lrusak this needs a rebase |
This adds a new interface to allow adjusting a hardware backlight (like those found in laptops or touchscreens). This change required a rework of the sysfs utility to comply with the kernel documentation (as interpreted by me). This backlight interface is also quite invasive as it touches many parts of Kodi internals so it could use a thorough review as maybe I did more than what is needed.
This change add no new dependencies or ifdefs. The interface is opt in and requires registration. The backlight utility can be used for amlogic and rpi windowing too if someone wants to implement that.
I also have basically zero knowledge of kodi dialogs and skinning, this is the first time I have touched these areas and am open for input about these changes. I also created the backlight icon myself so if someone wants to do it better feel free 🎨
This image shows both the touch screen interface and the onscreen indicator (hidden between the gallium hud elements).
I will outline the commits below with their messages:
SysfsUtils: cleanup and improve interface according to the documentation
Add new backlight interface and gui
CLibInputKeyboard: add brightness keys
CBacklight: add linux backlight helper utility
windowing/gbm: use CBacklight