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