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