OLD | NEW |
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 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_ | 5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_ |
6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_ | 6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_ |
7 | 7 |
8 #import <AppKit/NSOpenGL.h> | 8 #import <AppKit/NSOpenGL.h> |
9 #include <OpenGL/OpenGL.h> | 9 #include <OpenGL/OpenGL.h> |
10 #include <map> | 10 #include <map> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/mac/scoped_nsobject.h" | 14 #include "base/mac/scoped_nsobject.h" |
15 #include "base/memory/ref_counted.h" | 15 #include "base/memory/ref_counted.h" |
16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "content/public/browser/gpu_data_manager_observer.h" |
17 #include "ui/gl/scoped_cgl.h" | 18 #include "ui/gl/scoped_cgl.h" |
18 | 19 |
19 namespace content { | 20 namespace content { |
20 | 21 |
21 enum CoreAnimationStatus { | 22 enum CoreAnimationStatus { |
22 CORE_ANIMATION_DISABLED, | 23 CORE_ANIMATION_DISABLED, |
23 CORE_ANIMATION_ENABLED, | 24 CORE_ANIMATION_ENABLED, |
24 }; | 25 }; |
25 CoreAnimationStatus GetCoreAnimationStatus(); | 26 CoreAnimationStatus GetCoreAnimationStatus(); |
26 | 27 |
27 class CompositingIOSurfaceShaderPrograms; | 28 class CompositingIOSurfaceShaderPrograms; |
28 | 29 |
29 class CompositingIOSurfaceContext | 30 class CompositingIOSurfaceContext |
30 : public base::RefCounted<CompositingIOSurfaceContext> { | 31 : public base::RefCounted<CompositingIOSurfaceContext>, |
| 32 public content::GpuDataManagerObserver { |
31 public: | 33 public: |
32 enum { | 34 enum { |
33 // The number used to look up the context used for async readback and for | 35 // The number used to look up the context used for async readback and for |
34 // initializing the IOSurface. | 36 // initializing the IOSurface. |
35 kOffscreenContextWindowNumber = -2, | 37 kOffscreenContextWindowNumber = -2, |
36 // The number used to look up the context used by CAOpenGLLayers. | 38 // The number used to look up the context used by CAOpenGLLayers. |
37 kCALayerContextWindowNumber = -3, | 39 kCALayerContextWindowNumber = -3, |
38 }; | 40 }; |
39 | 41 |
40 // Get or create a GL context for the specified window with the specified | 42 // Get or create a GL context for the specified window with the specified |
(...skipping 10 matching lines...) Expand all Loading... |
51 bool HasBeenPoisoned() const { return poisoned_; } | 53 bool HasBeenPoisoned() const { return poisoned_; } |
52 | 54 |
53 CompositingIOSurfaceShaderPrograms* shader_program_cache() const { | 55 CompositingIOSurfaceShaderPrograms* shader_program_cache() const { |
54 return shader_program_cache_.get(); | 56 return shader_program_cache_.get(); |
55 } | 57 } |
56 NSOpenGLContext* nsgl_context() const; | 58 NSOpenGLContext* nsgl_context() const; |
57 CGLContextObj cgl_context() const { return cgl_context_; } | 59 CGLContextObj cgl_context() const { return cgl_context_; } |
58 bool is_vsync_disabled() const { return is_vsync_disabled_; } | 60 bool is_vsync_disabled() const { return is_vsync_disabled_; } |
59 int window_number() const { return window_number_; } | 61 int window_number() const { return window_number_; } |
60 | 62 |
| 63 // content::GpuDataManagerObserver implementation. |
| 64 virtual void OnGpuSwitching() OVERRIDE; |
| 65 |
61 private: | 66 private: |
62 friend class base::RefCounted<CompositingIOSurfaceContext>; | 67 friend class base::RefCounted<CompositingIOSurfaceContext>; |
63 | 68 |
64 CompositingIOSurfaceContext( | 69 CompositingIOSurfaceContext( |
65 int window_number, | 70 int window_number, |
66 NSOpenGLContext* nsgl_context, | 71 NSOpenGLContext* nsgl_context, |
67 base::ScopedTypeRef<CGLContextObj> clg_context_strong, | 72 base::ScopedTypeRef<CGLContextObj> clg_context_strong, |
68 CGLContextObj clg_context, | 73 CGLContextObj clg_context, |
69 bool is_vsync_disabled_, | 74 bool is_vsync_disabled_, |
70 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache); | 75 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache); |
71 ~CompositingIOSurfaceContext(); | 76 virtual ~CompositingIOSurfaceContext(); |
72 | 77 |
73 int window_number_; | 78 int window_number_; |
74 base::scoped_nsobject<NSOpenGLContext> nsgl_context_; | 79 base::scoped_nsobject<NSOpenGLContext> nsgl_context_; |
75 base::ScopedTypeRef<CGLContextObj> cgl_context_strong_; | 80 base::ScopedTypeRef<CGLContextObj> cgl_context_strong_; |
76 // Weak, backed by |nsgl_context_| or |cgl_context_strong_|. | 81 // Weak, backed by |nsgl_context_| or |cgl_context_strong_|. |
77 CGLContextObj cgl_context_; | 82 CGLContextObj cgl_context_; |
78 | 83 |
79 bool is_vsync_disabled_; | 84 bool is_vsync_disabled_; |
80 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache_; | 85 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache_; |
81 bool poisoned_; | 86 bool poisoned_; |
82 | 87 |
83 // The global map from window number and window ordering to | 88 // The global map from window number and window ordering to |
84 // context data. | 89 // context data. |
85 typedef std::map<int, CompositingIOSurfaceContext*> WindowMap; | 90 typedef std::map<int, CompositingIOSurfaceContext*> WindowMap; |
86 static base::LazyInstance<WindowMap> window_map_; | 91 static base::LazyInstance<WindowMap> window_map_; |
87 static WindowMap* window_map(); | 92 static WindowMap* window_map(); |
88 }; | 93 }; |
89 | 94 |
90 } // namespace content | 95 } // namespace content |
91 | 96 |
92 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_ | 97 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_ |
OLD | NEW |