1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "vsync_connection_proxy.h"
17 #include "graphic_common.h"
18 #include "vsync_log.h"
19
20 namespace OHOS {
21 namespace Rosen {
VSyncConnectionProxy(const sptr<IRemoteObject> & impl)22 VSyncConnectionProxy::VSyncConnectionProxy(const sptr<IRemoteObject>& impl)
23 : IRemoteProxy<IVSyncConnection>(impl)
24 {
25 }
26
RequestNextVSync()27 VsyncError VSyncConnectionProxy::RequestNextVSync()
28 {
29 return RequestNextVSync("unknown", 0);
30 }
31
RequestNextVSync(const std::string & fromWhom,int64_t lastVSyncTS)32 VsyncError VSyncConnectionProxy::RequestNextVSync(const std::string& fromWhom, int64_t lastVSyncTS)
33 {
34 MessageOption opt(MessageOption::TF_ASYNC);
35 MessageParcel arg;
36 MessageParcel ret;
37
38 arg.WriteInterfaceToken(GetDescriptor());
39 int res = Remote()->SendRequest(IVSYNC_CONNECTION_REQUEST_NEXT_VSYNC, arg, ret, opt);
40 if (res != NO_ERROR) {
41 VLOGE("ipc send fail, error:%{public}d", res);
42 return VSYNC_ERROR_BINDER_ERROR;
43 }
44 return VSYNC_ERROR_OK;
45 }
46
SetUiDvsyncSwitch(bool dvsyncSwitch)47 VsyncError VSyncConnectionProxy::SetUiDvsyncSwitch(bool dvsyncSwitch)
48 {
49 MessageOption opt(MessageOption::TF_ASYNC);
50 MessageParcel arg;
51 MessageParcel ret;
52
53 arg.WriteInterfaceToken(GetDescriptor());
54 arg.WriteBool(dvsyncSwitch);
55 int res = Remote()->SendRequest(IVSYNC_CONNECTION_SET_UI_DVSYNC_SWITCH, arg, ret, opt);
56 if (res != NO_ERROR) {
57 VLOGE("ipc send fail, error:%{public}d", res);
58 return VSYNC_ERROR_UNKOWN;
59 }
60 return VSYNC_ERROR_OK;
61 }
62
SetUiDvsyncConfig(int32_t bufferCount)63 VsyncError VSyncConnectionProxy::SetUiDvsyncConfig(int32_t bufferCount)
64 {
65 MessageOption opt(MessageOption::TF_ASYNC);
66 MessageParcel arg;
67 MessageParcel ret;
68
69 arg.WriteInterfaceToken(GetDescriptor());
70 if (!arg.WriteInt32(bufferCount)) {
71 VLOGE("SetUiDvsyncConfig bufferCount error");
72 return VSYNC_ERROR_UNKOWN;
73 }
74 int res = Remote()->SendRequest(IVSYNC_CONNECTION_SET_UI_DVSYNC_CONFIG, arg, ret, opt);
75 if (res != NO_ERROR) {
76 return VSYNC_ERROR_UNKOWN;
77 }
78 return VSYNC_ERROR_OK;
79 }
80
GetReceiveFd(int32_t & fd)81 VsyncError VSyncConnectionProxy::GetReceiveFd(int32_t &fd)
82 {
83 MessageOption opt;
84 MessageParcel arg;
85 MessageParcel ret;
86
87 arg.WriteInterfaceToken(GetDescriptor());
88 int res = Remote()->SendRequest(IVSYNC_CONNECTION_GET_RECEIVE_FD, arg, ret, opt);
89 if (res != NO_ERROR) {
90 VLOGE("GetReceiveFd Failed, res = %{public}d", res);
91 return VSYNC_ERROR_BINDER_ERROR;
92 }
93 fd = ret.ReadFileDescriptor();
94 if (fd <= 0) {
95 VLOGE("GetReceiveFd Invalid fd:%{public}d", fd);
96 return VSYNC_ERROR_API_FAILED;
97 }
98 return VSYNC_ERROR_OK;
99 }
100
SetVSyncRate(int32_t rate)101 VsyncError VSyncConnectionProxy::SetVSyncRate(int32_t rate)
102 {
103 if (rate < -1) {
104 return VSYNC_ERROR_INVALID_ARGUMENTS;
105 }
106 MessageOption opt;
107 MessageParcel arg;
108 MessageParcel ret;
109
110 arg.WriteInterfaceToken(GetDescriptor());
111 arg.WriteInt32(rate);
112 int res = Remote()->SendRequest(IVSYNC_CONNECTION_SET_RATE, arg, ret, opt);
113 if (res != NO_ERROR) {
114 return VSYNC_ERROR_BINDER_ERROR;
115 }
116 return VSYNC_ERROR_OK;
117 }
118
Destroy()119 VsyncError VSyncConnectionProxy::Destroy()
120 {
121 MessageOption opt;
122 MessageParcel arg;
123 MessageParcel ret;
124
125 arg.WriteInterfaceToken(GetDescriptor());
126 int res = Remote()->SendRequest(IVSYNC_CONNECTION_DESTROY, arg, ret, opt);
127 if (res != NO_ERROR) {
128 return VSYNC_ERROR_BINDER_ERROR;
129 }
130 return VSYNC_ERROR_OK;
131 }
132 } // namespace Vsync
133 } // namespace OHOS
134