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

Side by Side Diff: content/browser/renderer_host/compositing_iosurface_context_mac.mm

Issue 231863002: Mac: Recreate browser-side GL contexts on GPU switch (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove prototype Created 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/browser/renderer_host/compositing_iosurface_context_mac.h" 5 #include "content/browser/renderer_host/compositing_iosurface_context_mac.h"
6 6
7 #include <OpenGL/gl.h> 7 #include <OpenGL/gl.h>
8 #include <OpenGL/OpenGL.h> 8 #include <OpenGL/OpenGL.h>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/command_line.h" 11 #include "base/command_line.h"
12 #include "base/debug/trace_event.h" 12 #include "base/debug/trace_event.h"
13 #include "base/logging.h" 13 #include "base/logging.h"
14 #include "content/browser/renderer_host/compositing_iosurface_shader_programs_ma c.h" 14 #include "content/browser/renderer_host/compositing_iosurface_shader_programs_ma c.h"
15 #include "content/public/browser/gpu_data_manager.h"
Zhenyao Mo 2014/04/09 22:24:24 Usually inside content side, we directly use gpu_d
ccameron 2014/04/09 22:37:28 Done.
15 #include "ui/base/ui_base_switches.h" 16 #include "ui/base/ui_base_switches.h"
16 #include "ui/gl/gl_switches.h" 17 #include "ui/gl/gl_switches.h"
17 #include "ui/gl/gpu_switching_manager.h" 18 #include "ui/gl/gpu_switching_manager.h"
18 19
19 namespace content { 20 namespace content {
20 21
21 CoreAnimationStatus GetCoreAnimationStatus() { 22 CoreAnimationStatus GetCoreAnimationStatus() {
22 static CoreAnimationStatus status = 23 static CoreAnimationStatus status =
23 CommandLine::ForCurrentProcess()->HasSwitch( 24 CommandLine::ForCurrentProcess()->HasSwitch(
24 switches::kDisableCoreAnimation) ? 25 switches::kDisableCoreAnimation) ?
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache) 176 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache)
176 : window_number_(window_number), 177 : window_number_(window_number),
177 nsgl_context_(nsgl_context), 178 nsgl_context_(nsgl_context),
178 cgl_context_strong_(cgl_context_strong), 179 cgl_context_strong_(cgl_context_strong),
179 cgl_context_(cgl_context), 180 cgl_context_(cgl_context),
180 is_vsync_disabled_(is_vsync_disabled), 181 is_vsync_disabled_(is_vsync_disabled),
181 shader_program_cache_(shader_program_cache.Pass()), 182 shader_program_cache_(shader_program_cache.Pass()),
182 poisoned_(false) { 183 poisoned_(false) {
183 DCHECK(window_map()->find(window_number_) == window_map()->end()); 184 DCHECK(window_map()->find(window_number_) == window_map()->end());
184 window_map()->insert(std::make_pair(window_number_, this)); 185 window_map()->insert(std::make_pair(window_number_, this));
186
187 content::GpuDataManager::GetInstance()->AddObserver(this);
Zhenyao Mo 2014/04/09 22:24:24 nit:no need for content namespace, and use GpuData
ccameron 2014/04/09 22:37:28 Done.
185 } 188 }
186 189
187 CompositingIOSurfaceContext::~CompositingIOSurfaceContext() { 190 CompositingIOSurfaceContext::~CompositingIOSurfaceContext() {
191 content::GpuDataManager::GetInstance()->RemoveObserver(this);
192
188 { 193 {
189 gfx::ScopedCGLSetCurrentContext scoped_set_current_context(cgl_context_); 194 gfx::ScopedCGLSetCurrentContext scoped_set_current_context(cgl_context_);
190 shader_program_cache_->Reset(); 195 shader_program_cache_->Reset();
191 } 196 }
192 if (!poisoned_) { 197 if (!poisoned_) {
193 DCHECK(window_map()->find(window_number_) != window_map()->end()); 198 DCHECK(window_map()->find(window_number_) != window_map()->end());
194 DCHECK(window_map()->find(window_number_)->second == this); 199 DCHECK(window_map()->find(window_number_)->second == this);
195 window_map()->erase(window_number_); 200 window_map()->erase(window_number_);
196 } else { 201 } else {
197 WindowMap::const_iterator found = window_map()->find(window_number_); 202 WindowMap::const_iterator found = window_map()->find(window_number_);
198 if (found != window_map()->end()) 203 if (found != window_map()->end())
199 DCHECK(found->second != this); 204 DCHECK(found->second != this);
200 } 205 }
201 } 206 }
202 207
203 NSOpenGLContext* CompositingIOSurfaceContext::nsgl_context() const { 208 NSOpenGLContext* CompositingIOSurfaceContext::nsgl_context() const {
204 // This should not be called from any CoreAnimation paths. 209 // This should not be called from any CoreAnimation paths.
205 CHECK(GetCoreAnimationStatus() == CORE_ANIMATION_DISABLED); 210 CHECK(GetCoreAnimationStatus() == CORE_ANIMATION_DISABLED);
206 return nsgl_context_; 211 return nsgl_context_;
207 } 212 }
208 213
214 void CompositingIOSurfaceContext::OnGpuSwitching() {
215 // Recreate all browser-side GL contexts whenever the GPU switches. If this
216 // is not done, performance will suffer.
217 // http://crbug.com/361493
218 PoisonContextAndSharegroup();
219 }
220
209 // static 221 // static
210 CompositingIOSurfaceContext::WindowMap* 222 CompositingIOSurfaceContext::WindowMap*
211 CompositingIOSurfaceContext::window_map() { 223 CompositingIOSurfaceContext::window_map() {
212 return window_map_.Pointer(); 224 return window_map_.Pointer();
213 } 225 }
214 226
215 // static 227 // static
216 base::LazyInstance<CompositingIOSurfaceContext::WindowMap> 228 base::LazyInstance<CompositingIOSurfaceContext::WindowMap>
217 CompositingIOSurfaceContext::window_map_; 229 CompositingIOSurfaceContext::window_map_;
218 230
219 } // namespace content 231 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698