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"
20 class CompositingIOSurfaceShaderPrograms;
22 class CompositingIOSurfaceContext
23 : public base::RefCounted<CompositingIOSurfaceContext> {
25 // Get or create a GL context for the specified window with the specified
26 // surface ordering. Share these GL contexts as much as possible because
27 // creating and destroying them can be expensive
28 // http://crbug.com/180463
29 static scoped_refptr<CompositingIOSurfaceContext> Get(int window_number);
31 // Mark that all the currently existing GL contexts shouldn't be returned
32 // anymore by Get, but rather, new contexts should be created. This is
33 // called as a precaution when unexpected GL errors occur.
34 static void MarkExistingContextsAsNotShareable();
36 CompositingIOSurfaceShaderPrograms* shader_program_cache() const {
37 return shader_program_cache_.get();
39 NSOpenGLContext* nsgl_context() const { return nsgl_context_; }
40 CGLContextObj cgl_context() const { return cgl_context_; }
41 bool is_vsync_disabled() const { return is_vsync_disabled_; }
42 int window_number() const { return window_number_; }
45 friend class base::RefCounted<CompositingIOSurfaceContext>;
47 CompositingIOSurfaceContext(
49 NSOpenGLContext* nsgl_context,
50 CGLContextObj clg_context,
51 bool is_vsync_disabled_,
52 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache);
53 ~CompositingIOSurfaceContext();
56 base::scoped_nsobject<NSOpenGLContext> nsgl_context_;
57 CGLContextObj cgl_context_; // weak, backed by |nsgl_context_|
58 bool is_vsync_disabled_;
59 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache_;
62 // The global map from window number and window ordering to
64 typedef std::map<int, CompositingIOSurfaceContext*> WindowMap;
65 static base::LazyInstance<WindowMap> window_map_;
66 static WindowMap* window_map();
69 } // namespace content
71 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_