1/* 2 * Copyright (C) 2011 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#ifndef DrawingAreaImpl_h 27#define DrawingAreaImpl_h 28 29#include "DrawingArea.h" 30#include "LayerTreeHost.h" 31#include <WebCore/Region.h> 32#include <wtf/RunLoop.h> 33 34namespace WebCore { 35 class GraphicsContext; 36} 37 38namespace WebKit { 39 40class ShareableBitmap; 41class UpdateInfo; 42 43class DrawingAreaImpl : public DrawingArea { 44public: 45 DrawingAreaImpl(WebPage&, const WebPageCreationParameters&); 46 virtual ~DrawingAreaImpl(); 47 48 void layerHostDidFlushLayers(); 49 50private: 51 // DrawingArea 52 virtual void setNeedsDisplay() override; 53 virtual void setNeedsDisplayInRect(const WebCore::IntRect&) override; 54 virtual void scroll(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollDelta); 55 virtual void pageBackgroundTransparencyChanged() override; 56 virtual void setLayerTreeStateIsFrozen(bool); 57 virtual bool layerTreeStateIsFrozen() const { return m_layerTreeStateIsFrozen; } 58 virtual LayerTreeHost* layerTreeHost() const { return m_layerTreeHost.get(); } 59 virtual void forceRepaint(); 60 virtual bool forceRepaintAsync(uint64_t callbackID); 61 62 virtual void didInstallPageOverlay(PageOverlay*); 63 virtual void didUninstallPageOverlay(PageOverlay*); 64 virtual void setPageOverlayNeedsDisplay(PageOverlay*, const WebCore::IntRect&); 65 virtual void setPageOverlayOpacity(PageOverlay*, float); 66 67 virtual void setPaintingEnabled(bool); 68 virtual void updatePreferences(const WebPreferencesStore&) override; 69 70 virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() override; 71 virtual void setRootCompositingLayer(WebCore::GraphicsLayer*) override; 72 virtual void scheduleCompositingLayerFlush() override; 73 virtual void scheduleCompositingLayerFlushImmediately() override; 74 75 // IPC message handlers. 76 virtual void updateBackingStoreState(uint64_t backingStoreStateID, bool respondImmediately, float deviceScaleFactor, const WebCore::IntSize&, const WebCore::IntSize& scrollOffset); 77 virtual void didUpdate(); 78 virtual void suspendPainting(); 79 virtual void resumePainting(); 80 81 void sendDidUpdateBackingStoreState(); 82 83 void enterAcceleratedCompositingMode(WebCore::GraphicsLayer*); 84 void exitAcceleratedCompositingModeSoon(); 85 bool exitAcceleratedCompositingModePending() const { return m_exitCompositingTimer.isActive(); } 86 void exitAcceleratedCompositingMode(); 87 88 void scheduleDisplay(); 89 void displayTimerFired(); 90 void display(); 91 void display(UpdateInfo&); 92 93 uint64_t m_backingStoreStateID; 94 95 WebCore::Region m_dirtyRegion; 96 WebCore::IntRect m_scrollRect; 97 WebCore::IntSize m_scrollOffset; 98 99 // Whether painting is enabled. If painting is disabled, any calls to setNeedsDisplay and scroll are ignored. 100 bool m_isPaintingEnabled; 101 102 // Whether we're currently processing an UpdateBackingStoreState message. 103 bool m_inUpdateBackingStoreState; 104 105 // When true, we should send an UpdateBackingStoreState message instead of any other messages 106 // we normally send to the UI process. 107 bool m_shouldSendDidUpdateBackingStoreState; 108 109 // Whether we're waiting for a DidUpdate message. Used for throttling paints so that the 110 // web process won't paint more frequent than the UI process can handle. 111 bool m_isWaitingForDidUpdate; 112 113 // True between sending the 'enter compositing' messages, and the 'exit compositing' message. 114 bool m_compositingAccordingToProxyMessages; 115 116 // When true, we maintain the layer tree in its current state by not leaving accelerated compositing mode 117 // and not scheduling layer flushes. 118 bool m_layerTreeStateIsFrozen; 119 120 // True when we were asked to exit accelerated compositing mode but couldn't because layer tree 121 // state was frozen. 122 bool m_wantsToExitAcceleratedCompositingMode; 123 124 // Whether painting is suspended. We'll still keep track of the dirty region but we 125 // won't paint until painting has resumed again. 126 bool m_isPaintingSuspended; 127 bool m_alwaysUseCompositing; 128 129 RunLoop::Timer<DrawingAreaImpl> m_displayTimer; 130 RunLoop::Timer<DrawingAreaImpl> m_exitCompositingTimer; 131 132 // The layer tree host that handles accelerated compositing. 133 RefPtr<LayerTreeHost> m_layerTreeHost; 134}; 135 136} // namespace WebKit 137 138#endif // DrawingAreaImpl_h 139