7cd44f8c43ae13cebcfdea4fb5d7f7570cbf4de4
[WebKit-https.git] / Source / WebKit2 / WebProcess / WebPage / CoordinatedGraphics / ThreadedCoordinatedLayerTreeHost.h
1 /*
2  * Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies)
3  * Copyright (C) 2013 Company 100, Inc.
4  * Copyright (C) 2014 Igalia S.L.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25  * THE POSSIBILITY OF SUCH DAMAGE.
26  */
27
28 #ifndef ThreadedCoordinatedLayerTreeHost_h
29 #define ThreadedCoordinatedLayerTreeHost_h
30
31 #if USE(COORDINATED_GRAPHICS_THREADED)
32
33 #include "CoordinatedLayerTreeHost.h"
34 #include "SimpleViewportController.h"
35 #include "ThreadedCompositor.h"
36
37 namespace WebCore {
38 class GraphicsContext;
39 class GraphicsLayer;
40 struct CoordinatedGraphicsState;
41 }
42
43 namespace WebKit {
44
45 class AcceleratedSurface;
46 class WebPage;
47
48 class ThreadedCoordinatedLayerTreeHost final : public CoordinatedLayerTreeHost {
49 public:
50     static Ref<ThreadedCoordinatedLayerTreeHost> create(WebPage&);
51     virtual ~ThreadedCoordinatedLayerTreeHost();
52
53 private:
54     explicit ThreadedCoordinatedLayerTreeHost(WebPage&);
55
56     void scrollNonCompositedContents(const WebCore::IntRect& scrollRect) override;
57     void sizeDidChange(const WebCore::IntSize&) override;
58     void deviceOrPageScaleFactorChanged() override;
59     void pageBackgroundTransparencyChanged() override;
60
61     void contentsSizeChanged(const WebCore::IntSize&) override;
62     void didChangeViewportProperties(const WebCore::ViewportAttributes&) override;
63
64     void invalidate() override;
65
66     void forceRepaint() override;
67     bool forceRepaintAsync(uint64_t callbackID) override { return false; }
68
69 #if PLATFORM(GTK) && PLATFORM(X11) &&  !USE(REDIRECTED_XCOMPOSITE_WINDOW)
70     void setNativeSurfaceHandleForCompositing(uint64_t) override;
71 #endif
72
73     class CompositorClient final : public ThreadedCompositor::Client {
74         WTF_MAKE_NONCOPYABLE(CompositorClient);
75     public:
76         CompositorClient(ThreadedCoordinatedLayerTreeHost& layerTreeHost)
77             : m_layerTreeHost(layerTreeHost)
78         {
79         }
80
81     private:
82         void renderNextFrame() override
83         {
84             m_layerTreeHost.renderNextFrame();
85         }
86
87         void commitScrollOffset(uint32_t layerID, const WebCore::IntSize& offset) override
88         {
89             m_layerTreeHost.commitScrollOffset(layerID, offset);
90         }
91
92         ThreadedCoordinatedLayerTreeHost& m_layerTreeHost;
93     };
94
95     void didChangeViewport();
96
97     // CompositingCoordinator::Client
98     void didFlushRootLayer(const WebCore::FloatRect&) override { }
99     void commitSceneState(const WebCore::CoordinatedGraphicsState&) override;
100
101     CompositorClient m_compositorClient;
102     std::unique_ptr<AcceleratedSurface> m_surface;
103     RefPtr<ThreadedCompositor> m_compositor;
104     SimpleViewportController m_viewportController;
105     float m_lastPageScaleFactor { 1 };
106     WebCore::IntPoint m_lastScrollPosition;
107 };
108
109 } // namespace WebKit
110
111 #endif // USE(COORDINATED_GRAPHICS_THREADED)
112
113 #endif // ThreadedCoordinatedLayerTreeHost_h