Experimental ICU runtime linking

Introduce a build config option where ICU symbols are resolved at
runtime, against existing system libs.

Change-Id: I2325537438de0063fcc4a7c0f8411764cf550f09
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/431037
Commit-Queue: Florin Malita <fmalita@chromium.org>
Commit-Queue: Florin Malita <fmalita@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
This commit is contained in:
Florin Malita 2021-07-26 15:33:26 -04:00 committed by SkCQ
parent 5fea567664
commit f4aab0584d
22 changed files with 368 additions and 102 deletions

View File

@ -24,6 +24,7 @@ if (skia_enable_sktext && skia_enable_skshaper && skia_use_icu &&
deps = [
"../..:skia",
"../../modules/skshaper",
"../../modules/skunicode",
]
}

View File

@ -14,7 +14,7 @@
#include "include/core/SkString.h"
#include "include/core/SkTextBlob.h"
#include "modules/skshaper/include/SkShaper.h"
#include "modules/skshaper/src/SkUnicode.h"
#include "modules/skunicode/include/SkUnicode.h"
namespace skia {
namespace text {

View File

@ -2,7 +2,6 @@
#include "experimental/sktext/include/Text.h"
#include "experimental/sktext/src/Line.h"
#include "experimental/sktext/src/TextRun.h"
#include "modules/skshaper/src/SkUnicode.h"
namespace skia {
namespace text {

View File

@ -212,7 +212,8 @@ FONT_CFLAGS+=" -DCANVASKIT_NO_ALIAS_FONT"
fi
GN_SHAPER="skia_use_icu=true skia_use_system_icu=false skia_use_harfbuzz=true skia_use_system_harfbuzz=false"
SHAPER_LIB="$BUILD_DIR/libharfbuzz.a \
SHAPER_LIB="$BUILD_DIR/libskunicode.a \
$BUILD_DIR/libharfbuzz.a \
$BUILD_DIR/libicu.a"
if [[ $@ == *primitive_shaper* ]] || [[ $@ == *no_font* ]]; then
echo "Using the primitive shaper instead of the harfbuzz/icu one"

View File

@ -27,6 +27,7 @@ if (skia_enable_skparagraph && skia_enable_skshaper && skia_use_icu &&
deps = [
"../..:skia",
"../skshaper",
"../skunicode",
]
}

View File

@ -19,7 +19,6 @@
#include "modules/skparagraph/src/ParagraphImpl.h"
#include "modules/skparagraph/src/TextLine.h"
#include "modules/skparagraph/utils/TestFontCollection.h"
#include "modules/skshaper/src/SkUnicode.h"
#include "samplecode/Sample.h"
#include "src/core/SkOSFile.h"
#include "src/shaders/SkColorShader.h"

View File

@ -11,7 +11,7 @@
#include "modules/skparagraph/include/ParagraphBuilder.h"
#include "modules/skparagraph/include/ParagraphStyle.h"
#include "modules/skparagraph/include/TextStyle.h"
#include "modules/skshaper/src/SkUnicode.h"
#include "modules/skunicode/include/SkUnicode.h"
namespace skia {
namespace textlayout {

View File

@ -25,7 +25,7 @@
#include "modules/skparagraph/include/TextStyle.h"
#include "modules/skparagraph/src/Run.h"
#include "modules/skparagraph/src/TextLine.h"
#include "modules/skshaper/src/SkUnicode.h"
#include "modules/skunicode/include/SkUnicode.h"
#include <memory>
#include <string>

View File

@ -2,7 +2,6 @@
#include "modules/skparagraph/include/DartTypes.h"
#include "modules/skparagraph/include/ParagraphStyle.h"
#include "modules/skshaper/src/SkUnicode.h"
#include "src/core/SkStringUtils.h"
#include "src/utils/SkUTF.h"

View File

@ -18,7 +18,6 @@ if (skia_enable_skshaper) {
}
if (skia_use_icu && skia_use_harfbuzz) {
defines += [ "SK_SHAPER_HARFBUZZ_AVAILABLE" ]
defines += [ "SK_UNICODE_AVAILABLE" ]
}
}
@ -27,10 +26,7 @@ if (skia_enable_skshaper) {
public_configs = [ ":public_config" ]
public = skia_shaper_public
deps = [ "../..:skia" ]
defines = [
"SKSHAPER_IMPLEMENTATION=1",
"SKUNICODE_IMPLEMENTATION=1",
]
defines = [ "SKSHAPER_IMPLEMENTATION=1" ]
sources = skia_shaper_primitive_sources
if (skia_use_fonthost_mac) {
sources += skia_shaper_coretext_sources
@ -46,11 +42,10 @@ if (skia_enable_skshaper) {
}
}
if (skia_use_icu && skia_use_harfbuzz) {
sources += skia_shaper_icu_sources
sources += skia_shaper_harfbuzz_sources
deps += [
"//modules/skunicode",
"//third_party/harfbuzz",
"//third_party/icu",
]
}
configs += [

View File

@ -13,10 +13,6 @@ skia_shaper_primitive_sources = [
"$_src/SkShaper.cpp",
"$_src/SkShaper_primitive.cpp",
]
skia_shaper_icu_sources = [
"$_src/SkUnicode.h",
"$_src/SkUnicode_icu.cpp",
]
skia_shaper_harfbuzz_sources = [ "$_src/SkShaper_harfbuzz.cpp" ]
skia_shaper_coretext_sources = [ "$_src/SkShaper_coretext.cpp" ]

View File

@ -15,7 +15,7 @@
#include "modules/skshaper/include/SkShaper.h"
#ifdef SK_UNICODE_AVAILABLE
#include "modules/skshaper/src/SkUnicode.h"
#include "modules/skunicode/include/SkUnicode.h"
#endif
#include "src/core/SkTextBlobPriv.h"
#include "src/utils/SkUTF.h"

View File

@ -27,7 +27,7 @@
#include "include/private/SkTemplates.h"
#include "include/private/SkTo.h"
#include "modules/skshaper/include/SkShaper.h"
#include "modules/skshaper/src/SkUnicode.h"
#include "modules/skunicode/include/SkUnicode.h"
#include "src/core/SkLRUCache.h"
#include "src/core/SkTDPQueue.h"
#include "src/utils/SkUTF.h"

View File

@ -0,0 +1,43 @@
# Copyright 2021 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("../../gn/skia.gni")
import("skunicode.gni")
declare_args() {
skia_use_runtime_icu = false
}
if (skia_use_icu) {
config("public_config") {
include_dirs = [ "include" ]
defines = [ "SK_UNICODE_AVAILABLE" ]
}
component("skunicode") {
check_includes = false
public_configs = [ ":public_config" ]
public = skia_unicode_public
deps = [ "../..:skia" ]
defines = [ "SKUNICODE_IMPLEMENTATION=1" ]
sources = skia_unicode_sources
# only available for Android at the moment
if (skia_use_runtime_icu && (is_android || is_linux)) {
sources += skia_unicode_runtime_icu_sources
deps += [ "//third_party/icu:headers" ]
} else {
sources += skia_unicode_builtin_icu_sources
deps += [ "//third_party/icu" ]
}
configs += [
"../../:skia_private",
"../../third_party/icu/config:no_cxx",
]
}
} else {
group("skunicode") {
}
}

View File

@ -0,0 +1,18 @@
# Copyright 2021 Google Inc.
#
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
# Things are easiest for everyone if these source paths are absolute.
_src = get_path_info("src", "abspath")
_include = get_path_info("include", "abspath")
skia_unicode_public = [ "$_include/SkUnicode.h" ]
skia_unicode_sources = [
"$_src/SkUnicode_icu.cpp",
"$_src/SkUnicode_icu.h",
]
skia_unicode_builtin_icu_sources = [ "$_src/SkUnicode_icu_builtin.cpp" ]
skia_unicode_runtime_icu_sources = [ "$_src/SkUnicode_icu_runtime.cpp" ]

View File

@ -10,14 +10,9 @@
#include "include/private/SkTFitsIn.h"
#include "include/private/SkTHash.h"
#include "include/private/SkTemplates.h"
#include "modules/skshaper/src/SkUnicode.h"
#include "modules/skunicode/include/SkUnicode.h"
#include "modules/skunicode/src/SkUnicode_icu.h"
#include "src/utils/SkUTF.h"
#include <unicode/ubidi.h>
#include <unicode/ubrk.h>
#include <unicode/uscript.h>
#include <unicode/ustring.h>
#include <unicode/utext.h>
#include <unicode/utypes.h>
#include <vector>
#include <functional>
@ -25,26 +20,46 @@
#include "SkLoadICU.h"
#endif
// ubrk_clone added as draft in ICU69 and Android API 31 (first ICU NDK).
// ubrk_safeClone deprecated in ICU69 and not exposed by Android.
template<typename...> using void_t = void;
template<typename T, typename = void>
struct SkUbrkClone {
UBreakIterator* operator()(T bi, UErrorCode* status) {
return ubrk_safeClone(bi, nullptr, nullptr, status);
}
};
template<typename T>
struct SkUbrkClone<T, void_t<decltype(ubrk_clone(std::declval<T>(), nullptr))>> {
UBreakIterator* operator()(T bi, UErrorCode* status) {
return ubrk_clone(bi, status);
}
};
static const SkICULib* ICULib() {
static const auto gICU = SkLoadICULib();
using SkUnicodeBidi = std::unique_ptr<UBiDi, SkFunctionWrapper<decltype(ubidi_close), ubidi_close>>;
using ICUUText = std::unique_ptr<UText, SkFunctionWrapper<decltype(utext_close), utext_close>>;
using ICUBreakIterator = std::unique_ptr<UBreakIterator, SkFunctionWrapper<decltype(ubrk_close), ubrk_close>>;
return gICU.get();
}
// sk_* wrappers for ICU funcs
#define SKICU_FUNC(funcname) \
template <typename... Args> \
auto sk_##funcname(Args&&... args) -> decltype(funcname(std::forward<Args>(args)...)) { \
return ICULib()->f_##funcname(std::forward<Args>(args)...); \
} \
SKICU_EMIT_FUNCS
#undef SKICU_FUNC
static inline UBreakIterator* sk_ubrk_clone(const UBreakIterator* bi, UErrorCode* status) {
const auto* icu = ICULib();
SkASSERT(icu->f_ubrk_clone_ || icu->f_ubrk_safeClone_);
return icu->f_ubrk_clone_
? icu->f_ubrk_clone_(bi, status)
: icu->f_ubrk_safeClone_(bi, nullptr, nullptr, status);
}
static void ubidi_close_wrapper(UBiDi* bidi) {
sk_ubidi_close(bidi);
}
static UText* utext_close_wrapper(UText* ut) {
return sk_utext_close(ut);
}
static void ubrk_close_wrapper(UBreakIterator* bi) {
sk_ubrk_close(bi);
}
using SkUnicodeBidi = std::unique_ptr<UBiDi, SkFunctionWrapper<decltype(ubidi_close),
ubidi_close_wrapper>>;
using ICUUText = std::unique_ptr<UText, SkFunctionWrapper<decltype(utext_close),
utext_close_wrapper>>;
using ICUBreakIterator = std::unique_ptr<UBreakIterator, SkFunctionWrapper<decltype(ubrk_close),
ubrk_close_wrapper>>;
/** Replaces invalid utf-8 sequences with REPLACEMENT CHARACTER U+FFFD. */
static inline SkUnichar utf8_next(const char** ptr, const char* end) {
SkUnichar val = SkUTF::NextUTF8(ptr, end);
@ -65,23 +80,23 @@ class SkBidiIterator_icu : public SkBidiIterator {
SkUnicodeBidi fBidi;
public:
explicit SkBidiIterator_icu(SkUnicodeBidi bidi) : fBidi(std::move(bidi)) {}
Position getLength() override { return ubidi_getLength(fBidi.get()); }
Level getLevelAt(Position pos) override { return ubidi_getLevelAt(fBidi.get(), pos); }
Position getLength() override { return sk_ubidi_getLength(fBidi.get()); }
Level getLevelAt(Position pos) override { return sk_ubidi_getLevelAt(fBidi.get(), pos); }
static std::unique_ptr<SkBidiIterator> makeBidiIterator(const uint16_t utf16[], int utf16Units, Direction dir) {
UErrorCode status = U_ZERO_ERROR;
SkUnicodeBidi bidi(ubidi_openSized(utf16Units, 0, &status));
SkUnicodeBidi bidi(sk_ubidi_openSized(utf16Units, 0, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Bidi error: %s", u_errorName(status));
SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
return nullptr;
}
SkASSERT(bidi);
uint8_t bidiLevel = (dir == SkBidiIterator::kLTR) ? UBIDI_LTR : UBIDI_RTL;
// The required lifetime of utf16 isn't well documented.
// It appears it isn't used after ubidi_setPara except through ubidi_getText.
ubidi_setPara(bidi.get(), (const UChar*)utf16, utf16Units, bidiLevel, nullptr, &status);
sk_ubidi_setPara(bidi.get(), (const UChar*)utf16, utf16Units, bidiLevel, nullptr, &status);
if (U_FAILURE(status)) {
SkDEBUGF("Bidi error: %s", u_errorName(status));
SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
return nullptr;
}
return std::unique_ptr<SkBidiIterator>(new SkBidiIterator_icu(std::move(bidi)));
@ -145,7 +160,7 @@ public:
void SkBidiIterator::ReorderVisual(const Level runLevels[], int levelsCount,
int32_t logicalFromVisual[]) {
ubidi_reorderVisual(runLevels, levelsCount, logicalFromVisual);
sk_ubidi_reorderVisual(runLevels, levelsCount, logicalFromVisual);
}
class SkBreakIterator_icu : public SkBreakIterator {
@ -155,30 +170,30 @@ class SkBreakIterator_icu : public SkBreakIterator {
explicit SkBreakIterator_icu(ICUBreakIterator iter)
: fBreakIterator(std::move(iter)), fLastResult(0) {}
Position first() override
{ return fLastResult = ubrk_first(fBreakIterator.get()); }
{ return fLastResult = sk_ubrk_first(fBreakIterator.get()); }
Position current() override
{ return fLastResult = ubrk_current(fBreakIterator.get()); }
{ return fLastResult = sk_ubrk_current(fBreakIterator.get()); }
Position next() override
{ return fLastResult = ubrk_next(fBreakIterator.get()); }
{ return fLastResult = sk_ubrk_next(fBreakIterator.get()); }
Position preceding(Position offset) override
{ return fLastResult = ubrk_preceding(fBreakIterator.get(), offset); }
{ return fLastResult = sk_ubrk_preceding(fBreakIterator.get(), offset); }
Position following(Position offset) override
{ return fLastResult = ubrk_following(fBreakIterator.get(), offset);}
Status status() override { return ubrk_getRuleStatus(fBreakIterator.get()); }
{ return fLastResult = sk_ubrk_following(fBreakIterator.get(), offset);}
Status status() override { return sk_ubrk_getRuleStatus(fBreakIterator.get()); }
bool isDone() override { return fLastResult == UBRK_DONE; }
bool setText(const char utftext8[], int utf8Units) override {
UErrorCode status = U_ZERO_ERROR;
ICUUText text(utext_openUTF8(nullptr, &utftext8[0], utf8Units, &status));
ICUUText text(sk_utext_openUTF8(nullptr, &utftext8[0], utf8Units, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", u_errorName(status));
SkDEBUGF("Break error: %s", sk_u_errorName(status));
return false;
}
SkASSERT(text);
ubrk_setUText(fBreakIterator.get(), text.get(), &status);
sk_ubrk_setUText(fBreakIterator.get(), text.get(), &status);
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", u_errorName(status));
SkDEBUGF("Break error: %s", sk_u_errorName(status));
return false;
}
fLastResult = 0;
@ -186,16 +201,17 @@ class SkBreakIterator_icu : public SkBreakIterator {
}
bool setText(const char16_t utftext16[], int utf16Units) override {
UErrorCode status = U_ZERO_ERROR;
ICUUText text(utext_openUChars(nullptr, reinterpret_cast<const UChar*>(&utftext16[0]), utf16Units, &status));
ICUUText text(sk_utext_openUChars(nullptr, reinterpret_cast<const UChar*>(&utftext16[0]),
utf16Units, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", u_errorName(status));
SkDEBUGF("Break error: %s", sk_u_errorName(status));
return false;
}
SkASSERT(text);
ubrk_setUText(fBreakIterator.get(), text.get(), &status);
sk_ubrk_setUText(fBreakIterator.get(), text.get(), &status);
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", u_errorName(status));
SkDEBUGF("Break error: %s", sk_u_errorName(status));
return false;
}
fLastResult = 0;
@ -220,9 +236,10 @@ class SkIcuBreakIteratorCache {
SkAutoMutexExclusive lock(fBreakCacheMutex);
cachedIterator = fBreakCache.find(type);
if (!cachedIterator) {
ICUBreakIterator newIterator(ubrk_open(convertType(type), uloc_getDefault(), nullptr, 0, &status));
ICUBreakIterator newIterator(sk_ubrk_open(convertType(type), sk_uloc_getDefault(),
nullptr, 0, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", u_errorName(status));
SkDEBUGF("Break error: %s", sk_u_errorName(status));
} else {
cachedIterator = fBreakCache.set(type, std::move(newIterator));
}
@ -230,9 +247,9 @@ class SkIcuBreakIteratorCache {
}
ICUBreakIterator iterator;
if (cachedIterator) {
iterator.reset(SkUbrkClone<const UBreakIterator*>()(cachedIterator->get(), &status));
iterator.reset(sk_ubrk_clone(cachedIterator->get(), &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", u_errorName(status));
SkDEBUGF("Break error: %s", sk_u_errorName(status));
}
}
return iterator;
@ -243,7 +260,7 @@ class SkScriptIterator_icu : public SkScriptIterator {
public:
bool getScript(SkUnichar u, ScriptID* script) override {
UErrorCode status = U_ZERO_ERROR;
UScriptCode scriptCode = uscript_getScript(u, &status);
UScriptCode scriptCode = sk_uscript_getScript(u, &status);
if (U_FAILURE (status)) {
return false;
}
@ -273,18 +290,19 @@ class SkUnicode_icu : public SkUnicode {
// Create bidi iterator
UErrorCode status = U_ZERO_ERROR;
SkUnicodeBidi bidi(ubidi_openSized(utf16Units, 0, &status));
SkUnicodeBidi bidi(sk_ubidi_openSized(utf16Units, 0, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Bidi error: %s", u_errorName(status));
SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
return false;
}
SkASSERT(bidi);
uint8_t bidiLevel = (dir == TextDirection::kLTR) ? UBIDI_LTR : UBIDI_RTL;
// The required lifetime of utf16 isn't well documented.
// It appears it isn't used after ubidi_setPara except through ubidi_getText.
ubidi_setPara(bidi.get(), (const UChar*)utf16.get(), utf16Units, bidiLevel, nullptr, &status);
sk_ubidi_setPara(bidi.get(), (const UChar*)utf16.get(), utf16Units, bidiLevel, nullptr,
&status);
if (U_FAILURE(status)) {
SkDEBUGF("Bidi error: %s", u_errorName(status));
SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
return false;
}
@ -295,9 +313,9 @@ class SkUnicode_icu : public SkUnicode {
Position pos8 = 0;
Position pos16 = 0;
Position end16 = ubidi_getLength(bidi.get());
Position end16 = sk_ubidi_getLength(bidi.get());
while (pos16 < end16) {
auto level = ubidi_getLevelAt(bidi.get(), pos16);
auto level = sk_ubidi_getLevelAt(bidi.get(), pos16);
if (pos16 == 0) {
currentLevel = level;
} else if (level != currentLevel) {
@ -322,28 +340,28 @@ class SkUnicode_icu : public SkUnicode {
ICUBreakIterator iterator = SkIcuBreakIteratorCache::get().makeBreakIterator(BreakType::kWords);
if (!iterator) {
SkDEBUGF("Break error: %s", u_errorName(status));
SkDEBUGF("Break error: %s", sk_u_errorName(status));
return false;
}
SkASSERT(iterator);
ICUUText utf16UText(utext_openUChars(nullptr, (UChar*)utf16, utf16Units, &status));
ICUUText utf16UText(sk_utext_openUChars(nullptr, (UChar*)utf16, utf16Units, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", u_errorName(status));
SkDEBUGF("Break error: %s", sk_u_errorName(status));
return false;
}
ubrk_setUText(iterator.get(), utf16UText.get(), &status);
sk_ubrk_setUText(iterator.get(), utf16UText.get(), &status);
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", u_errorName(status));
SkDEBUGF("Break error: %s", sk_u_errorName(status));
return false;
}
// Get the words
int32_t pos = ubrk_first(iterator.get());
int32_t pos = sk_ubrk_first(iterator.get());
while (pos != UBRK_DONE) {
words->emplace_back(pos);
pos = ubrk_next(iterator.get());
pos = sk_ubrk_next(iterator.get());
}
return true;
@ -353,10 +371,10 @@ class SkUnicode_icu : public SkUnicode {
(const char utf8[], int utf8Units, BreakType type, std::function<void(int, int)> setBreak) {
UErrorCode status = U_ZERO_ERROR;
ICUUText text(utext_openUTF8(nullptr, &utf8[0], utf8Units, &status));
ICUUText text(sk_utext_openUTF8(nullptr, &utf8[0], utf8Units, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", u_errorName(status));
SkDEBUGF("Break error: %s", sk_u_errorName(status));
return false;
}
SkASSERT(text);
@ -366,20 +384,20 @@ class SkUnicode_icu : public SkUnicode {
return false;
}
ubrk_setUText(iterator.get(), text.get(), &status);
sk_ubrk_setUText(iterator.get(), text.get(), &status);
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", u_errorName(status));
SkDEBUGF("Break error: %s", sk_u_errorName(status));
return false;
}
auto iter = iterator.get();
int32_t pos = ubrk_first(iter);
int32_t pos = sk_ubrk_first(iter);
while (pos != UBRK_DONE) {
auto status = type == SkUnicode::BreakType::kLines
? UBRK_LINE_SOFT
: ubrk_getRuleStatus(iter);
: sk_ubrk_getRuleStatus(iter);
setBreak(pos, status);
pos = ubrk_next(iter);
pos = sk_ubrk_next(iter);
}
if (type == SkUnicode::BreakType::kLines) {
@ -437,15 +455,16 @@ public:
std::unique_ptr<SkBreakIterator> makeBreakIterator(const char locale[],
BreakType breakType) override {
UErrorCode status = U_ZERO_ERROR;
ICUBreakIterator iterator(ubrk_open(convertType(breakType), locale, nullptr, 0, &status));
ICUBreakIterator iterator(sk_ubrk_open(convertType(breakType), locale, nullptr, 0,
&status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", u_errorName(status));
SkDEBUGF("Break error: %s", sk_u_errorName(status));
return nullptr;
}
return std::unique_ptr<SkBreakIterator>(new SkBreakIterator_icu(std::move(iterator)));
}
std::unique_ptr<SkBreakIterator> makeBreakIterator(BreakType breakType) override {
return makeBreakIterator(uloc_getDefault(), breakType);
return makeBreakIterator(sk_uloc_getDefault(), breakType);
}
std::unique_ptr<SkScriptIterator> makeScriptIterator() override {
return SkScriptIterator_icu::makeScriptIterator();
@ -453,19 +472,19 @@ public:
// TODO: Use ICU data file to detect controls and whitespaces
bool isControl(SkUnichar utf8) override {
return u_iscntrl(utf8);
return sk_u_iscntrl(utf8);
}
bool isWhitespace(SkUnichar utf8) override {
return u_isWhitespace(utf8);
return sk_u_isWhitespace(utf8);
}
bool isSpace(SkUnichar utf8) override {
return u_isspace(utf8);
return sk_u_isspace(utf8);
}
static bool isHardLineBreak(SkUnichar utf8) {
auto property = u_getIntPropertyValue(utf8, UCHAR_LINE_BREAK);
auto property = sk_u_getIntPropertyValue(utf8, UCHAR_LINE_BREAK);
return property == U_LB_LINE_FEED || property == U_LB_MANDATORY_BREAK;
}
@ -520,7 +539,7 @@ public:
void reorderVisual(const BidiLevel runLevels[],
int levelsCount,
int32_t logicalFromVisual[]) override {
ubidi_reorderVisual(runLevels, levelsCount, logicalFromVisual);
sk_ubidi_reorderVisual(runLevels, levelsCount, logicalFromVisual);
}
};
@ -532,5 +551,8 @@ std::unique_ptr<SkUnicode> SkUnicode::Make() {
return nullptr;
}
#endif
return std::make_unique<SkUnicode_icu>();
return ICULib()
? std::make_unique<SkUnicode_icu>()
: nullptr;
}

View File

@ -0,0 +1,61 @@
/*
* Copyright 2021 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkUnicode_icu_DEFINED
#define SkUnicode_icu_DEFINED
#include <unicode/ubidi.h>
#include <unicode/ubrk.h>
#include <unicode/uscript.h>
#include <unicode/ustring.h>
#include <unicode/utext.h>
#include <unicode/utypes.h>
#include "include/private/SkTemplates.h"
#define SKICU_EMIT_FUNCS \
SKICU_FUNC(u_errorName) \
SKICU_FUNC(u_getIntPropertyValue) \
SKICU_FUNC(u_iscntrl) \
SKICU_FUNC(u_isspace) \
SKICU_FUNC(u_isWhitespace) \
SKICU_FUNC(ubidi_close) \
SKICU_FUNC(ubidi_getLength) \
SKICU_FUNC(ubidi_getLevelAt) \
SKICU_FUNC(ubidi_openSized) \
SKICU_FUNC(ubidi_reorderVisual) \
SKICU_FUNC(ubidi_setPara) \
SKICU_FUNC(ubrk_close) \
SKICU_FUNC(ubrk_current) \
SKICU_FUNC(ubrk_first) \
SKICU_FUNC(ubrk_following) \
SKICU_FUNC(ubrk_getRuleStatus) \
SKICU_FUNC(ubrk_next) \
SKICU_FUNC(ubrk_open) \
SKICU_FUNC(ubrk_preceding) \
SKICU_FUNC(ubrk_setText) \
SKICU_FUNC(ubrk_setUText) \
SKICU_FUNC(uloc_getDefault) \
SKICU_FUNC(uscript_getScript) \
SKICU_FUNC(utext_close) \
SKICU_FUNC(utext_openUChars) \
SKICU_FUNC(utext_openUTF8) \
#define SKICU_FUNC(funcname) decltype(funcname)* f_##funcname;
struct SkICULib {
SKICU_EMIT_FUNCS
// ubrk_clone added as draft in ICU69 and Android API 31 (first ICU NDK).
// ubrk_safeClone deprecated in ICU69 and not exposed by Android.
UBreakIterator* (*f_ubrk_clone_)(const UBreakIterator*, UErrorCode*);
UBreakIterator* (*f_ubrk_safeClone_)(const UBreakIterator*, void*, int32_t*, UErrorCode*);
};
#undef SKICU_FUNC
// Platform/config specific ICU factory.
std::unique_ptr<SkICULib> SkLoadICULib();
#endif // SkUnicode_icu_DEFINED

View File

@ -0,0 +1,27 @@
/*
* Copyright 2021 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "modules/skunicode/src/SkUnicode_icu.h"
#define SKICU_FUNC(funcname) funcname,
std::unique_ptr<SkICULib> SkLoadICULib() {
return std::make_unique<SkICULib>(SkICULib{
SKICU_EMIT_FUNCS
// ubrk_clone added as draft in ICU69 and Android API 31 (first ICU NDK).
// ubrk_safeClone deprecated in ICU69 and not exposed by Android.
#if U_ICU_VERSION_MAJOR_NUM >= 69
ubrk_clone,
nullptr,
#else
nullptr,
ubrk_safeClone,
#endif
});
}

View File

@ -0,0 +1,84 @@
/*
* Copyright 2021 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "include/core/SkString.h"
#include "include/core/SkTypes.h"
#include "modules/skunicode/src/SkUnicode_icu.h"
#include <dlfcn.h>
#define SK_RUNTIME_ICU_PATHS "libicuuc.so"
std::unique_ptr<SkICULib> SkLoadICULib() {
static constexpr char const* gLibPaths[] = { SK_RUNTIME_ICU_PATHS };
void* dlhnd = nullptr;
for (const auto path : gLibPaths) {
dlhnd = dlopen(path, RTLD_LAZY);
if (dlhnd) {
break;
}
}
if (!dlhnd) {
SkDEBUGF("ICU loader: failed to open libicuuc.\n");
return nullptr;
}
int icu_ver = -1;
bool resolved_required_syms = true;
auto resolve_sym = [&](void* hnd, const char name[], bool required = false) -> void* {
static constexpr int kMinVer = 44,
kMaxVer = 100;
// First call performs a search to determine the actual lib version.
// Subsequent calls are pinned to the version found.
const auto search_to = icu_ver > 0 ? icu_ver : kMaxVer;
icu_ver = icu_ver > 0 ? icu_ver : kMinVer;
for (;;) {
const auto sym = SkStringPrintf("%s_%d", name, icu_ver);
if (auto* addr = dlsym(dlhnd, sym.c_str())) {
return addr;
}
if (icu_ver == search_to) {
break;
}
icu_ver++;
}
if (required) {
resolved_required_syms = false;
}
return nullptr;
};
SkICULib lib {};
// When using dlsym
// *(void**)(&procPtr) = dlsym(self, "proc");
// is non-standard, but safe for POSIX. Cannot write
// *reinterpret_cast<void**>(&procPtr) = dlsym(self, "proc");
// because clang has not implemented DR573. See http://clang.llvm.org/cxx_dr_status.html .
#define SKICU_FUNC(fname) *(void**)(&lib.f_##fname) = resolve_sym(dlhnd, #fname, true);
SKICU_EMIT_FUNCS
*(void**)(&lib.f_ubrk_clone_) = resolve_sym(dlhnd, "ubrk_clone");
*(void**)(&lib.f_ubrk_safeClone_) = resolve_sym(dlhnd, "ubrk_safeClone");
if (!resolved_required_syms || (!lib.f_ubrk_clone_ && !lib.f_ubrk_safeClone_)) {
SkDEBUGF("ICU loader: failed to resolve required symbols.");
dlclose(dlhnd);
return nullptr;
}
return std::make_unique<SkICULib>(lib);
}

View File

@ -940,13 +940,21 @@ SKOTTIE_TOOL_SRCS = [
## SkShaper
################################################################################
# Stubs, pending SkUnicode fission
SKUNICODE_ICU_BUILTIN_SRCS = []
SKUNICODE_ICU_RUNTIME_SRCS = []
SKSHAPER_HARFBUZZ_SRCS = [
"modules/skshaper/include/SkShaper.h",
"modules/skshaper/src/SkShaper.cpp",
"modules/skshaper/src/SkShaper_harfbuzz.cpp",
"modules/skshaper/src/SkShaper_primitive.cpp",
"modules/skshaper/src/SkUnicode.h",
"modules/skshaper/src/SkUnicode_icu.cpp",
# TODO: move over to SkUnicode source sets
"modules/skunicode/include/SkUnicode.h",
"modules/skunicode/src/SkUnicode_icu.cpp",
"modules/skunicode/src/SkUnicode_icu.h",
"modules/skunicode/src/SkUnicode_icu_builtin.cpp",
]
SKSHAPER_PRIMITIVE_SRCS = [

View File

@ -60,6 +60,18 @@ if (skia_use_system_icu) {
}
}
third_party("headers") {
public_include_dirs = [
"../externals/icu/source/common",
"../externals/icu/source/i18n",
".",
]
public_defines = [
"U_USING_ICU_NAMESPACE=0",
"U_DISABLE_RENAMING",
]
}
third_party("icu") {
public_include_dirs = [
"../externals/icu/source/common",