OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_ | |
7 | |
8 #import <AppKit/NSOpenGL.h> | |
9 #include <OpenGL/OpenGL.h> | |
10 #include <map> | |
11 | |
12 #include "base/basictypes.h" | |
13 #include "base/lazy_instance.h" | |
14 #include "base/mac/scoped_nsobject.h" | |
15 #include "base/memory/ref_counted.h" | |
16 #include "base/memory/scoped_ptr.h" | |
17 #include "content/public/browser/gpu_data_manager_observer.h" | |
18 #include "ui/gl/scoped_cgl.h" | |
19 | |
20 namespace content { | |
21 | |
22 class CompositingIOSurfaceContext | |
23 : public base::RefCounted<CompositingIOSurfaceContext>, | |
24 public content::GpuDataManagerObserver { | |
25 public: | |
26 enum { | |
27 // The number used to look up the context used for async readback and for | |
28 // initializing the IOSurface. | |
29 kOffscreenContextWindowNumber = -2, | |
30 // The number used to look up the context used by CAOpenGLLayers. | |
31 kCALayerContextWindowNumber = -3, | |
32 }; | |
33 | |
34 // Get or create a GL context for the specified window with the specified | |
35 // surface ordering. Share these GL contexts as much as possible because | |
36 // creating and destroying them can be expensive | |
37 // http://crbug.com/180463 | |
38 static scoped_refptr<CompositingIOSurfaceContext> Get(int window_number); | |
39 | |
40 // Mark that all the GL contexts in the same sharegroup as this context as | |
41 // invalid, so they shouldn't be returned anymore by Get, but rather, new | |
42 // contexts should be created. This is called as a precaution when unexpected | |
43 // GL errors occur. | |
44 void PoisonContextAndSharegroup(); | |
45 bool HasBeenPoisoned() const { return poisoned_; } | |
46 | |
47 CGLContextObj cgl_context() const { return cgl_context_; } | |
48 int window_number() const { return window_number_; } | |
49 | |
50 // content::GpuDataManagerObserver implementation. | |
51 virtual void OnGpuSwitching() OVERRIDE; | |
52 | |
53 private: | |
54 friend class base::RefCounted<CompositingIOSurfaceContext>; | |
55 | |
56 CompositingIOSurfaceContext( | |
57 int window_number, | |
58 base::ScopedTypeRef<CGLContextObj> clg_context_strong, | |
59 CGLContextObj clg_context); | |
60 virtual ~CompositingIOSurfaceContext(); | |
61 | |
62 int window_number_; | |
63 base::ScopedTypeRef<CGLContextObj> cgl_context_strong_; | |
64 // Weak, backed by |cgl_context_strong_|. | |
65 CGLContextObj cgl_context_; | |
66 | |
67 bool poisoned_; | |
68 | |
69 // The global map from window number and window ordering to | |
70 // context data. | |
71 typedef std::map<int, CompositingIOSurfaceContext*> WindowMap; | |
72 static base::LazyInstance<WindowMap> window_map_; | |
73 static WindowMap* window_map(); | |
74 }; | |
75 | |
76 } // namespace content | |
77 | |
78 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_ | |
OLD | NEW |