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

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

Issue 1815823002: Move SkGLContext and some GrGLInterface implementations to skgputest module (Closed) Base URL: https://chromium.googlesource.com/skia.git@debugobject
Patch Set: fix windows and android? 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 | « src/gpu/GrContextFactory.h ('k') | src/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 * Copyright 2014 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 #include "GrContextFactory.h"
9
10 #if SK_ANGLE
11 #include "gl/angle/SkANGLEGLContext.h"
12 #endif
13 #if SK_COMMAND_BUFFER
14 #include "gl/command_buffer/SkCommandBufferGLContext.h"
15 #endif
16 #include "gl/debug/SkDebugGLContext.h"
17 #if SK_MESA
18 #include "gl/mesa/SkMesaGLContext.h"
19 #endif
20 #if SK_VULKAN
21 #include "vk/GrVkBackendContext.h"
22 #endif
23 #include "gl/SkGLContext.h"
24 #include "gl/SkNullGLContext.h"
25 #include "gl/GrGLGpu.h"
26 #include "GrCaps.h"
27
28 GrContextFactory::GrContextFactory() { }
29
30 GrContextFactory::GrContextFactory(const GrContextOptions& opts)
31 : fGlobalOptions(opts) {
32 }
33
34 GrContextFactory::~GrContextFactory() {
35 this->destroyContexts();
36 }
37
38 void GrContextFactory::destroyContexts() {
39 for (Context& context : fContexts) {
40 if (context.fGLContext) {
41 context.fGLContext->makeCurrent();
42 }
43 if (!context.fGrContext->unique()) {
44 context.fGrContext->abandonContext();
45 }
46 context.fGrContext->unref();
47 delete(context.fGLContext);
48 }
49 fContexts.reset();
50 }
51
52 void GrContextFactory::abandonContexts() {
53 for (Context& context : fContexts) {
54 if (context.fGLContext) {
55 context.fGLContext->makeCurrent();
56 context.fGLContext->testAbandon();
57 delete(context.fGLContext);
58 context.fGLContext = nullptr;
59 }
60 context.fGrContext->abandonContext();
61 }
62 }
63
64 GrContextFactory::ContextInfo GrContextFactory::getContextInfo(GLContextType typ e,
65 GLContextOptions options) {
66 for (int i = 0; i < fContexts.count(); ++i) {
67 Context& context = fContexts[i];
68 if (!context.fGLContext) {
69 continue;
70 }
71 if (context.fType == type &&
72 context.fOptions == options) {
73 context.fGLContext->makeCurrent();
74 return ContextInfo(context.fGrContext, context.fGLContext);
75 }
76 }
77 SkAutoTDelete<SkGLContext> glCtx;
78 SkAutoTUnref<GrContext> grCtx;
79 switch (type) {
80 case kNative_GLContextType:
81 glCtx.reset(SkCreatePlatformGLContext(kNone_GrGLStandard));
82 break;
83 case kGL_GLContextType:
84 glCtx.reset(SkCreatePlatformGLContext(kGL_GrGLStandard));
85 break;
86 case kGLES_GLContextType:
87 glCtx.reset(SkCreatePlatformGLContext(kGLES_GrGLStandard));
88 break;
89 #if SK_ANGLE
90 #ifdef SK_BUILD_FOR_WIN
91 case kANGLE_GLContextType:
92 glCtx.reset(SkANGLEGLContext::CreateDirectX());
93 break;
94 #endif
95 case kANGLE_GL_GLContextType:
96 glCtx.reset(SkANGLEGLContext::CreateOpenGL());
97 break;
98 #endif
99 #if SK_COMMAND_BUFFER
100 case kCommandBuffer_GLContextType:
101 glCtx.reset(SkCommandBufferGLContext::Create());
102 break;
103 #endif
104 #if SK_MESA
105 case kMESA_GLContextType:
106 glCtx.reset(SkMesaGLContext::Create());
107 break;
108 #endif
109 case kNull_GLContextType:
110 glCtx.reset(SkNullGLContext::Create());
111 break;
112 case kDebug_GLContextType:
113 glCtx.reset(SkDebugGLContext::Create());
114 break;
115 }
116 if (nullptr == glCtx.get()) {
117 return ContextInfo();
118 }
119
120 SkASSERT(glCtx->isValid());
121
122 // Block NVPR from non-NVPR types.
123 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx->gl()));
124 if (!(kEnableNVPR_GLContextOptions & options)) {
125 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface));
126 if (!glInterface) {
127 return ContextInfo();
128 }
129 }
130
131 glCtx->makeCurrent();
132 #ifdef SK_VULKAN
133 if (kEnableNVPR_GLContextOptions & options) {
134 return ContextInfo();
135 } else {
136 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(GrVkBackend Context::Create());
137 grCtx.reset(GrContext::Create(kVulkan_GrBackend, p3dctx, fGlobalOptions) );
138 }
139 #else
140 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface.get ());
141 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx, fGlobalOptions));
142 #endif
143 if (!grCtx.get()) {
144 return ContextInfo();
145 }
146 if (kEnableNVPR_GLContextOptions & options) {
147 if (!grCtx->caps()->shaderCaps()->pathRenderingSupport()) {
148 return ContextInfo();
149 }
150 }
151 if (kRequireSRGBSupport_GLContextOptions & options) {
152 if (!grCtx->caps()->srgbSupport()) {
153 return ContextInfo();
154 }
155 }
156
157 Context& context = fContexts.push_back();
158 context.fGLContext = glCtx.release();
159 context.fGrContext = SkRef(grCtx.get());
160 context.fType = type;
161 context.fOptions = options;
162 return ContextInfo(context.fGrContext, context.fGLContext);
163 }
OLDNEW
« no previous file with comments | « src/gpu/GrContextFactory.h ('k') | src/gpu/GrTest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698