RemoteGraphicsContextGLProxy.cpp [plain text]
#include "config.h"
#include "RemoteGraphicsContextGLProxy.h"
#if ENABLE(GPU_PROCESS) && ENABLE(WEBGL)
#include "GPUConnectionToWebProcess.h"
#include "GPUProcessConnection.h"
#include "RemoteGraphicsContextGLMessages.h"
#include "RemoteGraphicsContextGLProxyMessages.h"
#include "WebProcess.h"
#if PLATFORM(COCOA)
#include <WebCore/GraphicsContextCG.h>
#include <WebCore/GraphicsContextGLIOSurfaceSwapChain.h>
#endif
namespace WebKit {
using namespace WebCore;
RefPtr<RemoteGraphicsContextGLProxy> RemoteGraphicsContextGLProxy::create(const GraphicsContextGLAttributes& attributes)
{
return adoptRef(new RemoteGraphicsContextGLProxy(attributes));
}
RemoteGraphicsContextGLProxy::RemoteGraphicsContextGLProxy(const GraphicsContextGLAttributes& attrs)
: RemoteGraphicsContextGLProxyBase(attrs)
{
IPC::MessageReceiverMap& messageReceiverMap = WebProcess::singleton().ensureGPUProcessConnection().messageReceiverMap();
messageReceiverMap.addMessageReceiver(Messages::RemoteGraphicsContextGLProxy::messageReceiverName(), m_graphicsContextGLIdentifier.toUInt64(), *this);
send(Messages::GPUConnectionToWebProcess::CreateGraphicsContextGL(attrs, m_graphicsContextGLIdentifier), 0);
}
RemoteGraphicsContextGLProxy::~RemoteGraphicsContextGLProxy()
{
IPC::MessageReceiverMap& messageReceiverMap = WebProcess::singleton().ensureGPUProcessConnection().messageReceiverMap();
messageReceiverMap.removeMessageReceiver(*this);
send(Messages::GPUConnectionToWebProcess::ReleaseGraphicsContextGL(m_graphicsContextGLIdentifier), 0);
#if PLATFORM(COCOA)
platformSwapChain().recycleBuffer();
#endif
}
IPC::Connection* RemoteGraphicsContextGLProxy::messageSenderConnection() const
{
return &WebProcess::singleton().ensureGPUProcessConnection().connection();
}
uint64_t RemoteGraphicsContextGLProxy::messageSenderDestinationID() const
{
return m_graphicsContextGLIdentifier.toUInt64();
}
void RemoteGraphicsContextGLProxy::reshape(int width, int height)
{
m_currentWidth = width;
m_currentHeight = height;
send(Messages::RemoteGraphicsContextGL::Reshape(width, height), m_graphicsContextGLIdentifier);
}
void RemoteGraphicsContextGLProxy::prepareForDisplay()
{
#if PLATFORM(COCOA)
MachSendRight displayBufferSendRight;
sendSync(Messages::RemoteGraphicsContextGL::PrepareForDisplay(), Messages::RemoteGraphicsContextGL::PrepareForDisplay::Reply(displayBufferSendRight), m_graphicsContextGLIdentifier, 10_s);
auto displayBuffer = IOSurface::createFromSendRight(WTFMove(displayBufferSendRight), sRGBColorSpaceRef());
if (displayBuffer) {
auto& sc = platformSwapChain();
sc.recycleBuffer();
sc.present({ WTFMove(displayBuffer), nullptr });
}
#else
sendSync(Messages::RemoteGraphicsContextGL::PrepareForDisplay(), Messages::RemoteGraphicsContextGL::PrepareForDisplay::Reply(), m_graphicsContextGLIdentifier, 10_s);
#endif
markLayerComposited();
}
void RemoteGraphicsContextGLProxy::ensureExtensionEnabled(const String& extension)
{
send(Messages::RemoteGraphicsContextGL::EnsureExtensionEnabled(extension), m_graphicsContextGLIdentifier);
}
void RemoteGraphicsContextGLProxy::notifyMarkContextChanged()
{
send(Messages::RemoteGraphicsContextGL::NotifyMarkContextChanged(), m_graphicsContextGLIdentifier);
}
void RemoteGraphicsContextGLProxy::simulateContextChanged()
{
notImplemented();
}
void RemoteGraphicsContextGLProxy::paintRenderingResultsToCanvas(ImageBuffer*)
{
notImplemented();
}
void RemoteGraphicsContextGLProxy::paintCompositedResultsToCanvas(ImageBuffer*)
{
notImplemented();
}
RefPtr<ImageData> RemoteGraphicsContextGLProxy::paintRenderingResultsToImageData()
{
notImplemented();
return nullptr;
}
void RemoteGraphicsContextGLProxy::wasCreated(String&& availableExtensions, String&& requestedExtensions)
{
if (m_didInitialize) {
wasLost();
return;
}
initialize(availableExtensions, requestedExtensions);
m_didInitialize = true;
}
void RemoteGraphicsContextGLProxy::wasLost()
{
for (auto* client : copyToVector(m_clients))
client->forceContextLost();
}
void RemoteGraphicsContextGLProxy::wasChanged()
{
for (auto* client : copyToVector(m_clients))
client->dispatchContextChangedNotification();
}
void RemoteGraphicsContextGLProxy::waitUntilInitialized()
{
if (m_didInitialize)
return;
Ref<IPC::Connection> connection = WebProcess::singleton().ensureGPUProcessConnection().connection();
if (connection->waitForAndDispatchImmediately<Messages::RemoteGraphicsContextGLProxy::WasCreated>(m_graphicsContextGLIdentifier, 10_s, IPC::WaitForOption::InterruptWaitingIfSyncMessageArrives))
return;
wasCreated("", "");
}
}
#endif