Bug 1464032 Part 4: Record DrawTarget::Flush and DrawTarget::DetachAllSnapshots. r=jrmuizel
authorBob Owen <bobowencode@gmail.com>
Sun, 02 Dec 2018 14:14:11 +0000
changeset 477755 76f6050cb57f39e8dbe3d0ec6bc987725944e82a
parent 477754 b2e0e341bb82f5f6f04a02c631fd835c506e96e2
child 477756 c83dbcc4dade59208e1291208e1fad72543b503d
push id113373
push userbobowencode@gmail.com
push dateFri, 07 Jun 2019 11:10:59 +0000
treeherdermozilla-inbound@2195b79ea888 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel
bugs1464032
milestone69.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 1464032 Part 4: Record DrawTarget::Flush and DrawTarget::DetachAllSnapshots. r=jrmuizel
gfx/2d/DrawTargetRecording.cpp
gfx/2d/DrawTargetRecording.h
gfx/2d/RecordedEvent.h
gfx/2d/RecordedEventImpl.h
--- a/gfx/2d/DrawTargetRecording.cpp
+++ b/gfx/2d/DrawTargetRecording.cpp
@@ -363,17 +363,23 @@ already_AddRefed<SourceSurface> DrawTarg
       new SourceSurfaceRecording(mSize, SurfaceFormat::A8, mRecorder);
 
   mRecorder->RecordEvent(
       RecordedIntoLuminanceSource(retSurf, this, aLuminanceType, aOpacity));
 
   return retSurf.forget();
 }
 
-void DrawTargetRecording::DetachAllSnapshots() {}
+void DrawTargetRecording::Flush() {
+  mRecorder->RecordEvent(RecordedFlush(this));
+}
+
+void DrawTargetRecording::DetachAllSnapshots() {
+  mRecorder->RecordEvent(RecordedDetachAllSnapshots(this));
+}
 
 void DrawTargetRecording::DrawSurface(SourceSurface* aSurface,
                                       const Rect& aDest, const Rect& aSource,
                                       const DrawSurfaceOptions& aSurfOptions,
                                       const DrawOptions& aOptions) {
   EnsureSurfaceStoredRecording(mRecorder, aSurface, "DrawSurface");
 
   mRecorder->RecordEvent(RecordedDrawSurface(this, aSurface, aDest, aSource,
--- a/gfx/2d/DrawTargetRecording.h
+++ b/gfx/2d/DrawTargetRecording.h
@@ -32,21 +32,17 @@ class DrawTargetRecording : public DrawT
   virtual already_AddRefed<SourceSurface> Snapshot() override;
   virtual already_AddRefed<SourceSurface> IntoLuminanceSource(
       LuminanceType aLuminanceType, float aOpacity) override;
 
   virtual void DetachAllSnapshots() override;
 
   virtual IntSize GetSize() const override { return mSize; }
 
-  /* Ensure that the DrawTarget backend has flushed all drawing operations to
-   * this draw target. This must be called before using the backing surface of
-   * this draw target outside of GFX 2D code.
-   */
-  virtual void Flush() override { mFinalDT->Flush(); }
+  virtual void Flush() override;
 
   virtual void FlushItem(const IntRect& aBounds) override;
 
   /*
    * Draw a surface to the draw target. Possibly doing partial drawing or
    * applying scaling. No sampling happens outside the source.
    *
    * aSurface Source surface to draw
--- a/gfx/2d/RecordedEvent.h
+++ b/gfx/2d/RecordedEvent.h
@@ -245,19 +245,20 @@ class RecordedEvent {
     FONTDESC,
     PUSHLAYER,
     PUSHLAYERWITHBLEND,
     POPLAYER,
     UNSCALEDFONTCREATION,
     UNSCALEDFONTDESTRUCTION,
     INTOLUMINANCE,
     EXTERNALSURFACECREATION,
+    FLUSH,
+    DETACHALLSNAPSHOTS,
+    LAST,
   };
-  static const uint32_t kTotalEventTypes =
-      RecordedEvent::FILTERNODESETINPUT + 1;
 
   virtual ~RecordedEvent() = default;
 
   static std::string GetEventName(EventType aType);
 
   /**
    * Play back this event using the translator. Note that derived classes
    * should
--- a/gfx/2d/RecordedEventImpl.h
+++ b/gfx/2d/RecordedEventImpl.h
@@ -1074,16 +1074,58 @@ class RecordedGradientStopsDestruction
   friend class RecordedEvent;
 
   ReferencePtr mRefPtr;
 
   template <class S>
   MOZ_IMPLICIT RecordedGradientStopsDestruction(S& aStream);
 };
 
+class RecordedFlush : public RecordedDrawingEvent<RecordedFlush> {
+ public:
+  explicit RecordedFlush(DrawTarget* aDT) : RecordedDrawingEvent(FLUSH, aDT) {}
+
+  bool PlayEvent(Translator* aTranslator) const final;
+
+  template <class S>
+  void Record(S& aStream) const;
+  virtual void OutputSimpleEventInfo(
+      std::stringstream& aStringStream) const override;
+
+  virtual std::string GetName() const override { return "Flush"; }
+
+ private:
+  friend class RecordedEvent;
+
+  template <class S>
+  MOZ_IMPLICIT RecordedFlush(S& aStream);
+};
+
+class RecordedDetachAllSnapshots
+    : public RecordedDrawingEvent<RecordedDetachAllSnapshots> {
+ public:
+  explicit RecordedDetachAllSnapshots(DrawTarget* aDT)
+      : RecordedDrawingEvent(DETACHALLSNAPSHOTS, aDT) {}
+
+  bool PlayEvent(Translator* aTranslator) const final;
+
+  template <class S>
+  void Record(S& aStream) const;
+  virtual void OutputSimpleEventInfo(
+      std::stringstream& aStringStream) const override;
+
+  virtual std::string GetName() const override { return "DetachAllSnapshots"; }
+
+ private:
+  friend class RecordedEvent;
+
+  template <class S>
+  MOZ_IMPLICIT RecordedDetachAllSnapshots(S& aStream);
+};
+
 class RecordedSnapshot : public RecordedEventDerived<RecordedSnapshot> {
  public:
   RecordedSnapshot(ReferencePtr aRefPtr, DrawTarget* aDT)
       : RecordedEventDerived(SNAPSHOT), mRefPtr(aRefPtr), mDT(aDT) {}
 
   bool PlayEvent(Translator* aTranslator) const override;
 
   template <class S>
@@ -3009,16 +3051,55 @@ RecordedIntoLuminanceSource::RecordedInt
 }
 
 inline void RecordedIntoLuminanceSource::OutputSimpleEventInfo(
     std::stringstream& aStringStream) const {
   aStringStream << "[" << mRefPtr << "] Into Luminance Source (DT: " << mDT
                 << ")";
 }
 
+inline bool RecordedFlush::PlayEvent(Translator* aTranslator) const {
+  aTranslator->LookupDrawTarget(mDT)->Flush();
+  return true;
+}
+
+template <class S>
+void RecordedFlush::Record(S& aStream) const {
+  RecordedDrawingEvent::Record(aStream);
+}
+
+template <class S>
+RecordedFlush::RecordedFlush(S& aStream)
+    : RecordedDrawingEvent(FLUSH, aStream) {}
+
+inline void RecordedFlush::OutputSimpleEventInfo(
+    std::stringstream& aStringStream) const {
+  aStringStream << "[" << mDT << "] Flush";
+}
+
+inline bool RecordedDetachAllSnapshots::PlayEvent(
+    Translator* aTranslator) const {
+  aTranslator->LookupDrawTarget(mDT)->DetachAllSnapshots();
+  return true;
+}
+
+template <class S>
+void RecordedDetachAllSnapshots::Record(S& aStream) const {
+  RecordedDrawingEvent::Record(aStream);
+}
+
+template <class S>
+RecordedDetachAllSnapshots::RecordedDetachAllSnapshots(S& aStream)
+    : RecordedDrawingEvent(DETACHALLSNAPSHOTS, aStream) {}
+
+inline void RecordedDetachAllSnapshots::OutputSimpleEventInfo(
+    std::stringstream& aStringStream) const {
+  aStringStream << "[" << mDT << "] DetachAllSnapshots";
+}
+
 inline bool RecordedSnapshot::PlayEvent(Translator* aTranslator) const {
   RefPtr<SourceSurface> src = aTranslator->LookupDrawTarget(mDT)->Snapshot();
   aTranslator->AddSourceSurface(mRefPtr, src);
   return true;
 }
 
 template <class S>
 void RecordedSnapshot::Record(S& aStream) const {
@@ -3495,17 +3576,19 @@ inline void RecordedFilterNodeSetInput::
   f(FONTDATA, RecordedFontData);                                   \
   f(FONTDESC, RecordedFontDescriptor);                             \
   f(PUSHLAYER, RecordedPushLayer);                                 \
   f(PUSHLAYERWITHBLEND, RecordedPushLayerWithBlend);               \
   f(POPLAYER, RecordedPopLayer);                                   \
   f(UNSCALEDFONTCREATION, RecordedUnscaledFontCreation);           \
   f(UNSCALEDFONTDESTRUCTION, RecordedUnscaledFontDestruction);     \
   f(INTOLUMINANCE, RecordedIntoLuminanceSource);                   \
-  f(EXTERNALSURFACECREATION, RecordedExternalSurfaceCreation);
+  f(EXTERNALSURFACECREATION, RecordedExternalSurfaceCreation);     \
+  f(FLUSH, RecordedFlush);                                         \
+  f(DETACHALLSNAPSHOTS, RecordedDetachAllSnapshots);
 
 #define DO_WITH_EVENT_TYPE(_typeenum, _class) \
   case _typeenum: {                           \
     auto e = _class(aStream);                 \
     return aAction(&e);                       \
   }
 
 template <class S>