blob: 3a3071ef8bea041fddfa71541ecdb7af1d5e4189 [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;
Mathias Agopian8aedd472012-01-24 16:39:14 -080039class DisplayEventConnection;
Mathias Agopiand0566bc2011-11-17 17:49:17 -080040
41// ---------------------------------------------------------------------------
42
43class EventThread : public Thread {
44 friend class DisplayEventConnection;
45
46public:
47 EventThread(const sp<SurfaceFlinger>& flinger);
48
Mathias Agopian8aedd472012-01-24 16:39:14 -080049 sp<DisplayEventConnection> createEventConnection() const;
50
Mathias Agopiand0566bc2011-11-17 17:49:17 -080051 status_t registerDisplayEventConnection(
52 const sp<DisplayEventConnection>& connection);
53
54 status_t unregisterDisplayEventConnection(
55 const wp<DisplayEventConnection>& connection);
56
Mathias Agopian478ae5e2011-12-06 17:22:19 -080057 void setVsyncRate(uint32_t count,
58 const wp<DisplayEventConnection>& connection);
59
60 void requestNextVsync(const wp<DisplayEventConnection>& connection);
61
Mathias Agopian8aedd472012-01-24 16:39:14 -080062 nsecs_t getLastVSyncTimestamp() const;
63
64 nsecs_t getVSyncPeriod() const;
65
Mathias Agopiand0566bc2011-11-17 17:49:17 -080066 void dump(String8& result, char* buffer, size_t SIZE) const;
67
68private:
69 virtual bool threadLoop();
70 virtual status_t readyToRun();
71 virtual void onFirstRef();
72
Mathias Agopian478ae5e2011-12-06 17:22:19 -080073 struct ConnectionInfo {
74 ConnectionInfo() : count(-1) { }
75
76 // count >= 1 : continuous event. count is the vsync rate
77 // count == 0 : one-shot event that has not fired
78 // count ==-1 : one-shot event that fired this round / disabled
79 // count ==-2 : one-shot event that fired the round before
80 int32_t count;
81 };
82
83 void removeDisplayEventConnection(
84 const wp<DisplayEventConnection>& connection);
85
86 ConnectionInfo* getConnectionInfoLocked(
Mathias Agopian23748662011-12-05 14:33:34 -080087 const wp<DisplayEventConnection>& connection);
88
Mathias Agopiand0566bc2011-11-17 17:49:17 -080089 // constants
90 sp<SurfaceFlinger> mFlinger;
91 const DisplayHardware& mHw;
92
93 mutable Mutex mLock;
94 mutable Condition mCondition;
95
96 // protected by mLock
Mathias Agopian478ae5e2011-12-06 17:22:19 -080097 KeyedVector< wp<DisplayEventConnection>, ConnectionInfo > mDisplayEventConnections;
Mathias Agopian8aedd472012-01-24 16:39:14 -080098 nsecs_t mLastVSyncTimestamp;
Mathias Agopian478ae5e2011-12-06 17:22:19 -080099
100 // main thread only
Mathias Agopiand0566bc2011-11-17 17:49:17 -0800101 size_t mDeliveredEvents;
102};
103
104// ---------------------------------------------------------------------------
105
106}; // namespace android
107
108// ---------------------------------------------------------------------------
109
110#endif /* ANDROID_SURFACE_FLINGER_EVENT_THREAD_H */