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

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

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

Powered by Google App Engine
This is Rietveld 408576698