浏览代码

update build & platform

/siyaoH-1.17-PlatformMessage
siyao 4 年前
当前提交
88a3332c
共有 20 个文件被更改,包括 1320 次插入82 次删除
  1. 17
      Samples/UIWidgetsSamples_2019_4/Assets/CountDemo.cs
  2. 4
      Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/GalleryMain.cs
  3. 67
      com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanelWrapper.cs
  4. 347
      engine/Build.bee.cs
  5. 11
      engine/build.py
  6. 11
      engine/src/engine.cc
  7. 12
      engine/src/flow/raster_cache.cc
  8. 2
      engine/src/shell/platform/unity/uiwidgets_system.h
  9. 2
      engine/src/shell/platform/unity/android/cocoa_task_runner.cc
  10. 2
      engine/src/shell/platform/unity/android/uiwidgets_panel.h
  11. 508
      engine/src/shell/platform/unity/android/uiwidgets_panel.cc
  12. 343
      engine/src/shell/platform/unity/android/unity_surface_manager.cc
  13. 76
      engine/src/shell/platform/unity/android/unity_surface_manager.h
  14. 0
      /engine/src/shell/platform/unity/android/cocoa_task_runner.cc
  15. 0
      /engine/src/shell/platform/unity/android/cocoa_task_runner.h
  16. 0
      /engine/src/shell/platform/unity/android/uiwidgets_panel.h
  17. 0
      /engine/src/shell/platform/unity/android/uiwidgets_system.cc
  18. 0
      /engine/src/shell/platform/unity/android/uiwidgets_system.h

17
Samples/UIWidgetsSamples_2019_4/Assets/CountDemo.cs


using System.Collections.Generic;
using System.Runtime.InteropServices;
using Unity.UIWidgets.ui;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using Text = Unity.UIWidgets.widgets.Text;
using ui_ = Unity.UIWidgets.widgets.ui_;
using TextStyle = Unity.UIWidgets.painting.TextStyle;

{
protected void OnEnable()
{
Debug.Log("???? on enable");
#if !UNITY_EDITOR
var vv = TestFloat();
Debug.Log($"?? {vv}");
#endif
#if !UNITY_EDITOR
internal const string dllName = "libUIWidgets_d";
[DllImport(dllName)]
static extern float TestFloat();
#endif
Debug.Log("???? main");
ui_.runApp(new MyApp());
}

4
Samples/UIWidgetsSamples_2019_4/Assets/Editor/EditorWindowSample/GalleryMain.cs


#if UNITY_EDITOR
using UIWidgetsGallery.gallery;
using Unity.UIWidgets.Editor;
using UnityEditor;

ui_.runApp(new GalleryApp());
}
}
}
}
#endif

67
com.unity.uiwidgets/Runtime/engine2/UIWidgetsPanelWrapper.cs


#region Platform: Windows Specific Functionalities
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
public partial class UIWidgetsPanelWrapper {
RenderTexture _renderTexture;

#region Platform: MacOs Specific Functionalities
#if UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
#if (UNITY_EDITOR && UNITY_EDITOR_OSX) || UNITY_STANDALONE_OSX
public partial class UIWidgetsPanelWrapper {
Texture _renderTexture;

#endregion
#region Platform: Android Runtime Specific Functionalities
#if (!UNITY_EDITOR && UNITY_ANDROID )
public partial class UIWidgetsPanelWrapper {
RenderTexture _renderTexture;
public RenderTexture renderTexture {
get { return _renderTexture; }
}
void _createRenderTexture(int width, int height, float devicePixelRatio) {
D.assert(_renderTexture == null);
var desc = new RenderTextureDescriptor(
width, height, RenderTextureFormat.ARGB32, 0) {
useMipMap = false,
autoGenerateMips = false,
};
_renderTexture = new RenderTexture(desc) {hideFlags = HideFlags.HideAndDontSave};
_renderTexture.Create();
_width = width;
_height = height;
_devicePixelRatio = devicePixelRatio;
}
void _destroyRenderTexture() {
D.assert(_renderTexture != null);
ObjectUtils.SafeDestroy(_renderTexture);
_renderTexture = null;
}
void _enableUIWidgetsPanel(string font_settings) {
UIWidgetsPanel_onEnable(_ptr, _renderTexture.GetNativeTexturePtr(),
_width, _height, _devicePixelRatio, Application.streamingAssetsPath, font_settings);
}
void _resizeUIWidgetsPanel() {
UIWidgetsPanel_onRenderTexture(_ptr,
_renderTexture.GetNativeTexturePtr(),
_width, _height, _devicePixelRatio);
}
void _disableUIWidgetsPanel() {
_renderTexture = null;
}
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onEnable(IntPtr ptr,
IntPtr nativeTexturePtr, int width, int height, float dpi, string streamingAssetsPath,
string font_settings);
[DllImport(NativeBindings.dllName)]
static extern void UIWidgetsPanel_onRenderTexture(
IntPtr ptr, IntPtr nativeTexturePtr, int width, int height, float dpi);
}
#endif
#endregion
#region Window Common Properties and Functions

public void Initiate(IUIWidgetsWindow host, int width, int height, float dpr,
Dictionary<string, object> settings) {
D.assert(_renderTexture == null);
NativeConsole.OnEnable();
_recreateRenderTexture(width, height, dpr);
_handle = GCHandle.Alloc(this);

_enableUIWidgetsPanel(JSONMessageCodec.instance.toJson(settings));
NativeConsole.OnEnable();
}
public void _entryPoint() {

347
engine/Build.bee.cs


{
flutterRoot = Environment.GetEnvironmentVariable("USERPROFILE") + "/engine/src";
}
skiaRoot = flutterRoot + "/third_party/skia";
var buildAndroidEnv = Environment.GetEnvironmentVariable("BUILD_ANDROID");
buildAndroid = true;// buildAndroidEnv == "true";

}
else if (BuildUtils.IsHostMac())
{
if(buildAndroid){
if (buildAndroid)
{
}else {
}
else
{
//create xcode project
var nativePrograms = new List<NativeProgram>();
nativePrograms.Add(libUIWidgets);

{
Sources =
{
//"src/assets/test.cc",
//"src/assets/test.h",
"src/assets/asset_manager.cc",
"src/assets/asset_manager.h",
"src/assets/asset_resolver.h",

"src/lib/ui/painting/shader.h",
"src/lib/ui/painting/single_frame_codec.cc",
"src/lib/ui/painting/single_frame_codec.h",
"src/lib/ui/painting/skottie.cc",
"src/lib/ui/painting/skottie.h",
//"src/lib/ui/painting/skottie.cc",
//"src/lib/ui/painting/skottie.h",
"src/lib/ui/painting/vertices.cc",
"src/lib/ui/painting/vertices.h",

"src/shell/platform/unity/gfx_worker_task_runner.cc",
"src/shell/platform/unity/gfx_worker_task_runner.h",
"src/shell/platform/unity/uiwidgets_system.h",
"src/shell/platform/unity/unity_console.cc",
"src/shell/platform/unity/unity_console.h",

"src/shell/platform/unity/darwin/macos/unity_surface_manager.h",
};
var androidSource = new NPath[]
{
"src/shell/platform/unity/android/unity_surface_manager.cc",
"src/shell/platform/unity/android/uiwidgets_system.cc",
"src/shell/platform/unity/android/cocoa_task_runner.cc",
"src/shell/platform/unity/android/uiwidgets_panel.cc",
};
np.Sources.Add(c => {
np.Sources.Add(c =>
{
np.Sources.Add(c => IsAndroid(c), androidSource);
np.Libraries.Add(c => IsWindows(c), new BagOfObjectFilesLibrary(
new NPath[]{

np.CompilerSettings().Add(c => IsMac(c), c => c.WithCustomFlags(new []{"-Wno-c++11-narrowing"}));
np.CompilerSettings().Add(c => IsMac(c), c => c.WithCustomFlags(new[] { "-Wno-c++11-narrowing" }));
var FLUTTER_ROOT = flutterRoot;
var SKIA_ROOT = skiaRoot;
np.CompilerSettings().Add(c => IsAndroid(c), c => c.WithCustomFlags(new[] {
np.CompilerSettings().Add(c => IsAndroid(c), c => c.WithCustomFlags(new[] { "-stdlib=libc++" }));
np.CompilerSettings().Add(c => IsAndroid(c), c => c.WithCustomFlags(new[] { "-nostdlib" }));
np.CompilerSettings().Add(c => IsAndroid(c), c => c.WithCustomFlags(new[] { "-Wno-c++11-narrowing" }));
"-MD",
"-MF",
"-DUSE_OPENSSL=1",
"-DUSE_OPENSSL_CERTS=1",
"-DANDROID",
"-DHAVE_SYS_UIO_H",
"-D__STDC_CONSTANT_MACROS",
"-D__STDC_FORMAT_MACROS",
//"-D_FORTIFY_SOURCE=2",
"-D__compiler_offsetof=__builtin_offsetof",
"-Dnan=__builtin_nan",
"-D__GNU_SOURCE=1",
"-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS",
"-D_LIBCPP_ENABLE_THREAD_SAFETY_ANNOTATIONS",
"-D_DEBUG",
"-DU_USING_ICU_NAMESPACE=0",
"-DU_ENABLE_DYLOAD=0",
"-DUSE_CHROMIUM_ICU=1",
"-DU_STATIC_IMPLEMENTATION",
"-DICU_UTIL_DATA_IMPL=ICU_UTIL_DATA_FILE",
"-DUCHAR_TYPE=uint16_t",
"-DFLUTTER_RUNTIME_MODE_DEBUG=1",
"-DFLUTTER_RUNTIME_MODE_PROFILE=2",
"-DFLUTTER_RUNTIME_MODE_RELEASE=3",
"-DFLUTTER_RUNTIME_MODE_JIT_RELEASE=4",
"-DFLUTTER_RUNTIME_MODE=1",
"-DFLUTTER_JIT_RUNTIME=1",
// confige for rapidjson
//"-DUIWIDGETS_FORCE_ALIGNAS_8=\"1\"",
"-DRAPIDJSON_HAS_STDSTRING",
"-DRAPIDJSON_HAS_CXX11_RANGE_FOR",
"-DRAPIDJSON_HAS_CXX11_RVALUE_REFS",
"-DRAPIDJSON_HAS_CXX11_TYPETRAITS",
"-DRAPIDJSON_HAS_CXX11_NOEXCEPT",
"-DSK_ENABLE_SPIRV_VALIDATION",
"-DSK_GAMMA_APPLY_TO_A8",
"-DSK_GAMMA_EXPONENT=1.4",
"-DSK_GAMMA_CONTRAST=0.0",
"-DSK_ALLOW_STATIC_GLOBAL_INITIALIZERS=1",
"-DGR_TEST_UTILS=1",
"-DSKIA_IMPLEMENTATION=1",
"-DSK_GL",
"-DSK_ENABLE_DUMP_GPU",
"-DSK_SUPPORT_PDF",
"-DSK_CODEC_DECODES_JPEG",
"-DSK_ENCODE_JPEG",
"-DSK_ENABLE_ANDROID_UTILS",
"-DSK_USE_LIBGIFCODEC",
"-DSK_HAS_HEIF_LIBRARY",
"-DSK_CODEC_DECODES_PNG",
"-DSK_ENCODE_PNG",
"-DSK_CODEC_DECODES_RAW",
"-DSK_ENABLE_SKSL_INTERPRETER",
"-DSK_CODEC_DECODES_WEBP",
"-DSK_ENCODE_WEBP",
"-DSK_XML",
//"-DUIWIDGETS_ENGINE_VERSION=\"0.0\"",
//"-DSKIA_VERSION=\"0.0\"",
"-DXML_STATIC",
"-I.",
"-Ithird_party",
"-Isrc",
"-I"+FLUTTER_ROOT,
"-I"+FLUTTER_ROOT+"/third_party/rapidjson/include",
"-I"+SKIA_ROOT,
"-I"+SKIA_ROOT + "/include/third_party/vulkan",
"-I"+FLUTTER_ROOT+"/flutter/third_party/txt/src",
"-I" + FLUTTER_ROOT + "/third_party/harfbuzz/src",
"-I" + SKIA_ROOT + "/third_party/externals/icu/source/common",
// "-Igen",
"-I"+FLUTTER_ROOT+"/third_party/libcxx/include",
"-I"+FLUTTER_ROOT+"/third_party/libcxxabi/include",
"-I"+FLUTTER_ROOT+"/third_party/icu/source/common",
"-I"+FLUTTER_ROOT+"/third_party/icu/source/i18n",
// ignore deprecated code
"-Wno-deprecated-declarations",
"-fno-strict-aliasing",
"-march=armv7-a",
"-mfloat-abi=softfp",
"-mtune=generic-armv7-a",
"-mthumb",
"-fPIC",
"-pipe",
"-fcolor-diagnostics",
"-ffunction-sections",
"-funwind-tables",
"-fno-short-enums",
"-nostdinc++",
"--target=arm-linux-androideabi",
"-mfpu=neon",
"-Wall",
"-Wextra",
"-Wendif-labels",
"-Werror",
"-Wno-missing-field-initializers",
"-Wno-unused-parameter",
"-Wno-unused-variable",
"-Wno-unused-command-line-argument",
// "-Wno-non-c-typedef-for-linkage",
"-isystem"+FLUTTER_ROOT+"/third_party/android_tools/ndk/sources/android/support/include",
"-isystem"+FLUTTER_ROOT +
"/third_party/android_tools/ndk/sysroot/usr/include/arm-linux-androideabi",
//"-D__ANDROID_API__=16",
// "-fvisibility=hidden",
"--sysroot="+FLUTTER_ROOT+"/third_party/android_tools/ndk/sysroot",
"-Wstring-conversion",
// supress new line error
// "-Wnewline-eof",
"-O0",
"-g2",
"-fvisibility-inlines-hidden",
"-std=c++17",
"-fno-rtti",
"-fno-exceptions",
"-nostdlib"
}));
//np.CompilerSettings().Add(c => IsAndroid(c), c => c.WithCustomFlags(new[] { "-Wno-c++11-narrowing" }));
np.IncludeDirectories.Add("third_party");
np.IncludeDirectories.Add("src");

"-Wl,-z,now",
"-Wl,-z,relro",
"-Wl,-z,defs",
"--gcc-toolchain=/Users/siyao/temp/flutter/engine/src/third_party/android_tools/ndk/toolchains/x86_64-4.9/prebuilt/darwin-x86_64",
"--gcc-toolchain="+flutterRoot +
"/third_party/android_tools/ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64",
"-Wl,--no-undefined",
"-Wl,--exclude-libs,ALL",
"-fuse-ld=lld",

"-Wl,--warn-shared-textrel",
"-nostdlib",
"--sysroot=/Users/siyao/temp/flutter/engine/src/third_party/android_tools/ndk/platforms/android-16/arch-arm"
"--sysroot="+flutterRoot+"/third_party/android_tools/ndk/platforms/android-16/arch-arm",
"-L"+flutterRoot + "/third_party/android_tools/ndk/sources/cxx-stl/llvm-libc++/libs/armeabi-v7a",
"-Wl,--build-id=sha1",
"-Wl,-soname=libUIWidgets_d.so",
"-Wl,--whole-archive",
SetupFml(np);
SetupRadidJson(np);
//SetupFml(np);
//SetupRadidJson(np);
SetupTxt(np);
//SetupTxt(np);
var codegens = new[] { CodeGen.Debug };

//var codegens = new[] { CodeGen.Debug };
var androidToolchain = ToolChain.Store.Android().r19().Armv7();
//var androidToolchain = ToolChain.Store.Android().r16b().Armv7();
var validConfigurations = new List<NativeProgramConfiguration>();

return np;
}
static void SetupFml(NativeProgram np)
static void SetupFml(NativeProgram np)
{
np.Defines.Add(c => IsWindows(c), new[]

"FLUTTER_JIT_RUNTIME=1",
});
np.Defines.Add(c => IsMac(c), new []
np.Defines.Add(c => IsMac(c), new[]
{
"USE_OPENSSL=1",
"__STDC_CONSTANT_MACROS",

np.IncludeDirectories.Add(flutterRoot);
var fmlLibPath = flutterRoot + "/out/host_debug_unopt";
np.Libraries.Add(c => IsWindows(c), c => {
np.Libraries.Add(c => IsWindows(c), c =>
{
return new PrecompiledLibrary[]
{
new StaticLibrary(fmlLibPath + "/obj/flutter/fml/fml_lib.lib"),

np.Libraries.Add(c => IsMac(c), c => {
np.Libraries.Add(c => IsMac(c), c =>
{
return new PrecompiledLibrary[]
{
new StaticLibrary(fmlLibPath + "/obj/flutter/fml/libfml_lib.a"),

np.Libraries.Add(c => IsAndroid(c), c =>
{
var basePath = flutterRoot + "/out/android_debug_unopt";
//np.Libraries.Add(c => IsAndroid(c), c =>
//{
// var basePath = flutterRoot + "/out/android_debug_unopt";
return new PrecompiledLibrary[]
{
new StaticLibrary(basePath + "/obj/flutter/fml/libfml_lib.a"),
};
});
// return new PrecompiledLibrary[]
// {
// new StaticLibrary(basePath + "/obj/flutter/fml/libfml_lib.a"),
// };
//});
np.CompilerSettings().Add(c => IsAndroid(c), c => c.WithCustomFlags(new[] { "-std=c++14 -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables" }));
//np.CompilerSettings().Add(c => IsAndroid(c), c => c.WithCustomFlags(new[] { "-std=c++14 -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables" }));
}
static void SetupSkia(NativeProgram np)

"SK_XML"
});
np.Defines.Add(c => IsAndroid(c), new[]
{
// bin/gn desc out/arm //:skia defines
"SK_ENABLE_SPIRV_VALIDATION",
"SK_GAMMA_APPLY_TO_A8",
"SK_GAMMA_EXPONENT=1.4",
"SK_GAMMA_CONTRAST=0.0",
"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",
"SK_CODEC_DECODES_WEBP",
"SK_ENCODE_WEBP",
"SK_XML",
"XML_STATIC"
});
//np.Defines.Add(c => IsAndroid(c), new[]
//{
// // bin/gn desc out/arm //:skia defines
// "SK_ENABLE_SPIRV_VALIDATION",
// "SK_GAMMA_APPLY_TO_A8",
// "SK_GAMMA_EXPONENT=1.4",
// "SK_GAMMA_CONTRAST=0.0",
// "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",
// "SK_CODEC_DECODES_WEBP",
// "SK_ENCODE_WEBP",
// "SK_XML",
// "XML_STATIC"
//});
np.IncludeDirectories.Add(skiaRoot);
np.IncludeDirectories.Add(c => IsWindows(c), skiaRoot + "/third_party/externals/angle2/include");

np.CompilerSettings().Add(c => IsAndroid(c), c => c.WithCustomFlags(new[] { "-std=c++14" }));
np.Libraries.Add(IsWindows, c =>
{

};
});
np.Libraries.Add(IsMac, c => {
np.Libraries.Add(IsMac, c =>
{
var basePath = skiaRoot + "/out/Debug";
return new PrecompiledLibrary[]
{

};
});
np.Libraries.Add(IsAndroid, c => {
np.Libraries.Add(IsAndroid, c =>
{
new StaticLibrary(basePath + "/libskia.a"),
new StaticLibrary(basePath + "/libskottie.a"),
new StaticLibrary(basePath + "/libsksg.a"),
new StaticLibrary(basePath + "/libskshaper.a"),
// icudtl
new StaticLibrary("icudtl.o"),
// libcxx
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.algorithm.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.any.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.bind.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.charconv.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.chrono.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.condition_variable.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.condition_variable_destructor.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.debug.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.exception.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.functional.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.future.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.hash.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.ios.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.iostream.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.locale.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.memory.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.mutex.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.mutex_destructor.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.new.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.optional.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.random.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.regex.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.shared_mutex.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.stdexcept.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.string.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.strstream.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.system_error.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.thread.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.typeinfo.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.utility.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.valarray.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.variant.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxx/src/libcxx.vector.o"),
// libcxxabi
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.abort_message.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.cxa_aux_runtime.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.cxa_default_handlers.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.cxa_demangle.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.cxa_exception_storage.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.cxa_guard.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.cxa_handlers.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.cxa_noexception.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.cxa_unexpected.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.cxa_vector.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.cxa_virtual.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.fallback_malloc.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.private_typeinfo.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.stdlib_exception.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.stdlib_stdexcept.o"),
new StaticLibrary(flutterRoot+"/out/android_debug_unopt/obj/third_party/libcxxabi/src/libcxxabi.stdlib_typeinfo.o"),
new StaticLibrary(flutterRoot+"/third_party/android_tools/ndk/platforms/android-16/arch-arm/usr/lib/crtbegin_so.o"),
new StaticLibrary(flutterRoot+"/third_party/android_tools/ndk/platforms/android-16/arch-arm/usr/lib/crtend_so.o"),
new StaticLibrary( flutterRoot+"/out/android_debug_unopt/obj/flutter/third_party/txt/libtxt_lib.a"),
//new StaticLibrary(basePath + "/libskia.a"),
//new StaticLibrary(basePath + "/libskottie.a"),
//new StaticLibrary(basePath + "/libsksg.a"),
//new StaticLibrary(basePath + "/libskshaper.a"),
new SystemLibrary("android"),
new SystemLibrary("EGL"),

});
var basePath = skiaRoot + "/out/Debug";
np.SupportFiles.Add(c => IsWindows(c), new [] {
np.SupportFiles.Add(c => IsWindows(c), new[] {
new DeployableFile(basePath + "/libEGL.dll"),
new DeployableFile(basePath + "/libEGL.dll.pdb"),
new DeployableFile(basePath + "/libGLESv2.dll"),

"SK_ASSUME_GL_ES=1"
});
np.IncludeDirectories.Add(flutterRoot + "/flutter/third_party/txt/src");
np.IncludeDirectories.Add(skiaRoot + "/third_party/externals/harfbuzz/src");
np.IncludeDirectories.Add(flutterRoot + "/third_party/harfbuzz/src");
np.IncludeDirectories.Add(flutterRoot + "/third_party/icu/source/common");
np.IncludeDirectories.Add(flutterRoot + "/third_party/icu/source/i18n");
}
static void SetupTxt(NativeProgram np)

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.CompilerSettings().Add(c => IsMac(c), c => c.WithCppLanguageVersion(CppLanguageVersion.Cpp17));
txtLib.CompilerSettings().Add(c => IsMac(c), c => c.WithCustomFlags(new []{"-Wno-c++11-narrowing"}));
txtLib.CompilerSettings().Add(c => IsMac(c), c => c.WithCustomFlags(new[] { "-Wno-c++11-narrowing" }));
txtLib.CompilerSettings().Add(c => IsAndroid(c), c => c.WithCustomFlags(new[] { "-stdlib=libc++" }));
txtLib.CompilerSettings().Add(c => IsAndroid(c), c => c.WithCustomFlags(new[] { "-Wno-c++11-narrowing" }));
txtLib.Defines.Add(c => c.CodeGen == CodeGen.Debug,

11
engine/build.py


SKIA_ROOT = FLUTTER_ROOT+"/third_party/skia"
clang = FLUTTER_ROOT+"/buildtools/mac-x64/clang/bin/clang++"
clang = "artifacts/Stevedore/android-ndk-mac/toolchains/llvm/prebuilt/darwin-x86_64/bin/clang++"
# "src/shell/platform/unity/darwin/android/uiwidgets_system.cc",
"src/shell/platform/unity/android/unity_surface_manager.cc",
"src/shell/platform/unity/android/uiwidgets_system.cc",
"src/shell/platform/unity/android/cocoa_task_runner.cc",
"src/shell/platform/unity/android/uiwidgets_panel.cc",
"src/assets/asset_manager.cc",
"src/assets/asset_manager.h",
"src/assets/asset_resolver.h",

continue
FLUTTER_ROOT = FLUTTER_ROOT+""
clang = FLUTTER_ROOT + "/buildtools/mac-x64/clang/bin/clang++"
mkdirScript = ["mkdir", "-p", "obj/"+dir]
process = subprocess.Popen(
mkdirScript, stdout=subprocess.PIPE, stderr=subprocess.PIPE)

"-c",
dir+"/" + name + extention,
"-o",
"obj/"+dir+"/"+name+".o"
"obj/"+dir+"/"+name+".o",
]
objs.append("obj/"+dir+"/"+name+".o")
if linkOnly and (buildEngine == False):

11
engine/src/engine.cc


extern "C" void UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API UnityPluginUnload() {
uiwidgets::UIWidgetsSystem::GetInstancePtr()->UnBindUnityInterfaces();
}
extern "C" UNITY_INTERFACE_EXPORT UNITY_INTERFACE_API float TestFloat()
{
#if defined(__CYGWIN32__)
return 0.3f;
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(_WIN64) || defined(WINAPI_FAMILY)
return 0.2f;
#elif defined(__MACH__) || defined(__ANDROID__) || defined(__linux__) || defined(LUMIN)
return 0.1f;
#endif
}

12
engine/src/flow/raster_cache.cc


SkAutoCanvasRestore auto_restore(&canvas, true);
SkIRect bounds =
RasterCache::GetDeviceBounds(logical_rect_, canvas.getTotalMatrix());
auto a = bounds.size().width() - image_->dimensions().width();
if(a < 0){
a = -a;
}
auto b = bounds.size().height() - image_->dimensions().height();
if(b < 0){
b = -b;
}
std::abs(bounds.size().width() - image_->dimensions().width()) <= 1 &&
std::abs(bounds.size().height() - image_->dimensions().height()) <= 1);
a <= 1 &&
b <= 1);
canvas.resetMatrix();
canvas.drawImage(image_, bounds.fLeft, bounds.fTop, paint);
}

2
engine/src/shell/platform/unity/uiwidgets_system.h


#pragma once
#ifdef __ANDROID__
#include "shell/platform/unity/darwin/android/uiwidgets_system.h"
#include "shell/platform/unity/android/uiwidgets_system.h"
#elif __APPLE__
#include "shell/platform/unity/darwin/macos/uiwidgets_system.h"
#elif _WIN64

2
engine/src/shell/platform/unity/android/cocoa_task_runner.cc


CocoaTaskRunner::TaskTimePoint CocoaTaskRunner::TimePointFromUIWidgetsTime(
uint64_t uiwidgets_target_time_nanos) {
const auto fml_now = fml::TimePoint::Now().ToEpochDelta().ToNanoseconds();
if (uiwidgets_target_time_nanos <= fml_now) {
if (uiwidgets_target_time_nanos <= (uint64_t)fml_now) {
return {};
}
const auto uiwidgets_duration = uiwidgets_target_time_nanos - fml_now;

2
engine/src/shell/platform/unity/android/uiwidgets_panel.h


#include "unity_surface_manager.h"
#include "cocoa_task_runner.h"
#include "src/shell/platform/unity/unity_console.h"
namespace uiwidgets {
struct MouseState {

508
engine/src/shell/platform/unity/android/uiwidgets_panel.cc


#include "uiwidgets_panel.h"
// #include <Windows.h>
#include <flutter/fml/synchronization/waitable_event.h>
// #include <include\utils\SkBase64.h>
#include <fstream>
#include <iostream>
#include "lib/ui/window/viewport_metrics.h"
#include "runtime/mono_api.h"
#include "shell/common/switches.h"
#include "shell/platform/embedder/embedder_engine.h"
#include "uiwidgets_system.h"
// #include "unity_external_texture_gl.h"
namespace uiwidgets {
fml::RefPtr<UIWidgetsPanel> UIWidgetsPanel::Create(
Mono_Handle handle, EntrypointCallback entrypoint_callback) {
return fml::MakeRefCounted<UIWidgetsPanel>(handle, entrypoint_callback);
}
UIWidgetsPanel::UIWidgetsPanel(Mono_Handle handle,
EntrypointCallback entrypoint_callback)
: handle_(handle), entrypoint_callback_(entrypoint_callback) {}
UIWidgetsPanel::~UIWidgetsPanel() = default;
void UIWidgetsPanel::OnEnable(void* native_texture_ptr, size_t width,
size_t height, float device_pixel_ratio,
const char* streaming_assets_path,
const char* settings) {
UnityConsole::WriteLine("test ggg ++");
surface_manager_ = std::make_unique<UnitySurfaceManager>(
UIWidgetsSystem::GetInstancePtr()->GetUnityInterfaces());
FML_DCHECK(fbo_ == 0);
surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr);
surface_manager_->ClearCurrent();
// fml::AutoResetWaitableEvent latch;
// std::thread::id gfx_worker_thread_id;
// UIWidgetsSystem::GetInstancePtr()->PostTaskToGfxWorker(
// [&latch, &gfx_worker_thread_id]() -> void {
// gfx_worker_thread_id = std::this_thread::get_id();
// latch.Signal();
// });
// latch.Wait();
// gfx_worker_task_runner_ = std::make_unique<GfxWorkerTaskRunner>(
// gfx_worker_thread_id, [this](const auto* task) {
// if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) {
// std::cerr << "Could not post an gfx worker task." << std::endl;
// }
// });
// UIWidgetsTaskRunnerDescription render_task_runner = {};
// render_task_runner.struct_size = sizeof(UIWidgetsTaskRunnerDescription);
// render_task_runner.identifier = 1;
// render_task_runner.user_data = gfx_worker_task_runner_.get();
// render_task_runner.runs_task_on_current_thread_callback =
// [](void* user_data) -> bool {
// return static_cast<GfxWorkerTaskRunner*>(user_data)
// ->RunsTasksOnCurrentThread();
// };
// render_task_runner.post_task_callback = [](UIWidgetsTask task,
// uint64_t target_time_nanos,
// void* user_data) -> void {
// static_cast<GfxWorkerTaskRunner*>(user_data)->PostTask(task,
// target_time_nanos);
// };
// UIWidgetsRendererConfig config = {};
// config.type = kOpenGL;
// config.open_gl.struct_size = sizeof(config.open_gl);
// config.open_gl.clear_current = [](void* user_data) -> bool {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// return panel->surface_manager_->ClearCurrent();
// };
// config.open_gl.make_current = [](void* user_data) -> bool {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// return panel->surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
// };
// config.open_gl.make_resource_current = [](void* user_data) -> bool {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// return panel->surface_manager_->MakeResourceCurrent();
// };
// config.open_gl.fbo_callback = [](void* user_data) -> uint32_t {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// return panel->fbo_;
// };
// config.open_gl.present = [](void* user_data) -> bool { return true; };
// config.open_gl.gl_proc_resolver = [](void* user_data,
// const char* what) -> void* {
// return reinterpret_cast<void*>(eglGetProcAddress(what));
// };
// config.open_gl.fbo_reset_after_present = true;
// task_runner_ = std::make_unique<Win32TaskRunner>(
// GetCurrentThreadId(), [this](const auto* task) {
// if (UIWidgetsEngineRunTask(engine_, task) != kSuccess) {
// std::cerr << "Could not post an engine task." << std::endl;
// }
// });
// UIWidgetsTaskRunnerDescription ui_task_runner = {};
// ui_task_runner.struct_size = sizeof(UIWidgetsTaskRunnerDescription);
// ui_task_runner.identifier = 2;
// ui_task_runner.user_data = task_runner_.get();
// ui_task_runner.runs_task_on_current_thread_callback =
// [](void* user_data) -> bool {
// return static_cast<Win32TaskRunner*>(user_data)->RunsTasksOnCurrentThread();
// };
// ui_task_runner.post_task_callback = [](UIWidgetsTask task,
// uint64_t target_time_nanos,
// void* user_data) -> void {
// static_cast<Win32TaskRunner*>(user_data)->PostTask(task, target_time_nanos);
// };
// UIWidgetsCustomTaskRunners custom_task_runners = {};
// custom_task_runners.struct_size = sizeof(UIWidgetsCustomTaskRunners);
// custom_task_runners.platform_task_runner = &ui_task_runner;
// custom_task_runners.ui_task_runner = &ui_task_runner;
// custom_task_runners.render_task_runner = &render_task_runner;
// UIWidgetsProjectArgs args = {};
// args.struct_size = sizeof(UIWidgetsProjectArgs);
// args.assets_path = streaming_assets_path;
// args.font_asset = settings;
// // std::string icu_path = std::string(streaming_assets_path) + "/icudtl.dat";
// // args.icu_data_path = icu_path.c_str();
// args.icu_mapper = GetICUStaticMapping;
// // Used for IOS build
// // std::string icu_symbol_prefix = "_binary_icudtl_dat_start";
// // std::string native_lib_path =
// // "pathtodll/Plugins/x86_64/libUIWidgets_d.dll"; args.icu_mapper =
// // [icu_symbol_prefix, native_lib_path] {
// // return GetSymbolMapping(icu_symbol_prefix, native_lib_path);
// // };
// args.command_line_argc = 0;
// args.command_line_argv = nullptr;
// args.platform_message_callback =
// [](const UIWidgetsPlatformMessage* engine_message,
// void* user_data) -> void {};
// args.custom_task_runners = &custom_task_runners;
// args.task_observer_add = [](intptr_t key, void* callback,
// void* user_data) -> void {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// panel->task_runner_->AddTaskObserver(key,
// *static_cast<fml::closure*>(callback));
// };
// args.task_observer_remove = [](intptr_t key, void* user_data) -> void {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// panel->task_runner_->RemoveTaskObserver(key);
// };
// args.custom_mono_entrypoint = [](void* user_data) -> void {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// panel->MonoEntrypoint();
// };
// args.vsync_callback = [](void* user_data, intptr_t baton) -> void {
// auto* panel = static_cast<UIWidgetsPanel*>(user_data);
// panel->VSyncCallback(baton);
// };
// args.initial_window_metrics.width = width;
// args.initial_window_metrics.height = height;
// args.initial_window_metrics.pixel_ratio = device_pixel_ratio;
// UIWidgetsEngine engine = nullptr;
// auto result = UIWidgetsEngineInitialize(&config, &args, this, &engine);
// if (result != kSuccess || engine == nullptr) {
// std::cerr << "Failed to start UIWidgets engine: error " << result
// << std::endl;
// return;
// }
// engine_ = engine;
// UIWidgetsEngineRunInitialized(engine);
// UIWidgetsSystem::GetInstancePtr()->RegisterPanel(this);
// process_events_ = true;
}
void UIWidgetsPanel::MonoEntrypoint() { entrypoint_callback_(handle_); }
void UIWidgetsPanel::OnDisable() {
// drain pending messages
ProcessMessages();
// drain pending vsync batons
ProcessVSync();
process_events_ = false;
UIWidgetsSystem::GetInstancePtr()->UnregisterPanel(this);
if (engine_) {
UIWidgetsEngineShutdown(engine_);
engine_ = nullptr;
}
gfx_worker_task_runner_ = nullptr;
task_runner_ = nullptr;
// if (fbo_) {
// surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
// surface_manager_->DestroyRenderSurface();
// fbo_ = 0;
// surface_manager_->ClearCurrent();
// }
// surface_manager_ = nullptr;
}
void UIWidgetsPanel::OnRenderTexture(void* native_texture_ptr, size_t width,
size_t height, float device_pixel_ratio) {
// reinterpret_cast<EmbedderEngine*>(engine_)->PostRenderThreadTask(
// [this, native_texture_ptr]() -> void {
// surface_manager_->MakeCurrent(EGL_NO_DISPLAY);
// if (fbo_) {
// surface_manager_->DestroyRenderSurface();
// fbo_ = 0;
// }
// fbo_ = surface_manager_->CreateRenderSurface(native_texture_ptr);
// surface_manager_->ClearCurrent();
// });
// ViewportMetrics metrics;
// metrics.physical_width = static_cast<float>(width);
// metrics.physical_height = static_cast<float>(height);
// metrics.device_pixel_ratio = device_pixel_ratio;
// reinterpret_cast<EmbedderEngine*>(engine_)->SetViewportMetrics(metrics);
}
int UIWidgetsPanel::RegisterTexture(void* native_texture_ptr) {
int texture_identifier = 0;
// texture_identifier++;
// auto* engine = reinterpret_cast<EmbedderEngine*>(engine_);
// engine->GetShell().GetPlatformView()->RegisterTexture(
// std::make_unique<UnityExternalTextureGL>(
// texture_identifier, native_texture_ptr, surface_manager_.get()));
return texture_identifier;
}
void UIWidgetsPanel::UnregisterTexture(int texture_id) {
auto* engine = reinterpret_cast<EmbedderEngine*>(engine_);
engine->GetShell().GetPlatformView()->UnregisterTexture(texture_id);
}
std::chrono::nanoseconds UIWidgetsPanel::ProcessMessages() {
return std::chrono::nanoseconds(task_runner_->ProcessTasks().count());
}
void UIWidgetsPanel::ProcessVSync() {
std::vector<intptr_t> batons;
vsync_batons_.swap(batons);
for (intptr_t baton : batons) {
reinterpret_cast<EmbedderEngine*>(engine_)->OnVsyncEvent(
baton, fml::TimePoint::Now(),
fml::TimePoint::Now() +
fml::TimeDelta::FromNanoseconds(1000000000 / 60));
}
}
void UIWidgetsPanel::VSyncCallback(intptr_t baton) {
vsync_batons_.push_back(baton);
}
void UIWidgetsPanel::SetEventPhaseFromCursorButtonState(
UIWidgetsPointerEvent* event_data) {
MouseState state = GetMouseState();
event_data->phase = state.buttons == 0
? state.state_is_down ? UIWidgetsPointerPhase::kUp
: UIWidgetsPointerPhase::kHover
: state.state_is_down ? UIWidgetsPointerPhase::kMove
: UIWidgetsPointerPhase::kDown;
}
void UIWidgetsPanel::SendMouseMove(float x, float y) {
UIWidgetsPointerEvent event = {};
event.x = x;
event.y = y;
SetEventPhaseFromCursorButtonState(&event);
SendPointerEventWithData(event);
}
void UIWidgetsPanel::SendMouseDown(float x, float y) {
UIWidgetsPointerEvent event = {};
SetEventPhaseFromCursorButtonState(&event);
event.x = x;
event.y = y;
SendPointerEventWithData(event);
SetMouseStateDown(true);
}
void UIWidgetsPanel::SendMouseUp(float x, float y) {
UIWidgetsPointerEvent event = {};
SetEventPhaseFromCursorButtonState(&event);
event.x = x;
event.y = y;
SendPointerEventWithData(event);
if (event.phase == UIWidgetsPointerPhase::kUp) {
SetMouseStateDown(false);
}
}
void UIWidgetsPanel::SendMouseLeave() {
UIWidgetsPointerEvent event = {};
event.phase = UIWidgetsPointerPhase::kRemove;
SendPointerEventWithData(event);
}
void UIWidgetsPanel::SendPointerEventWithData(
const UIWidgetsPointerEvent& event_data) {
MouseState mouse_state = GetMouseState();
// If sending anything other than an add, and the pointer isn't already added,
// synthesize an add to satisfy Flutter's expectations about events.
if (!mouse_state.state_is_added &&
event_data.phase != UIWidgetsPointerPhase::kAdd) {
UIWidgetsPointerEvent event = {};
event.phase = UIWidgetsPointerPhase::kAdd;
event.x = event_data.x;
event.y = event_data.y;
event.buttons = 0;
SendPointerEventWithData(event);
}
// Don't double-add (e.g., if events are delivered out of order, so an add has
// already been synthesized).
if (mouse_state.state_is_added &&
event_data.phase == UIWidgetsPointerPhase::kAdd) {
return;
}
UIWidgetsPointerEvent event = event_data;
event.device_kind = kUIWidgetsPointerDeviceKindMouse;
event.buttons = mouse_state.buttons;
// Set metadata that's always the same regardless of the event.
event.struct_size = sizeof(event);
event.timestamp =
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch())
.count();
UIWidgetsEngineSendPointerEvent(engine_, &event, 1);
if (event_data.phase == UIWidgetsPointerPhase::kAdd) {
SetMouseStateAdded(true);
} else if (event_data.phase == UIWidgetsPointerPhase::kRemove) {
SetMouseStateAdded(false);
ResetMouseState();
}
}
void UIWidgetsPanel::OnKeyDown(int keyCode, bool isKeyDown) {
if (process_events_) {
UIWidgetsPointerEvent event = {};
event.phase = isKeyDown ? UIWidgetsPointerPhase::kMouseDown : UIWidgetsPointerPhase::kMouseUp;
event.device_kind =
UIWidgetsPointerDeviceKind::kUIWidgetsPointerDeviceKindKeyboard;
event.buttons = keyCode;
event.struct_size = sizeof(event);
event.timestamp =
std::chrono::duration_cast<std::chrono::microseconds>(
std::chrono::high_resolution_clock::now().time_since_epoch())
.count();
UIWidgetsEngineSendPointerEvent(engine_, &event, 1);
}
}
void UIWidgetsPanel::OnMouseMove(float x, float y) {
if (process_events_) {
SendMouseMove(x, y);
}
}
static uint64_t ConvertToUIWidgetsButton(int button) {
switch (button) {
case -1:
return kUIWidgetsPointerButtonMousePrimary;
case -2:
return kUIWidgetsPointerButtonMouseSecondary;
case -3:
return kUIWidgetsPointerButtonMouseMiddle;
}
std::cerr << "Mouse button not recognized: " << button << std::endl;
return 0;
}
void UIWidgetsPanel::OnMouseDown(float x, float y, int button) {
if (process_events_) {
uint64_t uiwidgets_button = ConvertToUIWidgetsButton(button);
if (uiwidgets_button != 0) {
uint64_t mouse_buttons = GetMouseState().buttons | uiwidgets_button;
SetMouseButtons(mouse_buttons);
SendMouseDown(x, y);
}
}
}
void UIWidgetsPanel::OnMouseUp(float x, float y, int button) {
if (process_events_) {
uint64_t uiwidgets_button = ConvertToUIWidgetsButton(button);
if (uiwidgets_button != 0) {
uint64_t mouse_buttons = GetMouseState().buttons & ~uiwidgets_button;
SetMouseButtons(mouse_buttons);
SendMouseUp(x, y);
}
}
}
void UIWidgetsPanel::OnMouseLeave() {
if (process_events_) {
SendMouseLeave();
}
}
UIWIDGETS_API(UIWidgetsPanel*)
UIWidgetsPanel_constructor(
Mono_Handle handle,
UIWidgetsPanel::EntrypointCallback entrypoint_callback) {
UnityConsole::WriteLine("??? constructor ggg ++");
const auto panel = UIWidgetsPanel::Create(handle, entrypoint_callback);
panel->AddRef();
return panel.get();
}
UIWIDGETS_API(void) UIWidgetsPanel_dispose(UIWidgetsPanel* panel) {
panel->Release();
}
UIWIDGETS_API(void)
UIWidgetsPanel_onEnable(UIWidgetsPanel* panel, void* native_texture_ptr,
size_t width, size_t height, float device_pixel_ratio,
const char* streaming_assets_path,
const char* settings) {
panel->OnEnable(native_texture_ptr, width, height, device_pixel_ratio,
streaming_assets_path, settings);
}
UIWIDGETS_API(void) UIWidgetsPanel_onDisable(UIWidgetsPanel* panel) {
panel->OnDisable();
}
UIWIDGETS_API(void)
UIWidgetsPanel_onRenderTexture(UIWidgetsPanel* panel, void* native_texture_ptr,
int width, int height, float dpi) {
panel->OnRenderTexture(native_texture_ptr, width, height, dpi);
}
UIWIDGETS_API(int)
UIWidgetsPanel_registerTexture(UIWidgetsPanel* panel,
void* native_texture_ptr) {
return panel->RegisterTexture(native_texture_ptr);
}
UIWIDGETS_API(void)
UIWidgetsPanel_unregisterTexture(UIWidgetsPanel* panel, int texture_id) {
panel->UnregisterTexture(texture_id);
}
UIWIDGETS_API(void)
UIWidgetsPanel_onKey(UIWidgetsPanel* panel, int keyCode, bool isKeyDown) {
panel->OnKeyDown(keyCode, isKeyDown);
}
UIWIDGETS_API(void)
UIWidgetsPanel_onMouseDown(UIWidgetsPanel* panel, float x, float y,
int button) {
panel->OnMouseDown(x, y, button);
}
UIWIDGETS_API(void)
UIWidgetsPanel_onMouseUp(UIWidgetsPanel* panel, float x, float y, int button) {
panel->OnMouseUp(x, y, button);
}
UIWIDGETS_API(void)
UIWidgetsPanel_onMouseMove(UIWidgetsPanel* panel, float x, float y) {
panel->OnMouseMove(x, y);
}
UIWIDGETS_API(void)
UIWidgetsPanel_onMouseLeave(UIWidgetsPanel* panel) { panel->OnMouseLeave(); }
} // namespace uiwidgets

343
engine/src/shell/platform/unity/android/unity_surface_manager.cc


#include "unity_surface_manager.h"
// #include <d3d11.h>
// #include <dxgi.h>
#include <flutter/fml/logging.h>
#include "Unity/IUnityGraphics.h"
// #include "Unity/IUnityGraphicsD3D11.h"
#include "src/shell/platform/unity/unity_console.h"
namespace uiwidgets
{
UnitySurfaceManager::UnitySurfaceManager(IUnityInterfaces *unity_interfaces)
: egl_display_(EGL_NO_DISPLAY),
egl_context_(EGL_NO_CONTEXT),
egl_resource_context_(EGL_NO_CONTEXT)
// ,
// egl_config_(nullptr)
{
initialize_succeeded_ = Initialize(unity_interfaces);
}
UnitySurfaceManager::~UnitySurfaceManager() { CleanUp(); }
GLuint UnitySurfaceManager::CreateRenderSurface(void *native_texture_ptr)
{
UnityConsole::WriteLine("test c++");
int i = 0;
EGLContext current_ctx = eglGetCurrentContext();
UnityConsole::WriteLine(("test c++" + std::to_string(i++)).c_str());
EGLDisplay hdc = eglGetCurrentDisplay();
// wglGetCurrentDC();
UnityConsole::WriteLine(("test c++" + std::to_string(i++)).c_str());
void *texture1_ptr_ = native_texture_ptr;
UnityConsole::WriteLine(("test c++" + std::to_string(i++)).c_str());
void *surface_texture1_ptr_ = texture1_ptr_;
textureInfo.fTarget = GR_GL_TEXTURE_2D;
textureInfo.fID = GrGLuint((long)texture1_ptr_);
textureInfo.fFormat = GR_GL_RGBA8;
UnityConsole::WriteLine(("test c++" + std::to_string(i++)).c_str());
m_backendTex =
GrBackendTexture(100, 100, GrMipMapped::kNo, textureInfo);
UnityConsole::WriteLine(("test c++??" + std::to_string(i++)).c_str());
// sk_sp<GrContext> gr_context_ = GrContext::MakeGL();
// UnityConsole::WriteLine(("test c++" + std::to_string(i++)).c_str());
// sk_sp<SkSurface> m_SkSurface = SkSurface::MakeFromBackendTexture(
// gr_context_.get(), m_backendTex, kBottomLeft_GrSurfaceOrigin, 1,
// kRGBA_8888_SkColorType, nullptr, nullptr);
// UnityConsole::WriteLine(("test c++" + std::to_string(i++)).c_str());
// SkCanvas* canvas = m_SkSurface->getCanvas();
// UnityConsole::WriteLine(("test c++" + std::to_string(i++)).c_str());
// canvas->drawColor(SK_ColorBLUE);
// // SkPaint paint;
// UnityConsole::WriteLine(("test c++" + std::to_string(i++)).c_str());
// SkRect rect = SkRect::MakeXYWH(50, 50, 40, 60);
// canvas->drawRect(rect, paint);
// SkPaint paint2;
// auto text = SkTextBlob::MakeFromString("Hello, Skia!", SkFont(nullptr, 18));
// canvas->drawTextBlob(text.get(), 50, 25, paint2);
// GrBackendTexture m_backendTex =
// GrBackendTexture(width_, height_, GrMipMapped::kNo, textureInfo);
// m_SkSurface = SkSurface::MakeFromBackendTexture(
// gr_context_.get(), m_backendTex, kBottomLeft_GrSurfaceOrigin, 1,
// kRGBA_8888_SkColorType, nullptr, nullptr);
// width_ = width;
// height_ = height;
// ID3D11Texture2D* d3d11_texture =
// static_cast<ID3D11Texture2D*>(native_texture_ptr);
// IDXGIResource* image_resource;
// HRESULT hr = d3d11_texture->QueryInterface(
// __uuidof(IDXGIResource), reinterpret_cast<void**>(&image_resource));
// FML_CHECK(SUCCEEDED(hr)) << "UnitySurfaceManager: QueryInterface() failed";
// HANDLE shared_image_handle;
// hr = image_resource->GetSharedHandle(&shared_image_handle);
// FML_CHECK(SUCCEEDED(hr)) << "UnitySurfaceManager: GetSharedHandle() failed";
// image_resource->Release();
// FML_CHECK(shared_image_handle != nullptr)
// << "UnitySurfaceManager: shared_image_handle is nullptr, miscFlags "
// "D3D11_RESOURCE_MISC_SHARED is needed";
// IDXGIResource* dxgi_resource;
// hr = d3d11_device_->OpenSharedResource(
// shared_image_handle, __uuidof(ID3D11Resource),
// reinterpret_cast<void**>(&dxgi_resource));
// FML_CHECK(SUCCEEDED(hr))
// << "UnitySurfaceManager: failed to open shared resource";
// ID3D11Texture2D* image_texture;
// hr = dxgi_resource->QueryInterface(__uuidof(ID3D11Texture2D),
// reinterpret_cast<void**>(&image_texture));
// FML_CHECK(SUCCEEDED(hr))
// << "UnitySurfaceManager: failed to query interface ID3D11Texture2D";
// dxgi_resource->Release();
// const EGLint attribs[] = {EGL_NONE};
// FML_DCHECK(fbo_egl_image_ == nullptr);
// fbo_egl_image_ =
// eglCreateImageKHR(egl_display_, EGL_NO_CONTEXT, EGL_D3D11_TEXTURE_ANGLE,
// static_cast<EGLClientBuffer>(image_texture), attribs);
// FML_CHECK(fbo_egl_image_ != EGL_NO_IMAGE_KHR);
// image_texture->Release();
// GLint old_texture_binding_2d;
// glGetIntegerv(GL_TEXTURE_BINDING_2D, &old_texture_binding_2d);
// FML_DCHECK(fbo_texture_ == 0);
// glGenTextures(1, &fbo_texture_);
// glBindTexture(GL_TEXTURE_2D, fbo_texture_);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// glEGLImageTargetTexture2DOES(GL_TEXTURE_2D, fbo_egl_image_);
// glBindTexture(GL_TEXTURE_2D, old_texture_binding_2d);
// GLint old_framebuffer_binding;
// glGetIntegerv(GL_FRAMEBUFFER_BINDING, &old_framebuffer_binding);
// FML_DCHECK(fbo_ == 0);
// glGenFramebuffers(1, &fbo_);
// glBindFramebuffer(GL_FRAMEBUFFER, fbo_);
// glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D,
// fbo_texture_, 0);
// FML_CHECK(glCheckFramebufferStatus(GL_FRAMEBUFFER) ==
// GL_FRAMEBUFFER_COMPLETE);
// glBindFramebuffer(GL_FRAMEBUFFER, old_framebuffer_binding);
return fbo_;
}
void UnitySurfaceManager::DestroyRenderSurface()
{
// FML_DCHECK(fbo_ != 0);
// glDeleteFramebuffers(1, &fbo_);
// fbo_ = 0;
// FML_DCHECK(fbo_texture_ != 0);
// glDeleteTextures(1, &fbo_texture_);
// fbo_texture_ = 0;
// FML_DCHECK(fbo_egl_image_ != nullptr);
// eglDestroyImageKHR(egl_display_, fbo_egl_image_);
// fbo_egl_image_ = nullptr;
}
bool UnitySurfaceManager::ClearCurrent()
{
UnityConsole::WriteLine("test c++: make current");
return eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
EGL_NO_CONTEXT) == EGL_TRUE;
}
bool UnitySurfaceManager::MakeCurrent(const EGLSurface surface)
{
int width_ = 100;
int height_ = 100;
UnityConsole::WriteLine("test c++: clear current");
EGLBoolean a = eglMakeCurrent(egl_display_, surface, surface, egl_context_) ==
EGL_TRUE;
int i = 0;
sk_sp<GrContext> gr_context_ = GrContext::MakeGL();
UnityConsole::WriteLine(("test c++" + std::to_string(i++)).c_str());
sk_sp<SkSurface> m_SkSurface = SkSurface::MakeFromBackendTexture(
gr_context_.get(), m_backendTex, kBottomLeft_GrSurfaceOrigin, 1,
kRGBA_8888_SkColorType, nullptr, nullptr);
UnityConsole::WriteLine(("test c++" + std::to_string(i++)).c_str());
SkCanvas* canvas = m_SkSurface->getCanvas();
UnityConsole::WriteLine(("test c++" + std::to_string(i++)).c_str());
canvas->drawColor(SK_ColorBLUE);
SkPaint paint;
UnityConsole::WriteLine(("test c++" + std::to_string(i++)).c_str());
SkRect rect = SkRect::MakeXYWH(50, 50, 40, 60);
canvas->drawRect(rect, paint);
SkPaint paint2;
auto text = SkTextBlob::MakeFromString("Hello, Skia!", SkFont(nullptr, 18));
canvas->drawTextBlob(text.get(), 50, 25, paint2);
GrBackendTexture m_backendTex =
GrBackendTexture(width_, height_, GrMipMapped::kNo, textureInfo);
m_SkSurface = SkSurface::MakeFromBackendTexture(
gr_context_.get(), m_backendTex, kBottomLeft_GrSurfaceOrigin, 1,
kRGBA_8888_SkColorType, nullptr, nullptr);
return a;
}
bool UnitySurfaceManager::MakeResourceCurrent()
{
UnityConsole::WriteLine("test c++: make resource");
return eglMakeCurrent(egl_display_, EGL_NO_SURFACE, EGL_NO_SURFACE,
egl_resource_context_) == EGL_TRUE;
}
bool UnitySurfaceManager::Initialize(IUnityInterfaces *unity_interfaces)
{
// IUnityGraphics* graphics = unity_interfaces->Get<IUnityGraphics>();
// FML_CHECK(graphics->GetRenderer() == kUnityGfxRendererD3D11)
// << "Renderer type is invalid";
// IUnityGraphicsD3D11* d3d11 = unity_interfaces->Get<IUnityGraphicsD3D11>();
// ID3D11Device* d3d11_device = d3d11->GetDevice();
// IDXGIDevice* dxgi_device;
// HRESULT hr = d3d11_device->QueryInterface(
// __uuidof(IDXGIDevice), reinterpret_cast<void**>(&dxgi_device));
// FML_CHECK(SUCCEEDED(hr)) << "d3d11_device->QueryInterface(...) failed";
// IDXGIAdapter* dxgi_adapter;
// hr = dxgi_device->GetAdapter(&dxgi_adapter);
// FML_CHECK(SUCCEEDED(hr)) << "dxgi_adapter->GetAdapter(...) failed";
// dxgi_device->Release();
// DXGI_ADAPTER_DESC adapter_desc;
// hr = dxgi_adapter->GetDesc(&adapter_desc);
// FML_CHECK(SUCCEEDED(hr)) << "dxgi_adapter->GetDesc(...) failed";
// dxgi_adapter->Release();
// EGLint displayAttribs[] = {EGL_PLATFORM_ANGLE_TYPE_ANGLE,
// EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE,
// EGL_PLATFORM_ANGLE_D3D_LUID_HIGH_ANGLE,
// adapter_desc.AdapterLuid.HighPart,
// EGL_PLATFORM_ANGLE_D3D_LUID_LOW_ANGLE,
// adapter_desc.AdapterLuid.LowPart,
// EGL_PLATFORM_ANGLE_ENABLE_AUTOMATIC_TRIM_ANGLE,
// EGL_TRUE,
// EGL_NONE};
// egl_display_ = eglGetPlatformDisplayEXT(EGL_PLATFORM_ANGLE_ANGLE,
// EGL_DEFAULT_DISPLAY, displayAttribs);
// FML_CHECK(egl_display_ != EGL_NO_DISPLAY)
// << "EGL: Failed to get a compatible EGLdisplay";
// if (eglInitialize(egl_display_, nullptr, nullptr) == EGL_FALSE) {
// FML_CHECK(false) << "EGL: Failed to initialize EGL";
// }
// EGLAttrib egl_device = 0;
// eglQueryDisplayAttribEXT(egl_display_, EGL_DEVICE_EXT, &egl_device);
// EGLAttrib angle_device = 0;
// eglQueryDeviceAttribEXT(reinterpret_cast<EGLDeviceEXT>(egl_device),
// EGL_D3D11_DEVICE_ANGLE, &angle_device);
// d3d11_device_ = reinterpret_cast<ID3D11Device*>(angle_device);
// const EGLint configAttributes[] = {EGL_RED_SIZE, 8, EGL_GREEN_SIZE, 8,
// EGL_BLUE_SIZE, 8, EGL_ALPHA_SIZE, 8,
// EGL_DEPTH_SIZE, 8, EGL_STENCIL_SIZE, 8,
// EGL_NONE};
// EGLint numConfigs = 0;
// if (eglChooseConfig(egl_display_, configAttributes, &egl_config_, 1,
// &numConfigs) == EGL_FALSE ||
// numConfigs == 0) {
// FML_CHECK(false) << "EGL: Failed to choose first context";
// }
// const EGLint display_context_attributes[] = {EGL_CONTEXT_CLIENT_VERSION, 2,
// EGL_NONE};
// egl_context_ = eglCreateContext(egl_display_, egl_config_, EGL_NO_CONTEXT,
// display_context_attributes);
// if (egl_context_ == EGL_NO_CONTEXT) {
// FML_CHECK(false) << "EGL: Failed to create EGL context";
// }
// egl_resource_context_ = eglCreateContext(
// egl_display_, egl_config_, egl_context_, display_context_attributes);
// if (egl_resource_context_ == EGL_NO_CONTEXT) {
// FML_CHECK(false) << "EGL: Failed to create EGL resource context";
// }
return true;
}
void UnitySurfaceManager::CleanUp()
{
// EGLBoolean result = EGL_FALSE;
// if (egl_display_ != EGL_NO_DISPLAY && egl_context_ != EGL_NO_CONTEXT) {
// result = eglDestroyContext(egl_display_, egl_context_);
// egl_context_ = EGL_NO_CONTEXT;
// if (result == EGL_FALSE) {
// FML_LOG(ERROR) << "EGL: Failed to destroy context";
// }
// }
// d3d11_device_ = nullptr;
// if (egl_display_ != EGL_NO_DISPLAY &&
// egl_resource_context_ != EGL_NO_CONTEXT) {
// result = eglDestroyContext(egl_display_, egl_resource_context_);
// egl_resource_context_ = EGL_NO_CONTEXT;
// if (result == EGL_FALSE) {
// FML_LOG(ERROR) << "EGL : Failed to destroy resource context";
// }
// }
// if (egl_display_ != EGL_NO_DISPLAY) {
// result = eglTerminate(egl_display_);
// egl_display_ = EGL_NO_DISPLAY;
// if (result == EGL_FALSE) {
// FML_LOG(ERROR) << "EGL : Failed to terminate EGL";
// }
// }
}
} // namespace uiwidgets

76
engine/src/shell/platform/unity/android/unity_surface_manager.h


#pragma once
// OpenGL ES and EGL includes
#include <EGL/egl.h>
#include <EGL/eglext.h>
#include <EGL/eglplatform.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
// #include <d3d11.h>
// #include <windows.h>
#include <cstdint>
#include "Unity/IUnityInterface.h"
#include "flutter/fml/macros.h"
#include <include/gpu/GrContext.h>
#include <src/gpu/gl/GrGLDefines.h>
#include "cassert"
#include "include/core/SkCanvas.h"
#include "include/core/SkSurface.h"
#include "include/core/SkTextBlob.h"
#include "include/effects/SkPerlinNoiseShader.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrContext.h"
#include "include/gpu/gl/GrGLTypes.h"
#include "modules/skottie/include/Skottie.h"
// #include "platform_base.h"
// #include "render_api.h"
#include "src/gpu/gl/GrGLDefines.h"
// #include "windows.h"
// #include <wingdi.h>
namespace uiwidgets {
class UnitySurfaceManager {
public:
UnitySurfaceManager(IUnityInterfaces* unity_interfaces);
~UnitySurfaceManager();
GLuint CreateRenderSurface(void* native_texture_ptr);
void DestroyRenderSurface();
bool ClearCurrent();
bool MakeCurrent(const EGLSurface surface);
bool MakeResourceCurrent();
// EGLDisplay GetEGLDisplay() const { return egl_display_; }
// ID3D11Device* GetD3D11Device() const { return d3d11_device_; }
FML_DISALLOW_COPY_AND_ASSIGN(UnitySurfaceManager);
private:
bool Initialize(IUnityInterfaces* unity_interfaces);
void CleanUp();
GrBackendTexture m_backendTex;
GrGLTextureInfo textureInfo;
EGLDisplay egl_display_;
EGLContext egl_context_;
EGLContext egl_resource_context_;
// EGLConfig egl_config_;
bool initialize_succeeded_;
// ID3D11Device* d3d11_device_;
// EGLImage fbo_egl_image_ = nullptr;
// GLuint fbo_texture_ = 0;
GLuint fbo_ = 0;
};
} // namespace uiwidgets

/engine/src/shell/platform/unity/darwin/android/cocoa_task_runner.cc → /engine/src/shell/platform/unity/android/cocoa_task_runner.cc

/engine/src/shell/platform/unity/darwin/android/cocoa_task_runner.h → /engine/src/shell/platform/unity/android/cocoa_task_runner.h

/engine/src/shell/platform/unity/darwin/android/uiwidgets_panel.h → /engine/src/shell/platform/unity/android/uiwidgets_panel.h

/engine/src/shell/platform/unity/darwin/android/uiwidgets_system.cc → /engine/src/shell/platform/unity/android/uiwidgets_system.cc

/engine/src/shell/platform/unity/darwin/android/uiwidgets_system.h → /engine/src/shell/platform/unity/android/uiwidgets_system.h

正在加载...
取消
保存