Clean up some TiledCoreAnimationDrawingArea members
[WebKit-https.git] / Source / WebKit / WebProcess / WebPage / mac / TiledCoreAnimationDrawingArea.h
1 /*
2  * Copyright (C) 2011-2018 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 #pragma once
27
28 #if PLATFORM(MAC)
29
30 #include "CallbackID.h"
31 #include "DrawingArea.h"
32 #include "LayerTreeContext.h"
33 #include <WebCore/FloatRect.h>
34 #include <WebCore/TransformationMatrix.h>
35 #include <wtf/HashMap.h>
36 #include <wtf/RetainPtr.h>
37 #include <wtf/RunLoop.h>
38
39 OBJC_CLASS CALayer;
40
41 namespace WebCore {
42 class FrameView;
43 class PlatformCALayer;
44 class RunLoopObserver;
45 class TiledBacking;
46 }
47
48 namespace WebKit {
49
50 class LayerHostingContext;
51
52 class TiledCoreAnimationDrawingArea : public DrawingArea, public CanMakeWeakPtr<TiledCoreAnimationDrawingArea> {
53 public:
54     TiledCoreAnimationDrawingArea(WebPage&, const WebPageCreationParameters&);
55     virtual ~TiledCoreAnimationDrawingArea();
56
57 private:
58     // DrawingArea
59     void setNeedsDisplay() override;
60     void setNeedsDisplayInRect(const WebCore::IntRect&) override;
61     void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta) override;
62
63     void forceRepaint() override;
64     bool forceRepaintAsync(CallbackID) override;
65     void setLayerTreeStateIsFrozen(bool) override;
66     bool layerTreeStateIsFrozen() const override;
67     void setRootCompositingLayer(WebCore::GraphicsLayer*) override;
68     void scheduleInitialDeferredPaint() 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(Optional<WebCore::FloatRect>) override;
76     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(OptionSet<WebCore::ActivityState::Flag> changed, ActivityStateChangeID, const Vector<CallbackID>&) override;
85     void didUpdateActivityStateTimerFired();
86
87     void attachViewOverlayGraphicsLayer(WebCore::GraphicsLayer*) override;
88
89     bool dispatchDidReachLayoutMilestone(OptionSet<WebCore::LayoutMilestone>) override;
90
91     void flushLayers();
92
93     // Message handlers.
94     void updateGeometry(const WebCore::IntSize& viewSize, bool flushSynchronously, const WTF::MachSendRight& fencePort) override;
95     void setDeviceScaleFactor(float) override;
96     void suspendPainting();
97     void resumePainting();
98     void setLayerHostingMode(LayerHostingMode) override;
99     void setColorSpace(const ColorSpaceData&) override;
100     void addFence(const WTF::MachSendRight&) override;
101
102     void addTransactionCallbackID(CallbackID) override;
103     void setShouldScaleViewToFitDocument(bool) override;
104
105     void sendEnterAcceleratedCompositingModeIfNeeded();
106
107     void adjustTransientZoom(double scale, WebCore::FloatPoint origin) override;
108     void commitTransientZoom(double scale, WebCore::FloatPoint origin) override;
109     void applyTransientZoomToPage(double scale, WebCore::FloatPoint origin);
110     WebCore::PlatformCALayer* layerForTransientZoom() const;
111     WebCore::PlatformCALayer* shadowLayerForTransientZoom() const;
112
113     void applyTransientZoomToLayers(double scale, WebCore::FloatPoint origin);
114
115     void updateLayerHostingContext();
116
117     void setRootCompositingLayer(CALayer *);
118     void updateRootLayers();
119
120     WebCore::TiledBacking* mainFrameTiledBacking() const;
121     void updateDebugInfoLayer(bool showLayer);
122
123     void updateIntrinsicContentSizeIfNeeded();
124     void updateScrolledExposedRect();
125     void scaleViewToFitDocumentIfNeeded();
126
127     void sendPendingNewlyReachedLayoutMilestones();
128
129     void layerFlushRunLoopCallback();
130     void invalidateLayerFlushRunLoopObserver();
131     void scheduleLayerFlushRunLoopObserver();
132
133     bool adjustLayerFlushThrottling(WebCore::LayerFlushThrottleState::Flags) override;
134     bool layerFlushThrottlingIsActive() const override;
135
136     void startLayerFlushThrottlingTimer();
137     void layerFlushThrottlingTimerFired();
138
139     std::unique_ptr<LayerHostingContext> m_layerHostingContext;
140
141     RetainPtr<CALayer> m_hostingLayer;
142     RetainPtr<CALayer> m_rootLayer;
143     RetainPtr<CALayer> m_debugInfoLayer;
144     RetainPtr<CALayer> m_pendingRootLayer;
145
146     Optional<WebCore::FloatRect> m_viewExposedRect;
147     Optional<WebCore::FloatRect> m_scrolledViewExposedRect;
148
149     WebCore::IntSize m_lastViewSizeForScaleToFit;
150     WebCore::IntSize m_lastDocumentSizeForScaleToFit;
151
152     WebCore::IntSize m_lastSentIntrinsicContentSize;
153
154     double m_transientZoomScale { 1 };
155     WebCore::FloatPoint m_transientZoomOrigin;
156
157     WebCore::Timer m_layerFlushThrottlingTimer;
158
159     RunLoop::Timer<TiledCoreAnimationDrawingArea> m_sendDidUpdateActivityStateTimer;
160     Vector<CallbackID> m_nextActivityStateChangeCallbackIDs;
161     ActivityStateChangeID m_activityStateChangeID { ActivityStateChangeAsynchronous };
162
163     RefPtr<WebCore::GraphicsLayer> m_viewOverlayRootLayer;
164
165     OptionSet<WebCore::LayoutMilestone> m_pendingNewlyReachedLayoutMilestones;
166     Vector<CallbackID> m_pendingCallbackIDs;
167
168     std::unique_ptr<WebCore::RunLoopObserver> m_layerFlushRunLoopObserver;
169
170     bool m_isPaintingSuspended { false };
171     bool m_inUpdateGeometry { false };
172     bool m_layerTreeStateIsFrozen { false };
173     bool m_shouldScaleViewToFitDocument { false };
174     bool m_isScalingViewToFitDocument { false };
175     bool m_isThrottlingLayerFlushes { false };
176     bool m_isLayerFlushThrottlingTemporarilyDisabledForInteraction { false };
177     bool m_needsSendEnterAcceleratedCompositingMode { true };
178 };
179
180 } // namespace WebKit
181
182 SPECIALIZE_TYPE_TRAITS_DRAWING_AREA(TiledCoreAnimationDrawingArea, DrawingAreaTypeTiledCoreAnimation)
183
184 #endif // PLATFORM(MAC)