Title: [168666] trunk
Revision
168666
Author
[email protected]
Date
2014-05-12 18:07:52 -0700 (Mon, 12 May 2014)

Log Message

Limit number of active graphics contexts per web process.
https://bugs.webkit.org/show_bug.cgi?id=132833.
<rdar://problem/16888459>

Reviewed by Dean Jackson.

Test: webgl/many-contexts.html

* platform/graphics/GraphicsContext3D.h:
* platform/graphics/mac/GraphicsContext3DMac.mm: Limit number of active contexts to 16.
(WebCore::GraphicsContext3D::create):
(WebCore::GraphicsContext3D::~GraphicsContext3D):
* webgl/many-contexts-expected.txt: Added.
* webgl/many-contexts.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (168665 => 168666)


--- trunk/LayoutTests/ChangeLog	2014-05-13 00:32:24 UTC (rev 168665)
+++ trunk/LayoutTests/ChangeLog	2014-05-13 01:07:52 UTC (rev 168666)
@@ -1,3 +1,14 @@
+2014-05-12  Roger Fong  <[email protected]>
+
+        Limit number of active graphics contexts per web process.
+        https://bugs.webkit.org/show_bug.cgi?id=132833.
+        <rdar://problem/16888459>
+
+        Reviewed by Dean Jackson.
+
+        * webgl/many-contexts-expected.txt: Added.
+        * webgl/many-contexts.html: Added.
+
 2014-05-12  Dirk Schulze  <[email protected]>
 
         <svg> with opacity and compositing double-applies its opacity

Added: trunk/LayoutTests/webgl/many-contexts-expected.txt (0 => 168666)


--- trunk/LayoutTests/webgl/many-contexts-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/webgl/many-contexts-expected.txt	2014-05-13 01:07:52 UTC (rev 168666)
@@ -0,0 +1 @@
+PASS if this test did not crash.

Added: trunk/LayoutTests/webgl/many-contexts.html (0 => 168666)


--- trunk/LayoutTests/webgl/many-contexts.html	                        (rev 0)
+++ trunk/LayoutTests/webgl/many-contexts.html	2014-05-13 01:07:52 UTC (rev 168666)
@@ -0,0 +1,18 @@
+<div id="result">PASS if this test did not crash and 1000th context was null.</div>
+<script>
+if (window.testRunner) {
+    testRunner.waitUntilDone();
+    testRunner.dumpAsText();
+    var size = 1000;
+    var canvii = new Array();
+    for (var i = 0; i < size; i++) {
+        canvii[i] = document.createElement("canvas");
+        canvii[i].width = 1;
+        canvii[i].height = 1;
+        var context = canvii[i].getContext("webgl", null);
+    }
+    if (canvii[1000] != null)
+        document.getElementById("result").innerHTML = "FAIL";
+    testRunner.notifyDone();
+}
+</script>

Modified: trunk/Source/WebCore/ChangeLog (168665 => 168666)


--- trunk/Source/WebCore/ChangeLog	2014-05-13 00:32:24 UTC (rev 168665)
+++ trunk/Source/WebCore/ChangeLog	2014-05-13 01:07:52 UTC (rev 168666)
@@ -1,3 +1,18 @@
+2014-05-12  Roger Fong  <[email protected]>
+
+        Limit number of active graphics contexts per web process.
+        https://bugs.webkit.org/show_bug.cgi?id=132833.
+        <rdar://problem/16888459>
+
+        Reviewed by Dean Jackson.
+
+        Test: webgl/many-contexts.html
+
+        * platform/graphics/GraphicsContext3D.h:
+        * platform/graphics/mac/GraphicsContext3DMac.mm: Limit number of active contexts to 16.
+        (WebCore::GraphicsContext3D::create):
+        (WebCore::GraphicsContext3D::~GraphicsContext3D):
+
 2014-05-12  Simon Fraser  <[email protected]>
 
         Build fix fix.

Modified: trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h (168665 => 168666)


--- trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h	2014-05-13 00:32:24 UTC (rev 168665)
+++ trunk/Source/WebCore/platform/graphics/GraphicsContext3D.h	2014-05-13 01:07:52 UTC (rev 168666)
@@ -968,6 +968,7 @@
 
 private:
     GraphicsContext3D(Attributes, HostWindow*, RenderStyle = RenderOffscreen);
+    static int numActiveContexts;
 
     // Helper for packImageData/extractImageData/extractTextureData which implement packing of pixel
     // data into the specified OpenGL destination format and type.

Modified: trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm (168665 => 168666)


--- trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm	2014-05-13 00:32:24 UTC (rev 168665)
+++ trunk/Source/WebCore/platform/graphics/mac/GraphicsContext3DMac.mm	2014-05-13 01:07:52 UTC (rev 168666)
@@ -61,6 +61,9 @@
 
 namespace WebCore {
 
+const int maxActiveContexts = 16;
+int GraphicsContext3D::numActiveContexts = 0;
+
 // FIXME: This class is currently empty on Mac, but will get populated as 
 // the restructuring in https://bugs.webkit.org/show_bug.cgi?id=66903 is done
 class GraphicsContext3DPrivate {
@@ -109,9 +112,19 @@
 {
     // This implementation doesn't currently support rendering directly to the HostWindow.
     if (renderStyle == RenderDirectlyToHostWindow)
-        return 0;
+        return nullptr;
+
+    if (numActiveContexts >= maxActiveContexts)
+        return nullptr;
+
     RefPtr<GraphicsContext3D> context = adoptRef(new GraphicsContext3D(attrs, hostWindow, renderStyle));
-    return context->m_contextObj ? context.release() : 0;
+
+    if (!context->m_contextObj)
+        return nullptr;
+
+    numActiveContexts++;
+
+    return context.release();
 }
 
 GraphicsContext3D::GraphicsContext3D(GraphicsContext3D::Attributes attrs, HostWindow* hostWindow, GraphicsContext3D::RenderStyle renderStyle)
@@ -319,6 +332,7 @@
         CGLSetCurrentContext(0);
         CGLDestroyContext(m_contextObj);
 #endif
+        numActiveContexts--;
     }
 }
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to