Bug 1362049 - Use channel_index to get the correct channel data info from RenderTextureHost. r=nical
authorJerryShih <hshih@mozilla.com>
Thu, 18 May 2017 22:59:07 +0800
changeset 359343 c74b9d026772b929b60ebc9faf241ed72b83f40d
parent 359342 f7cb82a21940b531024684266e4657c18410b6d4
child 359344 74c0e29fa0fb7bd263f6820dd90364514b658554
push id31852
push userkwierso@gmail.com
push dateFri, 19 May 2017 21:47:27 +0000
treeherdermozilla-central@979f11deabd0 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical
bugs1362049
milestone55.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 1362049 - Use channel_index to get the correct channel data info from RenderTextureHost. r=nical MozReview-Commit-ID: 3LaWdfglobe
gfx/webrender_bindings/RenderBufferTextureHost.cpp
gfx/webrender_bindings/RenderBufferTextureHost.h
gfx/webrender_bindings/RenderMacIOSurfaceTextureHostOGL.cpp
gfx/webrender_bindings/RenderMacIOSurfaceTextureHostOGL.h
gfx/webrender_bindings/RenderTextureHost.h
gfx/webrender_bindings/RenderTextureHostOGL.h
gfx/webrender_bindings/RendererOGL.cpp
--- a/gfx/webrender_bindings/RenderBufferTextureHost.cpp
+++ b/gfx/webrender_bindings/RenderBufferTextureHost.cpp
@@ -90,26 +90,21 @@ RenderBufferTextureHost::Unlock()
   MOZ_ASSERT(mLocked);
   mLocked = false;
   if (mSurface) {
     mSurface->Unmap();
   }
   mSurface = nullptr;
 }
 
-const uint8_t*
-RenderBufferTextureHost::GetDataForRender() const
+RenderBufferTextureHost::RenderBufferData
+RenderBufferTextureHost::GetBufferDataForRender(uint8_t aChannelIndex)
 {
+  // TODO: handle multiple channel bufferTextureHost(e.g. yuv textureHost)
+  MOZ_ASSERT(aChannelIndex < 1);
+
   MOZ_ASSERT(mLocked);
   MOZ_ASSERT(mSurface);
-  return mMap.mData;
-}
-
-size_t
-RenderBufferTextureHost::GetBufferSizeForRender() const
-{
-  MOZ_ASSERT(mLocked);
-  MOZ_ASSERT(mSurface);
-  return mMap.mStride * mSurface->GetSize().height;
+  return RenderBufferData(mMap.mData, mMap.mStride * mSurface->GetSize().height);
 }
 
 } // namespace wr
 } // namespace mozilla
--- a/gfx/webrender_bindings/RenderBufferTextureHost.h
+++ b/gfx/webrender_bindings/RenderBufferTextureHost.h
@@ -15,32 +15,34 @@ class RenderBufferTextureHost final : pu
 {
 public:
   RenderBufferTextureHost(uint8_t* aBuffer,
                           const layers::BufferDescriptor& aDescriptor);
 
   virtual bool Lock() override;
   virtual void Unlock() override;
 
-  virtual gfx::IntSize GetSize() const override
-  {
-    return mSize;
-  }
-  virtual gfx::SurfaceFormat GetFormat() const override
-  {
-    return mFormat;
-  }
-
   virtual RenderBufferTextureHost* AsBufferTextureHost() override
   {
     return this;
   }
 
-  const uint8_t* GetDataForRender() const;
-  size_t GetBufferSizeForRender() const;
+  class RenderBufferData
+  {
+  public:
+    RenderBufferData(uint8_t* aData, size_t aBufferSize)
+      : mData(aData)
+      , mBufferSize(aBufferSize)
+    {
+    }
+    const uint8_t* mData;
+    size_t mBufferSize;
+  };
+
+  RenderBufferData GetBufferDataForRender(uint8_t aChannelIndex);
 
 private:
   virtual ~RenderBufferTextureHost();
 
   already_AddRefed<gfx::DataSourceSurface> GetAsSurface();
   uint8_t* GetBuffer() const
   {
     return mBuffer;
--- a/gfx/webrender_bindings/RenderMacIOSurfaceTextureHostOGL.cpp
+++ b/gfx/webrender_bindings/RenderMacIOSurfaceTextureHostOGL.cpp
@@ -69,35 +69,10 @@ void
 RenderMacIOSurfaceTextureHostOGL::DeleteTextureHandle()
 {
   if (mTextureHandle != 0 && mGL && mGL->MakeCurrent()) {
     mGL->fDeleteTextures(1, &mTextureHandle);
   }
   mTextureHandle = 0;
 }
 
-GLuint
-RenderMacIOSurfaceTextureHostOGL::GetGLHandle()
-{
-  return mTextureHandle;
-}
-
-gfx::IntSize
-RenderMacIOSurfaceTextureHostOGL::GetSize() const
-{
-  if (!mSurface) {
-    return gfx::IntSize();
-  }
-  return gfx::IntSize(mSurface->GetDevicePixelWidth(),
-                      mSurface->GetDevicePixelHeight());
-}
-
-gfx::SurfaceFormat
-RenderMacIOSurfaceTextureHostOGL::GetFormat() const
-{
-  if (!mSurface) {
-    return gfx::SurfaceFormat::UNKNOWN;
-  }
-  return mSurface->GetReadFormat();
-}
-
 } // namespace wr
 } // namespace mozilla
--- a/gfx/webrender_bindings/RenderMacIOSurfaceTextureHostOGL.h
+++ b/gfx/webrender_bindings/RenderMacIOSurfaceTextureHostOGL.h
@@ -21,27 +21,25 @@ namespace wr {
 class RenderMacIOSurfaceTextureHostOGL final : public RenderTextureHostOGL
 {
 public:
   explicit RenderMacIOSurfaceTextureHostOGL(MacIOSurface* aSurface);
 
   virtual bool Lock() override;
   virtual void Unlock() override;
 
-  virtual gfx::IntSize GetSize() const override;
-  virtual gfx::SurfaceFormat GetFormat() const override;
-
   virtual RenderMacIOSurfaceTextureHostOGL* AsMacIOSurfaceTextureHostOGL() override
   {
     return this;
   }
 
   virtual void SetGLContext(gl::GLContext* aContext) override;
 
-  virtual GLuint GetGLHandle() override;
+  virtual gfx::IntSize GetSize(uint8_t aChannelIndex) const override;
+  virtual GLuint GetGLHandle(uint8_t aChannelIndex) const override;
 
 private:
   virtual ~RenderMacIOSurfaceTextureHostOGL();
   void DeleteTextureHandle();
 
   RefPtr<MacIOSurface> mSurface;
   RefPtr<gl::GLContext> mGL;
   GLuint mTextureHandle;
--- a/gfx/webrender_bindings/RenderTextureHost.h
+++ b/gfx/webrender_bindings/RenderTextureHost.h
@@ -22,19 +22,16 @@ class RenderTextureHost
   NS_INLINE_DECL_THREADSAFE_REFCOUNTING(RenderTextureHost)
 
 public:
   RenderTextureHost();
 
   virtual bool Lock() = 0;
   virtual void Unlock() = 0;
 
-  virtual gfx::IntSize GetSize() const = 0;
-  virtual gfx::SurfaceFormat GetFormat() const = 0;
-
   virtual RenderBufferTextureHost* AsBufferTextureHost() { return nullptr; }
   virtual RenderTextureHostOGL* AsTextureHostOGL() { return nullptr; }
 
 protected:
   virtual ~RenderTextureHost();
 };
 
 } // namespace wr
--- a/gfx/webrender_bindings/RenderTextureHostOGL.h
+++ b/gfx/webrender_bindings/RenderTextureHostOGL.h
@@ -15,17 +15,18 @@ class RenderMacIOSurfaceTextureHostOGL;
 
 class RenderTextureHostOGL : public RenderTextureHost
 {
 public:
   RenderTextureHostOGL();
 
   virtual void SetGLContext(gl::GLContext* aContext) = 0;
 
-  virtual GLuint GetGLHandle() = 0;
+  virtual gfx::IntSize GetSize(uint8_t aChannelIndex) const = 0;
+  virtual GLuint GetGLHandle(uint8_t aChannelIndex) const = 0;
 
   virtual RenderTextureHostOGL* AsTextureHostOGL() { return this; }
   virtual RenderMacIOSurfaceTextureHostOGL* AsMacIOSurfaceTextureHostOGL() { return nullptr; }
 
 protected:
   virtual ~RenderTextureHostOGL();
 };
 
--- a/gfx/webrender_bindings/RendererOGL.cpp
+++ b/gfx/webrender_bindings/RendererOGL.cpp
@@ -20,28 +20,30 @@ WrExternalImage LockExternalImage(void* 
 {
   RendererOGL* renderer = reinterpret_cast<RendererOGL*>(aObj);
   RenderTextureHost* texture = renderer->GetRenderTexture(aId);
 
   if (texture->AsBufferTextureHost()) {
     RenderBufferTextureHost* bufferTexture = texture->AsBufferTextureHost();
     MOZ_ASSERT(bufferTexture);
     bufferTexture->Lock();
+    RenderBufferTextureHost::RenderBufferData data =
+        bufferTexture->GetBufferDataForRender(aChannelIndex);
 
-    return RawDataToWrExternalImage(bufferTexture->GetDataForRender(),
-                                    bufferTexture->GetBufferSizeForRender());
+    return RawDataToWrExternalImage(data.mData, data.mBufferSize);
   } else {
     // texture handle case
     RenderTextureHostOGL* textureOGL = texture->AsTextureHostOGL();
     MOZ_ASSERT(textureOGL);
-    gfx::IntSize size = textureOGL->GetSize();
+
     textureOGL->SetGLContext(renderer->mGL);
     textureOGL->Lock();
+    gfx::IntSize size = textureOGL->GetSize(aChannelIndex);
 
-    return NativeTextureToWrExternalImage(textureOGL->GetGLHandle(),
+    return NativeTextureToWrExternalImage(textureOGL->GetGLHandle(aChannelIndex),
                                           0, 0,
                                           size.width, size.height);
   }
 }
 
 void UnlockExternalImage(void* aObj, WrExternalImageId aId, uint8_t aChannelIndex)
 {
   RendererOGL* renderer = reinterpret_cast<RendererOGL*>(aObj);