- add sources.
[platform/framework/web/crosswalk.git] / src / content / browser / renderer_host / compositing_iosurface_context_mac.h
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
18 namespace content {
19
20 class CompositingIOSurfaceShaderPrograms;
21
22 class CompositingIOSurfaceContext
23     : public base::RefCounted<CompositingIOSurfaceContext> {
24  public:
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);
30
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();
35
36   CompositingIOSurfaceShaderPrograms* shader_program_cache() const {
37     return shader_program_cache_.get();
38   }
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_; }
43
44  private:
45   friend class base::RefCounted<CompositingIOSurfaceContext>;
46
47   CompositingIOSurfaceContext(
48       int window_number,
49       NSOpenGLContext* nsgl_context,
50       CGLContextObj clg_context,
51       bool is_vsync_disabled_,
52       scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache);
53   ~CompositingIOSurfaceContext();
54
55   int window_number_;
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_;
60   bool can_be_shared_;
61
62   // The global map from window number and window ordering to
63   // context data.
64   typedef std::map<int, CompositingIOSurfaceContext*> WindowMap;
65   static base::LazyInstance<WindowMap> window_map_;
66   static WindowMap* window_map();
67 };
68
69 }  // namespace content
70
71 #endif  // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_