[BlackBerry] Add WebPageCompositor class to BlackBerry WebKit API
[WebKit-https.git] / Source / WebKit / blackberry / Api / WebPageCompositor_p.h
1 /*
2  * Copyright (C) 2010, 2011, 2012 Research In Motion Limited. All rights reserved.
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 WebPageCompositor_p_h
20 #define WebPageCompositor_p_h
21
22 #if USE(ACCELERATED_COMPOSITING)
23
24 #include "LayerCompositingThread.h"
25 #include "LayerRenderer.h"
26
27 #include <BlackBerryPlatformGLES2Context.h>
28 #include <BlackBerryPlatformTimer.h>
29 #include <wtf/OwnPtr.h>
30 #include <wtf/RefCounted.h>
31 #include <wtf/RefPtr.h>
32
33 namespace WebCore {
34 class LayerWebKitThread;
35 };
36
37 namespace BlackBerry {
38 namespace WebKit {
39
40 class WebPageCompositorClient;
41 class WebPagePrivate;
42
43 // This class may only be used on the compositing thread. So it does not need to be threadsaferefcounted.
44 class WebPageCompositorPrivate : public RefCounted<WebPageCompositorPrivate> {
45 public:
46     static PassRefPtr<WebPageCompositorPrivate> create(WebPagePrivate* page, WebPageCompositorClient* client)
47     {
48         return adoptRef(new WebPageCompositorPrivate(page, client));
49     }
50
51     ~WebPageCompositorPrivate();
52
53     bool hardwareCompositing() const;
54
55     Platform::Graphics::GLES2Context* context() const { return m_context; }
56     void setContext(Platform::Graphics::GLES2Context*);
57
58     void setRootLayer(WebCore::LayerCompositingThread*);
59
60     void commit(WebCore::LayerWebKitThread* rootLayerProxy);
61
62     // This is mapped from the public API, thus takes transformed contents
63     void render(const WebCore::IntRect& dstRect, const WebCore::IntRect& transformedContents);
64
65     // Render everything but the root layer
66     bool drawLayers(const WebCore::IntRect& dstRect, const WebCore::FloatRect& contents);
67
68     WebCore::IntRect layoutRectForCompositing() const { return m_layoutRectForCompositing; }
69     void setLayoutRectForCompositing(const WebCore::IntRect& rect) { m_layoutRectForCompositing = rect; }
70
71     WebCore::IntSize contentsSizeForCompositing() const { return m_contentsSizeForCompositing; }
72     void setContentsSizeForCompositing(const WebCore::IntSize& size) { m_contentsSizeForCompositing = size; }
73
74     WebCore::LayerRenderingResults lastCompositingResults() const { return m_lastCompositingResults; }
75     void setLastCompositingResults(const WebCore::LayerRenderingResults& results) { m_lastCompositingResults = results; }
76
77     double animationFrameTimestamp() const { return m_pendingAnimationFrame; }
78
79     void releaseLayerResources();
80
81     WebPagePrivate* page() const { return m_webPage; }
82     WebPageCompositorClient* client() const { return m_client; }
83     void compositorDestroyed();
84
85 protected:
86     WebPageCompositorPrivate(WebPagePrivate*, WebPageCompositorClient*);
87
88 private:
89     void animationTimerFired();
90
91     WebPageCompositorClient* m_client;
92     WebPagePrivate* m_webPage;
93     Platform::Graphics::GLES2Context* m_context;
94     OwnPtr<WebCore::LayerRenderer> m_layerRenderer;
95     RefPtr<WebCore::LayerCompositingThread> m_rootLayer;
96     WebCore::IntRect m_layoutRectForCompositing;
97     WebCore::IntSize m_contentsSizeForCompositing;
98     WebCore::LayerRenderingResults m_lastCompositingResults;
99     BlackBerry::Platform::Timer<WebPageCompositorPrivate> m_animationTimer;
100     BlackBerry::Platform::TimerClient* m_timerClient;
101     double m_pendingAnimationFrame;
102 };
103
104 } // namespace WebKit
105 } // namespace BlackBerry
106
107 #endif // USE(ACCELERATED_COMPOSITING)
108
109 #endif // WebPageCompositor_p_h