| 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 #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 */ |
| 26 enum GLContextType { | 32 enum GLContextType { |
| 27 kNative_GLContextType, | 33 kNative_GLContextType, |
| 28 #if SK_ANGLE | 34 #if SK_ANGLE |
| 29 kANGLE_GLContextType, | 35 kANGLE_GLContextType, |
| 30 kANGLE_GL_GLContextType, | 36 kANGLE_GL_GLContextType, |
| 31 #endif | 37 #endif |
| 32 #if SK_COMMAND_BUFFER | 38 #if SK_COMMAND_BUFFER |
| 33 kCommandBuffer_GLContextType, | 39 kCommandBuffer_GLContextType, |
| 34 #endif | 40 #endif |
| 35 #if SK_MESA | 41 #if SK_MESA |
| 36 kMESA_GLContextType, | 42 kMESA_GLContextType, |
| 37 #endif | 43 #endif |
| 38 kNull_GLContextType, | 44 /** Similar to kNative but does not filter NVPR. It will fail if the GL dr
iver does not |
| 39 kDebug_GLContextType, | 45 support NVPR */ |
| 40 kLastGLContextType = kDebug_GLContextType | 46 kNVPR_GLContextType, |
| 47 kNull_GLContextType, |
| 48 kDebug_GLContextType, |
| 49 |
| 50 kLastGLContextType = kDebug_GLContextType |
| 41 }; | 51 }; |
| 42 | 52 |
| 43 static const int kGLContextTypeCnt = kLastGLContextType + 1; | 53 static const int kGLContextTypeCnt = kLastGLContextType + 1; |
| 44 | 54 |
| 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 | |
| 54 static bool IsRenderingGLContext(GLContextType type) { | 55 static bool IsRenderingGLContext(GLContextType type) { |
| 55 switch (type) { | 56 switch (type) { |
| 56 case kNull_GLContextType: | 57 case kNull_GLContextType: |
| 57 case kDebug_GLContextType: | 58 case kDebug_GLContextType: |
| 58 return false; | 59 return false; |
| 59 default: | 60 default: |
| 60 return true; | 61 return true; |
| 61 } | 62 } |
| 62 } | 63 } |
| 63 | 64 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 74 return "angle-gl"; | 75 return "angle-gl"; |
| 75 #endif | 76 #endif |
| 76 #if SK_COMMAND_BUFFER | 77 #if SK_COMMAND_BUFFER |
| 77 case kCommandBuffer_GLContextType: | 78 case kCommandBuffer_GLContextType: |
| 78 return "commandbuffer"; | 79 return "commandbuffer"; |
| 79 #endif | 80 #endif |
| 80 #if SK_MESA | 81 #if SK_MESA |
| 81 case kMESA_GLContextType: | 82 case kMESA_GLContextType: |
| 82 return "mesa"; | 83 return "mesa"; |
| 83 #endif | 84 #endif |
| 85 case kNVPR_GLContextType: |
| 86 return "nvpr"; |
| 84 case kDebug_GLContextType: | 87 case kDebug_GLContextType: |
| 85 return "debug"; | 88 return "debug"; |
| 86 default: | 89 default: |
| 87 SkFAIL("Unknown GL Context type."); | 90 SkFAIL("Unknown GL Context type."); |
| 88 } | 91 } |
| 89 } | 92 } |
| 90 | 93 |
| 91 explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opt
s) { } | 94 explicit GrContextFactory(const GrContextOptions& opts) : fGlobalOptions(opt
s) { } |
| 92 GrContextFactory() { } | 95 GrContextFactory() { } |
| 93 | 96 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 109 if (fContexts[i]->fGLContext) { | 112 if (fContexts[i]->fGLContext) { |
| 110 fContexts[i]->fGLContext->testAbandon(); | 113 fContexts[i]->fGLContext->testAbandon(); |
| 111 SkSafeSetNull(fContexts[i]->fGLContext); | 114 SkSafeSetNull(fContexts[i]->fGLContext); |
| 112 } | 115 } |
| 113 fContexts[i]->fGrContext->abandonContext(); | 116 fContexts[i]->fGrContext->abandonContext(); |
| 114 } | 117 } |
| 115 } | 118 } |
| 116 | 119 |
| 117 struct ContextInfo { | 120 struct ContextInfo { |
| 118 GLContextType fType; | 121 GLContextType fType; |
| 119 GLContextOptions fOptions; | |
| 120 SkGLContext* fGLContext; | 122 SkGLContext* fGLContext; |
| 121 GrContext* fGrContext; | 123 GrContext* fGrContext; |
| 122 }; | 124 }; |
| 123 /** | 125 /** |
| 124 * Get a context initialized with a type of GL context. It also makes the GL
context current. | 126 * Get a context initialized with a type of GL context. It also makes the GL
context current. |
| 125 * Pointer is valid until destroyContexts() is called. | 127 * Pointer is valid until destroyContexts() is called. |
| 126 */ | 128 */ |
| 127 ContextInfo* getContextInfo(GLContextType type, GrGLStandard forcedGpuAPI =
kNone_GrGLStandard, | 129 ContextInfo* getContextInfo(GLContextType type, GrGLStandard forcedGpuAPI =
kNone_GrGLStandard); |
| 128 GLContextOptions options = kNone_GLContextOption
s); | |
| 129 | 130 |
| 130 /** | 131 /** |
| 131 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. | 132 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. |
| 132 */ | 133 */ |
| 133 GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLSta
ndard, | 134 GrContext* get(GLContextType type, GrGLStandard forcedGpuAPI = kNone_GrGLSta
ndard) { |
| 134 GLContextOptions options = kNone_GLContextOptions) { | 135 if (ContextInfo* info = this->getContextInfo(type, forcedGpuAPI)) { |
| 135 if (ContextInfo* info = this->getContextInfo(type, forcedGpuAPI, options
)) { | |
| 136 return info->fGrContext; | 136 return info->fGrContext; |
| 137 } | 137 } |
| 138 return nullptr; | 138 return nullptr; |
| 139 } | 139 } |
| 140 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } | 140 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } |
| 141 | 141 |
| 142 private: | 142 private: |
| 143 SkTArray<SkAutoTDelete<ContextInfo>, true> fContexts; | 143 SkTArray<SkAutoTDelete<ContextInfo>, true> fContexts; |
| 144 const GrContextOptions fGlobalOptions; | 144 const GrContextOptions fGlobalOptions; |
| 145 }; | 145 }; |
| 146 | 146 |
| 147 #endif | 147 #endif |
| OLD | NEW |