1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/gfx/skia/trunk/src/gpu/gl/GrGLContext.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,110 @@ 1.4 +/* 1.5 + * Copyright 2013 Google Inc. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license that can be 1.8 + * found in the LICENSE file. 1.9 + */ 1.10 + 1.11 + 1.12 +#ifndef GrGLContext_DEFINED 1.13 +#define GrGLContext_DEFINED 1.14 + 1.15 +#include "gl/GrGLExtensions.h" 1.16 +#include "gl/GrGLInterface.h" 1.17 +#include "GrGLCaps.h" 1.18 +#include "GrGLSL.h" 1.19 +#include "GrGLUtil.h" 1.20 + 1.21 +#include "SkString.h" 1.22 + 1.23 +/** 1.24 + * Encapsulates information about an OpenGL context including the OpenGL 1.25 + * version, the GrGLStandard type of the context, and GLSL version. 1.26 + */ 1.27 +class GrGLContextInfo { 1.28 +public: 1.29 + /** 1.30 + * Default constructor 1.31 + */ 1.32 + GrGLContextInfo() { 1.33 + fGLCaps.reset(SkNEW(GrGLCaps)); 1.34 + this->reset(); 1.35 + } 1.36 + 1.37 + GrGLContextInfo(const GrGLContextInfo& that) { 1.38 + fGLCaps.reset(SkNEW(GrGLCaps)); 1.39 + *this = that; 1.40 + } 1.41 + 1.42 + GrGLContextInfo& operator= (const GrGLContextInfo&); 1.43 + 1.44 + /** 1.45 + * Initializes a GrGLContextInfo from a GrGLInterface and the currently 1.46 + * bound OpenGL context accessible by the GrGLInterface. 1.47 + */ 1.48 + bool initialize(const GrGLInterface* interface); 1.49 + bool isInitialized() const; 1.50 + 1.51 + GrGLStandard standard() const { return fInterface->fStandard; } 1.52 + GrGLVersion version() const { return fGLVersion; } 1.53 + GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; } 1.54 + GrGLVendor vendor() const { return fVendor; } 1.55 + GrGLRenderer renderer() const { return fRenderer; } 1.56 + /** Is this a mesa-based driver. Does not mean it is the osmesa software rasterizer. */ 1.57 + bool isMesa() const { return fIsMesa; } 1.58 + /** Are we running inside Chromium (using the command buffer)? We make some different tradeoffs 1.59 + about what errors to check for because queries are synchronous. We should probably expose 1.60 + this as an option for clients other than Chromium. */ 1.61 + bool isChromium() const { return fIsChromium; } 1.62 + const GrGLCaps* caps() const { return fGLCaps.get(); } 1.63 + GrGLCaps* caps() { return fGLCaps; } 1.64 + bool hasExtension(const char* ext) const { 1.65 + if (!this->isInitialized()) { 1.66 + return false; 1.67 + } 1.68 + return fInterface->hasExtension(ext); 1.69 + } 1.70 + 1.71 + /** 1.72 + * Reset the information 1.73 + */ 1.74 + void reset(); 1.75 + 1.76 +protected: 1.77 + SkAutoTUnref<const GrGLInterface> fInterface; 1.78 + GrGLVersion fGLVersion; 1.79 + GrGLSLGeneration fGLSLGeneration; 1.80 + GrGLVendor fVendor; 1.81 + GrGLRenderer fRenderer; 1.82 + bool fIsMesa; 1.83 + bool fIsChromium; 1.84 + SkAutoTUnref<GrGLCaps> fGLCaps; 1.85 +}; 1.86 + 1.87 +/** 1.88 + * Extension of GrGLContextInfo that also provides access to GrGLInterface. 1.89 + */ 1.90 +class GrGLContext : public GrGLContextInfo { 1.91 +public: 1.92 + /** 1.93 + * Creates a GrGLContext from a GrGLInterface and the currently 1.94 + * bound OpenGL context accessible by the GrGLInterface. 1.95 + */ 1.96 + explicit GrGLContext(const GrGLInterface* interface) { 1.97 + this->initialize(interface); 1.98 + } 1.99 + 1.100 + GrGLContext(const GrGLContext& that) : INHERITED(that) {} 1.101 + 1.102 + GrGLContext& operator= (const GrGLContext& that) { 1.103 + this->INHERITED::operator=(that); 1.104 + return *this; 1.105 + } 1.106 + 1.107 + const GrGLInterface* interface() const { return fInterface.get(); } 1.108 + 1.109 +private: 1.110 + typedef GrGLContextInfo INHERITED; 1.111 +}; 1.112 + 1.113 +#endif