Remove the diagnostic server (includes Dart roll) (flutter/engine#4287)

This commit is contained in:
Jason Simmons
2017-10-27 11:53:00 -07:00
committed by GitHub
parent 826b91ceae
commit f9ccc371b9
8 changed files with 2 additions and 292 deletions

2
DEPS
View File

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

View File

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

View File

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

View File

@@ -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<const uint8_t*>(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<fxl::WeakPtr<Rasterizer>> 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<SkPicture> picture = recorder.finishRecordingAsPicture();
SkDynamicMemoryWStream stream;
PngPixelSerializer serializer;
picture->serialize(&stream, &serializer);
sk_sp<SkData> 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<uint8_t*>(picture_data->bytes());
c_object.value.as_typed_data.length = picture_data->size();
Dart_PostCObject(port_id, &c_object);
}
} // namespace shell

View File

@@ -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();
}

View File

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

View File

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

View File

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