summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Gittik <dangittik@google.com>2019-01-22 20:16:40 +0000
committerMichael Wright <michaelwr@google.com>2019-03-08 17:14:20 +0000
commita128d0aa4b4ef1ad931241c5627e641291d01e79 (patch)
tree0c00d02ed1dce436296d6a1e17f252e237ab56bc
parent1284c3f5c329b2c6aa4057f172742aa724a84478 (diff)
downloadandroid_hardware_qcom_sdm845_display-a128d0aa4b4ef1ad931241c5627e641291d01e79.tar.gz
android_hardware_qcom_sdm845_display-a128d0aa4b4ef1ad931241c5627e641291d01e79.tar.bz2
android_hardware_qcom_sdm845_display-a128d0aa4b4ef1ad931241c5627e641291d01e79.zip
Moved brightness from Lights to SF.
Test: manual. Check that brightness works. Fixes: 111435292 Change-Id: Ibce46fa763584962bd37734010a8b0c178cc4a7b
-rw-r--r--sdm/libs/hwc2/hwc_session.cpp99
-rw-r--r--sdm/libs/hwc2/hwc_session.h7
2 files changed, 105 insertions, 1 deletions
diff --git a/sdm/libs/hwc2/hwc_session.cpp b/sdm/libs/hwc2/hwc_session.cpp
index 6109ee08..60b719f8 100644
--- a/sdm/libs/hwc2/hwc_session.cpp
+++ b/sdm/libs/hwc2/hwc_session.cpp
@@ -53,6 +53,10 @@
#define HWC_UEVENT_GRAPHICS_FB0 "change@/devices/virtual/graphics/fb0"
#define HWC_UEVENT_DRM_EXT_HOTPLUG "mdss_mdp/drm/card"
+#define MAX_BRIGHTNESS 255
+#define BRIGHTNESS_FILE1 "/sys/class/leds/lcd-backlight/brightness"
+#define BRIGHTNESS_FILE2 "/sys/class/backlight/panel0-backlight/brightness"
+
static sdm::HWCSession::HWCModuleMethods g_hwc_module_methods;
hwc_module_t HAL_MODULE_INFO_SYM = {
@@ -211,6 +215,17 @@ int HWCSession::Init() {
}
}
+ char const *brightness_file;
+ if (access(BRIGHTNESS_FILE1, F_OK) == 0) {
+ brightness_file = BRIGHTNESS_FILE1;
+ } else {
+ brightness_file = BRIGHTNESS_FILE2;
+ }
+ brightness_fd_ = open(brightness_file, O_WRONLY);
+ if (brightness_fd_ == -1) {
+ DLOGW("Unable to open brightness file: [%d] %s", errno, strerror(errno));
+ }
+
return 0;
}
@@ -240,6 +255,8 @@ int HWCSession::Deinit() {
DLOGE("Display core de-initialization failed. Error = %d", error);
}
+ close(brightness_fd_);
+
return 0;
}
@@ -293,7 +310,7 @@ void HWCSession::GetCapabilities(struct hwc2_device *device, uint32_t *outCount,
if (Debug::Get()->GetProperty(DISABLE_SKIP_VALIDATE_PROP, &value) == kErrorNone) {
disable_skip_validate = (value == 1);
}
- uint32_t count = 1 + (disable_skip_validate ? 0 : 1);
+ uint32_t count = 2 + (disable_skip_validate ? 0 : 1);
if (outCapabilities != nullptr && (*outCount >= count)) {
outCapabilities[0] = HWC2_CAPABILITY_SKIP_CLIENT_COLOR_TRANSFORM;
@@ -925,6 +942,82 @@ int32_t HWCSession::ValidateDisplay(hwc2_device_t *device, hwc2_display_t displa
return INT32(status);
}
+int32_t HWCSession::GetDisplayCapabilities(hwc2_device_t* device, hwc2_display_t display,
+ uint32_t* outNumCapabilities, uint32_t* outCapabilities) {
+ if (outNumCapabilities == nullptr) {
+ return INT32(HWC2::Error::None);
+ }
+
+ bool brightness_support = display == HWC_DISPLAY_PRIMARY;
+ int doze_support = 0;
+ auto status = GetDozeSupport(device, display, &doze_support);
+ if (status != HWC2_ERROR_NONE) {
+ DLOGE("Failed to get doze support Error = %d", status);
+ return INT32(status);
+ }
+
+ uint32_t count = 1 + static_cast<uint32_t>(doze_support) + (brightness_support ? 1 : 0);
+ int index = 0;
+ if (outCapabilities != nullptr && (*outNumCapabilities >= count)) {
+ outCapabilities[index++] = HWC2_DISPLAY_CAPABILITY_SKIP_CLIENT_COLOR_TRANSFORM;
+ if (doze_support == 1) {
+ outCapabilities[index++] = HWC2_DISPLAY_CAPABILITY_DOZE;
+ }
+ if (brightness_support) {
+ outCapabilities[index++] = HWC2_DISPLAY_CAPABILITY_BRIGHTNESS;
+ }
+ }
+
+ *outNumCapabilities = count;
+ return INT32(HWC2::Error::None);
+}
+
+int32_t HWCSession::GetDisplayBrightnessSupport(hwc2_device_t *device, hwc2_display_t display,
+ bool *out_support) {
+ *out_support = display == HWC_DISPLAY_PRIMARY;
+ return INT32(HWC2::Error::None);
+}
+
+int32_t HWCSession::SetDisplayBrightness(hwc2_device_t *device, hwc2_display_t display,
+ float brightness) {
+ if (display != HWC_DISPLAY_PRIMARY) {
+ return INT32(HWC2::Error::BadDisplay);
+ }
+ int backlight = -1;
+ if (brightness == -1.0f) {
+ backlight = 0;
+ } else if (brightness < 0.0f || brightness > 1.0f) {
+ return INT32(HWC2::Error::BadParameter);
+ } else {
+ // 0 is reserved for "backlight off", so we scale the brightness from 1 to MAX_BRIGHTNESS.
+ backlight = (int) ((MAX_BRIGHTNESS - 1.0f) * brightness + 1.0f);
+ }
+ char buff[20];
+ int n = snprintf(buff, sizeof(buff), "%d\n", backlight);
+ if (n < 0 || n >= sizeof(buff)) {
+ return INT32(HWC2::Error::BadParameter);
+ }
+
+ HWCSession *hwc_session = static_cast<HWCSession *>(device);
+ long error = lseek(hwc_session->brightness_fd_, 0, SEEK_SET);
+ if (error == -1) {
+ DLOGW("Failed to rewind brightness file: [%d] %s", errno, strerror(errno));
+ return INT32(HWC2::Error::NoResources);
+ }
+ error = write(hwc_session->brightness_fd_, buff, (size_t) n);
+ if (error == -1) {
+ DLOGW("Failed to write to brightness file: [%d] %s", errno, strerror(errno));
+ return INT32(HWC2::Error::NoResources);
+ }
+ error = fsync(hwc_session->brightness_fd_);
+ if (error == -1) {
+ DLOGW("Failed to flush brightness file: [%d] %s", errno, strerror(errno));
+ return INT32(HWC2::Error::NoResources);
+ }
+
+ return INT32(HWC2::Error::None);
+}
+
hwc2_function_pointer_t HWCSession::GetFunction(struct hwc2_device *device,
int32_t int_descriptor) {
auto descriptor = static_cast<HWC2::FunctionDescriptor>(int_descriptor);
@@ -1039,6 +1132,10 @@ hwc2_function_pointer_t HWCSession::GetFunction(struct hwc2_device *device,
return AsFP<HWC2_PFN_GET_DISPLAYED_CONTENT_SAMPLING_ATTRIBUTES>(GetDisplayedContentSamplingAttributes);
case HWC2::FunctionDescriptor::GetDisplayedContentSample:
return AsFP<HWC2_PFN_GET_DISPLAYED_CONTENT_SAMPLE>(GetDisplayedContentSample);
+ case HWC2::FunctionDescriptor::GetDisplayBrightnessSupport:
+ return AsFP<HWC2_PFN_GET_DISPLAY_BRIGHTNESS_SUPPORT>(GetDisplayBrightnessSupport);
+ case HWC2::FunctionDescriptor::SetDisplayBrightness:
+ return AsFP<HWC2_PFN_SET_DISPLAY_BRIGHTNESS>(SetDisplayBrightness);
default:
DLOGD("Unknown/Unimplemented function descriptor: %d (%s)", int_descriptor,
to_string(descriptor).c_str());
diff --git a/sdm/libs/hwc2/hwc_session.h b/sdm/libs/hwc2/hwc_session.h
index b34f0aa4..52ae7e83 100644
--- a/sdm/libs/hwc2/hwc_session.h
+++ b/sdm/libs/hwc2/hwc_session.h
@@ -179,6 +179,12 @@ class HWCSession : hwc2_device_t, HWCUEventListener, IDisplayConfig, public qCli
int32_t *release_fence);
static int32_t GetDozeSupport(hwc2_device_t *device, hwc2_display_t display,
int32_t *out_support);
+ static int32_t GetDisplayCapabilities(hwc2_device_t* device, hwc2_display_t display,
+ uint32_t* outNumCapabilities, uint32_t* outCapabilities);
+ static int32_t GetDisplayBrightnessSupport(hwc2_device_t *device, hwc2_display_t display,
+ bool *out_support);
+ static int32_t SetDisplayBrightness(hwc2_device_t *device, hwc2_display_t display,
+ float brightness);
static Locker locker_[HWC_NUM_DISPLAY_TYPES];
@@ -304,6 +310,7 @@ class HWCSession : hwc2_device_t, HWCUEventListener, IDisplayConfig, public qCli
int hpd_bpp_ = 0;
int hpd_pattern_ = 0;
uint32_t idle_pc_ref_cnt_ = 0;
+ int brightness_fd_ = -1;
};
} // namespace sdm