| 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/GLTestContext.h" | 14 #include "gl/GLTestContext.h" |
| 15 #include "SkTArray.h" | 15 #include "SkTArray.h" |
| 16 | 16 |
| 17 namespace sk_gpu_test { | 17 namespace sk_gpu_test { |
| 18 /** | 18 /** |
| 19 * This is a simple class that is useful in test apps that use different | 19 * This is a simple class that is useful in test apps that use different |
| 20 * GrContexts backed by different types of GL contexts. It manages creating the | 20 * GrContexts backed by different types of GL contexts. It manages creating the |
| 21 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the | 21 * GL context and a GrContext that uses it. The GL/Gr contexts persist until the |
| 22 * factory is destroyed (though the caller can always grab a ref on the returned | 22 * factory is destroyed (though the caller can always grab a ref on the returned |
| 23 * Gr and GL contexts to make them outlive the factory). | 23 * Gr and GL contexts to make them outlive the factory). |
| 24 */ | 24 */ |
| 25 class GrContextFactory : SkNoncopyable { | 25 class GrContextFactory : SkNoncopyable { |
| 26 public: | 26 public: |
| 27 enum ContextType { | 27 enum GLContextType { |
| 28 kGL_ContextType, //! OpenGL context. | 28 kNative_GLContextType, //! OpenGL or OpenGL ES context. |
| 29 kGLES_ContextType, //! OpenGL ES context. | 29 kGL_GLContextType, //! OpenGL context. |
| 30 kGLES_GLContextType, //! OpenGL ES context. |
| 30 #if SK_ANGLE | 31 #if SK_ANGLE |
| 31 #ifdef SK_BUILD_FOR_WIN | 32 #ifdef SK_BUILD_FOR_WIN |
| 32 kANGLE_ContextType, //! ANGLE on DirectX OpenGL ES context. | 33 kANGLE_GLContextType, //! ANGLE on DirectX OpenGL ES context. |
| 33 #endif | 34 #endif |
| 34 kANGLE_GL_ContextType, //! ANGLE on OpenGL OpenGL ES context. | 35 kANGLE_GL_GLContextType, //! ANGLE on OpenGL OpenGL ES context. |
| 35 #endif | 36 #endif |
| 36 #if SK_COMMAND_BUFFER | 37 #if SK_COMMAND_BUFFER |
| 37 kCommandBuffer_ContextType, //! Chromium command buffer OpenGL ES contex
t. | 38 kCommandBuffer_GLContextType, //! Chromium command buffer OpenGL ES cont
ext. |
| 38 #endif | 39 #endif |
| 39 #if SK_MESA | 40 #if SK_MESA |
| 40 kMESA_ContextType, //! MESA OpenGL context | 41 kMESA_GLContextType, //! MESA OpenGL context |
| 41 #endif | 42 #endif |
| 42 kNullGL_ContextType, //! Non-rendering OpenGL mock context. | 43 kNull_GLContextType, //! Non-rendering OpenGL mock context. |
| 43 kDebugGL_ContextType, //! Non-rendering, state verifying OpenGL co
ntext. | 44 kDebug_GLContextType, //! Non-rendering, state verifying OpenGL context. |
| 44 kLastContextType = kDebugGL_ContextType | 45 kLastGLContextType = kDebug_GLContextType |
| 45 }; | 46 }; |
| 46 | 47 |
| 47 //! OpenGL or OpenGL ES context depending on the platform. To be removed. | 48 static const int kGLContextTypeCnt = kLastGLContextType + 1; |
| 48 static const ContextType kNativeGL_ContextType; | |
| 49 | |
| 50 static const int kContextTypeCnt = kLastContextType + 1; | |
| 51 | 49 |
| 52 /** | 50 /** |
| 53 * Options for GL context creation. For historical and testing reasons the o
ptions will default | 51 * Options for GL context creation. For historical and testing reasons the o
ptions will default |
| 54 * to not using GL_NV_path_rendering extension even when the driver support
s it. | 52 * to not using GL_NV_path_rendering extension even when the driver support
s it. |
| 55 */ | 53 */ |
| 56 enum ContextOptions { | 54 enum GLContextOptions { |
| 57 kNone_ContextOptions = 0x0, | 55 kNone_GLContextOptions = 0, |
| 58 kEnableNVPR_ContextOptions = 0x1, | 56 kEnableNVPR_GLContextOptions = 0x1, |
| 59 kRequireSRGBSupport_ContextOptions = 0x2, | 57 kRequireSRGBSupport_GLContextOptions = 0x2, |
| 60 }; | 58 }; |
| 61 | 59 |
| 62 static bool IsRenderingContext(ContextType type) { | 60 static bool IsRenderingGLContext(GLContextType type) { |
| 63 switch (type) { | 61 switch (type) { |
| 64 case kNullGL_ContextType: | 62 case kNull_GLContextType: |
| 65 case kDebugGL_ContextType: | 63 case kDebug_GLContextType: |
| 66 return false; | 64 return false; |
| 67 default: | 65 default: |
| 68 return true; | 66 return true; |
| 69 } | 67 } |
| 70 } | 68 } |
| 71 | 69 |
| 72 static const char* ContextTypeName(ContextType type) { | 70 static const char* GLContextTypeName(GLContextType type) { |
| 73 switch (type) { | 71 switch (type) { |
| 74 case kGL_ContextType: | 72 case kNative_GLContextType: |
| 73 return "native"; |
| 74 case kGL_GLContextType: |
| 75 return "gl"; | 75 return "gl"; |
| 76 case kGLES_ContextType: | 76 case kGLES_GLContextType: |
| 77 return "gles"; | 77 return "gles"; |
| 78 #if SK_ANGLE | 78 #if SK_ANGLE |
| 79 #ifdef SK_BUILD_FOR_WIN | 79 #ifdef SK_BUILD_FOR_WIN |
| 80 case kANGLE_ContextType: | 80 case kANGLE_GLContextType: |
| 81 return "angle"; | 81 return "angle"; |
| 82 #endif | 82 #endif |
| 83 case kANGLE_GL_ContextType: | 83 case kANGLE_GL_GLContextType: |
| 84 return "angle-gl"; | 84 return "angle-gl"; |
| 85 #endif | 85 #endif |
| 86 #if SK_COMMAND_BUFFER | 86 #if SK_COMMAND_BUFFER |
| 87 case kCommandBuffer_ContextType: | 87 case kCommandBuffer_GLContextType: |
| 88 return "commandbuffer"; | 88 return "commandbuffer"; |
| 89 #endif | 89 #endif |
| 90 #if SK_MESA | 90 #if SK_MESA |
| 91 case kMESA_ContextType: | 91 case kMESA_GLContextType: |
| 92 return "mesa"; | 92 return "mesa"; |
| 93 #endif | 93 #endif |
| 94 case kNullGL_ContextType: | 94 case kNull_GLContextType: |
| 95 return "null"; | 95 return "null"; |
| 96 case kDebugGL_ContextType: | 96 case kDebug_GLContextType: |
| 97 return "debug"; | 97 return "debug"; |
| 98 default: | 98 default: |
| 99 SkFAIL("Unknown GL Context type."); | 99 SkFAIL("Unknown GL Context type."); |
| 100 } | 100 } |
| 101 } | 101 } |
| 102 | 102 |
| 103 explicit GrContextFactory(const GrContextOptions& opts); | 103 explicit GrContextFactory(const GrContextOptions& opts); |
| 104 GrContextFactory(); | 104 GrContextFactory(); |
| 105 | 105 |
| 106 ~GrContextFactory(); | 106 ~GrContextFactory(); |
| 107 | 107 |
| 108 void destroyContexts(); | 108 void destroyContexts(); |
| 109 void abandonContexts(); | 109 void abandonContexts(); |
| 110 void releaseResourcesAndAbandonContexts(); | 110 void releaseResourcesAndAbandonContexts(); |
| 111 | 111 |
| 112 struct ContextInfo { | 112 struct ContextInfo { |
| 113 ContextInfo() | 113 ContextInfo() |
| 114 : fGrContext(nullptr), fGLContext(nullptr) { } | 114 : fGrContext(nullptr), fGLContext(nullptr) { } |
| 115 ContextInfo(GrContext* grContext, GLTestContext* glContext) | 115 ContextInfo(GrContext* grContext, GLTestContext* glContext) |
| 116 : fGrContext(grContext), fGLContext(glContext) { } | 116 : fGrContext(grContext), fGLContext(glContext) { } |
| 117 GrContext* fGrContext; | 117 GrContext* fGrContext; |
| 118 GLTestContext* fGLContext; //! Valid until the factory destroys it via a
bandonContexts() or | 118 GLTestContext* fGLContext; //! Valid until the factory destroys it via a
bandonContexts() or |
| 119 //! destroyContexts(). | 119 //! destroyContexts(). |
| 120 }; | 120 }; |
| 121 | 121 |
| 122 /** | 122 /** |
| 123 * Get a context initialized with a type of GL context. It also makes the GL
context current. | 123 * Get a context initialized with a type of GL context. It also makes the GL
context current. |
| 124 */ | 124 */ |
| 125 ContextInfo getContextInfo(ContextType type, | 125 ContextInfo getContextInfo(GLContextType type, |
| 126 ContextOptions options = kNone_ContextOptions); | 126 GLContextOptions options = kNone_GLContextOptions
); |
| 127 /** | 127 /** |
| 128 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. | 128 * Get a GrContext initialized with a type of GL context. It also makes the
GL context current. |
| 129 */ | 129 */ |
| 130 GrContext* get(ContextType type, ContextOptions options = kNone_ContextOptio
ns) { | 130 GrContext* get(GLContextType type, |
| 131 GLContextOptions options = kNone_GLContextOptions) { |
| 131 return this->getContextInfo(type, options).fGrContext; | 132 return this->getContextInfo(type, options).fGrContext; |
| 132 } | 133 } |
| 133 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } | 134 const GrContextOptions& getGlobalOptions() const { return fGlobalOptions; } |
| 134 | 135 |
| 135 private: | 136 private: |
| 136 struct Context { | 137 struct Context { |
| 137 ContextType fType; | 138 GLContextType fType; |
| 138 ContextOptions fOptions; | 139 GLContextOptions fOptions; |
| 139 GLTestContext* fGLContext; // null if non-GL | 140 GLTestContext* fGLContext; |
| 140 GrContext* fGrContext; | 141 GrContext* fGrContext; |
| 141 }; | 142 }; |
| 142 SkTArray<Context, true> fContexts; | 143 SkTArray<Context, true> fContexts; |
| 143 const GrContextOptions fGlobalOptions; | 144 const GrContextOptions fGlobalOptions; |
| 144 }; | 145 }; |
| 145 } // namespace sk_gpu_test | 146 } // namespace sk_gpu_test |
| 146 #endif | 147 #endif |
| OLD | NEW |