| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 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 |  | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 17 | #include <gui/IDisplayEventConnection.h> | 
| Mathias Agopian | 801ea09 | 2017-03-06 15:05:04 -0800 | [diff] [blame] | 18 |  | 
 | 19 | #include <private/gui/BitTube.h> | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 20 |  | 
 | 21 | namespace android { | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 22 |  | 
| Dan Stoza | 2d191c3 | 2017-04-03 13:27:12 -0700 | [diff] [blame] | 23 | namespace { // Anonymous | 
 | 24 |  | 
 | 25 | enum class Tag : uint32_t { | 
| Dan Stoza | 6b698e4 | 2017-04-03 13:09:08 -0700 | [diff] [blame] | 26 |     STEAL_RECEIVE_CHANNEL = IBinder::FIRST_CALL_TRANSACTION, | 
 | 27 |     SET_VSYNC_RATE, | 
| Dan Stoza | 2d191c3 | 2017-04-03 13:27:12 -0700 | [diff] [blame] | 28 |     REQUEST_NEXT_VSYNC, | 
| Alec Mouri | c080030 | 2020-08-05 12:50:03 -0700 | [diff] [blame] | 29 |     LAST = REQUEST_NEXT_VSYNC, | 
| Dan Stoza | 6b698e4 | 2017-04-03 13:09:08 -0700 | [diff] [blame] | 30 | }; | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 31 |  | 
| Dan Stoza | 2d191c3 | 2017-04-03 13:27:12 -0700 | [diff] [blame] | 32 | } // Anonymous namespace | 
 | 33 |  | 
 | 34 | class BpDisplayEventConnection : public SafeBpInterface<IDisplayEventConnection> { | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 35 | public: | 
| Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 36 |     explicit BpDisplayEventConnection(const sp<IBinder>& impl) | 
| Dan Stoza | 2d191c3 | 2017-04-03 13:27:12 -0700 | [diff] [blame] | 37 |           : SafeBpInterface<IDisplayEventConnection>(impl, "BpDisplayEventConnection") {} | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 38 |  | 
| Dan Stoza | e1c599b | 2017-03-30 16:37:19 -0700 | [diff] [blame] | 39 |     ~BpDisplayEventConnection() override; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 40 |  | 
| Dan Stoza | 6b698e4 | 2017-04-03 13:09:08 -0700 | [diff] [blame] | 41 |     status_t stealReceiveChannel(gui::BitTube* outChannel) override { | 
| Dan Stoza | 2d191c3 | 2017-04-03 13:27:12 -0700 | [diff] [blame] | 42 |         return callRemote<decltype( | 
 | 43 |                 &IDisplayEventConnection::stealReceiveChannel)>(Tag::STEAL_RECEIVE_CHANNEL, | 
 | 44 |                                                                 outChannel); | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 45 |     } | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 46 |  | 
| Dan Stoza | e1c599b | 2017-03-30 16:37:19 -0700 | [diff] [blame] | 47 |     status_t setVsyncRate(uint32_t count) override { | 
| Dan Stoza | 2d191c3 | 2017-04-03 13:27:12 -0700 | [diff] [blame] | 48 |         return callRemote<decltype(&IDisplayEventConnection::setVsyncRate)>(Tag::SET_VSYNC_RATE, | 
 | 49 |                                                                             count); | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 50 |     } | 
 | 51 |  | 
| Dan Stoza | e1c599b | 2017-03-30 16:37:19 -0700 | [diff] [blame] | 52 |     void requestNextVsync() override { | 
| Dan Stoza | 2d191c3 | 2017-04-03 13:27:12 -0700 | [diff] [blame] | 53 |         callRemoteAsync<decltype(&IDisplayEventConnection::requestNextVsync)>( | 
 | 54 |                 Tag::REQUEST_NEXT_VSYNC); | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 55 |     } | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 56 | }; | 
 | 57 |  | 
| Dan Stoza | a5f61dd | 2017-03-30 16:09:13 -0700 | [diff] [blame] | 58 | // Out-of-line virtual method definition to trigger vtable emission in this translation unit (see | 
 | 59 | // clang warning -Wweak-vtables) | 
| Dan Stoza | 2d191c3 | 2017-04-03 13:27:12 -0700 | [diff] [blame] | 60 | BpDisplayEventConnection::~BpDisplayEventConnection() = default; | 
| Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 61 |  | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 62 | IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection"); | 
 | 63 |  | 
| Dan Stoza | a5f61dd | 2017-03-30 16:09:13 -0700 | [diff] [blame] | 64 | status_t BnDisplayEventConnection::onTransact(uint32_t code, const Parcel& data, Parcel* reply, | 
 | 65 |                                               uint32_t flags) { | 
| Dan Stoza | 2d191c3 | 2017-04-03 13:27:12 -0700 | [diff] [blame] | 66 |     if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) { | 
 | 67 |         return BBinder::onTransact(code, data, reply, flags); | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 68 |     } | 
| Dan Stoza | 2d191c3 | 2017-04-03 13:27:12 -0700 | [diff] [blame] | 69 |     auto tag = static_cast<Tag>(code); | 
 | 70 |     switch (tag) { | 
 | 71 |         case Tag::STEAL_RECEIVE_CHANNEL: | 
 | 72 |             return callLocal(data, reply, &IDisplayEventConnection::stealReceiveChannel); | 
 | 73 |         case Tag::SET_VSYNC_RATE: | 
 | 74 |             return callLocal(data, reply, &IDisplayEventConnection::setVsyncRate); | 
 | 75 |         case Tag::REQUEST_NEXT_VSYNC: | 
 | 76 |             return callLocalAsync(data, reply, &IDisplayEventConnection::requestNextVsync); | 
 | 77 |     } | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 78 | } | 
 | 79 |  | 
| Dan Stoza | a5f61dd | 2017-03-30 16:09:13 -0700 | [diff] [blame] | 80 | } // namespace android |