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

Commit 915bb81

Browse files
committed
Add 2.4 api
implement vsync2.4 callback, setactiveconfigwithconstraints and getdisplayvsyncperiod. Add an empty SetDisplayBrightness to resolove boot problem Set the ALL_EDID_FLAG_PROPERTY to send SF all available modes. Tracked-On: OAM-92711 Signed-Off-By: Liu, Yuanzhe <yuanzhe.liu@intel.com>
1 parent 3b8f38a commit 915bb81

File tree

12 files changed

+154
-3
lines changed

12 files changed

+154
-3
lines changed

common/display/displayqueue.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -957,6 +957,11 @@ int DisplayQueue::RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
957957
return vblank_handler_->RegisterCallback(callback, display_id);
958958
}
959959

960+
int DisplayQueue::RegisterVsyncPeriodCallback(std::shared_ptr<VsyncPeriodCallback> callback,
961+
uint32_t display_id) {
962+
return vblank_handler_->RegisterCallback(callback, display_id);
963+
}
964+
960965
void DisplayQueue::RegisterRefreshCallback(
961966
std::shared_ptr<RefreshCallback> callback, uint32_t display_id) {
962967
idle_tracker_.idle_lock_.lock();

common/display/displayqueue.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class DisplayQueue {
8585
void RestoreVideoDefaultDeinterlace();
8686
int RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
8787
uint32_t display_id);
88-
88+
int RegisterVsyncPeriodCallback(std::shared_ptr<VsyncPeriodCallback> callback,
89+
uint32_t display_id);
8990
void RegisterRefreshCallback(std::shared_ptr<RefreshCallback> callback,
9091
uint32_t display_id);
9192

common/display/vblankeventhandler.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ VblankEventHandler::VblankEventHandler(DisplayQueue* queue)
3232
enabled_(false),
3333
fd_(-1),
3434
last_timestamp_(-1),
35+
previous_timestamp_(-1),
3536
queue_(queue) {
3637
memset(&type_, 0, sizeof(type_));
3738
}
@@ -69,6 +70,16 @@ int VblankEventHandler::RegisterCallback(
6970
return 0;
7071
}
7172

73+
int VblankEventHandler::RegisterCallback(
74+
std::shared_ptr<VsyncPeriodCallback> callback, uint32_t display) {
75+
spin_lock_.lock();
76+
callback_2_4_ = callback;
77+
display_ = display;
78+
last_timestamp_ = -1;
79+
spin_lock_.unlock();
80+
return 0;
81+
}
82+
7283
int VblankEventHandler::VSyncControl(bool enabled) {
7384
IPAGEFLIPEVENTTRACE("VblankEventHandler VSyncControl enabled %d", enabled);
7485
if (enabled_ == enabled)
@@ -87,14 +98,20 @@ void VblankEventHandler::HandlePageFlipEvent(unsigned int sec,
8798
int64_t timestamp = ((int64_t)sec * kOneSecondNs) + ((int64_t)usec * 1000);
8899
IPAGEFLIPEVENTTRACE("HandleVblankCallBack Frame Time %f",
89100
static_cast<float>(timestamp - last_timestamp_) / (1000));
101+
int64_t vperiod = timestamp - previous_timestamp_;
90102
last_timestamp_ = timestamp;
91103

92104
IPAGEFLIPEVENTTRACE("Callback called from HandlePageFlipEvent. %lu",
93105
timestamp);
94106
spin_lock_.lock();
95107
if (enabled_ && callback_) {
96-
callback_->Callback(display_, timestamp);
108+
if(abs(vperiod - vperiod_) > (13333333 - 11111111) && previous_timestamp_ != -1)
109+
callback_2_4_->Callback(display_, timestamp, vperiod);
110+
else
111+
callback_->Callback(display_, timestamp);
97112
}
113+
vperiod_ = vperiod;
114+
previous_timestamp_ = timestamp;
98115
spin_lock_.unlock();
99116
}
100117

common/display/vblankeventhandler.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class VblankEventHandler : public HWCThread {
4545
int RegisterCallback(std::shared_ptr<VsyncCallback> callback,
4646
uint32_t display_id);
4747

48+
int RegisterCallback(std::shared_ptr<VsyncPeriodCallback> callback,
49+
uint32_t display_id);
50+
4851
int VSyncControl(bool enabled);
4952

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

6368
int fd_;
6469
int64_t last_timestamp_;
70+
int64_t previous_timestamp_;
6571
drmVBlankSeqType type_;
6672
DisplayQueue* queue_;
6773
};

os/android/iahwc2.cpp

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,24 @@ class IAVsyncCallback : public hwcomposer::VsyncCallback {
5757
hwc2_function_pointer_t hook_;
5858
};
5959

60+
class IAVsyncPeriodCallback : public hwcomposer::VsyncPeriodCallback {
61+
public:
62+
IAVsyncPeriodCallback(hwc2_callback_data_t data, hwc2_function_pointer_t hook)
63+
: data_(data), hook_(hook) {
64+
}
65+
66+
void Callback(uint32_t display, int64_t timestamp, uint32_t vsyncPeriodNanos) {
67+
if (hook_ != NULL) {
68+
auto hook = reinterpret_cast<HWC2_PFN_VSYNC_2_4>(hook_);
69+
hook(data_, display, timestamp, vsyncPeriodNanos);
70+
}
71+
}
72+
73+
private:
74+
hwc2_callback_data_t data_;
75+
hwc2_function_pointer_t hook_;
76+
};
77+
6078
class IARefreshCallback : public hwcomposer::RefreshCallback {
6179
public:
6280
IARefreshCallback(hwc2_callback_data_t data, hwc2_function_pointer_t hook)
@@ -335,6 +353,15 @@ HWC2::Error IAHWC2::RegisterCallback(int32_t descriptor,
335353

336354
break;
337355
}
356+
case HWC2::Callback::Vsync_2_4: {
357+
primary_display_.RegisterVsyncPeriodCallback(data, function);
358+
for (size_t i = 0; i < size; ++i) {
359+
IAHWC2::HwcDisplay *display = extended_displays_.at(i).get();
360+
display->RegisterVsyncPeriodCallback(data, function);
361+
}
362+
363+
break;
364+
}
338365
case HWC2::Callback::Refresh: {
339366
primary_display_.RegisterRefreshCallback(data, function);
340367
for (size_t i = 0; i < size; ++i) {
@@ -425,6 +452,19 @@ HWC2::Error IAHWC2::HwcDisplay::RegisterVsyncCallback(
425452
return HWC2::Error::None;
426453
}
427454

455+
HWC2::Error IAHWC2::HwcDisplay::RegisterVsyncPeriodCallback(
456+
hwc2_callback_data_t data, hwc2_function_pointer_t func) {
457+
supported(__func__);
458+
auto callback = std::make_shared<IAVsyncPeriodCallback>(data, func);
459+
int ret = display_->RegisterVsyncPeriodCallback(std::move(callback),
460+
static_cast<int>(handle_));
461+
if (ret) {
462+
ALOGE("Failed to register callback d=%" PRIu64 " ret=%d", handle_, ret);
463+
return HWC2::Error::BadDisplay;
464+
}
465+
return HWC2::Error::None;
466+
}
467+
428468
HWC2::Error IAHWC2::HwcDisplay::RegisterRefreshCallback(
429469
hwc2_callback_data_t data, hwc2_function_pointer_t func) {
430470
supported(__func__);
@@ -815,6 +855,25 @@ HWC2::Error IAHWC2::HwcDisplay::SetActiveConfig(hwc2_config_t config) {
815855
return HWC2::Error::None;
816856
}
817857

858+
HWC2::Error IAHWC2::HwcDisplay::SetActiveConfigWithConstraints(
859+
hwc2_config_t config,
860+
hwc_vsync_period_change_constraints_t* vsyncPeriodChangeConstraints,
861+
hwc_vsync_period_change_timeline_t* outTimeline
862+
) {
863+
supported(__func__);
864+
return SetActiveConfig(config);
865+
}
866+
867+
HWC2::Error IAHWC2::HwcDisplay::GetDisplayVsyncPeriod(hwc2_vsync_period_t* outVsyncPeriod) {
868+
supported(__func__);
869+
//*outVsyncPeriod = 16666667;
870+
//return HWC2::Error::None;
871+
if(display_->GetDisplayVsyncPeriod(outVsyncPeriod))
872+
return HWC2::Error::None;
873+
else
874+
return HWC2::Error::BadConfig;
875+
}
876+
818877
HWC2::Error IAHWC2::HwcDisplay::SetClientTarget(buffer_handle_t target,
819878
int32_t acquire_fence,
820879
int32_t dataspace,
@@ -951,6 +1010,11 @@ HWC2::Error IAHWC2::HwcDisplay::SetVsyncEnabled(int32_t enabled) {
9511010
return HWC2::Error::None;
9521011
}
9531012

1013+
HWC2::Error IAHWC2::HwcDisplay::SetDisplayBrightness(float brightness) {
1014+
supported(__func__);
1015+
return HWC2::Error::None;
1016+
}
1017+
9541018
HWC2::Error IAHWC2::HwcDisplay::ValidateDisplay(uint32_t *num_types,
9551019
uint32_t *num_requests) {
9561020
std::map<uint32_t, hwc2_layer_t> z_map;
@@ -1439,6 +1503,16 @@ hwc2_function_pointer_t IAHWC2::HookDevGetFunction(struct hwc2_device * /*dev*/,
14391503
return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG>(
14401504
DisplayHook<decltype(&HwcDisplay::SetActiveConfig),
14411505
&HwcDisplay::SetActiveConfig, hwc2_config_t>);
1506+
case HWC2::FunctionDescriptor::SetActiveConfigWithConstraints:
1507+
return ToHook<HWC2_PFN_SET_ACTIVE_CONFIG_WITH_CONSTRAINTS>(
1508+
DisplayHook<decltype(&HwcDisplay::SetActiveConfigWithConstraints),
1509+
&HwcDisplay::SetActiveConfigWithConstraints, hwc2_config_t,
1510+
hwc_vsync_period_change_constraints_t*,
1511+
hwc_vsync_period_change_timeline_t*>);
1512+
case HWC2::FunctionDescriptor::GetDisplayVsyncPeriod:
1513+
return ToHook<HWC2_PFN_GET_DISPLAY_VSYNC_PERIOD>(
1514+
DisplayHook<decltype(&HwcDisplay::GetDisplayVsyncPeriod),
1515+
&HwcDisplay::GetDisplayVsyncPeriod, hwc2_vsync_period_t*>);
14421516
case HWC2::FunctionDescriptor::SetClientTarget:
14431517
return ToHook<HWC2_PFN_SET_CLIENT_TARGET>(DisplayHook<
14441518
decltype(&HwcDisplay::SetClientTarget), &HwcDisplay::SetClientTarget,
@@ -1473,6 +1547,10 @@ hwc2_function_pointer_t IAHWC2::HookDevGetFunction(struct hwc2_device * /*dev*/,
14731547
return ToHook<HWC2_PFN_SET_VSYNC_ENABLED>(
14741548
DisplayHook<decltype(&HwcDisplay::SetVsyncEnabled),
14751549
&HwcDisplay::SetVsyncEnabled, int32_t>);
1550+
case HWC2::FunctionDescriptor::SetDisplayBrightness:
1551+
return ToHook<HWC2_PFN_SET_DISPLAY_BRIGHTNESS>(
1552+
DisplayHook<decltype(&HwcDisplay::SetDisplayBrightness),
1553+
&HwcDisplay::SetDisplayBrightness, float>);
14761554
case HWC2::FunctionDescriptor::ValidateDisplay:
14771555
return ToHook<HWC2_PFN_VALIDATE_DISPLAY>(
14781556
DisplayHook<decltype(&HwcDisplay::ValidateDisplay),

os/android/iahwc2.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,9 @@ class IAHWC2 : public hwc2_device_t {
196196
HWC2::Error RegisterVsyncCallback(hwc2_callback_data_t data,
197197
hwc2_function_pointer_t func);
198198

199+
HWC2::Error RegisterVsyncPeriodCallback(hwc2_callback_data_t data,
200+
hwc2_function_pointer_t func);
201+
199202
HWC2::Error RegisterRefreshCallback(hwc2_callback_data_t data,
200203
hwc2_function_pointer_t func);
201204

@@ -232,6 +235,10 @@ class IAHWC2 : public hwc2_device_t {
232235
int32_t *fences);
233236
HWC2::Error PresentDisplay(int32_t *retire_fence);
234237
HWC2::Error SetActiveConfig(hwc2_config_t config);
238+
HWC2::Error SetActiveConfigWithConstraints(hwc2_config_t config,
239+
hwc_vsync_period_change_constraints_t* vsyncPeriodChangeConstraints,
240+
hwc_vsync_period_change_timeline_t* outTimeline);
241+
HWC2::Error GetDisplayVsyncPeriod(hwc2_vsync_period_t* outVsyncPeriod);
235242
HWC2::Error SetClientTarget(buffer_handle_t target, int32_t acquire_fence,
236243
int32_t dataspace, hwc_region_t damage);
237244
HWC2::Error SetColorMode(int32_t mode);
@@ -243,6 +250,7 @@ class IAHWC2 : public hwc2_device_t {
243250
HWC2::Error SetOutputBuffer(buffer_handle_t buffer, int32_t release_fence);
244251
HWC2::Error SetPowerMode(int32_t mode);
245252
HWC2::Error SetVsyncEnabled(int32_t enabled);
253+
HWC2::Error SetDisplayBrightness(float brightness);
246254
HWC2::Error ValidateDisplay(uint32_t *num_types, uint32_t *num_requests);
247255
HWC2::Error GetDisplayIdentificationData(uint8_t *outPort,
248256
uint32_t *outDataSize,

public/hwcutils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <sstream>
2626
#include "overlaylayer.h"
2727

28-
#define ALL_EDID_FLAG_PROPERTY "vendor.hwcomposer.edid.all"
28+
#define ALL_EDID_FLAG_PROPERTY "1"
2929

3030
namespace hwcomposer {
3131

public/nativedisplay.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ class VsyncCallback {
4141
virtual void Callback(uint32_t display, int64_t timestamp) = 0;
4242
};
4343

44+
class VsyncPeriodCallback {
45+
public:
46+
virtual ~VsyncPeriodCallback() {
47+
}
48+
virtual void Callback(uint32_t display, int64_t timestamp, uint32_t vsyncPeriodNanos) = 0;
49+
};
50+
4451
class RefreshCallback {
4552
public:
4653
virtual ~RefreshCallback() {
@@ -95,6 +102,9 @@ class NativeDisplay {
95102

96103
virtual void GetDisplayCapabilities(uint32_t *outNumCapabilities,
97104
uint32_t *outCapabilities) = 0;
105+
virtual bool GetDisplayVsyncPeriod(uint32_t *outVsyncPeriod) {
106+
return false;
107+
};
98108

99109
/**
100110
* API for getting connected display's pipe id.
@@ -132,6 +142,12 @@ class NativeDisplay {
132142

133143
virtual int RegisterVsyncCallback(std::shared_ptr<VsyncCallback> callback,
134144
uint32_t display_id) = 0;
145+
146+
virtual int RegisterVsyncPeriodCallback(std::shared_ptr<VsyncPeriodCallback> callback,
147+
uint32_t display_id) {
148+
return false;
149+
};
150+
135151
virtual void VSyncControl(bool enabled) = 0;
136152

137153
/**

wsi/drm/drmdisplay.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,15 @@ void DrmDisplay::UpdateDisplayConfig() {
575575
}
576576
flags_ |= DRM_MODE_ATOMIC_ALLOW_MODESET;
577577
SetDisplayAttribute(modes_[config_]);
578+
vsync_period_ = modes_[config_].vrefresh;
578579
SPIN_UNLOCK(display_lock_);
579580
}
580581

582+
bool DrmDisplay::GetDisplayVsyncPeriod(uint32_t* outVsyncPeriod) {
583+
return GetDisplayAttribute(config_, HWCDisplayAttribute::kRefreshRate,
584+
reinterpret_cast<int32_t*>(outVsyncPeriod));
585+
}
586+
581587
void DrmDisplay::PowerOn() {
582588
flags_ = 0;
583589
flags_ |= DRM_MODE_ATOMIC_ALLOW_MODESET;

wsi/drm/drmdisplay.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ class DrmDisplay : public PhysicalDisplay {
7878
bool InitializeDisplay() override;
7979
void PowerOn() override;
8080
void UpdateDisplayConfig() override;
81+
bool GetDisplayVsyncPeriod(uint32_t* outVsyncPeriod) override;
82+
8183
void SetColorCorrection(struct gamma_colors gamma, uint32_t contrast,
8284
uint32_t brightness) const override;
8385
void SetPipeCanvasColor(uint16_t bpc, uint16_t red, uint16_t green,
@@ -215,6 +217,7 @@ class DrmDisplay : public PhysicalDisplay {
215217
std::vector<drmModeModeInfo> modes_;
216218
SpinLock display_lock_;
217219
DrmDisplayManager *manager_;
220+
uint32_t vsync_period_ = 0;
218221
};
219222

220223
} // namespace hwcomposer

0 commit comments

Comments
 (0)