blob: 9890f44ef72b9c9946257d6e4a17334351d30639 [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>
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
30namespace android {
31// ----------------------------------------------------------------------------
32
33enum {
34 GET_DATA_CHANNEL = IBinder::FIRST_CALL_TRANSACTION,
Mathias Agopian478ae5e2011-12-06 17:22:19 -080035 SET_VSYNC_RATE,
36 REQUEST_NEXT_VSYNC
Mathias Agopiand0566bc2011-11-17 17:49:17 -080037};
38
39class BpDisplayEventConnection : public BpInterface<IDisplayEventConnection>
40{
41public:
42 BpDisplayEventConnection(const sp<IBinder>& impl)
43 : BpInterface<IDisplayEventConnection>(impl)
44 {
45 }
46
Dan Stozad723bd72014-11-18 10:24:03 -080047 virtual ~BpDisplayEventConnection();
48
Mathias Agopiand0566bc2011-11-17 17:49:17 -080049 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 Agopian478ae5e2011-12-06 17:22:19 -080056
57 virtual void setVsyncRate(uint32_t count) {
58 Parcel data, reply;
59 data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
Dan Stozad723bd72014-11-18 10:24:03 -080060 data.writeUint32(count);
Mathias Agopian478ae5e2011-12-06 17:22:19 -080061 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 Agopiand0566bc2011-11-17 17:49:17 -080069};
70
Dan Stozad723bd72014-11-18 10:24:03 -080071// Out-of-line virtual method definition to trigger vtable emission in this
72// translation unit (see clang warning -Wweak-vtables)
73BpDisplayEventConnection::~BpDisplayEventConnection() {}
74
Mathias Agopiand0566bc2011-11-17 17:49:17 -080075IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection");
76
77// ----------------------------------------------------------------------------
78
79status_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 Stozad723bd72014-11-18 10:24:03 -080088 }
Mathias Agopian478ae5e2011-12-06 17:22:19 -080089 case SET_VSYNC_RATE: {
90 CHECK_INTERFACE(IDisplayEventConnection, data, reply);
Dan Stozad723bd72014-11-18 10:24:03 -080091 setVsyncRate(data.readUint32());
Mathias Agopian478ae5e2011-12-06 17:22:19 -080092 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -080093 }
Mathias Agopian478ae5e2011-12-06 17:22:19 -080094 case REQUEST_NEXT_VSYNC: {
95 CHECK_INTERFACE(IDisplayEventConnection, data, reply);
96 requestNextVsync();
97 return NO_ERROR;
Dan Stozad723bd72014-11-18 10:24:03 -080098 }
Mathias Agopiand0566bc2011-11-17 17:49:17 -080099 }
100 return BBinder::onTransact(code, data, reply, flags);
101}
102
103// ----------------------------------------------------------------------------
104}; // namespace android