[BlackBerry] Always create a compositor

https://bugs.webkit.org/show_bug.cgi?id=87598

Patch by Arvid Nilsson <anilsson@rim.com> on 2012-05-28
Reviewed by Rob Buis.

There will likely be compositing layers either due to web content or
due to overlays.

Defer initialization of OpenGL objects (i.e., delay creation of the
LayerRenderer object) until we actually need to draw and there are such
layers, to avoid initializing OpenGL in the unlikely case that there
are no compositing layers or overlay layers.

PR #156811

* Api/WebPage.cpp:
(BlackBerry::WebKit::WebPagePrivate::init):
(BlackBerry::WebKit::WebPagePrivate::createCompositor):
* Api/WebPageCompositor.cpp:
(BlackBerry::WebKit::WebPageCompositorPrivate::setContext):
(BlackBerry::WebKit::WebPageCompositorPrivate::prepareFrame):
(BlackBerry::WebKit::WebPageCompositorPrivate::render):
(BlackBerry::WebKit::WebPageCompositorPrivate::drawLayers):
* Api/WebPageCompositor_p.h:
(WebPageCompositorPrivate):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@118704 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 42b4c730
......@@ -556,6 +556,14 @@ void WebPagePrivate::init(const WebString& pageGroupName)
#if ENABLE(WEB_TIMING)
m_page->settings()->setMemoryInfoEnabled(true);
#endif
#if USE(ACCELERATED_COMPOSITING)
// The compositor will be needed for overlay rendering, so create it
// unconditionally. It will allocate OpenGL objects lazily, so this incurs
// no overhead in the unlikely case where the compositor is not needed.
Platform::userInterfaceThreadMessageClient()->dispatchSyncMessage(
createMethodCallMessage(&WebPagePrivate::createCompositor, this));
#endif
}
class DeferredTaskLoadManualScript: public DeferredTask<&WebPagePrivate::m_wouldLoadManualScript> {
......@@ -5887,11 +5895,6 @@ bool WebPagePrivate::createCompositor()
m_compositor = WebPageCompositorPrivate::create(this, 0);
m_compositor->setContext(m_ownedContext.get());
if (!m_compositor->hardwareCompositing()) {
destroyCompositor();
return false;
}
return true;
}
......
......@@ -60,17 +60,8 @@ void WebPageCompositorPrivate::setContext(Platform::Graphics::GLES2Context* cont
return;
m_context = context;
if (!m_context) {
if (!m_context)
m_layerRenderer.clear();
return;
}
m_layerRenderer = LayerRenderer::create(m_context);
}
bool WebPageCompositorPrivate::hardwareCompositing() const
{
return m_layerRenderer && m_layerRenderer->hardwareCompositing();
}
void WebPageCompositorPrivate::setRootLayer(LayerCompositingThread* rootLayer)
......@@ -85,9 +76,24 @@ void WebPageCompositorPrivate::setOverlayLayer(LayerCompositingThread* overlayLa
void WebPageCompositorPrivate::prepareFrame(double animationTime)
{
if (!m_layerRenderer)
if (!m_context)
return;
// The LayerRenderer is involved in rendering the BackingStore when
// WebPageCompositor is used to render the web page. The presence of a
// WebPageCompositorClient (m_client) indicates this is the case, so
// create a LayerRenderer if there are layers or if there's a client.
if (!m_rootLayer && !m_overlayLayer && !m_client)
return;
if (!m_layerRenderer) {
m_layerRenderer = LayerRenderer::create(m_context);
if (!m_layerRenderer->hardwareCompositing()) {
m_layerRenderer.clear();
return;
}
}
// Unfortunately, we have to use currentTime() because the animations are
// started in that time coordinate system.
animationTime = currentTime();
......@@ -99,19 +105,16 @@ void WebPageCompositorPrivate::prepareFrame(double animationTime)
void WebPageCompositorPrivate::render(const IntRect& targetRect, const IntRect& clipRect, const TransformationMatrix& transformIn, const FloatRect& transformedContents, const FloatRect& /*viewport*/)
{
if (!m_layerRenderer) {
// It's not safe to call into the BackingStore if the compositor hasn't been set yet.
// For thread safety, we have to do it using a round-trip to the WebKit thread, so the
// embedder might call this before the round-trip to WebPagePrivate::setCompositor() is
// done.
if (m_webPage->compositor() != this)
return;
// m_layerRenderer should have been created in prepareFrame
if (!m_layerRenderer)
return;
// The clip rect is in OpenGL coordinate system, so turn it upside down to get to window coordinates.
IntRect dstRect(clipRect.x(), m_context->surfaceSize().height() - clipRect.y() - clipRect.height(), clipRect.width(), clipRect.height());
m_webPage->m_backingStore->d->blitContents(dstRect, enclosingIntRect(transformedContents), true);
// It's not safe to call into the BackingStore if the compositor hasn't been set yet.
// For thread safety, we have to do it using a round-trip to the WebKit thread, so the
// embedder might call this before the round-trip to WebPagePrivate::setCompositor() is
// done.
if (m_webPage->compositor() != this)
return;
}
m_layerRenderer->setClearSurfaceOnDrawLayers(false);
......@@ -145,6 +148,12 @@ bool WebPageCompositorPrivate::drawsRootLayer() const
bool WebPageCompositorPrivate::drawLayers(const IntRect& dstRect, const FloatRect& contents)
{
// Is there anything to draw?
if (!m_rootLayer && !m_overlayLayer)
return false;
// prepareFrame creates the LayerRenderer if needed
prepareFrame(currentTime());
if (!m_layerRenderer)
return false;
......@@ -157,7 +166,6 @@ bool WebPageCompositorPrivate::drawLayers(const IntRect& dstRect, const FloatRec
// WebKit uses upper left as the origin of the window coordinate system. The passed in 'dstRect'
// is in WebKit window coordinate system. Here we setup the viewport to the corresponding value
// in OpenGL window coordinates.
m_layerRenderer->prepareFrame(currentTime(), m_rootLayer.get());
int viewportY = std::max(0, m_context->surfaceSize().height() - dstRect.maxY());
IntRect viewport = IntRect(dstRect.x(), viewportY, dstRect.width(), dstRect.height());
......
......@@ -58,9 +58,6 @@ public:
const WebCore::FloatRect& contents, // This is public API, thus takes transformed contents
const WebCore::FloatRect& viewport);
// Internal
bool hardwareCompositing() const;
Platform::Graphics::GLES2Context* context() const { return m_context; }
void setContext(Platform::Graphics::GLES2Context*);
......
2012-05-28 Arvid Nilsson <anilsson@rim.com>
[BlackBerry] Always create a compositor
https://bugs.webkit.org/show_bug.cgi?id=87598
Reviewed by Rob Buis.
There will likely be compositing layers either due to web content or
due to overlays.
Defer initialization of OpenGL objects (i.e., delay creation of the
LayerRenderer object) until we actually need to draw and there are such
layers, to avoid initializing OpenGL in the unlikely case that there
are no compositing layers or overlay layers.
PR #156811
* Api/WebPage.cpp:
(BlackBerry::WebKit::WebPagePrivate::init):
(BlackBerry::WebKit::WebPagePrivate::createCompositor):
* Api/WebPageCompositor.cpp:
(BlackBerry::WebKit::WebPageCompositorPrivate::setContext):
(BlackBerry::WebKit::WebPageCompositorPrivate::prepareFrame):
(BlackBerry::WebKit::WebPageCompositorPrivate::render):
(BlackBerry::WebKit::WebPageCompositorPrivate::drawLayers):
* Api/WebPageCompositor_p.h:
(WebPageCompositorPrivate):
2012-05-28 Arvid Nilsson <anilsson@rim.com>
[BlackBerry] Dangling pointer in WebPagePrivate::setCompositor() message
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment