blob: 4d2d7e90f7d693ac9f459016ec38742c2ec1e21e [file] [log] [blame]
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001/*
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 Agopiand0566bc2011-11-17 17:49:17 -080017#include <gui/IDisplayEventConnection.h>
Mathias Agopian801ea092017-03-06 15:05:04 -080018
19#include <private/gui/BitTube.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080020
Dan Stozaa5f61dd2017-03-30 16:09:13 -070021#include <binder/Parcel.h>
22
Mathias Agopiand0566bc2011-11-17 17:49:17 -080023namespace android {
Mathias Agopiand0566bc2011-11-17 17:49:17 -080024
Dan Stozaa5f61dd2017-03-30 16:09:13 -070025enum { GET_DATA_CHANNEL = IBinder::FIRST_CALL_TRANSACTION, SET_VSYNC_RATE, REQUEST_NEXT_VSYNC };
Mathias Agopiand0566bc2011-11-17 17:49:17 -080026
Dan Stozaa5f61dd2017-03-30 16:09:13 -070027class BpDisplayEventConnection : public BpInterface<IDisplayEventConnection> {
Mathias Agopiand0566bc2011-11-17 17:49:17 -080028public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070029 explicit BpDisplayEventConnection(const sp<IBinder>& impl)
Dan Stozaa5f61dd2017-03-30 16:09:13 -070030 : BpInterface<IDisplayEventConnection>(impl) {}
Mathias Agopiand0566bc2011-11-17 17:49:17 -080031
Dan Stozad723bd72014-11-18 10:24:03 -080032 virtual ~BpDisplayEventConnection();
33
Dan Stozaa5f61dd2017-03-30 16:09:13 -070034 virtual sp<BitTube> getDataChannel() const {
Mathias Agopiand0566bc2011-11-17 17:49:17 -080035 Parcel data, reply;
36 data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
37 remote()->transact(GET_DATA_CHANNEL, data, &reply);
38 return new BitTube(reply);
39 }
Mathias Agopian478ae5e2011-12-06 17:22:19 -080040
41 virtual void setVsyncRate(uint32_t count) {
42 Parcel data, reply;
43 data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080044 data.writeUint32(count);
Mathias Agopian478ae5e2011-12-06 17:22:19 -080045 remote()->transact(SET_VSYNC_RATE, data, &reply);
46 }
47
48 virtual void requestNextVsync() {
49 Parcel data, reply;
50 data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
51 remote()->transact(REQUEST_NEXT_VSYNC, data, &reply, IBinder::FLAG_ONEWAY);
52 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -080053};
54
Dan Stozaa5f61dd2017-03-30 16:09:13 -070055// Out-of-line virtual method definition to trigger vtable emission in this translation unit (see
56// clang warning -Wweak-vtables)
Dan Stozad723bd72014-11-18 10:24:03 -080057BpDisplayEventConnection::~BpDisplayEventConnection() {}
58
Mathias Agopiand0566bc2011-11-17 17:49:17 -080059IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection");
60
Dan Stozaa5f61dd2017-03-30 16:09:13 -070061status_t BnDisplayEventConnection::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
62 uint32_t flags) {
63 switch (code) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -080064 case GET_DATA_CHANNEL: {
65 CHECK_INTERFACE(IDisplayEventConnection, data, reply);
66 sp<BitTube> channel(getDataChannel());
67 channel->writeToParcel(reply);
68 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -080069 }
Mathias Agopian478ae5e2011-12-06 17:22:19 -080070 case SET_VSYNC_RATE: {
71 CHECK_INTERFACE(IDisplayEventConnection, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -080072 setVsyncRate(data.readUint32());
Mathias Agopian478ae5e2011-12-06 17:22:19 -080073 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -080074 }
Mathias Agopian478ae5e2011-12-06 17:22:19 -080075 case REQUEST_NEXT_VSYNC: {
76 CHECK_INTERFACE(IDisplayEventConnection, data, reply);
77 requestNextVsync();
78 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -080079 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -080080 }
81 return BBinder::onTransact(code, data, reply, flags);
82}
83
Dan Stozaa5f61dd2017-03-30 16:09:13 -070084} // namespace android