OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // This include must be here so that the includes provided transitively | 5 // This include must be here so that the includes provided transitively |
6 // by gl_surface_egl.h don't make it impossible to compile this code. | 6 // by gl_surface_egl.h don't make it impossible to compile this code. |
7 #include "third_party/mesa/src/include/GL/osmesa.h" | 7 #include "third_party/mesa/src/include/GL/osmesa.h" |
8 | 8 |
9 #include "ui/gl/gl_surface_egl.h" | 9 #include "ui/gl/gl_surface_egl.h" |
10 | 10 |
11 #if defined(OS_ANDROID) | 11 #if defined(OS_ANDROID) |
12 #include <android/native_window_jni.h> | 12 #include <android/native_window_jni.h> |
13 #endif | 13 #endif |
14 | 14 |
15 #include "base/android/sys_utils.h" | |
kalyank
2014/01/20 14:48:31
We could include this only on Android platform.
kalyank
2014/01/20 14:49:52
sorry, ignore this. I was looking at wrong version
| |
15 #include "base/command_line.h" | 16 #include "base/command_line.h" |
16 #include "base/debug/trace_event.h" | 17 #include "base/debug/trace_event.h" |
17 #include "base/logging.h" | 18 #include "base/logging.h" |
18 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
19 #include "base/message_loop/message_loop.h" | 20 #include "base/message_loop/message_loop.h" |
20 #include "build/build_config.h" | 21 #include "build/build_config.h" |
21 #include "ui/gl/egl_util.h" | 22 #include "ui/gl/egl_util.h" |
22 #include "ui/gl/gl_context.h" | 23 #include "ui/gl/gl_context.h" |
23 #include "ui/gl/gl_implementation.h" | 24 #include "ui/gl/gl_implementation.h" |
24 #include "ui/gl/gl_surface_osmesa.h" | 25 #include "ui/gl/gl_surface_osmesa.h" |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
130 return false; | 131 return false; |
131 } | 132 } |
132 | 133 |
133 if (!eglInitialize(g_display, NULL, NULL)) { | 134 if (!eglInitialize(g_display, NULL, NULL)) { |
134 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); | 135 LOG(ERROR) << "eglInitialize failed with error " << GetLastEGLErrorString(); |
135 return false; | 136 return false; |
136 } | 137 } |
137 | 138 |
138 // Choose an EGL configuration. | 139 // Choose an EGL configuration. |
139 // On X this is only used for PBuffer surfaces. | 140 // On X this is only used for PBuffer surfaces. |
140 static const EGLint kConfigAttribs[] = { | 141 static EGLint configattribs_8888[] = { |
piman
2014/01/17 18:20:01
nit: config_attribs_8888
sivag
2014/01/20 14:10:37
Done.
| |
141 EGL_BUFFER_SIZE, 32, | 142 EGL_BUFFER_SIZE, 32, |
142 EGL_ALPHA_SIZE, 8, | 143 EGL_ALPHA_SIZE, 8, |
143 EGL_BLUE_SIZE, 8, | 144 EGL_BLUE_SIZE, 8, |
144 EGL_GREEN_SIZE, 8, | 145 EGL_GREEN_SIZE, 8, |
145 EGL_RED_SIZE, 8, | 146 EGL_RED_SIZE, 8, |
146 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 147 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
147 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, | 148 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, |
148 EGL_NONE | 149 EGL_NONE |
149 }; | 150 }; |
150 | 151 |
152 #if defined(OS_ANDROID) | |
153 static EGLint configattribs_565[] = { | |
piman
2014/01/17 18:20:01
nit: config_attribs_565
sivag
2014/01/20 14:10:37
Done.
| |
154 EGL_BUFFER_SIZE, 16, | |
155 EGL_BLUE_SIZE, 5, | |
156 EGL_GREEN_SIZE, 6, | |
157 EGL_RED_SIZE, 5, | |
158 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | |
159 EGL_SURFACE_TYPE, EGL_WINDOW_BIT | EGL_PBUFFER_BIT, | |
160 EGL_NONE | |
161 }; | |
162 #endif | |
163 | |
164 EGLint* choose_attributes = 0; | |
165 #if defined(OS_ANDROID) | |
166 if (base::android::SysUtils::IsLowEndDevice()) { | |
167 choose_attributes = configattribs_565; | |
168 } else { | |
169 choose_attributes = configattribs_8888; | |
170 } | |
171 #else | |
172 choose_attributes = configattribs_8888; | |
173 #endif | |
174 | |
151 #if defined(USE_OZONE) | 175 #if defined(USE_OZONE) |
152 const EGLint* config_attribs = | 176 const EGLint* kConfigAttribs = |
no sievers
2014/01/17 18:05:30
nit: Just use |choose_attributes| here and below.
sivag
2014/01/20 14:10:37
Done.
| |
153 surface_factory->GetEGLSurfaceProperties(kConfigAttribs); | 177 surface_factory->GetEGLSurfaceProperties(choose_attributes); |
154 #else | 178 #else |
155 const EGLint* config_attribs = kConfigAttribs; | 179 const EGLint* kConfigAttribs = choose_attributes; |
156 #endif | 180 #endif |
157 | 181 |
158 EGLint num_configs; | 182 EGLint num_configs; |
159 if (!eglChooseConfig(g_display, | 183 if (!eglChooseConfig(g_display, |
160 config_attribs, | 184 kConfigAttribs, |
161 NULL, | 185 NULL, |
162 0, | 186 0, |
163 &num_configs)) { | 187 &num_configs)) { |
164 LOG(ERROR) << "eglChooseConfig failed with error " | 188 LOG(ERROR) << "eglChooseConfig failed with error " |
165 << GetLastEGLErrorString(); | 189 << GetLastEGLErrorString(); |
166 return false; | 190 return false; |
167 } | 191 } |
168 | 192 |
169 if (num_configs == 0) { | 193 if (num_configs == 0) { |
170 LOG(ERROR) << "No suitable EGL configs found."; | 194 LOG(ERROR) << "No suitable EGL configs found."; |
171 return false; | 195 return false; |
172 } | 196 } |
173 | 197 |
198 EGLConfig* matching_configs = NULL; | |
199 int config_size = 1; | |
200 | |
201 #if defined(OS_ANDROID) | |
202 if (base::android::SysUtils::IsLowEndDevice()) { | |
203 matching_configs = (EGLConfig*)malloc(num_configs * sizeof(EGLConfig)); | |
no sievers
2014/01/17 18:05:30
Instead of malloc/free, you can use:
scoped_ptr<EG
sivag
2014/01/20 14:10:37
Done.
| |
204 config_size = num_configs; | |
205 } else { | |
206 matching_configs = &g_config; | |
207 config_size = 1; | |
208 } | |
209 #else | |
210 matching_configs = &g_config; | |
211 config_size = 1; | |
212 #endif | |
213 | |
174 if (!eglChooseConfig(g_display, | 214 if (!eglChooseConfig(g_display, |
175 config_attribs, | 215 kConfigAttribs, |
176 &g_config, | 216 matching_configs, |
177 1, | 217 config_size, |
178 &num_configs)) { | 218 &num_configs)) { |
179 LOG(ERROR) << "eglChooseConfig failed with error " | 219 LOG(ERROR) << "eglChooseConfig failed with error " |
180 << GetLastEGLErrorString(); | 220 << GetLastEGLErrorString(); |
181 return false; | 221 return false; |
182 } | 222 } |
183 | 223 |
224 #if defined(OS_ANDROID) | |
225 if (base::android::SysUtils::IsLowEndDevice()) { | |
226 bool match_found = false; | |
227 for (int i = 0; i < num_configs; i++) | |
228 { | |
piman
2014/01/17 18:20:01
nit: { on previous line
sivag
2014/01/20 14:10:37
Done.
| |
229 EGLBoolean success; | |
230 EGLint red, green, blue; | |
231 // Read the relevent attributes of the EGLConfig. | |
232 success = eglGetConfigAttrib(g_display, matching_configs[i], | |
233 EGL_RED_SIZE, &red); | |
234 success &= eglGetConfigAttrib(g_display, matching_configs[i], | |
235 EGL_BLUE_SIZE, &blue); | |
236 success &= eglGetConfigAttrib(g_display, matching_configs[i], | |
237 EGL_GREEN_SIZE, &green); | |
238 // Check that no error occurred and the attributes match. | |
239 if ((success == EGL_TRUE) && (red == 5) && | |
240 (green == 6) && (blue == 5)) { | |
241 g_config = matching_configs[i]; | |
242 match_found = true; | |
243 break; | |
244 } | |
245 } | |
246 if (matching_configs) { | |
247 free(matching_configs); | |
248 matching_configs = NULL; | |
249 } | |
250 if (!match_found) { | |
251 LOG(ERROR) << "eglChooseConfig failed with error for lowend device" | |
252 << GetLastEGLErrorString(); | |
253 return false; | |
no sievers
2014/01/17 18:05:30
We should fall back to 32bit, since not all driver
sivag
2014/01/20 14:10:37
Done.
| |
254 } | |
255 } | |
256 #endif | |
257 | |
184 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); | 258 g_egl_extensions = eglQueryString(g_display, EGL_EXTENSIONS); |
185 g_egl_create_context_robustness_supported = | 259 g_egl_create_context_robustness_supported = |
186 HasEGLExtension("EGL_EXT_create_context_robustness"); | 260 HasEGLExtension("EGL_EXT_create_context_robustness"); |
187 g_egl_sync_control_supported = | 261 g_egl_sync_control_supported = |
188 HasEGLExtension("EGL_CHROMIUM_sync_control"); | 262 HasEGLExtension("EGL_CHROMIUM_sync_control"); |
189 | 263 |
190 // Check if SurfacelessEGL is supported. | 264 // Check if SurfacelessEGL is supported. |
191 g_egl_surfaceless_context_supported = | 265 g_egl_surfaceless_context_supported = |
192 HasEGLExtension("EGL_KHR_surfaceless_context"); | 266 HasEGLExtension("EGL_KHR_surfaceless_context"); |
193 if (g_egl_surfaceless_context_supported) { | 267 if (g_egl_surfaceless_context_supported) { |
(...skipping 572 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 } | 840 } |
767 default: | 841 default: |
768 NOTREACHED(); | 842 NOTREACHED(); |
769 return NULL; | 843 return NULL; |
770 } | 844 } |
771 } | 845 } |
772 | 846 |
773 #endif | 847 #endif |
774 | 848 |
775 } // namespace gfx | 849 } // namespace gfx |
OLD | NEW |