aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/gl/GrGLContext.h
blob: 977d3606a513d6c09ccfe685317e3cddcbb4c4d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
 * Copyright 2013 Google Inc.
 *
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */


#ifndef GrGLContext_DEFINED
#define GrGLContext_DEFINED

#include "gl/GrGLExtensions.h"
#include "gl/GrGLInterface.h"
#include "GrGLCaps.h"
#include "GrGLUtil.h"

struct GrContextOptions;
namespace SkSL {
    class Compiler;
}

/**
 * Encapsulates information about an OpenGL context including the OpenGL
 * version, the GrGLStandard type of the context, and GLSL version.
 */
class GrGLContextInfo : public SkRefCnt {
public:
    GrGLStandard standard() const { return fInterface->fStandard; }
    GrGLVersion version() const { return fGLVersion; }
    GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
    GrGLVendor vendor() const { return fVendor; }
    GrGLRenderer renderer() const { return fRenderer; }
    GrGLANGLEBackend angleBackend() const { return fANGLEBackend; }
    GrGLANGLEVendor angleVendor() const { return fANGLEVendor; }
    GrGLANGLERenderer angleRenderer() const { return fANGLERenderer; }
    /** What driver is running our GL implementation? This is not necessarily related to the vendor.
        (e.g. Intel GPU being driven by Mesa) */
    GrGLDriver driver() const { return fDriver; }
    GrGLDriverVersion driverVersion() const { return fDriverVersion; }
    const GrGLCaps* caps() const { return fGLCaps.get(); }
    GrGLCaps* caps() { return fGLCaps.get(); }
    bool hasExtension(const char* ext) const {
        return fInterface->hasExtension(ext);
    }

    const GrGLExtensions& extensions() const { return fInterface->fExtensions; }

    virtual ~GrGLContextInfo() {}

protected:
    struct ConstructorArgs {
        const GrGLInterface*                fInterface;
        GrGLVersion                         fGLVersion;
        GrGLSLGeneration                    fGLSLGeneration;
        GrGLVendor                          fVendor;
        GrGLRenderer                        fRenderer;
        GrGLDriver                          fDriver;
        GrGLDriverVersion                   fDriverVersion;
        GrGLANGLEBackend                    fANGLEBackend;
        GrGLANGLEVendor                     fANGLEVendor;
        GrGLANGLERenderer                   fANGLERenderer;
        const  GrContextOptions*            fContextOptions;
    };

    GrGLContextInfo(const ConstructorArgs& args);

    sk_sp<const GrGLInterface> fInterface;
    GrGLVersion                fGLVersion;
    GrGLSLGeneration           fGLSLGeneration;
    GrGLVendor                 fVendor;
    GrGLRenderer               fRenderer;
    GrGLDriver                 fDriver;
    GrGLDriverVersion          fDriverVersion;
    GrGLANGLEBackend           fANGLEBackend;
    GrGLANGLEVendor            fANGLEVendor;
    GrGLANGLERenderer          fANGLERenderer;
    sk_sp<GrGLCaps>            fGLCaps;
};

/**
 * Extension of GrGLContextInfo that also provides access to GrGLInterface and SkSL::Compiler.
 */
class GrGLContext : public GrGLContextInfo {
public:
    /**
     * Creates a GrGLContext from a GrGLInterface and the currently
     * bound OpenGL context accessible by the GrGLInterface.
     */
    static GrGLContext* Create(const GrGLInterface* interface, const GrContextOptions& options);

    const GrGLInterface* interface() const { return fInterface.get(); }

    SkSL::Compiler* compiler() const;

    ~GrGLContext() override;

private:
    GrGLContext(const ConstructorArgs& args) 
    : INHERITED(args)
    , fCompiler(nullptr) {}

    mutable SkSL::Compiler* fCompiler;

    typedef GrGLContextInfo INHERITED;
};

#endif