Bug 1288618 - Part 9: Add a new SurfaceDescriptor type for video decoding in the GPU process. r=nical

--HG--
extra : rebase_source : f71052375b72ca2ea8d85b95e399a94bfaf93232
This commit is contained in:
Matt Woodrow 2016-09-21 15:36:10 +12:00
Родитель 2cb0c77257
Коммит 4773ea15c3
7 изменённых файлов: 231 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,51 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GPUVideoTextureClient.h"
namespace mozilla {
namespace layers {
using namespace gfx;
bool
GPUVideoTextureData::Serialize(SurfaceDescriptor& aOutDescriptor)
{
aOutDescriptor = mSD;
return true;
}
void
GPUVideoTextureData::FillInfo(TextureData::Info& aInfo) const
{
aInfo.size = mSize;
// TODO: We should probably try do better for this.
// layers::Image doesn't expose a format, so it's hard
// to figure out in VideoDecoderParent.
aInfo.format = SurfaceFormat::B8G8R8X8;
aInfo.hasIntermediateBuffer = false;
aInfo.hasSynchronization = false;
aInfo.supportsMoz2D = false;
aInfo.canExposeMappedData = false;
}
void
GPUVideoTextureData::Deallocate(ClientIPCAllocator* aAllocator)
{
mSD = SurfaceDescriptorGPUVideo();
}
void
GPUVideoTextureData::Forget(ClientIPCAllocator* aAllocator)
{
// We always need to manually deallocate on the client side.
// Ideally we'd set up our TextureClient with the DEALLOCATE_CLIENT
// flag, but that forces texture destruction to be synchronous.
// Instead let's just deallocate from here as well.
Deallocate(aAllocator);
}
} // namespace layers
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,45 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MOZILLA_GFX_GPUVIDEOTEXTURECLIENT_H
#define MOZILLA_GFX_GPUVIDEOTEXTURECLIENT_H
#include "mozilla/layers/TextureClient.h"
namespace mozilla {
namespace layers {
class GPUVideoTextureData : public TextureData
{
public:
GPUVideoTextureData(const SurfaceDescriptorGPUVideo& aSD,
const gfx::IntSize& aSize)
: mSD(aSD)
, mSize(aSize)
{}
~GPUVideoTextureData() {};
virtual void FillInfo(TextureData::Info& aInfo) const override;
virtual bool Lock(OpenMode, FenceHandle*) override { return true; };
virtual void Unlock() override {};
virtual bool Serialize(SurfaceDescriptor& aOutDescriptor) override;
virtual void Deallocate(ClientIPCAllocator* aAllocator) override;
virtual void Forget(ClientIPCAllocator* aAllocator) override;
protected:
SurfaceDescriptorGPUVideo mSD;
gfx::IntSize mSize;
};
} // namespace layers
} // namespace mozilla
#endif // MOZILLA_GFX_GPUVIDEOTEXTURECLIENT_H

Просмотреть файл

@ -0,0 +1,63 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "GPUVideoTextureHost.h"
#include "ImageContainer.h"
namespace mozilla {
namespace layers {
GPUVideoTextureHost::GPUVideoTextureHost(TextureFlags aFlags,
const SurfaceDescriptorGPUVideo& aDescriptor)
: TextureHost(aFlags)
{
MOZ_COUNT_CTOR(GPUVideoTextureHost);
}
GPUVideoTextureHost::~GPUVideoTextureHost()
{
MOZ_COUNT_DTOR(GPUVideoTextureHost);
}
bool
GPUVideoTextureHost::Lock()
{
if (!mImage || !mCompositor) {
return false;
}
if (!mTextureSource) {
mTextureSource = mCompositor->CreateTextureSourceForImage(mImage);
}
return !!mTextureSource;
}
void
GPUVideoTextureHost::SetCompositor(Compositor* aCompositor)
{
if (mCompositor != aCompositor) {
mTextureSource = nullptr;
mCompositor = aCompositor;
}
}
gfx::IntSize
GPUVideoTextureHost::GetSize() const
{
if (!mImage) {
return gfx::IntSize();
}
return mImage->GetSize();
}
gfx::SurfaceFormat
GPUVideoTextureHost::GetFormat() const
{
return mTextureSource ? mTextureSource->GetFormat() : gfx::SurfaceFormat::UNKNOWN;
}
} // namespace layers
} // namespace mozilla

Просмотреть файл

@ -0,0 +1,57 @@
/* -*- Mode: C++; tab-width: 20; indent-tabs-mode: nil; c-basic-offset: 2 -*-
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifndef MOZILLA_GFX_GPUVIDEOTEXTUREHOST_H
#define MOZILLA_GFX_GPUVIDEOTEXTUREHOST_H
#include "mozilla/layers/TextureHost.h"
namespace mozilla {
namespace layers {
class GPUVideoTextureHost : public TextureHost
{
public:
GPUVideoTextureHost(TextureFlags aFlags,
const SurfaceDescriptorGPUVideo& aDescriptor);
virtual ~GPUVideoTextureHost();
virtual void DeallocateDeviceData() override {}
virtual void SetCompositor(Compositor* aCompositor) override;
virtual Compositor* GetCompositor() override { return mCompositor; }
virtual bool Lock() override;
virtual gfx::SurfaceFormat GetFormat() const override;
virtual bool BindTextureSource(CompositableTextureSourceRef& aTexture) override
{
aTexture = mTextureSource;
return !!aTexture;
}
virtual already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override
{
return nullptr; // XXX - implement this (for MOZ_DUMP_PAINTING)
}
virtual gfx::IntSize GetSize() const override;
#ifdef MOZ_LAYERS_HAVE_LOG
virtual const char* Name() override { return "GPUVideoTextureHost"; }
#endif
protected:
RefPtr<Compositor> mCompositor;
RefPtr<TextureSource> mTextureSource;
RefPtr<Image> mImage;
};
} // namespace layers
} // namespace mozilla
#endif // MOZILLA_GFX_GPUVIDEOTEXTUREHOST_H

Просмотреть файл

@ -19,6 +19,7 @@
#include "mozilla/layers/TextureHostOGL.h" // for TextureHostOGL
#include "mozilla/layers/ImageDataSerializer.h"
#include "mozilla/layers/TextureClient.h"
#include "mozilla/layers/GPUVideoTextureHost.h"
#include "nsAString.h"
#include "mozilla/RefPtr.h" // for nsRefPtr
#include "nsPrintfCString.h" // for nsPrintfCString
@ -232,6 +233,7 @@ TextureHost::Create(const SurfaceDescriptor& aDesc,
case SurfaceDescriptor::TSurfaceDescriptorBuffer:
case SurfaceDescriptor::TSurfaceDescriptorDIB:
case SurfaceDescriptor::TSurfaceDescriptorFileMapping:
case SurfaceDescriptor::TSurfaceDescriptorGPUVideo:
return CreateBackendIndependentTextureHost(aDesc, aDeallocator, aFlags);
case SurfaceDescriptor::TEGLImageDescriptor:
@ -301,6 +303,10 @@ CreateBackendIndependentTextureHost(const SurfaceDescriptor& aDesc,
}
break;
}
case SurfaceDescriptor::TSurfaceDescriptorGPUVideo: {
result = new GPUVideoTextureHost(aFlags, aDesc.get_SurfaceDescriptorGPUVideo());
break;
}
#ifdef XP_WIN
case SurfaceDescriptor::TSurfaceDescriptorDIB: {
result = new DIBTextureHost(aFlags, aDesc);

Просмотреть файл

@ -98,6 +98,10 @@ struct SurfaceDescriptorGralloc {
bool isOpaque;
};
struct SurfaceDescriptorGPUVideo {
uint64_t handle;
};
struct RGBDescriptor {
IntSize size;
SurfaceFormat format;
@ -142,6 +146,7 @@ union SurfaceDescriptor {
SurfaceDescriptorMacIOSurface;
SurfaceDescriptorGralloc;
SurfaceDescriptorSharedGLTexture;
SurfaceDescriptorGPUVideo;
null_t;
};

Просмотреть файл

@ -131,6 +131,7 @@ EXPORTS.mozilla.layers += [
'client/CompositableChild.h',
'client/CompositableClient.h',
'client/ContentClient.h',
'client/GPUVideoTextureClient.h',
'client/ImageClient.h',
'client/SingleTiledContentClient.h',
'client/TextureClient.h',
@ -144,6 +145,7 @@ EXPORTS.mozilla.layers += [
'composite/ContainerLayerComposite.h',
'composite/ContentHost.h',
'composite/FrameUniformityData.h',
'composite/GPUVideoTextureHost.h',
'composite/ImageHost.h',
'composite/ImageLayerComposite.h',
'composite/LayerManagerComposite.h',
@ -322,6 +324,7 @@ UNIFIED_SOURCES += [
'client/CompositableChild.cpp',
'client/CompositableClient.cpp',
'client/ContentClient.cpp',
'client/GPUVideoTextureClient.cpp',
'client/ImageClient.cpp',
'client/SingleTiledContentClient.cpp',
'client/TextureClient.cpp',
@ -337,6 +340,7 @@ UNIFIED_SOURCES += [
'composite/ContentHost.cpp',
'composite/FPSCounter.cpp',
'composite/FrameUniformityData.cpp',
'composite/GPUVideoTextureHost.cpp',
'composite/ImageHost.cpp',
'composite/ImageLayerComposite.cpp',
'composite/LayerManagerComposite.cpp',