Bug 1543359 - P7. Plumb YUV Color Range info in Windows' Image types. r=mattwoodrow

Still non-functional.

Differential Revision: https://phabricator.services.mozilla.com/D27214

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Jean-Yves Avenard 2019-07-22 08:04:54 +00:00
parent 63be56621d
commit 9d741696fe
13 changed files with 75 additions and 32 deletions

View File

@ -593,7 +593,8 @@ class D3D11DXVA2Manager : public DXVA2Manager {
ID3D11Texture2D** aOutTexture) override;
HRESULT ConfigureForSize(IMFMediaType* aInputType,
gfx::YUVColorSpace aColorSpace, uint32_t aWidth,
gfx::YUVColorSpace aColorSpace,
gfx::ColorRange aColorRange, uint32_t aWidth,
uint32_t aHeight) override;
bool IsD3D11() override { return true; }
@ -626,6 +627,7 @@ class D3D11DXVA2Manager : public DXVA2Manager {
RefPtr<IMFMediaType> mInputType;
GUID mInputSubType;
gfx::YUVColorSpace mYUVColorSpace = gfx::YUVColorSpace::BT601;
gfx::ColorRange mColorRange = gfx::ColorRange::LIMITED;
};
bool D3D11DXVA2Manager::SupportsConfig(IMFMediaType* aType, float aFramerate) {
@ -888,7 +890,7 @@ D3D11DXVA2Manager::CopyToImage(IMFSample* aVideoSample,
MOZ_ASSERT(mTextureClientAllocator);
RefPtr<D3D11ShareHandleImage> image = new D3D11ShareHandleImage(
gfx::IntSize(mWidth, mHeight), aRegion, mYUVColorSpace);
gfx::IntSize(mWidth, mHeight), aRegion, mYUVColorSpace, mColorRange);
// Retrieve the DXGI_FORMAT for the current video sample.
RefPtr<IMFMediaBuffer> buffer;
@ -1022,7 +1024,8 @@ D3D11DXVA2Manager::CopyToBGRATexture(ID3D11Texture2D* aInTexture,
hr = inputType->SetUINT32(MF_MT_ALL_SAMPLES_INDEPENDENT, TRUE);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
hr = ConfigureForSize(inputType, mYUVColorSpace, desc.Width, desc.Height);
hr = ConfigureForSize(inputType, mYUVColorSpace, mColorRange, desc.Width,
desc.Height);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
}
@ -1089,13 +1092,14 @@ D3D11DXVA2Manager::CopyToBGRATexture(ID3D11Texture2D* aInTexture,
HRESULT
D3D11DXVA2Manager::ConfigureForSize(IMFMediaType* aInputType,
gfx::YUVColorSpace aColorSpace,
gfx::ColorRange aColorRange,
uint32_t aWidth, uint32_t aHeight) {
GUID subType = {0};
HRESULT hr = aInputType->GetGUID(MF_MT_SUBTYPE, &subType);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
if (subType == mInputSubType && aWidth == mWidth && aHeight == mHeight &&
mYUVColorSpace == aColorSpace) {
mYUVColorSpace == aColorSpace && mColorRange == aColorRange) {
// If the media type hasn't changed, don't reconfigure.
return S_OK;
}
@ -1153,6 +1157,7 @@ D3D11DXVA2Manager::ConfigureForSize(IMFMediaType* aInputType,
mInputType = inputType;
mInputSubType = subType;
mYUVColorSpace = aColorSpace;
mColorRange = aColorRange;
if (mTextureClientAllocator) {
gfx::SurfaceFormat format = [&]() {
if (subType == MFVideoFormat_NV12) {

View File

@ -51,7 +51,8 @@ class DXVA2Manager {
virtual HRESULT ConfigureForSize(IMFMediaType* aInputType,
gfx::YUVColorSpace aColorSpace,
uint32_t aWidth, uint32_t aHeight) {
gfx::ColorRange aColorRange, uint32_t aWidth,
uint32_t aHeight) {
return S_OK;
}

View File

@ -662,7 +662,8 @@ MediaResult WMFVideoMFTManager::InitInternal() {
if (mUseHwAccel) {
hr = mDXVA2Manager->ConfigureForSize(
outputType, mColorSpace.refOr(gfx::YUVColorSpace::BT601),
mVideoInfo.ImageRect().width, mVideoInfo.ImageRect().height);
gfx::ColorRange::LIMITED, mVideoInfo.ImageRect().width,
mVideoInfo.ImageRect().height);
NS_ENSURE_TRUE(SUCCEEDED(hr),
MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
RESULT_DETAIL("Fail to configure image size for "
@ -1043,7 +1044,8 @@ WMFVideoMFTManager::Output(int64_t aStreamOffset, RefPtr<MediaData>& aOutData) {
if (mUseHwAccel) {
hr = mDXVA2Manager->ConfigureForSize(
outputType, mColorSpace.refOr(gfx::YUVColorSpace::BT601),
mVideoInfo.ImageRect().width, mVideoInfo.ImageRect().height);
gfx::ColorRange::LIMITED, mVideoInfo.ImageRect().width,
mVideoInfo.ImageRect().height);
NS_ENSURE_TRUE(SUCCEEDED(hr), hr);
} else {
// The stride may have changed, recheck for it.

View File

@ -151,7 +151,8 @@ bool SharedSurface_ANGLEShareHandle::ToSurfaceDescriptor(
gfx::SurfaceFormat format =
mHasAlpha ? gfx::SurfaceFormat::B8G8R8A8 : gfx::SurfaceFormat::B8G8R8X8;
*out_descriptor = layers::SurfaceDescriptorD3D10(
(WindowsHandle)mShareHandle, format, mSize, gfx::YUVColorSpace::UNKNOWN);
(WindowsHandle)mShareHandle, format, mSize, gfx::YUVColorSpace::UNKNOWN,
gfx::ColorRange::FULL);
return true;
}

View File

@ -467,7 +467,8 @@ bool SharedSurface_D3D11Interop::ToSurfaceDescriptor(
const auto format =
(mHasAlpha ? gfx::SurfaceFormat::B8G8R8A8 : gfx::SurfaceFormat::B8G8R8X8);
*out_descriptor = layers::SurfaceDescriptorD3D10(
WindowsHandle(mDXGIHandle), format, mSize, gfx::YUVColorSpace::UNKNOWN);
WindowsHandle(mDXGIHandle), format, mSize, gfx::YUVColorSpace::UNKNOWN,
gfx::ColorRange::FULL);
return true;
}

View File

@ -25,16 +25,19 @@ using namespace gfx;
D3D11ShareHandleImage::D3D11ShareHandleImage(const gfx::IntSize& aSize,
const gfx::IntRect& aRect,
gfx::YUVColorSpace aColorSpace)
gfx::YUVColorSpace aColorSpace,
gfx::ColorRange aColorRange)
: Image(nullptr, ImageFormat::D3D11_SHARE_HANDLE_TEXTURE),
mSize(aSize),
mPictureRect(aRect),
mYUVColorSpace(aColorSpace) {}
mYUVColorSpace(aColorSpace),
mColorRange(aColorRange) {}
bool D3D11ShareHandleImage::AllocateTexture(D3D11RecycleAllocator* aAllocator,
ID3D11Device* aDevice) {
if (aAllocator) {
mTextureClient = aAllocator->CreateOrRecycleClient(mYUVColorSpace, mSize);
mTextureClient =
aAllocator->CreateOrRecycleClient(mYUVColorSpace, mColorRange, mSize);
if (mTextureClient) {
D3D11TextureData* textureData = GetData();
MOZ_DIAGNOSTIC_ASSERT(textureData, "Wrong TextureDataType");
@ -177,6 +180,7 @@ class MOZ_RAII D3D11TextureClientAllocationHelper
public:
D3D11TextureClientAllocationHelper(gfx::SurfaceFormat aFormat,
gfx::YUVColorSpace aColorSpace,
gfx::ColorRange aColorRange,
const gfx::IntSize& aSize,
TextureAllocationFlags aAllocFlags,
ID3D11Device* aDevice,
@ -184,6 +188,7 @@ class MOZ_RAII D3D11TextureClientAllocationHelper
: ITextureClientAllocationHelper(aFormat, aSize, BackendSelector::Content,
aTextureFlags, aAllocFlags),
mYUVColorSpace(aColorSpace),
mColorRange(aColorRange),
mDevice(aDevice) {}
bool IsCompatible(TextureClient* aTextureClient) override {
@ -198,6 +203,7 @@ class MOZ_RAII D3D11TextureClientAllocationHelper
aTextureClient->GetFormat() != gfx::SurfaceFormat::P010 &&
aTextureClient->GetFormat() != gfx::SurfaceFormat::P016) ||
(textureData->GetYUVColorSpace() == mYUVColorSpace &&
textureData->GetColorRange() == mColorRange &&
textureData->GetTextureAllocationFlags() == mAllocationFlags);
}
@ -209,12 +215,14 @@ class MOZ_RAII D3D11TextureClientAllocationHelper
return nullptr;
}
data->SetYUVColorSpace(mYUVColorSpace);
data->SetColorRange(mColorRange);
return MakeAndAddRef<TextureClient>(data, mTextureFlags,
aAllocator->GetTextureForwarder());
}
private:
gfx::YUVColorSpace mYUVColorSpace;
const gfx::YUVColorSpace mYUVColorSpace;
const gfx::ColorRange mColorRange;
const RefPtr<ID3D11Device> mDevice;
};
@ -246,7 +254,8 @@ void D3D11RecycleAllocator::SetPreferredSurfaceFormat(
}
already_AddRefed<TextureClient> D3D11RecycleAllocator::CreateOrRecycleClient(
gfx::YUVColorSpace aColorSpace, const gfx::IntSize& aSize) {
gfx::YUVColorSpace aColorSpace, gfx::ColorRange aColorRange,
const gfx::IntSize& aSize) {
// When CompositorDevice or ContentDevice is updated,
// we could not reuse old D3D11Textures. It could cause video flickering.
RefPtr<ID3D11Device> device = gfx::DeviceManagerDx::Get()->GetImageDevice();
@ -263,9 +272,9 @@ already_AddRefed<TextureClient> D3D11RecycleAllocator::CreateOrRecycleClient(
allocFlags = TextureAllocationFlags::ALLOC_MANUAL_SYNCHRONIZATION;
}
D3D11TextureClientAllocationHelper helper(mUsableSurfaceFormat, aColorSpace,
aSize, allocFlags, mDevice,
layers::TextureFlags::DEFAULT);
D3D11TextureClientAllocationHelper helper(
mUsableSurfaceFormat, aColorSpace, aColorRange, aSize, allocFlags,
mDevice, layers::TextureFlags::DEFAULT);
RefPtr<TextureClient> textureClient = CreateOrRecycle(helper);
return textureClient.forget();

View File

@ -28,7 +28,8 @@ class D3D11RecycleAllocator final : public TextureClientRecycleAllocator {
gfx::SurfaceFormat aPreferredFormat);
already_AddRefed<TextureClient> CreateOrRecycleClient(
gfx::YUVColorSpace aColorSpace, const gfx::IntSize& aSize);
gfx::YUVColorSpace aColorSpace, gfx::ColorRange aColorRange,
const gfx::IntSize& aSize);
void SetPreferredSurfaceFormat(gfx::SurfaceFormat aPreferredFormat);
@ -51,7 +52,8 @@ class D3D11RecycleAllocator final : public TextureClientRecycleAllocator {
class D3D11ShareHandleImage final : public Image {
public:
D3D11ShareHandleImage(const gfx::IntSize& aSize, const gfx::IntRect& aRect,
gfx::YUVColorSpace aColorSpace);
gfx::YUVColorSpace aColorSpace,
gfx::ColorRange aColorRange);
virtual ~D3D11ShareHandleImage() = default;
bool AllocateTexture(D3D11RecycleAllocator* aAllocator,
@ -65,6 +67,7 @@ class D3D11ShareHandleImage final : public Image {
ID3D11Texture2D* GetTexture() const;
gfx::YUVColorSpace GetYUVColorSpace() const { return mYUVColorSpace; }
gfx::ColorRange GetColorRange() const { return mColorRange; }
private:
friend class gl::GLBlitHelper;
@ -78,6 +81,7 @@ class D3D11ShareHandleImage final : public Image {
gfx::IntSize mSize;
gfx::IntRect mPictureRect;
gfx::YUVColorSpace mYUVColorSpace;
gfx::ColorRange mColorRange;
RefPtr<TextureClient> mTextureClient;
RefPtr<ID3D11Texture2D> mTexture;
};

View File

@ -33,6 +33,7 @@ bool D3D11YCbCrImage::SetData(KnowsCompositor* aAllocator,
mCbCrSize = aData.mCbCrSize;
mColorDepth = aData.mColorDepth;
mColorSpace = aData.mYUVColorSpace;
mColorRange = aData.mColorRange;
D3D11YCbCrRecycleAllocator* allocator =
aContainer->GetD3D11YCbCrRecycleAllocator(aAllocator);
@ -232,6 +233,7 @@ already_AddRefed<SourceSurface> D3D11YCbCrImage::GetAsSourceSurface() {
data.mStereoMode = StereoMode::MONO;
data.mColorDepth = mColorDepth;
data.mYUVColorSpace = mColorSpace;
data.mColorRange = mColorRange;
data.mYSkip = data.mCbSkip = data.mCrSkip = 0;
data.mYSize = mYSize;
data.mCbCrSize = mCbCrSize;
@ -404,7 +406,8 @@ already_AddRefed<TextureClient> DXGIYCbCrTextureAllocationHelper::Allocate(
return TextureClient::CreateWithData(
DXGIYCbCrTextureData::Create(textureY, textureCb, textureCr, mData.mYSize,
mData.mYSize, mData.mCbCrSize,
mData.mColorDepth, mData.mYUVColorSpace),
mData.mColorDepth, mData.mYUVColorSpace,
mData.mColorRange),
mTextureFlags, forwarder);
}

View File

@ -80,6 +80,7 @@ class D3D11YCbCrImage : public Image {
gfx::IntRect mPictureRect;
gfx::ColorDepth mColorDepth;
gfx::YUVColorSpace mColorSpace;
gfx::ColorRange mColorRange;
RefPtr<TextureClient> mTextureClient;
};

View File

@ -85,7 +85,8 @@ bool DXGID3D9TextureData::Serialize(SurfaceDescriptor& aOutDescriptor) {
mFormat == SurfaceFormat::P010 || mFormat == SurfaceFormat::P016;
aOutDescriptor = SurfaceDescriptorD3D10(
(WindowsHandle)(mHandle), mFormat, GetSize(),
isYUV ? gfx::YUVColorSpace::BT601 : gfx::YUVColorSpace::UNKNOWN);
isYUV ? gfx::YUVColorSpace::BT601 : gfx::YUVColorSpace::UNKNOWN,
gfx::ColorRange::LIMITED);
return true;
}

View File

@ -384,7 +384,7 @@ bool D3D11TextureData::SerializeSpecific(
}
*aOutDesc = SurfaceDescriptorD3D10((WindowsHandle)sharedHandle, mFormat,
mSize, mYUVColorSpace);
mSize, mYUVColorSpace, mColorRange);
return true;
}
@ -572,7 +572,7 @@ DXGIYCbCrTextureData* DXGIYCbCrTextureData::Create(
IDirect3DTexture9* aTextureCr, HANDLE aHandleY, HANDLE aHandleCb,
HANDLE aHandleCr, const gfx::IntSize& aSize, const gfx::IntSize& aSizeY,
const gfx::IntSize& aSizeCbCr, gfx::ColorDepth aColorDepth,
YUVColorSpace aYUVColorSpace) {
YUVColorSpace aYUVColorSpace, gfx::ColorRange aColorRange) {
if (!aHandleY || !aHandleCb || !aHandleCr || !aTextureY || !aTextureCb ||
!aTextureCr) {
return nullptr;
@ -590,6 +590,7 @@ DXGIYCbCrTextureData* DXGIYCbCrTextureData::Create(
texture->mSizeCbCr = aSizeCbCr;
texture->mColorDepth = aColorDepth;
texture->mYUVColorSpace = aYUVColorSpace;
texture->mColorRange = aColorRange;
return texture;
}
@ -598,7 +599,8 @@ DXGIYCbCrTextureData* DXGIYCbCrTextureData::Create(
ID3D11Texture2D* aTextureY, ID3D11Texture2D* aTextureCb,
ID3D11Texture2D* aTextureCr, const gfx::IntSize& aSize,
const gfx::IntSize& aSizeY, const gfx::IntSize& aSizeCbCr,
gfx::ColorDepth aColorDepth, YUVColorSpace aYUVColorSpace) {
gfx::ColorDepth aColorDepth, YUVColorSpace aYUVColorSpace,
gfx::ColorRange aColorRange) {
if (!aTextureY || !aTextureCb || !aTextureCr) {
return nullptr;
}
@ -650,6 +652,7 @@ DXGIYCbCrTextureData* DXGIYCbCrTextureData::Create(
texture->mSizeCbCr = aSizeCbCr;
texture->mColorDepth = aColorDepth;
texture->mYUVColorSpace = aYUVColorSpace;
texture->mColorRange = aColorRange;
return texture;
}
@ -667,7 +670,7 @@ void DXGIYCbCrTextureData::SerializeSpecific(
*aOutDesc = SurfaceDescriptorDXGIYCbCr(
(WindowsHandle)mHandles[0], (WindowsHandle)mHandles[1],
(WindowsHandle)mHandles[2], mSize, mSizeY, mSizeCbCr, mColorDepth,
mYUVColorSpace);
mYUVColorSpace, mColorRange);
}
bool DXGIYCbCrTextureData::Serialize(SurfaceDescriptor& aOutDescriptor) {
@ -762,6 +765,7 @@ DXGITextureHostD3D11::DXGITextureHostD3D11(
mHandle(aDescriptor.handle()),
mFormat(aDescriptor.format()),
mYUVColorSpace(aDescriptor.yUVColorSpace()),
mColorRange(aDescriptor.colorRange()),
mIsLocked(false) {}
bool DXGITextureHostD3D11::EnsureTexture() {
@ -1077,7 +1081,7 @@ void DXGITextureHostD3D11::PushDisplayItems(
? wr::ColorDepth::Color8
: wr::ColorDepth::Color16,
wr::ToWrYuvColorSpace(mYUVColorSpace),
wr::WrColorRange::Limited, aFilter);
wr::ToWrColorRange(mColorRange), aFilter);
break;
}
default: {
@ -1093,7 +1097,8 @@ DXGIYCbCrTextureHostD3D11::DXGIYCbCrTextureHostD3D11(
mSizeCbCr(aDescriptor.sizeCbCr()),
mIsLocked(false),
mColorDepth(aDescriptor.colorDepth()),
mYUVColorSpace(aDescriptor.yUVColorSpace()) {
mYUVColorSpace(aDescriptor.yUVColorSpace()),
mColorRange(aDescriptor.colorRange()) {
mHandles[0] = aDescriptor.handleY();
mHandles[1] = aDescriptor.handleCb();
mHandles[2] = aDescriptor.handleCr();
@ -1289,7 +1294,7 @@ void DXGIYCbCrTextureHostD3D11::PushDisplayItems(
aBuilder.PushYCbCrPlanarImage(
aBounds, aClip, true, aImageKeys[0], aImageKeys[1], aImageKeys[2],
wr::ToWrColorDepth(mColorDepth), wr::ToWrYuvColorSpace(mYUVColorSpace),
wr::WrColorRange::Limited, aFilter);
wr::ToWrColorRange(mColorRange), aFilter);
}
bool DXGIYCbCrTextureHostD3D11::AcquireTextureSource(

View File

@ -87,6 +87,8 @@ class D3D11TextureData final : public TextureData {
void SetYUVColorSpace(gfx::YUVColorSpace aColorSpace) {
mYUVColorSpace = aColorSpace;
}
gfx::ColorRange GetColorRange() const { return mColorRange; }
void SetColorRange(gfx::ColorRange aColorRange) { mColorRange = aColorRange; }
gfx::IntSize GetSize() const { return mSize; }
gfx::SurfaceFormat GetSurfaceFormat() const { return mFormat; }
@ -117,6 +119,7 @@ class D3D11TextureData final : public TextureData {
gfx::IntSize mSize;
gfx::SurfaceFormat mFormat;
gfx::YUVColorSpace mYUVColorSpace = gfx::YUVColorSpace::UNKNOWN;
gfx::ColorRange mColorRange = gfx::ColorRange::LIMITED;
bool mNeedsClear;
bool mNeedsClearWhite;
bool mHasSynchronization;
@ -135,13 +138,14 @@ class DXGIYCbCrTextureData : public TextureData {
IDirect3DTexture9* aTextureCr, HANDLE aHandleY, HANDLE aHandleCb,
HANDLE aHandleCr, const gfx::IntSize& aSize, const gfx::IntSize& aSizeY,
const gfx::IntSize& aSizeCbCr, gfx::ColorDepth aColorDepth,
gfx::YUVColorSpace aYUVColorSpace);
gfx::YUVColorSpace aYUVColorSpace, gfx::ColorRange aColorRange);
static DXGIYCbCrTextureData* Create(
ID3D11Texture2D* aTextureCb, ID3D11Texture2D* aTextureY,
ID3D11Texture2D* aTextureCr, const gfx::IntSize& aSize,
const gfx::IntSize& aSizeY, const gfx::IntSize& aSizeCbCr,
gfx::ColorDepth aColorDepth, gfx::YUVColorSpace aYUVColorSpace);
gfx::ColorDepth aColorDepth, gfx::YUVColorSpace aYUVColorSpace,
gfx::ColorRange aColorRange);
bool Lock(OpenMode) override { return true; }
@ -170,8 +174,8 @@ class DXGIYCbCrTextureData : public TextureData {
gfx::IntSize GetCbCrSize() const { return mSizeCbCr; }
gfx::ColorDepth GetColorDepth() const { return mColorDepth; }
gfx::YUVColorSpace GetYUVColorSpace() const { return mYUVColorSpace; }
gfx::ColorRange GetColorRange() const { return mColorRange; }
ID3D11Texture2D* GetD3D11Texture(size_t index) {
return mD3D11Textures[index];
@ -186,6 +190,7 @@ class DXGIYCbCrTextureData : public TextureData {
gfx::IntSize mSizeCbCr;
gfx::ColorDepth mColorDepth;
gfx::YUVColorSpace mYUVColorSpace;
gfx::ColorRange mColorRange;
};
/**
@ -336,6 +341,7 @@ class DXGITextureHostD3D11 : public TextureHost {
gfx::YUVColorSpace GetYUVColorSpace() const override {
return mYUVColorSpace;
}
gfx::ColorRange GetColorRange() const override { return mColorRange; }
already_AddRefed<gfx::DataSourceSurface> GetAsSurface() override;
@ -371,6 +377,7 @@ class DXGITextureHostD3D11 : public TextureHost {
WindowsHandle mHandle;
gfx::SurfaceFormat mFormat;
const gfx::YUVColorSpace mYUVColorSpace;
const gfx::ColorRange mColorRange;
bool mIsLocked;
};
@ -391,10 +398,10 @@ class DXGIYCbCrTextureHostD3D11 : public TextureHost {
}
gfx::ColorDepth GetColorDepth() const override { return mColorDepth; }
gfx::YUVColorSpace GetYUVColorSpace() const override {
return mYUVColorSpace;
}
gfx::ColorRange GetColorRange() const override { return mColorRange; }
bool Lock() override;
@ -438,6 +445,7 @@ class DXGIYCbCrTextureHostD3D11 : public TextureHost {
bool mIsLocked;
gfx::ColorDepth mColorDepth;
gfx::YUVColorSpace mYUVColorSpace;
gfx::ColorRange mColorRange;
};
class CompositingRenderTargetD3D11 : public CompositingRenderTarget,

View File

@ -36,6 +36,7 @@ struct SurfaceDescriptorD3D10 {
SurfaceFormat format;
IntSize size;
YUVColorSpace yUVColorSpace;
ColorRange colorRange;
};
struct SurfaceDescriptorDXGIYCbCr {
@ -47,6 +48,7 @@ struct SurfaceDescriptorDXGIYCbCr {
IntSize sizeCbCr;
ColorDepth colorDepth;
YUVColorSpace yUVColorSpace;
ColorRange colorRange;
};
struct SurfaceDescriptorMacIOSurface {