Skip to content

Commit

Permalink
shpwFPS cpu usage: don't reload the font for every frame
Browse files Browse the repository at this point in the history
  • Loading branch information
paraboul committed Jan 10, 2017
1 parent 9511639 commit 1d4af80
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 13 deletions.
14 changes: 8 additions & 6 deletions src/Binding/JSDocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Binding/JSDocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class JSDocument : public ClassMapper<JSDocument>
int weight = 400,
NidiumFont::Style = NidiumFont::kFontStyle_Normal);

SkTypeface *getFont(char *name);
SkTypeface *getFont(const char *name);
protected:

NIDIUM_DECL_JSCALL(run);
Expand Down
5 changes: 2 additions & 3 deletions src/Frontend/Context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ void Context::createDebugCanvas()

m_DebugHandler->setRight(0);
m_DebugHandler->setOpacity(0.6);
ctx2d->getSurface()->setFontType("monospace");
}

#if DEBUG
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/SkiaContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Graphics/SkiaContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/libapenetwork
Submodule libapenetwork updated 1 files
+3 −2 configure

0 comments on commit 1d4af80

Please sign in to comment.