From 2853ef80682b9b8d3964492674e0a27fd59640e1 Mon Sep 17 00:00:00 2001 From: Bob Owen Date: Sun, 2 Dec 2018 14:17:24 +0000 Subject: [PATCH] Bug 1464032 Part 11: Make SourceSurface from DrawTargetRecording::CreateSourceSurfaceFromData hold its data. r=jrmuizel This means that GetData on the returned SourceSurface will function correctly. --- gfx/2d/DrawTargetRecording.cpp | 38 +++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/gfx/2d/DrawTargetRecording.cpp b/gfx/2d/DrawTargetRecording.cpp index 4f0121559368..b2608c4d3814 100644 --- a/gfx/2d/DrawTargetRecording.cpp +++ b/gfx/2d/DrawTargetRecording.cpp @@ -85,23 +85,33 @@ class DataSourceSurfaceRecording : public DataSourceSurface { public: MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceRecording, override) DataSourceSurfaceRecording(UniquePtr aData, IntSize aSize, - int32_t aStride, SurfaceFormat aFormat) + int32_t aStride, SurfaceFormat aFormat, + DrawEventRecorderPrivate* aRecorder) : mData(std::move(aData)), mSize(aSize), mStride(aStride), - mFormat(aFormat) {} + mFormat(aFormat), + mRecorder(aRecorder) { + mRecorder->RecordEvent(RecordedSourceSurfaceCreation( + ReferencePtr(this), mData.get(), mStride, mSize, mFormat)); + mRecorder->AddStoredObject(this); + } - ~DataSourceSurfaceRecording() {} + ~DataSourceSurfaceRecording() { + mRecorder->RemoveStoredObject(this); + mRecorder->RecordEvent( + RecordedSourceSurfaceDestruction(ReferencePtr(this))); + } - static already_AddRefed Init(uint8_t* aData, IntSize aSize, - int32_t aStride, - SurfaceFormat aFormat) { + static already_AddRefed Init( + uint8_t* aData, IntSize aSize, int32_t aStride, SurfaceFormat aFormat, + DrawEventRecorderPrivate* aRecorder) { // XXX: do we need to ensure any alignment here? auto data = MakeUnique(aStride * aSize.height); if (data) { memcpy(data.get(), aData, aStride * aSize.height); RefPtr surf = new DataSourceSurfaceRecording( - std::move(data), aSize, aStride, aFormat); + std::move(data), aSize, aStride, aFormat, aRecorder); return surf.forget(); } return nullptr; @@ -117,6 +127,7 @@ class DataSourceSurfaceRecording : public DataSourceSurface { IntSize mSize; int32_t mStride; SurfaceFormat mFormat; + RefPtr mRecorder; }; class GradientStopsRecording : public GradientStops { @@ -486,16 +497,9 @@ DrawTargetRecording::CreateSourceSurfaceFromData(unsigned char* aData, const IntSize& aSize, int32_t aStride, SurfaceFormat aFormat) const { - RefPtr surf = - DataSourceSurfaceRecording::Init(aData, aSize, aStride, aFormat); - - RefPtr retSurf = - new SourceSurfaceRecording(aSize, aFormat, mRecorder); - - mRecorder->RecordEvent( - RecordedSourceSurfaceCreation(retSurf, aData, aStride, aSize, aFormat)); - - return retSurf.forget(); + RefPtr surf = DataSourceSurfaceRecording::Init( + aData, aSize, aStride, aFormat, mRecorder); + return surf.forget(); } already_AddRefed DrawTargetRecording::OptimizeSourceSurface(