blob: 2de2f8a2f4ed2fdd4a99a705f19039d9c006ad17 [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 Stozae1c599b2017-03-30 16:37:19 -070032 ~BpDisplayEventConnection() override;
Dan Stozad723bd72014-11-18 10:24:03 -080033
Dan Stozae1c599b2017-03-30 16:37:19 -070034 status_t getDataChannel(sp<BitTube>* outChannel) const override {
Mathias Agopiand0566bc2011-11-17 17:49:17 -080035 Parcel data, reply;
36 data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
37 remote()->transact(GET_DATA_CHANNEL, data, &reply);
Dan Stozae1c599b2017-03-30 16:37:19 -070038 *outChannel = new BitTube(reply);
39 return NO_ERROR;
Mathias Agopiand0566bc2011-11-17 17:49:17 -080040 }
Mathias Agopian478ae5e2011-12-06 17:22:19 -080041
Dan Stozae1c599b2017-03-30 16:37:19 -070042 status_t setVsyncRate(uint32_t count) override {
Mathias Agopian478ae5e2011-12-06 17:22:19 -080043 Parcel data, reply;
44 data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080045 data.writeUint32(count);
Mathias Agopian478ae5e2011-12-06 17:22:19 -080046 remote()->transact(SET_VSYNC_RATE, data, &reply);
Dan Stozae1c599b2017-03-30 16:37:19 -070047 return NO_ERROR;
Mathias Agopian478ae5e2011-12-06 17:22:19 -080048 }
49
Dan Stozae1c599b2017-03-30 16:37:19 -070050 void requestNextVsync() override {
Mathias Agopian478ae5e2011-12-06 17:22:19 -080051 Parcel data, reply;
52 data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
53 remote()->transact(REQUEST_NEXT_VSYNC, data, &reply, IBinder::FLAG_ONEWAY);
54 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -080055};
56
Dan Stozaa5f61dd2017-03-30 16:09:13 -070057// Out-of-line virtual method definition to trigger vtable emission in this translation unit (see
58// clang warning -Wweak-vtables)
Dan Stozad723bd72014-11-18 10:24:03 -080059BpDisplayEventConnection::~BpDisplayEventConnection() {}
60
Mathias Agopiand0566bc2011-11-17 17:49:17 -080061IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection");
62
Dan Stozaa5f61dd2017-03-30 16:09:13 -070063status_t BnDisplayEventConnection::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
64 uint32_t flags) {
65 switch (code) {
Mathias Agopiand0566bc2011-11-17 17:49:17 -080066 case GET_DATA_CHANNEL: {
67 CHECK_INTERFACE(IDisplayEventConnection, data, reply);
Dan Stozae1c599b2017-03-30 16:37:19 -070068 sp<BitTube> channel;
69 getDataChannel(&channel);
Mathias Agopiand0566bc2011-11-17 17:49:17 -080070 channel->writeToParcel(reply);
71 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -080072 }
Mathias Agopian478ae5e2011-12-06 17:22:19 -080073 case SET_VSYNC_RATE: {
74 CHECK_INTERFACE(IDisplayEventConnection, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -080075 setVsyncRate(data.readUint32());
Mathias Agopian478ae5e2011-12-06 17:22:19 -080076 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -080077 }
Mathias Agopian478ae5e2011-12-06 17:22:19 -080078 case REQUEST_NEXT_VSYNC: {
79 CHECK_INTERFACE(IDisplayEventConnection, data, reply);
80 requestNextVsync();
81 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -080082 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -080083 }
84 return BBinder::onTransact(code, data, reply, flags);
85}
86
Dan Stozaa5f61dd2017-03-30 16:09:13 -070087} // namespace android