IDisplayEventConnection.cpp revision 6b698e4fe4ff50dcef818452283637f9870ae770
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 <gui/IDisplayEventConnection.h>
18
19#include <private/gui/BitTube.h>
20
21#include <binder/Parcel.h>
22
23namespace android {
24
25enum {
26    STEAL_RECEIVE_CHANNEL = IBinder::FIRST_CALL_TRANSACTION,
27    SET_VSYNC_RATE,
28    REQUEST_NEXT_VSYNC
29};
30
31class BpDisplayEventConnection : public BpInterface<IDisplayEventConnection> {
32public:
33    explicit BpDisplayEventConnection(const sp<IBinder>& impl)
34          : BpInterface<IDisplayEventConnection>(impl) {}
35
36    ~BpDisplayEventConnection() override;
37
38    status_t stealReceiveChannel(gui::BitTube* outChannel) override {
39        Parcel data, reply;
40        data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
41        remote()->transact(STEAL_RECEIVE_CHANNEL, data, &reply);
42        outChannel->readFromParcel(&reply);
43        return NO_ERROR;
44    }
45
46    status_t setVsyncRate(uint32_t count) override {
47        Parcel data, reply;
48        data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
49        data.writeUint32(count);
50        remote()->transact(SET_VSYNC_RATE, data, &reply);
51        return NO_ERROR;
52    }
53
54    void requestNextVsync() override {
55        Parcel data, reply;
56        data.writeInterfaceToken(IDisplayEventConnection::getInterfaceDescriptor());
57        remote()->transact(REQUEST_NEXT_VSYNC, data, &reply, IBinder::FLAG_ONEWAY);
58    }
59};
60
61// Out-of-line virtual method definition to trigger vtable emission in this translation unit (see
62// clang warning -Wweak-vtables)
63BpDisplayEventConnection::~BpDisplayEventConnection() {}
64
65IMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection");
66
67status_t BnDisplayEventConnection::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
68                                              uint32_t flags) {
69    switch (code) {
70        case STEAL_RECEIVE_CHANNEL: {
71            CHECK_INTERFACE(IDisplayEventConnection, data, reply);
72            gui::BitTube channel;
73            stealReceiveChannel(&channel);
74            channel.writeToParcel(reply);
75            return NO_ERROR;
76        }
77        case SET_VSYNC_RATE: {
78            CHECK_INTERFACE(IDisplayEventConnection, data, reply);
79            setVsyncRate(data.readUint32());
80            return NO_ERROR;
81        }
82        case REQUEST_NEXT_VSYNC: {
83            CHECK_INTERFACE(IDisplayEventConnection, data, reply);
84            requestNextVsync();
85            return NO_ERROR;
86        }
87    }
88    return BBinder::onTransact(code, data, reply, flags);
89}
90
91} // namespace android
92