Bug 683803 - [OOPP] Add a 60 FPS Cap to throttle plugin drawing. r=cjones
authorBenoit Girard <b56girard@gmail.com>
Wed, 07 Sep 2011 16:18:42 -0400
changeset 77229 ef007a375b3475e4f622b06453affcaba41a0f85
parent 77228 f98f144896ad67aa57e737b8b74eaa95d42ad711
child 77230 a72195ce0eaa20bbc1fcf5c8e98c6b64044b972b
push id21187
push usermak77@bonardo.net
push dateWed, 21 Sep 2011 08:36:41 +0000
treeherdermozilla-central@3178f1c42505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs683803
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 683803 - [OOPP] Add a 60 FPS Cap to throttle plugin drawing. r=cjones
dom/plugins/ipc/PluginInstanceChild.cpp
layout/base/tests/test_flush_on_paint.html
--- a/dom/plugins/ipc/PluginInstanceChild.cpp
+++ b/dom/plugins/ipc/PluginInstanceChild.cpp
@@ -3347,16 +3347,26 @@ PluginInstanceChild::InvalidateRectDelay
 
     mCurrentInvalidateTask = nsnull;
     if (mAccumulatedInvalidRect.IsEmpty()) {
         return;
     }
 
     if (!ShowPluginFrame()) {
         AsyncShowPluginFrame();
+    } else if (!mCurrentInvalidateTask) {
+        // We have just painted a frame. Prepare a delayed mCurrentInvalidateTask
+        // task 15ms from now. This will cause any invalidate rect calls to
+        // accumulate. If none are made during this time the task will do
+        // nothing on an empty mAccumulatedInvalidRect.
+        // See bug 683803
+        mCurrentInvalidateTask =
+            NewRunnableMethod(this, &PluginInstanceChild::InvalidateRectDelayed);
+        MessageLoop::current()->PostDelayedTask(
+            FROM_HERE, mCurrentInvalidateTask, 15);
     }
 }
 
 void
 PluginInstanceChild::AsyncShowPluginFrame(void)
 {
     if (mCurrentInvalidateTask) {
         return;
--- a/layout/base/tests/test_flush_on_paint.html
+++ b/layout/base/tests/test_flush_on_paint.html
@@ -15,48 +15,41 @@
 SimpleTest.waitForExplicitFinish();
 
 var iterations = 0;
 var plugin = document.getElementById("plugin");
 var lastPaintCount;
 var expectedWidth;
 
 var toggle = true;
-function invalidationLoop() {
-  toggle = !toggle;
-  var color = toggle ? "8F" : "00";
-  plugin.setColor("FFFFFF" + color);
-  setTimeout(invalidationLoop, 20);
-}
-invalidationLoop();
 
 function doIteration() {
   lastPaintCount = window.mozPaintCount;
   ok(true, "Beginning iteration " + iterations + ", last paint count: " + lastPaintCount);
 
   expectedWidth = 201 + iterations;
   plugin.style.width = expectedWidth + "px";
-  checkDone();
+  setTimeout(checkDone, 60);
 }
 
 function checkDone() {
   ok(true, "Check to see if we're done: " + window.mozPaintCount);
   if (window.mozPaintCount == lastPaintCount) {
     setTimeout(checkDone, 30);
     return;
   }
 
   netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
   var utils = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
                  getInterface(Components.interfaces.nsIDOMWindowUtils);
   is(plugin.getWidthAtLastPaint(), utils.screenPixelsPerCSSPixel*expectedWidth,
      "Check that we set width before painting");
 
   ++iterations;
-  if (iterations < 100) {
+  if (iterations < 25) {
     doIteration();
   } else {
     SimpleTest.finish();
   }
 }
 </script>
 </pre>
 </body>