robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2013 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
| 8 | |
| 9 | #ifndef GrGLContext_DEFINED |
| 10 | #define GrGLContext_DEFINED |
| 11 | |
| 12 | #include "gl/GrGLExtensions.h" |
| 13 | #include "gl/GrGLInterface.h" |
| 14 | #include "GrGLCaps.h" |
| 15 | #include "GrGLSL.h" |
| 16 | #include "GrGLUtil.h" |
| 17 | |
| 18 | #include "SkString.h" |
| 19 | |
| 20 | /** |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 21 | * Encapsulates information about an OpenGL context including the OpenGL |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 22 | * version, the GrGLBinding type of the context, and GLSL version. |
| 23 | */ |
| 24 | class GrGLContextInfo { |
| 25 | public: |
| 26 | /** |
| 27 | * Default constructor |
| 28 | */ |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 29 | GrGLContextInfo() { |
| 30 | fGLCaps.reset(SkNEW(GrGLCaps)); |
| 31 | this->reset(); |
| 32 | } |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Copies a GrGLContextInfo |
| 36 | */ |
| 37 | GrGLContextInfo& operator= (const GrGLContextInfo& ctxInfo); |
skia.committer@gmail.com | 631cdcb | 2013-03-01 12:12:55 +0000 | [diff] [blame] | 38 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 39 | /** |
| 40 | * Initializes a GrGLContextInfo from a GrGLInterface and the currently |
| 41 | * bound OpenGL context accessible by the GrGLInterface. |
| 42 | */ |
| 43 | bool initialize(const GrGLInterface* interface); |
| 44 | bool isInitialized() const; |
| 45 | |
| 46 | GrGLBinding binding() const { return fBindingInUse; } |
| 47 | GrGLVersion version() const { return fGLVersion; } |
| 48 | GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; } |
| 49 | GrGLVendor vendor() const { return fVendor; } |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 50 | GrGLRenderer renderer() const { return fRenderer; } |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 51 | /** Is this a mesa-based driver. Does not mean it is the osmesa software rasterizer. */ |
| 52 | bool isMesa() const { return fIsMesa; } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 53 | const GrGLCaps* caps() const { return fGLCaps.get(); } |
| 54 | GrGLCaps* caps() { return fGLCaps; } |
bsalomon@google.com | 00142c4 | 2013-05-02 19:42:54 +0000 | [diff] [blame] | 55 | const GrGLExtensions& extensions() const { return fExtensions; } |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 56 | |
| 57 | /** |
bsalomon@google.com | 00142c4 | 2013-05-02 19:42:54 +0000 | [diff] [blame] | 58 | * Shortcut for extensions().has(ext); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 59 | */ |
| 60 | bool hasExtension(const char* ext) const { |
| 61 | if (!this->isInitialized()) { |
| 62 | return false; |
| 63 | } |
| 64 | return fExtensions.has(ext); |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Reset the information |
| 69 | */ |
| 70 | void reset(); |
| 71 | |
| 72 | private: |
| 73 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 74 | GrGLBinding fBindingInUse; |
| 75 | GrGLVersion fGLVersion; |
| 76 | GrGLSLGeneration fGLSLGeneration; |
| 77 | GrGLVendor fVendor; |
commit-bot@chromium.org | 0694ea7 | 2013-09-18 13:00:28 +0000 | [diff] [blame] | 78 | GrGLRenderer fRenderer; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 79 | GrGLExtensions fExtensions; |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 80 | bool fIsMesa; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 81 | SkAutoTUnref<GrGLCaps> fGLCaps; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 82 | }; |
| 83 | |
| 84 | /** |
| 85 | * Encapsulates the GrGLInterface used to make GL calls plus information |
| 86 | * about the context (via GrGLContextInfo). |
| 87 | */ |
| 88 | class GrGLContext { |
| 89 | public: |
| 90 | /** |
| 91 | * Default constructor |
| 92 | */ |
| 93 | GrGLContext() { this->reset(); } |
| 94 | |
| 95 | /** |
| 96 | * Creates a GrGLContext from a GrGLInterface and the currently |
| 97 | * bound OpenGL context accessible by the GrGLInterface. |
| 98 | */ |
| 99 | explicit GrGLContext(const GrGLInterface* interface); |
| 100 | |
| 101 | /** |
| 102 | * Copies a GrGLContext |
| 103 | */ |
| 104 | GrGLContext(const GrGLContext& ctx); |
| 105 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame] | 106 | ~GrGLContext() { SkSafeUnref(fInterface); } |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 107 | |
| 108 | /** |
| 109 | * Copies a GrGLContext |
| 110 | */ |
| 111 | GrGLContext& operator= (const GrGLContext& ctx); |
| 112 | |
| 113 | /** |
| 114 | * Initializes a GrGLContext from a GrGLInterface and the currently |
| 115 | * bound OpenGL context accessible by the GrGLInterface. |
| 116 | */ |
| 117 | bool initialize(const GrGLInterface* interface); |
| 118 | bool isInitialized() const { return fInfo.isInitialized(); } |
| 119 | |
| 120 | const GrGLInterface* interface() const { return fInterface; } |
| 121 | const GrGLContextInfo& info() const { return fInfo; } |
| 122 | GrGLContextInfo& info() { return fInfo; } |
| 123 | |
| 124 | private: |
| 125 | void reset(); |
| 126 | |
| 127 | const GrGLInterface* fInterface; |
| 128 | GrGLContextInfo fInfo; |
| 129 | }; |
| 130 | |
| 131 | #endif |