#include "base/mac/scoped_nsobject.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
+#include "content/public/browser/gpu_data_manager_observer.h"
+#include "ui/gl/scoped_cgl.h"
namespace content {
-class CompositingIOSurfaceShaderPrograms;
-
class CompositingIOSurfaceContext
- : public base::RefCounted<CompositingIOSurfaceContext> {
+ : public base::RefCounted<CompositingIOSurfaceContext>,
+ public content::GpuDataManagerObserver {
public:
+ enum {
+ // The number used to look up the context used for async readback and for
+ // initializing the IOSurface.
+ kOffscreenContextWindowNumber = -2,
+ // The number used to look up the context used by CAOpenGLLayers.
+ kCALayerContextWindowNumber = -3,
+ };
+
// Get or create a GL context for the specified window with the specified
// surface ordering. Share these GL contexts as much as possible because
// creating and destroying them can be expensive
// http://crbug.com/180463
static scoped_refptr<CompositingIOSurfaceContext> Get(int window_number);
- // Mark that all the currently existing GL contexts shouldn't be returned
- // anymore by Get, but rather, new contexts should be created. This is
- // called as a precaution when unexpected GL errors occur.
- static void MarkExistingContextsAsNotShareable();
+ // Mark that all the GL contexts in the same sharegroup as this context as
+ // invalid, so they shouldn't be returned anymore by Get, but rather, new
+ // contexts should be created. This is called as a precaution when unexpected
+ // GL errors occur.
+ void PoisonContextAndSharegroup();
+ bool HasBeenPoisoned() const { return poisoned_; }
- CompositingIOSurfaceShaderPrograms* shader_program_cache() const {
- return shader_program_cache_.get();
- }
- NSOpenGLContext* nsgl_context() const { return nsgl_context_; }
CGLContextObj cgl_context() const { return cgl_context_; }
- bool is_vsync_disabled() const { return is_vsync_disabled_; }
int window_number() const { return window_number_; }
+ // content::GpuDataManagerObserver implementation.
+ virtual void OnGpuSwitching() OVERRIDE;
+
private:
friend class base::RefCounted<CompositingIOSurfaceContext>;
CompositingIOSurfaceContext(
int window_number,
- NSOpenGLContext* nsgl_context,
- CGLContextObj clg_context,
- bool is_vsync_disabled_,
- scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache);
- ~CompositingIOSurfaceContext();
+ base::ScopedTypeRef<CGLContextObj> clg_context_strong,
+ CGLContextObj clg_context);
+ virtual ~CompositingIOSurfaceContext();
int window_number_;
- base::scoped_nsobject<NSOpenGLContext> nsgl_context_;
- CGLContextObj cgl_context_; // weak, backed by |nsgl_context_|
- bool is_vsync_disabled_;
- scoped_ptr<CompositingIOSurfaceShaderPrograms> shader_program_cache_;
- bool can_be_shared_;
+ base::ScopedTypeRef<CGLContextObj> cgl_context_strong_;
+ // Weak, backed by |cgl_context_strong_|.
+ CGLContextObj cgl_context_;
+
+ bool poisoned_;
// The global map from window number and window ordering to
// context data.