bool
VolatileBuffer::Init(size_t aSize, size_t aAlignment)
{
  MOZ_ASSERT(!mSize && !mBuf, "Init called twice");
  MOZ_ASSERT(!(aAlignment % sizeof(void *)),
             "Alignment must be multiple of pointer size");

  mSize = aSize;
  if (aSize < MIN_VOLATILE_ALLOC_SIZE) {
    goto heap_alloc;
  }

  static bool sUndoSupported = IsWin8OrLater();
  if (!sUndoSupported) {
    goto heap_alloc;
  }

  mBuf = VirtualAllocEx(GetCurrentProcess(),
                        nullptr,
                        mSize,
                        MEM_COMMIT | MEM_RESERVE,
                        PAGE_READWRITE);
  if (mBuf) {
    return true;
  }

heap_alloc:
#ifdef MOZ_MEMORY
  posix_memalign(&mBuf, aAlignment, aSize);
#else
  mBuf = _aligned_malloc(aSize, aAlignment);
#endif
  mHeap = true;
  return !!mBuf;
}
Example #2
0
  NS_IMETHOD Run() {
    NS_ASSERTION(NS_IsMainThread(), "Must be on main thread.");
    nsACString* failureReason = &mFailureReason;
    nsCString secondFailureReason;
    if (mBackend == LayersBackend::LAYERS_D3D11 &&
        MediaPrefs::PDMWMFAllowD3D11() && IsWin8OrLater()) {
      const nsACString& blacklistedDLL = FindD3D11BlacklistedDLL();
      if (!blacklistedDLL.IsEmpty()) {
        failureReason->AppendPrintf("D3D11 blacklisted with DLL %s",
                                    blacklistedDLL);
      } else {
        mDXVA2Manager = DXVA2Manager::CreateD3D11DXVA(*failureReason);
        if (mDXVA2Manager) {
          return NS_OK;
        }
      }
      // Try again with d3d9, but record the failure reason
      // into a new var to avoid overwriting the d3d11 failure.
      failureReason = &secondFailureReason;
      mFailureReason.Append(NS_LITERAL_CSTRING("; "));
    }

    const nsACString& blacklistedDLL = FindD3D9BlacklistedDLL();
    if (!blacklistedDLL.IsEmpty()) {
      mFailureReason.AppendPrintf("D3D9 blacklisted with DLL %s",
                                  blacklistedDLL);
    } else {
      mDXVA2Manager = DXVA2Manager::CreateD3D9DXVA(*failureReason);
      // Make sure we include the messages from both attempts (if applicable).
      mFailureReason.Append(secondFailureReason);
    }
    return NS_OK;
  }
 NS_IMETHOD Run() {
   NS_ASSERTION(NS_IsMainThread(), "Must be on main thread.");
   if (mBackend == LayersBackend::LAYERS_D3D11 &&
       IsWin8OrLater()) {
     mDXVA2Manager = DXVA2Manager::CreateD3D11DXVA();
   } else {
     mDXVA2Manager = DXVA2Manager::CreateD3D9DXVA();
   }
   return NS_OK;
 }
 NS_IMETHOD Run() {
   NS_ASSERTION(NS_IsMainThread(), "Must be on main thread.");
   if (mBackend == LayersBackend::LAYERS_D3D11 &&
       Preferences::GetBool("media.windows-media-foundation.allow-d3d11-dxva", false) &&
       IsWin8OrLater()) {
     mDXVA2Manager = DXVA2Manager::CreateD3D11DXVA();
   } else {
     mDXVA2Manager = DXVA2Manager::CreateD3D9DXVA();
   }
   return NS_OK;
 }
Example #5
0
void
DeviceManagerDx::CreateWARPCompositorDevice()
{
  ScopedGfxFeatureReporter reporterWARP("D3D11-WARP", gfxPrefs::LayersD3D11ForceWARP());
  FeatureState& d3d11 = gfxConfig::GetFeature(Feature::D3D11_COMPOSITING);

  HRESULT hr;
  RefPtr<ID3D11Device> device;

  // Use D3D11_CREATE_DEVICE_PREVENT_INTERNAL_THREADING_OPTIMIZATIONS
  // to prevent bug 1092260. IE 11 also uses this flag.
  UINT flags = D3D11_CREATE_DEVICE_BGRA_SUPPORT;
  if (!CreateDevice(nullptr, D3D_DRIVER_TYPE_WARP, flags, hr, device)) {
    gfxCriticalError() << "Exception occurred initializing WARP D3D11 device!";
    d3d11.SetFailed(FeatureStatus::CrashedInHandler, "Crashed creating a D3D11 WARP device",
                     NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_WARP_DEVICE"));
  }

  if (FAILED(hr) || !device) {
    // This should always succeed... in theory.
    gfxCriticalError() << "Failed to initialize WARP D3D11 device! " << hexa(hr);
    d3d11.SetFailed(FeatureStatus::Failed, "Failed to create a D3D11 WARP device",
                    NS_LITERAL_CSTRING("FEATURE_FAILURE_D3D11_WARP_DEVICE2"));
    return;
  }

  // Only test for texture sharing on Windows 8 since it puts the device into
  // an unusable state if used on Windows 7
  bool textureSharingWorks = false;
  if (IsWin8OrLater()) {
    textureSharingWorks = D3D11Checks::DoesTextureSharingWork(device);
  }

  DxgiAdapterDesc nullAdapter;
  PodZero(&nullAdapter);

  int featureLevel = device->GetFeatureLevel();
  {
    MutexAutoLock lock(mDeviceLock);
    mCompositorDevice = device;
    mDeviceStatus = Some(D3D11DeviceStatus(
      true,
      textureSharingWorks,
      featureLevel,
      nullAdapter));
  }
  mCompositorDevice->SetExceptionMode(0);

  reporterWARP.SetSuccessful();
}
bool
WMFDecoderModule::Supports(const TrackInfo& aTrackInfo,
                           DecoderDoctorDiagnostics* aDiagnostics) const
{
  if ((aTrackInfo.mMimeType.EqualsLiteral("audio/mp4a-latm") ||
       aTrackInfo.mMimeType.EqualsLiteral("audio/mp4")) &&
       WMFDecoderModule::HasAAC()) {
    return true;
  }
  if (MP4Decoder::IsH264(aTrackInfo.mMimeType) && WMFDecoderModule::HasH264()) {
    const VideoInfo* videoInfo = aTrackInfo.GetAsVideoInfo();
    MOZ_ASSERT(videoInfo);
    // Check Windows format constraints, based on:
    // https://msdn.microsoft.com/en-us/library/windows/desktop/dd797815(v=vs.85).aspx
    if (IsWin8OrLater()) {
      // Windows >7 supports at most 4096x2304.
      if (videoInfo->mImage.width > 4096 || videoInfo->mImage.height > 2304) {
        return false;
      }
    } else {
      // Windows <=7 supports at most 1920x1088.
      if (videoInfo->mImage.width > 1920 || videoInfo->mImage.height > 1088) {
        return false;
      }
    }
    return true;
  }
  if (aTrackInfo.mMimeType.EqualsLiteral("audio/mpeg") &&
      CanCreateWMFDecoder<CLSID_CMP3DecMediaObject>()) {
    return true;
  }
  if (MediaPrefs::PDMWMFIntelDecoderEnabled() && sDXVAEnabled) {
    if (VPXDecoder::IsVP8(aTrackInfo.mMimeType) &&
        CanCreateWMFDecoder<CLSID_WebmMfVp8Dec>()) {
      return true;
    }
    if (VPXDecoder::IsVP9(aTrackInfo.mMimeType) &&
        CanCreateWMFDecoder<CLSID_WebmMfVp9Dec>()) {
      return true;
    }
  }

  // Some unsupported codec.
  return false;
}
Example #7
0
 NS_IMETHOD Run() {
   NS_ASSERTION(NS_IsMainThread(), "Must be on main thread.");
   nsACString* failureReason = &mFailureReason;
   nsCString secondFailureReason;
   if (mBackend == LayersBackend::LAYERS_D3D11 &&
       Preferences::GetBool("media.windows-media-foundation.allow-d3d11-dxva", true) &&
       IsWin8OrLater()) {
     mDXVA2Manager = DXVA2Manager::CreateD3D11DXVA(*failureReason);
     if (mDXVA2Manager) {
       return NS_OK;
     }
     // Try again with d3d9, but record the failure reason
     // into a new var to avoid overwriting the d3d11 failure.
     failureReason = &secondFailureReason;
     mFailureReason.Append(NS_LITERAL_CSTRING("; "));
   }
   mDXVA2Manager = DXVA2Manager::CreateD3D9DXVA(*failureReason);
   // Make sure we include the messages from both attempts (if applicable).
   mFailureReason.Append(secondFailureReason);
   return NS_OK;
 }