buffer_format_utils.cc 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2019 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 "ui/gl/buffer_format_utils.h"
  5. #include "base/notreached.h"
  6. #include "ui/gl/gl_bindings.h"
  7. namespace gl {
  8. unsigned BufferFormatToGLInternalFormat(gfx::BufferFormat format) {
  9. switch (format) {
  10. case gfx::BufferFormat::R_8:
  11. return GL_RED_EXT;
  12. case gfx::BufferFormat::R_16:
  13. return GL_R16_EXT;
  14. case gfx::BufferFormat::RG_88:
  15. return GL_RG_EXT;
  16. case gfx::BufferFormat::RG_1616:
  17. return GL_RG16_EXT;
  18. case gfx::BufferFormat::BGR_565:
  19. return GL_RGB;
  20. case gfx::BufferFormat::RGBA_4444:
  21. return GL_RGBA;
  22. case gfx::BufferFormat::RGBX_8888:
  23. return GL_RGB;
  24. case gfx::BufferFormat::RGBA_8888:
  25. return GL_RGBA;
  26. case gfx::BufferFormat::BGRX_8888:
  27. return GL_RGB;
  28. case gfx::BufferFormat::BGRA_1010102:
  29. return GL_RGB10_A2_EXT;
  30. case gfx::BufferFormat::RGBA_1010102:
  31. return GL_RGB10_A2_EXT;
  32. case gfx::BufferFormat::BGRA_8888:
  33. return GL_BGRA_EXT;
  34. case gfx::BufferFormat::RGBA_F16:
  35. return GL_RGBA;
  36. case gfx::BufferFormat::YVU_420:
  37. return GL_RGB_YCRCB_420_CHROMIUM;
  38. case gfx::BufferFormat::YUV_420_BIPLANAR:
  39. return GL_RGB_YCBCR_420V_CHROMIUM;
  40. case gfx::BufferFormat::P010:
  41. return GL_RGB_YCBCR_P010_CHROMIUM;
  42. }
  43. NOTREACHED();
  44. return GL_NONE;
  45. }
  46. unsigned BufferFormatToGLDataType(gfx::BufferFormat format) {
  47. switch (format) {
  48. case gfx::BufferFormat::R_8:
  49. case gfx::BufferFormat::RG_88:
  50. case gfx::BufferFormat::RGBX_8888:
  51. case gfx::BufferFormat::BGRX_8888:
  52. case gfx::BufferFormat::RGBA_8888:
  53. case gfx::BufferFormat::BGRA_8888:
  54. return GL_UNSIGNED_BYTE;
  55. case gfx::BufferFormat::R_16:
  56. case gfx::BufferFormat::RG_1616:
  57. return GL_UNSIGNED_SHORT;
  58. case gfx::BufferFormat::BGR_565:
  59. return GL_UNSIGNED_SHORT_5_6_5;
  60. case gfx::BufferFormat::RGBA_4444:
  61. return GL_UNSIGNED_SHORT_4_4_4_4;
  62. case gfx::BufferFormat::RGBA_1010102:
  63. case gfx::BufferFormat::BGRA_1010102:
  64. return GL_UNSIGNED_INT_2_10_10_10_REV;
  65. case gfx::BufferFormat::RGBA_F16:
  66. return GL_HALF_FLOAT_OES;
  67. case gfx::BufferFormat::YVU_420:
  68. case gfx::BufferFormat::YUV_420_BIPLANAR:
  69. case gfx::BufferFormat::P010:
  70. return GL_NONE;
  71. }
  72. NOTREACHED();
  73. return GL_NONE;
  74. }
  75. } // namespace gl