Bug 1200595 - EGLImage TextureData implementation. r=mattwoodrow
☠☠ backed out by 027edbd76ba2 ☠ ☠
authorNicolas Silva <nsilva@mozilla.com>
Fri, 20 Nov 2015 14:24:49 +0100
changeset 273487 09e71ba15ea8cbdb96889b320a5e3e86d8e17490
parent 273486 b555b130d43920794b4bace4b9644decc3daec2b
child 273488 a369a2983ceb52583fb62537465619256e368b3e
push id68301
push usernsilva@mozilla.com
push dateFri, 20 Nov 2015 13:25:14 +0000
treeherdermozilla-inbound@c13228f84d85 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmattwoodrow
bugs1200595
milestone45.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 1200595 - EGLImage TextureData implementation. r=mattwoodrow
gfx/layers/client/ImageClient.cpp
gfx/layers/opengl/TextureClientOGL.cpp
gfx/layers/opengl/TextureClientOGL.h
--- a/gfx/layers/client/ImageClient.cpp
+++ b/gfx/layers/client/ImageClient.cpp
@@ -198,20 +198,18 @@ ImageClientSingle::UpdateImage(ImageCont
           return false;
         }
       } else if (image->GetFormat() == ImageFormat::SURFACE_TEXTURE ||
                  image->GetFormat() == ImageFormat::EGLIMAGE) {
         gfx::IntSize size = image->GetSize();
 
         if (image->GetFormat() == ImageFormat::EGLIMAGE) {
           EGLImageImage* typedImage = image->AsEGLImageImage();
-          texture = new EGLImageTextureClient(GetForwarder(),
-                                              mTextureFlags,
-                                              typedImage,
-                                              size);
+          texture = EGLImageTextureData::CreateTextureClient(
+            typedImage, size, GetForwarder(), mTextureFlags);
 #ifdef MOZ_WIDGET_ANDROID
         } else if (image->GetFormat() == ImageFormat::SURFACE_TEXTURE) {
           SurfaceTextureImage* typedImage = image->AsSurfaceTextureImage();
           texture = new SurfaceTextureClient(GetForwarder(), mTextureFlags,
                                              typedImage->GetSurfaceTexture(), size,
                                              typedImage->GetOriginPos());
 #endif
         } else {
--- a/gfx/layers/opengl/TextureClientOGL.cpp
+++ b/gfx/layers/opengl/TextureClientOGL.cpp
@@ -13,69 +13,60 @@
 using namespace mozilla::gl;
 
 namespace mozilla {
 namespace layers {
 
 class CompositableForwarder;
 
 ////////////////////////////////////////////////////////////////////////
-// EGLImageTextureClient
+// EGLImage
 
-EGLImageTextureClient::EGLImageTextureClient(ISurfaceAllocator* aAllocator,
-                                             TextureFlags aFlags,
-                                             EGLImageImage* aImage,
-                                             gfx::IntSize aSize)
-  : TextureClient(aAllocator, aFlags)
-  , mImage(aImage)
-  , mSize(aSize)
-  , mIsLocked(false)
+EGLImageTextureData::EGLImageTextureData(EGLImageImage* aImage, gfx::IntSize aSize)
+: mImage(aImage)
+, mSize(aSize)
+{
+  MOZ_ASSERT(aImage);
+}
+
+already_AddRefed<TextureClient>
+EGLImageTextureData::CreateTextureClient(EGLImageImage* aImage, gfx::IntSize aSize,
+                                         ISurfaceAllocator* aAllocator, TextureFlags aFlags)
 {
   MOZ_ASSERT(XRE_IsParentProcess(),
              "Can't pass an `EGLImage` between processes.");
 
-  AddFlags(TextureFlags::DEALLOCATE_CLIENT);
+  if (!aImage || !XRE_IsParentProcess()) {
+    return nullptr;
+  }
+
+  // XXX - This is quite sad and slow.
+  aFlags |= TextureFlags::DEALLOCATE_CLIENT;
 
   if (aImage->GetOriginPos() == gl::OriginPos::BottomLeft) {
-    AddFlags(TextureFlags::ORIGIN_BOTTOM_LEFT);
+    aFlags |= TextureFlags::ORIGIN_BOTTOM_LEFT;
   }
+
+  return TextureClient::CreateWithData(
+    new EGLImageTextureData(aImage, aSize),
+    aFlags, aAllocator
+  );
 }
 
 bool
-EGLImageTextureClient::ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor)
+EGLImageTextureData::Serialize(SurfaceDescriptor& aOutDescriptor)
 {
-  MOZ_ASSERT(IsValid());
-  MOZ_ASSERT(IsAllocated());
-
   const bool hasAlpha = true;
   aOutDescriptor =
     EGLImageDescriptor((uintptr_t)mImage->GetImage(),
                        (uintptr_t)mImage->GetSync(),
                        mImage->GetSize(), hasAlpha);
   return true;
 }
 
-bool
-EGLImageTextureClient::Lock(OpenMode mode)
-  {
-    MOZ_ASSERT(!mIsLocked);
-    if (!IsValid() || !IsAllocated()) {
-      return false;
-    }
-    mIsLocked = true;
-    return true;
-  }
-
-void
-EGLImageTextureClient::Unlock()
-{
-  MOZ_ASSERT(mIsLocked);
-  mIsLocked = false;
-}
-
 ////////////////////////////////////////////////////////////////////////
 // SurfaceTextureClient
 
 #ifdef MOZ_WIDGET_ANDROID
 
 SurfaceTextureClient::SurfaceTextureClient(ISurfaceAllocator* aAllocator,
                                            TextureFlags aFlags,
                                            AndroidSurfaceTexture* aSurfTex,
--- a/gfx/layers/opengl/TextureClientOGL.h
+++ b/gfx/layers/opengl/TextureClientOGL.h
@@ -15,60 +15,49 @@
 #include "mozilla/layers/LayersSurfaces.h"  // for SurfaceDescriptor
 #include "mozilla/layers/TextureClient.h"  // for TextureClient, etc
 #include "AndroidSurfaceTexture.h"
 
 namespace mozilla {
 
 namespace layers {
 
-class EGLImageTextureClient : public TextureClient
+class EGLImageTextureData : public TextureData
 {
 public:
-  EGLImageTextureClient(ISurfaceAllocator* aAllocator,
-                        TextureFlags aFlags,
-                        EGLImageImage* aImage,
-                        gfx::IntSize aSize);
 
-  virtual bool IsAllocated() const override { return true; }
+  static already_AddRefed<TextureClient>
+  CreateTextureClient(EGLImageImage* aImage, gfx::IntSize aSize,
+                      ISurfaceAllocator* aAllocator, TextureFlags aFlags);
 
   virtual bool HasInternalBuffer() const override { return false; }
 
   virtual gfx::IntSize GetSize() const override { return mSize; }
 
-  virtual bool ToSurfaceDescriptor(SurfaceDescriptor& aOutDescriptor) override;
+  virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
+
+  virtual void Deallocate(ISurfaceAllocator*) override { mImage = nullptr; }
 
-  // Useless functions.
-  virtual bool Lock(OpenMode mode) override;
+  virtual void Forget(ISurfaceAllocator*) override { mImage = nullptr; }
 
-  virtual void Unlock() override;
+  // Unused functions.
+  virtual bool Lock(OpenMode, FenceHandle*) override { return true; }
 
-  virtual bool IsLocked() const override { return mIsLocked; }
+  virtual void Unlock() override {}
 
   virtual gfx::SurfaceFormat GetFormat() const override
   {
     return gfx::SurfaceFormat::UNKNOWN;
   }
 
-  virtual already_AddRefed<TextureClient>
-  CreateSimilar(TextureFlags aFlags = TextureFlags::DEFAULT,
-                TextureAllocationFlags aAllocFlags = ALLOC_DEFAULT) const override
-  {
-    return nullptr;
-  }
+protected:
+  EGLImageTextureData(EGLImageImage* aImage, gfx::IntSize aSize);
 
-  virtual bool AllocateForSurface(gfx::IntSize aSize, TextureAllocationFlags aFlags) override
-  {
-    return false;
-  }
-
-protected:
   RefPtr<EGLImageImage> mImage;
   const gfx::IntSize mSize;
-  bool mIsLocked;
 };
 
 #ifdef MOZ_WIDGET_ANDROID
 
 class SurfaceTextureClient : public TextureClient
 {
 public:
   SurfaceTextureClient(ISurfaceAllocator* aAllocator,