Some changes to make it work WIP

This commit is contained in:
George Sokianos 2022-02-07 19:39:14 +00:00
parent 9d13525af0
commit cb30b591d2
7 changed files with 127 additions and 44 deletions

View File

@ -5,7 +5,7 @@
# #
LiteXL_OBJ := \ LiteXL_OBJ := \
src/dirmonitor.o src/main.o src/rencache.o src/renderer.o \ src/api/dirmonitor.o src/main.o src/rencache.o src/renderer.o \
src/renwindow.o src/api/api.o src/api/regex.o \ src/renwindow.o src/api/api.o src/api/regex.o \
src/api/renderer.o src/api/system.o src/platform/amigaos4.o src/api/renderer.o src/api/system.o src/platform/amigaos4.o
@ -43,10 +43,10 @@ LiteXL: $(LiteXL_OBJ)
@echo "Compiling $<" @echo "Compiling $<"
@$(compiler) -c $< -o $*.o $(CFLAGS) $(INCPATH) $(DFLAGS) @$(compiler) -c $< -o $*.o $(CFLAGS) $(INCPATH) $(DFLAGS)
src/dirmonitor.o: src/dirmonitor.c src/platform/amigaos4.h src/dirmonitor.o: src/api/dirmonitor.c
src/main.o: src/main.c src/api/api.h src/rencache.h \ src/main.o: src/main.c src/api/api.h src/rencache.h \
src/renderer.h src/platform/amigaos4.h src/dirmonitor.h src/renderer.h src/platform/amigaos4.h
src/rencache.o: src/rencache.c src/rencache.o: src/rencache.c

View File

@ -50,6 +50,8 @@ function dirwatch:watch(directory, bool)
end end
end end
self.watched[directory] = true self.watched[directory] = true
elseif PLATFORM == "AmigaOS 4" then
return self:scan(directory)
else else
local value = self.monitor:watch(directory) local value = self.monitor:watch(directory)
-- If for whatever reason, we can't watch this directory, revert back to scanning. -- If for whatever reason, we can't watch this directory, revert back to scanning.
@ -107,3 +109,4 @@ function dirwatch:check(change_callback, scan_time, wait_time)
end end
return dirwatch return dirwatch

View File

@ -5,6 +5,8 @@
#elif __linux__ #elif __linux__
#include <sys/inotify.h> #include <sys/inotify.h>
#include <limits.h> #include <limits.h>
#elif __amigaos4__
#include "platform/amigaos4.h"
#else #else
#include <sys/event.h> #include <sys/event.h>
#endif #endif
@ -32,10 +34,13 @@ struct dirmonitor {
}; };
struct dirmonitor* init_dirmonitor() { struct dirmonitor* init_dirmonitor() {
printf("DBG: init_dirmonitor\n");
struct dirmonitor* monitor = calloc(sizeof(struct dirmonitor), 1); struct dirmonitor* monitor = calloc(sizeof(struct dirmonitor), 1);
#ifndef _WIN32 #ifndef _WIN32
#if __linux__ #if __linux__
monitor->fd = inotify_init1(IN_NONBLOCK); monitor->fd = inotify_init1(IN_NONBLOCK);
#elif __amigaos4__
monitor->fd = notificationInit(); // TODO: This needs real implementation
#else #else
monitor->fd = kqueue(); monitor->fd = kqueue();
#endif #endif
@ -62,8 +67,11 @@ static void close_monitor_handle(struct dirmonitor* monitor) {
#endif #endif
void deinit_dirmonitor(struct dirmonitor* monitor) { void deinit_dirmonitor(struct dirmonitor* monitor) {
printf("DBG: deinit_dirmonitor\n");
#if _WIN32 #if _WIN32
close_monitor_handle(monitor); close_monitor_handle(monitor);
#elif __amigaos4__
monitor->fd = 0; // TODO: This needs real implementation
#else #else
close(monitor->fd); close(monitor->fd);
#endif #endif
@ -71,6 +79,7 @@ void deinit_dirmonitor(struct dirmonitor* monitor) {
} }
int check_dirmonitor(struct dirmonitor* monitor, int (*change_callback)(int, const char*, void*), void* data) { int check_dirmonitor(struct dirmonitor* monitor, int (*change_callback)(int, const char*, void*), void* data) {
printf("DBG: check_dirmonitor\n");
#if _WIN32 #if _WIN32
if (!monitor->running) { if (!monitor->running) {
if (ReadDirectoryChangesW(monitor->handle, monitor->buffer, sizeof(monitor->buffer), TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME, NULL, &monitor->overlapped, NULL) == 0) if (ReadDirectoryChangesW(monitor->handle, monitor->buffer, sizeof(monitor->buffer), TRUE, FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME, NULL, &monitor->overlapped, NULL) == 0)
@ -101,6 +110,8 @@ int check_dirmonitor(struct dirmonitor* monitor, int (*change_callback)(int, con
for (char *ptr = buf; ptr < buf + len; ptr += sizeof(struct inotify_event) + ((struct inotify_event*)ptr)->len) for (char *ptr = buf; ptr < buf + len; ptr += sizeof(struct inotify_event) + ((struct inotify_event*)ptr)->len)
change_callback(((const struct inotify_event *) ptr)->wd, NULL, data); change_callback(((const struct inotify_event *) ptr)->wd, NULL, data);
} }
#elif __amigaos4__
return 0; // TODO: This needs real implementation
#else #else
struct kevent event; struct kevent event;
while (1) { while (1) {
@ -116,6 +127,7 @@ int check_dirmonitor(struct dirmonitor* monitor, int (*change_callback)(int, con
} }
int add_dirmonitor(struct dirmonitor* monitor, const char* path) { int add_dirmonitor(struct dirmonitor* monitor, const char* path) {
printf("DBG: add_dirmonitor\n");
#if _WIN32 #if _WIN32
close_monitor_handle(monitor); close_monitor_handle(monitor);
monitor->handle = CreateFileA(path, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL); monitor->handle = CreateFileA(path, FILE_LIST_DIRECTORY, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, NULL);
@ -125,6 +137,8 @@ int add_dirmonitor(struct dirmonitor* monitor, const char* path) {
return -1; return -1;
#elif __linux__ #elif __linux__
return inotify_add_watch(monitor->fd, path, IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO); return inotify_add_watch(monitor->fd, path, IN_CREATE | IN_DELETE | IN_MOVED_FROM | IN_MOVED_TO);
#elif __amigaos4__
return -1; // TODO: This needs real implementation
#else #else
int fd = open(path, O_RDONLY); int fd = open(path, O_RDONLY);
struct kevent change; struct kevent change;
@ -135,16 +149,20 @@ int add_dirmonitor(struct dirmonitor* monitor, const char* path) {
} }
void remove_dirmonitor(struct dirmonitor* monitor, int fd) { void remove_dirmonitor(struct dirmonitor* monitor, int fd) {
printf("DBG: remove_dirmonitor\n");
#if _WIN32 #if _WIN32
close_monitor_handle(monitor); close_monitor_handle(monitor);
#elif __linux__ #elif __linux__
inotify_rm_watch(monitor->fd, fd); inotify_rm_watch(monitor->fd, fd);
#elif __amigaos4__
fd = 0; // TODO: This needs real implementation
#else #else
close(fd); close(fd);
#endif #endif
} }
static int f_check_dir_callback(int watch_id, const char* path, void* L) { static int f_check_dir_callback(int watch_id, const char* path, void* L) {
printf("DBG: f_check_dir_callback\n");
#if _WIN32 #if _WIN32
char buffer[PATH_MAX*4]; char buffer[PATH_MAX*4];
int count = WideCharToMultiByte(CP_UTF8, 0, (WCHAR*)path, watch_id, buffer, PATH_MAX*4 - 1, NULL, NULL); int count = WideCharToMultiByte(CP_UTF8, 0, (WCHAR*)path, watch_id, buffer, PATH_MAX*4 - 1, NULL, NULL);
@ -159,29 +177,34 @@ static int f_check_dir_callback(int watch_id, const char* path, void* L) {
} }
static int f_dirmonitor_new(lua_State* L) { static int f_dirmonitor_new(lua_State* L) {
struct dirmonitor** monitor = lua_newuserdata(L, sizeof(struct dirmonitor**)); printf("DBG: f_dirmonitor_new\n");
*monitor = init_dirmonitor(); // struct dirmonitor** monitor = lua_newuserdata(L, sizeof(struct dirmonitor**));
luaL_setmetatable(L, API_TYPE_DIRMONITOR); // *monitor = init_dirmonitor();
// luaL_setmetatable(L, API_TYPE_DIRMONITOR);
return 1; return 1;
} }
static int f_dirmonitor_gc(lua_State* L) { static int f_dirmonitor_gc(lua_State* L) {
deinit_dirmonitor(*((struct dirmonitor**)luaL_checkudata(L, 1, API_TYPE_DIRMONITOR))); printf("DBG: f_dirmonitor_gc\n");
// deinit_dirmonitor(*((struct dirmonitor**)luaL_checkudata(L, 1, API_TYPE_DIRMONITOR)));
return 0; return 0;
} }
static int f_dirmonitor_watch(lua_State *L) { static int f_dirmonitor_watch(lua_State *L) {
lua_pushnumber(L, add_dirmonitor(*(struct dirmonitor**)luaL_checkudata(L, 1, API_TYPE_DIRMONITOR), luaL_checkstring(L, 2))); printf("DBG: f_dirmonitor_watch\n");
// lua_pushnumber(L, add_dirmonitor(*(struct dirmonitor**)luaL_checkudata(L, 1, API_TYPE_DIRMONITOR), luaL_checkstring(L, 2)));
return 1; return 1;
} }
static int f_dirmonitor_unwatch(lua_State *L) { static int f_dirmonitor_unwatch(lua_State *L) {
remove_dirmonitor(*(struct dirmonitor**)luaL_checkudata(L, 1, API_TYPE_DIRMONITOR), luaL_checknumber(L, 2)); printf("DBG: f_dirmonitor_unwatch\n");
// remove_dirmonitor(*(struct dirmonitor**)luaL_checkudata(L, 1, API_TYPE_DIRMONITOR), luaL_checknumber(L, 2));
return 0; return 0;
} }
static int f_dirmonitor_check(lua_State* L) { static int f_dirmonitor_check(lua_State* L) {
lua_pushnumber(L, check_dirmonitor(*(struct dirmonitor**)luaL_checkudata(L, 1, API_TYPE_DIRMONITOR), f_check_dir_callback, L)); printf("DBG: f_dirmonitor_check\n");
// lua_pushnumber(L, check_dirmonitor(*(struct dirmonitor**)luaL_checkudata(L, 1, API_TYPE_DIRMONITOR), f_check_dir_callback, L));
return 1; return 1;
} }
static const luaL_Reg dirmonitor_lib[] = { static const luaL_Reg dirmonitor_lib[] = {
@ -200,3 +223,4 @@ int luaopen_dirmonitor(lua_State* L) {
lua_setfield(L, -2, "__index"); lua_setfield(L, -2, "__index");
return 1; return 1;
} }

View File

@ -11,6 +11,8 @@
#include <direct.h> #include <direct.h>
#include <windows.h> #include <windows.h>
#include <fileapi.h> #include <fileapi.h>
#elif __amigaos4__
#include "platform/amigaos4.h"
#elif __linux__ #elif __linux__
#include <sys/vfs.h> #include <sys/vfs.h>
#endif #endif

View File

@ -59,3 +59,13 @@ char *_fullpath(const char *path)
strcpy(result, getFullPath(path)); strcpy(result, getFullPath(path));
return result; return result;
} }
int notificationInit(void) {
// struct NotifyRequest *notifyRequest;
// if ((notifyrequest = AllocMem(sizeof(struct NotifyRequest), MEMF_CLEAR))) {
// }
return 1;
}

View File

@ -11,6 +11,7 @@ static CONST_STRPTR stack USED = "$STACK:102400";
static CONST_STRPTR version USED = VERSTAG; static CONST_STRPTR version USED = VERSTAG;
char *_fullpath(const char *); char *_fullpath(const char *);
int notificationInit(void);
#endif #endif

View File

@ -246,6 +246,22 @@ float ren_font_group_get_width(RenFont **fonts, const char *text) {
return width / surface_scale; return width / surface_scale;
} }
uint32_t get_pixel(SDL_Surface *surface, uint32_t x, uint32_t y)
{
uint32_t pixel = 0;
uint8_t *pointer = surface->pixels + y * surface->pitch;
pointer += x * surface->format->BytesPerPixel;
memcpy(&pixel, pointer, surface->format->BytesPerPixel);
return pixel;
}
void set_pixel(SDL_Surface *surface, uint32_t x, uint32_t y, uint32_t color)
{
uint8_t *pointer = surface->pixels + y * surface->pitch;
pointer += x * surface->format->BytesPerPixel;
memcpy(pointer, &color, surface->format->BytesPerPixel);
}
float ren_draw_text(RenFont **fonts, const char *text, float x, int y, RenColor color) { float ren_draw_text(RenFont **fonts, const char *text, float x, int y, RenColor color) {
SDL_Surface *surface = renwin_get_surface(&window_renderer); SDL_Surface *surface = renwin_get_surface(&window_renderer);
const RenRect clip = window_renderer.clip; const RenRect clip = window_renderer.clip;
@ -253,9 +269,9 @@ float ren_draw_text(RenFont **fonts, const char *text, float x, int y, RenColor
const int surface_scale = renwin_surface_scale(&window_renderer); const int surface_scale = renwin_surface_scale(&window_renderer);
float pen_x = x * surface_scale; float pen_x = x * surface_scale;
y *= surface_scale; y *= surface_scale;
int bytes_per_pixel = surface->format->BytesPerPixel; // int bytes_per_pixel = surface->format->BytesPerPixel;
const char* end = text + strlen(text); const char* end = text + strlen(text);
unsigned char* destination_pixels = surface->pixels; // unsigned char* destination_pixels = surface->pixels;
int clip_end_x = clip.x + clip.width, clip_end_y = clip.y + clip.height; int clip_end_x = clip.x + clip.width, clip_end_y = clip.y + clip.height;
while (text < end) { while (text < end) {
@ -283,16 +299,36 @@ float ren_draw_text(RenFont **fonts, const char *text, float x, int y, RenColor
start_x += offset; start_x += offset;
glyph_start += offset; glyph_start += offset;
} }
unsigned int* destination_pixel = (unsigned int*)&destination_pixels[surface->pitch * target_y + start_x * bytes_per_pixel]; // unsigned int* destination_pixel = (unsigned int*)&destination_pixels[surface->pitch * target_y + start_x * bytes_per_pixel];
unsigned char* source_pixel = &source_pixels[line * set->surface->pitch + glyph_start * (font->antialiasing == FONT_ANTIALIASING_SUBPIXEL ? 3 : 1)]; // unsigned char* source_pixel = &source_pixels[line * set->surface->pitch + glyph_start * (font->antialiasing == FONT_ANTIALIASING_SUBPIXEL ? 3 : 1)];
for (int x = glyph_start; x < glyph_end; ++x) { // for (int x = glyph_start; x < glyph_end; ++x) {
unsigned int destination_color = *destination_pixel; // unsigned int destination_color = *destination_pixel;
SDL_Color dst = { (destination_color & surface->format->Rmask) >> surface->format->Rshift, (destination_color & surface->format->Gmask) >> surface->format->Gshift, (destination_color & surface->format->Bmask) >> surface->format->Bshift, (destination_color & surface->format->Amask) >> surface->format->Ashift }; // SDL_Color dst = { (destination_color & surface->format->Rmask) >> surface->format->Rshift, (destination_color & surface->format->Gmask) >> surface->format->Gshift, (destination_color & surface->format->Bmask) >> surface->format->Bshift, (destination_color & surface->format->Amask) >> surface->format->Ashift };
SDL_Color src = { *(font->antialiasing == FONT_ANTIALIASING_SUBPIXEL ? source_pixel++ : source_pixel), *(font->antialiasing == FONT_ANTIALIASING_SUBPIXEL ? source_pixel++ : source_pixel), *source_pixel++ }; // SDL_Color src = { *(font->antialiasing == FONT_ANTIALIASING_SUBPIXEL ? source_pixel++ : source_pixel), *(font->antialiasing == FONT_ANTIALIASING_SUBPIXEL ? source_pixel++ : source_pixel), *source_pixel++ };
int px = start_x;
uint8_t* source_pixel = &source_pixels[line * set->surface->pitch + glyph_start * (font->antialiasing == FONT_ANTIALIASING_SUBPIXEL ? 3 : 1)];
for (int x = glyph_start; x < glyph_end; ++x, ++px) {
uint32_t destination_color = get_pixel(surface, px, target_y);
SDL_Color dst;
SDL_Color src;
SDL_GetRGBA(destination_color, surface->format, &dst.r, &dst.g, &dst.b, &dst.a);
if (font->antialiasing == FONT_ANTIALIASING_SUBPIXEL) {
src.r = *(source_pixel++);
src.g = *(source_pixel++);
}
else {
src.r = *(source_pixel);
src.g = *(source_pixel);
}
src.b = *(source_pixel++);
src.a = 0xFF;
r = (color.r * src.r * color.a + dst.r * (65025 - src.r * color.a) + 32767) / 65025; r = (color.r * src.r * color.a + dst.r * (65025 - src.r * color.a) + 32767) / 65025;
g = (color.g * src.g * color.a + dst.g * (65025 - src.g * color.a) + 32767) / 65025; g = (color.g * src.g * color.a + dst.g * (65025 - src.g * color.a) + 32767) / 65025;
b = (color.b * src.b * color.a + dst.b * (65025 - src.b * color.a) + 32767) / 65025; b = (color.b * src.b * color.a + dst.b * (65025 - src.b * color.a) + 32767) / 65025;
*destination_pixel++ = dst.a << surface->format->Ashift | r << surface->format->Rshift | g << surface->format->Gshift | b << surface->format->Bshift; // *destination_pixel++ = dst.a << surface->format->Ashift | r << surface->format->Rshift | g << surface->format->Gshift | b << surface->format->Bshift;
set_pixel(surface, px, target_y, SDL_MapRGBA(surface->format, r, g, b, dst.a));
} }
} }
} }
@ -332,15 +368,16 @@ void ren_draw_rect(RenRect rect, RenColor color) {
y2 = y2 > clip.y + clip.height ? clip.y + clip.height : y2; y2 = y2 > clip.y + clip.height ? clip.y + clip.height : y2;
SDL_Surface *surface = renwin_get_surface(&window_renderer); SDL_Surface *surface = renwin_get_surface(&window_renderer);
uint32_t *d = surface->pixels; // uint32_t *d = surface->pixels;
// #ifdef __amigaos4__
// d += x1 + y1 * surface->pitch/sizeof(uint32_t);
// int dr = surface->pitch/sizeof(uint32_t) - (x2 - x1);
// #else
// d += x1 + y1 * surface->w;
// int dr = surface->w - (x2 - x1);
// #endif
#ifdef __amigaos4__
d += x1 + y1 * surface->pitch/sizeof(uint32_t);
int dr = surface->pitch/sizeof(uint32_t) - (x2 - x1);
#else
d += x1 + y1 * surface->w;
int dr = surface->w - (x2 - x1);
#endif
if (color.a == 0xff) { if (color.a == 0xff) {
uint32_t translated = SDL_MapRGB(surface->format, color.r, color.g, color.b); uint32_t translated = SDL_MapRGB(surface->format, color.r, color.g, color.b);
SDL_Rect rect = { x1, y1, x2 - x1, y2 - y1 }; SDL_Rect rect = { x1, y1, x2 - x1, y2 - y1 };
@ -348,13 +385,19 @@ void ren_draw_rect(RenRect rect, RenColor color) {
} else { } else {
RenColor current_color; RenColor current_color;
RenColor blended_color; RenColor blended_color;
// printf("DBG: surface->w %d\tsurface->pitch %d\tsurface->pitch/4 %d\n", surface->w, surface->pitch, surface->pitch/4);
for (int j = y1; j < y2; j++) { for (int j = y1; j < y2; j++) {
for (int i = x1; i < x2; i++, d++) { // for (int i = x1; i < x2; i++, d++) {
SDL_GetRGB(*d, surface->format, &current_color.r, &current_color.g, &current_color.b); for (int i = x1; i < x2; i++) {
// SDL_GetRGB(*d, surface->format, &current_color.r, &current_color.g, &current_color.b);
uint32_t p = get_pixel(surface, i, j);
SDL_GetRGB(p, surface->format, &current_color.r, &current_color.g, &current_color.b);
blended_color = blend_pixel(current_color, color); blended_color = blend_pixel(current_color, color);
*d = SDL_MapRGB(surface->format, blended_color.r, blended_color.g, blended_color.b); // *d = SDL_MapRGB(surface->format, blended_color.r, blended_color.g, blended_color.b);
set_pixel(surface, i, j, SDL_MapRGB(surface->format, blended_color.r, blended_color.g, blended_color.b));
} }
d += dr; // d += dr;
} }
} }
} }