mirror of
https://github.com/roytam1/basilisk55.git
synced 2026-05-26 15:02:46 +00:00
import from UXP: Issue #2101 - Part 6: Plumbing of ColorRange between video decoders and YUV convert (2b88f2c9)
This commit is contained in:
@@ -268,6 +268,7 @@ bool VideoData::SetVideoDataToImage(PlanarYCbCrImage* aVideoImage,
|
||||
data.mPicSize = aPicture.Size();
|
||||
data.mStereoMode = aInfo.mStereoMode;
|
||||
data.mYUVColorSpace = aBuffer.mYUVColorSpace;
|
||||
data.mColorRange = aBuffer.mColorRange;
|
||||
|
||||
aVideoImage->SetDelayedConversion(true);
|
||||
if (aCopyData) {
|
||||
|
||||
@@ -990,6 +990,14 @@ struct ParamTraits<mozilla::YUVColorSpace>
|
||||
mozilla::YUVColorSpace::UNKNOWN>
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::ColorRange>
|
||||
: public ContiguousEnumSerializer<
|
||||
mozilla::ColorRange,
|
||||
mozilla::ColorRange::LIMITED,
|
||||
mozilla::ColorRange::UNKNOWN>
|
||||
{};
|
||||
|
||||
template <>
|
||||
struct ParamTraits<mozilla::layers::ScrollableLayerGuid>
|
||||
{
|
||||
|
||||
@@ -159,6 +159,7 @@ BufferTextureData*
|
||||
BufferTextureData::CreateForYCbCrWithBufferSize(KnowsCompositor* aAllocator,
|
||||
int32_t aBufferSize,
|
||||
YUVColorSpace aYUVColorSpace,
|
||||
ColorRange aColorRange,
|
||||
TextureFlags aTextureFlags)
|
||||
{
|
||||
if (aBufferSize == 0 || !gfx::Factory::CheckBufferSize(aBufferSize)) {
|
||||
@@ -173,7 +174,7 @@ BufferTextureData::CreateForYCbCrWithBufferSize(KnowsCompositor* aAllocator,
|
||||
// afterwards since we don't know the dimensions of the texture at this point.
|
||||
BufferDescriptor desc = YCbCrDescriptor(gfx::IntSize(), gfx::IntSize(),
|
||||
0, 0, 0, StereoMode::MONO,
|
||||
aYUVColorSpace,
|
||||
aYUVColorSpace, aColorRange,
|
||||
hasIntermediateBuffer);
|
||||
|
||||
return CreateInternal(aAllocator ? aAllocator->GetTextureForwarder() : nullptr,
|
||||
@@ -186,6 +187,7 @@ BufferTextureData::CreateForYCbCr(KnowsCompositor* aAllocator,
|
||||
gfx::IntSize aCbCrSize,
|
||||
StereoMode aStereoMode,
|
||||
YUVColorSpace aYUVColorSpace,
|
||||
ColorRange aColorRange,
|
||||
TextureFlags aTextureFlags)
|
||||
{
|
||||
uint32_t bufSize = ImageDataSerializer::ComputeYCbCrBufferSize(aYSize, aCbCrSize);
|
||||
@@ -206,7 +208,7 @@ BufferTextureData::CreateForYCbCr(KnowsCompositor* aAllocator,
|
||||
|
||||
YCbCrDescriptor descriptor = YCbCrDescriptor(aYSize, aCbCrSize, yOffset, cbOffset,
|
||||
crOffset, aStereoMode, aYUVColorSpace,
|
||||
hasIntermediateBuffer);
|
||||
aColorRange, hasIntermediateBuffer);
|
||||
|
||||
return CreateInternal(aAllocator ? aAllocator->GetTextureForwarder() : nullptr, descriptor,
|
||||
gfx::BackendType::NONE, bufSize, aTextureFlags);
|
||||
@@ -254,6 +256,12 @@ BufferTextureData::GetYUVColorSpace() const
|
||||
return ImageDataSerializer::YUVColorSpaceFromBufferDescriptor(mDescriptor);
|
||||
}
|
||||
|
||||
Maybe<ColorRange>
|
||||
BufferTextureData::GetColorRange() const
|
||||
{
|
||||
return ImageDataSerializer::ColorRangeFromBufferDescriptor(mDescriptor);
|
||||
}
|
||||
|
||||
Maybe<StereoMode>
|
||||
BufferTextureData::GetStereoMode() const
|
||||
{
|
||||
|
||||
@@ -33,6 +33,7 @@ public:
|
||||
gfx::IntSize aCbCrSize,
|
||||
StereoMode aStereoMode,
|
||||
YUVColorSpace aYUVColorSpace,
|
||||
ColorRange aColorRange,
|
||||
TextureFlags aTextureFlags);
|
||||
|
||||
// It is generally better to use CreateForYCbCr instead.
|
||||
@@ -41,6 +42,7 @@ public:
|
||||
static BufferTextureData* CreateForYCbCrWithBufferSize(KnowsCompositor* aAllocator,
|
||||
int32_t aSize,
|
||||
YUVColorSpace aYUVColorSpace,
|
||||
ColorRange aColorRange,
|
||||
TextureFlags aTextureFlags);
|
||||
|
||||
virtual bool Lock(OpenMode aMode) override { return true; }
|
||||
@@ -66,6 +68,7 @@ public:
|
||||
Maybe<gfx::IntSize> GetCbCrSize() const;
|
||||
|
||||
Maybe<YUVColorSpace> GetYUVColorSpace() const;
|
||||
Maybe<ColorRange> GetColorRange() const;
|
||||
|
||||
Maybe<StereoMode> GetStereoMode() const;
|
||||
|
||||
|
||||
@@ -171,7 +171,6 @@ Maybe<gfx::IntSize> CbCrSizeFromBufferDescriptor(const BufferDescriptor& aDescri
|
||||
}
|
||||
|
||||
Maybe<YUVColorSpace> YUVColorSpaceFromBufferDescriptor(const BufferDescriptor& aDescriptor)
|
||||
{
|
||||
{
|
||||
switch (aDescriptor.type()) {
|
||||
case BufferDescriptor::TRGBDescriptor:
|
||||
@@ -182,6 +181,17 @@ Maybe<YUVColorSpace> YUVColorSpaceFromBufferDescriptor(const BufferDescriptor& a
|
||||
MOZ_CRASH("GFX: CbCrSizeFromBufferDescriptor");
|
||||
}
|
||||
}
|
||||
|
||||
Maybe<ColorRange> ColorRangeFromBufferDescriptor(const BufferDescriptor& aDescriptor)
|
||||
{
|
||||
switch (aDescriptor.type()) {
|
||||
case BufferDescriptor::TRGBDescriptor:
|
||||
return Nothing();
|
||||
case BufferDescriptor::TYCbCrDescriptor:
|
||||
return Some(aDescriptor.get_YCbCrDescriptor().colorRange());
|
||||
default:
|
||||
MOZ_CRASH("GFX: CbCrSizeFromBufferDescriptor");
|
||||
}
|
||||
}
|
||||
|
||||
Maybe<StereoMode> StereoModeFromBufferDescriptor(const BufferDescriptor& aDescriptor)
|
||||
@@ -252,6 +262,7 @@ DataSourceSurfaceFromYCbCrDescriptor(uint8_t* aBuffer, const YCbCrDescriptor& aD
|
||||
ycbcrData.mCbCrSize = cbCrSize;
|
||||
ycbcrData.mPicSize = ySize;
|
||||
ycbcrData.mYUVColorSpace = aDescriptor.yUVColorSpace();
|
||||
ycbcrData.mColorRange = aDescriptor.colorRange();
|
||||
|
||||
gfx::ConvertYCbCrToRGB(ycbcrData,
|
||||
gfx::SurfaceFormat::B8G8R8X8,
|
||||
|
||||
@@ -65,6 +65,7 @@ gfx::IntSize SizeFromBufferDescriptor(const BufferDescriptor& aDescriptor);
|
||||
Maybe<gfx::IntSize> CbCrSizeFromBufferDescriptor(const BufferDescriptor& aDescriptor);
|
||||
|
||||
Maybe<YUVColorSpace> YUVColorSpaceFromBufferDescriptor(const BufferDescriptor& aDescriptor);
|
||||
Maybe<ColorRange> ColorRangeFromBufferDescriptor(const BufferDescriptor& aDescriptor);
|
||||
|
||||
Maybe<StereoMode> StereoModeFromBufferDescriptor(const BufferDescriptor& aDescriptor);
|
||||
|
||||
|
||||
@@ -104,7 +104,7 @@ ImageClient::CreateTextureClientForImage(Image* aImage, KnowsCompositor* aForwar
|
||||
}
|
||||
texture = TextureClient::CreateForYCbCr(aForwarder,
|
||||
data->mYSize, data->mCbCrSize, data->mStereoMode,
|
||||
data->mYUVColorSpace,
|
||||
data->mYUVColorSpace, data->mColorRange,
|
||||
TextureFlags::DEFAULT);
|
||||
if (!texture) {
|
||||
return nullptr;
|
||||
|
||||
@@ -1222,6 +1222,7 @@ TextureClient::CreateForYCbCr(KnowsCompositor* aAllocator,
|
||||
gfx::IntSize aCbCrSize,
|
||||
StereoMode aStereoMode,
|
||||
YUVColorSpace aYUVColorSpace,
|
||||
ColorRange aColorRange,
|
||||
TextureFlags aTextureFlags)
|
||||
{
|
||||
if (!aAllocator || !aAllocator->GetLayersIPCActor()->IPCOpen()) {
|
||||
@@ -1234,7 +1235,7 @@ TextureClient::CreateForYCbCr(KnowsCompositor* aAllocator,
|
||||
|
||||
TextureData* data = BufferTextureData::CreateForYCbCr(aAllocator, aYSize, aCbCrSize,
|
||||
aStereoMode, aYUVColorSpace,
|
||||
aTextureFlags);
|
||||
aColorRange, aTextureFlags);
|
||||
if (!data) {
|
||||
return nullptr;
|
||||
}
|
||||
@@ -1248,6 +1249,7 @@ already_AddRefed<TextureClient>
|
||||
TextureClient::CreateForYCbCrWithBufferSize(KnowsCompositor* aAllocator,
|
||||
size_t aSize,
|
||||
YUVColorSpace aYUVColorSpace,
|
||||
ColorRange aColorRange,
|
||||
TextureFlags aTextureFlags)
|
||||
{
|
||||
if (!aAllocator || !aAllocator->GetLayersIPCActor()->IPCOpen()) {
|
||||
@@ -1256,7 +1258,7 @@ TextureClient::CreateForYCbCrWithBufferSize(KnowsCompositor* aAllocator,
|
||||
|
||||
TextureData* data =
|
||||
BufferTextureData::CreateForYCbCrWithBufferSize(aAllocator, aSize, aYUVColorSpace,
|
||||
aTextureFlags);
|
||||
aColorRange, aTextureFlags);
|
||||
if (!data) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
@@ -360,6 +360,7 @@ public:
|
||||
gfx::IntSize aCbCrSize,
|
||||
StereoMode aStereoMode,
|
||||
YUVColorSpace aYUVColorSpace,
|
||||
ColorRange aColorRange,
|
||||
TextureFlags aTextureFlags);
|
||||
|
||||
// Creates and allocates a TextureClient (can be accessed through raw
|
||||
@@ -379,6 +380,7 @@ public:
|
||||
CreateForYCbCrWithBufferSize(KnowsCompositor* aAllocator,
|
||||
size_t aSize,
|
||||
YUVColorSpace aYUVColorSpace,
|
||||
ColorRange aColorRange,
|
||||
TextureFlags aTextureFlags);
|
||||
|
||||
// Creates and allocates a TextureClient of the same type.
|
||||
|
||||
@@ -108,6 +108,8 @@ YCbCrTextureClientAllocationHelper::IsCompatible(TextureClient* aTextureClient)
|
||||
bufferData->GetCbCrSize().ref() != mData.mCbCrSize ||
|
||||
bufferData->GetYUVColorSpace().isNothing() ||
|
||||
bufferData->GetYUVColorSpace().ref() != mData.mYUVColorSpace ||
|
||||
bufferData->GetColorRange().isNothing() ||
|
||||
bufferData->GetColorRange().ref() != mData.mColorRange ||
|
||||
bufferData->GetStereoMode().isNothing() ||
|
||||
bufferData->GetStereoMode().ref() != mData.mStereoMode) {
|
||||
return false;
|
||||
@@ -122,6 +124,7 @@ YCbCrTextureClientAllocationHelper::Allocate(KnowsCompositor* aAllocator)
|
||||
mData.mYSize, mData.mCbCrSize,
|
||||
mData.mStereoMode,
|
||||
mData.mYUVColorSpace,
|
||||
mData.mColorRange,
|
||||
mTextureFlags);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ using nsIntRegion from "nsRegion.h";
|
||||
using struct mozilla::layers::SurfaceDescriptorX11 from "gfxipc/ShadowLayerUtils.h";
|
||||
using mozilla::StereoMode from "ImageTypes.h";
|
||||
using mozilla::YUVColorSpace from "ImageTypes.h";
|
||||
using mozilla::ColorRange from "ImageTypes.h";
|
||||
using struct mozilla::null_t from "ipc/IPCMessageUtils.h";
|
||||
using mozilla::WindowsHandle from "ipc/IPCMessageUtils.h";
|
||||
using mozilla::gfx::SurfaceFormat from "mozilla/gfx/Types.h";
|
||||
@@ -102,6 +103,7 @@ struct YCbCrDescriptor {
|
||||
uint32_t crOffset;
|
||||
StereoMode stereoMode;
|
||||
YUVColorSpace yUVColorSpace;
|
||||
ColorRange colorRange;
|
||||
bool hasIntermediateBuffer;
|
||||
};
|
||||
|
||||
|
||||
@@ -119,6 +119,7 @@ SharedPlanarYCbCrImage::AllocateAndGetNewBuffer(uint32_t aSize)
|
||||
mTextureClient = TextureClient::CreateForYCbCrWithBufferSize(mCompositable->GetForwarder(),
|
||||
size,
|
||||
YUVColorSpace::BT601,
|
||||
ColorRange::LIMITED,
|
||||
mCompositable->GetTextureFlags());
|
||||
|
||||
// get new buffer _without_ setting mBuffer.
|
||||
@@ -164,7 +165,8 @@ SharedPlanarYCbCrImage::AdoptData(const Data &aData)
|
||||
|
||||
static_cast<BufferTextureData*>(mTextureClient->GetInternalData())->SetDesciptor(
|
||||
YCbCrDescriptor(aData.mYSize, aData.mCbCrSize, yOffset, cbOffset, crOffset,
|
||||
aData.mStereoMode, aData.mYUVColorSpace, hasIntermediateBuffer)
|
||||
aData.mStereoMode, aData.mYUVColorSpace, aData.mColorRange,
|
||||
hasIntermediateBuffer)
|
||||
);
|
||||
|
||||
return true;
|
||||
@@ -221,6 +223,7 @@ SharedPlanarYCbCrImage::Allocate(PlanarYCbCrData& aData)
|
||||
mData.mPicSize = aData.mPicSize;
|
||||
mData.mStereoMode = aData.mStereoMode;
|
||||
mData.mYUVColorSpace = aData.mYUVColorSpace;
|
||||
mData.mColorRange = aData.mColorRange;
|
||||
// those members are not always equal to aData's, due to potentially different
|
||||
// packing.
|
||||
mData.mYSkip = 0;
|
||||
|
||||
@@ -292,6 +292,7 @@ TEST(Layers, TextureYCbCrSerialization) {
|
||||
|
||||
RefPtr<TextureClient> client = TextureClient::CreateForYCbCr(imageBridge, clientData.mYSize, clientData.mCbCrSize,
|
||||
StereoMode::MONO, YUVColorSpace::BT601,
|
||||
ColorRange::LIMITED,
|
||||
TextureFlags::DEALLOCATE_CLIENT);
|
||||
|
||||
TestTextureClientYCbCr(client, clientData);
|
||||
|
||||
Reference in New Issue
Block a user