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

Side by Side Diff: services/ui/gpu/gpu_service.cc

Issue 2763493002: gpu: Use mojom API for recording log messages to the host. (Closed)
Patch Set: add comment 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/ui/gpu/gpu_service.h" 5 #include "services/ui/gpu/gpu_service.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/debug/crash_logging.h" 8 #include "base/debug/crash_logging.h"
9 #include "base/lazy_instance.h"
9 #include "base/memory/shared_memory.h" 10 #include "base/memory/shared_memory.h"
10 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
11 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
12 #include "build/build_config.h" 13 #include "build/build_config.h"
13 #include "cc/output/in_process_context_provider.h" 14 #include "cc/output/in_process_context_provider.h"
14 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" 15 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
15 #include "gpu/command_buffer/service/gpu_switches.h" 16 #include "gpu/command_buffer/service/gpu_switches.h"
16 #include "gpu/command_buffer/service/sync_point_manager.h" 17 #include "gpu/command_buffer/service/sync_point_manager.h"
17 #include "gpu/config/gpu_info_collector.h" 18 #include "gpu/config/gpu_info_collector.h"
18 #include "gpu/config/gpu_switches.h" 19 #include "gpu/config/gpu_switches.h"
(...skipping 17 matching lines...) Expand all
36 #include "ui/gl/init/gl_factory.h" 37 #include "ui/gl/init/gl_factory.h"
37 #include "url/gurl.h" 38 #include "url/gurl.h"
38 39
39 #if defined(OS_ANDROID) 40 #if defined(OS_ANDROID)
40 #include "base/android/throw_uncaught_exception.h" 41 #include "base/android/throw_uncaught_exception.h"
41 #include "media/gpu/avda_codec_allocator.h" 42 #include "media/gpu/avda_codec_allocator.h"
42 #endif 43 #endif
43 44
44 namespace ui { 45 namespace ui {
45 46
47 namespace {
48
49 static base::LazyInstance<base::Callback<
50 void(int severity, size_t message_start, const std::string& message)>>::
51 Leaky g_log_callback = LAZY_INSTANCE_INITIALIZER;
52
53 bool GpuLogMessageHandler(int severity,
54 const char* file,
55 int line,
56 size_t message_start,
57 const std::string& message) {
58 g_log_callback.Get().Run(severity, message_start, message);
59 return false;
60 }
61
62 } // namespace
63
46 GpuService::GpuService(const gpu::GPUInfo& gpu_info, 64 GpuService::GpuService(const gpu::GPUInfo& gpu_info,
47 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, 65 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread,
48 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, 66 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory,
49 scoped_refptr<base::SingleThreadTaskRunner> io_runner, 67 scoped_refptr<base::SingleThreadTaskRunner> io_runner,
50 const gpu::GpuFeatureInfo& gpu_feature_info) 68 const gpu::GpuFeatureInfo& gpu_feature_info)
51 : io_runner_(std::move(io_runner)), 69 : io_runner_(std::move(io_runner)),
52 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, 70 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL,
53 base::WaitableEvent::InitialState::NOT_SIGNALED), 71 base::WaitableEvent::InitialState::NOT_SIGNALED),
54 watchdog_thread_(std::move(watchdog_thread)), 72 watchdog_thread_(std::move(watchdog_thread)),
55 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), 73 gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
56 gpu_info_(gpu_info), 74 gpu_info_(gpu_info),
57 gpu_feature_info_(gpu_feature_info), 75 gpu_feature_info_(gpu_feature_info),
58 sync_point_manager_(nullptr) {} 76 sync_point_manager_(nullptr) {}
59 77
60 GpuService::~GpuService() { 78 GpuService::~GpuService() {
79 logging::SetLogMessageHandler(nullptr);
80 g_log_callback.Get() =
81 base::Callback<void(int, size_t, const std::string&)>();
61 bindings_.CloseAllBindings(); 82 bindings_.CloseAllBindings();
62 media_gpu_channel_manager_.reset(); 83 media_gpu_channel_manager_.reset();
63 gpu_channel_manager_.reset(); 84 gpu_channel_manager_.reset();
64 owned_sync_point_manager_.reset(); 85 owned_sync_point_manager_.reset();
65 86
66 // Signal this event before destroying the child process. That way all 87 // Signal this event before destroying the child process. That way all
67 // background threads can cleanup. 88 // background threads can cleanup.
68 // For example, in the renderer the RenderThread instances will be able to 89 // For example, in the renderer the RenderThread instances will be able to
69 // notice shutdown before the render process begins waiting for them to exit. 90 // notice shutdown before the render process begins waiting for them to exit.
70 shutdown_event_.Signal(); 91 shutdown_event_.Signal();
(...skipping 10 matching lines...) Expand all
81 gpu_preferences_ = preferences; 102 gpu_preferences_ = preferences;
82 gpu_info_.video_decode_accelerator_capabilities = 103 gpu_info_.video_decode_accelerator_capabilities =
83 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); 104 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_);
84 gpu_info_.video_encode_accelerator_supported_profiles = 105 gpu_info_.video_encode_accelerator_supported_profiles =
85 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); 106 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_);
86 gpu_info_.jpeg_decode_accelerator_supported = 107 gpu_info_.jpeg_decode_accelerator_supported =
87 media::GpuJpegDecodeAcceleratorFactoryProvider:: 108 media::GpuJpegDecodeAcceleratorFactoryProvider::
88 IsAcceleratedJpegDecodeSupported(); 109 IsAcceleratedJpegDecodeSupported();
89 gpu_host_->DidInitialize(gpu_info_); 110 gpu_host_->DidInitialize(gpu_info_);
90 111
112 if (!in_host_process_) {
113 // The global callback is reset from the dtor. So Unretained() here is safe.
114 // Note that the callback can be called from any thread. Consequently, the
115 // callback cannot use a WeakPtr.
116 g_log_callback.Get() =
117 base::Bind(&GpuService::RecordLogMessage, base::Unretained(this),
118 base::ThreadTaskRunnerHandle::Get());
piman 2017/03/20 21:20:26 So, this has different properties than the previou
sadrul 2017/03/20 21:40:17 There is ThreadSafeInterfacePtrBase<> that I could
Ken Rockot(use gerrit already) 2017/03/21 00:56:01 Well one option would be to move the GpuHostPtr to
119 logging::SetLogMessageHandler(GpuLogMessageHandler);
120 }
121
91 sync_point_manager_ = sync_point_manager; 122 sync_point_manager_ = sync_point_manager;
92 if (!sync_point_manager_) { 123 if (!sync_point_manager_) {
93 owned_sync_point_manager_ = base::MakeUnique<gpu::SyncPointManager>(); 124 owned_sync_point_manager_ = base::MakeUnique<gpu::SyncPointManager>();
94 sync_point_manager_ = owned_sync_point_manager_.get(); 125 sync_point_manager_ = owned_sync_point_manager_.get();
95 } 126 }
96 127
97 // Defer creation of the render thread. This is to prevent it from handling 128 // Defer creation of the render thread. This is to prevent it from handling
98 // IPC messages before the sandbox has been enabled and all other necessary 129 // IPC messages before the sandbox has been enabled and all other necessary
99 // initialization has succeeded. 130 // initialization has succeeded.
100 gpu_channel_manager_.reset(new gpu::GpuChannelManager( 131 gpu_channel_manager_.reset(new gpu::GpuChannelManager(
101 gpu_preferences_, this, watchdog_thread_.get(), 132 gpu_preferences_, this, watchdog_thread_.get(),
102 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(), 133 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(),
103 shutdown_event ? shutdown_event : &shutdown_event_, sync_point_manager_, 134 shutdown_event ? shutdown_event : &shutdown_event_, sync_point_manager_,
104 gpu_memory_buffer_factory_, gpu_feature_info_, 135 gpu_memory_buffer_factory_, gpu_feature_info_,
105 std::move(activity_flags))); 136 std::move(activity_flags)));
106 137
107 media_gpu_channel_manager_.reset( 138 media_gpu_channel_manager_.reset(
108 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); 139 new media::MediaGpuChannelManager(gpu_channel_manager_.get()));
109 } 140 }
110 141
111 void GpuService::Bind(mojom::GpuServiceRequest request) { 142 void GpuService::Bind(mojom::GpuServiceRequest request) {
112 bindings_.AddBinding(this, std::move(request)); 143 bindings_.AddBinding(this, std::move(request));
113 } 144 }
114 145
146 void GpuService::RecordLogMessage(
147 scoped_refptr<base::SingleThreadTaskRunner> task_runner,
148 int severity,
149 size_t message_start,
150 const std::string& str) {
151 if (!task_runner->BelongsToCurrentThread()) {
152 task_runner->PostTask(
153 FROM_HERE,
154 base::Bind(base::IgnoreResult(&GpuLogMessageHandler), severity,
155 nullptr /* file */, 0 /* line */, message_start, str));
156 return;
157 }
158 std::string header = str.substr(0, message_start);
159 std::string message = str.substr(message_start);
160 gpu_host_->RecordLogMessage(severity, header, message);
161 }
162
115 void GpuService::CreateGpuMemoryBuffer( 163 void GpuService::CreateGpuMemoryBuffer(
116 gfx::GpuMemoryBufferId id, 164 gfx::GpuMemoryBufferId id,
117 const gfx::Size& size, 165 const gfx::Size& size,
118 gfx::BufferFormat format, 166 gfx::BufferFormat format,
119 gfx::BufferUsage usage, 167 gfx::BufferUsage usage,
120 int client_id, 168 int client_id,
121 gpu::SurfaceHandle surface_handle, 169 gpu::SurfaceHandle surface_handle,
122 const CreateGpuMemoryBufferCallback& callback) { 170 const CreateGpuMemoryBufferCallback& callback) {
123 DCHECK(CalledOnValidThread()); 171 DCHECK(CalledOnValidThread());
124 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( 172 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 NOTREACHED() << "Java exception not supported on this platform."; 368 NOTREACHED() << "Java exception not supported on this platform.";
321 #endif 369 #endif
322 } 370 }
323 371
324 void GpuService::Stop(const StopCallback& callback) { 372 void GpuService::Stop(const StopCallback& callback) {
325 base::MessageLoop::current()->QuitWhenIdle(); 373 base::MessageLoop::current()->QuitWhenIdle();
326 callback.Run(); 374 callback.Run();
327 } 375 }
328 376
329 } // namespace ui 377 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698