Bug 1265824 - implement CreateDataTextureSourceAroundYCbCr() and CreateDataTextureSourceAround() for CompositorOGL r?mattwoodrow draft
authorDoug Thayer <dothayer@mozilla.com>
Wed, 02 May 2018 18:31:08 -0700
changeset 816209 570a882598f37507b58e5a9c533c7be360bd7314
parent 816208 f5245fe9246daab68f433ec38f741187d7c12ee9
child 816210 f5cbdceb802df4f80d36d7b0c31f3e2959fa1a18
push id115776
push userbmo:dothayer@mozilla.com
push dateTue, 10 Jul 2018 18:33:51 +0000
reviewersmattwoodrow
bugs1265824
milestone63.0a1
Bug 1265824 - implement CreateDataTextureSourceAroundYCbCr() and CreateDataTextureSourceAround() for CompositorOGL r?mattwoodrow This patch will use DirectMapTextureSource to wrap the DataSourceSurface data for gpu access. That could improve the texture uploading performance. MozReview-Commit-ID: CGPFcCsR1RY
gfx/layers/opengl/CompositorOGL.cpp
gfx/layers/opengl/CompositorOGL.h
--- a/gfx/layers/opengl/CompositorOGL.cpp
+++ b/gfx/layers/opengl/CompositorOGL.cpp
@@ -20,16 +20,17 @@
 #include "gfxRect.h"                    // for gfxRect
 #include "gfxUtils.h"                   // for gfxUtils, etc
 #include "mozilla/ArrayUtils.h"         // for ArrayLength
 #include "mozilla/Preferences.h"        // for Preferences
 #include "mozilla/gfx/BasePoint.h"      // for BasePoint
 #include "mozilla/gfx/Matrix.h"         // for Matrix4x4, Matrix
 #include "mozilla/gfx/Triangle.h"       // for Triangle
 #include "mozilla/gfx/gfxVars.h"        // for gfxVars
+#include "mozilla/layers/ImageDataSerializer.h"
 #include "mozilla/layers/LayerManagerComposite.h"  // for LayerComposite, etc
 #include "mozilla/layers/CompositingRenderTargetOGL.h"
 #include "mozilla/layers/Effects.h"     // for EffectChain, TexturedEffect, etc
 #include "mozilla/layers/TextureHost.h"  // for TextureSource, etc
 #include "mozilla/layers/TextureHostOGL.h"  // for TextureSourceOGL, etc
 #include "mozilla/mozalloc.h"           // for operator delete, etc
 #include "nsAppRunner.h"
 #include "nsAString.h"
@@ -1866,16 +1867,71 @@ CompositorOGL::Resume()
 }
 
 already_AddRefed<DataTextureSource>
 CompositorOGL::CreateDataTextureSource(TextureFlags aFlags)
 {
   return MakeAndAddRef<TextureImageTextureSourceOGL>(this, aFlags);
 }
 
+already_AddRefed<DataTextureSource>
+CompositorOGL::CreateDataTextureSourceAroundYCbCr(TextureHost* aTexture)
+{
+  BufferTextureHost* bufferTexture = aTexture->AsBufferTextureHost();
+  MOZ_ASSERT(bufferTexture);
+
+  if (!bufferTexture) {
+    return nullptr;
+  }
+
+  uint8_t* buf = bufferTexture->GetBuffer();
+  const BufferDescriptor& buffDesc = bufferTexture->GetBufferDescriptor();
+  const YCbCrDescriptor& desc = buffDesc.get_YCbCrDescriptor();
+
+  RefPtr<gfx::DataSourceSurface> tempY =
+    gfx::Factory::CreateWrappingDataSourceSurface(ImageDataSerializer::GetYChannel(buf, desc),
+                                                  desc.yStride(),
+                                                  desc.ySize(),
+                                                  SurfaceFormatForAlphaBitDepth(desc.bitDepth()));
+  if (!tempY) {
+    return nullptr;
+  }
+  RefPtr<gfx::DataSourceSurface> tempCb =
+    gfx::Factory::CreateWrappingDataSourceSurface(ImageDataSerializer::GetCbChannel(buf, desc),
+                                                  desc.cbCrStride(),
+                                                  desc.cbCrSize(),
+                                                  SurfaceFormatForAlphaBitDepth(desc.bitDepth()));
+  if (!tempCb) {
+    return nullptr;
+  }
+  RefPtr<gfx::DataSourceSurface> tempCr =
+    gfx::Factory::CreateWrappingDataSourceSurface(ImageDataSerializer::GetCrChannel(buf, desc),
+                                                  desc.cbCrStride(),
+                                                  desc.cbCrSize(),
+                                                  SurfaceFormatForAlphaBitDepth(desc.bitDepth()));
+  if (!tempCr) {
+    return nullptr;
+  }
+
+  RefPtr<DirectMapTextureSource> srcY = new DirectMapTextureSource(this, tempY);
+  RefPtr<DirectMapTextureSource> srcU = new DirectMapTextureSource(this, tempCb);
+  RefPtr<DirectMapTextureSource> srcV = new DirectMapTextureSource(this, tempCr);
+
+  srcY->SetNextSibling(srcU);
+  srcU->SetNextSibling(srcV);
+
+  return srcY.forget();
+}
+
+already_AddRefed<DataTextureSource>
+CompositorOGL::CreateDataTextureSourceAround(gfx::DataSourceSurface* aSurface)
+{
+  return MakeAndAddRef<DirectMapTextureSource>(this, aSurface);
+}
+
 bool
 CompositorOGL::SupportsPartialTextureUpdate()
 {
   return CanUploadSubTextures(mGLContext);
 }
 
 int32_t
 CompositorOGL::GetMaxTextureSize() const
@@ -1902,18 +1958,16 @@ CompositorOGL::BlitTextureImageHelper()
 {
     if (!mBlitTextureImageHelper) {
         mBlitTextureImageHelper = MakeUnique<GLBlitTextureImageHelper>(this);
     }
 
     return mBlitTextureImageHelper.get();
 }
 
-
-
 GLuint
 CompositorOGL::GetTemporaryTexture(GLenum aTarget, GLenum aUnit)
 {
   if (!mTexturePool) {
     mTexturePool = new PerUnitTexturePoolOGL(gl());
   }
   return mTexturePool->GetTexture(aTarget, aUnit);
 }
--- a/gfx/layers/opengl/CompositorOGL.h
+++ b/gfx/layers/opengl/CompositorOGL.h
@@ -126,16 +126,22 @@ protected:
   virtual ~CompositorOGL();
 
 public:
   virtual CompositorOGL* AsCompositorOGL() override { return this; }
 
   virtual already_AddRefed<DataTextureSource>
   CreateDataTextureSource(TextureFlags aFlags = TextureFlags::NO_FLAGS) override;
 
+  virtual already_AddRefed<DataTextureSource>
+  CreateDataTextureSourceAroundYCbCr(TextureHost* aTexture) override;
+
+  virtual already_AddRefed<DataTextureSource>
+  CreateDataTextureSourceAround(gfx::DataSourceSurface* aSurface) override;
+
   virtual bool Initialize(nsCString* const out_failureReason) override;
 
   virtual void Destroy() override;
 
   virtual TextureFactoryIdentifier GetTextureFactoryIdentifier() override
   {
     TextureFactoryIdentifier result =
       TextureFactoryIdentifier(LayersBackend::LAYERS_OPENGL,