Avi Drissman | 4e1b7bc3 | 2022-09-15 14:03:50 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d9f3793 | 2011-05-09 20:09:24 | [diff] [blame] | 5 | #ifndef CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_ |
| 6 | #define CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_ |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 7 | |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 8 | #include <stdint.h> |
| 9 | |
[email protected] | f017032 | 2011-04-26 06:41:16 | [diff] [blame] | 10 | #include <map> |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 11 | #include <memory> |
[email protected] | 5494703 | 2012-12-08 01:44:01 | [diff] [blame] | 12 | #include <set> |
[email protected] | a82af39 | 2012-02-24 04:40:20 | [diff] [blame] | 13 | #include <string> |
[email protected] | f017032 | 2011-04-26 06:41:16 | [diff] [blame] | 14 | |
Zhenyao Mo | c4f79c3 | 2018-01-27 02:44:13 | [diff] [blame] | 15 | #include "base/atomicops.h" |
Avi Drissman | adac2199 | 2023-01-11 23:46:39 | [diff] [blame] | 16 | #include "base/functional/callback.h" |
Omar Elmekkawy | 859c02e | 2022-08-17 11:50:11 | [diff] [blame] | 17 | #include "base/location.h" |
Sebastien Marchand | 9ea1262c | 2019-12-09 23:37:43 | [diff] [blame] | 18 | #include "base/memory/memory_pressure_listener.h" |
[email protected] | 8c4b4db | 2013-03-19 00:51:42 | [diff] [blame] | 19 | #include "base/memory/weak_ptr.h" |
[email protected] | a43858f | 2013-06-28 15:18:37 | [diff] [blame] | 20 | #include "base/time/time.h" |
avi | b734894 | 2015-12-25 20:57:10 | [diff] [blame] | 21 | #include "build/build_config.h" |
Mohsen Izadi | 0b9fbb6 | 2018-08-30 20:30:00 | [diff] [blame] | 22 | #include "components/viz/host/gpu_host_impl.h" |
[email protected] | 8d128d6 | 2011-09-13 22:11:57 | [diff] [blame] | 23 | #include "content/common/content_export.h" |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 24 | #include "content/public/browser/browser_child_process_host_delegate.h" |
[email protected] | e113050 | 2012-11-21 20:58:27 | [diff] [blame] | 25 | #include "content/public/browser/gpu_data_manager.h" |
[email protected] | 5494703 | 2012-12-08 01:44:01 | [diff] [blame] | 26 | #include "gpu/command_buffer/common/constants.h" |
Bo Liu | 01d003e4 | 2023-08-16 19:46:50 | [diff] [blame] | 27 | #include "gpu/command_buffer/common/shm_count.h" |
ericrk | 41a1579e | 2017-02-10 20:56:28 | [diff] [blame] | 28 | #include "gpu/config/gpu_feature_info.h" |
[email protected] | d7b5cc7 | 2013-05-23 20:05:00 | [diff] [blame] | 29 | #include "gpu/config/gpu_info.h" |
kylechar | 5d7fb33e | 2018-06-14 15:32:25 | [diff] [blame] | 30 | #include "gpu/config/gpu_mode.h" |
Ken Rockot | 8322a04 | 2019-08-20 18:02:00 | [diff] [blame] | 31 | #include "mojo/public/cpp/bindings/generic_pending_receiver.h" |
Julie Jeongeun Kim | 7b4a6aa1 | 2019-09-20 14:57:12 | [diff] [blame] | 32 | #include "mojo/public/cpp/bindings/pending_receiver.h" |
Alex Gough | 4d17312 | 2021-08-24 21:18:26 | [diff] [blame] | 33 | #include "sandbox/policy/mojom/sandbox.mojom.h" |
Miyoung Shin | 2be27f5 | 2019-07-27 15:35:39 | [diff] [blame] | 34 | #include "services/viz/privileged/mojom/compositing/frame_sink_manager.mojom.h" |
| 35 | #include "services/viz/privileged/mojom/gl/gpu_host.mojom.h" |
| 36 | #include "services/viz/privileged/mojom/gl/gpu_service.mojom.h" |
| 37 | #include "services/viz/privileged/mojom/viz_main.mojom.h" |
Alexander Dunaev | e6e09c1 | 2020-10-23 16:43:42 | [diff] [blame] | 38 | #include "ui/gfx/gpu_extra_info.h" |
[email protected] | 707e1c4 | 2013-07-09 21:18:58 | [diff] [blame] | 39 | #include "url/gurl.h" |
[email protected] | f017032 | 2011-04-26 06:41:16 | [diff] [blame] | 40 | |
Xiaohan Wang | 51dde998 | 2022-01-14 18:37:49 | [diff] [blame] | 41 | #if BUILDFLAG(IS_WIN) |
Maggie Chen | a6ece77 | 2020-04-27 17:19:06 | [diff] [blame] | 42 | #include "services/viz/privileged/mojom/gl/info_collection_gpu_service.mojom.h" |
| 43 | #endif |
| 44 | |
gab | 4d92485f | 2016-09-26 21:00:45 | [diff] [blame] | 45 | namespace base { |
| 46 | class Thread; |
| 47 | } |
| 48 | |
[email protected] | 21efac3 | 2012-10-29 02:41:11 | [diff] [blame] | 49 | namespace content { |
| 50 | class BrowserChildProcessHostImpl; |
[email protected] | d7a2d89 | 2013-08-16 07:45:36 | [diff] [blame] | 51 | |
Xiaohan Wang | 51dde998 | 2022-01-14 18:37:49 | [diff] [blame] | 52 | #if BUILDFLAG(IS_MAC) |
Patrick Monette | 31020ea | 2023-03-10 01:48:31 | [diff] [blame] | 53 | class BrowserChildProcessBackgroundedBridge; |
Sidney San Martín | 9387b40 | 2018-06-08 18:13:26 | [diff] [blame] | 54 | class CATransactionGPUCoordinator; |
| 55 | #endif |
| 56 | |
Tom Sepez | f3f28e1 | 2025-07-21 22:39:13 | [diff] [blame] | 57 | class GpuProcessHost final : public BrowserChildProcessHostDelegate, |
| 58 | public viz::GpuHostImpl::Delegate { |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 59 | public: |
Zhenyao Mo | c4f79c3 | 2018-01-27 02:44:13 | [diff] [blame] | 60 | static int GetGpuCrashCount(); |
[email protected] | 6395479 | 2011-07-11 04:17:48 | [diff] [blame] | 61 | |
sadrul | 6d310fa | 2016-08-04 02:12:16 | [diff] [blame] | 62 | // Creates a new GpuProcessHost (if |force_create| is turned on) or gets an |
| 63 | // existing one, resulting in the launching of a GPU process if required. |
| 64 | // Returns null on failure. It is not safe to store the pointer once control |
| 65 | // has returned to the message loop as it can be destroyed. Instead store the |
| 66 | // associated GPU host ID. This could return NULL if GPU access is not |
Corentin Wallez | 09c5fca | 2020-07-27 22:03:58 | [diff] [blame] | 67 | // allowed (blocklisted). |
sadrul | ca65d070 | 2017-04-10 18:08:13 | [diff] [blame] | 68 | CONTENT_EXPORT static GpuProcessHost* Get( |
| 69 | GpuProcessKind kind = GPU_PROCESS_KIND_SANDBOXED, |
| 70 | bool force_create = true); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 71 | |
Peter Boström | 9b03653 | 2021-10-28 23:37:28 | [diff] [blame] | 72 | GpuProcessHost(const GpuProcessHost&) = delete; |
| 73 | GpuProcessHost& operator=(const GpuProcessHost&) = delete; |
| 74 | |
sadrul | ca65d070 | 2017-04-10 18:08:13 | [diff] [blame] | 75 | // Returns whether there is an active GPU process or not. |
Nicholas Verne | 84dc55e | 2017-11-23 01:02:38 | [diff] [blame] | 76 | static void GetHasGpuProcess(base::OnceCallback<void(bool)> callback); |
[email protected] | e113050 | 2012-11-21 20:58:27 | [diff] [blame] | 77 | |
Thiabaud Engelbrecht | e7ed165 | 2023-06-04 21:42:35 | [diff] [blame] | 78 | // Helper function to run a callback on the UI thread. The callback receives |
sadrul | e6f6e10 | 2017-03-11 01:09:56 | [diff] [blame] | 79 | // the appropriate GpuProcessHost instance. Note that the callback can be |
| 80 | // called with a null host (e.g. when |force_create| is false, and no |
| 81 | // GpuProcessHost instance exists). |
Thiabaud Engelbrecht | e7ed165 | 2023-06-04 21:42:35 | [diff] [blame] | 82 | CONTENT_EXPORT static void CallOnUI( |
Omar Elmekkawy | 859c02e | 2022-08-17 11:50:11 | [diff] [blame] | 83 | const base::Location& location, |
sadrul | b428f6b | 2017-03-03 19:28:32 | [diff] [blame] | 84 | GpuProcessKind kind, |
| 85 | bool force_create, |
kylechar | ed18a48 | 2019-02-07 14:07:21 | [diff] [blame] | 86 | base::OnceCallback<void(GpuProcessHost*)> callback); |
sadrul | 3ab0a533 | 2017-03-01 03:16:45 | [diff] [blame] | 87 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 88 | // Get the GPU process host for the GPU process with the given ID. Returns |
| 89 | // null if the process no longer exists. |
| 90 | static GpuProcessHost* FromID(int host_id); |
[email protected] | f017032 | 2011-04-26 06:41:16 | [diff] [blame] | 91 | int host_id() const { return host_id_; } |
Mohsen Izadi | 0b9fbb6 | 2018-08-30 20:30:00 | [diff] [blame] | 92 | base::ProcessId process_id() const { return process_id_; } |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 93 | |
[email protected] | 7854d04 | 2012-03-15 19:08:18 | [diff] [blame] | 94 | // What kind of GPU process, e.g. sandboxed or unsandboxed. |
| 95 | GpuProcessKind kind(); |
[email protected] | 6f1485ee | 2012-01-28 00:29:19 | [diff] [blame] | 96 | |
derekjchow | 1b0f3bb | 2015-07-30 18:51:10 | [diff] [blame] | 97 | // Forcefully terminates the GPU process. |
[email protected] | 45aedeb | 2011-12-07 20:54:53 | [diff] [blame] | 98 | void ForceShutdown(); |
| 99 | |
Bo Liu | ae5b6def | 2020-06-01 19:44:51 | [diff] [blame] | 100 | // Dumps the stack of the child process without crashing it. |
| 101 | // Only implemented on Android. |
| 102 | void DumpProcessStack(); |
| 103 | |
Ken Rockot | 8322a04 | 2019-08-20 18:02:00 | [diff] [blame] | 104 | // Asks the GPU process to run a service instance corresponding to the |
Alex Gough | 4d17312 | 2021-08-24 21:18:26 | [diff] [blame] | 105 | // specific interface receiver type carried by |receiver|. The interface must |
| 106 | // have the [ServiceSandbox=sandbox.mojom.Sandbox.kGpu] mojom attribute. |
| 107 | template <typename Interface> |
| 108 | void RunService(mojo::PendingReceiver<Interface> receiver) { |
| 109 | // Note: consult chrome-security before changing these asserts. |
| 110 | using ProvidedSandboxType = decltype(Interface::kServiceSandbox); |
| 111 | static_assert( |
| 112 | std::is_same<ProvidedSandboxType, const sandbox::mojom::Sandbox>::value, |
| 113 | "This interface does not declare a proper ServiceSandbox attribute. " |
| 114 | "See //docs/mojo_and_services.md (Specifying a sandbox)."); |
| 115 | static_assert(Interface::kServiceSandbox == sandbox::mojom::Sandbox::kGpu, |
| 116 | "This interface must have [ServiceSandbox=kGpu]."); |
| 117 | return RunServiceImpl(std::move(receiver)); |
| 118 | } |
Ken Rockot | 8322a04 | 2019-08-20 18:02:00 | [diff] [blame] | 119 | |
Sadrul Habib Chowdhury | ef1abe78 | 2017-08-01 17:20:38 | [diff] [blame] | 120 | CONTENT_EXPORT viz::mojom::GpuService* gpu_service(); |
sadrul | 3ab0a533 | 2017-03-01 03:16:45 | [diff] [blame] | 121 | |
Xiaohan Wang | 51dde998 | 2022-01-14 18:37:49 | [diff] [blame] | 122 | #if BUILDFLAG(IS_WIN) |
Maggie Chen | a6ece77 | 2020-04-27 17:19:06 | [diff] [blame] | 123 | CONTENT_EXPORT viz::mojom::InfoCollectionGpuService* |
| 124 | info_collection_gpu_service(); |
| 125 | #endif |
| 126 | |
Khushal | 9b937d8 | 2018-06-04 22:18:03 | [diff] [blame] | 127 | CONTENT_EXPORT int GetIDForTesting() const; |
| 128 | |
Mohsen Izadi | 0b9fbb6 | 2018-08-30 20:30:00 | [diff] [blame] | 129 | viz::GpuHostImpl* gpu_host() { return gpu_host_.get(); } |
| 130 | |
Patrick Monette | 31020ea | 2023-03-10 01:48:31 | [diff] [blame] | 131 | #if BUILDFLAG(IS_MAC) |
| 132 | BrowserChildProcessBackgroundedBridge* |
| 133 | browser_child_process_backgrounded_bridge_for_testing() { |
| 134 | return browser_child_process_backgrounded_bridge_.get(); |
| 135 | } |
| 136 | #endif |
| 137 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 138 | private: |
Maksim Sisov | cbdc9b3 | 2018-08-16 07:17:07 | [diff] [blame] | 139 | enum class GpuTerminationOrigin { |
| 140 | kUnknownOrigin = 0, |
| 141 | kOzoneWaylandProxy = 1, |
| 142 | kMax = 2, |
| 143 | }; |
| 144 | |
[email protected] | de80ff20 | 2013-01-04 01:49:46 | [diff] [blame] | 145 | static bool ValidateHost(GpuProcessHost* host); |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 146 | |
Sean Gilhuly | 269cf4d2 | 2019-12-13 19:11:17 | [diff] [blame] | 147 | // Increments |recent_crash_count_| by one. Before incrementing, remove one |
| 148 | // old crash for each forgiveness interval that has passed since the previous |
| 149 | // crash. If |gpu_mode| doesn't match |last_crash_mode_|, first reset the |
| 150 | // crash count. |
| 151 | static void IncrementCrashCount(gpu::GpuMode gpu_mode); |
Mohsen Izadi | 35c8fbb | 2018-03-22 21:48:54 | [diff] [blame] | 152 | |
[email protected] | 7854d04 | 2012-03-15 19:08:18 | [diff] [blame] | 153 | GpuProcessHost(int host_id, GpuProcessKind kind); |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 154 | ~GpuProcessHost() override; |
[email protected] | 7a31f7c | 2011-03-21 23:22:04 | [diff] [blame] | 155 | |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 156 | bool Init(); |
| 157 | |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 158 | // BrowserChildProcessHostDelegate implementation. |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 159 | void OnProcessLaunched() override; |
wfh | 3adf87d | 2016-05-03 23:26:06 | [diff] [blame] | 160 | void OnProcessLaunchFailed(int error_code) override; |
dcheng | c2282aa | 2014-10-21 12:07:58 | [diff] [blame] | 161 | void OnProcessCrashed(int exit_code) override; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 162 | |
Mohsen Izadi | 0b9fbb6 | 2018-08-30 20:30:00 | [diff] [blame] | 163 | // viz::GpuHostImpl::Delegate: |
| 164 | gpu::GPUInfo GetGPUInfo() const override; |
| 165 | gpu::GpuFeatureInfo GetGpuFeatureInfo() const override; |
Mohsen Izadi | f9505d8 | 2018-10-06 01:34:03 | [diff] [blame] | 166 | void DidInitialize( |
Zhenyao Mo | 68ef56d | 2018-04-21 01:05:10 | [diff] [blame] | 167 | const gpu::GPUInfo& gpu_info, |
| 168 | const gpu::GpuFeatureInfo& gpu_feature_info, |
Arthur Sonzogni | c686e8f | 2024-01-11 08:36:37 | [diff] [blame] | 169 | const std::optional<gpu::GPUInfo>& gpu_info_for_hardware_gpu, |
| 170 | const std::optional<gpu::GpuFeatureInfo>& |
Jonah Ryan-Davis | a70577c | 2019-06-26 18:54:31 | [diff] [blame] | 171 | gpu_feature_info_for_hardware_gpu, |
Alexander Dunaev | e6e09c1 | 2020-10-23 16:43:42 | [diff] [blame] | 172 | const gfx::GpuExtraInfo& gpu_extra_info) override; |
sadrul | a235d7c | 2017-03-27 22:31:58 | [diff] [blame] | 173 | void DidFailInitialize() override; |
Bo Liu | d419419 | 2017-11-28 22:30:14 | [diff] [blame] | 174 | void DidCreateContextSuccessfully() override; |
Bo Liu | 95570f3 | 2020-03-16 23:42:17 | [diff] [blame] | 175 | void MaybeShutdownGpuProcess() override; |
Jonah Ryan-Davis | a54a300 | 2020-12-08 17:34:50 | [diff] [blame] | 176 | void DidUpdateGPUInfo(const gpu::GPUInfo& gpu_info) override; |
Xiaohan Wang | 51dde998 | 2022-01-14 18:37:49 | [diff] [blame] | 177 | #if BUILDFLAG(IS_WIN) |
Maggie Chen | 8f17717 | 2020-02-11 00:02:28 | [diff] [blame] | 178 | void DidUpdateOverlayInfo(const gpu::OverlayInfo& overlay_info) override; |
Christopher Cameron | b3ae6ff | 2022-05-02 18:11:00 | [diff] [blame] | 179 | void DidUpdateDXGIInfo(gfx::mojom::DXGIInfoPtr dxgi_info) override; |
Maggie Chen | 8f17717 | 2020-02-11 00:02:28 | [diff] [blame] | 180 | #endif |
Loko Kung | 76d0dab | 2022-10-08 01:58:50 | [diff] [blame] | 181 | std::string GetIsolationKey( |
| 182 | int32_t process_id, |
| 183 | const blink::WebGPUExecutionContextToken& token) override; |
Kenneth Russell | 601ac28 | 2022-08-11 01:58:14 | [diff] [blame] | 184 | void BlockDomainsFrom3DAPIs(const std::set<GURL>& urls, |
| 185 | gpu::DomainGuilt guilt) override; |
kylechar | f0a9935 | 2018-05-31 21:39:32 | [diff] [blame] | 186 | void DisableGpuCompositing() override; |
Mohsen Izadi | 0b9fbb6 | 2018-08-30 20:30:00 | [diff] [blame] | 187 | bool GpuAccessAllowed() const override; |
Loko Kung | a2461bd | 2022-08-05 09:26:08 | [diff] [blame] | 188 | gpu::GpuDiskCacheFactory* GetGpuDiskCacheFactory() override; |
sadrul | 6aafa7d | 2017-03-22 22:56:35 | [diff] [blame] | 189 | void RecordLogMessage(int32_t severity, |
| 190 | const std::string& header, |
| 191 | const std::string& message) override; |
Julie Jeongeun Kim | 7b4a6aa1 | 2019-09-20 14:57:12 | [diff] [blame] | 192 | void BindDiscardableMemoryReceiver( |
| 193 | mojo::PendingReceiver< |
| 194 | discardable_memory::mojom::DiscardableSharedMemoryManager> receiver) |
Mohsen Izadi | 0b9fbb6 | 2018-08-30 20:30:00 | [diff] [blame] | 195 | override; |
Mohsen Izadi | 63d85e7 | 2018-09-06 16:00:21 | [diff] [blame] | 196 | void BindInterface(const std::string& interface_name, |
| 197 | mojo::ScopedMessagePipeHandle interface_pipe) override; |
Henrique Ferreiro | c6c02e6 | 2019-09-17 09:39:02 | [diff] [blame] | 198 | void BindHostReceiver(mojo::GenericPendingReceiver generic_receiver) override; |
kylechar | 2d46387 | 2022-11-02 16:14:30 | [diff] [blame] | 199 | #if BUILDFLAG(IS_OZONE) |
Mohsen Izadi | 63d85e7 | 2018-09-06 16:00:21 | [diff] [blame] | 200 | void TerminateGpuProcess(const std::string& message) override; |
Mohsen Izadi | 63d85e7 | 2018-09-06 16:00:21 | [diff] [blame] | 201 | #endif |
sadrul | 550e264fd | 2017-02-14 03:44:57 | [diff] [blame] | 202 | |
perryuwang | 82496fc9 | 2017-07-15 01:59:59 | [diff] [blame] | 203 | bool LaunchGpuProcess(); |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 204 | |
Mohsen Izadi | bd50b1c | 2018-08-08 02:55:00 | [diff] [blame] | 205 | void SendOutstandingReplies(); |
[email protected] | f017032 | 2011-04-26 06:41:16 | [diff] [blame] | 206 | |
[email protected] | 5494703 | 2012-12-08 01:44:01 | [diff] [blame] | 207 | void BlockLiveOffscreenContexts(); |
| 208 | |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 209 | // Update GPU crash counters. Disable GPU if crash limit is reached. |
| 210 | void RecordProcessCrash(); |
Bo Liu | 4bc773a | 2023-04-11 19:02:47 | [diff] [blame] | 211 | int GetFallbackCrashLimit() const; |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 212 | |
Alex Gough | 4d17312 | 2021-08-24 21:18:26 | [diff] [blame] | 213 | void RunServiceImpl(mojo::GenericPendingReceiver receiver); |
| 214 | |
Xiaohan Wang | 51dde998 | 2022-01-14 18:37:49 | [diff] [blame] | 215 | #if !BUILDFLAG(IS_ANDROID) |
Sebastien Marchand | 9ea1262c | 2019-12-09 23:37:43 | [diff] [blame] | 216 | // Memory pressure handler, called by |memory_pressure_listener_|. |
| 217 | void OnMemoryPressure( |
| 218 | base::MemoryPressureListener::MemoryPressureLevel level); |
| 219 | #endif |
| 220 | |
Zhenyao Mo | 32a85bd | 2019-06-07 19:27:12 | [diff] [blame] | 221 | // The serial number of the GpuProcessHost. |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 222 | int host_id_; |
| 223 | |
Mohsen Izadi | 0b9fbb6 | 2018-08-30 20:30:00 | [diff] [blame] | 224 | // GPU process id in case GPU is not in-process. |
| 225 | base::ProcessId process_id_ = base::kNullProcessId; |
| 226 | |
[email protected] | 840a1d1a | 2012-08-04 00:26:19 | [diff] [blame] | 227 | // Whether the GPU process is valid, set to false after Send() failed. |
| 228 | bool valid_; |
| 229 | |
[email protected] | 2d9de411 | 2011-05-27 03:18:36 | [diff] [blame] | 230 | // Whether we are running a GPU thread inside the browser process instead |
| 231 | // of a separate GPU process. |
| 232 | bool in_process_; |
| 233 | |
[email protected] | 7854d04 | 2012-03-15 19:08:18 | [diff] [blame] | 234 | GpuProcessKind kind_; |
[email protected] | 947f3748 | 2011-11-11 21:04:40 | [diff] [blame] | 235 | |
kylechar | 5d7fb33e | 2018-06-14 15:32:25 | [diff] [blame] | 236 | gpu::GpuMode mode_ = gpu::GpuMode::UNKNOWN; |
| 237 | |
[email protected] | 995f7736 | 2012-02-08 00:42:42 | [diff] [blame] | 238 | // Whether we actually launched a GPU process. |
| 239 | bool process_launched_; |
| 240 | |
Maksim Sisov | cbdc9b3 | 2018-08-16 07:17:07 | [diff] [blame] | 241 | GpuTerminationOrigin termination_origin_ = |
| 242 | GpuTerminationOrigin::kUnknownOrigin; |
| 243 | |
[email protected] | fb25bee | 2012-04-11 01:49:53 | [diff] [blame] | 244 | // Time Init started. Used to log total GPU process startup time to UMA. |
| 245 | base::TimeTicks init_start_time_; |
| 246 | |
Antoine Labour | ee9dfa9 | 2018-11-13 19:32:09 | [diff] [blame] | 247 | // The GPU process reported failure to initialize. |
| 248 | bool did_fail_initialize_ = false; |
| 249 | |
kylechar | 2dd7c41 | 2018-06-05 01:59:07 | [diff] [blame] | 250 | // The total number of GPU process crashes. |
Zhenyao Mo | c4f79c3 | 2018-01-27 02:44:13 | [diff] [blame] | 251 | static base::subtle::Atomic32 gpu_crash_count_; |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 252 | static bool crashed_before_; |
Sean Gilhuly | 269cf4d2 | 2019-12-13 19:11:17 | [diff] [blame] | 253 | static int recent_crash_count_; |
| 254 | static gpu::GpuMode last_crash_mode_; |
[email protected] | 4775298 | 2014-07-29 08:01:43 | [diff] [blame] | 255 | |
Hugo Holgersson | f5f8cf9 | 2018-01-26 12:27:08 | [diff] [blame] | 256 | // Here the bottom-up destruction order matters: |
| 257 | // The GPU thread depends on its host so stop the host last. |
| 258 | // Otherwise, under rare timings when the thread is still in Init(), |
| 259 | // it could crash as it fails to find a message pipe to the host. |
dcheng | 5971627 | 2016-04-09 05:19:08 | [diff] [blame] | 260 | std::unique_ptr<BrowserChildProcessHostImpl> process_; |
Hugo Holgersson | f5f8cf9 | 2018-01-26 12:27:08 | [diff] [blame] | 261 | std::unique_ptr<base::Thread> in_process_gpu_thread_; |
[email protected] | 4967f79 | 2012-01-20 22:14:40 | [diff] [blame] | 262 | |
Xiaohan Wang | 51dde998 | 2022-01-14 18:37:49 | [diff] [blame] | 263 | #if BUILDFLAG(IS_MAC) |
Sidney San Martín | 9387b40 | 2018-06-08 18:13:26 | [diff] [blame] | 264 | scoped_refptr<CATransactionGPUCoordinator> ca_transaction_gpu_coordinator_; |
Patrick Monette | 31020ea | 2023-03-10 01:48:31 | [diff] [blame] | 265 | |
| 266 | // Ensures the backgrounded state of the GPU process mirrors the backgrounded |
| 267 | // state of the browser process. |
| 268 | std::unique_ptr<BrowserChildProcessBackgroundedBridge> |
| 269 | browser_child_process_backgrounded_bridge_; |
Sidney San Martín | 9387b40 | 2018-06-08 18:13:26 | [diff] [blame] | 270 | #endif |
| 271 | |
[email protected] | 5494703 | 2012-12-08 01:44:01 | [diff] [blame] | 272 | // Track the URLs of the pages which have live offscreen contexts, |
| 273 | // assumed to be associated with untrusted content such as WebGL. |
| 274 | // For best robustness, when any context lost notification is |
| 275 | // received, assume all of these URLs are guilty, and block |
| 276 | // automatic execution of 3D content from those domains. |
| 277 | std::multiset<GURL> urls_with_live_offscreen_contexts_; |
| 278 | |
Xiaohan Wang | 51dde998 | 2022-01-14 18:37:49 | [diff] [blame] | 279 | #if !BUILDFLAG(IS_ANDROID) |
Sebastien Marchand | 9ea1262c | 2019-12-09 23:37:43 | [diff] [blame] | 280 | // Responsible for forwarding the memory pressure notifications from the |
| 281 | // browser process to the GPU process. |
| 282 | std::unique_ptr<base::MemoryPressureListener> memory_pressure_listener_; |
| 283 | #endif |
| 284 | |
Mohsen Izadi | 0b9fbb6 | 2018-08-30 20:30:00 | [diff] [blame] | 285 | std::unique_ptr<viz::GpuHostImpl> gpu_host_; |
sadrul | 6c5aed8c | 2017-01-11 23:11:44 | [diff] [blame] | 286 | |
Jeremy Roman | 3bca4bf | 2019-07-11 03:41:25 | [diff] [blame] | 287 | base::WeakPtrFactory<GpuProcessHost> weak_ptr_factory_{this}; |
[email protected] | a042173 | 2011-02-23 03:55:40 | [diff] [blame] | 288 | }; |
| 289 | |
[email protected] | 21efac3 | 2012-10-29 02:41:11 | [diff] [blame] | 290 | } // namespace content |
| 291 | |
[email protected] | d9f3793 | 2011-05-09 20:09:24 | [diff] [blame] | 292 | #endif // CONTENT_BROWSER_GPU_GPU_PROCESS_HOST_H_ |