6b291d406ff6ce718786523d7bcd16819a1bbe2f
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / mac / TiledCoreAnimationDrawingArea.h
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
41 OBJC_CLASS CALayer;
42
43 namespace WebCore {
44 class FrameView;
45 class PlatformCALayer;
46 class TiledBacking;
47 }
48
49 namespace WebKit {
50
51 class LayerHostingContext;
52
53 class TiledCoreAnimationDrawingArea : public DrawingArea, WebCore::LayerFlushSchedulerClient {
54 public:
55     TiledCoreAnimationDrawingArea(WebPage&, const WebPageCreationParameters&);
56     virtual ~TiledCoreAnimationDrawingArea();
57
58 private:
59     // DrawingArea
60     void setNeedsDisplay() override;
61     void setNeedsDisplayInRect(const WebCore::IntRect&) override;
62     void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta) override;
63
64     void forceRepaint() override;
65     bool forceRepaintAsync(uint64_t callbackID) override;
66     void setLayerTreeStateIsFrozen(bool) override;
67     bool layerTreeStateIsFrozen() const override;
68     void setRootCompositingLayer(WebCore::GraphicsLayer*) override;
69     void scheduleCompositingLayerFlush() override;
70     void scheduleCompositingLayerFlushImmediately() override;
71
72     void updatePreferences(const WebPreferencesStore&) override;
73     void mainFrameContentSizeChanged(const WebCore::IntSize&) override;
74
75     void setViewExposedRect(std::optional<WebCore::FloatRect>) override;
76     std::optional<WebCore::FloatRect> viewExposedRect() const override { return m_scrolledViewExposedRect; }
77
78     bool supportsAsyncScrolling() override { return true; }
79
80     void dispatchAfterEnsuringUpdatedScrollPosition(WTF::Function<void ()>&&) override;
81
82     bool shouldUseTiledBackingForFrameView(const WebCore::FrameView*) override;
83
84     void activityStateDidChange(WebCore::ActivityState::Flags changed, bool wantsDidUpdateActivityState, const Vector<uint64_t>&) override;
85     void didUpdateActivityStateTimerFired();
86
87     void attachViewOverlayGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*) override;
88
89     bool dispatchDidReachLayoutMilestone(WebCore::LayoutMilestones) override;
90
91     // WebCore::LayerFlushSchedulerClient
92     bool flushLayers() override;
93
94     // Message handlers.
95     void updateGeometry(const WebCore::IntSize& viewSize, const WebCore::IntSize& layerPosition, bool flushSynchronously, const WebCore::MachSendRight& fencePort) override;
96     void setDeviceScaleFactor(float) override;
97     void suspendPainting();
98     void resumePainting();
99     void setLayerHostingMode(LayerHostingMode) override;
100     void setColorSpace(const ColorSpaceData&) override;
101     void addFence(const WebCore::MachSendRight&) override;
102
103     void setShouldScaleViewToFitDocument(bool) override;
104
105     void adjustTransientZoom(double scale, WebCore::FloatPoint origin) override;
106     void commitTransientZoom(double scale, WebCore::FloatPoint origin) override;
107     void applyTransientZoomToPage(double scale, WebCore::FloatPoint origin);
108     WebCore::PlatformCALayer* layerForTransientZoom() const;
109     WebCore::PlatformCALayer* shadowLayerForTransientZoom() const;
110
111     void applyTransientZoomToLayers(double scale, WebCore::FloatPoint origin);
112
113     void updateLayerHostingContext();
114
115     void setRootCompositingLayer(CALayer *);
116     void updateRootLayers();
117
118     WebCore::TiledBacking* mainFrameTiledBacking() const;
119     void updateDebugInfoLayer(bool showLayer);
120
121     void updateIntrinsicContentSizeIfNeeded();
122     void updateScrolledExposedRect();
123     void scaleViewToFitDocumentIfNeeded();
124
125     void sendPendingNewlyReachedLayoutMilestones();
126
127     bool m_layerTreeStateIsFrozen;
128     WebCore::LayerFlushScheduler m_layerFlushScheduler;
129
130     std::unique_ptr<LayerHostingContext> m_layerHostingContext;
131
132     RetainPtr<CALayer> m_hostingLayer;
133     RetainPtr<CALayer> m_rootLayer;
134     RetainPtr<CALayer> m_debugInfoLayer;
135
136     RetainPtr<CALayer> m_pendingRootLayer;
137
138     bool m_isPaintingSuspended;
139
140     std::optional<WebCore::FloatRect> m_viewExposedRect;
141     std::optional<WebCore::FloatRect> m_scrolledViewExposedRect;
142
143     WebCore::IntSize m_lastSentIntrinsicContentSize;
144     bool m_inUpdateGeometry;
145
146     double m_transientZoomScale;
147     WebCore::FloatPoint m_transientZoomOrigin;
148
149     WebCore::TransformationMatrix m_transform;
150
151     RunLoop::Timer<TiledCoreAnimationDrawingArea> m_sendDidUpdateActivityStateTimer;
152     Vector<uint64_t> m_nextActivityStateChangeCallbackIDs;
153     bool m_wantsDidUpdateActivityState;
154
155     WebCore::GraphicsLayer* m_viewOverlayRootLayer;
156
157     bool m_shouldScaleViewToFitDocument { false };
158     bool m_isScalingViewToFitDocument { false };
159     WebCore::IntSize m_lastViewSizeForScaleToFit;
160     WebCore::IntSize m_lastDocumentSizeForScaleToFit;
161
162     WebCore::LayoutMilestones m_pendingNewlyReachedLayoutMilestones { 0 };
163 };
164
165 } // namespace WebKit
166
167 SPECIALIZE_TYPE_TRAITS_DRAWING_AREA(TiledCoreAnimationDrawingArea, DrawingAreaTypeTiledCoreAnimation)
168
169 #endif // !PLATFORM(IOS)
170
171 #endif // TiledCoreAnimationDrawingArea_h