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 !PLATFORM(IOS)
30
31#include "DrawingArea.h"
32#include "LayerTreeContext.h"
33#include <WebCore/FloatRect.h>
34#include <WebCore/LayerFlushScheduler.h>
35#include <WebCore/LayerFlushSchedulerClient.h>
36#include <WebCore/TransformationMatrix.h>
37#include <wtf/HashMap.h>
38#include <wtf/RetainPtr.h>
39#include <wtf/RunLoop.h>
40
41OBJC_CLASS CALayer;
42
43namespace WebCore {
44class FrameView;
45class PlatformCALayer;
46class TiledBacking;
47}
48
49namespace WebKit {
50
51class LayerHostingContext;
52
53class TiledCoreAnimationDrawingArea : public DrawingArea, WebCore::LayerFlushSchedulerClient {
54public:
55    TiledCoreAnimationDrawingArea(WebPage&, const WebPageCreationParameters&);
56    virtual ~TiledCoreAnimationDrawingArea();
57
58private:
59    // DrawingArea
60    virtual void setNeedsDisplay() override;
61    virtual void setNeedsDisplayInRect(const WebCore::IntRect&) override;
62    virtual void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta) override;
63
64    virtual void forceRepaint() override;
65    virtual bool forceRepaintAsync(uint64_t callbackID) override;
66    virtual void setLayerTreeStateIsFrozen(bool) override;
67    virtual bool layerTreeStateIsFrozen() const override;
68    virtual void setRootCompositingLayer(WebCore::GraphicsLayer*) override;
69    virtual void scheduleCompositingLayerFlush() override;
70    virtual void scheduleCompositingLayerFlushImmediately() override;
71
72    virtual void updatePreferences(const WebPreferencesStore&) override;
73    virtual void mainFrameContentSizeChanged(const WebCore::IntSize&) override;
74
75    virtual void setExposedRect(const WebCore::FloatRect&) override;
76    virtual WebCore::FloatRect exposedRect() const override { return m_scrolledExposedRect; }
77
78    virtual bool supportsAsyncScrolling() override { return true; }
79
80    virtual void dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()>) override;
81
82    virtual bool shouldUseTiledBackingForFrameView(const WebCore::FrameView*) override;
83
84    virtual void viewStateDidChange(WebCore::ViewState::Flags changed, bool wantsDidUpdateViewState) override;
85    void didUpdateViewStateTimerFired();
86
87    // WebCore::LayerFlushSchedulerClient
88    virtual bool flushLayers() override;
89
90    // Message handlers.
91    virtual void updateGeometry(const WebCore::IntSize& viewSize, const WebCore::IntSize& layerPosition) override;
92    virtual void setDeviceScaleFactor(float) override;
93    void suspendPainting();
94    void resumePainting();
95    void setLayerHostingMode(LayerHostingMode) override;
96    virtual void setColorSpace(const ColorSpaceData&) override;
97
98    virtual void adjustTransientZoom(double scale, WebCore::FloatPoint origin) override;
99    virtual void commitTransientZoom(double scale, WebCore::FloatPoint origin) override;
100    void applyTransientZoomToPage(double scale, WebCore::FloatPoint origin);
101    WebCore::PlatformCALayer* layerForTransientZoom() const;
102    WebCore::PlatformCALayer* shadowLayerForTransientZoom() const;
103
104    void applyTransientZoomToLayers(double scale, WebCore::FloatPoint origin);
105
106    void updateLayerHostingContext();
107
108    void setRootCompositingLayer(CALayer *);
109
110    WebCore::TiledBacking* mainFrameTiledBacking() const;
111    void updateDebugInfoLayer(bool showLayer);
112
113    void updateIntrinsicContentSizeIfNeeded();
114    void updateScrolledExposedRect();
115
116    bool m_layerTreeStateIsFrozen;
117    WebCore::LayerFlushScheduler m_layerFlushScheduler;
118
119    std::unique_ptr<LayerHostingContext> m_layerHostingContext;
120
121    RetainPtr<CALayer> m_hostingLayer;
122    RetainPtr<CALayer> m_rootLayer;
123    RetainPtr<CALayer> m_debugInfoLayer;
124
125    RetainPtr<CALayer> m_pendingRootLayer;
126
127    bool m_isPaintingSuspended;
128
129    WebCore::FloatRect m_exposedRect;
130    WebCore::FloatRect m_scrolledExposedRect;
131
132    WebCore::IntSize m_lastSentIntrinsicContentSize;
133    bool m_inUpdateGeometry;
134
135    double m_transientZoomScale;
136    WebCore::FloatPoint m_transientZoomOrigin;
137
138    WebCore::TransformationMatrix m_transform;
139
140    RunLoop::Timer<TiledCoreAnimationDrawingArea> m_sendDidUpdateViewStateTimer;
141};
142
143DRAWING_AREA_TYPE_CASTS(TiledCoreAnimationDrawingArea, type() == DrawingAreaTypeTiledCoreAnimation);
144
145} // namespace WebKit
146
147#endif // !PLATFORM(IOS)
148
149#endif // TiledCoreAnimationDrawingArea_h
150