OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "gpu/gles2_conform_support/egl/config.h" | 5 #include "gpu/gles2_conform_support/egl/config.h" |
| 6 #include "base/logging.h" |
6 | 7 |
7 namespace egl { | 8 namespace egl { |
8 | 9 |
9 Config::Config() | 10 Config::Config(EGLint surface_type) |
10 : buffer_size_(0), | 11 : buffer_size_(0), |
11 red_size_(0), | 12 red_size_(0), |
12 green_size_(0), | 13 green_size_(0), |
13 blue_size_(0), | 14 blue_size_(0), |
14 luminance_size_(0), | 15 luminance_size_(0), |
15 alpha_size_(0), | 16 alpha_size_(0), |
16 alpha_mask_size_(0), | 17 alpha_mask_size_(0), |
17 bind_to_texture_rgb_(EGL_FALSE), | 18 bind_to_texture_rgb_(EGL_FALSE), |
18 bind_to_texture_rgba_(EGL_FALSE), | 19 bind_to_texture_rgba_(EGL_FALSE), |
19 color_buffer_type_(EGL_RGB_BUFFER), | 20 color_buffer_type_(EGL_RGB_BUFFER), |
20 config_caveat_(EGL_NONE), | 21 config_caveat_(EGL_NONE), |
21 config_id_(EGL_DONT_CARE), | 22 config_id_(EGL_DONT_CARE), |
22 conformant_(EGL_OPENGL_ES2_BIT), | 23 conformant_(EGL_OPENGL_ES2_BIT), |
23 depth_size_(0), | 24 depth_size_(0), |
24 level_(0), | 25 level_(0), |
25 max_pbuffer_width_(0), | 26 max_pbuffer_width_(0), |
26 max_pbuffer_height_(0), | 27 max_pbuffer_height_(0), |
27 max_pbuffer_pixels_(0), | 28 max_pbuffer_pixels_(0), |
28 min_swap_interval_(EGL_DONT_CARE), | 29 min_swap_interval_(EGL_DONT_CARE), |
29 max_swap_interval_(EGL_DONT_CARE), | 30 max_swap_interval_(EGL_DONT_CARE), |
30 native_renderable_(EGL_TRUE), | 31 native_renderable_(EGL_TRUE), |
31 native_visual_id_(0), | 32 native_visual_id_(0), |
32 native_visual_type_(EGL_DONT_CARE), | 33 native_visual_type_(EGL_DONT_CARE), |
33 renderable_type_(EGL_OPENGL_ES2_BIT), | 34 renderable_type_(EGL_OPENGL_ES2_BIT), |
34 sample_buffers_(0), | 35 sample_buffers_(0), |
35 samples_(0), | 36 samples_(0), |
36 stencil_size_(0), | 37 stencil_size_(0), |
37 surface_type_(EGL_WINDOW_BIT), | 38 surface_type_(surface_type), |
38 transparent_type_(EGL_NONE), | 39 transparent_type_(EGL_NONE), |
39 transparent_red_value_(EGL_DONT_CARE), | 40 transparent_red_value_(EGL_DONT_CARE), |
40 transparent_green_value_(EGL_DONT_CARE), | 41 transparent_green_value_(EGL_DONT_CARE), |
41 transparent_blue_value_(EGL_DONT_CARE) { | 42 transparent_blue_value_(EGL_DONT_CARE) { |
| 43 DCHECK(surface_type == EGL_WINDOW_BIT || surface_type == EGL_PBUFFER_BIT); |
42 } | 44 } |
43 | 45 |
44 Config::~Config() { | 46 Config::~Config() { |
45 } | 47 } |
46 | 48 |
| 49 bool Config::Matches(const EGLint* attrib_list) const { |
| 50 DCHECK(ValidateAttributeList(attrib_list)); |
| 51 if (attrib_list) { |
| 52 for (int i = 0; attrib_list[i] != EGL_NONE; i += 2) { |
| 53 switch (attrib_list[i]) { |
| 54 case EGL_SURFACE_TYPE: { |
| 55 EGLint requested_surface_type = attrib_list[i + 1]; |
| 56 if (requested_surface_type != EGL_DONT_CARE && |
| 57 (requested_surface_type & surface_type_) != |
| 58 requested_surface_type) |
| 59 return false; |
| 60 } |
| 61 default: |
| 62 break; |
| 63 } |
| 64 } |
| 65 } |
| 66 return true; |
| 67 } |
| 68 |
47 bool Config::GetAttrib(EGLint attribute, EGLint* value) const { | 69 bool Config::GetAttrib(EGLint attribute, EGLint* value) const { |
48 // TODO(alokp): Find out how to get correct values. | 70 // TODO(alokp): Find out how to get correct values. |
49 switch (attribute) { | 71 switch (attribute) { |
50 case EGL_BUFFER_SIZE: | 72 case EGL_BUFFER_SIZE: |
51 *value = buffer_size_; | 73 *value = buffer_size_; |
52 break; | 74 break; |
53 case EGL_RED_SIZE: | 75 case EGL_RED_SIZE: |
54 *value = red_size_; | 76 *value = red_size_; |
55 break; | 77 break; |
56 case EGL_GREEN_SIZE: | 78 case EGL_GREEN_SIZE: |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 break; | 164 break; |
143 case EGL_TRANSPARENT_BLUE_VALUE: | 165 case EGL_TRANSPARENT_BLUE_VALUE: |
144 *value = transparent_blue_value_; | 166 *value = transparent_blue_value_; |
145 break; | 167 break; |
146 default: | 168 default: |
147 return false; | 169 return false; |
148 } | 170 } |
149 return true; | 171 return true; |
150 } | 172 } |
151 | 173 |
| 174 bool Config::ValidateAttributeList(const EGLint* attrib_list) { |
| 175 if (attrib_list) { |
| 176 for (int i = 0; attrib_list[i] != EGL_NONE; i += 2) { |
| 177 switch (attrib_list[i]) { |
| 178 case EGL_ALPHA_MASK_SIZE: |
| 179 case EGL_ALPHA_SIZE: |
| 180 case EGL_BIND_TO_TEXTURE_RGB: |
| 181 case EGL_BIND_TO_TEXTURE_RGBA: |
| 182 case EGL_BLUE_SIZE: |
| 183 case EGL_BUFFER_SIZE: |
| 184 case EGL_COLOR_BUFFER_TYPE: |
| 185 case EGL_CONFIG_CAVEAT: |
| 186 case EGL_CONFIG_ID: |
| 187 case EGL_CONFORMANT: |
| 188 case EGL_DEPTH_SIZE: |
| 189 case EGL_GREEN_SIZE: |
| 190 case EGL_LEVEL: |
| 191 case EGL_LUMINANCE_SIZE: |
| 192 case EGL_MATCH_NATIVE_PIXMAP: |
| 193 case EGL_NATIVE_RENDERABLE: |
| 194 case EGL_MAX_SWAP_INTERVAL: |
| 195 case EGL_MIN_SWAP_INTERVAL: |
| 196 case EGL_RED_SIZE: |
| 197 case EGL_SAMPLE_BUFFERS: |
| 198 case EGL_SAMPLES: |
| 199 case EGL_STENCIL_SIZE: |
| 200 case EGL_RENDERABLE_TYPE: |
| 201 case EGL_SURFACE_TYPE: |
| 202 case EGL_MULTISAMPLE_RESOLVE_BOX_BIT: |
| 203 case EGL_PBUFFER_BIT: |
| 204 case EGL_PIXMAP_BIT: |
| 205 case EGL_SWAP_BEHAVIOR_PRESERVED_BIT: |
| 206 case EGL_VG_ALPHA_FORMAT_PRE_BIT: |
| 207 case EGL_VG_COLORSPACE_LINEAR_BIT: |
| 208 case EGL_WINDOW_BIT: |
| 209 case EGL_TRANSPARENT_TYPE: |
| 210 case EGL_TRANSPARENT_RED_VALUE: |
| 211 case EGL_TRANSPARENT_GREEN_VALUE: |
| 212 case EGL_TRANSPARENT_BLUE_VALUE: |
| 213 break; |
| 214 default: |
| 215 return false; |
| 216 } |
| 217 } |
| 218 } |
| 219 return true; |
| 220 } |
| 221 |
152 } // namespace egl | 222 } // namespace egl |
OLD | NEW |