Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(485)

Side by Side Diff: tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp

Issue 1878943008: Only eglTerminate command buffer displays when no displays are in use (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: add statics Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "SkOnce.h" 10 #include "SkOnce.h"
10 #include "gl/GrGLInterface.h" 11 #include "gl/GrGLInterface.h"
11 #include "gl/GrGLAssembleInterface.h" 12 #include "gl/GrGLAssembleInterface.h"
12 #include "gl/command_buffer/GLTestContext_command_buffer.h" 13 #include "gl/command_buffer/GLTestContext_command_buffer.h"
13 #include "../ports/SkOSEnvironment.h" 14 #include "../ports/SkOSEnvironment.h"
14 #include "../ports/SkOSLibrary.h" 15 #include "../ports/SkOSLibrary.h"
15 16
16 #if defined SK_BUILD_FOR_MAC 17 #if defined SK_BUILD_FOR_MAC
17 18
18 // EGL doesn't exist on the mac, so expose what we need to get the command buffe r's EGL running. 19 // EGL doesn't exist on the mac, so expose what we need to get the command buffe r's EGL running.
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 } 133 }
133 134
134 static const GrGLInterface* create_command_buffer_interface() { 135 static const GrGLInterface* create_command_buffer_interface() {
135 load_command_buffer_once(); 136 load_command_buffer_once();
136 if (!gfFunctionsLoadedSuccessfully) { 137 if (!gfFunctionsLoadedSuccessfully) {
137 return nullptr; 138 return nullptr;
138 } 139 }
139 return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc); 140 return GrGLAssembleGLESInterface(gLibrary, command_buffer_get_gl_proc);
140 } 141 }
141 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 }
142 } // anonymous namespace 178 } // anonymous namespace
143 179
144 namespace sk_gpu_test { 180 namespace sk_gpu_test {
145 181
146 CommandBufferGLTestContext::CommandBufferGLTestContext() 182 CommandBufferGLTestContext::CommandBufferGLTestContext()
147 : fContext(EGL_NO_CONTEXT), fDisplay(EGL_NO_DISPLAY), fSurface(EGL_NO_SURFAC E) { 183 : fContext(EGL_NO_CONTEXT), fDisplay(EGL_NO_DISPLAY), fSurface(EGL_NO_SURFAC E) {
148 184
149 static const EGLint configAttribs[] = { 185 static const EGLint configAttribs[] = {
150 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, 186 EGL_SURFACE_TYPE, EGL_PBUFFER_BIT,
151 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 187 EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 void CommandBufferGLTestContext::initializeGLContext(void *nativeWindow, const i nt *configAttribs, 225 void CommandBufferGLTestContext::initializeGLContext(void *nativeWindow, const i nt *configAttribs,
190 const int *surfaceAttribs) { 226 const int *surfaceAttribs) {
191 load_command_buffer_once(); 227 load_command_buffer_once();
192 if (!gfFunctionsLoadedSuccessfully) { 228 if (!gfFunctionsLoadedSuccessfully) {
193 SkDebugf("Command Buffer: Could not load EGL functions.\n"); 229 SkDebugf("Command Buffer: Could not load EGL functions.\n");
194 return; 230 return;
195 } 231 }
196 232
197 // Make sure CHROMIUM_path_rendering is enabled for NVPR support. 233 // Make sure CHROMIUM_path_rendering is enabled for NVPR support.
198 sk_setenv("CHROME_COMMAND_BUFFER_GLES2_ARGS", "--enable-gl-path-rendering"); 234 sk_setenv("CHROME_COMMAND_BUFFER_GLES2_ARGS", "--enable-gl-path-rendering");
199 fDisplay = gfGetDisplay(EGL_DEFAULT_DISPLAY); 235 fDisplay = get_and_init_display();
200 if (EGL_NO_DISPLAY == fDisplay) { 236 if (EGL_NO_DISPLAY == fDisplay) {
201 SkDebugf("Command Buffer: Could not create EGL display.\n"); 237 SkDebugf("Command Buffer: Could not create EGL display.\n");
202 return; 238 return;
203 } 239 }
204 240
205 EGLint majorVersion;
206 EGLint minorVersion;
207 if (!gfInitialize(fDisplay, &majorVersion, &minorVersion)) {
208 SkDebugf("Command Buffer: Could not initialize EGL display.\n");
209 this->destroyGLContext();
210 return;
211 }
212
213 EGLint numConfigs; 241 EGLint numConfigs;
214 if (!gfChooseConfig(fDisplay, configAttribs, static_cast<EGLConfig *>(&fConf ig), 1, 242 if (!gfChooseConfig(fDisplay, configAttribs, static_cast<EGLConfig *>(&fConf ig), 1,
215 &numConfigs) || numConfigs != 1) { 243 &numConfigs) || numConfigs != 1) {
216 SkDebugf("Command Buffer: Could not choose EGL config.\n"); 244 SkDebugf("Command Buffer: Could not choose EGL config.\n");
217 this->destroyGLContext(); 245 this->destroyGLContext();
218 return; 246 return;
219 } 247 }
220 248
221 if (nativeWindow) { 249 if (nativeWindow) {
222 fSurface = gfCreateWindowSurface(fDisplay, 250 fSurface = gfCreateWindowSurface(fDisplay,
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 if (fContext) { 309 if (fContext) {
282 gfDestroyContext(fDisplay, fContext); 310 gfDestroyContext(fDisplay, fContext);
283 fContext = EGL_NO_CONTEXT; 311 fContext = EGL_NO_CONTEXT;
284 } 312 }
285 313
286 if (fSurface) { 314 if (fSurface) {
287 gfDestroySurface(fDisplay, fSurface); 315 gfDestroySurface(fDisplay, fSurface);
288 fSurface = EGL_NO_SURFACE; 316 fSurface = EGL_NO_SURFACE;
289 } 317 }
290 318
291 gfTerminate(fDisplay); 319 retire_display(fDisplay);
292 fDisplay = EGL_NO_DISPLAY; 320 fDisplay = EGL_NO_DISPLAY;
293 } 321 }
294 } 322 }
295 323
296 void CommandBufferGLTestContext::onPlatformMakeCurrent() const { 324 void CommandBufferGLTestContext::onPlatformMakeCurrent() const {
297 if (!gfFunctionsLoadedSuccessfully) { 325 if (!gfFunctionsLoadedSuccessfully) {
298 return; 326 return;
299 } 327 }
300 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) { 328 if (!gfMakeCurrent(fDisplay, fSurface, fSurface, fContext)) {
301 SkDebugf("Command Buffer: Could not make EGL context current.\n"); 329 SkDebugf("Command Buffer: Could not make EGL context current.\n");
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 return result; 364 return result;
337 } 365 }
338 366
339 int CommandBufferGLTestContext::getSampleCount() { 367 int CommandBufferGLTestContext::getSampleCount() {
340 EGLint result = 0; 368 EGLint result = 0;
341 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_SAMPLES, &r esult); 369 gfGetConfigAttrib(fDisplay, static_cast<EGLConfig>(fConfig), EGL_SAMPLES, &r esult);
342 return result; 370 return result;
343 } 371 }
344 372
345 } // namespace sk_gpu_test 373 } // namespace sk_gpu_test
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698