[deploy] pref: auto enable text pre render mode
This commit is contained in:
parent
6f880db21e
commit
946bada0ec
|
|
@ -222,16 +222,20 @@ void TextActor::SetTextLayout(TextLayoutPtr layout)
|
|||
|
||||
void TextActor::SetPreRenderEnabled(bool enable)
|
||||
{
|
||||
if (enable)
|
||||
const bool enabled = texture_cached_ != nullptr;
|
||||
if (enabled != enable)
|
||||
{
|
||||
texture_cached_ = MakePtr<Texture>();
|
||||
if (enable)
|
||||
{
|
||||
texture_cached_ = MakePtr<Texture>();
|
||||
}
|
||||
else
|
||||
{
|
||||
texture_cached_ = nullptr;
|
||||
}
|
||||
render_ctx_ = nullptr;
|
||||
is_cache_dirty_ = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
texture_cached_ = nullptr;
|
||||
}
|
||||
render_ctx_ = nullptr;
|
||||
is_cache_dirty_ = true;
|
||||
}
|
||||
|
||||
void TextActor::Update(Duration dt)
|
||||
|
|
@ -273,6 +277,10 @@ void TextActor::ForceUpdateLayout()
|
|||
|
||||
void TextActor::UpdateCachedTexture()
|
||||
{
|
||||
// 有文字描边或其他额外渲染时,需要开启预渲染以提升性能
|
||||
this->SetPreRenderEnabled(outline_brush_ || style_.show_strikethrough || style_.show_underline
|
||||
|| (layout_ && layout_->GetContentLength() > 30));
|
||||
|
||||
if (!texture_cached_)
|
||||
{
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -142,10 +142,6 @@ public:
|
|||
/// @brief 设置文本布局
|
||||
void SetTextLayout(TextLayoutPtr layout);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置预渲染模式,在描边等情况下会有更好的性能
|
||||
void SetPreRenderEnabled(bool enable);
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 更新脏文字布局
|
||||
/// @details 仅当文字布局脏时更新
|
||||
|
|
@ -165,6 +161,10 @@ protected:
|
|||
|
||||
void UpdateCachedTexture();
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置预渲染模式,在描边等情况下会有更好的性能
|
||||
void SetPreRenderEnabled(bool enable);
|
||||
|
||||
private:
|
||||
bool is_cache_dirty_;
|
||||
String content_;
|
||||
|
|
|
|||
|
|
@ -68,6 +68,10 @@ public:
|
|||
/// @brief 获取文本行数
|
||||
uint32_t GetLineCount() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 获取文本长度
|
||||
uint32_t GetContentLength() const;
|
||||
|
||||
/// \~chinese
|
||||
/// @brief 设置字体
|
||||
/// @param font 字体
|
||||
|
|
@ -136,6 +140,11 @@ inline void TextLayout::Clear()
|
|||
ResetNativePointer();
|
||||
}
|
||||
|
||||
inline uint32_t TextLayout::GetContentLength() const
|
||||
{
|
||||
return content_length_;
|
||||
}
|
||||
|
||||
inline TextLayout::DirtyFlag TextLayout::GetDirtyFlag() const
|
||||
{
|
||||
return dirty_flag_;
|
||||
|
|
|
|||
Loading…
Reference in New Issue