blob: e5c3c48248ccf54be85d3494a134a5fe5c92eb99 [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
17#include <stdint.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080018
19#include <utils/Errors.h>
20#include <utils/RefBase.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080021
22#include <binder/Parcel.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080023
24#include <gui/IDisplayEventConnection.h>
Mathias Agopian801ea092017-03-06 15:05:04 -080025
26#include <private/gui/BitTube.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080027
28namespace android {
29// ----------------------------------------------------------------------------
30
31enum {
32 GET_DATA_CHANNEL = IBinder::FIRST_CALL_TRANSACTION,
Mathias Agopian478ae5e2011-12-06 17:22:19 -080033 SET_VSYNC_RATE,
34 REQUEST_NEXT_VSYNC
Mathias Agopiand0566bc2011-11-17 17:49:17 -080035};
36
37class BpDisplayEventConnection : public BpInterface<IDisplayEventConnection>
38{
39public:
Chih-Hung Hsiehe2347b72016-04-25 15:41:05 -070040 explicit BpDisplayEventConnection(const sp<IBinder>& impl)
Mathias Agopiand0566bc2011-11-17 17:49:17 -080041 : BpInterface<IDisplayEventConnection>(impl)
42 {
43 }
44
Dan Stozad723bd72014-11-18 10:24:03 -080045 virtual ~BpDisplayEventConnection();
46
Mathias Agopiand0566bc2011-11-17 17:49:17 -080047 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 Agopian478ae5e2011-12-06 17:22:19 -080054
55 virtual void setVsyncRate(uint32_t count) {
56 Parcel data, reply;
57 data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080058 data.writeUint32(count);
Mathias Agopian478ae5e2011-12-06 17:22:19 -080059 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 Agopiand0566bc2011-11-17 17:49:17 -080067};
68
Dan Stozad723bd72014-11-18 10:24:03 -080069// Out-of-line virtual method definition to trigger vtable emission in this
70// translation unit (see clang warning -Wweak-vtables)
71BpDisplayEventConnection::~BpDisplayEventConnection() {}
72
Mathias Agopiand0566bc2011-11-17 17:49:17 -080073IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection");
74
75// ----------------------------------------------------------------------------
76
77status_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 Stozad723bd72014-11-18 10:24:03 -080086 }
Mathias Agopian478ae5e2011-12-06 17:22:19 -080087 case SET_VSYNC_RATE: {
88 CHECK_INTERFACE(IDisplayEventConnection, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -080089 setVsyncRate(data.readUint32());
Mathias Agopian478ae5e2011-12-06 17:22:19 -080090 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -080091 }
Mathias Agopian478ae5e2011-12-06 17:22:19 -080092 case REQUEST_NEXT_VSYNC: {
93 CHECK_INTERFACE(IDisplayEventConnection, data, reply);
94 requestNextVsync();
95 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -080096 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -080097 }
98 return BBinder::onTransact(code, data, reply, flags);
99}
100
101// ----------------------------------------------------------------------------
102}; // namespace android