Bug 1449029. Moz2D Recording: Make Finish() return if any items. r=lsalzman
authorJeff Muizelaar <jmuizelaar@mozilla.com>
Tue, 20 Feb 2018 15:59:31 -0500
changeset 773614 c751156bf6d48fccea115931dcee147aec74ff40
parent 773613 9a145bccd8870c361551b11fa20ffda97c82bc31
child 773615 8b73ff00586c06cdbf61957c0c4b1d64178446e6
push id104266
push userbmo:hsivonen@hsivonen.fi
push dateWed, 28 Mar 2018 07:33:03 +0000
reviewerslsalzman
bugs1449029
milestone61.0a1
Bug 1449029. Moz2D Recording: Make Finish() return if any items. r=lsalzman Blob image invalidation will use will use this to avoid sending empty recordings. MozReview-Commit-ID: BlP5kqCbBys
gfx/2d/2D.h
gfx/2d/DrawEventRecorder.cpp
gfx/2d/DrawEventRecorder.h
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -1513,17 +1513,18 @@ public:
                                          Color& aColor,
                                          std::vector<Glyph>& aGlyphs) = 0;
 };
 
 class DrawEventRecorder : public RefCounted<DrawEventRecorder>
 {
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorder)
-  virtual void Finish() = 0;
+  // returns true if there were any items in the recording
+  virtual bool Finish() = 0;
   virtual ~DrawEventRecorder() { }
 };
 
 struct Tile
 {
   RefPtr<DrawTarget> mDrawTarget;
   IntPoint mTileOrigin;
 };
--- a/gfx/2d/DrawEventRecorder.cpp
+++ b/gfx/2d/DrawEventRecorder.cpp
@@ -111,26 +111,30 @@ DrawEventRecorderMemory::FlushItem(IntRe
   WriteElement(mIndex, aRect.x);
   WriteElement(mIndex, aRect.y);
   WriteElement(mIndex, aRect.XMost());
   WriteElement(mIndex, aRect.YMost());
   ClearResources();
   WriteHeader(mOutputStream);
 }
 
-void
+bool
 DrawEventRecorderMemory::Finish()
 {
+  // this length might be 0, and things should still work.
+  // for example if there are no items in a particular area
   size_t indexOffset = mOutputStream.mLength;
   // write out the index
   mOutputStream.write(mIndex.mData, mIndex.mLength);
+  bool hasItems = mIndex.mLength != 0;
   mIndex = MemStream();
   // write out the offset of the Index to the end of the output stream
   WriteElement(mOutputStream, indexOffset);
   ClearResources();
+  return hasItems;
 }
 
 
 size_t
 DrawEventRecorderMemory::RecordingSize()
 {
   return mOutputStream.mLength;
 }
--- a/gfx/2d/DrawEventRecorder.h
+++ b/gfx/2d/DrawEventRecorder.h
@@ -23,17 +23,17 @@ class PathRecording;
 
 class DrawEventRecorderPrivate : public DrawEventRecorder
 {
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawEventRecorderPrivate, override)
 
   DrawEventRecorderPrivate();
   virtual ~DrawEventRecorderPrivate() { }
-  virtual void Finish() override { ClearResources(); }
+  virtual bool Finish() override { ClearResources(); return true; }
   virtual void FlushItem(IntRect) { }
   void DetatchResources() {
     // The iteration is a bit awkward here because our iterator will
     // be invalidated by the removal
     for (auto font = mStoredFonts.begin(); font != mStoredFonts.end(); ) {
       auto oldFont = font++;
       (*oldFont)->RemoveUserData(reinterpret_cast<UserDataKey*>(this));
     }
@@ -184,17 +184,17 @@ public:
   size_t RecordingSize();
 
   /**
    * Wipes the internal recording buffer, but the recorder does NOT forget which
    * objects it has recorded. This can be used so that a recording can be copied
    * and processed in chunks, releasing memory as it goes.
    */
   void WipeRecording();
-  void Finish() override;
+  bool Finish() override;
   void FlushItem(IntRect) override;
 
   MemStream mOutputStream;
   /* The index stream is of the form:
    * ItemIndex { size_t dataEnd; size_t extraDataEnd; }
    * It gets concatenated to the end of mOutputStream in Finish()
    * The last size_t in the stream is offset of the begining of the
    * index.