1d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian/*
2d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * Copyright (C) 2011 The Android Open Source Project
3d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian *
4d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * Licensed under the Apache License, Version 2.0 (the "License");
5d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * you may not use this file except in compliance with the License.
6d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * You may obtain a copy of the License at
7d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian *
8d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian *      http://www.apache.org/licenses/LICENSE-2.0
9d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian *
10d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * Unless required by applicable law or agreed to in writing, software
11d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * distributed under the License is distributed on an "AS IS" BASIS,
12d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * See the License for the specific language governing permissions and
14d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian * limitations under the License.
15d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian */
16d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
17d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian#include <gui/IDisplayEventConnection.h>
18801ea093b0e923a61b832f2adba698a273479880Mathias Agopian
19801ea093b0e923a61b832f2adba698a273479880Mathias Agopian#include <private/gui/BitTube.h>
20d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
21d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopiannamespace android {
22d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
232d191c302df1c7b2443d333a5a243c0043a37101Dan Stozanamespace { // Anonymous
242d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza
252d191c302df1c7b2443d333a5a243c0043a37101Dan Stozaenum class Tag : uint32_t {
266b698e4fe4ff50dcef818452283637f9870ae770Dan Stoza    STEAL_RECEIVE_CHANNEL = IBinder::FIRST_CALL_TRANSACTION,
276b698e4fe4ff50dcef818452283637f9870ae770Dan Stoza    SET_VSYNC_RATE,
282d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza    REQUEST_NEXT_VSYNC,
292d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza    LAST = REQUEST_NEXT_VSYNC,
306b698e4fe4ff50dcef818452283637f9870ae770Dan Stoza};
31d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
322d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza} // Anonymous namespace
332d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza
342d191c302df1c7b2443d333a5a243c0043a37101Dan Stozaclass BpDisplayEventConnection : public SafeBpInterface<IDisplayEventConnection> {
35d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopianpublic:
36e2347b7953f70232541bdc1b392230d6231aaeb9Chih-Hung Hsieh    explicit BpDisplayEventConnection(const sp<IBinder>& impl)
372d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza          : SafeBpInterface<IDisplayEventConnection>(impl, "BpDisplayEventConnection") {}
38d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
39e1c599b52fcce94bd27ebbc4d74cd59c9e71b452Dan Stoza    ~BpDisplayEventConnection() override;
40d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza
416b698e4fe4ff50dcef818452283637f9870ae770Dan Stoza    status_t stealReceiveChannel(gui::BitTube* outChannel) override {
422d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza        return callRemote<decltype(
432d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza                &IDisplayEventConnection::stealReceiveChannel)>(Tag::STEAL_RECEIVE_CHANNEL,
442d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza                                                                outChannel);
45d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian    }
46478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian
47e1c599b52fcce94bd27ebbc4d74cd59c9e71b452Dan Stoza    status_t setVsyncRate(uint32_t count) override {
482d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza        return callRemote<decltype(&IDisplayEventConnection::setVsyncRate)>(Tag::SET_VSYNC_RATE,
492d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza                                                                            count);
50478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian    }
51478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian
52e1c599b52fcce94bd27ebbc4d74cd59c9e71b452Dan Stoza    void requestNextVsync() override {
532d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza        callRemoteAsync<decltype(&IDisplayEventConnection::requestNextVsync)>(
542d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza                Tag::REQUEST_NEXT_VSYNC);
55478ae5eb5a0047e1b2988c896cff6363b455ee50Mathias Agopian    }
56d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian};
57d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
58a5f61dd70ac151c8adbde20d3bc4cd7d27808d21Dan Stoza// Out-of-line virtual method definition to trigger vtable emission in this translation unit (see
59a5f61dd70ac151c8adbde20d3bc4cd7d27808d21Dan Stoza// clang warning -Wweak-vtables)
602d191c302df1c7b2443d333a5a243c0043a37101Dan StozaBpDisplayEventConnection::~BpDisplayEventConnection() = default;
61d723bd7669b4fc88dc282d8bf8ba5ecb2849d22fDan Stoza
62d0566bc26fcf6ca396118701fa11900b627f2c09Mathias AgopianIMPLEMENT_META_INTERFACE(DisplayEventConnection, "android.gui.DisplayEventConnection");
63d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
64a5f61dd70ac151c8adbde20d3bc4cd7d27808d21Dan Stozastatus_t BnDisplayEventConnection::onTransact(uint32_t code, const Parcel& data, Parcel* reply,
65a5f61dd70ac151c8adbde20d3bc4cd7d27808d21Dan Stoza                                              uint32_t flags) {
662d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza    if (code < IBinder::FIRST_CALL_TRANSACTION || code > static_cast<uint32_t>(Tag::LAST)) {
672d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza        return BBinder::onTransact(code, data, reply, flags);
682d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza    }
692d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza    auto tag = static_cast<Tag>(code);
702d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza    switch (tag) {
712d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza        case Tag::STEAL_RECEIVE_CHANNEL:
722d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza            return callLocal(data, reply, &IDisplayEventConnection::stealReceiveChannel);
732d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza        case Tag::SET_VSYNC_RATE:
742d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza            return callLocal(data, reply, &IDisplayEventConnection::setVsyncRate);
752d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza        case Tag::REQUEST_NEXT_VSYNC:
762d191c302df1c7b2443d333a5a243c0043a37101Dan Stoza            return callLocalAsync(data, reply, &IDisplayEventConnection::requestNextVsync);
77d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian    }
78d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian}
79d0566bc26fcf6ca396118701fa11900b627f2c09Mathias Agopian
80a5f61dd70ac151c8adbde20d3bc4cd7d27808d21Dan Stoza} // namespace android
81