From ba79b7b3e484974ae6d1949ff5dc3489b37b8399 Mon Sep 17 00:00:00 2001 From: Andreas Pehrson Date: Mon, 6 Jul 2015 11:49:32 +0800 Subject: [PATCH] Bug 1176363 - Make a raw copy of each Canvas::CaptureStream frame. r=mattwoodrow --HG-- extra : rebase_source : 0658dae3991f6839d93aa3a7d4165330307b74a5 --- dom/media/CanvasCaptureMediaStream.cpp | 40 ++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 6 deletions(-) diff --git a/dom/media/CanvasCaptureMediaStream.cpp b/dom/media/CanvasCaptureMediaStream.cpp index d8f06b790e60..c46134e78a4e 100644 --- a/dom/media/CanvasCaptureMediaStream.cpp +++ b/dom/media/CanvasCaptureMediaStream.cpp @@ -8,9 +8,10 @@ #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; @@ -204,15 +205,42 @@ public: return NS_ERROR_FAILURE; } - RefPtr opt = gfxPlatform::GetPlatform() - ->ScreenReferenceDrawTarget()->OptimizeSourceSurface(snapshot); - if (!opt) { + RefPtr data = snapshot->GetDataSurface(); + if (!data) { return NS_ERROR_FAILURE; } + RefPtr 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 image = new layers::CairoImage(); image->SetData(imageData);