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

Side by Side Diff: gpu/gles2_conform_support/egl/display.cc

Issue 1674223002: Only call gles2::Terminate when all Display objects are deleted (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@egl_test_branch
Patch Set: Created 4 years, 10 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
OLDNEW
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 #include "gpu/gles2_conform_support/egl/display.h" 5 #include "gpu/gles2_conform_support/egl/display.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <vector> 10 #include <vector>
(...skipping 13 matching lines...) Expand all
24 #include "gpu/gles2_conform_support/egl/config.h" 24 #include "gpu/gles2_conform_support/egl/config.h"
25 #include "gpu/gles2_conform_support/egl/surface.h" 25 #include "gpu/gles2_conform_support/egl/surface.h"
26 #include "gpu/gles2_conform_support/egl/test_support.h" 26 #include "gpu/gles2_conform_support/egl/test_support.h"
27 27
28 namespace { 28 namespace {
29 const int32_t kCommandBufferSize = 1024 * 1024; 29 const int32_t kCommandBufferSize = 1024 * 1024;
30 const int32_t kTransferBufferSize = 512 * 1024; 30 const int32_t kTransferBufferSize = 512 * 1024;
31 } 31 }
32 32
33 namespace egl { 33 namespace egl {
34 #if defined(COMMAND_BUFFER_GLES_LIB_SUPPORT_ONLY) 34
35 // egl::Display is used for comformance tests and command_buffer_gles. We only 35 // egl::Display is used for comformance tests and command_buffer_gles. We only
36 // need the exit manager for the command_buffer_gles library. 36 // need the exit manager for the command_buffer_gles library.
37 // TODO(hendrikw): Find a cleaner solution for this. 37 // TODO(hendrikw): Find a cleaner solution for this.
38 namespace { 38 namespace {
39 base::LazyInstance<base::Lock>::Leaky g_exit_manager_lock; 39 base::LazyInstance<base::Lock>::Leaky g_init_lock;
40 int g_exit_manager_use_count; 40 int g_init_count;
41
42 #if defined(COMMAND_BUFFER_GLES_LIB_SUPPORT_ONLY)
41 base::AtExitManager* g_exit_manager; 43 base::AtExitManager* g_exit_manager;
42 void RefAtExitManager() { 44 #endif
43 base::AutoLock lock(g_exit_manager_lock.Get()); 45
46 void InitGlobal() {
47 base::AutoLock lock(g_init_lock.Get());
48 if (g_init_count == 0) {
49 gles2::Initialize();
50 }
51
52 #if defined(COMMAND_BUFFER_GLES_LIB_SUPPORT_ONLY)
53 #if defined(COMPONENT_BUILD)
54 if (g_command_buffer_gles_has_atexit_manager) {
piman 2016/02/08 17:36:08 nit: indent (should be at +2, not +4)
Sami Väisänen 2016/02/09 10:05:28 Acknowledged.
55 ++g_init_count;
56 return;
57 }
58 #endif
59 if (g_init_count == 0) {
60 g_exit_manager = new base::AtExitManager;
61 }
62 #endif
63
64 ++g_init_count;
65
66 }
67 void ReleaseGlobal() {
68 base::AutoLock lock(g_init_lock.Get());
69 --g_init_count;
70 if (g_init_count == 0) {
71 gles2::Terminate();
72 }
73
74 #if defined(COMMAND_BUFFER_GLES_LIB_SUPPORT_ONLY)
44 #if defined(COMPONENT_BUILD) 75 #if defined(COMPONENT_BUILD)
45 if (g_command_buffer_gles_has_atexit_manager) { 76 if (g_command_buffer_gles_has_atexit_manager) {
46 return; 77 return;
47 } 78 }
48 #endif 79 #endif
49 if (g_exit_manager_use_count == 0) { 80 if (g_init_count == 0) {
50 g_exit_manager = new base::AtExitManager;
51 }
52 ++g_exit_manager_use_count;
53 }
54 void ReleaseAtExitManager() {
55 base::AutoLock lock(g_exit_manager_lock.Get());
56 #if defined(COMPONENT_BUILD)
57 if (g_command_buffer_gles_has_atexit_manager) {
58 return;
59 }
60 #endif
61 --g_exit_manager_use_count;
62 if (g_exit_manager_use_count == 0) {
63 delete g_exit_manager; 81 delete g_exit_manager;
64 g_exit_manager = nullptr; 82 g_exit_manager = nullptr;
65 } 83 }
84 #endif
66 } 85 }
67 } 86 } // namespace
68 #endif 87
69 88
70 Display::Display(EGLNativeDisplayType display_id) 89 Display::Display(EGLNativeDisplayType display_id)
71 : display_id_(display_id), 90 : display_id_(display_id),
72 is_initialized_(false), 91 is_initialized_(false),
73 create_offscreen_(false), 92 create_offscreen_(false),
74 create_offscreen_width_(0), 93 create_offscreen_width_(0),
75 create_offscreen_height_(0), 94 create_offscreen_height_(0),
76 next_fence_sync_release_(1) { 95 next_fence_sync_release_(1) {
77 #if defined(COMMAND_BUFFER_GLES_LIB_SUPPORT_ONLY) 96
78 RefAtExitManager(); 97 InitGlobal();
79 #endif 98
80 } 99 }
81 100
82 Display::~Display() { 101 Display::~Display() {
83 gles2::Terminate(); 102
84 #if defined(COMMAND_BUFFER_GLES_LIB_SUPPORT_ONLY) 103 ReleaseGlobal();
85 ReleaseAtExitManager(); 104
86 #endif
87 } 105 }
88 106
89 bool Display::Initialize() { 107 bool Display::Initialize() {
90 gles2::Initialize();
91 is_initialized_ = true; 108 is_initialized_ = true;
92 return true; 109 return true;
93 } 110 }
94 111
95 bool Display::IsValidConfig(EGLConfig config) { 112 bool Display::IsValidConfig(EGLConfig config) {
96 return (config != NULL) && (config == config_.get()); 113 return (config != NULL) && (config == config_.get());
97 } 114 }
98 115
99 bool Display::ChooseConfigs(EGLConfig* configs, 116 bool Display::ChooseConfigs(EGLConfig* configs,
100 EGLint config_size, 117 EGLint config_size,
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
396 void Display::SignalSyncToken(const gpu::SyncToken& sync_token, 413 void Display::SignalSyncToken(const gpu::SyncToken& sync_token,
397 const base::Closure& callback) { 414 const base::Closure& callback) {
398 NOTIMPLEMENTED(); 415 NOTIMPLEMENTED();
399 } 416 }
400 417
401 bool Display::CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) { 418 bool Display::CanWaitUnverifiedSyncToken(const gpu::SyncToken* sync_token) {
402 return false; 419 return false;
403 } 420 }
404 421
405 } // namespace egl 422 } // namespace egl
OLDNEW
« gpu/command_buffer/tests/egl_test.cc ('K') | « gpu/command_buffer/tests/egl_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698