浏览代码

Merge pull request #8 from fzhangtj/skia

add engine txt
/siyaoH-1.17-PlatformMessage
GitHub 4 年前
当前提交
b5843c49
共有 5 个文件被更改,包括 339 次插入19 次删除
  1. 179
      engine/Build.bee.cs
  2. 19
      engine/README.md
  3. 59
      engine/src/render_api_d3d11.cc
  4. 99
      engine/src/TestLoadICU.cpp
  5. 2
      engine/src/TestLoadICU.h

179
engine/Build.bee.cs


using Bee.VisualStudioSolution;
using static Bee.NativeProgramSupport.NativeProgramConfiguration;
using Bee.NativeProgramSupport;
using Bee.Tools;
using NiceIO;
using System.Collections.Generic;
skiaRoot = Environment.GetEnvironmentVariable("SKIA_ROOT");
if (string.IsNullOrEmpty(skiaRoot))
{
skiaRoot = Environment.GetEnvironmentVariable("USERPROFILE") + "/skia_repo/skia";
}
flutterRoot = Environment.GetEnvironmentVariable("FLUTTER_ROOT");
if (string.IsNullOrEmpty(flutterRoot))
{
flutterRoot = Environment.GetEnvironmentVariable("USERPROFILE") + "/engine/src";
}
var libUIWidgets = SetupLibUIWidgets();
var builder = new VisualStudioNativeProjectFileBuilder(libUIWidgets);

sln.Projects.Add(builder.DeployTo("libUIWidgets.gen.vcxproj"));
Backend.Current.AddAliasDependency("ProjectFiles", sln.Setup());
}
private static string skiaRoot;
private static string flutterRoot;
static NativeProgram SetupLibUIWidgets()
{

"src/render_api.cc",
"src/render_api.h",
"src/render_api_d3d11.cc",
"src/TestLoadICU.cpp", // load icu temp solution
//"src/render_api_vulkan.cc",
//"src/render_api_opengles.cc",
},

SetupFml(np);
SetupSkia(np);
SetupTxt(np);
var toolchain = ToolChain.Store.Windows().VS2019().Sdk_17134().x64();

builtNP.DeployTo("../Samples/UIWidgetsSamples_2019_4/Assets/Plugins/x86_64");
}
//CopyTool.Instance().Setup(new NPath("../Samples/UIWidgetsSamples_2019_4/Assets/Plugins/x86_64").Combine("icudtl.dat"), new NPath("").Combine(skiaRoot, "third_party/externals/icu/common/icudtl.dat"));
//
// var npAndroid = new NativeProgram("libUIWidgets")
// {

static void SetupFml(NativeProgram np)
{
var flutterRoot = Environment.GetEnvironmentVariable("FLUTTER_ROOT");
if (string.IsNullOrEmpty(flutterRoot))
{
flutterRoot = Environment.GetEnvironmentVariable("USERPROFILE") + "/engine/src";
}
np.Defines.Add(new[]
{
// gn desc out\host_debug_unopt\ //flutter/fml:fml_lib defines

static void SetupSkia(NativeProgram np)
{
var skiaRoot = Environment.GetEnvironmentVariable("SKIA_ROOT");
if (string.IsNullOrEmpty(skiaRoot))
{
skiaRoot = Environment.GetEnvironmentVariable("USERPROFILE") + "/skia_repo/skia";
}
np.Defines.Add(new[]
{
// bin\gn desc out\Debug\ //:skia defines

new StaticLibrary(basePath + "/skottie.lib"),
new StaticLibrary(basePath + "/sksg.lib"),
new StaticLibrary(basePath + "/skshaper.lib"),
new StaticLibrary(basePath + "/icu.lib"),
new StaticLibrary(basePath + "/harfbuzz.lib"),
new StaticLibrary(basePath + "/libEGL.dll.lib"),
new StaticLibrary(basePath + "/libGLESv2.dll.lib"),
// new SystemLibrary("Opengl32.lib"),

new DeployableFile(basePath + "/libGLESv2.dll.pdb")
);
}
static void SetupTxtDependency(NativeProgram np)
{
np.Defines.Add(new[] { "SK_USING_THIRD_PARTY_ICU", "U_USING_ICU_NAMESPACE=0", "U_DISABLE_RENAMING",
"U_ENABLE_DYLOAD=0", "USE_CHROMIUM_ICU=1", "U_STATIC_IMPLEMENTATION",
"ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_STATIC"
});
np.IncludeDirectories.Add(flutterRoot + "/flutter/third_party/txt/src");
np.IncludeDirectories.Add(skiaRoot + "/third_party/externals/harfbuzz/src");
np.IncludeDirectories.Add(skiaRoot + "/third_party/externals/icu/source/common");
}
static void SetupTxt(NativeProgram np)
{
// gn desc .\out\host_debug_unopt\ //flutter/third_party/txt:txt
IEnumerable<NPath> sources = new List<NPath> {
"src/log/log.cc",
"src/log/log.h",
"src/minikin/CmapCoverage.cpp",
"src/minikin/CmapCoverage.h",
"src/minikin/Emoji.cpp",
"src/minikin/Emoji.h",
"src/minikin/FontCollection.cpp",
"src/minikin/FontCollection.h",
"src/minikin/FontFamily.cpp",
"src/minikin/FontFamily.h",
"src/minikin/FontLanguage.cpp",
"src/minikin/FontLanguage.h",
"src/minikin/FontLanguageListCache.cpp",
"src/minikin/FontLanguageListCache.h",
"src/minikin/FontUtils.cpp",
"src/minikin/FontUtils.h",
"src/minikin/GraphemeBreak.cpp",
"src/minikin/GraphemeBreak.h",
"src/minikin/HbFontCache.cpp",
"src/minikin/HbFontCache.h",
"src/minikin/Hyphenator.cpp",
"src/minikin/Hyphenator.h",
"src/minikin/Layout.cpp",
"src/minikin/Layout.h",
"src/minikin/LayoutUtils.cpp",
"src/minikin/LayoutUtils.h",
"src/minikin/LineBreaker.cpp",
"src/minikin/LineBreaker.h",
"src/minikin/Measurement.cpp",
"src/minikin/Measurement.h",
"src/minikin/MinikinFont.cpp",
"src/minikin/MinikinFont.h",
"src/minikin/MinikinInternal.cpp",
"src/minikin/MinikinInternal.h",
"src/minikin/SparseBitSet.cpp",
"src/minikin/SparseBitSet.h",
"src/minikin/WordBreaker.cpp",
"src/minikin/WordBreaker.h",
"src/txt/asset_font_manager.cc",
"src/txt/asset_font_manager.h",
"src/txt/font_asset_provider.cc",
"src/txt/font_asset_provider.h",
"src/txt/font_collection.cc",
"src/txt/font_collection.h",
"src/txt/font_features.cc",
"src/txt/font_features.h",
"src/txt/font_skia.cc",
"src/txt/font_skia.h",
"src/txt/font_style.h",
"src/txt/font_weight.h",
"src/txt/line_metrics.h",
"src/txt/paint_record.cc",
"src/txt/paint_record.h",
"src/txt/paragraph.h",
"src/txt/paragraph_builder.cc",
"src/txt/paragraph_builder.h",
"src/txt/paragraph_builder_txt.cc",
"src/txt/paragraph_builder_txt.h",
"src/txt/paragraph_style.cc",
"src/txt/paragraph_style.h",
"src/txt/paragraph_txt.cc",
"src/txt/paragraph_txt.h",
"src/txt/placeholder_run.cc",
"src/txt/placeholder_run.h",
"src/txt/platform.h",
"src/txt/run_metrics.h",
"src/txt/styled_runs.cc",
"src/txt/styled_runs.h",
"src/txt/test_font_manager.cc",
"src/txt/test_font_manager.h",
"src/txt/text_baseline.h",
"src/txt/text_decoration.cc",
"src/txt/text_decoration.h",
"src/txt/text_shadow.cc",
"src/txt/text_shadow.h",
"src/txt/text_style.cc",
"src/txt/text_style.h",
"src/txt/typeface_font_asset_provider.cc",
"src/txt/typeface_font_asset_provider.h",
"src/utils/JenkinsHash.cpp",
"src/utils/JenkinsHash.h",
"src/utils/LinuxUtils.h",
"src/utils/LruCache.h",
"src/utils/MacUtils.h",
"src/utils/TypeHelpers.h",
"src/utils/WindowsUtils.h",
};
var txtLib = new NativeProgram("txt_lib")
{
IncludeDirectories = {
"third_party",
flutterRoot,
skiaRoot,
},
};
SetupTxtDependency(txtLib);
var ignoreWarnigs = new string[] { "4091", "4722", "4312", "4838", "4172", "4005", "4311", "4477"}; // todo comparing the list with engine
txtLib.CompilerSettings().Add(s => s.WithWarningPolicies(ignoreWarnigs.Select((code) => new WarningAndPolicy(code, WarningPolicy.Silent)).ToArray())) ;
txtLib.Defines.Add(c => c.CodeGen == CodeGen.Debug,
new[] { "_ITERATOR_DEBUG_LEVEL=2", "_HAS_ITERATOR_DEBUGGING=1", "_SECURE_SCL=1" });
txtLib.Defines.Add(c => IsWindows(c),
new[] { "UCHAR_TYPE=wchar_t" });
txtLib.Defines.Add(c => !IsWindows(c),
new[] { "UCHAR_TYPE=uint16_t" });
txtLib.Defines.Add(c => c.CodeGen == CodeGen.Release,
new[] { "UIWidgets_RELEASE=1" });
var txtPath = new NPath(flutterRoot + "/flutter/third_party/txt");
sources = sources.Select(p => txtPath.Combine(p));
txtLib.Sources.Add(sources);
txtLib.Sources.Add(c => IsWindows(c), txtPath.Combine(new NPath("src/txt/platform_windows.cc")));
txtLib.NonLumpableFiles.Add(sources);
np.Libraries.Add(txtLib);
SetupTxtDependency(np);
}
// static void SetupSkiaAndroid(NativeProgram np)
// {

19
engine/README.md


ninja -C .\out\host_debug_unopt\ flutter/fml:fml_lib
```
### Build flutter txt
...
### Create symbolic
```
cd <uiwidigets_dir>\engine
cd third_party \\ create the directory if not exists
mklink /D skia <SKIA_ROOT>
```
Flutter engine txt include skia header in this pattern 'third_party/skia/*', so without symbolic, the txt lib will include skia
header file in flutter engine, instead of headers in skia repo.
```
```
## Set ICU Data Enviroment Varaible
```
set UIWIDGETS_ICUDATA=<SKIA_ROOT>/out/Debug/icudtl.dat
```
Unity Editor need to run with those environment variables set.

59
engine/src/render_api_d3d11.cc


#include <cassert>
#include <cassert>
#include "platform_base.h"
#include "render_api.h"

#include "Unity/IUnityGraphicsD3D11.h"
#include "flutter/fml/message_loop.h"
#include "flutter/third_party/txt/src/txt/paragraph.h"
#include "flutter/third_party/txt/src/txt/paragraph_builder.h"
#include "flutter/third_party/txt/src/txt/font_collection.h"
#include "flutter/fml/synchronization/waitable_event.h"
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"

#include "modules/skottie/include/Skottie.h"
#include "src/gpu/gl/GrGLDefines.h"
#include "third_party/dart/runtime/include/dart_tools_api.h"
#include "third_party/icu/SkLoadICU.h"
#include "TestLoadICU.h"
static std::shared_ptr<txt::FontCollection> _fontCollection;
void Dart_TimelineEvent(const char* label, int64_t timestamp0,
int64_t timestamp1_or_async_id,
Dart_Timeline_Event_Type type, intptr_t argument_count,

kRGBA_8888_SkColorType, kOpaque_SkAlphaType, nullptr);
}
std::shared_ptr<txt::FontCollection> GetTestFontCollection();
std::unique_ptr<txt::Paragraph> testParagraph;
void RenderAPI_D3D11::draw(SkCanvas* canvas) {
canvas->drawColor(SK_ColorWHITE);

SkPaint paint2;
auto text = SkTextBlob::MakeFromString("Hello, Skia!", SkFont(nullptr, 18));
canvas->drawTextBlob(text.get(), 50, 25, paint2);
if (testParagraph == NULL) {
TestLoadICU();
_fontCollection = GetTestFontCollection();
txt::ParagraphStyle style;
txt::FontCollection tf;
txt::TextStyle ts;
//style.
style.font_family = "Arial";
ts.font_size = 28;
ts.height = 4.0;
std::unique_ptr<txt::ParagraphBuilder> pb = txt::ParagraphBuilder::CreateTxtBuilder(style, _fontCollection);
ts.font_families.clear();
ts.font_families.push_back("Arial");
ts.color = SK_ColorBLACK;
pb->PushStyle(ts);
std::u16string s16 = u"Hello, some text.你好!";
pb->AddText(s16);
testParagraph = pb->Build();
testParagraph->Layout(500);
}
// canvas->drawColor(SK_ColorWHITE);
testParagraph->Paint(canvas, 10, 200);
}
void draw1(SkCanvas* canvas) {

double t = 0;
/* canvas->clear(SK_ColorWHITE);

animation_->seekFrameTime(t);
animation_->render(canvas);*/
SkRect rect = SkRect::MakeLTRB(100, 100, 200, 200);
canvas->drawImageRect(image_, rect, nullptr);
//SkRect rect = SkRect::MakeLTRB(100, 100, 200, 200);
//canvas->drawImageRect(image_, rect, nullptr);
// mutex_skia->ReleaseSync(0);
canvas->flush();

void RenderAPI_D3D11::PostDraw() {
// mutex_unity->ReleaseSync(0);
}
using namespace txt;
std::shared_ptr<txt::FontCollection> GetTestFontCollection() {
std::shared_ptr<txt::FontCollection> collection =
std::make_shared<txt::FontCollection>();
collection->SetupDefaultFontManager();
return collection;
}
#endif // #if SUPPORT_D3D11

99
engine/src/TestLoadICU.cpp


// Copyright 2019 Google LLC.
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
#include "TestLoadICU.h"
//#if defined(_WIN32) && defined(SK_USING_THIRD_PARTY_ICU)
#ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN
#endif
#include <windows.h>
#include <io.h>
#include <cstdio>
#include <cstring>
#include <mutex>
#include <string>
#include "unicode/udata.h"
static void* win_mmap(const char* dataFile) {
if (!dataFile) {
return nullptr;
}
struct FCloseWrapper { void operator()(FILE* f) { fclose(f); } };
std::unique_ptr<FILE, FCloseWrapper> stream(fopen(dataFile, "rb"));
if (stream == NULL) {
fprintf(stderr, "SkIcuLoader: datafile missing.\n");
return nullptr;
}
int fileno = _fileno(stream.get());
if (fileno < 0) {
fprintf(stderr, "SkIcuLoader: datafile fileno error.\n");
return nullptr;
}
HANDLE file = (HANDLE)_get_osfhandle(fileno);
if ((HANDLE)INVALID_HANDLE_VALUE == file) {
fprintf(stderr, "SkIcuLoader: datafile handle error.\n");
return nullptr;
}
struct CloseHandleWrapper { void operator()(HANDLE h) { CloseHandle(h); } };
std::unique_ptr<void, CloseHandleWrapper> mmapHandle(
CreateFileMapping(file, nullptr, PAGE_READONLY, 0, 0, nullptr));
if (!mmapHandle) {
fprintf(stderr, "SkIcuLoader: datafile mmap error.\n");
return nullptr;
}
void* addr = MapViewOfFile(mmapHandle.get(), FILE_MAP_READ, 0, 0, 0);
if (nullptr == addr) {
fprintf(stderr, "SkIcuLoader: datafile view error.\n");
return nullptr;
}
return addr;
}
static bool init_icu(void* addr) {
UErrorCode err = U_ZERO_ERROR;
udata_setCommonData(addr, &err);
if (err != U_ZERO_ERROR) {
fprintf(stderr, "udata_setCommonData() returned %d.\n", (int)err);
return false;
}
udata_setFileAccess(UDATA_ONLY_PACKAGES, &err);
if (err != U_ZERO_ERROR) {
fprintf(stderr, "udata_setFileAccess() returned %d.\n", (int)err);
return false;
}
return true;
}
static std::string executable_directory() {
HMODULE hModule = GetModuleHandleA(NULL);
char path[MAX_PATH];
GetModuleFileNameA(hModule, path, MAX_PATH);
const char* end = strrchr(path, '\\');
return end ? std::string(path, end - path) : std::string();
}
bool TestLoadICU()
{
static bool good = false;
static std::once_flag flag;
std::call_once(flag, []() {
const char *env_p = std::getenv("UIWIDGETS_ICUDATA");
if (env_p)
{
if (void *addr = win_mmap(env_p))
{
if (init_icu(addr))
{
good = true;
}
}
}
});
return good;
}

2
engine/src/TestLoadICU.h


bool TestLoadICU();
正在加载...
取消
保存