Skip to content

Commit

Permalink
Get //flutter/runtime building on Fuchsia (flutter#2922)
Browse files Browse the repository at this point in the history
  • Loading branch information
abarth authored Aug 13, 2016
1 parent fe509b0 commit 0c000bd
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 36 deletions.
5 changes: 1 addition & 4 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
22 changes: 15 additions & 7 deletions lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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.
Expand Down
12 changes: 9 additions & 3 deletions lib/ui/dart_ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand All @@ -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));
}
Expand Down
15 changes: 11 additions & 4 deletions lib/ui/ui_dart_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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<FontSelector> selector) {
font_selector_ = selector;
Expand All @@ -73,4 +78,6 @@ PassRefPtr<FontSelector> UIDartState::font_selector() {
return font_selector_;
}

#endif // !defined(OS_FUCHSIA)

} // namespace blink
17 changes: 13 additions & 4 deletions lib/ui/ui_dart_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -42,24 +45,30 @@ class UIDartState : public tonic::DartState {
void set_mojo_services(std::unique_ptr<MojoServices> 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<FontSelector> selector);
PassRefPtr<FontSelector> font_selector();
#endif

private:
void DidSetIsolate() override;

IsolateClient* isolate_client_;
Dart_Port main_port_;
std::unique_ptr<MojoServices> mojo_services_;
#ifdef OS_ANDROID
std::unique_ptr<Window> window_;

#if defined(OS_ANDROID)
std::unique_ptr<DartJniIsolateData> jni_data_;
#endif
std::unique_ptr<Window> window_;

#if !defined(OS_FUCHSIA)
RefPtr<FontSelector> font_selector_;
#endif
};

} // namespace blink
Expand Down
24 changes: 18 additions & 6 deletions runtime/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
13 changes: 7 additions & 6 deletions runtime/dart_init.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -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<DartClassProvider> jni_class_provider(
new DartClassProvider(dart_state, "dart:jni"));
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}

Expand Down Expand Up @@ -583,7 +584,7 @@ void InitDartVM() {
#endif

DartUI::InitForGlobal();
#ifdef OS_ANDROID
#if defined(OS_ANDROID)
DartJni::InitForGlobal(GetDartJniDataForCurrentIsolate);
#endif

Expand Down
2 changes: 1 addition & 1 deletion runtime/dart_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion runtime/sky_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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> window(new Window(this));
Expand Down

0 comments on commit 0c000bd

Please sign in to comment.