| 1 | /* |
| 2 | * Copyright (C) 2011 Apple Inc. All rights reserved. |
| 3 | * Copyright (C) 2013 Nokia Corporation and/or its subsidiary(-ies). |
| 4 | * Copyright (C) 2019 Igalia S.L. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions |
| 8 | * are met: |
| 9 | * 1. Redistributions of source code must retain the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer. |
| 11 | * 2. Redistributions in binary form must reproduce the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer in the |
| 13 | * documentation and/or other materials provided with the distribution. |
| 14 | * |
| 15 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
| 16 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
| 17 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 18 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
| 19 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 20 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 21 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 22 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 23 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 24 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
| 25 | * THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #pragma once |
| 29 | |
| 30 | #include "DrawingArea.h" |
| 31 | #include <WebCore/Region.h> |
| 32 | #include <wtf/RunLoop.h> |
| 33 | |
| 34 | namespace WebCore { |
| 35 | class GraphicsContext; |
| 36 | } |
| 37 | |
| 38 | namespace WebKit { |
| 39 | |
| 40 | class ShareableBitmap; |
| 41 | class UpdateInfo; |
| 42 | |
| 43 | class DrawingAreaCoordinatedGraphics final : public DrawingArea { |
| 44 | public: |
| 45 | DrawingAreaCoordinatedGraphics(WebPage&, const WebPageCreationParameters&); |
| 46 | virtual ~DrawingAreaCoordinatedGraphics(); |
| 47 | |
| 48 | private: |
| 49 | // DrawingArea |
| 50 | void setNeedsDisplay() override; |
| 51 | void setNeedsDisplayInRect(const WebCore::IntRect&) override; |
| 52 | void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta) override; |
| 53 | void forceRepaint() override; |
| 54 | bool forceRepaintAsync(CallbackID) override; |
| 55 | |
| 56 | void setLayerTreeStateIsFrozen(bool) override; |
| 57 | bool layerTreeStateIsFrozen() const override { return m_layerTreeStateIsFrozen; } |
| 58 | |
| 59 | void setPaintingEnabled(bool paintingEnabled) override { m_isPaintingEnabled = paintingEnabled; }; |
| 60 | void updatePreferences(const WebPreferencesStore&) override; |
| 61 | void mainFrameContentSizeChanged(const WebCore::IntSize&) override; |
| 62 | void deviceOrPageScaleFactorChanged() override; |
| 63 | void didChangeViewportAttributes(WebCore::ViewportAttributes&&) override; |
| 64 | |
| 65 | WebCore::GraphicsLayerFactory* graphicsLayerFactory() override; |
| 66 | void setRootCompositingLayer(WebCore::GraphicsLayer*) override; |
| 67 | void scheduleInitialDeferredPaint() override { }; |
| 68 | void scheduleCompositingLayerFlush() override; |
| 69 | void scheduleCompositingLayerFlushImmediately() override { scheduleCompositingLayerFlush(); }; |
| 70 | void layerHostDidFlushLayers() override; |
| 71 | |
| 72 | #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) |
| 73 | RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID) override; |
| 74 | #endif |
| 75 | |
| 76 | #if USE(TEXTURE_MAPPER_GL) && PLATFORM(GTK) && PLATFORM(X11) && !USE(REDIRECTED_XCOMPOSITE_WINDOW) |
| 77 | void setNativeSurfaceHandleForCompositing(uint64_t) override; |
| 78 | void destroyNativeSurfaceHandleForCompositing(bool&) override; |
| 79 | #endif |
| 80 | |
| 81 | void activityStateDidChange(OptionSet<WebCore::ActivityState::Flag>, ActivityStateChangeID, const Vector<CallbackID>& /* callbackIDs */) override; |
| 82 | void attachViewOverlayGraphicsLayer(WebCore::GraphicsLayer*) override; |
| 83 | |
| 84 | // IPC message handlers. |
| 85 | void updateBackingStoreState(uint64_t backingStoreStateID, bool respondImmediately, float deviceScaleFactor, const WebCore::IntSize&, const WebCore::IntSize& scrollOffset) override; |
| 86 | void didUpdate() override; |
| 87 | |
| 88 | void sendDidUpdateBackingStoreState(); |
| 89 | |
| 90 | void exitAcceleratedCompositingModeSoon(); |
| 91 | bool exitAcceleratedCompositingModePending() const { return m_exitCompositingTimer.isActive(); } |
| 92 | void discardPreviousLayerTreeHost(); |
| 93 | |
| 94 | void suspendPainting(); |
| 95 | void resumePainting(); |
| 96 | |
| 97 | void enterAcceleratedCompositingMode(WebCore::GraphicsLayer*); |
| 98 | void exitAcceleratedCompositingMode(); |
| 99 | |
| 100 | void scheduleDisplay(); |
| 101 | void displayTimerFired(); |
| 102 | void display(); |
| 103 | void display(UpdateInfo&); |
| 104 | |
| 105 | uint64_t m_backingStoreStateID { 0 }; |
| 106 | |
| 107 | // Whether painting is enabled. If painting is disabled, any calls to setNeedsDisplay and scroll are ignored. |
| 108 | bool m_isPaintingEnabled { true }; |
| 109 | |
| 110 | // Whether we're currently processing an UpdateBackingStoreState message. |
| 111 | bool m_inUpdateBackingStoreState { false }; |
| 112 | |
| 113 | // When true, we should send an UpdateBackingStoreState message instead of any other messages |
| 114 | // we normally send to the UI process. |
| 115 | bool m_shouldSendDidUpdateBackingStoreState { false }; |
| 116 | |
| 117 | // True between sending the 'enter compositing' messages, and the 'exit compositing' message. |
| 118 | bool m_compositingAccordingToProxyMessages { false }; |
| 119 | |
| 120 | // When true, we maintain the layer tree in its current state by not leaving accelerated compositing mode |
| 121 | // and not scheduling layer flushes. |
| 122 | bool m_layerTreeStateIsFrozen { false }; |
| 123 | |
| 124 | // True when we were asked to exit accelerated compositing mode but couldn't because layer tree |
| 125 | // state was frozen. |
| 126 | bool m_wantsToExitAcceleratedCompositingMode { false }; |
| 127 | |
| 128 | // Whether painting is suspended. We'll still keep track of the dirty region but we |
| 129 | // won't paint until painting has resumed again. |
| 130 | bool m_isPaintingSuspended { false }; |
| 131 | |
| 132 | RunLoop::Timer<DrawingAreaCoordinatedGraphics> m_exitCompositingTimer; |
| 133 | |
| 134 | // The layer tree host that handles accelerated compositing. |
| 135 | std::unique_ptr<LayerTreeHost> m_layerTreeHost; |
| 136 | |
| 137 | std::unique_ptr<LayerTreeHost> m_previousLayerTreeHost; |
| 138 | RunLoop::Timer<DrawingAreaCoordinatedGraphics> m_discardPreviousLayerTreeHostTimer; |
| 139 | |
| 140 | WebCore::Region m_dirtyRegion; |
| 141 | WebCore::IntRect m_scrollRect; |
| 142 | WebCore::IntSize m_scrollOffset; |
| 143 | |
| 144 | // Whether we're waiting for a DidUpdate message. Used for throttling paints so that the |
| 145 | // web process won't paint more frequent than the UI process can handle. |
| 146 | bool m_isWaitingForDidUpdate { false }; |
| 147 | |
| 148 | bool m_alwaysUseCompositing {false }; |
| 149 | bool m_forceRepaintAfterBackingStoreStateUpdate { false }; |
| 150 | |
| 151 | RunLoop::Timer<DrawingAreaCoordinatedGraphics> m_displayTimer; |
| 152 | }; |
| 153 | |
| 154 | } // namespace WebKit |
| 155 | |