提交 4fa03ded 编写于 作者: A Adam Barth 提交者: GitHub

Remove //base dependencies from //sky/shell (#2888)

上级 11dbbd0b
......@@ -4,12 +4,10 @@
#include "sky/shell/diagnostic/diagnostic_server.h"
#include "base/bind.h"
#include "base/location.h"
#include "base/logging.h"
#include "dart/runtime/include/dart_api.h"
#include "dart/runtime/include/dart_native_api.h"
#include "flow/compositor_context.h"
#include "lib/ftl/logging.h"
#include "lib/tonic/dart_binding_macros.h"
#include "lib/tonic/dart_library_natives.h"
#include "lib/tonic/logging/dart_invoke.h"
......@@ -38,17 +36,17 @@ namespace {
DartLibraryNatives* g_natives = nullptr;
const char kDiagnosticServerScript[] = "/diagnostic_server.dart";
constexpr char kDiagnosticServerScript[] = "/diagnostic_server.dart";
Dart_NativeFunction GetNativeFunction(Dart_Handle name,
int argument_count,
bool* auto_setup_scope) {
CHECK(g_natives);
FTL_CHECK(g_natives);
return g_natives->GetNativeFunction(name, argument_count, auto_setup_scope);
}
const uint8_t* GetSymbol(Dart_NativeFunction native_function) {
CHECK(g_natives);
FTL_CHECK(g_natives);
return g_natives->GetSymbol(native_function);
}
......@@ -73,35 +71,35 @@ void DiagnosticServer::Start() {
EmbedderResources resources(
&mojo::dart::__sky_embedder_diagnostic_server_resources_[0]);
const char* source = NULL;
const char* source = nullptr;
int source_length =
resources.ResourceLookup(kDiagnosticServerScript, &source);
DCHECK(source_length != EmbedderResources::kNoSuchInstance);
FTL_DCHECK(source_length != EmbedderResources::kNoSuchInstance);
Dart_Handle diagnostic_library = Dart_LoadLibrary(
Dart_NewStringFromCString("dart:diagnostic_server"), Dart_Null(),
Dart_NewStringFromUTF8(reinterpret_cast<const uint8_t*>(source),
source_length),
0, 0);
CHECK(!LogIfError(diagnostic_library));
CHECK(!LogIfError(Dart_SetNativeResolver(diagnostic_library,
GetNativeFunction, GetSymbol)));
FTL_CHECK(!LogIfError(diagnostic_library));
FTL_CHECK(!LogIfError(Dart_SetNativeResolver(diagnostic_library,
GetNativeFunction, GetSymbol)));
CHECK(!LogIfError(Dart_LibraryImportLibrary(
FTL_CHECK(!LogIfError(Dart_LibraryImportLibrary(
Dart_RootLibrary(), diagnostic_library, Dart_Null())));
CHECK(!LogIfError(Dart_FinalizeLoading(false)));
FTL_CHECK(!LogIfError(Dart_FinalizeLoading(false)));
DartInvokeField(Dart_RootLibrary(), "diagnosticServerStart", {});
}
void DiagnosticServer::HandleSkiaPictureRequest(Dart_Handle send_port) {
Dart_Port port_id;
CHECK(!LogIfError(Dart_SendPortGetId(send_port, &port_id)));
FTL_CHECK(!LogIfError(Dart_SendPortGetId(send_port, &port_id)));
Shell::Shared().gpu_task_runner()->PostTask(
FROM_HERE, base::Bind(SkiaPictureTask, port_id));
Shell::Shared().gpu_ftl_task_runner()->PostTask(
[port_id]() { SkiaPictureTask(port_id); });
}
void DiagnosticServer::SkiaPictureTask(Dart_Port port_id) {
......
......@@ -5,7 +5,6 @@
#ifndef SKY_ENGINE_CORE_DIAGNOSTIC_DIAGNOSTIC_SERVER_H_
#define SKY_ENGINE_CORE_DIAGNOSTIC_DIAGNOSTIC_SERVER_H_
#include "base/memory/weak_ptr.h"
#include "dart/runtime/include/dart_api.h"
namespace sky {
......
......@@ -4,7 +4,8 @@
#include "sky/shell/gpu/direct/ganesh_canvas.h"
#include "base/logging.h"
#include "lib/ftl/arraysize.h"
#include "lib/ftl/logging.h"
#include "third_party/skia/include/gpu/gl/GrGLInterface.h"
namespace sky {
......@@ -55,7 +56,7 @@ bool GaneshCanvas::SelectPixelConfig(GrPixelConfig* config) {
}
SkCanvas* GaneshCanvas::GetCanvas(int32_t fbo, const SkISize& size) {
DCHECK(IsValid());
FTL_DCHECK(IsValid());
if (sk_surface_ && sk_surface_->width() == size.width() &&
sk_surface_->height() == size.height())
......@@ -64,16 +65,16 @@ SkCanvas* GaneshCanvas::GetCanvas(int32_t fbo, const SkISize& size) {
GrBackendRenderTargetDesc desc;
desc.fWidth = size.width();
desc.fHeight = size.height();
CHECK(SelectPixelConfig(&desc.fConfig));
FTL_CHECK(SelectPixelConfig(&desc.fConfig));
desc.fStencilBits = 8;
desc.fOrigin = kBottomLeft_GrSurfaceOrigin;
desc.fRenderTargetHandle = fbo;
sk_sp<GrRenderTarget> target(
gr_context_->textureProvider()->wrapBackendRenderTarget(desc));
DCHECK(target);
FTL_DCHECK(target);
sk_surface_ = SkSurface::MakeRenderTargetDirect(target.get(), nullptr);
DCHECK(sk_surface_);
FTL_DCHECK(sk_surface_);
return sk_surface_->getCanvas();
}
......
......@@ -4,7 +4,7 @@
#include "sky/shell/gpu/direct/rasterizer_direct.h"
#include "base/trace_event/trace_event.h"
#include "glue/trace_event.h"
#include "mojo/public/cpp/system/data_pipe.h"
#include "sky/engine/wtf/PassRefPtr.h"
#include "sky/engine/wtf/RefPtr.h"
......@@ -143,7 +143,7 @@ void RasterizerDirect::Draw(uint64_t layer_tree_ptr,
const auto& tracingController = Shell::Shared().tracing_controller();
if (frameExceededThreshold || tracingController.picture_tracing_enabled()) {
base::FilePath path = tracingController.PictureTracingPathForCurrentTime();
std::string path = tracingController.PictureTracingPathForCurrentTime();
SkPictureRecorder recoder;
recoder.beginRecording(SkRect::MakeWH(size.width(), size.height()));
......
......@@ -6,7 +6,7 @@
#include <MGL/mgl_echo.h>
#include "base/trace_event/trace_event.h"
#include "glue/trace_event.h"
#include "mojo/gpu/gl_texture.h"
#include "mojo/skia/ganesh_texture_surface.h"
#include "sky/shell/shell.h"
......
......@@ -27,8 +27,8 @@ SkData* PngPixelSerializer::onEncode(const SkPixmap& pixmap) {
SkImageEncoder::kDefaultQuality);
}
void SerializePicture(const base::FilePath& file_name, SkPicture* picture) {
SkFILEWStream stream(file_name.AsUTF8Unsafe().c_str());
void SerializePicture(const std::string& path, SkPicture* picture) {
SkFILEWStream stream(path.c_str());
PngPixelSerializer serializer;
picture->serialize(&stream, &serializer);
}
......
......@@ -5,7 +5,8 @@
#ifndef SKY_SHELL_GPU_PICTURE_SERIALIZER_H_
#define SKY_SHELL_GPU_PICTURE_SERIALIZER_H_
#include "base/files/file_path.h"
#include <string>
#include "third_party/skia/include/core/SkPicture.h"
#include "third_party/skia/include/core/SkPixelSerializer.h"
......@@ -17,7 +18,7 @@ class PngPixelSerializer : public SkPixelSerializer {
SkData* onEncode(const SkPixmap& pixmap) override;
};
void SerializePicture(const base::FilePath& file_name, SkPicture*);
void SerializePicture(const std::string& path, SkPicture* picture);
} // namespace sky
......
......@@ -50,9 +50,8 @@ void InitializeTracing() {
base::FilePath path;
bool result = ::PathService::Get(base::DIR_ANDROID_APP_DATA, &path);
DCHECK(result);
sky::shell::Shell::Shared()
.tracing_controller()
.set_traces_base_path(path);
sky::shell::Shell::Shared().tracing_controller().set_traces_base_path(
path.AsUTF8Unsafe());
}
} // namespace
......@@ -84,9 +83,11 @@ static void Init(JNIEnv* env,
InitializeTracing();
}
static void RecordStartTimestamp(JNIEnv* env, jclass jcaller,
jlong initTimeMillis) {
int64_t initTimeMicros = static_cast<int64_t>(initTimeMillis) * static_cast<int64_t>(1000);
static void RecordStartTimestamp(JNIEnv* env,
jclass jcaller,
jlong initTimeMillis) {
int64_t initTimeMicros =
static_cast<int64_t>(initTimeMillis) * static_cast<int64_t>(1000);
blink::engine_main_enter_ts = Dart_TimelineGetMicros() - initTimeMicros;
}
......
......@@ -110,11 +110,8 @@ void FlutterInit(int argc, const char* argv[]) {
- (void)setupTracing {
NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask, YES);
base::FilePath tracesPath =
base::FilePath::FromUTF8Unsafe([paths.firstObject UTF8String]);
sky::shell::Shell::Shared().tracing_controller().set_traces_base_path(
tracesPath);
[paths.firstObject UTF8String]);
}
- (void)setupNotificationCenterObservers {
......
......@@ -4,16 +4,19 @@
#include "sky/shell/platform_view_service_protocol.h"
#include <string.h>
#include <string>
#include "base/strings/string_util.h"
#include "sky/shell/shell.h"
namespace sky {
namespace shell {
namespace {
constexpr char kViewIdPrefx[] = "_flutterView/";
constexpr size_t kViewIdPrefxLength = sizeof(kViewIdPrefx) - 1;
static intptr_t KeyIndex(const char** param_keys,
intptr_t num_params,
const char* key) {
......@@ -39,8 +42,7 @@ static const char* ValueForKey(const char** param_keys,
return param_values[index];
}
static bool ErrorMissingParameter(const char** json_object,
const char* name) {
static bool ErrorMissingParameter(const char** json_object, const char* name) {
const intptr_t kInvalidParams = -32602;
std::stringstream response;
response << "{\"code\":" << std::to_string(kInvalidParams) << ",";
......@@ -63,8 +65,7 @@ static bool ErrorBadParameter(const char** json_object,
return false;
}
static bool ErrorUnknownView(const char** json_object,
const char* view_id) {
static bool ErrorUnknownView(const char** json_object, const char* view_id) {
const intptr_t kInvalidParams = -32602;
std::stringstream response;
response << "{\"code\":" << std::to_string(kInvalidParams) << ",";
......@@ -74,8 +75,7 @@ static bool ErrorUnknownView(const char** json_object,
return false;
}
static bool ErrorIsolateSpawn(const char** json_object,
const char* view_id) {
static bool ErrorIsolateSpawn(const char** json_object, const char* view_id) {
const intptr_t kInvalidParams = -32602;
std::stringstream response;
response << "{\"code\":" << std::to_string(kInvalidParams) << ",";
......@@ -86,18 +86,15 @@ static bool ErrorIsolateSpawn(const char** json_object,
return false;
}
} // namespace
} // namespace
void PlatformViewServiceProtocol::RegisterHook(bool running_precompiled_code) {
if (running_precompiled_code) {
return;
}
Dart_RegisterRootServiceRequestCallback(kRunInViewExtensionName,
&RunInView,
Dart_RegisterRootServiceRequestCallback(kRunInViewExtensionName, &RunInView,
nullptr);
Dart_RegisterRootServiceRequestCallback(kListViewsExtensionName,
&ListViews,
Dart_RegisterRootServiceRequestCallback(kListViewsExtensionName, &ListViews,
nullptr);
}
......@@ -121,7 +118,7 @@ bool PlatformViewServiceProtocol::RunInView(const char* method,
if (view_id == NULL) {
return ErrorMissingParameter(json_object, "viewId");
}
if (!base::StartsWithASCII(view_id, "_flutterView/", true)) {
if (strncmp(view_id, kViewIdPrefx, kViewIdPrefxLength) != 0) {
return ErrorBadParameter(json_object, "viewId", view_id);
}
if (asset_directory == NULL) {
......@@ -136,19 +133,15 @@ bool PlatformViewServiceProtocol::RunInView(const char* method,
// Convert the actual flutter view hex id into a number.
uintptr_t view_id_as_num =
std::stoull((view_id + strlen("_flutterView/")), nullptr, 16);
std::stoull((view_id + kViewIdPrefxLength), nullptr, 16);
// Ask the Shell to run this script in the specified view. This will run a
// task on the UI thread before returning.
Shell& shell = Shell::Shared();
bool view_existed = false;
Dart_Port main_port = ILLEGAL_PORT;
shell.RunInPlatformView(view_id_as_num,
main_script,
packages_file,
asset_directory,
&view_existed,
&main_port);
shell.RunInPlatformView(view_id_as_num, main_script, packages_file,
asset_directory, &view_existed, &main_port);
if (!view_existed) {
// If the view did not exist this request has definitely failed.
......@@ -159,12 +152,11 @@ bool PlatformViewServiceProtocol::RunInView(const char* method,
} else {
// The view existed and the isolate was created. Success.
std::stringstream response;
response << "{\"type\":\"Success\",";
response << "\"viewId\": \"_flutterView/";
response << "0x" << std::hex << view_id;
response << "\",";
response << "\"isolateId\": \"isolates/" << std::dec << main_port << "\"";
response << "}";
response << "{\"type\":\"Success\","
<< "\"viewId\": \"" << kViewIdPrefx << "0x" << std::hex << view_id
<< "\","
<< "\"isolateId\": \"isolates/" << std::dec << main_port << "\""
<< "}";
*json_object = strdup(response.str().c_str());
return true;
}
......@@ -201,11 +193,10 @@ bool PlatformViewServiceProtocol::ListViews(const char* method,
} else {
prefix_comma = true;
}
response << "{\"type\":\"FlutterView\", \"id\": \"_flutterView/";
response << "0x" << std::hex << view_id;
response << "\",";
response << "\"isolateId\": \"isolates/" << std::dec << isolate_id << "\"";
response << "}";
response << "{\"type\":\"FlutterView\", \"id\": \"" << kViewIdPrefx << "0x"
<< std::hex << view_id << "\","
<< "\"isolateId\": \"isolates/" << std::dec << isolate_id << "\""
<< "}";
}
response << "]}";
// Copy the response.
......
......@@ -5,7 +5,7 @@
#ifndef SKY_SHELL_TESTING_PLATFORM_VIEW_TEST_H_
#define SKY_SHELL_TESTING_PLATFORM_VIEW_TEST_H_
#include "base/macros.h"
#include "lib/ftl/macros.h"
#include "sky/shell/platform_view.h"
namespace sky {
......@@ -32,7 +32,7 @@ class PlatformViewTest : public PlatformView {
private:
base::WeakPtrFactory<PlatformViewTest> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(PlatformViewTest);
FTL_DISALLOW_COPY_AND_ASSIGN(PlatformViewTest);
};
} // namespace shell
......
......@@ -4,9 +4,9 @@
#include "sky/shell/tracing_controller.h"
#include "base/threading/platform_thread.h"
#include "base/trace_event/trace_event.h"
#include "dart/runtime/include/dart_tools_api.h"
#include "lib/ftl/logging.h"
#include "sky/engine/core/script/dart_init.h"
#include "sky/engine/wtf/MakeUnique.h"
#include "sky/shell/shell.h"
......@@ -18,11 +18,9 @@ namespace shell {
TracingController::TracingController()
: picture_tracing_enabled_(false), tracing_active_(false) {
auto start = [this]() { StartTracing(); };
auto stop = [this]() { StopTracing(); };
blink::SetEmbedderTracingCallbacks(
WTF::MakeUnique<blink::EmbedderTracingCallbacks>(start, stop));
WTF::MakeUnique<blink::EmbedderTracingCallbacks>(
[this]() { StartTracing(); }, [this]() { StopTracing(); }));
}
TracingController::~TracingController() {
......@@ -86,7 +84,7 @@ static void BaseTraceEventCallback(base::TraceTicks timestamp,
// discrete begin-end pairs. This greatly simplifies things. We dont have
// to track the second timestamp to pass to the Dart timeline event
// because we never see a Dart_Timeline_Event_Duration event.
DCHECK(false) << "Unknown trace event phase";
FTL_DCHECK(false) << "Unknown trace event phase";
return;
}
......@@ -145,43 +143,30 @@ static void BaseTraceEventCallback(base::TraceTicks timestamp,
}
}
static void TraceThreadMetadataToObservatory() {
const char* name = base::PlatformThread::GetName();
if (name == nullptr) {
return;
}
Dart_SetThreadName(name);
}
static void AddTraceMetadata() {
Shell::Shared().gpu_task_runner()->PostTask(
FROM_HERE, base::Bind(&TraceThreadMetadataToObservatory));
Shell::Shared().ui_task_runner()->PostTask(
FROM_HERE, base::Bind(&TraceThreadMetadataToObservatory));
Shell::Shared().io_task_runner()->PostTask(
FROM_HERE, base::Bind(&TraceThreadMetadataToObservatory));
Shell::Shared().gpu_ftl_task_runner()->PostTask(
[]() { Dart_SetThreadName("gpu_thread"); });
Shell::Shared().ui_ftl_task_runner()->PostTask(
[]() { Dart_SetThreadName("ui_thread"); });
Shell::Shared().io_ftl_task_runner()->PostTask(
[]() { Dart_SetThreadName("io_thread"); });
}
void TracingController::StartTracing() {
if (tracing_active_) {
if (tracing_active_)
return;
}
tracing_active_ = true;
StartBaseTracing();
AddTraceMetadata();
}
void TracingController::StartBaseTracing() {
namespace TE = base::trace_event;
auto config =
TE::TraceConfig("*,disabled-by-default-skia", TE::RECORD_CONTINUOUSLY);
auto config = base::trace_event::TraceConfig(
"*,disabled-by-default-skia", base::trace_event::RECORD_CONTINUOUSLY);
auto log = TE::TraceLog::GetInstance();
auto log = base::trace_event::TraceLog::GetInstance();
log->SetEnabled(config, TE::TraceLog::MONITORING_MODE);
log->SetEnabled(config, base::trace_event::TraceLog::MONITORING_MODE);
log->SetEventCallbackEnabled(config, &BaseTraceEventCallback);
}
......@@ -196,15 +181,14 @@ void TracingController::StopTracing() {
}
void TracingController::StopBaseTracing() {
auto log = base::trace_event::TraceLog::GetInstance();
log->SetDisabled();
log->SetEventCallbackDisabled();
auto trace_log = base::trace_event::TraceLog::GetInstance();
trace_log->SetDisabled();
trace_log->SetEventCallbackDisabled();
}
base::FilePath TracingController::TracePathWithExtension(
base::FilePath dir,
std::string extension) const {
std::string TracingController::TracePathWithExtension(
const std::string& directory,
const std::string& extension) const {
base::Time::Exploded exploded;
base::Time now = base::Time::Now();
......@@ -212,20 +196,20 @@ base::FilePath TracingController::TracePathWithExtension(
std::stringstream stream;
// Example: trace_2015-10-08_at_11.38.25.121_.extension
stream << "trace_" << exploded.year << "-" << exploded.month << "-"
<< exploded.day_of_month << "_at_" << exploded.hour << "."
stream << directory << "/trace_" << exploded.year << "-" << exploded.month
<< "-" << exploded.day_of_month << "_at_" << exploded.hour << "."
<< exploded.minute << "." << exploded.second << "."
<< exploded.millisecond << "." << extension;
return dir.Append(stream.str());
return stream.str();
}
base::FilePath TracingController::PictureTracingPathForCurrentTime() const {
std::string TracingController::PictureTracingPathForCurrentTime() const {
return PictureTracingPathForCurrentTime(traces_base_path_);
}
base::FilePath TracingController::PictureTracingPathForCurrentTime(
base::FilePath dir) const {
return TracePathWithExtension(dir, "skp");
std::string TracingController::PictureTracingPathForCurrentTime(
const std::string& directory) const {
return TracePathWithExtension(directory, "skp");
}
} // namespace shell
......
......@@ -5,8 +5,9 @@
#ifndef __SKY_SHELL_TRACING_CONTROLLER__
#define __SKY_SHELL_TRACING_CONTROLLER__
#include "base/macros.h"
#include "base/files/file.h"
#include <string>
#include "lib/ftl/macros.h"
namespace sky {
namespace shell {
......@@ -26,14 +27,14 @@ class TracingController {
// tracing controller should be used.
static void StartBaseTracing();
base::FilePath PictureTracingPathForCurrentTime() const;
base::FilePath PictureTracingPathForCurrentTime(base::FilePath dir) const;
std::string PictureTracingPathForCurrentTime() const;
std::string PictureTracingPathForCurrentTime(
const std::string& directory) const;
bool tracing_active() const { return tracing_active_; }
void set_traces_base_path(const base::FilePath& base_path) {
traces_base_path_ = base_path;
void set_traces_base_path(std::string base_path) {
traces_base_path_ = std::move(base_path);
}
void set_picture_tracing_enabled(bool enabled) {
......@@ -43,17 +44,18 @@ class TracingController {
bool picture_tracing_enabled() const { return picture_tracing_enabled_; }
private:
base::FilePath traces_base_path_;
std::string traces_base_path_;
bool picture_tracing_enabled_;
bool tracing_active_;
void StopBaseTracing();
base::FilePath TracePathWithExtension(base::FilePath dir,
std::string extension) const;
std::string TracePathWithExtension(const std::string& directory,
const std::string& extension) const;
DISALLOW_COPY_AND_ASSIGN(TracingController);
FTL_DISALLOW_COPY_AND_ASSIGN(TracingController);
};
} // namespace shell
} // namespace sky
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册