12021-07-23 Myles C. Maxfield <mmaxfield@apple.com>
2
3 [GPU Process] Add resource use counter infrastructure to RemoteResourceCache
4 https://bugs.webkit.org/show_bug.cgi?id=228222
5
6 Reviewed by NOBODY (OOPS!).
7
8 This patch adds the infrastructure for associating a counter with each resource in the RemoteResourceCache.
9 As the web process uses a resource during display list recording, it increments a counter, and as the GPU
10 process uses a resource, it increments a counter in the RemoteResourceCache. When the web process is done
11 with a resource, it sends a release message to the GPU process which crucially includes the web process's
12 counter. The GPU process has to then wait to actually delete the resource until its own use counter matches
13 the one it received from the web process. This patch implements this deferred deletion infrastructure
14 in the GPU process.
15
16 * GPUProcess/graphics/RemoteRenderingBackend.cpp:
17 (WebKit::RemoteRenderingBackend::ReplayerDelegate::recordResourceUse):
18 (WebKit::RemoteRenderingBackend::releaseRemoteResource): Pass the use count to the RemoteResourceCache.
19 * GPUProcess/graphics/RemoteRenderingBackend.h: Add the use count field.
20 * GPUProcess/graphics/RemoteRenderingBackend.messages.in: Ditto.
21 * GPUProcess/graphics/RemoteResourceCache.cpp:
22 (WebKit::RemoteResourceCache::cacheImageBuffer): It's actually okay if there's already an resource cached.
23 That just means that the web process started using a resource again before the GPU process consumed all
24 commands that used it the first time. All we need to do is increment the open count.
25 (WebKit::RemoteResourceCache::cacheNativeImage): Ditto.
26 (WebKit::RemoteResourceCache::cacheFont): Ditto.
27 (WebKit::RemoteResourceCache::ensureResourceUseCounter):
28 (WebKit::RemoteResourceCache::maybeRemoveResource): This is called whenever it's possible for us to be in
29 situation where we should be removing a resource (aka whenever the use count increments). It checks to see
30 if we can remove the resource, and if it can, does so.
31 (WebKit::RemoteResourceCache::recordResourceUse): The callback that runs for each resource use during
32 replaying. It can't actually delete any resources, so instead it just records which resources had their
33 use counts incremented, and waits for prune() to actually call maybeRemoveResource().
34 (WebKit::RemoteResourceCache::prune): After the replay is complete, call maybeRemoveResource() on all the
35 resources which had their use counters touched.
36 (WebKit::RemoteResourceCache::releaseRemoteResource): Put the relevant resource into the state where we
37 are waiting for the use counters to match before we can delete the resource. Also, call maybeRemoveResource()
38 so it can be deleted immediately if the counters already match.
39 * GPUProcess/graphics/RemoteResourceCache.h: Add a new data structure to hold the use counters. There's
40 a big comment in here that describes what these fields mean.
41 * WebProcess/GPU/graphics/RemoteImageBufferProxy.h:
42 (WebKit::RemoteImageBufferProxy::~RemoteImageBufferProxy): Send a dummy use count for now. This will be
43 implemented in a follow-up patch.
44 * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
45 (WebKit::RemoteRenderingBackendProxy::releaseRemoteResource): Add the useCount parameter.
46 * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.h: Ditto.
47 * WebProcess/GPU/graphics/RemoteResourceCacheProxy.cpp:
48 (WebKit::RemoteResourceCacheProxy::releaseNativeImage): Send a dummy use count for now. This will be
49 implemented in a follow-up patch.
50 (WebKit::RemoteResourceCacheProxy::clearFontMap): Ditto.
51 (WebKit::RemoteResourceCacheProxy::finalizeRenderingUpdateForFonts): Ditto.
52