OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/logging.h" | 5 #include "base/logging.h" |
6 #include "ui/gl/gl_surface_format.h" | 6 #include "ui/gl/gl_surface_format.h" |
7 | 7 |
8 namespace gl { | 8 namespace gl { |
9 | 9 |
10 GLSurfaceFormat::GLSurfaceFormat() { | 10 GLSurfaceFormat::GLSurfaceFormat() { |
11 } | 11 } |
12 | 12 |
13 GLSurfaceFormat::GLSurfaceFormat(SurfacePixelLayout layout) { | 13 GLSurfaceFormat::GLSurfaceFormat(SurfacePixelLayout layout) { |
14 is_default_ = false; | |
15 pixel_layout_ = layout; | 14 pixel_layout_ = layout; |
16 } | 15 } |
17 | 16 |
18 GLSurfaceFormat::GLSurfaceFormat(const GLSurfaceFormat& other) = default; | 17 GLSurfaceFormat::GLSurfaceFormat(const GLSurfaceFormat& other) = default; |
19 | 18 |
20 GLSurfaceFormat::~GLSurfaceFormat() { | 19 GLSurfaceFormat::~GLSurfaceFormat() { |
21 } | 20 } |
22 | 21 |
23 bool GLSurfaceFormat::IsSurfaceless() { | |
24 return is_surfaceless_; | |
25 } | |
26 | |
27 GLSurfaceFormat::SurfacePixelLayout GLSurfaceFormat::GetPixelLayout() { | 22 GLSurfaceFormat::SurfacePixelLayout GLSurfaceFormat::GetPixelLayout() { |
28 return pixel_layout_; | 23 return pixel_layout_; |
29 } | 24 } |
30 | 25 |
31 void GLSurfaceFormat::SetDefaultPixelLayout(SurfacePixelLayout layout) { | 26 void GLSurfaceFormat::SetDefaultPixelLayout(SurfacePixelLayout layout) { |
32 if (pixel_layout_ == PIXEL_LAYOUT_DONT_CARE && | 27 if (pixel_layout_ == PIXEL_LAYOUT_DONT_CARE && |
33 layout != PIXEL_LAYOUT_DONT_CARE) { | 28 layout != PIXEL_LAYOUT_DONT_CARE) { |
34 pixel_layout_ = layout; | 29 pixel_layout_ = layout; |
35 is_default_ = false; | |
36 } | 30 } |
37 } | 31 } |
38 | 32 |
39 void GLSurfaceFormat::SetRGB565() { | 33 void GLSurfaceFormat::SetRGB565() { |
40 red_bits_ = blue_bits_ = 5; | 34 red_bits_ = blue_bits_ = 5; |
41 green_bits_ = 6; | 35 green_bits_ = 6; |
42 alpha_bits_ = 0; | 36 alpha_bits_ = 0; |
43 is_default_ = false; | |
44 } | |
45 | |
46 void GLSurfaceFormat::SetIsSurfaceless() { | |
47 is_surfaceless_ = true; | |
48 is_default_ = false; | |
49 } | 37 } |
50 | 38 |
51 static int GetValue(int num, int default_value) { | 39 static int GetValue(int num, int default_value) { |
52 return num == -1 ? default_value : num; | 40 return num == -1 ? default_value : num; |
53 } | 41 } |
54 | 42 |
55 static int GetBitSize(int num) { | 43 static int GetBitSize(int num) { |
56 return GetValue(num, 8); | 44 return GetValue(num, 8); |
57 } | 45 } |
58 | 46 |
59 | |
60 bool GLSurfaceFormat::IsDefault() { | |
61 return is_default_; | |
62 } | |
63 | |
64 bool GLSurfaceFormat::IsCompatible(GLSurfaceFormat other) { | 47 bool GLSurfaceFormat::IsCompatible(GLSurfaceFormat other) { |
65 if (IsDefault() && other.IsDefault()) return true; | |
66 | |
67 if (GetBitSize(red_bits_) == GetBitSize(other.red_bits_) && | 48 if (GetBitSize(red_bits_) == GetBitSize(other.red_bits_) && |
68 GetBitSize(green_bits_) == GetBitSize(other.green_bits_) && | 49 GetBitSize(green_bits_) == GetBitSize(other.green_bits_) && |
69 GetBitSize(blue_bits_) == GetBitSize(other.blue_bits_) && | 50 GetBitSize(blue_bits_) == GetBitSize(other.blue_bits_) && |
70 GetBitSize(alpha_bits_) == GetBitSize(other.alpha_bits_) && | 51 GetBitSize(alpha_bits_) == GetBitSize(other.alpha_bits_) && |
71 GetValue(stencil_bits_, 8) == GetValue(other.stencil_bits_, 8) && | 52 GetValue(stencil_bits_, 8) == GetValue(other.stencil_bits_, 8) && |
72 GetValue(depth_bits_, 24) == GetValue(other.depth_bits_, 24) && | 53 GetValue(depth_bits_, 24) == GetValue(other.depth_bits_, 24) && |
73 GetValue(samples_, 0) == GetValue(other.samples_, 0) && | 54 GetValue(samples_, 0) == GetValue(other.samples_, 0) && |
74 is_surfaceless_ == other.is_surfaceless_ && | |
75 pixel_layout_ == other.pixel_layout_) { | 55 pixel_layout_ == other.pixel_layout_) { |
76 return true; | 56 return true; |
77 } | 57 } |
78 return false; | 58 return false; |
79 } | 59 } |
80 | 60 |
81 void GLSurfaceFormat::SetDepthBits(int bits) { | 61 void GLSurfaceFormat::SetDepthBits(int bits) { |
82 if (bits != -1) { | 62 if (bits != -1) { |
83 depth_bits_ = bits; | 63 depth_bits_ = bits; |
84 is_default_ = false; | |
85 } | 64 } |
86 } | 65 } |
87 | 66 |
88 int GLSurfaceFormat::GetDepthBits() { | 67 int GLSurfaceFormat::GetDepthBits() { |
89 return depth_bits_; | 68 return depth_bits_; |
90 } | 69 } |
91 | 70 |
92 void GLSurfaceFormat::SetStencilBits(int bits) { | 71 void GLSurfaceFormat::SetStencilBits(int bits) { |
93 if (bits != -1) { | 72 if (bits != -1) { |
94 stencil_bits_ = bits; | 73 stencil_bits_ = bits; |
95 is_default_ = false; | |
96 } | 74 } |
97 } | 75 } |
98 | 76 |
99 int GLSurfaceFormat::GetStencilBits() { | 77 int GLSurfaceFormat::GetStencilBits() { |
100 return stencil_bits_; | 78 return stencil_bits_; |
101 } | 79 } |
102 | 80 |
103 void GLSurfaceFormat::SetSamples(int num) { | 81 void GLSurfaceFormat::SetSamples(int num) { |
104 if (num != -1) { | 82 if (num != -1) { |
105 samples_ = num; | 83 samples_ = num; |
106 is_default_ = false; | |
107 } | 84 } |
108 } | 85 } |
109 | 86 |
110 int GLSurfaceFormat::GetSamples() { | 87 int GLSurfaceFormat::GetSamples() { |
111 return samples_; | 88 return samples_; |
112 } | 89 } |
113 | 90 |
114 int GLSurfaceFormat::GetBufferSize() { | 91 int GLSurfaceFormat::GetBufferSize() { |
115 int bits = GetBitSize(red_bits_) + GetBitSize(green_bits_) + | 92 int bits = GetBitSize(red_bits_) + GetBitSize(green_bits_) + |
116 GetBitSize(blue_bits_) + GetBitSize(alpha_bits_); | 93 GetBitSize(blue_bits_) + GetBitSize(alpha_bits_); |
117 if (bits <= 16) { | 94 if (bits <= 16) { |
118 return 16; | 95 return 16; |
119 } else if (bits <= 32) { | 96 } else if (bits <= 32) { |
120 return 32; | 97 return 32; |
121 } | 98 } |
122 NOTREACHED(); | 99 NOTREACHED(); |
123 return 64; | 100 return 64; |
124 } | 101 } |
125 | 102 |
126 } // namespace gl | 103 } // namespace gl |
OLD | NEW |