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.
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_
6 #define CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_
8 #import <AppKit/NSOpenGL.h>
9 #include <OpenGL/OpenGL.h>
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/browser/renderer_host/display_link_mac.h"
18 #include "ui/gl/scoped_cgl.h"
22 enum CoreAnimationStatus {
23 CORE_ANIMATION_DISABLED,
24 CORE_ANIMATION_ENABLED,
26 CoreAnimationStatus GetCoreAnimationStatus();
28 class CompositingIOSurfaceShaderPrograms;
30 class CompositingIOSurfaceContext
31 : public base::RefCounted<CompositingIOSurfaceContext> {
33 enum { kOffscreenContextWindowNumber = -2 };
35 // Get or create a GL context for the specified window with the specified
36 // surface ordering. Share these GL contexts as much as possible because
37 // creating and destroying them can be expensive
38 // http://crbug.com/180463
39 static scoped_refptr<CompositingIOSurfaceContext> Get(int window_number);
41 // Mark that all the currently existing GL contexts shouldn't be returned
42 // anymore by Get, but rather, new contexts should be created. This is
43 // called as a precaution when unexpected GL errors occur.
44 static void MarkExistingContextsAsNotShareable();
46 CompositingIOSurfaceShaderPrograms* shader_program_cache() const {
47 return shader_program_cache_.get();
49 NSOpenGLContext* nsgl_context() const;
50 CGLContextObj cgl_context() const { return cgl_context_; }
51 bool is_vsync_disabled() const { return is_vsync_disabled_; }
52 int window_number() const { return window_number_; }
56 DisplayLinkMac* display_link() { return display_link_; }
59 friend class base::RefCounted<CompositingIOSurfaceContext>;
61 CompositingIOSurfaceContext(
63 NSOpenGLContext* nsgl_context,
64 base::ScopedTypeRef<CGLContextObj> clg_context_strong,
65 CGLContextObj clg_context,
66 bool is_vsync_disabled_,
67 scoped_refptr<DisplayLinkMac> display_link,
68 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache);
69 ~CompositingIOSurfaceContext();
72 base::scoped_nsobject<NSOpenGLContext> nsgl_context_;
73 base::ScopedTypeRef<CGLContextObj> cgl_context_strong_;
74 // Weak, backed by |nsgl_context_| or |cgl_context_strong_|.
75 CGLContextObj cgl_context_;
77 bool is_vsync_disabled_;
78 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache_;
81 bool initialized_is_intel_;
85 // Display link for getting vsync info.
86 scoped_refptr<DisplayLinkMac> display_link_;
88 // The global map from window number and window ordering to
90 typedef std::map<int, CompositingIOSurfaceContext*> WindowMap;
91 static base::LazyInstance<WindowMap> window_map_;
92 static WindowMap* window_map();
95 } // namespace content
97 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_