AcceleratedDrawingAreaProxy.cpp [plain text]
#include "config.h"
#include "AcceleratedDrawingAreaProxy.h"
#include "DrawingAreaMessages.h"
#include "DrawingAreaProxyMessages.h"
#include "LayerTreeContext.h"
#include "UpdateInfo.h"
#include "WebPageProxy.h"
#include "WebPreferences.h"
#include "WebProcessProxy.h"
#include <WebCore/Region.h>
#if PLATFORM(WAYLAND)
#include "WaylandCompositor.h"
#include <WebCore/PlatformDisplay.h>
#endif
namespace WebKit {
using namespace WebCore;
AcceleratedDrawingAreaProxy::AcceleratedDrawingAreaProxy(WebPageProxy& webPageProxy)
: DrawingAreaProxy(DrawingAreaTypeImpl, webPageProxy)
{
}
AcceleratedDrawingAreaProxy::~AcceleratedDrawingAreaProxy()
{
if (isInAcceleratedCompositingMode())
exitAcceleratedCompositingMode();
}
bool AcceleratedDrawingAreaProxy::alwaysUseCompositing() const
{
return m_webPageProxy.preferences().acceleratedCompositingEnabled() && m_webPageProxy.preferences().forceCompositingMode();
}
void AcceleratedDrawingAreaProxy::dispatchAfterEnsuringDrawing(WTF::Function<void(CallbackBase::Error)>&& callbackFunction)
{
if (!m_webPageProxy.isValid()) {
callbackFunction(CallbackBase::Error::OwnerWasInvalidated);
return;
}
RunLoop::main().dispatch([callbackFunction = WTFMove(callbackFunction)] {
callbackFunction(CallbackBase::Error::None);
});
}
void AcceleratedDrawingAreaProxy::sizeDidChange()
{
backingStoreStateDidChange(RespondImmediately);
}
void AcceleratedDrawingAreaProxy::deviceScaleFactorDidChange()
{
backingStoreStateDidChange(RespondImmediately);
}
void AcceleratedDrawingAreaProxy::visibilityDidChange()
{
if (m_layerTreeContext.isEmpty())
backingStoreStateDidChange(DoNotRespondImmediately);
}
void AcceleratedDrawingAreaProxy::waitForBackingStoreUpdateOnNextPaint()
{
m_hasReceivedFirstUpdate = true;
}
void AcceleratedDrawingAreaProxy::didUpdateBackingStoreState(uint64_t backingStoreStateID, const UpdateInfo& updateInfo, const LayerTreeContext& layerTreeContext)
{
ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_nextBackingStoreStateID);
ASSERT_ARG(backingStoreStateID, backingStoreStateID > m_currentBackingStoreStateID);
m_currentBackingStoreStateID = backingStoreStateID;
m_isWaitingForDidUpdateBackingStoreState = false;
m_webPageProxy.process().responsivenessTimer().stop();
if (layerTreeContext != m_layerTreeContext) {
if (layerTreeContext.isEmpty() && !m_layerTreeContext.isEmpty()) {
exitAcceleratedCompositingMode();
ASSERT(m_layerTreeContext.isEmpty());
} else if (!layerTreeContext.isEmpty() && m_layerTreeContext.isEmpty()) {
enterAcceleratedCompositingMode(layerTreeContext);
ASSERT(layerTreeContext == m_layerTreeContext);
} else {
updateAcceleratedCompositingMode(layerTreeContext);
ASSERT(layerTreeContext == m_layerTreeContext);
}
}
if (m_nextBackingStoreStateID != m_currentBackingStoreStateID)
sendUpdateBackingStoreState(RespondImmediately);
else {
m_hasReceivedFirstUpdate = true;
#if USE(TEXTURE_MAPPER_GL) && PLATFORM(GTK) && PLATFORM(X11) && !USE(REDIRECTED_XCOMPOSITE_WINDOW)
if (m_pendingNativeSurfaceHandleForCompositing) {
setNativeSurfaceHandleForCompositing(m_pendingNativeSurfaceHandleForCompositing);
m_pendingNativeSurfaceHandleForCompositing = 0;
}
#endif
}
}
void AcceleratedDrawingAreaProxy::enterAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext& layerTreeContext)
{
ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_currentBackingStoreStateID);
if (backingStoreStateID < m_currentBackingStoreStateID)
return;
enterAcceleratedCompositingMode(layerTreeContext);
}
void AcceleratedDrawingAreaProxy::exitAcceleratedCompositingMode(uint64_t backingStoreStateID, const UpdateInfo& updateInfo)
{
ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_currentBackingStoreStateID);
if (backingStoreStateID < m_currentBackingStoreStateID)
return;
exitAcceleratedCompositingMode();
}
void AcceleratedDrawingAreaProxy::updateAcceleratedCompositingMode(uint64_t backingStoreStateID, const LayerTreeContext& layerTreeContext)
{
ASSERT_ARG(backingStoreStateID, backingStoreStateID <= m_currentBackingStoreStateID);
if (backingStoreStateID < m_currentBackingStoreStateID)
return;
updateAcceleratedCompositingMode(layerTreeContext);
}
void AcceleratedDrawingAreaProxy::backingStoreStateDidChange(RespondImmediatelyOrNot respondImmediatelyOrNot)
{
++m_nextBackingStoreStateID;
sendUpdateBackingStoreState(respondImmediatelyOrNot);
}
void AcceleratedDrawingAreaProxy::sendUpdateBackingStoreState(RespondImmediatelyOrNot respondImmediatelyOrNot)
{
ASSERT(m_currentBackingStoreStateID < m_nextBackingStoreStateID);
if (!m_webPageProxy.isValid())
return;
if (m_isWaitingForDidUpdateBackingStoreState)
return;
if (m_webPageProxy.viewSize().isEmpty() && !m_webPageProxy.useFixedLayout())
return;
m_isWaitingForDidUpdateBackingStoreState = respondImmediatelyOrNot == RespondImmediately;
m_webPageProxy.process().send(Messages::DrawingArea::UpdateBackingStoreState(m_nextBackingStoreStateID, respondImmediatelyOrNot == RespondImmediately, m_webPageProxy.deviceScaleFactor(), m_size, m_scrollOffset), m_webPageProxy.pageID());
m_scrollOffset = IntSize();
if (m_isWaitingForDidUpdateBackingStoreState) {
m_webPageProxy.process().responsivenessTimer().start();
}
if (m_isWaitingForDidUpdateBackingStoreState && !m_layerTreeContext.isEmpty()) {
waitForAndDispatchDidUpdateBackingStoreState();
}
}
void AcceleratedDrawingAreaProxy::waitForAndDispatchDidUpdateBackingStoreState()
{
ASSERT(m_isWaitingForDidUpdateBackingStoreState);
if (!m_webPageProxy.isValid())
return;
if (m_webPageProxy.process().state() == WebProcessProxy::State::Launching)
return;
if (!m_webPageProxy.isViewVisible())
return;
#if PLATFORM(WAYLAND) && USE(EGL)
if (PlatformDisplay::sharedDisplay().type() == PlatformDisplay::Type::Wayland && isInAcceleratedCompositingMode())
return;
#endif
m_webPageProxy.process().connection()->waitForAndDispatchImmediately<Messages::DrawingAreaProxy::DidUpdateBackingStoreState>(m_webPageProxy.pageID(), Seconds::fromMilliseconds(500));
}
void AcceleratedDrawingAreaProxy::enterAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
{
ASSERT(alwaysUseCompositing() || !isInAcceleratedCompositingMode());
m_layerTreeContext = layerTreeContext;
m_webPageProxy.enterAcceleratedCompositingMode(layerTreeContext);
}
void AcceleratedDrawingAreaProxy::exitAcceleratedCompositingMode()
{
ASSERT(isInAcceleratedCompositingMode());
m_layerTreeContext = LayerTreeContext();
m_webPageProxy.exitAcceleratedCompositingMode();
}
void AcceleratedDrawingAreaProxy::updateAcceleratedCompositingMode(const LayerTreeContext& layerTreeContext)
{
ASSERT(isInAcceleratedCompositingMode());
m_layerTreeContext = layerTreeContext;
m_webPageProxy.updateAcceleratedCompositingMode(layerTreeContext);
}
#if USE(TEXTURE_MAPPER_GL) && PLATFORM(GTK) && PLATFORM(X11) && !USE(REDIRECTED_XCOMPOSITE_WINDOW)
void AcceleratedDrawingAreaProxy::setNativeSurfaceHandleForCompositing(uint64_t handle)
{
if (!m_hasReceivedFirstUpdate) {
m_pendingNativeSurfaceHandleForCompositing = handle;
return;
}
m_webPageProxy.process().send(Messages::DrawingArea::SetNativeSurfaceHandleForCompositing(handle), m_webPageProxy.pageID(), IPC::SendOption::DispatchMessageEvenWhenWaitingForSyncReply);
}
void AcceleratedDrawingAreaProxy::destroyNativeSurfaceHandleForCompositing()
{
if (m_pendingNativeSurfaceHandleForCompositing) {
m_pendingNativeSurfaceHandleForCompositing = 0;
return;
}
bool handled;
m_webPageProxy.process().sendSync(Messages::DrawingArea::DestroyNativeSurfaceHandleForCompositing(), Messages::DrawingArea::DestroyNativeSurfaceHandleForCompositing::Reply(handled), m_webPageProxy.pageID());
}
#endif
}