• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_protocol.h>
7 
8 using android::dvr::display::VSyncProtocol;
9 using android::pdx::Transaction;
10 
11 namespace android {
12 namespace dvr {
13 
VSyncClient(long timeout_ms)14 VSyncClient::VSyncClient(long timeout_ms)
15     : BASE(pdx::default_transport::ClientChannelFactory::Create(
16                VSyncProtocol::kClientPath),
17            timeout_ms) {}
18 
VSyncClient()19 VSyncClient::VSyncClient()
20     : BASE(pdx::default_transport::ClientChannelFactory::Create(
21           VSyncProtocol::kClientPath)) {}
22 
Wait(int64_t * timestamp_ns)23 int VSyncClient::Wait(int64_t* timestamp_ns) {
24   auto status = InvokeRemoteMethod<VSyncProtocol::Wait>();
25   if (!status) {
26     ALOGE("VSyncClient::Wait: Failed to wait for vsync: %s",
27           status.GetErrorMessage().c_str());
28     return -status.error();
29   }
30 
31   if (timestamp_ns != nullptr) {
32     *timestamp_ns = status.get();
33   }
34   return 0;
35 }
36 
GetFd()37 int VSyncClient::GetFd() { return event_fd(); }
38 
GetLastTimestamp(int64_t * timestamp_ns)39 int VSyncClient::GetLastTimestamp(int64_t* timestamp_ns) {
40   auto status = InvokeRemoteMethod<VSyncProtocol::GetLastTimestamp>();
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 
GetSchedInfo(int64_t * vsync_period_ns,int64_t * timestamp_ns,uint32_t * next_vsync_count)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 
55   auto status = InvokeRemoteMethod<VSyncProtocol::GetSchedInfo>();
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 
Acknowledge()68 int VSyncClient::Acknowledge() {
69   auto status = InvokeRemoteMethod<VSyncProtocol::Acknowledge>();
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
77