Remote Layer Tree: Implement Page Overlays

https://bugs.webkit.org/show_bug.cgi?id=124165
<rdar://problem/15199056>

Reviewed by Anders Carlsson.

Implement page overlays, very similar to how they work in TiledCoreAnimationDrawingArea,
but manipulating the PlatformCALayer tree instead of the CALayer tree directly.

* WebProcess/WebPage/mac/RemoteLayerTreeContext.h:
* WebProcess/WebPage/mac/RemoteLayerTreeContext.mm:
(WebKit::RemoteLayerTreeContext::outOfTreeLayerWasAdded):
(WebKit::RemoteLayerTreeContext::outOfTreeLayerWillBeRemoved):
(WebKit::RemoteLayerTreeContext::flushLayers):
Add a list of out-of-tree GraphicsLayers which are flushed in addition
to the page's GraphicsLayer tree, and functions to manipulate this list.

* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h:
Make RemoteLayerTreeDrawingArea a GraphicsLayerClient, so we can get callbacks
from the GraphicsLayers that drive our page overlays.
Override the relevant page overlay functions.
Add storage for the root layer, view size, and a map of PageOverlay->GraphicsLayer.

* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm:
(WebKit::RemoteLayerTreeDrawingArea::setRootCompositingLayer):
Store the root GraphicsLayer for later use.

(WebKit::RemoteLayerTreeDrawingArea::updateGeometry):
Update the size of the page overlays when the DrawingArea's geometry changes.

(WebKit::RemoteLayerTreeDrawingArea::updatePreferences):
Update the page overlay settings when necessary.

(WebKit::RemoteLayerTreeDrawingArea::didInstallPageOverlay):
Create a GraphicsLayer for our page overlay, set it up, and parent it.
Inform the RemoteLayerTreeContext that it will need to flush this GraphicsLayer,
since it's not a part of the page's GraphicsLayer tree.

(WebKit::RemoteLayerTreeDrawingArea::didUninstallPageOverlay):
Tear down our page overlay's GraphicsLayer.

(WebKit::RemoteLayerTreeDrawingArea::setPageOverlayNeedsDisplay):
(WebKit::RemoteLayerTreeDrawingArea::setPageOverlayOpacity):
(WebKit::RemoteLayerTreeDrawingArea::paintContents):
(WebKit::RemoteLayerTreeDrawingArea::deviceScaleFactor):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@159079 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 016f6b4c
2013-11-11 Tim Horton <timothy_horton@apple.com>
Remote Layer Tree: Implement Page Overlays
https://bugs.webkit.org/show_bug.cgi?id=124165
<rdar://problem/15199056>
Reviewed by Anders Carlsson.
Implement page overlays, very similar to how they work in TiledCoreAnimationDrawingArea,
but manipulating the PlatformCALayer tree instead of the CALayer tree directly.
* WebProcess/WebPage/mac/RemoteLayerTreeContext.h:
* WebProcess/WebPage/mac/RemoteLayerTreeContext.mm:
(WebKit::RemoteLayerTreeContext::outOfTreeLayerWasAdded):
(WebKit::RemoteLayerTreeContext::outOfTreeLayerWillBeRemoved):
(WebKit::RemoteLayerTreeContext::flushLayers):
Add a list of out-of-tree GraphicsLayers which are flushed in addition
to the page's GraphicsLayer tree, and functions to manipulate this list.
* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h:
Make RemoteLayerTreeDrawingArea a GraphicsLayerClient, so we can get callbacks
from the GraphicsLayers that drive our page overlays.
Override the relevant page overlay functions.
Add storage for the root layer, view size, and a map of PageOverlay->GraphicsLayer.
* WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.mm:
(WebKit::RemoteLayerTreeDrawingArea::setRootCompositingLayer):
Store the root GraphicsLayer for later use.
(WebKit::RemoteLayerTreeDrawingArea::updateGeometry):
Update the size of the page overlays when the DrawingArea's geometry changes.
(WebKit::RemoteLayerTreeDrawingArea::updatePreferences):
Update the page overlay settings when necessary.
(WebKit::RemoteLayerTreeDrawingArea::didInstallPageOverlay):
Create a GraphicsLayer for our page overlay, set it up, and parent it.
Inform the RemoteLayerTreeContext that it will need to flush this GraphicsLayer,
since it's not a part of the page's GraphicsLayer tree.
(WebKit::RemoteLayerTreeDrawingArea::didUninstallPageOverlay):
Tear down our page overlay's GraphicsLayer.
(WebKit::RemoteLayerTreeDrawingArea::setPageOverlayNeedsDisplay):
(WebKit::RemoteLayerTreeDrawingArea::setPageOverlayOpacity):
(WebKit::RemoteLayerTreeDrawingArea::paintContents):
(WebKit::RemoteLayerTreeDrawingArea::deviceScaleFactor):
2013-11-11 Anders Carlsson <andersca@apple.com>
Add a FrameLoadState object and begin moving loading related members from WebFrameProxy
......
......@@ -51,6 +51,9 @@ public:
void layerWasCreated(PlatformCALayerRemote*, WebCore::PlatformCALayer::LayerType);
void layerWillBeDestroyed(PlatformCALayerRemote*);
void outOfTreeLayerWasAdded(WebCore::GraphicsLayer*);
void outOfTreeLayerWillBeRemoved(WebCore::GraphicsLayer*);
LayerHostingMode layerHostingMode() const { return m_webPage->layerHostingMode(); }
private:
......@@ -64,6 +67,7 @@ private:
WebCore::Timer<RemoteLayerTreeContext> m_layerFlushTimer;
RefPtr<PlatformCALayerRemote> m_rootLayer;
Vector<WebCore::GraphicsLayer*> m_outOfTreeLayers;
Vector<RemoteLayerTreeTransaction::LayerCreationProperties> m_createdLayers;
Vector<RemoteLayerTreeTransaction::LayerID> m_destroyedLayers;
......
......@@ -78,6 +78,19 @@ void RemoteLayerTreeContext::layerWillBeDestroyed(PlatformCALayerRemote* layer)
m_destroyedLayers.append(layer->layerID());
}
void RemoteLayerTreeContext::outOfTreeLayerWasAdded(GraphicsLayer* layer)
{
ASSERT(!m_outOfTreeLayers.contains(layer));
m_outOfTreeLayers.append(layer);
}
void RemoteLayerTreeContext::outOfTreeLayerWillBeRemoved(GraphicsLayer* layer)
{
size_t layerIndex = m_outOfTreeLayers.find(layer);
ASSERT(layerIndex != notFound);
m_outOfTreeLayers.remove(layerIndex);
}
void RemoteLayerTreeContext::scheduleLayerFlush()
{
if (m_layerFlushTimer.isActive())
......@@ -108,6 +121,9 @@ void RemoteLayerTreeContext::flushLayers()
m_webPage->layoutIfNeeded();
m_webPage->corePage()->mainFrame().view()->flushCompositingStateIncludingSubframes();
for (const auto& layer : m_outOfTreeLayers)
layer->flushCompositingStateForThisLayerOnly();
transaction.setCreatedLayers(std::move(m_createdLayers));
transaction.setDestroyedLayerIDs(std::move(m_destroyedLayers));
m_rootLayer->recursiveBuildTransaction(transaction);
......
......@@ -27,12 +27,19 @@
#define RemoteLayerTreeDrawingArea_h
#include "DrawingArea.h"
#include "GraphicsLayerCARemote.h"
#include <WebCore/GraphicsLayerClient.h>
#include <wtf/HashMap.h>
namespace WebCore {
class PlatformCALayer;
}
namespace WebKit {
class RemoteLayerTreeContext;
class RemoteLayerTreeDrawingArea : public DrawingArea {
class RemoteLayerTreeDrawingArea : public DrawingArea, public WebCore::GraphicsLayerClient {
public:
RemoteLayerTreeDrawingArea(WebPage*, const WebPageCreationParameters&);
virtual ~RemoteLayerTreeDrawingArea();
......@@ -52,7 +59,24 @@ private:
virtual void updatePreferences(const WebPreferencesStore&) OVERRIDE;
virtual void didInstallPageOverlay(PageOverlay*) OVERRIDE;
virtual void didUninstallPageOverlay(PageOverlay*) OVERRIDE;
virtual void setPageOverlayNeedsDisplay(PageOverlay*, const WebCore::IntRect&) OVERRIDE;
virtual void setPageOverlayOpacity(PageOverlay*, float) OVERRIDE;
// WebCore::GraphicsLayerClient
virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time) OVERRIDE { }
virtual void notifyFlushRequired(const WebCore::GraphicsLayer*) OVERRIDE { }
virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect) OVERRIDE;
virtual float deviceScaleFactor() const OVERRIDE;
virtual void didCommitChangesForLayer(const WebCore::GraphicsLayer*) const OVERRIDE { }
std::unique_ptr<RemoteLayerTreeContext> m_remoteLayerTreeContext;
RefPtr<WebCore::PlatformCALayer> m_rootLayer;
HashMap<PageOverlay*, std::unique_ptr<GraphicsLayerCARemote>> m_pageOverlayLayers;
WebCore::IntSize m_viewSize;
};
} // namespace WebKit
......
......@@ -27,6 +27,7 @@
#import "RemoteLayerTreeDrawingArea.h"
#import "DrawingAreaProxyMessages.h"
#import "GraphicsLayerCARemote.h"
#import "RemoteLayerTreeContext.h"
#import "WebPage.h"
#import <WebCore/Frame.h>
......@@ -68,6 +69,8 @@ GraphicsLayerFactory* RemoteLayerTreeDrawingArea::graphicsLayerFactory()
void RemoteLayerTreeDrawingArea::setRootCompositingLayer(GraphicsLayer* rootLayer)
{
m_rootLayer = rootLayer ? static_cast<GraphicsLayerCARemote*>(rootLayer)->platformCALayer() : nullptr;
m_remoteLayerTreeContext->setRootLayer(rootLayer);
}
......@@ -78,7 +81,15 @@ void RemoteLayerTreeDrawingArea::scheduleCompositingLayerFlush()
void RemoteLayerTreeDrawingArea::updateGeometry(const IntSize& viewSize, const IntSize& layerPosition)
{
m_viewSize = viewSize;
m_webPage->setSize(viewSize);
for (const auto& overlayAndLayer : m_pageOverlayLayers) {
GraphicsLayer* layer = overlayAndLayer.value.get();
if (layer->drawsContent())
layer->setSize(viewSize);
}
scheduleCompositingLayerFlush();
m_webPage->send(Messages::DrawingAreaProxy::DidUpdateGeometry());
......@@ -97,6 +108,83 @@ void RemoteLayerTreeDrawingArea::updatePreferences(const WebPreferencesStore&)
// in order to be scrolled by the ScrollingCoordinator.
settings.setAcceleratedCompositingForFixedPositionEnabled(true);
settings.setFixedPositionCreatesStackingContext(true);
for (const auto& overlayAndLayer : m_pageOverlayLayers) {
overlayAndLayer.value->setAcceleratesDrawing(settings.acceleratedDrawingEnabled());
overlayAndLayer.value->setShowDebugBorder(settings.showDebugBorders());
overlayAndLayer.value->setShowRepaintCounter(settings.showRepaintCounter());
}
}
void RemoteLayerTreeDrawingArea::didInstallPageOverlay(PageOverlay* pageOverlay)
{
std::unique_ptr<GraphicsLayerCARemote> layer(static_cast<GraphicsLayerCARemote*>(GraphicsLayer::create(graphicsLayerFactory(), this).release()));
#ifndef NDEBUG
layer->setName("page overlay content");
#endif
layer->setAcceleratesDrawing(m_webPage->corePage()->settings().acceleratedDrawingEnabled());
layer->setShowDebugBorder(m_webPage->corePage()->settings().showDebugBorders());
layer->setShowRepaintCounter(m_webPage->corePage()->settings().showRepaintCounter());
m_rootLayer->appendSublayer(layer->platformCALayer());
m_remoteLayerTreeContext->outOfTreeLayerWasAdded(layer.get());
m_pageOverlayLayers.add(pageOverlay, std::move(layer));
scheduleCompositingLayerFlush();
}
void RemoteLayerTreeDrawingArea::didUninstallPageOverlay(PageOverlay* pageOverlay)
{
std::unique_ptr<GraphicsLayerCARemote> layer = m_pageOverlayLayers.take(pageOverlay);
ASSERT(layer);
m_remoteLayerTreeContext->outOfTreeLayerWillBeRemoved(layer.get());
layer->platformCALayer()->removeFromSuperlayer();
scheduleCompositingLayerFlush();
}
void RemoteLayerTreeDrawingArea::setPageOverlayNeedsDisplay(PageOverlay* pageOverlay, const IntRect& rect)
{
GraphicsLayerCARemote* layer = m_pageOverlayLayers.get(pageOverlay);
if (!layer)
return;
if (!layer->drawsContent()) {
layer->setDrawsContent(true);
layer->setSize(m_viewSize);
}
layer->setNeedsDisplayInRect(rect);
scheduleCompositingLayerFlush();
}
void RemoteLayerTreeDrawingArea::setPageOverlayOpacity(PageOverlay* pageOverlay, float opacity)
{
GraphicsLayerCARemote* layer = m_pageOverlayLayers.get(pageOverlay);
if (!layer)
return;
layer->setOpacity(opacity);
scheduleCompositingLayerFlush();
}
void RemoteLayerTreeDrawingArea::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& graphicsContext, GraphicsLayerPaintingPhase, const IntRect& clipRect)
{
for (const auto& overlayAndLayer : m_pageOverlayLayers) {
if (overlayAndLayer.value.get() == graphicsLayer) {
m_webPage->drawPageOverlay(overlayAndLayer.key, graphicsContext, clipRect);
break;
}
}
}
float RemoteLayerTreeDrawingArea::deviceScaleFactor() const
{
return m_webPage->corePage()->deviceScaleFactor();
}
} // namespace WebKit
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment