2 * Copyright (C) 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Igalia S.L.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
27 #ifndef LayerTreeHostGtk_h
28 #define LayerTreeHostGtk_h
30 #if USE(TEXTURE_MAPPER_GL)
32 #include "LayerTreeContext.h"
33 #include "LayerTreeHost.h"
34 #include "TextureMapperLayer.h"
35 #include <WebCore/GLContext.h>
36 #include <WebCore/GraphicsLayerClient.h>
37 #include <WebCore/TransformationMatrix.h>
38 #include <wtf/RunLoop.h>
42 class AcceleratedSurface;
44 class LayerTreeHostGtk final : public LayerTreeHost, WebCore::GraphicsLayerClient {
46 static Ref<LayerTreeHostGtk> create(WebPage&);
47 virtual ~LayerTreeHostGtk();
50 explicit LayerTreeHostGtk(WebPage&);
52 WebCore::GraphicsLayer* rootLayer() const { return m_rootLayer.get(); }
55 void scheduleLayerFlush() override;
56 void cancelPendingLayerFlush() override;
57 void setRootCompositingLayer(WebCore::GraphicsLayer*) override;
58 void invalidate() override;
60 void forceRepaint() override;
61 void sizeDidChange(const WebCore::IntSize& newSize) override;
62 void deviceOrPageScaleFactorChanged() override;
63 void pageBackgroundTransparencyChanged() override;
65 void setNonCompositedContentsNeedDisplay() override;
66 void setNonCompositedContentsNeedDisplayInRect(const WebCore::IntRect&) override;
67 void scrollNonCompositedContents(const WebCore::IntRect& scrollRect) override;
68 void setViewOverlayRootLayer(WebCore::GraphicsLayer*) override;
70 #if PLATFORM(X11) && !USE(REDIRECTED_XCOMPOSITE_WINDOW)
71 void setNativeSurfaceHandleForCompositing(uint64_t) override;
74 class RenderFrameScheduler {
76 RenderFrameScheduler(std::function<bool()>);
77 ~RenderFrameScheduler();
86 std::function<bool()> m_renderer;
87 RunLoop::Timer<RenderFrameScheduler> m_timer;
88 double m_fireTime { 0 };
89 double m_lastImmediateFlushTime { 0 };
92 // GraphicsLayerClient
93 void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::FloatRect& clipRect) override;
94 float deviceScaleFactor() const override;
95 float pageScaleFactor() const override;
97 bool flushPendingLayerChanges();
99 enum CompositePurpose { ForResize, NotForResize };
100 void compositeLayersToContext(CompositePurpose = NotForResize);
102 void flushAndRenderLayers();
104 bool makeContextCurrent();
105 void createTextureMapper();
107 std::unique_ptr<WebCore::GraphicsLayer> m_rootLayer;
108 std::unique_ptr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;
109 std::unique_ptr<WebCore::TextureMapper> m_textureMapper;
110 std::unique_ptr<WebCore::GLContext> m_context;
111 WebCore::TransformationMatrix m_scaleMatrix;
112 std::unique_ptr<AcceleratedSurface> m_surface;
113 RenderFrameScheduler m_renderFrameScheduler;
116 } // namespace WebKit
120 #endif // LayerTreeHostGtk_h