REGRESSION (PSON): White or Black flash occurs when process swapping on navigation...
[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(IOS)
29
30 #include "CallbackID.h"
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(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(OptionSet<WebCore::ActivityState::Flag> changed, ActivityStateChangeID, const Vector<CallbackID>&) 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, bool flushSynchronously, const WTF::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 WTF::MachSendRight&) override;
102
103     void addTransactionCallbackID(CallbackID) override;
104     void setShouldScaleViewToFitDocument(bool) override;
105
106     void attach() override;
107
108     void adjustTransientZoom(double scale, WebCore::FloatPoint origin) override;
109     void commitTransientZoom(double scale, WebCore::FloatPoint origin) override;
110     void applyTransientZoomToPage(double scale, WebCore::FloatPoint origin);
111     WebCore::PlatformCALayer* layerForTransientZoom() const;
112     WebCore::PlatformCALayer* shadowLayerForTransientZoom() const;
113
114     void applyTransientZoomToLayers(double scale, WebCore::FloatPoint origin);
115
116     void updateLayerHostingContext();
117
118     void setRootCompositingLayer(CALayer *);
119     void updateRootLayers();
120
121     WebCore::TiledBacking* mainFrameTiledBacking() const;
122     void updateDebugInfoLayer(bool showLayer);
123
124     void updateIntrinsicContentSizeIfNeeded();
125     void updateScrolledExposedRect();
126     void scaleViewToFitDocumentIfNeeded();
127
128     void sendPendingNewlyReachedLayoutMilestones();
129
130     bool m_layerTreeStateIsFrozen;
131     WebCore::LayerFlushScheduler m_layerFlushScheduler;
132
133     std::unique_ptr<LayerHostingContext> m_layerHostingContext;
134
135     RetainPtr<CALayer> m_hostingLayer;
136     RetainPtr<CALayer> m_rootLayer;
137     RetainPtr<CALayer> m_debugInfoLayer;
138
139     RetainPtr<CALayer> m_pendingRootLayer;
140
141     bool m_isPaintingSuspended;
142
143     std::optional<WebCore::FloatRect> m_viewExposedRect;
144     std::optional<WebCore::FloatRect> m_scrolledViewExposedRect;
145
146     WebCore::IntSize m_lastSentIntrinsicContentSize;
147     bool m_inUpdateGeometry;
148
149     double m_transientZoomScale;
150     WebCore::FloatPoint m_transientZoomOrigin;
151
152     WebCore::TransformationMatrix m_transform;
153
154     RunLoop::Timer<TiledCoreAnimationDrawingArea> m_sendDidUpdateActivityStateTimer;
155     Vector<CallbackID> m_nextActivityStateChangeCallbackIDs;
156     ActivityStateChangeID m_activityStateChangeID { ActivityStateChangeAsynchronous };
157
158     WebCore::GraphicsLayer* m_viewOverlayRootLayer;
159
160     bool m_shouldScaleViewToFitDocument { false };
161     bool m_isScalingViewToFitDocument { false };
162     WebCore::IntSize m_lastViewSizeForScaleToFit;
163     WebCore::IntSize m_lastDocumentSizeForScaleToFit;
164
165     WebCore::LayoutMilestones m_pendingNewlyReachedLayoutMilestones { 0 };
166     Vector<CallbackID> m_pendingCallbackIDs;
167 };
168
169 } // namespace WebKit
170
171 SPECIALIZE_TYPE_TRAITS_DRAWING_AREA(TiledCoreAnimationDrawingArea, DrawingAreaTypeTiledCoreAnimation)
172
173 #endif // !PLATFORM(IOS)
174