[GTK] Use XDamage to simplify RedirectedXCompositeWindow
[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
68     enum CompositePurpose { ForResize, NotForResize };
69     void compositeLayersToContext(CompositePurpose = NotForResize);
70
71     void flushAndRenderLayers();
72     bool flushPendingLayerChanges();
73     void scrollNonCompositedContents(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
74
75 private:
76     WebKitWebView* m_webView;
77     unsigned int m_layerFlushTimerCallbackId;
78
79 #if USE(CLUTTER)
80     WebCore::GraphicsLayer* m_rootGraphicsLayer;
81     GtkWidget* m_rootLayerEmbedder;
82 #elif USE(TEXTURE_MAPPER_GL)
83     OwnPtr<WebCore::RedirectedXCompositeWindow> m_redirectedWindow;
84     OwnPtr<WebCore::GraphicsLayer> m_rootLayer;
85     OwnPtr<WebCore::GraphicsLayer> m_nonCompositedContentLayer;
86     OwnPtr<WebCore::TextureMapper> m_textureMapper;
87     double m_lastFlushTime;
88     double m_redrawPendingTime;
89     bool m_needsExtraFlush;
90
91     void layerFlushTimerFired();
92     void stopAnyPendingLayerFlush();
93     static gboolean layerFlushTimerFiredCallback(AcceleratedCompositingContext*);
94     WebCore::GLContext* prepareForRendering();
95     void clearEverywhere();
96 #elif USE(TEXTURE_MAPPER)
97     WebCore::TextureMapperLayer* m_rootTextureMapperLayer;
98     OwnPtr<WebCore::GraphicsLayer> m_rootGraphicsLayer;
99     OwnPtr<WebCore::TextureMapper> m_textureMapper;
100 #endif
101
102     AcceleratedCompositingContext(WebKitWebView*);
103 };
104
105 } // namespace WebKit
106
107 #endif // USE(ACCELERATED_COMPOSITING)
108 #endif // AcceleratedCompositingContext_h