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