Bug 1332952 - Implement GetAsSourceSurface() for SharedRGBImage. r=mattwoodrow a=lizzard
authorkaro <kkoorts@mozilla.com>
Mon, 23 Jan 2017 11:06:17 +1300
changeset 378071 fcb2593e3808492dcf2e0dc3519ef31796ae128d
parent 378070 18731e46b2eae085d2a665713acb2d3b03d6b097
child 378072 4d570c752fc9249899dac5a9ae98cc35e4061084
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow, lizzard
bugs1332952
milestone53.0a2
Bug 1332952 - Implement GetAsSourceSurface() for SharedRGBImage. r=mattwoodrow a=lizzard MozReview-Commit-ID: E9zl5FchvZG
gfx/layers/ipc/SharedRGBImage.cpp
gfx/layers/ipc/SharedRGBImage.h
--- a/gfx/layers/ipc/SharedRGBImage.cpp
+++ b/gfx/layers/ipc/SharedRGBImage.cpp
@@ -100,13 +100,38 @@ TextureClient*
 SharedRGBImage::GetTextureClient(KnowsCompositor* aForwarder)
 {
   return mTextureClient.get();
 }
 
 already_AddRefed<gfx::SourceSurface>
 SharedRGBImage::GetAsSourceSurface()
 {
-  return nullptr;
+  NS_ASSERTION(NS_IsMainThread(), "Must be main thread");
+
+  if (mSourceSurface) {
+    RefPtr<gfx::SourceSurface> surface(mSourceSurface);
+    return surface.forget();
+  }
+
+  RefPtr<gfx::SourceSurface> surface;
+  {
+    // We are 'borrowing' the DrawTarget and retaining a permanent reference to
+    // the underlying data (via the surface). It is in this instance since we
+    // know that the TextureClient is always wrapping a BufferTextureData and
+    // therefore it won't go away underneath us.
+    BufferTextureData* decoded_buffer =
+      mTextureClient->GetInternalData()->AsBufferTextureData();
+    RefPtr<gfx::DrawTarget> drawTarget = decoded_buffer->BorrowDrawTarget();
+
+    if (!drawTarget) {
+      return nullptr;
+    }
+
+    surface = drawTarget->Snapshot();
+  }
+
+  mSourceSurface = surface;
+  return surface.forget();
 }
 
 } // namespace layers
 } // namespace mozilla
--- a/gfx/layers/ipc/SharedRGBImage.h
+++ b/gfx/layers/ipc/SharedRGBImage.h
@@ -46,14 +46,15 @@ public:
 
   already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
 
   bool Allocate(gfx::IntSize aSize, gfx::SurfaceFormat aFormat);
 private:
   gfx::IntSize mSize;
   RefPtr<ImageClient> mCompositable;
   RefPtr<TextureClient> mTextureClient;
+  nsCountedRef<nsMainThreadSourceSurfaceRef> mSourceSurface;
 };
 
 } // namespace layers
 } // namespace mozilla
 
 #endif