1/* 2 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies) 3 Copyright (C) 2013 Company 100, Inc. 4 5 This library is free software; you can redistribute it and/or 6 modify it under the terms of the GNU Library General Public 7 License as published by the Free Software Foundation; either 8 version 2 of the License, or (at your option) any later version. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Library General Public License for more details. 14 15 You should have received a copy of the GNU Library General Public License 16 along with this library; see the file COPYING.LIB. If not, write to 17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 18 Boston, MA 02110-1301, USA. 19*/ 20 21#ifndef CoordinatedLayerTreeHost_h 22#define CoordinatedLayerTreeHost_h 23 24#if USE(COORDINATED_GRAPHICS) 25 26#include "LayerTreeContext.h" 27#include "LayerTreeHost.h" 28#include <WebCore/CompositingCoordinator.h> 29#include <WebCore/GraphicsLayerFactory.h> 30#include <wtf/HashSet.h> 31 32namespace WebCore { 33class CoordinatedSurface; 34} 35 36namespace WebKit { 37 38class WebPage; 39 40class CoordinatedLayerTreeHost : public LayerTreeHost, public WebCore::CompositingCoordinator::Client 41{ 42public: 43 static PassRefPtr<CoordinatedLayerTreeHost> create(WebPage*); 44 virtual ~CoordinatedLayerTreeHost(); 45 46 virtual const LayerTreeContext& layerTreeContext() { return m_layerTreeContext; } 47 virtual void setLayerFlushSchedulingEnabled(bool); 48 virtual void scheduleLayerFlush(); 49 virtual void setShouldNotifyAfterNextScheduledLayerFlush(bool); 50 virtual void setRootCompositingLayer(WebCore::GraphicsLayer*); 51 virtual void invalidate(); 52 53 virtual void setNonCompositedContentsNeedDisplay() override { } 54 virtual void setNonCompositedContentsNeedDisplayInRect(const WebCore::IntRect&) override { } 55 virtual void scrollNonCompositedContents(const WebCore::IntRect&) override { } 56 virtual void forceRepaint(); 57 virtual bool forceRepaintAsync(uint64_t callbackID); 58 virtual void sizeDidChange(const WebCore::IntSize& newSize); 59 60 virtual void pauseRendering() { m_isSuspended = true; } 61 virtual void resumeRendering() { m_isSuspended = false; scheduleLayerFlush(); } 62 virtual void deviceOrPageScaleFactorChanged() override; 63 virtual void pageBackgroundTransparencyChanged() override; 64 65 virtual void didReceiveCoordinatedLayerTreeHostMessage(IPC::Connection*, IPC::MessageDecoder&); 66 virtual WebCore::GraphicsLayerFactory* graphicsLayerFactory() override; 67 WebCore::CoordinatedGraphicsLayer* mainContentsLayer(); 68 69#if ENABLE(REQUEST_ANIMATION_FRAME) 70 virtual void scheduleAnimation() override; 71#endif 72 virtual void setBackgroundColor(const WebCore::Color&) override; 73 74 static PassRefPtr<WebCore::CoordinatedSurface> createCoordinatedSurface(const WebCore::IntSize&, WebCore::CoordinatedSurface::Flags); 75 76protected: 77 explicit CoordinatedLayerTreeHost(WebPage*); 78 79private: 80 // CoordinatedLayerTreeHost 81 void cancelPendingLayerFlush(); 82 void performScheduledLayerFlush(); 83 void setVisibleContentsRect(const WebCore::FloatRect&, const WebCore::FloatPoint&); 84 void renderNextFrame(); 85 void purgeBackingStores(); 86 void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset); 87 88 void layerFlushTimerFired(WebCore::Timer<CoordinatedLayerTreeHost>*); 89 90 // CompositingCoordinator::Client 91 virtual void didFlushRootLayer(const WebCore::FloatRect& visibleContentRect) override; 92 virtual void notifyFlushRequired() override { scheduleLayerFlush(); }; 93 virtual void commitSceneState(const WebCore::CoordinatedGraphicsState&) override; 94 virtual void paintLayerContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, const WebCore::IntRect& clipRect) override; 95 96 std::unique_ptr<WebCore::CompositingCoordinator> m_coordinator; 97 98 bool m_notifyAfterScheduledLayerFlush; 99 bool m_isValid; 100 bool m_isSuspended; 101 bool m_isWaitingForRenderer; 102 103 LayerTreeContext m_layerTreeContext; 104 105 WebCore::Timer<CoordinatedLayerTreeHost> m_layerFlushTimer; 106 bool m_layerFlushSchedulingEnabled; 107 uint64_t m_forceRepaintAsyncCallbackID; 108}; 109 110} // namespace WebKit 111 112#endif // USE(COORDINATED_GRAPHICS) 113 114#endif // CoordinatedLayerTreeHost_h 115