Bug 948221 - Part 4: Add a gfxSurfaceDrawable constructor that takes a SourceSurface. r=roc
authorMatt Woodrow <mwoodrow@mozilla.com>
Wed, 27 Nov 2013 14:05:03 +1300
changeset 159997 f81e94b06315a312c59b1b487399a82c9bfa34a2
parent 159996 7b0f7f3dfa8e625a902c946efaa4f4bde2d63755
child 159998 d4cceaf55796067ef26fe203e5854118d0f2852a
push id25821
push usercbook@mozilla.com
push dateThu, 12 Dec 2013 11:53:39 +0000
treeherdermozilla-central@d15ed5648a5f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs948221
milestone29.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 948221 - Part 4: Add a gfxSurfaceDrawable constructor that takes a SourceSurface. r=roc
gfx/thebes/gfxDrawable.cpp
gfx/thebes/gfxDrawable.h
--- a/gfx/thebes/gfxDrawable.cpp
+++ b/gfx/thebes/gfxDrawable.cpp
@@ -28,16 +28,25 @@ gfxSurfaceDrawable::gfxSurfaceDrawable(D
                                        const gfxIntSize aSize,
                                        const gfxMatrix aTransform)
  : gfxDrawable(aSize)
  , mDrawTarget(aDrawTarget)
  , mTransform(aTransform)
 {
 }
 
+gfxSurfaceDrawable::gfxSurfaceDrawable(SourceSurface* aSurface,
+                                       const gfxIntSize aSize,
+                                       const gfxMatrix aTransform)
+ : gfxDrawable(aSize)
+ , mSourceSurface(aSurface)
+ , mTransform(aTransform)
+{
+}
+
 static gfxMatrix
 DeviceToImageTransform(gfxContext* aContext,
                        const gfxMatrix& aUserSpaceToImageSpace)
 {
     gfxFloat deviceX, deviceY;
     nsRefPtr<gfxASurface> currentTarget =
         aContext->CurrentSurface(&deviceX, &deviceY);
     gfxMatrix currentMatrix = aContext->CurrentMatrix();
@@ -122,16 +131,18 @@ gfxSurfaceDrawable::Draw(gfxContext* aCo
       if (aContext->IsCairo()) {
         nsRefPtr<gfxASurface> source =
           gfxPlatform::GetPlatform()->GetThebesSurfaceForDrawTarget(mDrawTarget);
         pattern = new gfxPattern(source);
       } else {
         RefPtr<SourceSurface> source = mDrawTarget->Snapshot();
         pattern = new gfxPattern(source, Matrix());
       }
+    } else if (mSourceSurface) {
+      pattern = new gfxPattern(mSourceSurface, Matrix());
     } else {
       pattern = new gfxPattern(mSurface);
     }
     if (aRepeat) {
         pattern->SetExtend(gfxPattern::EXTEND_REPEAT);
         pattern->SetFilter(aFilter);
     } else {
         GraphicsFilter filter = aFilter;
@@ -155,17 +166,17 @@ gfxSurfaceDrawable::Draw(gfxContext* aCo
     aContext->Rectangle(aFillRect);
     aContext->Fill();
     return true;
 }
 
 already_AddRefed<gfxImageSurface>
 gfxSurfaceDrawable::GetAsImageSurface()
 {
-    if (mDrawTarget) {
+    if (mDrawTarget || mSourceSurface) {
       // TODO: Find a way to implement this. The caller really wants a 'sub-image' of
       // the original, without having to do a copy. GetDataSurface() might just copy,
       // which isn't useful.
       return nullptr;
 
     }
     return mSurface->GetAsImageSurface();
 }
--- a/gfx/thebes/gfxDrawable.h
+++ b/gfx/thebes/gfxDrawable.h
@@ -53,29 +53,32 @@ protected:
  * A convenience implementation of gfxDrawable for surfaces.
  */
 class gfxSurfaceDrawable : public gfxDrawable {
 public:
     gfxSurfaceDrawable(gfxASurface* aSurface, const gfxIntSize aSize,
                        const gfxMatrix aTransform = gfxMatrix());
     gfxSurfaceDrawable(mozilla::gfx::DrawTarget* aDT, const gfxIntSize aSize,
                        const gfxMatrix aTransform = gfxMatrix());
+    gfxSurfaceDrawable(mozilla::gfx::SourceSurface* aSurface, const gfxIntSize aSize,
+                       const gfxMatrix aTransform = gfxMatrix());
     virtual ~gfxSurfaceDrawable() {}
 
     virtual bool Draw(gfxContext* aContext,
                         const gfxRect& aFillRect,
                         bool aRepeat,
                         const GraphicsFilter& aFilter,
                         const gfxMatrix& aTransform = gfxMatrix());
     
     virtual already_AddRefed<gfxImageSurface> GetAsImageSurface();
 
 protected:
     nsRefPtr<gfxASurface> mSurface;
     mozilla::RefPtr<mozilla::gfx::DrawTarget> mDrawTarget;
+    mozilla::RefPtr<mozilla::gfx::SourceSurface> mSourceSurface;
     const gfxMatrix mTransform;
 };
 
 /**
  * gfxDrawingCallback
  * A simple drawing functor.
  */
 class gfxDrawingCallback {