Bug 1464032 Part 11: Make SourceSurface from DrawTargetRecording::CreateSourceSurfaceFromData hold its data. r=jrmuizel
authorBob Owen <bobowencode@gmail.com>
Sun, 02 Dec 2018 14:17:24 +0000
changeset 477807 e32d6c3ba88775579562d9d1f27098306b7bfbb0
parent 477806 04067aec22bb2f8da87a34893c99e2195efd0b8c
child 477808 4357d695b8d5dd901788d922b73e89f16c45b2c9
push id36124
push userdvarga@mozilla.com
push dateFri, 07 Jun 2019 16:20:31 +0000
treeherdermozilla-central@bee3a910397d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1464032
milestone69.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 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
--- a/gfx/2d/DrawTargetRecording.cpp
+++ b/gfx/2d/DrawTargetRecording.cpp
@@ -80,48 +80,59 @@ class SourceSurfaceRecording : public So
   SurfaceFormat mFormat;
   RefPtr<DrawEventRecorderPrivate> mRecorder;
 };
 
 class DataSourceSurfaceRecording : public DataSourceSurface {
  public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DataSourceSurfaceRecording, override)
   DataSourceSurfaceRecording(UniquePtr<uint8_t[]> 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) {}
-
-  ~DataSourceSurfaceRecording() {}
+        mFormat(aFormat),
+        mRecorder(aRecorder) {
+    mRecorder->RecordEvent(RecordedSourceSurfaceCreation(
+        ReferencePtr(this), mData.get(), mStride, mSize, mFormat));
+    mRecorder->AddStoredObject(this);
+  }
 
-  static already_AddRefed<DataSourceSurface> Init(uint8_t* aData, IntSize aSize,
-                                                  int32_t aStride,
-                                                  SurfaceFormat aFormat) {
+  ~DataSourceSurfaceRecording() {
+    mRecorder->RemoveStoredObject(this);
+    mRecorder->RecordEvent(
+        RecordedSourceSurfaceDestruction(ReferencePtr(this)));
+  }
+
+  static already_AddRefed<DataSourceSurface> 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<uint8_t[]>(aStride * aSize.height);
     if (data) {
       memcpy(data.get(), aData, aStride * aSize.height);
       RefPtr<DataSourceSurfaceRecording> surf = new DataSourceSurfaceRecording(
-          std::move(data), aSize, aStride, aFormat);
+          std::move(data), aSize, aStride, aFormat, aRecorder);
       return surf.forget();
     }
     return nullptr;
   }
 
   SurfaceType GetType() const override { return SurfaceType::RECORDING; }
   IntSize GetSize() const override { return mSize; }
   int32_t Stride() override { return mStride; }
   SurfaceFormat GetFormat() const override { return mFormat; }
   uint8_t* GetData() override { return mData.get(); }
 
   UniquePtr<uint8_t[]> mData;
   IntSize mSize;
   int32_t mStride;
   SurfaceFormat mFormat;
+  RefPtr<DrawEventRecorderPrivate> mRecorder;
 };
 
 class GradientStopsRecording : public GradientStops {
  public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(GradientStopsRecording, override)
 
   explicit GradientStopsRecording(DrawEventRecorderPrivate* aRecorder)
       : mRecorder(aRecorder) {
@@ -481,26 +492,19 @@ void DrawTargetRecording::PopLayer() {
   mRecorder->RecordEvent(RecordedPopLayer(static_cast<DrawTarget*>(this)));
 }
 
 already_AddRefed<SourceSurface>
 DrawTargetRecording::CreateSourceSurfaceFromData(unsigned char* aData,
                                                  const IntSize& aSize,
                                                  int32_t aStride,
                                                  SurfaceFormat aFormat) const {
-  RefPtr<SourceSurface> surf =
-      DataSourceSurfaceRecording::Init(aData, aSize, aStride, aFormat);
-
-  RefPtr<SourceSurface> retSurf =
-      new SourceSurfaceRecording(aSize, aFormat, mRecorder);
-
-  mRecorder->RecordEvent(
-      RecordedSourceSurfaceCreation(retSurf, aData, aStride, aSize, aFormat));
-
-  return retSurf.forget();
+  RefPtr<SourceSurface> surf = DataSourceSurfaceRecording::Init(
+      aData, aSize, aStride, aFormat, mRecorder);
+  return surf.forget();
 }
 
 already_AddRefed<SourceSurface> DrawTargetRecording::OptimizeSourceSurface(
     SourceSurface* aSurface) const {
   RefPtr<SourceSurface> surf(aSurface);
   return surf.forget();
 }