forked from krnlyng/sfdroid_renderer
-
Notifications
You must be signed in to change notification settings - Fork 6
/
sfconnection.h
67 lines (52 loc) · 1.81 KB
/
sfconnection.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef __SF_CONNECTION_H__
#define __SF_CONNECTION_H__
#include <thread>
#include <atomic>
#include <condition_variable>
#include <vector>
#include <mutex>
#include <hardware/hardware.h>
#include <hardware/gralloc.h>
#include <system/window.h>
#include "sfdroid_defs.h"
extern gralloc_module_t *gralloc_module;
class sfconnection_t {
public:
sfconnection_t() : current_status(0), fd_pass_socket(-1), fd_client(-1), running(false), current_buffer(nullptr), timeout_count(0), my_have_focus(true), notified(false) {}
int init();
void deinit();
int wait_for_client();
buffer_info_t *get_current_info();
ANativeWindowBuffer *get_current_buffer();
void wait_for_event(int timeout);
void start_thread();
void thread_loop();
void stop_thread();
void update_timeout();
bool have_client();
bool have_focus() { return my_have_focus; }
void notify_buffer_done(int failed);
void remove_buffers();
void lost_focus();
void gained_focus();
private:
int wait_for_buffer(int &timedout, bool &is_not_a_buffer);
void send_status_and_cleanup();
int current_status;
bool thread_exited;
int fd_pass_socket; // listen for surfaceflinger
int fd_client; // the client (sharebuffer module)
std::thread my_thread;
std::atomic<bool> running;
std::condition_variable buffer_cond;
std::condition_variable back_cond;
std::mutex notify_mutex, notify_back_mutex;
buffer_info_t current_info;
ANativeWindowBuffer *current_buffer;
unsigned int timeout_count;
bool my_have_focus;
bool notified;
std::vector<ANativeWindowBuffer*> buffers;
std::vector<buffer_info_t> buffer_infos;
};
#endif