| 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_SURFACE_FLINGER_EVENT_THREAD_H | 
|  | 18 | #define ANDROID_SURFACE_FLINGER_EVENT_THREAD_H | 
|  | 19 |  | 
|  | 20 | #include <stdint.h> | 
|  | 21 | #include <sys/types.h> | 
|  | 22 |  | 
|  | 23 | #include <gui/IDisplayEventConnection.h> | 
|  | 24 |  | 
|  | 25 | #include <utils/Errors.h> | 
|  | 26 | #include <utils/threads.h> | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 27 | #include <utils/KeyedVector.h> | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 28 |  | 
|  | 29 | #include "DisplayEventConnection.h" | 
|  | 30 |  | 
|  | 31 | // --------------------------------------------------------------------------- | 
|  | 32 |  | 
|  | 33 | namespace android { | 
|  | 34 |  | 
|  | 35 | // --------------------------------------------------------------------------- | 
|  | 36 |  | 
|  | 37 | class SurfaceFlinger; | 
|  | 38 | class DisplayHardware; | 
|  | 39 |  | 
|  | 40 | // --------------------------------------------------------------------------- | 
|  | 41 |  | 
|  | 42 | class EventThread : public Thread { | 
|  | 43 | friend class DisplayEventConnection; | 
|  | 44 |  | 
|  | 45 | public: | 
|  | 46 | EventThread(const sp<SurfaceFlinger>& flinger); | 
|  | 47 |  | 
|  | 48 | status_t registerDisplayEventConnection( | 
|  | 49 | const sp<DisplayEventConnection>& connection); | 
|  | 50 |  | 
|  | 51 | status_t unregisterDisplayEventConnection( | 
|  | 52 | const wp<DisplayEventConnection>& connection); | 
|  | 53 |  | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 54 | void setVsyncRate(uint32_t count, | 
|  | 55 | const wp<DisplayEventConnection>& connection); | 
|  | 56 |  | 
|  | 57 | void requestNextVsync(const wp<DisplayEventConnection>& connection); | 
|  | 58 |  | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 59 | void dump(String8& result, char* buffer, size_t SIZE) const; | 
|  | 60 |  | 
|  | 61 | private: | 
|  | 62 | virtual bool        threadLoop(); | 
|  | 63 | virtual status_t    readyToRun(); | 
|  | 64 | virtual void        onFirstRef(); | 
|  | 65 |  | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 66 | struct ConnectionInfo { | 
|  | 67 | ConnectionInfo() : count(-1) { } | 
|  | 68 |  | 
|  | 69 | // count >= 1 : continuous event. count is the vsync rate | 
|  | 70 | // count == 0 : one-shot event that has not fired | 
|  | 71 | // count ==-1 : one-shot event that fired this round / disabled | 
|  | 72 | // count ==-2 : one-shot event that fired the round before | 
|  | 73 | int32_t count; | 
|  | 74 | }; | 
|  | 75 |  | 
|  | 76 | void removeDisplayEventConnection( | 
|  | 77 | const wp<DisplayEventConnection>& connection); | 
|  | 78 |  | 
|  | 79 | ConnectionInfo* getConnectionInfoLocked( | 
| Mathias Agopian | 2374866 | 2011-12-05 14:33:34 -0800 | [diff] [blame] | 80 | const wp<DisplayEventConnection>& connection); | 
|  | 81 |  | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 82 | // constants | 
|  | 83 | sp<SurfaceFlinger> mFlinger; | 
|  | 84 | const DisplayHardware& mHw; | 
|  | 85 |  | 
|  | 86 | mutable Mutex mLock; | 
|  | 87 | mutable Condition mCondition; | 
|  | 88 |  | 
|  | 89 | // protected by mLock | 
| Mathias Agopian | 478ae5e | 2011-12-06 17:22:19 -0800 | [diff] [blame] | 90 | KeyedVector< wp<DisplayEventConnection>, ConnectionInfo > mDisplayEventConnections; | 
|  | 91 |  | 
|  | 92 | // main thread only | 
| Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 93 | size_t mDeliveredEvents; | 
|  | 94 | }; | 
|  | 95 |  | 
|  | 96 | // --------------------------------------------------------------------------- | 
|  | 97 |  | 
|  | 98 | }; // namespace android | 
|  | 99 |  | 
|  | 100 | // --------------------------------------------------------------------------- | 
|  | 101 |  | 
|  | 102 | #endif /* ANDROID_SURFACE_FLINGER_EVENT_THREAD_H */ |