2 * Copyright (C) 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
28 #include "DrawingAreaInfo.h"
29 #include "LayerTreeContext.h"
30 #include "MessageReceiver.h"
31 #include <WebCore/FloatRect.h>
32 #include <WebCore/IntRect.h>
33 #include <WebCore/LayerFlushThrottleState.h>
34 #include <WebCore/LayoutMilestones.h>
35 #include <WebCore/PlatformScreen.h>
36 #include <WebCore/ViewState.h>
38 #include <wtf/Forward.h>
39 #include <wtf/Noncopyable.h>
40 #include <wtf/TypeCasts.h>
41 #include <wtf/Vector.h>
49 class DisplayRefreshMonitor;
53 class GraphicsLayerFactory;
59 struct ColorSpaceData;
62 struct WebPageCreationParameters;
63 struct WebPreferencesStore;
65 class DrawingArea : public IPC::MessageReceiver {
66 WTF_MAKE_NONCOPYABLE(DrawingArea);
69 static std::unique_ptr<DrawingArea> create(WebPage&, const WebPageCreationParameters&);
70 virtual ~DrawingArea();
72 DrawingAreaType type() const { return m_type; }
74 virtual void setNeedsDisplay() = 0;
75 virtual void setNeedsDisplayInRect(const WebCore::IntRect&) = 0;
76 virtual void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta) = 0;
78 // FIXME: These should be pure virtual.
79 virtual void pageBackgroundTransparencyChanged() { }
80 virtual void forceRepaint() { }
81 virtual bool forceRepaintAsync(uint64_t /*callbackID*/) { return false; }
82 virtual void setLayerTreeStateIsFrozen(bool) { }
83 virtual bool layerTreeStateIsFrozen() const { return false; }
84 virtual LayerTreeHost* layerTreeHost() const { return 0; }
86 virtual void setPaintingEnabled(bool) { }
87 virtual void updatePreferences(const WebPreferencesStore&) { }
88 virtual void mainFrameContentSizeChanged(const WebCore::IntSize&) { }
91 virtual void setViewExposedRect(Optional<WebCore::FloatRect>) = 0;
92 virtual Optional<WebCore::FloatRect> viewExposedRect() const = 0;
94 virtual void acceleratedAnimationDidStart(uint64_t /*layerID*/, const String& /*key*/, double /*startTime*/) { }
95 virtual void acceleratedAnimationDidEnd(uint64_t /*layerID*/, const String& /*key*/) { }
96 virtual void addFence(const WebCore::MachSendRight&) { }
99 virtual WebCore::FloatRect exposedContentRect() const = 0;
100 virtual void setExposedContentRect(const WebCore::FloatRect&) = 0;
102 virtual void mainFrameScrollabilityChanged(bool) { }
104 virtual bool supportsAsyncScrolling() { return false; }
106 virtual bool shouldUseTiledBackingForFrameView(const WebCore::FrameView*) { return false; }
108 virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() { return nullptr; }
109 virtual void setRootCompositingLayer(WebCore::GraphicsLayer*) = 0;
110 virtual void scheduleCompositingLayerFlush() = 0;
111 virtual void scheduleCompositingLayerFlushImmediately() = 0;
113 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
114 virtual RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID);
117 #if USE(COORDINATED_GRAPHICS_MULTIPROCESS)
118 virtual void didReceiveCoordinatedLayerTreeHostMessage(IPC::Connection&, IPC::Decoder&) = 0;
121 virtual void dispatchAfterEnsuringUpdatedScrollPosition(std::function<void ()>);
123 virtual void viewStateDidChange(WebCore::ViewState::Flags, bool /* wantsDidUpdateViewState */, const Vector<uint64_t>& /* callbackIDs */) { }
124 virtual void setLayerHostingMode(LayerHostingMode) { }
126 virtual bool markLayersVolatileImmediatelyIfPossible() { return true; }
128 virtual bool adjustLayerFlushThrottling(WebCore::LayerFlushThrottleState::Flags) { return false; }
130 virtual void attachViewOverlayGraphicsLayer(WebCore::Frame*, WebCore::GraphicsLayer*) { }
132 virtual void setShouldScaleViewToFitDocument(bool) { }
134 virtual bool dispatchDidReachLayoutMilestone(WebCore::LayoutMilestones) { return false; }
137 // Used by TiledCoreAnimationDrawingArea.
138 virtual void updateGeometry(const WebCore::IntSize& viewSize, const WebCore::IntSize& layerPosition, bool flushSynchronously, const WebCore::MachSendRight& fencePort) { }
141 virtual void layerHostDidFlushLayers() { };
144 DrawingArea(DrawingAreaType, WebPage&);
146 DrawingAreaType m_type;
149 #if USE(TEXTURE_MAPPER_GL) && PLATFORM(GTK) && PLATFORM(X11) && !USE(REDIRECTED_XCOMPOSITE_WINDOW)
150 uint64_t m_nativeSurfaceHandleForCompositing { 0 };
154 // IPC::MessageReceiver.
155 void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override;
156 void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override;
159 // FIXME: These should be pure virtual.
160 virtual void updateBackingStoreState(uint64_t /*backingStoreStateID*/, bool /*respondImmediately*/, float /*deviceScaleFactor*/, const WebCore::IntSize& /*size*/,
161 const WebCore::IntSize& /*scrollOffset*/) { }
162 virtual void didUpdate() { }
165 // Used by TiledCoreAnimationDrawingArea.
166 virtual void setDeviceScaleFactor(float) { }
167 virtual void setColorSpace(const ColorSpaceData&) { }
169 virtual void adjustTransientZoom(double scale, WebCore::FloatPoint origin) { }
170 virtual void commitTransientZoom(double scale, WebCore::FloatPoint origin) { }
172 virtual void addTransactionCallbackID(uint64_t callbackID) { ASSERT_NOT_REACHED(); }
175 #if USE(TEXTURE_MAPPER_GL) && PLATFORM(GTK) && PLATFORM(X11) && !USE(REDIRECTED_XCOMPOSITE_WINDOW)
176 virtual void setNativeSurfaceHandleForCompositing(uint64_t) = 0;
177 virtual void destroyNativeSurfaceHandleForCompositing(bool&) = 0;
181 } // namespace WebKit
183 #define SPECIALIZE_TYPE_TRAITS_DRAWING_AREA(ToValueTypeName, AreaType) \
184 SPECIALIZE_TYPE_TRAITS_BEGIN(WebKit::ToValueTypeName) \
185 static bool isType(const WebKit::DrawingArea& area) { return area.type() == WebKit::AreaType; } \
186 SPECIALIZE_TYPE_TRAITS_END()