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

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: . 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
« 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/threading/thread_task_runner_handle.h" 11 #include "base/threading/thread_task_runner_handle.h"
11 #include "build/build_config.h" 12 #include "build/build_config.h"
12 #include "cc/output/in_process_context_provider.h" 13 #include "cc/output/in_process_context_provider.h"
13 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" 14 #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h"
14 #include "gpu/command_buffer/service/gpu_switches.h" 15 #include "gpu/command_buffer/service/gpu_switches.h"
15 #include "gpu/command_buffer/service/sync_point_manager.h" 16 #include "gpu/command_buffer/service/sync_point_manager.h"
16 #include "gpu/config/gpu_info_collector.h" 17 #include "gpu/config/gpu_info_collector.h"
17 #include "gpu/config/gpu_switches.h" 18 #include "gpu/config/gpu_switches.h"
18 #include "gpu/config/gpu_util.h" 19 #include "gpu/config/gpu_util.h"
(...skipping 16 matching lines...) Expand all
35 #include "ui/gl/init/gl_factory.h" 36 #include "ui/gl/init/gl_factory.h"
36 #include "url/gurl.h" 37 #include "url/gurl.h"
37 38
38 #if defined(OS_ANDROID) 39 #if defined(OS_ANDROID)
39 #include "base/android/throw_uncaught_exception.h" 40 #include "base/android/throw_uncaught_exception.h"
40 #include "media/gpu/avda_codec_allocator.h" 41 #include "media/gpu/avda_codec_allocator.h"
41 #endif 42 #endif
42 43
43 namespace ui { 44 namespace ui {
44 45
46 namespace {
47
48 static base::LazyInstance<base::Callback<
49 void(int severity, size_t message_start, const std::string& message)>>::
50 Leaky g_log_callback = LAZY_INSTANCE_INITIALIZER;
51
52 bool GpuLogMessageHandler(int severity,
53 const char* file,
54 int line,
55 size_t message_start,
56 const std::string& message) {
57 g_log_callback.Get().Run(severity, message_start, message);
58 return false;
59 }
60
61 } // namespace
62
45 GpuService::GpuService(const gpu::GPUInfo& gpu_info, 63 GpuService::GpuService(const gpu::GPUInfo& gpu_info,
46 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, 64 std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread,
47 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory, 65 gpu::GpuMemoryBufferFactory* gpu_memory_buffer_factory,
48 scoped_refptr<base::SingleThreadTaskRunner> io_runner, 66 scoped_refptr<base::SingleThreadTaskRunner> io_runner,
49 const gpu::GpuFeatureInfo& gpu_feature_info) 67 const gpu::GpuFeatureInfo& gpu_feature_info)
50 : io_runner_(std::move(io_runner)), 68 : io_runner_(std::move(io_runner)),
51 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL, 69 shutdown_event_(base::WaitableEvent::ResetPolicy::MANUAL,
52 base::WaitableEvent::InitialState::NOT_SIGNALED), 70 base::WaitableEvent::InitialState::NOT_SIGNALED),
53 watchdog_thread_(std::move(watchdog_thread)), 71 watchdog_thread_(std::move(watchdog_thread)),
54 gpu_memory_buffer_factory_(gpu_memory_buffer_factory), 72 gpu_memory_buffer_factory_(gpu_memory_buffer_factory),
55 gpu_info_(gpu_info), 73 gpu_info_(gpu_info),
56 gpu_feature_info_(gpu_feature_info), 74 gpu_feature_info_(gpu_feature_info),
57 sync_point_manager_(nullptr) {} 75 sync_point_manager_(nullptr) {}
58 76
59 GpuService::~GpuService() { 77 GpuService::~GpuService() {
78 logging::SetLogMessageHandler(nullptr);
79 g_log_callback.Get() =
80 base::Callback<void(int, size_t, const std::string&)>();
60 bindings_.CloseAllBindings(); 81 bindings_.CloseAllBindings();
61 media_gpu_channel_manager_.reset(); 82 media_gpu_channel_manager_.reset();
62 gpu_channel_manager_.reset(); 83 gpu_channel_manager_.reset();
63 owned_sync_point_manager_.reset(); 84 owned_sync_point_manager_.reset();
64 85
65 // Signal this event before destroying the child process. That way all 86 // Signal this event before destroying the child process. That way all
66 // background threads can cleanup. 87 // background threads can cleanup.
67 // For example, in the renderer the RenderThread instances will be able to 88 // For example, in the renderer the RenderThread instances will be able to
68 // notice shutdown before the render process begins waiting for them to exit. 89 // notice shutdown before the render process begins waiting for them to exit.
69 shutdown_event_.Signal(); 90 shutdown_event_.Signal();
(...skipping 10 matching lines...) Expand all
80 gpu_info_.video_decode_accelerator_capabilities = 101 gpu_info_.video_decode_accelerator_capabilities =
81 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_); 102 media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences_);
82 gpu_info_.video_encode_accelerator_supported_profiles = 103 gpu_info_.video_encode_accelerator_supported_profiles =
83 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_); 104 media::GpuVideoEncodeAccelerator::GetSupportedProfiles(gpu_preferences_);
84 gpu_info_.jpeg_decode_accelerator_supported = 105 gpu_info_.jpeg_decode_accelerator_supported =
85 media::GpuJpegDecodeAcceleratorFactoryProvider:: 106 media::GpuJpegDecodeAcceleratorFactoryProvider::
86 IsAcceleratedJpegDecodeSupported(); 107 IsAcceleratedJpegDecodeSupported();
87 gpu_host->DidInitialize(gpu_info_); 108 gpu_host->DidInitialize(gpu_info_);
88 gpu_host_ = 109 gpu_host_ =
89 mojom::ThreadSafeGpuHostPtr::Create(gpu_host.PassInterface(), io_runner_); 110 mojom::ThreadSafeGpuHostPtr::Create(gpu_host.PassInterface(), io_runner_);
111 if (!in_host_process_) {
112 // The global callback is reset from the dtor. So Unretained() here is safe.
113 // Note that the callback can be called from any thread. Consequently, the
114 // callback cannot use a WeakPtr.
115 g_log_callback.Get() =
116 base::Bind(&GpuService::RecordLogMessage, base::Unretained(this));
117 logging::SetLogMessageHandler(GpuLogMessageHandler);
118 }
119
90 sync_point_manager_ = sync_point_manager; 120 sync_point_manager_ = sync_point_manager;
91 if (!sync_point_manager_) { 121 if (!sync_point_manager_) {
92 owned_sync_point_manager_ = base::MakeUnique<gpu::SyncPointManager>(); 122 owned_sync_point_manager_ = base::MakeUnique<gpu::SyncPointManager>();
93 sync_point_manager_ = owned_sync_point_manager_.get(); 123 sync_point_manager_ = owned_sync_point_manager_.get();
94 } 124 }
95 125
96 // Defer creation of the render thread. This is to prevent it from handling 126 // Defer creation of the render thread. This is to prevent it from handling
97 // IPC messages before the sandbox has been enabled and all other necessary 127 // IPC messages before the sandbox has been enabled and all other necessary
98 // initialization has succeeded. 128 // initialization has succeeded.
99 gpu_channel_manager_.reset(new gpu::GpuChannelManager( 129 gpu_channel_manager_.reset(new gpu::GpuChannelManager(
100 gpu_preferences_, this, watchdog_thread_.get(), 130 gpu_preferences_, this, watchdog_thread_.get(),
101 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(), 131 base::ThreadTaskRunnerHandle::Get().get(), io_runner_.get(),
102 shutdown_event ? shutdown_event : &shutdown_event_, sync_point_manager_, 132 shutdown_event ? shutdown_event : &shutdown_event_, sync_point_manager_,
103 gpu_memory_buffer_factory_, gpu_feature_info_, 133 gpu_memory_buffer_factory_, gpu_feature_info_,
104 std::move(activity_flags))); 134 std::move(activity_flags)));
105 135
106 media_gpu_channel_manager_.reset( 136 media_gpu_channel_manager_.reset(
107 new media::MediaGpuChannelManager(gpu_channel_manager_.get())); 137 new media::MediaGpuChannelManager(gpu_channel_manager_.get()));
108 } 138 }
109 139
110 void GpuService::Bind(mojom::GpuServiceRequest request) { 140 void GpuService::Bind(mojom::GpuServiceRequest request) {
111 bindings_.AddBinding(this, std::move(request)); 141 bindings_.AddBinding(this, std::move(request));
112 } 142 }
113 143
144 void GpuService::RecordLogMessage(int severity,
145 size_t message_start,
146 const std::string& str) {
147 std::string header = str.substr(0, message_start);
148 std::string message = str.substr(message_start);
149 (*gpu_host_)->RecordLogMessage(severity, header, message);
150 }
151
114 void GpuService::CreateGpuMemoryBuffer( 152 void GpuService::CreateGpuMemoryBuffer(
115 gfx::GpuMemoryBufferId id, 153 gfx::GpuMemoryBufferId id,
116 const gfx::Size& size, 154 const gfx::Size& size,
117 gfx::BufferFormat format, 155 gfx::BufferFormat format,
118 gfx::BufferUsage usage, 156 gfx::BufferUsage usage,
119 int client_id, 157 int client_id,
120 gpu::SurfaceHandle surface_handle, 158 gpu::SurfaceHandle surface_handle,
121 const CreateGpuMemoryBufferCallback& callback) { 159 const CreateGpuMemoryBufferCallback& callback) {
122 DCHECK(CalledOnValidThread()); 160 DCHECK(CalledOnValidThread());
123 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer( 161 callback.Run(gpu_memory_buffer_factory_->CreateGpuMemoryBuffer(
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 NOTREACHED() << "Java exception not supported on this platform."; 304 NOTREACHED() << "Java exception not supported on this platform.";
267 #endif 305 #endif
268 } 306 }
269 307
270 void GpuService::Stop(const StopCallback& callback) { 308 void GpuService::Stop(const StopCallback& callback) {
271 base::MessageLoop::current()->QuitWhenIdle(); 309 base::MessageLoop::current()->QuitWhenIdle();
272 callback.Run(); 310 callback.Run();
273 } 311 }
274 312
275 } // namespace ui 313 } // namespace ui
OLDNEW
« 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