Skip to content
Permalink
Browse files
[Threaded Compositor] Stop creating the GLContext on demand the first…
… time makeContextCurrent is called

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

Reviewed by Žan Doberšek.

This is causing problems with animations when entering AC mode on demand. What happens is that the threaded
compositor is created, then the animation is scheduled and during the first animation iteration the GLContext is
created, making the first frame of the animation quite slow. In my computer creating the GLContext takes 0.8
seconds. If the animation duration is less than the time it takes to create the GLContext, the animation ends
without iterating. This causing timeouts in the bots in tests like
animations/animation-iteration-event-destroy-renderer.html that expect webkitAnimationIteration events that
never fire.

* Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:
(WebKit::ThreadedCompositor::ThreadedCompositor): Create the GLContext right after the compositing thread is
created if we already have a native surface handle.
(WebKit::ThreadedCompositor::createGLContext): Helper to create the GLContext.
(WebKit::ThreadedCompositor::setNativeSurfaceHandleForCompositing): Create the GLContext when a native surface
handle is given.
(WebKit::ThreadedCompositor::makeContextCurrent): Deleted.
(WebKit::ThreadedCompositor::renderLayerTree): Make the context cunrrent directly here.
* Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:

Canonical link: https://commits.webkit.org/184535@main
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@211281 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
carlosgcampos committed Jan 27, 2017
1 parent 6f94143 commit 0ac612b43115a2e7a6bd62ebd4e89f5579b00930
@@ -1,3 +1,28 @@
2017-01-27 Carlos Garcia Campos <cgarcia@igalia.com>

[Threaded Compositor] Stop creating the GLContext on demand the first time makeContextCurrent is called
https://bugs.webkit.org/show_bug.cgi?id=167496

Reviewed by Žan Doberšek.

This is causing problems with animations when entering AC mode on demand. What happens is that the threaded
compositor is created, then the animation is scheduled and during the first animation iteration the GLContext is
created, making the first frame of the animation quite slow. In my computer creating the GLContext takes 0.8
seconds. If the animation duration is less than the time it takes to create the GLContext, the animation ends
without iterating. This causing timeouts in the bots in tests like
animations/animation-iteration-event-destroy-renderer.html that expect webkitAnimationIteration events that
never fire.

* Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.cpp:
(WebKit::ThreadedCompositor::ThreadedCompositor): Create the GLContext right after the compositing thread is
created if we already have a native surface handle.
(WebKit::ThreadedCompositor::createGLContext): Helper to create the GLContext.
(WebKit::ThreadedCompositor::setNativeSurfaceHandleForCompositing): Create the GLContext when a native surface
handle is given.
(WebKit::ThreadedCompositor::makeContextCurrent): Deleted.
(WebKit::ThreadedCompositor::renderLayerTree): Make the context cunrrent directly here.
* Shared/CoordinatedGraphics/threadedcompositor/ThreadedCompositor.h:

2017-01-27 Carlos Garcia Campos <cgarcia@igalia.com>

[GTK] Stop forcing accelerated compositing by default
@@ -59,14 +59,33 @@ ThreadedCompositor::ThreadedCompositor(Client& client, const IntSize& viewportSi
{
m_compositingRunLoop->performTaskSync([this, protectedThis = makeRef(*this)] {
m_scene = adoptRef(new CoordinatedGraphicsScene(this));
m_scene->setActive(!!m_nativeSurfaceHandle);
if (m_nativeSurfaceHandle) {
createGLContext();
m_scene->setActive(true);
} else
m_scene->setActive(false);
});
}

ThreadedCompositor::~ThreadedCompositor()
{
}

void ThreadedCompositor::createGLContext()
{
ASSERT(!isMainThread());
ASSERT(m_nativeSurfaceHandle);

m_context = GLContext::createContextForWindow(reinterpret_cast<GLNativeWindowType>(m_nativeSurfaceHandle), &PlatformDisplay::sharedDisplayForCompositing());
if (!m_context)
return;

if (m_doFrameSync == ShouldDoFrameSync::No) {
if (m_context->makeContextCurrent())
m_context->swapInterval(0);
}
}

void ThreadedCompositor::invalidate()
{
m_scene->detach();
@@ -83,13 +102,16 @@ void ThreadedCompositor::setNativeSurfaceHandleForCompositing(uint64_t handle)
{
m_compositingRunLoop->stopUpdateTimer();
m_compositingRunLoop->performTaskSync([this, protectedThis = makeRef(*this), handle] {
m_scene->setActive(!!handle);

// A new native handle can't be set without destroying the previous one first if any.
ASSERT(!!handle ^ !!m_nativeSurfaceHandle);
m_nativeSurfaceHandle = handle;
if (!m_nativeSurfaceHandle)
if (m_nativeSurfaceHandle) {
createGLContext();
m_scene->setActive(true);
} else {
m_scene->setActive(false);
m_context = nullptr;
}
});
}

@@ -150,27 +172,6 @@ void ThreadedCompositor::scheduleDisplayImmediately()
m_compositingRunLoop->startUpdateTimer(CompositingRunLoop::Immediate);
}

bool ThreadedCompositor::makeContextCurrent()
{
if (m_context)
return m_context->makeContextCurrent();

if (!m_nativeSurfaceHandle)
return false;

m_context = GLContext::createContextForWindow(reinterpret_cast<GLNativeWindowType>(m_nativeSurfaceHandle), &PlatformDisplay::sharedDisplayForCompositing());
if (!m_context)
return false;

if (!m_context->makeContextCurrent())
return false;

if (m_doFrameSync == ShouldDoFrameSync::No)
m_context->swapInterval(0);

return true;
}

void ThreadedCompositor::forceRepaint()
{
m_compositingRunLoop->performTaskSync([this, protectedThis = makeRef(*this)] {
@@ -183,7 +184,7 @@ void ThreadedCompositor::renderLayerTree()
if (!m_scene || !m_scene->isActive())
return;

if (!makeContextCurrent())
if (!m_context || !m_context->makeContextCurrent())
return;

if (m_needsResize) {
@@ -84,7 +84,7 @@ class ThreadedCompositor : public CoordinatedGraphicsSceneClient, public ThreadS
void renderLayerTree();
void scheduleDisplayImmediately();

bool makeContextCurrent();
void createGLContext();

Client& m_client;
RefPtr<CoordinatedGraphicsScene> m_scene;

0 comments on commit 0ac612b

Please sign in to comment.