diff options
Diffstat (limited to 'Source/WebKit2/WebProcess/WebPage/ca')
4 files changed, 559 insertions, 0 deletions
diff --git a/Source/WebKit2/WebProcess/WebPage/ca/LayerTreeHostCA.cpp b/Source/WebKit2/WebProcess/WebPage/ca/LayerTreeHostCA.cpp new file mode 100644 index 0000000..2460607 --- /dev/null +++ b/Source/WebKit2/WebProcess/WebPage/ca/LayerTreeHostCA.cpp @@ -0,0 +1,262 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "LayerTreeHostCA.h" + +#include "DrawingAreaImpl.h" +#include "WebPage.h" +#include "WebProcess.h" +#include <WebCore/Frame.h> +#include <WebCore/FrameView.h> +#include <WebCore/Page.h> +#include <WebCore/Settings.h> + +using namespace WebCore; + +namespace WebKit { + +PassRefPtr<LayerTreeHostCA> LayerTreeHostCA::create(WebPage* webPage) +{ + return adoptRef(new LayerTreeHostCA(webPage)); +} + +LayerTreeHostCA::LayerTreeHostCA(WebPage* webPage) + : LayerTreeHost(webPage) + , m_isValid(true) + , m_notifyAfterScheduledLayerFlush(false) +{ + + // Create a root layer. + m_rootLayer = GraphicsLayer::create(this); +#ifndef NDEBUG + m_rootLayer->setName("LayerTreeHost root layer"); +#endif + m_rootLayer->setDrawsContent(false); + m_rootLayer->setSize(webPage->size()); + + m_nonCompositedContentLayer = GraphicsLayer::create(this); +#ifndef NDEBUG + m_nonCompositedContentLayer->setName("LayerTreeHost non-composited content"); +#endif + m_nonCompositedContentLayer->setDrawsContent(true); + m_nonCompositedContentLayer->setContentsOpaque(m_webPage->drawsBackground() && !m_webPage->drawsTransparentBackground()); + m_nonCompositedContentLayer->setSize(webPage->size()); + if (m_webPage->corePage()->settings()->acceleratedDrawingEnabled()) + m_nonCompositedContentLayer->setAcceleratesDrawing(true); + + m_rootLayer->addChild(m_nonCompositedContentLayer.get()); + + if (m_webPage->hasPageOverlay()) + createPageOverlayLayer(); + + platformInitialize(); + + scheduleLayerFlush(); +} + +LayerTreeHostCA::~LayerTreeHostCA() +{ + ASSERT(!m_isValid); + ASSERT(!m_rootLayer); +#if PLATFORM(MAC) + ASSERT(!m_flushPendingLayerChangesRunLoopObserver); + ASSERT(!m_remoteLayerClient); +#endif +} + +const LayerTreeContext& LayerTreeHostCA::layerTreeContext() +{ + return m_layerTreeContext; +} + +void LayerTreeHostCA::setShouldNotifyAfterNextScheduledLayerFlush(bool notifyAfterScheduledLayerFlush) +{ + m_notifyAfterScheduledLayerFlush = notifyAfterScheduledLayerFlush; +} + +void LayerTreeHostCA::setRootCompositingLayer(GraphicsLayer* graphicsLayer) +{ + m_nonCompositedContentLayer->removeAllChildren(); + + // Add the accelerated layer tree hierarchy. + if (graphicsLayer) + m_nonCompositedContentLayer->addChild(graphicsLayer); +} + +void LayerTreeHostCA::invalidate() +{ + ASSERT(m_isValid); + platformInvalidate(); + m_rootLayer = nullptr; + m_isValid = false; +} + +void LayerTreeHostCA::setNonCompositedContentsNeedDisplay(const IntRect& rect) +{ + m_nonCompositedContentLayer->setNeedsDisplayInRect(rect); + if (m_pageOverlayLayer) + m_pageOverlayLayer->setNeedsDisplayInRect(rect); + + scheduleLayerFlush(); +} + +void LayerTreeHostCA::scrollNonCompositedContents(const IntRect& scrollRect, const IntSize& scrollOffset) +{ + setNonCompositedContentsNeedDisplay(scrollRect); +} + +void LayerTreeHostCA::sizeDidChange(const IntSize& newSize) +{ + m_rootLayer->setSize(newSize); + m_nonCompositedContentLayer->setSize(newSize); + + if (m_pageOverlayLayer) + m_pageOverlayLayer->setSize(newSize); + + scheduleLayerFlush(); + flushPendingLayerChanges(); + + platformSizeDidChange(); +} + +void LayerTreeHostCA::forceRepaint() +{ + scheduleLayerFlush(); + flushPendingLayerChanges(); + + platformForceRepaint(); +} + +void LayerTreeHostCA::didInstallPageOverlay() +{ + createPageOverlayLayer(); + scheduleLayerFlush(); +} + +void LayerTreeHostCA::didUninstallPageOverlay() +{ + destroyPageOverlayLayer(); + scheduleLayerFlush(); +} + +void LayerTreeHostCA::setPageOverlayNeedsDisplay(const IntRect& rect) +{ + ASSERT(m_pageOverlayLayer); + m_pageOverlayLayer->setNeedsDisplayInRect(rect); + scheduleLayerFlush(); +} + +void LayerTreeHostCA::notifyAnimationStarted(const WebCore::GraphicsLayer*, double time) +{ +} + +void LayerTreeHostCA::notifySyncRequired(const WebCore::GraphicsLayer*) +{ +} + +void LayerTreeHostCA::paintContents(const GraphicsLayer* graphicsLayer, GraphicsContext& graphicsContext, GraphicsLayerPaintingPhase, const IntRect& clipRect) +{ + if (graphicsLayer == m_nonCompositedContentLayer) { + m_webPage->drawRect(graphicsContext, clipRect); + return; + } + + if (graphicsLayer == m_pageOverlayLayer) { + m_webPage->drawPageOverlay(graphicsContext, clipRect); + return; + } +} + +bool LayerTreeHostCA::showDebugBorders() const +{ + return m_webPage->corePage()->settings()->showDebugBorders(); +} + +bool LayerTreeHostCA::showRepaintCounter() const +{ + return m_webPage->corePage()->settings()->showRepaintCounter(); +} + +void LayerTreeHostCA::performScheduledLayerFlush() +{ + { + RefPtr<LayerTreeHostCA> protect(this); + m_webPage->layoutIfNeeded(); + + if (!m_isValid) + return; + } + + if (!flushPendingLayerChanges()) + return; + + didPerformScheduledLayerFlush(); +} + +void LayerTreeHostCA::didPerformScheduledLayerFlush() +{ + platformDidPerformScheduledLayerFlush(); + + if (m_notifyAfterScheduledLayerFlush) { + // Let the drawing area know that we've done a flush of the layer changes. + static_cast<DrawingAreaImpl*>(m_webPage->drawingArea())->layerHostDidFlushLayers(); + m_notifyAfterScheduledLayerFlush = false; + } +} + +bool LayerTreeHostCA::flushPendingLayerChanges() +{ + m_rootLayer->syncCompositingStateForThisLayerOnly(); + m_nonCompositedContentLayer->syncCompositingStateForThisLayerOnly(); + if (m_pageOverlayLayer) + m_pageOverlayLayer->syncCompositingStateForThisLayerOnly(); + + return m_webPage->corePage()->mainFrame()->view()->syncCompositingStateIncludingSubframes(); +} + +void LayerTreeHostCA::createPageOverlayLayer() +{ + ASSERT(!m_pageOverlayLayer); + + m_pageOverlayLayer = GraphicsLayer::create(this); +#ifndef NDEBUG + m_pageOverlayLayer->setName("LayerTreeHost page overlay content"); +#endif + + m_pageOverlayLayer->setDrawsContent(true); + m_pageOverlayLayer->setSize(m_webPage->size()); + + m_rootLayer->addChild(m_pageOverlayLayer.get()); +} + +void LayerTreeHostCA::destroyPageOverlayLayer() +{ + ASSERT(m_pageOverlayLayer); + m_pageOverlayLayer->removeFromParent(); + m_pageOverlayLayer = nullptr; +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/WebPage/ca/LayerTreeHostCA.h b/Source/WebKit2/WebProcess/WebPage/ca/LayerTreeHostCA.h new file mode 100644 index 0000000..ba4e33a --- /dev/null +++ b/Source/WebKit2/WebProcess/WebPage/ca/LayerTreeHostCA.h @@ -0,0 +1,119 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef LayerTreeHostCA_h +#define LayerTreeHostCA_h + +#include "LayerTreeContext.h" +#include "LayerTreeHost.h" +#include <WebCore/GraphicsLayerClient.h> +#include <wtf/OwnPtr.h> + +#if PLATFORM(MAC) +#include <wtf/RetainPtr.h> +#endif + +#if PLATFORM(MAC) +typedef struct __WKCARemoteLayerClientRef* WKCARemoteLayerClientRef; +#endif + +namespace WebKit { + +class LayerTreeHostCA : public LayerTreeHost, WebCore::GraphicsLayerClient { +public: + static PassRefPtr<LayerTreeHostCA> create(WebPage*); + ~LayerTreeHostCA(); + +private: + explicit LayerTreeHostCA(WebPage*); + + // LayerTreeHost. + virtual const LayerTreeContext& layerTreeContext(); + virtual void scheduleLayerFlush(); + virtual void setShouldNotifyAfterNextScheduledLayerFlush(bool); + virtual void setRootCompositingLayer(WebCore::GraphicsLayer*); + virtual void invalidate(); + + virtual void setNonCompositedContentsNeedDisplay(const WebCore::IntRect&); + virtual void scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset); + virtual void sizeDidChange(const WebCore::IntSize& newSize); + virtual void forceRepaint(); + + virtual void didInstallPageOverlay(); + virtual void didUninstallPageOverlay(); + virtual void setPageOverlayNeedsDisplay(const WebCore::IntRect&); + + // GraphicsLayerClient + virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time); + virtual void notifySyncRequired(const WebCore::GraphicsLayer*); + virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect); + virtual bool showDebugBorders() const; + virtual bool showRepaintCounter() const; + + void platformInitialize(); + void platformInvalidate(); + void platformSizeDidChange(); + void platformForceRepaint(); + + void performScheduledLayerFlush(); + void didPerformScheduledLayerFlush(); + void platformDidPerformScheduledLayerFlush(); + bool flushPendingLayerChanges(); + + void createPageOverlayLayer(); + void destroyPageOverlayLayer(); + +#if PLATFORM(MAC) + static void flushPendingLayerChangesRunLoopObserverCallback(CFRunLoopObserverRef, CFRunLoopActivity, void*); +#endif + + // The context for this layer tree. + LayerTreeContext m_layerTreeContext; + + // Whether the layer tree host is valid or not. + bool m_isValid; + + // Whether we should let the drawing area know the next time we've flushed + // layer tree changes. + bool m_notifyAfterScheduledLayerFlush; + + // The root layer. + OwnPtr<WebCore::GraphicsLayer> m_rootLayer; + + // The layer which contains all non-composited content. + OwnPtr<WebCore::GraphicsLayer> m_nonCompositedContentLayer; + + // The page overlay layer. Will be null if there's no page overlay. + OwnPtr<WebCore::GraphicsLayer> m_pageOverlayLayer; + +#if PLATFORM(MAC) + RetainPtr<WKCARemoteLayerClientRef> m_remoteLayerClient; + RetainPtr<CFRunLoopObserverRef> m_flushPendingLayerChangesRunLoopObserver; +#endif +}; + +} // namespace WebKit + +#endif // LayerTreeHostCA_h diff --git a/Source/WebKit2/WebProcess/WebPage/ca/mac/LayerTreeHostCAMac.mm b/Source/WebKit2/WebProcess/WebPage/ca/mac/LayerTreeHostCAMac.mm new file mode 100644 index 0000000..50776d7 --- /dev/null +++ b/Source/WebKit2/WebProcess/WebPage/ca/mac/LayerTreeHostCAMac.mm @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#import "config.h" +#import "LayerTreeHostCA.h" + +#import "WebProcess.h" +#import <QuartzCore/CATransaction.h> +#import <WebCore/GraphicsLayer.h> +#import <WebKitSystemInterface.h> + +@interface CATransaction (Details) ++ (void)synchronize; +@end + +namespace WebKit { + +void LayerTreeHostCA::platformInitialize() +{ + mach_port_t serverPort = WebProcess::shared().compositingRenderServerPort(); + m_remoteLayerClient = WKCARemoteLayerClientMakeWithServerPort(serverPort); + + [m_rootLayer->platformLayer() setGeometryFlipped:YES]; + + WKCARemoteLayerClientSetLayer(m_remoteLayerClient.get(), m_rootLayer->platformLayer()); + + m_layerTreeContext.contextID = WKCARemoteLayerClientGetClientId(m_remoteLayerClient.get()); +} + +void LayerTreeHostCA::scheduleLayerFlush() +{ + CFRunLoopRef currentRunLoop = CFRunLoopGetCurrent(); + + // Make sure we wake up the loop or the observer could be delayed until some other source fires. + CFRunLoopWakeUp(currentRunLoop); + + if (m_flushPendingLayerChangesRunLoopObserver) + return; + + // Run before the Core Animation commit observer, which has order 2000000. + const CFIndex runLoopOrder = 2000000 - 1; + CFRunLoopObserverContext context = { 0, this, 0, 0, 0 }; + m_flushPendingLayerChangesRunLoopObserver.adoptCF(CFRunLoopObserverCreate(0, kCFRunLoopBeforeWaiting | kCFRunLoopExit, true, runLoopOrder, flushPendingLayerChangesRunLoopObserverCallback, &context)); + + CFRunLoopAddObserver(currentRunLoop, m_flushPendingLayerChangesRunLoopObserver.get(), kCFRunLoopCommonModes); +} + +void LayerTreeHostCA::platformInvalidate() +{ + if (m_flushPendingLayerChangesRunLoopObserver) { + CFRunLoopObserverInvalidate(m_flushPendingLayerChangesRunLoopObserver.get()); + m_flushPendingLayerChangesRunLoopObserver = nullptr; + } + + WKCARemoteLayerClientInvalidate(m_remoteLayerClient.get()); + m_remoteLayerClient = nullptr; +} + +void LayerTreeHostCA::platformSizeDidChange() +{ + [CATransaction flush]; + [CATransaction synchronize]; +} + +void LayerTreeHostCA::platformForceRepaint() +{ + [CATransaction flush]; + [CATransaction synchronize]; +} + +void LayerTreeHostCA::flushPendingLayerChangesRunLoopObserverCallback(CFRunLoopObserverRef, CFRunLoopActivity, void* context) +{ + // This gets called outside of the normal event loop so wrap in an autorelease pool + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + static_cast<LayerTreeHostCA*>(context)->performScheduledLayerFlush(); + [pool drain]; +} + +void LayerTreeHostCA::platformDidPerformScheduledLayerFlush() +{ + // We successfully flushed the pending layer changes, remove the run loop observer. + ASSERT(m_flushPendingLayerChangesRunLoopObserver); + CFRunLoopObserverInvalidate(m_flushPendingLayerChangesRunLoopObserver.get()); + m_flushPendingLayerChangesRunLoopObserver = 0; +} + +} // namespace WebKit diff --git a/Source/WebKit2/WebProcess/WebPage/ca/win/LayerTreeHostCAWin.cpp b/Source/WebKit2/WebProcess/WebPage/ca/win/LayerTreeHostCAWin.cpp new file mode 100644 index 0000000..81db03e --- /dev/null +++ b/Source/WebKit2/WebProcess/WebPage/ca/win/LayerTreeHostCAWin.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (C) 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "LayerTreeHostCA.h" + +#include <WebCore/NotImplemented.h> + +namespace WebKit { + +void LayerTreeHostCA::platformInitialize() +{ + // FIXME: <http://webkit.org/b/45567> Implement this! + notImplemented(); +} + +void LayerTreeHostCA::scheduleLayerFlush() +{ + // FIXME: <http://webkit.org/b/45567> Implement this! + notImplemented(); +} + +void LayerTreeHostCA::platformInvalidate() +{ + // FIXME: <http://webkit.org/b/45567> Implement this! + notImplemented(); +} + +void LayerTreeHostCA::platformSizeDidChange() +{ + // FIXME: <http://webkit.org/b/45567> Implement this! + notImplemented(); +} + +void LayerTreeHostCA::platformForceRepaint() +{ + // FIXME: <http://webkit.org/b/45567> Implement this! + notImplemented(); +} + +void LayerTreeHostCA::platformDidPerformScheduledLayerFlush() +{ + // FIXME: <http://webkit.org/b/45567> Implement this! + notImplemented(); +} + +} // namespace WebKit |