• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2016 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_SURFACEREPLAYER_EVENT_H
18 #define ANDROID_SURFACEREPLAYER_EVENT_H
19 
20 #include <frameworks/native/cmds/surfacereplayer/proto/src/trace.pb.h>
21 
22 #include <condition_variable>
23 #include <mutex>
24 
25 namespace android {
26 
27 using Increment = surfaceflinger::Increment;
28 
29 class Event {
30   public:
31     Event(Increment::IncrementCase);
32 
33     enum class EventState {
34         SettingUp,  // Completing as much time-independent work as possible
35         Waiting,    // Waiting for signal from main thread to finish execution
36         Signaled,   // Signaled by main thread, about to immediately switch to Running
37         Running     // Finishing execution of rest of work
38     };
39 
40     void readyToExecute();
41     void complete();
42 
43     Increment::IncrementCase getIncrementType();
44 
45   private:
46     void waitUntil(EventState state);
47     void changeState(EventState state);
48 
49     std::mutex mLock;
50     std::condition_variable mCond;
51 
52     EventState mState = EventState::SettingUp;
53 
54     Increment::IncrementCase mIncrementType;
55 };
56 }
57 #endif
58