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 | |
Dan Stoza | a5f61dd | 2017-03-30 16:09:13 -0700 | [diff] [blame] | 21 | #include <binder/Parcel.h> |
| 22 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 23 | namespace android { |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 24 | |
Dan Stoza | a5f61dd | 2017-03-30 16:09:13 -0700 | [diff] [blame] | 25 | enum { GET_DATA_CHANNEL = IBinder::FIRST_CALL_TRANSACTION, SET_VSYNC_RATE, REQUEST_NEXT_VSYNC }; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 26 | |
Dan Stoza | a5f61dd | 2017-03-30 16:09:13 -0700 | [diff] [blame] | 27 | class BpDisplayEventConnection : public BpInterface<IDisplayEventConnection> { |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 28 | public: |
Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 29 | explicit BpDisplayEventConnection(const sp<IBinder>& impl) |
Dan Stoza | a5f61dd | 2017-03-30 16:09:13 -0700 | [diff] [blame] | 30 | : BpInterface<IDisplayEventConnection>(impl) {} |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 31 | |
Dan Stoza | e1c599b | 2017-03-30 16:37:19 -0700 | [diff] [blame] | 32 | ~BpDisplayEventConnection() override; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 33 | |
Dan Stoza | e1c599b | 2017-03-30 16:37:19 -0700 | [diff] [blame] | 34 | status_t getDataChannel(sp<BitTube>* outChannel) const override { |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 35 | Parcel data, reply; |
| 36 | data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor()); |
| 37 | remote()->transact(GET_DATA_CHANNEL, data, &reply); |
Dan Stoza | e1c599b | 2017-03-30 16:37:19 -0700 | [diff] [blame] | 38 | *outChannel = new BitTube(reply); |
| 39 | return NO_ERROR; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 40 | } |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 41 | |
Dan Stoza | e1c599b | 2017-03-30 16:37:19 -0700 | [diff] [blame] | 42 | status_t setVsyncRate(uint32_t count) override { |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 43 | Parcel data, reply; |
| 44 | data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor()); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 45 | data.writeUint32(count); |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 46 | remote()->transact(SET_VSYNC_RATE, data, &reply); |
Dan Stoza | e1c599b | 2017-03-30 16:37:19 -0700 | [diff] [blame] | 47 | return NO_ERROR; |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Dan Stoza | e1c599b | 2017-03-30 16:37:19 -0700 | [diff] [blame] | 50 | void requestNextVsync() override { |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 51 | Parcel data, reply; |
| 52 | data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor()); |
| 53 | remote()->transact(REQUEST_NEXT_VSYNC, data, &reply, IBinder::FLAG_ONEWAY); |
| 54 | } |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 55 | }; |
| 56 | |
Dan Stoza | a5f61dd | 2017-03-30 16:09:13 -0700 | [diff] [blame] | 57 | // Out-of-line virtual method definition to trigger vtable emission in this translation unit (see |
| 58 | // clang warning -Wweak-vtables) |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 59 | BpDisplayEventConnection::~BpDisplayEventConnection() {} |
| 60 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 61 | IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection"); |
| 62 | |
Dan Stoza | a5f61dd | 2017-03-30 16:09:13 -0700 | [diff] [blame] | 63 | status_t BnDisplayEventConnection::onTransact(uint32_t code, const Parcel& data, Parcel* reply, |
| 64 | uint32_t flags) { |
| 65 | switch (code) { |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 66 | case GET_DATA_CHANNEL: { |
| 67 | CHECK_INTERFACE(IDisplayEventConnection, data, reply); |
Dan Stoza | e1c599b | 2017-03-30 16:37:19 -0700 | [diff] [blame] | 68 | sp<BitTube> channel; |
| 69 | getDataChannel(&channel); |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 70 | channel->writeToParcel(reply); |
| 71 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 72 | } |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 73 | case SET_VSYNC_RATE: { |
| 74 | CHECK_INTERFACE(IDisplayEventConnection, data, reply); |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 75 | setVsyncRate(data.readUint32()); |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 76 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 77 | } |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 78 | case REQUEST_NEXT_VSYNC: { |
| 79 | CHECK_INTERFACE(IDisplayEventConnection, data, reply); |
| 80 | requestNextVsync(); |
| 81 | return NO_ERROR; |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 82 | } |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 83 | } |
| 84 | return BBinder::onTransact(code, data, reply, flags); |
| 85 | } |
| 86 | |
Dan Stoza | a5f61dd | 2017-03-30 16:09:13 -0700 | [diff] [blame] | 87 | } // namespace android |