Upstream version 5.34.104.0
[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 #include "content/browser/renderer_host/display_link_mac.h"
18 #include "ui/gl/scoped_cgl.h"
19
20 namespace content {
21
22 enum CoreAnimationStatus {
23   CORE_ANIMATION_DISABLED,
24   CORE_ANIMATION_ENABLED,
25 };
26 CoreAnimationStatus GetCoreAnimationStatus();
27
28 class CompositingIOSurfaceShaderPrograms;
29
30 class CompositingIOSurfaceContext
31     : public base::RefCounted<CompositingIOSurfaceContext> {
32  public:
33   enum { kOffscreenContextWindowNumber = -2 };
34
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);
40
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();
45
46   CompositingIOSurfaceShaderPrograms* shader_program_cache() const {
47     return shader_program_cache_.get();
48   }
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_; }
53
54   bool IsVendorIntel();
55
56   DisplayLinkMac* display_link() { return display_link_; }
57
58  private:
59   friend class base::RefCounted<CompositingIOSurfaceContext>;
60
61   CompositingIOSurfaceContext(
62       int window_number,
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();
70
71   int window_number_;
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_;
76
77   bool is_vsync_disabled_;
78   scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache_;
79   bool can_be_shared_;
80
81   bool initialized_is_intel_;
82   bool is_intel_;
83   GLint screen_;
84
85   // Display link for getting vsync info.
86   scoped_refptr<DisplayLinkMac> display_link_;
87
88   // The global map from window number and window ordering to
89   // context data.
90   typedef std::map<int, CompositingIOSurfaceContext*> WindowMap;
91   static base::LazyInstance<WindowMap> window_map_;
92   static WindowMap* window_map();
93 };
94
95 }  // namespace content
96
97 #endif  // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_