1/* 2 * Copyright (C) 2011 Apple Inc. All rights reserved. 3 * Copyright (C) 2012 Igalia S.L. 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 LayerTreeHostGtk_h 28#define LayerTreeHostGtk_h 29 30#if USE(TEXTURE_MAPPER_GL) 31 32#include "LayerTreeContext.h" 33#include "LayerTreeHost.h" 34#include "TextureMapperLayer.h" 35#include <WebCore/GLContext.h> 36#include <WebCore/GraphicsLayerClient.h> 37#include <wtf/HashMap.h> 38#include <wtf/OwnPtr.h> 39#include <wtf/gobject/GMainLoopSource.h> 40 41namespace WebKit { 42 43class LayerTreeHostGtk : public LayerTreeHost, WebCore::GraphicsLayerClient { 44public: 45 static PassRefPtr<LayerTreeHostGtk> create(WebPage*); 46 virtual ~LayerTreeHostGtk(); 47 48protected: 49 explicit LayerTreeHostGtk(WebPage*); 50 51 WebCore::GraphicsLayer* rootLayer() const { return m_rootLayer.get(); } 52 53 void initialize(); 54 55 // LayerTreeHost. 56 virtual void invalidate(); 57 virtual void sizeDidChange(const WebCore::IntSize& newSize); 58 virtual void deviceOrPageScaleFactorChanged(); 59 virtual void forceRepaint(); 60 virtual void setRootCompositingLayer(WebCore::GraphicsLayer*); 61 virtual void scheduleLayerFlush(); 62 virtual void setLayerFlushSchedulingEnabled(bool layerFlushingEnabled); 63 virtual void pageBackgroundTransparencyChanged() override; 64 65private: 66 // LayerTreeHost. 67 virtual const LayerTreeContext& layerTreeContext(); 68 virtual void setShouldNotifyAfterNextScheduledLayerFlush(bool); 69 70 virtual void setNonCompositedContentsNeedDisplay() override; 71 virtual void setNonCompositedContentsNeedDisplayInRect(const WebCore::IntRect&) override; 72 virtual void scrollNonCompositedContents(const WebCore::IntRect& scrollRect); 73 74 virtual void didInstallPageOverlay(PageOverlay*) override; 75 virtual void didUninstallPageOverlay(PageOverlay*) override; 76 virtual void setPageOverlayNeedsDisplay(PageOverlay*, const WebCore::IntRect&) override; 77 78 virtual bool flushPendingLayerChanges(); 79 80 // GraphicsLayerClient 81 virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time); 82 virtual void notifyFlushRequired(const WebCore::GraphicsLayer*); 83 virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::FloatRect& clipRect); 84 virtual void didCommitChangesForLayer(const WebCore::GraphicsLayer*) const { } 85 86 void createPageOverlayLayer(PageOverlay*); 87 void destroyPageOverlayLayer(PageOverlay*); 88 89 enum CompositePurpose { ForResize, NotForResize }; 90 void compositeLayersToContext(CompositePurpose = NotForResize); 91 92 void flushAndRenderLayers(); 93 void cancelPendingLayerFlush(); 94 95 void layerFlushTimerFired(); 96 97 WebCore::GLContext* glContext(); 98 99 LayerTreeContext m_layerTreeContext; 100 bool m_isValid; 101 bool m_notifyAfterScheduledLayerFlush; 102 std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer; 103 std::unique_ptr<WebCore::GraphicsLayer> m_nonCompositedContentLayer; 104 typedef HashMap<PageOverlay*, std::unique_ptr<WebCore::GraphicsLayer>> PageOverlayLayerMap; 105 PageOverlayLayerMap m_pageOverlayLayers; 106 std::unique_ptr<WebCore::TextureMapper> m_textureMapper; 107 OwnPtr<WebCore::GLContext> m_context; 108 double m_lastFlushTime; 109 bool m_layerFlushSchedulingEnabled; 110 GMainLoopSource m_layerFlushTimerCallback; 111}; 112 113} // namespace WebKit 114 115#endif 116 117#endif // LayerTreeHostGtk_h 118