gl_surface_format.cc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 "ui/gl/gl_surface_format.h"
  5. #include "base/notreached.h"
  6. namespace gl {
  7. GLSurfaceFormat::GLSurfaceFormat() {
  8. }
  9. GLSurfaceFormat::GLSurfaceFormat(const GLSurfaceFormat& other) = default;
  10. GLSurfaceFormat::~GLSurfaceFormat() {
  11. }
  12. void GLSurfaceFormat::SetRGB565() {
  13. red_bits_ = blue_bits_ = 5;
  14. green_bits_ = 6;
  15. alpha_bits_ = 0;
  16. }
  17. static int GetValue(int num, int default_value) {
  18. return num == -1 ? default_value : num;
  19. }
  20. static int GetBitSize(int num) {
  21. return GetValue(num, 8);
  22. }
  23. bool GLSurfaceFormat::IsCompatible(GLSurfaceFormat other) const {
  24. if (GetBitSize(red_bits_) == GetBitSize(other.red_bits_) &&
  25. GetBitSize(green_bits_) == GetBitSize(other.green_bits_) &&
  26. GetBitSize(blue_bits_) == GetBitSize(other.blue_bits_) &&
  27. GetBitSize(alpha_bits_) == GetBitSize(other.alpha_bits_) &&
  28. GetValue(stencil_bits_, 8) == GetValue(other.stencil_bits_, 8) &&
  29. GetValue(depth_bits_, 24) == GetValue(other.depth_bits_, 24) &&
  30. GetValue(samples_, 0) == GetValue(other.samples_, 0)) {
  31. return true;
  32. }
  33. return false;
  34. }
  35. void GLSurfaceFormat::SetDepthBits(int bits) {
  36. if (bits != -1) {
  37. depth_bits_ = bits;
  38. }
  39. }
  40. void GLSurfaceFormat::SetStencilBits(int bits) {
  41. if (bits != -1) {
  42. stencil_bits_ = bits;
  43. }
  44. }
  45. void GLSurfaceFormat::SetSamples(int num) {
  46. if (num != -1) {
  47. samples_ = num;
  48. }
  49. }
  50. int GLSurfaceFormat::GetBufferSize() const {
  51. int bits = GetBitSize(red_bits_) + GetBitSize(green_bits_) +
  52. GetBitSize(blue_bits_) + GetBitSize(alpha_bits_);
  53. if (bits <= 16) {
  54. return 16;
  55. } else if (bits <= 32) {
  56. return 32;
  57. }
  58. NOTREACHED();
  59. return 64;
  60. }
  61. } // namespace gl