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