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

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

Issue 1446453003: Generate list of GPU contexts outside SurfaceTest tests (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: msvc fixes Created 5 years, 1 month 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
« no previous file with comments | « dm/DM.cpp ('k') | src/gpu/GrContextFactory.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 91 }
92 } 92 }
93 93
94 explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opt s) { } 94 explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opt s) { }
95 GrContextFactory() { } 95 GrContextFactory() { }
96 96
97 ~GrContextFactory() { this->destroyContexts(); } 97 ~GrContextFactory() { this->destroyContexts(); }
98 98
99 void destroyContexts() { 99 void destroyContexts() {
100 for (int i = 0; i < fContexts.count(); ++i) { 100 for (int i = 0; i < fContexts.count(); ++i) {
101 if (fContexts[i].fGLContext) { // could be abandoned. 101 if (fContexts[i]->fGLContext) { // could be abandoned.
102 fContexts[i].fGLContext->makeCurrent(); 102 fContexts[i]->fGLContext->makeCurrent();
103 } 103 }
104 fContexts[i].fGrContext->unref(); 104 fContexts[i]->fGrContext->unref();
105 if (fContexts[i].fGLContext) { 105 SkSafeUnref(fContexts[i]->fGLContext);
106 fContexts[i].fGLContext->unref();
107 }
108 } 106 }
109 fContexts.reset(); 107 fContexts.reset();
110 } 108 }
111 109
112 void abandonContexts() { 110 void abandonContexts() {
113 for (int i = 0; i < fContexts.count(); ++i) { 111 for (int i = 0; i < fContexts.count(); ++i) {
114 if (fContexts[i].fGLContext) { 112 if (fContexts[i]->fGLContext) {
115 fContexts[i].fGLContext->testAbandon(); 113 fContexts[i]->fGLContext->testAbandon();
116 SkSafeSetNull(fContexts[i].fGLContext); 114 SkSafeSetNull(fContexts[i]->fGLContext);
117 } 115 }
118 fContexts[i].fGrContext->abandonContext(); 116 fContexts[i]->fGrContext->abandonContext();
119 } 117 }
120 } 118 }
121 119
120 struct ContextInfo {
121 GLContextType fType;
122 SkGLContext* fGLContext;
123 GrContext* fGrContext;
124 };
125 /**
126 * Get a context initialized with a type of GL context. It also makes the GL context current.
127 * Pointer is valid until destroyContexts() is called.
128 */
129 ContextInfo* getContextInfo(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLStandard);
130
122 /** 131 /**
123 * Get a GrContext initialized with a type of GL context. It also makes the GL context current. 132 * Get a GrContext initialized with a type of GL context. It also makes the GL context current.
124 */ 133 */
125 GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLSta ndard); 134 GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLSta ndard) {
126 135 if (ContextInfo* info = this->getContextInfo(type, forcedGpuAPI)) {
136 return info->fGrContext;
137 }
138 return nullptr;
139 }
127 140
128 // Returns the GLContext of the given type. If it has not been created yet, 141 // Returns the GLContext of the given type. If it has not been created yet,
129 // nullptr is returned instead. 142 // nullptr is returned instead.
130 SkGLContext* getGLContext(GLContextType type) { 143 SkGLContext* getGLContext(GLContextType type) {
131 for (int i = 0; i < fContexts.count(); ++i) { 144 for (int i = 0; i < fContexts.count(); ++i) {
132 if (fContexts[i].fType == type) { 145 if (fContexts[i]->fType == type) {
133 return fContexts[i].fGLContext; 146 return fContexts[i]->fGLContext;
134 } 147 }
135 } 148 }
136 149
137 return nullptr; 150 return nullptr;
138 } 151 }
139 152
140 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } 153 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; }
141 154
142 private: 155 private:
143 struct GPUContext { 156 SkTArray<SkAutoTDelete<ContextInfo>, true> fContexts;
144 GLContextType fType;
145 SkGLContext* fGLContext;
146 GrContext* fGrContext;
147 };
148 SkTArray<GPUContext, true> fContexts;
149 const GrContextOptions fGlobalOptions; 157 const GrContextOptions fGlobalOptions;
150 }; 158 };
151 159
152 #endif 160 #endif
OLDNEW
« no previous file with comments | « dm/DM.cpp ('k') | src/gpu/GrContextFactory.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698