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 | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 50 | /** Is this a mesa-based driver. Does not mean it is the osmesa software rasterizer. */ |
| 51 | bool isMesa() const { return fIsMesa; } |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 52 | const GrGLCaps* caps() const { return fGLCaps.get(); } |
| 53 | GrGLCaps* caps() { return fGLCaps; } |
bsalomon@google.com | 00142c4 | 2013-05-02 19:42:54 +0000 | [diff] [blame] | 54 | const GrGLExtensions& extensions() const { return fExtensions; } |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 55 | |
| 56 | /** |
bsalomon@google.com | 00142c4 | 2013-05-02 19:42:54 +0000 | [diff] [blame] | 57 | * Shortcut for extensions().has(ext); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 58 | */ |
| 59 | bool hasExtension(const char* ext) const { |
| 60 | if (!this->isInitialized()) { |
| 61 | return false; |
| 62 | } |
| 63 | return fExtensions.has(ext); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * Reset the information |
| 68 | */ |
| 69 | void reset(); |
| 70 | |
| 71 | private: |
| 72 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 73 | GrGLBinding fBindingInUse; |
| 74 | GrGLVersion fGLVersion; |
| 75 | GrGLSLGeneration fGLSLGeneration; |
| 76 | GrGLVendor fVendor; |
| 77 | GrGLExtensions fExtensions; |
commit-bot@chromium.org | 459104c | 2013-06-14 14:42:56 +0000 | [diff] [blame] | 78 | bool fIsMesa; |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 79 | SkAutoTUnref<GrGLCaps> fGLCaps; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 80 | }; |
| 81 | |
| 82 | /** |
| 83 | * Encapsulates the GrGLInterface used to make GL calls plus information |
| 84 | * about the context (via GrGLContextInfo). |
| 85 | */ |
| 86 | class GrGLContext { |
| 87 | public: |
| 88 | /** |
| 89 | * Default constructor |
| 90 | */ |
| 91 | GrGLContext() { this->reset(); } |
| 92 | |
| 93 | /** |
| 94 | * Creates a GrGLContext from a GrGLInterface and the currently |
| 95 | * bound OpenGL context accessible by the GrGLInterface. |
| 96 | */ |
| 97 | explicit GrGLContext(const GrGLInterface* interface); |
| 98 | |
| 99 | /** |
| 100 | * Copies a GrGLContext |
| 101 | */ |
| 102 | GrGLContext(const GrGLContext& ctx); |
| 103 | |
commit-bot@chromium.org | a4de8c2 | 2013-09-09 13:38:37 +0000 | [diff] [blame^] | 104 | ~GrGLContext() { SkSafeUnref(fInterface); } |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 105 | |
| 106 | /** |
| 107 | * Copies a GrGLContext |
| 108 | */ |
| 109 | GrGLContext& operator= (const GrGLContext& ctx); |
| 110 | |
| 111 | /** |
| 112 | * Initializes a GrGLContext from a GrGLInterface and the currently |
| 113 | * bound OpenGL context accessible by the GrGLInterface. |
| 114 | */ |
| 115 | bool initialize(const GrGLInterface* interface); |
| 116 | bool isInitialized() const { return fInfo.isInitialized(); } |
| 117 | |
| 118 | const GrGLInterface* interface() const { return fInterface; } |
| 119 | const GrGLContextInfo& info() const { return fInfo; } |
| 120 | GrGLContextInfo& info() { return fInfo; } |
| 121 | |
| 122 | private: |
| 123 | void reset(); |
| 124 | |
| 125 | const GrGLInterface* fInterface; |
| 126 | GrGLContextInfo fInfo; |
| 127 | }; |
| 128 | |
| 129 | #endif |