Skip to content
This repository has been archived by the owner on Oct 8, 2024. It is now read-only.

HDR enable #701

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions common/display/displayqueue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,11 @@ int DisplayQueue::RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
return vblank_handler_->RegisterCallback(callback, display_id);
}

int DisplayQueue::RegisterVsyncPeriodCallback(std::shared_ptr<VsyncPeriodCallback> callback,
uint32_t display_id) {
return vblank_handler_->RegisterCallback(callback, display_id);
}

void DisplayQueue::RegisterRefreshCallback(
std::shared_ptr<RefreshCallback> callback, uint32_t display_id) {
idle_tracker_.idle_lock_.lock();
Expand Down
3 changes: 2 additions & 1 deletion common/display/displayqueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ class DisplayQueue {
void RestoreVideoDefaultDeinterlace();
int RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
uint32_t display_id);

int RegisterVsyncPeriodCallback(std::shared_ptr<VsyncPeriodCallback> callback,
uint32_t display_id);
void RegisterRefreshCallback(std::shared_ptr<RefreshCallback> callback,
uint32_t display_id);

Expand Down
19 changes: 18 additions & 1 deletion common/display/vblankeventhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ VblankEventHandler::VblankEventHandler(DisplayQueue* queue)
enabled_(false),
fd_(-1),
last_timestamp_(-1),
previous_timestamp_(-1),
queue_(queue) {
memset(&type_, 0, sizeof(type_));
}
Expand Down Expand Up @@ -69,6 +70,16 @@ int VblankEventHandler::RegisterCallback(
return 0;
}

int VblankEventHandler::RegisterCallback(
std::shared_ptr<VsyncPeriodCallback> callback, uint32_t display) {
spin_lock_.lock();
callback_2_4_ = callback;
display_ = display;
last_timestamp_ = -1;
spin_lock_.unlock();
return 0;
}

int VblankEventHandler::VSyncControl(bool enabled) {
IPAGEFLIPEVENTTRACE("VblankEventHandler VSyncControl enabled %d", enabled);
if (enabled_ == enabled)
Expand All @@ -87,14 +98,20 @@ void VblankEventHandler::HandlePageFlipEvent(unsigned int sec,
int64_t timestamp = ((int64_t)sec * kOneSecondNs) + ((int64_t)usec * 1000);
IPAGEFLIPEVENTTRACE("HandleVblankCallBack Frame Time %f",
static_cast<float>(timestamp - last_timestamp_) / (1000));
int64_t vperiod = timestamp - previous_timestamp_;
last_timestamp_ = timestamp;

IPAGEFLIPEVENTTRACE("Callback called from HandlePageFlipEvent. %lu",
timestamp);
spin_lock_.lock();
if (enabled_ && callback_) {
callback_->Callback(display_, timestamp);
if(abs(vperiod - vperiod_) > (13333333 - 11111111) && previous_timestamp_ != -1)
callback_2_4_->Callback(display_, timestamp, vperiod);
else
callback_->Callback(display_, timestamp);
}
vperiod_ = vperiod;
previous_timestamp_ = timestamp;
spin_lock_.unlock();
}

Expand Down
6 changes: 6 additions & 0 deletions common/display/vblankeventhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class VblankEventHandler : public HWCThread {
int RegisterCallback(std::shared_ptr<VsyncCallback> callback,
uint32_t display_id);

int RegisterCallback(std::shared_ptr<VsyncPeriodCallback> callback,
uint32_t display_id);

int VSyncControl(bool enabled);

protected:
Expand All @@ -56,12 +59,15 @@ class VblankEventHandler : public HWCThread {
// actually call the hook) and we don't want the memory freed until we're
// done
std::shared_ptr<VsyncCallback> callback_ = NULL;
std::shared_ptr<VsyncPeriodCallback> callback_2_4_ = NULL;
SpinLock spin_lock_;
uint32_t display_;
int64_t vperiod_;
bool enabled_ = false;

int fd_;
int64_t last_timestamp_;
int64_t previous_timestamp_;
drmVBlankSeqType type_;
DisplayQueue* queue_;
};
Expand Down
78 changes: 78 additions & 0 deletions os/android/iahwc2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ class IAVsyncCallback : public hwcomposer::VsyncCallback {
hwc2_function_pointer_t hook_;
};

class IAVsyncPeriodCallback : public hwcomposer::VsyncPeriodCallback {
public:
IAVsyncPeriodCallback(hwc2_callback_data_t data, hwc2_function_pointer_t hook)
: data_(data), hook_(hook) {
}

void Callback(uint32_t display, int64_t timestamp, uint32_t vsyncPeriodNanos) {
if (hook_ != NULL) {
auto hook = reinterpret_cast<HWC2_PFN_VSYNC_2_4>(hook_);
hook(data_, display, timestamp, vsyncPeriodNanos);
}
}

private:
hwc2_callback_data_t data_;
hwc2_function_pointer_t hook_;
};

class IARefreshCallback : public hwcomposer::RefreshCallback {
public:
IARefreshCallback(hwc2_callback_data_t data, hwc2_function_pointer_t hook)
Expand Down Expand Up @@ -335,6 +353,15 @@ HWC2::Error IAHWC2::RegisterCallback(int32_t descriptor,

break;
}
case HWC2::Callback::Vsync_2_4: {
primary_display_.RegisterVsyncPeriodCallback(data, function);
for (size_t i = 0; i < size; ++i) {
IAHWC2::HwcDisplay *display = extended_displays_.at(i).get();
display->RegisterVsyncPeriodCallback(data, function);
}

break;
}
case HWC2::Callback::Refresh: {
primary_display_.RegisterRefreshCallback(data, function);
for (size_t i = 0; i < size; ++i) {
Expand Down Expand Up @@ -425,6 +452,19 @@ HWC2::Error IAHWC2::HwcDisplay::RegisterVsyncCallback(
return HWC2::Error::None;
}

HWC2::Error IAHWC2::HwcDisplay::RegisterVsyncPeriodCallback(
hwc2_callback_data_t data, hwc2_function_pointer_t func) {
supported(__func__);
auto callback = std::make_shared<IAVsyncPeriodCallback>(data, func);
int ret = display_->RegisterVsyncPeriodCallback(std::move(callback),
static_cast<int>(handle_));
if (ret) {
ALOGE("Failed to register callback d=%" PRIu64 " ret=%d", handle_, ret);
return HWC2::Error::BadDisplay;
}
return HWC2::Error::None;
}

HWC2::Error IAHWC2::HwcDisplay::RegisterRefreshCallback(
hwc2_callback_data_t data, hwc2_function_pointer_t func) {
supported(__func__);
Expand Down Expand Up @@ -815,6 +855,25 @@ HWC2::Error IAHWC2::HwcDisplay::SetActiveConfig(hwc2_config_t config) {
return HWC2::Error::None;
}

HWC2::Error IAHWC2::HwcDisplay::SetActiveConfigWithConstraints(
hwc2_config_t config,
hwc_vsync_period_change_constraints_t* vsyncPeriodChangeConstraints,
hwc_vsync_period_change_timeline_t* outTimeline
) {
supported(__func__);
return SetActiveConfig(config);
}

HWC2::Error IAHWC2::HwcDisplay::GetDisplayVsyncPeriod(hwc2_vsync_period_t* outVsyncPeriod) {
supported(__func__);
//*outVsyncPeriod = 16666667;
//return HWC2::Error::None;
if(display_->GetDisplayVsyncPeriod(outVsyncPeriod))
return HWC2::Error::None;
else
return HWC2::Error::BadConfig;
}

HWC2::Error IAHWC2::HwcDisplay::SetClientTarget(buffer_handle_t target,
int32_t acquire_fence,
int32_t dataspace,
Expand Down Expand Up @@ -951,6 +1010,11 @@ HWC2::Error IAHWC2::HwcDisplay::SetVsyncEnabled(int32_t enabled) {
return HWC2::Error::None;
}

HWC2::Error IAHWC2::HwcDisplay::SetDisplayBrightness(float brightness) {
supported(__func__);
return HWC2::Error::None;
}

HWC2::Error IAHWC2::HwcDisplay::ValidateDisplay(uint32_t *num_types,
uint32_t *num_requests) {
std::map<uint32_t, hwc2_layer_t> z_map;
Expand Down Expand Up @@ -1439,6 +1503,16 @@ hwc2_function_pointer_t IAHWC2::HookDevGetFunction(struct hwc2_device * /*dev*/,
return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG>(
DisplayHook<decltype(&HwcDisplay::SetActiveConfig),
&HwcDisplay::SetActiveConfig, hwc2_config_t>);
case HWC2::FunctionDescriptor::SetActiveConfigWithConstraints:
return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG_WITH_CONSTRAINTS>(
DisplayHook<decltype(&HwcDisplay::SetActiveConfigWithConstraints),
&HwcDisplay::SetActiveConfigWithConstraints, hwc2_config_t,
hwc_vsync_period_change_constraints_t*,
hwc_vsync_period_change_timeline_t*>);
case HWC2::FunctionDescriptor::GetDisplayVsyncPeriod:
return ToHook<HWC2_PFN_GET_DISPLAY_VSYNC_PERIOD>(
DisplayHook<decltype(&HwcDisplay::GetDisplayVsyncPeriod),
&HwcDisplay::GetDisplayVsyncPeriod, hwc2_vsync_period_t*>);
case HWC2::FunctionDescriptor::SetClientTarget:
return ToHook<HWC2_PFN_SET_CLIENT_TARGET>(DisplayHook<
decltype(&HwcDisplay::SetClientTarget), &HwcDisplay::SetClientTarget,
Expand Down Expand Up @@ -1473,6 +1547,10 @@ hwc2_function_pointer_t IAHWC2::HookDevGetFunction(struct hwc2_device * /*dev*/,
return ToHook<HWC2_PFN_SET_VSYNC_ENABLED>(
DisplayHook<decltype(&HwcDisplay::SetVsyncEnabled),
&HwcDisplay::SetVsyncEnabled, int32_t>);
case HWC2::FunctionDescriptor::SetDisplayBrightness:
return ToHook<HWC2_PFN_SET_DISPLAY_BRIGHTNESS>(
DisplayHook<decltype(&HwcDisplay::SetDisplayBrightness),
&HwcDisplay::SetDisplayBrightness, float>);
case HWC2::FunctionDescriptor::ValidateDisplay:
return ToHook<HWC2_PFN_VALIDATE_DISPLAY>(
DisplayHook<decltype(&HwcDisplay::ValidateDisplay),
Expand Down
8 changes: 8 additions & 0 deletions os/android/iahwc2.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ class IAHWC2 : public hwc2_device_t {
HWC2::Error RegisterVsyncCallback(hwc2_callback_data_t data,
hwc2_function_pointer_t func);

HWC2::Error RegisterVsyncPeriodCallback(hwc2_callback_data_t data,
hwc2_function_pointer_t func);

HWC2::Error RegisterRefreshCallback(hwc2_callback_data_t data,
hwc2_function_pointer_t func);

Expand Down Expand Up @@ -232,6 +235,10 @@ class IAHWC2 : public hwc2_device_t {
int32_t *fences);
HWC2::Error PresentDisplay(int32_t *retire_fence);
HWC2::Error SetActiveConfig(hwc2_config_t config);
HWC2::Error SetActiveConfigWithConstraints(hwc2_config_t config,
hwc_vsync_period_change_constraints_t* vsyncPeriodChangeConstraints,
hwc_vsync_period_change_timeline_t* outTimeline);
HWC2::Error GetDisplayVsyncPeriod(hwc2_vsync_period_t* outVsyncPeriod);
HWC2::Error SetClientTarget(buffer_handle_t target, int32_t acquire_fence,
int32_t dataspace, hwc_region_t damage);
HWC2::Error SetColorMode(int32_t mode);
Expand All @@ -243,6 +250,7 @@ class IAHWC2 : public hwc2_device_t {
HWC2::Error SetOutputBuffer(buffer_handle_t buffer, int32_t release_fence);
HWC2::Error SetPowerMode(int32_t mode);
HWC2::Error SetVsyncEnabled(int32_t enabled);
HWC2::Error SetDisplayBrightness(float brightness);
HWC2::Error ValidateDisplay(uint32_t *num_types, uint32_t *num_requests);
HWC2::Error GetDisplayIdentificationData(uint8_t *outPort,
uint32_t *outDataSize,
Expand Down
2 changes: 1 addition & 1 deletion public/hwcutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <sstream>
#include "overlaylayer.h"

#define ALL_EDID_FLAG_PROPERTY "vendor.hwcomposer.edid.all"
#define ALL_EDID_FLAG_PROPERTY "1"

namespace hwcomposer {

Expand Down
16 changes: 16 additions & 0 deletions public/nativedisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ class VsyncCallback {
virtual void Callback(uint32_t display, int64_t timestamp) = 0;
};

class VsyncPeriodCallback {
public:
virtual ~VsyncPeriodCallback() {
}
virtual void Callback(uint32_t display, int64_t timestamp, uint32_t vsyncPeriodNanos) = 0;
};

class RefreshCallback {
public:
virtual ~RefreshCallback() {
Expand Down Expand Up @@ -95,6 +102,9 @@ class NativeDisplay {

virtual void GetDisplayCapabilities(uint32_t *outNumCapabilities,
uint32_t *outCapabilities) = 0;
virtual bool GetDisplayVsyncPeriod(uint32_t *outVsyncPeriod) {
return false;
};

/**
* API for getting connected display's pipe id.
Expand Down Expand Up @@ -132,6 +142,12 @@ class NativeDisplay {

virtual int RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
uint32_t display_id) = 0;

virtual int RegisterVsyncPeriodCallback(std::shared_ptr<VsyncPeriodCallback> callback,
uint32_t display_id) {
return false;
};

virtual void VSyncControl(bool enabled) = 0;

/**
Expand Down
6 changes: 6 additions & 0 deletions wsi/drm/drmdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,15 @@ void DrmDisplay::UpdateDisplayConfig() {
}
flags_ |= DRM_MODE_ATOMIC_ALLOW_MODESET;
SetDisplayAttribute(modes_[config_]);
vsync_period_ = modes_[config_].vrefresh;
SPIN_UNLOCK(display_lock_);
}

bool DrmDisplay::GetDisplayVsyncPeriod(uint32_t* outVsyncPeriod) {
return GetDisplayAttribute(config_, HWCDisplayAttribute::kRefreshRate,
reinterpret_cast<int32_t*>(outVsyncPeriod));
}

void DrmDisplay::PowerOn() {
flags_ = 0;
flags_ |= DRM_MODE_ATOMIC_ALLOW_MODESET;
Expand Down
3 changes: 3 additions & 0 deletions wsi/drm/drmdisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class DrmDisplay : public PhysicalDisplay {
bool InitializeDisplay() override;
void PowerOn() override;
void UpdateDisplayConfig() override;
bool GetDisplayVsyncPeriod(uint32_t* outVsyncPeriod) override;

void SetColorCorrection(struct gamma_colors gamma, uint32_t contrast,
uint32_t brightness) const override;
void SetPipeCanvasColor(uint16_t bpc, uint16_t red, uint16_t green,
Expand Down Expand Up @@ -215,6 +217,7 @@ class DrmDisplay : public PhysicalDisplay {
std::vector<drmModeModeInfo> modes_;
SpinLock display_lock_;
DrmDisplayManager *manager_;
uint32_t vsync_period_ = 0;
};

} // namespace hwcomposer
Expand Down
5 changes: 5 additions & 0 deletions wsi/physicaldisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,11 @@ int PhysicalDisplay::RegisterVsyncCallback(
return display_queue_->RegisterVsyncCallback(callback, display_id);
}

int PhysicalDisplay::RegisterVsyncPeriodCallback(
std::shared_ptr<VsyncPeriodCallback> callback, uint32_t display_id) {
return display_queue_->RegisterVsyncPeriodCallback(callback, display_id);
}

void PhysicalDisplay::RegisterRefreshCallback(
std::shared_ptr<RefreshCallback> callback, uint32_t display_id) {
display_queue_->RegisterRefreshCallback(callback, display_id);
Expand Down
6 changes: 6 additions & 0 deletions wsi/physicaldisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class PhysicalDisplay : public NativeDisplay, public DisplayPlaneHandler {
int RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
uint32_t display_id) override;

int RegisterVsyncPeriodCallback(std::shared_ptr<VsyncPeriodCallback> callback,
uint32_t display_id) override;

void RegisterRefreshCallback(std::shared_ptr<RefreshCallback> callback,
uint32_t display_id) override;

Expand Down Expand Up @@ -201,6 +204,9 @@ class PhysicalDisplay : public NativeDisplay, public DisplayPlaneHandler {
*/
virtual void UpdateDisplayConfig() = 0;


virtual bool GetDisplayVsyncPeriod(uint32_t* outVsyncPeriod) = 0;

/**
* API for powering on the display
*/
Expand Down