Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 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 | #ifndef ANDROID_GUI_DISPLAY_EVENT_H |
| 18 | #define ANDROID_GUI_DISPLAY_EVENT_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
| 23 | #include <utils/Errors.h> |
| 24 | #include <utils/RefBase.h> |
| 25 | #include <utils/Timers.h> |
| 26 | |
| 27 | #include <binder/IInterface.h> |
| 28 | |
| 29 | // ---------------------------------------------------------------------------- |
| 30 | |
| 31 | namespace android { |
| 32 | |
| 33 | // ---------------------------------------------------------------------------- |
| 34 | |
| 35 | class BitTube; |
| 36 | class IDisplayEventConnection; |
| 37 | |
| 38 | // ---------------------------------------------------------------------------- |
| 39 | |
| 40 | class DisplayEventReceiver { |
| 41 | public: |
| 42 | enum { |
| 43 | DISPLAY_EVENT_VSYNC = 'vsyn' |
| 44 | }; |
| 45 | |
| 46 | struct Event { |
| 47 | |
| 48 | struct Header { |
| 49 | uint32_t type; |
| 50 | nsecs_t timestamp; |
| 51 | }; |
| 52 | |
| 53 | struct VSync { |
| 54 | uint32_t count; |
| 55 | }; |
| 56 | |
| 57 | Header header; |
| 58 | union { |
| 59 | VSync vsync; |
| 60 | }; |
| 61 | }; |
| 62 | |
| 63 | public: |
| 64 | /* |
| 65 | * DisplayEventReceiver creates and registers an event connection with |
| 66 | * SurfaceFlinger. Events start being delivered immediately. |
| 67 | */ |
| 68 | DisplayEventReceiver(); |
| 69 | |
| 70 | /* |
| 71 | * ~DisplayEventReceiver severs the connection with SurfaceFlinger, new events |
| 72 | * stop being delivered immediately. Note that the queue could have |
| 73 | * some events pending. These will be delivered. |
| 74 | */ |
| 75 | ~DisplayEventReceiver(); |
| 76 | |
| 77 | /* |
| 78 | * initCheck returns the state of DisplayEventReceiver after construction. |
| 79 | */ |
| 80 | status_t initCheck() const; |
| 81 | |
| 82 | /* |
| 83 | * getFd returns the file descriptor to use to receive events. |
| 84 | * OWNERSHIP IS RETAINED by DisplayEventReceiver. DO NOT CLOSE this |
| 85 | * file-descriptor. |
| 86 | */ |
| 87 | int getFd() const; |
| 88 | |
| 89 | /* |
| 90 | * getEvents reads event from the queue and returns how many events were |
| 91 | * read. Returns 0 if there are no more events or a negative error code. |
| 92 | * If NOT_ENOUGH_DATA is returned, the object has become invalid forever, it |
| 93 | * should be destroyed and getEvents() shouldn't be called again. |
| 94 | */ |
| 95 | ssize_t getEvents(Event* events, size_t count); |
| 96 | |
Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame^] | 97 | /* |
| 98 | * setVsyncRate() sets the Event::VSync delivery rate. A value of |
| 99 | * 1 returns every Event::VSync. A value of 2 returns every other event, |
| 100 | * etc... a value of 0 returns no event unless requestNextVsync() has |
| 101 | * been called. |
| 102 | */ |
| 103 | status_t setVsyncRate(uint32_t count); |
| 104 | |
| 105 | /* |
| 106 | * requestNextVsync() schedules the next Event::VSync. It has no effect |
| 107 | * if the vsync rate is > 0. |
| 108 | */ |
| 109 | status_t requestNextVsync(); |
| 110 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 111 | private: |
| 112 | sp<IDisplayEventConnection> mEventConnection; |
| 113 | sp<BitTube> mDataChannel; |
| 114 | }; |
| 115 | |
| 116 | // ---------------------------------------------------------------------------- |
| 117 | }; // namespace android |
| 118 | |
| 119 | #endif // ANDROID_GUI_DISPLAY_EVENT_H |