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 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 12 | #include "include/gpu/gl/GrGLExtensions.h" |
| 13 | #include "include/gpu/gl/GrGLInterface.h" |
| 14 | #include "src/gpu/gl/GrGLCaps.h" |
| 15 | #include "src/gpu/gl/GrGLUtil.h" |
| 16 | #include "src/gpu/glsl/GrGLSL.h" |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 17 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 18 | struct GrContextOptions; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 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 |
commit-bot@chromium.org | 9e90aed | 2014-01-16 16:35:09 +0000 | [diff] [blame] | 22 | * version, the GrGLStandard type of the context, and GLSL version. |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 23 | */ |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 24 | class GrGLContextInfo { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 25 | public: |
Brian Salomon | 4695312 | 2021-05-10 10:21:06 -0400 | [diff] [blame] | 26 | GrGLContextInfo(GrGLContextInfo&&) = default; |
| 27 | GrGLContextInfo& operator=(GrGLContextInfo&&) = default; |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 28 | |
| 29 | virtual ~GrGLContextInfo() {} |
| 30 | |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 31 | GrGLStandard standard() const { return fInterface->fStandard; } |
Brian Salomon | 1989342 | 2021-05-06 15:11:43 -0400 | [diff] [blame] | 32 | GrGLVersion version() const { return fDriverInfo.fVersion; } |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 33 | GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; } |
Brian Salomon | 1989342 | 2021-05-06 15:11:43 -0400 | [diff] [blame] | 34 | GrGLVendor vendor() const { return fDriverInfo.fVendor; } |
| 35 | GrGLRenderer renderer() const { return fDriverInfo.fRenderer; } |
| 36 | GrGLANGLEBackend angleBackend() const { return fDriverInfo.fANGLEBackend; } |
Brian Salomon | 96263aa | 2021-05-07 13:42:17 -0400 | [diff] [blame] | 37 | GrGLVendor angleVendor() const { return fDriverInfo.fANGLEVendor; } |
| 38 | GrGLRenderer angleRenderer() const { return fDriverInfo.fANGLERenderer; } |
cdalton | 1acea86 | 2015-06-02 13:05:52 -0700 | [diff] [blame] | 39 | /** What driver is running our GL implementation? This is not necessarily related to the vendor. |
| 40 | (e.g. Intel GPU being driven by Mesa) */ |
Brian Salomon | 1989342 | 2021-05-06 15:11:43 -0400 | [diff] [blame] | 41 | GrGLDriver driver() const { return fDriverInfo.fDriver; } |
| 42 | GrGLDriverVersion driverVersion() const { return fDriverInfo.fDriverVersion; } |
Brian Salomon | 4af11a1 | 2021-05-18 14:58:03 -0400 | [diff] [blame] | 43 | bool isOverCommandBuffer() const { return fDriverInfo.fIsOverCommandBuffer; } |
| 44 | |
bsalomon@google.com | bcce892 | 2013-03-25 15:38:39 +0000 | [diff] [blame] | 45 | const GrGLCaps* caps() const { return fGLCaps.get(); } |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 46 | GrGLCaps* caps() { return fGLCaps.get(); } |
Brian Salomon | 4af11a1 | 2021-05-18 14:58:03 -0400 | [diff] [blame] | 47 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 48 | bool hasExtension(const char* ext) const { |
commit-bot@chromium.org | 90313cc | 2014-01-17 15:05:38 +0000 | [diff] [blame] | 49 | return fInterface->hasExtension(ext); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 50 | } |
| 51 | |
bsalomon | e904c09 | 2014-07-17 10:50:59 -0700 | [diff] [blame] | 52 | const GrGLExtensions& extensions() const { return fInterface->fExtensions; } |
| 53 | |
Brian Salomon | 4695312 | 2021-05-10 10:21:06 -0400 | [diff] [blame] | 54 | /** |
| 55 | * Makes a version of this context info that strips the "angle-ness". It will report kUnknown |
| 56 | * for angleBackend() and report this info's angleRenderer() as renderer() and similiar for |
| 57 | * driver(), driverVersion(), and vendor(). |
| 58 | */ |
| 59 | GrGLContextInfo makeNonAngle() const; |
| 60 | |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 61 | protected: |
Brian Salomon | 4695312 | 2021-05-10 10:21:06 -0400 | [diff] [blame] | 62 | GrGLContextInfo& operator=(const GrGLContextInfo&) = default; |
| 63 | GrGLContextInfo(const GrGLContextInfo&) = default; |
| 64 | |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 65 | struct ConstructorArgs { |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 66 | sk_sp<const GrGLInterface> fInterface; |
Brian Salomon | 1989342 | 2021-05-06 15:11:43 -0400 | [diff] [blame] | 67 | GrGLDriverInfo fDriverInfo; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 68 | GrGLSLGeneration fGLSLGeneration; |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 69 | const GrContextOptions* fContextOptions; |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 70 | }; |
| 71 | |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 72 | GrGLContextInfo(ConstructorArgs&&); |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 73 | |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 74 | sk_sp<const GrGLInterface> fInterface; |
Brian Salomon | 1989342 | 2021-05-06 15:11:43 -0400 | [diff] [blame] | 75 | GrGLDriverInfo fDriverInfo; |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 76 | GrGLSLGeneration fGLSLGeneration; |
Hal Canary | 144caf5 | 2016-11-07 17:57:18 -0500 | [diff] [blame] | 77 | sk_sp<GrGLCaps> fGLCaps; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | /** |
Brian Osman | 7971926 | 2020-11-23 14:54:33 -0500 | [diff] [blame] | 81 | * Extension of GrGLContextInfo that also provides access to GrGLInterface. |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 82 | */ |
commit-bot@chromium.org | b1854a8 | 2014-01-16 18:39:04 +0000 | [diff] [blame] | 83 | class GrGLContext : public GrGLContextInfo { |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 84 | public: |
| 85 | /** |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 86 | * Creates a GrGLContext from a GrGLInterface and the currently |
| 87 | * bound OpenGL context accessible by the GrGLInterface. |
| 88 | */ |
Brian Salomon | 8ab1cc4 | 2017-12-07 12:40:00 -0500 | [diff] [blame] | 89 | static std::unique_ptr<GrGLContext> Make(sk_sp<const GrGLInterface>, const GrContextOptions&); |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 90 | |
Jim Van Verth | 03b8ab2 | 2020-02-24 11:36:15 -0500 | [diff] [blame] | 91 | const GrGLInterface* glInterface() const { return fInterface.get(); } |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 92 | |
ethannicholas | 5961bc9 | 2016-10-12 06:39:56 -0700 | [diff] [blame] | 93 | ~GrGLContext() override; |
| 94 | |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 95 | private: |
Brian Osman | 7971926 | 2020-11-23 14:54:33 -0500 | [diff] [blame] | 96 | GrGLContext(ConstructorArgs&& args) : INHERITED(std::move(args)) {} |
bsalomon | 424cc26 | 2015-05-22 10:37:30 -0700 | [diff] [blame] | 97 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 98 | using INHERITED = GrGLContextInfo; |
robertphillips@google.com | 6177e69 | 2013-02-28 20:16:25 +0000 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | #endif |