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

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

Issue 1448883002: Make NVPR a GL context option instead of a GL context (Closed) Base URL: https://skia.googlesource.com/skia.git@commandbuffer-as-api-02-other-tests-refactor
Patch Set: Created 5 years 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
11 #include "GrContext.h" 11 #include "GrContext.h"
12 #include "GrContextOptions.h" 12 #include "GrContextOptions.h"
13 13
14 #include "gl/SkGLContext.h" 14 #include "gl/SkGLContext.h"
15 #include "SkTArray.h" 15 #include "SkTArray.h"
16 16
17 /** 17 /**
18 * This is a simple class that is useful in test apps that use different 18 * This is a simple class that is useful in test apps that use different
19 * GrContexts backed by different types of GL contexts. It manages creating the 19 * GrContexts backed by different types of GL contexts. It manages creating the
20 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the 20 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the
21 * factory is destroyed (though the caller can always grab a ref on the returned 21 * factory is destroyed (though the caller can always grab a ref on the returned
22 * Gr and GL contexts to make them outlive the factory). 22 * Gr and GL contexts to make them outlive the factory).
23 */ 23 */
24 class GrContextFactory : SkNoncopyable { 24 class GrContextFactory : SkNoncopyable {
25 public: 25 public:
26 /**
27 * Types of GL contexts supported. For historical and testing reasons the na tive GrContext will
28 * not use "GL_NV_path_rendering" even when the driver supports it. There is a separate context
29 * type that does not remove NVPR support and which will fail when the drive r does not support
30 * the extension.
31 */
32 enum GLContextType { 26 enum GLContextType {
33 kNative_GLContextType, 27 kNative_GLContextType,
34 #if SK_ANGLE 28 #if SK_ANGLE
35 kANGLE_GLContextType, 29 kANGLE_GLContextType,
36 kANGLE_GL_GLContextType, 30 kANGLE_GL_GLContextType,
37 #endif 31 #endif
38 #if SK_COMMAND_BUFFER 32 #if SK_COMMAND_BUFFER
39 kCommandBuffer_GLContextType, 33 kCommandBuffer_GLContextType,
40 #endif 34 #endif
41 #if SK_MESA 35 #if SK_MESA
42 kMESA_GLContextType, 36 kMESA_GLContextType,
43 #endif 37 #endif
44 /** Similar to kNative but does not filter NVPR. It will fail if the GL dr iver does not 38 kNull_GLContextType,
45 support NVPR */ 39 kDebug_GLContextType,
46 kNVPR_GLContextType, 40 kLastGLContextType = kDebug_GLContextType
47 kNull_GLContextType,
48 kDebug_GLContextType,
49
50 kLastGLContextType = kDebug_GLContextType
51 }; 41 };
52 42
53 static const int kGLContextTypeCnt = kLastGLContextType + 1; 43 static const int kGLContextTypeCnt = kLastGLContextType + 1;
54 44
45 /**
46 * Options for GL context creation. For historical and testing reasons the o ptions will default
47 * to not using GL_NV_path_rendering extension even when the driver support s it.
48 */
49 enum GLContextOptions {
50 kNone_GLContextOptions = 0,
51 kEnableNVPR_GLContextOptions = 0x1,
52 };
53
55 static bool IsRenderingGLContext(GLContextType type) { 54 static bool IsRenderingGLContext(GLContextType type) {
56 switch (type) { 55 switch (type) {
57 case kNull_GLContextType: 56 case kNull_GLContextType:
58 case kDebug_GLContextType: 57 case kDebug_GLContextType:
59 return false; 58 return false;
60 default: 59 default:
61 return true; 60 return true;
62 } 61 }
63 } 62 }
64 63
(...skipping 10 matching lines...) Expand all
75 return "angle-gl"; 74 return "angle-gl";
76 #endif 75 #endif
77 #if SK_COMMAND_BUFFER 76 #if SK_COMMAND_BUFFER
78 case kCommandBuffer_GLContextType: 77 case kCommandBuffer_GLContextType:
79 return "commandbuffer"; 78 return "commandbuffer";
80 #endif 79 #endif
81 #if SK_MESA 80 #if SK_MESA
82 case kMESA_GLContextType: 81 case kMESA_GLContextType:
83 return "mesa"; 82 return "mesa";
84 #endif 83 #endif
85 case kNVPR_GLContextType:
86 return "nvpr";
87 case kDebug_GLContextType: 84 case kDebug_GLContextType:
88 return "debug"; 85 return "debug";
89 default: 86 default:
90 SkFAIL("Unknown GL Context type."); 87 SkFAIL("Unknown GL Context type.");
91 } 88 }
92 } 89 }
93 90
94 explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opt s) { } 91 explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opt s) { }
95 GrContextFactory() { } 92 GrContextFactory() { }
96 93
(...skipping 15 matching lines...) Expand all
112 if (fContexts[i]->fGLContext) { 109 if (fContexts[i]->fGLContext) {
113 fContexts[i]->fGLContext->testAbandon(); 110 fContexts[i]->fGLContext->testAbandon();
114 SkSafeSetNull(fContexts[i]->fGLContext); 111 SkSafeSetNull(fContexts[i]->fGLContext);
115 } 112 }
116 fContexts[i]->fGrContext->abandonContext(); 113 fContexts[i]->fGrContext->abandonContext();
117 } 114 }
118 } 115 }
119 116
120 struct ContextInfo { 117 struct ContextInfo {
121 GLContextType fType; 118 GLContextType fType;
119 GLContextOptions fOptions;
122 SkGLContext* fGLContext; 120 SkGLContext* fGLContext;
123 GrContext* fGrContext; 121 GrContext* fGrContext;
124 }; 122 };
125 /** 123 /**
126 * Get a context initialized with a type of GL context. It also makes the GL context current. 124 * 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. 125 * Pointer is valid until destroyContexts() is called.
128 */ 126 */
129 ContextInfo* getContextInfo(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLStandard); 127 ContextInfo* getContextInfo(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLStandard, GLContextOptions options = kNone_GLContextOptions);
130 128
131 /** 129 /**
132 * Get a GrContext initialized with a type of GL context. It also makes the GL context current. 130 * Get a GrContext initialized with a type of GL context. It also makes the GL context current.
133 */ 131 */
134 GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLSta ndard) { 132 GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLSta ndard,
135 if (ContextInfo* info = this->getContextInfo(type, forcedGpuAPI)) { 133 GLContextOptions options = kNone_GLContextOptions) {
134 if (ContextInfo* info = this->getContextInfo(type, forcedGpuAPI, options )) {
136 return info->fGrContext; 135 return info->fGrContext;
137 } 136 }
138 return nullptr; 137 return nullptr;
139 } 138 }
140 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } 139 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; }
141 140
142 private: 141 private:
143 SkTArray<SkAutoTDelete<ContextInfo>, true> fContexts; 142 SkTArray<SkAutoTDelete<ContextInfo>, true> fContexts;
144 const GrContextOptions fGlobalOptions; 143 const GrContextOptions fGlobalOptions;
145 }; 144 };
146 145
147 #endif 146 #endif
OLDNEW
« no previous file with comments | « dm/DMSrcSink.cpp ('k') | src/gpu/GrContextFactory.cpp » ('j') | src/gpu/GrContextFactory.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698