| 1 | /* |
| 2 | * Copyright (C) 2010-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 | #include "CallbackID.h" |
| 29 | #include "DrawingAreaInfo.h" |
| 30 | #include "LayerTreeContext.h" |
| 31 | #include "MessageReceiver.h" |
| 32 | #include "WebPage.h" |
| 33 | #include <WebCore/ActivityState.h> |
| 34 | #include <WebCore/FloatRect.h> |
| 35 | #include <WebCore/IntRect.h> |
| 36 | #include <WebCore/LayerFlushThrottleState.h> |
| 37 | #include <WebCore/LayoutMilestone.h> |
| 38 | #include <WebCore/PlatformScreen.h> |
| 39 | #include <wtf/Forward.h> |
| 40 | #include <wtf/Noncopyable.h> |
| 41 | #include <wtf/TypeCasts.h> |
| 42 | |
| 43 | namespace WTF { |
| 44 | class MachSendRight; |
| 45 | } |
| 46 | |
| 47 | namespace IPC { |
| 48 | class Connection; |
| 49 | class Decoder; |
| 50 | } |
| 51 | |
| 52 | namespace WebCore { |
| 53 | class DisplayRefreshMonitor; |
| 54 | class Frame; |
| 55 | class FrameView; |
| 56 | class GraphicsLayer; |
| 57 | class GraphicsLayerFactory; |
| 58 | struct ViewportAttributes; |
| 59 | } |
| 60 | |
| 61 | namespace WebKit { |
| 62 | |
| 63 | struct ColorSpaceData; |
| 64 | class LayerTreeHost; |
| 65 | struct WebPageCreationParameters; |
| 66 | struct WebPreferencesStore; |
| 67 | |
| 68 | class DrawingArea : public IPC::MessageReceiver { |
| 69 | WTF_MAKE_FAST_ALLOCATED; |
| 70 | WTF_MAKE_NONCOPYABLE(DrawingArea); |
| 71 | |
| 72 | public: |
| 73 | static std::unique_ptr<DrawingArea> create(WebPage&, const WebPageCreationParameters&); |
| 74 | virtual ~DrawingArea(); |
| 75 | |
| 76 | DrawingAreaType type() const { return m_type; } |
| 77 | DrawingAreaIdentifier identifier() const { return m_identifier; } |
| 78 | |
| 79 | virtual void setNeedsDisplay() = 0; |
| 80 | virtual void setNeedsDisplayInRect(const WebCore::IntRect&) = 0; |
| 81 | virtual void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta) = 0; |
| 82 | |
| 83 | // FIXME: These should be pure virtual. |
| 84 | virtual void forceRepaint() { } |
| 85 | virtual bool forceRepaintAsync(CallbackID) { return false; } |
| 86 | virtual void setLayerTreeStateIsFrozen(bool) { } |
| 87 | virtual bool layerTreeStateIsFrozen() const { return false; } |
| 88 | virtual bool layerFlushThrottlingIsActive() const { return false; } |
| 89 | |
| 90 | virtual void setPaintingEnabled(bool) { } |
| 91 | virtual void updatePreferences(const WebPreferencesStore&) { } |
| 92 | virtual void mainFrameContentSizeChanged(const WebCore::IntSize&) { } |
| 93 | |
| 94 | #if PLATFORM(COCOA) |
| 95 | virtual void setViewExposedRect(Optional<WebCore::FloatRect>) = 0; |
| 96 | virtual Optional<WebCore::FloatRect> viewExposedRect() const = 0; |
| 97 | |
| 98 | virtual void acceleratedAnimationDidStart(uint64_t /*layerID*/, const String& /*key*/, MonotonicTime /*startTime*/) { } |
| 99 | virtual void acceleratedAnimationDidEnd(uint64_t /*layerID*/, const String& /*key*/) { } |
| 100 | virtual void addFence(const WTF::MachSendRight&) { } |
| 101 | #endif |
| 102 | #if PLATFORM(IOS_FAMILY) |
| 103 | virtual WebCore::FloatRect exposedContentRect() const = 0; |
| 104 | virtual void setExposedContentRect(const WebCore::FloatRect&) = 0; |
| 105 | #endif |
| 106 | virtual void mainFrameScrollabilityChanged(bool) { } |
| 107 | |
| 108 | virtual bool supportsAsyncScrolling() { return false; } |
| 109 | |
| 110 | virtual bool shouldUseTiledBackingForFrameView(const WebCore::FrameView&) { return false; } |
| 111 | |
| 112 | virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() { return nullptr; } |
| 113 | virtual void setRootCompositingLayer(WebCore::GraphicsLayer*) = 0; |
| 114 | virtual void scheduleCompositingLayerFlush() = 0; |
| 115 | virtual void scheduleInitialDeferredPaint() = 0; |
| 116 | virtual void scheduleCompositingLayerFlushImmediately() = 0; |
| 117 | |
| 118 | #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
| 119 | virtual RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID); |
| 120 | #endif |
| 121 | |
| 122 | virtual void dispatchAfterEnsuringUpdatedScrollPosition(WTF::Function<void ()>&&); |
| 123 | |
| 124 | virtual void activityStateDidChange(OptionSet<WebCore::ActivityState::Flag>, ActivityStateChangeID, const Vector<CallbackID>&) { } |
| 125 | virtual void setLayerHostingMode(LayerHostingMode) { } |
| 126 | |
| 127 | virtual bool markLayersVolatileImmediatelyIfPossible() { return true; } |
| 128 | |
| 129 | virtual bool adjustLayerFlushThrottling(WebCore::LayerFlushThrottleState::Flags) { return false; } |
| 130 | |
| 131 | virtual void attachViewOverlayGraphicsLayer(WebCore::GraphicsLayer*) { } |
| 132 | |
| 133 | virtual void setShouldScaleViewToFitDocument(bool) { } |
| 134 | |
| 135 | virtual bool addMilestonesToDispatch(OptionSet<WebCore::LayoutMilestone>) { return false; } |
| 136 | |
| 137 | #if PLATFORM(COCOA) |
| 138 | // Used by TiledCoreAnimationDrawingArea. |
| 139 | virtual void updateGeometry(const WebCore::IntSize& viewSize, bool flushSynchronously, const WTF::MachSendRight& fencePort) { } |
| 140 | #endif |
| 141 | |
| 142 | virtual void layerHostDidFlushLayers() { } |
| 143 | |
| 144 | #if USE(COORDINATED_GRAPHICS) || USE(TEXTURE_MAPPER) |
| 145 | virtual void didChangeViewportAttributes(WebCore::ViewportAttributes&&) = 0; |
| 146 | virtual void deviceOrPageScaleFactorChanged() = 0; |
| 147 | #endif |
| 148 | |
| 149 | virtual void adoptLayersFromDrawingArea(DrawingArea&) { } |
| 150 | |
| 151 | void removeMessageReceiverIfNeeded(); |
| 152 | |
| 153 | protected: |
| 154 | DrawingArea(DrawingAreaType, DrawingAreaIdentifier, WebPage&); |
| 155 | |
| 156 | template<typename U> bool send(const U& message) |
| 157 | { |
| 158 | return m_webPage.send(message, m_identifier.toUInt64(), { }); |
| 159 | } |
| 160 | |
| 161 | DrawingAreaType m_type; |
| 162 | DrawingAreaIdentifier m_identifier; |
| 163 | WebPage& m_webPage; |
| 164 | |
| 165 | #if USE(TEXTURE_MAPPER_GL) && PLATFORM(GTK) && PLATFORM(X11) && !USE(REDIRECTED_XCOMPOSITE_WINDOW) |
| 166 | uint64_t m_nativeSurfaceHandleForCompositing { 0 }; |
| 167 | #endif |
| 168 | |
| 169 | private: |
| 170 | // IPC::MessageReceiver. |
| 171 | void didReceiveMessage(IPC::Connection&, IPC::Decoder&) override; |
| 172 | void didReceiveSyncMessage(IPC::Connection&, IPC::Decoder&, std::unique_ptr<IPC::Encoder>&) override; |
| 173 | |
| 174 | // Message handlers. |
| 175 | // FIXME: These should be pure virtual. |
| 176 | virtual void updateBackingStoreState(uint64_t /*backingStoreStateID*/, bool /*respondImmediately*/, float /*deviceScaleFactor*/, const WebCore::IntSize& /*size*/, |
| 177 | const WebCore::IntSize& /*scrollOffset*/) { } |
| 178 | virtual void didUpdate() { } |
| 179 | |
| 180 | #if PLATFORM(COCOA) |
| 181 | // Used by TiledCoreAnimationDrawingArea. |
| 182 | virtual void setDeviceScaleFactor(float) { } |
| 183 | virtual void setColorSpace(const ColorSpaceData&) { } |
| 184 | |
| 185 | virtual void adjustTransientZoom(double scale, WebCore::FloatPoint origin) { } |
| 186 | virtual void commitTransientZoom(double scale, WebCore::FloatPoint origin) { } |
| 187 | |
| 188 | virtual void addTransactionCallbackID(WebKit::CallbackID) { ASSERT_NOT_REACHED(); } |
| 189 | #endif |
| 190 | |
| 191 | #if USE(TEXTURE_MAPPER_GL) && PLATFORM(GTK) && PLATFORM(X11) && !USE(REDIRECTED_XCOMPOSITE_WINDOW) |
| 192 | virtual void setNativeSurfaceHandleForCompositing(uint64_t) = 0; |
| 193 | virtual void destroyNativeSurfaceHandleForCompositing(bool&) = 0; |
| 194 | #endif |
| 195 | |
| 196 | bool m_hasRemovedMessageReceiver { false }; |
| 197 | }; |
| 198 | |
| 199 | } // namespace WebKit |
| 200 | |
| 201 | #define SPECIALIZE_TYPE_TRAITS_DRAWING_AREA(ToValueTypeName, AreaType) \ |
| 202 | SPECIALIZE_TYPE_TRAITS_BEGIN(WebKit::ToValueTypeName) \ |
| 203 | static bool isType(const WebKit::DrawingArea& area) { return area.type() == WebKit::AreaType; } \ |
| 204 | SPECIALIZE_TYPE_TRAITS_END() |
| 205 | |