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 / format_utils.cc [blame]

// Copyright 2024 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/format_utils.h"

#include "base/notreached.h"

namespace media {

size_t GetFormatPlaneCount(DXGI_FORMAT format) {
  switch (format) {
    case DXGI_FORMAT_NV12:
    case DXGI_FORMAT_P010:
    case DXGI_FORMAT_P016:
    case DXGI_FORMAT_NV11:
      return 2;
    case DXGI_FORMAT_AYUV:
    case DXGI_FORMAT_Y410:
    case DXGI_FORMAT_Y416:
    case DXGI_FORMAT_YUY2:
    case DXGI_FORMAT_Y210:
    case DXGI_FORMAT_Y216:
    case DXGI_FORMAT_R8_UNORM:
    case DXGI_FORMAT_R8G8_UNORM:
    case DXGI_FORMAT_R16_UNORM:
    case DXGI_FORMAT_R16G16_UNORM:
    case DXGI_FORMAT_R8G8B8A8_UNORM:
    case DXGI_FORMAT_B8G8R8A8_UNORM:
    case DXGI_FORMAT_R10G10B10A2_UNORM:
    case DXGI_FORMAT_R16G16B16A16_FLOAT:
      return 1;
    default:
      NOTREACHED();
  }
}

const char* DxgiFormatToString(DXGI_FORMAT format) {
  switch (format) {
    case DXGI_FORMAT_Y416:
      return "Y416";
    case DXGI_FORMAT_Y216:
      return "Y216";
    case DXGI_FORMAT_P016:
      return "P016";
    case DXGI_FORMAT_NV12:
      return "NV12";
    case DXGI_FORMAT_P010:
      return "P010";
    case DXGI_FORMAT_Y210:
      return "Y210";
    case DXGI_FORMAT_AYUV:
      return "AYUV";
    case DXGI_FORMAT_Y410:
      return "Y410";
    case DXGI_FORMAT_YUY2:
      return "YUY2";
    default:
      return "UNKNOWN";
  }
}

DXGI_FORMAT VideoPixelFormatToDxgiFormat(VideoPixelFormat format) {
  switch (format) {
    case PIXEL_FORMAT_I420:
      return DXGI_FORMAT_420_OPAQUE;
    case PIXEL_FORMAT_NV12:
      return DXGI_FORMAT_NV12;
    case PIXEL_FORMAT_ARGB:
      return DXGI_FORMAT_B8G8R8A8_UNORM;
    case PIXEL_FORMAT_P010LE:
      return DXGI_FORMAT_P010;
    default:
      return DXGI_FORMAT_UNKNOWN;
  }
}

}  // namespace media