Finish removing //flutter/tonic (flutter/engine#2917)

This pulled a refactoring of how we keep track of the primary threads.
This commit is contained in:
Adam Barth
2016-08-12 12:05:48 -07:00
committed by GitHub
parent cbb28cb25d
commit 6b0e5e85a4
13 changed files with 186 additions and 116 deletions

View File

@@ -13,7 +13,7 @@ group("flutter") {
"//flutter/glue",
"//flutter/lib/ui",
"//flutter/snapshotter",
"//flutter/tonic",
"//lib/tonic",
]
} else {
deps = [

View File

@@ -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",
]
}

View File

@@ -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.

View File

@@ -0,0 +1,29 @@
// 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/settings.h"
#include <memory>
#include "lib/ftl/logging.h"
namespace blink {
namespace {
Settings* g_settings = nullptr;
} // namespace
const Settings& Settings::Get() {
FTL_CHECK(g_settings);
return *g_settings;
}
void Settings::Set(const Settings& settings) {
FTL_CHECK(!g_settings);
g_settings = new Settings();
*g_settings = settings;
}
} // namespace blink

View File

@@ -0,0 +1,33 @@
// 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_SETTINGS_H_
#define FLUTTER_COMMON_SETTINGS_H_
#include <stdint.h>
#include <string>
#include <vector>
namespace blink {
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.
uint32_t observatory_port = 0;
bool start_paused = false;
bool enable_dart_checked_mode = false;
bool trace_startup = false;
std::string aot_snapshot_path;
std::string temp_directory_path;
std::vector<std::string> dart_flags;
static const Settings& Get();
static void Set(const Settings& settings);
};
} // namespace blink
#endif // FLUTTER_COMMON_SETTINGS_H_

View File

@@ -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

View File

@@ -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_

View File

@@ -20,6 +20,6 @@ source_set("jni") {
deps = [
"//base",
"//flutter/tonic",
"//lib/tonic",
]
}

View File

@@ -41,10 +41,10 @@ source_set("ui") {
]
deps = [
"//flutter/common",
"//flutter/flow",
"//flutter/glue",
"//flutter/skia",
"//flutter/tonic",
"//lib/tonic",
"//lib/tonic/mojo",
]

View File

@@ -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"
@@ -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());
});
}
@@ -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)));
new DartPersistentValue(tonic::DartState::Current(), 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));
});
});
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) {
@@ -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

View File

@@ -1,21 +0,0 @@
# 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("tonic") {
sources = [
"dart_state.cc",
"dart_state.h",
]
deps = [
"//dart/runtime/bin:embedded_dart_io",
"//lib/ftl",
]
public_deps = [
"//dart/runtime:libdart",
"//dart/runtime/vm:libdart_platform",
"//lib/tonic",
]
}

View File

@@ -1,21 +0,0 @@
// Copyright 2015 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/tonic/dart_state.h"
namespace blink {
DartState::DartState() {}
DartState::~DartState() {}
DartState* DartState::From(Dart_Isolate isolate) {
return static_cast<DartState*>(tonic::DartState::From(isolate));
}
DartState* DartState::Current() {
return static_cast<DartState*>(tonic::DartState::Current());
}
} // namespace blink

View File

@@ -1,43 +0,0 @@
// Copyright 2015 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_TONIC_DART_STATE_H_
#define FLUTTER_TONIC_DART_STATE_H_
#include <utility>
#include "dart/runtime/include/dart_api.h"
#include "lib/ftl/tasks/task_runner.h"
#include "lib/tonic/dart_persistent_value.h"
#include "lib/tonic/dart_state.h"
#include "lib/tonic/scopes/dart_api_scope.h"
#include "lib/tonic/scopes/dart_isolate_scope.h"
namespace blink {
class DartState : public tonic::DartState {
public:
DartState();
virtual ~DartState();
static DartState* From(Dart_Isolate isolate);
static DartState* Current();
const ftl::RefPtr<ftl::TaskRunner>& ui_task_runner() {
return ui_task_runner_;
}
const ftl::RefPtr<ftl::TaskRunner>& io_task_runner() {
return io_task_runner_;
}
protected:
ftl::RefPtr<ftl::TaskRunner> ui_task_runner_;
ftl::RefPtr<ftl::TaskRunner> io_task_runner_;
FTL_DISALLOW_COPY_AND_ASSIGN(DartState);
};
} // namespace blink
#endif // FLUTTER_TONIC_DART_STATE_H_