blob: 5ea81781fe17c0a92a444175c6c86dfef2f179ef [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;
ethannicholas5961bc92016-10-12 06:39:56 -070019namespace SkSL {
20 class Compiler;
21}
robertphillips@google.com6177e692013-02-28 20:16:25 +000022
23/**
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000024 * Encapsulates information about an OpenGL context including the OpenGL
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000025 * version, the GrGLStandard type of the context, and GLSL version.
robertphillips@google.com6177e692013-02-28 20:16:25 +000026 */
Brian Salomon8ab1cc42017-12-07 12:40:00 -050027class GrGLContextInfo {
robertphillips@google.com6177e692013-02-28 20:16:25 +000028public:
Brian Salomon8ab1cc42017-12-07 12:40:00 -050029 GrGLContextInfo(const GrGLContextInfo&) = delete;
30 GrGLContextInfo& operator=(const GrGLContextInfo&) = delete;
31
32 virtual ~GrGLContextInfo() {}
33
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000034 GrGLStandard standard() const { return fInterface->fStandard; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000035 GrGLVersion version() const { return fGLVersion; }
36 GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
37 GrGLVendor vendor() const { return fVendor; }
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000038 GrGLRenderer renderer() const { return fRenderer; }
Brian Salomon266ef6d2017-09-22 11:27:42 -040039 GrGLANGLEBackend angleBackend() const { return fANGLEBackend; }
40 GrGLANGLEVendor angleVendor() const { return fANGLEVendor; }
41 GrGLANGLERenderer angleRenderer() const { return fANGLERenderer; }
cdalton1acea862015-06-02 13:05:52 -070042 /** What driver is running our GL implementation? This is not necessarily related to the vendor.
43 (e.g. Intel GPU being driven by Mesa) */
44 GrGLDriver driver() const { return fDriver; }
45 GrGLDriverVersion driverVersion() const { return fDriverVersion; }
bsalomon@google.combcce8922013-03-25 15:38:39 +000046 const GrGLCaps* caps() const { return fGLCaps.get(); }
Hal Canary144caf52016-11-07 17:57:18 -050047 GrGLCaps* caps() { return fGLCaps.get(); }
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
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000054protected:
bsalomon424cc262015-05-22 10:37:30 -070055 struct ConstructorArgs {
Brian Salomon8ab1cc42017-12-07 12:40:00 -050056 sk_sp<const GrGLInterface> fInterface;
bsalomon424cc262015-05-22 10:37:30 -070057 GrGLVersion fGLVersion;
58 GrGLSLGeneration fGLSLGeneration;
59 GrGLVendor fVendor;
60 GrGLRenderer fRenderer;
cdalton1acea862015-06-02 13:05:52 -070061 GrGLDriver fDriver;
62 GrGLDriverVersion fDriverVersion;
Brian Salomon266ef6d2017-09-22 11:27:42 -040063 GrGLANGLEBackend fANGLEBackend;
64 GrGLANGLEVendor fANGLEVendor;
65 GrGLANGLERenderer fANGLERenderer;
bsalomon682c2692015-05-22 14:01:46 -070066 const GrContextOptions* fContextOptions;
bsalomon424cc262015-05-22 10:37:30 -070067 };
68
Brian Salomon8ab1cc42017-12-07 12:40:00 -050069 GrGLContextInfo(ConstructorArgs&&);
bsalomon424cc262015-05-22 10:37:30 -070070
Hal Canary144caf52016-11-07 17:57:18 -050071 sk_sp<const GrGLInterface> fInterface;
72 GrGLVersion fGLVersion;
73 GrGLSLGeneration fGLSLGeneration;
74 GrGLVendor fVendor;
75 GrGLRenderer fRenderer;
76 GrGLDriver fDriver;
77 GrGLDriverVersion fDriverVersion;
Brian Salomon266ef6d2017-09-22 11:27:42 -040078 GrGLANGLEBackend fANGLEBackend;
79 GrGLANGLEVendor fANGLEVendor;
80 GrGLANGLERenderer fANGLERenderer;
Hal Canary144caf52016-11-07 17:57:18 -050081 sk_sp<GrGLCaps> fGLCaps;
robertphillips@google.com6177e692013-02-28 20:16:25 +000082};
83
84/**
ethannicholas5961bc92016-10-12 06:39:56 -070085 * Extension of GrGLContextInfo that also provides access to GrGLInterface and SkSL::Compiler.
robertphillips@google.com6177e692013-02-28 20:16:25 +000086 */
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000087class GrGLContext : public GrGLContextInfo {
robertphillips@google.com6177e692013-02-28 20:16:25 +000088public:
89 /**
robertphillips@google.com6177e692013-02-28 20:16:25 +000090 * Creates a GrGLContext from a GrGLInterface and the currently
91 * bound OpenGL context accessible by the GrGLInterface.
92 */
Brian Salomon8ab1cc42017-12-07 12:40:00 -050093 static std::unique_ptr<GrGLContext> Make(sk_sp<const GrGLInterface>, const GrContextOptions&);
robertphillips@google.com6177e692013-02-28 20:16:25 +000094
Hal Canary144caf52016-11-07 17:57:18 -050095 const GrGLInterface* interface() const { return fInterface.get(); }
robertphillips@google.com6177e692013-02-28 20:16:25 +000096
ethannicholas5961bc92016-10-12 06:39:56 -070097 SkSL::Compiler* compiler() const;
98
99 ~GrGLContext() override;
100
robertphillips@google.com6177e692013-02-28 20:16:25 +0000101private:
Brian Salomon8ab1cc42017-12-07 12:40:00 -0500102 GrGLContext(ConstructorArgs&& args) : INHERITED(std::move(args)), fCompiler(nullptr) {}
ethannicholas5961bc92016-10-12 06:39:56 -0700103
104 mutable SkSL::Compiler* fCompiler;
bsalomon424cc262015-05-22 10:37:30 -0700105
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000106 typedef GrGLContextInfo INHERITED;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000107};
108
109#endif