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 enum { kOffscreenContextWindowNumber = -2 }; 26 27 // Get or create a GL context for the specified window with the specified 28 // surface ordering. Share these GL contexts as much as possible because 29 // creating and destroying them can be expensive 30 // http://crbug.com/180463 31 static scoped_refptr<CompositingIOSurfaceContext> Get(int window_number); 32 33 // Mark that all the currently existing GL contexts shouldn't be returned 34 // anymore by Get, but rather, new contexts should be created. This is 35 // called as a precaution when unexpected GL errors occur. 36 static void MarkExistingContextsAsNotShareable(); 37 38 CompositingIOSurfaceShaderPrograms* shader_program_cache() const { 39 return shader_program_cache_.get(); 40 } 41 NSOpenGLContext* nsgl_context() const { return nsgl_context_; } 42 CGLContextObj cgl_context() const { return cgl_context_; } 43 bool is_vsync_disabled() const { return is_vsync_disabled_; } 44 int window_number() const { return window_number_; } 45 46 bool IsVendorIntel(); 47 48 private: 49 friend class base::RefCounted<CompositingIOSurfaceContext>; 50 51 CompositingIOSurfaceContext( 52 int window_number, 53 NSOpenGLContext* nsgl_context, 54 CGLContextObj clg_context, 55 bool is_vsync_disabled_, 56 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache); 57 ~CompositingIOSurfaceContext(); 58 59 int window_number_; 60 base::scoped_nsobject<NSOpenGLContext> nsgl_context_; 61 CGLContextObj cgl_context_; // weak, backed by |nsgl_context_| 62 bool is_vsync_disabled_; 63 scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache_; 64 bool can_be_shared_; 65 66 bool initialized_is_intel_; 67 bool is_intel_; 68 GLint screen_; 69 70 // The global map from window number and window ordering to 71 // context data. 72 typedef std::map<int, CompositingIOSurfaceContext*> WindowMap; 73 static base::LazyInstance<WindowMap> window_map_; 74 static WindowMap* window_map(); 75 }; 76 77 } // namespace content 78 79 #endif // CONTENT_BROWSER_RENDERER_HOST_COMPOSITING_IOSURFACE_CONTEXT_MAC_H_ 80