blob: 0bf045a7db40ba57bade16f55d232a580b822f86 [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;
ethannicholas5961bc92016-10-12 06:39:56 -070018namespace SkSL {
19 class Compiler;
20}
robertphillips@google.com6177e692013-02-28 20:16:25 +000021
22/**
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000023 * Encapsulates information about an OpenGL context including the OpenGL
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000024 * version, the GrGLStandard type of the context, and GLSL version.
robertphillips@google.com6177e692013-02-28 20:16:25 +000025 */
reedf9ad5582015-06-25 21:29:25 -070026class GrGLContextInfo : public SkRefCnt {
robertphillips@google.com6177e692013-02-28 20:16:25 +000027public:
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000028 GrGLStandard standard() const { return fInterface->fStandard; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000029 GrGLVersion version() const { return fGLVersion; }
30 GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
31 GrGLVendor vendor() const { return fVendor; }
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000032 GrGLRenderer renderer() const { return fRenderer; }
cdalton1acea862015-06-02 13:05:52 -070033 /** What driver is running our GL implementation? This is not necessarily related to the vendor.
34 (e.g. Intel GPU being driven by Mesa) */
35 GrGLDriver driver() const { return fDriver; }
36 GrGLDriverVersion driverVersion() const { return fDriverVersion; }
bsalomon@google.combcce8922013-03-25 15:38:39 +000037 const GrGLCaps* caps() const { return fGLCaps.get(); }
Hal Canary144caf52016-11-07 17:57:18 -050038 GrGLCaps* caps() { return fGLCaps.get(); }
robertphillips@google.com6177e692013-02-28 20:16:25 +000039 bool hasExtension(const char* ext) const {
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000040 return fInterface->hasExtension(ext);
robertphillips@google.com6177e692013-02-28 20:16:25 +000041 }
42
bsalomone904c092014-07-17 10:50:59 -070043 const GrGLExtensions& extensions() const { return fInterface->fExtensions; }
44
ethannicholas5961bc92016-10-12 06:39:56 -070045 virtual ~GrGLContextInfo() {}
46
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000047protected:
bsalomon424cc262015-05-22 10:37:30 -070048 struct ConstructorArgs {
49 const GrGLInterface* fInterface;
50 GrGLVersion fGLVersion;
51 GrGLSLGeneration fGLSLGeneration;
52 GrGLVendor fVendor;
53 GrGLRenderer fRenderer;
cdalton1acea862015-06-02 13:05:52 -070054 GrGLDriver fDriver;
55 GrGLDriverVersion fDriverVersion;
bsalomon682c2692015-05-22 14:01:46 -070056 const GrContextOptions* fContextOptions;
bsalomon424cc262015-05-22 10:37:30 -070057 };
58
59 GrGLContextInfo(const ConstructorArgs& args);
60
Hal Canary144caf52016-11-07 17:57:18 -050061 sk_sp<const GrGLInterface> fInterface;
62 GrGLVersion fGLVersion;
63 GrGLSLGeneration fGLSLGeneration;
64 GrGLVendor fVendor;
65 GrGLRenderer fRenderer;
66 GrGLDriver fDriver;
67 GrGLDriverVersion fDriverVersion;
68 sk_sp<GrGLCaps> fGLCaps;
robertphillips@google.com6177e692013-02-28 20:16:25 +000069};
70
71/**
ethannicholas5961bc92016-10-12 06:39:56 -070072 * Extension of GrGLContextInfo that also provides access to GrGLInterface and SkSL::Compiler.
robertphillips@google.com6177e692013-02-28 20:16:25 +000073 */
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000074class GrGLContext : public GrGLContextInfo {
robertphillips@google.com6177e692013-02-28 20:16:25 +000075public:
76 /**
robertphillips@google.com6177e692013-02-28 20:16:25 +000077 * Creates a GrGLContext from a GrGLInterface and the currently
78 * bound OpenGL context accessible by the GrGLInterface.
79 */
bsalomon682c2692015-05-22 14:01:46 -070080 static GrGLContext* Create(const GrGLInterface* interface, const GrContextOptions& options);
robertphillips@google.com6177e692013-02-28 20:16:25 +000081
Hal Canary144caf52016-11-07 17:57:18 -050082 const GrGLInterface* interface() const { return fInterface.get(); }
robertphillips@google.com6177e692013-02-28 20:16:25 +000083
ethannicholas5961bc92016-10-12 06:39:56 -070084 SkSL::Compiler* compiler() const;
85
86 ~GrGLContext() override;
87
robertphillips@google.com6177e692013-02-28 20:16:25 +000088private:
ethannicholas5961bc92016-10-12 06:39:56 -070089 GrGLContext(const ConstructorArgs& args)
90 : INHERITED(args)
91 , fCompiler(nullptr) {}
92
93 mutable SkSL::Compiler* fCompiler;
bsalomon424cc262015-05-22 10:37:30 -070094
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000095 typedef GrGLContextInfo INHERITED;
robertphillips@google.com6177e692013-02-28 20:16:25 +000096};
97
98#endif