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/public/browser/gpu_data_manager_observer.h"
18 #include "ui/gl/scoped_cgl.h"
22 class CompositingIOSurfaceContext
23 : public base::RefCounted
<CompositingIOSurfaceContext
>,
24 public content::GpuDataManagerObserver
{
27 // The number used to look up the context used for async readback and for
28 // initializing the IOSurface.
29 kOffscreenContextWindowNumber
= -2,
30 // The number used to look up the context used by CAOpenGLLayers.
31 kCALayerContextWindowNumber
= -3,
34 // Get or create a GL context for the specified window with the specified
35 // surface ordering. Share these GL contexts as much as possible because
36 // creating and destroying them can be expensive
37 // http://crbug.com/180463
38 static scoped_refptr
<CompositingIOSurfaceContext
> Get(int window_number
);
40 // Mark that all the GL contexts in the same sharegroup as this context as
41 // invalid, so they shouldn't be returned anymore by Get, but rather, new
42 // contexts should be created. This is called as a precaution when unexpected
44 void PoisonContextAndSharegroup();
45 bool HasBeenPoisoned() const { return poisoned_
; }
47 CGLContextObj
cgl_context() const { return cgl_context_
; }
48 int window_number() const { return window_number_
; }
50 // content::GpuDataManagerObserver implementation.
51 virtual void OnGpuSwitching() OVERRIDE
;
54 friend class base::RefCounted
<CompositingIOSurfaceContext
>;
56 CompositingIOSurfaceContext(
58 base::ScopedTypeRef
<CGLContextObj
> clg_context_strong
,
59 CGLContextObj clg_context
);
60 virtual ~CompositingIOSurfaceContext();
63 base::ScopedTypeRef
<CGLContextObj
> cgl_context_strong_
;
64 // Weak, backed by |cgl_context_strong_|.
65 CGLContextObj cgl_context_
;
69 // The global map from window number and window ordering to
71 typedef std::map
<int, CompositingIOSurfaceContext
*> WindowMap
;
72 static base::LazyInstance
<WindowMap
> window_map_
;
73 static WindowMap
* window_map();
76 } // namespace content
78 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_