blob: b6e1ab3942ce803155963a27d9c5eea9b81273e2 [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; }
bsalomon@google.combcce8922013-03-25 15:38:39 +000053 const GrGLCaps* caps() const { return fGLCaps.get(); }
54 GrGLCaps* caps() { return fGLCaps; }
bsalomon@google.com00142c42013-05-02 19:42:54 +000055 const GrGLExtensions& extensions() const { return fExtensions; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000056
57 /**
bsalomon@google.com00142c42013-05-02 19:42:54 +000058 * Shortcut for extensions().has(ext);
robertphillips@google.com6177e692013-02-28 20:16:25 +000059 */
60 bool hasExtension(const char* ext) const {
61 if (!this->isInitialized()) {
62 return false;
63 }
64 return fExtensions.has(ext);
65 }
66
67 /**
68 * Reset the information
69 */
70 void reset();
71
72private:
73
bsalomon@google.combcce8922013-03-25 15:38:39 +000074 GrGLBinding fBindingInUse;
75 GrGLVersion fGLVersion;
76 GrGLSLGeneration fGLSLGeneration;
77 GrGLVendor fVendor;
commit-bot@chromium.org0694ea72013-09-18 13:00:28 +000078 GrGLRenderer fRenderer;
bsalomon@google.combcce8922013-03-25 15:38:39 +000079 GrGLExtensions fExtensions;
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000080 bool fIsMesa;
bsalomon@google.combcce8922013-03-25 15:38:39 +000081 SkAutoTUnref<GrGLCaps> fGLCaps;
robertphillips@google.com6177e692013-02-28 20:16:25 +000082};
83
84/**
85 * Encapsulates the GrGLInterface used to make GL calls plus information
86 * about the context (via GrGLContextInfo).
87 */
88class GrGLContext {
89public:
90 /**
91 * Default constructor
92 */
93 GrGLContext() { this->reset(); }
94
95 /**
96 * Creates a GrGLContext from a GrGLInterface and the currently
97 * bound OpenGL context accessible by the GrGLInterface.
98 */
99 explicit GrGLContext(const GrGLInterface* interface);
100
101 /**
102 * Copies a GrGLContext
103 */
104 GrGLContext(const GrGLContext& ctx);
105
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000106 ~GrGLContext() { SkSafeUnref(fInterface); }
robertphillips@google.com6177e692013-02-28 20:16:25 +0000107
108 /**
109 * Copies a GrGLContext
110 */
111 GrGLContext& operator= (const GrGLContext& ctx);
112
113 /**
114 * Initializes a GrGLContext from a GrGLInterface and the currently
115 * bound OpenGL context accessible by the GrGLInterface.
116 */
117 bool initialize(const GrGLInterface* interface);
118 bool isInitialized() const { return fInfo.isInitialized(); }
119
120 const GrGLInterface* interface() const { return fInterface; }
121 const GrGLContextInfo& info() const { return fInfo; }
122 GrGLContextInfo& info() { return fInfo; }
123
124private:
125 void reset();
126
127 const GrGLInterface* fInterface;
128 GrGLContextInfo fInfo;
129};
130
131#endif