blob: ac9e9ed900e3fcac845bb60179ba7913f5f11a52 [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.org459104c2013-06-14 14:42:56 +000050 /** Is this a mesa-based driver. Does not mean it is the osmesa software rasterizer. */
51 bool isMesa() const { return fIsMesa; }
bsalomon@google.combcce8922013-03-25 15:38:39 +000052 const GrGLCaps* caps() const { return fGLCaps.get(); }
53 GrGLCaps* caps() { return fGLCaps; }
bsalomon@google.com00142c42013-05-02 19:42:54 +000054 const GrGLExtensions& extensions() const { return fExtensions; }
robertphillips@google.com6177e692013-02-28 20:16:25 +000055
56 /**
bsalomon@google.com00142c42013-05-02 19:42:54 +000057 * Shortcut for extensions().has(ext);
robertphillips@google.com6177e692013-02-28 20:16:25 +000058 */
59 bool hasExtension(const char* ext) const {
60 if (!this->isInitialized()) {
61 return false;
62 }
63 return fExtensions.has(ext);
64 }
65
66 /**
67 * Reset the information
68 */
69 void reset();
70
71private:
72
bsalomon@google.combcce8922013-03-25 15:38:39 +000073 GrGLBinding fBindingInUse;
74 GrGLVersion fGLVersion;
75 GrGLSLGeneration fGLSLGeneration;
76 GrGLVendor fVendor;
77 GrGLExtensions fExtensions;
commit-bot@chromium.org459104c2013-06-14 14:42:56 +000078 bool fIsMesa;
bsalomon@google.combcce8922013-03-25 15:38:39 +000079 SkAutoTUnref<GrGLCaps> fGLCaps;
robertphillips@google.com6177e692013-02-28 20:16:25 +000080};
81
82/**
83 * Encapsulates the GrGLInterface used to make GL calls plus information
84 * about the context (via GrGLContextInfo).
85 */
86class GrGLContext {
87public:
88 /**
89 * Default constructor
90 */
91 GrGLContext() { this->reset(); }
92
93 /**
94 * Creates a GrGLContext from a GrGLInterface and the currently
95 * bound OpenGL context accessible by the GrGLInterface.
96 */
97 explicit GrGLContext(const GrGLInterface* interface);
98
99 /**
100 * Copies a GrGLContext
101 */
102 GrGLContext(const GrGLContext& ctx);
103
commit-bot@chromium.orga4de8c22013-09-09 13:38:37 +0000104 ~GrGLContext() { SkSafeUnref(fInterface); }
robertphillips@google.com6177e692013-02-28 20:16:25 +0000105
106 /**
107 * Copies a GrGLContext
108 */
109 GrGLContext& operator= (const GrGLContext& ctx);
110
111 /**
112 * Initializes a GrGLContext from a GrGLInterface and the currently
113 * bound OpenGL context accessible by the GrGLInterface.
114 */
115 bool initialize(const GrGLInterface* interface);
116 bool isInitialized() const { return fInfo.isInitialized(); }
117
118 const GrGLInterface* interface() const { return fInterface; }
119 const GrGLContextInfo& info() const { return fInfo; }
120 GrGLContextInfo& info() { return fInfo; }
121
122private:
123 void reset();
124
125 const GrGLInterface* fInterface;
126 GrGLContextInfo fInfo;
127};
128
129#endif