michael@0: /* michael@0: * Copyright 2013 Google Inc. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license that can be michael@0: * found in the LICENSE file. michael@0: */ michael@0: michael@0: michael@0: #ifndef GrGLContext_DEFINED michael@0: #define GrGLContext_DEFINED michael@0: michael@0: #include "gl/GrGLExtensions.h" michael@0: #include "gl/GrGLInterface.h" michael@0: #include "GrGLCaps.h" michael@0: #include "GrGLSL.h" michael@0: #include "GrGLUtil.h" michael@0: michael@0: #include "SkString.h" michael@0: michael@0: /** michael@0: * Encapsulates information about an OpenGL context including the OpenGL michael@0: * version, the GrGLStandard type of the context, and GLSL version. michael@0: */ michael@0: class GrGLContextInfo { michael@0: public: michael@0: /** michael@0: * Default constructor michael@0: */ michael@0: GrGLContextInfo() { michael@0: fGLCaps.reset(SkNEW(GrGLCaps)); michael@0: this->reset(); michael@0: } michael@0: michael@0: GrGLContextInfo(const GrGLContextInfo& that) { michael@0: fGLCaps.reset(SkNEW(GrGLCaps)); michael@0: *this = that; michael@0: } michael@0: michael@0: GrGLContextInfo& operator= (const GrGLContextInfo&); michael@0: michael@0: /** michael@0: * Initializes a GrGLContextInfo from a GrGLInterface and the currently michael@0: * bound OpenGL context accessible by the GrGLInterface. michael@0: */ michael@0: bool initialize(const GrGLInterface* interface); michael@0: bool isInitialized() const; michael@0: michael@0: GrGLStandard standard() const { return fInterface->fStandard; } michael@0: GrGLVersion version() const { return fGLVersion; } michael@0: GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; } michael@0: GrGLVendor vendor() const { return fVendor; } michael@0: GrGLRenderer renderer() const { return fRenderer; } michael@0: /** Is this a mesa-based driver. Does not mean it is the osmesa software rasterizer. */ michael@0: bool isMesa() const { return fIsMesa; } michael@0: /** Are we running inside Chromium (using the command buffer)? We make some different tradeoffs michael@0: about what errors to check for because queries are synchronous. We should probably expose michael@0: this as an option for clients other than Chromium. */ michael@0: bool isChromium() const { return fIsChromium; } michael@0: const GrGLCaps* caps() const { return fGLCaps.get(); } michael@0: GrGLCaps* caps() { return fGLCaps; } michael@0: bool hasExtension(const char* ext) const { michael@0: if (!this->isInitialized()) { michael@0: return false; michael@0: } michael@0: return fInterface->hasExtension(ext); michael@0: } michael@0: michael@0: /** michael@0: * Reset the information michael@0: */ michael@0: void reset(); michael@0: michael@0: protected: michael@0: SkAutoTUnref fInterface; michael@0: GrGLVersion fGLVersion; michael@0: GrGLSLGeneration fGLSLGeneration; michael@0: GrGLVendor fVendor; michael@0: GrGLRenderer fRenderer; michael@0: bool fIsMesa; michael@0: bool fIsChromium; michael@0: SkAutoTUnref fGLCaps; michael@0: }; michael@0: michael@0: /** michael@0: * Extension of GrGLContextInfo that also provides access to GrGLInterface. michael@0: */ michael@0: class GrGLContext : public GrGLContextInfo { michael@0: public: michael@0: /** michael@0: * Creates a GrGLContext from a GrGLInterface and the currently michael@0: * bound OpenGL context accessible by the GrGLInterface. michael@0: */ michael@0: explicit GrGLContext(const GrGLInterface* interface) { michael@0: this->initialize(interface); michael@0: } michael@0: michael@0: GrGLContext(const GrGLContext& that) : INHERITED(that) {} michael@0: michael@0: GrGLContext& operator= (const GrGLContext& that) { michael@0: this->INHERITED::operator=(that); michael@0: return *this; michael@0: } michael@0: michael@0: const GrGLInterface* interface() const { return fInterface.get(); } michael@0: michael@0: private: michael@0: typedef GrGLContextInfo INHERITED; michael@0: }; michael@0: michael@0: #endif