format_utils.cc 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "media/base/format_utils.h"
  5. #include "base/logging.h"
  6. #include "ui/gfx/buffer_format_util.h"
  7. namespace media {
  8. absl::optional<VideoPixelFormat> GfxBufferFormatToVideoPixelFormat(
  9. gfx::BufferFormat format) {
  10. switch (format) {
  11. case gfx::BufferFormat::BGRX_8888:
  12. return PIXEL_FORMAT_XRGB;
  13. case gfx::BufferFormat::BGRA_8888:
  14. return PIXEL_FORMAT_ARGB;
  15. case gfx::BufferFormat::RGBA_8888:
  16. return PIXEL_FORMAT_ABGR;
  17. // There is no PIXEL_FORMAT_XBGR which would have been the right mapping.
  18. // See ui/ozone drm_util.cc::GetFourCCFormatFromBufferFormat as reference.
  19. // But here it is only about indicating to not consider the alpha channel.
  20. // Useful for the compositor to avoid drawing behind as mentioned in
  21. // https://chromium-review.googlesource.com/590772.
  22. case gfx::BufferFormat::RGBX_8888:
  23. return PIXEL_FORMAT_XRGB;
  24. case gfx::BufferFormat::YVU_420:
  25. return PIXEL_FORMAT_YV12;
  26. case gfx::BufferFormat::YUV_420_BIPLANAR:
  27. return PIXEL_FORMAT_NV12;
  28. case gfx::BufferFormat::P010:
  29. return PIXEL_FORMAT_P016LE;
  30. default:
  31. DLOG(WARNING) << "Unsupported BufferFormat: "
  32. << gfx::BufferFormatToString(format);
  33. return absl::nullopt;
  34. }
  35. }
  36. absl::optional<gfx::BufferFormat> VideoPixelFormatToGfxBufferFormat(
  37. VideoPixelFormat pixel_format) {
  38. switch (pixel_format) {
  39. case PIXEL_FORMAT_ARGB:
  40. return gfx::BufferFormat::BGRA_8888;
  41. case PIXEL_FORMAT_XRGB:
  42. return gfx::BufferFormat::BGRX_8888;
  43. case PIXEL_FORMAT_YV12:
  44. return gfx::BufferFormat::YVU_420;
  45. case PIXEL_FORMAT_NV12:
  46. return gfx::BufferFormat::YUV_420_BIPLANAR;
  47. case PIXEL_FORMAT_ABGR:
  48. return gfx::BufferFormat::RGBA_8888;
  49. case PIXEL_FORMAT_XBGR:
  50. return gfx::BufferFormat::RGBX_8888;
  51. case PIXEL_FORMAT_P016LE:
  52. return gfx::BufferFormat::P010;
  53. default:
  54. DLOG(WARNING) << "Unsupported VideoPixelFormat: " << pixel_format;
  55. return absl::nullopt;
  56. }
  57. }
  58. } // namespace media