Skip to content

Commit

Permalink
Finish removing //flutter/tonic (flutter#2917)
Browse files Browse the repository at this point in the history
This pulled a refactoring of how we keep track of the primary threads.
  • Loading branch information
abarth authored Aug 12, 2016
1 parent 855e471 commit f8d80c4
Show file tree
Hide file tree
Showing 41 changed files with 261 additions and 300 deletions.
2 changes: 1 addition & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ group("flutter") {
"//flutter/glue",
"//flutter/lib/ui",
"//flutter/snapshotter",
"//flutter/tonic",
"//lib/tonic",
]
} else {
deps = [
Expand Down
16 changes: 16 additions & 0 deletions common/BUILD.gn
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2016 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

source_set("common") {
sources = [
"settings.cc",
"settings.h",
"threads.cc",
"threads.h",
]

deps = [
"//lib/ftl",
]
}
5 changes: 5 additions & 0 deletions common/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Flutter Common
==============

The bottom of the dependency graph for Flutter. Useful for static constants.
Please don't put too much in here.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/sky/engine/public/platform/sky_settings.h"
#include "flutter/common/settings.h"

#include <memory>

Expand All @@ -11,19 +11,19 @@
namespace blink {
namespace {

SkySettings* g_settings = nullptr;
Settings* g_settings = nullptr;

} // namespace

const SkySettings& SkySettings::Get() {
const Settings& Settings::Get() {
FTL_CHECK(g_settings);
return *g_settings;
}

void SkySettings::Set(const SkySettings& settings) {
void Settings::Set(const Settings& settings) {
FTL_CHECK(!g_settings);
g_settings = new SkySettings();
g_settings = new Settings();
*g_settings = settings;
}

} // namespace blink
} // namespace blink
12 changes: 6 additions & 6 deletions sky/engine/public/platform/sky_settings.h → common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef SKY_ENGINE_PUBLIC_PLATFORM_SKY_SETTINGS_H_
#define SKY_ENGINE_PUBLIC_PLATFORM_SKY_SETTINGS_H_
#ifndef FLUTTER_COMMON_SETTINGS_H_
#define FLUTTER_COMMON_SETTINGS_H_

#include <stdint.h>

Expand All @@ -12,7 +12,7 @@

namespace blink {

struct SkySettings {
struct Settings {
bool enable_observatory = false;
// Port on target will be auto selected by the OS. A message will be printed
// on the target with the port after it has been selected.
Expand All @@ -24,10 +24,10 @@ struct SkySettings {
std::string temp_directory_path;
std::vector<std::string> dart_flags;

static const SkySettings& Get();
static void Set(const SkySettings& settings);
static const Settings& Get();
static void Set(const Settings& settings);
};

} // namespace blink

#endif // SKY_ENGINE_PUBLIC_PLATFORM_SKY_SETTINGS_H_
#endif // FLUTTER_COMMON_SETTINGS_H_
48 changes: 48 additions & 0 deletions common/threads.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/common/threads.h"

#include <utility>

namespace blink {
namespace {

Threads* g_threads = nullptr;

} // namespace

Threads::Threads() {}

Threads::Threads(ftl::RefPtr<ftl::TaskRunner> gpu,
ftl::RefPtr<ftl::TaskRunner> ui,
ftl::RefPtr<ftl::TaskRunner> io)
: gpu_(std::move(gpu)), ui_(std::move(ui)), io_(std::move(io)) {}

Threads::~Threads() {}

const ftl::RefPtr<ftl::TaskRunner>& Threads::Gpu() {
return Get().gpu_;
}

const ftl::RefPtr<ftl::TaskRunner>& Threads::UI() {
return Get().ui_;
}

const ftl::RefPtr<ftl::TaskRunner>& Threads::IO() {
return Get().io_;
}

const Threads& Threads::Get() {
FTL_CHECK(g_threads);
return *g_threads;
}

void Threads::Set(const Threads& threads) {
FTL_CHECK(!g_threads);
g_threads = new Threads();
*g_threads = threads;
}

} // namespace blink
36 changes: 36 additions & 0 deletions common/threads.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef FLUTTER_COMMON_THREADS_H_
#define FLUTTER_COMMON_THREADS_H_

#include "lib/ftl/tasks/task_runner.h"

namespace blink {

class Threads {
public:
Threads();
Threads(ftl::RefPtr<ftl::TaskRunner> gpu,
ftl::RefPtr<ftl::TaskRunner> ui,
ftl::RefPtr<ftl::TaskRunner> io);
~Threads();

static const ftl::RefPtr<ftl::TaskRunner>& Gpu();
static const ftl::RefPtr<ftl::TaskRunner>& UI();
static const ftl::RefPtr<ftl::TaskRunner>& IO();

static void Set(const Threads& settings);

private:
static const Threads& Get();

ftl::RefPtr<ftl::TaskRunner> gpu_;
ftl::RefPtr<ftl::TaskRunner> ui_;
ftl::RefPtr<ftl::TaskRunner> io_;
};

} // namespace blink

#endif // FLUTTER_COMMON_THREADS_H_
2 changes: 1 addition & 1 deletion lib/jni/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ source_set("jni") {

deps = [
"//base",
"//flutter/tonic",
"//lib/tonic",
]
}
2 changes: 1 addition & 1 deletion lib/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ source_set("ui") {
]

deps = [
"//flutter/common",
"//flutter/flow",
"//flutter/glue",
"//flutter/skia",
"//flutter/tonic",
"//lib/tonic",
"//lib/tonic/mojo",
]
Expand Down
46 changes: 17 additions & 29 deletions lib/ui/painting/image_decoding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

#include "flutter/lib/ui/painting/image_decoding.h"

#include "flutter/common/threads.h"
#include "flutter/flow/texture_image.h"
#include "flutter/glue/drain_data_pipe_job.h"
#include "flutter/glue/movable_wrapper.h"
#include "flutter/glue/trace_event.h"
#include "flutter/lib/ui/painting/image.h"
#include "flutter/lib/ui/painting/resource_context.h"
#include "flutter/tonic/dart_state.h"
#include "lib/ftl/tasks/task_runner.h"
#include "lib/tonic/dart_persistent_value.h"
#include "lib/tonic/dart_state.h"
#include "lib/tonic/logging/dart_invoke.h"
#include "lib/tonic/mojo/mojo_converter.h"
#include "lib/tonic/typed_data/uint8_list.h"
Expand Down Expand Up @@ -73,11 +73,10 @@ void InvokeImageCallback(sk_sp<SkImage> image,
}

void DecodeImageAndInvokeImageCallback(
ftl::RefPtr<ftl::TaskRunner> task_runner,
glue::MovableWrapper<std::unique_ptr<DartPersistentValue>> callback,
std::vector<char> buffer) {
sk_sp<SkImage> image = DecodeImage(std::move(buffer));
task_runner->PostTask([callback, image]() mutable {
Threads::UI()->PostTask([callback, image]() mutable {
InvokeImageCallback(image, callback.Unwrap());
});
}
Expand All @@ -99,23 +98,17 @@ void DecodeImageFromDataPipe(Dart_NativeArguments args) {
return;
}

DartState* dart_state = DartState::Current();
ftl::RefPtr<ftl::TaskRunner> task_runner = dart_state->ui_task_runner();

auto callback = glue::WrapMovable(std::unique_ptr<DartPersistentValue>(
new DartPersistentValue(dart_state, callback_handle)));

dart_state->io_task_runner()->PostTask(
[task_runner, callback, consumer]() mutable {
glue::DrainDataPipeJob* job = nullptr;
job = new glue::DrainDataPipeJob(
consumer.Unwrap(),
[task_runner, callback, job](std::vector<char> buffer) {
delete job;
DecodeImageAndInvokeImageCallback(task_runner, callback,
std::move(buffer));
});
});
new DartPersistentValue(tonic::DartState::Current(), callback_handle)));

Threads::IO()->PostTask([callback, consumer]() mutable {
glue::DrainDataPipeJob* job = nullptr;
job = new glue::DrainDataPipeJob(
consumer.Unwrap(), [callback, job](std::vector<char> buffer) {
delete job;
DecodeImageAndInvokeImageCallback(callback, std::move(buffer));
});
});
}

void DecodeImageFromList(Dart_NativeArguments args) {
Expand All @@ -134,21 +127,16 @@ void DecodeImageFromList(Dart_NativeArguments args) {
return;
}

DartState* dart_state = DartState::Current();
ftl::RefPtr<ftl::TaskRunner> task_runner = dart_state->ui_task_runner();

auto callback = glue::WrapMovable(std::unique_ptr<DartPersistentValue>(
new DartPersistentValue(dart_state, callback_handle)));
new DartPersistentValue(tonic::DartState::Current(), callback_handle)));

const char* bytes = reinterpret_cast<const char*>(list.data());
auto buffer = glue::WrapMovable(std::unique_ptr<std::vector<char>>(
new std::vector<char>(bytes, bytes + list.num_elements())));

dart_state->io_task_runner()->PostTask(
[task_runner, callback, buffer]() mutable {
DecodeImageAndInvokeImageCallback(task_runner, callback,
std::move(*buffer.Unwrap()));
});
Threads::IO()->PostTask([callback, buffer]() mutable {
DecodeImageAndInvokeImageCallback(callback, std::move(*buffer.Unwrap()));
});
}

} // namespace
Expand Down
1 change: 0 additions & 1 deletion sky/engine/bindings/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ source_set("bindings") {
"//dart/runtime/bin:embedded_dart_io",
"//flutter/assets",
"//flutter/lib/ui",
"//flutter/tonic",
"//lib/tonic",
"//mojo/public/c/system",
"//mojo/public/cpp/application",
Expand Down
8 changes: 4 additions & 4 deletions sky/engine/bindings/dart_runtime_hooks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@
#include "dart/runtime/bin/embedded_dart_io.h"
#include "dart/runtime/include/dart_api.h"
#include "dart/runtime/include/dart_tools_api.h"
#include "lib/tonic/dart_library_natives.h"
#include "flutter/tonic/dart_state.h"
#include "flutter/sky/engine/core/script/ui_dart_state.h"
#include "flutter/sky/engine/wtf/text/WTFString.h"
#include "lib/ftl/logging.h"
#include "lib/tonic/converter/dart_converter.h"
#include "lib/tonic/dart_library_natives.h"
#include "lib/tonic/dart_microtask_queue.h"
#include "lib/tonic/dart_state.h"
#include "lib/tonic/logging/dart_error.h"
#include "lib/tonic/logging/dart_invoke.h"
#include "lib/tonic/scopes/dart_api_scope.h"
#include "lib/tonic/scopes/dart_isolate_scope.h"
#include "flutter/sky/engine/core/script/ui_dart_state.h"
#include "flutter/sky/engine/wtf/text/WTFString.h"

#if defined(OS_ANDROID)
#include <android/log.h>
Expand Down
8 changes: 3 additions & 5 deletions sky/engine/bindings/flutter_dart_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include <string>

#include "dart/runtime/include/dart_api.h"
#include "flutter/tonic/dart_state.h"
#include "lib/ftl/build_config.h"
#include "lib/tonic/dart_persistent_value.h"
#include "lib/tonic/dart_state.h"

namespace blink {

Expand All @@ -25,7 +25,7 @@ class IsolateClient {
virtual ~IsolateClient();
};

class FlutterDartState : public DartState {
class FlutterDartState : public tonic::DartState {
public:
FlutterDartState* CreateForChildIsolate();
~FlutterDartState() override;
Expand All @@ -37,9 +37,7 @@ class FlutterDartState : public DartState {

static FlutterDartState* Current();

Dart_Port main_port() const {
return main_port_;
}
Dart_Port main_port() const { return main_port_; }

void set_mojo_services(std::unique_ptr<MojoServices> mojo_services);
MojoServices* mojo_services();
Expand Down
8 changes: 5 additions & 3 deletions sky/engine/bindings/mojo_services.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

#include "flutter/sky/engine/bindings/mojo_services.h"

#include "flutter/sky/engine/bindings/flutter_dart_state.h"
#include "lib/tonic/converter/dart_converter.h"
#include "lib/tonic/logging/dart_error.h"
#include "lib/tonic/dart_library_natives.h"
#include "flutter/tonic/dart_state.h"
#include "lib/tonic/dart_state.h"
#include "lib/tonic/logging/dart_error.h"
#include "mojo/public/cpp/application/connect.h"
#include "mojo/public/cpp/bindings/array.h"
#include "flutter/sky/engine/bindings/flutter_dart_state.h"

using tonic::DartState;

namespace blink {
namespace {
Expand Down
2 changes: 1 addition & 1 deletion sky/engine/core/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ visibility = [ "//flutter/sky/engine/*", "//flutter/sky/shell/*" ]
source_set("libraries") {
public_deps = [
"//base",
"//flutter/common",
"//flutter/flow",
"//flutter/glue",
"//flutter/lib/io",
"//flutter/lib/ui",
"//flutter/tonic",
"//lib/ftl",
"//lib/tonic",
"//lib/tonic/debugger",
Expand Down
Loading

0 comments on commit f8d80c4

Please sign in to comment.