blob: 35bd299a867511c860c6fe0348edab49fd82e40c [file] [log] [blame]
Mathias Agopiand0566bc2011-11-17 17:49:17 -08001/*
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 Agopian478ae5e2011-12-06 17:22:19 -080027#include <utils/KeyedVector.h>
Mathias Agopiand0566bc2011-11-17 17:49:17 -080028
29#include "DisplayEventConnection.h"
30
31// ---------------------------------------------------------------------------
32
33namespace android {
34
35// ---------------------------------------------------------------------------
36
37class SurfaceFlinger;
38class DisplayHardware;
39
40// ---------------------------------------------------------------------------
41
42class EventThread : public Thread {
43 friend class DisplayEventConnection;
44
45public:
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 Agopian478ae5e2011-12-06 17:22:19 -080054 void setVsyncRate(uint32_t count,
55 const wp<DisplayEventConnection>& connection);
56
57 void requestNextVsync(const wp<DisplayEventConnection>& connection);
58
Mathias Agopiand0566bc2011-11-17 17:49:17 -080059 void dump(String8& result, char* buffer, size_t SIZE) const;
60
61private:
62 virtual bool threadLoop();
63 virtual status_t readyToRun();
64 virtual void onFirstRef();
65
Mathias Agopian478ae5e2011-12-06 17:22:19 -080066 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 Agopian23748662011-12-05 14:33:34 -080080 const wp<DisplayEventConnection>& connection);
81
Mathias Agopiand0566bc2011-11-17 17:49:17 -080082 // constants
83 sp<SurfaceFlinger> mFlinger;
84 const DisplayHardware& mHw;
85
86 mutable Mutex mLock;
87 mutable Condition mCondition;
88
89 // protected by mLock
Mathias Agopian478ae5e2011-12-06 17:22:19 -080090 KeyedVector< wp<DisplayEventConnection>, ConnectionInfo > mDisplayEventConnections;
91
92 // main thread only
Mathias Agopiand0566bc2011-11-17 17:49:17 -080093 size_t mDeliveredEvents;
94};
95
96// ---------------------------------------------------------------------------
97
98}; // namespace android
99
100// ---------------------------------------------------------------------------
101
102#endif /* ANDROID_SURFACE_FLINGER_EVENT_THREAD_H */