2017-10-28 02:10:06 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2017-05-04 00:23:45 +03:00
|
|
|
* 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"
|
2018-07-31 02:13:19 +03:00
|
|
|
|
|
|
|
#include "gfx2DGlue.h"
|
2017-05-04 00:23:45 +03:00
|
|
|
#include "YCbCrUtils.h"
|
|
|
|
#include "mozilla/gfx/gfxVars.h"
|
2018-05-31 03:35:24 +03:00
|
|
|
#include "mozilla/gfx/DeviceManagerDx.h"
|
2017-05-04 00:23:45 +03:00
|
|
|
#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;
|
2018-09-25 23:44:55 +03:00
|
|
|
mColorDepth = aData.mColorDepth;
|
2017-05-04 00:23:45 +03:00
|
|
|
mColorSpace = aData.mYUVColorSpace;
|
|
|
|
|
|
|
|
D3D11YCbCrRecycleAllocator* allocator =
|
|
|
|
aContainer->GetD3D11YCbCrRecycleAllocator(aAllocator);
|
|
|
|
if (!allocator) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-31 03:35:24 +03:00
|
|
|
RefPtr<ID3D11Device> device = gfx::DeviceManagerDx::Get()->GetImageDevice();
|
|
|
|
if (!device) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-10 12:15:54 +03:00
|
|
|
{
|
2018-05-31 03:35:24 +03:00
|
|
|
DXGIYCbCrTextureAllocationHelper helper(aData, TextureFlags::DEFAULT, device);
|
2017-11-10 12:15:54 +03:00
|
|
|
mTextureClient = allocator->CreateOrRecycle(helper);
|
|
|
|
}
|
|
|
|
|
2017-05-04 00:23:45 +03:00
|
|
|
if (!mTextureClient) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-10 12:15:54 +03:00
|
|
|
DXGIYCbCrTextureData* data =
|
|
|
|
mTextureClient->GetInternalData()->AsDXGIYCbCrTextureData();
|
2017-05-04 00:23:45 +03:00
|
|
|
|
|
|
|
ID3D11Texture2D* textureY = data->GetD3D11Texture(0);
|
|
|
|
ID3D11Texture2D* textureCb = data->GetD3D11Texture(1);
|
|
|
|
ID3D11Texture2D* textureCr = data->GetD3D11Texture(2);
|
|
|
|
|
|
|
|
RefPtr<ID3D10Multithread> mt;
|
2018-05-31 03:35:24 +03:00
|
|
|
HRESULT hr = device->QueryInterface(
|
2017-05-04 00:23:45 +03:00
|
|
|
(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;
|
|
|
|
}
|
|
|
|
|
2017-06-20 21:45:40 +03:00
|
|
|
D3D11MTAutoEnter mtAutoEnter(mt.forget());
|
2017-05-04 00:23:45 +03:00
|
|
|
|
|
|
|
RefPtr<ID3D11DeviceContext> ctx;
|
2018-05-31 03:35:24 +03:00
|
|
|
device->GetImmediateContext(getter_AddRefs(ctx));
|
2017-10-10 13:09:37 +03:00
|
|
|
if (!ctx) {
|
|
|
|
gfxCriticalError() << "Failed to get immediate context.";
|
|
|
|
return false;
|
|
|
|
}
|
2017-05-04 00:23:45 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
|
2017-05-04 00:23:45 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntSize
|
2017-11-30 21:03:02 +03:00
|
|
|
D3D11YCbCrImage::GetSize() const
|
2017-05-04 00:23:45 +03:00
|
|
|
{
|
|
|
|
return mPictureRect.Size();
|
|
|
|
}
|
|
|
|
|
|
|
|
TextureClient*
|
|
|
|
D3D11YCbCrImage::GetTextureClient(KnowsCompositor* aForwarder)
|
|
|
|
{
|
|
|
|
return mTextureClient;
|
|
|
|
}
|
|
|
|
|
2017-07-18 05:17:41 +03:00
|
|
|
const DXGIYCbCrTextureData*
|
|
|
|
D3D11YCbCrImage::GetData() const
|
|
|
|
{
|
|
|
|
if (!mTextureClient)
|
|
|
|
return nullptr;
|
|
|
|
|
2017-11-10 12:15:54 +03:00
|
|
|
return mTextureClient->GetInternalData()->AsDXGIYCbCrTextureData();
|
2017-07-18 05:17:41 +03:00
|
|
|
}
|
|
|
|
|
2017-05-04 00:23:45 +03:00
|
|
|
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;
|
|
|
|
|
2017-11-10 12:15:54 +03:00
|
|
|
DXGIYCbCrTextureData* dxgiData =
|
|
|
|
mTextureClient->GetInternalData()->AsDXGIYCbCrTextureData();
|
2017-05-04 00:23:45 +03:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-06-20 21:45:40 +03:00
|
|
|
D3D11MTAutoEnter mtAutoEnter(mt.forget());
|
2017-05-04 00:23:45 +03:00
|
|
|
|
|
|
|
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));
|
2017-11-15 13:13:12 +03:00
|
|
|
|
|
|
|
texCr->GetDesc(&desc);
|
|
|
|
desc.BindFlags = 0;
|
|
|
|
desc.MiscFlags = 0;
|
|
|
|
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
|
|
|
desc.Usage = D3D11_USAGE_STAGING;
|
|
|
|
|
2017-05-04 00:23:45 +03:00
|
|
|
dev->CreateTexture2D(&desc, nullptr, getter_AddRefs(softTexCr));
|
|
|
|
|
|
|
|
RefPtr<ID3D11DeviceContext> ctx;
|
|
|
|
dev->GetImmediateContext(getter_AddRefs(ctx));
|
2017-10-10 13:09:37 +03:00
|
|
|
if (!ctx) {
|
|
|
|
gfxCriticalError() << "Failed to get immediate context.";
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-05-04 00:23:45 +03:00
|
|
|
|
|
|
|
{
|
|
|
|
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);
|
|
|
|
|
2017-12-19 23:48:39 +03:00
|
|
|
data.mPicX = mPictureRect.X();
|
|
|
|
data.mPicY = mPictureRect.Y();
|
2017-05-04 00:23:45 +03:00
|
|
|
data.mPicSize = mPictureRect.Size();
|
|
|
|
data.mStereoMode = StereoMode::MONO;
|
2018-09-25 23:44:55 +03:00
|
|
|
data.mColorDepth = mColorDepth;
|
2017-05-04 00:23:45 +03:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-09-07 17:12:27 +03:00
|
|
|
class AutoCheckLockD3D11Texture
|
|
|
|
{
|
|
|
|
public:
|
2018-09-07 17:52:33 +03:00
|
|
|
explicit AutoCheckLockD3D11Texture(ID3D11Texture2D* aTexture)
|
2018-09-07 17:12:27 +03:00
|
|
|
: mIsLocked(false)
|
|
|
|
{
|
|
|
|
aTexture->QueryInterface((IDXGIKeyedMutex**)getter_AddRefs(mMutex));
|
|
|
|
if (!mMutex) {
|
|
|
|
// If D3D11Texture does not have keyed mutex, we think that the D3D11Texture could be locked.
|
|
|
|
mIsLocked = true;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test to see if the keyed mutex has been released
|
|
|
|
HRESULT hr = mMutex->AcquireSync(0, 0);
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
mIsLocked = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoCheckLockD3D11Texture()
|
|
|
|
{
|
|
|
|
if (!mMutex) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
HRESULT hr = mMutex->ReleaseSync(0);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
NS_WARNING("Failed to unlock the texture");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IsLocked() const
|
|
|
|
{
|
|
|
|
return mIsLocked;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mIsLocked;
|
|
|
|
RefPtr<IDXGIKeyedMutex> mMutex;
|
|
|
|
};
|
|
|
|
|
2017-11-10 12:15:54 +03:00
|
|
|
DXGIYCbCrTextureAllocationHelper::DXGIYCbCrTextureAllocationHelper(const PlanarYCbCrData& aData,
|
|
|
|
TextureFlags aTextureFlags,
|
|
|
|
ID3D11Device* aDevice)
|
|
|
|
: ITextureClientAllocationHelper(gfx::SurfaceFormat::YUV,
|
|
|
|
aData.mYSize,
|
|
|
|
BackendSelector::Content,
|
|
|
|
aTextureFlags,
|
|
|
|
ALLOC_DEFAULT)
|
|
|
|
, mData(aData)
|
|
|
|
, mDevice(aDevice)
|
2017-05-04 00:23:45 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2017-11-10 12:15:54 +03:00
|
|
|
bool
|
|
|
|
DXGIYCbCrTextureAllocationHelper::IsCompatible(TextureClient* aTextureClient)
|
2017-05-04 00:23:45 +03:00
|
|
|
{
|
2017-11-10 12:15:54 +03:00
|
|
|
MOZ_ASSERT(aTextureClient->GetFormat() == gfx::SurfaceFormat::YUV);
|
|
|
|
|
|
|
|
DXGIYCbCrTextureData* dxgiData = aTextureClient->GetInternalData()->AsDXGIYCbCrTextureData();
|
|
|
|
if (!dxgiData ||
|
|
|
|
aTextureClient->GetSize() != mData.mYSize ||
|
|
|
|
dxgiData->GetYSize() != mData.mYSize ||
|
|
|
|
dxgiData->GetCbCrSize() != mData.mCbCrSize ||
|
2018-09-25 23:44:55 +03:00
|
|
|
dxgiData->GetColorDepth() != mData.mColorDepth ||
|
2017-11-10 12:15:54 +03:00
|
|
|
dxgiData->GetYUVColorSpace() != mData.mYUVColorSpace) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-31 03:35:24 +03:00
|
|
|
|
2018-09-07 17:12:27 +03:00
|
|
|
ID3D11Texture2D* textureY = dxgiData->GetD3D11Texture(0);
|
|
|
|
ID3D11Texture2D* textureCb = dxgiData->GetD3D11Texture(1);
|
|
|
|
ID3D11Texture2D* textureCr = dxgiData->GetD3D11Texture(2);
|
|
|
|
|
2018-05-31 03:35:24 +03:00
|
|
|
RefPtr<ID3D11Device> device;
|
2018-09-07 17:12:27 +03:00
|
|
|
textureY->GetDevice(getter_AddRefs(device));
|
2018-05-31 03:35:24 +03:00
|
|
|
if (!device || device != gfx::DeviceManagerDx::Get()->GetImageDevice()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-09-07 17:12:27 +03:00
|
|
|
// Test to see if the keyed mutex has been released.
|
|
|
|
// If D3D11Texture failed to lock, do not recycle the DXGIYCbCrTextureData.
|
|
|
|
|
|
|
|
AutoCheckLockD3D11Texture lockY(textureY);
|
|
|
|
AutoCheckLockD3D11Texture lockCr(textureCr);
|
|
|
|
AutoCheckLockD3D11Texture lockCb(textureCb);
|
|
|
|
|
|
|
|
if (!lockY.IsLocked() ||
|
|
|
|
!lockCr.IsLocked() ||
|
|
|
|
!lockCb.IsLocked()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-10 12:15:54 +03:00
|
|
|
return true;
|
|
|
|
}
|
2017-05-04 00:23:45 +03:00
|
|
|
|
2017-11-10 12:15:54 +03:00
|
|
|
already_AddRefed<TextureClient>
|
|
|
|
DXGIYCbCrTextureAllocationHelper::Allocate(KnowsCompositor* aAllocator)
|
|
|
|
{
|
2018-09-25 23:44:55 +03:00
|
|
|
CD3D11_TEXTURE2D_DESC newDesc(mData.mColorDepth == gfx::ColorDepth::COLOR_8
|
|
|
|
? DXGI_FORMAT_R8_UNORM
|
|
|
|
: DXGI_FORMAT_R16_UNORM,
|
|
|
|
mData.mYSize.width,
|
|
|
|
mData.mYSize.height,
|
|
|
|
1,
|
|
|
|
1);
|
2018-06-28 06:56:36 +03:00
|
|
|
// WebRender requests keyed mutex
|
|
|
|
if (mDevice == gfx::DeviceManagerDx::Get()->GetCompositorDevice() &&
|
|
|
|
!gfxVars::UseWebRender()) {
|
|
|
|
newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
|
|
|
|
} else {
|
|
|
|
newDesc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
|
|
|
|
}
|
2017-05-04 00:23:45 +03:00
|
|
|
|
2017-10-09 12:05:49 +03:00
|
|
|
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());
|
|
|
|
|
2017-05-04 00:23:45 +03:00
|
|
|
RefPtr<ID3D11Texture2D> textureY;
|
2017-10-09 12:05:49 +03:00
|
|
|
hr = mDevice->CreateTexture2D(&newDesc, nullptr, getter_AddRefs(textureY));
|
2017-05-04 00:23:45 +03:00
|
|
|
NS_ENSURE_TRUE(SUCCEEDED(hr), nullptr);
|
|
|
|
|
2017-11-10 12:15:54 +03:00
|
|
|
newDesc.Width = mData.mCbCrSize.width;
|
|
|
|
newDesc.Height = mData.mCbCrSize.height;
|
2017-05-04 00:23:45 +03:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2018-06-28 06:56:36 +03:00
|
|
|
TextureForwarder* forwarder = aAllocator ? aAllocator->GetTextureForwarder() : nullptr;
|
|
|
|
|
2017-05-04 00:23:45 +03:00
|
|
|
return TextureClient::CreateWithData(
|
|
|
|
DXGIYCbCrTextureData::Create(
|
|
|
|
textureY,
|
|
|
|
textureCb,
|
|
|
|
textureCr,
|
2017-11-10 12:15:54 +03:00
|
|
|
mData.mYSize,
|
|
|
|
mData.mYSize,
|
|
|
|
mData.mCbCrSize,
|
2018-09-25 23:44:55 +03:00
|
|
|
mData.mColorDepth,
|
2017-11-10 12:15:54 +03:00
|
|
|
mData.mYUVColorSpace),
|
|
|
|
mTextureFlags,
|
2018-06-28 06:56:36 +03:00
|
|
|
forwarder);
|
2017-11-10 12:15:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<TextureClient>
|
|
|
|
D3D11YCbCrRecycleAllocator::Allocate(SurfaceFormat aFormat,
|
|
|
|
IntSize aSize,
|
|
|
|
BackendSelector aSelector,
|
|
|
|
TextureFlags aTextureFlags,
|
|
|
|
TextureAllocationFlags aAllocFlags)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT_UNREACHABLE("unexpected to be called");
|
|
|
|
return nullptr;
|
2017-05-04 00:23:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace layers
|
|
|
|
} // namespace mozilla
|