From 1d4af802cc72626e80d8163240c17d6ee64ba2b9 Mon Sep 17 00:00:00 2001 From: Anthony Catel Date: Tue, 10 Jan 2017 10:08:50 +0100 Subject: [PATCH] shpwFPS cpu usage: don't reload the font for every frame --- src/Binding/JSDocument.cpp | 14 ++++++++------ src/Binding/JSDocument.h | 2 +- src/Frontend/Context.cpp | 5 ++--- src/Graphics/SkiaContext.cpp | 2 +- src/Graphics/SkiaContext.h | 2 +- src/libapenetwork | 2 +- 6 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/Binding/JSDocument.cpp b/src/Binding/JSDocument.cpp index 6e1446f8..b7a78907 100644 --- a/src/Binding/JSDocument.cpp +++ b/src/Binding/JSDocument.cpp @@ -424,16 +424,18 @@ bool JSDocument::JS_loadFont(JSContext *cx, JS::CallArgs &args) return true; } -SkTypeface *JSDocument::getFont(char *name) +SkTypeface *JSDocument::getFont(const char *name) { - char *pTmp = name; + char *pTmp = strdup(name); - while (*pTmp != '\0') { - *pTmp = tolower(*pTmp); - pTmp++; + for (int i = 0; name[i] != '\0'; i++) { + pTmp[i] = tolower(name[i]); } - NidiumFont *font = m_Fonts.get(name); + NidiumFont *font = m_Fonts.get(pTmp); + + free(pTmp); + if (font) { return font->m_Typeface; } diff --git a/src/Binding/JSDocument.h b/src/Binding/JSDocument.h index ca92bb56..78e46449 100644 --- a/src/Binding/JSDocument.h +++ b/src/Binding/JSDocument.h @@ -56,7 +56,7 @@ class JSDocument : public ClassMapper int weight = 400, NidiumFont::Style = NidiumFont::kFontStyle_Normal); - SkTypeface *getFont(char *name); + SkTypeface *getFont(const char *name); protected: NIDIUM_DECL_JSCALL(run); diff --git a/src/Frontend/Context.cpp b/src/Frontend/Context.cpp index 09eab3ae..43f8cecc 100644 --- a/src/Frontend/Context.cpp +++ b/src/Frontend/Context.cpp @@ -256,6 +256,7 @@ void Context::createDebugCanvas() m_DebugHandler->setRight(0); m_DebugHandler->setOpacity(0.6); + ctx2d->getSurface()->setFontType("monospace"); } #if DEBUG @@ -292,9 +293,7 @@ void Context::postDraw() s->drawRect(0, 0, m_DebugHandler->getWidth(), m_DebugHandler->getHeight(), 0); s->setFillColor(0xFFEEEEEEu); - - // TODO: new style cast - s->setFontType((char *)("monospace")); + s->drawTextf(5, 12, "Nidium build %s %s", __DATE__, __TIME__); s->drawTextf(5, 25, "Frame: %lld (%lldms)", m_Stats.nframe, m_Stats.lastdifftime / 1000000LL); diff --git a/src/Graphics/SkiaContext.cpp b/src/Graphics/SkiaContext.cpp index 9ee06153..61a8b39c 100644 --- a/src/Graphics/SkiaContext.cpp +++ b/src/Graphics/SkiaContext.cpp @@ -1461,7 +1461,7 @@ void SkiaContext::setFontStyle(const char *style) PAINT->setTextSkewX(strcasestr(style, "italic") ? m_FontSkew : 0); } -void SkiaContext::setFontType(char *str, JSDocument *doc) +void SkiaContext::setFontType(const char *str, JSDocument *doc) { if (doc) { SkTypeface *tf = doc->getFont(str); diff --git a/src/Graphics/SkiaContext.h b/src/Graphics/SkiaContext.h index 888da989..8c56c9b4 100644 --- a/src/Graphics/SkiaContext.h +++ b/src/Graphics/SkiaContext.h @@ -219,7 +219,7 @@ class SkiaContext void setGlobalComposite(const char *str); void setLineCap(const char *capStyle); void setLineJoin(const char *joinStyle); - void setFontType(char *str, Binding::JSDocument *doc = NULL); + void setFontType(const char *str, Binding::JSDocument *doc = NULL); bool setFontFile(const char *str); void clearRect(double, double, double, double); diff --git a/src/libapenetwork b/src/libapenetwork index b1b544d3..8076166f 160000 --- a/src/libapenetwork +++ b/src/libapenetwork @@ -1 +1 @@ -Subproject commit b1b544d3c4a1c62ce5bd73fd6005e574da17d4c0 +Subproject commit 8076166fd5cf3882de2eeba4cf65e970a9856b65