浏览代码

Merge pull request #107 from Unity-Technologies/zxw/dev_mac_update_engine

Zxw/dev mac update engine
/siyaoH-1.17-PlatformMessage
GitHub 4 年前
当前提交
0a07b871
共有 13 个文件被更改,包括 301 次插入130 次删除
  1. 103
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs
  2. 219
      engine/Build.bee.cs
  3. 84
      engine/README.md
  4. 2
      engine/src/flow/layers/opacity_layer.cc
  5. 2
      engine/src/lib/ui/compositing/scene_builder.cc
  6. 2
      engine/src/lib/ui/painting/gradient.h
  7. 2
      engine/src/lib/ui/text/paragraph.cc
  8. 2
      engine/src/lib/ui/window/window.cc
  9. 2
      engine/src/shell/common/canvas_spy.cc
  10. 2
      engine/src/shell/common/canvas_spy.h
  11. 6
      engine/src/shell/gpu/gpu_surface_gl.cc
  12. 2
      engine/src/shell/platform/embedder/embedder.cc
  13. 3
      engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.mm

103
com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanel.cs


}
}
enum UIWidgetsInputMode
{
Mouse,
Touch
}
public void OnDrag(PointerEventData eventData) {
var pos = _getPointerPosition(position: Input.mousePosition);
_wrapper.OnDrag(pos: pos, pointerId: eventData.pointerId);
}
public void OnPointerDown(PointerEventData eventData) {
var pos = _getPointerPosition(position: Input.mousePosition);
_wrapper.OnPointerDown(pos: pos, pointerId: eventData.pointerId);
}
public void OnPointerEnter(PointerEventData eventData) {
D.assert(eventData.pointerId < 0);
_isEntered = true;
_lastMousePosition = Input.mousePosition;
}
public void OnPointerExit(PointerEventData eventData) {
D.assert(eventData.pointerId < 0);
_isEntered = false;
_wrapper.OnPointerLeave();
}
UIWidgetsInputMode _inputMode;
public void OnPointerUp(PointerEventData eventData) {
var pos = _getPointerPosition(position: Input.mousePosition);
_wrapper.OnPointerUp(pos: pos, pointerId: eventData.pointerId);
void _convertPointerData(PointerEventData evt, out Vector2? position, out int pointerId) {
position = _inputMode == UIWidgetsInputMode.Mouse
? _getPointerPosition(Input.mousePosition)
: _getPointerPosition(evt);
pointerId = _inputMode == UIWidgetsInputMode.Mouse ? evt.pointerId : (-1 - evt.pointerId);
}
Vector2? _getPointerPosition(Vector2 position) {

}
return null;
}
Vector2? _getPointerPosition(PointerEventData eventData) {
//refer to: https://zhuanlan.zhihu.com/p/37127981
Camera eventCamera = null;
if (canvas.renderMode != RenderMode.ScreenSpaceOverlay) {
eventCamera = canvas.GetComponent<GraphicRaycaster>().eventCamera;
}
Vector2 localPoint;
RectTransformUtility.ScreenPointToLocalPointInRectangle(rectTransform, eventData.position,
eventCamera, out localPoint);
var scaleFactor = canvas.scaleFactor;
localPoint.x = (localPoint.x - rectTransform.rect.min.x) * scaleFactor;
localPoint.y = (rectTransform.rect.max.y - localPoint.y) * scaleFactor;
return localPoint;
_inputMode = Input.mousePresent ? UIWidgetsInputMode.Mouse : UIWidgetsInputMode.Touch;
}
void Input_OnDisable() {

if (Input.touchCount == 0 && Input.mousePresent) {
//we only process hover events for desktop applications
if (_inputMode == UIWidgetsInputMode.Mouse) {
if (_isEntered) {
if (!Input.GetMouseButton(0) && !Input.GetMouseButton(1) && !Input.GetMouseButton(2)) {
if (_lastMousePosition.x != Input.mousePosition.x ||

}
void _onMouseMove() {
var pos = _getPointerPosition(position: Input.mousePosition);
_wrapper.OnMouseMove(pos: pos);
if (_inputMode != UIWidgetsInputMode.Mouse) {
return;
}
var pos = _getPointerPosition(Input.mousePosition);
_wrapper.OnMouseMove(pos);
var pos = _getPointerPosition(position: Input.mousePosition);
_wrapper.OnMouseScroll(delta: Input.mouseScrollDelta, pos: pos);
if (_inputMode != UIWidgetsInputMode.Mouse) {
return;
}
var pos = _getPointerPosition(Input.mousePosition);
_wrapper.OnMouseScroll(Input.mouseScrollDelta, pos);
}
public void OnPointerEnter(PointerEventData eventData) {
if (_inputMode != UIWidgetsInputMode.Mouse) {
return;
}
D.assert(eventData.pointerId < 0);
_isEntered = true;
_lastMousePosition = Input.mousePosition;
}
public void OnPointerExit(PointerEventData eventData) {
if (_inputMode != UIWidgetsInputMode.Mouse) {
return;
}
D.assert(eventData.pointerId < 0);
_isEntered = false;
_wrapper.OnPointerLeave();
}
public void OnPointerDown(PointerEventData eventData) {
_convertPointerData(eventData, out var pos, out var pointerId);
_wrapper.OnPointerDown(pos, pointerId);
}
public void OnPointerUp(PointerEventData eventData) {
_convertPointerData(eventData, out var pos, out var pointerId);
_wrapper.OnPointerUp(pos, pointerId);
}
public void OnDrag(PointerEventData eventData) {
_convertPointerData(eventData, out var pos, out var pointerId);
_wrapper.OnDrag(pos, pointerId);
}
}
}

219
engine/Build.bee.cs


using Bee.Tools;
using NiceIO;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using RuntimeInformation = System.Runtime.InteropServices.RuntimeInformation;
using OSPlatform = System.Runtime.InteropServices.OSPlatform;
using Bee.Toolchain.GNU;
using Bee.Toolchain.IOS;
using System.Diagnostics;
class BuildUtils
enum UIWidgetsBuildTargetPlatform
public static bool IsHostWindows()
{
windows,
mac,
ios,
android
}
static class BuildUtils {
public static bool IsHostWindows() {
public static bool IsHostMac()
{
public static bool IsHostMac() {
/**
* How to add new target platform (taking iOS as the example)
* (1) add a new static void DeployIOS() {} in which we need call SetupLibUIWidgets() with UIWidgetsBuildTargetPlatform.ios as its
* first parameter. We should also generate the corresponding project file (i.e., XcodeProjectFile). Finally, we should call
* Backend.Current.AddAliasDependency("ios", dep) to add the alias "ios" to all the final output files for ios platform. By
* doing so, we can call "mono bee.exe ios" in command line to tell bee to process the specific subgraph for ios build only.
* (refer to the following session for the details on this: https://unity.slack.com/archives/C1RM0NBLY/p1615797377297800)
*
* (2) add the DeployIOS() function inside the available target platforms of MacOS in Main() since the dependencies on ios-platform
* , i.e., skia, flutter, etc. can only be built on Mac.
*
* (3) pick the corresponding toolchains for UIWidgetsBuildTargetPlatform.ios at the end of the function SetupLibUIWidgets() and setup
* the build targets.
*
* (4) change all the build settings (e.g., Defines, Includes, Source files) accordingly with platform-filters like IsMac, IsWindows,
* IsIosOrTvos inside bee for plaform-dependent settings.
*
* (5) finally, try call "mono bee.exe" with our predefined platform-dependent alias name "ios" in step (1), i.e., "mono bee.exe ios"
* to start the build
**/
static void Main()
//bee.exe win
static void DeployWindows()
{
var libUIWidgets = SetupLibUIWidgets(UIWidgetsBuildTargetPlatform.windows, out var dependencies);
var builder = new VisualStudioNativeProjectFileBuilder(libUIWidgets);
builder = libUIWidgets.SetupConfigurations.Aggregate(
builder,
(current, c) => current.AddProjectConfiguration(c));
var sln = new VisualStudioSolution();
sln.Path = "libUIWidgets.gen.sln";
var deployed = builder.DeployTo("libUIWidgets.gen.vcxproj");
sln.Projects.Add(deployed);
Backend.Current.AddAliasDependency("ProjectFiles", sln.Setup());
Backend.Current.AddAliasDependency("win", deployed.Path);
foreach(var dep in dependencies) {
Backend.Current.AddAliasDependency("win", dep);
}
}
//bee.exe mac
static void DeployMac()
skiaRoot = Environment.GetEnvironmentVariable("SKIA_ROOT");
if (string.IsNullOrEmpty(skiaRoot))
{
skiaRoot = Environment.GetEnvironmentVariable("USERPROFILE") + "/skia_repo/skia";
var libUIWidgets = SetupLibUIWidgets(UIWidgetsBuildTargetPlatform.mac, out var dependencies);
var nativePrograms = new List<NativeProgram>();
nativePrograms.Add(libUIWidgets);
var xcodeProject = new XCodeProjectFile(nativePrograms, new NPath("libUIWidgetsMac.xcodeproj/project.pbxproj"));
Backend.Current.AddAliasDependency("mac", new NPath("libUIWidgetsMac.xcodeproj/project.pbxproj"));
foreach(var dep in dependencies) {
Backend.Current.AddAliasDependency("mac", dep);
}
static void Main()
{
flutterRoot = Environment.GetEnvironmentVariable("FLUTTER_ROOT");
if (string.IsNullOrEmpty(flutterRoot))
{

var libUIWidgets = SetupLibUIWidgets();
skiaRoot = flutterRoot + "/third_party/skia";
//create ide projects
//available target platforms of Windows
//create vs project
var builder = new VisualStudioNativeProjectFileBuilder(libUIWidgets);
builder = libUIWidgets.SetupConfigurations.Aggregate(
builder,
(current, c) => current.AddProjectConfiguration(c));
var sln = new VisualStudioSolution();
sln.Path = "libUIWidgets.gen.sln";
sln.Projects.Add(builder.DeployTo("libUIWidgets.gen.vcxproj"));
Backend.Current.AddAliasDependency("ProjectFiles", sln.Setup());
DeployWindows();
//available target platforms of MacOS
//create xcode project
var nativePrograms = new List<NativeProgram>();
nativePrograms.Add(libUIWidgets);
var xcodeProject = new XCodeProjectFile(nativePrograms, new NPath("libUIWidgets.xcodeproj/project.pbxproj"));
DeployMac();
}
}

static NativeProgram SetupLibUIWidgets()
static NativeProgram SetupLibUIWidgets(UIWidgetsBuildTargetPlatform platform, out List<NPath> dependencies)
{
var np = new NativeProgram("libUIWidgets")
{

np.LinkerSettings().Add(c => IsWindows(c), l => l.WithCustomFlags_workaround(new[] { "/DEBUG:FULL" }));
SetupFml(np);
SetupRadidJson(np);
SetupSkia(np);
SetupTxt(np);
SetupDependency(np);
//SetupFml(np);
//SetupSkia(np);
//SetupTxt(np);
dependencies = new List<NPath>();
if (BuildUtils.IsHostWindows())
if (platform == UIWidgetsBuildTargetPlatform.windows)
{
var toolchain = ToolChain.Store.Windows().VS2019().Sdk_17134().x64();

var builtNP = np.SetupSpecificConfiguration(config, toolchain.DynamicLibraryFormat)
.DeployTo("build");
dependencies.Add(builtNP.Path);
else if (BuildUtils.IsHostMac())
else if (platform == UIWidgetsBuildTargetPlatform.mac)
{
var toolchain = ToolChain.Store.Host();
var validConfigurations = new List<NativeProgramConfiguration>();

validConfigurations.Add(config);
var builtNP = np.SetupSpecificConfiguration(config, toolchain.DynamicLibraryFormat).DeployTo("build");
builtNP.DeployTo("../Samples/UIWidgetsSamples_2019_4/Assets/Plugins/osx");
var buildProgram = np.SetupSpecificConfiguration(config, toolchain.DynamicLibraryFormat);
var buildNp = buildProgram.DeployTo("build");
var deployNp = buildProgram.DeployTo("../Samples/UIWidgetsSamples_2019_4/Assets/Plugins/osx");
dependencies.Add(buildNp.Path);
dependencies.Add(deployNp.Path);
}
np.ValidConfigurations = validConfigurations;

{
new StaticLibrary(fmlLibPath + "/obj/flutter/fml/libfml_lib.a"),
new SystemFramework("Foundation"),
};
});
}
static void SetupDependency(NativeProgram np)
{
SetupRadidJson(np);
np.Defines.Add(c => IsMac(c), new []
{
//lib flutter
"USE_OPENSSL=1",
"__STDC_CONSTANT_MACROS",
"__STDC_FORMAT_MACROS",
"_FORTIFY_SOURCE=2",
"_LIBCPP_DISABLE_AVAILABILITY=1",
"_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
"_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
"_DEBUG",
"FLUTTER_RUNTIME_MODE_DEBUG=1",
"FLUTTER_RUNTIME_MODE_PROFILE=2",
"FLUTTER_RUNTIME_MODE_RELEASE=3",
"FLUTTER_RUNTIME_MODE_JIT_RELEASE=4",
"FLUTTER_RUNTIME_MODE=1",
"FLUTTER_JIT_RUNTIME=1",
//lib skia
"SK_ENABLE_SPIRV_VALIDATION",
"SK_ASSUME_GL=1",
"SK_ENABLE_API_AVAILABLE",
"SK_GAMMA_APPLY_TO_A8",
"GR_OP_ALLOCATE_USE_NEW",
"SK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1",
"GR_TEST_UTILS=1",
"SKIA_IMPLEMENTATION=1",
"SK_GL",
"SK_ENABLE_DUMP_GPU",
"SK_SUPPORT_PDF",
"SK_CODEC_DECODES_JPEG",
"SK_ENCODE_JPEG",
"SK_ENABLE_ANDROID_UTILS",
"SK_USE_LIBGIFCODEC",
"SK_HAS_HEIF_LIBRARY",
"SK_CODEC_DECODES_PNG",
"SK_ENCODE_PNG",
"SK_CODEC_DECODES_RAW",
"SK_ENABLE_SKSL_INTERPRETER",
"SKVM_JIT_WHEN_POSSIBLE",
"SK_CODEC_DECODES_WEBP",
"SK_ENCODE_WEBP",
"SK_XML",
});
//lib txt
np.Defines.Add(c => IsMac(c), new[] {
"SK_USING_THIRD_PARTY_ICU", "U_USING_ICU_NAMESPACE=0",
"U_ENABLE_DYLOAD=0", "USE_CHROMIUM_ICU=1", "U_STATIC_IMPLEMENTATION",
"ICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_STATIC"
});
np.CompilerSettings().Add(c => IsMac(c), c => c.WithCustomFlags(new[] {
"-MD",
"-MF",
"-I.",
"-Ithird_party",
"-Isrc",
"-I"+ flutterRoot,
"-I"+ flutterRoot+"/third_party/rapidjson/include",
"-I"+ skiaRoot,
"-I"+ flutterRoot+"/flutter/third_party/txt/src",
"-I" + flutterRoot + "/third_party/harfbuzz/src",
"-I" + skiaRoot + "/third_party/externals/icu/source/common",
// "-Igen",
"-I"+ flutterRoot+"/third_party/icu/source/common",
"-I"+ flutterRoot+"/third_party/icu/source/i18n",
"-fvisibility-inlines-hidden",
}));
np.Libraries.Add(IsMac, c => {
return new PrecompiledLibrary[]
{
new StaticLibrary(flutterRoot+"/out/host_debug_unopt/obj/flutter/third_party/txt/libtxt_lib.a"),
new SystemFramework("Foundation"),
new SystemFramework("ApplicationServices"),
new SystemFramework("OpenGL"),
new SystemFramework("AppKit"),
new SystemFramework("CoreVideo"),
};
});
}

84
engine/README.md


## How to Build (Mac)
### Install Depot_tools
```
git clone 'https://chromium.googlesource.com/chromium/tools/depot_tools.git'
export PATH="${PWD}/depot_tools:${PATH}"
```
### Build Skia
```
git clone https://skia.googlesource.com/skia.git
git checkout chrome/m85
bin/gn gen out/Debug
python tools/git-sync-deps
ninja -C out/Debug -k 0
```
Please ensure that you are using python2 when executing "python tools/git-sync-deps".
### Build Flutter Engine
### Build Dependencies
Setting up the Engine development environment

```
cd $FLUTTER_ROOT/flutter
Apply changes to BUILD.gn (src/flutter/fml/BUILD.gn)
Apply following to end of `flutter/third_party/txt/BUILD.gn`
diff --git a/fml/BUILD.gn b/fml/BUILD.gn
index 9b5626e78..da1322ce5 100644
--- a/fml/BUILD.gn
+++ b/fml/BUILD.gn
@@ -295,3 +295,10 @@ executable("fml_benchmarks") {
"//flutter/runtime:libdart",
diff --git a/third_party/txt/BUILD.gn b/third_party/txt/BUILD.gn
index 56b73a020..d42e88045 100644
--- a/third_party/txt/BUILD.gn
+++ b/third_party/txt/BUILD.gn
@@ -141,6 +141,7 @@ source_set("txt") {
"//third_party/harfbuzz",
"//third_party/icu",
"//third_party/skia",
+ "//third_party/skia/modules/skottie",
deps = [
@@ -339,3 +340,10 @@ executable("txt_benchmarks") {
deps += [ "//third_party/skia/modules/skparagraph" ]
}
+static_library("fml_lib") {
+static_library("txt_lib") {
+ "//flutter/fml",
+ ":txt",
Comiple engine:
Compile engine:
cd engine/src
cd $FLUTTER_ROOT
ninja -C ./out/host_debug_unopt/ flutter/fml:fml_lib
If the compilation fails because "no available Mac SDK is found" (in flutter-1.17 the build tool will only try to find Mac 10.XX SDKs), please modify the file "/src/build/Mac/find_sdk.py" under flutter root by setting "sdks" as your current sdk, e.g., ['11.0'].
### Build Lib
add this line to the end of out/host_debug_unopt/args.gn:
```
icu_use_data_file=false
```
set SKIA_ROOT and FLUTTER_ROOT to your $PATH. SKIA_ROOT is the root folder of your skia repository. FLUTTER_ROOT is the root folder of your flutter engine repository.
finally run ninja:
```
ninja -C out/host_debug_unopt/ flutter/third_party/txt:txt_lib
```
If the compilation fails because "no available Mac SDK is found" (in flutter-1.17 the build tool will only try to find Mac 10.XX SDKs), please modify the file "/src/build/Mac/find_sdk.py" under flutter root by setting "sdks" as your current sdk, e.g., ['11.0'].
Create symbolic as follows. 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.
cmd
```
cd <uiwidigets_dir>\engine
cd third_party   \\ create the directory if not exists
ln -s <SKIA_ROOT> skia
```
mono bee.exe
mono bee.exe mac
```

2
engine/src/flow/layers/opacity_layer.cc


context->is_opaque = parent_is_opaque && (alpha_ == SK_AlphaOPAQUE);
context->mutators_stack.PushTransform(
SkMatrix::Translate(offset_.fX, offset_.fY));
SkMatrix::MakeTrans(offset_.fX, offset_.fY));
context->mutators_stack.PushOpacity(alpha_);
Layer::AutoPrerollSaveLayerState save =
Layer::AutoPrerollSaveLayerState::Create(context);

2
engine/src/lib/ui/compositing/scene_builder.cc


}
fml::RefPtr<EngineLayer> SceneBuilder::pushOffset(float dx, float dy) {
SkMatrix sk_matrix = SkMatrix::Translate(dx, dy);
SkMatrix sk_matrix = SkMatrix::MakeTrans(dx, dy);
auto layer = std::make_shared<TransformLayer>(sk_matrix);
PushLayer(layer);
return EngineLayer::MakeRetained(layer);

2
engine/src/lib/ui/painting/gradient.h


#pragma
#pragma once
#include "include/effects/SkGradientShader.h"
#include "lib/ui/painting/matrix.h"

2
engine/src/lib/ui/text/paragraph.cc


// text direction index.
int size = boxes.size() * 5;
Float32List result = {(float*)malloc(sizeof(float) * size),
boxes.size() * size};
(int)boxes.size() * size};
unsigned long position = 0;
for (unsigned long i = 0; i < boxes.size(); i++) {
const txt::Paragraph::TextBox& box = boxes[i];

2
engine/src/lib/ui/window/window.cc


Window_updateWindowMetricsCallback Window_updateWindowMetrics_;
typedef void (*Window_beginFrameCallback)(long microseconds);
typedef void (*Window_beginFrameCallback)(int64_t microseconds);
Window_beginFrameCallback Window_beginFrame_;
typedef void (*Window_drawFrameCallback)();

2
engine/src/shell/common/canvas_spy.cc


void DidDrawCanvas::didConcat(const SkMatrix& matrix) {}
void DidDrawCanvas::didConcat44(const SkM44&) {}
void DidDrawCanvas::didConcat44(const SkScalar[]) {}
void DidDrawCanvas::didScale(SkScalar, SkScalar) {}

2
engine/src/shell/common/canvas_spy.h


// |SkCanvasVirtualEnforcer<SkNoDrawCanvas>|
void didConcat(const SkMatrix&) override;
void didConcat44(const SkM44&) override;
void didConcat44(const SkScalar[]) override;
void didScale(SkScalar, SkScalar) override;
void didTranslate(SkScalar, SkScalar) override;

6
engine/src/shell/gpu/gpu_surface_gl.cc


{
TRACE_EVENT0("uiwidgets", "SkCanvas::Flush");
onscreen_surface_->getCanvas()->flush();
onscreen_surface_->getContext()->submit(true);
//submit this frame to gpu
auto flushInfo = GrFlushInfo();
flushInfo.fFlags = GrFlushFlags::kSyncCpu_GrFlushFlag;
onscreen_surface_->flush(SkSurface::BackendSurfaceAccess::kNoAccess, flushInfo);
}
if (!delegate_->GLContextPresent()) {

2
engine/src/shell/platform/embedder/embedder.cc


case PointerData::Change::kHover:
case PointerData::Change::kUp:
return 0;
default:
return 0;
}
return 0;
}

3
engine/src/shell/platform/unity/darwin/macos/uiwidgets_panel.mm


args.struct_size = sizeof(UIWidgetsProjectArgs);
args.assets_path = streaming_assets_path;
args.font_asset = settings;
//TODO: not support icu yet
//args.icu_mapper = GetICUStaticMapping;
args.command_line_argc = 0;
args.command_line_argv = nullptr;
args.platform_message_callback =

正在加载...
取消
保存