From f9ccc371b954488acf030ba4e031570489340ebe Mon Sep 17 00:00:00 2001 From: Jason Simmons Date: Fri, 27 Oct 2017 11:53:00 -0700 Subject: [PATCH] Remove the diagnostic server (includes Dart roll) (flutter/engine#4287) --- DEPS | 2 +- engine/src/flutter/common/settings.h | 2 - engine/src/flutter/shell/common/BUILD.gn | 13 -- .../common/diagnostic/diagnostic_server.cc | 159 ------------------ .../common/diagnostic/diagnostic_server.dart | 63 ------- .../common/diagnostic/diagnostic_server.h | 23 --- engine/src/flutter/shell/common/shell.cc | 22 --- engine/src/flutter/shell/common/switches.h | 10 +- 8 files changed, 2 insertions(+), 292 deletions(-) delete mode 100644 engine/src/flutter/shell/common/diagnostic/diagnostic_server.cc delete mode 100644 engine/src/flutter/shell/common/diagnostic/diagnostic_server.dart delete mode 100644 engine/src/flutter/shell/common/diagnostic/diagnostic_server.h diff --git a/DEPS b/DEPS index d742b5da7b..6c87af7f00 100644 --- a/DEPS +++ b/DEPS @@ -31,7 +31,7 @@ vars = { # Dart is: https://github.com/dart-lang/sdk/blob/master/DEPS. # You can use //tools/dart/create_updated_flutter_deps.py to produce # updated revision list of existing dependencies. - 'dart_revision': 'b6d7ad59dc5bb996d40726977f5798172e503bce', + 'dart_revision': '16d4e9606f8186fb81886c34fca02b95ffcc09b9', 'dart_args_tag': '0.13.7', 'dart_async_tag': '2.0.0', diff --git a/engine/src/flutter/common/settings.h b/engine/src/flutter/common/settings.h index 0846264f72..5a937b6f57 100644 --- a/engine/src/flutter/common/settings.h +++ b/engine/src/flutter/common/settings.h @@ -17,8 +17,6 @@ struct Settings { // 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 enable_diagnostic = false; - uint32_t diagnostic_port = 0; bool ipv6 = false; bool start_paused = false; bool trace_startup = false; diff --git a/engine/src/flutter/shell/common/BUILD.gn b/engine/src/flutter/shell/common/BUILD.gn index ad23fe9e3c..e1008b7b72 100644 --- a/engine/src/flutter/shell/common/BUILD.gn +++ b/engine/src/flutter/shell/common/BUILD.gn @@ -55,22 +55,10 @@ template("dart_embedder_resources") { } } -dart_embedder_resources("generate_embedder_diagnostic_server_resources_cc") { - inputs = [ - "$flutter_root/shell/common/diagnostic/diagnostic_server.dart", - ] - root_prefix = "$flutter_root/shell/common/diagnostic/" - output = "$target_gen_dir/embedder_diagnostic_server_resources.cc" - table_name = "sky_embedder_diagnostic_server" -} - source_set("common") { sources = [ - "$target_gen_dir/embedder_diagnostic_server_resources.cc", "animator.cc", "animator.h", - "diagnostic/diagnostic_server.cc", - "diagnostic/diagnostic_server.h", "engine.cc", "engine.h", "null_rasterizer.cc", @@ -100,7 +88,6 @@ source_set("common") { ] deps = [ - ":generate_embedder_diagnostic_server_resources_cc", "//third_party/dart/runtime:dart_api", "//third_party/dart/runtime/platform:libdart_platform", "$flutter_root/assets", diff --git a/engine/src/flutter/shell/common/diagnostic/diagnostic_server.cc b/engine/src/flutter/shell/common/diagnostic/diagnostic_server.cc deleted file mode 100644 index 3a6588c191..0000000000 --- a/engine/src/flutter/shell/common/diagnostic/diagnostic_server.cc +++ /dev/null @@ -1,159 +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. - -#include "flutter/shell/common/diagnostic/diagnostic_server.h" - -#include "flutter/common/threads.h" -#include "flutter/flow/compositor_context.h" -#include "flutter/runtime/dart_init.h" -#include "flutter/runtime/embedder_resources.h" -#include "flutter/shell/common/engine.h" -#include "flutter/shell/common/picture_serializer.h" -#include "flutter/shell/common/rasterizer.h" -#include "flutter/shell/common/shell.h" -#include "lib/fxl/logging.h" -#include "lib/tonic/dart_binding_macros.h" -#include "lib/tonic/dart_library_natives.h" -#include "lib/tonic/logging/dart_invoke.h" -#include "third_party/dart/runtime/include/dart_api.h" -#include "third_party/dart/runtime/include/dart_native_api.h" -#include "third_party/skia/include/core/SkStream.h" - -namespace flutter { -namespace runtime { -extern ResourcesEntry __sky_embedder_diagnostic_server_resources_[]; -} -} // namespace flutter - -namespace shell { - -using blink::EmbedderResources; -using tonic::DartInvokeField; -using tonic::DartLibraryNatives; -using tonic::LogIfError; -using tonic::ToDart; - -namespace { - -DartLibraryNatives* g_natives = nullptr; - -constexpr char kDiagnosticServerScript[] = "/diagnostic_server.dart"; - -Dart_NativeFunction GetNativeFunction(Dart_Handle name, - int argument_count, - bool* auto_setup_scope) { - FXL_CHECK(g_natives); - return g_natives->GetNativeFunction(name, argument_count, auto_setup_scope); -} - -const uint8_t* GetSymbol(Dart_NativeFunction native_function) { - FXL_CHECK(g_natives); - return g_natives->GetSymbol(native_function); -} - -void SendNull(Dart_Port port_id) { - Dart_CObject null_object; - null_object.type = Dart_CObject_kNull; - Dart_PostCObject(port_id, &null_object); -} - -} // namespace - -DART_NATIVE_CALLBACK_STATIC(DiagnosticServer, HandleSkiaPictureRequest); - -void DiagnosticServer::Start(uint32_t port, bool ipv6) { - if (!g_natives) { - g_natives = new DartLibraryNatives(); - g_natives->Register({ - DART_REGISTER_NATIVE_STATIC(DiagnosticServer, HandleSkiaPictureRequest), - }); - } - - EmbedderResources resources( - &flutter::runtime::__sky_embedder_diagnostic_server_resources_[0]); - - Dart_Handle diagnostic_library; - if (blink::GetKernelPlatformBinary() != nullptr) { - diagnostic_library = - Dart_LookupLibrary(Dart_NewStringFromCString("dart:diagnostic_server")); - } else { - const char* source = nullptr; - int source_length = - resources.ResourceLookup(kDiagnosticServerScript, &source); - FXL_DCHECK(source_length != EmbedderResources::kNoSuchInstance); - - diagnostic_library = Dart_LoadLibrary( - Dart_NewStringFromCString("dart:diagnostic_server"), Dart_Null(), - Dart_NewStringFromUTF8(reinterpret_cast(source), - source_length), - 0, 0); - } - - FXL_CHECK(!LogIfError(diagnostic_library)); - FXL_CHECK(!LogIfError(Dart_SetNativeResolver(diagnostic_library, - GetNativeFunction, GetSymbol))); - - FXL_CHECK(!LogIfError(Dart_LibraryImportLibrary( - Dart_RootLibrary(), diagnostic_library, Dart_Null()))); - - FXL_CHECK(!LogIfError(Dart_FinalizeLoading(false))); - - DartInvokeField(Dart_RootLibrary(), "diagnosticServerStart", - {ToDart(port), ToDart(ipv6)}); -} - -void DiagnosticServer::HandleSkiaPictureRequest(Dart_Handle send_port) { - Dart_Port port_id; - FXL_CHECK(!LogIfError(Dart_SendPortGetId(send_port, &port_id))); - - blink::Threads::Gpu()->PostTask([port_id]() { SkiaPictureTask(port_id); }); -} - -void DiagnosticServer::SkiaPictureTask(Dart_Port port_id) { - std::vector> rasterizers; - Shell::Shared().GetRasterizers(&rasterizers); - if (rasterizers.size() != 1) { - SendNull(port_id); - return; - } - - Rasterizer* rasterizer = rasterizers[0].get(); - if (rasterizer == nullptr) { - SendNull(port_id); - return; - } - - flow::LayerTree* layer_tree = rasterizer->GetLastLayerTree(); - if (layer_tree == nullptr) { - SendNull(port_id); - return; - } - - SkPictureRecorder recorder; - recorder.beginRecording(SkRect::MakeWH(layer_tree->frame_size().width(), - layer_tree->frame_size().height())); - - flow::CompositorContext compositor_context(nullptr); - flow::CompositorContext::ScopedFrame frame = compositor_context.AcquireFrame( - nullptr, recorder.getRecordingCanvas(), false); - layer_tree->Raster(frame); - - sk_sp picture = recorder.finishRecordingAsPicture(); - - SkDynamicMemoryWStream stream; - PngPixelSerializer serializer; - picture->serialize(&stream, &serializer); - sk_sp picture_data(stream.detachAsData()); - - Dart_CObject c_object; - c_object.type = Dart_CObject_kTypedData; - c_object.value.as_typed_data.type = Dart_TypedData_kUint8; - c_object.value.as_typed_data.values = - const_cast(picture_data->bytes()); - c_object.value.as_typed_data.length = picture_data->size(); - - Dart_PostCObject(port_id, &c_object); -} - -} // namespace shell diff --git a/engine/src/flutter/shell/common/diagnostic/diagnostic_server.dart b/engine/src/flutter/shell/common/diagnostic/diagnostic_server.dart deleted file mode 100644 index 4b13f4e8b1..0000000000 --- a/engine/src/flutter/shell/common/diagnostic/diagnostic_server.dart +++ /dev/null @@ -1,63 +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. - -library diagnostic_server; - -import 'dart:io'; -import 'dart:isolate'; -import 'dart:typed_data'; - -void handleSkiaPictureRequest(SendPort sendPort) - native 'DiagnosticServer_HandleSkiaPictureRequest'; - -void diagnosticServerStart(int port, [bool ipv6 = false]) { - InternetAddress address = ipv6 - ? InternetAddress.LOOPBACK_IP_V6 - : InternetAddress.LOOPBACK_IP_V4; - HttpServer.bind(address, port).then((HttpServer server) { - server.listen(dispatchRequest, cancelOnError: true); - - String ip = address.address; - String port = server.port.toString(); - String url = ipv6 ? 'http://[$ip]:$port/' : 'http://$ip:$port/'; - print('Diagnostic server listening on $url'); - }); -} - -void sendError(HttpResponse response, String error) { - response.statusCode = HttpStatus.INTERNAL_SERVER_ERROR; - response.headers.contentType = ContentType.TEXT; - response.write(error); -} - -void dispatchRequest(HttpRequest request) { - HttpResponse response = request.response; - - try { - if (request.uri.path == '/skp') { - ReceivePort port = new ReceivePort(); - port.first.then((Uint8List data) => onReceiveSkiaPicture(response, data)); - handleSkiaPictureRequest(port.sendPort); - return; - } - - sendError(response, 'Diagnostic server: unexpected request, uri=${request.uri}'); - } catch (e) { - sendError(response, 'Diagnostic server: error processing request, uri=${request.uri}\n${e}'); - } - - response.close(); -} - -void onReceiveSkiaPicture(HttpResponse response, Uint8List data) { - if (data != null) { - response.statusCode = HttpStatus.OK; - response.headers.contentType = ContentType.BINARY; - response.headers.contentLength = data.length; - response.add(data); - } else { - sendError(response, 'Unable to capture Skia picture'); - } - response.close(); -} diff --git a/engine/src/flutter/shell/common/diagnostic/diagnostic_server.h b/engine/src/flutter/shell/common/diagnostic/diagnostic_server.h deleted file mode 100644 index 9149d2ea10..0000000000 --- a/engine/src/flutter/shell/common/diagnostic/diagnostic_server.h +++ /dev/null @@ -1,23 +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. - -#ifndef SKY_ENGINE_CORE_DIAGNOSTIC_DIAGNOSTIC_SERVER_H_ -#define SKY_ENGINE_CORE_DIAGNOSTIC_DIAGNOSTIC_SERVER_H_ - -#include "third_party/dart/runtime/include/dart_api.h" - -namespace shell { - -class DiagnosticServer { - public: - static void Start(uint32_t port, bool ipv6); - static void HandleSkiaPictureRequest(Dart_Handle send_port); - - private: - static void SkiaPictureTask(Dart_Port port_id); -}; - -} // namespace shell - -#endif // SKY_ENGINE_CORE_DIAGNOSTIC_DIAGNOSTIC_SERVER_H_ diff --git a/engine/src/flutter/shell/common/shell.cc b/engine/src/flutter/shell/common/shell.cc index c673c7a442..f734fe7572 100644 --- a/engine/src/flutter/shell/common/shell.cc +++ b/engine/src/flutter/shell/common/shell.cc @@ -15,7 +15,6 @@ #include "flutter/fml/message_loop.h" #include "flutter/fml/trace_event.h" #include "flutter/runtime/dart_init.h" -#include "flutter/shell/common/diagnostic/diagnostic_server.h" #include "flutter/shell/common/engine.h" #include "flutter/shell/common/platform_view_service_protocol.h" #include "flutter/shell/common/skia_event_tracer_impl.h" @@ -57,14 +56,6 @@ bool GetSwitchValue(const fxl::CommandLine& command_line, return false; } -void ServiceIsolateHook(bool running_precompiled) { - if (!running_precompiled) { - const blink::Settings& settings = blink::Settings::Get(); - if (settings.enable_diagnostic) - DiagnosticServer::Start(settings.diagnostic_port, settings.ipv6); - } -} - } // namespace Shell::Shell(fxl::CommandLine command_line) @@ -87,7 +78,6 @@ Shell::Shell(fxl::CommandLine command_line) blink::Threads::Gpu()->PostTask([this]() { InitGpuThread(); }); blink::Threads::UI()->PostTask([this]() { InitUIThread(); }); - blink::SetServiceIsolateHook(ServiceIsolateHook); blink::SetRegisterNativeServiceProtocolExtensionHook( PlatformViewServiceProtocol::RegisterHook); } @@ -125,18 +115,6 @@ void Shell::InitStandalone(fxl::CommandLine command_line, settings.dart_non_checked_mode = command_line.HasOption(FlagForSwitch(Switch::DartNonCheckedMode)); - settings.enable_diagnostic = - !command_line.HasOption(FlagForSwitch(Switch::DisableDiagnostic)); - - if (command_line.HasOption(FlagForSwitch(Switch::DeviceDiagnosticPort))) { - if (!GetSwitchValue(command_line, Switch::DeviceDiagnosticPort, - &settings.diagnostic_port)) { - FXL_LOG(INFO) - << "Diagnostic port specified was malformed. Will default to " - << settings.diagnostic_port; - } - } - settings.ipv6 = command_line.HasOption(FlagForSwitch(Switch::IPv6)); settings.start_paused = diff --git a/engine/src/flutter/shell/common/switches.h b/engine/src/flutter/shell/common/switches.h index a47471be91..176e0b1e9c 100644 --- a/engine/src/flutter/shell/common/switches.h +++ b/engine/src/flutter/shell/common/switches.h @@ -39,17 +39,9 @@ DEF_SWITCH(DisableObservatory, "disable-observatory", "Disable the Dart Observatory. The observatory is never available " "in release mode.") -DEF_SWITCH(DeviceDiagnosticPort, - "diagnostic-port", - "A custom diagnostic server port.") -DEF_SWITCH(DisableDiagnostic, - "disable-diagnostic", - "Disable the diagnostic server. The diagnostic server is never " - "available in release mode.") DEF_SWITCH(IPv6, "ipv6", - "Bind to the IPv6 localhost address for the Dart Observatory and " - "the diagnostic server.") + "Bind to the IPv6 localhost address for the Dart Observatory.") DEF_SWITCH(EnableDartProfiling, "enable-dart-profiling", "Enable Dart profiling. Profiling information can be viewed from "