From 6686e6688f6dd44b536c6890192743a4b08b5a85 Mon Sep 17 00:00:00 2001 From: erathke Date: Tue, 26 Jan 2021 13:57:11 -0300 Subject: [PATCH 1/2] feature: option to build tcvm without skia This feature ables to build TCVM without Skia. By default, this option is ON. Without Skia, is possible to generate a very little final libtcvm (~3MB on Linux). It's also now possible to test the VM on OpenBSD. Usage - Disable Skia: cmake -DUSE_SKIA=OFF --- TotalCrossVM/CMakeLists.txt | 12 +++++++++--- TotalCrossVM/src/nm/ui/GraphicsPrimitives.h | 2 +- TotalCrossVM/src/nm/ui/PalmFont_c.h | 2 +- TotalCrossVM/src/nm/ui/font_Font.c | 3 ++- TotalCrossVM/src/nm/ui/gfx_Graphics.c | 2 +- TotalCrossVM/src/nm/ui/image_Image.c | 2 +- TotalCrossVM/src/nm/ui/linux/gfx_Graphics_c.h | 7 ++++++- 7 files changed, 21 insertions(+), 9 deletions(-) diff --git a/TotalCrossVM/CMakeLists.txt b/TotalCrossVM/CMakeLists.txt index dc8be73909..fdd50ad614 100644 --- a/TotalCrossVM/CMakeLists.txt +++ b/TotalCrossVM/CMakeLists.txt @@ -16,6 +16,11 @@ if(NOT DEFINED BUILD_SHARED_LIBS AND NOT DEFINED TCVM_SHARED) endif() endif() +# Use skia +if (NOT DEFINED USE_SKIA) + set(USE_SKIA ON) +endif() + if(TCVM_SHARED) add_library(tcvm SHARED) else() @@ -34,10 +39,11 @@ IF (NOT (DEFINED ANDROID_ABI OR MSVC OR CMAKE_GENERATOR STREQUAL Xcode)) ENDIF (NOT (DEFINED ANDROID_ABI OR MSVC OR CMAKE_GENERATOR STREQUAL Xcode)) # Find Skia -if(NOT MSVC) +if(NOT MSVC AND USE_SKIA) find_package(Skia REQUIRED) include_directories(${SKIA_INCLUDE_DIRS}) -endif(NOT MSVC) + add_definitions(-DUSE_SKIA) +endif(NOT MSVC AND USE_SKIA) set(TC_SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/src") set(LB_SRCDIR "${CMAKE_CURRENT_SOURCE_DIR}/src/litebase") @@ -668,4 +674,4 @@ if(MSVC) add_dependencies(Intermec tcvm) INCLUDE_EXTERNAL_MSPROJECT(Pidion ${CMAKE_CURRENT_SOURCE_DIR}/vc2008/Pidion.vcproj) endif() -endif() \ No newline at end of file +endif() diff --git a/TotalCrossVM/src/nm/ui/GraphicsPrimitives.h b/TotalCrossVM/src/nm/ui/GraphicsPrimitives.h index 40e016a149..ef09a6b3d8 100644 --- a/TotalCrossVM/src/nm/ui/GraphicsPrimitives.h +++ b/TotalCrossVM/src/nm/ui/GraphicsPrimitives.h @@ -10,7 +10,7 @@ #include "tcclass.h" -#if defined ANDROID || defined darwin || defined HEADLESS +#if defined USE_SKIA && (defined ANDROID || defined darwin || defined HEADLESS) #include "android/skia.h" #endif diff --git a/TotalCrossVM/src/nm/ui/PalmFont_c.h b/TotalCrossVM/src/nm/ui/PalmFont_c.h index 1e97855e21..2eb72f34ab 100644 --- a/TotalCrossVM/src/nm/ui/PalmFont_c.h +++ b/TotalCrossVM/src/nm/ui/PalmFont_c.h @@ -715,7 +715,7 @@ UserFont loadUserFontFromFontObj(Context currentContext, TCObject fontObj, JChar } } -#if defined ANDROID || defined darwin || defined HEADLESS +#if defined USE_SKIA && (defined ANDROID || defined darwin || defined HEADLESS) #include "android/skia.h" int32 getJCharWidth(Context currentContext, TCObject fontObj, JChar ch) { diff --git a/TotalCrossVM/src/nm/ui/font_Font.c b/TotalCrossVM/src/nm/ui/font_Font.c index db0bf6da4d..66f70884c4 100644 --- a/TotalCrossVM/src/nm/ui/font_Font.c +++ b/TotalCrossVM/src/nm/ui/font_Font.c @@ -7,7 +7,7 @@ #include "tcvm.h" #include "PalmFont_c.h" -#if defined ANDROID || defined darwin || defined HEADLESS +#if defined USE_SKIA && (defined ANDROID || defined darwin || defined HEADLESS) #include "android/skia.h" #endif @@ -37,6 +37,7 @@ TC_API void tufF_fontCreate(NMParams p) // totalcross/ui/font/Font native void f if(!(nameTTF[len-4] == '.' && nameTTF[len-3] == 't' && nameTTF[len-2] == 't' && nameTTF[len-1] == 'f')) { xstrcat(nameTTF, ".ttf"); } + int32 fontIdx = skia_getTypefaceIndex(nameTTF); if (fontIdx == -1) { if ((file = tczGetFile(nameTTF, false)) != null) { diff --git a/TotalCrossVM/src/nm/ui/gfx_Graphics.c b/TotalCrossVM/src/nm/ui/gfx_Graphics.c index b04b087db6..f9bb920538 100644 --- a/TotalCrossVM/src/nm/ui/gfx_Graphics.c +++ b/TotalCrossVM/src/nm/ui/gfx_Graphics.c @@ -4,7 +4,7 @@ // SPDX-License-Identifier: LGPL-2.1-only #include "tcvm.h" -#if defined ANDROID || defined darwin || defined HEADLESS +#if defined USE_SKIA && (defined ANDROID || defined darwin || defined HEADLESS) #define Graphics_forePixel(o) (Graphics_foreColor(o) | 0xFF000000) #define Graphics_backPixel(o) (Graphics_backColor(o) | 0xFF000000) #else diff --git a/TotalCrossVM/src/nm/ui/image_Image.c b/TotalCrossVM/src/nm/ui/image_Image.c index 25cb5bf573..31d58ece66 100644 --- a/TotalCrossVM/src/nm/ui/image_Image.c +++ b/TotalCrossVM/src/nm/ui/image_Image.c @@ -145,7 +145,7 @@ TC_API void tuiI_setTransparentColor_i(NMParams p) // totalcross/ui/image/Image p->retO = thisObj; } -#if defined ANDROID || defined darwin || defined HEADLESS +#if defined USE_SKIA && (defined ANDROID || defined darwin || defined HEADLESS) #include "android/skia.h" #endif ////////////////////////////////////////////////////////////////////////// diff --git a/TotalCrossVM/src/nm/ui/linux/gfx_Graphics_c.h b/TotalCrossVM/src/nm/ui/linux/gfx_Graphics_c.h index 691ad5bf71..c22d53a0c0 100644 --- a/TotalCrossVM/src/nm/ui/linux/gfx_Graphics_c.h +++ b/TotalCrossVM/src/nm/ui/linux/gfx_Graphics_c.h @@ -12,7 +12,9 @@ void privateScreenChange(int32 w, int32 h) } #include "../../init/tcsdl.h" +#ifdef USE_SKIA #include "../android/skia.h" +#endif bool graphicsStartup(ScreenSurface screen, int16 appTczAttr) @@ -63,7 +65,8 @@ bool graphicsStartup(ScreenSurface screen, int16 appTczAttr) screen->screenW = w; screen->screenH = h; - +#else + TCSDL_Init(screen, exeName, *(tcSettings.isFullScreenPtr)); #endif return true; } @@ -87,6 +90,8 @@ void graphicsUpdateScreen(Context currentContext, ScreenSurface screen) // scree bounds.x2 = currentContext->dirtyX2; bounds.y2 = currentContext->dirtyY2; SCREEN_EX(screen)->primary->Flip(SCREEN_EX(screen)->primary, &bounds, DSFLIP_ONSYNC); +#else + TCSDL_UpdateTexture(screen->screenW, screen->screenH, screen->pitch, screen->pixels); #endif } From 26098f8ba0aa6a06ba23d4633783c24b183a6f03 Mon Sep 17 00:00:00 2001 From: Evandro Rathke Date: Sat, 8 May 2021 14:12:11 -0300 Subject: [PATCH 2/2] feature: setting window title --- TotalCrossSDK/src/main/java/totalcross/Launcher.java | 3 +++ TotalCrossVM/src/nm/ui/linux/gfx_Graphics_c.h | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/TotalCrossSDK/src/main/java/totalcross/Launcher.java b/TotalCrossSDK/src/main/java/totalcross/Launcher.java index df9fe89be8..7efc80a5b3 100644 --- a/TotalCrossSDK/src/main/java/totalcross/Launcher.java +++ b/TotalCrossSDK/src/main/java/totalcross/Launcher.java @@ -412,6 +412,7 @@ static void showInstructions() { System.out.println(" /scr iphone : iPhone 8 resolution (same of /scr 750x1334x24 /density 2)"); System.out.println(" /scr ipad : iPad resolution (same of /scr 1536x2048x24 /density 2)"); System.out.println(" /fullscreen : Use full-screen window"); + System.out.println(" /title : Sets the window title"); System.out.println(" /pos x,y : Sets the openning position of the application"); System.out.println(" /uiStyle Flat : Flat user interface style"); System.out.println("* /uiStyle Vista : Vista user interface style"); @@ -527,6 +528,8 @@ protected void parseArguments(String clazz, String... args) { System.out.println("Screen is " + toWidth + "x" + toHeight + "x" + toBpp); } else if (args[i].equalsIgnoreCase("/fullscreen")) { fullscreen = true; + } else if (args[i].equalsIgnoreCase("/title")) { + frameTitle = args[++i]; } else if (args[i].equalsIgnoreCase("/r")) { ++i; } else if (args[i].equalsIgnoreCase("/pos")) /* x,y */ diff --git a/TotalCrossVM/src/nm/ui/linux/gfx_Graphics_c.h b/TotalCrossVM/src/nm/ui/linux/gfx_Graphics_c.h index c22d53a0c0..c10949fa05 100644 --- a/TotalCrossVM/src/nm/ui/linux/gfx_Graphics_c.h +++ b/TotalCrossVM/src/nm/ui/linux/gfx_Graphics_c.h @@ -23,7 +23,8 @@ bool graphicsStartup(ScreenSurface screen, int16 appTczAttr) *(tcSettings.isFullScreenPtr)=true; #endif #ifdef SKIA_H - TCSDL_Init(screen, exeName, *(tcSettings.isFullScreenPtr)); + char* title = getenv("TC_TITLE"); // setting window title + TCSDL_Init(screen, title ? title : exeName, *(tcSettings.isFullScreenPtr)); #elif !defined HEADLESS DFBResult err; IDirectFB *_dfb; @@ -66,7 +67,8 @@ bool graphicsStartup(ScreenSurface screen, int16 appTczAttr) screen->screenW = w; screen->screenH = h; #else - TCSDL_Init(screen, exeName, *(tcSettings.isFullScreenPtr)); + char* title = getenv("TC_TITLE"); // setting window title + TCSDL_Init(screen, title ? title : exeName, *(tcSettings.isFullScreenPtr)); #endif return true; }