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 "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"
17
18struct GrContextOptions;
19namespace SkSL {
20 class Compiler;
21}
22
23/**
24 * Encapsulates information about an OpenGL context including the OpenGL
25 * version, the GrGLStandard type of the context, and GLSL version.
26 */
27class GrGLContextInfo {
28public:
29 GrGLContextInfo(const GrGLContextInfo&) = delete;
30 GrGLContextInfo& operator=(const GrGLContextInfo&) = delete;
31
32 virtual ~GrGLContextInfo() {}
33
34 GrGLStandard standard() const { return fInterface->fStandard; }
35 GrGLVersion version() const { return fGLVersion; }
36 GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
37 GrGLVendor vendor() const { return fVendor; }
38 GrGLRenderer renderer() const { return fRenderer; }
39 GrGLANGLEBackend angleBackend() const { return fANGLEBackend; }
40 GrGLANGLEVendor angleVendor() const { return fANGLEVendor; }
41 GrGLANGLERenderer angleRenderer() const { return fANGLERenderer; }
42 /** 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; }
46 const GrGLCaps* caps() const { return fGLCaps.get(); }
47 GrGLCaps* caps() { return fGLCaps.get(); }
48 bool hasExtension(const char* ext) const {
49 return fInterface->hasExtension(ext);
50 }
51
52 const GrGLExtensions& extensions() const { return fInterface->fExtensions; }
53
54protected:
55 struct ConstructorArgs {
56 sk_sp<const GrGLInterface> fInterface;
57 GrGLVersion fGLVersion;
58 GrGLSLGeneration fGLSLGeneration;
59 GrGLVendor fVendor;
60 GrGLRenderer fRenderer;
61 GrGLDriver fDriver;
62 GrGLDriverVersion fDriverVersion;
63 GrGLANGLEBackend fANGLEBackend;
64 GrGLANGLEVendor fANGLEVendor;
65 GrGLANGLERenderer fANGLERenderer;
66 const GrContextOptions* fContextOptions;
67 };
68
69 GrGLContextInfo(ConstructorArgs&&);
70
71 sk_sp<const GrGLInterface> fInterface;
72 GrGLVersion fGLVersion;
73 GrGLSLGeneration fGLSLGeneration;
74 GrGLVendor fVendor;
75 GrGLRenderer fRenderer;
76 GrGLDriver fDriver;
77 GrGLDriverVersion fDriverVersion;
78 GrGLANGLEBackend fANGLEBackend;
79 GrGLANGLEVendor fANGLEVendor;
80 GrGLANGLERenderer fANGLERenderer;
81 sk_sp<GrGLCaps> fGLCaps;
82};
83
84/**
85 * Extension of GrGLContextInfo that also provides access to GrGLInterface and SkSL::Compiler.
86 */
87class GrGLContext : public GrGLContextInfo {
88public:
89 /**
90 * Creates a GrGLContext from a GrGLInterface and the currently
91 * bound OpenGL context accessible by the GrGLInterface.
92 */
93 static std::unique_ptr<GrGLContext> Make(sk_sp<const GrGLInterface>, const GrContextOptions&);
94
95 const GrGLInterface* glInterface() const { return fInterface.get(); }
96
97 SkSL::Compiler* compiler() const;
98
99 ~GrGLContext() override;
100
101private:
102 GrGLContext(ConstructorArgs&& args) : INHERITED(std::move(args)), fCompiler(nullptr) {}
103
104 mutable SkSL::Compiler* fCompiler;
105
106 typedef GrGLContextInfo INHERITED;
107};
108
109#endif
110