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

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

Issue 1555053003: Revert of Make SkGLContext lifetime more well-defined (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « src/gpu/GrContextFactory.h ('k') | tests/EGLImageTest.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 /* 2 /*
3 * Copyright 2014 Google Inc. 3 * Copyright 2014 Google Inc.
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "GrContextFactory.h" 9 #include "GrContextFactory.h"
10 10
11 #if SK_ANGLE 11 #if SK_ANGLE
12 #include "gl/angle/SkANGLEGLContext.h" 12 #include "gl/angle/SkANGLEGLContext.h"
13 #endif 13 #endif
14 #if SK_COMMAND_BUFFER 14 #if SK_COMMAND_BUFFER
15 #include "gl/command_buffer/SkCommandBufferGLContext.h" 15 #include "gl/command_buffer/SkCommandBufferGLContext.h"
16 #endif 16 #endif
17 #include "gl/debug/SkDebugGLContext.h" 17 #include "gl/debug/SkDebugGLContext.h"
18 #if SK_MESA 18 #if SK_MESA
19 #include "gl/mesa/SkMesaGLContext.h" 19 #include "gl/mesa/SkMesaGLContext.h"
20 #endif 20 #endif
21 #include "gl/SkGLContext.h" 21 #include "gl/SkGLContext.h"
22 #include "gl/SkNullGLContext.h" 22 #include "gl/SkNullGLContext.h"
23 #include "gl/GrGLGpu.h" 23 #include "gl/GrGLGpu.h"
24 #include "GrCaps.h" 24 #include "GrCaps.h"
25 25
26 GrContextFactory::GrContextFactory() { } 26 GrContextFactory::ContextInfo* GrContextFactory::getContextInfo(GLContextType ty pe,
27 27 GLContextOptions options) {
28 GrContextFactory::GrContextFactory(const GrContextOptions& opts)
29 : fGlobalOptions(opts) {
30 }
31
32 GrContextFactory::~GrContextFactory() {
33 this->destroyContexts();
34 }
35
36 void GrContextFactory::destroyContexts() {
37 for (Context& context : fContexts) {
38 if (context.fGLContext) {
39 context.fGLContext->makeCurrent();
40 }
41 if (!context.fGrContext->unique()) {
42 context.fGrContext->abandonContext();
43 }
44 context.fGrContext->unref();
45 delete(context.fGLContext);
46 }
47 fContexts.reset();
48 }
49
50 void GrContextFactory::abandonContexts() {
51 for (Context& context : fContexts) {
52 if (context.fGLContext) {
53 context.fGLContext->makeCurrent();
54 context.fGLContext->testAbandon();
55 delete(context.fGLContext);
56 context.fGLContext = nullptr;
57 }
58 context.fGrContext->abandonContext();
59 }
60 }
61
62 GrContextFactory::ContextInfo GrContextFactory::getContextInfo(GLContextType typ e,
63 GLContextOptions options) {
64 for (int i = 0; i < fContexts.count(); ++i) { 28 for (int i = 0; i < fContexts.count(); ++i) {
65 Context& context = fContexts[i]; 29 if (fContexts[i]->fType == type &&
66 if (!context.fGLContext) { 30 fContexts[i]->fOptions == options) {
67 continue; 31 fContexts[i]->fGLContext->makeCurrent();
68 } 32 return fContexts[i];
69 if (context.fType == type &&
70 context.fOptions == options) {
71 context.fGLContext->makeCurrent();
72 return ContextInfo(context.fGrContext, context.fGLContext);
73 } 33 }
74 } 34 }
75 SkAutoTDelete<SkGLContext> glCtx; 35 SkAutoTUnref<SkGLContext> glCtx;
76 SkAutoTUnref<GrContext> grCtx; 36 SkAutoTUnref<GrContext> grCtx;
77 switch (type) { 37 switch (type) {
78 case kNative_GLContextType: 38 case kNative_GLContextType:
79 glCtx.reset(SkCreatePlatformGLContext(kNone_GrGLStandard)); 39 glCtx.reset(SkCreatePlatformGLContext(kNone_GrGLStandard));
80 break; 40 break;
81 case kGL_GLContextType: 41 case kGL_GLContextType:
82 glCtx.reset(SkCreatePlatformGLContext(kGL_GrGLStandard)); 42 glCtx.reset(SkCreatePlatformGLContext(kGL_GrGLStandard));
83 break; 43 break;
84 case kGLES_GLContextType: 44 case kGLES_GLContextType:
85 glCtx.reset(SkCreatePlatformGLContext(kGLES_GrGLStandard)); 45 glCtx.reset(SkCreatePlatformGLContext(kGLES_GrGLStandard));
(...skipping 19 matching lines...) Expand all
105 break; 65 break;
106 #endif 66 #endif
107 case kNull_GLContextType: 67 case kNull_GLContextType:
108 glCtx.reset(SkNullGLContext::Create()); 68 glCtx.reset(SkNullGLContext::Create());
109 break; 69 break;
110 case kDebug_GLContextType: 70 case kDebug_GLContextType:
111 glCtx.reset(SkDebugGLContext::Create()); 71 glCtx.reset(SkDebugGLContext::Create());
112 break; 72 break;
113 } 73 }
114 if (nullptr == glCtx.get()) { 74 if (nullptr == glCtx.get()) {
115 return ContextInfo(); 75 return nullptr;
116 } 76 }
117 77
118 SkASSERT(glCtx->isValid()); 78 SkASSERT(glCtx->isValid());
119 79
120 // Block NVPR from non-NVPR types. 80 // Block NVPR from non-NVPR types.
121 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl())); 81 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl()));
122 if (!(kEnableNVPR_GLContextOptions & options)) { 82 if (!(kEnableNVPR_GLContextOptions & options)) {
123 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); 83 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface));
124 if (!glInterface) { 84 if (!glInterface) {
125 return ContextInfo(); 85 return nullptr;
126 } 86 }
127 } 87 }
128 88
129 glCtx->makeCurrent(); 89 glCtx->makeCurrent();
130 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get ()); 90 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get ());
131 #ifdef SK_VULKAN 91 #ifdef SK_VULKAN
132 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions)); 92 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions));
133 #else 93 #else
134 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions)); 94 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions));
135 #endif 95 #endif
136 if (!grCtx.get()) { 96 if (!grCtx.get()) {
137 return ContextInfo(); 97 return nullptr;
138 } 98 }
139 if (kEnableNVPR_GLContextOptions & options) { 99 if (kEnableNVPR_GLContextOptions & options) {
140 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) { 100 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) {
141 return ContextInfo(); 101 return nullptr;
142 } 102 }
143 } 103 }
144 104
145 Context& context = fContexts.push_back(); 105 ContextInfo* ctx = fContexts.emplace_back(new ContextInfo);
146 context.fGLContext = glCtx.detach(); 106 ctx->fGLContext = SkRef(glCtx.get());
147 context.fGrContext = SkRef(grCtx.get()); 107 ctx->fGrContext = SkRef(grCtx.get());
148 context.fType = type; 108 ctx->fType = type;
149 context.fOptions = options; 109 ctx->fOptions = options;
150 return ContextInfo(context.fGrContext, context.fGLContext); 110 return ctx;
151 } 111 }
OLDNEW
« no previous file with comments | « src/gpu/GrContextFactory.h ('k') | tests/EGLImageTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698