Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1617)

Unified Diff: services/ui/gpu/gpu_service.cc

Issue 2763493002: gpu: Use mojom API for recording log messages to the host. (Closed)
Patch Set: . Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/ui/gpu/gpu_service.h ('k') | services/ui/gpu/interfaces/gpu_host.mojom » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/gpu/gpu_service.cc
diff --git a/services/ui/gpu/gpu_service.cc b/services/ui/gpu/gpu_service.cc
index 75a81a656cc896852571152417eac520c40b91e7..948353c70e5ef2cbb6a08bc8bb97f43637bb832a 100644
--- a/services/ui/gpu/gpu_service.cc
+++ b/services/ui/gpu/gpu_service.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/debug/crash_logging.h"
+#include "base/lazy_instance.h"
#include "base/memory/shared_memory.h"
#include "base/threading/thread_task_runner_handle.h"
#include "build/build_config.h"
@@ -42,6 +43,23 @@
namespace ui {
+namespace {
+
+static base::LazyInstance<base::Callback<
+ void(int severity, size_t message_start, const std::string& message)>>::
+ Leaky g_log_callback = LAZY_INSTANCE_INITIALIZER;
+
+bool GpuLogMessageHandler(int severity,
+ const char* file,
+ int line,
+ size_t message_start,
+ const std::string& message) {
+ g_log_callback.Get().Run(severity, message_start, message);
+ return false;
+}
+
+} // namespace
+
GpuService::GpuService(const gpu::GPUInfo& gpu_info,
std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread,
gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory,
@@ -57,6 +75,9 @@ GpuService::GpuService(const gpu::GPUInfo& gpu_info,
sync_point_manager_(nullptr) {}
GpuService::~GpuService() {
+ logging::SetLogMessageHandler(nullptr);
+ g_log_callback.Get() =
+ base::Callback<void(int, size_t, const std::string&)>();
bindings_.CloseAllBindings();
media_gpu_channel_manager_.reset();
gpu_channel_manager_.reset();
@@ -87,6 +108,15 @@ void GpuService::InitializeWithHost(mojom::GpuHostPtr gpu_host,
gpu_host->DidInitialize(gpu_info_);
gpu_host_ =
mojom::ThreadSafeGpuHostPtr::Create(gpu_host.PassInterface(), io_runner_);
+ if (!in_host_process_) {
+ // The global callback is reset from the dtor. So Unretained() here is safe.
+ // Note that the callback can be called from any thread. Consequently, the
+ // callback cannot use a WeakPtr.
+ g_log_callback.Get() =
+ base::Bind(&GpuService::RecordLogMessage, base::Unretained(this));
+ logging::SetLogMessageHandler(GpuLogMessageHandler);
+ }
+
sync_point_manager_ = sync_point_manager;
if (!sync_point_manager_) {
owned_sync_point_manager_ = base::MakeUnique<gpu::SyncPointManager>();
@@ -111,6 +141,14 @@ void GpuService::Bind(mojom::GpuServiceRequest request) {
bindings_.AddBinding(this, std::move(request));
}
+void GpuService::RecordLogMessage(int severity,
+ size_t message_start,
+ const std::string& str) {
+ std::string header = str.substr(0, message_start);
+ std::string message = str.substr(message_start);
+ (*gpu_host_)->RecordLogMessage(severity, header, message);
+}
+
void GpuService::CreateGpuMemoryBuffer(
gfx::GpuMemoryBufferId id,
const gfx::Size& size,
« no previous file with comments | « services/ui/gpu/gpu_service.h ('k') | services/ui/gpu/interfaces/gpu_host.mojom » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698