1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <gui/IDisplayEventConnection.h>
18 
19 #include <private/gui/BitTube.h>
20 
21 namespace android {
22 
23 namespace { // Anonymous
24 
25 enum class Tag : uint32_t {
26     STEAL_RECEIVE_CHANNEL = IBinder::FIRST_CALL_TRANSACTION,
27     SET_VSYNC_RATE,
28     REQUEST_NEXT_VSYNC,
29     REQUEST_LATEST_CONFIG,
30     LAST = REQUEST_LATEST_CONFIG,
31 };
32 
33 } // Anonymous namespace
34 
35 class BpDisplayEventConnection : public SafeBpInterface<IDisplayEventConnection> {
36 public:
BpDisplayEventConnection(const sp<IBinder> & impl)37     explicit BpDisplayEventConnection(const sp<IBinder>& impl)
38           : SafeBpInterface<IDisplayEventConnection>(impl, "BpDisplayEventConnection") {}
39 
40     ~BpDisplayEventConnection() override;
41 
stealReceiveChannel(gui::BitTube * outChannel)42     status_t stealReceiveChannel(gui::BitTube* outChannel) override {
43         return callRemote<decltype(
44                 &IDisplayEventConnection::stealReceiveChannel)>(Tag::STEAL_RECEIVE_CHANNEL,
45                                                                 outChannel);
46     }
47 
setVsyncRate(uint32_t count)48     status_t setVsyncRate(uint32_t count) override {
49         return callRemote<decltype(&IDisplayEventConnection::setVsyncRate)>(Tag::SET_VSYNC_RATE,
50                                                                             count);
51     }
52 
requestNextVsync()53     void requestNextVsync() override {
54         callRemoteAsync<decltype(&IDisplayEventConnection::requestNextVsync)>(
55                 Tag::REQUEST_NEXT_VSYNC);
56     }
57 
requestLatestConfig()58     void requestLatestConfig() override {
59         callRemoteAsync<decltype(&IDisplayEventConnection::requestLatestConfig)>(
60                 Tag::REQUEST_LATEST_CONFIG);
61     }
62 };
63 
64 // Out-of-line virtual method definition to trigger vtable emission in this translation unit (see
65 // clang warning -Wweak-vtables)
66 BpDisplayEventConnection::~BpDisplayEventConnection() = default;
67 
68 IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection");
69 
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)70 status_t BnDisplayEventConnection::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
71                                               uint32_t flags) {
72     if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) {
73         return BBinder::onTransact(code, data, reply, flags);
74     }
75     auto tag = static_cast<Tag>(code);
76     switch (tag) {
77         case Tag::STEAL_RECEIVE_CHANNEL:
78             return callLocal(data, reply, &IDisplayEventConnection::stealReceiveChannel);
79         case Tag::SET_VSYNC_RATE:
80             return callLocal(data, reply, &IDisplayEventConnection::setVsyncRate);
81         case Tag::REQUEST_NEXT_VSYNC:
82             return callLocalAsync(data, reply, &IDisplayEventConnection::requestNextVsync);
83         case Tag::REQUEST_LATEST_CONFIG:
84             return callLocalAsync(data, reply, &IDisplayEventConnection::requestLatestConfig);
85     }
86 }
87 
88 } // namespace android
89