Skip to content

Commit

Permalink
build atlas from needed characters only
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown321 committed Jan 17, 2025
1 parent 5454b80 commit a8fc5fd
Show file tree
Hide file tree
Showing 22 changed files with 163 additions and 196 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ product_info
libMali*
ss/*
*.tbl
*.dat
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@
[submodule "libs/llusbdac"]
path = libs/llusbdac
url = https://github.com/zhangboyang/llusbdac.git
[submodule "libs/sqlite"]
path = libs/sqlite
url = https://github.com/sqlite/sqlite.git
ignore = dirty
9 changes: 7 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ include_directories(
libs/glm
libs/alsa-lib/src/include
libs/mINI/src
libs/sqlite/build-${arch}/install/include
libs
server/armv5-unknown-linux-gnueabihf
${PROTOBUF_INCLUDE}
Expand Down Expand Up @@ -152,6 +153,10 @@ target_link_libraries(${PROJECT_NAME} ${ImageMagick_LIBRARIES})
find_library(PROTOBUF protobuf REQUIRED PATHS libs/protobuf/build-${arch}/lib/ REQUIRED)
target_link_libraries(${PROJECT_NAME} "${PROTOBUF}")

set(CMAKE_PREFIX_PATH "${CMAKE_SOURCE_DIR}/libs/sqlite/build-${arch}/install")
find_package(SQLite3 REQUIRED)
target_link_libraries(${PROJECT_NAME} "${SQLite3_LIBRARIES}")

add_custom_target(version
${CMAKE_COMMAND} -D SRC=${CMAKE_SOURCE_DIR}/src/Version.h.in
-D DST=${CMAKE_SOURCE_DIR}/src/Version.h
Expand All @@ -163,7 +168,7 @@ add_dependencies(${PROJECT_NAME} version)

if (DESKTOP EQUAL 1)
find_library(GLES GLESv2 PATHS /usr/lib)
target_link_libraries(${PROJECT_NAME} "${GLES}")
target_link_libraries(${PROJECT_NAME} ${GLES})
target_compile_definitions(${PROJECT_NAME} PRIVATE DESKTOP=1)
else ()
set_target_properties(${PROJECT_NAME} PROPERTIES
Expand All @@ -173,7 +178,7 @@ else ()

find_library(MALI Mali_linux PATHS libs)
# find_library(ASOUND asound PATHS libs)
target_link_libraries(${PROJECT_NAME} "${MALI}")
target_link_libraries(${PROJECT_NAME} ${MALI})
# target_link_libraries(${PROJECT_NAME} "${ASOUND}")
endif ()

Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ RUN apt-get build-dep qtbase5-dev -y && \
RUN ln -s /x-tools/armv5-unknown-linux-gnueabihf/bin/armv5-unknown-linux-gnueabihf-ld /usr/bin/arm-linux-gnueabihf-ld && \
ln -s /x-tools/armv5-unknown-linux-gnueabihf/bin/armv5-unknown-linux-gnueabihf-ld.bfd /usr/bin/arm-linux-gnueabihf-ld.bfd && \
ln -s /x-tools/armv5-unknown-linux-gnueabihf/bin/armv5-unknown-linux-gnueabihf-gcc /usr/bin/arm-linux-gnueabihf-gcc && \
ln -s /x-tools/armv5-unknown-linux-gnueabihf/bin/armv5-unknown-linux-gnueabihf-strip /usr/bin/arm-linux-gnueabihf-strip
ln -s /x-tools/armv5-unknown-linux-gnueabihf/bin/armv5-unknown-linux-gnueabihf-strip /usr/bin/arm-linux-gnueabihf-strip

RUN apt-get install tclsh patchelf -y && apt-get clean
2 changes: 1 addition & 1 deletion MAKING_OF.md
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,7 @@ supported at all, it's a guaranteed OOM.
It could've been avoided by providing exact list of characters that will be used. Obtaining such list is relatively
easy: query local song database for all artists and all titles, get unique characters. Most likely it will be your
alphabet, some punctuation and 10-20 characters from foreign languages. The problem is the query - no idea how to do it
quickly.
quickly. After some time I successfully used this approach.
Another workaround is to use another framework like Qt - how do they render all these characters without font atlas with
such ease? But at that point it was too late to switch.
Expand Down
20 changes: 1 addition & 19 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
* [Wampy is not showing when "Hold" is toggled](#wampy-is-not-showing-when-hold-is-toggled)
* [There is no song info](#there-is-no-song-info)
* [Notes on ugly settings](#notes-on-ugly-settings)
* [Fonts](#fonts)
* [There is a "detailed info" popup after turning screen off and on instead of Wampy](#there-is-a-detailed-info-popup-after-turning-screen-off-and-on-instead-of-wampy)
* [Everything lags after changing skins/tapes too much](#everything-lags-after-changing-skinstapes-too-much)
* [Using Wampy](#using-wampy)
Expand Down Expand Up @@ -49,7 +48,7 @@ points in default player terms).
### ⚠️What to do if device crashes / Wampy doesn't start?⚠️

If Wampy failed to start 3 times (read: device rebooted trice), it stops starting until you edit `wampy/config.ini`.
Remove config file or set `[wampy][badboots]` to 0 (along with device-breaking settings you changed such as fonts) and
Remove config file or set `[wampy][badboots]` to 0 (along with possible device-breaking settings) and
reboot the device. If you cannot access config file (device stuck in boot loop and won't connect to pc, very unlikely
situation), restore it from backup that you made beforehand (see [BACKUP.md](./BACKUP.md)).

Expand All @@ -74,23 +73,6 @@ default music player, not SensMe or Language Study.
Due to unfortunate combination of font and framework quirks, all text in settings is placed slightly lower than
expected.

### Fonts

By default, basic latin characters plus various punctuation are used. If your songs have non-latin glyphs in their
artist/title fields, you'll have to toggle on needed character set.

⚠️**WARNING**⚠️

Due to gui framework limitations all characters are loaded into huge texture (font atlas) which is then uploaded to GPU
memory. GPU memory is shared with main memory and usually there is not much left. If you turn on all character sets,
this **will** cause crashes. Generally it is fine to turn on one or two of these. Chinese characters are guaranteed to
crash your device, so they are explicitly disabled.

If crashes occur,
see [What to do if device crashes / Wampy doesn't start?](#what-to-do-if-device-crashes--Wampy-doesnt-start) section.

<img src="images/fonts.png" alt="fonts settings">

### There is a "detailed info" popup after turning screen off and on instead of Wampy

This is the place where current track info is coming from. Toggle Wampy on and off to close it automatically or just
Expand Down
Binary file removed images/fonts.png
Binary file not shown.
23 changes: 21 additions & 2 deletions libs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ libjpeg-turbo/build-arm:
make && make install \
"

sqlite/build-arm:
mkdir -p $@
$(DOCKER) bash -c "\
cd $@ && \
../configure $(ARM_CC) $(ARM_CXX) --host arm-unknown-linux --prefix=`pwd`/$@/install && \
make && make install && patchelf --set-soname libsqlite3.so `pwd`/$@/install/lib/libsqlite3.so \
"

sqlite/build-x86:
mkdir -p $@
$(DOCKER) bash -c "\
cd $@ && \
../configure --prefix=`pwd`/$@/install && \
make && make install && patchelf --set-soname libsqlite3.so `pwd`/$@/install/lib/libsqlite3.so \
"

libEGL.so: libMali_linux.so
ln -s libMali_linux.so libEGL.so

Expand All @@ -93,6 +109,8 @@ libjpeg: libjpeg-turbo/build-arm libjpeg-turbo/build-x86

magick: ImageMagick/build-x86 ImageMagick/build-arm

sqlite: sqlite/build-arm sqlite/build-x86

protobuf:
$(DOCKER) bash -c "\
make -f Makefile.protobuf \
Expand All @@ -101,16 +119,17 @@ protobuf:
llusbdac:
$(MAKE) -f Makefile.llusbdac

all: patch libEGL.so libGLESv2.so libjpeg magick protobuf llusbdac
all: patch libEGL.so libGLESv2.so libjpeg magick protobuf llusbdac sqlite

clean:
rm -rf libjpeg-turbo/build-*
rm -rf ImageMagick/build-*
rm -rf protobuf/build-*
-make -C protobuf clean
-make -C ImageMagick clean
rm -rf sqlite/build-*


.DEFAULT_GOAL := all

.PHONY: libjpeg-turbo/build-arm libjpeg-turbo/build-x86 protobuf patch llusbdac
.PHONY: libjpeg-turbo/build-arm libjpeg-turbo/build-x86 protobuf patch llusbdac sqlite
1 change: 1 addition & 0 deletions libs/sqlite
Submodule sqlite added at 2c7636
34 changes: 8 additions & 26 deletions src/cassette/cassette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@
#include <sstream>
#include <thread>

const ImWchar rangesPunctuation[] = {
0x2000,
0x206F, // General Punctuation
0,
};

namespace Cassette {

#ifdef DESKTOP
Expand Down Expand Up @@ -72,26 +66,14 @@ namespace Cassette {
gr.clear();

range.AddRanges(io.Fonts->GetGlyphRangesDefault());
range.AddRanges(rangesPunctuation);
range.AddChar(ImWchar(0x266a));
range.AddChar(ImWchar(0x266b));
range.AddChar(ImWchar(0x24c8));

if (fontRanges) {
if (fontRanges->Japanese)
range.AddRanges(ImGui::GetIO().Fonts->GetGlyphRangesJapanese());
if (fontRanges->ChineseFull)
range.AddRanges(ImGui::GetIO().Fonts->GetGlyphRangesChineseFull());
if (fontRanges->Cyrillic)
range.AddRanges(ImGui::GetIO().Fonts->GetGlyphRangesCyrillic());
if (fontRanges->Greek)
range.AddRanges(ImGui::GetIO().Fonts->GetGlyphRangesGreek());
if (fontRanges->Korean)
range.AddRanges(ImGui::GetIO().Fonts->GetGlyphRangesKorean());
if (fontRanges->Thai)
range.AddRanges(ImGui::GetIO().Fonts->GetGlyphRangesThai());
if (fontRanges->Vietnamese)
range.AddRanges(ImGui::GetIO().Fonts->GetGlyphRangesVietnamese());
range.AddChar(ImWchar(0x266a)); //
range.AddChar(ImWchar(0x266b)); //
range.AddChar(ImWchar(0x24c8)); //

std::vector<uint32_t> allchars;
getCharRange(&allchars);
for (const auto c : allchars) {
range.AddChar(c);
}

range.BuildRanges(&gr);
Expand Down
26 changes: 0 additions & 26 deletions src/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,6 @@ namespace AppConfig {
ini["features"]["touchscreenStaysOFF"] = std::to_string(features.touchscreenStaysOFF);
ini["mpd"]["socketPath"] = MPDSocketPath;

#ifdef DESKTOP
ini["fonts"]["chineseFull"] = std::to_string(fontRanges.ChineseFull);
#else
ini["fonts"]["chineseFull"] = std::to_string(false);
#endif
ini["fonts"]["cyrillic"] = std::to_string(fontRanges.Cyrillic);
ini["fonts"]["greek"] = std::to_string(fontRanges.Greek);
ini["fonts"]["japanese"] = std::to_string(fontRanges.Japanese);
ini["fonts"]["korean"] = std::to_string(fontRanges.Korean);
ini["fonts"]["thai"] = std::to_string(fontRanges.Thai);
ini["fonts"]["vietnamese"] = std::to_string(fontRanges.Vietnamese);

ini["w1"]["deviceColor"] = std::to_string(w1Options.deviceColor);

ini["digitalClock"]["color"] = digitalClock.color;
Expand All @@ -90,7 +78,6 @@ namespace AppConfig {
void AppConfig::Default() {
cassette.Default();
winamp.Default();
fontRanges = FontRanges{};
digitalClock.Default();

activeSkin = WINAMP;
Expand Down Expand Up @@ -170,19 +157,6 @@ namespace AppConfig {
features.limitVolume = (bool)std::atoi(ini["features"]["limitVolume"].c_str());
features.touchscreenStaysOFF = (bool)std::atoi(ini["features"]["touchscreenStaysOFF"].c_str());

#ifdef DESKTOP
fontRanges.ChineseFull = (bool)std::atoi(ini["fonts"]["chineseFull"].c_str());
#else
// device cannot handle full chinese range
fontRanges.ChineseFull = false;
#endif
fontRanges.Cyrillic = (bool)std::atoi(ini["fonts"]["cyrillic"].c_str());
fontRanges.Greek = (bool)std::atoi(ini["fonts"]["greek"].c_str());
fontRanges.Japanese = (bool)std::atoi(ini["fonts"]["japanese"].c_str());
fontRanges.Korean = (bool)std::atoi(ini["fonts"]["korean"].c_str());
fontRanges.Thai = (bool)std::atoi(ini["fonts"]["thai"].c_str());
fontRanges.Vietnamese = (bool)std::atoi(ini["fonts"]["vietnamese"].c_str());

w1Options.deviceColor = std::atoi(ini["w1"]["deviceColor"].c_str());
if (W1::colorByValue.count(w1Options.deviceColor) == 0) {
w1Options.deviceColor = W1::defaultColor;
Expand Down
2 changes: 0 additions & 2 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include "cassette/cassette.h"
#include "digital_clock/digital_clock.h"
#include "fontranges.h"
#include "mini/ini.h"
#include "w1/w1.h"
#include "winamp/winamp.h"
Expand Down Expand Up @@ -43,7 +42,6 @@ namespace AppConfig {
Features features{};
W1::W1Options w1Options{};
bool debug{};
FontRanges fontRanges;
int badBoots{};
bool limitFPS = false;
std::string forceConnector{};
Expand Down
16 changes: 6 additions & 10 deletions src/digital_clock/digital_clock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,6 @@
#include "../skin.h"
#include "imgui_impl_opengl3.h"

const ImWchar rangesPunctuation[] = {
0x2000,
0x206F, // General Punctuation
0,
};

namespace DigitalClock {
#ifdef DESKTOP
const std::string FontPath = "../NotoSansKR-Regular.otf";
Expand Down Expand Up @@ -346,11 +340,13 @@ namespace DigitalClock {
ImVector<ImWchar> gr;
gr.clear();

// no need to pull chars from db, skin has no text
// ascii is enough for settings

range.AddRanges(io.Fonts->GetGlyphRangesDefault());
range.AddRanges(rangesPunctuation);
range.AddChar(ImWchar(0x266a));
range.AddChar(ImWchar(0x266b));
range.AddChar(ImWchar(0x24c8));
range.AddChar(ImWchar(0x266a)); //
range.AddChar(ImWchar(0x266b)); //
range.AddChar(ImWchar(0x24c8)); //

range.BuildRanges(&gr);
*fontRegular = io.Fonts->AddFontFromFileTTF(FontPath.c_str(), fontSizeTTF, nullptr, gr.Data);
Expand Down
14 changes: 0 additions & 14 deletions src/fontranges.h

This file was deleted.

3 changes: 0 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,11 +398,8 @@ int main(int, char **) {
skin.winamp.connector = connector;
skin.cassette.connector = connector;

skin.winamp.fontRanges = &config.fontRanges;
skin.cassette.fontRanges = &config.fontRanges;
skin.winamp.WithConfig(&config.winamp);
skin.cassette.WithConfig(&config.cassette);
skin.digitalClock.fontRanges = &config.fontRanges;
skin.digitalClock.WithConfig(&config.digitalClock);

connector->clients.push_back(&skin.winamp);
Expand Down
Loading

0 comments on commit a8fc5fd

Please sign in to comment.