diff options
author | android-build-team Robot | 2017-09-21 02:26:59 -0500 |
---|---|---|
committer | android-build-team Robot | 2017-09-21 02:26:59 -0500 |
commit | 5d0c9188a7cc5b49df32e025ab9a4455f3bc0324 (patch) | |
tree | d6fd810e0c564efccb114f1d574f792524bb2d15 | |
parent | 4f9ed81274535d117bb8e142c2a692a5e624b4de (diff) | |
parent | 55f8883bb5b93c6b88350eeb6052a3f145496fdd (diff) | |
download | frameworks-native-5d0c9188a7cc5b49df32e025ab9a4455f3bc0324.tar.gz frameworks-native-5d0c9188a7cc5b49df32e025ab9a4455f3bc0324.tar.xz frameworks-native-5d0c9188a7cc5b49df32e025ab9a4455f3bc0324.zip |
release-request-bbc747ae-190b-4d38-8704-432aa6396c16-for-git_oc-mr1-release-4351869 snap-temp-L93800000104806132
Change-Id: I1530ca75a479667c9ab39178deaa0e6a15df84ed
-rw-r--r-- | libs/binder/aidl/android/content/pm/IPackageManagerNative.aidl | 16 | ||||
-rw-r--r-- | libs/hwc2on1adapter/HWC2On1Adapter.cpp | 17 | ||||
-rw-r--r-- | libs/vr/libvrflinger/display_manager_service.cpp | 1 | ||||
-rw-r--r-- | libs/vr/libvrflinger/display_service.cpp | 2 | ||||
-rw-r--r-- | libs/vr/libvrflinger/hardware_composer.cpp | 238 | ||||
-rw-r--r-- | libs/vr/libvrflinger/hardware_composer.h | 26 | ||||
-rw-r--r-- | libs/vr/libvrflinger/vr_flinger.cpp | 6 | ||||
-rw-r--r-- | libs/vr/libvrflinger/vsync_service.cpp | 1 | ||||
-rw-r--r-- | services/inputflinger/InputWindow.cpp | 3 | ||||
-rw-r--r-- | services/inputflinger/InputWindow.h | 1 |
10 files changed, 248 insertions, 63 deletions
diff --git a/libs/binder/aidl/android/content/pm/IPackageManagerNative.aidl b/libs/binder/aidl/android/content/pm/IPackageManagerNative.aidl index 6b7254cbb..3264666a2 100644 --- a/libs/binder/aidl/android/content/pm/IPackageManagerNative.aidl +++ b/libs/binder/aidl/android/content/pm/IPackageManagerNative.aidl | |||
@@ -38,4 +38,20 @@ interface IPackageManagerNative { | |||
38 | * strings. | 38 | * strings. |
39 | */ | 39 | */ |
40 | @utf8InCpp String[] getNamesForUids(in int[] uids); | 40 | @utf8InCpp String[] getNamesForUids(in int[] uids); |
41 | |||
42 | /** | ||
43 | * Returns the name of the installer (a package) which installed the named | ||
44 | * package. Preloaded packages return the string "preload". Sideloaded packages | ||
45 | * return an empty string. Unknown or unknowable are returned as empty strings. | ||
46 | */ | ||
47 | |||
48 | @utf8InCpp String getInstallerForPackage(in String packageName); | ||
49 | |||
50 | /** | ||
51 | * Returns the version code of the named package. | ||
52 | * Unknown or unknowable versions are returned as 0. | ||
53 | */ | ||
54 | |||
55 | int getVersionCodeForPackage(in String packageName); | ||
56 | |||
41 | } | 57 | } |
diff --git a/libs/hwc2on1adapter/HWC2On1Adapter.cpp b/libs/hwc2on1adapter/HWC2On1Adapter.cpp index 8c6ef691a..e1b9a8a6f 100644 --- a/libs/hwc2on1adapter/HWC2On1Adapter.cpp +++ b/libs/hwc2on1adapter/HWC2On1Adapter.cpp | |||
@@ -2005,10 +2005,21 @@ Error HWC2On1Adapter::Layer::setTransform(Transform transform) { | |||
2005 | return Error::None; | 2005 | return Error::None; |
2006 | } | 2006 | } |
2007 | 2007 | ||
2008 | static bool compareRects(const hwc_rect_t& rect1, const hwc_rect_t& rect2) { | ||
2009 | return rect1.left == rect2.left && | ||
2010 | rect1.right == rect2.right && | ||
2011 | rect1.top == rect2.top && | ||
2012 | rect1.bottom == rect2.bottom; | ||
2013 | } | ||
2014 | |||
2008 | Error HWC2On1Adapter::Layer::setVisibleRegion(hwc_region_t visible) { | 2015 | Error HWC2On1Adapter::Layer::setVisibleRegion(hwc_region_t visible) { |
2009 | mVisibleRegion.resize(visible.numRects); | 2016 | if ((getNumVisibleRegions() != visible.numRects) || |
2010 | std::copy_n(visible.rects, visible.numRects, mVisibleRegion.begin()); | 2017 | !std::equal(mVisibleRegion.begin(), mVisibleRegion.end(), visible.rects, |
2011 | mDisplay.markGeometryChanged(); | 2018 | compareRects)) { |
2019 | mVisibleRegion.resize(visible.numRects); | ||
2020 | std::copy_n(visible.rects, visible.numRects, mVisibleRegion.begin()); | ||
2021 | mDisplay.markGeometryChanged(); | ||
2022 | } | ||
2012 | return Error::None; | 2023 | return Error::None; |
2013 | } | 2024 | } |
2014 | 2025 | ||
diff --git a/libs/vr/libvrflinger/display_manager_service.cpp b/libs/vr/libvrflinger/display_manager_service.cpp index 40396b90c..ef8cca38d 100644 --- a/libs/vr/libvrflinger/display_manager_service.cpp +++ b/libs/vr/libvrflinger/display_manager_service.cpp | |||
@@ -65,6 +65,7 @@ void DisplayManagerService::OnChannelClose( | |||
65 | } | 65 | } |
66 | 66 | ||
67 | pdx::Status<void> DisplayManagerService::HandleMessage(pdx::Message& message) { | 67 | pdx::Status<void> DisplayManagerService::HandleMessage(pdx::Message& message) { |
68 | ATRACE_NAME("DisplayManagerService::HandleMessage"); | ||
68 | auto channel = std::static_pointer_cast<DisplayManager>(message.GetChannel()); | 69 | auto channel = std::static_pointer_cast<DisplayManager>(message.GetChannel()); |
69 | 70 | ||
70 | switch (message.GetOp()) { | 71 | switch (message.GetOp()) { |
diff --git a/libs/vr/libvrflinger/display_service.cpp b/libs/vr/libvrflinger/display_service.cpp index 10abc5efa..ac68a5e3a 100644 --- a/libs/vr/libvrflinger/display_service.cpp +++ b/libs/vr/libvrflinger/display_service.cpp | |||
@@ -124,6 +124,8 @@ void DisplayService::OnChannelClose(pdx::Message& message, | |||
124 | // surface-specific messages to the per-instance handlers. | 124 | // surface-specific messages to the per-instance handlers. |
125 | Status<void> DisplayService::HandleMessage(pdx::Message& message) { | 125 | Status<void> DisplayService::HandleMessage(pdx::Message& message) { |
126 | ALOGD_IF(TRACE, "DisplayService::HandleMessage: opcode=%d", message.GetOp()); | 126 | ALOGD_IF(TRACE, "DisplayService::HandleMessage: opcode=%d", message.GetOp()); |
127 | ATRACE_NAME("DisplayService::HandleMessage"); | ||
128 | |||
127 | switch (message.GetOp()) { | 129 | switch (message.GetOp()) { |
128 | case DisplayProtocol::GetMetrics::Opcode: | 130 | case DisplayProtocol::GetMetrics::Opcode: |
129 | DispatchRemoteMethod<DisplayProtocol::GetMetrics>( | 131 | DispatchRemoteMethod<DisplayProtocol::GetMetrics>( |
diff --git a/libs/vr/libvrflinger/hardware_composer.cpp b/libs/vr/libvrflinger/hardware_composer.cpp index 0bf1d2b5a..de6477b1e 100644 --- a/libs/vr/libvrflinger/hardware_composer.cpp +++ b/libs/vr/libvrflinger/hardware_composer.cpp | |||
@@ -5,12 +5,14 @@ | |||
5 | #include <fcntl.h> | 5 | #include <fcntl.h> |
6 | #include <log/log.h> | 6 | #include <log/log.h> |
7 | #include <poll.h> | 7 | #include <poll.h> |
8 | #include <stdint.h> | ||
8 | #include <sync/sync.h> | 9 | #include <sync/sync.h> |
9 | #include <sys/eventfd.h> | 10 | #include <sys/eventfd.h> |
10 | #include <sys/prctl.h> | 11 | #include <sys/prctl.h> |
11 | #include <sys/resource.h> | 12 | #include <sys/resource.h> |
12 | #include <sys/system_properties.h> | 13 | #include <sys/system_properties.h> |
13 | #include <sys/timerfd.h> | 14 | #include <sys/timerfd.h> |
15 | #include <sys/types.h> | ||
14 | #include <time.h> | 16 | #include <time.h> |
15 | #include <unistd.h> | 17 | #include <unistd.h> |
16 | #include <utils/Trace.h> | 18 | #include <utils/Trace.h> |
@@ -30,7 +32,9 @@ | |||
30 | 32 | ||
31 | using android::hardware::Return; | 33 | using android::hardware::Return; |
32 | using android::hardware::Void; | 34 | using android::hardware::Void; |
35 | using android::pdx::ErrorStatus; | ||
33 | using android::pdx::LocalHandle; | 36 | using android::pdx::LocalHandle; |
37 | using android::pdx::Status; | ||
34 | using android::pdx::rpc::EmptyVariant; | 38 | using android::pdx::rpc::EmptyVariant; |
35 | using android::pdx::rpc::IfAnyOf; | 39 | using android::pdx::rpc::IfAnyOf; |
36 | 40 | ||
@@ -82,6 +86,29 @@ bool SetThreadPolicy(const std::string& scheduler_class, | |||
82 | return true; | 86 | return true; |
83 | } | 87 | } |
84 | 88 | ||
89 | // Utility to generate scoped tracers with arguments. | ||
90 | // TODO(eieio): Move/merge this into utils/Trace.h? | ||
91 | class TraceArgs { | ||
92 | public: | ||
93 | template <typename... Args> | ||
94 | TraceArgs(const char* format, Args&&... args) { | ||
95 | std::array<char, 1024> buffer; | ||
96 | snprintf(buffer.data(), buffer.size(), format, std::forward<Args>(args)...); | ||
97 | atrace_begin(ATRACE_TAG, buffer.data()); | ||
98 | } | ||
99 | |||
100 | ~TraceArgs() { atrace_end(ATRACE_TAG); } | ||
101 | |||
102 | private: | ||
103 | TraceArgs(const TraceArgs&) = delete; | ||
104 | void operator=(const TraceArgs&) = delete; | ||
105 | }; | ||
106 | |||
107 | // Macro to define a scoped tracer with arguments. Uses PASTE(x, y) macro | ||
108 | // defined in utils/Trace.h. | ||
109 | #define TRACE_FORMAT(format, ...) \ | ||
110 | TraceArgs PASTE(__tracer, __LINE__) { format, ##__VA_ARGS__ } | ||
111 | |||
85 | } // anonymous namespace | 112 | } // anonymous namespace |
86 | 113 | ||
87 | HardwareComposer::HardwareComposer() | 114 | HardwareComposer::HardwareComposer() |
@@ -411,14 +438,12 @@ void HardwareComposer::PostLayers() { | |||
411 | retire_fence_fds_.erase(retire_fence_fds_.begin()); | 438 | retire_fence_fds_.erase(retire_fence_fds_.begin()); |
412 | } | 439 | } |
413 | 440 | ||
414 | const bool is_frame_pending = IsFramePendingInDriver(); | ||
415 | const bool is_fence_pending = static_cast<int32_t>(retire_fence_fds_.size()) > | 441 | const bool is_fence_pending = static_cast<int32_t>(retire_fence_fds_.size()) > |
416 | post_thread_config_.allowed_pending_fence_count; | 442 | post_thread_config_.allowed_pending_fence_count; |
417 | 443 | ||
418 | if (is_fence_pending || is_frame_pending) { | 444 | if (is_fence_pending) { |
419 | ATRACE_INT("frame_skip_count", ++frame_skip_count_); | 445 | ATRACE_INT("frame_skip_count", ++frame_skip_count_); |
420 | 446 | ||
421 | ALOGW_IF(is_frame_pending, "Warning: frame already queued, dropping frame"); | ||
422 | ALOGW_IF(is_fence_pending, | 447 | ALOGW_IF(is_fence_pending, |
423 | "Warning: dropping a frame to catch up with HWC (pending = %zd)", | 448 | "Warning: dropping a frame to catch up with HWC (pending = %zd)", |
424 | retire_fence_fds_.size()); | 449 | retire_fence_fds_.size()); |
@@ -587,18 +612,28 @@ int HardwareComposer::PostThreadPollInterruptible( | |||
587 | } | 612 | } |
588 | } | 613 | } |
589 | 614 | ||
615 | Status<int64_t> HardwareComposer::GetVSyncTime() { | ||
616 | auto status = composer_callback_->GetVsyncTime(HWC_DISPLAY_PRIMARY); | ||
617 | ALOGE_IF(!status, | ||
618 | "HardwareComposer::GetVSyncTime: Failed to get vsync timestamp: %s", | ||
619 | status.GetErrorMessage().c_str()); | ||
620 | return status; | ||
621 | } | ||
622 | |||
590 | // Waits for the next vsync and returns the timestamp of the vsync event. If | 623 | // Waits for the next vsync and returns the timestamp of the vsync event. If |
591 | // vsync already passed since the last call, returns the latest vsync timestamp | 624 | // vsync already passed since the last call, returns the latest vsync timestamp |
592 | // instead of blocking. | 625 | // instead of blocking. |
593 | int HardwareComposer::WaitForVSync(int64_t* timestamp) { | 626 | Status<int64_t> HardwareComposer::WaitForVSync() { |
594 | int error = PostThreadPollInterruptible(composer_callback_->GetVsyncEventFd(), | 627 | const int64_t predicted_vsync_time = |
595 | POLLIN, /*timeout_ms*/ 1000); | 628 | last_vsync_timestamp_ + |
596 | if (error == kPostThreadInterrupted || error < 0) { | 629 | display_metrics_.vsync_period_ns * vsync_prediction_interval_; |
630 | const int error = SleepUntil(predicted_vsync_time); | ||
631 | if (error < 0) { | ||
632 | ALOGE("HardwareComposer::WaifForVSync:: Failed to sleep: %s", | ||
633 | strerror(-error)); | ||
597 | return error; | 634 | return error; |
598 | } else { | ||
599 | *timestamp = composer_callback_->GetVsyncTime(); | ||
600 | return 0; | ||
601 | } | 635 | } |
636 | return {predicted_vsync_time}; | ||
602 | } | 637 | } |
603 | 638 | ||
604 | int HardwareComposer::SleepUntil(int64_t wakeup_timestamp) { | 639 | int HardwareComposer::SleepUntil(int64_t wakeup_timestamp) { |
@@ -704,26 +739,41 @@ void HardwareComposer::PostThread() { | |||
704 | thread_policy_setup = | 739 | thread_policy_setup = |
705 | SetThreadPolicy("graphics:high", "/system/performance"); | 740 | SetThreadPolicy("graphics:high", "/system/performance"); |
706 | } | 741 | } |
742 | |||
743 | // Initialize the last vsync timestamp with the current time. The | ||
744 | // predictor below uses this time + the vsync interval in absolute time | ||
745 | // units for the initial delay. Once the driver starts reporting vsync the | ||
746 | // predictor will sync up with the real vsync. | ||
747 | last_vsync_timestamp_ = GetSystemClockNs(); | ||
707 | } | 748 | } |
708 | 749 | ||
709 | int64_t vsync_timestamp = 0; | 750 | int64_t vsync_timestamp = 0; |
710 | { | 751 | { |
711 | std::array<char, 128> buf; | 752 | TRACE_FORMAT("wait_vsync|vsync=%u;last_timestamp=%" PRId64 |
712 | snprintf(buf.data(), buf.size(), "wait_vsync|vsync=%d|", | 753 | ";prediction_interval=%d|", |
713 | vsync_count_ + 1); | 754 | vsync_count_ + 1, last_vsync_timestamp_, |
714 | ATRACE_NAME(buf.data()); | 755 | vsync_prediction_interval_); |
715 | 756 | ||
716 | const int error = WaitForVSync(&vsync_timestamp); | 757 | auto status = WaitForVSync(); |
717 | ALOGE_IF( | 758 | ALOGE_IF( |
718 | error < 0, | 759 | !status, |
719 | "HardwareComposer::PostThread: Failed to wait for vsync event: %s", | 760 | "HardwareComposer::PostThread: Failed to wait for vsync event: %s", |
720 | strerror(-error)); | 761 | status.GetErrorMessage().c_str()); |
721 | // Don't bother processing this frame if a pause was requested | 762 | |
722 | if (error == kPostThreadInterrupted) | 763 | // If there was an error either sleeping was interrupted due to pausing or |
764 | // there was an error getting the latest timestamp. | ||
765 | if (!status) | ||
723 | continue; | 766 | continue; |
767 | |||
768 | // Predicted vsync timestamp for this interval. This is stable because we | ||
769 | // use absolute time for the wakeup timer. | ||
770 | vsync_timestamp = status.get(); | ||
724 | } | 771 | } |
725 | 772 | ||
726 | ++vsync_count_; | 773 | // Advance the vsync counter only if the system is keeping up with hardware |
774 | // vsync to give clients an indication of the delays. | ||
775 | if (vsync_prediction_interval_ == 1) | ||
776 | ++vsync_count_; | ||
727 | 777 | ||
728 | const bool layer_config_changed = UpdateLayerConfig(); | 778 | const bool layer_config_changed = UpdateLayerConfig(); |
729 | 779 | ||
@@ -773,6 +823,38 @@ void HardwareComposer::PostThread() { | |||
773 | } | 823 | } |
774 | } | 824 | } |
775 | 825 | ||
826 | { | ||
827 | auto status = GetVSyncTime(); | ||
828 | if (!status) { | ||
829 | ALOGE("HardwareComposer::PostThread: Failed to get VSYNC time: %s", | ||
830 | status.GetErrorMessage().c_str()); | ||
831 | } | ||
832 | |||
833 | // If we failed to read vsync there might be a problem with the driver. | ||
834 | // Since there's nothing we can do just behave as though we didn't get an | ||
835 | // updated vsync time and let the prediction continue. | ||
836 | const int64_t current_vsync_timestamp = | ||
837 | status ? status.get() : last_vsync_timestamp_; | ||
838 | |||
839 | const bool vsync_delayed = | ||
840 | last_vsync_timestamp_ == current_vsync_timestamp; | ||
841 | ATRACE_INT("vsync_delayed", vsync_delayed); | ||
842 | |||
843 | // If vsync was delayed advance the prediction interval and allow the | ||
844 | // fence logic in PostLayers() to skip the frame. | ||
845 | if (vsync_delayed) { | ||
846 | ALOGW( | ||
847 | "HardwareComposer::PostThread: VSYNC timestamp did not advance " | ||
848 | "since last frame: timestamp=%" PRId64 " prediction_interval=%d", | ||
849 | current_vsync_timestamp, vsync_prediction_interval_); | ||
850 | vsync_prediction_interval_++; | ||
851 | } else { | ||
852 | // We have an updated vsync timestamp, reset the prediction interval. | ||
853 | last_vsync_timestamp_ = current_vsync_timestamp; | ||
854 | vsync_prediction_interval_ = 1; | ||
855 | } | ||
856 | } | ||
857 | |||
776 | PostLayers(); | 858 | PostLayers(); |
777 | } | 859 | } |
778 | } | 860 | } |
@@ -860,14 +942,28 @@ void HardwareComposer::SetBacklightBrightness(int brightness) { | |||
860 | } | 942 | } |
861 | } | 943 | } |
862 | 944 | ||
863 | HardwareComposer::ComposerCallback::ComposerCallback() { | ||
864 | vsync_event_fd_.Reset(eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK)); | ||
865 | LOG_ALWAYS_FATAL_IF(!vsync_event_fd_, "Failed to create vsync event fd : %s", | ||
866 | strerror(errno)); | ||
867 | } | ||
868 | |||
869 | Return<void> HardwareComposer::ComposerCallback::onHotplug( | 945 | Return<void> HardwareComposer::ComposerCallback::onHotplug( |
870 | Hwc2::Display /*display*/, IComposerCallback::Connection /*conn*/) { | 946 | Hwc2::Display display, IComposerCallback::Connection /*conn*/) { |
947 | // See if the driver supports the vsync_event node in sysfs. | ||
948 | if (display < HWC_NUM_PHYSICAL_DISPLAY_TYPES && | ||
949 | !displays_[display].driver_vsync_event_fd) { | ||
950 | std::array<char, 1024> buffer; | ||
951 | snprintf(buffer.data(), buffer.size(), | ||
952 | "/sys/class/graphics/fb%" PRIu64 "/vsync_event", display); | ||
953 | if (LocalHandle handle{buffer.data(), O_RDONLY}) { | ||
954 | ALOGI( | ||
955 | "HardwareComposer::ComposerCallback::onHotplug: Driver supports " | ||
956 | "vsync_event node for display %" PRIu64, | ||
957 | display); | ||
958 | displays_[display].driver_vsync_event_fd = std::move(handle); | ||
959 | } else { | ||
960 | ALOGI( | ||
961 | "HardwareComposer::ComposerCallback::onHotplug: Driver does not " | ||
962 | "support vsync_event node for display %" PRIu64, | ||
963 | display); | ||
964 | } | ||
965 | } | ||
966 | |||
871 | return Void(); | 967 | return Void(); |
872 | } | 968 | } |
873 | 969 | ||
@@ -878,29 +974,81 @@ Return<void> HardwareComposer::ComposerCallback::onRefresh( | |||
878 | 974 | ||
879 | Return<void> HardwareComposer::ComposerCallback::onVsync(Hwc2::Display display, | 975 | Return<void> HardwareComposer::ComposerCallback::onVsync(Hwc2::Display display, |
880 | int64_t timestamp) { | 976 | int64_t timestamp) { |
881 | if (display == HWC_DISPLAY_PRIMARY) { | 977 | TRACE_FORMAT("vsync_callback|display=%" PRIu64 ";timestamp=%" PRId64 "|", |
882 | std::lock_guard<std::mutex> lock(vsync_mutex_); | 978 | display, timestamp); |
883 | vsync_time_ = timestamp; | 979 | if (display < HWC_NUM_PHYSICAL_DISPLAY_TYPES) { |
884 | int error = eventfd_write(vsync_event_fd_.Get(), 1); | 980 | displays_[display].callback_vsync_timestamp = timestamp; |
885 | LOG_ALWAYS_FATAL_IF(error != 0, "Failed writing to vsync event fd"); | 981 | } else { |
982 | ALOGW( | ||
983 | "HardwareComposer::ComposerCallback::onVsync: Received vsync on " | ||
984 | "non-physical display: display=%" PRId64, | ||
985 | display); | ||
886 | } | 986 | } |
887 | return Void(); | 987 | return Void(); |
888 | } | 988 | } |
889 | 989 | ||
890 | const pdx::LocalHandle& HardwareComposer::ComposerCallback::GetVsyncEventFd() | 990 | Status<int64_t> HardwareComposer::ComposerCallback::GetVsyncTime( |
891 | const { | 991 | Hwc2::Display display) { |
892 | return vsync_event_fd_; | 992 | if (display >= HWC_NUM_PHYSICAL_DISPLAY_TYPES) { |
893 | } | 993 | ALOGE( |
994 | "HardwareComposer::ComposerCallback::GetVsyncTime: Invalid physical " | ||
995 | "display requested: display=%" PRIu64, | ||
996 | display); | ||
997 | return ErrorStatus(EINVAL); | ||
998 | } | ||
999 | |||
1000 | // See if the driver supports direct vsync events. | ||
1001 | LocalHandle& event_fd = displays_[display].driver_vsync_event_fd; | ||
1002 | if (!event_fd) { | ||
1003 | // Fall back to returning the last timestamp returned by the vsync | ||
1004 | // callback. | ||
1005 | std::lock_guard<std::mutex> autolock(vsync_mutex_); | ||
1006 | return displays_[display].callback_vsync_timestamp; | ||
1007 | } | ||
1008 | |||
1009 | // When the driver supports the vsync_event sysfs node we can use it to | ||
1010 | // determine the latest vsync timestamp, even if the HWC callback has been | ||
1011 | // delayed. | ||
1012 | |||
1013 | // The driver returns data in the form "VSYNC=<timestamp ns>". | ||
1014 | std::array<char, 32> data; | ||
1015 | data.fill('\0'); | ||
1016 | |||
1017 | // Seek back to the beginning of the event file. | ||
1018 | int ret = lseek(event_fd.Get(), 0, SEEK_SET); | ||
1019 | if (ret < 0) { | ||
1020 | const int error = errno; | ||
1021 | ALOGE( | ||
1022 | "HardwareComposer::ComposerCallback::GetVsyncTime: Failed to seek " | ||
1023 | "vsync event fd: %s", | ||
1024 | strerror(error)); | ||
1025 | return ErrorStatus(error); | ||
1026 | } | ||
1027 | |||
1028 | // Read the vsync event timestamp. | ||
1029 | ret = read(event_fd.Get(), data.data(), data.size()); | ||
1030 | if (ret < 0) { | ||
1031 | const int error = errno; | ||
1032 | ALOGE_IF(error != EAGAIN, | ||
1033 | "HardwareComposer::ComposerCallback::GetVsyncTime: Error " | ||
1034 | "while reading timestamp: %s", | ||
1035 | strerror(error)); | ||
1036 | return ErrorStatus(error); | ||
1037 | } | ||
1038 | |||
1039 | int64_t timestamp; | ||
1040 | ret = sscanf(data.data(), "VSYNC=%" PRIu64, | ||
1041 | reinterpret_cast<uint64_t*>(×tamp)); | ||
1042 | if (ret < 0) { | ||
1043 | const int error = errno; | ||
1044 | ALOGE( | ||
1045 | "HardwareComposer::ComposerCallback::GetVsyncTime: Error while " | ||
1046 | "parsing timestamp: %s", | ||
1047 | strerror(error)); | ||
1048 | return ErrorStatus(error); | ||
1049 | } | ||
894 | 1050 | ||
895 | int64_t HardwareComposer::ComposerCallback::GetVsyncTime() { | 1051 | return {timestamp}; |
896 | std::lock_guard<std::mutex> lock(vsync_mutex_); | ||
897 | eventfd_t event; | ||
898 | eventfd_read(vsync_event_fd_.Get(), &event); | ||
899 | LOG_ALWAYS_FATAL_IF(vsync_time_ < 0, | ||
900 | "Attempt to read vsync time before vsync event"); | ||
901 | int64_t return_val = vsync_time_; | ||
902 | vsync_time_ = -1; | ||
903 | return return_val; | ||
904 | } | 1052 | } |
905 | 1053 | ||
906 | Hwc2::Composer* Layer::composer_{nullptr}; | 1054 | Hwc2::Composer* Layer::composer_{nullptr}; |
diff --git a/libs/vr/libvrflinger/hardware_composer.h b/libs/vr/libvrflinger/hardware_composer.h index 793c3e887..8131e5098 100644 --- a/libs/vr/libvrflinger/hardware_composer.h +++ b/libs/vr/libvrflinger/hardware_composer.h | |||
@@ -142,9 +142,7 @@ class Layer { | |||
142 | bool operator<(const Layer& other) const { | 142 | bool operator<(const Layer& other) const { |
143 | return GetSurfaceId() < other.GetSurfaceId(); | 143 | return GetSurfaceId() < other.GetSurfaceId(); |
144 | } | 144 | } |
145 | bool operator<(int surface_id) const { | 145 | bool operator<(int surface_id) const { return GetSurfaceId() < surface_id; } |
146 | return GetSurfaceId() < surface_id; | ||
147 | } | ||
148 | 146 | ||
149 | // Sets the composer instance used by all Layer instances. | 147 | // Sets the composer instance used by all Layer instances. |
150 | static void SetComposer(Hwc2::Composer* composer) { composer_ = composer; } | 148 | static void SetComposer(Hwc2::Composer* composer) { composer_ = composer; } |
@@ -340,19 +338,23 @@ class HardwareComposer { | |||
340 | 338 | ||
341 | class ComposerCallback : public Hwc2::IComposerCallback { | 339 | class ComposerCallback : public Hwc2::IComposerCallback { |
342 | public: | 340 | public: |
343 | ComposerCallback(); | 341 | ComposerCallback() = default; |
344 | hardware::Return<void> onHotplug(Hwc2::Display display, | 342 | hardware::Return<void> onHotplug(Hwc2::Display display, |
345 | Connection conn) override; | 343 | Connection conn) override; |
346 | hardware::Return<void> onRefresh(Hwc2::Display display) override; | 344 | hardware::Return<void> onRefresh(Hwc2::Display display) override; |
347 | hardware::Return<void> onVsync(Hwc2::Display display, | 345 | hardware::Return<void> onVsync(Hwc2::Display display, |
348 | int64_t timestamp) override; | 346 | int64_t timestamp) override; |
349 | const pdx::LocalHandle& GetVsyncEventFd() const; | 347 | |
350 | int64_t GetVsyncTime(); | 348 | pdx::Status<int64_t> GetVsyncTime(Hwc2::Display display); |
351 | 349 | ||
352 | private: | 350 | private: |
353 | std::mutex vsync_mutex_; | 351 | std::mutex vsync_mutex_; |
354 | pdx::LocalHandle vsync_event_fd_; | 352 | |
355 | int64_t vsync_time_ = -1; | 353 | struct Display { |
354 | pdx::LocalHandle driver_vsync_event_fd; | ||
355 | int64_t callback_vsync_timestamp{0}; | ||
356 | }; | ||
357 | std::array<Display, HWC_NUM_PHYSICAL_DISPLAY_TYPES> displays_; | ||
356 | }; | 358 | }; |
357 | 359 | ||
358 | HWC::Error Validate(hwc2_display_t display); | 360 | HWC::Error Validate(hwc2_display_t display); |
@@ -392,11 +394,10 @@ class HardwareComposer { | |||
392 | // can be interrupted by a control thread. If interrupted, these calls return | 394 | // can be interrupted by a control thread. If interrupted, these calls return |
393 | // kPostThreadInterrupted. | 395 | // kPostThreadInterrupted. |
394 | int ReadWaitPPState(); | 396 | int ReadWaitPPState(); |
395 | int WaitForVSync(int64_t* timestamp); | 397 | pdx::Status<int64_t> WaitForVSync(); |
398 | pdx::Status<int64_t> GetVSyncTime(); | ||
396 | int SleepUntil(int64_t wakeup_timestamp); | 399 | int SleepUntil(int64_t wakeup_timestamp); |
397 | 400 | ||
398 | bool IsFramePendingInDriver() { return false; } | ||
399 | |||
400 | // Reconfigures the layer stack if the display surfaces changed since the last | 401 | // Reconfigures the layer stack if the display surfaces changed since the last |
401 | // frame. Called only from the post thread. | 402 | // frame. Called only from the post thread. |
402 | bool UpdateLayerConfig(); | 403 | bool UpdateLayerConfig(); |
@@ -463,6 +464,9 @@ class HardwareComposer { | |||
463 | // The timestamp of the last vsync. | 464 | // The timestamp of the last vsync. |
464 | int64_t last_vsync_timestamp_ = 0; | 465 | int64_t last_vsync_timestamp_ = 0; |
465 | 466 | ||
467 | // The number of vsync intervals to predict since the last vsync. | ||
468 | int vsync_prediction_interval_ = 1; | ||
469 | |||
466 | // Vsync count since display on. | 470 | // Vsync count since display on. |
467 | uint32_t vsync_count_ = 0; | 471 | uint32_t vsync_count_ = 0; |
468 | 472 | ||
diff --git a/libs/vr/libvrflinger/vr_flinger.cpp b/libs/vr/libvrflinger/vr_flinger.cpp index fcf94f086..85dc586ea 100644 --- a/libs/vr/libvrflinger/vr_flinger.cpp +++ b/libs/vr/libvrflinger/vr_flinger.cpp | |||
@@ -64,9 +64,6 @@ bool VrFlinger::Init(Hwc2::Composer* hidl, | |||
64 | 64 | ||
65 | ALOGI("Starting up VrFlinger..."); | 65 | ALOGI("Starting up VrFlinger..."); |
66 | 66 | ||
67 | setpriority(PRIO_PROCESS, 0, android::PRIORITY_URGENT_DISPLAY); | ||
68 | set_sched_policy(0, SP_FOREGROUND); | ||
69 | |||
70 | // We need to be able to create endpoints with full perms. | 67 | // We need to be able to create endpoints with full perms. |
71 | umask(0000); | 68 | umask(0000); |
72 | 69 | ||
@@ -100,6 +97,9 @@ bool VrFlinger::Init(Hwc2::Composer* hidl, | |||
100 | prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("VrDispatch"), 0, 0, 0); | 97 | prctl(PR_SET_NAME, reinterpret_cast<unsigned long>("VrDispatch"), 0, 0, 0); |
101 | ALOGI("Entering message loop."); | 98 | ALOGI("Entering message loop."); |
102 | 99 | ||
100 | setpriority(PRIO_PROCESS, 0, android::PRIORITY_URGENT_DISPLAY); | ||
101 | set_sched_policy(0, SP_FOREGROUND); | ||
102 | |||
103 | int ret = dispatcher_->EnterDispatchLoop(); | 103 | int ret = dispatcher_->EnterDispatchLoop(); |
104 | if (ret < 0) { | 104 | if (ret < 0) { |
105 | ALOGE("Dispatch loop exited because: %s\n", strerror(-ret)); | 105 | ALOGE("Dispatch loop exited because: %s\n", strerror(-ret)); |
diff --git a/libs/vr/libvrflinger/vsync_service.cpp b/libs/vr/libvrflinger/vsync_service.cpp index 3098b4331..fdeb899f6 100644 --- a/libs/vr/libvrflinger/vsync_service.cpp +++ b/libs/vr/libvrflinger/vsync_service.cpp | |||
@@ -110,6 +110,7 @@ void VSyncService::UpdateClients() { | |||
110 | } | 110 | } |
111 | 111 | ||
112 | pdx::Status<void> VSyncService::HandleMessage(pdx::Message& message) { | 112 | pdx::Status<void> VSyncService::HandleMessage(pdx::Message& message) { |
113 | ATRACE_NAME("VSyncService::HandleMessage"); | ||
113 | switch (message.GetOp()) { | 114 | switch (message.GetOp()) { |
114 | case VSyncProtocol::Wait::Opcode: | 115 | case VSyncProtocol::Wait::Opcode: |
115 | AddWaiter(message); | 116 | AddWaiter(message); |
diff --git a/services/inputflinger/InputWindow.cpp b/services/inputflinger/InputWindow.cpp index b54752b08..3ae797277 100644 --- a/services/inputflinger/InputWindow.cpp +++ b/services/inputflinger/InputWindow.cpp | |||
@@ -49,7 +49,8 @@ bool InputWindowInfo::isTrustedOverlay() const { | |||
49 | || layoutParamsType == TYPE_NAVIGATION_BAR_PANEL | 49 | || layoutParamsType == TYPE_NAVIGATION_BAR_PANEL |
50 | || layoutParamsType == TYPE_SECURE_SYSTEM_OVERLAY | 50 | || layoutParamsType == TYPE_SECURE_SYSTEM_OVERLAY |
51 | || layoutParamsType == TYPE_DOCK_DIVIDER | 51 | || layoutParamsType == TYPE_DOCK_DIVIDER |
52 | || layoutParamsType == TYPE_ACCESSIBILITY_OVERLAY; | 52 | || layoutParamsType == TYPE_ACCESSIBILITY_OVERLAY |
53 | || layoutParamsType == TYPE_INPUT_CONSUMER; | ||
53 | } | 54 | } |
54 | 55 | ||
55 | bool InputWindowInfo::supportsSplitTouch() const { | 56 | bool InputWindowInfo::supportsSplitTouch() const { |
diff --git a/services/inputflinger/InputWindow.h b/services/inputflinger/InputWindow.h index 610290b2e..9eb27983c 100644 --- a/services/inputflinger/InputWindow.h +++ b/services/inputflinger/InputWindow.h | |||
@@ -101,6 +101,7 @@ struct InputWindowInfo { | |||
101 | TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19, | 101 | TYPE_NAVIGATION_BAR = FIRST_SYSTEM_WINDOW+19, |
102 | TYPE_VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW+20, | 102 | TYPE_VOLUME_OVERLAY = FIRST_SYSTEM_WINDOW+20, |
103 | TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21, | 103 | TYPE_BOOT_PROGRESS = FIRST_SYSTEM_WINDOW+21, |
104 | TYPE_INPUT_CONSUMER = FIRST_SYSTEM_WINDOW+22, | ||
104 | TYPE_NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW+24, | 105 | TYPE_NAVIGATION_BAR_PANEL = FIRST_SYSTEM_WINDOW+24, |
105 | TYPE_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW+27, | 106 | TYPE_MAGNIFICATION_OVERLAY = FIRST_SYSTEM_WINDOW+27, |
106 | TYPE_ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW+32, | 107 | TYPE_ACCESSIBILITY_OVERLAY = FIRST_SYSTEM_WINDOW+32, |