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
--- 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"
@@ -1868,16 +1869,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
@@ -1904,18 +1960,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,