Verified Commit 12586d10 authored by DonalMe's avatar DonalMe Committed by ma1
Browse files

Bug 2051658 a=dmeehan

parent c67e88d5
Loading
Loading
Loading
Loading
+48 −10
Original line number Diff line number Diff line
@@ -57,6 +57,37 @@ RenderDXGITextureHost::~RenderDXGITextureHost() {
  DeleteTextureHandle();
}

static bool IsCompatibleDXGIFormat(gfx::SurfaceFormat aFormat,
                                   DXGI_FORMAT aDXGIFormat) {
  switch (aFormat) {
    case gfx::SurfaceFormat::B8G8R8A8:
    case gfx::SurfaceFormat::B8G8R8X8:
    case gfx::SurfaceFormat::R8G8B8A8:
    case gfx::SurfaceFormat::R8G8B8X8:
      return aDXGIFormat == DXGI_FORMAT_B8G8R8A8_UNORM ||
             aDXGIFormat == DXGI_FORMAT_B8G8R8X8_UNORM ||
             aDXGIFormat == DXGI_FORMAT_R8G8B8A8_UNORM;
    case gfx::SurfaceFormat::R10G10B10A2_UINT32:
    case gfx::SurfaceFormat::R10G10B10X2_UINT32:
      return aDXGIFormat == DXGI_FORMAT_R10G10B10A2_UNORM;
    case gfx::SurfaceFormat::R16G16B16A16F:
      return aDXGIFormat == DXGI_FORMAT_R16G16B16A16_FLOAT;
    case gfx::SurfaceFormat::NV12:
      return aDXGIFormat == DXGI_FORMAT_NV12;
    case gfx::SurfaceFormat::P010:
      return aDXGIFormat == DXGI_FORMAT_P010;
    case gfx::SurfaceFormat::P016:
      return aDXGIFormat == DXGI_FORMAT_P016;
    case gfx::SurfaceFormat::A8:
      return aDXGIFormat == DXGI_FORMAT_R8_UNORM ||
             aDXGIFormat == DXGI_FORMAT_A8_UNORM;
    case gfx::SurfaceFormat::A16:
      return aDXGIFormat == DXGI_FORMAT_R16_UNORM;
    default:
      return false;
  }
}

ID3D11Texture2D* RenderDXGITextureHost::GetD3D11Texture2DWithGL() {
  if (mTexture) {
    return mTexture;
@@ -217,7 +248,7 @@ bool RenderDXGITextureHost::EnsureD3D11Texture2D(ID3D11Device* aDevice) {
    aDevice->QueryInterface((ID3D11Device1**)getter_AddRefs(device1));
    if (!device1) {
      gfxCriticalNoteOnce << "Failed to get ID3D11Device1";
      return 0;
      return false;
    }

    // Get the D3D11 texture from shared handle.
@@ -245,10 +276,12 @@ bool RenderDXGITextureHost::EnsureD3D11Texture2D(ID3D11Device* aDevice) {
  D3D11_TEXTURE2D_DESC desc{};
  mTexture->GetDesc(&desc);
  if (uint32_t(mSize.width) > desc.Width ||
      uint32_t(mSize.height) > desc.Height) {
    gfxCriticalNote << "RenderDXGITextureHost descriptor size " << mSize.width
                    << "x" << mSize.height << " exceeds resource size "
                    << desc.Width << "x" << desc.Height;
      uint32_t(mSize.height) > desc.Height ||
      !IsCompatibleDXGIFormat(mFormat, desc.Format)) {
    gfxCriticalNote << "RenderDXGITextureHost descriptor (" << mSize.width
                    << "x" << mSize.height << " fmt " << int(mFormat)
                    << ") does not match resource (" << desc.Width << "x"
                    << desc.Height << " DXGI " << int(desc.Format) << ")";
    mTexture = nullptr;
    mKeyedMutex = nullptr;
    return false;
@@ -630,6 +663,9 @@ bool RenderDXGIYCbCrTextureHost::EnsureD3D11Texture2D(ID3D11Device* aDevice) {
    return true;
  }

  const DXGI_FORMAT expectedFormat = mColorDepth == gfx::ColorDepth::COLOR_8
                                         ? DXGI_FORMAT_R8_UNORM
                                         : DXGI_FORMAT_R16_UNORM;
  for (int i = 0; i < 3; ++i) {
    // Get the R8 D3D11 texture from shared handle.
    HRESULT hr = device1->OpenSharedResource1(
@@ -650,11 +686,13 @@ bool RenderDXGIYCbCrTextureHost::EnsureD3D11Texture2D(ID3D11Device* aDevice) {
    mTextures[i]->GetDesc(&desc);
    const gfx::IntSize& expected = (i == 0) ? mSizeY : mSizeCbCr;
    if (uint32_t(expected.width) > desc.Width ||
        uint32_t(expected.height) > desc.Height) {
      gfxCriticalNote << "RenderDXGIYCbCrTextureHost descriptor size "
                      << expected.width << "x" << expected.height
                      << " exceeds resource size " << desc.Width << "x"
                      << desc.Height;
        uint32_t(expected.height) > desc.Height ||
        desc.Format != expectedFormat) {
      gfxCriticalNote << "RenderDXGIYCbCrTextureHost descriptor ("
                      << expected.width << "x" << expected.height << " depth "
                      << int(mColorDepth) << ") does not match resource ("
                      << desc.Width << "x" << desc.Height << " DXGI "
                      << int(desc.Format) << ")";
      for (auto& tex : mTextures) {
        tex = nullptr;
      }