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 "gl/GrGLExtensions.h"
13#include "gl/GrGLInterface.h"
14#include "GrGLCaps.h"
15#include "GrGLUtil.h"
16
17struct GrContextOptions;
18
19/**
20 * Encapsulates information about an OpenGL context including the OpenGL
21 * version, the GrGLStandard type of the context, and GLSL version.
22 */
23class GrGLContextInfo : public SkRefCnt {
24public:
25    GrGLStandard standard() const { return fInterface->fStandard; }
26    GrGLVersion version() const { return fGLVersion; }
27    GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
28    GrGLVendor vendor() const { return fVendor; }
29    GrGLRenderer renderer() const { return fRenderer; }
30    /** What driver is running our GL implementation? This is not necessarily related to the vendor.
31        (e.g. Intel GPU being driven by Mesa) */
32    GrGLDriver driver() const { return fDriver; }
33    GrGLDriverVersion driverVersion() const { return fDriverVersion; }
34    const GrGLCaps* caps() const { return fGLCaps.get(); }
35    GrGLCaps* caps() { return fGLCaps; }
36    bool hasExtension(const char* ext) const {
37        return fInterface->hasExtension(ext);
38    }
39
40    const GrGLExtensions& extensions() const { return fInterface->fExtensions; }
41
42protected:
43    struct ConstructorArgs {
44        const GrGLInterface*                fInterface;
45        GrGLVersion                         fGLVersion;
46        GrGLSLGeneration                    fGLSLGeneration;
47        GrGLVendor                          fVendor;
48        GrGLRenderer                        fRenderer;
49        GrGLDriver                          fDriver;
50        GrGLDriverVersion                   fDriverVersion;
51        const  GrContextOptions*            fContextOptions;
52    };
53
54    GrGLContextInfo(const ConstructorArgs& args);
55
56    SkAutoTUnref<const GrGLInterface>   fInterface;
57    GrGLVersion                         fGLVersion;
58    GrGLSLGeneration                    fGLSLGeneration;
59    GrGLVendor                          fVendor;
60    GrGLRenderer                        fRenderer;
61    GrGLDriver                          fDriver;
62    GrGLDriverVersion                   fDriverVersion;
63    SkAutoTUnref<GrGLCaps>              fGLCaps;
64};
65
66/**
67 * Extension of GrGLContextInfo that also provides access to GrGLInterface.
68 */
69class GrGLContext : public GrGLContextInfo {
70public:
71    /**
72     * Creates a GrGLContext from a GrGLInterface and the currently
73     * bound OpenGL context accessible by the GrGLInterface.
74     */
75    static GrGLContext* Create(const GrGLInterface* interface, const GrContextOptions& options);
76
77    const GrGLInterface* interface() const { return fInterface; }
78
79private:
80    GrGLContext(const ConstructorArgs& args) : INHERITED(args) {}
81
82    typedef GrGLContextInfo INHERITED;
83};
84
85#endif
86