Bug 1417549: Execute IntoLuminanceSource during replay rather than synchronously. r=dvander
authorBas Schouten <bschouten@mozilla.com>
Tue, 21 Nov 2017 16:41:08 +0100
changeset 392862 6c992f927177a4badf1f3663ce130c6f714ba155
parent 392861 980f4e0f6dab8ca825d3f34a644dc6db7f37a3f5
child 392863 f10d05c0b3d21ee77242e4396c9d0bb05264347d
child 392979 b96f009478987d44a68a8d7cad40c6a3d6626235
push id97541
push userbschouten@mozilla.com
push dateTue, 21 Nov 2017 15:41:23 +0000
treeherdermozilla-inbound@6c992f927177 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdvander
bugs1417549
milestone59.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 1417549: Execute IntoLuminanceSource during replay rather than synchronously. r=dvander MozReview-Commit-ID: DWGQoTpUnyT
gfx/2d/DrawTargetCapture.cpp
gfx/2d/DrawTargetCapture.h
gfx/2d/SourceSurfaceCapture.cpp
gfx/2d/SourceSurfaceCapture.h
--- a/gfx/2d/DrawTargetCapture.cpp
+++ b/gfx/2d/DrawTargetCapture.cpp
@@ -82,16 +82,24 @@ DrawTargetCaptureImpl::Snapshot()
     mSnapshot = new SourceSurfaceCapture(this);
   }
 
   RefPtr<SourceSurface> surface = mSnapshot;
   return surface.forget();
 }
 
 already_AddRefed<SourceSurface>
+DrawTargetCaptureImpl::IntoLuminanceSource(LuminanceType aLuminanceType,
+                                           float aOpacity)
+{
+  RefPtr<SourceSurface> surface = new SourceSurfaceCapture(this, aLuminanceType, aOpacity);
+  return surface.forget();
+}
+
+already_AddRefed<SourceSurface>
 DrawTargetCaptureImpl::OptimizeSourceSurface(SourceSurface *aSurface) const
 {
   // If the surface is a recording, make sure it gets resolved on the paint thread.
   if (aSurface->GetType() == SurfaceType::CAPTURE) {
     RefPtr<SourceSurface> surface = aSurface;
     return surface.forget();
   }
   return mRefDT->OptimizeSourceSurface(aSurface);
--- a/gfx/2d/DrawTargetCapture.h
+++ b/gfx/2d/DrawTargetCapture.h
@@ -28,16 +28,18 @@ public:
 
   bool Init(const IntSize& aSize, DrawTarget* aRefDT);
   void InitForData(int32_t aStride, size_t aSurfaceAllocationSize);
 
   virtual BackendType GetBackendType() const override { return mRefDT->GetBackendType(); }
   virtual DrawTargetType GetType() const override { return mRefDT->GetType(); }
   virtual bool IsCaptureDT() const override { return true; }
   virtual already_AddRefed<SourceSurface> Snapshot() override;
+  virtual already_AddRefed<SourceSurface> IntoLuminanceSource(LuminanceType aLuminanceType,
+                                                              float aOpacity) override;
   virtual void SetPermitSubpixelAA(bool aPermitSubpixelAA) override;
   virtual void DetachAllSnapshots() override;
   virtual IntSize GetSize() override { return mSize; }
   virtual void Flush() override {}
   virtual void DrawSurface(SourceSurface *aSurface,
                            const Rect &aDest,
                            const Rect &aSource,
                            const DrawSurfaceOptions &aSurfOptions,
--- a/gfx/2d/SourceSurfaceCapture.cpp
+++ b/gfx/2d/SourceSurfaceCapture.cpp
@@ -10,25 +10,48 @@
 #include "mozilla/gfx/Logging.h"
 
 namespace mozilla {
 namespace gfx {
 
 SourceSurfaceCapture::SourceSurfaceCapture(DrawTargetCaptureImpl* aOwner)
  : mOwner(aOwner),
    mHasCommandList(false),
+   mShouldResolveToLuminance{false},
+   mLuminanceType{LuminanceType::LUMINANCE},
+   mOpacity{1.0f},
    mLock("SourceSurfaceCapture.mLock")
 {
   mSize = mOwner->GetSize();
   mFormat = mOwner->GetFormat();
   mRefDT = mOwner->mRefDT;
   mStride = mOwner->mStride;
   mSurfaceAllocationSize = mOwner->mSurfaceAllocationSize;
 }
 
+SourceSurfaceCapture::SourceSurfaceCapture(DrawTargetCaptureImpl* aOwner,
+                                           LuminanceType aLuminanceType /* = LuminanceType::LINEARRGB */,
+                                           Float aOpacity /* = 1.0f */)
+  : mOwner{aOwner}
+  , mHasCommandList{false}
+  , mShouldResolveToLuminance{true}
+  , mLuminanceType{aLuminanceType}
+  , mOpacity{aOpacity}
+  , mLock{"SourceSurfaceCapture.mLock"}
+{
+  mSize = mOwner->GetSize();
+  mFormat = mOwner->GetFormat();
+  mRefDT = mOwner->mRefDT;
+  mStride = mOwner->mStride;
+  mSurfaceAllocationSize = mOwner->mSurfaceAllocationSize;
+
+  // In this case our DrawTarget will not track us, so copy its drawing commands.
+  DrawTargetWillChange();
+}
+
 SourceSurfaceCapture::~SourceSurfaceCapture()
 {
 }
 
 bool
 SourceSurfaceCapture::IsValid() const
 {
   // We must either be able to source a command list, or we must have a cached
@@ -100,17 +123,21 @@ SourceSurfaceCapture::ResolveImpl(Backen
   // our own (which will be empty).
   CaptureCommandList& commands = mHasCommandList
                                  ? mCommands
                                  : mOwner->mCommands;
   for (CaptureCommandList::iterator iter(commands); !iter.Done(); iter.Next()) {
     DrawingCommand* cmd = iter.Get();
     cmd->ExecuteOnDT(dt, nullptr);
   }
-  return dt->Snapshot();
+  if (!mShouldResolveToLuminance) {
+    return dt->Snapshot();
+  } else {
+    return dt->IntoLuminanceSource(mLuminanceType, mOpacity);
+  }
 }
 
 already_AddRefed<DataSourceSurface>
 SourceSurfaceCapture::GetDataSurface()
 {
   RefPtr<SourceSurface> surface = Resolve();
   if (!surface) {
     return nullptr;
--- a/gfx/2d/SourceSurfaceCapture.h
+++ b/gfx/2d/SourceSurfaceCapture.h
@@ -17,16 +17,19 @@ class DrawTargetCaptureImpl;
 
 class SourceSurfaceCapture : public SourceSurface
 {
   friend class DrawTargetCaptureImpl;
 public:
   MOZ_DECLARE_REFCOUNTED_VIRTUAL_TYPENAME(SourceSurfaceCapture, override)
 
   explicit SourceSurfaceCapture(DrawTargetCaptureImpl* aOwner);
+  explicit SourceSurfaceCapture(DrawTargetCaptureImpl* aOwner,
+                                LuminanceType aLuminanceType,
+                                float aOpacity);
   ~SourceSurfaceCapture();
 
   SurfaceType GetType() const override { return SurfaceType::CAPTURE; }
   IntSize GetSize() const override { return mSize; }
   SurfaceFormat GetFormat() const override { return mFormat; }
 
   bool IsValid() const override;
   already_AddRefed<DataSourceSurface> GetDataSurface() override;
@@ -45,16 +48,20 @@ private:
   SurfaceFormat mFormat;
   int32_t mStride;
   int32_t mSurfaceAllocationSize;
   RefPtr<DrawTarget> mRefDT;
   DrawTargetCaptureImpl* mOwner;
   CaptureCommandList mCommands;
   bool mHasCommandList;
 
+  bool mShouldResolveToLuminance;
+  LuminanceType mLuminanceType;
+  float mOpacity;
+
   // Note that we have to keep a reference around. Internal methods like
   // GetSkImageForSurface expect their callers to hold a reference, which
   // isn't easily possible for nested surfaces.
   mutable Mutex mLock;
   RefPtr<SourceSurface> mResolved;
 };
 
 } // namespace gfx