• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
18 struct GrContextOptions;
19 
20 /**
21  * Encapsulates information about an OpenGL context including the OpenGL
22  * version, the GrGLStandard type of the context, and GLSL version.
23  */
24 class GrGLContextInfo {
25 public:
26     GrGLContextInfo(GrGLContextInfo&&) = default;
27     GrGLContextInfo& operator=(GrGLContextInfo&&) = default;
28 
~GrGLContextInfo()29     virtual ~GrGLContextInfo() {}
30 
standard()31     GrGLStandard standard() const { return fInterface->fStandard; }
version()32     GrGLVersion version() const { return fDriverInfo.fVersion; }
glslGeneration()33     GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
vendor()34     GrGLVendor vendor() const { return fDriverInfo.fVendor; }
renderer()35     GrGLRenderer renderer() const { return fDriverInfo.fRenderer; }
angleBackend()36     GrGLANGLEBackend angleBackend() const { return fDriverInfo.fANGLEBackend; }
angleVendor()37     GrGLVendor angleVendor() const { return fDriverInfo.fANGLEVendor; }
angleRenderer()38     GrGLRenderer angleRenderer() const { return fDriverInfo.fANGLERenderer; }
39     /** What driver is running our GL implementation? This is not necessarily related to the vendor.
40         (e.g. Intel GPU being driven by Mesa) */
driver()41     GrGLDriver driver() const { return fDriverInfo.fDriver; }
driverVersion()42     GrGLDriverVersion driverVersion() const { return fDriverInfo.fDriverVersion; }
isOverCommandBuffer()43     bool isOverCommandBuffer() const { return fDriverInfo.fIsOverCommandBuffer; }
44 
caps()45     const GrGLCaps* caps() const { return fGLCaps.get(); }
caps()46     GrGLCaps* caps() { return fGLCaps.get(); }
47 
hasExtension(const char * ext)48     bool hasExtension(const char* ext) const {
49         return fInterface->hasExtension(ext);
50     }
51 
extensions()52     const GrGLExtensions& extensions() const { return fInterface->fExtensions; }
53 
54     /**
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 
61 protected:
62     GrGLContextInfo& operator=(const GrGLContextInfo&) = default;
63     GrGLContextInfo(const GrGLContextInfo&) = default;
64 
65     struct ConstructorArgs {
66         sk_sp<const GrGLInterface>          fInterface;
67         GrGLDriverInfo                      fDriverInfo;
68         GrGLSLGeneration                    fGLSLGeneration;
69         const  GrContextOptions*            fContextOptions;
70     };
71 
72     GrGLContextInfo(ConstructorArgs&&);
73 
74     sk_sp<const GrGLInterface> fInterface;
75     GrGLDriverInfo             fDriverInfo;
76     GrGLSLGeneration           fGLSLGeneration;
77     sk_sp<GrGLCaps>            fGLCaps;
78 };
79 
80 /**
81  * Extension of GrGLContextInfo that also provides access to GrGLInterface.
82  */
83 class GrGLContext : public GrGLContextInfo {
84 public:
85     /**
86      * Creates a GrGLContext from a GrGLInterface and the currently
87      * bound OpenGL context accessible by the GrGLInterface.
88      */
89     static std::unique_ptr<GrGLContext> Make(sk_sp<const GrGLInterface>, const GrContextOptions&);
90 
glInterface()91     const GrGLInterface* glInterface() const { return fInterface.get(); }
92 
93     ~GrGLContext() override;
94 
95 private:
GrGLContext(ConstructorArgs && args)96     GrGLContext(ConstructorArgs&& args) : INHERITED(std::move(args)) {}
97 
98     using INHERITED = GrGLContextInfo;
99 };
100 
101 #endif
102