gl_surface_format.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. #ifndef UI_GL_GL_SURFACE_FORMAT_H_
  5. #define UI_GL_GL_SURFACE_FORMAT_H_
  6. #include "ui/gl/gl_export.h"
  7. namespace gl {
  8. // Expresses surface format properties that may vary depending
  9. // on the underlying gl_surface implementation or specific usage
  10. // scenarios. Intended usage is to support copying formats and
  11. // checking compatibility.
  12. class GL_EXPORT GLSurfaceFormat {
  13. public:
  14. // Default surface format for the underlying gl_surface subtype.
  15. // Use the setters below to change attributes if needed.
  16. GLSurfaceFormat();
  17. // Copy constructor from pre-existing format.
  18. GLSurfaceFormat(const GLSurfaceFormat& other);
  19. ~GLSurfaceFormat();
  20. // A given pair of surfaces is considered compatible if glSetSurface
  21. // can be used to switch between them without generating BAD_MATCH
  22. // errors, visual errors, or gross inefficiency, and incompatible
  23. // otherwise. For example, a pixel layout mismatch would be
  24. // considered incompatible. This comparison only makes sense within
  25. // the context of a single gl_surface subtype.
  26. bool IsCompatible(GLSurfaceFormat other_format) const;
  27. // Default pixel format is RGBA8888. Use this method to select
  28. // a preference of RGB565. TODO(klausw): use individual setter
  29. // methods if there's a use case for them.
  30. void SetRGB565();
  31. // Other properties for future use.
  32. void SetDepthBits(int depth_bits);
  33. int GetDepthBits() const { return depth_bits_; }
  34. void SetStencilBits(int stencil_bits);
  35. int GetStencilBits() const { return stencil_bits_; }
  36. void SetSamples(int samples);
  37. int GetSamples() const { return samples_; }
  38. enum SurfaceColorSpace {
  39. COLOR_SPACE_UNSPECIFIED = -1,
  40. COLOR_SPACE_SRGB,
  41. COLOR_SPACE_DISPLAY_P3,
  42. };
  43. void SetColorSpace(SurfaceColorSpace color_space) {
  44. color_space_ = color_space;
  45. }
  46. SurfaceColorSpace GetColorSpace() const { return color_space_; }
  47. // Compute number of bits needed for storing one pixel, not
  48. // including any padding. At this point mainly used to distinguish
  49. // RGB565 (16) from RGBA8888 (32).
  50. int GetBufferSize() const;
  51. private:
  52. SurfaceColorSpace color_space_ = COLOR_SPACE_UNSPECIFIED;
  53. int red_bits_ = -1;
  54. int green_bits_ = -1;
  55. int blue_bits_ = -1;
  56. int alpha_bits_ = -1;
  57. int depth_bits_ = -1;
  58. int samples_ = -1;
  59. int stencil_bits_ = -1;
  60. };
  61. } // namespace gl
  62. #endif // UI_GL_GL_SURFACE_FORMAT_H_