OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2015 Google Inc. | 3 * Copyright 2015 Google Inc. |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkMutex.h" | 9 #include "SkMutex.h" |
10 #include "SkOnce.h" | 10 #include "SkOnce.h" |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
133 } | 133 } |
134 | 134 |
135 static const GrGLInterface* create_command_buffer_interface() { | 135 static const GrGLInterface* create_command_buffer_interface() { |
136 load_command_buffer_once(); | 136 load_command_buffer_once(); |
137 if (!gfFunctionsLoadedSuccessfully) { | 137 if (!gfFunctionsLoadedSuccessfully) { |
138 return nullptr; | 138 return nullptr; |
139 } | 139 } |
140 return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc); | 140 return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc); |
141 } | 141 } |
142 | 142 |
143 // We use a poor man's garbage collector of EGLDisplays. They are only | |
144 // terminated when there are no more EGLDisplays in use. See crbug.com/603223 | |
145 SK_DECLARE_STATIC_MUTEX(gDisplayMutex); | |
146 static int gActiveDisplayCnt; | |
147 SkTArray<EGLDisplay> gRetiredDisplays; | |
148 | |
149 static EGLDisplay get_and_init_display() { | |
150 SkAutoMutexAcquire am(gDisplayMutex); | |
151 EGLDisplay dsp = gfGetDisplay(EGL_DEFAULT_DISPLAY); | |
152 if (dsp == EGL_NO_DISPLAY) { | |
153 return EGL_NO_DISPLAY; | |
154 } | |
155 EGLint major, minor; | |
156 if (!gfInitialize(dsp, &major, &minor)) { | |
157 gRetiredDisplays.push_back(dsp); | |
158 return EGL_NO_DISPLAY; | |
159 } | |
160 ++gActiveDisplayCnt; | |
161 return dsp; | |
162 } | |
163 | |
164 static void retire_display(EGLDisplay dsp) { | |
165 if (dsp == EGL_NO_DISPLAY) { | |
166 return; | |
167 } | |
168 SkAutoMutexAcquire am(gDisplayMutex); | |
169 gRetiredDisplays.push_back(dsp); | |
170 --gActiveDisplayCnt; | |
171 if (!gActiveDisplayCnt) { | |
172 for (EGLDisplay d : gRetiredDisplays) { | |
173 gfTerminate(d); | |
174 } | |
175 gRetiredDisplays.reset(); | |
176 } | |
177 } | |
178 } // anonymous namespace | 143 } // anonymous namespace |
179 | 144 |
180 namespace sk_gpu_test { | 145 namespace sk_gpu_test { |
181 | 146 |
182 CommandBufferGLTestContext::CommandBufferGLTestContext() | 147 CommandBufferGLTestContext::CommandBufferGLTestContext() |
183 : fContext(EGL_NO_CONTEXT), fDisplay(EGL_NO_DISPLAY), fSurface(EGL_NO_SURFAC
E) { | 148 : fContext(EGL_NO_CONTEXT), fDisplay(EGL_NO_DISPLAY), fSurface(EGL_NO_SURFAC
E) { |
184 | 149 |
185 static const EGLint configAttribs[] = { | 150 static const EGLint configAttribs[] = { |
186 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, | 151 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, |
187 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, | 152 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 void CommandBufferGLTestContext::initializeGLContext(void *nativeWindow, const i
nt *configAttribs, | 190 void CommandBufferGLTestContext::initializeGLContext(void *nativeWindow, const i
nt *configAttribs, |
226 const int *surfaceAttribs) { | 191 const int *surfaceAttribs) { |
227 load_command_buffer_once(); | 192 load_command_buffer_once(); |
228 if (!gfFunctionsLoadedSuccessfully) { | 193 if (!gfFunctionsLoadedSuccessfully) { |
229 SkDebugf("Command Buffer: Could not load EGL functions.\n"); | 194 SkDebugf("Command Buffer: Could not load EGL functions.\n"); |
230 return; | 195 return; |
231 } | 196 } |
232 | 197 |
233 // Make sure CHROMIUM_path_rendering is enabled for NVPR support. | 198 // Make sure CHROMIUM_path_rendering is enabled for NVPR support. |
234 sk_setenv("CHROME_COMMAND_BUFFER_GLES2_ARGS", "--enable-gl-path-rendering"); | 199 sk_setenv("CHROME_COMMAND_BUFFER_GLES2_ARGS", "--enable-gl-path-rendering"); |
235 fDisplay = get_and_init_display(); | 200 fDisplay = gfGetDisplay(EGL_DEFAULT_DISPLAY); |
236 if (EGL_NO_DISPLAY == fDisplay) { | 201 if (EGL_NO_DISPLAY == fDisplay) { |
237 SkDebugf("Command Buffer: Could not create EGL display.\n"); | 202 SkDebugf("Command Buffer: Could not create EGL display.\n"); |
238 return; | 203 return; |
239 } | 204 } |
240 | 205 if (!gfInitialize(fDisplay, nullptr, nullptr)) { |
| 206 SkDebugf("Command Buffer: Could not initialize EGL display.\n"); |
| 207 this->destroyGLContext(); |
| 208 return; |
| 209 } |
241 EGLint numConfigs; | 210 EGLint numConfigs; |
242 if (!gfChooseConfig(fDisplay, configAttribs, static_cast<EGLConfig *>(&fConf
ig), 1, | 211 if (!gfChooseConfig(fDisplay, configAttribs, static_cast<EGLConfig *>(&fConf
ig), 1, |
243 &numConfigs) || numConfigs != 1) { | 212 &numConfigs) || numConfigs != 1) { |
244 SkDebugf("Command Buffer: Could not choose EGL config.\n"); | 213 SkDebugf("Command Buffer: Could not choose EGL config.\n"); |
245 this->destroyGLContext(); | 214 this->destroyGLContext(); |
246 return; | 215 return; |
247 } | 216 } |
248 | 217 |
249 if (nativeWindow) { | 218 if (nativeWindow) { |
250 fSurface = gfCreateWindowSurface(fDisplay, | 219 fSurface = gfCreateWindowSurface(fDisplay, |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 | 265 |
297 CommandBufferGLTestContext::~CommandBufferGLTestContext() { | 266 CommandBufferGLTestContext::~CommandBufferGLTestContext() { |
298 this->teardown(); | 267 this->teardown(); |
299 this->destroyGLContext(); | 268 this->destroyGLContext(); |
300 } | 269 } |
301 | 270 |
302 void CommandBufferGLTestContext::destroyGLContext() { | 271 void CommandBufferGLTestContext::destroyGLContext() { |
303 if (!gfFunctionsLoadedSuccessfully) { | 272 if (!gfFunctionsLoadedSuccessfully) { |
304 return; | 273 return; |
305 } | 274 } |
306 if (fDisplay) { | 275 if (EGL_NO_DISPLAY == fDisplay) { |
307 gfMakeCurrent(fDisplay, 0, 0, 0); | 276 return; |
| 277 } |
| 278 if (EGL_NO_CONTEXT != fContext) { |
| 279 gfDestroyContext(fDisplay, fContext); |
| 280 fContext = EGL_NO_CONTEXT; |
| 281 } |
| 282 // Call MakeCurrent after destroying the context, so that the EGL implementa
tion knows that |
| 283 // the context is not used anymore after it is released from being current.
This way |
| 284 // command buffer does not need to abandon the context before destruction, a
nd no |
| 285 // client-side errors are printed. |
| 286 gfMakeCurrent(fDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); |
308 | 287 |
309 if (fContext) { | 288 if (EGL_NO_SURFACE != fSurface) { |
310 gfDestroyContext(fDisplay, fContext); | 289 gfDestroySurface(fDisplay, fSurface); |
311 fContext = EGL_NO_CONTEXT; | 290 fSurface = EGL_NO_SURFACE; |
312 } | |
313 | |
314 if (fSurface) { | |
315 gfDestroySurface(fDisplay, fSurface); | |
316 fSurface = EGL_NO_SURFACE; | |
317 } | |
318 | |
319 retire_display(fDisplay); | |
320 fDisplay = EGL_NO_DISPLAY; | |
321 } | 291 } |
| 292 fDisplay = EGL_NO_DISPLAY; |
322 } | 293 } |
323 | 294 |
324 void CommandBufferGLTestContext::onPlatformMakeCurrent() const { | 295 void CommandBufferGLTestContext::onPlatformMakeCurrent() const { |
325 if (!gfFunctionsLoadedSuccessfully) { | 296 if (!gfFunctionsLoadedSuccessfully) { |
326 return; | 297 return; |
327 } | 298 } |
328 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { | 299 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { |
329 SkDebugf("Command Buffer: Could not make EGL context current.\n"); | 300 SkDebugf("Command Buffer: Could not make EGL context current.\n"); |
330 } | 301 } |
331 } | 302 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
364 return result; | 335 return result; |
365 } | 336 } |
366 | 337 |
367 int CommandBufferGLTestContext::getSampleCount() { | 338 int CommandBufferGLTestContext::getSampleCount() { |
368 EGLint result = 0; | 339 EGLint result = 0; |
369 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_SAMPLES, &r
esult); | 340 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_SAMPLES, &r
esult); |
370 return result; | 341 return result; |
371 } | 342 } |
372 | 343 |
373 } // namespace sk_gpu_test | 344 } // namespace sk_gpu_test |
OLD | NEW |