Bug 1291033 (Part 2) - Ensure atomicity of ISurfaceProvider locking changes. r=dholbert
authorSeth Fowler <mark.seth.fowler@gmail.com>
Mon, 01 Aug 2016 16:28:06 -0700
changeset 308322 f0725e82f2869baeb01cb86b8aa6bece0ca26cd6
parent 308321 4a2a5e36e0d32612f4ac7c488300cc9800886032
child 308323 d320ef56876f52db9bc0eb79554c7332d4793769
child 308351 f67a96475ab179eae558a36ae8b6cd77e42eb910
push id31092
push usercbook@mozilla.com
push dateFri, 05 Aug 2016 10:16:59 +0000
treeherderautoland@b97dd7dd3cb9 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdholbert
bugs1291033
milestone51.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 1291033 (Part 2) - Ensure atomicity of ISurfaceProvider locking changes. r=dholbert
image/ISurfaceProvider.h
--- a/image/ISurfaceProvider.h
+++ b/image/ISurfaceProvider.h
@@ -18,16 +18,18 @@
 #include "mozilla/gfx/2D.h"
 
 #include "imgFrame.h"
 #include "SurfaceCache.h"
 
 namespace mozilla {
 namespace image {
 
+class CachedSurface;
+
 /**
  * An interface for objects which can either store a surface or dynamically
  * generate one.
  */
 class ISurfaceProvider
 {
 public:
   // Subclasses may or may not be XPCOM classes, so we just require that they
@@ -36,23 +38,16 @@ public:
   NS_IMETHOD_(MozExternalRefCountType) Release() = 0;
 
   /// @return a drawable reference to a surface.
   virtual DrawableFrameRef DrawableRef() = 0;
 
   /// @return true if DrawableRef() will return a completely decoded surface.
   virtual bool IsFinished() const = 0;
 
-  /// @return true if this ISurfaceProvider is locked. (@see SetLocked())
-  virtual bool IsLocked() const = 0;
-
-  /// If @aLocked is true, hint that this ISurfaceProvider is in use and it
-  /// should avoid releasing its resources.
-  virtual void SetLocked(bool aLocked) = 0;
-
   /// @return the number of bytes of memory this ISurfaceProvider is expected to
   /// require. Optimizations may result in lower real memory usage. Trivial
   /// overhead is ignored.
   virtual size_t LogicalSizeInBytes() const = 0;
 
   /// @return the availability state of this ISurfaceProvider, which indicates
   /// whether DrawableRef() could successfully return a surface. Should only be
   /// called from SurfaceCache code as it relies on SurfaceCache for
@@ -62,17 +57,29 @@ public:
 
 protected:
   explicit ISurfaceProvider(AvailabilityState aAvailability)
     : mAvailability(aAvailability)
   { }
 
   virtual ~ISurfaceProvider() { }
 
+  /// @return true if this ISurfaceProvider is locked. (@see SetLocked())
+  /// Should only be called from SurfaceCache code as it relies on SurfaceCache
+  /// for synchronization.
+  virtual bool IsLocked() const = 0;
+
+  /// If @aLocked is true, hint that this ISurfaceProvider is in use and it
+  /// should avoid releasing its resources. Should only be called from
+  /// SurfaceCache code as it relies on SurfaceCache for synchronization.
+  virtual void SetLocked(bool aLocked) = 0;
+
 private:
+  friend class CachedSurface;
+
   AvailabilityState mAvailability;
 };
 
 /**
  * An ISurfaceProvider that stores a single surface.
  */
 class SimpleSurfaceProvider final : public ISurfaceProvider
 {
@@ -81,36 +88,38 @@ public:
 
   explicit SimpleSurfaceProvider(NotNull<imgFrame*> aSurface)
     : ISurfaceProvider(AvailabilityState::StartAvailable())
     , mSurface(aSurface)
   { }
 
   DrawableFrameRef DrawableRef() override { return mSurface->DrawableRef(); }
   bool IsFinished() const override { return mSurface->IsFinished(); }
+
+  size_t LogicalSizeInBytes() const override
+  {
+    gfx::IntSize size = mSurface->GetSize();
+    return size.width * size.height * mSurface->GetBytesPerPixel();
+  }
+
+protected:
   bool IsLocked() const override { return bool(mLockRef); }
 
   void SetLocked(bool aLocked) override
   {
     if (aLocked == IsLocked()) {
       return;  // Nothing changed.
     }
 
     // If we're locked, hold a DrawableFrameRef to |mSurface|, which will keep
     // any volatile buffer it owns in memory.
     mLockRef = aLocked ? mSurface->DrawableRef()
                        : DrawableFrameRef();
   }
 
-  size_t LogicalSizeInBytes() const override
-  {
-    gfx::IntSize size = mSurface->GetSize();
-    return size.width * size.height * mSurface->GetBytesPerPixel();
-  }
-
 private:
   virtual ~SimpleSurfaceProvider() { }
 
   NotNull<RefPtr<imgFrame>> mSurface;
   DrawableFrameRef mLockRef;
 };
 
 } // namespace image