summaryrefslogtreecommitdiff
path: root/source/base/base_platform.h
diff options
context:
space:
mode:
Diffstat (limited to 'source/base/base_platform.h')
-rw-r--r--source/base/base_platform.h134
1 files changed, 74 insertions, 60 deletions
diff --git a/source/base/base_platform.h b/source/base/base_platform.h
index 10f90b0..875986d 100644
--- a/source/base/base_platform.h
+++ b/source/base/base_platform.h
@@ -16,14 +16,30 @@ struct Directory {
16 String8List *file_names; 16 String8List *file_names;
17}; 17};
18 18
19#if 0 // TODO: @WAYLAND and @X11 implementation 19#if 1 // TODO: @WAYLAND and @X11 implementation
20typedef struct LinuxWindowHandle LinuxWindowHandle; 20
21struct LinuxWindowHandle { 21typedef struct Display Display;
22struct Display
23{
24 int width;
25 int height;
26};
27
28typedef struct Window Window;
29struct Window
30{
31 int width;
32 int height;
33};
34
35typedef struct LinuxWindowParams LinuxWindowParams;
36struct LinuxWindowParams {
37 cstring name;
22 Display *display; 38 Display *display;
23 Window window; 39 Window window;
24}; 40};
25 41
26#define LinuxLoadSharedLibrary(library, name) unix_ 42#define LinuxLoadSharedLibrary(arena, library) unix_load_shared_library(arena, library)
27#endif 43#endif
28 44
29//- Shared libraries 45//- Shared libraries
@@ -51,14 +67,16 @@ internal void unix_log_with_args(const char *format, ...);
51#define FileExists(path) unix_file_exists(path) 67#define FileExists(path) unix_file_exists(path)
52#define DirLoad(arena, path) unix_open_dir(arena, path) 68#define DirLoad(arena, path) unix_open_dir(arena, path)
53 69
54#define OSExit() unix_os_exit();
55 70
56#if COMPILER_GCC || COMPILER_CLANG 71#if DEBUG
57// TODO: __VA_ARGS__ CLANG 72#define OSExit(code) _exit(code)
58#define Log(...) unix_log_with_args(__VA_ARGS__) 73#define Log(...) unix_log_with_args(__VA_ARGS__)
59#define LogStr8(message) \ 74#define LogStr8(message) Log(Str8Fmt, Str8Arg(message))
60 Log(Str8Fmt, Str8Arg(message)) // NOTE: for this to wwork we need the /analyze argument 75#else
61#endif // COMPILER_GCC || COMPILER_CLANG 76#define OSExit(code) Unused(code)
77#define Log(...) ((void)0)
78#define LogStr8(message) ((void)0)
79#endif // disable comments when debug mode is disabled
62 80
63//- Entrypoint and platform window layer 81//- Entrypoint and platform window layer
64#define ENTRYPOINT() int main(int count, char **args) 82#define ENTRYPOINT() int main(int count, char **args)
@@ -95,59 +113,55 @@ internal s32 x11_read_input();
95//- Wayland 113//- Wayland
96#elif WAYLAND 114#elif WAYLAND
97 115
98//- protocol values defined in the wayland library. it's a library load less i guess 116typedef struct WaylandState WaylandState;
99global_variable const u32 wayland_display_object_id = 1; 117struct WaylandState {
100global_variable const u16 wayland_wl_registry_event_global = 0; 118 //- connection
101global_variable const u16 wayland_shm_pool_event_format = 0; 119 struct wl_display *display;
102global_variable const u16 wayland_wl_buffer_event_release = 0; 120 struct wl_registry *registry;
103global_variable const u16 wayland_xdg_wm_base_event_ping = 0;
104global_variable const u16 wayland_xdg_toplevel_event_configure = 0;
105global_variable const u16 wayland_xdg_toplevel_event_close = 1;
106global_variable const u16 wayland_xdg_surface_event_configure = 0;
107global_variable const u16 wayland_wl_display_get_registry_opcode = 1;
108global_variable const u16 wayland_wl_registry_bind_opcode = 0;
109global_variable const u16 wayland_wl_compositor_create_surface_opcode = 0;
110global_variable const u16 wayland_xdg_wm_base_pong_opcode = 3;
111global_variable const u16 wayland_xdg_surface_ack_configure_opcode = 4;
112global_variable const u16 wayland_wl_shm_create_pool_opcode = 0;
113global_variable const u16 wayland_xdg_wm_base_get_xdg_surface_opcode = 2;
114global_variable const u16 wayland_wl_shm_pool_create_buffer_opcode = 0;
115global_variable const u16 wayland_wl_surface_attach_opcode = 1;
116global_variable const u16 wayland_xdg_surface_get_toplevel_opcode = 1;
117global_variable const u16 wayland_wl_surface_commit_opcode = 6;
118global_variable const u16 wayland_wl_display_error_event = 0;
119global_variable const u32 wayland_format_xrgb8888 = 1;
120global_variable const u32 wayland_header_size = 8;
121global_variable const u32 color_channels = 4;
122 121
123enum state_state_t: u16 { 122 struct wl_compositor *compositor;
124 STATE_NONE, 123 struct wl_shm *shm;
125 STATE_SURFACE_ACKED_CONFIGURE, 124 struct xdg_wm_base *xdg_wm_base;
126 STATE_SURFACE_ATTACHED, 125 struct wl_seat *seat;
127}; 126
127 //- window objects
128 128
129typedef struct state_t state_t; 129 struct wl_surface *surface;
130struct state_t { 130 struct xdg_surface *xdg_surface;
131 uint32_t wl_registry; 131 struct xdg_toplevel *xdg_toplevel;
132 uint32_t wl_shm; 132
133 uint32_t wl_shm_pool; 133 //- keyboard input
134 uint32_t wl_buffer; 134 struct wl_keyboard *keyboard;
135 uint32_t xdg_wm_base; 135 b32 keys_down[256]; // indexed by linux scancode
136 uint32_t xdg_surface; 136
137 uint32_t wl_compositor; 137//- mouse (pointer) input
138 uint32_t wl_surface; 138
139 uint32_t xdg_toplevel; 139struct wl_pointer *pointer; // wl_pointer is a predefined <wayland-client.h> struct
140 uint32_t stride; 140f32 mouse_x, mouse_y;
141 uint32_t w; 141b32 mouse_buttons[3];
142 uint32_t h; 142f32 x_offset, y_offset;
143 uint32_t shm_pool_size; 143b32 mouse_in_window;
144 int shm_fd; 144
145 uint8_t *shm_pool_data; 145
146 146
147 state_state_t state; 147 //- software framebuffer
148 struct wl_buffer *buffer;
149 u8 *pixels;
150 u32 width;
151 u32 height;
152 u32 stride;
153 u32 size;
154
155 b32 should_close;
148}; 156};
149 157
158#pragma GCC diagnostic push
159#pragma GCC diagnostic ignored "-Wattributes"
160#include "xdg-shell-protocol.c"
161#pragma GCC diagnostic pop
162
150 163
164#include "base_platform_linux_wayland_input.cpp"
151#include "base_platform_linux_wayland.cpp" 165#include "base_platform_linux_wayland.cpp"
152 166
153#endif // X11 and Wayland -- set by build params 167#endif // X11 and Wayland -- set by build params
@@ -190,7 +204,7 @@ internal void win32_log(String8List messages);
190#define FileExists(path) win32_file_exists(path) 204#define FileExists(path) win32_file_exists(path)
191#define Win32FileExists(path) win32_file_exists(path) 205#define Win32FileExists(path) win32_file_exists(path)
192#define DirLoad(arena, path) win32_open_dir(arena, original_path); 206#define DirLoad(arena, path) win32_open_dir(arena, original_path);
193#define OSExit() win32_os_exit(); 207#define OSExit(code) win32_os_exit()
194 208
195#if COMPILER_GCC || COMPILER_CLANG 209#if COMPILER_GCC || COMPILER_CLANG
196 210
@@ -200,7 +214,7 @@ internal void win32_logf(const char *fmt, ...) PRINTF_FORMAT;
200#elif COMPILER_MSVC 214#elif COMPILER_MSVC
201internal void win32_logf(_Printf_format_string_ const char *fmt, ...); 215internal void win32_logf(_Printf_format_string_ const char *fmt, ...);
202 216
203#define Log(fmt, ...) win32_logf(fmt, __VA_ARGS__) 217#define Log(fmt, ...) win32_logf(fmt, ##__VA_ARGS__)
204 218
205#endif // COMPILER_GCC || COMPILER_CLANG 219#endif // COMPILER_GCC || COMPILER_CLANG
206 220