Skip to content

Commit

Permalink
Update the content handler to use the Mozart session API. (flutter#3887)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored and Jeff Brown committed Jul 18, 2017
1 parent d098b35 commit 925298d
Show file tree
Hide file tree
Showing 67 changed files with 2,183 additions and 1,663 deletions.
9 changes: 9 additions & 0 deletions common/threads.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

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

#define ASSERT_IS_PLATFORM_THREAD \
FTL_DCHECK(::blink::Threads::Platform()->RunsTasksOnCurrentThread());
#define ASSERT_IS_GPU_THREAD \
FTL_DCHECK(::blink::Threads::Gpu()->RunsTasksOnCurrentThread());
#define ASSERT_IS_UI_THREAD \
FTL_DCHECK(::blink::Threads::UI()->RunsTasksOnCurrentThread());
#define ASSERT_IS_IO_THREAD \
FTL_DCHECK(::blink::Threads::IO()->RunsTasksOnCurrentThread());

namespace blink {

class Threads {
Expand Down
102 changes: 38 additions & 64 deletions content_handler/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ assert(is_fuchsia)

import("//build/vulkan/config.gni")

declare_args() {
flutter_enable_vulkan = fuchsia_use_vulkan
flutter_use_vulkan_native_surface = false
}

template("flutter_content_handler") {
invoker_output_name = invoker.output_name
extra_deps = invoker.extra_deps
Expand All @@ -27,82 +22,61 @@ template("flutter_content_handler") {
"app.h",
"application_controller_impl.cc",
"application_controller_impl.h",
"content_handler_thread.cc",
"content_handler_thread.h",
"main.cc",
"rasterizer.cc",
"rasterizer.h",
"runtime_holder.cc",
"runtime_holder.h",
"service_protocol_hooks.cc",
"service_protocol_hooks.h",
"software_rasterizer.cc",
"software_rasterizer.h",
"session_connection.cc",
"session_connection.h",
"vulkan_rasterizer.cc",
"vulkan_rasterizer.h",
"vulkan_surface.cc",
"vulkan_surface.h",
"vulkan_surface_pool.cc",
"vulkan_surface_pool.h",
"vulkan_surface_producer.cc",
"vulkan_surface_producer.h",
]

deps = [
"//application/lib/app",
"//application/lib/svc",
"//apps/icu_data/lib",
"//apps/mozart/lib/flutter/sdk_ext",
"//apps/mozart/lib/skia:vmo",
"//apps/mozart/services/buffers",
"//apps/mozart/services/buffers/cpp",
"//apps/mozart/services/composition",
"//apps/mozart/services/input",
"//apps/mozart/services/views",
"//apps/tracing/lib/trace:provider",

# TODO(abarth): We shouldn't need to depend on libdart_builtin but we fail
# to link otherwise.
"//dart/runtime/bin:libdart_builtin",
"//dart/runtime/vm:libdart_platform",
"//flutter/assets",
"//flutter/common",
"//flutter/flow",
"//flutter/glue",
"//flutter/lib/ui",
"//flutter/runtime",
"//flutter/sky/engine/platform",
"//lib/fidl/dart/sdk_ext",
"//lib/ftl",
"//lib/mtl",
"//lib/tonic/mx",
"//lib/zip",
"//third_party/rapidjson",
"//third_party/skia",
]
deps += extra_deps

if (flutter_enable_vulkan) {
defines += [ "FLUTTER_ENABLE_VULKAN=1" ]

if (flutter_use_vulkan_native_surface) {
defines += [ "FLUTTER_USE_VULKAN_NATIVE_SURFACE=1" ]
sources += [
"vulkan_native_rasterizer.cc",
"vulkan_native_rasterizer.h",
]
libs += [ "hid" ]
} else {
sources += [
"vulkan_rasterizer.cc",
"vulkan_rasterizer.h",
]
}

deps += [
"//flutter/vulkan",
"//magma:vulkan",
]
}
"//application/lib/app",
"//application/lib/svc",
"//apps/icu_data/lib",
"//apps/mozart/lib/flutter/sdk_ext",
"//apps/mozart/lib/scene:client",
"//apps/mozart/services/input",
"//apps/mozart/services/views",
"//apps/tracing/lib/trace:provider",
"//dart/runtime/bin:libdart_builtin",
"//dart/runtime/vm:libdart_platform",
"//flutter/assets",
"//flutter/common",
"//flutter/flow",
"//flutter/glue",
"//flutter/lib/ui",
"//flutter/runtime",
"//flutter/sky/engine/platform",
"//flutter/vulkan",
"//lib/fidl/dart/sdk_ext",
"//lib/ftl",
"//lib/mtl",
"//lib/tonic/mx",
"//lib/zip",
"//magma:vulkan",
"//third_party/rapidjson",
"//third_party/skia",
] + extra_deps

# The flags below are needed so that Dart's CPU profiler can walk the
# C++ stack.
cflags = [
"-mno-omit-leaf-frame-pointer",
"-fno-omit-frame-pointer",
]

# This flag is needed so that the call to dladdr() in Dart's native symbol
# resolver can report good symbol information for the CPU profiler.
ldflags = [ "-rdynamic" ]
Expand Down
11 changes: 7 additions & 4 deletions content_handler/app.cc
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,14 @@ App::App() {

tracing::InitializeTracer(context_.get(), {});

gpu_thread_ = std::make_unique<Thread>();
io_thread_ = std::make_unique<Thread>();
gpu_thread_ = std::make_unique<mtl::Thread>();
io_thread_ = std::make_unique<mtl::Thread>();

FTL_CHECK(gpu_thread_->IsValid()) << "Must be able to create the GPU thread";
FTL_CHECK(io_thread_->IsValid()) << "Must be able to create the IO thread";
auto gpu_thread_success = gpu_thread_->Run();
auto io_thread_success = io_thread_->Run();

FTL_CHECK(gpu_thread_success) << "Must be able to create the GPU thread";
FTL_CHECK(io_thread_success) << "Must be able to create the IO thread";

auto ui_task_runner = mtl::MessageLoop::GetCurrent()->task_runner();
auto gpu_task_runner = gpu_thread_->TaskRunner();
Expand Down
18 changes: 9 additions & 9 deletions content_handler/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "application/lib/app/application_context.h"
#include "application/services/application_runner.fidl.h"
#include "flutter/content_handler/application_controller_impl.h"
#include "flutter/content_handler/content_handler_thread.h"
#include "lib/ftl/macros.h"
#include "lib/ftl/synchronization/waitable_event.h"
#include "lib/mtl/threading/thread.h"

namespace flutter_runner {

Expand All @@ -26,10 +26,10 @@ class App : public app::ApplicationRunner {

// |app::ApplicationRunner| implementation:

void StartApplication(app::ApplicationPackagePtr application,
app::ApplicationStartupInfoPtr startup_info,
fidl::InterfaceRequest<app::ApplicationController>
controller) override;
void StartApplication(
app::ApplicationPackagePtr application,
app::ApplicationStartupInfoPtr startup_info,
fidl::InterfaceRequest<app::ApplicationController> controller) override;

void Destroy(ApplicationControllerImpl* controller);

Expand All @@ -43,13 +43,13 @@ class App : public app::ApplicationRunner {

private:
void WaitForPlatformViewsIdsUIThread(
std::vector<PlatformViewInfo>* platform_view_ids,
ftl::AutoResetWaitableEvent* latch);
std::vector<PlatformViewInfo>* platform_view_ids,
ftl::AutoResetWaitableEvent* latch);
void UpdateProcessLabel();

std::unique_ptr<app::ApplicationContext> context_;
std::unique_ptr<Thread> gpu_thread_;
std::unique_ptr<Thread> io_thread_;
std::unique_ptr<mtl::Thread> gpu_thread_;
std::unique_ptr<mtl::Thread> io_thread_;
fidl::BindingSet<app::ApplicationRunner> runner_bindings_;
std::unordered_map<ApplicationControllerImpl*,
std::unique_ptr<ApplicationControllerImpl>>
Expand Down
89 changes: 0 additions & 89 deletions content_handler/content_handler_thread.cc

This file was deleted.

48 changes: 0 additions & 48 deletions content_handler/content_handler_thread.h

This file was deleted.

28 changes: 2 additions & 26 deletions content_handler/rasterizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,17 @@
// found in the LICENSE file.

#include "flutter/content_handler/rasterizer.h"

#include "flutter/content_handler/software_rasterizer.h"

#if FLUTTER_ENABLE_VULKAN
#if FLUTTER_USE_VULKAN_NATIVE_SURFACE
#include "flutter/content_handler/vulkan_native_rasterizer.h"
#else // FLUTTER_USE_VULKAN_NATIVE_SURFACE
#include "flutter/content_handler/vulkan_rasterizer.h"
#endif // FLUTTER_USE_VULKAN_NATIVE_SURFACE
#endif // FLUTTER_ENABLE_VULKAN

namespace flutter_runner {

Rasterizer::~Rasterizer() = default;

std::unique_ptr<Rasterizer> Rasterizer::Create() {
#if FLUTTER_ENABLE_VULKAN
#if FLUTTER_USE_VULKAN_NATIVE_SURFACE
auto vulkan_rasterizer = std::make_unique<VulkanNativeRasterizer>();
#else // FLUTTER_USE_VULKAN_NATIVE_SURFACE
auto vulkan_rasterizer = std::make_unique<VulkanRasterizer>();
#endif // FLUTTER_USE_VULKAN_NATIVE_SURFACE

if (!vulkan_rasterizer->IsValid()) {
FTL_DLOG(INFO) << "Could not initialize a valid vulkan rasterizer. "
"Attempting to fallback to the software rasterizer.";
return std::make_unique<SoftwareRasterizer>();
}

FTL_DLOG(INFO) << "Successfully initialized a valid vulkan rasterizer.";

FTL_CHECK(vulkan_rasterizer)
<< "The vulkan rasterizer must be correctly initialized.";
return vulkan_rasterizer;
#else // FLUTTER_ENABLE_VULKAN
return std::make_unique<SoftwareRasterizer>();
#endif // FLUTTER_ENABLE_VULKAN
}

} // namespace flutter_runner
Loading

0 comments on commit 925298d

Please sign in to comment.