2 * Copyright (C) 2011 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef ANDROID_GUI_DISPLAY_EVENT_H
18 #define ANDROID_GUI_DISPLAY_EVENT_H
21 #include <sys/types.h>
23 #include <utils/Errors.h>
24 #include <utils/RefBase.h>
25 #include <utils/Timers.h>
27 #include <binder/IInterface.h>
28 #include <gui/ISurfaceComposer.h>
30 // ----------------------------------------------------------------------------
34 // ----------------------------------------------------------------------------
36 class IDisplayEventConnection;
42 static inline constexpr uint32_t fourcc(char c1, char c2, char c3, char c4) {
43 return static_cast<uint32_t>(c1) << 24 |
44 static_cast<uint32_t>(c2) << 16 |
45 static_cast<uint32_t>(c3) << 8 |
46 static_cast<uint32_t>(c4);
49 // ----------------------------------------------------------------------------
50 class DisplayEventReceiver {
53 DISPLAY_EVENT_VSYNC = fourcc('v', 's', 'y', 'n'),
54 DISPLAY_EVENT_HOTPLUG = fourcc('p', 'l', 'u', 'g'),
62 nsecs_t timestamp __attribute__((aligned(8)));
82 * DisplayEventReceiver creates and registers an event connection with
83 * SurfaceFlinger. VSync events are disabled by default. Call setVSyncRate
84 * or requestNextVsync to receive them.
85 * Other events start being delivered immediately.
88 ISurfaceComposer::VsyncSource vsyncSource = ISurfaceComposer::eVsyncSourceApp);
91 * ~DisplayEventReceiver severs the connection with SurfaceFlinger, new events
92 * stop being delivered immediately. Note that the queue could have
93 * some events pending. These will be delivered.
95 ~DisplayEventReceiver();
98 * initCheck returns the state of DisplayEventReceiver after construction.
100 status_t initCheck() const;
103 * getFd returns the file descriptor to use to receive events.
104 * OWNERSHIP IS RETAINED by DisplayEventReceiver. DO NOT CLOSE this
110 * getEvents reads events from the queue and returns how many events were
111 * read. Returns 0 if there are no more events or a negative error code.
112 * If NOT_ENOUGH_DATA is returned, the object has become invalid forever, it
113 * should be destroyed and getEvents() shouldn't be called again.
115 ssize_t getEvents(Event* events, size_t count);
116 static ssize_t getEvents(gui::BitTube* dataChannel, Event* events, size_t count);
119 * sendEvents write events to the queue and returns how many events were
122 static ssize_t sendEvents(gui::BitTube* dataChannel, Event const* events, size_t count);
125 * setVsyncRate() sets the Event::VSync delivery rate. A value of
126 * 1 returns every Event::VSync. A value of 2 returns every other event,
127 * etc... a value of 0 returns no event unless requestNextVsync() has
130 status_t setVsyncRate(uint32_t count);
133 * requestNextVsync() schedules the next Event::VSync. It has no effect
134 * if the vsync rate is > 0.
136 status_t requestNextVsync();
139 sp<IDisplayEventConnection> mEventConnection;
140 std::unique_ptr<gui::BitTube> mDataChannel;
143 // ----------------------------------------------------------------------------
144 }; // namespace android
146 #endif // ANDROID_GUI_DISPLAY_EVENT_H