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,
35     SET_VSYNC_RATE,
36     REQUEST_NEXT_VSYNC
37 };
38 
39 class BpDisplayEventConnection : public BpInterface<IDisplayEventConnection>
40 {
41 public:
BpDisplayEventConnection(const sp<IBinder> & impl)42     BpDisplayEventConnection(const sp<IBinder>& impl)
43         : BpInterface<IDisplayEventConnection>(impl)
44     {
45     }
46 
47     virtual ~BpDisplayEventConnection();
48 
getDataChannel() const49     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     }
56 
setVsyncRate(uint32_t count)57     virtual void setVsyncRate(uint32_t count) {
58         Parcel data, reply;
59         data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
60         data.writeUint32(count);
61         remote()->transact(SET_VSYNC_RATE, data, &reply);
62     }
63 
requestNextVsync()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     }
69 };
70 
71 // Out-of-line virtual method definition to trigger vtable emission in this
72 // translation unit (see clang warning -Wweak-vtables)
~BpDisplayEventConnection()73 BpDisplayEventConnection::~BpDisplayEventConnection() {}
74 
75 IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection");
76 
77 // ----------------------------------------------------------------------------
78 
onTransact(uint32_t code,const Parcel & data,Parcel * reply,uint32_t flags)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;
88         }
89         case SET_VSYNC_RATE: {
90             CHECK_INTERFACE(IDisplayEventConnection, data, reply);
91             setVsyncRate(data.readUint32());
92             return NO_ERROR;
93         }
94         case REQUEST_NEXT_VSYNC: {
95             CHECK_INTERFACE(IDisplayEventConnection, data, reply);
96             requestNextVsync();
97             return NO_ERROR;
98         }
99     }
100     return BBinder::onTransact(code, data, reply, flags);
101 }
102 
103 // ----------------------------------------------------------------------------
104 }; // namespace android
105