Changeset 273204 in webkit


Ignore:
Timestamp:
Feb 20, 2021 12:33:25 PM (3 years ago)
Author:
Peng Liu
Message:

WebGL GPU process IPC should use shared memory for asynchronous messages
https://bugs.webkit.org/show_bug.cgi?id=219641
<rdar://problem/72340651>

Patch by Kimmo Kinnunen <kkinnunen@apple.com> on 2021-02-20
Reviewed by Geoff Garen.

Source/WebKit:

Implement a concept of a message buffer. This is a similar concept as
"command buffer" or "display list" in some graphics APIs. Messages
can be added to the buffer by a client and then played back by a
server.

Current implementation adds a specific pseudo-infinite,
semi-duplex message buffer type IPC::StreamConnectionBuffer. This
is a buffer that can be attached to stream connection, an object
that can deliver IPC messages either through the message buffer
or through normal IPC::Connection. The stream connection is
implemented as IPC::StreamClientConnection and IPC::StreamServerConnection.
The connection has server and client distinction, similar to
IPC::Connection. Unlike IPC::Connection, a stream connection is asymmetric
in features: the client can send messages and receive replies, where
as the server can receive messages and send replies.

Messages received through IPC::StreamServerConnection can be
processed by StreamConnectionWorkQueue.

Currently asynchronous messages are added to the stream. Synchronous messages
and their replies are dispatched through normal IPC.

WebGL is implemented by having one StreamConnectionWorkQueue for all WebGL
in the browser. Currently each web process WebGL context in has one
StreamClientConnection attached to one 2mb StreamConnectionBuffer.

Later on, there will be only one WebGL stream connection and connection
buffer shared between all contexts in particular thread in Web process.
The implementation is "optimized" for the later on case. Due to single-
process nature of each page, it does not make much sense to have buffer
per context. However, it is anticipated that many of the successive calls
are to same context. The SHM message format implements an optimization
where the destination id is maintained as part of the stream connection
state.

In GPU process side, all WebGL is processed in one task queue,
"RemoteGraphicsContextGL task queue". It will process up to 1000 commands
per connection per iteration.

Implemented as follows:
Sender shares the shared memory area with the destination when creating
the destination.

If the message fits to the stream shared memory area, write it there.
Otherwise send it via normal IPC as out of line message.

Messages to the destination arrive as before, in order. For each out of line
message, an entry is pushed to the stream. Receiver will stop processing the
stream and processing will continue once the out-of-line
message has been processed.

Sender can write messages to the stream simultaneous to the receiver reading
the messages. This is implemented as a ring buffer with atomic sender and receiver
pointers.

Stream connection processing is implemented as a shared semaphore. This semaphore
is notified if the receiver is waiting on it.

Performance impact (iMac Pro):

  • MotionMark triangles: 300 points -> 4000 points (~7000 points no-GPUP)
  • WebGL samples Aquarium: 1000 fish ~60fps -> 5000 fish ~60fps (~5000 fish with no-GPUP)

No new tests, tested by existing tests.

  • GPUProcess/GPUConnectionToWebProcess.cpp:

(WebKit::GPUConnectionToWebProcess::createGraphicsContextGL):

  • GPUProcess/GPUConnectionToWebProcess.h:
  • GPUProcess/GPUConnectionToWebProcess.messages.in:
  • GPUProcess/graphics/RemoteGraphicsContextGL.cpp:

(WebKit::remoteGraphicsContextGLStreamWorkQueue):
(WebKit::RemoteGraphicsContextGL::create):
(WebKit::RemoteGraphicsContextGL::RemoteGraphicsContextGL):
(WebKit::RemoteGraphicsContextGL::~RemoteGraphicsContextGL):
(WebKit::RemoteGraphicsContextGL::initialize):
(WebKit::RemoteGraphicsContextGL::connectWebProcessConnection):
(WebKit::RemoteGraphicsContextGL::disconnectWebProcessConnection):
(WebKit::RemoteGraphicsContextGL::workQueueInitialize):
(WebKit::RemoteGraphicsContextGL::workQueueUninitialize):
Initialize the OpenGL context in the work queue, since OpenGL
has various limitations wrt thread mobility.

(WebKit::RemoteGraphicsContextGL::forceContextLost):
(WebKit::RemoteGraphicsContextGL::dispatchContextChangedNotification):

  • GPUProcess/graphics/RemoteGraphicsContextGL.h:

(WebKit::RemoteGraphicsContextGL::platformWorkQueueInitialize):
(WebKit::RemoteGraphicsContextGL::send const):

  • GPUProcess/graphics/RemoteGraphicsContextGL.messages.in:
  • GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp:

(WebKit::RemoteGraphicsContextGL::create):
(WebKit::RemoteGraphicsContextGLCocoa::RemoteGraphicsContextGLCocoa):
(WebKit::RemoteGraphicsContextGLCocoa::platformWorkQueueInitialize):

  • NetworkProcess/webrtc/NetworkRTCProvider.h:
  • Platform/IPC/ArgumentCoder.h:
  • Platform/IPC/ArgumentCoders.cpp:
  • Platform/IPC/ArgumentCoders.h:

Make it possible to use multiple different Encoder classes to encode
the IPC data.

  • Platform/IPC/Connection.cpp:

(IPC::Connection::processIncomingMessage):
(IPC::Connection::dispatchDidReceiveInvalidMessage):

  • Platform/IPC/Connection.h:

Add possibility for the stream decoding logic to send the didReceiveInvalidMessage
notification to the connection client.

  • Platform/IPC/Decoder.cpp:

(IPC::Decoder::Decoder):
(IPC::m_bufferDeallocator):
(IPC::m_destinationID):

  • Platform/IPC/Decoder.h:

Add a constructor for Decoder for constructing a decoder in place in
the stream buffer.

  • Platform/IPC/HandleMessage.h:

(IPC::handleMessageSynchronous):
Adds a stream-specific handleMessageSynchronous.
The old ones are unneccessarily complex, as they need redundant calls through redundant
generated send functions.
The old ones need the reply encoder passed in, which is redundant and problematic
for the upcoming case where the stream messaging will mainly reply through the stream itself,
constructing the IPC::StreamConnectionEncoder instead of normal IPC::Encoder.

  • Platform/IPC/StreamClientConnection.cpp: Copied from Source/WebKit/Platform/IPC/cocoa/MachPort.h.

(IPC::StreamClientConnection::StreamClientConnection):
(IPC::StreamClientConnection::setWakeUpSemaphore):
Add function to set the connection receive side wakeup semaphore.
Currently the semaphore is the semaphore that StreamConnectionWorkQueue
waits on. All streams processed by the same work queue will receive the same
semaphore and will notify it when they have written new data.

(IPC::StreamClientConnection::wakeUpReceiver):

  • Platform/IPC/StreamClientConnection.h: Added.

(IPC::StreamClientConnection::send):
(IPC::StreamClientConnection::sendSync):
(IPC::StreamClientConnection::trySendDestinationIDIfNeeded):
(IPC::StreamClientConnection::sendProcessOutOfStreamMessage):
(IPC::StreamClientConnection::tryAcquire):
(IPC::StreamClientConnection::release):
(IPC::StreamClientConnection::alignedSpan):
(IPC::StreamClientConnection::size):
(IPC::StreamClientConnection::clampedLimit const):
Add the implementation for sending data through the shared memory.

  • Platform/IPC/StreamConnectionBuffer.cpp: Added.

(IPC::createMemory):
(IPC::StreamConnectionBuffer::StreamConnectionBuffer):
(IPC::StreamConnectionBuffer::operator=):
(IPC::StreamConnectionBuffer::encode const):
(IPC::StreamConnectionBuffer::decode):

  • Platform/IPC/StreamConnectionBuffer.h: Added.

(IPC::StreamConnectionBuffer::wrapOffset const):
(IPC::StreamConnectionBuffer::alignOffset const):
(IPC::StreamConnectionBuffer::senderOffset):
(IPC::StreamConnectionBuffer::receiverOffset):
(IPC::StreamConnectionBuffer::data const):
(IPC::StreamConnectionBuffer::dataSize const):
(IPC::StreamConnectionBuffer::senderWaitSemaphore):
(IPC::StreamConnectionBuffer::header const):
(IPC::StreamConnectionBuffer::headerSize):
Add the common implementation for the shared memory ring buffer.
This is the common implementation used by both the sender side
as well as the receiver side.
Due to the selection of how the size is marked up, the
common implementation does not contain all the non-trivial code.
The "algorithm" uses a "hole indicator" to differentiate between
cases of "buffer is empty" and "buffer is full". The other
alternative could be better and maybe explored later.

  • Platform/IPC/StreamConnectionEncoder.h: Added.
  • Platform/IPC/StreamConnectionWorkQueue.cpp: Added.

(IPC::StreamConnectionWorkQueue::StreamConnectionWorkQueue):
(IPC::StreamConnectionWorkQueue::dispatch):
(IPC::StreamConnectionWorkQueue::addStreamConnection):
(IPC::StreamConnectionWorkQueue::removeStreamConnection):
(IPC::StreamConnectionWorkQueue::stop):
(IPC::StreamConnectionWorkQueue::wakeUp):
(IPC::StreamConnectionWorkQueue::wakeUpSemaphore):
(IPC::StreamConnectionWorkQueue::wakeUpProcessingThread):
(IPC::StreamConnectionWorkQueue::processStreams):
Work queue contains multiple StreamServerConnection instances.
For each iteration of the work queue thread, it will process
1000 items from each connection. If none of the connections contain
work, the queue will sleep on the work queue semaphore.
The senders will send through StreamClientConnection which
will wake up the work queue by signaling the semaphore.

  • Platform/IPC/StreamConnectionWorkQueue.h: Copied from Source/WebKit/Platform/IPC/cocoa/MachPort.h.
  • Platform/IPC/StreamServerConnection.cpp: Added.

(IPC::StreamServerConnectionBase::StreamServerConnectionBase):
(IPC::StreamServerConnectionBase::startReceivingMessagesImpl):
(IPC::StreamServerConnectionBase::stopReceivingMessagesImpl):
(IPC::StreamServerConnectionBase::enqueueMessage):
(IPC::StreamServerConnectionBase::tryAquire):
(IPC::StreamServerConnectionBase::release):
(IPC::StreamServerConnectionBase::alignedSpan):
(IPC::StreamServerConnectionBase::size):
(IPC::StreamServerConnectionBase::clampedLimit const):

  • Platform/IPC/StreamServerConnection.h: Added.

(IPC::StreamServerConnectionBase::connection):
(IPC::StreamServerConnectionBase::wrapOffset const):
(IPC::StreamServerConnectionBase::alignOffset const):
(IPC::StreamServerConnectionBase::sharedSenderOffset):
(IPC::StreamServerConnectionBase::sharedReceiverOffset):
(IPC::StreamServerConnectionBase::data const):
(IPC::StreamServerConnectionBase::dataSize const):
(IPC::StreamServerConnectionBase::sendSyncReply):
(IPC::StreamServerConnection<Receiver>::startReceivingMessages):
(IPC::StreamServerConnection<Receiver>::stopReceivingMessages):
(IPC::StreamServerConnection<Receiver>::dispatchStreamMessages):
(IPC::StreamServerConnection<Receiver>::processSetStreamDestinationID):
(IPC::StreamServerConnection<Receiver>::dispatchStreamMessage):
(IPC::StreamServerConnection<Receiver>::dispatchOutOfStreamMessage):
StreamServerConnection will process the message buffer and dispatch
messages based on the buffer contents. The class is a template so
that the message data decode switch (generated by the normal IPC
generator) is perhaps inlined to the message unpack loop.

  • Platform/IPC/cocoa/MachPort.h:
  • Scripts/webkit/messages.py:
  • Scripts/webkit/messages_unittest.py:

Implements a 'Stream' attribute for the message receiver. When marked as
'Stream', the receiver message handler is didReceiveStreamMessage and it
will be called for all messages, stream or normal IPC, sync or async.

  • Scripts/webkit/model.py:

Adds IPC control message ProcessOutOfStreamMessage that is acted on if
it is part of the stream messages. It means that the stream processing
should stop until one normal IPC message, sync or non-synch, should be
processed.

Adds IPC control message SetStreamDestinationID that is acted on if it
is part of the stream messages. It will set the destination ID for all
the subsequent stream messages, until another SetStreamDestinationID
message is seen.

  • Scripts/webkit/tests/Makefile:
  • Scripts/webkit/tests/MessageNames.cpp:

(IPC::description):
(IPC::receiverName):
(IPC::isValidMessageName):

  • Scripts/webkit/tests/MessageNames.h:
  • Scripts/webkit/tests/TestWithStream.messages.in: Copied from Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.messages.in.
  • Scripts/webkit/tests/TestWithStreamBuffer.messages.in: Copied from Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.messages.in.
  • Scripts/webkit/tests/TestWithStreamBufferMessageReceiver.cpp: Added.

(WebKit::TestWithStreamBuffer::didReceiveMessage):

  • Scripts/webkit/tests/TestWithStreamBufferMessages.h: Added.

(Messages::TestWithStreamBuffer::messageReceiverName):
(Messages::TestWithStreamBuffer::SendStreamBuffer::name):
(Messages::TestWithStreamBuffer::SendStreamBuffer::SendStreamBuffer):
(Messages::TestWithStreamBuffer::SendStreamBuffer::arguments const):

  • Scripts/webkit/tests/TestWithStreamBufferMessagesReplies.h: Added.
  • Scripts/webkit/tests/TestWithStreamMessageReceiver.cpp: Added.

(WebKit::TestWithStream::didReceiveStreamMessage):

  • Scripts/webkit/tests/TestWithStreamMessages.h: Added.

(Messages::TestWithStream::messageReceiverName):
(Messages::TestWithStream::SendString::name):
(Messages::TestWithStream::SendString::SendString):
(Messages::TestWithStream::SendString::arguments const):
(Messages::TestWithStream::SendStringSynchronized::name):
(Messages::TestWithStream::SendStringSynchronized::SendStringSynchronized):
(Messages::TestWithStream::SendStringSynchronized::arguments const):

  • Scripts/webkit/tests/TestWithStreamMessagesReplies.h: Added.
  • Sources.txt:
  • UIProcess/Downloads/DownloadProxy.h:
  • UIProcess/ProvisionalPageProxy.cpp:
  • WebKit.xcodeproj/project.pbxproj:
  • WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp:

(WebKit::RemoteGraphicsContextGLProxy::RemoteGraphicsContextGLProxy):
(WebKit::RemoteGraphicsContextGLProxy::wasCreated):
Send the work queue wakeup semaphore as a result of the context creation.

  • Platform/IPC/ScopedActiveMessageReceiveQueue.h: Added.

(IPC::ScopedActiveMessageReceiveQueue::ScopedActiveMessageReceiveQueue):
(IPC::ScopedActiveMessageReceiveQueue::operator=):
(IPC::ScopedActiveMessageReceiveQueue::~ScopedActiveMessageReceiveQueue):
(IPC::ScopedActiveMessageReceiveQueue::reset):
(IPC::ScopedActiveMessageReceiveQueue::get const):
(IPC::ScopedActiveMessageReceiveQueue::stopListeningForIPCAndRelease):
Add a holder to replace previous RemoteRenderingBackendWrapper.
Now other classes can be held similarly.

  • WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h:
  • WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.messages.in:
  • WebProcess/Network/webrtc/LibWebRTCNetwork.h:

Tools:

Mark RemoteGraphicsContextGL message receiver as "Stream",
a new variant of receiver.

  • Scripts/generate-gpup-webgl:

LayoutTests:

Mark few tests as not timing out now that the implementation is not so slow.

  • gpu-process/TestExpectations:
Location:
trunk
Files:
14 added
42 edited
4 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r273203 r273204  
     12021-02-20  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        WebGL GPU process IPC should use shared memory for asynchronous messages
     4        https://bugs.webkit.org/show_bug.cgi?id=219641
     5        <rdar://problem/72340651>
     6
     7        Reviewed by Geoff Garen.
     8
     9        Mark few tests as not timing out now that the implementation is not so slow.
     10
     11        * gpu-process/TestExpectations:
     12
    1132021-02-19  Yusuke Suzuki  <ysuzuki@apple.com>
    214
  • trunk/LayoutTests/gpu-process/TestExpectations

    r273149 r273204  
    3636fast/canvas/webgl/context-update-on-display-configuration.html [ Timeout ]
    3737fast/canvas/webgl/texImage2D-video-flipY-false.html [ Timeout ]
    38 fast/canvas/webgl/uniform-samplers-test.html [ Timeout ]
    3938fast/canvas/webgl/webglcontextchangedevent.html [ Timeout ]
     39
     40fast/canvas/webgl/uniform-samplers-test.html [ Slow ]
     41webgl/2.0.0/conformance/attribs/gl-vertexattribpointer.html [ Slow ]
     42webgl/2.0.0/conformance2/rendering/blitframebuffer-filter-outofbounds.html [ Slow ]
     43
    4044fast/images/animated-image-mp4-crash.html [ Timeout ]
    4145fast/images/animated-image-mp4.html [ Timeout ]
     
    181185webgl/1.0.3/conformance/extensions/oes-texture-half-float-with-canvas.html [ Failure ]
    182186webgl/1.0.3/conformance/extensions/oes-texture-half-float-with-video.html [ Failure ]
    183 webgl/1.0.3/conformance/rendering/many-draw-calls.html [ Timeout ]
    184187webgl/1.0.3/conformance/state/gl-object-get-calls.html [ Timeout ]
    185188webgl/1.0.3/conformance/textures/tex-image-and-sub-image-2d-with-canvas-rgb565.html [ Failure ]
     
    195198webgl/1.0.3/conformance/textures/texture-active-bind-2.html [ Failure ]
    196199webgl/1.0.3/conformance/textures/texture-active-bind.html [ Failure ]
    197 webgl/1.0.3/conformance/uniforms/uniform-samplers-test.html [ Timeout ]
     200webgl/1.0.3/conformance/uniforms/uniform-samplers-test.html [ Slow ]
    198201webgl/2.0.0/conformance/extensions/oes-texture-float-with-canvas.html [ Failure ]
    199202webgl/2.0.0/conformance/extensions/oes-texture-float-with-video.html [ Failure ]
     
    201204webgl/2.0.0/conformance/extensions/oes-texture-half-float-with-video.html [ Failure ]
    202205webgl/2.0.0/conformance/reading/read-pixels-test.html [ Failure ]
    203 webgl/2.0.0/conformance/rendering/many-draw-calls.html [ Timeout ]
    204206webgl/2.0.0/conformance/state/gl-object-get-calls.html [ Timeout ]
    205207webgl/2.0.0/conformance/textures/canvas/tex-2d-rgb-rgb-unsigned_byte.html [ Failure ]
     
    221223webgl/2.0.0/conformance/textures/video/tex-2d-rgba-rgba-unsigned_short_4_4_4_4.html [ Failure ]
    222224webgl/2.0.0/conformance/textures/video/tex-2d-rgba-rgba-unsigned_short_5_5_5_1.html [ Failure ]
    223 webgl/2.0.0/conformance/uniforms/uniform-samplers-test.html [ Timeout ]
     225webgl/2.0.0/conformance/uniforms/uniform-samplers-test.html [ Slow ]
    224226webgl/2.0.0/conformance2/reading/read-pixels-pack-parameters.html [ Failure ]
    225227webgl/2.0.0/conformance2/state/gl-object-get-calls.html [ Timeout ]
  • trunk/Source/WebKit/ChangeLog

    r273202 r273204  
     12021-02-20  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        WebGL GPU process IPC should use shared memory for asynchronous messages
     4        https://bugs.webkit.org/show_bug.cgi?id=219641
     5        <rdar://problem/72340651>
     6
     7        Reviewed by Geoff Garen.
     8
     9        Implement a concept of a message buffer. This is a similar concept as
     10        "command buffer" or "display list" in some graphics APIs. Messages
     11        can be added to the buffer by a client and then played back by a
     12        server.
     13
     14        Current implementation adds a specific pseudo-infinite,
     15        semi-duplex message buffer type IPC::StreamConnectionBuffer. This
     16        is a buffer that can be attached to stream connection, an object
     17        that can deliver IPC messages either through the message buffer
     18        or through normal IPC::Connection. The stream connection is
     19        implemented as IPC::StreamClientConnection and IPC::StreamServerConnection.
     20        The connection has server and client distinction, similar to
     21        IPC::Connection. Unlike IPC::Connection, a stream connection is asymmetric
     22        in features: the client can send messages and receive replies, where
     23        as the server can receive messages and send replies.
     24
     25        Messages received through IPC::StreamServerConnection can be
     26        processed by StreamConnectionWorkQueue.
     27
     28        Currently asynchronous messages are added to the stream. Synchronous messages
     29        and their replies are dispatched through normal IPC.
     30
     31        WebGL is implemented by having one StreamConnectionWorkQueue for all WebGL
     32        in the browser. Currently each web process WebGL context in has one
     33        StreamClientConnection attached to one 2mb StreamConnectionBuffer.
     34
     35        Later on, there will be only one WebGL stream connection and connection
     36        buffer shared between all contexts in particular thread in Web process.
     37        The implementation is "optimized" for the later on case. Due to single-
     38        process nature of each page, it does not make much sense to have buffer
     39        per context. However, it is anticipated that many of the successive calls
     40        are to same context. The SHM message format implements an optimization
     41        where the destination id is maintained as part of the stream connection
     42        state.
     43
     44        In GPU process side, all WebGL is processed in one task queue,
     45        "RemoteGraphicsContextGL task queue". It will process up to 1000 commands
     46        per connection per iteration.
     47
     48        Implemented as follows:
     49        Sender shares the shared memory area with the destination when creating
     50        the destination.
     51
     52        If the message fits to the stream shared memory area, write it there.
     53        Otherwise send it via normal IPC as out of line message.
     54
     55        Messages to the destination arrive as before, in order. For each out of line
     56        message, an entry is pushed to the stream. Receiver will stop processing the
     57        stream and processing will continue once the out-of-line
     58        message has been processed.
     59
     60        Sender can write messages to the stream simultaneous to the receiver reading
     61        the messages. This is implemented as a ring buffer with atomic sender and receiver
     62        pointers.
     63
     64        Stream connection processing is implemented as a shared semaphore. This semaphore
     65        is notified if the receiver is waiting on it.
     66
     67        Performance impact (iMac Pro):
     68            - MotionMark triangles: 300 points -> 4000 points
     69              (~7000 points no-GPUP)
     70            - WebGL samples Aquarium: 1000 fish ~60fps -> 5000 fish ~60fps
     71              (~5000 fish with no-GPUP)
     72
     73        No new tests, tested by existing tests.
     74
     75        * GPUProcess/GPUConnectionToWebProcess.cpp:
     76        (WebKit::GPUConnectionToWebProcess::createGraphicsContextGL):
     77        * GPUProcess/GPUConnectionToWebProcess.h:
     78        * GPUProcess/GPUConnectionToWebProcess.messages.in:
     79        * GPUProcess/graphics/RemoteGraphicsContextGL.cpp:
     80        (WebKit::remoteGraphicsContextGLStreamWorkQueue):
     81        (WebKit::RemoteGraphicsContextGL::create):
     82        (WebKit::RemoteGraphicsContextGL::RemoteGraphicsContextGL):
     83        (WebKit::RemoteGraphicsContextGL::~RemoteGraphicsContextGL):
     84        (WebKit::RemoteGraphicsContextGL::initialize):
     85        (WebKit::RemoteGraphicsContextGL::connectWebProcessConnection):
     86        (WebKit::RemoteGraphicsContextGL::disconnectWebProcessConnection):
     87        (WebKit::RemoteGraphicsContextGL::workQueueInitialize):
     88        (WebKit::RemoteGraphicsContextGL::workQueueUninitialize):
     89        Initialize the OpenGL context in the work queue, since OpenGL
     90        has various limitations wrt thread mobility.
     91
     92        (WebKit::RemoteGraphicsContextGL::forceContextLost):
     93        (WebKit::RemoteGraphicsContextGL::dispatchContextChangedNotification):
     94        * GPUProcess/graphics/RemoteGraphicsContextGL.h:
     95        (WebKit::RemoteGraphicsContextGL::platformWorkQueueInitialize):
     96        (WebKit::RemoteGraphicsContextGL::send const):
     97        * GPUProcess/graphics/RemoteGraphicsContextGL.messages.in:
     98        * GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp:
     99        (WebKit::RemoteGraphicsContextGL::create):
     100        (WebKit::RemoteGraphicsContextGLCocoa::RemoteGraphicsContextGLCocoa):
     101        (WebKit::RemoteGraphicsContextGLCocoa::platformWorkQueueInitialize):
     102        * NetworkProcess/webrtc/NetworkRTCProvider.h:
     103        * Platform/IPC/ArgumentCoder.h:
     104        * Platform/IPC/ArgumentCoders.cpp:
     105        * Platform/IPC/ArgumentCoders.h:
     106        Make it possible to use multiple different Encoder classes to encode
     107        the IPC data.
     108
     109        * Platform/IPC/Connection.cpp:
     110        (IPC::Connection::processIncomingMessage):
     111        (IPC::Connection::dispatchDidReceiveInvalidMessage):
     112        * Platform/IPC/Connection.h:
     113        Add possibility for the stream decoding logic to send the didReceiveInvalidMessage
     114        notification to the connection client.
     115
     116        * Platform/IPC/Decoder.cpp:
     117        (IPC::Decoder::Decoder):
     118        (IPC::m_bufferDeallocator):
     119        (IPC::m_destinationID):
     120        * Platform/IPC/Decoder.h:
     121        Add a constructor for Decoder for constructing a decoder in place in
     122        the stream buffer.
     123
     124        * Platform/IPC/HandleMessage.h:
     125        (IPC::handleMessageSynchronous):
     126        Adds a stream-specific handleMessageSynchronous.
     127        The old ones are unneccessarily complex, as they need redundant calls through redundant
     128        generated send functions.
     129        The old ones need the reply encoder passed in, which is redundant and problematic
     130        for the upcoming case where the stream messaging will mainly reply through the stream itself,
     131        constructing the IPC::StreamConnectionEncoder instead of normal IPC::Encoder.
     132
     133        * Platform/IPC/StreamClientConnection.cpp: Copied from Source/WebKit/Platform/IPC/cocoa/MachPort.h.
     134        (IPC::StreamClientConnection::StreamClientConnection):
     135        (IPC::StreamClientConnection::setWakeUpSemaphore):
     136        Add function to set the connection receive side wakeup semaphore.
     137        Currently the semaphore is the semaphore that StreamConnectionWorkQueue
     138        waits on. All streams processed by the same work queue will receive the same
     139        semaphore and will notify it when they have written new data.
     140
     141        (IPC::StreamClientConnection::wakeUpReceiver):
     142        * Platform/IPC/StreamClientConnection.h: Added.
     143        (IPC::StreamClientConnection::send):
     144        (IPC::StreamClientConnection::sendSync):
     145        (IPC::StreamClientConnection::trySendDestinationIDIfNeeded):
     146        (IPC::StreamClientConnection::sendProcessOutOfStreamMessage):
     147        (IPC::StreamClientConnection::tryAcquire):
     148        (IPC::StreamClientConnection::release):
     149        (IPC::StreamClientConnection::alignedSpan):
     150        (IPC::StreamClientConnection::size):
     151        (IPC::StreamClientConnection::clampedLimit const):
     152        Add the implementation for sending data through the shared memory.
     153
     154
     155        * Platform/IPC/StreamConnectionBuffer.cpp: Added.
     156        (IPC::createMemory):
     157        (IPC::StreamConnectionBuffer::StreamConnectionBuffer):
     158        (IPC::StreamConnectionBuffer::operator=):
     159        (IPC::StreamConnectionBuffer::encode const):
     160        (IPC::StreamConnectionBuffer::decode):
     161        * Platform/IPC/StreamConnectionBuffer.h: Added.
     162        (IPC::StreamConnectionBuffer::wrapOffset const):
     163        (IPC::StreamConnectionBuffer::alignOffset const):
     164        (IPC::StreamConnectionBuffer::senderOffset):
     165        (IPC::StreamConnectionBuffer::receiverOffset):
     166        (IPC::StreamConnectionBuffer::data const):
     167        (IPC::StreamConnectionBuffer::dataSize const):
     168        (IPC::StreamConnectionBuffer::senderWaitSemaphore):
     169        (IPC::StreamConnectionBuffer::header const):
     170        (IPC::StreamConnectionBuffer::headerSize):
     171        Add the common implementation for the shared memory ring buffer.
     172        This is the common implementation used by both the sender side
     173        as well as the receiver side.
     174        Due to the selection of how the size is marked up, the
     175        common implementation does not contain all the non-trivial code.
     176        The "algorithm" uses a "hole indicator" to differentiate between
     177        cases of "buffer is empty" and "buffer is full". The other
     178        alternative could be better and maybe explored later.
     179
     180        * Platform/IPC/StreamConnectionEncoder.h: Added.
     181        * Platform/IPC/StreamConnectionWorkQueue.cpp: Added.
     182        (IPC::StreamConnectionWorkQueue::StreamConnectionWorkQueue):
     183        (IPC::StreamConnectionWorkQueue::dispatch):
     184        (IPC::StreamConnectionWorkQueue::addStreamConnection):
     185        (IPC::StreamConnectionWorkQueue::removeStreamConnection):
     186        (IPC::StreamConnectionWorkQueue::stop):
     187        (IPC::StreamConnectionWorkQueue::wakeUp):
     188        (IPC::StreamConnectionWorkQueue::wakeUpSemaphore):
     189        (IPC::StreamConnectionWorkQueue::wakeUpProcessingThread):
     190        (IPC::StreamConnectionWorkQueue::processStreams):
     191        Work queue contains multiple StreamServerConnection instances.
     192        For each iteration of the work queue thread, it will process
     193        1000 items from each connection. If none of the connections contain
     194        work, the queue will sleep on the work queue semaphore.
     195        The senders will send through StreamClientConnection which
     196        will wake up the work queue by signaling the semaphore.
     197
     198        * Platform/IPC/StreamConnectionWorkQueue.h: Copied from Source/WebKit/Platform/IPC/cocoa/MachPort.h.
     199        * Platform/IPC/StreamServerConnection.cpp: Added.
     200        (IPC::StreamServerConnectionBase::StreamServerConnectionBase):
     201        (IPC::StreamServerConnectionBase::startReceivingMessagesImpl):
     202        (IPC::StreamServerConnectionBase::stopReceivingMessagesImpl):
     203        (IPC::StreamServerConnectionBase::enqueueMessage):
     204        (IPC::StreamServerConnectionBase::tryAquire):
     205        (IPC::StreamServerConnectionBase::release):
     206        (IPC::StreamServerConnectionBase::alignedSpan):
     207        (IPC::StreamServerConnectionBase::size):
     208        (IPC::StreamServerConnectionBase::clampedLimit const):
     209        * Platform/IPC/StreamServerConnection.h: Added.
     210        (IPC::StreamServerConnectionBase::connection):
     211        (IPC::StreamServerConnectionBase::wrapOffset const):
     212        (IPC::StreamServerConnectionBase::alignOffset const):
     213        (IPC::StreamServerConnectionBase::sharedSenderOffset):
     214        (IPC::StreamServerConnectionBase::sharedReceiverOffset):
     215        (IPC::StreamServerConnectionBase::data const):
     216        (IPC::StreamServerConnectionBase::dataSize const):
     217        (IPC::StreamServerConnectionBase::sendSyncReply):
     218        (IPC::StreamServerConnection<Receiver>::startReceivingMessages):
     219        (IPC::StreamServerConnection<Receiver>::stopReceivingMessages):
     220        (IPC::StreamServerConnection<Receiver>::dispatchStreamMessages):
     221        (IPC::StreamServerConnection<Receiver>::processSetStreamDestinationID):
     222        (IPC::StreamServerConnection<Receiver>::dispatchStreamMessage):
     223        (IPC::StreamServerConnection<Receiver>::dispatchOutOfStreamMessage):
     224        StreamServerConnection will process the message buffer and dispatch
     225        messages based on the buffer contents. The class is a template so
     226        that the message data decode switch (generated by the normal IPC
     227        generator) is perhaps inlined to the message unpack loop.
     228        * Platform/IPC/cocoa/MachPort.h:
     229
     230        * Scripts/webkit/messages.py:
     231        * Scripts/webkit/messages_unittest.py:
     232        Implements a 'Stream' attribute for the message receiver. When marked as
     233        'Stream', the receiver message handler is didReceiveStreamMessage and it
     234        will be called for all messages, stream or normal IPC, sync or async.
     235
     236        * Scripts/webkit/model.py:
     237        Adds IPC control message ProcessOutOfStreamMessage that is acted on if
     238        it is part of the stream messages. It means that the stream processing
     239        should stop until one normal IPC message, sync or non-synch, should be
     240        processed.
     241
     242        Adds IPC control message SetStreamDestinationID that is acted on if it
     243        is part of the stream messages. It will set the destination ID for all
     244        the subsequent stream messages, until another SetStreamDestinationID
     245        message is seen.
     246
     247        * Scripts/webkit/tests/Makefile:
     248        * Scripts/webkit/tests/MessageNames.cpp:
     249        (IPC::description):
     250        (IPC::receiverName):
     251        (IPC::isValidMessageName):
     252        * Scripts/webkit/tests/MessageNames.h:
     253        * Scripts/webkit/tests/TestWithStream.messages.in: Copied from Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.messages.in.
     254        * Scripts/webkit/tests/TestWithStreamBuffer.messages.in: Copied from Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.messages.in.
     255        * Scripts/webkit/tests/TestWithStreamBufferMessageReceiver.cpp: Added.
     256        (WebKit::TestWithStreamBuffer::didReceiveMessage):
     257        * Scripts/webkit/tests/TestWithStreamBufferMessages.h: Added.
     258        (Messages::TestWithStreamBuffer::messageReceiverName):
     259        (Messages::TestWithStreamBuffer::SendStreamBuffer::name):
     260        (Messages::TestWithStreamBuffer::SendStreamBuffer::SendStreamBuffer):
     261        (Messages::TestWithStreamBuffer::SendStreamBuffer::arguments const):
     262        * Scripts/webkit/tests/TestWithStreamBufferMessagesReplies.h: Added.
     263        * Scripts/webkit/tests/TestWithStreamMessageReceiver.cpp: Added.
     264        (WebKit::TestWithStream::didReceiveStreamMessage):
     265        * Scripts/webkit/tests/TestWithStreamMessages.h: Added.
     266        (Messages::TestWithStream::messageReceiverName):
     267        (Messages::TestWithStream::SendString::name):
     268        (Messages::TestWithStream::SendString::SendString):
     269        (Messages::TestWithStream::SendString::arguments const):
     270        (Messages::TestWithStream::SendStringSynchronized::name):
     271        (Messages::TestWithStream::SendStringSynchronized::SendStringSynchronized):
     272        (Messages::TestWithStream::SendStringSynchronized::arguments const):
     273        * Scripts/webkit/tests/TestWithStreamMessagesReplies.h: Added.
     274        * Sources.txt:
     275        * UIProcess/Downloads/DownloadProxy.h:
     276        * UIProcess/ProvisionalPageProxy.cpp:
     277        * WebKit.xcodeproj/project.pbxproj:
     278        * WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp:
     279        (WebKit::RemoteGraphicsContextGLProxy::RemoteGraphicsContextGLProxy):
     280        (WebKit::RemoteGraphicsContextGLProxy::wasCreated):
     281        Send the work queue wakeup semaphore as a result of the context creation.
     282
     283
     284        * Platform/IPC/ScopedActiveMessageReceiveQueue.h: Added.
     285        (IPC::ScopedActiveMessageReceiveQueue::ScopedActiveMessageReceiveQueue):
     286        (IPC::ScopedActiveMessageReceiveQueue::operator=):
     287        (IPC::ScopedActiveMessageReceiveQueue::~ScopedActiveMessageReceiveQueue):
     288        (IPC::ScopedActiveMessageReceiveQueue::reset):
     289        (IPC::ScopedActiveMessageReceiveQueue::get const):
     290        (IPC::ScopedActiveMessageReceiveQueue::stopListeningForIPCAndRelease):
     291        Add a holder to replace previous RemoteRenderingBackendWrapper.
     292        Now other classes can be held similarly.
     293
     294        * WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h:
     295        * WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.messages.in:
     296        * WebProcess/Network/webrtc/LibWebRTCNetwork.h:
     297
    12982021-02-20  Wenson Hsieh  <wenson_hsieh@apple.com>
    2299
  • trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.cpp

    r273080 r273204  
    316316{
    317317    auto addResult = m_remoteRenderingBackendMap.ensure(identifier, [&]() {
    318         return makeUnique<RemoteRenderingBackendWrapper>(RemoteRenderingBackend::create(*this, identifier, WTFMove(resumeDisplayListSemaphore)));
     318        return IPC::ScopedActiveMessageReceiveQueue { RemoteRenderingBackend::create(*this, identifier, WTFMove(resumeDisplayListSemaphore)) };
    319319    });
    320320    ASSERT_UNUSED(addResult, addResult.isNewEntry);
     
    327327}
    328328
    329 GPUConnectionToWebProcess::RemoteRenderingBackendWrapper::RemoteRenderingBackendWrapper(Ref<RemoteRenderingBackend>&& remoteRenderingBackend)
    330     : m_remoteRenderingBackend(WTFMove(remoteRenderingBackend))
    331 {
    332 }
    333 
    334 GPUConnectionToWebProcess::RemoteRenderingBackendWrapper::~RemoteRenderingBackendWrapper()
    335 {
    336     m_remoteRenderingBackend->disconnect();
    337 }
    338 
    339329#if ENABLE(WEBGL)
    340 void GPUConnectionToWebProcess::createGraphicsContextGL(WebCore::GraphicsContextGLAttributes attributes, GraphicsContextGLIdentifier graphicsContextGLIdentifier, RenderingBackendIdentifier renderingBackendIdentifier)
    341 {
    342     auto* renderingBackend = m_remoteRenderingBackendMap.get(renderingBackendIdentifier);
    343     if (!renderingBackend)
     330void GPUConnectionToWebProcess::createGraphicsContextGL(WebCore::GraphicsContextGLAttributes attributes, GraphicsContextGLIdentifier graphicsContextGLIdentifier, RenderingBackendIdentifier renderingBackendIdentifier, IPC::StreamConnectionBuffer&& stream)
     331{
     332    auto it = m_remoteRenderingBackendMap.find(renderingBackendIdentifier);
     333    if (it == m_remoteRenderingBackendMap.end())
    344334        return;
     335    auto* renderingBackend = it->value.get();
    345336
    346337    auto addResult = m_remoteGraphicsContextGLMap.ensure(graphicsContextGLIdentifier, [&]() {
    347         return RemoteGraphicsContextGL::create(attributes, *this, graphicsContextGLIdentifier, renderingBackend->get());
     338        return IPC::ScopedActiveMessageReceiveQueue { RemoteGraphicsContextGL::create(*this, WTFMove(attributes), graphicsContextGLIdentifier, *renderingBackend, WTFMove(stream)) };
    348339    });
    349340    ASSERT_UNUSED(addResult, addResult.isNewEntry);
  • trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.h

    r273080 r273204  
    3535#include "RemoteRemoteCommandListenerIdentifier.h"
    3636#include "RenderingBackendIdentifier.h"
     37#include "ScopedActiveMessageReceiveQueue.h"
    3738
    3839#include <WebCore/LibWebRTCEnumTraits.h>
     
    139140
    140141#if ENABLE(WEBGL)
    141     void createGraphicsContextGL(WebCore::GraphicsContextGLAttributes, GraphicsContextGLIdentifier, RenderingBackendIdentifier);
     142    void createGraphicsContextGL(WebCore::GraphicsContextGLAttributes, GraphicsContextGLIdentifier, RenderingBackendIdentifier, IPC::StreamConnectionBuffer&&);
    142143    void releaseGraphicsContextGL(GraphicsContextGLIdentifier);
    143144#endif
     
    207208#endif
    208209
    209     class RemoteRenderingBackendWrapper {
    210         WTF_MAKE_FAST_ALLOCATED;
    211     public:
    212         RemoteRenderingBackendWrapper(Ref<RemoteRenderingBackend>&&);
    213         ~RemoteRenderingBackendWrapper();
    214         RemoteRenderingBackend& get() const { return m_remoteRenderingBackend.get(); }
    215     private:
    216         Ref<RemoteRenderingBackend> m_remoteRenderingBackend;
    217     };
    218 
    219     using RemoteRenderingBackendMap = HashMap<RenderingBackendIdentifier, std::unique_ptr<RemoteRenderingBackendWrapper>>;
     210    using RemoteRenderingBackendMap = HashMap<RenderingBackendIdentifier, IPC::ScopedActiveMessageReceiveQueue<RemoteRenderingBackend>>;
    220211    RemoteRenderingBackendMap m_remoteRenderingBackendMap;
    221212#if ENABLE(WEBGL)
    222     using RemoteGraphicsContextGLMap = HashMap<GraphicsContextGLIdentifier, std::unique_ptr<RemoteGraphicsContextGL>>;
     213    using RemoteGraphicsContextGLMap = HashMap<GraphicsContextGLIdentifier, IPC::ScopedActiveMessageReceiveQueue<RemoteGraphicsContextGL>>;
    223214    RemoteGraphicsContextGLMap m_remoteGraphicsContextGLMap;
    224215#endif
  • trunk/Source/WebKit/GPUProcess/GPUConnectionToWebProcess.messages.in

    r273080 r273204  
    2727    void ReleaseRenderingBackend(WebKit::RenderingBackendIdentifier renderingBackendIdentifier)
    2828#if ENABLE(WEBGL)
    29     void CreateGraphicsContextGL(struct WebCore::GraphicsContextGLAttributes attributes, WebKit::GraphicsContextGLIdentifier graphicsContextGLIdentifier, WebKit::RenderingBackendIdentifier renderingBackendIdentifier)
     29    void CreateGraphicsContextGL(struct WebCore::GraphicsContextGLAttributes attributes, WebKit::GraphicsContextGLIdentifier graphicsContextGLIdentifier, WebKit::RenderingBackendIdentifier renderingBackendIdentifier, IPC::StreamConnectionBuffer stream)
    3030    void ReleaseGraphicsContextGL(WebKit::GraphicsContextGLIdentifier graphicsContextGLIdentifier)
    3131#endif
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.cpp

    r273080 r273204  
    3232#include "RemoteGraphicsContextGLMessages.h"
    3333#include "RemoteGraphicsContextGLProxyMessages.h"
     34#include "StreamConnectionWorkQueue.h"
    3435#include <WebCore/GraphicsContextGLOpenGL.h>
    3536#include <WebCore/NotImplemented.h>
    36 
     37#include <wtf/NeverDestroyed.h>
    3738
    3839namespace WebKit {
     40
    3941using namespace WebCore;
    4042
     43// Currently we have one global WebGL processing instance.
     44static IPC::StreamConnectionWorkQueue& remoteGraphicsContextGLStreamWorkQueue()
     45{
     46    static NeverDestroyed<IPC::StreamConnectionWorkQueue> instance("RemoteGraphicsContextGL work queue");
     47    return instance.get();
     48}
     49
    4150#if !PLATFORM(COCOA)
    42 std::unique_ptr<RemoteGraphicsContextGL> RemoteGraphicsContextGL::create(const WebCore::GraphicsContextGLAttributes&, GPUConnectionToWebProcess&, GraphicsContextGLIdentifier, RemoteRenderingBackend&)
     51Ref<RemoteGraphicsContextGL> RemoteGraphicsContextGL::create(GPUConnectionToWebProcess& gpuConnectionToWebProcess, GraphicsContextGLAttributes&& attributes, GraphicsContextGLIdentifier graphicsContextGLIdentifier, RemoteRenderingBackend& renderingBackend, IPC::StreamConnectionBuffer&& stream)
    4352{
    4453    ASSERT_NOT_REACHED();
    45     return nullptr;
     54    auto instance = adoptRef(*new RemoteGraphicsContextGL(gpuConnectionToWebProcess, graphicsContextGLIdentifier, renderingBackend, WTFMove(stream)));
     55    instance->initialize(WTFMove(attributes));
     56    return instance;
    4657}
    4758#endif
    4859
    49 RemoteGraphicsContextGL::RemoteGraphicsContextGL(const WebCore::GraphicsContextGLAttributes& attributes, GPUConnectionToWebProcess& connection, GraphicsContextGLIdentifier identifier, Ref<GraphicsContextGLOpenGL> context, RemoteRenderingBackend& renderingBackend)
    50     : m_context(WTFMove(context))
    51     , m_gpuConnectionToWebProcess(makeWeakPtr(connection))
    52     , m_graphicsContextGLIdentifier(identifier)
     60RemoteGraphicsContextGL::RemoteGraphicsContextGL(GPUConnectionToWebProcess& gpuConnectionToWebProcess, GraphicsContextGLIdentifier graphicsContextGLIdentifier, RemoteRenderingBackend& renderingBackend, IPC::StreamConnectionBuffer&& stream)
     61    : m_streamConnection(IPC::StreamServerConnection<RemoteGraphicsContextGL>::create(gpuConnectionToWebProcess.connection(), WTFMove(stream), remoteGraphicsContextGLStreamWorkQueue()))
     62    , m_graphicsContextGLIdentifier(graphicsContextGLIdentifier)
    5363    , m_renderingBackend(makeRef(renderingBackend))
    5464{
    55     if (auto* gpuConnectionToWebProcess = m_gpuConnectionToWebProcess.get())
    56         gpuConnectionToWebProcess->messageReceiverMap().addMessageReceiver(Messages::RemoteGraphicsContextGL::messageReceiverName(), m_graphicsContextGLIdentifier.toUInt64(), *this);
    57     m_context->addClient(*this);
    58     String extensions = m_context->getString(GraphicsContextGL::EXTENSIONS);
    59     String requestableExtensions = m_context->getString(ExtensionsGL::REQUESTABLE_EXTENSIONS_ANGLE);
    60     send(Messages::RemoteGraphicsContextGLProxy::WasCreated(true, extensions, requestableExtensions), m_graphicsContextGLIdentifier);
     65    ASSERT(RunLoop::isMain());
    6166}
    6267
    6368RemoteGraphicsContextGL::~RemoteGraphicsContextGL()
    6469{
    65     if (auto* gpuConnectionToWebProcess = m_gpuConnectionToWebProcess.get())
    66         gpuConnectionToWebProcess->messageReceiverMap().removeMessageReceiver(Messages::RemoteGraphicsContextGL::messageReceiverName(), m_graphicsContextGLIdentifier.toUInt64());
    67 }
    68 
    69 GPUConnectionToWebProcess* RemoteGraphicsContextGL::gpuConnectionToWebProcess() const
    70 {
    71     return m_gpuConnectionToWebProcess.get();
    72 }
    73 
    74 IPC::Connection* RemoteGraphicsContextGL::messageSenderConnection() const
    75 {
    76     if (auto* gpuConnectionToWebProcess = m_gpuConnectionToWebProcess.get())
    77         return &gpuConnectionToWebProcess->connection();
    78     return nullptr;
    79 }
    80 
    81 uint64_t RemoteGraphicsContextGL::messageSenderDestinationID() const
    82 {
    83     return m_graphicsContextGLIdentifier.toUInt64();
     70    ASSERT(!m_streamConnection);
     71    ASSERT(!m_context);
     72}
     73
     74void RemoteGraphicsContextGL::initialize(GraphicsContextGLAttributes&& attributes)
     75{
     76    ASSERT(RunLoop::isMain());
     77    remoteGraphicsContextGLStreamWorkQueue().dispatch([attributes = WTFMove(attributes), protectedThis = makeRef(*this)]() mutable {
     78        protectedThis->workQueueInitialize(WTFMove(attributes));
     79    });
     80    m_streamConnection->startReceivingMessages(*this, Messages::RemoteGraphicsContextGL::messageReceiverName(), m_graphicsContextGLIdentifier.toUInt64());
     81}
     82
     83void RemoteGraphicsContextGL::stopListeningForIPC(Ref<RemoteGraphicsContextGL>&& refFromConnection)
     84{
     85    ASSERT(RunLoop::isMain());
     86    m_streamConnection->stopReceivingMessages(Messages::RemoteGraphicsContextGL::messageReceiverName(), m_graphicsContextGLIdentifier.toUInt64());
     87    remoteGraphicsContextGLStreamWorkQueue().dispatch([protectedThis = WTFMove(refFromConnection)]() {
     88        protectedThis->workQueueUninitialize();
     89    });
     90}
     91
     92void RemoteGraphicsContextGL::workQueueInitialize(WebCore::GraphicsContextGLAttributes&& attributes)
     93{
     94    platformWorkQueueInitialize(WTFMove(attributes));
     95    if (m_context) {
     96        m_context->addClient(*this);
     97        String extensions = m_context->getString(GraphicsContextGL::EXTENSIONS);
     98        String requestableExtensions = m_context->getString(ExtensionsGL::REQUESTABLE_EXTENSIONS_ANGLE);
     99        send(Messages::RemoteGraphicsContextGLProxy::WasCreated(true, remoteGraphicsContextGLStreamWorkQueue().wakeUpSemaphore(), extensions, requestableExtensions));
     100    } else
     101        send(Messages::RemoteGraphicsContextGLProxy::WasCreated(false, IPC::Semaphore { }, "", ""));
     102}
     103
     104void RemoteGraphicsContextGL::workQueueUninitialize()
     105{
     106    m_context = nullptr;
     107    m_streamConnection = nullptr;
    84108}
    85109
     
    90114void RemoteGraphicsContextGL::forceContextLost()
    91115{
    92     send(Messages::RemoteGraphicsContextGLProxy::WasLost(), m_graphicsContextGLIdentifier);
     116    send(Messages::RemoteGraphicsContextGLProxy::WasLost());
    93117}
    94118
     
    100124void RemoteGraphicsContextGL::dispatchContextChangedNotification()
    101125{
    102     send(Messages::RemoteGraphicsContextGLProxy::WasChanged(), m_graphicsContextGLIdentifier);
     126    send(Messages::RemoteGraphicsContextGLProxy::WasChanged());
    103127}
    104128
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.h

    r273080 r273204  
    2929
    3030#include "Connection.h"
     31#include "GPUConnectionToWebProcess.h"
    3132#include "GraphicsContextGLIdentifier.h"
    32 #include "MessageReceiver.h"
    33 #include "MessageSender.h"
    3433#include "RemoteRenderingBackend.h"
     34#include "StreamServerConnection.h"
    3535#include <WebCore/ExtensionsGL.h>
    3636#include <WebCore/GraphicsContextGLOpenGL.h>
     
    5050namespace WebKit {
    5151
    52 class GPUConnectionToWebProcess;
    53 
    5452// GPU process side implementation of that receives messages about GraphicsContextGL calls
    5553// and issues real GraphicsContextGL calls based on the received messages.
    5654// The implementation is largely generated by running Tools/Scripts/generate-gpup-webgl.
    57 class RemoteGraphicsContextGL
    58     : public IPC::MessageSender
    59     , private IPC::MessageReceiver
    60     , private WebCore::GraphicsContextGL::Client {
     55class RemoteGraphicsContextGL : public ThreadSafeRefCounted<RemoteGraphicsContextGL>, private WebCore::GraphicsContextGL::Client {
    6156    WTF_MAKE_FAST_ALLOCATED;
    6257public:
    63     static std::unique_ptr<RemoteGraphicsContextGL> create(const WebCore::GraphicsContextGLAttributes&, GPUConnectionToWebProcess&, GraphicsContextGLIdentifier, RemoteRenderingBackend&);
     58    static Ref<RemoteGraphicsContextGL> create(GPUConnectionToWebProcess&, WebCore::GraphicsContextGLAttributes&&, GraphicsContextGLIdentifier, RemoteRenderingBackend&, IPC::StreamConnectionBuffer&&);
    6459    ~RemoteGraphicsContextGL() override;
     60    void stopListeningForIPC(Ref<RemoteGraphicsContextGL>&& refFromConnection);
    6561
    66     GPUConnectionToWebProcess* gpuConnectionToWebProcess() const;
     62    // IPC::StreamServerConnection<RemoteGraphicsContextGL> template contract implementation.
     63    void didReceiveStreamMessage(IPC::StreamServerConnectionBase&, IPC::Decoder&);
    6764
    6865protected:
    69     RemoteGraphicsContextGL(const WebCore::GraphicsContextGLAttributes&, GPUConnectionToWebProcess&, GraphicsContextGLIdentifier, Ref<WebCore::GraphicsContextGLOpenGL>, RemoteRenderingBackend&);
     66    RemoteGraphicsContextGL(GPUConnectionToWebProcess&, GraphicsContextGLIdentifier, RemoteRenderingBackend&, IPC::StreamConnectionBuffer&&);
     67    void initialize(WebCore::GraphicsContextGLAttributes&&);
    7068
    71     // IPC::MessageSender overrides.
    72     IPC::Connection* messageSenderConnection() const final;
    73     uint64_t messageSenderDestinationID() const final;
    74 
    75     // IPC::MessageReceiver overrides.
    76     void didReceiveMessage(IPC::Connection&, IPC::Decoder&) final;
    77     void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) final;
     69    void workQueueInitialize(WebCore::GraphicsContextGLAttributes&&);
     70    virtual void platformWorkQueueInitialize(WebCore::GraphicsContextGLAttributes&&) { };
     71    void workQueueUninitialize();
     72    template<typename T>
     73    bool send(T&& message) const { return m_streamConnection->connection().send(WTFMove(message), m_graphicsContextGLIdentifier); }
    7874
    7975    // GraphicsContextGL::Client overrides.
     
    10197    void paintImageDataToImageBuffer(RefPtr<WebCore::ImageData>&&, WebCore::RenderingResourceIdentifier, CompletionHandler<void()>&&);
    10298
    103     Ref<WebCore::GraphicsContextGLOpenGL> m_context;
    104     WeakPtr<GPUConnectionToWebProcess> m_gpuConnectionToWebProcess;
     99    RefPtr<IPC::StreamServerConnection<RemoteGraphicsContextGL>> m_streamConnection;
     100    RefPtr<WebCore::GraphicsContextGLOpenGL> m_context;
    105101    GraphicsContextGLIdentifier m_graphicsContextGLIdentifier;
    106102    Ref<RemoteRenderingBackend> m_renderingBackend;
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGL.messages.in

    r273080 r273204  
    2525#if ENABLE(GPU_PROCESS) && ENABLE(WEBGL)
    2626
    27 messages -> RemoteGraphicsContextGL NotRefCounted {
     27messages -> RemoteGraphicsContextGL NotRefCounted Stream {
    2828    void Reshape(int32_t width, int32_t height)
    2929#if PLATFORM(COCOA)
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteGraphicsContextGLCocoa.cpp

    r273080 r273204  
    4040class RemoteGraphicsContextGLCocoa final : public RemoteGraphicsContextGL {
    4141public:
    42     RemoteGraphicsContextGLCocoa(const WebCore::GraphicsContextGLAttributes&, GPUConnectionToWebProcess&, GraphicsContextGLIdentifier, RemoteRenderingBackend&);
     42    RemoteGraphicsContextGLCocoa(GPUConnectionToWebProcess&, GraphicsContextGLIdentifier, RemoteRenderingBackend&, IPC::StreamConnectionBuffer&&);
    4343    ~RemoteGraphicsContextGLCocoa() final = default;
    4444
    4545    // RemoteGraphicsContextGL overrides.
     46    void platformWorkQueueInitialize(WebCore::GraphicsContextGLAttributes&&) final;
    4647    void prepareForDisplay(CompletionHandler<void(WTF::MachSendRight&&)>&&) final;
    4748private:
     
    5152}
    5253
    53 std::unique_ptr<RemoteGraphicsContextGL> RemoteGraphicsContextGL::create(const WebCore::GraphicsContextGLAttributes& attributes, GPUConnectionToWebProcess& connection, GraphicsContextGLIdentifier identifier, RemoteRenderingBackend& renderingBackend)
     54Ref<RemoteGraphicsContextGL> RemoteGraphicsContextGL::create(GPUConnectionToWebProcess& gpuConnectionToWebProcess, GraphicsContextGLAttributes&& attributes, GraphicsContextGLIdentifier graphicsContextGLIdentifier, RemoteRenderingBackend& renderingBackend, IPC::StreamConnectionBuffer&& stream)
    5455{
    55     return makeUnique<RemoteGraphicsContextGLCocoa>(attributes, connection, identifier, renderingBackend);
     56    auto instance = adoptRef(*new RemoteGraphicsContextGLCocoa(gpuConnectionToWebProcess, graphicsContextGLIdentifier, renderingBackend, WTFMove(stream)));
     57    instance->initialize(WTFMove(attributes));
     58    return instance;
    5659}
    5760
    58 RemoteGraphicsContextGLCocoa::RemoteGraphicsContextGLCocoa(const WebCore::GraphicsContextGLAttributes& attributes, GPUConnectionToWebProcess& connection, GraphicsContextGLIdentifier identifier, RemoteRenderingBackend& renderingBackend)
    59     : RemoteGraphicsContextGL(attributes, connection, identifier, GraphicsContextGLOpenGL::createForGPUProcess(attributes, &m_swapChain), renderingBackend)
     61RemoteGraphicsContextGLCocoa::RemoteGraphicsContextGLCocoa(GPUConnectionToWebProcess& gpuConnectionToWebProcess, GraphicsContextGLIdentifier graphicsContextGLIdentifier, RemoteRenderingBackend& renderingBackend, IPC::StreamConnectionBuffer&& stream)
     62    : RemoteGraphicsContextGL(gpuConnectionToWebProcess, graphicsContextGLIdentifier, renderingBackend, WTFMove(stream))
    6063{
     64}
     65
     66void RemoteGraphicsContextGLCocoa::platformWorkQueueInitialize(WebCore::GraphicsContextGLAttributes&& attributes)
     67{
     68    m_context = GraphicsContextGLOpenGL::createForGPUProcess(WTFMove(attributes), &m_swapChain);
    6169}
    6270
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.cpp

    r273139 r273204  
    9090}
    9191
    92 void RemoteRenderingBackend::disconnect()
     92void RemoteRenderingBackend::stopListeningForIPC()
    9393{
    9494    ASSERT(RunLoop::isMain());
  • trunk/Source/WebKit/GPUProcess/graphics/RemoteRenderingBackend.h

    r273139 r273204  
    6767    static Ref<RemoteRenderingBackend> create(GPUConnectionToWebProcess&, RenderingBackendIdentifier, IPC::Semaphore&& resumeDisplayListSemaphore);
    6868    virtual ~RemoteRenderingBackend();
     69    void stopListeningForIPC();
    6970
    7071    RemoteResourceCache& remoteResourceCache() { return m_remoteResourceCache; }
     
    7879
    7980    void setNextItemBufferToRead(WebCore::DisplayList::ItemBufferIdentifier, WebCore::RenderingResourceIdentifier destination);
    80 
    81     void disconnect();
    8281
    8382    // Runs Function in RemoteRenderingBackend task queue.
  • trunk/Source/WebKit/NetworkProcess/Downloads/PendingDownload.h

    r268261 r273204  
    2626#pragma once
    2727
     28#include "DataReference.h"
    2829#include "DownloadID.h"
    2930#include "MessageSender.h"
  • trunk/Source/WebKit/NetworkProcess/webrtc/NetworkRTCProvider.h

    r273074 r273204  
    2929
    3030#include "Connection.h"
     31#include "DataReference.h"
    3132#include "LibWebRTCResolverIdentifier.h"
    3233#include "NetworkRTCMonitor.h"
  • trunk/Source/WebKit/Platform/IPC/ArgumentCoder.h

    r272058 r273204  
    2828#include "Decoder.h"
    2929#include "Encoder.h"
     30#include <wtf/EnumTraits.h>
    3031#include <wtf/Optional.h>
    3132
     
    7677template<typename T>
    7778struct ArgumentCoder<T, typename std::enable_if_t<std::is_arithmetic_v<T>>> {
     79    template<typename Encoder>
    7880    static void encode(Encoder& encoder, T value)
    7981    {
     
    9294template<typename T>
    9395struct ArgumentCoder<T, typename std::enable_if_t<std::is_enum_v<T>>> {
     96    template<typename Encoder>
    9497    static void encode(Encoder& encoder, T value)
    9598    {
  • trunk/Source/WebKit/Platform/IPC/ArgumentCoders.cpp

    r259940 r273204  
    2828
    2929#include "DataReference.h"
     30#include "StreamConnectionEncoder.h"
    3031#include <wtf/text/CString.h>
    3132#include <wtf/text/WTFString.h>
     
    112113}
    113114
    114 
     115template<typename Encoder>
    115116void ArgumentCoder<String>::encode(Encoder& encoder, const String& string)
    116117{
     
    131132        encoder.encodeFixedLengthData(reinterpret_cast<const uint8_t*>(string.characters16()), length * sizeof(UChar), alignof(UChar));
    132133}
     134template
     135void ArgumentCoder<String>::encode<Encoder>(Encoder&, const String&);
     136template
     137void ArgumentCoder<String>::encode<StreamConnectionEncoder>(StreamConnectionEncoder&, const String&);
    133138
    134139template <typename CharacterType>
  • trunk/Source/WebKit/Platform/IPC/ArgumentCoders.h

    r272058 r273204  
    5656template<typename T, size_t Extent> struct ArgumentCoder<ArrayReference<T, Extent>> {
    5757    using ArrayReferenceType = ArrayReference<T, Extent>;
     58    template<typename Encoder>
    5859    static void encode(Encoder& encoder, const ArrayReferenceType& arrayReference)
    5960    {
     
    7576template<typename T> struct ArgumentCoder<ArrayReference<T, arrayReferenceDynamicExtent>> {
    7677    using ArrayReferenceType = ArrayReference<T, arrayReferenceDynamicExtent>;
     78    template<typename Encoder>
    7779    static void encode(Encoder& encoder, const ArrayReferenceType& arrayReference)
    7880    {
     
    267269template<size_t index, typename... Elements>
    268270struct TupleEncoder {
     271    template<typename Encoder>
    269272    static void encode(Encoder& encoder, const std::tuple<Elements...>& tuple)
    270273    {
     
    276279template<typename... Elements>
    277280struct TupleEncoder<0, Elements...> {
     281    template<typename Encoder>
    278282    static void encode(Encoder&, const std::tuple<Elements...>&)
    279283    {
     
    339343
    340344template<typename... Elements> struct ArgumentCoder<std::tuple<Elements...>> {
     345    template<typename Encoder>
    341346    static void encode(Encoder& encoder, const std::tuple<Elements...>& tuple)
    342347    {
     
    375380
    376381template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> struct VectorArgumentCoder<false, T, inlineCapacity, OverflowHandler, minCapacity> {
     382    template<typename Encoder>
    377383    static void encode(Encoder& encoder, const Vector<T, inlineCapacity, OverflowHandler, minCapacity>& vector)
    378384    {
     
    412418
    413419template<typename T, size_t inlineCapacity, typename OverflowHandler, size_t minCapacity> struct VectorArgumentCoder<true, T, inlineCapacity, OverflowHandler, minCapacity> {
     420    template<typename Encoder>
    414421    static void encode(Encoder& encoder, const Vector<T, inlineCapacity, OverflowHandler, minCapacity>& vector)
    415422    {
     
    754761
    755762template<> struct ArgumentCoder<String> {
     763    template<typename Encoder>
    756764    static void encode(Encoder&, const String&);
    757765    static WARN_UNUSED_RETURN bool decode(Decoder&, String&);
  • trunk/Source/WebKit/Platform/IPC/Connection.cpp

    r273183 r273204  
    2727#include "Connection.h"
    2828
     29#include "ArgumentCoder.h"
    2930#include "Logging.h"
    3031#include "MessageFlags.h"
     
    931932void Connection::dispatchDidReceiveInvalidMessage(MessageName messageName)
    932933{
    933     ASSERT(RunLoop::isMain());
    934 
     934    if (!RunLoop::isMain()) {
     935        RunLoop::main().dispatch([protectedThis = makeRef(*this), messageName]() mutable {
     936            if (!protectedThis->isValid())
     937                return;
     938            protectedThis->m_client.didReceiveInvalidMessage(protectedThis, messageName);
     939        });
     940    }
    935941    if (!isValid())
    936942        return;
  • trunk/Source/WebKit/Platform/IPC/Connection.h

    r272916 r273204  
    3131#include "Decoder.h"
    3232#include "Encoder.h"
    33 #include "HandleMessage.h"
    3433#include "MessageReceiveQueueMap.h"
    3534#include "MessageReceiver.h"
    36 #include <atomic>
     35#include <wtf/CompletionHandler.h>
    3736#include <wtf/Condition.h>
    3837#include <wtf/Deque.h>
     
    313312
    314313    void dispatchMessageReceiverMessage(MessageReceiver&, std::unique_ptr<Decoder>&&);
     314    // Can be called from any thread.
     315    void dispatchDidReceiveInvalidMessage(MessageName);
    315316private:
    316317    Connection(Identifier, bool isServer, Client&);
     
    340341    void dispatchMessage(Decoder&);
    341342    void dispatchSyncMessage(Decoder&);
    342     void dispatchDidReceiveInvalidMessage(MessageName);
    343343    void didFailToSendSyncMessage();
    344344
  • trunk/Source/WebKit/Platform/IPC/Decoder.cpp

    r273196 r273204  
    111111}
    112112
     113Decoder::Decoder(const uint8_t* stream, size_t streamSize, uint64_t destinationID)
     114    : m_buffer { stream }
     115    , m_bufferPos { m_buffer }
     116    , m_bufferEnd { m_buffer + streamSize }
     117    , m_bufferDeallocator([] (const uint8_t*, size_t) { })
     118    , m_destinationID(destinationID)
     119{
     120    if (!decode(m_messageName))
     121        return;
     122}
     123
    113124Decoder::~Decoder()
    114125{
  • trunk/Source/WebKit/Platform/IPC/Decoder.h

    r273196 r273204  
    5151public:
    5252    static std::unique_ptr<Decoder> create(const uint8_t* buffer, size_t bufferSize, void (*bufferDeallocator)(const uint8_t*, size_t), Vector<Attachment>&&);
     53    Decoder(const uint8_t* stream, size_t streamSize, uint64_t destinationID);
     54
    5355    ~Decoder();
    5456
  • trunk/Source/WebKit/Platform/IPC/HandleMessage.h

    r272873 r273204  
    2828#include "ArgumentCoders.h"
    2929#include "DataReference.h"
     30#include "StreamServerConnection.h"
    3031#include <wtf/CompletionHandler.h>
    3132#include <wtf/StdLibExtras.h>
     
    163164    };
    164165    callMemberFunction(connection, WTFMove(*arguments), WTFMove(completionHandler), object, function);
     166}
     167
     168template<typename T, typename C, typename MF>
     169void handleMessageSynchronous(StreamServerConnectionBase& connection, Decoder& decoder, C* object, MF function)
     170{
     171    uint64_t syncRequestID = 0;
     172    if (!decoder.decode(syncRequestID) || !syncRequestID) {
     173        decoder.markInvalid();
     174        return;
     175    }
     176
     177    Optional<typename CodingType<typename T::Arguments>::Type> arguments;
     178    decoder >> arguments;
     179    if (!arguments) {
     180        decoder.markInvalid();
     181        return;
     182    }
     183
     184    typename T::DelayedReply completionHandler = [syncRequestID, connection = makeRef(connection)] (auto&&... args) mutable {
     185        connection->sendSyncReply(syncRequestID, args...);
     186    };
     187    callMemberFunction(WTFMove(*arguments), WTFMove(completionHandler), object, function);
    165188}
    166189
  • trunk/Source/WebKit/Platform/IPC/StreamClientConnection.cpp

    r273203 r273204  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2020 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2424 */
    2525
    26 #pragma once
    27 
    28 #include "Attachment.h"
    29 #include "Decoder.h"
    30 #include "Encoder.h"
     26#include "config.h"
     27#include "StreamClientConnection.h"
    3128
    3229namespace IPC {
    3330
    34 class MachPort {
    35 public:
    36     MachPort()
    37         : m_port(MACH_PORT_NULL)
    38         , m_disposition(0)
    39     {
    40     }
     31StreamClientConnection::StreamClientConnection(Connection& connection, size_t size)
     32    : m_connection(connection)
     33    , m_buffer(size)
     34{
     35    // Read starts from 0 with limit of 0 and reader sleeping.
     36    sharedSenderOffset().store(StreamConnectionBuffer::senderOffsetReceiverIsSleepingTag, std::memory_order_relaxed);
     37    // Write starts from 0 with a limit of the whole buffer.
     38    sharedReceiverOffset().store(0, std::memory_order_relaxed);
     39}
    4140
    42     MachPort(mach_port_name_t port, mach_msg_type_name_t disposition)
    43         : m_port(port)
    44         , m_disposition(disposition)
    45     {
    46     }
     41void StreamClientConnection::setWakeUpSemaphore(IPC::Semaphore&& semaphore)
     42{
     43#if PLATFORM(COCOA)
     44    m_wakeUpSemaphore = WTFMove(semaphore);
     45#endif
     46    wakeUpReceiver();
     47}
    4748
    48     void encode(Encoder& encoder) const
    49     {
    50         encoder << Attachment(m_port, m_disposition);
    51     }
     49void StreamClientConnection::wakeUpReceiver()
     50{
     51#if PLATFORM(COCOA)
     52    if (m_wakeUpSemaphore)
     53        m_wakeUpSemaphore->signal();
     54#endif
     55}
    5256
    53     static WARN_UNUSED_RETURN bool decode(Decoder& decoder, MachPort& p)
    54     {
    55         Attachment attachment;
    56         if (!decoder.decode(attachment))
    57             return false;
    58        
    59         p.m_port = attachment.port();
    60         p.m_disposition = attachment.disposition();
    61         return true;
    62     }
    63 
    64     mach_port_name_t port() const { return m_port; }
    65     mach_msg_type_name_t disposition() const { return m_disposition; }
    66 
    67 private:
    68     mach_port_name_t m_port;
    69     mach_msg_type_name_t m_disposition;
    70 };
    71 
    72 } // namespace IPC
     57}
  • trunk/Source/WebKit/Platform/IPC/StreamConnectionWorkQueue.h

    r273203 r273204  
    11/*
    2  * Copyright (C) 2010 Apple Inc. All rights reserved.
     2 * Copyright (C) 2021 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    2626#pragma once
    2727
    28 #include "Attachment.h"
    29 #include "Decoder.h"
    30 #include "Encoder.h"
     28#include "IPCSemaphore.h"
     29#include "StreamServerConnection.h"
     30#include <atomic>
     31#include <wtf/Deque.h>
     32#include <wtf/FunctionDispatcher.h>
     33#include <wtf/HashSet.h>
     34#include <wtf/Lock.h>
     35#include <wtf/Threading.h>
    3136
    3237namespace IPC {
    3338
    34 class MachPort {
     39class StreamConnectionWorkQueue final : public FunctionDispatcher {
    3540public:
    36     MachPort()
    37         : m_port(MACH_PORT_NULL)
    38         , m_disposition(0)
    39     {
    40     }
     41    StreamConnectionWorkQueue(const char*);
     42    ~StreamConnectionWorkQueue() = default;
     43    void addStreamConnection(StreamServerConnectionBase&);
     44    void removeStreamConnection(StreamServerConnectionBase&);
    4145
    42     MachPort(mach_port_name_t port, mach_msg_type_name_t disposition)
    43         : m_port(port)
    44         , m_disposition(disposition)
    45     {
    46     }
     46    void dispatch(WTF::Function<void()>&&) final;
     47    void stop();
    4748
    48     void encode(Encoder& encoder) const
    49     {
    50         encoder << Attachment(m_port, m_disposition);
    51     }
     49    void wakeUp();
    5250
    53     static WARN_UNUSED_RETURN bool decode(Decoder& decoder, MachPort& p)
    54     {
    55         Attachment attachment;
    56         if (!decoder.decode(attachment))
    57             return false;
    58        
    59         p.m_port = attachment.port();
    60         p.m_disposition = attachment.disposition();
    61         return true;
    62     }
     51    Semaphore& wakeUpSemaphore();
     52private:
     53    void wakeUpProcessingThread();
     54    void processStreams();
    6355
    64     mach_port_name_t port() const { return m_port; }
    65     mach_msg_type_name_t disposition() const { return m_disposition; }
     56    const char* const m_name;
     57    Semaphore m_wakeUpSemaphore;
     58    RefPtr<Thread> m_processingThread;
    6659
    67 private:
    68     mach_port_name_t m_port;
    69     mach_msg_type_name_t m_disposition;
     60    std::atomic<bool> m_shouldQuit { false };
     61
     62    Lock m_lock;
     63    Deque<Function<void()>> m_functions;
     64    HashSet<Ref<StreamServerConnectionBase>> m_connections;
    7065};
    7166
    72 } // namespace IPC
     67}
  • trunk/Source/WebKit/Platform/IPC/cocoa/MachPort.h

    r259847 r273204  
    2626#pragma once
    2727
     28#include "ArgumentCoder.h"
    2829#include "Attachment.h"
    29 #include "Decoder.h"
    30 #include "Encoder.h"
    3130
    3231namespace IPC {
  • trunk/Source/WebKit/Platform/IPC/win/ConnectionWin.cpp

    r273196 r273204  
    2727#include "Connection.h"
    2828
     29#include "ArgumentCoder.h"
    2930#include "DataReference.h"
    3031#include <wtf/HexNumber.h>
  • trunk/Source/WebKit/Scripts/webkit/messages.py

    r273143 r273204  
    2525import sys
    2626
     27from model import MessageReceiver, Message
    2728from webkit import parser
    28 from webkit.model import BUILTIN_ATTRIBUTE, ASYNC_ATTRIBUTE, SYNCHRONOUS_ATTRIBUTE, MAINTHREADCALLBACK_ATTRIBUTE
     29from webkit.model import BUILTIN_ATTRIBUTE, ASYNC_ATTRIBUTE, SYNCHRONOUS_ATTRIBUTE, MAINTHREADCALLBACK_ATTRIBUTE, STREAM_ATTRIBUTE, WANTS_CONNECTION_ATTRIBUTE
    2930
    3031_license_header = """/*
     
    5455"""
    5556
    56 WANTS_CONNECTION_ATTRIBUTE = 'WantsConnection'
    5757WANTS_DISPATCH_MESSAGE_ATTRIBUTE = 'WantsDispatchMessage'
    5858WANTS_ASYNC_DISPATCH_MESSAGE_ATTRIBUTE = 'WantsAsyncDispatchMessage'
    5959LEGACY_RECEIVER_ATTRIBUTE = 'LegacyReceiver'
    6060NOT_REFCOUNTED_RECEIVER_ATTRIBUTE = 'NotRefCounted'
    61 
    6261
    6362def receiver_enumerator_order_key(receiver_name):
     
    214213        else:
    215214            result.append('    static constexpr auto callbackThread = WTF::CompletionHandlerCallThread::ConstructionThread;\n')
    216         if message.has_attribute(SYNCHRONOUS_ATTRIBUTE) or message.has_attribute(ASYNC_ATTRIBUTE):
     215        if (message.has_attribute(SYNCHRONOUS_ATTRIBUTE) or message.has_attribute(ASYNC_ATTRIBUTE)) and not receiver.has_attribute(STREAM_ATTRIBUTE):
    217216            result.append('    static void send(std::unique_ptr<IPC::Encoder>&&, IPC::Connection&')
    218217            if len(send_parameters):
     
    262261        'IPC::DataReference',
    263262        'IPC::FontReference',
     263        'IPC::Semaphore',
    264264        'MachSendRight',
    265265        'MediaTime',
     
    574574
    575575    wants_connection = message.has_attribute(SYNCHRONOUS_ATTRIBUTE) or message.has_attribute(WANTS_CONNECTION_ATTRIBUTE)
     576    maybe_reply_encoder = ", *replyEncoder"
     577    if receiver.has_attribute(STREAM_ATTRIBUTE):
     578        maybe_reply_encoder = ''
     579    elif message.has_attribute(SYNCHRONOUS_ATTRIBUTE) or message.has_attribute(ASYNC_ATTRIBUTE):
     580        maybe_reply_encoder = ', replyEncoder'
    576581
    577582    result = []
    578583    result.append('    if (decoder.messageName() == Messages::%s::%s::name()) {\n' % (receiver.name, message.name))
    579     result.append('        IPC::%s<Messages::%s::%s>(%sdecoder, %sreplyEncoder, this, &%s);\n' % (dispatch_function, receiver.name, message.name, 'connection, ' if wants_connection else '', '' if message.has_attribute(SYNCHRONOUS_ATTRIBUTE) or message.has_attribute(ASYNC_ATTRIBUTE) else '*', handler_function(receiver, message)))
     584    result.append('        IPC::%s<Messages::%s::%s>(%sdecoder%s, this, &%s);\n' % (dispatch_function, receiver.name, message.name, 'connection, ' if wants_connection else '', maybe_reply_encoder, handler_function(receiver, message)))
    580585    result.append('        return;\n')
    581586    result.append('    }\n')
     
    876881            delayed_or_async_messages.append(message)
    877882
    878     if delayed_or_async_messages:
     883    if delayed_or_async_messages and not receiver.has_attribute(STREAM_ATTRIBUTE):
    879884        result.append('namespace Messages {\n\nnamespace %s {\n\n' % receiver.name)
    880885
     
    924929            async_messages.append(message)
    925930
    926     if async_messages or receiver.has_attribute(WANTS_DISPATCH_MESSAGE_ATTRIBUTE) or receiver.has_attribute(WANTS_ASYNC_DISPATCH_MESSAGE_ATTRIBUTE):
    927         result.append('void %s::didReceive%sMessage(IPC::Connection& connection, IPC::Decoder& decoder)\n' % (receiver.name, receiver.name if receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE) else ''))
     931    if receiver.has_attribute(STREAM_ATTRIBUTE):
     932        result.append('void %s::didReceiveStreamMessage(IPC::StreamServerConnectionBase& connection, IPC::Decoder& decoder)\n' % (receiver.name))
    928933        result.append('{\n')
    929         if not receiver.has_attribute(NOT_REFCOUNTED_RECEIVER_ATTRIBUTE):
     934        assert(receiver.has_attribute(NOT_REFCOUNTED_RECEIVER_ATTRIBUTE))
     935        assert(not receiver.has_attribute(WANTS_DISPATCH_MESSAGE_ATTRIBUTE))
     936        assert(not receiver.has_attribute(WANTS_ASYNC_DISPATCH_MESSAGE_ATTRIBUTE))
     937
     938        result += [async_message_statement(receiver, message) for message in async_messages]
     939        result += [sync_message_statement(receiver, message) for message in sync_messages]
     940
     941        if (receiver.superclass):
     942            result.append('    %s::didReceiveStreamMessage(connection, decoder);\n' % (receiver.superclass))
     943        else:
     944            result.append('    UNUSED_PARAM(decoder);\n')
     945            result.append('    UNUSED_PARAM(connection);\n')
     946            result.append('    ASSERT_NOT_REACHED();\n')
     947        result.append('}\n')
     948    elif async_messages or receiver.has_attribute(WANTS_DISPATCH_MESSAGE_ATTRIBUTE) or receiver.has_attribute(WANTS_ASYNC_DISPATCH_MESSAGE_ATTRIBUTE):
     949        receive_variant = receiver.name if receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE) else ''
     950        result.append('void %s::didReceive%sMessage(IPC::Connection& connection, IPC::Decoder& decoder)\n' % (receiver.name, receive_variant))
     951        result.append('{\n')
     952        if not (receiver.has_attribute(NOT_REFCOUNTED_RECEIVER_ATTRIBUTE) or receiver.has_attribute(STREAM_ATTRIBUTE)):
    930953            result.append('    auto protectedThis = makeRef(*this);\n')
    931954
    932955        result += [async_message_statement(receiver, message) for message in async_messages]
     956
    933957        if receiver.has_attribute(WANTS_DISPATCH_MESSAGE_ATTRIBUTE) or receiver.has_attribute(WANTS_ASYNC_DISPATCH_MESSAGE_ATTRIBUTE):
    934958            result.append('    if (dispatchMessage(connection, decoder))\n')
    935959            result.append('        return;\n')
    936960        if (receiver.superclass):
    937             result.append('    %s::didReceiveMessage(connection, decoder);\n' % (receiver.superclass))
     961            result.append('    %s::didReceive%sMessage(connection, decoder);\n' % (receiver.superclass, receive_variant))
    938962        else:
    939963            result.append('    UNUSED_PARAM(connection);\n')
     
    942966        result.append('}\n')
    943967
    944     if sync_messages or receiver.has_attribute(WANTS_DISPATCH_MESSAGE_ATTRIBUTE):
     968    if not receiver.has_attribute(STREAM_ATTRIBUTE) and (sync_messages or receiver.has_attribute(WANTS_DISPATCH_MESSAGE_ATTRIBUTE)):
    945969        result.append('\n')
    946970        result.append('void %s::didReceiveSync%sMessage(IPC::Connection& connection, IPC::Decoder& decoder, std::unique_ptr<IPC::Encoder>& replyEncoder)\n' % (receiver.name, receiver.name if receiver.has_attribute(LEGACY_RECEIVER_ATTRIBUTE) else ''))
  • trunk/Source/WebKit/Scripts/webkit/messages_unittest.py

    r272786 r273204  
    4747    'TestWithSemaphore',
    4848    'TestWithImageData',
     49    'TestWithStream',
     50    'TestWithStreamBuffer'
    4951]
    5052
  • trunk/Source/WebKit/Scripts/webkit/model.py

    r272873 r273204  
    2929MAINTHREADCALLBACK_ATTRIBUTE = "MainThreadCallback"
    3030SYNCHRONOUS_ATTRIBUTE = 'Synchronous'
     31STREAM_ATTRIBUTE = "Stream"
     32WANTS_CONNECTION_ATTRIBUTE = 'WantsConnection'
    3133
    3234class MessageReceiver(object):
     
    7476    Message('SyncMessageReply', [], [], attributes=[BUILTIN_ATTRIBUTE], condition=None),
    7577    Message('InitializeConnection', [], [], attributes=[BUILTIN_ATTRIBUTE], condition="PLATFORM(COCOA)"),
    76     Message('LegacySessionState', [], [], attributes=[BUILTIN_ATTRIBUTE], condition=None)
     78    Message('LegacySessionState', [], [], attributes=[BUILTIN_ATTRIBUTE], condition=None),
     79    Message('SetStreamDestinationID', [], [], attributes=[BUILTIN_ATTRIBUTE], condition=None),
     80    Message('ProcessOutOfStreamMessage', [], [], attributes=[BUILTIN_ATTRIBUTE], condition=None)
    7781], condition=None)
    7882
  • trunk/Source/WebKit/Scripts/webkit/tests/Makefile

    r272786 r273204  
    77    TestWithSemaphore \
    88    TestWithImageData \
     9        TestWithStream \
     10        TestWithStreamBuffer \
    911#
    1012
  • trunk/Source/WebKit/Scripts/webkit/tests/MessageNames.cpp

    r272786 r273204  
    135135    case MessageName::LegacySessionState:
    136136        return "LegacySessionState";
     137    case MessageName::ProcessOutOfStreamMessage:
     138        return "ProcessOutOfStreamMessage";
     139    case MessageName::SetStreamDestinationID:
     140        return "SetStreamDestinationID";
    137141    case MessageName::SyncMessageReply:
    138142        return "SyncMessageReply";
     
    225229    case MessageName::InitializeConnection:
    226230    case MessageName::LegacySessionState:
     231    case MessageName::ProcessOutOfStreamMessage:
     232    case MessageName::SetStreamDestinationID:
    227233    case MessageName::SyncMessageReply:
    228234        return ReceiverName::IPC;
     
    402408    if (messageName == IPC::MessageName::LegacySessionState)
    403409        return true;
     410    if (messageName == IPC::MessageName::ProcessOutOfStreamMessage)
     411        return true;
     412    if (messageName == IPC::MessageName::SetStreamDestinationID)
     413        return true;
    404414    if (messageName == IPC::MessageName::SyncMessageReply)
    405415        return true;
  • trunk/Source/WebKit/Scripts/webkit/tests/MessageNames.h

    r272786 r273204  
    9494    , InitializeConnection
    9595    , LegacySessionState
     96    , ProcessOutOfStreamMessage
     97    , SetStreamDestinationID
    9698    , SyncMessageReply
    9799    , TestWithSuperclass_TestAsyncMessageReply
  • trunk/Source/WebKit/Scripts/webkit/tests/TestWithStream.messages.in

    r273203 r273204  
    2121# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2222
    23 #if ENABLE(GPU_PROCESS) && ENABLE(WEBGL)
    24 
    25 messages -> RemoteGraphicsContextGLProxy NotRefCounted {
    26     void WasCreated(bool didSucceed, String availableExtensions, String requestableExtensions)
    27     void WasLost()
    28     void WasChanged()
     23# Tests Stream receiver attribute.
     24messages -> TestWithStream NotRefCounted Stream {
     25    void SendString(String url)
     26    void SendStringSynchronized(String url) -> (int64_t return)
    2927}
    30 
    31 #endif
  • trunk/Source/WebKit/Scripts/webkit/tests/TestWithStreamBuffer.messages.in

    r273203 r273204  
    2121# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2222
    23 #if ENABLE(GPU_PROCESS) && ENABLE(WEBGL)
    24 
    25 messages -> RemoteGraphicsContextGLProxy NotRefCounted {
    26     void WasCreated(bool didSucceed, String availableExtensions, String requestableExtensions)
    27     void WasLost()
    28     void WasChanged()
     23# Tests Stream receiver attribute.
     24messages -> TestWithStreamBuffer  {
     25    void SendStreamBuffer(IPC::StreamConnectionBuffer stream)
    2926}
    30 
    31 #endif
  • trunk/Source/WebKit/Sources.txt

    r272916 r273204  
    151151Platform/IPC/SharedBufferCopy.cpp @no-unify
    152152Platform/IPC/SharedBufferDataReference.cpp @no-unify
     153Platform/IPC/StreamClientConnection.cpp @no-unify
     154Platform/IPC/StreamConnectionBuffer.cpp @no-unify
     155Platform/IPC/StreamConnectionWorkQueue.cpp @no-unify
     156Platform/IPC/StreamServerConnection.cpp @no-unify
    153157Platform/IPC/StringReference.cpp @no-unify
    154158
  • trunk/Source/WebKit/UIProcess/Downloads/DownloadProxy.h

    r270638 r273204  
    2828#include "APIObject.h"
    2929#include "Connection.h"
     30#include "DataReference.h"
    3031#include "DownloadID.h"
    3132#include "SandboxExtension.h"
  • trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.cpp

    r273183 r273204  
    3131#include "DrawingAreaProxy.h"
    3232#include "FormDataReference.h"
     33#include "HandleMessage.h"
    3334#include "Logging.h"
    3435#include "PageClient.h"
  • trunk/Source/WebKit/UIProcess/ProvisionalPageProxy.h

    r267885 r273204  
    2626#pragma once
    2727
     28#include "DataReference.h"
    2829#include "MessageReceiver.h"
    2930#include "MessageSender.h"
  • trunk/Source/WebKit/WebKit.xcodeproj/project.pbxproj

    r273184 r273204  
    13361336                7B483F2125CDDA9C00120486 /* MessageReceiveQueueMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B483F1D25CDDA9B00120486 /* MessageReceiveQueueMap.cpp */; };
    13371337                7B483F2225CDDA9C00120486 /* MessageReceiveQueues.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B483F1E25CDDA9B00120486 /* MessageReceiveQueues.h */; };
     1338                7B73123A25CC8525003B2796 /* StreamConnectionBuffer.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B73123125CC8523003B2796 /* StreamConnectionBuffer.h */; };
     1339                7B73123B25CC8525003B2796 /* StreamConnectionWorkQueue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B73123225CC8523003B2796 /* StreamConnectionWorkQueue.cpp */; };
     1340                7B73123C25CC8525003B2796 /* StreamClientConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B73123325CC8523003B2796 /* StreamClientConnection.h */; };
     1341                7B73123D25CC8525003B2796 /* StreamConnectionBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B73123425CC8524003B2796 /* StreamConnectionBuffer.cpp */; };
     1342                7B73123E25CC8525003B2796 /* StreamConnectionWorkQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B73123525CC8524003B2796 /* StreamConnectionWorkQueue.h */; };
     1343                7B73123F25CC8525003B2796 /* StreamClientConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B73123625CC8524003B2796 /* StreamClientConnection.cpp */; };
     1344                7B73124025CC8525003B2796 /* StreamServerConnection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7B73123725CC8524003B2796 /* StreamServerConnection.cpp */; };
     1345                7B73124125CC8525003B2796 /* StreamServerConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B73123825CC8524003B2796 /* StreamServerConnection.h */; };
     1346                7B73124225CC8525003B2796 /* StreamConnectionEncoder.h in Headers */ = {isa = PBXBuildFile; fileRef = 7B73123925CC8525003B2796 /* StreamConnectionEncoder.h */; };
     1347                7BAB111025DD02B3008FC479 /* ScopedActiveMessageReceiveQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = 7BAB110F25DD02B2008FC479 /* ScopedActiveMessageReceiveQueue.h */; };
    13381348                7C065F2C1C8CD95F00C2D950 /* WebUserContentControllerDataTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C065F2A1C8CD95F00C2D950 /* WebUserContentControllerDataTypes.h */; };
    13391349                7C135AA9173B0BCA00586AE2 /* WKPluginInformation.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C135AA7173B0BCA00586AE2 /* WKPluginInformation.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    45464556                7B483F1E25CDDA9B00120486 /* MessageReceiveQueues.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MessageReceiveQueues.h; sourceTree = "<group>"; };
    45474557                7B64C0B6254C5C250006B4AF /* GraphicsContextGLIdentifier.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GraphicsContextGLIdentifier.h; sourceTree = "<group>"; };
     4558                7B73123125CC8523003B2796 /* StreamConnectionBuffer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamConnectionBuffer.h; sourceTree = "<group>"; };
     4559                7B73123225CC8523003B2796 /* StreamConnectionWorkQueue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StreamConnectionWorkQueue.cpp; sourceTree = "<group>"; };
     4560                7B73123325CC8523003B2796 /* StreamClientConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamClientConnection.h; sourceTree = "<group>"; };
     4561                7B73123425CC8524003B2796 /* StreamConnectionBuffer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StreamConnectionBuffer.cpp; sourceTree = "<group>"; };
     4562                7B73123525CC8524003B2796 /* StreamConnectionWorkQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamConnectionWorkQueue.h; sourceTree = "<group>"; };
     4563                7B73123625CC8524003B2796 /* StreamClientConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StreamClientConnection.cpp; sourceTree = "<group>"; };
     4564                7B73123725CC8524003B2796 /* StreamServerConnection.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StreamServerConnection.cpp; sourceTree = "<group>"; };
     4565                7B73123825CC8524003B2796 /* StreamServerConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamServerConnection.h; sourceTree = "<group>"; };
     4566                7B73123925CC8525003B2796 /* StreamConnectionEncoder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StreamConnectionEncoder.h; sourceTree = "<group>"; };
    45484567                7B904165254AFDEA006EEB8C /* RemoteGraphicsContextGLProxy.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteGraphicsContextGLProxy.cpp; sourceTree = "<group>"; };
    45494568                7B904166254AFDEB006EEB8C /* RemoteGraphicsContextGLProxy.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteGraphicsContextGLProxy.h; sourceTree = "<group>"; };
     
    45534572                7B90416A254AFEA7006EEB8C /* RemoteGraphicsContextGL.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteGraphicsContextGL.h; sourceTree = "<group>"; };
    45544573                7B90416D2550108C006EEB8C /* RemoteGraphicsContextGLFunctionsGenerated.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RemoteGraphicsContextGLFunctionsGenerated.h; sourceTree = "<group>"; };
     4574                7BAB110F25DD02B2008FC479 /* ScopedActiveMessageReceiveQueue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ScopedActiveMessageReceiveQueue.h; sourceTree = "<group>"; };
    45554575                7BE726572574F67200E85D98 /* RemoteGraphicsContextGLProxyFunctionsGenerated.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteGraphicsContextGLProxyFunctionsGenerated.cpp; sourceTree = "<group>"; };
    45564576                7BE72668257680EF00E85D98 /* RemoteGraphicsContextGLCocoa.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = RemoteGraphicsContextGLCocoa.cpp; sourceTree = "<group>"; };
     
    69887008                                1AAB0377185A7C6A00EDF501 /* MessageSender.cpp */,
    69897009                                1AAB0378185A7C6A00EDF501 /* MessageSender.h */,
     7010                                7BAB110F25DD02B2008FC479 /* ScopedActiveMessageReceiveQueue.h */,
    69907011                                2DC18001D90DDD15FC6991A9 /* SharedBufferCopy.cpp */,
    69917012                                5CC5DB9121488E16006CB8A8 /* SharedBufferCopy.h */,
    69927013                                2DC1855EDBFB850BA0B6D06D /* SharedBufferDataReference.cpp */,
    69937014                                2DC1881ACBCAB5D57C5C6EF0 /* SharedBufferDataReference.h */,
     7015                                7B73123625CC8524003B2796 /* StreamClientConnection.cpp */,
     7016                                7B73123325CC8523003B2796 /* StreamClientConnection.h */,
     7017                                7B73123425CC8524003B2796 /* StreamConnectionBuffer.cpp */,
     7018                                7B73123125CC8523003B2796 /* StreamConnectionBuffer.h */,
     7019                                7B73123925CC8525003B2796 /* StreamConnectionEncoder.h */,
     7020                                7B73123225CC8523003B2796 /* StreamConnectionWorkQueue.cpp */,
     7021                                7B73123525CC8524003B2796 /* StreamConnectionWorkQueue.h */,
     7022                                7B73123725CC8524003B2796 /* StreamServerConnection.cpp */,
     7023                                7B73123825CC8524003B2796 /* StreamServerConnection.h */,
    69947024                                1AE00D6918327C1200087DD7 /* StringReference.cpp */,
    69957025                                1AE00D6A18327C1200087DD7 /* StringReference.h */,
     
    1201612046                                1AAB4A8D1296F0A20023952F /* SandboxExtension.h in Headers */,
    1201712047                                E1E552C516AE065F004ED653 /* SandboxInitializationParameters.h in Headers */,
     12048                                7BAB111025DD02B3008FC479 /* ScopedActiveMessageReceiveQueue.h in Headers */,
    1201812049                                E4D54D0421F1D72D007E3C36 /* ScrollingTreeFrameScrollingNodeRemoteIOS.h in Headers */,
    1201912050                                0F931C1C18C5711900DBA7C3 /* ScrollingTreeOverflowScrollingNodeIOS.h in Headers */,
     
    1206512096                                9368EEDF2303A9ED00BDB11A /* StorageManagerSetMessages.h in Headers */,
    1206612097                                465F4E06230B2E95003CEDB7 /* StorageNamespaceIdentifier.h in Headers */,
     12098                                7B73123C25CC8525003B2796 /* StreamClientConnection.h in Headers */,
     12099                                7B73123A25CC8525003B2796 /* StreamConnectionBuffer.h in Headers */,
     12100                                7B73124225CC8525003B2796 /* StreamConnectionEncoder.h in Headers */,
     12101                                7B73123E25CC8525003B2796 /* StreamConnectionWorkQueue.h in Headers */,
     12102                                7B73124125CC8525003B2796 /* StreamServerConnection.h in Headers */,
    1206712103                                1AE00D6C18327C1200087DD7 /* StringReference.h in Headers */,
    1206812104                                296BD85D15019BC30071F424 /* StringUtilities.h in Headers */,
     
    1389113927                                1A334DED16DE8F88006A8E38 /* StorageAreaMapMessageReceiver.cpp in Sources */,
    1389213928                                9368EEDE2303A90200BDB11A /* StorageManagerSetMessageReceiver.cpp in Sources */,
     13929                                7B73123F25CC8525003B2796 /* StreamClientConnection.cpp in Sources */,
     13930                                7B73123D25CC8525003B2796 /* StreamConnectionBuffer.cpp in Sources */,
     13931                                7B73123B25CC8525003B2796 /* StreamConnectionWorkQueue.cpp in Sources */,
     13932                                7B73124025CC8525003B2796 /* StreamServerConnection.cpp in Sources */,
    1389313933                                2D92A783212B6A7100F493FD /* StringReference.cpp in Sources */,
    1389413934                                2D11B7512126A282006F8878 /* UnifiedSource1-mm.mm in Sources */,
  • trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.cpp

    r273080 r273204  
    5050}
    5151
     52static constexpr size_t defaultStreamSize = 1 << 21;
     53
    5254RemoteGraphicsContextGLProxy::RemoteGraphicsContextGLProxy(GPUProcessConnection& gpuProcessConnection, const GraphicsContextGLAttributes& attributes, RenderingBackendIdentifier renderingBackend)
    5355    : RemoteGraphicsContextGLProxyBase(attributes)
    5456    , m_gpuProcessConnection(&gpuProcessConnection)
     57    , m_streamConnection(gpuProcessConnection.connection(), defaultStreamSize)
    5558{
    5659    m_gpuProcessConnection->addClient(*this);
    5760    m_gpuProcessConnection->messageReceiverMap().addMessageReceiver(Messages::RemoteGraphicsContextGLProxy::messageReceiverName(), m_graphicsContextGLIdentifier.toUInt64(), *this);
    58     connection().send(Messages::GPUConnectionToWebProcess::CreateGraphicsContextGL(attributes, m_graphicsContextGLIdentifier, renderingBackend), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
     61    connection().send(Messages::GPUConnectionToWebProcess::CreateGraphicsContextGL(attributes, m_graphicsContextGLIdentifier, renderingBackend, m_streamConnection.streamBuffer()), 0, IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
    5962}
    6063
     
    185188}
    186189
    187 void RemoteGraphicsContextGLProxy::wasCreated(bool didSucceed, String&& availableExtensions, String&& requestedExtensions)
     190void RemoteGraphicsContextGLProxy::wasCreated(bool didSucceed, IPC::Semaphore&& semaphore, String&& availableExtensions, String&& requestedExtensions)
    188191{
    189192    if (isContextLost())
     
    194197    }
    195198    ASSERT(!m_didInitialize);
     199    m_streamConnection.setWakeUpSemaphore(WTFMove(semaphore));
    196200    m_didInitialize = true;
    197201    initialize(availableExtensions, requestedExtensions);
  • trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.h

    r273080 r273204  
    3030#include "GPUProcessConnection.h"
    3131#include "GraphicsContextGLIdentifier.h"
     32#include "IPCSemaphore.h"
    3233#include "MessageReceiver.h"
    33 #include "MessageSender.h"
    3434#include "RemoteGraphicsContextGLMessages.h"
    3535#include "RemoteResourceCacheProxy.h"
    3636#include "RenderingBackendIdentifier.h"
     37#include "StreamClientConnection.h"
    3738#include "WebCoreArgumentCoders.h"
    3839#include <WebCore/NotImplemented.h>
     
    336337    WARN_UNUSED_RETURN bool send(T&& message)
    337338    {
    338         connection().send(WTFMove(message), m_graphicsContextGLIdentifier.toUInt64(), IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
    339         return true;
     339        return m_streamConnection.send(WTFMove(message), m_graphicsContextGLIdentifier, defaultSendTimeout);
    340340    }
    341341    template<typename T>
    342342    WARN_UNUSED_RETURN IPC::Connection::SendSyncResult sendSync(T&& message, typename T::Reply&& reply)
    343343    {
    344         return connection().sendSync(WTFMove(message), WTFMove(reply), m_graphicsContextGLIdentifier.toUInt64(), defaultSendTimeout);
     344        return m_streamConnection.sendSync(WTFMove(message), WTFMove(reply), m_graphicsContextGLIdentifier, defaultSendTimeout);
    345345    }
    346346    IPC::Connection& connection() const { return m_gpuProcessConnection->connection(); }
     
    348348private:
    349349    // Messages to be received.
    350     void wasCreated(bool didSucceed, String&& availableExtensions, String&& requestedExtensions);
     350    void wasCreated(bool didSucceed, IPC::Semaphore&&, String&& availableExtensions, String&& requestedExtensions);
    351351    void wasLost();
    352352    void wasChanged();
     
    362362    bool m_didInitialize { false };
    363363    GCGLenum m_errorWhenContextIsLost = NO_ERROR;
    364 
    365364    GraphicsContextGLIdentifier m_graphicsContextGLIdentifier { GraphicsContextGLIdentifier::generate() };
     365    IPC::StreamClientConnection m_streamConnection;
    366366};
    367367
  • trunk/Source/WebKit/WebProcess/GPU/graphics/RemoteGraphicsContextGLProxy.messages.in

    r272645 r273204  
    2424
    2525messages -> RemoteGraphicsContextGLProxy NotRefCounted {
    26     void WasCreated(bool didSucceed, String availableExtensions, String requestableExtensions)
     26    void WasCreated(bool didSucceed, IPC::Semaphore streamWakeUpSemaphore, String availableExtensions, String requestableExtensions)
    2727    void WasLost()
    2828    void WasChanged()
  • trunk/Source/WebKit/WebProcess/Inspector/WebInspectorUIExtensionController.h

    r272684 r273204  
    2929
    3030#include "Connection.h"
     31#include "DataReference.h"
    3132#include "InspectorExtensionTypes.h"
    3233#include "MessageReceiver.h"
  • trunk/Source/WebKit/WebProcess/Network/webrtc/LibWebRTCNetwork.h

    r273074 r273204  
    2727
    2828#include "Connection.h"
     29#include "DataReference.h"
    2930#include "LibWebRTCProvider.h"
    3031#include "LibWebRTCSocketFactory.h"
  • trunk/Tools/ChangeLog

    r273202 r273204  
     12021-02-20  Kimmo Kinnunen  <kkinnunen@apple.com>
     2
     3        WebGL GPU process IPC should use shared memory for asynchronous messages
     4        https://bugs.webkit.org/show_bug.cgi?id=219641
     5        <rdar://problem/72340651>
     6
     7        Reviewed by Geoff Garen.
     8
     9        Mark RemoteGraphicsContextGL message receiver as "Stream",
     10        a new variant of receiver.
     11
     12        * Scripts/generate-gpup-webgl:
     13
    1142021-02-20  Wenson Hsieh  <wenson_hsieh@apple.com>
    215
  • trunk/Tools/Scripts/generate-gpup-webgl

    r273080 r273204  
    9090    + """#if ENABLE(GPU_PROCESS) && ENABLE(WEBGL)
    9191
    92 messages -> RemoteGraphicsContextGL NotRefCounted {{
     92messages -> RemoteGraphicsContextGL NotRefCounted Stream {{
    9393    void Reshape(int32_t width, int32_t height)
    9494#if PLATFORM(COCOA)
Note: See TracChangeset for help on using the changeset viewer.