Android底层开发之字符绘制TextLayoutCache

来源:互联网 发布:aster遥感数据 编辑:程序博客网 时间:2024/06/17 17:59

查看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中开发了。讲它俩关系的文章中已经提到这种可能了,真是神预言。



0 0
原创粉丝点击