blob: 7f46522af290cc681697402b6d18c758bf7667a3 [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"
15#include "GrGLSL.h"
16#include "GrGLUtil.h"
17
18#include "SkString.h"
19
20/**
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000021 * Encapsulates information about an OpenGL context including the OpenGL
commit-bot@chromium.org9e90aed2014-01-16 16:35:09 +000022 * version, the GrGLStandard type of the context, and GLSL version.
robertphillips@google.com6177e692013-02-28 20:16:25 +000023 */
24class GrGLContextInfo {
25public:
26 /**
27 * Default constructor
28 */
bsalomon@google.combcce8922013-03-25 15:38:39 +000029 GrGLContextInfo() {
30 fGLCaps.reset(SkNEW(GrGLCaps));
31 this->reset();
32 }
robertphillips@google.com6177e692013-02-28 20:16:25 +000033
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000034 GrGLContextInfo(const GrGLContextInfo& that) {
35 fGLCaps.reset(SkNEW(GrGLCaps));
36 *this = that;
37 }
38
39 GrGLContextInfo& operator= (const GrGLContextInfo&);
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000040
robertphillips@google.com6177e692013-02-28 20:16:25 +000041 /**
42 * Initializes a GrGLContextInfo from a GrGLInterface and the currently
43 * bound OpenGL context accessible by the GrGLInterface.
44 */
45 bool initialize(const GrGLInterface* interface);
46 bool isInitialized() const;
47
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000048 GrGLStandard standard() const { return fInterface->fStandard; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000049 GrGLVersion version() const { return fGLVersion; }
50 GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
51 GrGLVendor vendor() const { return fVendor; }
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000052 GrGLRenderer renderer() const { return fRenderer; }
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000053 /** Is this a mesa-based driver. Does not mean it is the osmesa software rasterizer. */
54 bool isMesa() const { return fIsMesa; }
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000055 /** Are we running inside Chromium (using the command buffer)? We make some different tradeoffs
56 about what errors to check for because queries are synchronous. We should probably expose
57 this as an option for clients other than Chromium. */
58 bool isChromium() const { return fIsChromium; }
bsalomon@google.combcce8922013-03-25 15:38:39 +000059 const GrGLCaps* caps() const { return fGLCaps.get(); }
60 GrGLCaps* caps() { return fGLCaps; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000061 bool hasExtension(const char* ext) const {
62 if (!this->isInitialized()) {
63 return false;
64 }
commit-bot@chromium.org90313cc2014-01-17 15:05:38 +000065 return fInterface->hasExtension(ext);
robertphillips@google.com6177e692013-02-28 20:16:25 +000066 }
67
bsalomone904c092014-07-17 10:50:59 -070068 const GrGLExtensions& extensions() const { return fInterface->fExtensions; }
69
robertphillips@google.com6177e692013-02-28 20:16:25 +000070 /**
71 * Reset the information
72 */
73 void reset();
74
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000075protected:
76 SkAutoTUnref<const GrGLInterface> fInterface;
77 GrGLVersion fGLVersion;
78 GrGLSLGeneration fGLSLGeneration;
79 GrGLVendor fVendor;
80 GrGLRenderer fRenderer;
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000081 bool fIsMesa;
82 bool fIsChromium;
83 SkAutoTUnref<GrGLCaps> fGLCaps;
robertphillips@google.com6177e692013-02-28 20:16:25 +000084};
85
86/**
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000087 * Extension of GrGLContextInfo that also provides access to GrGLInterface.
robertphillips@google.com6177e692013-02-28 20:16:25 +000088 */
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000089class GrGLContext : public GrGLContextInfo {
robertphillips@google.com6177e692013-02-28 20:16:25 +000090public:
91 /**
robertphillips@google.com6177e692013-02-28 20:16:25 +000092 * Creates a GrGLContext from a GrGLInterface and the currently
93 * bound OpenGL context accessible by the GrGLInterface.
94 */
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000095 explicit GrGLContext(const GrGLInterface* interface) {
96 this->initialize(interface);
97 }
robertphillips@google.com6177e692013-02-28 20:16:25 +000098
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +000099 GrGLContext(const GrGLContext& that) : INHERITED(that) {}
robertphillips@google.com6177e692013-02-28 20:16:25 +0000100
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000101 GrGLContext& operator= (const GrGLContext& that) {
102 this->INHERITED::operator=(that);
103 return *this;
104 }
robertphillips@google.com6177e692013-02-28 20:16:25 +0000105
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000106 const GrGLInterface* interface() const { return fInterface.get(); }
robertphillips@google.com6177e692013-02-28 20:16:25 +0000107
108private:
commit-bot@chromium.orgb1854a82014-01-16 18:39:04 +0000109 typedef GrGLContextInfo INHERITED;
robertphillips@google.com6177e692013-02-28 20:16:25 +0000110};
111
112#endif