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