Bug 1200595 - EGLImage TextureData implementation. r=mattwoodrow
authorNicolas Silva <nsilva@mozilla.com>
Fri, 20 Nov 2015 14:24:49 +0100
changeset 308849 0083654ce7df841924b497f7e34001ba9038f3d6
parent 308848 d296b66867926f465c23e2c8e14bccede063cc5d
child 308850 cccfd06730e92ddf7b0cc50fc57ccfa2f0310554
push id5513
push userraliiev@mozilla.com
push dateMon, 25 Jan 2016 13:55:34 +0000
treeherdermozilla-beta@5ee97dd05b5c [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,