1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78

media / gpu / windows / d3d11_video_device_format_support.cc [blame]

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "media/gpu/windows/d3d11_video_device_format_support.h"

namespace media {

FormatSupportChecker::FormatSupportChecker(ComD3D11Device device)
    : device_(std::move(device)) {
}

FormatSupportChecker::~FormatSupportChecker() {
  if (initialized_)
    enumerator_.Reset();
  device_.Reset();
}

bool FormatSupportChecker::Initialize() {
  ComD3D11VideoDevice v_device;
  if (!device_)
    return false;

  if (!SUCCEEDED(device_.As(&v_device)))
    return false;

  // The values here should have _no_ effect on supported profiles, but they
  // are needed anyway for initialization.
  D3D11_VIDEO_PROCESSOR_CONTENT_DESC desc;
  desc.InputFrameFormat = D3D11_VIDEO_FRAME_FORMAT_PROGRESSIVE;
  desc.InputFrameRate.Numerator = 60;
  desc.InputFrameRate.Denominator = 1;
  desc.InputWidth = 1920;
  desc.InputHeight = 1080;
  desc.OutputFrameRate.Numerator = 60;
  desc.OutputFrameRate.Denominator = 1;
  desc.OutputWidth = 1920;
  desc.OutputHeight = 1080;
  desc.Usage = D3D11_VIDEO_USAGE_PLAYBACK_NORMAL;

  if (!SUCCEEDED(v_device->CreateVideoProcessorEnumerator(&desc, &enumerator_)))
    return false;

  // For tests, which don't provide one (successfully).
  if (!enumerator_)
    return false;

  // Check that the |CheckFormatSupport| and |CheckVideoProcessorFormat| calls
  // won't be failing
  UINT unneeded = 0;
  DXGI_FORMAT example = DXGI_FORMAT_NV12;
  if (!SUCCEEDED(device_->CheckFormatSupport(example, &unneeded)))
    return false;

  if (!SUCCEEDED(enumerator_->CheckVideoProcessorFormat(example, &unneeded)))
    return false;

  initialized_ = true;
  return true;
}

bool FormatSupportChecker::CheckOutputFormatSupport(DXGI_FORMAT format) const {
  if (!device_ || !enumerator_)
    return false;

  DCHECK(initialized_);

  UINT device = 0, enumerator = 0;
  if (!SUCCEEDED(device_->CheckFormatSupport(format, &device)))
    return false;
  if (!SUCCEEDED(enumerator_->CheckVideoProcessorFormat(format, &enumerator)))
    return false;

  return (enumerator & D3D11_VIDEO_PROCESSOR_FORMAT_SUPPORT_OUTPUT) &&
         (device & D3D11_FORMAT_SUPPORT_VIDEO_PROCESSOR_OUTPUT);
}

}  // namespace media