Revert 268405 "Make sure that ScratchBuffer::Allocate() always r..."
[chromium-blink-merge.git] / content / browser / renderer_host / compositing_iosurface_context_mac.h
blob2904178ca396b307184cbf65cbe4e34b12801546
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>
10 #include <map>
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"
20 namespace content {
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>,
32 public content::GpuDataManagerObserver {
33 public:
34 enum {
35 // The number used to look up the context used for async readback and for
36 // initializing the IOSurface.
37 kOffscreenContextWindowNumber = -2,
38 // The number used to look up the context used by CAOpenGLLayers.
39 kCALayerContextWindowNumber = -3,
42 // Get or create a GL context for the specified window with the specified
43 // surface ordering. Share these GL contexts as much as possible because
44 // creating and destroying them can be expensive
45 // http://crbug.com/180463
46 static scoped_refptr<CompositingIOSurfaceContext> Get(int window_number);
48 // Mark that all the GL contexts in the same sharegroup as this context as
49 // invalid, so they shouldn't be returned anymore by Get, but rather, new
50 // contexts should be created. This is called as a precaution when unexpected
51 // GL errors occur.
52 void PoisonContextAndSharegroup();
53 bool HasBeenPoisoned() const { return poisoned_; }
55 CompositingIOSurfaceShaderPrograms* shader_program_cache() const {
56 return shader_program_cache_.get();
58 NSOpenGLContext* nsgl_context() const;
59 CGLContextObj cgl_context() const { return cgl_context_; }
60 bool is_vsync_disabled() const { return is_vsync_disabled_; }
61 int window_number() const { return window_number_; }
63 // content::GpuDataManagerObserver implementation.
64 virtual void OnGpuSwitching() OVERRIDE;
66 private:
67 friend class base::RefCounted<CompositingIOSurfaceContext>;
69 CompositingIOSurfaceContext(
70 int window_number,
71 NSOpenGLContext* nsgl_context,
72 base::ScopedTypeRef<CGLContextObj> clg_context_strong,
73 CGLContextObj clg_context,
74 bool is_vsync_disabled_,
75 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache);
76 virtual ~CompositingIOSurfaceContext();
78 int window_number_;
79 base::scoped_nsobject<NSOpenGLContext> nsgl_context_;
80 base::ScopedTypeRef<CGLContextObj> cgl_context_strong_;
81 // Weak, backed by |nsgl_context_| or |cgl_context_strong_|.
82 CGLContextObj cgl_context_;
84 bool is_vsync_disabled_;
85 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache_;
86 bool poisoned_;
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();
95 } // namespace content
97 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_