2
* Copyright (C) 2019-2020 Apple Inc. All rights reserved.
4
* Redistribution and use in source and binary forms, with or without
5
* modification, are permitted provided that the following conditions
7
* 1. Redistributions of source code must retain the above copyright
8
* notice, this list of conditions and the following disclaimer.
9
* 2. Redistributions in binary form must reproduce the above copyright
10
* notice, this list of conditions and the following disclaimer in the
11
* documentation and/or other materials provided with the distribution.
13
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23
* THE POSSIBILITY OF SUCH DAMAGE.
28
#if ENABLE(GPU_PROCESS)
30
#include "AuxiliaryProcessProxy.h"
31
#include "GPUProcessProxyMessagesReplies.h"
32
#include "ProcessLauncher.h"
33
#include "ProcessThrottler.h"
34
#include "ProcessThrottlerClient.h"
35
#include "WebPageProxyIdentifier.h"
36
#include "WebProcessProxyMessagesReplies.h"
38
#include <pal/SessionID.h>
42
class WebProcessProxy;
43
class WebsiteDataStore;
44
struct GPUProcessCreationParameters;
46
class GPUProcessProxy final : public AuxiliaryProcessProxy, private ProcessThrottlerClient, public CanMakeWeakPtr<GPUProcessProxy> {
47
WTF_MAKE_FAST_ALLOCATED;
48
WTF_MAKE_NONCOPYABLE(GPUProcessProxy);
49
friend LazyNeverDestroyed<GPUProcessProxy>;
51
static GPUProcessProxy& singleton();
52
static GPUProcessProxy* singletonIfCreated() { return m_singleton; }
54
void getGPUProcessConnection(WebProcessProxy&, Messages::WebProcessProxy::GetGPUProcessConnectionDelayedReply&&);
56
ProcessThrottler& throttler() { return m_throttler; }
57
void updateProcessAssertion();
59
// ProcessThrottlerClient
60
void sendProcessDidResume() final { }
62
#if ENABLE(MEDIA_STREAM)
63
void setUseMockCaptureDevices(bool);
66
void removeSession(PAL::SessionID);
69
explicit GPUProcessProxy();
72
void addSession(const WebsiteDataStore&);
74
// AuxiliaryProcessProxy
75
ASCIILiteral processName() const final { return "GPU"_s; }
77
void getLaunchOptions(ProcessLauncher::LaunchOptions&) override;
78
void connectionWillOpen(IPC::Connection&) override;
79
void processWillShutDown(IPC::Connection&) override;
81
void gpuProcessCrashed();
83
// ProcessThrottlerClient
84
void sendPrepareToSuspend(IsSuspensionImminent, CompletionHandler<void()>&&) final { }
85
void didSetAssertionState(AssertionState) final { }
87
// ProcessLauncher::Client
88
void didFinishLaunching(ProcessLauncher*, IPC::Connection::Identifier) override;
90
typedef uint64_t ConnectionRequestIdentifier;
91
void openGPUProcessConnection(ConnectionRequestIdentifier, WebProcessProxy&);
93
// IPC::Connection::Client
94
void didClose(IPC::Connection&) override;
95
void didReceiveInvalidMessage(IPC::Connection&, IPC::StringReference messageReceiverName, IPC::StringReference messageName) override;
97
static GPUProcessProxy* m_singleton;
99
struct ConnectionRequest {
100
WeakPtr<WebProcessProxy> webProcess;
101
Messages::WebProcessProxy::GetGPUProcessConnectionDelayedReply reply;
103
ConnectionRequestIdentifier m_connectionRequestIdentifier { 0 };
104
HashMap<ConnectionRequestIdentifier, ConnectionRequest> m_connectionRequests;
106
ProcessThrottler m_throttler;
107
ProcessThrottler::ActivityVariant m_activityFromWebProcesses;
108
#if ENABLE(MEDIA_STREAM)
109
bool m_useMockCaptureDevices { false };
111
HashSet<PAL::SessionID> m_sessionIDs;
114
} // namespace WebKit
116
#endif // ENABLE(GPU_PROCESS)