some work on x11 ext
This commit is contained in:
+1
-1
@@ -71,6 +71,6 @@ bool com_std_connect(com_std_fd fd, bool isnetwork, char const *address) {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void com_std_exit(uint32_t status) { exit(status); }
|
void com_std_exit(int32_t status) { exit(status); }
|
||||||
|
|
||||||
void com_std_close(com_std_fd fd) { fclose(fd); }
|
void com_std_close(com_std_fd fd) { fclose(fd); }
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ inline bool com_std_connect(com_std_fd fd, bool isnetwork,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void com_std_exit(uint32_t status) {
|
inline void com_std_exit(int32_t status) {
|
||||||
__asm__ volatile("syscall" : : "a"(60), "D"(status) : "rcx", "r11", "memory");
|
__asm__ volatile("syscall" : : "a"(60), "D"(status) : "rcx", "r11", "memory");
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ inline bool com_std_connect(com_std_fd fd, bool isnetwork,
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void com_std_exit(uint32_t status) {
|
inline void com_std_exit(int32_t status) {
|
||||||
__asm__ volatile("int $0x80" : : "a"(1), "b"(status) : "memory", "cc");
|
__asm__ volatile("int $0x80" : : "a"(1), "b"(status) : "memory", "cc");
|
||||||
__builtin_unreachable();
|
__builtin_unreachable();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,3 +12,5 @@ void *com_std_alloc(void *ptr, size_t size) { return NULL; }
|
|||||||
|
|
||||||
double com_std_sqrt(double v) { return __builtin_sqrt(v); }
|
double com_std_sqrt(double v) { return __builtin_sqrt(v); }
|
||||||
double com_std_fabs(double v) { return __builtin_fabs(v); }
|
double com_std_fabs(double v) { return __builtin_fabs(v); }
|
||||||
|
double com_std_sin(double v) { return __builtin_sin(v); }
|
||||||
|
double com_std_cos(double v) { return __builtin_cos(v); }
|
||||||
|
|||||||
+22
-17
@@ -24,23 +24,28 @@ size_t strlen(char const *s) {
|
|||||||
return p - s;
|
return p - s;
|
||||||
}
|
}
|
||||||
|
|
||||||
double com_std_sin(double v) {
|
double sin(double v) {
|
||||||
double result;
|
double r;
|
||||||
__asm__ __volatile__("fldl %1\n\t"
|
__asm__ __volatile__("fsin" : "=t"(r) : "0"(v));
|
||||||
"fsin\n\t"
|
|
||||||
"fstpl %0"
|
return r;
|
||||||
: "=g"(result)
|
|
||||||
: "m"(v)
|
|
||||||
: "st", "st(1)");
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
double com_std_cos(double v) {
|
double cos(double v) {
|
||||||
double result;
|
double r;
|
||||||
__asm__ __volatile__("fldl %1\n\t"
|
__asm__ __volatile__("fcos" : "=t"(r) : "0"(v));
|
||||||
"fcos\n\t"
|
return r;
|
||||||
"fstpl %0"
|
}
|
||||||
: "=g"(result)
|
|
||||||
: "m"(v));
|
void sincos(double v, double *s, double *c) {
|
||||||
return result;
|
double sv, cv;
|
||||||
|
__asm__ __volatile__("fsincos" : "=t"(cv), "=u"(sv) : "0"(v));
|
||||||
|
*s = sv;
|
||||||
|
*c = cv;
|
||||||
|
}
|
||||||
|
|
||||||
|
double sqrt(double v) {
|
||||||
|
double r;
|
||||||
|
__asm__ volatile("sqrtss %1, %0" : "=x"(r) : "x"(v));
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -37,7 +37,7 @@ typedef struct com_buf {
|
|||||||
struct com_buf *p_v = (struct com_buf *)&p_v##_buf; \
|
struct com_buf *p_v = (struct com_buf *)&p_v##_buf; \
|
||||||
p_v->cap = (p_c); \
|
p_v->cap = (p_c); \
|
||||||
p_v->flags = p_f | COM_BUF_STACK; \
|
p_v->flags = p_f | COM_BUF_STACK; \
|
||||||
p_v->typesz = sizeof(p_t);
|
p_v->typesz = sizeof(p_t)
|
||||||
|
|
||||||
#define com_buf_index_as(p_t, p_v, p_i) \
|
#define com_buf_index_as(p_t, p_v, p_i) \
|
||||||
(p_t *)(&(p_v)->data[sizeof(p_t) * (p_i)])
|
(p_t *)(&(p_v)->data[sizeof(p_t) * (p_i)])
|
||||||
|
|||||||
+2
-6
@@ -57,12 +57,7 @@ static inline uint8_t com_gem_clip_vis_project(com_vec_t a, com_pnt_t *out) {
|
|||||||
mask ^= COM_GEM_VERTEX_CLIPPED_X;
|
mask ^= COM_GEM_VERTEX_CLIPPED_X;
|
||||||
if (a.a[1] < -a.a[2] || a.a[1] > a.a[2])
|
if (a.a[1] < -a.a[2] || a.a[1] > a.a[2])
|
||||||
mask ^= COM_GEM_VERTEX_CLIPPED_Y;
|
mask ^= COM_GEM_VERTEX_CLIPPED_Y;
|
||||||
// out->a[0] = com_fix_mul((com_fix_div(a.a[0], a.a[2]) + COM_FIX_FRACUNIT) >>
|
|
||||||
// 1,
|
|
||||||
// COM_CFG_WIDTH * COM_FIX_FRACUNIT);
|
|
||||||
// out->a[1] = com_fix_mul((com_fix_div(a.a[1], a.a[2]) + COM_FIX_FRACUNIT) >>
|
|
||||||
// 1,
|
|
||||||
// COM_CFG_HEIGHT * COM_FIX_FRACUNIT);
|
|
||||||
out->a[0] = (com_fix_mul(com_fix_div(a.a[0], a.a[2]),
|
out->a[0] = (com_fix_mul(com_fix_div(a.a[0], a.a[2]),
|
||||||
COM_CFG_WIDTH * COM_FIX_FRACUNIT) >>
|
COM_CFG_WIDTH * COM_FIX_FRACUNIT) >>
|
||||||
COM_FIX_FRACBITS) +
|
COM_FIX_FRACBITS) +
|
||||||
@@ -71,6 +66,7 @@ static inline uint8_t com_gem_clip_vis_project(com_vec_t a, com_pnt_t *out) {
|
|||||||
COM_CFG_HEIGHT * COM_FIX_FRACUNIT) >>
|
COM_CFG_HEIGHT * COM_FIX_FRACUNIT) >>
|
||||||
COM_FIX_FRACBITS) +
|
COM_FIX_FRACBITS) +
|
||||||
(COM_CFG_HEIGHT / 2);
|
(COM_CFG_HEIGHT / 2);
|
||||||
|
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -26,12 +26,13 @@ typedef void *com_std_fd;
|
|||||||
#define COM_STD_OPEN_WRITE (1 << 1)
|
#define COM_STD_OPEN_WRITE (1 << 1)
|
||||||
com_std_fd com_std_open(char const *path, uint32_t flags);
|
com_std_fd com_std_open(char const *path, uint32_t flags);
|
||||||
bool com_std_write(com_std_fd fd, void const *data, uint32_t bytes);
|
bool com_std_write(com_std_fd fd, void const *data, uint32_t bytes);
|
||||||
|
/* TODO: Return unit32_t, error on ZERO? Separate EOF check? */
|
||||||
int32_t com_std_read(com_std_fd fd, void *data, uint32_t upto);
|
int32_t com_std_read(com_std_fd fd, void *data, uint32_t upto);
|
||||||
bool com_std_has_data(com_std_fd);
|
bool com_std_has_data(com_std_fd);
|
||||||
bool com_std_sfwd(com_std_fd fd, uint32_t bytes);
|
bool com_std_sfwd(com_std_fd fd, uint32_t bytes);
|
||||||
com_std_fd com_std_socket(bool isnetwork);
|
com_std_fd com_std_socket(bool isnetwork);
|
||||||
bool com_std_connect(com_std_fd sock, bool isnetwork, char const *address);
|
bool com_std_connect(com_std_fd sock, bool isnetwork, char const *address);
|
||||||
void com_std_exit(uint32_t status) __attribute__((noreturn));
|
void com_std_exit(int32_t status) __attribute__((noreturn));
|
||||||
void com_std_close(com_std_fd fd);
|
void com_std_close(com_std_fd fd);
|
||||||
|
|
||||||
/* TODO: Remove, use buffer semantics instead. */
|
/* TODO: Remove, use buffer semantics instead. */
|
||||||
|
|||||||
+3
-3
@@ -47,9 +47,9 @@ static inline int32_t com_str_ext_find_char(char const *s, char ch) {
|
|||||||
|
|
||||||
/* Returns true if string 'a' is prefixed by 'b'. */
|
/* Returns true if string 'a' is prefixed by 'b'. */
|
||||||
static inline bool com_str_ext_prefixed(char const *__restrict a,
|
static inline bool com_str_ext_prefixed(char const *__restrict a,
|
||||||
struct com_str prefix) {
|
struct com_str const *prefix) {
|
||||||
uint32_t n = prefix.len;
|
uint32_t n = prefix->len;
|
||||||
char *b = prefix.data;
|
char *b = prefix->data;
|
||||||
while (n && *a && (*a == *b)) {
|
while (n && *a && (*a == *b)) {
|
||||||
++a;
|
++a;
|
||||||
++b;
|
++b;
|
||||||
|
|||||||
+30
-5
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "bits.h"
|
#include "bits.h"
|
||||||
#include "fix.h"
|
#include "fix.h"
|
||||||
|
#include "mat.h"
|
||||||
#include "std.h"
|
#include "std.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
@@ -18,7 +19,7 @@
|
|||||||
static bool com_test_fix(void) {
|
static bool com_test_fix(void) {
|
||||||
bool anyfail = false;
|
bool anyfail = false;
|
||||||
{
|
{
|
||||||
double max_sqrt_deviation = 0.0f;
|
double max_sqrt_deviation = 0.0;
|
||||||
com_fix_t sqrt_accumulator = 0;
|
com_fix_t sqrt_accumulator = 0;
|
||||||
com_fix_t sqrt_test_step = COM_FIX_FRACUNIT >> 2; /* Quarter step */
|
com_fix_t sqrt_test_step = COM_FIX_FRACUNIT >> 2; /* Quarter step */
|
||||||
for (int i = 0; i < COM_FIX_FRACUNIT << 1; ++i) {
|
for (int i = 0; i < COM_FIX_FRACUNIT << 1; ++i) {
|
||||||
@@ -34,7 +35,7 @@ static bool com_test_fix(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
double max_sin_deviation = 0.0f;
|
double max_sin_deviation = 0.0;
|
||||||
com_fix_t sin_accumulator = -COM_FIX_PI * 4;
|
com_fix_t sin_accumulator = -COM_FIX_PI * 4;
|
||||||
com_fix_t sin_test_step = (COM_FIX_PI << 1) >> 10;
|
com_fix_t sin_test_step = (COM_FIX_PI << 1) >> 10;
|
||||||
for (int i = 0; i < 1024 * 32; ++i) {
|
for (int i = 0; i < 1024 * 32; ++i) {
|
||||||
@@ -50,7 +51,7 @@ static bool com_test_fix(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
double max_cos_deviation = 0.0f;
|
double max_cos_deviation = 0.0;
|
||||||
com_fix_t cos_accumulator = -COM_FIX_PI * 4;
|
com_fix_t cos_accumulator = -COM_FIX_PI * 4;
|
||||||
com_fix_t cos_test_step = (COM_FIX_PI << 1) >> 10;
|
com_fix_t cos_test_step = (COM_FIX_PI << 1) >> 10;
|
||||||
for (int i = 0; i < 1024 * 32; ++i) {
|
for (int i = 0; i < 1024 * 32; ++i) {
|
||||||
@@ -66,8 +67,8 @@ static bool com_test_fix(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
double max_sin_deviation = 0.0f;
|
double max_sin_deviation = 0.0;
|
||||||
double max_cos_deviation = 0.0f;
|
double max_cos_deviation = 0.0;
|
||||||
com_fix_t sincos_accumulator = -COM_FIX_PI * 4;
|
com_fix_t sincos_accumulator = -COM_FIX_PI * 4;
|
||||||
com_fix_t sincos_test_step = (COM_FIX_PI << 1) >> 10;
|
com_fix_t sincos_test_step = (COM_FIX_PI << 1) >> 10;
|
||||||
for (int i = 0; i < 1024 * 32; ++i) {
|
for (int i = 0; i < 1024 * 32; ++i) {
|
||||||
@@ -105,6 +106,26 @@ static bool com_test_bits(void) {
|
|||||||
return anyfail;
|
return anyfail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool com_test_mat(void) {
|
||||||
|
bool anyfail = false;
|
||||||
|
|
||||||
|
com_mat_t const m0 = com_mat_identity();
|
||||||
|
com_mat_t m1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
||||||
|
for (int i = 0; i < 16; ++i)
|
||||||
|
m1.a[i] *= COM_FIX_FRACUNIT;
|
||||||
|
|
||||||
|
com_mat_t const mul = com_mat_mul(m1, m0);
|
||||||
|
com_mat_t const mul_reordered = com_mat_mul_reodered(com_mat_reoder(m1), m0);
|
||||||
|
|
||||||
|
for (int i = 0; i < 16; ++i) {
|
||||||
|
TEST(mul.a[i] == mul_reordered.a[i]);
|
||||||
|
if (mul.a[i] != mul_reordered.a[i])
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return anyfail;
|
||||||
|
}
|
||||||
|
|
||||||
static bool com_test_run(void) {
|
static bool com_test_run(void) {
|
||||||
bool anyfail = false;
|
bool anyfail = false;
|
||||||
if (com_test_fix()) {
|
if (com_test_fix()) {
|
||||||
@@ -115,6 +136,10 @@ static bool com_test_run(void) {
|
|||||||
com_std_print('c', "com_bits tests failed!");
|
com_std_print('c', "com_bits tests failed!");
|
||||||
anyfail = true;
|
anyfail = true;
|
||||||
}
|
}
|
||||||
|
if (com_test_mat()) {
|
||||||
|
com_std_print('c', "com_mat tests failed!");
|
||||||
|
anyfail = true;
|
||||||
|
}
|
||||||
return !anyfail;
|
return !anyfail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+128
-53
@@ -10,7 +10,6 @@
|
|||||||
#include "../../Common/cfg.h"
|
#include "../../Common/cfg.h"
|
||||||
#include "../../Common/def.h"
|
#include "../../Common/def.h"
|
||||||
#include "../../Common/lzw.h"
|
#include "../../Common/lzw.h"
|
||||||
#include "../../Common/mat.h"
|
|
||||||
#include "../../Common/std.h"
|
#include "../../Common/std.h"
|
||||||
#include "../../Common/str.h"
|
#include "../../Common/str.h"
|
||||||
#include "../../Common/test.h"
|
#include "../../Common/test.h"
|
||||||
@@ -53,13 +52,13 @@ static struct {
|
|||||||
uint32_t resource_id_mask;
|
uint32_t resource_id_mask;
|
||||||
} plr_x11_connection;
|
} plr_x11_connection;
|
||||||
|
|
||||||
bool quited = false;
|
static bool fileread(void *ctx, char *into, uint32_t bytes) {
|
||||||
|
|
||||||
bool fileread(void *ctx, char *into, uint32_t bytes) {
|
|
||||||
return com_std_read(ctx, into, bytes) == bytes;
|
return com_std_read(ctx, into, bytes) == bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool fileskip(void *ctx, uint32_t bytes) { return com_std_sfwd(ctx, bytes); }
|
static bool fileskip(void *ctx, uint32_t bytes) {
|
||||||
|
return com_std_sfwd(ctx, bytes);
|
||||||
|
}
|
||||||
|
|
||||||
#define AUTH_ENTRY_MAGIC_COOKIE "MIT-MAGIC-COOKIE-1"
|
#define AUTH_ENTRY_MAGIC_COOKIE "MIT-MAGIC-COOKIE-1"
|
||||||
|
|
||||||
@@ -145,6 +144,8 @@ static bool plr_x11_handshake(com_std_fd xfd,
|
|||||||
if (response.success != 1)
|
if (response.success != 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
/* https://xorg.freedesktop.org/archive/X11R7.7-RC1/doc/xproto/x11protocol.html#server_response
|
||||||
|
*/
|
||||||
struct {
|
struct {
|
||||||
uint32_t release_number;
|
uint32_t release_number;
|
||||||
uint32_t resource_id_base;
|
uint32_t resource_id_base;
|
||||||
@@ -175,8 +176,13 @@ static bool plr_x11_handshake(com_std_fd xfd,
|
|||||||
return false;
|
return false;
|
||||||
if (!com_std_read(xfd, scratch, 8 * dyn_response.formats_count))
|
if (!com_std_read(xfd, scratch, 8 * dyn_response.formats_count))
|
||||||
return false;
|
return false;
|
||||||
|
/* Read first and hope it is what we need. */
|
||||||
if (!com_std_read(xfd, &plr_x11_root_screen, sizeof plr_x11_root_screen))
|
if (!com_std_read(xfd, &plr_x11_root_screen, sizeof plr_x11_root_screen))
|
||||||
return false;
|
return false;
|
||||||
|
/* Then drop all the things that proceed, such as other screens and their
|
||||||
|
* visual profiles. */
|
||||||
|
while (com_std_has_data(xfd))
|
||||||
|
com_std_read(xfd, scratch, sizeof scratch);
|
||||||
|
|
||||||
plr_x11_connection.resource_id_base = dyn_response.resource_id_base;
|
plr_x11_connection.resource_id_base = dyn_response.resource_id_base;
|
||||||
plr_x11_connection.resource_id_mask = dyn_response.resource_id_mask;
|
plr_x11_connection.resource_id_mask = dyn_response.resource_id_mask;
|
||||||
@@ -184,9 +190,7 @@ static bool plr_x11_handshake(com_std_fd xfd,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Instead have a poll_events function instead. */
|
union plr_x11_response {
|
||||||
static inline bool plr_x11_poll_errors(com_std_fd xfd) {
|
|
||||||
union {
|
|
||||||
struct {
|
struct {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
uint8_t errcode;
|
uint8_t errcode;
|
||||||
@@ -203,32 +207,49 @@ static inline bool plr_x11_poll_errors(com_std_fd xfd) {
|
|||||||
uint32_t length;
|
uint32_t length;
|
||||||
char pad[24];
|
char pad[24];
|
||||||
} __attribute__((packed)) reply;
|
} __attribute__((packed)) reply;
|
||||||
} response;
|
};
|
||||||
|
|
||||||
while (com_std_has_data(xfd)) {
|
static bool plr_x11_poll(com_std_fd xfd, bool wait,
|
||||||
if (!com_std_read(xfd, &response, sizeof response))
|
union plr_x11_response *response) {
|
||||||
|
if (!wait && !com_std_has_data(xfd))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
/* Exhaust variable length data of reply. */
|
com_std_read(xfd, response, sizeof(union plr_x11_response));
|
||||||
if (response.reply.type == 1) {
|
return true;
|
||||||
char buf[1024];
|
}
|
||||||
com_std_assert(response.reply.length * 4 <= sizeof buf);
|
|
||||||
if (!com_std_read(xfd, &buf, response.reply.length * 4))
|
static bool plr_x11_poll_reply(com_std_fd xfd, uint16_t seqid,
|
||||||
return false;
|
union plr_x11_response *response) {
|
||||||
|
while (plr_x11_poll(xfd, true, response)) {
|
||||||
|
/* Wait for match. */
|
||||||
|
if (response->reply.type == 1 && response->reply.sequenceid == seqid)
|
||||||
|
break;
|
||||||
|
|
||||||
|
/* Errors could be encountered here, report along the way. */
|
||||||
|
if (response->reply.type == 0) {
|
||||||
|
com_std_print('c', "X11 error code=", 'u', response->error.errcode, 'c',
|
||||||
|
" for seqid=", 'u', response->error.sequenceid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response.reply.type == 0 && response.error.errcode != 0) {
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TODO: Instead we should poll for events, errors are only byproduct. */
|
||||||
|
static bool plr_x11_poll_errors(com_std_fd xfd) {
|
||||||
|
union plr_x11_response response;
|
||||||
|
|
||||||
|
while (plr_x11_poll(xfd, false, &response)) {
|
||||||
|
/* There should be no replies unhandled. */
|
||||||
|
/* TODO: Write down encountered events. */
|
||||||
|
if (response.reply.type == 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (response.reply.type == 0)
|
||||||
com_std_print('c', "X11 error code=", 'u', response.error.errcode, 'c',
|
com_std_print('c', "X11 error code=", 'u', response.error.errcode, 'c',
|
||||||
" for seqid=", 'u', response.error.sequenceid);
|
" for seqid=", 'u', response.error.sequenceid);
|
||||||
|
|
||||||
/* This means X11 closed the connection. */
|
|
||||||
// if (response.error.errcode == 0)
|
|
||||||
// return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO: Save polled events, as they might be used later. */
|
|
||||||
};
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,6 +343,7 @@ static uint32_t plr_x11_create_window(com_std_fd xfd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool plr_x11_show_window(com_std_fd xfd, uint32_t window_id) {
|
static bool plr_x11_show_window(com_std_fd xfd, uint32_t window_id) {
|
||||||
|
uint32_t const seq = plr_x11_next_seqid();
|
||||||
struct {
|
struct {
|
||||||
uint8_t opcode;
|
uint8_t opcode;
|
||||||
uint8_t pad1;
|
uint8_t pad1;
|
||||||
@@ -361,16 +383,82 @@ static uint32_t plr_x11_create_pixmap(com_std_fd xfd, uint32_t window_id) {
|
|||||||
return pixmap_id;
|
return pixmap_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Returns opcode for given extension. */
|
||||||
|
static uint8_t plr_x11_query_extension(com_std_fd xfd, com_str const *ext) {
|
||||||
|
uint32_t const seq = plr_x11_next_seqid();
|
||||||
|
uint16_t const pad = com_bits_nalign(ext->len, 4);
|
||||||
|
struct {
|
||||||
|
uint8_t opcode;
|
||||||
|
uint8_t pad1;
|
||||||
|
uint16_t request_length;
|
||||||
|
uint16_t name_length;
|
||||||
|
uint16_t pad2;
|
||||||
|
} __attribute__((packed)) request = {
|
||||||
|
.opcode = 98,
|
||||||
|
.request_length = sizeof request / 4 + pad / 4,
|
||||||
|
.name_length = ext->len,
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!com_std_write(xfd, &request, sizeof request))
|
||||||
|
return 0;
|
||||||
|
if (!com_std_write(xfd, ext->data, ext->len))
|
||||||
|
return 0;
|
||||||
|
if ((pad - ext->len) && !com_std_write(xfd, ext->data, pad - ext->len))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
union plr_x11_response response;
|
||||||
|
plr_x11_poll_reply(xfd, seq, &response);
|
||||||
|
|
||||||
|
return response.reply.pad[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
This is needed as base X11 doesn't allow passing more than 16bit x 4bytes.
|
||||||
|
https://xorg.freedesktop.org/archive/current/doc/bigreqsproto/bigreq.html
|
||||||
|
*/
|
||||||
|
static bool plr_x11_enable_big_requests(com_std_fd xfd) {
|
||||||
|
static com_str bigreqext = com_str_lit("BIG-REQUESTS");
|
||||||
|
uint8_t const opcode = plr_x11_query_extension(xfd, &bigreqext);
|
||||||
|
|
||||||
|
/* Request the thing. */
|
||||||
|
struct {
|
||||||
|
uint8_t opcode;
|
||||||
|
uint8_t micode;
|
||||||
|
uint16_t request_length;
|
||||||
|
} __attribute__((packed)) request = {
|
||||||
|
.opcode = opcode,
|
||||||
|
.request_length = sizeof request / 4,
|
||||||
|
};
|
||||||
|
|
||||||
|
uint32_t const seq = plr_x11_next_seqid();
|
||||||
|
if (!com_std_write(xfd, &request, sizeof request))
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Read the response. */
|
||||||
|
union plr_x11_response response;
|
||||||
|
plr_x11_poll_reply(xfd, seq, &response);
|
||||||
|
|
||||||
|
uint32_t const limit = *(uint32_t *)response.reply.pad;
|
||||||
|
com_std_print('c', "Request limit: ", 'u', limit);
|
||||||
|
if (limit < COM_CFG_FBSIZE) {
|
||||||
|
com_std_print('c', "Big request can't accommodate for framebuffer.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool plr_x11_put_framebuffer(com_std_fd xfd, uint32_t gc_id,
|
static bool plr_x11_put_framebuffer(com_std_fd xfd, uint32_t gc_id,
|
||||||
uint32_t pixmap_id,
|
uint32_t pixmap_id,
|
||||||
uint8_t pixels[COM_CFG_FBSIZE]) {
|
uint8_t pixels[COM_CFG_FBSIZE]) {
|
||||||
uint32_t const seq = plr_x11_next_seqid();
|
|
||||||
uint32_t const padded = com_bits_nalign(COM_CFG_FBSIZE, 4);
|
uint32_t const padded = com_bits_nalign(COM_CFG_FBSIZE, 4);
|
||||||
|
uint32_t const seq = plr_x11_next_seqid();
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
uint8_t opcode;
|
uint8_t opcode;
|
||||||
uint8_t format;
|
uint8_t format;
|
||||||
uint16_t request_length;
|
uint16_t bigreq; /* Marked zero so that 32bit could be used. */
|
||||||
|
uint32_t request_length;
|
||||||
uint32_t drawable_id;
|
uint32_t drawable_id;
|
||||||
uint32_t gc_id;
|
uint32_t gc_id;
|
||||||
uint16_t width;
|
uint16_t width;
|
||||||
@@ -398,8 +486,8 @@ static bool plr_x11_put_framebuffer(com_std_fd xfd, uint32_t gc_id,
|
|||||||
if (!com_std_write(xfd, pixels, COM_CFG_FBSIZE))
|
if (!com_std_write(xfd, pixels, COM_CFG_FBSIZE))
|
||||||
return false;
|
return false;
|
||||||
/* Use request memory for pad, it doesn't matter what we write. */
|
/* Use request memory for pad, it doesn't matter what we write. */
|
||||||
uint32_t const padfinal = padded - COM_CFG_FBSIZE;
|
if ((padded - COM_CFG_FBSIZE) &&
|
||||||
if (padfinal && !com_std_write(xfd, &pixels, padfinal))
|
!com_std_write(xfd, &pixels, padded - COM_CFG_FBSIZE))
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -418,7 +506,7 @@ static bool plr_x11_establish_connection(com_std_fd xfd, int argc,
|
|||||||
char const *xauthpath = NULL;
|
char const *xauthpath = NULL;
|
||||||
for (char const *const *envp = &argv[argc + 1]; *envp != NULL; ++envp) {
|
for (char const *const *envp = &argv[argc + 1]; *envp != NULL; ++envp) {
|
||||||
static const struct com_str xauthlit = com_str_lit("XAUTHORITY=");
|
static const struct com_str xauthlit = com_str_lit("XAUTHORITY=");
|
||||||
if (com_str_ext_prefixed(*envp, xauthlit)) {
|
if (com_str_ext_prefixed(*envp, &xauthlit)) {
|
||||||
xauthpath = &((*envp)[xauthlit.len]);
|
xauthpath = &((*envp)[xauthlit.len]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -473,29 +561,11 @@ extern int plr_display_x11_main(int argc, char const *const *argv) {
|
|||||||
com_lzw_free_table(&table);
|
com_lzw_free_table(&table);
|
||||||
com_std_assert(test);
|
com_std_assert(test);
|
||||||
|
|
||||||
com_mat_t m0 = com_mat_identity();
|
|
||||||
com_mat_t m1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16};
|
|
||||||
for (int i = 0; i < 16; ++i)
|
|
||||||
m1.a[i] *= COM_FIX_FRACUNIT;
|
|
||||||
|
|
||||||
com_mat_t t0 = com_mat_mul(m1, m0);
|
|
||||||
com_mat_t t1 = com_mat_mul_reodered(com_mat_reoder(m1), m0);
|
|
||||||
com_std_print('f', t0.a[4]);
|
|
||||||
com_std_print('f', t1.a[4]);
|
|
||||||
|
|
||||||
// com_vec_t v0 = com_mat_vec_project(com_mat_reoder(m0), com_vec_identity());
|
|
||||||
// com_fix_print(v0.a[0]);
|
|
||||||
|
|
||||||
/* TODO: Move to separate executable maybe? */
|
/* TODO: Move to separate executable maybe? */
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
// com_test_run();
|
com_test_run();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// com_fix_run_tests();
|
|
||||||
// com_fix_run_bench();
|
|
||||||
// com_mat_run_bench();
|
|
||||||
|
|
||||||
/* TODO: Move init to separate func. */
|
|
||||||
/* Open X11 socket for communication. */
|
/* Open X11 socket for communication. */
|
||||||
com_std_fd const xfd = com_std_socket(false);
|
com_std_fd const xfd = com_std_socket(false);
|
||||||
if (!xfd) {
|
if (!xfd) {
|
||||||
@@ -513,6 +583,11 @@ extern int plr_display_x11_main(int argc, char const *const *argv) {
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!plr_x11_enable_big_requests(xfd)) {
|
||||||
|
com_std_print('c', "Big requests unsupported for your X11");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t const gc = plr_x11_create_graphical_context(xfd);
|
uint32_t const gc = plr_x11_create_graphical_context(xfd);
|
||||||
if (!gc) {
|
if (!gc) {
|
||||||
com_std_print('c', "Failure to initialize X11");
|
com_std_print('c', "Failure to initialize X11");
|
||||||
@@ -629,10 +704,10 @@ extern int plr_display_x11_main(int argc, char const *const *argv) {
|
|||||||
uint8_t *fbm = plr_draw_get_pixel_buffer();
|
uint8_t *fbm = plr_draw_get_pixel_buffer();
|
||||||
plr_draw_screen(fbm);
|
plr_draw_screen(fbm);
|
||||||
|
|
||||||
// if (!plr_x11_put_framebuffer(xfd, gc, fb, fbm)) {
|
if (!plr_x11_put_framebuffer(xfd, gc, fb, fbm)) {
|
||||||
// com_std_print('c', "Failure to drive X11");
|
com_std_print('c', "Failure to drive X11");
|
||||||
// return -1;
|
return -1;
|
||||||
// }
|
}
|
||||||
|
|
||||||
if (!plr_x11_show_window(xfd, win)) {
|
if (!plr_x11_show_window(xfd, win)) {
|
||||||
com_std_print('c', "Failure to drive X11");
|
com_std_print('c', "Failure to drive X11");
|
||||||
|
|||||||
+23
-10
@@ -1,27 +1,37 @@
|
|||||||
CC = clang
|
CC ?= clang
|
||||||
RELEASE ?= 0 # Optimize.
|
RELEASE ?= 0 # Optimize.
|
||||||
DEBUG ?= 1 # Emit debug info.
|
DEBUG ?= 1 # Emit debug info.
|
||||||
SQUEEZE ?= 0 # Nuclear option to save space.
|
SQUEEZE ?= 0 # Nuclear option to save space.
|
||||||
BITS ?= 64
|
BITS ?= 64
|
||||||
RUN ?= 0
|
RUN ?= 0
|
||||||
|
|
||||||
ISCLANG = 1
|
CFLAGS = -Wall -std=gnu99 -ffast-math -fno-ident -fvisibility=hidden
|
||||||
|
|
||||||
|
# Set cosmopolitan toolchain.
|
||||||
ifeq ($(MAKECMDGOALS),cosmo)
|
ifeq ($(MAKECMDGOALS),cosmo)
|
||||||
ISCLANG = 0
|
CC = ./Cosmo/bin/cosmocc -mclang
|
||||||
ifeq ($(DEBUG), 1)
|
ifeq ($(DEBUG), 1)
|
||||||
CFLAGS += -mdbg
|
CFLAGS += -mdbg
|
||||||
else
|
else
|
||||||
CFLAGS += -mtiny
|
CFLAGS += -mtiny
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
CFLAGS = -Wall -std=gnu99 -ffast-math -fno-ident -fvisibility=hidden
|
|
||||||
ifeq ($(ISCLANG), 1)
|
# Provide LTO where it's applicable.
|
||||||
CFLAGS = -flto=thin -fuse-ld=lld
|
ifeq ($(CC),clang)
|
||||||
|
ISCLANG = 1
|
||||||
|
CFLAGS += -flto=thin -fuse-ld=lld
|
||||||
|
else
|
||||||
|
ifneq ($(MAKECMDGOALS),cosmo)
|
||||||
|
CFLAGS += -flto
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Linux specific options.
|
||||||
ifeq ($(MAKECMDGOALS),linux)
|
ifeq ($(MAKECMDGOALS),linux)
|
||||||
CFLAGS += -fno-pic -fno-pie
|
CFLAGS += -fno-pic -fno-pie
|
||||||
ifeq ($(RELEASE), 1)
|
ifeq ($(RELEASE), 1)
|
||||||
CFLAGS += -Wl,--ignore-data-address-equality -Wl,--ignore-function-address-equality \
|
# CFLAGS += -Wl,--ignore-data-address-equality -Wl,--ignore-function-address-equality \
|
||||||
-Wl,--optimize-bb-jumps
|
-Wl,--optimize-bb-jumps
|
||||||
endif
|
endif
|
||||||
ifeq ($(SQUEEZE), 1)
|
ifeq ($(SQUEEZE), 1)
|
||||||
@@ -37,11 +47,15 @@ ifeq ($(MAKECMDGOALS),linux)
|
|||||||
CFLAGS += -m32 -msse2
|
CFLAGS += -m32 -msse2
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# WASM specific options.
|
||||||
ifeq ($(MAKECMDGOALS),wasm)
|
ifeq ($(MAKECMDGOALS),wasm)
|
||||||
ifeq ($(RELEASE), 1)
|
ifeq ($(RELEASE), 1)
|
||||||
CFLAGS += -Wl,--compress-relocations
|
CFLAGS += -Wl,--compress-relocations
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Separate debug and release switches.
|
||||||
ifeq ($(DEBUG), 1)
|
ifeq ($(DEBUG), 1)
|
||||||
CFLAGS += -g3
|
CFLAGS += -g3
|
||||||
else
|
else
|
||||||
@@ -50,7 +64,7 @@ endif
|
|||||||
ifeq ($(RELEASE), 1)
|
ifeq ($(RELEASE), 1)
|
||||||
CFLAGS += -O3 -fmerge-all-constants -Wl,-O3 \
|
CFLAGS += -O3 -fmerge-all-constants -Wl,-O3 \
|
||||||
-ffunction-sections -fdata-sections -Wl,--gc-sections
|
-ffunction-sections -fdata-sections -Wl,--gc-sections
|
||||||
ifeq ($(ISCLANG), 1)
|
ifeq ($(CC),clang)
|
||||||
CFLAGS += -Wl,-mllvm,--vectorize-slp=true \
|
CFLAGS += -Wl,-mllvm,--vectorize-slp=true \
|
||||||
-Wl,-mllvm,--enable-gvn-hoist=true
|
-Wl,-mllvm,--enable-gvn-hoist=true
|
||||||
endif
|
endif
|
||||||
@@ -66,8 +80,7 @@ wasm:
|
|||||||
$(CC) -o player.wasm ./amalgam.c $(CFLAGS)
|
$(CC) -o player.wasm ./amalgam.c $(CFLAGS)
|
||||||
|
|
||||||
# todo: Add -mtiny for release without debug
|
# todo: Add -mtiny for release without debug
|
||||||
cosmo: CC = ./Cosmo/bin/cosmocc
|
cosmo: CFLAGS += -I /usr/include/X11
|
||||||
cosmo: CFLAGS += -I /usr/include/X11 -mclang
|
|
||||||
cosmo: ./amalgam.c
|
cosmo: ./amalgam.c
|
||||||
$(CC) $(CFLAGS) -o ./Out/Cosmo/player $^
|
$(CC) $(CFLAGS) -o ./Out/Cosmo/player $^
|
||||||
ifeq ($(RUN), 1)
|
ifeq ($(RUN), 1)
|
||||||
|
|||||||
+27
-26
@@ -29,36 +29,37 @@ com_def_export_sym("plr_draw_screen") void plr_draw_screen(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
com_mat_t proj = com_mat_perspective(COM_CFG_WIDTH, COM_CFG_HEIGHT, 1,
|
// com_mat_t proj = com_mat_perspective(COM_CFG_WIDTH, COM_CFG_HEIGHT, 1,
|
||||||
100 * COM_FIX_FRACUNIT, COM_FIX_PIHALF);
|
// 100 * COM_FIX_FRACUNIT,
|
||||||
com_mat_t view = com_mat_look_at(com_vec_from(0, 0, 0),
|
// COM_FIX_PIHALF);
|
||||||
com_vec_from(0, COM_FIX_FRACUNIT, 0),
|
// com_mat_t view = com_mat_look_at(com_vec_from(0, 0, 0),
|
||||||
com_vec_from(-COM_FIX_FRACUNIT, 0, 0));
|
// com_vec_from(0, COM_FIX_FRACUNIT, 0),
|
||||||
com_mat_t mvp = com_mat_reoder(com_mat_mul(proj, view));
|
// com_vec_from(-COM_FIX_FRACUNIT, 0, 0));
|
||||||
|
// com_mat_t mvp = com_mat_reoder(com_mat_mul(proj, view));
|
||||||
|
|
||||||
com_vec_t v0 = com_vec_from(0 * COM_FIX_FRACUNIT, 0, 1 * COM_FIX_FRACUNIT);
|
// com_vec_t v0 = com_vec_from(0 * COM_FIX_FRACUNIT, 0, 1 * COM_FIX_FRACUNIT);
|
||||||
com_vec_t v1 = com_vec_from(1 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT,
|
// com_vec_t v1 = com_vec_from(1 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT,
|
||||||
1 * COM_FIX_FRACUNIT);
|
// 1 * COM_FIX_FRACUNIT);
|
||||||
com_vec_t v2 = com_vec_from(1 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT,
|
// com_vec_t v2 = com_vec_from(1 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT,
|
||||||
1 * COM_FIX_FRACUNIT);
|
// 1 * COM_FIX_FRACUNIT);
|
||||||
com_vec_t v3 = com_vec_from(1 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT,
|
// com_vec_t v3 = com_vec_from(1 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT,
|
||||||
-1 * COM_FIX_FRACUNIT);
|
// -1 * COM_FIX_FRACUNIT);
|
||||||
|
|
||||||
com_pnt_t uv0 = com_pnt_from(0 * COM_FIX_FRACUNIT, 0 * COM_FIX_FRACUNIT);
|
// com_pnt_t uv0 = com_pnt_from(0 * COM_FIX_FRACUNIT, 0 * COM_FIX_FRACUNIT);
|
||||||
com_pnt_t uv1 = com_pnt_from(1 * COM_FIX_FRACUNIT, 0 * COM_FIX_FRACUNIT);
|
// com_pnt_t uv1 = com_pnt_from(1 * COM_FIX_FRACUNIT, 0 * COM_FIX_FRACUNIT);
|
||||||
com_pnt_t uv2 = com_pnt_from(1 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT);
|
// com_pnt_t uv2 = com_pnt_from(1 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT);
|
||||||
com_pnt_t uv3 = com_pnt_from(0 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT);
|
// com_pnt_t uv3 = com_pnt_from(0 * COM_FIX_FRACUNIT, 1 * COM_FIX_FRACUNIT);
|
||||||
|
|
||||||
com_vec_t c0 = com_gem_vec_project_clip(mvp, v0);
|
// com_vec_t c0 = com_gem_vec_project_clip(mvp, v0);
|
||||||
com_vec_t c1 = com_gem_vec_project_clip(mvp, v1);
|
// com_vec_t c1 = com_gem_vec_project_clip(mvp, v1);
|
||||||
com_vec_t c2 = com_gem_vec_project_clip(mvp, v2);
|
// com_vec_t c2 = com_gem_vec_project_clip(mvp, v2);
|
||||||
com_vec_t c3 = com_gem_vec_project_clip(mvp, v3);
|
// com_vec_t c3 = com_gem_vec_project_clip(mvp, v3);
|
||||||
|
|
||||||
com_pnt_t p0, p1, p2, p3;
|
// com_pnt_t p0, p1, p2, p3;
|
||||||
uint8_t cc0 = com_gem_clip_vis_project(c0, &p0);
|
// uint8_t cc0 = com_gem_clip_vis_project(c0, &p0);
|
||||||
uint8_t cc1 = com_gem_clip_vis_project(c1, &p1);
|
// uint8_t cc1 = com_gem_clip_vis_project(c1, &p1);
|
||||||
uint8_t cc2 = com_gem_clip_vis_project(c2, &p2);
|
// uint8_t cc2 = com_gem_clip_vis_project(c2, &p2);
|
||||||
uint8_t cc3 = com_gem_clip_vis_project(c3, &p3);
|
// uint8_t cc3 = com_gem_clip_vis_project(c3, &p3);
|
||||||
|
|
||||||
// com_std_printf("%i, %i\n", p0.a[0], p0.a[1]);
|
// com_std_printf("%i, %i\n", p0.a[0], p0.a[1]);
|
||||||
// com_std_printf("%i, %i\n", p1.a[0], p1.a[1]);
|
// com_std_printf("%i, %i\n", p1.a[0], p1.a[1]);
|
||||||
|
|||||||
Reference in New Issue
Block a user