45ef470b6a73da957b79cbe6fb46715ab24ecaa2
[WebKit-https.git] / Source / WebKit / gtk / WebCoreSupport / AcceleratedCompositingContext.h
1 /*
2  * Copyright (C) 2011 Igalia, S.L.
3  *
4  *  This library is free software; you can redistribute it and/or
5  *  modify it under the terms of the GNU Lesser General Public
6  *  License as published by the Free Software Foundation; either
7  *  version 2 of the License, or (at your option) any later version.
8  *
9  *  This library is distributed in the hope that it will be useful,
10  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  *  Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public
15  *  License along with this library; if not, write to the Free Software
16  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18
19 #ifndef AcceleratedCompositingContext_h
20 #define AcceleratedCompositingContext_h
21
22 #include "GraphicsLayer.h"
23 #include "GraphicsLayerClient.h"
24 #include "IntRect.h"
25 #include "IntSize.h"
26 #include "Timer.h"
27 #include "webkitwebview.h"
28 #include <wtf/PassOwnPtr.h>
29
30 #if USE(TEXTURE_MAPPER)
31 #include "TextureMapperLayer.h"
32 #endif
33
34 #if USE(TEXTURE_MAPPER_GL)
35 #include "GLContext.h"
36 #include "RedirectedXCompositeWindow.h"
37 #endif
38
39 #if USE(ACCELERATED_COMPOSITING)
40
41 namespace WebKit {
42
43 class AcceleratedCompositingContext : public WebCore::GraphicsLayerClient {
44     WTF_MAKE_NONCOPYABLE(AcceleratedCompositingContext);
45 public:
46     static PassOwnPtr<AcceleratedCompositingContext> create(WebKitWebView* webView)
47     {
48         return adoptPtr(new AcceleratedCompositingContext(webView));
49     }
50
51     virtual ~AcceleratedCompositingContext();
52     void setRootCompositingLayer(WebCore::GraphicsLayer*);
53     void setNonCompositedContentsNeedDisplay(const WebCore::IntRect&);
54     void scheduleLayerFlush();
55     void resizeRootLayer(const WebCore::IntSize&);
56     bool renderLayersToWindow(cairo_t*, const WebCore::IntRect& clipRect);
57     bool enabled();
58
59     // GraphicsLayerClient
60     virtual void notifyAnimationStarted(const WebCore::GraphicsLayer*, double time);
61     virtual void notifySyncRequired(const WebCore::GraphicsLayer*);
62     virtual void paintContents(const WebCore::GraphicsLayer*, WebCore::GraphicsContext&, WebCore::GraphicsLayerPaintingPhase, const WebCore::IntRect& rectToPaint);
63     virtual bool showDebugBorders(const WebCore::GraphicsLayer*) const;
64     virtual bool showRepaintCounter(const WebCore::GraphicsLayer*) const;
65
66     void initialize();
67     void compositeLayersToContext();
68     void flushAndRenderLayers();
69     bool flushPendingLayerChanges();
70     void scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
71
72 private:
73     WebKitWebView* m_webView;
74     unsigned int m_layerFlushTimerCallbackId;
75
76 #if USE(CLUTTER)
77     WebCore::GraphicsLayer* m_rootGraphicsLayer;
78     GtkWidget* m_rootLayerEmbedder;
79 #elif USE(TEXTURE_MAPPER_GL)
80     OwnPtr<WebCore::RedirectedXCompositeWindow> m_redirectedWindow;
81     OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
82     OwnPtr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;
83     OwnPtr<WebCore::TextureMapper> m_textureMapper;
84     double m_lastFlushTime;
85     double m_redrawPendingTime;
86     bool m_needsExtraFlush;
87
88     void layerFlushTimerFired();
89     void stopAnyPendingLayerFlush();
90     static gboolean layerFlushTimerFiredCallback(AcceleratedCompositingContext*);
91     WebCore::GLContext* prepareForRendering();
92     void clearEverywhere();
93 #elif USE(TEXTURE_MAPPER)
94     WebCore::TextureMapperLayer* m_rootTextureMapperLayer;
95     OwnPtr<WebCore::GraphicsLayer> m_rootGraphicsLayer;
96     OwnPtr<WebCore::TextureMapper> m_textureMapper;
97 #endif
98
99     AcceleratedCompositingContext(WebKitWebView*);
100 };
101
102 } // namespace WebKit
103
104 #endif // USE(ACCELERATED_COMPOSITING)
105 #endif // AcceleratedCompositingContext_h