Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 #if SK_ANGLE | 11 #if SK_ANGLE |
| 12 #include "gl/SkANGLEGLContext.h" | 12 #include "gl/SkANGLEGLContext.h" |
| 13 #endif | 13 #endif |
| 14 #include "gl/SkDebugGLContext.h" | 14 #include "gl/SkDebugGLContext.h" |
| 15 #if SK_MESA | 15 #if SK_MESA |
| 16 #include "gl/SkMesaGLContext.h" | 16 #include "gl/SkMesaGLContext.h" |
| 17 #endif | 17 #endif |
| 18 #include "gl/SkNativeGLContext.h" | 18 #include "gl/SkNativeGLContext.h" |
| 19 #include "gl/SkNullGLContext.h" | 19 #include "gl/SkNullGLContext.h" |
| 20 | 20 |
| 21 #include "GrContext.h" | 21 #include "GrContext.h" |
| 22 #include "SkTArray.h" | 22 #include "SkTArray.h" |
| 23 | 23 |
| 24 /** | 24 /** |
| 25 * This is a simple class that is useful in test apps that use different | 25 * This is a simple class that is useful in test apps that use different |
| 26 * GrContexts backed by different types of GL contexts. It manages creating the | 26 * GrContexts backed by different types of GL contexts. It manages creating the |
| 27 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the | 27 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the |
| 28 * factory is destroyed (though the caller can always grab a ref on the returned | 28 * factory is destroyed (though the caller can always grab a ref on the returned |
| 29 * GrContext to make it outlive the factory). | 29 * Gr and GL contexts to make them outlive the factory). |
| 30 */ | 30 */ |
| 31 class GrContextFactory : public SkNoncopyable { | 31 class GrContextFactory : public SkNoncopyable { |
| 32 public: | 32 public: |
| 33 /** | 33 /** |
| 34 * Types of GL contexts supported. | 34 * Types of GL contexts supported. For historical and testing reasons the na tive GrContext will |
| 35 * not use "GL_NV_path_rendering" even when the driver supports it. There is a separate context | |
| 36 * type that does not remove NVPR support and which will fail when the drive r does not support | |
| 37 * the extension. | |
| 35 */ | 38 */ |
| 36 enum GLContextType { | 39 enum GLContextType { |
|
robertphillips
2014/01/22 20:12:06
remove this comment since it appears above?
bsalomon
2014/01/23 16:16:09
oops, done
| |
| 40 // For historical and testing reasons the native context will not expose G L_NV_path_rendering | |
| 41 // even when the driver does. There is a a | |
| 37 kNative_GLContextType, | 42 kNative_GLContextType, |
| 38 #if SK_ANGLE | 43 #if SK_ANGLE |
| 39 kANGLE_GLContextType, | 44 kANGLE_GLContextType, |
| 40 #endif | 45 #endif |
| 41 #if SK_MESA | 46 #if SK_MESA |
| 42 kMESA_GLContextType, | 47 kMESA_GLContextType, |
| 43 #endif | 48 #endif |
|
robertphillips
2014/01/22 20:12:06
no,t?
bsalomon
2014/01/23 16:16:09
Done.
| |
| 49 /** Similar to kNative but does no,t filter NVPR. It will fail if the GL d river does not | |
| 50 support NVPR */ | |
| 51 kNVPR_GLContextType, | |
| 44 kNull_GLContextType, | 52 kNull_GLContextType, |
| 45 kDebug_GLContextType, | 53 kDebug_GLContextType, |
| 46 | 54 |
| 47 kLastGLContextType = kDebug_GLContextType | 55 kLastGLContextType = kDebug_GLContextType |
| 48 }; | 56 }; |
| 49 | 57 |
| 50 static const int kGLContextTypeCnt = kLastGLContextType + 1; | 58 static const int kGLContextTypeCnt = kLastGLContextType + 1; |
| 51 | 59 |
| 52 static bool IsRenderingGLContext(GLContextType type) { | 60 static bool IsRenderingGLContext(GLContextType type) { |
| 53 switch (type) { | 61 switch (type) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 66 case kNull_GLContextType: | 74 case kNull_GLContextType: |
| 67 return "null"; | 75 return "null"; |
| 68 #if SK_ANGLE | 76 #if SK_ANGLE |
| 69 case kANGLE_GLContextType: | 77 case kANGLE_GLContextType: |
| 70 return "angle"; | 78 return "angle"; |
| 71 #endif | 79 #endif |
| 72 #if SK_MESA | 80 #if SK_MESA |
| 73 case kMESA_GLContextType: | 81 case kMESA_GLContextType: |
| 74 return "mesa"; | 82 return "mesa"; |
| 75 #endif | 83 #endif |
| 84 case kNVPR_GLContextType: | |
| 85 return "nvpr"; | |
| 76 case kDebug_GLContextType: | 86 case kDebug_GLContextType: |
| 77 return "debug"; | 87 return "debug"; |
| 78 default: | 88 default: |
| 79 GrCrash("Unknown GL Context type."); | 89 GrCrash("Unknown GL Context type."); |
| 80 } | 90 } |
| 81 } | 91 } |
| 82 | 92 |
| 83 GrContextFactory() { | 93 GrContextFactory() { |
| 84 } | 94 } |
| 85 | 95 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 100 | 110 |
| 101 for (int i = 0; i < fContexts.count(); ++i) { | 111 for (int i = 0; i < fContexts.count(); ++i) { |
| 102 if (fContexts[i].fType == type) { | 112 if (fContexts[i].fType == type) { |
| 103 fContexts[i].fGLContext->makeCurrent(); | 113 fContexts[i].fGLContext->makeCurrent(); |
| 104 return fContexts[i].fGrContext; | 114 return fContexts[i].fGrContext; |
| 105 } | 115 } |
| 106 } | 116 } |
| 107 SkAutoTUnref<SkGLContextHelper> glCtx; | 117 SkAutoTUnref<SkGLContextHelper> glCtx; |
| 108 SkAutoTUnref<GrContext> grCtx; | 118 SkAutoTUnref<GrContext> grCtx; |
| 109 switch (type) { | 119 switch (type) { |
| 120 case kNVPR_GLContextType: // fallthru | |
| 110 case kNative_GLContextType: | 121 case kNative_GLContextType: |
| 111 glCtx.reset(SkNEW(SkNativeGLContext)); | 122 glCtx.reset(SkNEW(SkNativeGLContext)); |
| 112 break; | 123 break; |
| 113 #ifdef SK_ANGLE | 124 #ifdef SK_ANGLE |
| 114 case kANGLE_GLContextType: | 125 case kANGLE_GLContextType: |
| 115 glCtx.reset(SkNEW(SkANGLEGLContext)); | 126 glCtx.reset(SkNEW(SkANGLEGLContext)); |
| 116 break; | 127 break; |
| 117 #endif | 128 #endif |
| 118 #ifdef SK_MESA | 129 #ifdef SK_MESA |
| 119 case kMESA_GLContextType: | 130 case kMESA_GLContextType: |
| 120 glCtx.reset(SkNEW(SkMesaGLContext)); | 131 glCtx.reset(SkNEW(SkMesaGLContext)); |
| 121 break; | 132 break; |
| 122 #endif | 133 #endif |
| 123 case kNull_GLContextType: | 134 case kNull_GLContextType: |
| 124 glCtx.reset(SkNEW(SkNullGLContext)); | 135 glCtx.reset(SkNEW(SkNullGLContext)); |
| 125 break; | 136 break; |
| 126 case kDebug_GLContextType: | 137 case kDebug_GLContextType: |
| 127 glCtx.reset(SkNEW(SkDebugGLContext)); | 138 glCtx.reset(SkNEW(SkDebugGLContext)); |
| 128 break; | 139 break; |
| 129 } | 140 } |
| 130 static const int kBogusSize = 1; | 141 static const int kBogusSize = 1; |
| 131 if (!glCtx.get()) { | 142 if (!glCtx.get()) { |
| 132 return NULL; | 143 return NULL; |
| 133 } | 144 } |
| 134 if (!glCtx.get()->init(kBogusSize, kBogusSize)) { | 145 if (!glCtx.get()->init(kBogusSize, kBogusSize)) { |
| 135 return NULL; | 146 return NULL; |
| 136 } | 147 } |
| 137 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glCtx.get() ->gl()); | 148 |
| 149 // Ensure NVPR is available for the NVPR type and block it from other ty pes. | |
| 150 SkAutoTUnref<const GrGLInterface> glInterface(SkRef(glCtx.get()->gl())); | |
| 151 if (kNVPR_GLContextType == type) { | |
| 152 if (!glInterface->hasExtension("GL_NV_path_rendering")) { | |
| 153 return NULL; | |
| 154 } | |
| 155 } else { | |
| 156 glInterface.reset(GrGLInterfaceRemoveNVPR(glInterface)); | |
| 157 if (!glInterface) { | |
| 158 return NULL; | |
| 159 } | |
| 160 } | |
| 161 | |
| 162 GrBackendContext p3dctx = reinterpret_cast<GrBackendContext>(glInterface .get()); | |
| 138 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx)); | 163 grCtx.reset(GrContext::Create(kOpenGL_GrBackend, p3dctx)); |
| 139 if (!grCtx.get()) { | 164 if (!grCtx.get()) { |
| 140 return NULL; | 165 return NULL; |
| 141 } | 166 } |
| 142 GPUContext& ctx = fContexts.push_back(); | 167 GPUContext& ctx = fContexts.push_back(); |
| 143 ctx.fGLContext = glCtx.get(); | 168 ctx.fGLContext = glCtx.get(); |
| 144 ctx.fGLContext->ref(); | 169 ctx.fGLContext->ref(); |
| 145 ctx.fGrContext = grCtx.get(); | 170 ctx.fGrContext = grCtx.get(); |
| 146 ctx.fGrContext->ref(); | 171 ctx.fGrContext->ref(); |
| 147 ctx.fType = type; | 172 ctx.fType = type; |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 163 private: | 188 private: |
| 164 struct GPUContext { | 189 struct GPUContext { |
| 165 GLContextType fType; | 190 GLContextType fType; |
| 166 SkGLContextHelper* fGLContext; | 191 SkGLContextHelper* fGLContext; |
| 167 GrContext* fGrContext; | 192 GrContext* fGrContext; |
| 168 }; | 193 }; |
| 169 SkTArray<GPUContext, true> fContexts; | 194 SkTArray<GPUContext, true> fContexts; |
| 170 }; | 195 }; |
| 171 | 196 |
| 172 #endif | 197 #endif |
| OLD | NEW |