Bug 1176363 - Part 1: Make a raw copy of each Canvas::CaptureStream frame. r=mattwoodrow

This commit is contained in:
Andreas Pehrson 2015-07-16 18:31:24 +08:00
parent 0e03fb2f74
commit 0d32f24a50

View File

@ -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<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);