blob: 998a5f519473796cf9e33c6cb6bce24d1bf9e4ef [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
12#include "gl/GrGLExtensions.h"
13#include "gl/GrGLInterface.h"
14#include "GrGLCaps.h"
robertphillips@google.com6177e692013-02-28 20:16:25 +000015#include "GrGLUtil.h"
16
bsalomon682c2692015-05-22 14:01:46 -070017struct GrContextOptions;
ethannicholas5961bc92016-10-12 06:39:56 -070018namespace SkSL {
19 class Compiler;
20}
robertphillips@google.com6177e692013-02-28 20:16:25 +000021
22/**
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000023 * Encapsulates information about an OpenGL context including the OpenGL
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000024 * version, the GrGLStandard type of the context, and GLSL version.
robertphillips@google.com6177e692013-02-28 20:16:25 +000025 */
Brian Salomon8ab1cc42017-12-07 12:40:00 -050026class GrGLContextInfo {
robertphillips@google.com6177e692013-02-28 20:16:25 +000027public:
Brian Salomon8ab1cc42017-12-07 12:40:00 -050028 GrGLContextInfo(const GrGLContextInfo&) = delete;
29 GrGLContextInfo& operator=(const GrGLContextInfo&) = delete;
30
31 virtual ~GrGLContextInfo() {}
32
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000033 GrGLStandard standard() const { return fInterface->fStandard; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000034 GrGLVersion version() const { return fGLVersion; }
35 GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
36 GrGLVendor vendor() const { return fVendor; }
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000037 GrGLRenderer renderer() const { return fRenderer; }
Brian Salomon266ef6d2017-09-22 11:27:42 -040038 GrGLANGLEBackend angleBackend() const { return fANGLEBackend; }
39 GrGLANGLEVendor angleVendor() const { return fANGLEVendor; }
40 GrGLANGLERenderer angleRenderer() const { return fANGLERenderer; }
cdalton1acea862015-06-02 13:05:52 -070041 /** What driver is running our GL implementation? This is not necessarily related to the vendor.
42 (e.g. Intel GPU being driven by Mesa) */
43 GrGLDriver driver() const { return fDriver; }
44 GrGLDriverVersion driverVersion() const { return fDriverVersion; }
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(); }
robertphillips@google.com6177e692013-02-28 20:16:25 +000047 bool hasExtension(const char* ext) const {
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000048 return fInterface->hasExtension(ext);
robertphillips@google.com6177e692013-02-28 20:16:25 +000049 }
50
bsalomone904c092014-07-17 10:50:59 -070051 const GrGLExtensions& extensions() const { return fInterface->fExtensions; }
52
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000053protected:
bsalomon424cc262015-05-22 10:37:30 -070054 struct ConstructorArgs {
Brian Salomon8ab1cc42017-12-07 12:40:00 -050055 sk_sp<const GrGLInterface> fInterface;
bsalomon424cc262015-05-22 10:37:30 -070056 GrGLVersion fGLVersion;
57 GrGLSLGeneration fGLSLGeneration;
58 GrGLVendor fVendor;
59 GrGLRenderer fRenderer;
cdalton1acea862015-06-02 13:05:52 -070060 GrGLDriver fDriver;
61 GrGLDriverVersion fDriverVersion;
Brian Salomon266ef6d2017-09-22 11:27:42 -040062 GrGLANGLEBackend fANGLEBackend;
63 GrGLANGLEVendor fANGLEVendor;
64 GrGLANGLERenderer fANGLERenderer;
bsalomon682c2692015-05-22 14:01:46 -070065 const GrContextOptions* fContextOptions;
bsalomon424cc262015-05-22 10:37:30 -070066 };
67
Brian Salomon8ab1cc42017-12-07 12:40:00 -050068 GrGLContextInfo(ConstructorArgs&&);
bsalomon424cc262015-05-22 10:37:30 -070069
Hal Canary144caf52016-11-07 17:57:18 -050070 sk_sp<const GrGLInterface> fInterface;
71 GrGLVersion fGLVersion;
72 GrGLSLGeneration fGLSLGeneration;
73 GrGLVendor fVendor;
74 GrGLRenderer fRenderer;
75 GrGLDriver fDriver;
76 GrGLDriverVersion fDriverVersion;
Brian Salomon266ef6d2017-09-22 11:27:42 -040077 GrGLANGLEBackend fANGLEBackend;
78 GrGLANGLEVendor fANGLEVendor;
79 GrGLANGLERenderer fANGLERenderer;
Hal Canary144caf52016-11-07 17:57:18 -050080 sk_sp<GrGLCaps> fGLCaps;
robertphillips@google.com6177e692013-02-28 20:16:25 +000081};
82
83/**
ethannicholas5961bc92016-10-12 06:39:56 -070084 * Extension of GrGLContextInfo that also provides access to GrGLInterface and SkSL::Compiler.
robertphillips@google.com6177e692013-02-28 20:16:25 +000085 */
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000086class GrGLContext : public GrGLContextInfo {
robertphillips@google.com6177e692013-02-28 20:16:25 +000087public:
88 /**
robertphillips@google.com6177e692013-02-28 20:16:25 +000089 * Creates a GrGLContext from a GrGLInterface and the currently
90 * bound OpenGL context accessible by the GrGLInterface.
91 */
Brian Salomon8ab1cc42017-12-07 12:40:00 -050092 static std::unique_ptr<GrGLContext> Make(sk_sp<const GrGLInterface>, const GrContextOptions&);
robertphillips@google.com6177e692013-02-28 20:16:25 +000093
Hal Canary144caf52016-11-07 17:57:18 -050094 const GrGLInterface* interface() const { return fInterface.get(); }
robertphillips@google.com6177e692013-02-28 20:16:25 +000095
ethannicholas5961bc92016-10-12 06:39:56 -070096 SkSL::Compiler* compiler() const;
97
98 ~GrGLContext() override;
99
robertphillips@google.com6177e692013-02-28 20:16:25 +0000100private:
Brian Salomon8ab1cc42017-12-07 12:40:00 -0500101 GrGLContext(ConstructorArgs&& args) : INHERITED(std::move(args)), fCompiler(nullptr) {}
ethannicholas5961bc92016-10-12 06:39:56 -0700102
103 mutable SkSL::Compiler* fCompiler;
bsalomon424cc262015-05-22 10:37:30 -0700104
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000105 typedef GrGLContextInfo INHERITED;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000106};
107
108#endif