From f363c34499e18cc7a3970dd08d41f8a596860de8 Mon Sep 17 00:00:00 2001 From: George Sokianos Date: Sun, 27 Mar 2022 21:17:48 +0100 Subject: [PATCH] Applied all the necessary changes to make it run under AmigaOS 4.1 FE --- .gitignore | 5 ++ Makefile.os4 | 81 +++++++++++++++++++ README_OS4.md | 164 ++++++++++++++++++++++++++++++++++++++ README_OS4.md.info | Bin 0 -> 5092 bytes data/core/init.lua | 2 +- data/core/keymap.lua | 3 +- data/core/modkeys-os4.lua | 15 ++++ data/core/start.lua | 2 +- lib/dmon/dmon.h | 6 +- src/api/api.c | 4 +- src/api/system.c | 59 ++++++++------ src/dirmonitor.c | 14 ++-- src/main.c | 12 ++- src/platform/amigaos4.c | 61 ++++++++++++++ src/platform/amigaos4.h | 16 ++++ src/renderer.c | 31 ++++--- src/renwindow.c | 14 +++- 17 files changed, 439 insertions(+), 50 deletions(-) create mode 100644 Makefile.os4 create mode 100644 README_OS4.md create mode 100644 README_OS4.md.info create mode 100644 data/core/modkeys-os4.lua create mode 100644 src/platform/amigaos4.c create mode 100644 src/platform/amigaos4.h diff --git a/.gitignore b/.gitignore index 16974405..4cd410cc 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,8 @@ compile_commands.json error.txt lite-xl* LiteXL* +lite +.config/ +*.lha +release_files +*.o diff --git a/Makefile.os4 b/Makefile.os4 new file mode 100644 index 00000000..16b1f414 --- /dev/null +++ b/Makefile.os4 @@ -0,0 +1,81 @@ +# +# Project: Lite XL +# +# Created on: 26-12-2021 +# + +LiteXL_OBJ := \ + src/dirmonitor.o src/main.o src/rencache.o src/renderer.o \ + src/renwindow.o src/api/api.o src/api/regex.o \ + src/api/renderer.o src/api/system.o src/platform/amigaos4.o + + +outfile := lite +compiler := gcc +cxxcompiler := g++ + +INCPATH := -Isrc -Ilib/dmon -I/sdk/local/newlib/include/SDL2 -I/sdk/local/common/include/freetype2 +DFLAGS := -D__USE_INLINE__ -DLITE_XL_DATA_USE_EXEDIR +# -DLITE_USE_SDL_RENDERER +# -Wextra -Wall +CFLAGS := -Werror -Wwrite-strings -O3 -g -std=gnu11 -fno-strict-aliasing +# "-gstabs -finstrument-functions -fno-inline -DPROFILING" +LFLAGS := -mcrt=newlib -static-libgcc -static-libstdc++ -lauto -lpcre2 -lSDL2 -llua -lagg -lfreetype -lm -lunix -lpthread -athread=native +# " -lprofyle" + + + +.PHONY: LiteXL clean release + +default: LiteXL + +clean: + @echo "Cleaning compiler objects..." + @rm -f $(LiteXL_OBJ) + +LiteXL: $(LiteXL_OBJ) + @echo "Linking LiteXL" + @$(cxxcompiler) -o $(outfile) $(LiteXL_OBJ) $(LFLAGS) + + + +.c.o: + @echo "Compiling $<" + @$(compiler) -c $< -o $*.o $(CFLAGS) $(INCPATH) $(DFLAGS) + +src/dirmonitor.o: src/dirmonitor.c src/platform/amigaos4.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/rencache.o: src/rencache.c + +src/renderer.o: src/renderer.c + +src/renwindow.o: src/renwindow.c + +src/api/api.o: src/api/api.c + +src/api/regex.o: src/api/regex.c + +src/api/renderer.o: src/api/renderer.c + +src/api/system.o: src/api/system.c + +src/platform/amigaos4.o: src/platform/amigaos4.c + + + + +release: + mkdir -p release/LiteXL + cp release_files/* release/LiteXL/ -r + mv release/LiteXL/LiteXL.info release/ + cp data release/LiteXL/ -r + cp changelog.md release/LiteXL/ + cp lite release/LiteXL/ + strip release/LiteXL/lite + cp README.md release/LiteXL/ + cp README_OS4.md release/LiteXL/ + cp LICENSE release/LiteXL/ + lha -aeqr3 a LiteXL.lha release/ diff --git a/README_OS4.md b/README_OS4.md new file mode 100644 index 00000000..60c1b578 --- /dev/null +++ b/README_OS4.md @@ -0,0 +1,164 @@ +# Lite XL v2.0.5 for AmigaOS 4.1 FE + +Lite XL is a lightweight text editor written in Lua. + +## Installation +You can extract the Lite XL archive wherever you want and run the *lite* +editor. + +## Configuration folder +This editor creates a `.config` folder where the configuration is saved, as +well as plugins, themes etc.. By default this AmigaOS 4.1 FE version uses the +executable folder, but if you want to ovveride it, create an ENV variable +named `HOME` and set there your path. + +You can check if there is one already set by executing the following command +in a shell +``` +GetEnv HOME +``` +If there is one set, then you will see the path at the output. + +Otherwise, you can set your home path be executing the following command. +Change the path to the one of your preference. +``` +SetEnv SAVE HOME "Sys:home/" +``` + +## Addons +### Colors +Colors are lua files that set the color scheme of the editor. There are +light and dark themes for you to choose. + +To install and use them you have to copy the ones you would like from +`addons/colors/light` or `addons/colors/dark` into the folder +`.config/lite-xl/colors/`. Don't add light or dark folders. Just copy the +.lua files in there. + +Then you have to start Lite XL and open your configuration by clicking +at the cog icon at the toolbar (bottom left sixth icon). Go at the line +that looks like below +``` +-- core.reload_module("colors.summer") +``` +and change the `summer` with the name of your color theme. Also, remove +the two dashes `--` at the start of the line and save the file. If you +did everything right, the color schema should change instantly. + +The themes can also be found at +https://github.com/lite-xl/lite-xl-colors + +### Plugins +The Lite XL that you are using on AmigaOS 4 is based on version 1.16.12 +and not the latest version that is available by the development team. +This means that the latest plugins are not working at all or need some +modifications to work. + +To make it easier for you, I gathered some of the plugins that are working +well, and I included them at the `addons/plugins`. For you to install the +ones you would like to use, you have to copy the `.lua` files into the +folder `.config/lite-xl/plugins/` and restart the editor. + +The included plugins are the following: + +**autoinsert** +Automatically inserts closing brackets and quotes. Also allows selected + text to be wrapped with brackets or quotes. + +**autowrap** +Automatically hardwraps lines when typing + +**bigclock** +Shows the current time and date in a view with large text + +**bracketmatch** +Underlines matching pair for bracket under the caret + +**colorpreview** +Underlays color values (eg. `#ff00ff` or `rgb(255, 0, 255)`) with their +resultant color. + +**eofnewline-xl** +Make sure the file ends with one blank line. + +**ephemeral_tabs** +Preview tabs. Opening a doc will replace the contents of the preview tab. +Marks tabs as non-preview on any change or tab double clicking. + +**ghmarkdown** +Opens a preview of the current markdown file in a browser window + +**indentguide** +Adds indent guides + +**language_make** +Syntax for the Make build system language + +**language_sh** +Syntax for shell scripting language + +**lfautoinsert** +Automatically inserts indentation and closing bracket/text after newline + +**markers** +Add markers to docs and jump between them quickly + +**navigate** +Allows moving back and forward between document positions, reducing the +amount of scrolling + +**rainbowparen** +Show nesting of parentheses with rainbow colours + +**restoretabs** +Keep a list of recently closed tabs, and restore the tab in order on +cntrl+shift+t. + +**selectionhighlight** +Highlights regions of code that match the current selection + +## Tips and tricks + +### Transitions + +If you want to disable the transitions and make the scrolling a little faster, +open your configuration by clicking at the cog icon at the toolbar +(bottom left sixth icon) and add the followline at the end of the file and +save it. + +``` +config.transitions = false +``` + +### Hide files from the file list + +If you would like to hide files or whole folder from the left side bar list, +open your configuration by clicking at the cog icon at the toolbar +(bottom left sixth icon) and add the followline at the end of the file and +save it. This hides all the files that start with a dot, and all the `.info` +files. + +``` +config.ignore_files = {"^%.", "%.info$"} +``` + +You can add as many rules as you want in there, to hide fore files or +folders, as you like. + + +## Know issues +You can find the known issues at +https://git.walkero.gr/walkero/lite-xl/issues + + +# Changelog + +## [2.0.5r1] - 2022-03-27 +### Changed +- Synced with v2.0.5 tag of lite-xl official github page +- Applied all the necessary changes to make it run under AmigaOS 4.1 FE + +## [2.0.3.1] - 2022-01-18 +### Changed +- Applied all the necessary changes to make it run under AmigaOS 4.1 FE + diff --git a/README_OS4.md.info b/README_OS4.md.info new file mode 100644 index 0000000000000000000000000000000000000000..cfd4ecb595010fa5f6f2f337dfcd4b841d0513d4 GIT binary patch literal 5092 zcmeHJ3sjQ%w*So1W-_s-W-2|jr<#oq5Jb``9V_kW`$0xpW=Z5*5maWfe1xM`L#R}g zrm3ZkIX)0;RB}woF(nfpCCVf!Dk?A{-^J2%*E;8}nS0iKoU_h4doB2}_x^qRzxV!c z_WB0202N?S_5u31%zdi=s?{`Y5z{|xg{miV#F z0M!Nizu_O(fqj49(OQ2W{U5@HfJzw$fd4KopU+ZR*q`zL6?l?605D&NB>r=~lDY*{ z+UDz*EZ~e1=Xp~Ly0V?0{EJw(pvNome?t~_g2n&U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3^R!yh-*_=i|!7&DrH|K_4r`L$^D2ga(E0bB$n*Du>!l4s#fcaXy zQm+L*m@)%9H4E7S7>u#HPIzrHRF;1Qz2mi4(c``1S>pa1b3@w+j zD!%p5_L2mOn@=ueI*^aBu_|IoLc9kJ|Kn|Ky^qOwqV+1 zpI^9$)Hpp0og}k8#?exu5jw2=fJ!N1Httyvlth4o|aMqG0r^^Oy&LR+qDrYPfdpwOo;Tp5T zqan&!-1bteNS8;AKGB{!+!dE+Ly{CuccmqU#}1Zze964a)|{+?@uwlSNQv2R1!c1? zb`qwr^U)K9VLkl1J?^*C92@wHJ= # include # include +#elif DMON_OS_AMIGAOS4 #endif #ifndef DMON_MALLOC @@ -954,7 +958,7 @@ _DMON_PRIVATE void dmon__inotify_process_events(void) if ((check_ev->mask & IN_MODIFY) && strcmp(ev->filepath, check_ev->filepath) == 0) { check_ev->skip = true; break; - } + } } } } diff --git a/src/api/api.c b/src/api/api.c index c479ca4a..c3031459 100644 --- a/src/api/api.c +++ b/src/api/api.c @@ -4,14 +4,14 @@ int luaopen_system(lua_State *L); int luaopen_renderer(lua_State *L); int luaopen_regex(lua_State *L); -int luaopen_process(lua_State *L); +// int luaopen_process(lua_State *L); static const luaL_Reg libs[] = { { "system", luaopen_system }, { "renderer", luaopen_renderer }, { "regex", luaopen_regex }, - { "process", luaopen_process }, + // { "process", luaopen_process }, { NULL, NULL } }; diff --git a/src/api/system.c b/src/api/system.c index 10288eba..2f563ed4 100644 --- a/src/api/system.c +++ b/src/api/system.c @@ -6,7 +6,7 @@ #include #include #include "api.h" -#include "dirmonitor.h" +// #include "dirmonitor.h" #include "rencache.h" #ifdef _WIN32 #include @@ -14,6 +14,8 @@ #include #elif __linux__ #include +#elif __amigaos4__ + #include "platform/amigaos4.h" #endif extern SDL_Window *window; @@ -242,19 +244,19 @@ top: case SDL_USEREVENT: lua_pushstring(L, "dirchange"); lua_pushnumber(L, e.user.code >> 16); - switch (e.user.code & 0xffff) { - case DMON_ACTION_DELETE: - lua_pushstring(L, "delete"); - break; - case DMON_ACTION_CREATE: - lua_pushstring(L, "create"); - break; - case DMON_ACTION_MODIFY: - lua_pushstring(L, "modify"); - break; - default: - return luaL_error(L, "unknown dmon event action: %d", e.user.code & 0xffff); - } + // switch (e.user.code & 0xffff) { + // case DMON_ACTION_DELETE: + // lua_pushstring(L, "delete"); + // break; + // case DMON_ACTION_CREATE: + // lua_pushstring(L, "create"); + // break; + // case DMON_ACTION_MODIFY: + // lua_pushstring(L, "modify"); + // break; + // default: + // return luaL_error(L, "unknown dmon event action: %d", e.user.code & 0xffff); + // } lua_pushstring(L, e.user.data1); free(e.user.data1); return 4; @@ -325,7 +327,11 @@ static int f_set_window_mode(lua_State *L) { int n = luaL_checkoption(L, 1, "normal", window_opts); SDL_SetWindowFullscreen(window, n == WIN_FULLSCREEN ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); - if (n == WIN_NORMAL) { SDL_RestoreWindow(window); } + if (n == WIN_NORMAL) + { + ren_resize_window(); + SDL_RestoreWindow(window); + } if (n == WIN_MAXIMIZED) { SDL_MaximizeWindow(window); } if (n == WIN_MINIMIZED) { SDL_MinimizeWindow(window); } return 0; @@ -507,6 +513,10 @@ static int f_list_dir(lua_State *L) { #define realpath(x, y) _fullpath(y, x, MAX_PATH) #endif +#ifdef __amigaos4__ + #define realpath(x, y) _fullpath(x) +#endif + static int f_absolute_path(lua_State *L) { const char *path = luaL_checkstring(L, 1); char *res = realpath(path, NULL); @@ -735,17 +745,20 @@ static int f_watch_dir(lua_State *L) { const uint32_t dmon_flags = DMON_WATCHFLAGS_FOLLOW_SYMLINKS; #elif __APPLE__ const uint32_t dmon_flags = DMON_WATCHFLAGS_FOLLOW_SYMLINKS | DMON_WATCHFLAGS_RECURSIVE; +#elif __amigaos4__ + // const uint32_t dmon_flags = 0; #else const uint32_t dmon_flags = DMON_WATCHFLAGS_RECURSIVE; #endif - dmon_error error; - dmon_watch_id watch_id = dmon_watch(path, dirmonitor_watch_callback, dmon_flags, NULL, &error); - if (watch_id.id == 0) { - lua_pushnil(L); - lua_pushstring(L, dmon_error_str(error)); - return 2; - } - lua_pushnumber(L, watch_id.id); + // dmon_error error; + // dmon_watch_id watch_id = dmon_watch(path, dirmonitor_watch_callback, dmon_flags, NULL, &error); + // if (watch_id.id == 0) { + // lua_pushnil(L); + // lua_pushstring(L, dmon_error_str(error)); + // return 2; + // } + // lua_pushnumber(L, watch_id.id); + lua_pushnumber(L, 0); return 1; } diff --git a/src/dirmonitor.c b/src/dirmonitor.c index 0063e400..cf4f2b1b 100644 --- a/src/dirmonitor.c +++ b/src/dirmonitor.c @@ -3,9 +3,11 @@ #include +#ifndef __amigaos4__ #define DMON_IMPL #include "dmon.h" #include "dmon_extra.h" +#endif #include "dirmonitor.h" @@ -32,14 +34,14 @@ static void send_sdl_event(dmon_watch_id watch_id, dmon_action action, const cha } void dirmonitor_init() { - dmon_init(); + // dmon_init(); /* In theory we should register our user event but since we have just one type of user event this is not really needed. */ /* sdl_dmon_event_type = SDL_RegisterEvents(1); */ } void dirmonitor_deinit() { - dmon_deinit(); + // dmon_deinit(); } void dirmonitor_watch_callback(dmon_watch_id watch_id, dmon_action action, const char *rootdir, @@ -49,11 +51,11 @@ void dirmonitor_watch_callback(dmon_watch_id watch_id, dmon_action action, const (void) user; switch (action) { case DMON_ACTION_MOVE: - send_sdl_event(watch_id, DMON_ACTION_DELETE, oldfilepath); - send_sdl_event(watch_id, DMON_ACTION_CREATE, filepath); + // send_sdl_event(watch_id, DMON_ACTION_DELETE, oldfilepath); + // send_sdl_event(watch_id, DMON_ACTION_CREATE, filepath); break; - default: - send_sdl_event(watch_id, action, filepath); + // default: + // send_sdl_event(watch_id, action, filepath); } } diff --git a/src/main.c b/src/main.c index e0fcb107..947a9d0f 100644 --- a/src/main.c +++ b/src/main.c @@ -12,6 +12,8 @@ #include #elif __APPLE__ #include +#elif __amigaos4__ + #include "platform/amigaos4.h" #endif #include "dirmonitor.h" @@ -46,6 +48,8 @@ static void get_exe_filename(char *buf, int sz) { char exepath[size]; _NSGetExecutablePath(exepath, &size); realpath(exepath, buf); +#elif __amigaos4__ + strcpy(buf, _fullpath("./lite")); #else strcpy(buf, "./lite"); #endif @@ -109,11 +113,12 @@ int main(int argc, char **argv) { SDL_DisplayMode dm; SDL_GetCurrentDisplayMode(0, &dm); - dirmonitor_init(); + // dirmonitor_init(); window = SDL_CreateWindow( "", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, dm.w * 0.8, dm.h * 0.8, SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI | SDL_WINDOW_HIDDEN); + SDL_SetWindowDisplayMode(window, &dm); init_window_icon(); ren_init(window); @@ -155,6 +160,9 @@ init_lua: " HOME = os.getenv('" LITE_OS_HOME "')\n" " local exedir = EXEFILE:match('^(.*)" LITE_PATHSEP_PATTERN LITE_NONPATHSEP_PATTERN "$')\n" " local prefix = exedir:match('^(.*)" LITE_PATHSEP_PATTERN "bin$')\n" + " if not HOME then\n" + " HOME = exedir\n" + " end\n" " dofile((MACOS_RESOURCES or (prefix and prefix .. '/share/lite-xl' or exedir .. '/data')) .. '/core/start.lua')\n" " core = require(os.getenv('LITE_XL_RUNTIME') or 'core')\n" " core.init()\n" @@ -193,7 +201,7 @@ init_lua: lua_close(L); ren_free_window_resources(); - dirmonitor_deinit(); + // dirmonitor_deinit(); return EXIT_SUCCESS; } diff --git a/src/platform/amigaos4.c b/src/platform/amigaos4.c new file mode 100644 index 00000000..fd53bd2f --- /dev/null +++ b/src/platform/amigaos4.c @@ -0,0 +1,61 @@ + +#include +#include +#include + +#include "amigaos4.h" + +static char *getFullPath(const char *path) +{ + char *appPath = malloc(sizeof(char) * MAX_DOS_NAME); + BPTR pathLock = Lock(path, SHARED_LOCK); + if (pathLock) + { + NameFromLock(pathLock, appPath, sizeof(char) * MAX_DOS_NAME); + UnLock(pathLock); + + return appPath; + } + return NULL; +} + +static char *getCurrentPath(void) +{ + char *appPath = malloc(sizeof(char) * MAX_DOS_NAME); + BPTR pathLock = GetCurrentDir(); + if (pathLock) + { + NameFromLock(pathLock, appPath, sizeof(char) * MAX_DOS_NAME); + return appPath; + } + return NULL; +} + +char *_fullpath(const char *path) +{ + static char prvPath[MAX_DOS_NAME]; + static char result[MAX_DOS_NAME]; + + if (!strcmp(path, prvPath)) + { + return result; + } + + strcpy(prvPath, path); + + if (!strcmp(path, "./lite")) + { + // TODO: Add code to get the name of the executable + strcpy(result, getFullPath("PROGDIR:lite")); + return result; + } + + if (!strcmp(path, ".")) + { + strcpy(result, getCurrentPath()); + return result; + } + + strcpy(result, getFullPath(path)); + return result; +} diff --git a/src/platform/amigaos4.h b/src/platform/amigaos4.h new file mode 100644 index 00000000..76e61106 --- /dev/null +++ b/src/platform/amigaos4.h @@ -0,0 +1,16 @@ +#ifndef _AMIGAOS4_H +#define _AMIGAOS4_H + +#include +#include + +#define VSTRING "Lite XL OS4 2.0.5 (04.01.2022)" +#define VERSTAG "\0$VER: " VSTRING + +static CONST_STRPTR stack USED = "$STACK:102400"; +static CONST_STRPTR version USED = VERSTAG; + +char *_fullpath(const char *); + + +#endif diff --git a/src/renderer.c b/src/renderer.c index cd269687..f45dae44 100644 --- a/src/renderer.c +++ b/src/renderer.c @@ -1,5 +1,6 @@ #include #include +#include #include #include #include "font_renderer.h" @@ -274,16 +275,6 @@ static inline RenColor blend_pixel(RenColor dst, RenColor src) { return dst; } - -#define rect_draw_loop(expr) \ - for (int j = y1; j < y2; j++) { \ - for (int i = x1; i < x2; i++) { \ - *d = expr; \ - d++; \ - } \ - d += dr; \ - } - void ren_draw_rect(RenRect rect, RenColor color) { if (color.a == 0) { return; } @@ -304,15 +295,31 @@ void ren_draw_rect(RenRect rect, RenColor color) { y2 = y2 > clip.y + clip.height ? clip.y + clip.height : y2; SDL_Surface *surface = renwin_get_surface(&window_renderer); - RenColor *d = (RenColor*) 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 if (color.a == 0xff) { + uint32_t translated = SDL_MapRGB(surface->format, color.r, color.g, color.b); SDL_Rect rect = { x1, y1, x2 - x1, y2 - y1 }; SDL_FillRect(surface, &rect, SDL_MapRGBA(surface->format, color.r, color.g, color.b, color.a)); } else { - rect_draw_loop(blend_pixel(*d, color)); + RenColor current_color; + RenColor blended_color; + for (int j = y1; j < y2; j++) { + for (int i = x1; i < x2; i++, d++) { + SDL_GetRGB(*d, surface->format, ¤t_color.r, ¤t_color.g, ¤t_color.b); + blended_color = blend_pixel(current_color, color); + *d = SDL_MapRGB(surface->format, blended_color.r, blended_color.g, blended_color.b); + } + d += dr; + } } } diff --git a/src/renwindow.c b/src/renwindow.c index f67002f8..c4dc5b72 100644 --- a/src/renwindow.c +++ b/src/renwindow.c @@ -9,6 +9,18 @@ static int query_surface_scale(RenWindow *ren) { SDL_GetWindowSize(ren->window, &w_points, &h_points); /* We consider that the ratio pixel/point will always be an integer and it is the same along the x and the y axis. */ + + #ifdef __amigaos4__ + // This is a workaround when the w_pixels != w_points and h_pixels != h_points + // because of redraw delays, especially when the "Resize with contents" is enabled + if (w_pixels != w_points) { + w_pixels = w_points; + } + if (h_pixels != h_points) { + h_pixels = h_points; + } + #endif + assert(w_pixels % w_points == 0 && h_pixels % h_points == 0 && w_pixels / w_points == h_pixels / h_points); return w_pixels / w_points; } @@ -20,7 +32,7 @@ static void setup_renderer(RenWindow *ren, int w, int h) { SDL_DestroyTexture(ren->texture); SDL_DestroyRenderer(ren->renderer); } - ren->renderer = SDL_CreateRenderer(ren->window, -1, 0); + ren->renderer = SDL_CreateRenderer(ren->window, -1, SDL_RENDERER_ACCELERATED | SDL_RENDERER_PRESENTVSYNC); ren->texture = SDL_CreateTexture(ren->renderer, SDL_PIXELFORMAT_BGRA32, SDL_TEXTUREACCESS_STREAMING, w, h); ren->surface_scale = query_surface_scale(ren); }