2f717df92fa858397a2bfd21daadf894c32cc5e5
[WebKit-https.git] / Source / WebKit / blackberry / Api / WebPageCompositor.cpp
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 #include "config.h"
20
21 #if USE(ACCELERATED_COMPOSITING)
22 #include "WebPageCompositor_p.h"
23
24 #include "BackingStore_p.h"
25 #include "LayerWebKitThread.h"
26 #include "WebPage_p.h"
27
28 #include <BlackBerryPlatformExecutableMessage.h>
29 #include <BlackBerryPlatformMessage.h>
30 #include <BlackBerryPlatformMessageClient.h>
31 #include <GenericTimerClient.h>
32 #include <ThreadTimerClient.h>
33
34 using namespace WebCore;
35
36 namespace BlackBerry {
37 namespace WebKit {
38
39 WebPageCompositorPrivate::WebPageCompositorPrivate(WebPagePrivate* page)
40     : m_webPage(page)
41     , m_context(GLES2Context::create(page))
42     , m_layerRenderer(LayerRenderer::create(m_context.get()))
43     , m_backingStoreUsesOpenGL(false)
44     , m_animationTimer(this, &WebPageCompositorPrivate::animationTimerFired)
45     , m_timerClient(new Platform::GenericTimerClient(Platform::userInterfaceThreadTimerClient()))
46 {
47     m_animationTimer.setClient(m_timerClient);
48 }
49
50 WebPageCompositorPrivate::~WebPageCompositorPrivate()
51 {
52     m_animationTimer.stop();
53     delete m_timerClient;
54 }
55
56 bool WebPageCompositorPrivate::hardwareCompositing() const
57 {
58     return m_layerRenderer->hardwareCompositing();
59 }
60
61 void WebPageCompositorPrivate::setRootLayer(LayerCompositingThread* rootLayer)
62 {
63     m_rootLayer = rootLayer;
64     m_layerRenderer->setRootLayer(m_rootLayer.get());
65 }
66
67 void WebPageCompositorPrivate::setBackingStoreUsesOpenGL(bool backingStoreUsesOpenGL)
68 {
69     m_backingStoreUsesOpenGL = backingStoreUsesOpenGL;
70     m_layerRenderer->setClearSurfaceOnDrawLayers(!backingStoreUsesOpenGL);
71 }
72
73 void WebPageCompositorPrivate::commit(LayerWebKitThread* rootLayer)
74 {
75     if (!rootLayer)
76         return;
77
78     rootLayer->commitOnCompositingThread();
79 }
80
81 bool WebPageCompositorPrivate::drawLayers(const IntRect& dstRect, const FloatRect& contents)
82 {
83     m_layerRenderer->drawLayers(contents, m_layoutRectForCompositing, m_contentsSizeForCompositing, dstRect);
84     m_lastCompositingResults = m_layerRenderer->lastRenderingResults();
85
86     if (m_lastCompositingResults.needsAnimationFrame) {
87         // Using a timeout of 0 actually won't start a timer, it will send a message.
88         m_animationTimer.start(1.0 / 60.0);
89         m_webPage->updateDelegatedOverlays();
90     }
91
92     return true;
93 }
94
95 void WebPageCompositorPrivate::releaseLayerResources()
96 {
97     m_layerRenderer->releaseLayerResources();
98 }
99
100 void WebPageCompositorPrivate::animationTimerFired()
101 {
102     if (m_webPage->m_backingStore->d->shouldDirectRenderingToWindow()) {
103         if (m_webPage->m_backingStore->d->isDirectRenderingAnimationMessageScheduled())
104             return; // don't send new messages as long as we haven't rerendered
105
106         m_webPage->m_backingStore->d->setDirectRenderingAnimationMessageScheduled();
107         BlackBerry::Platform::webKitThreadMessageClient()->dispatchMessage(
108             BlackBerry::Platform::createMethodCallMessage(
109                 &BackingStorePrivate::renderVisibleContents, m_webPage->m_backingStore->d));
110         return;
111     }
112     m_webPage->blitVisibleContents();
113 }
114
115 } // namespace WebKit
116 } // namespace BlackBerry
117
118 #endif // USE(ACCELERATED_COMPOSITING)