已合并
fix icu load error #2319
fix icu load error #2319
已合并
Amber创建于 6月3日
4 个文件变更+95-5
Mm133/modules/skunicode/BUILD.gn+3-0
@@ -86,6 +86,9 @@ if (skia_use_icu || skia_use_client_icu || skia_use_libgrapheme ||
86 if (!skia_use_system_icu) {86 if (!skia_use_system_icu) {
87 defines += [ "U_DISABLE_RENAMING=1" ]87 defines += [ "U_DISABLE_RENAMING=1" ]
88 }88 }
89 if (is_ohos) {
90 defines += [ "SK_BUILD_FOR_OHOS" ]
91 }
89 92 
90 sources = skia_unicode_icu_bidi_sources93 sources = skia_unicode_icu_bidi_sources
91 sources += skia_unicode_bidi_full_sources94 sources += skia_unicode_bidi_full_sources
Mm133/modules/skunicode/src/SkUnicode_icu.cpp+5-3
@@ -42,8 +42,9 @@
42#ifdef ENABLE_TEXT_ENHANCE42#ifdef ENABLE_TEXT_ENHANCE
43#include <unordered_set>43#include <unordered_set>
44#endif44#endif
45#if defined(SK_USING_THIRD_PARTY_ICU) && defined(SK_BUILD_FOR_WIN)45#if (defined(SK_USING_THIRD_PARTY_ICU) && defined(SK_BUILD_FOR_WIN)) || \
46#include "SkLoadICU.h"46 defined(SK_BUILD_FOR_OHOS)
47#include "third_party/icu/SkLoadICU.h"
47#include "include/private/base/SkOnce.h"48#include "include/private/base/SkOnce.h"
48#endif49#endif
49 50 
@@ -919,7 +920,8 @@ namespace SkUnicodes::ICU {
919sk_sp<SkUnicode> Make() {920sk_sp<SkUnicode> Make() {
920 // We haven't yet created a way to encode the ICU data for assembly on Windows,921 // We haven't yet created a way to encode the ICU data for assembly on Windows,
921 // so we use a helper library to load icudtl.dat from the harddrive.922 // so we use a helper library to load icudtl.dat from the harddrive.
922#if defined(SK_USING_THIRD_PARTY_ICU) && defined(SK_BUILD_FOR_WIN)923#if (defined(SK_USING_THIRD_PARTY_ICU) && defined(SK_BUILD_FOR_WIN)) || \
924 defined(SK_BUILD_FOR_OHOS)
923 if (!SkLoadICU()) {925 if (!SkLoadICU()) {
924 static SkOnce once;926 static SkOnce once;
925 once([] { SkDEBUGF("SkLoadICU() failed!\n"); });927 once([] { SkDEBUGF("SkLoadICU() failed!\n"); });
Mm133/third_party/icu/SkLoadICU.cpp+84-0
@@ -119,3 +119,87 @@ bool SkLoadICU() {
119}119}
120 120 
121#endif // defined(_WIN32) && defined(SK_USING_THIRD_PARTY_ICU)121#endif // defined(_WIN32) && defined(SK_USING_THIRD_PARTY_ICU)
122 
123#if defined(SK_BUILD_FOR_OHOS)
124 
125#include <fcntl.h>
126#include <sys/mman.h>
127#include <sys/stat.h>
128#include <unistd.h>
129 
130#include <cstdio>
131#include <cstring>
132#include <mutex>
133#include <string>
134 
135#include "unicode/udata.h"
136 
137static const char* kICUDataPaths[] = {
138 "/usr/icu/icudt74l.dat",
139 "/system/usr/icu/icudt74l.dat",
140};
141 
142static void* posix_mmap(const char* dataFile) {
143 if (!dataFile) {
144 return nullptr;
145 }
146 int fd = open(dataFile, O_RDONLY);
147 if (fd < 0) {
148 fprintf(stderr, "SkIcuLoader: datafile missing: %s.\n", dataFile);
149 return nullptr;
150 }
151 struct stat st;
152 if (fstat(fd, &st) < 0) {
153 fprintf(stderr, "SkIcuLoader: datafile stat error.\n");
154 close(fd);
155 return nullptr;
156 }
157 void* addr = mmap(nullptr, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
158 close(fd);
159 if (addr == MAP_FAILED) {
160 fprintf(stderr, "SkIcuLoader: datafile mmap error.\n");
161 return nullptr;
162 }
163 return addr;
164}
165 
166static bool init_icu(void* addr) {
167 UErrorCode err = U_ZERO_ERROR;
168 udata_setCommonData(addr, &err);
169 if (err != U_ZERO_ERROR && err != U_USING_DEFAULT_WARNING) {
170 fprintf(stderr, "udata_setCommonData() returned %d.\n", (int)err);
171 return false;
172 }
173 err = U_ZERO_ERROR;
174 udata_setFileAccess(UDATA_ONLY_PACKAGES, &err);
175 if (err != U_ZERO_ERROR) {
176 fprintf(stderr, "udata_setFileAccess() returned %d.\n", (int)err);
177 return false;
178 }
179 return true;
180}
181 
182static bool load_from(const char* path) {
183 if (void* addr = posix_mmap(path)) {
wyykak
wyykakwyykak6月3日

这个文件map了之后就不会卸载了?符合预期吗

likedislike
184 if (init_icu(addr)) {
185 return true;
186 }
187 }
188 return false;
189}
190 
191bool SkLoadICU() {
192 static bool good = false;
193 static std::once_flag flag;
194 std::call_once(flag, []() {
195 for (auto path : kICUDataPaths) {
196 if (load_from(path)) {
197 good = true;
198 return;
199 }
200 }
201 });
202 return good;
203}
204 
205#endif // defined(SK_BUILD_FOR_OHOS)
Mm133/third_party/icu/SkLoadICU.h+3-2
@@ -7,10 +7,11 @@
7#ifndef load_icu_DEFINED7#ifndef load_icu_DEFINED
8#define load_icu_DEFINED8#define load_icu_DEFINED
9 9 
10#if defined(_WIN32) && defined(SK_USING_THIRD_PARTY_ICU)10#if (defined(_WIN32) && defined(SK_USING_THIRD_PARTY_ICU)) || \
11 defined(SK_BUILD_FOR_OHOS)
11bool SkLoadICU();12bool SkLoadICU();
12#else13#else
13static inline bool SkLoadICU() { return true; }14static inline bool SkLoadICU() { return true; }
14#endif // defined(_WIN32) && defined(SK_USING_THIRD_PARTY_ICU)15#endif
15 16 
16#endif // load_icu_DEFINED17#endif // load_icu_DEFINED