Revert "Experimental ICU runtime linking"

This reverts commit f4aab0584d.

Reason for revert: build failures

Original change's description:
> 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>

TBR=djsollen@google.com,bungeman@google.com,fmalita@chromium.org,fmalita@google.com,jlavrova@google.com,skcq-be@skia-corp.google.com.iam.gserviceaccount.com

Change-Id: Ic252af1d7ba0a72b3c596e61f86746c27a0685b7
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/433276
Reviewed-by: Florin Malita <fmalita@google.com>
Commit-Queue: Florin Malita <fmalita@google.com>
This commit is contained in:
Florin Malita 2021-07-27 12:13:15 +00:00 committed by SkCQ
parent 84cc1f6acf
commit 6cce9615a0
22 changed files with 102 additions and 368 deletions

View File

@ -24,7 +24,6 @@ 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/skunicode/include/SkUnicode.h"
#include "modules/skshaper/src/SkUnicode.h"
namespace skia {
namespace text {

View File

@ -2,6 +2,7 @@
#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,8 +212,7 @@ 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/libskunicode.a \
$BUILD_DIR/libharfbuzz.a \
SHAPER_LIB="$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,7 +27,6 @@ if (skia_enable_skparagraph && skia_enable_skshaper && skia_use_icu &&
deps = [
"../..:skia",
"../skshaper",
"../skunicode",
]
}

View File

@ -19,6 +19,7 @@
#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/skunicode/include/SkUnicode.h"
#include "modules/skshaper/src/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/skunicode/include/SkUnicode.h"
#include "modules/skshaper/src/SkUnicode.h"
#include <memory>
#include <string>

View File

@ -2,6 +2,7 @@
#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,6 +18,7 @@ if (skia_enable_skshaper) {
}
if (skia_use_icu && skia_use_harfbuzz) {
defines += [ "SK_SHAPER_HARFBUZZ_AVAILABLE" ]
defines += [ "SK_UNICODE_AVAILABLE" ]
}
}
@ -26,7 +27,10 @@ if (skia_enable_skshaper) {
public_configs = [ ":public_config" ]
public = skia_shaper_public
deps = [ "../..:skia" ]
defines = [ "SKSHAPER_IMPLEMENTATION=1" ]
defines = [
"SKSHAPER_IMPLEMENTATION=1",
"SKUNICODE_IMPLEMENTATION=1",
]
sources = skia_shaper_primitive_sources
if (skia_use_fonthost_mac) {
sources += skia_shaper_coretext_sources
@ -42,10 +46,11 @@ 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,6 +13,10 @@ 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/skunicode/include/SkUnicode.h"
#include "modules/skshaper/src/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/skunicode/include/SkUnicode.h"
#include "modules/skshaper/src/SkUnicode.h"
#include "src/core/SkLRUCache.h"
#include "src/core/SkTDPQueue.h"
#include "src/utils/SkUTF.h"

View File

@ -10,9 +10,14 @@
#include "include/private/SkTFitsIn.h"
#include "include/private/SkTHash.h"
#include "include/private/SkTemplates.h"
#include "modules/skunicode/include/SkUnicode.h"
#include "modules/skunicode/src/SkUnicode_icu.h"
#include "modules/skshaper/src/SkUnicode.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>
@ -20,46 +25,26 @@
#include "SkLoadICU.h"
#endif
static const SkICULib* ICULib() {
static const auto gICU = SkLoadICULib();
// 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);
}
};
return gICU.get();
}
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>>;
// 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);
@ -80,23 +65,23 @@ class SkBidiIterator_icu : public SkBidiIterator {
SkUnicodeBidi fBidi;
public:
explicit SkBidiIterator_icu(SkUnicodeBidi bidi) : fBidi(std::move(bidi)) {}
Position getLength() override { return sk_ubidi_getLength(fBidi.get()); }
Level getLevelAt(Position pos) override { return sk_ubidi_getLevelAt(fBidi.get(), pos); }
Position getLength() override { return ubidi_getLength(fBidi.get()); }
Level getLevelAt(Position pos) override { return 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(sk_ubidi_openSized(utf16Units, 0, &status));
SkUnicodeBidi bidi(ubidi_openSized(utf16Units, 0, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
SkDEBUGF("Bidi error: %s", 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.
sk_ubidi_setPara(bidi.get(), (const UChar*)utf16, utf16Units, bidiLevel, nullptr, &status);
ubidi_setPara(bidi.get(), (const UChar*)utf16, utf16Units, bidiLevel, nullptr, &status);
if (U_FAILURE(status)) {
SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
SkDEBUGF("Bidi error: %s", u_errorName(status));
return nullptr;
}
return std::unique_ptr<SkBidiIterator>(new SkBidiIterator_icu(std::move(bidi)));
@ -160,7 +145,7 @@ public:
void SkBidiIterator::ReorderVisual(const Level runLevels[], int levelsCount,
int32_t logicalFromVisual[]) {
sk_ubidi_reorderVisual(runLevels, levelsCount, logicalFromVisual);
ubidi_reorderVisual(runLevels, levelsCount, logicalFromVisual);
}
class SkBreakIterator_icu : public SkBreakIterator {
@ -170,30 +155,30 @@ class SkBreakIterator_icu : public SkBreakIterator {
explicit SkBreakIterator_icu(ICUBreakIterator iter)
: fBreakIterator(std::move(iter)), fLastResult(0) {}
Position first() override
{ return fLastResult = sk_ubrk_first(fBreakIterator.get()); }
{ return fLastResult = ubrk_first(fBreakIterator.get()); }
Position current() override
{ return fLastResult = sk_ubrk_current(fBreakIterator.get()); }
{ return fLastResult = ubrk_current(fBreakIterator.get()); }
Position next() override
{ return fLastResult = sk_ubrk_next(fBreakIterator.get()); }
{ return fLastResult = ubrk_next(fBreakIterator.get()); }
Position preceding(Position offset) override
{ return fLastResult = sk_ubrk_preceding(fBreakIterator.get(), offset); }
{ return fLastResult = ubrk_preceding(fBreakIterator.get(), offset); }
Position following(Position offset) override
{ return fLastResult = sk_ubrk_following(fBreakIterator.get(), offset);}
Status status() override { return sk_ubrk_getRuleStatus(fBreakIterator.get()); }
{ return fLastResult = ubrk_following(fBreakIterator.get(), offset);}
Status status() override { return 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(sk_utext_openUTF8(nullptr, &utftext8[0], utf8Units, &status));
ICUUText text(utext_openUTF8(nullptr, &utftext8[0], utf8Units, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", sk_u_errorName(status));
SkDEBUGF("Break error: %s", u_errorName(status));
return false;
}
SkASSERT(text);
sk_ubrk_setUText(fBreakIterator.get(), text.get(), &status);
ubrk_setUText(fBreakIterator.get(), text.get(), &status);
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", sk_u_errorName(status));
SkDEBUGF("Break error: %s", u_errorName(status));
return false;
}
fLastResult = 0;
@ -201,17 +186,16 @@ class SkBreakIterator_icu : public SkBreakIterator {
}
bool setText(const char16_t utftext16[], int utf16Units) override {
UErrorCode status = U_ZERO_ERROR;
ICUUText text(sk_utext_openUChars(nullptr, reinterpret_cast<const UChar*>(&utftext16[0]),
utf16Units, &status));
ICUUText text(utext_openUChars(nullptr, reinterpret_cast<const UChar*>(&utftext16[0]), utf16Units, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", sk_u_errorName(status));
SkDEBUGF("Break error: %s", u_errorName(status));
return false;
}
SkASSERT(text);
sk_ubrk_setUText(fBreakIterator.get(), text.get(), &status);
ubrk_setUText(fBreakIterator.get(), text.get(), &status);
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", sk_u_errorName(status));
SkDEBUGF("Break error: %s", u_errorName(status));
return false;
}
fLastResult = 0;
@ -236,10 +220,9 @@ class SkIcuBreakIteratorCache {
SkAutoMutexExclusive lock(fBreakCacheMutex);
cachedIterator = fBreakCache.find(type);
if (!cachedIterator) {
ICUBreakIterator newIterator(sk_ubrk_open(convertType(type), sk_uloc_getDefault(),
nullptr, 0, &status));
ICUBreakIterator newIterator(ubrk_open(convertType(type), uloc_getDefault(), nullptr, 0, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", sk_u_errorName(status));
SkDEBUGF("Break error: %s", u_errorName(status));
} else {
cachedIterator = fBreakCache.set(type, std::move(newIterator));
}
@ -247,9 +230,9 @@ class SkIcuBreakIteratorCache {
}
ICUBreakIterator iterator;
if (cachedIterator) {
iterator.reset(sk_ubrk_clone(cachedIterator->get(), &status));
iterator.reset(SkUbrkClone<const UBreakIterator*>()(cachedIterator->get(), &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", sk_u_errorName(status));
SkDEBUGF("Break error: %s", u_errorName(status));
}
}
return iterator;
@ -260,7 +243,7 @@ class SkScriptIterator_icu : public SkScriptIterator {
public:
bool getScript(SkUnichar u, ScriptID* script) override {
UErrorCode status = U_ZERO_ERROR;
UScriptCode scriptCode = sk_uscript_getScript(u, &status);
UScriptCode scriptCode = uscript_getScript(u, &status);
if (U_FAILURE (status)) {
return false;
}
@ -290,19 +273,18 @@ class SkUnicode_icu : public SkUnicode {
// Create bidi iterator
UErrorCode status = U_ZERO_ERROR;
SkUnicodeBidi bidi(sk_ubidi_openSized(utf16Units, 0, &status));
SkUnicodeBidi bidi(ubidi_openSized(utf16Units, 0, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
SkDEBUGF("Bidi error: %s", 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.
sk_ubidi_setPara(bidi.get(), (const UChar*)utf16.get(), utf16Units, bidiLevel, nullptr,
&status);
ubidi_setPara(bidi.get(), (const UChar*)utf16.get(), utf16Units, bidiLevel, nullptr, &status);
if (U_FAILURE(status)) {
SkDEBUGF("Bidi error: %s", sk_u_errorName(status));
SkDEBUGF("Bidi error: %s", u_errorName(status));
return false;
}
@ -313,9 +295,9 @@ class SkUnicode_icu : public SkUnicode {
Position pos8 = 0;
Position pos16 = 0;
Position end16 = sk_ubidi_getLength(bidi.get());
Position end16 = ubidi_getLength(bidi.get());
while (pos16 < end16) {
auto level = sk_ubidi_getLevelAt(bidi.get(), pos16);
auto level = ubidi_getLevelAt(bidi.get(), pos16);
if (pos16 == 0) {
currentLevel = level;
} else if (level != currentLevel) {
@ -340,28 +322,28 @@ class SkUnicode_icu : public SkUnicode {
ICUBreakIterator iterator = SkIcuBreakIteratorCache::get().makeBreakIterator(BreakType::kWords);
if (!iterator) {
SkDEBUGF("Break error: %s", sk_u_errorName(status));
SkDEBUGF("Break error: %s", u_errorName(status));
return false;
}
SkASSERT(iterator);
ICUUText utf16UText(sk_utext_openUChars(nullptr, (UChar*)utf16, utf16Units, &status));
ICUUText utf16UText(utext_openUChars(nullptr, (UChar*)utf16, utf16Units, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", sk_u_errorName(status));
SkDEBUGF("Break error: %s", u_errorName(status));
return false;
}
sk_ubrk_setUText(iterator.get(), utf16UText.get(), &status);
ubrk_setUText(iterator.get(), utf16UText.get(), &status);
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", sk_u_errorName(status));
SkDEBUGF("Break error: %s", u_errorName(status));
return false;
}
// Get the words
int32_t pos = sk_ubrk_first(iterator.get());
int32_t pos = ubrk_first(iterator.get());
while (pos != UBRK_DONE) {
words->emplace_back(pos);
pos = sk_ubrk_next(iterator.get());
pos = ubrk_next(iterator.get());
}
return true;
@ -371,10 +353,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(sk_utext_openUTF8(nullptr, &utf8[0], utf8Units, &status));
ICUUText text(utext_openUTF8(nullptr, &utf8[0], utf8Units, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", sk_u_errorName(status));
SkDEBUGF("Break error: %s", u_errorName(status));
return false;
}
SkASSERT(text);
@ -384,20 +366,20 @@ class SkUnicode_icu : public SkUnicode {
return false;
}
sk_ubrk_setUText(iterator.get(), text.get(), &status);
ubrk_setUText(iterator.get(), text.get(), &status);
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", sk_u_errorName(status));
SkDEBUGF("Break error: %s", u_errorName(status));
return false;
}
auto iter = iterator.get();
int32_t pos = sk_ubrk_first(iter);
int32_t pos = ubrk_first(iter);
while (pos != UBRK_DONE) {
auto status = type == SkUnicode::BreakType::kLines
? UBRK_LINE_SOFT
: sk_ubrk_getRuleStatus(iter);
: ubrk_getRuleStatus(iter);
setBreak(pos, status);
pos = sk_ubrk_next(iter);
pos = ubrk_next(iter);
}
if (type == SkUnicode::BreakType::kLines) {
@ -455,16 +437,15 @@ public:
std::unique_ptr<SkBreakIterator> makeBreakIterator(const char locale[],
BreakType breakType) override {
UErrorCode status = U_ZERO_ERROR;
ICUBreakIterator iterator(sk_ubrk_open(convertType(breakType), locale, nullptr, 0,
&status));
ICUBreakIterator iterator(ubrk_open(convertType(breakType), locale, nullptr, 0, &status));
if (U_FAILURE(status)) {
SkDEBUGF("Break error: %s", sk_u_errorName(status));
SkDEBUGF("Break error: %s", 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(sk_uloc_getDefault(), breakType);
return makeBreakIterator(uloc_getDefault(), breakType);
}
std::unique_ptr<SkScriptIterator> makeScriptIterator() override {
return SkScriptIterator_icu::makeScriptIterator();
@ -472,19 +453,19 @@ public:
// TODO: Use ICU data file to detect controls and whitespaces
bool isControl(SkUnichar utf8) override {
return sk_u_iscntrl(utf8);
return u_iscntrl(utf8);
}
bool isWhitespace(SkUnichar utf8) override {
return sk_u_isWhitespace(utf8);
return u_isWhitespace(utf8);
}
bool isSpace(SkUnichar utf8) override {
return sk_u_isspace(utf8);
return u_isspace(utf8);
}
static bool isHardLineBreak(SkUnichar utf8) {
auto property = sk_u_getIntPropertyValue(utf8, UCHAR_LINE_BREAK);
auto property = u_getIntPropertyValue(utf8, UCHAR_LINE_BREAK);
return property == U_LB_LINE_FEED || property == U_LB_MANDATORY_BREAK;
}
@ -539,7 +520,7 @@ public:
void reorderVisual(const BidiLevel runLevels[],
int levelsCount,
int32_t logicalFromVisual[]) override {
sk_ubidi_reorderVisual(runLevels, levelsCount, logicalFromVisual);
ubidi_reorderVisual(runLevels, levelsCount, logicalFromVisual);
}
};
@ -551,8 +532,5 @@ std::unique_ptr<SkUnicode> SkUnicode::Make() {
return nullptr;
}
#endif
return ICULib()
? std::make_unique<SkUnicode_icu>()
: nullptr;
return std::make_unique<SkUnicode_icu>();
}

View File

@ -1,43 +0,0 @@
# 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

@ -1,18 +0,0 @@
# 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

@ -1,61 +0,0 @@
/*
* 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

@ -1,27 +0,0 @@
/*
* 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

@ -1,84 +0,0 @@
/*
* 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,21 +940,13 @@ 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",
# 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",
"modules/skshaper/src/SkUnicode.h",
"modules/skshaper/src/SkUnicode_icu.cpp",
]
SKSHAPER_PRIMITIVE_SRCS = [

View File

@ -60,18 +60,6 @@ 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",