blob: bc6cf6cabe08291b888f9d4a1c562a6d3f8372a9 [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>
Corey Tabaka3f82d312017-04-20 14:42:08 -07006#include <private/dvr/display_protocol.h>
Alex Vakulenkoe4eec202017-01-27 14:41:04 -08007
Corey Tabaka2251d822017-04-20 16:04:07 -07008using android::dvr::display::VSyncProtocol;
Alex Vakulenkoe4eec202017-01-27 14:41:04 -08009using android::pdx::Transaction;
10
11namespace android {
12namespace dvr {
13
14VSyncClient::VSyncClient(long timeout_ms)
15 : BASE(pdx::default_transport::ClientChannelFactory::Create(
Corey Tabaka2251d822017-04-20 16:04:07 -070016 VSyncProtocol::kClientPath),
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080017 timeout_ms) {}
18
19VSyncClient::VSyncClient()
20 : BASE(pdx::default_transport::ClientChannelFactory::Create(
Corey Tabaka2251d822017-04-20 16:04:07 -070021 VSyncProtocol::kClientPath)) {}
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080022
23int VSyncClient::Wait(int64_t* timestamp_ns) {
Corey Tabaka2251d822017-04-20 16:04:07 -070024 auto status = InvokeRemoteMethod<VSyncProtocol::Wait>();
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080025 if (!status) {
26 ALOGE("VSyncClient::Wait: Failed to wait for vsync: %s",
27 status.GetErrorMessage().c_str());
28 return -status.error();
29 }
Okan Arikanb4213f72017-02-03 15:06:35 -080030
31 if (timestamp_ns != nullptr) {
32 *timestamp_ns = status.get();
33 }
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080034 return 0;
35}
36
37int VSyncClient::GetFd() { return event_fd(); }
38
39int VSyncClient::GetLastTimestamp(int64_t* timestamp_ns) {
Corey Tabaka2251d822017-04-20 16:04:07 -070040 auto status = InvokeRemoteMethod<VSyncProtocol::GetLastTimestamp>();
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080041 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
50int 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 Tabaka2251d822017-04-20 16:04:07 -070055 auto status = InvokeRemoteMethod<VSyncProtocol::GetSchedInfo>();
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080056 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
68int VSyncClient::Acknowledge() {
Corey Tabaka2251d822017-04-20 16:04:07 -070069 auto status = InvokeRemoteMethod<VSyncProtocol::Acknowledge>();
Alex Vakulenkoe4eec202017-01-27 14:41:04 -080070 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