Bug 997517: Never try to use D2D for BufferTextureClients. r=nical
authorBas Schouten <bschouten@mozilla.com>
Tue, 29 Apr 2014 22:33:10 +0200
changeset 181211 a71ab94278556083224dcf8b6d0f77603720ec2b
parent 181210 57292971f11018f5f690abf59e82454e48c70082
child 181212 522dc31908beeb5484cbd720cbbf612bbec14773
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersnical
bugs997517
milestone32.0a1
Bug 997517: Never try to use D2D for BufferTextureClients. r=nical
gfx/layers/client/TextureClient.cpp
gfx/layers/client/TextureClient.h
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -643,17 +643,16 @@ BufferTextureClient::BufferTextureClient
                                          gfx::SurfaceFormat aFormat,
                                          gfx::BackendType aMoz2DBackend,
                                          TextureFlags aFlags)
   : TextureClient(aFlags)
   , mAllocator(aAllocator)
   , mFormat(aFormat)
   , mBackend(aMoz2DBackend)
   , mOpenMode(OpenMode::OPEN_NONE)
-  , mUsingFallbackDrawTarget(false)
   , mLocked(false)
 {}
 
 BufferTextureClient::~BufferTextureClient()
 {}
 
 ISurfaceAllocator*
 BufferTextureClient::GetAllocator() const
@@ -694,36 +693,23 @@ BufferTextureClient::GetAsDrawTarget()
     return mDrawTarget;
   }
 
   ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
   if (!serializer.IsValid()) {
     return nullptr;
   }
 
-  MOZ_ASSERT(mUsingFallbackDrawTarget == false);
   mDrawTarget = serializer.GetAsDrawTarget(mBackend);
   if (mDrawTarget) {
     return mDrawTarget;
   }
 
-  // fallback path, probably because the Moz2D backend can't create a
-  // DrawTarget around raw memory. This is going to be slow :(
-  mDrawTarget = gfx::Factory::CreateDrawTarget(mBackend, serializer.GetSize(),
-                                               serializer.GetFormat());
-  if (!mDrawTarget) {
-    return nullptr;
-  }
+  mDrawTarget = serializer.GetAsDrawTarget(BackendType::CAIRO);
 
-  mUsingFallbackDrawTarget = true;
-  if (mOpenMode & OpenMode::OPEN_READ) {
-    RefPtr<DataSourceSurface> surface = serializer.GetAsSurface();
-    IntRect rect(0, 0, surface->GetSize().width, surface->GetSize().height);
-    mDrawTarget->CopySurface(surface, rect, IntPoint(0,0));
-  }
   return mDrawTarget;
 }
 
 bool
 BufferTextureClient::Lock(OpenMode aMode)
 {
   MOZ_ASSERT(!mLocked, "The TextureClient is already Locked!");
   mOpenMode = aMode;
@@ -732,52 +718,27 @@ BufferTextureClient::Lock(OpenMode aMode
 }
 
 void
 BufferTextureClient::Unlock()
 {
   MOZ_ASSERT(mLocked, "The TextureClient is already Unlocked!");
   mLocked = false;
   if (!mDrawTarget) {
-    mUsingFallbackDrawTarget = false;
     return;
   }
 
   // see the comment on TextureClient::GetAsDrawTarget.
   // This DrawTarget is internal to the TextureClient and is only exposed to the
   // outside world between Lock() and Unlock(). This assertion checks that no outside
   // reference remains by the time Unlock() is called.
   MOZ_ASSERT(mDrawTarget->refCount() == 1);
 
   mDrawTarget->Flush();
-  if (mUsingFallbackDrawTarget && (mOpenMode & OpenMode::OPEN_WRITE)) {
-    // When we are using a fallback DrawTarget, it means we could not create
-    // a DrawTarget wrapping the TextureClient's shared memory. In this scenario
-    // we need to put the content of the fallback draw target back into our shared
-    // memory.
-    RefPtr<SourceSurface> snapshot = mDrawTarget->Snapshot();
-    RefPtr<DataSourceSurface> surface = snapshot->GetDataSurface();
-    ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
-    if (!serializer.IsValid() || serializer.GetSize() != surface->GetSize()) {
-      NS_WARNING("Could not write the data back into the texture.");
-      mDrawTarget = nullptr;
-      mUsingFallbackDrawTarget = false;
-      return;
-    }
-    MOZ_ASSERT(surface->GetSize() == serializer.GetSize());
-    MOZ_ASSERT(surface->GetFormat() == serializer.GetFormat());
-    int bpp = BytesPerPixel(surface->GetFormat());
-    for (int i = 0; i < surface->GetSize().height; ++i) {
-      memcpy(serializer.GetData() + i*serializer.GetStride(),
-             surface->GetData() + i*surface->Stride(),
-             surface->GetSize().width * bpp);
-    }
-  }
   mDrawTarget = nullptr;
-  mUsingFallbackDrawTarget = false;
 }
 
 bool
 BufferTextureClient::UpdateYCbCr(const PlanarYCbCrData& aData)
 {
   MOZ_ASSERT(mLocked);
   MOZ_ASSERT(mFormat == gfx::SurfaceFormat::YUV, "This textureClient can only use YCbCr data");
   MOZ_ASSERT(!IsImmutable());
--- a/gfx/layers/client/TextureClient.h
+++ b/gfx/layers/client/TextureClient.h
@@ -440,17 +440,16 @@ public:
 
 protected:
   RefPtr<gfx::DrawTarget> mDrawTarget;
   RefPtr<ISurfaceAllocator> mAllocator;
   gfx::SurfaceFormat mFormat;
   gfx::IntSize mSize;
   gfx::BackendType mBackend;
   OpenMode mOpenMode;
-  bool mUsingFallbackDrawTarget;
   bool mLocked;
 };
 
 /**
  * TextureClient that wraps shared memory.
  * the corresponding texture on the host side is ShmemTextureHost.
  */
 class ShmemTextureClient : public BufferTextureClient