config.cc 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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
  3. // found in the LICENSE file.
  4. #include "gpu/gles2_conform_support/egl/config.h"
  5. #include "base/check.h"
  6. namespace gles2_conform_support {
  7. namespace egl {
  8. Config::Config(EGLint surface_type)
  9. : buffer_size_(0),
  10. red_size_(0),
  11. green_size_(0),
  12. blue_size_(0),
  13. luminance_size_(0),
  14. alpha_size_(0),
  15. alpha_mask_size_(0),
  16. bind_to_texture_rgb_(EGL_FALSE),
  17. bind_to_texture_rgba_(EGL_FALSE),
  18. color_buffer_type_(EGL_RGB_BUFFER),
  19. config_caveat_(EGL_NONE),
  20. config_id_(EGL_DONT_CARE),
  21. conformant_(EGL_OPENGL_ES2_BIT),
  22. depth_size_(0),
  23. level_(0),
  24. max_pbuffer_width_(0),
  25. max_pbuffer_height_(0),
  26. max_pbuffer_pixels_(0),
  27. min_swap_interval_(EGL_DONT_CARE),
  28. max_swap_interval_(EGL_DONT_CARE),
  29. native_renderable_(EGL_TRUE),
  30. native_visual_id_(0),
  31. native_visual_type_(EGL_DONT_CARE),
  32. renderable_type_(EGL_OPENGL_ES2_BIT),
  33. sample_buffers_(0),
  34. samples_(0),
  35. stencil_size_(0),
  36. surface_type_(surface_type),
  37. transparent_type_(EGL_NONE),
  38. transparent_red_value_(EGL_DONT_CARE),
  39. transparent_green_value_(EGL_DONT_CARE),
  40. transparent_blue_value_(EGL_DONT_CARE) {
  41. DCHECK(surface_type == EGL_WINDOW_BIT || surface_type == EGL_PBUFFER_BIT);
  42. }
  43. Config::~Config() = default;
  44. bool Config::Matches(const EGLint* attrib_list) const {
  45. DCHECK(ValidateAttributeList(attrib_list));
  46. if (attrib_list) {
  47. for (int i = 0; attrib_list[i] != EGL_NONE; i += 2) {
  48. switch (attrib_list[i]) {
  49. case EGL_SURFACE_TYPE: {
  50. EGLint requested_surface_type = attrib_list[i + 1];
  51. if (requested_surface_type != EGL_DONT_CARE &&
  52. (requested_surface_type & surface_type_) !=
  53. requested_surface_type)
  54. return false;
  55. break;
  56. }
  57. default:
  58. break;
  59. }
  60. }
  61. }
  62. return true;
  63. }
  64. bool Config::GetAttrib(EGLint attribute, EGLint* value) const {
  65. // TODO(alokp): Find out how to get correct values.
  66. switch (attribute) {
  67. case EGL_BUFFER_SIZE:
  68. *value = buffer_size_;
  69. break;
  70. case EGL_RED_SIZE:
  71. *value = red_size_;
  72. break;
  73. case EGL_GREEN_SIZE:
  74. *value = green_size_;
  75. break;
  76. case EGL_BLUE_SIZE:
  77. *value = blue_size_;
  78. break;
  79. case EGL_LUMINANCE_SIZE:
  80. *value = luminance_size_;
  81. break;
  82. case EGL_ALPHA_SIZE:
  83. *value = alpha_size_;
  84. break;
  85. case EGL_ALPHA_MASK_SIZE:
  86. *value = alpha_mask_size_;
  87. break;
  88. case EGL_BIND_TO_TEXTURE_RGB:
  89. *value = bind_to_texture_rgb_;
  90. break;
  91. case EGL_BIND_TO_TEXTURE_RGBA:
  92. *value = bind_to_texture_rgba_;
  93. break;
  94. case EGL_COLOR_BUFFER_TYPE:
  95. *value = color_buffer_type_;
  96. break;
  97. case EGL_CONFIG_CAVEAT:
  98. *value = config_caveat_;
  99. break;
  100. case EGL_CONFIG_ID:
  101. *value = config_id_;
  102. break;
  103. case EGL_CONFORMANT:
  104. *value = conformant_;
  105. break;
  106. case EGL_DEPTH_SIZE:
  107. *value = depth_size_;
  108. break;
  109. case EGL_LEVEL:
  110. *value = level_;
  111. break;
  112. case EGL_MAX_PBUFFER_WIDTH:
  113. *value = max_pbuffer_width_;
  114. break;
  115. case EGL_MAX_PBUFFER_HEIGHT:
  116. *value = max_pbuffer_height_;
  117. break;
  118. case EGL_MAX_PBUFFER_PIXELS:
  119. *value = max_pbuffer_pixels_;
  120. break;
  121. case EGL_MIN_SWAP_INTERVAL:
  122. *value = min_swap_interval_;
  123. break;
  124. case EGL_MAX_SWAP_INTERVAL:
  125. *value = max_swap_interval_;
  126. break;
  127. case EGL_NATIVE_RENDERABLE:
  128. *value = native_renderable_;
  129. break;
  130. case EGL_NATIVE_VISUAL_ID:
  131. *value = native_visual_id_;
  132. break;
  133. case EGL_NATIVE_VISUAL_TYPE:
  134. *value = native_visual_type_;
  135. break;
  136. case EGL_RENDERABLE_TYPE:
  137. *value = renderable_type_;
  138. break;
  139. case EGL_SAMPLE_BUFFERS:
  140. *value = sample_buffers_;
  141. break;
  142. case EGL_SAMPLES:
  143. *value = samples_;
  144. break;
  145. case EGL_STENCIL_SIZE:
  146. *value = stencil_size_;
  147. break;
  148. case EGL_SURFACE_TYPE:
  149. *value = surface_type_;
  150. break;
  151. case EGL_TRANSPARENT_TYPE:
  152. *value = transparent_type_;
  153. break;
  154. case EGL_TRANSPARENT_RED_VALUE:
  155. *value = transparent_red_value_;
  156. break;
  157. case EGL_TRANSPARENT_GREEN_VALUE:
  158. *value = transparent_green_value_;
  159. break;
  160. case EGL_TRANSPARENT_BLUE_VALUE:
  161. *value = transparent_blue_value_;
  162. break;
  163. default:
  164. return false;
  165. }
  166. return true;
  167. }
  168. bool Config::ValidateAttributeList(const EGLint* attrib_list) {
  169. if (attrib_list) {
  170. for (int i = 0; attrib_list[i] != EGL_NONE; i += 2) {
  171. switch (attrib_list[i]) {
  172. case EGL_ALPHA_MASK_SIZE:
  173. case EGL_ALPHA_SIZE:
  174. case EGL_BIND_TO_TEXTURE_RGB:
  175. case EGL_BIND_TO_TEXTURE_RGBA:
  176. case EGL_BLUE_SIZE:
  177. case EGL_BUFFER_SIZE:
  178. case EGL_COLOR_BUFFER_TYPE:
  179. case EGL_CONFIG_CAVEAT:
  180. case EGL_CONFIG_ID:
  181. case EGL_CONFORMANT:
  182. case EGL_DEPTH_SIZE:
  183. case EGL_GREEN_SIZE:
  184. case EGL_LEVEL:
  185. case EGL_LUMINANCE_SIZE:
  186. case EGL_MATCH_NATIVE_PIXMAP:
  187. case EGL_NATIVE_RENDERABLE:
  188. case EGL_MAX_SWAP_INTERVAL:
  189. case EGL_MIN_SWAP_INTERVAL:
  190. case EGL_RED_SIZE:
  191. case EGL_SAMPLE_BUFFERS:
  192. case EGL_SAMPLES:
  193. case EGL_STENCIL_SIZE:
  194. case EGL_RENDERABLE_TYPE:
  195. case EGL_SURFACE_TYPE:
  196. case EGL_MULTISAMPLE_RESOLVE_BOX_BIT:
  197. case EGL_PBUFFER_BIT:
  198. case EGL_PIXMAP_BIT:
  199. case EGL_SWAP_BEHAVIOR_PRESERVED_BIT:
  200. case EGL_VG_ALPHA_FORMAT_PRE_BIT:
  201. case EGL_VG_COLORSPACE_LINEAR_BIT:
  202. case EGL_WINDOW_BIT:
  203. case EGL_TRANSPARENT_TYPE:
  204. case EGL_TRANSPARENT_RED_VALUE:
  205. case EGL_TRANSPARENT_GREEN_VALUE:
  206. case EGL_TRANSPARENT_BLUE_VALUE:
  207. break;
  208. default:
  209. return false;
  210. }
  211. }
  212. }
  213. return true;
  214. }
  215. } // namespace egl
  216. } // namespace gles2_conform_support