Android底层开发之字符绘制TextLayoutCache

本文介绍如何在Android系统中启用TextLayoutCache的调试信息,通过设置rtl.debug_level属性值来打开调试,并重启系统查看详细日志。适用于字体渲染相关的应用开发者。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

查看TextLayoutCache调试信息

版本为Android 4.2.2_r1

 

关于TextLayoutCache

The input of TextLayoutCache is a font and a Java UTF-16 string and its output is a list of glyph identifiers with their x/y positions.

 

来自:https://medium.com/@romainguy/androids-font-renderer-c368bbde87d9

 

以TextLayoutCache查看Log默认只能看到如下一条信息,如何打开调试信息呢?

08-12 07:21:38.490: D/TextLayoutCache(100): Using debug level = 0 - Debug Enabled = 0

 

追踪了一下:

void TextLayoutCache::init() {

    mCache.setOnEntryRemovedListener(this);

 

    mDebugLevel = readRtlDebugLevel();

    mDebugEnabled = mDebugLevel & kRtlDebugCaches;

    ALOGD("Using debug level = %d - Debug Enabled = %d", mDebugLevel, mDebugEnabled);

 

    mCacheStartTime = systemTime(SYSTEM_TIME_MONOTONIC);

 

    if (mDebugEnabled) {

        ALOGD("Initialization is done - Start time = %lld", mCacheStartTime);

    }

 

    mInitialized = true;

}

位于:frameworks/base/core/jni/android/graphics/TextLayoutCache.cpp

 

/**

 * Debug level for app developers.

 */

#define RTL_PROPERTY_DEBUG "rtl.debug_level"

 

/**

 * Debug levels. Debug levels are used as flags.

 */

enum RtlDebugLevel {

    kRtlDebugDisabled = 0,

    kRtlDebugMemory = 1,

    kRtlDebugCaches = 2,

    kRtlDebugAllocations = 3

};

 

static RtlDebugLevel readRtlDebugLevel() {

    char property[PROPERTY_VALUE_MAX];

    if (property_get(RTL_PROPERTY_DEBUG, property, NULL) > 0) {

        return (RtlDebugLevel) atoi(property);

    }

    return kRtlDebugDisabled;

}

位于:frameworks/base/core/jni/android/graphics/RtlProperties.h

 

当rtl.debug_level等于2kRtlDebugCaches)调试信息才可以被打开。在adb shell中执行:

#打开调试

setprop rtl.debug_level 2

#仅重启Android

stop && start

之后就可以以TextLayoutCache来查看它的LOG了。以下是部分信息截图:

片断1 SystemUI的文字处理过程:

 

片断自己编写的测试程序文字处理过程:

 

 

后续

打开调试信息,看init中调用的是harfbuzz还是icu。像下面这段代码一样:

#if RTL_USE_HARFBUZZ
        LOGD("TextLayoutCache is using HARFBUZZ");
#else
        LOGD("TextLayoutCache is using ICU");
#endif

ICU和HARFBUZZ关系这里闲聊文本渲染技术的近期发展有讲到,在ICU官网上已经看到推荐以前使用ICU的客户使用HARFBUZZ,他们的团队也已经加入到了HARFBUZZ中开发了。讲它俩关系的文章中已经提到这种可能了,真是神预言。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

袁保康

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值