buffer_format_util.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // Copyright 2015 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. #ifndef UI_GFX_BUFFER_FORMAT_UTIL_H_
  5. #define UI_GFX_BUFFER_FORMAT_UTIL_H_
  6. #include <stddef.h>
  7. #include <vector>
  8. #include "ui/gfx/buffer_types.h"
  9. #include "ui/gfx/geometry/size.h"
  10. #include "ui/gfx/gfx_export.h"
  11. namespace gfx {
  12. // Returns a vector containing all buffer formats.
  13. GFX_EXPORT std::vector<BufferFormat> GetBufferFormatsForTesting();
  14. // Returns the number of bits of alpha for the specified format.
  15. GFX_EXPORT size_t AlphaBitsForBufferFormat(BufferFormat format);
  16. // Returns the number of planes for |format|.
  17. GFX_EXPORT size_t NumberOfPlanesForLinearBufferFormat(BufferFormat format);
  18. // Returns the subsampling factor applied to the given zero-indexed |plane| of
  19. // |format| both horizontally and vertically.
  20. GFX_EXPORT size_t SubsamplingFactorForBufferFormat(BufferFormat format,
  21. size_t plane);
  22. // Returns the number of bytes used to store a row of the given zero-indexed
  23. // |plane| of |format|.
  24. GFX_EXPORT size_t RowSizeForBufferFormat(size_t width,
  25. BufferFormat format,
  26. size_t plane);
  27. [[nodiscard]] GFX_EXPORT bool RowSizeForBufferFormatChecked(
  28. size_t width,
  29. BufferFormat format,
  30. size_t plane,
  31. size_t* size_in_bytes);
  32. // Returns the number of bytes used to the plane of a given |format|.
  33. GFX_EXPORT size_t PlaneSizeForBufferFormat(const Size& size,
  34. BufferFormat format,
  35. size_t plane);
  36. [[nodiscard]] GFX_EXPORT bool PlaneSizeForBufferFormatChecked(
  37. const Size& size,
  38. BufferFormat format,
  39. size_t plane,
  40. size_t* size_in_bytes);
  41. // Returns the number of bytes used to store all the planes of a given |format|.
  42. GFX_EXPORT size_t BufferSizeForBufferFormat(const Size& size,
  43. BufferFormat format);
  44. [[nodiscard]] GFX_EXPORT bool BufferSizeForBufferFormatChecked(
  45. const Size& size,
  46. BufferFormat format,
  47. size_t* size_in_bytes);
  48. GFX_EXPORT size_t BufferOffsetForBufferFormat(const Size& size,
  49. BufferFormat format,
  50. size_t plane);
  51. // Returns the name of |format| as a string.
  52. GFX_EXPORT const char* BufferFormatToString(BufferFormat format);
  53. // Returns the name of |plane| as a string.
  54. GFX_EXPORT const char* BufferPlaneToString(BufferPlane plane);
  55. // Multiplanar buffer formats (e.g, YUV_420_BIPLANAR, YVU_420, P010) can be
  56. // tricky when the size of the primary plane is odd, because the subsampled
  57. // planes will have a size that is not a divisor of the primary plane's size.
  58. // This indicates that odd height multiplanar formats are supported.
  59. GFX_EXPORT bool IsOddHeightMultiPlanarBuffersAllowed();
  60. GFX_EXPORT bool IsOddWidthMultiPlanarBuffersAllowed();
  61. } // namespace gfx
  62. #endif // UI_GFX_BUFFER_FORMAT_UTIL_H_