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(SurfaceFormat format) { |
| 14 is_default = false; |
| 15 switch (format) { |
| 16 case SURFACE_ARGB8888: |
| 17 red_bits = green_bits = blue_bits = alpha_bits = 8; |
| 18 // For backwards compatibility, treat this as equivalent to the |
| 19 // default format. |
| 20 is_default = true; |
| 21 break; |
| 22 case SURFACE_RGB565: |
| 23 red_bits = blue_bits = 5; |
| 24 green_bits = 6; |
| 25 alpha_bits = 0; |
| 26 break; |
| 27 case SURFACE_OSMESA_BGRA: |
| 28 pixel_layout = SURFACE_PIXEL_LAYOUT_BGRA; |
| 29 break; |
| 30 case SURFACE_OSMESA_RGBA: |
| 31 pixel_layout = SURFACE_PIXEL_LAYOUT_RGBA; |
| 32 break; |
| 33 case SURFACE_SURFACELESS: |
| 34 is_surfaceless = true; |
| 35 break; |
| 36 default: |
| 37 NOTREACHED(); |
| 38 } |
| 39 } |
| 40 |
| 41 bool GLSurfaceFormat::IsSurfaceless() { |
| 42 return is_surfaceless; |
| 43 } |
| 44 |
| 45 GLSurfaceFormat::SurfacePixelLayout GLSurfaceFormat::GetPixelLayout() { |
| 46 return pixel_layout; |
| 47 } |
| 48 |
| 49 static int GetValue(int num, int default_value) { |
| 50 return num == -1 ? default_value : num; |
| 51 } |
| 52 |
| 53 static int GetBitSize(int num) { |
| 54 return GetValue(num, 8); |
| 55 } |
| 56 |
| 57 |
| 58 bool GLSurfaceFormat::IsDefault() { |
| 59 return is_default; |
| 60 } |
| 61 |
| 62 bool GLSurfaceFormat::IsCompatible(GLSurfaceFormat other) { |
| 63 if (this->IsDefault() && other.IsDefault()) return true; |
| 64 |
| 65 if (GetBitSize(this->red_bits) == GetBitSize(other.red_bits) && |
| 66 GetBitSize(this->green_bits) == GetBitSize(other.green_bits) && |
| 67 GetBitSize(this->blue_bits) == GetBitSize(other.blue_bits) && |
| 68 GetBitSize(this->alpha_bits) == GetBitSize(other.alpha_bits) && |
| 69 GetValue(this->stencil_bits, 8) == GetValue(other.stencil_bits, 8) && |
| 70 GetValue(this->depth_bits, 24) == GetValue(other.depth_bits, 24) && |
| 71 GetValue(this->samples, 0) == GetValue(other.samples, 0) && |
| 72 this->is_surfaceless == other.is_surfaceless && |
| 73 this->pixel_layout == other.pixel_layout) { |
| 74 return true; |
| 75 } |
| 76 return false; |
| 77 } |
| 78 |
| 79 void GLSurfaceFormat::SetDepthBits(int bits) { |
| 80 depth_bits = bits; |
| 81 } |
| 82 |
| 83 void GLSurfaceFormat::SetStencilBits(int bits) { |
| 84 stencil_bits = bits; |
| 85 } |
| 86 |
| 87 void GLSurfaceFormat::SetSamples(int num) { |
| 88 samples = num; |
| 89 } |
| 90 |
| 91 int GLSurfaceFormat::GetBufferSize() { |
| 92 int bits = GetBitSize(red_bits) + GetBitSize(green_bits) + |
| 93 GetBitSize(blue_bits) + GetBitSize(alpha_bits); |
| 94 if (bits <= 16) { |
| 95 return 16; |
| 96 } else if (bits <= 32) { |
| 97 return 32; |
| 98 } |
| 99 NOTREACHED(); |
| 100 return 64; |
| 101 } |
| 102 |
| 103 } // namespace gl |
OLD | NEW |