blob: 93bd57c2c5811ddeba27de31e6c527b8f8c8ed85 [file] [log] [blame]
robertphillips@google.com6177e692013-02-28 20:16:25 +00001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -050012#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.com6177e692013-02-28 20:16:25 +000017
bsalomon682c2692015-05-22 14:01:46 -070018struct GrContextOptions;
robertphillips@google.com6177e692013-02-28 20:16:25 +000019
20/**
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000021 * Encapsulates information about an OpenGL context including the OpenGL
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000022 * version, the GrGLStandard type of the context, and GLSL version.
robertphillips@google.com6177e692013-02-28 20:16:25 +000023 */
Brian Salomon8ab1cc42017-12-07 12:40:00 -050024class GrGLContextInfo {
robertphillips@google.com6177e692013-02-28 20:16:25 +000025public:
Brian Salomon46953122021-05-10 10:21:06 -040026 GrGLContextInfo(GrGLContextInfo&&) = default;
27 GrGLContextInfo& operator=(GrGLContextInfo&&) = default;
Brian Salomon8ab1cc42017-12-07 12:40:00 -050028
29 virtual ~GrGLContextInfo() {}
30
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000031 GrGLStandard standard() const { return fInterface->fStandard; }
Brian Salomon19893422021-05-06 15:11:43 -040032 GrGLVersion version() const { return fDriverInfo.fVersion; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000033 GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
Brian Salomon19893422021-05-06 15:11:43 -040034 GrGLVendor vendor() const { return fDriverInfo.fVendor; }
35 GrGLRenderer renderer() const { return fDriverInfo.fRenderer; }
36 GrGLANGLEBackend angleBackend() const { return fDriverInfo.fANGLEBackend; }
Brian Salomon96263aa2021-05-07 13:42:17 -040037 GrGLVendor angleVendor() const { return fDriverInfo.fANGLEVendor; }
38 GrGLRenderer angleRenderer() const { return fDriverInfo.fANGLERenderer; }
cdalton1acea862015-06-02 13:05:52 -070039 /** 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 Salomon19893422021-05-06 15:11:43 -040041 GrGLDriver driver() const { return fDriverInfo.fDriver; }
42 GrGLDriverVersion driverVersion() const { return fDriverInfo.fDriverVersion; }
Brian Salomon4af11a12021-05-18 14:58:03 -040043 bool isOverCommandBuffer() const { return fDriverInfo.fIsOverCommandBuffer; }
44
bsalomon@google.combcce8922013-03-25 15:38:39 +000045 const GrGLCaps* caps() const { return fGLCaps.get(); }
Hal Canary144caf52016-11-07 17:57:18 -050046 GrGLCaps* caps() { return fGLCaps.get(); }
Brian Salomon4af11a12021-05-18 14:58:03 -040047
robertphillips@google.com6177e692013-02-28 20:16:25 +000048 bool hasExtension(const char* ext) const {
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000049 return fInterface->hasExtension(ext);
robertphillips@google.com6177e692013-02-28 20:16:25 +000050 }
51
bsalomone904c092014-07-17 10:50:59 -070052 const GrGLExtensions& extensions() const { return fInterface->fExtensions; }
53
Brian Salomon46953122021-05-10 10:21:06 -040054 /**
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.orgb1854a82014-01-16 18:39:04 +000061protected:
Brian Salomon46953122021-05-10 10:21:06 -040062 GrGLContextInfo& operator=(const GrGLContextInfo&) = default;
63 GrGLContextInfo(const GrGLContextInfo&) = default;
64
bsalomon424cc262015-05-22 10:37:30 -070065 struct ConstructorArgs {
Brian Salomon8ab1cc42017-12-07 12:40:00 -050066 sk_sp<const GrGLInterface> fInterface;
Brian Salomon19893422021-05-06 15:11:43 -040067 GrGLDriverInfo fDriverInfo;
bsalomon424cc262015-05-22 10:37:30 -070068 GrGLSLGeneration fGLSLGeneration;
bsalomon682c2692015-05-22 14:01:46 -070069 const GrContextOptions* fContextOptions;
bsalomon424cc262015-05-22 10:37:30 -070070 };
71
Brian Salomon8ab1cc42017-12-07 12:40:00 -050072 GrGLContextInfo(ConstructorArgs&&);
bsalomon424cc262015-05-22 10:37:30 -070073
Hal Canary144caf52016-11-07 17:57:18 -050074 sk_sp<const GrGLInterface> fInterface;
Brian Salomon19893422021-05-06 15:11:43 -040075 GrGLDriverInfo fDriverInfo;
Hal Canary144caf52016-11-07 17:57:18 -050076 GrGLSLGeneration fGLSLGeneration;
Hal Canary144caf52016-11-07 17:57:18 -050077 sk_sp<GrGLCaps> fGLCaps;
robertphillips@google.com6177e692013-02-28 20:16:25 +000078};
79
80/**
Brian Osman79719262020-11-23 14:54:33 -050081 * Extension of GrGLContextInfo that also provides access to GrGLInterface.
robertphillips@google.com6177e692013-02-28 20:16:25 +000082 */
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000083class GrGLContext : public GrGLContextInfo {
robertphillips@google.com6177e692013-02-28 20:16:25 +000084public:
85 /**
robertphillips@google.com6177e692013-02-28 20:16:25 +000086 * Creates a GrGLContext from a GrGLInterface and the currently
87 * bound OpenGL context accessible by the GrGLInterface.
88 */
Brian Salomon8ab1cc42017-12-07 12:40:00 -050089 static std::unique_ptr<GrGLContext> Make(sk_sp<const GrGLInterface>, const GrContextOptions&);
robertphillips@google.com6177e692013-02-28 20:16:25 +000090
Jim Van Verth03b8ab22020-02-24 11:36:15 -050091 const GrGLInterface* glInterface() const { return fInterface.get(); }
robertphillips@google.com6177e692013-02-28 20:16:25 +000092
ethannicholas5961bc92016-10-12 06:39:56 -070093 ~GrGLContext() override;
94
robertphillips@google.com6177e692013-02-28 20:16:25 +000095private:
Brian Osman79719262020-11-23 14:54:33 -050096 GrGLContext(ConstructorArgs&& args) : INHERITED(std::move(args)) {}
bsalomon424cc262015-05-22 10:37:30 -070097
John Stiles7571f9e2020-09-02 22:42:33 -040098 using INHERITED = GrGLContextInfo;
robertphillips@google.com6177e692013-02-28 20:16:25 +000099};
100
101#endif