Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 1 | #include "include/private/dvr/vsync_client.h" |
| 2 | |
Alex Vakulenko | 4fe6058 | 2017-02-02 11:35:59 -0800 | [diff] [blame] | 3 | #include <log/log.h> |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 4 | |
| 5 | #include <pdx/default_transport/client_channel_factory.h> |
Corey Tabaka | 3f82d31 | 2017-04-20 14:42:08 -0700 | [diff] [blame] | 6 | #include <private/dvr/display_protocol.h> |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 7 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 8 | using android::dvr::display::VSyncProtocol; |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 9 | using android::pdx::Transaction; |
| 10 | |
| 11 | namespace android { |
| 12 | namespace dvr { |
| 13 | |
| 14 | VSyncClient::VSyncClient(long timeout_ms) |
| 15 | : BASE(pdx::default_transport::ClientChannelFactory::Create( |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 16 | VSyncProtocol::kClientPath), |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 17 | timeout_ms) {} |
| 18 | |
| 19 | VSyncClient::VSyncClient() |
| 20 | : BASE(pdx::default_transport::ClientChannelFactory::Create( |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 21 | VSyncProtocol::kClientPath)) {} |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 22 | |
| 23 | int VSyncClient::Wait(int64_t* timestamp_ns) { |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 24 | auto status = InvokeRemoteMethod<VSyncProtocol::Wait>(); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 25 | if (!status) { |
| 26 | ALOGE("VSyncClient::Wait: Failed to wait for vsync: %s", |
| 27 | status.GetErrorMessage().c_str()); |
| 28 | return -status.error(); |
| 29 | } |
Okan Arikan | b4213f7 | 2017-02-03 15:06:35 -0800 | [diff] [blame] | 30 | |
| 31 | if (timestamp_ns != nullptr) { |
| 32 | *timestamp_ns = status.get(); |
| 33 | } |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | int VSyncClient::GetFd() { return event_fd(); } |
| 38 | |
| 39 | int VSyncClient::GetLastTimestamp(int64_t* timestamp_ns) { |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 40 | auto status = InvokeRemoteMethod<VSyncProtocol::GetLastTimestamp>(); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 41 | if (!status) { |
| 42 | ALOGE("VSyncClient::GetLastTimestamp: Failed to get vsync timestamp: %s", |
| 43 | status.GetErrorMessage().c_str()); |
| 44 | return -status.error(); |
| 45 | } |
| 46 | *timestamp_ns = status.get(); |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | int VSyncClient::GetSchedInfo(int64_t* vsync_period_ns, int64_t* timestamp_ns, |
| 51 | uint32_t* next_vsync_count) { |
| 52 | if (!vsync_period_ns || !timestamp_ns || !next_vsync_count) |
| 53 | return -EINVAL; |
| 54 | |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 55 | auto status = InvokeRemoteMethod<VSyncProtocol::GetSchedInfo>(); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 56 | if (!status) { |
| 57 | ALOGE("VSyncClient::GetSchedInfo:: Failed to get warp timestamp: %s", |
| 58 | status.GetErrorMessage().c_str()); |
| 59 | return -status.error(); |
| 60 | } |
| 61 | |
| 62 | *vsync_period_ns = status.get().vsync_period_ns; |
| 63 | *timestamp_ns = status.get().timestamp_ns; |
| 64 | *next_vsync_count = status.get().next_vsync_count; |
| 65 | return 0; |
| 66 | } |
| 67 | |
| 68 | int VSyncClient::Acknowledge() { |
Corey Tabaka | 2251d82 | 2017-04-20 16:04:07 -0700 | [diff] [blame] | 69 | auto status = InvokeRemoteMethod<VSyncProtocol::Acknowledge>(); |
Alex Vakulenko | e4eec20 | 2017-01-27 14:41:04 -0800 | [diff] [blame] | 70 | ALOGE_IF(!status, "VSuncClient::Acknowledge: Failed to ack vsync because: %s", |
| 71 | status.GetErrorMessage().c_str()); |
| 72 | return ReturnStatusOrError(status); |
| 73 | } |
| 74 | |
| 75 | } // namespace dvr |
| 76 | } // namespace android |