Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(631)

Side by Side Diff: include/gpu/GrContextFactory.h

Issue 319043005: Support using OpenGL ES context on desktop (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2012 Google Inc. 2 * Copyright 2012 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef GrContextFactory_DEFINED 8 #ifndef GrContextFactory_DEFINED
9 #define GrContextFactory_DEFINED 9 #define GrContextFactory_DEFINED
10 10
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 #endif 81 #endif
82 case kNVPR_GLContextType: 82 case kNVPR_GLContextType:
83 return "nvpr"; 83 return "nvpr";
84 case kDebug_GLContextType: 84 case kDebug_GLContextType:
85 return "debug"; 85 return "debug";
86 default: 86 default:
87 SkFAIL("Unknown GL Context type."); 87 SkFAIL("Unknown GL Context type.");
88 } 88 }
89 } 89 }
90 90
91 GrContextFactory() { 91 GrContextFactory() { }
92 }
93 92
94 ~GrContextFactory() { this->destroyContexts(); } 93 ~GrContextFactory() { this->destroyContexts(); }
95 94
96 void destroyContexts() { 95 void destroyContexts() {
97 for (int i = 0; i < fContexts.count(); ++i) { 96 for (int i = 0; i < fContexts.count(); ++i) {
98 fContexts[i].fGLContext->makeCurrent(); 97 fContexts[i].fGLContext->makeCurrent();
99 fContexts[i].fGrContext->unref(); 98 fContexts[i].fGrContext->unref();
100 fContexts[i].fGLContext->unref(); 99 fContexts[i].fGLContext->unref();
101 } 100 }
102 fContexts.reset(); 101 fContexts.reset();
103 } 102 }
104 103
105 /** 104 /**
106 * Get a GrContext initialized with a type of GL context. It also makes the GL context current. 105 * Get a GrContext initialized with a type of GL context. It also makes the GL context current.
107 */ 106 */
108 GrContext* get(GLContextType type) { 107 GrContext* get(GLContextType type, GrGLStandard forcedApi) {
109 108
110 for (int i = 0; i < fContexts.count(); ++i) { 109 for (int i = 0; i < fContexts.count(); ++i) {
110 if (forcedApi != kNone_GrGLStandard &&
111 forcedApi != fContexts[i].fGLContext->gl()->fStandard)
112 continue;
113
111 if (fContexts[i].fType == type) { 114 if (fContexts[i].fType == type) {
112 fContexts[i].fGLContext->makeCurrent(); 115 fContexts[i].fGLContext->makeCurrent();
113 return fContexts[i].fGrContext; 116 return fContexts[i].fGrContext;
114 } 117 }
115 } 118 }
116 SkAutoTUnref<SkGLContextHelper> glCtx; 119 SkAutoTUnref<SkGLContextHelper> glCtx;
117 SkAutoTUnref<GrContext> grCtx; 120 SkAutoTUnref<GrContext> grCtx;
118 switch (type) { 121 switch (type) {
119 case kNVPR_GLContextType: // fallthru 122 case kNVPR_GLContextType: // fallthru
120 case kNative_GLContextType: 123 case kNative_GLContextType:
(...skipping 13 matching lines...) Expand all
134 glCtx.reset(SkNEW(SkNullGLContext)); 137 glCtx.reset(SkNEW(SkNullGLContext));
135 break; 138 break;
136 case kDebug_GLContextType: 139 case kDebug_GLContextType:
137 glCtx.reset(SkNEW(SkDebugGLContext)); 140 glCtx.reset(SkNEW(SkDebugGLContext));
138 break; 141 break;
139 } 142 }
140 static const int kBogusSize = 1; 143 static const int kBogusSize = 1;
141 if (!glCtx.get()) { 144 if (!glCtx.get()) {
142 return NULL; 145 return NULL;
143 } 146 }
144 if (!glCtx.get()->init(kBogusSize, kBogusSize)) { 147 if (!glCtx.get()->init(forcedApi, kBogusSize, kBogusSize)) {
145 return NULL; 148 return NULL;
146 } 149 }
147 150
148 // Ensure NVPR is available for the NVPR type and block it from other ty pes. 151 // Ensure NVPR is available for the NVPR type and block it from other ty pes.
149 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx.get()->gl())); 152 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx.get()->gl()));
150 if (kNVPR_GLContextType == type) { 153 if (kNVPR_GLContextType == type) {
151 if (!glInterface->hasExtension("GL_NV_path_rendering")) { 154 if (!glInterface->hasExtension("GL_NV_path_rendering")) {
152 return NULL; 155 return NULL;
153 } 156 }
154 } else { 157 } else {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 private: 191 private:
189 struct GPUContext { 192 struct GPUContext {
190 GLContextType fType; 193 GLContextType fType;
191 SkGLContextHelper* fGLContext; 194 SkGLContextHelper* fGLContext;
192 GrContext* fGrContext; 195 GrContext* fGrContext;
193 }; 196 };
194 SkTArray<GPUContext, true> fContexts; 197 SkTArray<GPUContext, true> fContexts;
195 }; 198 };
196 199
197 #endif 200 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698