Skip to content

Commit d564525

Browse files
committed
Clean up some code in SharedDisplayListHandle
https://bugs.webkit.org/show_bug.cgi?id=219089 Reviewed by Geoff Garen. Currently, `reservedCapacityAtStart` is defined as a constant 16 bytes, which is enough to encompass the contents of the header structure in a shared display list handle (i.e. an 8-byte atomic for the lock, and another 8 bytes for the unread count). Instead of hard-coding this, we could simply make this a constexpr function that returns the size of `DisplayListSharedMemoryHeader` (rounded up to ensure alignment of all display list item data). No change in behavior. * GPUProcess/graphics/RemoteRenderingBackend.cpp: (WebKit::RemoteRenderingBackend::wakeUpAndApplyDisplayList): (WebKit::RemoteRenderingBackend::didCreateSharedDisplayListHandle): * Shared/SharedDisplayListHandle.h: (WebKit::SharedDisplayListHandle::headerSize): * WebProcess/GPU/graphics/DisplayListWriterHandle.cpp: (WebKit::DisplayListWriterHandle::resetWritableOffsetIfPossible): * WebProcess/GPU/graphics/DisplayListWriterHandle.h: (WebKit::DisplayListWriterHandle::DisplayListWriterHandle): * WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp: (WebKit::RemoteRenderingBackendProxy::createItemBuffer): Also add a static assert that the size of a newly allocated buffer is larger than the reserved header capacity. Canonical link: https://commits.webkit.org/231718@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269969 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 986be9d commit d564525

6 files changed

Lines changed: 42 additions & 8 deletions

File tree

Source/WebKit/ChangeLog

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,33 @@
1+
2020-11-18 Wenson Hsieh <wenson_hsieh@apple.com>
2+
3+
Clean up some code in SharedDisplayListHandle
4+
https://bugs.webkit.org/show_bug.cgi?id=219089
5+
6+
Reviewed by Geoff Garen.
7+
8+
Currently, `reservedCapacityAtStart` is defined as a constant 16 bytes, which is enough to encompass the
9+
contents of the header structure in a shared display list handle (i.e. an 8-byte atomic for the lock, and
10+
another 8 bytes for the unread count).
11+
12+
Instead of hard-coding this, we could simply make this a constexpr function that returns the size of
13+
`DisplayListSharedMemoryHeader` (rounded up to ensure alignment of all display list item data).
14+
15+
No change in behavior.
16+
17+
* GPUProcess/graphics/RemoteRenderingBackend.cpp:
18+
(WebKit::RemoteRenderingBackend::wakeUpAndApplyDisplayList):
19+
(WebKit::RemoteRenderingBackend::didCreateSharedDisplayListHandle):
20+
* Shared/SharedDisplayListHandle.h:
21+
(WebKit::SharedDisplayListHandle::headerSize):
22+
* WebProcess/GPU/graphics/DisplayListWriterHandle.cpp:
23+
(WebKit::DisplayListWriterHandle::resetWritableOffsetIfPossible):
24+
* WebProcess/GPU/graphics/DisplayListWriterHandle.h:
25+
(WebKit::DisplayListWriterHandle::DisplayListWriterHandle):
26+
* WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp:
27+
(WebKit::RemoteRenderingBackendProxy::createItemBuffer):
28+
29+
Also add a static assert that the size of a newly allocated buffer is larger than the reserved header capacity.
30+
131
2020-11-18 Per Arne Vollan <pvollan@apple.com>
232

333
[macOS] Fix message filter sandbox violation

Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ void RemoteRenderingBackend::wakeUpAndApplyDisplayList(DisplayList::ItemBufferId
198198
}
199199
// Otherwise, continue reading the next display list item buffer from the start.
200200
m_nextItemBufferToRead = { };
201-
applyDisplayListsFromHandle(*imageBuffer, *nextHandle, SharedDisplayListHandle::reservedCapacityAtStart);
201+
applyDisplayListsFromHandle(*imageBuffer, *nextHandle, SharedDisplayListHandle::headerSize());
202202
}
203203
}
204204

@@ -243,7 +243,7 @@ void RemoteRenderingBackend::didCreateSharedDisplayListHandle(DisplayList::ItemB
243243

244244
if (m_nextItemBufferToRead == identifier) {
245245
m_nextItemBufferToRead = { };
246-
wakeUpAndApplyDisplayList(identifier, SharedDisplayListHandle::reservedCapacityAtStart, destinationBufferIdentifier);
246+
wakeUpAndApplyDisplayList(identifier, SharedDisplayListHandle::headerSize(), destinationBufferIdentifier);
247247
}
248248
}
249249

Source/WebKit/Shared/SharedDisplayListHandle.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ class SharedDisplayListHandle : public RefCounted<SharedDisplayListHandle> {
3737
public:
3838
virtual ~SharedDisplayListHandle() = default;
3939

40-
static constexpr auto reservedCapacityAtStart = 2 * sizeof(uint64_t);
40+
static constexpr size_t headerSize()
41+
{
42+
return roundUpToMultipleOf<sizeof(std::max_align_t)>(sizeof(DisplayListSharedMemoryHeader));
43+
}
4144

4245
SharedMemory& sharedMemory() { return m_sharedMemory.get(); }
4346
const SharedMemory& sharedMemory() const { return m_sharedMemory.get(); }

Source/WebKit/WebProcess/GPU/graphics/DisplayListWriterHandle.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ DisplayList::ItemBufferHandle DisplayListWriterHandle::createHandle() const
6868

6969
bool DisplayListWriterHandle::resetWritableOffsetIfPossible()
7070
{
71-
if (m_writableOffset <= SharedDisplayListHandle::reservedCapacityAtStart) {
72-
RELEASE_ASSERT(m_writableOffset == SharedDisplayListHandle::reservedCapacityAtStart);
71+
if (m_writableOffset <= SharedDisplayListHandle::headerSize()) {
72+
RELEASE_ASSERT(m_writableOffset == SharedDisplayListHandle::headerSize());
7373
return true;
7474
}
7575

7676
if (unreadBytes())
7777
return false;
7878

79-
m_writableOffset = SharedDisplayListHandle::reservedCapacityAtStart;
79+
m_writableOffset = SharedDisplayListHandle::headerSize();
8080
return true;
8181
}
8282

Source/WebKit/WebProcess/GPU/graphics/DisplayListWriterHandle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class DisplayListWriterHandle : public SharedDisplayListHandle {
4949
private:
5050
DisplayListWriterHandle(WebCore::DisplayList::ItemBufferIdentifier identifier, Ref<SharedMemory>&& sharedMemory)
5151
: SharedDisplayListHandle(identifier, WTFMove(sharedMemory))
52-
, m_writableOffset(SharedDisplayListHandle::reservedCapacityAtStart)
52+
, m_writableOffset(SharedDisplayListHandle::headerSize())
5353
{
5454
}
5555

Source/WebKit/WebProcess/GPU/graphics/RemoteRenderingBackendProxy.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,9 @@ DisplayList::ItemBufferHandle RemoteRenderingBackendProxy::createItemBuffer(size
239239
}
240240

241241
static constexpr size_t defaultSharedItemBufferSize = 1 << 16;
242+
static_assert(defaultSharedItemBufferSize > SharedDisplayListHandle::headerSize());
242243

243-
auto sharedMemory = SharedMemory::allocate(std::max(defaultSharedItemBufferSize, capacity + SharedDisplayListHandle::reservedCapacityAtStart));
244+
auto sharedMemory = SharedMemory::allocate(std::max(defaultSharedItemBufferSize, capacity + SharedDisplayListHandle::headerSize()));
244245
if (!sharedMemory)
245246
return { };
246247

0 commit comments

Comments
 (0)