blob: d2174c56c8c23310cabdaaa0e1f547948da609b1 [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
robertphillips@google.com6177e692013-02-28 20:16:25 +000022 * version, the GrGLBinding type of the context, and GLSL version.
23 */
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
34 /**
35 * Copies a GrGLContextInfo
36 */
37 GrGLContextInfo& operator= (const GrGLContextInfo& ctxInfo);
skia.committer@gmail.com631cdcb2013-03-01 12:12:55 +000038
robertphillips@google.com6177e692013-02-28 20:16:25 +000039 /**
40 * Initializes a GrGLContextInfo from a GrGLInterface and the currently
41 * bound OpenGL context accessible by the GrGLInterface.
42 */
43 bool initialize(const GrGLInterface* interface);
44 bool isInitialized() const;
45
46 GrGLBinding binding() const { return fBindingInUse; }
47 GrGLVersion version() const { return fGLVersion; }
48 GrGLSLGeneration glslGeneration() const { return fGLSLGeneration; }
49 GrGLVendor vendor() const { return fVendor; }
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000050 GrGLRenderer renderer() const { return fRenderer; }
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000051 /** Is this a mesa-based driver. Does not mean it is the osmesa software rasterizer. */
52 bool isMesa() const { return fIsMesa; }
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000053 /** Are we running inside Chromium (using the command buffer)? We make some different tradeoffs
54 about what errors to check for because queries are synchronous. We should probably expose
55 this as an option for clients other than Chromium. */
56 bool isChromium() const { return fIsChromium; }
bsalomon@google.combcce8922013-03-25 15:38:39 +000057 const GrGLCaps* caps() const { return fGLCaps.get(); }
58 GrGLCaps* caps() { return fGLCaps; }
bsalomon@google.com00142c42013-05-02 19:42:54 +000059 const GrGLExtensions& extensions() const { return fExtensions; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000060
61 /**
bsalomon@google.com00142c42013-05-02 19:42:54 +000062 * Shortcut for extensions().has(ext);
robertphillips@google.com6177e692013-02-28 20:16:25 +000063 */
64 bool hasExtension(const char* ext) const {
65 if (!this->isInitialized()) {
66 return false;
67 }
68 return fExtensions.has(ext);
69 }
70
71 /**
72 * Reset the information
73 */
74 void reset();
75
76private:
77
bsalomon@google.combcce8922013-03-25 15:38:39 +000078 GrGLBinding fBindingInUse;
79 GrGLVersion fGLVersion;
80 GrGLSLGeneration fGLSLGeneration;
81 GrGLVendor fVendor;
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000082 GrGLRenderer fRenderer;
bsalomon@google.combcce8922013-03-25 15:38:39 +000083 GrGLExtensions fExtensions;
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000084 bool fIsMesa;
commit-bot@chromium.orgc9424b82013-10-30 20:03:16 +000085 bool fIsChromium;
bsalomon@google.combcce8922013-03-25 15:38:39 +000086 SkAutoTUnref<GrGLCaps> fGLCaps;
robertphillips@google.com6177e692013-02-28 20:16:25 +000087};
88
89/**
90 * Encapsulates the GrGLInterface used to make GL calls plus information
91 * about the context (via GrGLContextInfo).
92 */
93class GrGLContext {
94public:
95 /**
96 * Default constructor
97 */
98 GrGLContext() { this->reset(); }
99
100 /**
101 * Creates a GrGLContext from a GrGLInterface and the currently
102 * bound OpenGL context accessible by the GrGLInterface.
103 */
104 explicit GrGLContext(const GrGLInterface* interface);
105
106 /**
107 * Copies a GrGLContext
108 */
109 GrGLContext(const GrGLContext& ctx);
110
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000111 ~GrGLContext() { SkSafeUnref(fInterface); }
robertphillips@google.com6177e692013-02-28 20:16:25 +0000112
113 /**
114 * Copies a GrGLContext
115 */
116 GrGLContext& operator= (const GrGLContext& ctx);
117
118 /**
119 * Initializes a GrGLContext from a GrGLInterface and the currently
120 * bound OpenGL context accessible by the GrGLInterface.
121 */
122 bool initialize(const GrGLInterface* interface);
123 bool isInitialized() const { return fInfo.isInitialized(); }
124
125 const GrGLInterface* interface() const { return fInterface; }
126 const GrGLContextInfo& info() const { return fInfo; }
127 GrGLContextInfo& info() { return fInfo; }
128
129private:
130 void reset();
131
132 const GrGLInterface* fInterface;
133 GrGLContextInfo fInfo;
134};
135
136#endif