blob: 6016f6859a35e5cbfd9213dd043d6b85813e7f2d [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;
robertphillips@google.com6177e692013-02-28 20:16:25 +000018
19/**
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000020 * Encapsulates information about an OpenGL context including the OpenGL
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000021 * version, the GrGLStandard type of the context, and GLSL version.
robertphillips@google.com6177e692013-02-28 20:16:25 +000022 */
reedf9ad5582015-06-25 21:29:25 -070023class GrGLContextInfo : public SkRefCnt {
robertphillips@google.com6177e692013-02-28 20:16:25 +000024public:
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000025 GrGLStandard standard() const { return fInterface->fStandard; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000026 GrGLVersion version() const { return fGLVersion; }
27 GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
28 GrGLVendor vendor() const { return fVendor; }
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000029 GrGLRenderer renderer() const { return fRenderer; }
cdalton1acea862015-06-02 13:05:52 -070030 /** 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; }
bsalomon@google.combcce8922013-03-25 15:38:39 +000034 const GrGLCaps* caps() const { return fGLCaps.get(); }
35 GrGLCaps* caps() { return fGLCaps; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000036 bool hasExtension(const char* ext) const {
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000037 return fInterface->hasExtension(ext);
robertphillips@google.com6177e692013-02-28 20:16:25 +000038 }
39
bsalomone904c092014-07-17 10:50:59 -070040 const GrGLExtensions& extensions() const { return fInterface->fExtensions; }
41
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000042protected:
bsalomon424cc262015-05-22 10:37:30 -070043 struct ConstructorArgs {
44 const GrGLInterface* fInterface;
45 GrGLVersion fGLVersion;
46 GrGLSLGeneration fGLSLGeneration;
47 GrGLVendor fVendor;
48 GrGLRenderer fRenderer;
cdalton1acea862015-06-02 13:05:52 -070049 GrGLDriver fDriver;
50 GrGLDriverVersion fDriverVersion;
bsalomon682c2692015-05-22 14:01:46 -070051 const GrContextOptions* fContextOptions;
bsalomon424cc262015-05-22 10:37:30 -070052 };
53
54 GrGLContextInfo(const ConstructorArgs& args);
55
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000056 SkAutoTUnref<const GrGLInterface> fInterface;
57 GrGLVersion fGLVersion;
58 GrGLSLGeneration fGLSLGeneration;
59 GrGLVendor fVendor;
60 GrGLRenderer fRenderer;
cdalton1acea862015-06-02 13:05:52 -070061 GrGLDriver fDriver;
62 GrGLDriverVersion fDriverVersion;
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000063 SkAutoTUnref<GrGLCaps> fGLCaps;
robertphillips@google.com6177e692013-02-28 20:16:25 +000064};
65
66/**
jvanverth9df16b52016-10-11 10:03:56 -070067 * Extension of GrGLContextInfo that also provides access to GrGLInterface.
robertphillips@google.com6177e692013-02-28 20:16:25 +000068 */
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000069class GrGLContext : public GrGLContextInfo {
robertphillips@google.com6177e692013-02-28 20:16:25 +000070public:
71 /**
robertphillips@google.com6177e692013-02-28 20:16:25 +000072 * Creates a GrGLContext from a GrGLInterface and the currently
73 * bound OpenGL context accessible by the GrGLInterface.
74 */
bsalomon682c2692015-05-22 14:01:46 -070075 static GrGLContext* Create(const GrGLInterface* interface, const GrContextOptions& options);
robertphillips@google.com6177e692013-02-28 20:16:25 +000076
bsalomon424cc262015-05-22 10:37:30 -070077 const GrGLInterface* interface() const { return fInterface; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000078
79private:
jvanverth9df16b52016-10-11 10:03:56 -070080 GrGLContext(const ConstructorArgs& args) : INHERITED(args) {}
bsalomon424cc262015-05-22 10:37:30 -070081
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000082 typedef GrGLContextInfo INHERITED;
robertphillips@google.com6177e692013-02-28 20:16:25 +000083};
84
85#endif