1/*
2 * Copyright (C) 2017 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#ifndef ANDROID_FRAMEWORKS_DISPLAYSERVICE_V1_0_DISPLAYEVENTRECEIVER_H
18#define ANDROID_FRAMEWORKS_DISPLAYSERVICE_V1_0_DISPLAYEVENTRECEIVER_H
19
20#include <android/frameworks/displayservice/1.0/IDisplayEventReceiver.h>
21#include <gui/DisplayEventReceiver.h>
22#include <hidl/Status.h>
23#include <gui/DisplayEventReceiver.h>
24#include <utils/Looper.h>
25
26#include <mutex>
27
28namespace android {
29namespace frameworks {
30namespace displayservice {
31namespace V1_0 {
32namespace implementation {
33
34using ::android::hardware::Return;
35using ::android::hardware::Void;
36
37class DisplayEventReceiver : public IDisplayEventReceiver {
38public:
39    Return<Status> init(const sp<IEventCallback>& callback) override;
40    Return<Status> setVsyncRate(int32_t count) override;
41    Return<Status> requestNextVsync() override;
42    Return<Status> close() override;
43
44private:
45    using FwkReceiver = ::android::DisplayEventReceiver;
46
47    struct AttachedEvent : LooperCallback {
48        AttachedEvent(const sp<IEventCallback> &callback);
49        ~AttachedEvent();
50
51        bool detach();
52        bool valid() const;
53        FwkReceiver &receiver();
54        virtual int handleEvent(int fd, int events, void* /* data */) override;
55
56    private:
57        FwkReceiver mFwkReceiver;
58        sp<IEventCallback> mCallback;
59        bool mLooperAttached;
60    };
61
62    sp<AttachedEvent> mAttached;
63    std::mutex mMutex;
64};
65
66}  // namespace implementation
67}  // namespace V1_0
68}  // namespace displayservice
69}  // namespace frameworks
70}  // namespace android
71
72#endif  // ANDROID_FRAMEWORKS_DISPLAYSERVICE_V1_0_DISPLAYEVENTRECEIVER_H
73