mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-10-22 15:17:29 +09:00
Issue #2393 - Part 2 - Add D3D11YCbCrImage type and related methods
Will allow to directly upload a YUV420 buffer into a D3D11 texture.
This commit is contained in:
parent
1fc1753d4d
commit
74a22e5c00
9 changed files with 568 additions and 69 deletions
351
gfx/layers/D3D11YCbCrImage.cpp
Normal file
351
gfx/layers/D3D11YCbCrImage.cpp
Normal file
|
|
@ -0,0 +1,351 @@
|
||||||
|
/* -*- 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 "D3D11YCbCrImage.h"
|
||||||
|
|
||||||
|
#include "gfx2DGlue.h"
|
||||||
|
#include "YCbCrUtils.h"
|
||||||
|
#include "mozilla/gfx/gfxVars.h"
|
||||||
|
#include "mozilla/layers/CompositableClient.h"
|
||||||
|
#include "mozilla/layers/CompositableForwarder.h"
|
||||||
|
#include "mozilla/layers/TextureD3D11.h"
|
||||||
|
|
||||||
|
using namespace mozilla::gfx;
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace layers {
|
||||||
|
|
||||||
|
D3D11YCbCrImage::D3D11YCbCrImage()
|
||||||
|
: Image(NULL, ImageFormat::D3D11_YCBCR_IMAGE)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
D3D11YCbCrImage::~D3D11YCbCrImage() { }
|
||||||
|
|
||||||
|
bool
|
||||||
|
D3D11YCbCrImage::SetData(KnowsCompositor* aAllocator,
|
||||||
|
ImageContainer* aContainer,
|
||||||
|
const PlanarYCbCrData& aData)
|
||||||
|
{
|
||||||
|
mPictureRect = IntRect(
|
||||||
|
aData.mPicX, aData.mPicY, aData.mPicSize.width, aData.mPicSize.height);
|
||||||
|
mYSize = aData.mYSize;
|
||||||
|
mCbCrSize = aData.mCbCrSize;
|
||||||
|
mColorSpace = aData.mYUVColorSpace;
|
||||||
|
|
||||||
|
D3D11YCbCrRecycleAllocator* allocator =
|
||||||
|
aContainer->GetD3D11YCbCrRecycleAllocator(aAllocator);
|
||||||
|
if (!allocator) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
allocator->SetSizes(aData.mYSize, aData.mCbCrSize);
|
||||||
|
|
||||||
|
mTextureClient = allocator->CreateOrRecycle(SurfaceFormat::A8,
|
||||||
|
mYSize,
|
||||||
|
BackendSelector::Content,
|
||||||
|
TextureFlags::DEFAULT);
|
||||||
|
if (!mTextureClient) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
DXGIYCbCrTextureData *data =
|
||||||
|
static_cast<DXGIYCbCrTextureData*>(mTextureClient->GetInternalData());
|
||||||
|
|
||||||
|
ID3D11Texture2D* textureY = data->GetD3D11Texture(0);
|
||||||
|
ID3D11Texture2D* textureCb = data->GetD3D11Texture(1);
|
||||||
|
ID3D11Texture2D* textureCr = data->GetD3D11Texture(2);
|
||||||
|
|
||||||
|
RefPtr<ID3D10Multithread> mt;
|
||||||
|
HRESULT hr = allocator->GetDevice()->QueryInterface(
|
||||||
|
(ID3D10Multithread**)getter_AddRefs(mt));
|
||||||
|
|
||||||
|
if (FAILED(hr) || !mt) {
|
||||||
|
gfxCriticalError() << "Multithread safety interface not supported. " << hr;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mt->GetMultithreadProtected()) {
|
||||||
|
gfxCriticalError() << "Device used not marked as multithread-safe.";
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
mt->Enter();
|
||||||
|
|
||||||
|
RefPtr<ID3D11DeviceContext> ctx;
|
||||||
|
allocator->GetDevice()->GetImmediateContext(getter_AddRefs(ctx));
|
||||||
|
|
||||||
|
AutoLockD3D11Texture lockY(textureY);
|
||||||
|
AutoLockD3D11Texture lockCb(textureCb);
|
||||||
|
AutoLockD3D11Texture lockCr(textureCr);
|
||||||
|
|
||||||
|
ctx->UpdateSubresource(textureY,
|
||||||
|
0,
|
||||||
|
nullptr,
|
||||||
|
aData.mYChannel,
|
||||||
|
aData.mYStride,
|
||||||
|
aData.mYStride * aData.mYSize.height);
|
||||||
|
ctx->UpdateSubresource(textureCb,
|
||||||
|
0,
|
||||||
|
nullptr,
|
||||||
|
aData.mCbChannel,
|
||||||
|
aData.mCbCrStride,
|
||||||
|
aData.mCbCrStride * aData.mCbCrSize.height);
|
||||||
|
ctx->UpdateSubresource(textureCr,
|
||||||
|
0,
|
||||||
|
nullptr,
|
||||||
|
aData.mCrChannel,
|
||||||
|
aData.mCbCrStride,
|
||||||
|
aData.mCbCrStride * aData.mCbCrSize.height);
|
||||||
|
|
||||||
|
mt->Leave();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
IntSize
|
||||||
|
D3D11YCbCrImage::GetSize()
|
||||||
|
{
|
||||||
|
return mPictureRect.Size();
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureClient*
|
||||||
|
D3D11YCbCrImage::GetTextureClient(KnowsCompositor* aForwarder)
|
||||||
|
{
|
||||||
|
return mTextureClient;
|
||||||
|
}
|
||||||
|
|
||||||
|
already_AddRefed<SourceSurface>
|
||||||
|
D3D11YCbCrImage::GetAsSourceSurface()
|
||||||
|
{
|
||||||
|
if (!mTextureClient) {
|
||||||
|
gfxWarning()
|
||||||
|
<< "GetAsSourceSurface() called on uninitialized D3D11YCbCrImage.";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx::IntSize size(mPictureRect.Size());
|
||||||
|
gfx::SurfaceFormat format =
|
||||||
|
gfx::ImageFormatToSurfaceFormat(gfxVars::OffscreenFormat());
|
||||||
|
HRESULT hr;
|
||||||
|
|
||||||
|
PlanarYCbCrData data;
|
||||||
|
|
||||||
|
DXGIYCbCrTextureData *dxgiData =
|
||||||
|
static_cast<DXGIYCbCrTextureData*>(mTextureClient->GetInternalData());
|
||||||
|
|
||||||
|
if (!dxgiData) {
|
||||||
|
gfxCriticalError() << "Failed to get texture client internal data.";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<ID3D11Texture2D> texY = dxgiData->GetD3D11Texture(0);
|
||||||
|
RefPtr<ID3D11Texture2D> texCb = dxgiData->GetD3D11Texture(1);
|
||||||
|
RefPtr<ID3D11Texture2D> texCr = dxgiData->GetD3D11Texture(2);
|
||||||
|
RefPtr<ID3D11Texture2D> softTexY, softTexCb, softTexCr;
|
||||||
|
D3D11_TEXTURE2D_DESC desc;
|
||||||
|
|
||||||
|
RefPtr<ID3D11Device> dev;
|
||||||
|
texY->GetDevice(getter_AddRefs(dev));
|
||||||
|
|
||||||
|
RefPtr<ID3D10Multithread> mt;
|
||||||
|
hr = dev->QueryInterface((ID3D10Multithread**)getter_AddRefs(mt));
|
||||||
|
|
||||||
|
if (FAILED(hr) || !mt) {
|
||||||
|
gfxCriticalError() << "Multithread safety interface not supported.";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mt->GetMultithreadProtected()) {
|
||||||
|
gfxCriticalError() << "Device used not marked as multithread-safe.";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
class D3D11MTAutoEnter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit D3D11MTAutoEnter(already_AddRefed<ID3D10Multithread> aMT)
|
||||||
|
: mMT(aMT)
|
||||||
|
{
|
||||||
|
mMT->Enter();
|
||||||
|
}
|
||||||
|
~D3D11MTAutoEnter()
|
||||||
|
{
|
||||||
|
mMT->Leave();
|
||||||
|
}
|
||||||
|
private:
|
||||||
|
RefPtr<ID3D10Multithread> mMT;
|
||||||
|
} mtAutoEnter(mt.forget());
|
||||||
|
|
||||||
|
texY->GetDesc(&desc);
|
||||||
|
desc.BindFlags = 0;
|
||||||
|
desc.MiscFlags = 0;
|
||||||
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||||
|
desc.Usage = D3D11_USAGE_STAGING;
|
||||||
|
|
||||||
|
dev->CreateTexture2D(&desc, nullptr, getter_AddRefs(softTexY));
|
||||||
|
|
||||||
|
texCb->GetDesc(&desc);
|
||||||
|
desc.BindFlags = 0;
|
||||||
|
desc.MiscFlags = 0;
|
||||||
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||||
|
desc.Usage = D3D11_USAGE_STAGING;
|
||||||
|
|
||||||
|
dev->CreateTexture2D(&desc, nullptr, getter_AddRefs(softTexCb));
|
||||||
|
|
||||||
|
texCr->GetDesc(&desc);
|
||||||
|
desc.BindFlags = 0;
|
||||||
|
desc.MiscFlags = 0;
|
||||||
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||||
|
desc.Usage = D3D11_USAGE_STAGING;
|
||||||
|
|
||||||
|
dev->CreateTexture2D(&desc, nullptr, getter_AddRefs(softTexCr));
|
||||||
|
|
||||||
|
RefPtr<ID3D11DeviceContext> ctx;
|
||||||
|
dev->GetImmediateContext(getter_AddRefs(ctx));
|
||||||
|
|
||||||
|
{
|
||||||
|
AutoLockD3D11Texture lockY(texY);
|
||||||
|
AutoLockD3D11Texture lockCb(texCb);
|
||||||
|
AutoLockD3D11Texture lockCr(texCr);
|
||||||
|
ctx->CopyResource(softTexY, texY);
|
||||||
|
ctx->CopyResource(softTexCb, texCb);
|
||||||
|
ctx->CopyResource(softTexCr, texCr);
|
||||||
|
}
|
||||||
|
|
||||||
|
D3D11_MAPPED_SUBRESOURCE mapY, mapCb, mapCr;
|
||||||
|
RefPtr<gfx::DataSourceSurface> surface;
|
||||||
|
mapY.pData = mapCb.pData = mapCr.pData = nullptr;
|
||||||
|
|
||||||
|
hr = ctx->Map(softTexY, 0, D3D11_MAP_READ, 0, &mapY);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
gfxCriticalError() << "Failed to map Y plane (" << hr << ")";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
hr = ctx->Map(softTexCb, 0, D3D11_MAP_READ, 0, &mapCb);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
gfxCriticalError() << "Failed to map Y plane (" << hr << ")";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
hr = ctx->Map(softTexCr, 0, D3D11_MAP_READ, 0, &mapCr);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
gfxCriticalError() << "Failed to map Y plane (" << hr << ")";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
MOZ_ASSERT(mapCb.RowPitch == mapCr.RowPitch);
|
||||||
|
|
||||||
|
data.mPicX = mPictureRect.x;
|
||||||
|
data.mPicY = mPictureRect.y;
|
||||||
|
data.mPicSize = mPictureRect.Size();
|
||||||
|
data.mStereoMode = StereoMode::MONO;
|
||||||
|
data.mYUVColorSpace = mColorSpace;
|
||||||
|
data.mYSkip = data.mCbSkip = data.mCrSkip = 0;
|
||||||
|
data.mYSize = mYSize;
|
||||||
|
data.mCbCrSize = mCbCrSize;
|
||||||
|
data.mYChannel = static_cast<uint8_t*>(mapY.pData);
|
||||||
|
data.mYStride = mapY.RowPitch;
|
||||||
|
data.mCbChannel = static_cast<uint8_t*>(mapCb.pData);
|
||||||
|
data.mCrChannel = static_cast<uint8_t*>(mapCr.pData);
|
||||||
|
data.mCbCrStride = mapCb.RowPitch;
|
||||||
|
|
||||||
|
gfx::GetYCbCrToRGBDestFormatAndSize(data, format, size);
|
||||||
|
if (size.width > PlanarYCbCrImage::MAX_DIMENSION ||
|
||||||
|
size.height > PlanarYCbCrImage::MAX_DIMENSION) {
|
||||||
|
gfxCriticalError() << "Illegal image dest width or height";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
surface = gfx::Factory::CreateDataSourceSurface(size, format);
|
||||||
|
if (!surface) {
|
||||||
|
gfxCriticalError() << "Failed to create DataSourceSurface for image: "
|
||||||
|
<< size << " " << format;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
DataSourceSurface::ScopedMap mapping(surface, DataSourceSurface::WRITE);
|
||||||
|
if (!mapping.IsMapped()) {
|
||||||
|
gfxCriticalError() << "Failed to map DataSourceSurface for D3D11YCbCrImage";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx::ConvertYCbCrToRGB(
|
||||||
|
data, format, size, mapping.GetData(), mapping.GetStride());
|
||||||
|
|
||||||
|
ctx->Unmap(softTexY, 0);
|
||||||
|
ctx->Unmap(softTexCb, 0);
|
||||||
|
ctx->Unmap(softTexCr, 0);
|
||||||
|
|
||||||
|
return surface.forget();
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
D3D11YCbCrRecycleAllocator::SetSizes(const gfx::IntSize& aYSize,
|
||||||
|
const gfx::IntSize& aCbCrSize)
|
||||||
|
{
|
||||||
|
mYSize = Some(aYSize);
|
||||||
|
mCbCrSize = Some(aCbCrSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
already_AddRefed<TextureClient>
|
||||||
|
D3D11YCbCrRecycleAllocator::Allocate(SurfaceFormat aFormat,
|
||||||
|
IntSize aSize,
|
||||||
|
BackendSelector aSelector,
|
||||||
|
TextureFlags aTextureFlags,
|
||||||
|
TextureAllocationFlags aAllocFlags)
|
||||||
|
{
|
||||||
|
MOZ_ASSERT(aFormat == SurfaceFormat::A8);
|
||||||
|
|
||||||
|
gfx::IntSize YSize = mYSize.refOr(aSize);
|
||||||
|
gfx::IntSize CbCrSize =
|
||||||
|
mCbCrSize.refOr(gfx::IntSize(YSize.width, YSize.height));
|
||||||
|
CD3D11_TEXTURE2D_DESC newDesc(DXGI_FORMAT_R8_UNORM, YSize.width, YSize.height,
|
||||||
|
1, 1);
|
||||||
|
newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
||||||
|
|
||||||
|
RefPtr<ID3D10Multithread> mt;
|
||||||
|
HRESULT hr = mDevice->QueryInterface(
|
||||||
|
(ID3D10Multithread**)getter_AddRefs(mt));
|
||||||
|
|
||||||
|
if (FAILED(hr) || !mt) {
|
||||||
|
gfxCriticalError() << "Multithread safety interface not supported. " << hr;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!mt->GetMultithreadProtected()) {
|
||||||
|
gfxCriticalError() << "Device used not marked as multithread-safe.";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
D3D11MTAutoEnter mtAutoEnter(mt.forget());
|
||||||
|
|
||||||
|
RefPtr<ID3D11Texture2D> textureY;
|
||||||
|
hr = mDevice->CreateTexture2D(&newDesc, nullptr, getter_AddRefs(textureY));
|
||||||
|
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
|
||||||
|
|
||||||
|
newDesc.Width = CbCrSize.width;
|
||||||
|
newDesc.Height = CbCrSize.height;
|
||||||
|
|
||||||
|
RefPtr<ID3D11Texture2D> textureCb;
|
||||||
|
hr = mDevice->CreateTexture2D(&newDesc, nullptr, getter_AddRefs(textureCb));
|
||||||
|
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
|
||||||
|
|
||||||
|
RefPtr<ID3D11Texture2D> textureCr;
|
||||||
|
hr = mDevice->CreateTexture2D(&newDesc, nullptr, getter_AddRefs(textureCr));
|
||||||
|
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
|
||||||
|
|
||||||
|
return TextureClient::CreateWithData(
|
||||||
|
DXGIYCbCrTextureData::Create(
|
||||||
|
textureY,
|
||||||
|
textureCb,
|
||||||
|
textureCr,
|
||||||
|
aSize,
|
||||||
|
YSize,
|
||||||
|
CbCrSize),
|
||||||
|
TextureFlags::DEFAULT,
|
||||||
|
mSurfaceAllocator->GetTextureForwarder());
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace layers
|
||||||
|
} // namespace mozilla
|
||||||
78
gfx/layers/D3D11YCbCrImage.h
Normal file
78
gfx/layers/D3D11YCbCrImage.h
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
/* -*- 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 GFX_D3D11_YCBCR_IMAGE_H
|
||||||
|
#define GFX_D3D11_YCBCR_IMAGE_H
|
||||||
|
|
||||||
|
#include "d3d11.h"
|
||||||
|
#include "mozilla/layers/TextureClientRecycleAllocator.h"
|
||||||
|
#include "mozilla/Maybe.h"
|
||||||
|
#include "ImageContainer.h"
|
||||||
|
|
||||||
|
namespace mozilla {
|
||||||
|
namespace layers {
|
||||||
|
|
||||||
|
class ImageContainer;
|
||||||
|
class DXGIYCbCrTextureClient;
|
||||||
|
|
||||||
|
class D3D11YCbCrRecycleAllocator : public TextureClientRecycleAllocator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit D3D11YCbCrRecycleAllocator(KnowsCompositor* aAllocator,
|
||||||
|
ID3D11Device* aDevice)
|
||||||
|
: TextureClientRecycleAllocator(aAllocator)
|
||||||
|
, mDevice(aDevice)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ID3D11Device* GetDevice() { return mDevice; }
|
||||||
|
KnowsCompositor* GetAllocator() { return mSurfaceAllocator; }
|
||||||
|
void SetSizes(const gfx::IntSize& aYSize, const gfx::IntSize& aCbCrSize);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
already_AddRefed<TextureClient>
|
||||||
|
Allocate(gfx::SurfaceFormat aFormat,
|
||||||
|
gfx::IntSize aSize,
|
||||||
|
BackendSelector aSelector,
|
||||||
|
TextureFlags aTextureFlags,
|
||||||
|
TextureAllocationFlags aAllocFlags) override;
|
||||||
|
|
||||||
|
RefPtr<ID3D11Device> mDevice;
|
||||||
|
Maybe<gfx::IntSize> mYSize;
|
||||||
|
Maybe<gfx::IntSize> mCbCrSize;
|
||||||
|
};
|
||||||
|
|
||||||
|
class D3D11YCbCrImage : public Image
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
D3D11YCbCrImage();
|
||||||
|
virtual ~D3D11YCbCrImage();
|
||||||
|
|
||||||
|
// Copies the surface into a sharable texture's surface, and initializes
|
||||||
|
// the image.
|
||||||
|
bool SetData(KnowsCompositor* aAllocator,
|
||||||
|
ImageContainer* aContainer,
|
||||||
|
const PlanarYCbCrData& aData);
|
||||||
|
|
||||||
|
gfx::IntSize GetSize() override;
|
||||||
|
|
||||||
|
already_AddRefed<gfx::SourceSurface> GetAsSourceSurface() override;
|
||||||
|
|
||||||
|
TextureClient* GetTextureClient(KnowsCompositor* aForwarder) override;
|
||||||
|
|
||||||
|
gfx::IntRect GetPictureRect() override { return mPictureRect; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
gfx::IntSize mYSize;
|
||||||
|
gfx::IntSize mCbCrSize;
|
||||||
|
gfx::IntRect mPictureRect;
|
||||||
|
YUVColorSpace mColorSpace;
|
||||||
|
RefPtr<TextureClient> mTextureClient;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namepace layers
|
||||||
|
} // namespace mozilla
|
||||||
|
|
||||||
|
#endif // GFX_D3D11_YCBCR_IMAGE_H
|
||||||
|
|
@ -34,38 +34,6 @@ IMFYCbCrImage::~IMFYCbCrImage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct AutoLockTexture
|
|
||||||
{
|
|
||||||
AutoLockTexture(ID3D11Texture2D* aTexture)
|
|
||||||
{
|
|
||||||
aTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mMutex));
|
|
||||||
if (!mMutex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
HRESULT hr = mMutex->AcquireSync(0, 10000);
|
|
||||||
if (hr == WAIT_TIMEOUT) {
|
|
||||||
MOZ_CRASH("GFX: IMFYCbCrImage timeout");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (FAILED(hr)) {
|
|
||||||
NS_WARNING("Failed to lock the texture");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~AutoLockTexture()
|
|
||||||
{
|
|
||||||
if (!mMutex) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
HRESULT hr = mMutex->ReleaseSync(0);
|
|
||||||
if (FAILED(hr)) {
|
|
||||||
NS_WARNING("Failed to unlock the texture");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
RefPtr<IDXGIKeyedMutex> mMutex;
|
|
||||||
};
|
|
||||||
|
|
||||||
static already_AddRefed<IDirect3DTexture9>
|
static already_AddRefed<IDirect3DTexture9>
|
||||||
InitTextures(IDirect3DDevice9* aDevice,
|
InitTextures(IDirect3DDevice9* aDevice,
|
||||||
const IntSize &aSize,
|
const IntSize &aSize,
|
||||||
|
|
@ -302,9 +270,9 @@ IMFYCbCrImage::GetTextureClient(KnowsCompositor* aForwarder)
|
||||||
// required but were added for extra security.
|
// required but were added for extra security.
|
||||||
|
|
||||||
{
|
{
|
||||||
AutoLockTexture lockY(textureY);
|
AutoLockD3D11Texture lockY(textureY);
|
||||||
AutoLockTexture lockCr(textureCr);
|
AutoLockD3D11Texture lockCr(textureCr);
|
||||||
AutoLockTexture lockCb(textureCb);
|
AutoLockD3D11Texture lockCb(textureCb);
|
||||||
|
|
||||||
mt->Enter();
|
mt->Enter();
|
||||||
|
|
||||||
|
|
@ -327,9 +295,9 @@ IMFYCbCrImage::GetTextureClient(KnowsCompositor* aForwarder)
|
||||||
}
|
}
|
||||||
|
|
||||||
mTextureClient = TextureClient::CreateWithData(
|
mTextureClient = TextureClient::CreateWithData(
|
||||||
DXGIYCbCrTextureData::Create(TextureFlags::DEFAULT,
|
DXGIYCbCrTextureData::Create(textureY, textureCb, textureCr,
|
||||||
textureY, textureCb, textureCr,
|
aSize, aData.mYSize, aData.mCbCrSize);
|
||||||
GetSize(), mData.mYSize, mData.mCbCrSize),
|
|
||||||
TextureFlags::DEFAULT,
|
TextureFlags::DEFAULT,
|
||||||
aForwarder->GetTextureForwarder()
|
aForwarder->GetTextureForwarder()
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@
|
||||||
#ifdef XP_WIN
|
#ifdef XP_WIN
|
||||||
#include "gfxWindowsPlatform.h"
|
#include "gfxWindowsPlatform.h"
|
||||||
#include <d3d10_1.h>
|
#include <d3d10_1.h>
|
||||||
|
#include "mozilla/gfx/DeviceManagerDx.h"
|
||||||
|
#include "mozilla/layers/D3D11YCbCrImage.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace mozilla {
|
namespace mozilla {
|
||||||
|
|
@ -395,6 +397,40 @@ ImageContainer::NotifyCompositeInternal(const ImageCompositeNotification& aNotif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef XP_WIN
|
||||||
|
D3D11YCbCrRecycleAllocator*
|
||||||
|
ImageContainer::GetD3D11YCbCrRecycleAllocator(KnowsCompositor* aAllocator)
|
||||||
|
{
|
||||||
|
if (mD3D11YCbCrRecycleAllocator &&
|
||||||
|
aAllocator == mD3D11YCbCrRecycleAllocator->GetAllocator()) {
|
||||||
|
return mD3D11YCbCrRecycleAllocator;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<ID3D11Device> device = gfx::DeviceManagerDx::Get()->GetContentDevice();
|
||||||
|
if (!device) {
|
||||||
|
device = gfx::DeviceManagerDx::Get()->GetCompositorDevice();
|
||||||
|
}
|
||||||
|
|
||||||
|
LayersBackend backend = aAllocator->GetCompositorBackendType();
|
||||||
|
if (!device || backend != LayersBackend::LAYERS_D3D11) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
RefPtr<ID3D10Multithread> multi;
|
||||||
|
HRESULT hr =
|
||||||
|
device->QueryInterface((ID3D10Multithread**)getter_AddRefs(multi));
|
||||||
|
if (FAILED(hr) || !multi) {
|
||||||
|
gfxWarning() << "Multithread safety interface not supported. " << hr;
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
multi->SetMultithreadProtected(TRUE);
|
||||||
|
|
||||||
|
mD3D11YCbCrRecycleAllocator =
|
||||||
|
new D3D11YCbCrRecycleAllocator(aAllocator, device);
|
||||||
|
return mD3D11YCbCrRecycleAllocator;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
PlanarYCbCrImage::PlanarYCbCrImage()
|
PlanarYCbCrImage::PlanarYCbCrImage()
|
||||||
: Image(nullptr, ImageFormat::PLANAR_YCBCR)
|
: Image(nullptr, ImageFormat::PLANAR_YCBCR)
|
||||||
, mOffscreenFormat(SurfaceFormat::UNKNOWN)
|
, mOffscreenFormat(SurfaceFormat::UNKNOWN)
|
||||||
|
|
|
||||||
|
|
@ -153,6 +153,9 @@ class PlanarYCbCrImage;
|
||||||
class TextureClient;
|
class TextureClient;
|
||||||
class KnowsCompositor;
|
class KnowsCompositor;
|
||||||
class NVImage;
|
class NVImage;
|
||||||
|
#ifdef XP_WIN
|
||||||
|
class D3D11YCbCrRecycleAllocator;
|
||||||
|
#endif
|
||||||
|
|
||||||
struct ImageBackendData
|
struct ImageBackendData
|
||||||
{
|
{
|
||||||
|
|
@ -521,6 +524,11 @@ public:
|
||||||
return mImageFactory;
|
return mImageFactory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef XP_WIN
|
||||||
|
D3D11YCbCrRecycleAllocator* GetD3D11YCbCrRecycleAllocator(
|
||||||
|
KnowsCompositor* aAllocator);
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the delay between the last composited image's presentation
|
* Returns the delay between the last composited image's presentation
|
||||||
* timestamp and when it was first composited. It's possible for the delay
|
* timestamp and when it was first composited. It's possible for the delay
|
||||||
|
|
@ -587,6 +595,10 @@ private:
|
||||||
// image", and any other state which is shared between threads.
|
// image", and any other state which is shared between threads.
|
||||||
ReentrantMonitor mReentrantMonitor;
|
ReentrantMonitor mReentrantMonitor;
|
||||||
|
|
||||||
|
#ifdef XP_WIN
|
||||||
|
RefPtr<D3D11YCbCrRecycleAllocator> mD3D11YCbCrRecycleAllocator;
|
||||||
|
#endif
|
||||||
|
|
||||||
nsTArray<OwningImage> mCurrentImages;
|
nsTArray<OwningImage> mCurrentImages;
|
||||||
|
|
||||||
// Updates every time mActiveImage changes
|
// Updates every time mActiveImage changes
|
||||||
|
|
|
||||||
|
|
@ -99,6 +99,11 @@ enum class ImageFormat {
|
||||||
*/
|
*/
|
||||||
TEXTURE_WRAPPER,
|
TEXTURE_WRAPPER,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A D3D11 backed YUV image.
|
||||||
|
*/
|
||||||
|
D3D11_YCBCR_IMAGE,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An opaque handle that refers to an Image stored in the GPU
|
* An opaque handle that refers to an Image stored in the GPU
|
||||||
* process.
|
* process.
|
||||||
|
|
|
||||||
|
|
@ -516,10 +516,9 @@ D3D11TextureData::GetDXGIResource(IDXGIResource** aOutResource)
|
||||||
}
|
}
|
||||||
|
|
||||||
DXGIYCbCrTextureData*
|
DXGIYCbCrTextureData*
|
||||||
DXGIYCbCrTextureData::Create(TextureFlags aFlags,
|
DXGIYCbCrTextureData::Create(IDirect3DTexture9* aTextureY,
|
||||||
IUnknown* aTextureY,
|
IDirect3DTexture9* aTextureCb,
|
||||||
IUnknown* aTextureCb,
|
IDirect3DTexture9* aTextureCr,
|
||||||
IUnknown* aTextureCr,
|
|
||||||
HANDLE aHandleY,
|
HANDLE aHandleY,
|
||||||
HANDLE aHandleCb,
|
HANDLE aHandleCb,
|
||||||
HANDLE aHandleCr,
|
HANDLE aHandleCr,
|
||||||
|
|
@ -536,9 +535,9 @@ DXGIYCbCrTextureData::Create(TextureFlags aFlags,
|
||||||
texture->mHandles[0] = aHandleY;
|
texture->mHandles[0] = aHandleY;
|
||||||
texture->mHandles[1] = aHandleCb;
|
texture->mHandles[1] = aHandleCb;
|
||||||
texture->mHandles[2] = aHandleCr;
|
texture->mHandles[2] = aHandleCr;
|
||||||
texture->mHoldRefs[0] = aTextureY;
|
texture->mD3D9Textures[0] = aTextureY;
|
||||||
texture->mHoldRefs[1] = aTextureCb;
|
texture->mD3D9Textures[1] = aTextureCb;
|
||||||
texture->mHoldRefs[2] = aTextureCr;
|
texture->mD3D9Textures[2] = aTextureCr;
|
||||||
texture->mSize = aSize;
|
texture->mSize = aSize;
|
||||||
texture->mSizeY = aSizeY;
|
texture->mSizeY = aSizeY;
|
||||||
texture->mSizeCbCr = aSizeCbCr;
|
texture->mSizeCbCr = aSizeCbCr;
|
||||||
|
|
@ -547,8 +546,7 @@ DXGIYCbCrTextureData::Create(TextureFlags aFlags,
|
||||||
}
|
}
|
||||||
|
|
||||||
DXGIYCbCrTextureData*
|
DXGIYCbCrTextureData*
|
||||||
DXGIYCbCrTextureData::Create(TextureFlags aFlags,
|
DXGIYCbCrTextureData::Create(ID3D11Texture2D* aTextureY,
|
||||||
ID3D11Texture2D* aTextureY,
|
|
||||||
ID3D11Texture2D* aTextureCb,
|
ID3D11Texture2D* aTextureCb,
|
||||||
ID3D11Texture2D* aTextureCr,
|
ID3D11Texture2D* aTextureCr,
|
||||||
const gfx::IntSize& aSize,
|
const gfx::IntSize& aSize,
|
||||||
|
|
@ -591,10 +589,18 @@ DXGIYCbCrTextureData::Create(TextureFlags aFlags,
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return DXGIYCbCrTextureData::Create(aFlags,
|
DXGIYCbCrTextureData* texture = new DXGIYCbCrTextureData();
|
||||||
aTextureY, aTextureCb, aTextureCr,
|
texture->mHandles[0] = handleY;
|
||||||
handleY, handleCb, handleCr,
|
texture->mHandles[1] = handleCb;
|
||||||
aSize, aSizeY, aSizeCbCr);
|
texture->mHandles[2] = handleCr;
|
||||||
|
texture->mD3D11Textures[0] = aTextureY;
|
||||||
|
texture->mD3D11Textures[1] = aTextureCb;
|
||||||
|
texture->mD3D11Textures[2] = aTextureCr;
|
||||||
|
texture->mSize = aSize;
|
||||||
|
texture->mSizeY = aSizeY;
|
||||||
|
texture->mSizeCbCr = aSizeCbCr;
|
||||||
|
|
||||||
|
return texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -620,9 +626,12 @@ DXGIYCbCrTextureData::Serialize(SurfaceDescriptor& aOutDescriptor)
|
||||||
void
|
void
|
||||||
DXGIYCbCrTextureData::Deallocate(LayersIPCChannel*)
|
DXGIYCbCrTextureData::Deallocate(LayersIPCChannel*)
|
||||||
{
|
{
|
||||||
mHoldRefs[0] = nullptr;
|
mD3D9Textures[0] = nullptr;
|
||||||
mHoldRefs[1] = nullptr;
|
mD3D9Textures[1] = nullptr;
|
||||||
mHoldRefs[2] = nullptr;
|
mD3D9Textures[2] = nullptr;
|
||||||
|
mD3D11Textures[0] = nullptr;
|
||||||
|
mD3D11Textures[1] = nullptr;
|
||||||
|
mD3D11Textures[2] = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
already_AddRefed<TextureHost>
|
already_AddRefed<TextureHost>
|
||||||
|
|
@ -1282,5 +1291,32 @@ SyncObjectD3D11::FinalizeFrame()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
AutoLockD3D11Texture::AutoLockD3D11Texture(ID3D11Texture2D* aTexture)
|
||||||
|
{
|
||||||
|
aTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mMutex));
|
||||||
|
if (!mMutex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HRESULT hr = mMutex->AcquireSync(0, 10000);
|
||||||
|
if (hr == WAIT_TIMEOUT) {
|
||||||
|
MOZ_CRASH("GFX: IMFYCbCrImage timeout");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
NS_WARNING("Failed to lock the texture");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
AutoLockD3D11Texture::~AutoLockD3D11Texture()
|
||||||
|
{
|
||||||
|
if (!mMutex) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HRESULT hr = mMutex->ReleaseSync(0);
|
||||||
|
if (FAILED(hr)) {
|
||||||
|
NS_WARNING("Failed to unlock the texture");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -127,10 +127,9 @@ class DXGIYCbCrTextureData : public TextureData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
static DXGIYCbCrTextureData*
|
static DXGIYCbCrTextureData*
|
||||||
Create(TextureFlags aFlags,
|
Create(IDirect3DTexture9* aTextureY,
|
||||||
IUnknown* aTextureY,
|
IDirect3DTexture9* aTextureCb,
|
||||||
IUnknown* aTextureCb,
|
IDirect3DTexture9* aTextureCr,
|
||||||
IUnknown* aTextureCr,
|
|
||||||
HANDLE aHandleY,
|
HANDLE aHandleY,
|
||||||
HANDLE aHandleCb,
|
HANDLE aHandleCb,
|
||||||
HANDLE aHandleCr,
|
HANDLE aHandleCr,
|
||||||
|
|
@ -139,8 +138,7 @@ public:
|
||||||
const gfx::IntSize& aSizeCbCr);
|
const gfx::IntSize& aSizeCbCr);
|
||||||
|
|
||||||
static DXGIYCbCrTextureData*
|
static DXGIYCbCrTextureData*
|
||||||
Create(TextureFlags aFlags,
|
Create(ID3D11Texture2D* aTextureCb,
|
||||||
ID3D11Texture2D* aTextureCb,
|
|
||||||
ID3D11Texture2D* aTextureY,
|
ID3D11Texture2D* aTextureY,
|
||||||
ID3D11Texture2D* aTextureCr,
|
ID3D11Texture2D* aTextureCr,
|
||||||
const gfx::IntSize& aSize,
|
const gfx::IntSize& aSize,
|
||||||
|
|
@ -166,8 +164,11 @@ public:
|
||||||
return TextureFlags::DEALLOCATE_MAIN_THREAD;
|
return TextureFlags::DEALLOCATE_MAIN_THREAD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ID3D11Texture2D* GetD3D11Texture(size_t index) { return mD3D11Textures[index]; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
RefPtr<IUnknown> mHoldRefs[3];
|
RefPtr<ID3D11Texture2D> mD3D11Textures[3];
|
||||||
|
RefPtr<IDirect3DTexture9> mD3D9Textures[3];
|
||||||
HANDLE mHandles[3];
|
HANDLE mHandles[3];
|
||||||
gfx::IntSize mSize;
|
gfx::IntSize mSize;
|
||||||
gfx::IntSize mSizeY;
|
gfx::IntSize mSizeY;
|
||||||
|
|
@ -450,6 +451,16 @@ inline uint32_t GetMaxTextureSizeForFeatureLevel(D3D_FEATURE_LEVEL aFeatureLevel
|
||||||
return maxTextureSize;
|
return maxTextureSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AutoLockD3D11Texture
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit AutoLockD3D11Texture(ID3D11Texture2D* aTexture);
|
||||||
|
~AutoLockD3D11Texture();
|
||||||
|
|
||||||
|
private:
|
||||||
|
RefPtr<IDXGIKeyedMutex> mMutex;
|
||||||
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,7 @@ EXPORTS += [
|
||||||
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
|
if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'windows':
|
||||||
SOURCES += [
|
SOURCES += [
|
||||||
'D3D11ShareHandleImage.cpp',
|
'D3D11ShareHandleImage.cpp',
|
||||||
|
'D3D11YCbCrImage.cpp',
|
||||||
]
|
]
|
||||||
UNIFIED_SOURCES += [
|
UNIFIED_SOURCES += [
|
||||||
'D3D9SurfaceImage.cpp',
|
'D3D9SurfaceImage.cpp',
|
||||||
|
|
@ -153,6 +154,7 @@ EXPORTS.mozilla.layers += [
|
||||||
'Compositor.h',
|
'Compositor.h',
|
||||||
'CompositorTypes.h',
|
'CompositorTypes.h',
|
||||||
'D3D11ShareHandleImage.h',
|
'D3D11ShareHandleImage.h',
|
||||||
|
'D3D11YCbCrImage.h',
|
||||||
'D3D9SurfaceImage.h',
|
'D3D9SurfaceImage.h',
|
||||||
'Effects.h',
|
'Effects.h',
|
||||||
'ImageDataSerializer.h',
|
'ImageDataSerializer.h',
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue