Bug 1522021. Implement SourceSurfaceOffset. r=mstange
authorJeff Muizelaar <jrmuizel@gmail.com>
Fri, 25 Jan 2019 23:06:24 +0000
changeset 455564 5ae9eadd86a7eaaaeb0816f27aab4f17c055da44
parent 455563 e6701b43c193ed00469b7b7b270e43f6bf834cc4
child 455565 11f88edba10fcab0a5e508b1fba9b58203a51fa4
push id76859
push userjmuizelaar@mozilla.com
push dateSat, 26 Jan 2019 23:08:31 +0000
treeherderautoland@5ae9eadd86a7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmstange
bugs1522021
milestone66.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 1522021. Implement SourceSurfaceOffset. r=mstange This forwards to an underlying source surface but also has an origin that it uses to correctly return results from GetRect() Differential Revision: https://phabricator.services.mozilla.com/D17692
gfx/2d/DrawTargetOffset.cpp
gfx/2d/DrawTargetOffset.h
gfx/2d/Types.h
--- a/gfx/2d/DrawTargetOffset.cpp
+++ b/gfx/2d/DrawTargetOffset.cpp
@@ -20,17 +20,17 @@ bool DrawTargetOffset::Init(DrawTarget* 
   mOrigin = aOrigin;
   mDrawTarget->SetTransform(Matrix::Translation(-mOrigin.x, -mOrigin.y));
   mFormat = mDrawTarget->GetFormat();
   SetPermitSubpixelAA(IsOpaque(mFormat));
   return true;
 }
 
 already_AddRefed<SourceSurface> DrawTargetOffset::Snapshot() {
-  return mDrawTarget->Snapshot();
+  return MakeAndAddRef<SourceSurfaceOffset>(mDrawTarget->Snapshot(), mOrigin);
 }
 
 void DrawTargetOffset::DetachAllSnapshots() {}
 
 // Skip the mClippedOut check since this is only used for Flush() which
 // should happen even if we're clipped.
 #define OFFSET_COMMAND(command) \
   void DrawTargetOffset::command() { mDrawTarget->command(); }
--- a/gfx/2d/DrawTargetOffset.h
+++ b/gfx/2d/DrawTargetOffset.h
@@ -14,16 +14,31 @@
 #include "Filters.h"
 #include "Logging.h"
 
 #include <vector>
 
 namespace mozilla {
 namespace gfx {
 
+class SourceSurfaceOffset: public SourceSurface {
+  public:
+  SourceSurfaceOffset(RefPtr<SourceSurface> aSurface, IntPoint aOffset) :
+    mSurface(aSurface),
+    mOffset(aOffset) {}
+  virtual SurfaceType GetType() const override { return SurfaceType::OFFSET; }
+  virtual IntSize GetSize() const override { return mSurface->GetSize(); }
+  virtual IntRect GetRect() const override { return IntRect(mOffset, mSurface->GetSize()); }
+  virtual SurfaceFormat GetFormat() const override { return mSurface->GetFormat(); }
+  virtual already_AddRefed<DataSourceSurface> GetDataSurface() override { return mSurface->GetDataSurface(); }
+  private:
+  RefPtr<SourceSurface> mSurface;
+  IntPoint mOffset;
+};
+
 class DrawTargetOffset : public DrawTarget {
  public:
   DrawTargetOffset();
 
   bool Init(DrawTarget *aDrawTarget, IntPoint aOrigin);
 
   // We'll pestimistically return true here
   virtual bool IsTiledDrawTarget() const override { return true; }
--- a/gfx/2d/Types.h
+++ b/gfx/2d/Types.h
@@ -29,17 +29,18 @@ enum class SurfaceType : int8_t {
   COREGRAPHICS_CGCONTEXT, /* Surface wrapping a CG context */
   SKIA,                   /* Surface wrapping a Skia bitmap */
   DUAL_DT,                /* Snapshot of a dual drawtarget */
   D2D1_1_IMAGE,           /* A D2D 1.1 ID2D1Image SourceSurface */
   RECORDING,              /* Surface used for recording */
   TILED,                  /* Surface from a tiled DrawTarget */
   DATA_SHARED,            /* Data surface using shared memory */
   CAPTURE,                /* Data from a DrawTargetCapture */
-  DATA_RECYCLING_SHARED   /* Data surface using shared memory */
+  DATA_RECYCLING_SHARED,  /* Data surface using shared memory */
+  OFFSET,                 /* Offset */
 };
 
 enum class SurfaceFormat : int8_t {
   // The following values are named to reflect layout of colors in memory, from
   // lowest byte to highest byte. The 32-bit value layout depends on machine
   // endianness.
   //               in-memory            32-bit LE value   32-bit BE value
   B8G8R8A8,  // [BB, GG, RR, AA]     0xAARRGGBB        0xBBGGRRAA