| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 | 8 |
| 9 #ifndef GrGLContext_DEFINED | 9 #ifndef GrGLContext_DEFINED |
| 10 #define GrGLContext_DEFINED | 10 #define GrGLContext_DEFINED |
| 11 | 11 |
| 12 #include "gl/GrGLExtensions.h" | 12 #include "gl/GrGLExtensions.h" |
| 13 #include "gl/GrGLInterface.h" | 13 #include "gl/GrGLInterface.h" |
| 14 #include "GrGLCaps.h" | 14 #include "GrGLCaps.h" |
| 15 #include "GrGLSL.h" | 15 #include "GrGLSL.h" |
| 16 #include "GrGLUtil.h" | 16 #include "GrGLUtil.h" |
| 17 | 17 |
| 18 #include "SkString.h" | 18 #include "SkString.h" |
| 19 | 19 |
| 20 /** | 20 /** |
| 21 * Encapsulates information about an OpenGL context including the OpenGL | 21 * Encapsulates information about an OpenGL context including the OpenGL |
| 22 * version, the GrGLStandard type of the context, and GLSL version. | 22 * version, the GrGLStandard type of the context, and GLSL version. |
| 23 */ | 23 */ |
| 24 class GrGLContextInfo { | 24 class GrGLContextInfo : public SkNoncopyable { |
| 25 public: | 25 public: |
| 26 /** | |
| 27 * Default constructor | |
| 28 */ | |
| 29 GrGLContextInfo() { | |
| 30 fGLCaps.reset(SkNEW(GrGLCaps)); | |
| 31 this->reset(); | |
| 32 } | |
| 33 | |
| 34 GrGLContextInfo(const GrGLContextInfo& that) { | |
| 35 fGLCaps.reset(SkNEW(GrGLCaps)); | |
| 36 *this = that; | |
| 37 } | |
| 38 | |
| 39 GrGLContextInfo& operator= (const GrGLContextInfo&); | |
| 40 | |
| 41 /** | |
| 42 * Initializes a GrGLContextInfo from a GrGLInterface and the currently | |
| 43 * bound OpenGL context accessible by the GrGLInterface. | |
| 44 */ | |
| 45 bool initialize(const GrGLInterface* interface); | |
| 46 bool isInitialized() const; | |
| 47 | |
| 48 GrGLStandard standard() const { return fInterface->fStandard; } | 26 GrGLStandard standard() const { return fInterface->fStandard; } |
| 49 GrGLVersion version() const { return fGLVersion; } | 27 GrGLVersion version() const { return fGLVersion; } |
| 50 GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; } | 28 GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; } |
| 51 GrGLVendor vendor() const { return fVendor; } | 29 GrGLVendor vendor() const { return fVendor; } |
| 52 GrGLRenderer renderer() const { return fRenderer; } | 30 GrGLRenderer renderer() const { return fRenderer; } |
| 53 /** Is this a mesa-based driver. Does not mean it is the osmesa software ras
terizer. */ | 31 /** Is this a mesa-based driver. Does not mean it is the osmesa software ras
terizer. */ |
| 54 bool isMesa() const { return fIsMesa; } | 32 bool isMesa() const { return fIsMesa; } |
| 55 /** Are we running inside Chromium (using the command buffer)? We make some
different tradeoffs | 33 /** Are we running inside Chromium (using the command buffer)? We make some
different tradeoffs |
| 56 about what errors to check for because queries are synchronous. We shoul
d probably expose | 34 about what errors to check for because queries are synchronous. We shoul
d probably expose |
| 57 this as an option for clients other than Chromium. */ | 35 this as an option for clients other than Chromium. */ |
| 58 bool isChromium() const { return fIsChromium; } | 36 bool isChromium() const { return fIsChromium; } |
| 59 const GrGLCaps* caps() const { return fGLCaps.get(); } | 37 const GrGLCaps* caps() const { return fGLCaps.get(); } |
| 60 GrGLCaps* caps() { return fGLCaps; } | 38 GrGLCaps* caps() { return fGLCaps; } |
| 61 bool hasExtension(const char* ext) const { | 39 bool hasExtension(const char* ext) const { |
| 62 if (!this->isInitialized()) { | |
| 63 return false; | |
| 64 } | |
| 65 return fInterface->hasExtension(ext); | 40 return fInterface->hasExtension(ext); |
| 66 } | 41 } |
| 67 | 42 |
| 68 const GrGLExtensions& extensions() const { return fInterface->fExtensions; } | 43 const GrGLExtensions& extensions() const { return fInterface->fExtensions; } |
| 69 | 44 |
| 70 /** | 45 protected: |
| 71 * Reset the information | 46 struct ConstructorArgs { |
| 72 */ | 47 const GrGLInterface* fInterface; |
| 73 void reset(); | 48 GrGLVersion fGLVersion; |
| 49 GrGLSLGeneration fGLSLGeneration; |
| 50 GrGLVendor fVendor; |
| 51 GrGLRenderer fRenderer; |
| 52 bool fIsMesa; |
| 53 bool fIsChromium; |
| 54 }; |
| 74 | 55 |
| 75 protected: | 56 GrGLContextInfo(const ConstructorArgs& args); |
| 57 |
| 76 SkAutoTUnref<const GrGLInterface> fInterface; | 58 SkAutoTUnref<const GrGLInterface> fInterface; |
| 77 GrGLVersion fGLVersion; | 59 GrGLVersion fGLVersion; |
| 78 GrGLSLGeneration fGLSLGeneration; | 60 GrGLSLGeneration fGLSLGeneration; |
| 79 GrGLVendor fVendor; | 61 GrGLVendor fVendor; |
| 80 GrGLRenderer fRenderer; | 62 GrGLRenderer fRenderer; |
| 81 bool fIsMesa; | 63 bool fIsMesa; |
| 82 bool fIsChromium; | 64 bool fIsChromium; |
| 83 SkAutoTUnref<GrGLCaps> fGLCaps; | 65 SkAutoTUnref<GrGLCaps> fGLCaps; |
| 84 }; | 66 }; |
| 85 | 67 |
| 86 /** | 68 /** |
| 87 * Extension of GrGLContextInfo that also provides access to GrGLInterface. | 69 * Extension of GrGLContextInfo that also provides access to GrGLInterface. |
| 88 */ | 70 */ |
| 89 class GrGLContext : public GrGLContextInfo { | 71 class GrGLContext : public GrGLContextInfo { |
| 90 public: | 72 public: |
| 91 /** | 73 /** |
| 92 * Creates a GrGLContext from a GrGLInterface and the currently | 74 * Creates a GrGLContext from a GrGLInterface and the currently |
| 93 * bound OpenGL context accessible by the GrGLInterface. | 75 * bound OpenGL context accessible by the GrGLInterface. |
| 94 */ | 76 */ |
| 95 explicit GrGLContext(const GrGLInterface* interface) { | 77 static GrGLContext* Create(const GrGLInterface* interface); |
| 96 this->initialize(interface); | |
| 97 } | |
| 98 | 78 |
| 99 GrGLContext(const GrGLContext& that) : INHERITED(that) {} | 79 const GrGLInterface* interface() const { return fInterface; } |
| 100 | |
| 101 GrGLContext& operator= (const GrGLContext& that) { | |
| 102 this->INHERITED::operator=(that); | |
| 103 return *this; | |
| 104 } | |
| 105 | |
| 106 const GrGLInterface* interface() const { return fInterface.get(); } | |
| 107 | 80 |
| 108 private: | 81 private: |
| 82 GrGLContext(const ConstructorArgs& args) : INHERITED(args) {} |
| 83 |
| 109 typedef GrGLContextInfo INHERITED; | 84 typedef GrGLContextInfo INHERITED; |
| 110 }; | 85 }; |
| 111 | 86 |
| 112 #endif | 87 #endif |
| OLD | NEW |