OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 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 |
| 5 #include "base/logging.h" |
| 6 #include "ui/gl/gl_surface_format.h" |
| 7 |
| 8 namespace gl { |
| 9 |
| 10 GLSurfaceFormat::GLSurfaceFormat() { |
| 11 } |
| 12 |
| 13 GLSurfaceFormat::GLSurfaceFormat(SurfacePixelLayout layout) { |
| 14 is_default = false; |
| 15 pixel_layout = layout; |
| 16 } |
| 17 |
| 18 GLSurfaceFormat::GLSurfaceFormat(const GLSurfaceFormat& other) = default; |
| 19 |
| 20 GLSurfaceFormat::~GLSurfaceFormat() { |
| 21 } |
| 22 |
| 23 bool GLSurfaceFormat::IsSurfaceless() { |
| 24 return is_surfaceless; |
| 25 } |
| 26 |
| 27 GLSurfaceFormat::SurfacePixelLayout GLSurfaceFormat::GetPixelLayout() { |
| 28 return pixel_layout; |
| 29 } |
| 30 |
| 31 void GLSurfaceFormat::SetDefaultPixelLayout(SurfacePixelLayout layout) { |
| 32 if (pixel_layout == PIXEL_LAYOUT_DONT_CARE && |
| 33 layout != PIXEL_LAYOUT_DONT_CARE) { |
| 34 pixel_layout = layout; |
| 35 is_default = false; |
| 36 } |
| 37 } |
| 38 |
| 39 void GLSurfaceFormat::SetRGB565() { |
| 40 red_bits = blue_bits = 5; |
| 41 green_bits = 6; |
| 42 alpha_bits = 0; |
| 43 is_default = false; |
| 44 } |
| 45 |
| 46 void GLSurfaceFormat::SetIsSurfaceless() { |
| 47 is_surfaceless = true; |
| 48 is_default = false; |
| 49 } |
| 50 |
| 51 static int GetValue(int num, int default_value) { |
| 52 return num == -1 ? default_value : num; |
| 53 } |
| 54 |
| 55 static int GetBitSize(int num) { |
| 56 return GetValue(num, 8); |
| 57 } |
| 58 |
| 59 |
| 60 bool GLSurfaceFormat::IsDefault() { |
| 61 return is_default; |
| 62 } |
| 63 |
| 64 bool GLSurfaceFormat::IsCompatible(GLSurfaceFormat other) { |
| 65 if (IsDefault() && other.IsDefault()) return true; |
| 66 |
| 67 if (GetBitSize(red_bits) == GetBitSize(other.red_bits) && |
| 68 GetBitSize(green_bits) == GetBitSize(other.green_bits) && |
| 69 GetBitSize(blue_bits) == GetBitSize(other.blue_bits) && |
| 70 GetBitSize(alpha_bits) == GetBitSize(other.alpha_bits) && |
| 71 GetValue(stencil_bits, 8) == GetValue(other.stencil_bits, 8) && |
| 72 GetValue(depth_bits, 24) == GetValue(other.depth_bits, 24) && |
| 73 GetValue(samples, 0) == GetValue(other.samples, 0) && |
| 74 is_surfaceless == other.is_surfaceless && |
| 75 pixel_layout == other.pixel_layout) { |
| 76 return true; |
| 77 } |
| 78 return false; |
| 79 } |
| 80 |
| 81 void GLSurfaceFormat::SetDepthBits(int bits) { |
| 82 if (bits != -1) { |
| 83 depth_bits = bits; |
| 84 is_default = false; |
| 85 } |
| 86 } |
| 87 |
| 88 int GLSurfaceFormat::GetDepthBits() { |
| 89 return depth_bits; |
| 90 } |
| 91 |
| 92 void GLSurfaceFormat::SetStencilBits(int bits) { |
| 93 if (bits != -1) { |
| 94 stencil_bits = bits; |
| 95 is_default = false; |
| 96 } |
| 97 } |
| 98 |
| 99 int GLSurfaceFormat::GetStencilBits() { |
| 100 return stencil_bits; |
| 101 } |
| 102 |
| 103 void GLSurfaceFormat::SetSamples(int num) { |
| 104 if (num != -1) { |
| 105 samples = num; |
| 106 is_default = false; |
| 107 } |
| 108 } |
| 109 |
| 110 int GLSurfaceFormat::GetSamples() { |
| 111 return samples; |
| 112 } |
| 113 |
| 114 int GLSurfaceFormat::GetBufferSize() { |
| 115 int bits = GetBitSize(red_bits) + GetBitSize(green_bits) + |
| 116 GetBitSize(blue_bits) + GetBitSize(alpha_bits); |
| 117 if (bits <= 16) { |
| 118 return 16; |
| 119 } else if (bits <= 32) { |
| 120 return 32; |
| 121 } |
| 122 NOTREACHED(); |
| 123 return 64; |
| 124 } |
| 125 |
| 126 } // namespace gl |
OLD | NEW |