Bug 1156742 Part 12: Record CreateSimilarDrawTarget separately for Moz2D. r=bas
☠☠ backed out by 9bdfae920430 ☠ ☠
authorBob Owen <bobowencode@gmail.com>
Mon, 21 Dec 2015 20:33:13 +0000
changeset 277224 48c6ce65a5c2e41b292dc2704d703d7b1bdbabc0
parent 277223 dd52947f73c624f99e4838e0a26779d7ae074a61
child 277225 4dd34ea230c633fb41d35f731840c4637aafbe4a
push id29819
push usercbook@mozilla.com
push dateTue, 22 Dec 2015 10:47:17 +0000
treeherdermozilla-central@ad16863d1d45 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas
bugs1156742
milestone46.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 1156742 Part 12: Record CreateSimilarDrawTarget separately for Moz2D. r=bas This is so we can create the real print DrawTarget from our nsDeviceContext at the beginning of each page. Default behaviour for other Translators is still to always use CreateSimilarDrawTarget.
gfx/2d/DrawTargetRecording.cpp
gfx/2d/DrawTargetRecording.h
gfx/2d/RecordedEvent.cpp
gfx/2d/RecordedEvent.h
--- a/gfx/2d/DrawTargetRecording.cpp
+++ b/gfx/2d/DrawTargetRecording.cpp
@@ -292,16 +292,26 @@ DrawTargetRecording::DrawTargetRecording
   mRecorder->RecordEvent(RecordedDrawTargetCreation(this,
                                                     mFinalDT->GetBackendType(),
                                                     mFinalDT->GetSize(),
                                                     mFinalDT->GetFormat(),
                                                     aHasData, snapshot));
   mFormat = mFinalDT->GetFormat();
 }
 
+DrawTargetRecording::DrawTargetRecording(const DrawTargetRecording *aDT,
+                                         const IntSize &aSize,
+                                         SurfaceFormat aFormat)
+  : mRecorder(aDT->mRecorder)
+  , mFinalDT(aDT->mFinalDT->CreateSimilarDrawTarget(aSize, aFormat))
+{
+  mRecorder->RecordEvent(RecordedCreateSimilarDrawTarget(this, aSize, aFormat));
+  mFormat = mFinalDT->GetFormat();
+}
+
 DrawTargetRecording::~DrawTargetRecording()
 {
   mRecorder->RecordEvent(RecordedDrawTargetDestruction(this));
 }
 
 void
 DrawTargetRecording::FillRect(const Rect &aRect,
                               const Pattern &aPattern,
@@ -584,18 +594,17 @@ DrawTargetRecording::CreateSourceSurface
   StoreSourceSurface(mRecorder, retSurf, dataSurf, "CreateSourceSurfaceFromNativeSurface");
 
   return retSurf.forget();
 }
 
 already_AddRefed<DrawTarget>
 DrawTargetRecording::CreateSimilarDrawTarget(const IntSize &aSize, SurfaceFormat aFormat) const
 {
-  RefPtr<DrawTarget> dt = mFinalDT->CreateSimilarDrawTarget(aSize, aFormat);
-  return MakeAndAddRef<DrawTargetRecording>(mRecorder.get(), dt);
+  return MakeAndAddRef<DrawTargetRecording>(this, aSize, aFormat);
 }
 
 already_AddRefed<PathBuilder>
 DrawTargetRecording::CreatePathBuilder(FillRule aFillRule) const
 {
   RefPtr<PathBuilder> builder = mFinalDT->CreatePathBuilder(aFillRule);
   return MakeAndAddRef<PathBuilderRecording>(builder, aFillRule);
 }
--- a/gfx/2d/DrawTargetRecording.h
+++ b/gfx/2d/DrawTargetRecording.h
@@ -13,16 +13,27 @@
 namespace mozilla {
 namespace gfx {
 
 class DrawTargetRecording : public DrawTarget
 {
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(DrawTargetRecording, override)
   DrawTargetRecording(DrawEventRecorder *aRecorder, DrawTarget *aDT, bool aHasData = false);
+
+  /**
+   * Used for creating a DrawTargetRecording for a CreateSimilarDrawTarget call.
+   *
+   * @param aDT DrawTargetRecording on which CreateSimilarDrawTarget  was called
+   * @param aSize size for the similar DrawTarget
+   * @param aFormat format for the similar DrawTarget
+   */
+  DrawTargetRecording(const DrawTargetRecording *aDT, const IntSize &aSize,
+                      SurfaceFormat aFormat);
+
   ~DrawTargetRecording();
 
   virtual DrawTargetType GetType() const override { return mFinalDT->GetType(); }
   virtual BackendType GetBackendType() const override { return mFinalDT->GetBackendType(); }
   virtual bool IsRecording() const override { return true; }
 
   virtual already_AddRefed<SourceSurface> Snapshot() override;
 
--- a/gfx/2d/RecordedEvent.cpp
+++ b/gfx/2d/RecordedEvent.cpp
@@ -23,16 +23,26 @@ static std::string NameFromBackend(Backe
     return "None";
   case BackendType::DIRECT2D:
     return "Direct2D";
   default:
     return "Unknown";
   }
 }
 
+already_AddRefed<DrawTarget>
+Translator::CreateDrawTarget(ReferencePtr aRefPtr, const IntSize &aSize,
+                             SurfaceFormat aFormat)
+{
+  RefPtr<DrawTarget> newDT =
+    GetReferenceDrawTarget()->CreateSimilarDrawTarget(aSize, aFormat);
+  AddDrawTarget(aRefPtr, newDT);
+  return newDT.forget();
+}
+
 #define LOAD_EVENT_TYPE(_typeenum, _class) \
   case _typeenum: return new _class(aStream)
 
 RecordedEvent *
 RecordedEvent::LoadEventFromStream(std::istream &aStream, EventType aType)
 {
   switch (aType) {
     LOAD_EVENT_TYPE(DRAWTARGETCREATION, RecordedDrawTargetCreation);
@@ -62,16 +72,17 @@ RecordedEvent::LoadEventFromStream(std::
     LOAD_EVENT_TYPE(GRADIENTSTOPSCREATION, RecordedGradientStopsCreation);
     LOAD_EVENT_TYPE(GRADIENTSTOPSDESTRUCTION, RecordedGradientStopsDestruction);
     LOAD_EVENT_TYPE(SNAPSHOT, RecordedSnapshot);
     LOAD_EVENT_TYPE(SCALEDFONTCREATION, RecordedScaledFontCreation);
     LOAD_EVENT_TYPE(SCALEDFONTDESTRUCTION, RecordedScaledFontDestruction);
     LOAD_EVENT_TYPE(MASKSURFACE, RecordedMaskSurface);
     LOAD_EVENT_TYPE(FILTERNODESETATTRIBUTE, RecordedFilterNodeSetAttribute);
     LOAD_EVENT_TYPE(FILTERNODESETINPUT, RecordedFilterNodeSetInput);
+    LOAD_EVENT_TYPE(CREATESIMILARDRAWTARGET, RecordedCreateSimilarDrawTarget);
   default:
     return nullptr;
   }
 }
 
 string
 RecordedEvent::GetEventName(EventType aType)
 {
@@ -135,16 +146,18 @@ RecordedEvent::GetEventName(EventType aT
   case SCALEDFONTDESTRUCTION:
     return "ScaledFontDestruction";
   case MASKSURFACE:
     return "MaskSurface";
   case FILTERNODESETATTRIBUTE:
     return "SetAttribute";
   case FILTERNODESETINPUT:
     return "SetInput";
+  case CREATESIMILARDRAWTARGET:
+    return "CreateSimilarDrawTarget";
   default:
     return "Unknown";
   }
 }
 
 void
 RecordedEvent::RecordPatternData(std::ostream &aStream, const PatternStorage &aPattern) const
 {
@@ -362,20 +375,19 @@ RecordedDrawingEvent::GetObjectRef() con
 {
   return mDT;
 }
 
 void
 RecordedDrawTargetCreation::PlayEvent(Translator *aTranslator) const
 {
   RefPtr<DrawTarget> newDT =
-    aTranslator->GetReferenceDrawTarget()->CreateSimilarDrawTarget(mSize, mFormat);
-  aTranslator->AddDrawTarget(mRefPtr, newDT);
+    aTranslator->CreateDrawTarget(mRefPtr, mSize, mFormat);
 
-  if (mHasExistingData) {
+  if (newDT && mHasExistingData) {
     Rect dataRect(0, 0, mExistingData->GetSize().width, mExistingData->GetSize().height);
     newDT->DrawSurface(mExistingData, dataRect, dataRect);
   }
 }
 
 void
 RecordedDrawTargetCreation::RecordToStream(ostream &aStream) const
 {
@@ -448,16 +460,46 @@ RecordedDrawTargetDestruction::RecordedD
 }
 
 void
 RecordedDrawTargetDestruction::OutputSimpleEventInfo(stringstream &aStringStream) const
 {
   aStringStream << "[" << mRefPtr << "] DrawTarget Destruction";
 }
 
+void
+RecordedCreateSimilarDrawTarget::PlayEvent(Translator *aTranslator) const
+{
+  RefPtr<DrawTarget> newDT =
+    aTranslator->GetReferenceDrawTarget()->CreateSimilarDrawTarget(mSize, mFormat);
+  aTranslator->AddDrawTarget(mRefPtr, newDT);
+}
+
+void
+RecordedCreateSimilarDrawTarget::RecordToStream(ostream &aStream) const
+{
+  WriteElement(aStream, mRefPtr);
+  WriteElement(aStream, mSize);
+  WriteElement(aStream, mFormat);
+}
+
+RecordedCreateSimilarDrawTarget::RecordedCreateSimilarDrawTarget(istream &aStream)
+  : RecordedEvent(CREATESIMILARDRAWTARGET)
+{
+  ReadElement(aStream, mRefPtr);
+  ReadElement(aStream, mSize);
+  ReadElement(aStream, mFormat);
+}
+
+void
+RecordedCreateSimilarDrawTarget::OutputSimpleEventInfo(stringstream &aStringStream) const
+{
+  aStringStream << "[" << mRefPtr << "] CreateSimilarDrawTarget (Size: " << mSize.width << "x" << mSize.height << ")";
+}
+
 struct GenericPattern
 {
   GenericPattern(const PatternStorage &aStorage, Translator *aTranslator)
     : mPattern(nullptr), mTranslator(aTranslator)
   {
     mStorage = const_cast<PatternStorage*>(&aStorage);
   }
 
--- a/gfx/2d/RecordedEvent.h
+++ b/gfx/2d/RecordedEvent.h
@@ -87,16 +87,19 @@ public:
   virtual void RemoveSourceSurface(ReferencePtr aRefPtr) = 0;
   virtual void AddFilterNode(mozilla::gfx::ReferencePtr aRefPtr, FilterNode *aSurface) = 0;
   virtual void RemoveFilterNode(mozilla::gfx::ReferencePtr aRefPtr) = 0;
   virtual void AddGradientStops(ReferencePtr aRefPtr, GradientStops *aPath) = 0;
   virtual void RemoveGradientStops(ReferencePtr aRefPtr) = 0;
   virtual void AddScaledFont(ReferencePtr aRefPtr, ScaledFont *aScaledFont) = 0;
   virtual void RemoveScaledFont(ReferencePtr aRefPtr) = 0;
 
+  virtual already_AddRefed<DrawTarget> CreateDrawTarget(ReferencePtr aRefPtr,
+                                                        const IntSize &aSize,
+                                                        SurfaceFormat aFormat);
   virtual DrawTarget *GetReferenceDrawTarget() = 0;
   virtual FontType GetDesiredFontType() = 0;
 };
 
 struct ColorPatternStorage
 {
   Color mColor;
 };
@@ -168,17 +171,18 @@ public:
     SNAPSHOT,
     SCALEDFONTCREATION,
     SCALEDFONTDESTRUCTION,
     MASKSURFACE,
     FILTERNODECREATION,
     FILTERNODEDESTRUCTION,
     DRAWFILTER,
     FILTERNODESETATTRIBUTE,
-    FILTERNODESETINPUT
+    FILTERNODESETINPUT,
+    CREATESIMILARDRAWTARGET
   };
   static const uint32_t kTotalEventTypes = RecordedEvent::FILTERNODESETINPUT + 1;
 
   static std::string GetEventName(EventType aType);
 
   virtual void PlayEvent(Translator *aTranslator) const {}
 
   virtual void RecordToStream(std::ostream &aStream) const {}
@@ -278,16 +282,44 @@ public:
 
   BackendType mBackendType;
 private:
   friend class RecordedEvent;
 
   MOZ_IMPLICIT RecordedDrawTargetDestruction(std::istream &aStream);
 };
 
+class RecordedCreateSimilarDrawTarget : public RecordedEvent
+{
+public:
+  RecordedCreateSimilarDrawTarget(ReferencePtr aRefPtr, const IntSize &aSize,
+                                  SurfaceFormat aFormat)
+    : RecordedEvent(CREATESIMILARDRAWTARGET)
+    , mRefPtr(aRefPtr) , mSize(aSize), mFormat(aFormat)
+  {
+  }
+
+  virtual void PlayEvent(Translator *aTranslator) const;
+
+  virtual void RecordToStream(std::ostream &aStream) const;
+  virtual void OutputSimpleEventInfo(std::stringstream &aStringStream) const;
+
+  virtual std::string GetName() const { return "CreateSimilarDrawTarget"; }
+  virtual ReferencePtr GetObjectRef() const { return mRefPtr; }
+
+  ReferencePtr mRefPtr;
+  IntSize mSize;
+  SurfaceFormat mFormat;
+
+private:
+  friend class RecordedEvent;
+
+  MOZ_IMPLICIT RecordedCreateSimilarDrawTarget(std::istream &aStream);
+};
+
 class RecordedFillRect : public RecordedDrawingEvent {
 public:
   RecordedFillRect(DrawTarget *aDT, const Rect &aRect, const Pattern &aPattern, const DrawOptions &aOptions)
     : RecordedDrawingEvent(FILLRECT, aDT), mRect(aRect), mOptions(aOptions)
   {
     StorePattern(mPattern, aPattern);
   }