vsync_client.cpp revision 4fe60582f314e381098f8f3bc2e39c5880e9243a
1#include "include/private/dvr/vsync_client.h"
2
3#include <log/log.h>
4
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  }
29  *timestamp_ns = status.get();
30  return 0;
31}
32
33int VSyncClient::GetFd() { return event_fd(); }
34
35int VSyncClient::GetLastTimestamp(int64_t* timestamp_ns) {
36  auto status = InvokeRemoteMethod<DisplayVSyncRPC::GetLastTimestamp>();
37  if (!status) {
38    ALOGE("VSyncClient::GetLastTimestamp: Failed to get vsync timestamp: %s",
39          status.GetErrorMessage().c_str());
40    return -status.error();
41  }
42  *timestamp_ns = status.get();
43  return 0;
44}
45
46int VSyncClient::GetSchedInfo(int64_t* vsync_period_ns, int64_t* timestamp_ns,
47                              uint32_t* next_vsync_count) {
48  if (!vsync_period_ns || !timestamp_ns || !next_vsync_count)
49    return -EINVAL;
50
51  auto status = InvokeRemoteMethod<DisplayVSyncRPC::GetSchedInfo>();
52  if (!status) {
53    ALOGE("VSyncClient::GetSchedInfo:: Failed to get warp timestamp: %s",
54          status.GetErrorMessage().c_str());
55    return -status.error();
56  }
57
58  *vsync_period_ns = status.get().vsync_period_ns;
59  *timestamp_ns = status.get().timestamp_ns;
60  *next_vsync_count = status.get().next_vsync_count;
61  return 0;
62}
63
64int VSyncClient::Acknowledge() {
65  auto status = InvokeRemoteMethod<DisplayVSyncRPC::Acknowledge>();
66  ALOGE_IF(!status, "VSuncClient::Acknowledge: Failed to ack vsync because: %s",
67           status.GetErrorMessage().c_str());
68  return ReturnStatusOrError(status);
69}
70
71}  // namespace dvr
72}  // namespace android
73