diff --git a/libstarlight/source/starlight/ThemeManager.cpp b/libstarlight/source/starlight/ThemeManager.cpp index 9da5194..e966922 100644 --- a/libstarlight/source/starlight/ThemeManager.cpp +++ b/libstarlight/source/starlight/ThemeManager.cpp @@ -25,6 +25,10 @@ #include "starlight/util/JsonConversions.h" +#include "starlight/util/Profiler.h" +using starlight::util::Profiler; +#include + using std::string; using std::shared_ptr; using std::make_shared; @@ -75,40 +79,48 @@ namespace { } CTexture* LoadPNG(const std::string& path, bool isPremult = false) { + //Profiler::TaskStart(); unsigned char* imgbuf; unsigned width, height; + lodepng::State state; lodepng_decode32_file(&imgbuf, &width, &height, path.c_str()); + if (state.info_png.color.colortype != 6) isPremult = true; // expect no alpha if not rgba + /*{ + std::stringstream ss; ss << "loaded png, "; + ss << width; ss << "x"; ss << height; + Profiler::TaskFinish(ss.str()); + }*/ unsigned bw = NextPow2(width), bh = NextPow2(height); u8* gpubuf = static_cast(linearAlloc(bw*bh*4)); + //Profiler::TaskStart(); + //memset(gpubuf, 0, bw*bh*4); + //Profiler::TaskFinish("cleared canvas"); - u8* src = static_cast(imgbuf); u8* dst = static_cast(gpubuf); + //Profiler::TaskStart(); if (isPremult) { + u32* src = reinterpret_cast(imgbuf); u32* dst = reinterpret_cast(gpubuf); // just convert endianness for(unsigned iy = 0; iy < height; iy++) { for (unsigned ix = 0; ix < width; ix++) { - int r = *src++; - int g = *src++; - int b = *src++; - int a = *src++; + u32 clr = *src; + *dst = __builtin_bswap32(clr); - *dst++ = a; - *dst++ = b; - *dst++ = g; - *dst++ = r; + src+=4; dst+=4; } dst += (bw - width) * 4; // skip the difference } } else { + u8* src = static_cast(imgbuf); u8* dst = static_cast(gpubuf); // convert and premultiply for(unsigned iy = 0; iy < height; iy++) { for (unsigned ix = 0; ix < width; ix++) { - int r = *src++; - int g = *src++; - int b = *src++; - int a = *src++; + u8 r = *src++; + u8 g = *src++; + u8 b = *src++; + u8 a = *src++; float aa = (1.0f / 255.0f) * a; @@ -120,11 +132,14 @@ namespace { dst += (bw - width) * 4; // skip the difference } } + //Profiler::TaskFinish("made into canvas, flipped and premult"); // completely skipping over the difference instead of erasing might eventually lead to garbage outside of frame, // but meh; that'll only be visible if you intentionally push the UVs outside the image proper + //Profiler::TaskStart(); CTexture* tx = RenderCore::LoadTexture(static_cast(gpubuf), bw, bh); tx->size = Vector2(width, height); // and for now just fix the size after the fact + //Profiler::TaskFinish("copied into linear"); std::free(imgbuf); linearFree(gpubuf); @@ -216,7 +231,7 @@ shared_ptr ThemeManager::LoadAsset(string& path, ThemeRefContainer nulldrw = make_shared(); string ext = FindExtension(path); - printf("load: %s (%s)\n", path.c_str(), ext.c_str()); + //printf("load: %s (%s)\n", path.c_str(), ext.c_str()); /**/ if (ext == "png") { return make_shared(LoadPNG(path)); } @@ -227,7 +242,7 @@ shared_ptr ThemeManager::LoadAsset(string& path, ThemeRefContainer> j; } auto st = j.dump(); - printf("file contents: %s\n", st.c_str()); + //printf("file contents: %s\n", st.c_str()); string type = j["assetType"]; /**/ if (type == "ninepatch") { diff --git a/libstarlight/source/starlight/gfx/RenderCore.cpp b/libstarlight/source/starlight/gfx/RenderCore.cpp index 0ee7149..9852f45 100644 --- a/libstarlight/source/starlight/gfx/RenderCore.cpp +++ b/libstarlight/source/starlight/gfx/RenderCore.cpp @@ -264,7 +264,7 @@ CTexture* RenderCore::LoadTexture(void* src, int width, int height) { C3D_TexBind(0, tex->texture); - printf("loaded image w %i (%i) h %i (%i)\n", width, owidth, height, oheight); + //printf("loaded image w %i (%i) h %i (%i)\n", width, owidth, height, oheight); return tex; } diff --git a/libstarlight/source/starlight/ui/DebugConsole.cpp b/libstarlight/source/starlight/ui/DebugConsole.cpp index dace710..5971f54 100644 --- a/libstarlight/source/starlight/ui/DebugConsole.cpp +++ b/libstarlight/source/starlight/ui/DebugConsole.cpp @@ -88,6 +88,7 @@ void DebugConsole::PreDraw() { if (!buffer) buffer = std::make_unique(rect.size + Vector2(0, 8)); buffer->Clear(); GFXManager::PushContext(buffer.get()); + GFXManager::PrepareForDrawing(); // force clear even if nothing to write textConfig.Print(buffer->rect, text); GFXManager::PopContext(); } diff --git a/libstarlight/source/starlight/ui/Label.cpp b/libstarlight/source/starlight/ui/Label.cpp index a70e437..749cbfd 100644 --- a/libstarlight/source/starlight/ui/Label.cpp +++ b/libstarlight/source/starlight/ui/Label.cpp @@ -53,6 +53,7 @@ void Label::PreDraw() { buffer = std::make_unique(rect.size + Vector2(0, 8)); buffer->Clear(); GFXManager::PushContext(buffer.get()); + GFXManager::PrepareForDrawing(); // force clear even if nothing to write textConfig.ROGet().Print(buffer->rect, text); GFXManager::PopContext(); } diff --git a/libstarlight/source/starlight/util/Profiler.cpp b/libstarlight/source/starlight/util/Profiler.cpp new file mode 100644 index 0000000..a2f870f --- /dev/null +++ b/libstarlight/source/starlight/util/Profiler.cpp @@ -0,0 +1,19 @@ +#include "Profiler.h" + +#include + +#include "3ds.h" + +using starlight::util::Profiler; + +Profiler::TickCount Profiler::tc = Profiler::TickCount(); + +void Profiler::TaskStart() { + osTickCounterUpdate(reinterpret_cast(&tc)); +} + +void Profiler::TaskFinish(const std::string& msg) { + osTickCounterUpdate(reinterpret_cast(&tc)); + double tm = osTickCounterRead(reinterpret_cast(&tc)); + printf("T:%f - %s\n", tm, msg.c_str()); +} diff --git a/libstarlight/source/starlight/util/Profiler.h b/libstarlight/source/starlight/util/Profiler.h new file mode 100644 index 0000000..32f55de --- /dev/null +++ b/libstarlight/source/starlight/util/Profiler.h @@ -0,0 +1,22 @@ +#pragma once +#include "starlight/_global.h" + +#include + +namespace starlight { + namespace util { + class Profiler { + private: + struct TickCount { + unsigned long long int elapsed; + unsigned long long int ref; + }; + static TickCount tc; + Profiler() {}; + + public: + static void TaskStart(); + static void TaskFinish(const std::string& msg); + }; + } +} diff --git a/libstarlight/todo.txt b/libstarlight/todo.txt index ca565d9..9a95f00 100644 --- a/libstarlight/todo.txt +++ b/libstarlight/todo.txt @@ -13,6 +13,9 @@ roadmap to v0.5.1 { - libctru console as ui element + pngcrush the biggest assets (default and osk backdrops etc.) + - profile image loading (for large images, loading the png and spanned copy/premult take about the same time; memset to preclear is only ~2ms with a 512x512) + - fix the hang on osk when pressing (L|R)+up+left figure out what (else) to put on the left side of the keyboard (opposite backspace and enter) temporary drawable loading, local themeref, discard etc. @@ -28,6 +31,7 @@ roadmap to v0.5.1 { ...and some mechanism for allowing it to opt out of the rest of the cycle Trackable sideclass for threads; float progress 0..1, etc. + ^ make progress bar and use it for a progress/"please wait" dialog - MAKE THREADS END CLEANLY ^ observed a single instance of being stalled on redscreen, not really sure what that was about lambda task thread diff --git a/testbed/Makefile b/testbed/Makefile index 694c993..fc52a9a 100644 --- a/testbed/Makefile +++ b/testbed/Makefile @@ -173,7 +173,7 @@ send: $(BUILD) #--------------------------------------------------------------------------------- send-cia: $(TARGET)-strip.elf @makerom -f cia -o $(TARGET).cia -elf $(TARGET)-strip.elf -rsf resources/$(TARGET).rsf -icon resources/icon.icn -banner resources/banner.bnr -exefslogo -target t - @sockme $(TARGET).cia $(3DSIP) + @sockme $(TARGET).cia $(3DSIP) || sockme $(TARGET).cia $(3DSIP) || sockme $(TARGET).cia $(3DSIP) #--------------------------------------------------------------------------------- run: $(BUILD) @citra $(TARGET).3dsx diff --git a/testbed/resources/starlight-testbed.rsf b/testbed/resources/starlight-testbed.rsf index 98ec6ba..dfd5ae1 100644 --- a/testbed/resources/starlight-testbed.rsf +++ b/testbed/resources/starlight-testbed.rsf @@ -91,6 +91,12 @@ AccessControlInfo: Priority : 16 MaxCpu : 0x9E # Default + + # New3DS Exclusive Process Settings + SystemModeExt : Legacy # Legacy(Default)/124MB/178MB Legacy:Use Old3DS SystemMode + CpuSpeed : 804MHz # 268MHz(Default)/804MHz + EnableL2Cache : true # false(default)/true + CanAccessCore2 : true DisableDebug : true EnableForceDebug : false diff --git a/testbed/source/Core.cpp b/testbed/source/Core.cpp index 8bf6c1d..5688629 100644 --- a/testbed/source/Core.cpp +++ b/testbed/source/Core.cpp @@ -11,6 +11,7 @@ #include "starlight/gfx/RenderCore.h" #include "starlight/util/Path.h" +#include "starlight/util/Profiler.h" #include "starlight/ui/ParallaxLayer.h" #include "starlight/ui/ScrollField.h" @@ -36,6 +37,7 @@ using starlight::GFXManager; using starlight::gfx::RenderCore; using starlight::util::Path; +using starlight::util::Profiler; using starlight::Application; diff --git a/themes/default/decorations/generic backdrop.png b/themes/default/decorations/generic backdrop.png index dd84cdd..29b8caf 100644 Binary files a/themes/default/decorations/generic backdrop.png and b/themes/default/decorations/generic backdrop.png differ diff --git a/themes/default/decorations/osk.background.png b/themes/default/decorations/osk.background.png index ac72c66..cdbe2bf 100644 Binary files a/themes/default/decorations/osk.background.png and b/themes/default/decorations/osk.background.png differ