Bug 1381180 - Refactor out StrokeOptions from DrawCommands. r=dvander
authorMason Chang <mchang@mozilla.com>
Thu, 20 Jul 2017 13:14:51 -0700
changeset 418714 b25d6223cf67202d09930defbf08e6bacb60fc4d
parent 418713 dbb63faa7da342f7e55ab65c33e905dafd5b7295
child 418715 ea67db1628e0ad1f96bd67fc9f28197cecb71561
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs1381180
milestone56.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 1381180 - Refactor out StrokeOptions from DrawCommands. r=dvander
gfx/2d/DrawCommand.h
--- a/gfx/2d/DrawCommand.h
+++ b/gfx/2d/DrawCommand.h
@@ -56,16 +56,41 @@ protected:
     : mType(aType)
   {
   }
 
 private:
   CommandType mType;
 };
 
+class StrokeOptionsCommand : public DrawingCommand
+{
+public:
+  StrokeOptionsCommand(CommandType aType,
+                       const StrokeOptions& aStrokeOptions)
+    : DrawingCommand(aType)
+    , mStrokeOptions(aStrokeOptions)
+  {
+    // Stroke Options dashes are owned by the caller.
+    // Have to copy them here so they don't get freed
+    // between now and replay.
+    if (aStrokeOptions.mDashLength) {
+      mDashes.resize(aStrokeOptions.mDashLength);
+      mStrokeOptions.mDashPattern = &mDashes.front();
+      PodCopy(&mDashes.front(), aStrokeOptions.mDashPattern, mStrokeOptions.mDashLength);
+    }
+  }
+
+  virtual ~StrokeOptionsCommand() {}
+
+protected:
+  StrokeOptions mStrokeOptions;
+  std::vector<Float> mDashes;
+};
+
 class StoredPattern
 {
 public:
   explicit StoredPattern(const Pattern& aPattern)
   {
     Assign(aPattern);
   }
 
@@ -247,86 +272,67 @@ public:
   }
 
 private:
   Rect mRect;
   StoredPattern mPattern;
   DrawOptions mOptions;
 };
 
-class StrokeRectCommand : public DrawingCommand
+class StrokeRectCommand : public StrokeOptionsCommand
 {
 public:
   StrokeRectCommand(const Rect& aRect,
                     const Pattern& aPattern,
                     const StrokeOptions& aStrokeOptions,
                     const DrawOptions& aOptions)
-    : DrawingCommand(CommandType::STROKERECT)
+    : StrokeOptionsCommand(CommandType::STROKERECT, aStrokeOptions)
     , mRect(aRect)
     , mPattern(aPattern)
-    , mStrokeOptions(aStrokeOptions)
     , mOptions(aOptions)
   {
-    if (aStrokeOptions.mDashLength) {
-      mDashes.resize(aStrokeOptions.mDashLength);
-      mStrokeOptions.mDashPattern = &mDashes.front();
-      memcpy(&mDashes.front(), aStrokeOptions.mDashPattern, mStrokeOptions.mDashLength * sizeof(Float));
-    }
   }
 
   virtual void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const
   {
     aDT->StrokeRect(mRect, mPattern, mStrokeOptions, mOptions);
   }
 
 private:
   Rect mRect;
   StoredPattern mPattern;
-  StrokeOptions mStrokeOptions;
   DrawOptions mOptions;
-  std::vector<Float> mDashes;
 };
 
-class StrokeLineCommand : public DrawingCommand
+class StrokeLineCommand : public StrokeOptionsCommand
 {
 public:
   StrokeLineCommand(const Point& aStart,
                     const Point& aEnd,
                     const Pattern& aPattern,
                     const StrokeOptions& aStrokeOptions,
                     const DrawOptions& aOptions)
-    : DrawingCommand(CommandType::STROKELINE)
+    : StrokeOptionsCommand(CommandType::STROKELINE, aStrokeOptions)
     , mStart(aStart)
     , mEnd(aEnd)
     , mPattern(aPattern)
-    , mStrokeOptions(aStrokeOptions)
     , mOptions(aOptions)
   {
-    // Stroke Options dashes are owned by the caller.
-    // Have to copy them here so they don't get freed
-    // between now and replay.
-    if (aStrokeOptions.mDashLength) {
-      mDashes.resize(aStrokeOptions.mDashLength);
-      mStrokeOptions.mDashPattern = &mDashes.front();
-      memcpy(&mDashes.front(), aStrokeOptions.mDashPattern, mStrokeOptions.mDashLength * sizeof(Float));
-    }
   }
 
   virtual void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const
   {
     aDT->StrokeLine(mStart, mEnd, mPattern, mStrokeOptions, mOptions);
   }
 
 private:
   Point mStart;
   Point mEnd;
   StoredPattern mPattern;
-  StrokeOptions mStrokeOptions;
   DrawOptions mOptions;
-  std::vector<Float> mDashes;
 };
 
 class FillCommand : public DrawingCommand
 {
 public:
   FillCommand(const Path* aPath,
               const Pattern& aPattern,
               const DrawOptions& aOptions)
@@ -389,53 +395,46 @@ PathExtentsToMaxStrokeExtents(const Stro
   dx = ceil(dx);
   dy = ceil(dy);
 
   Rect result = aRect;
   result.Inflate(dx, dy);
   return result;
 }
 
-class StrokeCommand : public DrawingCommand
+
+class StrokeCommand : public StrokeOptionsCommand
 {
 public:
   StrokeCommand(const Path* aPath,
                 const Pattern& aPattern,
                 const StrokeOptions& aStrokeOptions,
                 const DrawOptions& aOptions)
-    : DrawingCommand(CommandType::STROKE)
+    : StrokeOptionsCommand(CommandType::STROKE, aStrokeOptions)
     , mPath(const_cast<Path*>(aPath))
     , mPattern(aPattern)
-    , mStrokeOptions(aStrokeOptions)
     , mOptions(aOptions)
   {
-    if (aStrokeOptions.mDashLength) {
-      mDashes.resize(aStrokeOptions.mDashLength);
-      mStrokeOptions.mDashPattern = &mDashes.front();
-      memcpy(&mDashes.front(), aStrokeOptions.mDashPattern, mStrokeOptions.mDashLength * sizeof(Float));
-    }
   }
 
   virtual void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const
   {
     aDT->Stroke(mPath, mPattern, mStrokeOptions, mOptions);
   }
 
   bool GetAffectedRect(Rect& aDeviceRect, const Matrix& aTransform) const
   {
     aDeviceRect = PathExtentsToMaxStrokeExtents(mStrokeOptions, mPath->GetBounds(aTransform), aTransform);
     return true;
   }
 
 private:
   RefPtr<Path> mPath;
   StoredPattern mPattern;
-  StrokeOptions mStrokeOptions;
   DrawOptions mOptions;
-  std::vector<Float> mDashes;
 };
 
 class FillGlyphsCommand : public DrawingCommand
 {
   friend class DrawTargetCaptureImpl;
 public:
   FillGlyphsCommand(ScaledFont* aFont,
                     const GlyphBuffer& aBuffer,
@@ -463,59 +462,50 @@ public:
 private:
   RefPtr<ScaledFont> mFont;
   std::vector<Glyph> mGlyphs;
   StoredPattern mPattern;
   DrawOptions mOptions;
   RefPtr<GlyphRenderingOptions> mRenderingOptions;
 };
 
-class StrokeGlyphsCommand : public DrawingCommand
+class StrokeGlyphsCommand : public StrokeOptionsCommand
 {
   friend class DrawTargetCaptureImpl;
 public:
   StrokeGlyphsCommand(ScaledFont* aFont,
                       const GlyphBuffer& aBuffer,
                       const Pattern& aPattern,
                       const StrokeOptions& aStrokeOptions,
                       const DrawOptions& aOptions,
                       const GlyphRenderingOptions* aRenderingOptions)
-    : DrawingCommand(CommandType::STROKEGLYPHS)
+    : StrokeOptionsCommand(CommandType::STROKEGLYPHS, aStrokeOptions)
     , mFont(aFont)
     , mPattern(aPattern)
-    , mStrokeOptions(aStrokeOptions)
     , mOptions(aOptions)
     , mRenderingOptions(const_cast<GlyphRenderingOptions*>(aRenderingOptions))
   {
     mGlyphs.resize(aBuffer.mNumGlyphs);
     memcpy(&mGlyphs.front(), aBuffer.mGlyphs, sizeof(Glyph) * aBuffer.mNumGlyphs);
-
-    if (aStrokeOptions.mDashLength) {
-      mDashes.resize(aStrokeOptions.mDashLength);
-      mStrokeOptions.mDashPattern = &mDashes.front();
-      PodCopy(&mDashes.front(), aStrokeOptions.mDashPattern, mStrokeOptions.mDashLength);
-    }
   }
 
   virtual void ExecuteOnDT(DrawTarget* aDT, const Matrix*) const
   {
     GlyphBuffer buf;
     buf.mNumGlyphs = mGlyphs.size();
     buf.mGlyphs = &mGlyphs.front();
     aDT->StrokeGlyphs(mFont, buf, mPattern, mStrokeOptions, mOptions, mRenderingOptions);
   }
 
 private:
   RefPtr<ScaledFont> mFont;
   std::vector<Glyph> mGlyphs;
   StoredPattern mPattern;
-  StrokeOptions mStrokeOptions;
   DrawOptions mOptions;
   RefPtr<GlyphRenderingOptions> mRenderingOptions;
-  std::vector<Float> mDashes;
 };
 
 class MaskCommand : public DrawingCommand
 {
 public:
   MaskCommand(const Pattern& aSource,
               const Pattern& aMask,
               const DrawOptions& aOptions)