Creating a large number of WebGL contexts should recycle older contexts
https://bugs.webkit.org/show_bug.cgi?id=156689
<rdar://problem/19535330>
Patch by Antoine Quint <graouts@apple.com> on 2016-04-21
Reviewed by Dean Jackson.
Source/WebCore:
We used to stop creating WebGL contexts once a maximum of 64 WebGL contexts had been
created on a page. Other browsers have a limit of 16 concurrent active WebGL contexts
and they lose older contexts when the developer creates a new context, logging a warning
to the console. We now follow the same approach.
Tests: webgl/max-active-contexts-console-warning.html
webgl/max-active-contexts-gc.html
webgl/max-active-contexts-oldest-context-lost.html
webgl/max-active-contexts-webglcontextlost-prevent-default.html
* html/canvas/WebGLRenderingContextBase.cpp:
(WebCore::WebGLRenderingContextBase::recycleContext):
Prints a warning message to the console indicating that an older WebGL context
will be lost to accomodate for the active contexts limit being reached and loses
the provided context in a way that it may not be recovered by calling `event.preventDefault()`
in the `webglcontextlost` event handler. Finally, we destroy the associated GraphicsContext3D
since it will no longer be useful and it may hold large Open GL resources.
* html/canvas/WebGLRenderingContextBase.h:
* platform/graphics/GraphicsContext3D.h:
Changed GraphicsContext3D::create to return RefPtr instead of PassRefPtr.
* platform/graphics/cairo/GraphicsContext3DCairo.cpp:
(WebCore::GraphicsContext3D::create):
* platform/graphics/efl/GraphicsContext3DEfl.cpp:
(WebCore::GraphicsContext3D::create):
* platform/graphics/mac/GraphicsContext3DMac.mm:
(WebCore::activeContexts):
(WebCore::GraphicsContext3D::create):
Check if we are at the active contexts limit (16) and recycle the oldest context
in our active contexts list. Calling recycleContext() on a context will call the
GraphicsContext3D destructor and remove it from the active contexts list there.
(WebCore::GraphicsContext3D::~GraphicsContext3D):
Remove the deconstructed context from the active contexts list.
* platform/graphics/opengl/GraphicsContext3DOpenGLCommon.cpp:
(WebCore::GraphicsContext3D::recycleContext):
* platform/graphics/win/GraphicsContext3DWin.cpp:
(WebCore::GraphicsContext3D::create):
LayoutTests:
* webgl/many-contexts-expected.txt:
* webgl/many-contexts.html:
New output for this existing test since a lot of warnings are now logged to
indicate that we've reached the active contexts limit. We also removed the
check that the last context created was null since it no longer is due to this
source change (older contexts are lost instead).
* webgl/max-active-contexts-console-warning-expected.txt: Added.
* webgl/max-active-contexts-console-warning.html: Added.
This new test checks that we log a warning when we've created one context more
than the active contexts limit.
* webgl/max-active-contexts-gc-expected.txt: Added.
* webgl/max-active-contexts-gc.html: Added.
This new test checks that contexts that are garbage collected do not count
agaist the active contexts limit.
* webgl/max-active-contexts-oldest-context-lost-expected.txt: Added.
* webgl/max-active-contexts-oldest-context-lost.html: Added.
This new test checks that older contexts are lost when we reach the active
contexts limit and we create a new context.
* webgl/max-active-contexts-webglcontextlost-prevent-default-expected.txt: Added.
* webgl/max-active-contexts-webglcontextlost-prevent-default.html: Added.
This new test checks that calling `event.preventDefault()` in a `webglcontextlost`
event handler does not prevent a context from being lost when the active contexts
limit is reached.
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@199819 268f45cc-cd09-0410-ab3c-d52691b4dbfc
20 files changed