summaryrefslogtreecommitdiff
path: root/src/screen/screen.h
blob: bb28a1b71beb61b3a85ebcab28f7e28a04983a81 (plain)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#pragma once

#include <al/array.h>
#include <al/atomic.h>
#ifdef CAMU_SCREEN_THREADED
#include <nnwt/thread.h>
#endif
#include <stl/window.h>

#include "../buffer/video.h"
#include "../render/renderer.h"

#include "view.h"

#define CAMU_SCREEN_DEBUG_KEY

// Interpret click and drag as seeking. Mainly a seek performance test.
//#define CAMU_SCREEN_DRAG_SEEK

#define CAMU_SCREEN_WIDTH 840
#define CAMU_SCREEN_HEIGHT 700

enum {
    CAMU_SCREEN_MOD_SHIFT = 1,
    CAMU_SCREEN_MOD_CONTROL = 1 << 1,
    CAMU_SCREEN_DRAGGING = 1 << 2,
    CAMU_SCREEN_MOUSE_MOD = 1 << 3,
    CAMU_SCREEN_ZOOMING = 1 << 4,
    CAMU_SCREEN_ZOOM_PAN_SIMPLE = 1 << 5,
    CAMU_SCREEN_ZOOM_FOV = 1 << 6,
    CAMU_SCREEN_FROZEN = 1 << 7
};

enum {
    CAMU_SCREEN_PAUSED = 0,
    CAMU_SCREEN_PLAYING
};

enum {
    CAMU_SCREEN_SET_VOLUME = 0, // f32
    CAMU_SCREEN_OFFSET_VOLUME, // f32
    CAMU_SCREEN_ADD, // str
    CAMU_SCREEN_SKIP, // s32
    CAMU_SCREEN_TOGGLE_PAUSE,
    CAMU_SCREEN_PERCENT_SEEK, // f64
    CAMU_SCREEN_RELATIVE_SEEK, // f64
    CAMU_SCREEN_RESEEK,
    CAMU_SCREEN_AUDIO_TRACK, // s32
    CAMU_SCREEN_SUBTITLE_TRACK, // s32
    CAMU_SCREEN_SHUFFLE,
    CAMU_SCREEN_STATUS,
    CAMU_SCREEN_PRINT,
#ifdef CAMU_SCREEN_DEBUG_KEY
    CAMU_SCREEN_DEBUG,
#endif
    CAMU_SCREEN_CLOSE
};

struct camu_screen_video {
    struct camu_view view;
    struct camu_video_buffer *buf;
};

enum {
    CAMU_OSD_CONNECTING = 1,
    CAMU_OSD_PAUSE = 1 << 1,
    CAMU_OSD_EMPTY = 1 << 2,
    CAMU_OSD_TOGGLED = 1 << 3,
    CAMU_OSD_ALT_TOGGLED = 1 << 4,
    CAMU_OSD_KEY_HELD = 1 << 5
};

enum {
    CAMU_OSD_ALT_NONE = 0,
    CAMU_OSD_ALT_BINDS
};

enum {
    CAMU_OSD_BAR_PROGRESS = 0,
    CAMU_OSD_BAR_SEEK,
    CAMU_OSD_BAR_VOLUME
};

#define CAMU_OSD_FLASH_FOR(s) (nn_get_tick() + s)

struct camu_osd {
    u32 show;
    u8 alt;
    u8 shown_for;
    bool no_force_render;
    f64 flash;
    u32 connecting;
    u32 paused;
    u32 bar_mode;
    f64 bar;
    f64 pts;
    u64 duration;
};

struct camu_screen {
    atomic(s32) state;
    struct stl_window *window;
#ifdef STELA_EVENT_BUFFER
    struct nn_thread thread;
#endif
    struct camu_renderer *renderer;
    atomic(u32) force_refresh;
    u32 flags;
    u32 width;
    u32 height;
    bool fullscreen;
    bool scaling_disabled;
    bool transparent_background;
#ifdef CAMU_HAVE_SUBTITLES
    bool subtitles_enabled;
#endif
    u64 last_click_ts;
    f64 last_pointer_y;
    f64 last_pointer_x;
    f64 last_touch_x[2];
    f64 last_touch_y[2];
    f64 last_distance;
    f64 midpoint_x;
    f64 midpoint_y;
#ifdef CAMU_SCREEN_DRAG_SEEK
    u64 last_seek_ts;
#endif
    bool touch_mode;
    struct camu_osd osd;
    u8 vr_emulation;
    bool vr_left_eye;
    f64 vr_calibrate_x;
    f64 vr_calibrate_y;
    array(struct camu_screen_video) videos;
#ifdef CAMU_SCREEN_THREADED
    array(struct camu_video_buffer *) add_queue;
    array(struct camu_video_buffer *) rem_queue;
    atomic(bool) queued;
    struct nn_mutex mutex;
#endif
    void (*callback)(void *, u8, void *);
    void *userdata;
};

void camu_screen_init(struct camu_screen *scr);
bool camu_screen_create_window(struct camu_screen *scr, const char *name);
bool camu_screen_create_renderer(struct camu_screen *scr, struct camu_renderer *renderer);
void camu_screen_add_buffer(struct camu_screen *scr, struct camu_video_buffer *buf);
void camu_screen_remove_buffer(struct camu_screen *scr, struct camu_video_buffer *buf);
#ifdef CAMU_SCREEN_THREADED
void camu_screen_run_queue(struct camu_screen *scr);
void camu_screen_clear(struct camu_screen *scr);
#endif
void camu_screen_set_state(struct camu_screen *scr, s32 state);
void camu_screen_force_refresh(struct camu_screen *scr);
bool camu_screen_poll(struct camu_screen *scr, bool block);
bool camu_screen_tick(struct camu_screen *scr, bool *force);
void camu_screen_wake(struct camu_screen *scr);
void camu_screen_close(struct camu_screen *scr);