1/*
2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#ifndef TiledCoreAnimationDrawingArea_h
27#define TiledCoreAnimationDrawingArea_h
28
29#if ENABLE(THREADED_SCROLLING)
30
31#include "DrawingArea.h"
32#include "LayerTreeContext.h"
33#include <WebCore/FloatRect.h>
34#include <WebCore/GraphicsLayerClient.h>
35#include <WebCore/LayerFlushScheduler.h>
36#include <WebCore/LayerFlushSchedulerClient.h>
37#include <WebCore/Timer.h>
38#include <wtf/HashMap.h>
39#include <wtf/RetainPtr.h>
40
41OBJC_CLASS CALayer;
42OBJC_CLASS WKContentLayer;
43
44namespace WebCore {
45class TiledBacking;
46}
47
48namespace WebKit {
49
50class LayerHostingContext;
51
52class TiledCoreAnimationDrawingArea : public DrawingArea, WebCore::GraphicsLayerClient, WebCore::LayerFlushSchedulerClient {
53public:
54    static PassOwnPtr<TiledCoreAnimationDrawingArea> create(WebPage*, const WebPageCreationParameters&);
55    virtual ~TiledCoreAnimationDrawingArea();
56
57private:
58    TiledCoreAnimationDrawingArea(WebPage*, const WebPageCreationParameters&);
59
60    // DrawingArea
61    virtual void setNeedsDisplay() OVERRIDE;
62    virtual void setNeedsDisplayInRect(const WebCore::IntRect&) OVERRIDE;
63    virtual void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta) OVERRIDE;
64
65    virtual void forceRepaint() OVERRIDE;
66    virtual bool forceRepaintAsync(uint64_t callbackID) OVERRIDE;
67    virtual void setLayerTreeStateIsFrozen(bool) OVERRIDE;
68    virtual bool layerTreeStateIsFrozen() const OVERRIDE;
69    virtual void setRootCompositingLayer(WebCore::GraphicsLayer*) OVERRIDE;
70    virtual void scheduleCompositingLayerFlush() OVERRIDE;
71
72    virtual void didInstallPageOverlay(PageOverlay*) OVERRIDE;
73    virtual void didUninstallPageOverlay(PageOverlay*) OVERRIDE;
74    virtual void setPageOverlayNeedsDisplay(PageOverlay*, const WebCore::IntRect&) OVERRIDE;
75    virtual void updatePreferences(const WebPreferencesStore&) OVERRIDE;
76    virtual void mainFrameContentSizeChanged(const WebCore::IntSize&) OVERRIDE;
77
78    virtual void setExposedRect(const WebCore::FloatRect&) OVERRIDE;
79    virtual void setClipsToExposedRect(bool) OVERRIDE;
80
81    virtual void didChangeScrollOffsetForAnyFrame() OVERRIDE;
82
83    virtual void dispatchAfterEnsuringUpdatedScrollPosition(const Function<void ()>&) OVERRIDE;
84
85    // WebCore::GraphicsLayerClient
86    virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time) OVERRIDE;
87    virtual void notifyFlushRequired(const WebCore::GraphicsLayer*) OVERRIDE;
88    virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& clipRect) OVERRIDE;
89    virtual float deviceScaleFactor() const OVERRIDE;
90    virtual void didCommitChangesForLayer(const WebCore::GraphicsLayer*) const OVERRIDE;
91
92    // WebCore::LayerFlushSchedulerClient
93    virtual bool flushLayers() OVERRIDE;
94
95    // Message handlers.
96    virtual void suspendPainting() OVERRIDE;
97    virtual void resumePainting() OVERRIDE;
98    virtual void updateGeometry(const WebCore::IntSize& viewSize, const WebCore::IntSize& layerPosition) OVERRIDE;
99    virtual void setDeviceScaleFactor(float) OVERRIDE;
100    virtual void setLayerHostingMode(uint32_t) OVERRIDE;
101    virtual void setColorSpace(const ColorSpaceData&) OVERRIDE;
102
103    void updateLayerHostingContext();
104
105    void setRootCompositingLayer(CALayer *);
106
107    void createPageOverlayLayer(PageOverlay*);
108    void destroyPageOverlayLayer(PageOverlay*);
109    WebCore::TiledBacking* mainFrameTiledBacking() const;
110    void updateDebugInfoLayer(bool showLayer);
111
112    void updateIntrinsicContentSizeTimerFired(WebCore::Timer<TiledCoreAnimationDrawingArea>*);
113    void updateMainFrameClipsToExposedRect();
114    void updateScrolledExposedRect();
115
116    void invalidateAllPageOverlays();
117
118    bool m_layerTreeStateIsFrozen;
119    WebCore::LayerFlushScheduler m_layerFlushScheduler;
120
121    OwnPtr<LayerHostingContext> m_layerHostingContext;
122
123    RetainPtr<CALayer> m_rootLayer;
124    RetainPtr<CALayer> m_pendingRootCompositingLayer;
125
126    RetainPtr<CALayer> m_debugInfoLayer;
127
128    typedef HashMap<PageOverlay*, OwnPtr<WebCore::GraphicsLayer>> PageOverlayLayerMap;
129    PageOverlayLayerMap m_pageOverlayLayers;
130    mutable HashMap<const WebCore::GraphicsLayer*, RetainPtr<CALayer>> m_pageOverlayPlatformLayers;
131
132    bool m_isPaintingSuspended;
133    bool m_hasRootCompositingLayer;
134
135    WebCore::FloatRect m_exposedRect;
136    WebCore::FloatRect m_scrolledExposedRect;
137    bool m_clipsToExposedRect;
138
139    WebCore::IntSize m_lastSentIntrinsicContentSize;
140    WebCore::Timer<TiledCoreAnimationDrawingArea> m_updateIntrinsicContentSizeTimer;
141    bool m_inUpdateGeometry;
142};
143
144} // namespace WebKit
145
146#endif // ENABLE(THREADED_SCROLLING)
147
148#endif // TiledCoreAnimationDrawingArea_h
149