fsamuel | b25f854 | 2016-04-22 19:14:07 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 5 | #include "components/viz/service/gl/gpu_service_impl.h" |
fsamuel | b25f854 | 2016-04-22 19:14:07 | [diff] [blame] | 6 | |
Jinho Bang | 24ca9cd | 2018-01-02 22:01:00 | [diff] [blame] | 7 | #include <memory> |
Jonathan Backer | a57031b | 2018-06-04 15:44:32 | [diff] [blame] | 8 | #include <string> |
Claudio DeSouza | 591a997 | 2018-02-21 17:27:16 | [diff] [blame] | 9 | #include <utility> |
Adlai Holler | 7a7503a | 2020-08-05 21:22:17 | [diff] [blame] | 10 | #include <vector> |
Jinho Bang | 24ca9cd | 2018-01-02 22:01:00 | [diff] [blame] | 11 | |
fsamuel | 4af1869 | 2016-11-22 21:41:34 | [diff] [blame] | 12 | #include "base/bind.h" |
Zhenyao Mo | 74b0491b | 2017-08-19 06:53:17 | [diff] [blame] | 13 | #include "base/command_line.h" |
Andres Calderon Jaramillo | 12a1c6d | 2019-06-26 04:42:34 | [diff] [blame] | 14 | #include "base/feature_list.h" |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 15 | #include "base/no_destructor.h" |
Gabriel Charette | 44db142 | 2018-08-06 11:19:33 | [diff] [blame] | 16 | #include "base/task/post_task.h" |
Gabriel Charette | dd8d5985e | 2020-02-26 18:38:35 | [diff] [blame] | 17 | #include "base/task/thread_pool.h" |
Robert Liao | 1214b5e | 2017-07-29 02:48:58 | [diff] [blame] | 18 | #include "base/task_runner_util.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 19 | #include "base/threading/thread_task_runner_handle.h" |
penghuang | cab01d2 | 2016-06-12 15:16:39 | [diff] [blame] | 20 | #include "build/build_config.h" |
Yuta Hijikata | 5a9692ce | 2020-11-20 07:26:16 | [diff] [blame] | 21 | #include "build/chromeos_buildflags.h" |
Saman Sami | 1cf5217 | 2020-01-13 19:05:27 | [diff] [blame] | 22 | #include "components/viz/common/features.h" |
Christopher Cameron | 4f7ce36 | 2019-04-26 02:21:37 | [diff] [blame] | 23 | #include "components/viz/common/gpu/metal_context_provider.h" |
fsamuel | 2a2351a9 | 2016-12-01 01:08:04 | [diff] [blame] | 24 | #include "gpu/command_buffer/client/gpu_memory_buffer_manager.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 25 | #include "gpu/command_buffer/service/gpu_switches.h" |
sunnyps | 8f9139e | 2017-05-12 17:53:25 | [diff] [blame] | 26 | #include "gpu/command_buffer/service/scheduler.h" |
Peng Huang | 8294a5a7f | 2019-01-23 18:56:26 | [diff] [blame] | 27 | #include "gpu/command_buffer/service/shared_context_state.h" |
Peng Huang | 0fb98bc | 2020-04-07 22:08:28 | [diff] [blame] | 28 | #include "gpu/command_buffer/service/skia_utils.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 29 | #include "gpu/command_buffer/service/sync_point_manager.h" |
Robert Liao | 1214b5e | 2017-07-29 02:48:58 | [diff] [blame] | 30 | #include "gpu/config/dx_diag_node.h" |
Andres Calderon Jaramillo | 12a1c6d | 2019-06-26 04:42:34 | [diff] [blame] | 31 | #include "gpu/config/gpu_finch_features.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 32 | #include "gpu/config/gpu_info_collector.h" |
| 33 | #include "gpu/config/gpu_switches.h" |
| 34 | #include "gpu/config/gpu_util.h" |
Khushal | c2667e3 | 2018-07-20 01:07:18 | [diff] [blame] | 35 | #include "gpu/ipc/common/gpu_client_ids.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 36 | #include "gpu/ipc/common/gpu_memory_buffer_support.h" |
jonross | 1f2903d | 2020-03-06 13:59:40 | [diff] [blame] | 37 | #include "gpu/ipc/common/gpu_peak_memory.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 38 | #include "gpu/ipc/common/memory_stats.h" |
Sadrul Habib Chowdhury | 7102df0b | 2018-05-30 03:04:17 | [diff] [blame] | 39 | #include "gpu/ipc/in_process_command_buffer.h" |
sunnyps | 41a6a15a | 2017-03-31 00:38:54 | [diff] [blame] | 40 | #include "gpu/ipc/service/gpu_channel.h" |
fsamuel | 4af1869 | 2016-11-22 21:41:34 | [diff] [blame] | 41 | #include "gpu/ipc/service/gpu_channel_manager.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 42 | #include "gpu/ipc/service/gpu_memory_buffer_factory.h" |
sadrul | 2fb7e15 | 2016-08-30 05:21:45 | [diff] [blame] | 43 | #include "gpu/ipc/service/gpu_watchdog_thread.h" |
Andres Calderon Jaramillo | 12a1c6d | 2019-06-26 04:42:34 | [diff] [blame] | 44 | #include "gpu/ipc/service/image_decode_accelerator_worker.h" |
Peng Huang | cfc3180d | 2018-07-16 21:47:08 | [diff] [blame] | 45 | #include "gpu/vulkan/buildflags.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 46 | #include "ipc/ipc_channel_handle.h" |
sunnyps | 41a6a15a | 2017-03-31 00:38:54 | [diff] [blame] | 47 | #include "ipc/ipc_sync_channel.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 48 | #include "ipc/ipc_sync_message_filter.h" |
Andres Calderon Jaramillo | 12a1c6d | 2019-06-26 04:42:34 | [diff] [blame] | 49 | #include "media/gpu/buildflags.h" |
Miguel Casas | be4dac8 | 2017-12-20 17:52:39 | [diff] [blame] | 50 | #include "media/gpu/gpu_video_accelerator_util.h" |
Miguel Casas-Sanchez | f5261d9 | 2017-07-26 06:31:34 | [diff] [blame] | 51 | #include "media/gpu/gpu_video_encode_accelerator_factory.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 52 | #include "media/gpu/ipc/service/gpu_video_decode_accelerator.h" |
xhwang | b2402d9 | 2016-10-15 07:29:37 | [diff] [blame] | 53 | #include "media/gpu/ipc/service/media_gpu_channel_manager.h" |
Miguel Casas-Sanchez | 7d46470 | 2017-07-29 14:19:21 | [diff] [blame] | 54 | #include "media/mojo/services/mojo_video_encode_accelerator_provider.h" |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 55 | #include "mojo/public/cpp/bindings/self_owned_receiver.h" |
Sean Gilhuly | e534232 | 2019-11-08 16:40:53 | [diff] [blame] | 56 | #include "skia/buildflags.h" |
Adlai Holler | 7a7503a | 2020-08-05 21:22:17 | [diff] [blame] | 57 | #include "third_party/skia/include/gpu/GrDirectContext.h" |
Peng Huang | fb0cf37 | 2018-03-22 17:29:27 | [diff] [blame] | 58 | #include "third_party/skia/include/gpu/gl/GrGLAssembleInterface.h" |
| 59 | #include "third_party/skia/include/gpu/gl/GrGLInterface.h" |
| 60 | #include "ui/gl/gl_context.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 61 | #include "ui/gl/gl_implementation.h" |
| 62 | #include "ui/gl/gl_switches.h" |
Kenneth Russell | 3689f3e | 2018-08-07 00:45:40 | [diff] [blame] | 63 | #include "ui/gl/gl_utils.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 64 | #include "ui/gl/gpu_switching_manager.h" |
Peng Huang | fb0cf37 | 2018-03-22 17:29:27 | [diff] [blame] | 65 | #include "ui/gl/init/create_gr_gl_interface.h" |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 66 | #include "ui/gl/init/gl_factory.h" |
| 67 | #include "url/gurl.h" |
fsamuel | b25f854 | 2016-04-22 19:14:07 | [diff] [blame] | 68 | |
Andres Calderon Jaramillo | 12a1c6d | 2019-06-26 04:42:34 | [diff] [blame] | 69 | #if BUILDFLAG(USE_VAAPI) |
Gil Dekel | 270ab99 | 2019-07-29 22:59:10 | [diff] [blame] | 70 | #include "media/gpu/vaapi/vaapi_image_decode_accelerator_worker.h" |
Andres Calderon Jaramillo | 12a1c6d | 2019-06-26 04:42:34 | [diff] [blame] | 71 | #endif // BUILDFLAG(USE_VAAPI) |
| 72 | |
sadrul | 9cef0df | 2017-03-03 18:18:07 | [diff] [blame] | 73 | #if defined(OS_ANDROID) |
Andrew Grieve | 2640788 | 2018-08-28 15:15:33 | [diff] [blame] | 74 | #include "components/viz/service/gl/throw_uncaught_exception.h" |
Dale Curtis | a3f8ba3 | 2020-04-27 23:01:09 | [diff] [blame] | 75 | #include "media/base/android/media_codec_util.h" |
sadrul | 9cef0df | 2017-03-03 18:18:07 | [diff] [blame] | 76 | #endif |
| 77 | |
Yuta Hijikata | 5a9692ce | 2020-11-20 07:26:16 | [diff] [blame] | 78 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Hirokazu Honda | 12eaf9c | 2017-12-12 02:40:16 | [diff] [blame] | 79 | #include "components/arc/video_accelerator/gpu_arc_video_decode_accelerator.h" |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 80 | #include "components/arc/video_accelerator/gpu_arc_video_encode_accelerator.h" |
Hirokazu Honda | 0526850 | 2018-03-31 05:18:39 | [diff] [blame] | 81 | #include "components/arc/video_accelerator/gpu_arc_video_protected_buffer_allocator.h" |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 82 | #include "components/arc/video_accelerator/protected_buffer_manager.h" |
| 83 | #include "components/arc/video_accelerator/protected_buffer_manager_proxy.h" |
Wei Lee | 01d63ef | 2019-05-09 09:24:50 | [diff] [blame] | 84 | #include "components/chromeos_camera/gpu_mjpeg_decode_accelerator_factory.h" |
| 85 | #include "components/chromeos_camera/mojo_jpeg_encode_accelerator_service.h" |
| 86 | #include "components/chromeos_camera/mojo_mjpeg_decode_accelerator_service.h" |
Yuta Hijikata | 5a9692ce | 2020-11-20 07:26:16 | [diff] [blame] | 87 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 88 | |
Christopher Cameron | 51e1d9e | 2017-10-14 00:01:45 | [diff] [blame] | 89 | #if defined(OS_WIN) |
Zhenyao Mo | e0bc16a | 2019-05-21 19:24:59 | [diff] [blame] | 90 | #include "ui/gl/direct_composition_surface_win.h" |
Christopher Cameron | 51e1d9e | 2017-10-14 00:01:45 | [diff] [blame] | 91 | #endif |
| 92 | |
Avi Drissman | 8fd9217 | 2020-07-28 15:49:45 | [diff] [blame] | 93 | #if defined(OS_APPLE) |
Sidney San MartÃn | 9387b40 | 2018-06-08 18:13:26 | [diff] [blame] | 94 | #include "ui/base/cocoa/quartz_util.h" |
| 95 | #endif |
| 96 | |
Sean Gilhuly | e534232 | 2019-11-08 16:40:53 | [diff] [blame] | 97 | #if BUILDFLAG(SKIA_USE_DAWN) |
| 98 | #include "components/viz/common/gpu/dawn_context_provider.h" |
| 99 | #endif |
| 100 | |
Sebastien Marchand | 836d04b3 | 2020-04-28 18:10:03 | [diff] [blame] | 101 | #if BUILDFLAG(CLANG_PROFILING_INSIDE_SANDBOX) |
| 102 | #include "base/test/clang_profiling.h" |
| 103 | #endif |
| 104 | |
Peng Huang | 81a9a98 | 2020-05-13 02:55:20 | [diff] [blame] | 105 | #if BUILDFLAG(ENABLE_VULKAN) |
| 106 | #include "components/viz/common/gpu/vulkan_context_provider.h" |
| 107 | #include "components/viz/common/gpu/vulkan_in_process_context_provider.h" |
| 108 | #endif |
| 109 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 110 | namespace viz { |
sadrul | ad8b21be | 2016-08-26 00:45:09 | [diff] [blame] | 111 | |
sadrul | 6aafa7d | 2017-03-22 22:56:35 | [diff] [blame] | 112 | namespace { |
| 113 | |
Dale Curtis | ef40483 | 2020-03-31 23:05:42 | [diff] [blame] | 114 | using LogCallback = base::RepeatingCallback< |
| 115 | void(int severity, const std::string& header, const std::string& message)>; |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 116 | |
| 117 | struct LogMessage { |
| 118 | LogMessage(int severity, |
| 119 | const std::string& header, |
| 120 | const std::string& message) |
| 121 | : severity(severity), |
| 122 | header(std::move(header)), |
| 123 | message(std::move(message)) {} |
| 124 | const int severity; |
| 125 | const std::string header; |
| 126 | const std::string message; |
| 127 | }; |
| 128 | |
Dale Curtis | ef40483 | 2020-03-31 23:05:42 | [diff] [blame] | 129 | // Forward declare log handlers so they can be used within LogMessageManager. |
| 130 | bool PreInitializeLogHandler(int severity, |
| 131 | const char* file, |
| 132 | int line, |
| 133 | size_t message_start, |
| 134 | const std::string& message); |
| 135 | bool PostInitializeLogHandler(int severity, |
| 136 | const char* file, |
| 137 | int line, |
| 138 | size_t message_start, |
| 139 | const std::string& message); |
| 140 | |
| 141 | // Class which manages LOG() message forwarding before and after GpuServiceImpl |
| 142 | // InitializeWithHost(). Prior to initialize, log messages are deferred and kept |
| 143 | // within the class. During initialize, InstallPostInitializeLogHandler() will |
| 144 | // be called to flush deferred messages and route new ones directly to GpuHost. |
| 145 | class LogMessageManager { |
| 146 | public: |
| 147 | LogMessageManager() = default; |
| 148 | ~LogMessageManager() = delete; |
| 149 | |
| 150 | // Queues a deferred LOG() message into |deferred_messages_| unless |
| 151 | // |log_callback_| has been set -- in which case RouteMessage() is called. |
| 152 | void AddDeferredMessage(int severity, |
| 153 | const std::string& header, |
| 154 | const std::string& message) { |
| 155 | base::AutoLock lock(message_lock_); |
| 156 | // During InstallPostInitializeLogHandler() there's a brief window where a |
| 157 | // call into this function may be waiting on |message_lock_|, so we need to |
| 158 | // check if |log_callback_| was set once we get the lock. |
| 159 | if (log_callback_) { |
| 160 | RouteMessage(severity, std::move(header), std::move(message)); |
| 161 | return; |
| 162 | } |
| 163 | |
| 164 | // Otherwise just queue the message for InstallPostInitializeLogHandler() to |
| 165 | // forward later. |
| 166 | deferred_messages_.emplace_back(severity, std::move(header), |
| 167 | std::move(message)); |
| 168 | } |
| 169 | |
| 170 | // Used after InstallPostInitializeLogHandler() to route messages directly to |
| 171 | // |log_callback_|; avoids the need for a global lock. |
| 172 | void RouteMessage(int severity, |
| 173 | const std::string& header, |
| 174 | const std::string& message) { |
| 175 | log_callback_.Run(severity, std::move(header), std::move(message)); |
| 176 | } |
| 177 | |
| 178 | // If InstallPostInitializeLogHandler() will never be called, this method is |
| 179 | // called prior to process exit to ensure logs are forwarded. |
| 180 | void FlushMessages(mojom::GpuHost* gpu_host) { |
| 181 | base::AutoLock lock(message_lock_); |
| 182 | for (auto& log : deferred_messages_) { |
| 183 | gpu_host->RecordLogMessage(log.severity, std::move(log.header), |
| 184 | std::move(log.message)); |
| 185 | } |
| 186 | deferred_messages_.clear(); |
| 187 | } |
| 188 | |
| 189 | // Used prior to InitializeWithHost() during GpuMain startup to ensure logs |
| 190 | // aren't lost before initialize. |
| 191 | void InstallPreInitializeLogHandler() { |
| 192 | DCHECK(!log_callback_); |
| 193 | logging::SetLogMessageHandler(PreInitializeLogHandler); |
| 194 | } |
| 195 | |
| 196 | // Called by InitializeWithHost() to take over logging from the |
| 197 | // PostInitializeLogHandler(). Flushes all deferred messages. |
| 198 | void InstallPostInitializeLogHandler(LogCallback log_callback) { |
| 199 | base::AutoLock lock(message_lock_); |
| 200 | DCHECK(!log_callback_); |
| 201 | log_callback_ = std::move(log_callback); |
| 202 | for (auto& log : deferred_messages_) |
| 203 | RouteMessage(log.severity, std::move(log.header), std::move(log.message)); |
| 204 | deferred_messages_.clear(); |
| 205 | logging::SetLogMessageHandler(PostInitializeLogHandler); |
| 206 | } |
| 207 | |
| 208 | // Called when it's no longer safe to invoke |log_callback_|. |
| 209 | void ShutdownLogging() { logging::SetLogMessageHandler(nullptr); } |
| 210 | |
| 211 | private: |
| 212 | base::Lock message_lock_; |
| 213 | std::vector<LogMessage> deferred_messages_ GUARDED_BY(message_lock_); |
| 214 | |
| 215 | // Set once under |mesage_lock_|, but may be accessed without lock after that. |
| 216 | LogCallback log_callback_; |
| 217 | }; |
| 218 | |
| 219 | LogMessageManager* GetLogMessageManager() { |
| 220 | static base::NoDestructor<LogMessageManager> message_manager; |
| 221 | return message_manager.get(); |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 222 | } |
| 223 | |
Dale Curtis | ef40483 | 2020-03-31 23:05:42 | [diff] [blame] | 224 | bool PreInitializeLogHandler(int severity, |
| 225 | const char* file, |
| 226 | int line, |
| 227 | size_t message_start, |
| 228 | const std::string& message) { |
| 229 | GetLogMessageManager()->AddDeferredMessage(severity, |
| 230 | message.substr(0, message_start), |
| 231 | message.substr(message_start)); |
| 232 | return false; |
| 233 | } |
| 234 | |
| 235 | bool PostInitializeLogHandler(int severity, |
| 236 | const char* file, |
| 237 | int line, |
| 238 | size_t message_start, |
| 239 | const std::string& message) { |
| 240 | GetLogMessageManager()->RouteMessage(severity, |
| 241 | message.substr(0, message_start), |
| 242 | message.substr(message_start)); |
| 243 | return false; |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 244 | } |
sadrul | 6aafa7d | 2017-03-22 22:56:35 | [diff] [blame] | 245 | |
Wei Lee | 01d63ef | 2019-05-09 09:24:50 | [diff] [blame] | 246 | bool IsAcceleratedJpegDecodeSupported() { |
Yuta Hijikata | 5a9692ce | 2020-11-20 07:26:16 | [diff] [blame] | 247 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Wei Lee | 01d63ef | 2019-05-09 09:24:50 | [diff] [blame] | 248 | return chromeos_camera::GpuMjpegDecodeAcceleratorFactory:: |
| 249 | IsAcceleratedJpegDecodeSupported(); |
| 250 | #else |
| 251 | return false; |
Yuta Hijikata | 5a9692ce | 2020-11-20 07:26:16 | [diff] [blame] | 252 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
Wei Lee | 01d63ef | 2019-05-09 09:24:50 | [diff] [blame] | 253 | } |
| 254 | |
Dale Curtis | a3f8ba3 | 2020-04-27 23:01:09 | [diff] [blame] | 255 | void GetVideoCapabilities(const gpu::GpuPreferences& gpu_preferences, |
| 256 | const gpu::GpuDriverBugWorkarounds& gpu_workarounds, |
| 257 | gpu::GPUInfo* gpu_info) { |
| 258 | // Due to https://crbug.com/709631, we don't want to query Android video |
| 259 | // decode/encode capabilities during startup. The renderer needs this info |
| 260 | // though, so assume some baseline capabilities. |
| 261 | #if defined(OS_ANDROID) |
| 262 | // Note: Video encoding on Android relies on MediaCodec, so all cases |
| 263 | // where it's disabled for decoding it is also disabled for encoding. |
| 264 | if (gpu_preferences.disable_accelerated_video_decode || |
| 265 | gpu_preferences.disable_accelerated_video_encode) { |
| 266 | return; |
| 267 | } |
| 268 | |
| 269 | auto& encoding_profiles = |
| 270 | gpu_info->video_encode_accelerator_supported_profiles; |
| 271 | |
| 272 | gpu::VideoEncodeAcceleratorSupportedProfile vea_profile; |
| 273 | vea_profile.max_resolution = gfx::Size(1280, 720); |
| 274 | vea_profile.max_framerate_numerator = 30; |
| 275 | vea_profile.max_framerate_denominator = 1; |
| 276 | |
| 277 | if (media::MediaCodecUtil::IsVp8EncoderAvailable()) { |
| 278 | vea_profile.profile = gpu::VP8PROFILE_ANY; |
| 279 | encoding_profiles.push_back(vea_profile); |
| 280 | } |
| 281 | |
| 282 | #if BUILDFLAG(USE_PROPRIETARY_CODECS) |
| 283 | if (media::MediaCodecUtil::IsH264EncoderAvailable(/*use_codec_list*/ false)) { |
| 284 | vea_profile.profile = gpu::H264PROFILE_BASELINE; |
| 285 | encoding_profiles.push_back(vea_profile); |
| 286 | } |
| 287 | #endif |
| 288 | |
| 289 | // Note: Since Android doesn't have to support PPAPI/Flash, we have not |
| 290 | // returned the decoder profiles here since https://crrev.com/665999. |
| 291 | #else |
| 292 | gpu_info->video_decode_accelerator_capabilities = |
| 293 | media::GpuVideoDecodeAccelerator::GetCapabilities(gpu_preferences, |
| 294 | gpu_workarounds); |
| 295 | gpu_info->video_encode_accelerator_supported_profiles = |
| 296 | media::GpuVideoAcceleratorUtil::ConvertMediaToGpuEncodeProfiles( |
| 297 | media::GpuVideoEncodeAcceleratorFactory::GetSupportedProfiles( |
Miguel Casas | 0acd0c2 | 2020-09-01 17:07:18 | [diff] [blame] | 298 | gpu_preferences, gpu_workarounds)); |
Dale Curtis | a3f8ba3 | 2020-04-27 23:01:09 | [diff] [blame] | 299 | #endif |
| 300 | } |
| 301 | |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 302 | // Returns a callback which does a PostTask to run |callback| on the |runner| |
| 303 | // task runner. |
Sidney San MartÃn | 9387b40 | 2018-06-08 18:13:26 | [diff] [blame] | 304 | template <typename... Params> |
| 305 | base::OnceCallback<void(Params&&...)> WrapCallback( |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 306 | scoped_refptr<base::SingleThreadTaskRunner> runner, |
Sidney San MartÃn | 9387b40 | 2018-06-08 18:13:26 | [diff] [blame] | 307 | base::OnceCallback<void(Params...)> callback) { |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 308 | return base::BindOnce( |
| 309 | [](base::SingleThreadTaskRunner* runner, |
Sidney San MartÃn | 9387b40 | 2018-06-08 18:13:26 | [diff] [blame] | 310 | base::OnceCallback<void(Params && ...)> callback, Params&&... params) { |
| 311 | runner->PostTask(FROM_HERE, |
| 312 | base::BindOnce(std::move(callback), |
| 313 | std::forward<Params>(params)...)); |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 314 | }, |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 315 | base::RetainedRef(std::move(runner)), std::move(callback)); |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 316 | } |
| 317 | |
sadrul | 6aafa7d | 2017-03-22 22:56:35 | [diff] [blame] | 318 | } // namespace |
| 319 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 320 | GpuServiceImpl::GpuServiceImpl( |
| 321 | const gpu::GPUInfo& gpu_info, |
| 322 | std::unique_ptr<gpu::GpuWatchdogThread> watchdog_thread, |
| 323 | scoped_refptr<base::SingleThreadTaskRunner> io_runner, |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 324 | const gpu::GpuFeatureInfo& gpu_feature_info, |
Zhenyao Mo | 68ef56d | 2018-04-21 01:05:10 | [diff] [blame] | 325 | const gpu::GpuPreferences& gpu_preferences, |
Zhenyao Mo | b79101d | 2018-04-24 21:12:07 | [diff] [blame] | 326 | const base::Optional<gpu::GPUInfo>& gpu_info_for_hardware_gpu, |
| 327 | const base::Optional<gpu::GpuFeatureInfo>& |
kylechar | 56ddcdc2 | 2018-05-28 16:45:38 | [diff] [blame] | 328 | gpu_feature_info_for_hardware_gpu, |
Alexander Dunaev | e6e09c1 | 2020-10-23 16:43:42 | [diff] [blame] | 329 | const gfx::GpuExtraInfo& gpu_extra_info, |
Peng Huang | cfc3180d | 2018-07-16 21:47:08 | [diff] [blame] | 330 | gpu::VulkanImplementation* vulkan_implementation, |
Patrick To | df5911c | 2020-05-12 19:31:42 | [diff] [blame] | 331 | base::OnceCallback<void(base::Optional<ExitCode>)> exit_callback) |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 332 | : main_runner_(base::ThreadTaskRunnerHandle::Get()), |
| 333 | io_runner_(std::move(io_runner)), |
ericrk | 32c08ce | 2016-10-14 15:44:12 | [diff] [blame] | 334 | watchdog_thread_(std::move(watchdog_thread)), |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 335 | gpu_preferences_(gpu_preferences), |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 336 | gpu_info_(gpu_info), |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 337 | gpu_feature_info_(gpu_feature_info), |
Zhenyao Mo | 68ef56d | 2018-04-21 01:05:10 | [diff] [blame] | 338 | gpu_info_for_hardware_gpu_(gpu_info_for_hardware_gpu), |
| 339 | gpu_feature_info_for_hardware_gpu_(gpu_feature_info_for_hardware_gpu), |
Jonah Ryan-Davis | a70577c | 2019-06-26 18:54:31 | [diff] [blame] | 340 | gpu_extra_info_(gpu_extra_info), |
Peng Huang | cfc3180d | 2018-07-16 21:47:08 | [diff] [blame] | 341 | #if BUILDFLAG(ENABLE_VULKAN) |
| 342 | vulkan_implementation_(vulkan_implementation), |
| 343 | #endif |
kylechar | 14fe0ac | 2019-10-18 18:38:35 | [diff] [blame] | 344 | exit_callback_(std::move(exit_callback)) { |
sadrul | 9594ef3 | 2017-04-11 22:17:12 | [diff] [blame] | 345 | DCHECK(!io_runner_->BelongsToCurrentThread()); |
Wez | d476f83e | 2018-09-10 21:05:50 | [diff] [blame] | 346 | DCHECK(exit_callback_); |
| 347 | |
Yuta Hijikata | 5a9692ce | 2020-11-20 07:26:16 | [diff] [blame] | 348 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Hirokazu Honda | c6dac9f | 2018-03-24 02:07:06 | [diff] [blame] | 349 | protected_buffer_manager_ = new arc::ProtectedBufferManager(); |
Yuta Hijikata | 5a9692ce | 2020-11-20 07:26:16 | [diff] [blame] | 350 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
Peng Huang | cfc3180d | 2018-07-16 21:47:08 | [diff] [blame] | 351 | |
Khushal | cbce6f7 | 2020-12-12 03:48:30 | [diff] [blame^] | 352 | GrContextOptions context_options = GetDefaultGrContextOptions( |
| 353 | gpu_preferences_.gr_context_type, gpu_preferences_); |
Sergey Ulanov | 689c31f | 2020-01-24 23:21:16 | [diff] [blame] | 354 | if (gpu_preferences_.force_max_texture_size) { |
| 355 | context_options.fMaxTextureSizeOverride = |
| 356 | gpu_preferences_.force_max_texture_size; |
| 357 | } |
Sergey Ulanov | d0066bbd | 2020-01-24 01:13:40 | [diff] [blame] | 358 | |
Peng Huang | cfc3180d | 2018-07-16 21:47:08 | [diff] [blame] | 359 | #if BUILDFLAG(ENABLE_VULKAN) |
| 360 | if (vulkan_implementation_) { |
Peng Huang | ea21d6f | 2020-05-14 18:22:22 | [diff] [blame] | 361 | bool is_native_vulkan = |
| 362 | gpu_preferences_.use_vulkan == gpu::VulkanImplementationName::kNative || |
| 363 | gpu_preferences_.use_vulkan == |
| 364 | gpu::VulkanImplementationName::kForcedNative; |
| 365 | // With swiftshader the vendor_id is 0xffff. For some tests gpu_info is not |
| 366 | // initialized, so the vendor_id is 0. |
| 367 | bool is_native_gl = |
| 368 | gpu_info_.gpu.vendor_id != 0xffff && gpu_info_.gpu.vendor_id != 0; |
| 369 | // If GL is using a real GPU, the gpu_info will be passed in and vulkan will |
| 370 | // use the same GPU. |
Sergey Ulanov | d0066bbd | 2020-01-24 01:13:40 | [diff] [blame] | 371 | vulkan_context_provider_ = VulkanInProcessContextProvider::Create( |
Vasiliy Telezhnikov | 6aee929 | 2020-11-24 22:46:55 | [diff] [blame] | 372 | vulkan_implementation_, |
Peng Huang | ea21d6f | 2020-05-14 18:22:22 | [diff] [blame] | 373 | (is_native_vulkan && is_native_gl) ? &gpu_info : nullptr); |
Jonathan Backer | 7f3b64a | 2019-05-16 21:41:39 | [diff] [blame] | 374 | if (vulkan_context_provider_) { |
| 375 | // If Vulkan is supported, then OOP-R is supported. |
| 376 | gpu_info_.oop_rasterization_supported = true; |
| 377 | gpu_feature_info_.status_values[gpu::GPU_FEATURE_TYPE_OOP_RASTERIZATION] = |
| 378 | gpu::kGpuFeatureStatusEnabled; |
| 379 | } else { |
Peng Huang | 576415de | 2020-03-02 20:04:32 | [diff] [blame] | 380 | DLOG(ERROR) << "Failed to create Vulkan context provider."; |
Jonathan Backer | 7f3b64a | 2019-05-16 21:41:39 | [diff] [blame] | 381 | } |
Peng Huang | cfc3180d | 2018-07-16 21:47:08 | [diff] [blame] | 382 | } |
| 383 | #endif |
| 384 | |
Sean Gilhuly | e534232 | 2019-11-08 16:40:53 | [diff] [blame] | 385 | #if BUILDFLAG(SKIA_USE_DAWN) |
| 386 | if (gpu_preferences_.gr_context_type == gpu::GrContextType::kDawn) { |
Stephen White | 349114a | 2020-01-27 21:40:24 | [diff] [blame] | 387 | dawn_context_provider_ = DawnContextProvider::Create(); |
Sean Gilhuly | e534232 | 2019-11-08 16:40:53 | [diff] [blame] | 388 | if (dawn_context_provider_) { |
| 389 | gpu_info_.oop_rasterization_supported = true; |
| 390 | gpu_feature_info_.status_values[gpu::GPU_FEATURE_TYPE_OOP_RASTERIZATION] = |
| 391 | gpu::kGpuFeatureStatusEnabled; |
| 392 | } else { |
Peng Huang | 576415de | 2020-03-02 20:04:32 | [diff] [blame] | 393 | DLOG(ERROR) << "Failed to create Dawn context provider."; |
Sean Gilhuly | e534232 | 2019-11-08 16:40:53 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | #endif |
| 397 | |
Ted Meyer | c80c136 | 2020-10-13 00:43:42 | [diff] [blame] | 398 | #if BUILDFLAG(USE_VAAPI_IMAGE_CODECS) |
Gil Dekel | 8f4b564 | 2019-07-27 05:27:40 | [diff] [blame] | 399 | image_decode_accelerator_worker_ = |
| 400 | media::VaapiImageDecodeAcceleratorWorker::Create(); |
Ted Meyer | c80c136 | 2020-10-13 00:43:42 | [diff] [blame] | 401 | #endif // BUILDFLAG(USE_VAAPI_IMAGE_CODECS) |
Andres Calderon Jaramillo | 12a1c6d | 2019-06-26 04:42:34 | [diff] [blame] | 402 | |
Avi Drissman | 8fd9217 | 2020-07-28 15:49:45 | [diff] [blame] | 403 | #if defined(OS_APPLE) |
Christopher Cameron | 3a360189 | 2019-05-16 21:43:52 | [diff] [blame] | 404 | if (gpu_feature_info_.status_values[gpu::GPU_FEATURE_TYPE_METAL] == |
| 405 | gpu::kGpuFeatureStatusEnabled) { |
Sergey Ulanov | d0066bbd | 2020-01-24 01:13:40 | [diff] [blame] | 406 | metal_context_provider_ = MetalContextProvider::Create(context_options); |
Christopher Cameron | 3a360189 | 2019-05-16 21:43:52 | [diff] [blame] | 407 | } |
Christopher Cameron | 4f7ce36 | 2019-04-26 02:21:37 | [diff] [blame] | 408 | #endif |
| 409 | |
Maggie Chen | 05364bf3 | 2020-06-03 08:34:06 | [diff] [blame] | 410 | #if defined(OS_WIN) |
| 411 | auto info_callback = base::BindRepeating( |
| 412 | &GpuServiceImpl::UpdateOverlayAndHDRInfo, weak_ptr_factory_.GetWeakPtr()); |
| 413 | gl::DirectCompositionSurfaceWin::SetOverlayHDRGpuInfoUpdateCallback( |
| 414 | info_callback); |
| 415 | #endif |
| 416 | |
Sergey Ulanov | 3a8f8d2d | 2019-04-22 18:33:11 | [diff] [blame] | 417 | gpu_memory_buffer_factory_ = |
| 418 | gpu::GpuMemoryBufferFactory::CreateNativeType(vulkan_context_provider()); |
| 419 | |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 420 | weak_ptr_ = weak_ptr_factory_.GetWeakPtr(); |
| 421 | } |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 422 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 423 | GpuServiceImpl::~GpuServiceImpl() { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 424 | DCHECK(main_runner_->BelongsToCurrentThread()); |
kylechar | 32f8fbf | 2019-06-12 16:46:24 | [diff] [blame] | 425 | |
| 426 | // Ensure we don't try to exit when already in the process of exiting. |
| 427 | is_exiting_.Set(); |
| 428 | |
sadrul | 7468588 | 2017-04-01 01:33:43 | [diff] [blame] | 429 | bind_task_tracker_.TryCancelAll(); |
Dale Curtis | ef40483 | 2020-03-31 23:05:42 | [diff] [blame] | 430 | GetLogMessageManager()->ShutdownLogging(); |
kylechar | 14fe0ac | 2019-10-18 18:38:35 | [diff] [blame] | 431 | |
| 432 | // Destroy the receiver on the IO thread. |
kylechar | 56ddcdc2 | 2018-05-28 16:45:38 | [diff] [blame] | 433 | base::WaitableEvent wait; |
kylechar | 14fe0ac | 2019-10-18 18:38:35 | [diff] [blame] | 434 | auto destroy_receiver_task = base::BindOnce( |
| 435 | [](mojo::Receiver<mojom::GpuService>* receiver, |
| 436 | base::WaitableEvent* wait) { |
| 437 | receiver->reset(); |
| 438 | wait->Signal(); |
| 439 | }, |
| 440 | &receiver_, &wait); |
| 441 | if (io_runner_->PostTask(FROM_HERE, std::move(destroy_receiver_task))) |
sadrul | 9594ef3 | 2017-04-11 22:17:12 | [diff] [blame] | 442 | wait.Wait(); |
Peng Huang | fb0cf37 | 2018-03-22 17:29:27 | [diff] [blame] | 443 | |
Maggie Chen | 8309029 | 2019-08-30 05:15:48 | [diff] [blame] | 444 | if (watchdog_thread_) |
| 445 | watchdog_thread_->OnGpuProcessTearDown(); |
| 446 | |
xhwang | b2402d9 | 2016-10-15 07:29:37 | [diff] [blame] | 447 | media_gpu_channel_manager_.reset(); |
sadrul | 5b860bd | 2016-09-26 20:15:34 | [diff] [blame] | 448 | gpu_channel_manager_.reset(); |
Sunny Sachanandani | d3d647d8 | 2019-01-16 04:52:45 | [diff] [blame] | 449 | |
| 450 | // Scheduler must be destroyed before sync point manager is destroyed. |
| 451 | scheduler_.reset(); |
sadrul | 5b860bd | 2016-09-26 20:15:34 | [diff] [blame] | 452 | owned_sync_point_manager_.reset(); |
Peng Huang | e3b8c1d | 2019-03-05 17:21:12 | [diff] [blame] | 453 | owned_shared_image_manager_.reset(); |
sadrul | 08f982ad | 2016-09-14 03:04:53 | [diff] [blame] | 454 | |
Andres Calderon Jaramillo | 12a1c6d | 2019-06-26 04:42:34 | [diff] [blame] | 455 | // The image decode accelerator worker must outlive the GPU channel manager so |
| 456 | // that it doesn't get any decode requests during/after destruction. |
| 457 | DCHECK(!gpu_channel_manager_); |
Gil Dekel | 8f4b564 | 2019-07-27 05:27:40 | [diff] [blame] | 458 | image_decode_accelerator_worker_.reset(); |
Andres Calderon Jaramillo | 12a1c6d | 2019-06-26 04:42:34 | [diff] [blame] | 459 | |
sunnyps | 41a6a15a | 2017-03-31 00:38:54 | [diff] [blame] | 460 | // Signal this event before destroying the child process. That way all |
| 461 | // background threads can cleanup. For example, in the renderer the |
| 462 | // RenderThread instances will be able to notice shutdown before the render |
| 463 | // process begins waiting for them to exit. |
| 464 | if (owned_shutdown_event_) |
| 465 | owned_shutdown_event_->Signal(); |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 466 | } |
fsamuel | b25f854 | 2016-04-22 19:14:07 | [diff] [blame] | 467 | |
Zhenyao Mo | 83b895e | 2017-10-18 18:50:54 | [diff] [blame] | 468 | void GpuServiceImpl::UpdateGPUInfo() { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 469 | DCHECK(main_runner_->BelongsToCurrentThread()); |
sadrul | b92e8e93 | 2016-12-08 20:59:24 | [diff] [blame] | 470 | DCHECK(!gpu_host_); |
Zhenyao Mo | d4dba105 | 2017-07-27 23:02:39 | [diff] [blame] | 471 | gpu::GpuDriverBugWorkarounds gpu_workarounds( |
| 472 | gpu_feature_info_.enabled_gpu_driver_bug_workarounds); |
Dale Curtis | a3f8ba3 | 2020-04-27 23:01:09 | [diff] [blame] | 473 | |
| 474 | GetVideoCapabilities(gpu_preferences_, gpu_workarounds, &gpu_info_); |
| 475 | |
Wei Lee | 01d63ef | 2019-05-09 09:24:50 | [diff] [blame] | 476 | gpu_info_.jpeg_decode_accelerator_supported = |
| 477 | IsAcceleratedJpegDecodeSupported(); |
Andres Calderon Jaramillo | 12a1c6d | 2019-06-26 04:42:34 | [diff] [blame] | 478 | |
Gil Dekel | 8f4b564 | 2019-07-27 05:27:40 | [diff] [blame] | 479 | if (image_decode_accelerator_worker_) { |
Andres Calderon Jaramillo | 12a1c6d | 2019-06-26 04:42:34 | [diff] [blame] | 480 | gpu_info_.image_decode_accelerator_supported_profiles = |
Gil Dekel | 8f4b564 | 2019-07-27 05:27:40 | [diff] [blame] | 481 | image_decode_accelerator_worker_->GetSupportedProfiles(); |
Andres Calderon Jaramillo | 12a1c6d | 2019-06-26 04:42:34 | [diff] [blame] | 482 | } |
| 483 | |
sadrul | 041ca72 | 2017-03-24 22:35:35 | [diff] [blame] | 484 | // Record initialization only after collecting the GPU info because that can |
| 485 | // take a significant amount of time. |
| 486 | gpu_info_.initialization_time = base::Time::Now() - start_time_; |
| 487 | } |
| 488 | |
Jonah Ryan-Davis | a54a300 | 2020-12-08 17:34:50 | [diff] [blame] | 489 | void GpuServiceImpl::UpdateGPUInfoGL() { |
| 490 | DCHECK(main_runner_->BelongsToCurrentThread()); |
| 491 | gpu::CollectGraphicsInfoGL(&gpu_info_); |
| 492 | gpu_host_->DidUpdateGPUInfo(gpu_info_); |
| 493 | } |
| 494 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 495 | void GpuServiceImpl::InitializeWithHost( |
Shimi Zhang | 88ae922 | 2019-07-19 16:54:16 | [diff] [blame] | 496 | mojo::PendingRemote<mojom::GpuHost> pending_gpu_host, |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 497 | gpu::GpuProcessActivityFlags activity_flags, |
Eric Karl | 304eff1 | 2018-07-27 21:13:35 | [diff] [blame] | 498 | scoped_refptr<gl::GLSurface> default_offscreen_surface, |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 499 | gpu::SyncPointManager* sync_point_manager, |
Peng Huang | e3b8c1d | 2019-03-05 17:21:12 | [diff] [blame] | 500 | gpu::SharedImageManager* shared_image_manager, |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 501 | base::WaitableEvent* shutdown_event) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 502 | DCHECK(main_runner_->BelongsToCurrentThread()); |
Shimi Zhang | 88ae922 | 2019-07-19 16:54:16 | [diff] [blame] | 503 | |
| 504 | mojo::Remote<mojom::GpuHost> gpu_host(std::move(pending_gpu_host)); |
Zhenyao Mo | 68ef56d | 2018-04-21 01:05:10 | [diff] [blame] | 505 | gpu_host->DidInitialize(gpu_info_, gpu_feature_info_, |
| 506 | gpu_info_for_hardware_gpu_, |
Jonah Ryan-Davis | a70577c | 2019-06-26 18:54:31 | [diff] [blame] | 507 | gpu_feature_info_for_hardware_gpu_, gpu_extra_info_); |
Shimi Zhang | 88ae922 | 2019-07-19 16:54:16 | [diff] [blame] | 508 | gpu_host_ = mojo::SharedRemote<mojom::GpuHost>(gpu_host.Unbind(), io_runner_); |
Sadrul Habib Chowdhury | dbe4da9 | 2017-10-12 15:53:15 | [diff] [blame] | 509 | if (!in_host_process()) { |
sadrul | 6aafa7d | 2017-03-22 22:56:35 | [diff] [blame] | 510 | // The global callback is reset from the dtor. So Unretained() here is safe. |
| 511 | // Note that the callback can be called from any thread. Consequently, the |
| 512 | // callback cannot use a WeakPtr. |
Dale Curtis | ef40483 | 2020-03-31 23:05:42 | [diff] [blame] | 513 | GetLogMessageManager()->InstallPostInitializeLogHandler(base::BindRepeating( |
| 514 | &GpuServiceImpl::RecordLogMessage, base::Unretained(this))); |
sadrul | 6aafa7d | 2017-03-22 22:56:35 | [diff] [blame] | 515 | } |
| 516 | |
Peng Huang | d5b1caf | 2019-03-05 20:51:18 | [diff] [blame] | 517 | if (!sync_point_manager) { |
Jinho Bang | 24ca9cd | 2018-01-02 22:01:00 | [diff] [blame] | 518 | owned_sync_point_manager_ = std::make_unique<gpu::SyncPointManager>(); |
Peng Huang | d5b1caf | 2019-03-05 20:51:18 | [diff] [blame] | 519 | sync_point_manager = owned_sync_point_manager_.get(); |
sadrul | 72aae8a | 2017-01-24 04:52:32 | [diff] [blame] | 520 | } |
sadrul | b92e8e93 | 2016-12-08 20:59:24 | [diff] [blame] | 521 | |
Peng Huang | e3b8c1d | 2019-03-05 17:21:12 | [diff] [blame] | 522 | if (!shared_image_manager) { |
Saman Sami | 1cf5217 | 2020-01-13 19:05:27 | [diff] [blame] | 523 | // When using real buffers for testing overlay configurations, we need |
| 524 | // access to SharedImageManager on the viz thread to obtain the buffer |
| 525 | // corresponding to a mailbox. |
| 526 | bool thread_safe_manager = features::ShouldUseRealBuffersForPageFlipTest(); |
| 527 | owned_shared_image_manager_ = std::make_unique<gpu::SharedImageManager>( |
| 528 | thread_safe_manager, false /* display_context_on_another_thread */); |
Peng Huang | e3b8c1d | 2019-03-05 17:21:12 | [diff] [blame] | 529 | shared_image_manager = owned_shared_image_manager_.get(); |
Saman Sami | 1cf5217 | 2020-01-13 19:05:27 | [diff] [blame] | 530 | } else { |
| 531 | // With this feature enabled, we don't expect to receive an external |
| 532 | // SharedImageManager. |
| 533 | DCHECK(!features::ShouldUseRealBuffersForPageFlipTest()); |
Peng Huang | e3b8c1d | 2019-03-05 17:21:12 | [diff] [blame] | 534 | } |
| 535 | |
sunnyps | 41a6a15a | 2017-03-31 00:38:54 | [diff] [blame] | 536 | shutdown_event_ = shutdown_event; |
| 537 | if (!shutdown_event_) { |
Jinho Bang | 24ca9cd | 2018-01-02 22:01:00 | [diff] [blame] | 538 | owned_shutdown_event_ = std::make_unique<base::WaitableEvent>( |
sunnyps | 41a6a15a | 2017-03-31 00:38:54 | [diff] [blame] | 539 | base::WaitableEvent::ResetPolicy::MANUAL, |
| 540 | base::WaitableEvent::InitialState::NOT_SIGNALED); |
| 541 | shutdown_event_ = owned_shutdown_event_.get(); |
| 542 | } |
| 543 | |
Vasiliy Telezhnikov | 533c564 | 2019-12-03 15:10:16 | [diff] [blame] | 544 | scheduler_ = std::make_unique<gpu::Scheduler>( |
Kramer Ge | 65a4de9 | 2020-02-24 20:46:49 | [diff] [blame] | 545 | main_runner_, sync_point_manager, gpu_preferences_); |
sunnyps | 8f9139e | 2017-05-12 17:53:25 | [diff] [blame] | 546 | |
sadrul | b92e8e93 | 2016-12-08 20:59:24 | [diff] [blame] | 547 | // Defer creation of the render thread. This is to prevent it from handling |
| 548 | // IPC messages before the sandbox has been enabled and all other necessary |
| 549 | // initialization has succeeded. |
Peng Huang | 42c8a1d | 2018-10-30 18:28:14 | [diff] [blame] | 550 | gpu_channel_manager_ = std::make_unique<gpu::GpuChannelManager>( |
Zhenyao Mo | d4dba105 | 2017-07-27 23:02:39 | [diff] [blame] | 551 | gpu_preferences_, this, watchdog_thread_.get(), main_runner_, io_runner_, |
Kramer Ge | 65a4de9 | 2020-02-24 20:46:49 | [diff] [blame] | 552 | scheduler_.get(), sync_point_manager, shared_image_manager, |
Peng Huang | e3b8c1d | 2019-03-05 17:21:12 | [diff] [blame] | 553 | gpu_memory_buffer_factory_.get(), gpu_feature_info_, |
Kramer Ge | 65a4de9 | 2020-02-24 20:46:49 | [diff] [blame] | 554 | std::move(activity_flags), std::move(default_offscreen_surface), |
Gil Dekel | 8f4b564 | 2019-07-27 05:27:40 | [diff] [blame] | 555 | image_decode_accelerator_worker_.get(), vulkan_context_provider(), |
Sean Gilhuly | e534232 | 2019-11-08 16:40:53 | [diff] [blame] | 556 | metal_context_provider_.get(), dawn_context_provider()); |
sadrul | b92e8e93 | 2016-12-08 20:59:24 | [diff] [blame] | 557 | |
Kramer Ge | 65a4de9 | 2020-02-24 20:46:49 | [diff] [blame] | 558 | media_gpu_channel_manager_.reset( |
| 559 | new media::MediaGpuChannelManager(gpu_channel_manager_.get())); |
| 560 | if (watchdog_thread()) |
| 561 | watchdog_thread()->AddPowerObserver(); |
sadrul | b92e8e93 | 2016-12-08 20:59:24 | [diff] [blame] | 562 | } |
| 563 | |
kylechar | 14fe0ac | 2019-10-18 18:38:35 | [diff] [blame] | 564 | void GpuServiceImpl::Bind( |
| 565 | mojo::PendingReceiver<mojom::GpuService> pending_receiver) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 566 | if (main_runner_->BelongsToCurrentThread()) { |
sadrul | 7468588 | 2017-04-01 01:33:43 | [diff] [blame] | 567 | bind_task_tracker_.PostTask( |
| 568 | io_runner_.get(), FROM_HERE, |
Claudio DeSouza | 591a997 | 2018-02-21 17:27:16 | [diff] [blame] | 569 | base::BindOnce(&GpuServiceImpl::Bind, base::Unretained(this), |
kylechar | 14fe0ac | 2019-10-18 18:38:35 | [diff] [blame] | 570 | std::move(pending_receiver))); |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 571 | return; |
| 572 | } |
kylechar | 14fe0ac | 2019-10-18 18:38:35 | [diff] [blame] | 573 | DCHECK(!receiver_.is_bound()); |
| 574 | receiver_.Bind(std::move(pending_receiver)); |
sadrul | d1cca1e | 2016-09-13 19:51:35 | [diff] [blame] | 575 | } |
| 576 | |
kylechar | f0a9935 | 2018-05-31 21:39:32 | [diff] [blame] | 577 | void GpuServiceImpl::DisableGpuCompositing() { |
| 578 | // Can be called from any thread. |
Shimi Zhang | 88ae922 | 2019-07-19 16:54:16 | [diff] [blame] | 579 | gpu_host_->DisableGpuCompositing(); |
kylechar | f0a9935 | 2018-05-31 21:39:32 | [diff] [blame] | 580 | } |
| 581 | |
Chris Blume | 40d79e9 | 2019-03-28 19:26:09 | [diff] [blame] | 582 | scoped_refptr<gpu::SharedContextState> GpuServiceImpl::GetContextState() { |
Peng Huang | fb0cf37 | 2018-03-22 17:29:27 | [diff] [blame] | 583 | DCHECK(main_runner_->BelongsToCurrentThread()); |
Peng Huang | 42c8a1d | 2018-10-30 18:28:14 | [diff] [blame] | 584 | gpu::ContextResult result; |
Peng Huang | 20361dad1 | 2019-01-23 14:48:10 | [diff] [blame] | 585 | return gpu_channel_manager_->GetSharedContextState(&result); |
Peng Huang | cfc3180d | 2018-07-16 21:47:08 | [diff] [blame] | 586 | } |
| 587 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 588 | gpu::ImageFactory* GpuServiceImpl::gpu_image_factory() { |
sadrul | 6d41b82 | 2017-04-02 03:38:50 | [diff] [blame] | 589 | return gpu_memory_buffer_factory_ |
| 590 | ? gpu_memory_buffer_factory_->AsImageFactory() |
| 591 | : nullptr; |
| 592 | } |
| 593 | |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 594 | // static |
| 595 | void GpuServiceImpl::InstallPreInitializeLogHandler() { |
Dale Curtis | ef40483 | 2020-03-31 23:05:42 | [diff] [blame] | 596 | GetLogMessageManager()->InstallPreInitializeLogHandler(); |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | // static |
| 600 | void GpuServiceImpl::FlushPreInitializeLogMessages(mojom::GpuHost* gpu_host) { |
Dale Curtis | ef40483 | 2020-03-31 23:05:42 | [diff] [blame] | 601 | GetLogMessageManager()->FlushMessages(gpu_host); |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 602 | } |
| 603 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 604 | void GpuServiceImpl::RecordLogMessage(int severity, |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 605 | const std::string& header, |
| 606 | const std::string& message) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 607 | // This can be run from any thread. |
Dale Curtis | 1b6becebb | 2020-03-30 20:13:35 | [diff] [blame] | 608 | gpu_host_->RecordLogMessage(severity, std::move(header), std::move(message)); |
sadrul | 6aafa7d | 2017-03-22 22:56:35 | [diff] [blame] | 609 | } |
| 610 | |
Yuta Hijikata | 5a9692ce | 2020-11-20 07:26:16 | [diff] [blame] | 611 | #if BUILDFLAG(IS_CHROMEOS_ASH) |
Hirokazu Honda | 12eaf9c | 2017-12-12 02:40:16 | [diff] [blame] | 612 | void GpuServiceImpl::CreateArcVideoDecodeAccelerator( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 613 | mojo::PendingReceiver<arc::mojom::VideoDecodeAccelerator> vda_receiver) { |
Hirokazu Honda | 12eaf9c | 2017-12-12 02:40:16 | [diff] [blame] | 614 | DCHECK(io_runner_->BelongsToCurrentThread()); |
| 615 | main_runner_->PostTask( |
| 616 | FROM_HERE, |
| 617 | base::BindOnce( |
| 618 | &GpuServiceImpl::CreateArcVideoDecodeAcceleratorOnMainThread, |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 619 | weak_ptr_, std::move(vda_receiver))); |
Hirokazu Honda | 12eaf9c | 2017-12-12 02:40:16 | [diff] [blame] | 620 | } |
| 621 | |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 622 | void GpuServiceImpl::CreateArcVideoEncodeAccelerator( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 623 | mojo::PendingReceiver<arc::mojom::VideoEncodeAccelerator> vea_receiver) { |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 624 | DCHECK(io_runner_->BelongsToCurrentThread()); |
| 625 | main_runner_->PostTask( |
| 626 | FROM_HERE, |
| 627 | base::BindOnce( |
| 628 | &GpuServiceImpl::CreateArcVideoEncodeAcceleratorOnMainThread, |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 629 | weak_ptr_, std::move(vea_receiver))); |
Hirokazu Honda | 0526850 | 2018-03-31 05:18:39 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | void GpuServiceImpl::CreateArcVideoProtectedBufferAllocator( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 633 | mojo::PendingReceiver<arc::mojom::VideoProtectedBufferAllocator> |
| 634 | pba_receiver) { |
Hirokazu Honda | 0526850 | 2018-03-31 05:18:39 | [diff] [blame] | 635 | DCHECK(io_runner_->BelongsToCurrentThread()); |
| 636 | main_runner_->PostTask( |
| 637 | FROM_HERE, |
| 638 | base::BindOnce( |
| 639 | &GpuServiceImpl::CreateArcVideoProtectedBufferAllocatorOnMainThread, |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 640 | weak_ptr_, std::move(pba_receiver))); |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 641 | } |
| 642 | |
| 643 | void GpuServiceImpl::CreateArcProtectedBufferManager( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 644 | mojo::PendingReceiver<arc::mojom::ProtectedBufferManager> pbm_receiver) { |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 645 | DCHECK(io_runner_->BelongsToCurrentThread()); |
| 646 | main_runner_->PostTask( |
| 647 | FROM_HERE, |
| 648 | base::BindOnce( |
| 649 | &GpuServiceImpl::CreateArcProtectedBufferManagerOnMainThread, |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 650 | weak_ptr_, std::move(pbm_receiver))); |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 651 | } |
| 652 | |
Hirokazu Honda | 12eaf9c | 2017-12-12 02:40:16 | [diff] [blame] | 653 | void GpuServiceImpl::CreateArcVideoDecodeAcceleratorOnMainThread( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 654 | mojo::PendingReceiver<arc::mojom::VideoDecodeAccelerator> vda_receiver) { |
Hirokazu Honda | 12eaf9c | 2017-12-12 02:40:16 | [diff] [blame] | 655 | DCHECK(main_runner_->BelongsToCurrentThread()); |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 656 | mojo::MakeSelfOwnedReceiver( |
| 657 | std::make_unique<arc::GpuArcVideoDecodeAccelerator>( |
Chunbo Hua | d90bffb2 | 2020-09-28 15:34:36 | [diff] [blame] | 658 | gpu_preferences_, gpu_channel_manager_->gpu_driver_bug_workarounds(), |
| 659 | protected_buffer_manager_), |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 660 | std::move(vda_receiver)); |
Hirokazu Honda | 12eaf9c | 2017-12-12 02:40:16 | [diff] [blame] | 661 | } |
| 662 | |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 663 | void GpuServiceImpl::CreateArcVideoEncodeAcceleratorOnMainThread( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 664 | mojo::PendingReceiver<arc::mojom::VideoEncodeAccelerator> vea_receiver) { |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 665 | DCHECK(main_runner_->BelongsToCurrentThread()); |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 666 | mojo::MakeSelfOwnedReceiver( |
Chunbo Hua | d90bffb2 | 2020-09-28 15:34:36 | [diff] [blame] | 667 | std::make_unique<arc::GpuArcVideoEncodeAccelerator>( |
| 668 | gpu_preferences_, gpu_channel_manager_->gpu_driver_bug_workarounds()), |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 669 | std::move(vea_receiver)); |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 670 | } |
| 671 | |
Hirokazu Honda | 0526850 | 2018-03-31 05:18:39 | [diff] [blame] | 672 | void GpuServiceImpl::CreateArcVideoProtectedBufferAllocatorOnMainThread( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 673 | mojo::PendingReceiver<arc::mojom::VideoProtectedBufferAllocator> |
| 674 | pba_receiver) { |
Hirokazu Honda | 0526850 | 2018-03-31 05:18:39 | [diff] [blame] | 675 | DCHECK(main_runner_->BelongsToCurrentThread()); |
| 676 | auto gpu_arc_video_protected_buffer_allocator = |
| 677 | arc::GpuArcVideoProtectedBufferAllocator::Create( |
| 678 | protected_buffer_manager_); |
| 679 | if (!gpu_arc_video_protected_buffer_allocator) |
| 680 | return; |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 681 | mojo::MakeSelfOwnedReceiver( |
| 682 | std::move(gpu_arc_video_protected_buffer_allocator), |
| 683 | std::move(pba_receiver)); |
Hirokazu Honda | 0526850 | 2018-03-31 05:18:39 | [diff] [blame] | 684 | } |
| 685 | |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 686 | void GpuServiceImpl::CreateArcProtectedBufferManagerOnMainThread( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 687 | mojo::PendingReceiver<arc::mojom::ProtectedBufferManager> pbm_receiver) { |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 688 | DCHECK(main_runner_->BelongsToCurrentThread()); |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 689 | mojo::MakeSelfOwnedReceiver( |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 690 | std::make_unique<arc::GpuArcProtectedBufferManagerProxy>( |
Hirokazu Honda | c6dac9f | 2018-03-24 02:07:06 | [diff] [blame] | 691 | protected_buffer_manager_), |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 692 | std::move(pbm_receiver)); |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 693 | } |
Wei Lee | 377f3a6 | 2019-04-17 04:12:11 | [diff] [blame] | 694 | |
Wei Lee | 0cdabc9 | 2019-04-23 04:06:19 | [diff] [blame] | 695 | void GpuServiceImpl::CreateJpegDecodeAccelerator( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 696 | mojo::PendingReceiver<chromeos_camera::mojom::MjpegDecodeAccelerator> |
| 697 | jda_receiver) { |
Wei Lee | 0cdabc9 | 2019-04-23 04:06:19 | [diff] [blame] | 698 | DCHECK(io_runner_->BelongsToCurrentThread()); |
Wei Lee | 01d63ef | 2019-05-09 09:24:50 | [diff] [blame] | 699 | chromeos_camera::MojoMjpegDecodeAcceleratorService::Create( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 700 | std::move(jda_receiver)); |
Wei Lee | 0cdabc9 | 2019-04-23 04:06:19 | [diff] [blame] | 701 | } |
| 702 | |
Wei Lee | 377f3a6 | 2019-04-17 04:12:11 | [diff] [blame] | 703 | void GpuServiceImpl::CreateJpegEncodeAccelerator( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 704 | mojo::PendingReceiver<chromeos_camera::mojom::JpegEncodeAccelerator> |
| 705 | jea_receiver) { |
Wei Lee | 377f3a6 | 2019-04-17 04:12:11 | [diff] [blame] | 706 | DCHECK(io_runner_->BelongsToCurrentThread()); |
Wei Lee | 01d63ef | 2019-05-09 09:24:50 | [diff] [blame] | 707 | chromeos_camera::MojoJpegEncodeAcceleratorService::Create( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 708 | std::move(jea_receiver)); |
Wei Lee | 377f3a6 | 2019-04-17 04:12:11 | [diff] [blame] | 709 | } |
Yuta Hijikata | 5a9692ce | 2020-11-20 07:26:16 | [diff] [blame] | 710 | #endif // BUILDFLAG(IS_CHROMEOS_ASH) |
Peng Huang | 417f0cf7 | 2017-11-20 20:06:16 | [diff] [blame] | 711 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 712 | void GpuServiceImpl::CreateVideoEncodeAcceleratorProvider( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 713 | mojo::PendingReceiver<media::mojom::VideoEncodeAcceleratorProvider> |
| 714 | vea_provider_receiver) { |
Miguel Casas-Sanchez | daca325 | 2017-07-11 08:05:45 | [diff] [blame] | 715 | DCHECK(io_runner_->BelongsToCurrentThread()); |
Miguel Casas-Sanchez | 7d46470 | 2017-07-29 14:19:21 | [diff] [blame] | 716 | media::MojoVideoEncodeAcceleratorProvider::Create( |
Gyuyoung Kim | a1ddaae | 2019-09-12 07:30:25 | [diff] [blame] | 717 | std::move(vea_provider_receiver), |
kylechar | d50f57ee | 2019-01-08 20:23:18 | [diff] [blame] | 718 | base::BindRepeating(&media::GpuVideoEncodeAcceleratorFactory::CreateVEA), |
Chunbo Hua | d90bffb2 | 2020-09-28 15:34:36 | [diff] [blame] | 719 | gpu_preferences_, gpu_channel_manager_->gpu_driver_bug_workarounds()); |
Miguel Casas-Sanchez | daca325 | 2017-07-11 08:05:45 | [diff] [blame] | 720 | } |
| 721 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 722 | void GpuServiceImpl::CreateGpuMemoryBuffer( |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 723 | gfx::GpuMemoryBufferId id, |
sammc | 813a8eb3 | 2016-05-28 03:34:07 | [diff] [blame] | 724 | const gfx::Size& size, |
penghuang | 591151b | 2016-06-04 13:45:32 | [diff] [blame] | 725 | gfx::BufferFormat format, |
| 726 | gfx::BufferUsage usage, |
| 727 | int client_id, |
sadrul | 763bd59 | 2016-09-27 14:33:44 | [diff] [blame] | 728 | gpu::SurfaceHandle surface_handle, |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 729 | CreateGpuMemoryBufferCallback callback) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 730 | DCHECK(io_runner_->BelongsToCurrentThread()); |
| 731 | // This needs to happen in the IO thread. |
Saman Sami | 640ac434 | 2019-07-11 22:52:48 | [diff] [blame] | 732 | gpu_memory_buffer_factory_->CreateGpuMemoryBufferAsync( |
| 733 | id, size, format, usage, client_id, surface_handle, std::move(callback)); |
penghuang | 6cddff4 | 2016-05-13 15:37:46 | [diff] [blame] | 734 | } |
| 735 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 736 | void GpuServiceImpl::DestroyGpuMemoryBuffer(gfx::GpuMemoryBufferId id, |
| 737 | int client_id, |
| 738 | const gpu::SyncToken& sync_token) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 739 | if (io_runner_->BelongsToCurrentThread()) { |
tzik | 2bcf8e4 | 2018-07-31 11:22:15 | [diff] [blame] | 740 | main_runner_->PostTask( |
| 741 | FROM_HERE, base::BindOnce(&GpuServiceImpl::DestroyGpuMemoryBuffer, |
| 742 | weak_ptr_, id, client_id, sync_token)); |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 743 | return; |
| 744 | } |
sadrul | 6a900aa | 2017-04-07 23:30:37 | [diff] [blame] | 745 | gpu_channel_manager_->DestroyGpuMemoryBuffer(id, client_id, sync_token); |
penghuang | 6cddff4 | 2016-05-13 15:37:46 | [diff] [blame] | 746 | } |
| 747 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 748 | void GpuServiceImpl::GetVideoMemoryUsageStats( |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 749 | GetVideoMemoryUsageStatsCallback callback) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 750 | if (io_runner_->BelongsToCurrentThread()) { |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 751 | auto wrap_callback = WrapCallback(io_runner_, std::move(callback)); |
| 752 | main_runner_->PostTask( |
| 753 | FROM_HERE, base::BindOnce(&GpuServiceImpl::GetVideoMemoryUsageStats, |
| 754 | weak_ptr_, std::move(wrap_callback))); |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 755 | return; |
| 756 | } |
sadrul | 3ab0a533 | 2017-03-01 03:16:45 | [diff] [blame] | 757 | gpu::VideoMemoryUsageStats video_memory_usage_stats; |
Antoine Labour | 3b79a44 | 2018-07-06 20:19:34 | [diff] [blame] | 758 | gpu_channel_manager_->GetVideoMemoryUsageStats(&video_memory_usage_stats); |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 759 | std::move(callback).Run(video_memory_usage_stats); |
sadrul | 3ab0a533 | 2017-03-01 03:16:45 | [diff] [blame] | 760 | } |
| 761 | |
jonross | d2ca5e64 | 2019-10-16 12:08:52 | [diff] [blame] | 762 | void GpuServiceImpl::StartPeakMemoryMonitor(uint32_t sequence_num) { |
| 763 | DCHECK(io_runner_->BelongsToCurrentThread()); |
| 764 | main_runner_->PostTask( |
| 765 | FROM_HERE, |
| 766 | base::BindOnce(&GpuServiceImpl::StartPeakMemoryMonitorOnMainThread, |
| 767 | weak_ptr_, sequence_num)); |
| 768 | } |
| 769 | |
| 770 | void GpuServiceImpl::GetPeakMemoryUsage(uint32_t sequence_num, |
| 771 | GetPeakMemoryUsageCallback callback) { |
| 772 | DCHECK(io_runner_->BelongsToCurrentThread()); |
| 773 | main_runner_->PostTask( |
| 774 | FROM_HERE, base::BindOnce(&GpuServiceImpl::GetPeakMemoryUsageOnMainThread, |
| 775 | weak_ptr_, sequence_num, std::move(callback))); |
| 776 | } |
| 777 | |
Christopher Cameron | 51e1d9e | 2017-10-14 00:01:45 | [diff] [blame] | 778 | void GpuServiceImpl::RequestHDRStatus(RequestHDRStatusCallback callback) { |
| 779 | DCHECK(io_runner_->BelongsToCurrentThread()); |
| 780 | main_runner_->PostTask( |
| 781 | FROM_HERE, base::BindOnce(&GpuServiceImpl::RequestHDRStatusOnMainThread, |
| 782 | weak_ptr_, std::move(callback))); |
| 783 | } |
| 784 | |
| 785 | void GpuServiceImpl::RequestHDRStatusOnMainThread( |
| 786 | RequestHDRStatusCallback callback) { |
| 787 | DCHECK(main_runner_->BelongsToCurrentThread()); |
Maggie Chen | 05364bf3 | 2020-06-03 08:34:06 | [diff] [blame] | 788 | |
Christopher Cameron | 51e1d9e | 2017-10-14 00:01:45 | [diff] [blame] | 789 | #if defined(OS_WIN) |
Maggie Chen | 05364bf3 | 2020-06-03 08:34:06 | [diff] [blame] | 790 | hdr_enabled_ = gl::DirectCompositionSurfaceWin::IsHDRSupported(); |
Christopher Cameron | 51e1d9e | 2017-10-14 00:01:45 | [diff] [blame] | 791 | #endif |
| 792 | io_runner_->PostTask(FROM_HERE, |
Maggie Chen | 05364bf3 | 2020-06-03 08:34:06 | [diff] [blame] | 793 | base::BindOnce(std::move(callback), hdr_enabled_)); |
Christopher Cameron | 51e1d9e | 2017-10-14 00:01:45 | [diff] [blame] | 794 | } |
| 795 | |
kylechar | f9148cfb | 2019-07-22 23:12:07 | [diff] [blame] | 796 | void GpuServiceImpl::RegisterDisplayContext( |
| 797 | gpu::DisplayContext* display_context) { |
| 798 | DCHECK(main_runner_->BelongsToCurrentThread()); |
| 799 | display_contexts_.AddObserver(display_context); |
| 800 | } |
| 801 | |
| 802 | void GpuServiceImpl::UnregisterDisplayContext( |
| 803 | gpu::DisplayContext* display_context) { |
| 804 | DCHECK(main_runner_->BelongsToCurrentThread()); |
| 805 | display_contexts_.RemoveObserver(display_context); |
| 806 | } |
| 807 | |
| 808 | void GpuServiceImpl::LoseAllContexts() { |
| 809 | DCHECK(main_runner_->BelongsToCurrentThread()); |
| 810 | |
| 811 | if (IsExiting()) |
| 812 | return; |
| 813 | |
| 814 | for (auto& display_context : display_contexts_) |
| 815 | display_context.MarkContextLost(); |
| 816 | gpu_channel_manager_->LoseAllContexts(); |
| 817 | } |
| 818 | |
Bo Liu | d419419 | 2017-11-28 22:30:14 | [diff] [blame] | 819 | void GpuServiceImpl::DidCreateContextSuccessfully() { |
| 820 | DCHECK(main_runner_->BelongsToCurrentThread()); |
Shimi Zhang | 88ae922 | 2019-07-19 16:54:16 | [diff] [blame] | 821 | gpu_host_->DidCreateContextSuccessfully(); |
Bo Liu | d419419 | 2017-11-28 22:30:14 | [diff] [blame] | 822 | } |
| 823 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 824 | void GpuServiceImpl::DidCreateOffscreenContext(const GURL& active_url) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 825 | DCHECK(main_runner_->BelongsToCurrentThread()); |
Shimi Zhang | 88ae922 | 2019-07-19 16:54:16 | [diff] [blame] | 826 | gpu_host_->DidCreateOffscreenContext(active_url); |
fsamuel | b25f854 | 2016-04-22 19:14:07 | [diff] [blame] | 827 | } |
| 828 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 829 | void GpuServiceImpl::DidDestroyChannel(int client_id) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 830 | DCHECK(main_runner_->BelongsToCurrentThread()); |
xhwang | b2402d9 | 2016-10-15 07:29:37 | [diff] [blame] | 831 | media_gpu_channel_manager_->RemoveChannel(client_id); |
Shimi Zhang | 88ae922 | 2019-07-19 16:54:16 | [diff] [blame] | 832 | gpu_host_->DidDestroyChannel(client_id); |
fsamuel | b25f854 | 2016-04-22 19:14:07 | [diff] [blame] | 833 | } |
| 834 | |
Bo Liu | 95570f3 | 2020-03-16 23:42:17 | [diff] [blame] | 835 | void GpuServiceImpl::DidDestroyAllChannels() { |
| 836 | DCHECK(main_runner_->BelongsToCurrentThread()); |
| 837 | gpu_host_->DidDestroyAllChannels(); |
| 838 | } |
| 839 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 840 | void GpuServiceImpl::DidDestroyOffscreenContext(const GURL& active_url) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 841 | DCHECK(main_runner_->BelongsToCurrentThread()); |
Shimi Zhang | 88ae922 | 2019-07-19 16:54:16 | [diff] [blame] | 842 | gpu_host_->DidDestroyOffscreenContext(active_url); |
fsamuel | b25f854 | 2016-04-22 19:14:07 | [diff] [blame] | 843 | } |
| 844 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 845 | void GpuServiceImpl::DidLoseContext(bool offscreen, |
| 846 | gpu::error::ContextLostReason reason, |
| 847 | const GURL& active_url) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 848 | DCHECK(main_runner_->BelongsToCurrentThread()); |
Shimi Zhang | 88ae922 | 2019-07-19 16:54:16 | [diff] [blame] | 849 | gpu_host_->DidLoseContext(offscreen, reason, active_url); |
fsamuel | b25f854 | 2016-04-22 19:14:07 | [diff] [blame] | 850 | } |
| 851 | |
Maggie Chen | 8f17717 | 2020-02-11 00:02:28 | [diff] [blame] | 852 | #if defined(OS_WIN) |
| 853 | void GpuServiceImpl::DidUpdateOverlayInfo( |
| 854 | const gpu::OverlayInfo& overlay_info) { |
| 855 | gpu_host_->DidUpdateOverlayInfo(gpu_info_.overlay_info); |
| 856 | } |
Maggie Chen | 05364bf3 | 2020-06-03 08:34:06 | [diff] [blame] | 857 | |
| 858 | void GpuServiceImpl::DidUpdateHDRStatus(bool hdr_enabled) { |
| 859 | gpu_host_->DidUpdateHDRStatus(hdr_enabled); |
| 860 | } |
Maggie Chen | 8f17717 | 2020-02-11 00:02:28 | [diff] [blame] | 861 | #endif |
| 862 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 863 | void GpuServiceImpl::StoreShaderToDisk(int client_id, |
| 864 | const std::string& key, |
| 865 | const std::string& shader) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 866 | DCHECK(main_runner_->BelongsToCurrentThread()); |
Shimi Zhang | 88ae922 | 2019-07-19 16:54:16 | [diff] [blame] | 867 | gpu_host_->StoreShaderToDisk(client_id, key, shader); |
fsamuel | b25f854 | 2016-04-22 19:14:07 | [diff] [blame] | 868 | } |
| 869 | |
kylechar | 6c0ba1e | 2019-02-01 23:20:24 | [diff] [blame] | 870 | void GpuServiceImpl::MaybeExitOnContextLost() { |
| 871 | MaybeExit(true); |
| 872 | } |
| 873 | |
| 874 | bool GpuServiceImpl::IsExiting() const { |
| 875 | return is_exiting_.IsSet(); |
kylechar | 56ddcdc2 | 2018-05-28 16:45:38 | [diff] [blame] | 876 | } |
| 877 | |
fsamuel | b25f854 | 2016-04-22 19:14:07 | [diff] [blame] | 878 | #if defined(OS_WIN) |
kylechar | cd157cc | 2018-05-30 17:30:02 | [diff] [blame] | 879 | void GpuServiceImpl::SendCreatedChildWindow(gpu::SurfaceHandle parent_window, |
| 880 | gpu::SurfaceHandle child_window) { |
| 881 | // This can be called from main or display compositor thread. |
Shimi Zhang | 88ae922 | 2019-07-19 16:54:16 | [diff] [blame] | 882 | gpu_host_->SetChildSurface(parent_window, child_window); |
fsamuel | b25f854 | 2016-04-22 19:14:07 | [diff] [blame] | 883 | } |
| 884 | #endif |
| 885 | |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 886 | void GpuServiceImpl::EstablishGpuChannel(int32_t client_id, |
| 887 | uint64_t client_tracing_id, |
| 888 | bool is_gpu_host, |
Khushal | c2667e3 | 2018-07-20 01:07:18 | [diff] [blame] | 889 | bool cache_shaders_on_disk, |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 890 | EstablishGpuChannelCallback callback) { |
kylechar | fa018c9 | 2019-10-18 16:09:44 | [diff] [blame] | 891 | // This should always be called on the IO thread first. |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 892 | if (io_runner_->BelongsToCurrentThread()) { |
kylechar | fa018c9 | 2019-10-18 16:09:44 | [diff] [blame] | 893 | if (IsExiting()) { |
| 894 | // We are already exiting so there is no point in responding. Close the |
| 895 | // receiver so we can safely drop the callback. |
kylechar | 14fe0ac | 2019-10-18 18:38:35 | [diff] [blame] | 896 | receiver_.reset(); |
kylechar | fa018c9 | 2019-10-18 16:09:44 | [diff] [blame] | 897 | return; |
| 898 | } |
| 899 | |
| 900 | if (gpu::IsReservedClientId(client_id)) { |
| 901 | // This returns a null handle, which is treated by the client as a failure |
| 902 | // case. |
| 903 | std::move(callback).Run(mojo::ScopedMessagePipeHandle()); |
| 904 | return; |
| 905 | } |
| 906 | |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 907 | EstablishGpuChannelCallback wrap_callback = base::BindOnce( |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 908 | [](scoped_refptr<base::SingleThreadTaskRunner> runner, |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 909 | EstablishGpuChannelCallback cb, |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 910 | mojo::ScopedMessagePipeHandle handle) { |
sadrul | 0835f28 | 2017-03-29 19:41:55 | [diff] [blame] | 911 | runner->PostTask(FROM_HERE, |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 912 | base::BindOnce(std::move(cb), std::move(handle))); |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 913 | }, |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 914 | io_runner_, std::move(callback)); |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 915 | main_runner_->PostTask( |
Khushal | c2667e3 | 2018-07-20 01:07:18 | [diff] [blame] | 916 | FROM_HERE, |
| 917 | base::BindOnce(&GpuServiceImpl::EstablishGpuChannel, weak_ptr_, |
| 918 | client_id, client_tracing_id, is_gpu_host, |
| 919 | cache_shaders_on_disk, std::move(wrap_callback))); |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 920 | return; |
| 921 | } |
sadrul | 08f982ad | 2016-09-14 03:04:53 | [diff] [blame] | 922 | |
sunnyps | 41a6a15a | 2017-03-31 00:38:54 | [diff] [blame] | 923 | gpu::GpuChannel* gpu_channel = gpu_channel_manager_->EstablishChannel( |
Khushal | c2667e3 | 2018-07-20 01:07:18 | [diff] [blame] | 924 | client_id, client_tracing_id, is_gpu_host, cache_shaders_on_disk); |
sunnyps | 41a6a15a | 2017-03-31 00:38:54 | [diff] [blame] | 925 | |
Vikas Soni | 76906de | 2019-03-28 03:18:10 | [diff] [blame] | 926 | if (!gpu_channel) { |
| 927 | // This returns a null handle, which is treated by the client as a failure |
| 928 | // case. |
| 929 | std::move(callback).Run(mojo::ScopedMessagePipeHandle()); |
| 930 | return; |
| 931 | } |
sunnyps | 41a6a15a | 2017-03-31 00:38:54 | [diff] [blame] | 932 | mojo::MessagePipe pipe; |
Sunny Sachanandani | b6b590a | 2018-09-28 05:20:43 | [diff] [blame] | 933 | gpu_channel->Init(pipe.handle0.release(), shutdown_event_); |
sunnyps | 41a6a15a | 2017-03-31 00:38:54 | [diff] [blame] | 934 | |
xhwang | b2402d9 | 2016-10-15 07:29:37 | [diff] [blame] | 935 | media_gpu_channel_manager_->AddChannel(client_id); |
sunnyps | 41a6a15a | 2017-03-31 00:38:54 | [diff] [blame] | 936 | |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 937 | std::move(callback).Run(std::move(pipe.handle1)); |
sadrul | ad8b21be | 2016-08-26 00:45:09 | [diff] [blame] | 938 | } |
| 939 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 940 | void GpuServiceImpl::CloseChannel(int32_t client_id) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 941 | if (io_runner_->BelongsToCurrentThread()) { |
tzik | 2bcf8e4 | 2018-07-31 11:22:15 | [diff] [blame] | 942 | main_runner_->PostTask( |
| 943 | FROM_HERE, |
| 944 | base::BindOnce(&GpuServiceImpl::CloseChannel, weak_ptr_, client_id)); |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 945 | return; |
| 946 | } |
sadrul | 9cef0df | 2017-03-03 18:18:07 | [diff] [blame] | 947 | gpu_channel_manager_->RemoveChannel(client_id); |
| 948 | } |
| 949 | |
Khushal | c2667e3 | 2018-07-20 01:07:18 | [diff] [blame] | 950 | void GpuServiceImpl::LoadedShader(int32_t client_id, |
| 951 | const std::string& key, |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 952 | const std::string& data) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 953 | if (io_runner_->BelongsToCurrentThread()) { |
tzik | 2bcf8e4 | 2018-07-31 11:22:15 | [diff] [blame] | 954 | main_runner_->PostTask( |
| 955 | FROM_HERE, base::BindOnce(&GpuServiceImpl::LoadedShader, weak_ptr_, |
| 956 | client_id, key, data)); |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 957 | return; |
| 958 | } |
Khushal | c2667e3 | 2018-07-20 01:07:18 | [diff] [blame] | 959 | gpu_channel_manager_->PopulateShaderCache(client_id, key, data); |
sadrul | 9cef0df | 2017-03-03 18:18:07 | [diff] [blame] | 960 | } |
| 961 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 962 | void GpuServiceImpl::WakeUpGpu() { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 963 | if (io_runner_->BelongsToCurrentThread()) { |
tzik | 2bcf8e4 | 2018-07-31 11:22:15 | [diff] [blame] | 964 | main_runner_->PostTask( |
| 965 | FROM_HERE, base::BindOnce(&GpuServiceImpl::WakeUpGpu, weak_ptr_)); |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 966 | return; |
| 967 | } |
sadrul | 9cef0df | 2017-03-03 18:18:07 | [diff] [blame] | 968 | #if defined(OS_ANDROID) |
sadrul | 9cef0df | 2017-03-03 18:18:07 | [diff] [blame] | 969 | gpu_channel_manager_->WakeUpGpu(); |
| 970 | #else |
| 971 | NOTREACHED() << "WakeUpGpu() not supported on this platform."; |
| 972 | #endif |
| 973 | } |
| 974 | |
Kenneth Russell | 35d7e73 | 2019-11-08 00:47:04 | [diff] [blame] | 975 | void GpuServiceImpl::GpuSwitched(gl::GpuPreference active_gpu_heuristic) { |
sadrul | d93a2b10 | 2017-03-29 04:11:52 | [diff] [blame] | 976 | DVLOG(1) << "GPU: GPU has switched"; |
Jonah Ryan-Davis | a54a300 | 2020-12-08 17:34:50 | [diff] [blame] | 977 | if (!in_host_process()) { |
Kenneth Russell | 35d7e73 | 2019-11-08 00:47:04 | [diff] [blame] | 978 | ui::GpuSwitchingManager::GetInstance()->NotifyGpuSwitched( |
| 979 | active_gpu_heuristic); |
Jonah Ryan-Davis | a54a300 | 2020-12-08 17:34:50 | [diff] [blame] | 980 | } |
| 981 | if (io_runner_->BelongsToCurrentThread()) { |
| 982 | main_runner_->PostTask( |
| 983 | FROM_HERE, base::BindOnce(&GpuServiceImpl::UpdateGPUInfoGL, weak_ptr_)); |
| 984 | return; |
| 985 | } |
| 986 | GpuServiceImpl::UpdateGPUInfoGL(); |
sadrul | d93a2b10 | 2017-03-29 04:11:52 | [diff] [blame] | 987 | } |
| 988 | |
Maggie Chen | bde7f92 | 2020-01-24 17:57:01 | [diff] [blame] | 989 | void GpuServiceImpl::DisplayAdded() { |
Maggie Chen | 87d01b4 | 2020-03-13 19:34:13 | [diff] [blame] | 990 | if (io_runner_->BelongsToCurrentThread()) { |
| 991 | main_runner_->PostTask( |
| 992 | FROM_HERE, base::BindOnce(&GpuServiceImpl::DisplayAdded, weak_ptr_)); |
| 993 | return; |
| 994 | } |
Maggie Chen | bde7f92 | 2020-01-24 17:57:01 | [diff] [blame] | 995 | DVLOG(1) << "GPU: A monitor is plugged in"; |
| 996 | |
| 997 | if (!in_host_process()) |
| 998 | ui::GpuSwitchingManager::GetInstance()->NotifyDisplayAdded(); |
| 999 | } |
| 1000 | |
| 1001 | void GpuServiceImpl::DisplayRemoved() { |
Maggie Chen | 87d01b4 | 2020-03-13 19:34:13 | [diff] [blame] | 1002 | if (io_runner_->BelongsToCurrentThread()) { |
| 1003 | main_runner_->PostTask( |
| 1004 | FROM_HERE, base::BindOnce(&GpuServiceImpl::DisplayRemoved, weak_ptr_)); |
| 1005 | return; |
| 1006 | } |
Maggie Chen | bde7f92 | 2020-01-24 17:57:01 | [diff] [blame] | 1007 | DVLOG(1) << "GPU: A monitor is unplugged "; |
| 1008 | |
| 1009 | if (!in_host_process()) |
| 1010 | ui::GpuSwitchingManager::GetInstance()->NotifyDisplayRemoved(); |
| 1011 | } |
| 1012 | |
Maggie Chen | 954dc16 | 2020-11-11 22:34:36 | [diff] [blame] | 1013 | void GpuServiceImpl::DisplayMetricsChanged() { |
| 1014 | if (io_runner_->BelongsToCurrentThread()) { |
| 1015 | main_runner_->PostTask( |
| 1016 | FROM_HERE, |
| 1017 | base::BindOnce(&GpuServiceImpl::DisplayMetricsChanged, weak_ptr_)); |
| 1018 | return; |
| 1019 | } |
| 1020 | DVLOG(1) << "GPU: Display Metrics changed"; |
| 1021 | |
| 1022 | if (!in_host_process()) |
| 1023 | ui::GpuSwitchingManager::GetInstance()->NotifyDisplayMetricsChanged(); |
| 1024 | } |
| 1025 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 1026 | void GpuServiceImpl::DestroyAllChannels() { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 1027 | if (io_runner_->BelongsToCurrentThread()) { |
| 1028 | main_runner_->PostTask( |
tzik | 2bcf8e4 | 2018-07-31 11:22:15 | [diff] [blame] | 1029 | FROM_HERE, |
| 1030 | base::BindOnce(&GpuServiceImpl::DestroyAllChannels, weak_ptr_)); |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 1031 | return; |
| 1032 | } |
sadrul | b428f6b | 2017-03-03 19:28:32 | [diff] [blame] | 1033 | DVLOG(1) << "GPU: Removing all contexts"; |
| 1034 | gpu_channel_manager_->DestroyAllChannels(); |
| 1035 | } |
| 1036 | |
Eric Karl | 033cd99 | 2018-05-16 15:32:33 | [diff] [blame] | 1037 | void GpuServiceImpl::OnBackgroundCleanup() { |
Eric Karl | 73cfd3f | 2018-03-26 22:49:45 | [diff] [blame] | 1038 | // Currently only called on Android. |
| 1039 | #if defined(OS_ANDROID) |
| 1040 | if (io_runner_->BelongsToCurrentThread()) { |
| 1041 | main_runner_->PostTask( |
Eric Karl | 033cd99 | 2018-05-16 15:32:33 | [diff] [blame] | 1042 | FROM_HERE, |
| 1043 | base::BindOnce(&GpuServiceImpl::OnBackgroundCleanup, weak_ptr_)); |
Eric Karl | 73cfd3f | 2018-03-26 22:49:45 | [diff] [blame] | 1044 | return; |
| 1045 | } |
| 1046 | DVLOG(1) << "GPU: Performing background cleanup"; |
Khushal | cbaac9b | 2018-07-10 06:00:45 | [diff] [blame] | 1047 | gpu_channel_manager_->OnBackgroundCleanup(); |
Kramer Ge | 65a4de9 | 2020-02-24 20:46:49 | [diff] [blame] | 1048 | #else |
Kramer Ge | a799e28 | 2020-02-19 21:58:53 | [diff] [blame] | 1049 | NOTREACHED(); |
Kramer Ge | 65a4de9 | 2020-02-24 20:46:49 | [diff] [blame] | 1050 | #endif |
Eric Karl | 73cfd3f | 2018-03-26 22:49:45 | [diff] [blame] | 1051 | } |
| 1052 | |
Eric Karl | 033cd99 | 2018-05-16 15:32:33 | [diff] [blame] | 1053 | void GpuServiceImpl::OnBackgrounded() { |
Eric Karl | 614b5b8 | 2018-11-10 00:58:34 | [diff] [blame] | 1054 | DCHECK(io_runner_->BelongsToCurrentThread()); |
Eric Karl | 033cd99 | 2018-05-16 15:32:33 | [diff] [blame] | 1055 | if (watchdog_thread_) |
| 1056 | watchdog_thread_->OnBackgrounded(); |
Khushal | cbaac9b | 2018-07-10 06:00:45 | [diff] [blame] | 1057 | |
Eric Karl | 614b5b8 | 2018-11-10 00:58:34 | [diff] [blame] | 1058 | main_runner_->PostTask( |
| 1059 | FROM_HERE, |
| 1060 | base::BindOnce(&GpuServiceImpl::OnBackgroundedOnMainThread, weak_ptr_)); |
| 1061 | } |
| 1062 | |
| 1063 | void GpuServiceImpl::OnBackgroundedOnMainThread() { |
Khushal | cbaac9b | 2018-07-10 06:00:45 | [diff] [blame] | 1064 | gpu_channel_manager_->OnApplicationBackgrounded(); |
Eric Karl | 033cd99 | 2018-05-16 15:32:33 | [diff] [blame] | 1065 | } |
| 1066 | |
| 1067 | void GpuServiceImpl::OnForegrounded() { |
| 1068 | if (watchdog_thread_) |
| 1069 | watchdog_thread_->OnForegrounded(); |
| 1070 | } |
| 1071 | |
Sebastien Marchand | 9ea1262c | 2019-12-09 23:37:43 | [diff] [blame] | 1072 | #if !defined(OS_ANDROID) |
| 1073 | void GpuServiceImpl::OnMemoryPressure( |
| 1074 | ::base::MemoryPressureListener::MemoryPressureLevel level) { |
| 1075 | // Forward the notification to the registry of MemoryPressureListeners. |
| 1076 | base::MemoryPressureListener::NotifyMemoryPressure(level); |
| 1077 | } |
| 1078 | #endif |
| 1079 | |
Avi Drissman | 8fd9217 | 2020-07-28 15:49:45 | [diff] [blame] | 1080 | #if defined(OS_APPLE) |
Sidney San MartÃn | 9387b40 | 2018-06-08 18:13:26 | [diff] [blame] | 1081 | void GpuServiceImpl::BeginCATransaction() { |
| 1082 | DCHECK(io_runner_->BelongsToCurrentThread()); |
| 1083 | main_runner_->PostTask(FROM_HERE, base::BindOnce(&ui::BeginCATransaction)); |
| 1084 | } |
| 1085 | |
| 1086 | void GpuServiceImpl::CommitCATransaction(CommitCATransactionCallback callback) { |
| 1087 | DCHECK(io_runner_->BelongsToCurrentThread()); |
| 1088 | main_runner_->PostTaskAndReply(FROM_HERE, |
| 1089 | base::BindOnce(&ui::CommitCATransaction), |
| 1090 | WrapCallback(io_runner_, std::move(callback))); |
| 1091 | } |
| 1092 | #endif |
| 1093 | |
Sebastien Marchand | 836d04b3 | 2020-04-28 18:10:03 | [diff] [blame] | 1094 | #if BUILDFLAG(CLANG_PROFILING_INSIDE_SANDBOX) |
| 1095 | void GpuServiceImpl::WriteClangProfilingProfile( |
| 1096 | WriteClangProfilingProfileCallback callback) { |
| 1097 | base::WriteClangProfilingProfile(); |
| 1098 | std::move(callback).Run(); |
| 1099 | } |
| 1100 | #endif |
| 1101 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 1102 | void GpuServiceImpl::Crash() { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 1103 | DCHECK(io_runner_->BelongsToCurrentThread()); |
Kenneth Russell | 3689f3e | 2018-08-07 00:45:40 | [diff] [blame] | 1104 | gl::Crash(); |
sadrul | b428f6b | 2017-03-03 19:28:32 | [diff] [blame] | 1105 | } |
| 1106 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 1107 | void GpuServiceImpl::Hang() { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 1108 | DCHECK(io_runner_->BelongsToCurrentThread()); |
Zhenyao Mo | 75bd50d | 2019-09-09 22:31:18 | [diff] [blame] | 1109 | main_runner_->PostTask(FROM_HERE, base::BindOnce(&gl::Hang)); |
sadrul | b428f6b | 2017-03-03 19:28:32 | [diff] [blame] | 1110 | } |
| 1111 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 1112 | void GpuServiceImpl::ThrowJavaException() { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 1113 | DCHECK(io_runner_->BelongsToCurrentThread()); |
sadrul | b428f6b | 2017-03-03 19:28:32 | [diff] [blame] | 1114 | #if defined(OS_ANDROID) |
Andrew Grieve | 2640788 | 2018-08-28 15:15:33 | [diff] [blame] | 1115 | ThrowUncaughtException(); |
sadrul | b428f6b | 2017-03-03 19:28:32 | [diff] [blame] | 1116 | #else |
| 1117 | NOTREACHED() << "Java exception not supported on this platform."; |
| 1118 | #endif |
| 1119 | } |
| 1120 | |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 1121 | void GpuServiceImpl::Stop(StopCallback callback) { |
sadrul | 0526dc5e | 2017-03-28 20:04:29 | [diff] [blame] | 1122 | DCHECK(io_runner_->BelongsToCurrentThread()); |
Gabriel Charette | 53a9ef81 | 2017-07-26 12:36:23 | [diff] [blame] | 1123 | main_runner_->PostTaskAndReply( |
kylechar | 6c0ba1e | 2019-02-01 23:20:24 | [diff] [blame] | 1124 | FROM_HERE, base::BindOnce(&GpuServiceImpl::MaybeExit, weak_ptr_, false), |
tzik | 7ea663633 | 2017-08-17 10:19:57 | [diff] [blame] | 1125 | std::move(callback)); |
sadrul | e6f6e10 | 2017-03-11 01:09:56 | [diff] [blame] | 1126 | } |
| 1127 | |
jonross | d2ca5e64 | 2019-10-16 12:08:52 | [diff] [blame] | 1128 | void GpuServiceImpl::StartPeakMemoryMonitorOnMainThread(uint32_t sequence_num) { |
| 1129 | gpu_channel_manager_->StartPeakMemoryMonitor(sequence_num); |
| 1130 | } |
| 1131 | |
| 1132 | void GpuServiceImpl::GetPeakMemoryUsageOnMainThread( |
| 1133 | uint32_t sequence_num, |
| 1134 | GetPeakMemoryUsageCallback callback) { |
jonross | 1f2903d | 2020-03-06 13:59:40 | [diff] [blame] | 1135 | uint64_t peak_memory = 0u; |
| 1136 | auto allocation_per_source = |
| 1137 | gpu_channel_manager_->GetPeakMemoryUsage(sequence_num, &peak_memory); |
jonross | d2ca5e64 | 2019-10-16 12:08:52 | [diff] [blame] | 1138 | io_runner_->PostTask(FROM_HERE, |
jonross | 1f2903d | 2020-03-06 13:59:40 | [diff] [blame] | 1139 | base::BindOnce(std::move(callback), peak_memory, |
| 1140 | std::move(allocation_per_source))); |
jonross | d2ca5e64 | 2019-10-16 12:08:52 | [diff] [blame] | 1141 | } |
| 1142 | |
kylechar | 6c0ba1e | 2019-02-01 23:20:24 | [diff] [blame] | 1143 | void GpuServiceImpl::MaybeExit(bool for_context_loss) { |
| 1144 | DCHECK(main_runner_->BelongsToCurrentThread()); |
| 1145 | |
| 1146 | // We can't restart the GPU process when running in the host process. |
| 1147 | if (in_host_process()) |
| 1148 | return; |
| 1149 | |
kylechar | 32f8fbf | 2019-06-12 16:46:24 | [diff] [blame] | 1150 | if (IsExiting() || !exit_callback_) |
| 1151 | return; |
| 1152 | |
| 1153 | if (for_context_loss) { |
| 1154 | LOG(ERROR) << "Exiting GPU process because some drivers can't recover " |
| 1155 | "from errors. GPU process will restart shortly."; |
kylechar | 6c0ba1e | 2019-02-01 23:20:24 | [diff] [blame] | 1156 | } |
kylechar | 32f8fbf | 2019-06-12 16:46:24 | [diff] [blame] | 1157 | is_exiting_.Set(); |
Maggie Chen | ba08c24 | 2020-02-05 21:35:40 | [diff] [blame] | 1158 | // For the unsandboxed GPU info collection process used for info collection, |
| 1159 | // if we exit immediately, then the reply message could be lost. That's why |
| 1160 | // the |exit_callback_| takes the boolean argument. |
Patrick To | df5911c | 2020-05-12 19:31:42 | [diff] [blame] | 1161 | if (for_context_loss) |
| 1162 | std::move(exit_callback_) |
| 1163 | .Run(ExitCode::RESULT_CODE_GPU_EXIT_ON_CONTEXT_LOST); |
| 1164 | else |
| 1165 | std::move(exit_callback_).Run(base::nullopt); |
kylechar | 6c0ba1e | 2019-02-01 23:20:24 | [diff] [blame] | 1166 | } |
| 1167 | |
Vasiliy Telezhnikov | 1744bd0 | 2019-10-31 19:32:22 | [diff] [blame] | 1168 | gpu::Scheduler* GpuServiceImpl::GetGpuScheduler() { |
| 1169 | return scheduler_.get(); |
| 1170 | } |
| 1171 | |
Maggie Chen | 8f17717 | 2020-02-11 00:02:28 | [diff] [blame] | 1172 | #if defined(OS_WIN) |
Maggie Chen | 05364bf3 | 2020-06-03 08:34:06 | [diff] [blame] | 1173 | void GpuServiceImpl::UpdateOverlayAndHDRInfo() { |
Maggie Chen | 8f17717 | 2020-02-11 00:02:28 | [diff] [blame] | 1174 | gpu::OverlayInfo old_overlay_info = gpu_info_.overlay_info; |
| 1175 | gpu::CollectHardwareOverlayInfo(&gpu_info_.overlay_info); |
| 1176 | |
Maggie Chen | 05364bf3 | 2020-06-03 08:34:06 | [diff] [blame] | 1177 | // Update overlay info in the GPU process and send the updated data back to |
| 1178 | // the GPU host in the Browser process through mojom if the info has changed. |
Maggie Chen | 8f17717 | 2020-02-11 00:02:28 | [diff] [blame] | 1179 | if (old_overlay_info != gpu_info_.overlay_info) |
| 1180 | DidUpdateOverlayInfo(gpu_info_.overlay_info); |
Maggie Chen | 05364bf3 | 2020-06-03 08:34:06 | [diff] [blame] | 1181 | |
| 1182 | // Update HDR status in the GPU process through the GPU host mojom. |
| 1183 | bool old_hdr_enabled_status = hdr_enabled_; |
| 1184 | hdr_enabled_ = gl::DirectCompositionSurfaceWin::IsHDRSupported(); |
| 1185 | if (old_hdr_enabled_status != hdr_enabled_) |
| 1186 | DidUpdateHDRStatus(hdr_enabled_); |
Maggie Chen | 8f17717 | 2020-02-11 00:02:28 | [diff] [blame] | 1187 | } |
| 1188 | #endif |
| 1189 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 1190 | } // namespace viz |