Bug 1176363 - Part 1: Make a raw copy of each Canvas::CaptureStream frame. r=mattwoodrow
authorAndreas Pehrson <pehrsons@gmail.com>
Thu, 16 Jul 2015 18:31:24 +0800
changeset 253491 1ece1edb6956bd13c4f62ca2ccefce518e1c245d
parent 253490 8e1b61112fbb126d25ca739fa99217230267fb50
child 253492 0d3ad656d93fa4e703b77c8906c2d7d6c46e4a71
push id29067
push userkwierso@gmail.com
push dateSat, 18 Jul 2015 00:57:04 +0000
treeherdermozilla-central@e2f2eb9ecca0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1176363
milestone42.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 1176363 - Part 1: Make a raw copy of each Canvas::CaptureStream frame. r=mattwoodrow
dom/media/CanvasCaptureMediaStream.cpp
--- a/dom/media/CanvasCaptureMediaStream.cpp
+++ b/dom/media/CanvasCaptureMediaStream.cpp
@@ -3,19 +3,20 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "CanvasCaptureMediaStream.h"
 #include "DOMMediaStream.h"
 #include "gfxPlatform.h"
 #include "ImageContainer.h"
 #include "MediaStreamGraph.h"
-#include "mozilla/Mutex.h"
 #include "mozilla/dom/CanvasCaptureMediaStreamBinding.h"
 #include "mozilla/dom/HTMLCanvasElement.h"
+#include "mozilla/gfx/2D.h"
+#include "mozilla/Mutex.h"
 #include "nsContentUtils.h"
 
 using namespace mozilla::layers;
 using namespace mozilla::gfx;
 
 namespace mozilla {
 namespace dom {
 
@@ -199,25 +200,52 @@ public:
     }
 
     // Pass `nullptr` to force alpha-premult.
     RefPtr<SourceSurface> snapshot = DOMStream()->Canvas()->GetSurfaceSnapshot(nullptr);
     if (!snapshot) {
       return NS_ERROR_FAILURE;
     }
 
-    RefPtr<SourceSurface> opt = gfxPlatform::GetPlatform()
-      ->ScreenReferenceDrawTarget()->OptimizeSourceSurface(snapshot);
-    if (!opt) {
+    RefPtr<DataSourceSurface> data = snapshot->GetDataSurface();
+    if (!data) {
       return NS_ERROR_FAILURE;
     }
 
+    RefPtr<DataSourceSurface> copy;
+
+    {
+      DataSourceSurface::ScopedMap read(data, DataSourceSurface::READ);
+      if (!read.IsMapped()) {
+        return NS_ERROR_FAILURE;
+      }
+
+      copy = Factory::CreateDataSourceSurfaceWithStride(data->GetSize(),
+                                                        data->GetFormat(),
+                                                        read.GetStride());
+      if (!copy) {
+        return NS_ERROR_FAILURE;
+      }
+
+      DataSourceSurface::ScopedMap write(copy, DataSourceSurface::WRITE);
+      if (!write.IsMapped()) {
+        return NS_ERROR_FAILURE;
+      }
+
+      MOZ_ASSERT(read.GetStride() == write.GetStride());
+      MOZ_ASSERT(data->GetSize() == copy->GetSize());
+      MOZ_ASSERT(data->GetFormat() == copy->GetFormat());
+
+      memcpy(write.GetData(), read.GetData(),
+             write.GetStride() * copy->GetSize().height);
+    }
+
     CairoImage::Data imageData;
-    imageData.mSize = opt->GetSize();
-    imageData.mSourceSurface = opt;
+    imageData.mSize = copy->GetSize();
+    imageData.mSourceSurface = copy;
 
     RefPtr<CairoImage> image = new layers::CairoImage();
     image->SetData(imageData);
 
     SetImage(image);
     return NS_OK;
   }