From 1d67a42888ae4e9574c226a6181e3075ad09f736 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 12 Aug 2016 21:55:00 -0700 Subject: [PATCH] Get //flutter/runtime building on Fuchsia (flutter/engine#2922) --- engine/src/flutter/BUILD.gn | 5 +---- engine/src/flutter/lib/ui/BUILD.gn | 22 +++++++++++++------- engine/src/flutter/lib/ui/dart_ui.cc | 12 ++++++++--- engine/src/flutter/lib/ui/ui_dart_state.cc | 15 ++++++++++---- engine/src/flutter/lib/ui/ui_dart_state.h | 17 +++++++++++---- engine/src/flutter/runtime/BUILD.gn | 24 ++++++++++++++++------ engine/src/flutter/runtime/dart_init.cc | 13 ++++++------ engine/src/flutter/runtime/dart_init.h | 2 +- engine/src/flutter/runtime/sky_view.cc | 2 +- 9 files changed, 76 insertions(+), 36 deletions(-) diff --git a/engine/src/flutter/BUILD.gn b/engine/src/flutter/BUILD.gn index e4b5945c55c..698b9477c5f 100644 --- a/engine/src/flutter/BUILD.gn +++ b/engine/src/flutter/BUILD.gn @@ -8,12 +8,9 @@ group("flutter") { if (is_fuchsia) { # TODO(abarth) Remove this specific list once Fuchsia can build everything. deps = [ - "//flutter/assets", "//flutter/flow", - "//flutter/glue", - "//flutter/lib/ui", + "//flutter/runtime", "//flutter/snapshotter", - "//lib/tonic", ] } else { deps = [ diff --git a/engine/src/flutter/lib/ui/BUILD.gn b/engine/src/flutter/lib/ui/BUILD.gn index d9f0c7e2461..55ec7b29f82 100644 --- a/engine/src/flutter/lib/ui/BUILD.gn +++ b/engine/src/flutter/lib/ui/BUILD.gn @@ -44,12 +44,6 @@ source_set("ui") { "painting/rrect.h", "painting/shader.cc", "painting/shader.h", - "text/paragraph_builder.cc", - "text/paragraph_builder.h", - "text/paragraph.cc", - "text/paragraph.h", - "text/text_box.cc", - "text/text_box.h", "ui_dart_state.cc", "ui_dart_state.h", "window/window.cc", @@ -64,7 +58,6 @@ source_set("ui") { "//flutter/services/engine:interfaces", "//flutter/services/pointer:interfaces", "//flutter/skia", - "//flutter/sky/engine", "//lib/tonic", "//lib/tonic/mojo", "//mojo/public/cpp/application", @@ -73,6 +66,21 @@ source_set("ui") { "//mojo/services/asset_bundle/interfaces", ] + if (!is_fuchsia) { + sources += [ + "text/paragraph_builder.cc", + "text/paragraph_builder.h", + "text/paragraph.cc", + "text/paragraph.h", + "text/text_box.cc", + "text/text_box.h", + ] + + deps += [ + "//flutter/sky/engine", + ] + } + if (is_android) { deps += [ # TODO(abarth): In principle, these libraries should be fully independent. diff --git a/engine/src/flutter/lib/ui/dart_ui.cc b/engine/src/flutter/lib/ui/dart_ui.cc index 39c33575346..8953c425634 100644 --- a/engine/src/flutter/lib/ui/dart_ui.cc +++ b/engine/src/flutter/lib/ui/dart_ui.cc @@ -18,12 +18,16 @@ #include "flutter/lib/ui/painting/path.h" #include "flutter/lib/ui/painting/picture_recorder.h" #include "flutter/lib/ui/painting/picture.h" -#include "flutter/lib/ui/text/paragraph_builder.h" -#include "flutter/lib/ui/text/paragraph.h" #include "flutter/lib/ui/window/window.h" +#include "lib/ftl/build_config.h" #include "lib/tonic/converter/dart_converter.h" #include "lib/tonic/logging/dart_error.h" +#if !defined(OS_FUCHSIA) +#include "flutter/lib/ui/text/paragraph_builder.h" +#include "flutter/lib/ui/text/paragraph.h" +#endif + using tonic::ToDart; namespace blink { @@ -56,8 +60,10 @@ void DartUI::InitForGlobal() { ImageShader::RegisterNatives(g_natives); MaskFilter::RegisterNatives(g_natives); MojoServices::RegisterNatives(g_natives); +#if !defined(OS_FUCHSIA) Paragraph::RegisterNatives(g_natives); ParagraphBuilder::RegisterNatives(g_natives); +#endif Picture::RegisterNatives(g_natives); PictureRecorder::RegisterNatives(g_natives); Scene::RegisterNatives(g_natives); @@ -67,7 +73,7 @@ void DartUI::InitForGlobal() { } void DartUI::InitForIsolate() { - DCHECK(g_natives); + FTL_DCHECK(g_natives); DART_CHECK_VALID(Dart_SetNativeResolver(Dart_LookupLibrary(ToDart("dart:ui")), GetNativeFunction, GetSymbol)); } diff --git a/engine/src/flutter/lib/ui/ui_dart_state.cc b/engine/src/flutter/lib/ui/ui_dart_state.cc index 026749e4525..e7ea7f21443 100644 --- a/engine/src/flutter/lib/ui/ui_dart_state.cc +++ b/engine/src/flutter/lib/ui/ui_dart_state.cc @@ -6,13 +6,16 @@ #include "flutter/lib/ui/mojo_services.h" #include "flutter/lib/ui/window/window.h" -#include "flutter/sky/engine/platform/fonts/FontSelector.h" #include "lib/tonic/converter/dart_converter.h" -#ifdef OS_ANDROID +#if defined(OS_ANDROID) #include "flutter/lib/jni/dart_jni.h" #endif +#if !defined(OS_FUCHSIA) +#include "flutter/sky/engine/platform/fonts/FontSelector.h" +#endif + using tonic::ToDart; namespace blink { @@ -59,11 +62,13 @@ MojoServices* UIDartState::mojo_services() { return mojo_services_.get(); } -#ifdef OS_ANDROID +#if defined(OS_ANDROID) DartJniIsolateData* UIDartState::jni_data() { return jni_data_.get(); } -#endif +#endif // defined(OS_ANDROID) + +#if !defined(OS_FUCHSIA) void UIDartState::set_font_selector(PassRefPtr selector) { font_selector_ = selector; @@ -73,4 +78,6 @@ PassRefPtr UIDartState::font_selector() { return font_selector_; } +#endif // !defined(OS_FUCHSIA) + } // namespace blink diff --git a/engine/src/flutter/lib/ui/ui_dart_state.h b/engine/src/flutter/lib/ui/ui_dart_state.h index cc60b37fcb2..5eb15f0bd93 100644 --- a/engine/src/flutter/lib/ui/ui_dart_state.h +++ b/engine/src/flutter/lib/ui/ui_dart_state.h @@ -6,11 +6,14 @@ #define FLUTTER_LIB_UI_UI_DART_STATE_H_ #include "dart/runtime/include/dart_api.h" -#include "flutter/sky/engine/wtf/RefPtr.h" #include "lib/ftl/build_config.h" #include "lib/tonic/dart_persistent_value.h" #include "lib/tonic/dart_state.h" +#if !defined(OS_FUCHSIA) +#include "flutter/sky/engine/wtf/RefPtr.h" +#endif + namespace blink { class FontSelector; class DartJniIsolateData; @@ -42,12 +45,14 @@ class UIDartState : public tonic::DartState { void set_mojo_services(std::unique_ptr mojo_services); MojoServices* mojo_services(); -#ifdef OS_ANDROID +#if defined(OS_ANDROID) DartJniIsolateData* jni_data(); #endif +#if !defined(OS_FUCHSIA) void set_font_selector(PassRefPtr selector); PassRefPtr font_selector(); +#endif private: void DidSetIsolate() override; @@ -55,11 +60,15 @@ class UIDartState : public tonic::DartState { IsolateClient* isolate_client_; Dart_Port main_port_; std::unique_ptr mojo_services_; -#ifdef OS_ANDROID + std::unique_ptr window_; + +#if defined(OS_ANDROID) std::unique_ptr jni_data_; #endif - std::unique_ptr window_; + +#if !defined(OS_FUCHSIA) RefPtr font_selector_; +#endif }; } // namespace blink diff --git a/engine/src/flutter/runtime/BUILD.gn b/engine/src/flutter/runtime/BUILD.gn index e6cb17e1e18..1686253f171 100644 --- a/engine/src/flutter/runtime/BUILD.gn +++ b/engine/src/flutter/runtime/BUILD.gn @@ -2,21 +2,33 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import("//mojo/dart/embedder/embedder.gni") - vmservice_sources_gypi = exec_script("//build/gypi_to_gn.py", [ rebase_path("//dart/runtime/bin/vmservice/vmservice_sources.gypi") ], "scope", [ rebase_path("//dart/runtime/bin/vmservice/vmservice_sources.gypi") ]) -dart_embedder_resources("gen_embedded_resources_cc") { +action("gen_embedded_resources_cc") { + script = "//dart/runtime/tools/create_resources.py" + output_file = "$target_gen_dir/embedded_resources.cc" + outputs = [ output_file ] + inputs = rebase_path(vmservice_sources_gypi.sources, "", "//dart/runtime/bin/vmservice") - root_prefix = "//dart/runtime/bin/" - output = "$target_gen_dir/embedded_resources.cc" - table_name = "flutter_embedded_service_isolate" + + args = [ + "--output", + rebase_path(output_file), + "--outer_namespace", + "mojo", # TODO(abarth): Change namespace. + "--inner_namespace", + "dart", # TODO(abarth): Change namespace. + "--table_name", + "flutter_embedded_service_isolate", + "--root_prefix", + rebase_path("//dart/runtime/bin/"), + ] + rebase_path(inputs) } source_set("embedded_resources_cc") { diff --git a/engine/src/flutter/runtime/dart_init.cc b/engine/src/flutter/runtime/dart_init.cc index f2ac25ea628..65397b97459 100644 --- a/engine/src/flutter/runtime/dart_init.cc +++ b/engine/src/flutter/runtime/dart_init.cc @@ -29,6 +29,7 @@ #include "flutter/lib/ui/ui_dart_state.h" #include "flutter/runtime/dart_service_isolate.h" #include "flutter/runtime/start_up.h" +#include "lib/ftl/arraysize.h" #include "lib/ftl/files/eintr_wrapper.h" #include "lib/ftl/files/unique_fd.h" #include "lib/ftl/logging.h" @@ -44,7 +45,7 @@ #include "lib/tonic/typed_data/uint8_list.h" #include "mojo/public/platform/dart/dart_handle_watcher.h" -#ifdef OS_ANDROID +#if defined(OS_ANDROID) #include "flutter/lib/jni/dart_jni.h" #endif @@ -159,7 +160,7 @@ bool DartFileModifiedCallback(const char* source_url, int64_t since_ms) { } void ThreadExitCallback() { -#ifdef OS_ANDROID +#if defined(OS_ANDROID) DartJni::OnThreadExit(); #endif } @@ -271,7 +272,7 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, dart_state->class_library().add_provider("ui", std::move(ui_class_provider)); -#ifdef OS_ANDROID +#if defined(OS_ANDROID) DartJni::InitForIsolate(); std::unique_ptr jni_class_provider( new DartClassProvider(dart_state, "dart:jni")); @@ -325,7 +326,7 @@ static void ServiceStreamCancelCallback(const char* stream_id) { } } -#ifdef OS_ANDROID +#if defined(OS_ANDROID) DartJniIsolateData* GetDartJniDataForCurrentIsolate() { return UIDartState::Current()->jni_data(); @@ -499,7 +500,7 @@ void SetServiceIsolateHook(ServiceIsolateHook hook) { void SetRegisterNativeServiceProtocolExtensionHook( RegisterNativeServiceProtocolExtensionHook hook) { - CHECK(!g_service_isolate_initialized); + FTL_CHECK(!g_service_isolate_initialized); g_register_native_service_protocol_extensions_hook = hook; } @@ -583,7 +584,7 @@ void InitDartVM() { #endif DartUI::InitForGlobal(); -#ifdef OS_ANDROID +#if defined(OS_ANDROID) DartJni::InitForGlobal(GetDartJniDataForCurrentIsolate); #endif diff --git a/engine/src/flutter/runtime/dart_init.h b/engine/src/flutter/runtime/dart_init.h index a4e12558c3f..16501a9732f 100644 --- a/engine/src/flutter/runtime/dart_init.h +++ b/engine/src/flutter/runtime/dart_init.h @@ -14,7 +14,7 @@ namespace blink { -#define DART_ALLOW_DYNAMIC_RESOLUTION (defined(OS_IOS) || FLUTTER_AOT) +#define DART_ALLOW_DYNAMIC_RESOLUTION (OS_IOS || FLUTTER_AOT) #if DART_ALLOW_DYNAMIC_RESOLUTION diff --git a/engine/src/flutter/runtime/sky_view.cc b/engine/src/flutter/runtime/sky_view.cc index 4f96b824ca0..7d2e91c971d 100644 --- a/engine/src/flutter/runtime/sky_view.cc +++ b/engine/src/flutter/runtime/sky_view.cc @@ -51,7 +51,7 @@ void SkyView::PopRoute() { } void SkyView::CreateView(const std::string& script_uri) { - DCHECK(!dart_controller_); + FTL_DCHECK(!dart_controller_); dart_controller_.reset(new DartController()); std::unique_ptr window(new Window(this));