Bug 881634 - Backout 1c39ca9daa6c for causing bug 911502. a=bajaj CLOSED TREE
authorMatt Woodrow <mwoodrow@mozilla.com>
Tue, 10 Sep 2013 11:33:57 +1200
changeset 148539 59babbe186711fd183736983c65fa1f6c0524ce5
parent 148538 1093a29a5a3e96a458d734ab710649ec29077b49
child 148540 0e12cf5c9bc986a7c6d54705049bc508b42af16c
child 148542 260fcd9e23a367cea5ca92fc157064edd7630d2a
child 148544 36c11828950ab3bb1e7e14bc9c3f5fd7020cabec
child 148546 cb5b1d8e602abdc8b62b4144f291ffd2964cce86
push id2850
push usermwoodrow@mozilla.com
push dateMon, 09 Sep 2013 23:47:00 +0000
treeherdermozilla-beta@59babbe18671 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbajaj
bugs881634, 911502
milestone24.0
Bug 881634 - Backout 1c39ca9daa6c for causing bug 911502. a=bajaj CLOSED TREE
gfx/2d/DrawTargetSkia.cpp
gfx/2d/DrawTargetSkia.h
gfx/2d/SourceSurfaceSkia.cpp
gfx/2d/SourceSurfaceSkia.h
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -75,36 +75,41 @@ public:
 
   std::vector<SkColor> mColors;
   std::vector<SkScalar> mPositions;
   int mCount;
   ExtendMode mExtendMode;
 };
 
 DrawTargetSkia::DrawTargetSkia()
-  : mSnapshot(nullptr)
 {
 }
 
 DrawTargetSkia::~DrawTargetSkia()
 {
+  if (mSnapshots.size()) {
+    for (std::vector<SourceSurfaceSkia*>::iterator iter = mSnapshots.begin();
+         iter != mSnapshots.end(); iter++) {
+      (*iter)->DrawTargetDestroyed();
+    }
+    // All snapshots will now have copied data.
+    mSnapshots.clear();
+  }
 }
 
 TemporaryRef<SourceSurface>
 DrawTargetSkia::Snapshot()
 {
-  RefPtr<SourceSurfaceSkia> snapshot = mSnapshot;
-  if (!snapshot) {
-    snapshot = new SourceSurfaceSkia();
-    mSnapshot = snapshot;
-    if (!snapshot->InitFromCanvas(mCanvas.get(), mFormat, this))
-      return nullptr;
-  }
+  RefPtr<SourceSurfaceSkia> source = new SourceSurfaceSkia();
 
-  return snapshot;
+  if (!source->InitFromCanvas(mCanvas.get(), mFormat, this))
+    return nullptr;
+
+  AppendSnapshot(source);
+  return source;
 }
 
 void SetPaintPattern(SkPaint& aPaint, const Pattern& aPattern, Float aAlpha = 1.0)
 {
   switch (aPattern.GetType()) {
     case PATTERN_COLOR: {
       Color color = static_cast<const ColorPattern&>(aPattern).mColor;
       aPaint.setColor(ColorToSkColor(color, aAlpha));
@@ -709,24 +714,37 @@ DrawTargetSkia::CreateGradientStops(Grad
     stops[i] = aStops[i];
   }
   std::stable_sort(stops.begin(), stops.end());
   
   return new GradientStopsSkia(stops, aNumStops, aExtendMode);
 }
 
 void
-DrawTargetSkia::MarkChanged()
+DrawTargetSkia::AppendSnapshot(SourceSurfaceSkia* aSnapshot)
 {
-  if (mSnapshot) {
-    mSnapshot->DrawTargetWillChange();
-    mSnapshot = nullptr;
+  mSnapshots.push_back(aSnapshot);
+}
+
+void
+DrawTargetSkia::RemoveSnapshot(SourceSurfaceSkia* aSnapshot)
+{
+  std::vector<SourceSurfaceSkia*>::iterator iter = std::find(mSnapshots.begin(), mSnapshots.end(), aSnapshot);
+  if (iter != mSnapshots.end()) {
+    mSnapshots.erase(iter);
   }
 }
 
 void
-DrawTargetSkia::SnapshotDestroyed()
+DrawTargetSkia::MarkChanged()
 {
-  mSnapshot = nullptr;
+  if (mSnapshots.size()) {
+    for (std::vector<SourceSurfaceSkia*>::iterator iter = mSnapshots.begin();
+         iter != mSnapshots.end(); iter++) {
+      (*iter)->DrawTargetWillChange();
+    }
+    // All snapshots will now have copied data.
+    mSnapshots.clear();
+  }
 }
 
 }
 }
--- a/gfx/2d/DrawTargetSkia.h
+++ b/gfx/2d/DrawTargetSkia.h
@@ -104,19 +104,20 @@ public:
   operator std::string() const {
     std::stringstream stream;
     stream << "DrawTargetSkia(" << this << ")";
     return stream.str();
   }
 
 private:
   friend class SourceSurfaceSkia;
-  void SnapshotDestroyed();
+  void AppendSnapshot(SourceSurfaceSkia* aSnapshot);
+  void RemoveSnapshot(SourceSurfaceSkia* aSnapshot);
 
   void MarkChanged();
 
   IntSize mSize;
   SkRefPtr<SkCanvas> mCanvas;
-  SourceSurfaceSkia* mSnapshot;
+  std::vector<SourceSurfaceSkia*> mSnapshots;
 };
 
 }
 }
--- a/gfx/2d/SourceSurfaceSkia.cpp
+++ b/gfx/2d/SourceSurfaceSkia.cpp
@@ -17,20 +17,17 @@ namespace gfx {
 SourceSurfaceSkia::SourceSurfaceSkia()
   : mDrawTarget(nullptr), mLocked(false)
 {
 }
 
 SourceSurfaceSkia::~SourceSurfaceSkia()
 {
   MaybeUnlock();
-  if (mDrawTarget) {
-    mDrawTarget->SnapshotDestroyed();
-    mDrawTarget = nullptr;
-  }
+  MarkIndependent();
 }
 
 IntSize
 SourceSurfaceSkia::GetSize() const
 {
   return mSize;
 }
 
@@ -107,16 +104,31 @@ SourceSurfaceSkia::DrawTargetWillChange(
     mDrawTarget = nullptr;
     SkBitmap temp = mBitmap;
     mBitmap.reset();
     temp.copyTo(&mBitmap, temp.getConfig());
   }
 }
 
 void
+SourceSurfaceSkia::DrawTargetDestroyed()
+{
+  mDrawTarget = nullptr;
+}
+
+void
+SourceSurfaceSkia::MarkIndependent()
+{
+  if (mDrawTarget) {
+    mDrawTarget->RemoveSnapshot(this);
+    mDrawTarget = nullptr;
+  }
+}
+
+void
 SourceSurfaceSkia::MaybeUnlock()
 {
   if (mLocked) {
     mBitmap.unlockPixels();
     mLocked = false;
   }
 }
 
--- a/gfx/2d/SourceSurfaceSkia.h
+++ b/gfx/2d/SourceSurfaceSkia.h
@@ -40,22 +40,24 @@ public:
   virtual unsigned char *GetData();
 
   virtual int32_t Stride() { return mStride; }
 
 private:
   friend class DrawTargetSkia;
 
   void DrawTargetWillChange();
+  void DrawTargetDestroyed();
+  void MarkIndependent();
   void MaybeUnlock();
 
   SkBitmap mBitmap;
   SurfaceFormat mFormat;
   IntSize mSize;
   int32_t mStride;
-  RefPtr<DrawTargetSkia> mDrawTarget;
+  DrawTargetSkia* mDrawTarget;
   bool mLocked;
 };
 
 }
 }
 
 #endif /* MOZILLA_GFX_SOURCESURFACESKIA_H_ */