Backed out changeset af2af798ad8f (bug 1165710) for OS X 10.6 crashes
authorCarsten "Tomcat" Book <cbook@mozilla.com>
Tue, 26 May 2015 09:00:19 +0200
changeset 245633 dc683817edece10117f758c4274d5af3a2f57107
parent 245632 36f972c7df01753af0c4a34a8c6ad1831774593e
child 245634 af26700a02edb540ebfc0d1965fa71448c23bae0
push id28814
push userkwierso@gmail.com
push dateTue, 26 May 2015 23:16:29 +0000
treeherdermozilla-central@ff2e07228041 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs1165710
milestone41.0a1
backs outaf2af798ad8fcdaaefcc85a995f1d73689dcb922
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
Backed out changeset af2af798ad8f (bug 1165710) for OS X 10.6 crashes
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
@@ -127,28 +127,27 @@ DrawTargetSkia::DrawTargetSkia()
  mTexture(0),
 #endif
  mSnapshot(nullptr)
 {
 }
 
 DrawTargetSkia::~DrawTargetSkia()
 {
-  MarkChanged();
 }
 
 TemporaryRef<SourceSurface>
 DrawTargetSkia::Snapshot()
 {
   RefPtr<SourceSurfaceSkia> snapshot = mSnapshot;
   if (!snapshot) {
     snapshot = new SourceSurfaceSkia();
-    if (!snapshot->InitFromCanvas(mCanvas.get(), mFormat))
+    mSnapshot = snapshot;
+    if (!snapshot->InitFromCanvas(mCanvas.get(), mFormat, this))
       return nullptr;
-    mSnapshot = snapshot;
   }
 
   return snapshot.forget();
 }
 
 bool
 DrawTargetSkia::LockBits(uint8_t** aData, IntSize* aSize,
                           int32_t* aStride, SurfaceFormat* aFormat)
@@ -1004,10 +1003,16 @@ DrawTargetSkia::MarkChanged()
 // Return a rect (in user space) that covers the entire surface by applying
 // the inverse of GetTransform() to (0, 0, mSize.width, mSize.height).
 SkRect
 DrawTargetSkia::SkRectCoveringWholeSurface() const
 {
   return RectToSkRect(mTransform.TransformBounds(Rect(0, 0, mSize.width, mSize.height)));
 }
 
+void
+DrawTargetSkia::SnapshotDestroyed()
+{
+  mSnapshot = nullptr;
+}
+
 }
 }
--- a/gfx/2d/DrawTargetSkia.h
+++ b/gfx/2d/DrawTargetSkia.h
@@ -120,31 +120,32 @@ public:
   operator std::string() const {
     std::stringstream stream;
     stream << "DrawTargetSkia(" << this << ")";
     return stream.str();
   }
 
 private:
   friend class SourceSurfaceSkia;
+  void SnapshotDestroyed();
 
   void MarkChanged();
 
   bool ShouldLCDRenderText(FontType aFontType, AntialiasMode aAntialiasMode);
 
   SkRect SkRectCoveringWholeSurface() const;
 
   bool UsingSkiaGPU() const;
 
 #ifdef USE_SKIA_GPU
   RefPtrSkia<GrContext> mGrContext;
   uint32_t mTexture;
 #endif
 
   IntSize mSize;
   RefPtrSkia<SkCanvas> mCanvas;
-  RefPtr<SourceSurfaceSkia> mSnapshot;
+  SourceSurfaceSkia* mSnapshot;
 };
 
 }
 }
 
 #endif // _MOZILLA_GFX_SOURCESURFACESKIA_H
--- a/gfx/2d/SourceSurfaceSkia.cpp
+++ b/gfx/2d/SourceSurfaceSkia.cpp
@@ -12,51 +12,55 @@
 #include "DrawTargetSkia.h"
 #include "DataSurfaceHelpers.h"
 #include "skia/SkGrPixelRef.h"
 
 namespace mozilla {
 namespace gfx {
 
 SourceSurfaceSkia::SourceSurfaceSkia()
-  : mLocked(false)
-  , mBitmapDataOwned(false)
+  : mDrawTarget(nullptr), mLocked(false)
 {
 }
 
 SourceSurfaceSkia::~SourceSurfaceSkia()
 {
   MaybeUnlock();
+  if (mDrawTarget) {
+    mDrawTarget->SnapshotDestroyed();
+    mDrawTarget = nullptr;
+  }
 }
 
 IntSize
 SourceSurfaceSkia::GetSize() const
 {
   return mSize;
 }
 
 SurfaceFormat
 SourceSurfaceSkia::GetFormat() const
 {
   return mFormat;
 }
 
 bool
 SourceSurfaceSkia::InitFromCanvas(SkCanvas* aCanvas,
-                                  SurfaceFormat aFormat)
+                                  SurfaceFormat aFormat,
+                                  DrawTargetSkia* aOwner)
 {
   SkISize size = aCanvas->getDeviceSize();
 
   mBitmap = (SkBitmap)aCanvas->getDevice()->accessBitmap(false);
 
   mFormat = aFormat;
 
   mSize = IntSize(size.fWidth, size.fHeight);
   mStride = mBitmap.rowBytes();
-  mBitmapDataOwned = true;
+  mDrawTarget = aOwner;
 
   return true;
 }
 
 bool 
 SourceSurfaceSkia::InitFromData(unsigned char* aData,
                                 const IntSize &aSize,
                                 int32_t aStride,
@@ -106,16 +110,17 @@ SourceSurfaceSkia::InitFromTexture(DrawT
 
   GrTexture *skiaTexture = aOwner->mGrContext->wrapBackendTexture(skiaTexGlue);
   SkImageInfo imgInfo = SkImageInfo::Make(aSize.width, aSize.height, GfxFormatToSkiaColorType(aFormat), kOpaque_SkAlphaType);
   SkGrPixelRef *texRef = new SkGrPixelRef(imgInfo, skiaTexture, false);
   mBitmap.setInfo(imgInfo, aSize.width*aSize.height*4);
   mBitmap.setPixelRef(texRef);
 #endif
 
+  mDrawTarget = aOwner;
   return true;
 }
 
 unsigned char*
 SourceSurfaceSkia::GetData()
 {
   if (!mLocked) {
     mBitmap.lockPixels();
@@ -124,19 +129,20 @@ SourceSurfaceSkia::GetData()
 
   unsigned char *pixels = (unsigned char *)mBitmap.getPixels();
   return pixels;
 }
 
 void
 SourceSurfaceSkia::DrawTargetWillChange()
 {
-  if (mBitmapDataOwned) {
+  if (mDrawTarget) {
     MaybeUnlock();
 
+    mDrawTarget = nullptr;
     SkBitmap temp = mBitmap;
     mBitmap.reset();
     temp.copyTo(&mBitmap, temp.colorType());
   }
 }
 
 void
 SourceSurfaceSkia::MaybeUnlock()
--- a/gfx/2d/SourceSurfaceSkia.h
+++ b/gfx/2d/SourceSurfaceSkia.h
@@ -31,40 +31,42 @@ public:
   SkBitmap& GetBitmap() { return mBitmap; }
 
   bool InitFromData(unsigned char* aData,
                     const IntSize &aSize,
                     int32_t aStride,
                     SurfaceFormat aFormat);
 
   bool InitFromCanvas(SkCanvas* aCanvas,
-                      SurfaceFormat aFormat);
+                      SurfaceFormat aFormat,
+                      DrawTargetSkia* aOwner);
 
   /**
    * NOTE: While wrapping a Texture for SkiaGL, the texture *must* be created
    *       with the same GLcontext of DrawTargetSkia
    */
   bool InitFromTexture(DrawTargetSkia* aOwner,
                        unsigned int aTexture,
                        const IntSize &aSize,
                        SurfaceFormat aFormat);
 
   virtual unsigned char *GetData();
 
   virtual int32_t Stride() { return mStride; }
 
 private:
   friend class DrawTargetSkia;
+
   void DrawTargetWillChange();
   void MaybeUnlock();
 
   SkBitmap mBitmap;
   SurfaceFormat mFormat;
   IntSize mSize;
   int32_t mStride;
+  RefPtr<DrawTargetSkia> mDrawTarget;
   bool mLocked;
-  bool mBitmapDataOwned;
 };
 
 }
 }
 
 #endif /* MOZILLA_GFX_SOURCESURFACESKIA_H_ */