From 4bf74ef2b507a2d0dca3048f07d777418b74d2cc Mon Sep 17 00:00:00 2001 From: Rye Mutt <rye@alchemyviewer.org> Date: Mon, 13 Dec 2021 10:50:49 -0500 Subject: [PATCH] Reduce needless UTF conversions during draw --- indra/llrender/llfontgl.cpp | 4 ++-- indra/llui/llbadge.cpp | 11 ++++------- indra/llui/llbadge.h | 6 +++--- indra/llui/llstatbar.cpp | 12 ++++++------ indra/llui/llstatbar.h | 2 +- indra/llui/lltextbase.cpp | 5 ++--- indra/newview/llpanelobjectinventory.cpp | 6 ++++-- indra/newview/llpreviewtexture.cpp | 6 ++++-- indra/newview/llworldmapview.cpp | 2 +- 9 files changed, 27 insertions(+), 27 deletions(-) diff --git a/indra/llrender/llfontgl.cpp b/indra/llrender/llfontgl.cpp index 3c6783ca660..30ec1c771f4 100644 --- a/indra/llrender/llfontgl.cpp +++ b/indra/llrender/llfontgl.cpp @@ -395,11 +395,11 @@ S32 LLFontGL::render(const LLWString &wstr, S32 begin_offset, F32 x, F32 y, cons if (draw_ellipses) { - + static const LLWString elipses = utf8str_to_wstring(std::string("...")); // recursively render ellipses at end of string // we've already reserved enough room gGL.pushUIMatrix(); - renderUTF8(std::string("..."), + render(elipses, 0, (cur_x - origin.mV[VX]) / sScaleX, (F32)y, color, diff --git a/indra/llui/llbadge.cpp b/indra/llui/llbadge.cpp index 62a167f2c4d..0c7950bdd22 100644 --- a/indra/llui/llbadge.cpp +++ b/indra/llui/llbadge.cpp @@ -90,7 +90,7 @@ LLBadge::LLBadge(const LLBadge::Params& p) , mGLFont(p.font) , mImage(p.image) , mImageColor(p.image_color) - , mLabel(p.label) + , mLabel(utf8str_to_wstring(p.label)) , mLabelColor(p.label_color) , mLabelOffsetHoriz(p.label_offset_horiz) , mLabelOffsetVert(p.label_offset_vert) @@ -174,7 +174,7 @@ bool LLBadge::addToView(LLView * view) void LLBadge::setLabel(const LLStringExplicit& label) { - mLabel = label; + mLabel = utf8str_to_wstring(label); } // @@ -228,9 +228,6 @@ void LLBadge::draw() // // Calculate badge size based on label text // - - const LLWString& badge_label_wstring = mLabel.getWString(); - S32 badge_label_begin_offset = 0; S32 badge_char_length = S32_MAX; S32 badge_pixel_length = S32_MAX; @@ -238,7 +235,7 @@ void LLBadge::draw() BOOL do_not_use_ellipses = false; F32 badge_width = (2.0f * mPaddingHoriz) + - mGLFont->getWidthF32(badge_label_wstring.c_str(), badge_label_begin_offset, badge_char_length); + mGLFont->getWidthF32(mLabel.c_str(), badge_label_begin_offset, badge_char_length); F32 badge_height = (2.0f * mPaddingVert) + mGLFont->getLineHeight(); @@ -352,7 +349,7 @@ void LLBadge::draw() // Draw the label // - mGLFont->render(badge_label_wstring, + mGLFont->render(mLabel, badge_label_begin_offset, badge_center_x + mLabelOffsetHoriz, badge_center_y + mLabelOffsetVert, diff --git a/indra/llui/llbadge.h b/indra/llui/llbadge.h index cd89c5f7408..6e309cc4d00 100644 --- a/indra/llui/llbadge.h +++ b/indra/llui/llbadge.h @@ -87,7 +87,7 @@ namespace LLInitParam // Classes // -class LLBadge +class LLBadge final : public LLUICtrl { public: @@ -134,7 +134,7 @@ class LLBadge virtual void draw(); - const std::string& getLabel() const { return mLabel.getString(); } + //const std::string& getLabel() const { return mLabel.getString(); } void setLabel( const LLStringExplicit& label); void setDrawAtParentTop(bool draw_at_top) { mDrawAtParentTop = draw_at_top;} @@ -148,7 +148,7 @@ class LLBadge LLPointer< LLUIImage > mImage; LLUIColor mImageColor; - LLUIString mLabel; + LLWString mLabel; LLUIColor mLabelColor; S32 mLabelOffsetHoriz; diff --git a/indra/llui/llstatbar.cpp b/indra/llui/llstatbar.cpp index 41a49026999..0101868f21f 100644 --- a/indra/llui/llstatbar.cpp +++ b/indra/llui/llstatbar.cpp @@ -175,7 +175,7 @@ LLStatBar::Params::Params() LLStatBar::LLStatBar(const Params& p) : LLView(p), - mLabel(p.label), + mLabel(utf8str_to_wstring(p.label)), mUnitLabel(p.unit_label), mTargetMinBar(llmin(p.bar_min, p.bar_max)), mTargetMaxBar(llmax(p.bar_max, p.bar_min)), @@ -620,7 +620,7 @@ LLRect LLStatBar::getRequiredRect() void LLStatBar::drawLabelAndValue( F32 value, std::string &label, LLRect &bar_rect, S32 decimal_digits ) { - LLFontGL::getFontMonospace()->renderUTF8(mLabel, 0, 0, getRect().getHeight(), LLColor4(1.f, 1.f, 1.f, 1.f), + LLFontGL::getFontMonospace()->render(mLabel, 0, 0, getRect().getHeight(), LLColor4(1.f, 1.f, 1.f, 1.f), LLFontGL::LEFT, LLFontGL::TOP); std::string value_str = !llisnan(value) @@ -695,14 +695,14 @@ void LLStatBar::drawTicks( F32 min, F32 max, F32 value_scale, LLRect &bar_rect ) { decimal_digits = 0; } - std::string tick_label = llformat("%.*f", decimal_digits, tick_value); - S32 tick_label_width = LLFontGL::getFontMonospace()->getWidth(tick_label); + LLWString tick_label = utf8str_to_wstring(llformat("%.*f", decimal_digits, tick_value)); + S32 tick_label_width = LLFontGL::getFontMonospace()->getWidth(tick_label.c_str()); if (mOrientation == HORIZONTAL) { if (tick_begin > last_label + MIN_LABEL_SPACING) { gl_rect_2d(bar_rect.mLeft, tick_end, bar_rect.mRight - TICK_LENGTH, tick_begin, LLColor4(1.f, 1.f, 1.f, 0.25f)); - LLFontGL::getFontMonospace()->renderUTF8(tick_label, 0, bar_rect.mRight, tick_begin, + LLFontGL::getFontMonospace()->render(tick_label, 0, bar_rect.mRight, tick_begin, LLColor4(1.f, 1.f, 1.f, 0.5f), LLFontGL::LEFT, LLFontGL::VCENTER); last_label = tick_begin; @@ -718,7 +718,7 @@ void LLStatBar::drawTicks( F32 min, F32 max, F32 value_scale, LLRect &bar_rect ) { gl_rect_2d(tick_begin, bar_rect.mTop, tick_end, bar_rect.mBottom - TICK_LENGTH, LLColor4(1.f, 1.f, 1.f, 0.25f)); S32 label_pos = tick_begin - ll_round((F32)tick_label_width * ((F32)tick_begin / (F32)bar_rect.getWidth())); - LLFontGL::getFontMonospace()->renderUTF8(tick_label, 0, label_pos, bar_rect.mBottom - TICK_LENGTH, + LLFontGL::getFontMonospace()->render(tick_label, 0, label_pos, bar_rect.mBottom - TICK_LENGTH, LLColor4(1.f, 1.f, 1.f, 0.5f), LLFontGL::LEFT, LLFontGL::TOP); last_label = label_pos; diff --git a/indra/llui/llstatbar.h b/indra/llui/llstatbar.h index 1ff4c67fc51..08bce6ca185 100644 --- a/indra/llui/llstatbar.h +++ b/indra/llui/llstatbar.h @@ -107,7 +107,7 @@ class LLStatBar : public LLView const LLTrace::StatType<LLTrace::MemAccumulator>* memStatp; } mStat; - LLUIString mLabel; + LLWString mLabel; std::string mUnitLabel; bool mDisplayBar, // Display the bar graph. diff --git a/indra/llui/lltextbase.cpp b/indra/llui/lltextbase.cpp index 59b4a6bb7af..fb465ca5f39 100644 --- a/indra/llui/lltextbase.cpp +++ b/indra/llui/lltextbase.cpp @@ -569,7 +569,6 @@ void LLTextBase::drawCursor() && !mReadOnly) { const LLWString &wtext = getWText(); - const llwchar* text = wtext.c_str(); LLRect cursor_rect = getLocalRectFromDocIndex(mCursorPos); cursor_rect.translate(-1, 0); @@ -613,13 +612,13 @@ void LLTextBase::drawCursor() gl_rect_2d(cursor_rect); - if (LL_KIM_OVERWRITE == gKeyboard->getInsertMode() && !hasSelection() && text[mCursorPos] != '\n') + if (LL_KIM_OVERWRITE == gKeyboard->getInsertMode() && !hasSelection() && wtext[mCursorPos] != '\n') { LLColor4 text_color; const LLFontGL* fontp; text_color = segmentp->getColor(); fontp = segmentp->getStyle()->getFont(); - fontp->render(text, mCursorPos, cursor_rect, + fontp->render(wtext, mCursorPos, cursor_rect, LLColor4(1.f - text_color.mV[VRED], 1.f - text_color.mV[VGREEN], 1.f - text_color.mV[VBLUE], alpha), LLFontGL::LEFT, mVAlign, LLFontGL::NORMAL, diff --git a/indra/newview/llpanelobjectinventory.cpp b/indra/newview/llpanelobjectinventory.cpp index 20d53379cf9..aeed2b9b01c 100644 --- a/indra/newview/llpanelobjectinventory.cpp +++ b/indra/newview/llpanelobjectinventory.cpp @@ -1791,7 +1791,8 @@ void LLPanelObjectInventory::draw() { if((LLUUID::null != mTaskUUID) && (!mHaveInventory)) { - LLFontGL::getFontSansSerif()->renderUTF8(LLTrans::getString("LoadingContents"), 0, + static const LLWString loading_contents_str = utf8str_to_wstring(LLTrans::getString("LoadingContents")); + LLFontGL::getFontSansSerif()->render(loading_contents_str, 0, (S32)(getRect().getWidth() * 0.5f), 10, LLColor4( 1, 1, 1, 1 ), @@ -1800,7 +1801,8 @@ void LLPanelObjectInventory::draw() } else if(mHaveInventory) { - LLFontGL::getFontSansSerif()->renderUTF8(LLTrans::getString("NoContents"), 0, + static const LLWString no_contents_str = utf8str_to_wstring(LLTrans::getString("NoContents")); + LLFontGL::getFontSansSerif()->render(no_contents_str, 0, (S32)(getRect().getWidth() * 0.5f), 10, LLColor4( 1, 1, 1, 1 ), diff --git a/indra/newview/llpreviewtexture.cpp b/indra/newview/llpreviewtexture.cpp index a5aa0e706ae..ab200f0a768 100644 --- a/indra/newview/llpreviewtexture.cpp +++ b/indra/newview/llpreviewtexture.cpp @@ -231,7 +231,8 @@ void LLPreviewTexture::draw() if( mLoadingFullImage ) { - LLFontGL::getFontSansSerif()->renderUTF8(LLTrans::getString("Receiving"), 0, + static const LLWString receiving_str = utf8str_to_wstring(LLTrans::getString("Receiving")); + LLFontGL::getFontSansSerif()->render(receiving_str, 0, interior.mLeft + 4, interior.mBottom + 4, LLColor4::white, LLFontGL::LEFT, LLFontGL::BOTTOM, @@ -268,7 +269,8 @@ void LLPreviewTexture::draw() else if( !mSavedFileTimer.hasExpired() ) { - LLFontGL::getFontSansSerif()->renderUTF8(LLTrans::getString("FileSaved"), 0, + static const LLWString file_saved_str = utf8str_to_wstring(LLTrans::getString("FileSaved")); + LLFontGL::getFontSansSerif()->render(file_saved_str, 0, interior.mLeft + 4, interior.mBottom + 4, LLColor4::white, LLFontGL::LEFT, LLFontGL::BOTTOM, diff --git a/indra/newview/llworldmapview.cpp b/indra/newview/llworldmapview.cpp index db39738ed38..3e1d1bf0174 100644 --- a/indra/newview/llworldmapview.cpp +++ b/indra/newview/llworldmapview.cpp @@ -1018,7 +1018,7 @@ void LLWorldMapView::drawTracking(const LLVector3d& pos_global, const LLColor4& // if (label != "") // [RLVa:KB] - Checked: 2009-07-04 (RLVa-1.4.5) | Added: RLVa-1.0.0 - if ( (label != "") && (RlvActions::canShowLocation()) ) + if (!label.empty() && (RlvActions::canShowLocation())) // [/RLVa:KB] { // clamp text position to on-screen -- GitLab