| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 #include "SkTypes.h" | 8 #include "SkTypes.h" |
| 9 | 9 |
| 10 #if SK_SUPPORT_GPU | 10 #if SK_SUPPORT_GPU |
| 11 | 11 |
| 12 #include "GrContextFactory.h" | 12 #include "GrContextFactory.h" |
| 13 #include "GrCaps.h" | 13 #include "GrCaps.h" |
| 14 #include "Test.h" | 14 #include "Test.h" |
| 15 | 15 |
| 16 using sk_gpu_test::GrContextFactory; | 16 using sk_gpu_test::GrContextFactory; |
| 17 | 17 |
| 18 DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter,
/*factory*/) { | 18 DEF_GPUTEST(GrContextFactory_NVPRContextOptionHasPathRenderingSupport, reporter,
/*factory*/) { |
| 19 // Test that if NVPR is requested, the context always has path rendering | 19 // Test that if NVPR is requested, the context always has path rendering |
| 20 // or the context creation fails. | 20 // or the context creation fails. |
| 21 GrContextFactory testFactory; | 21 GrContextFactory testFactory; |
| 22 // Test that if NVPR is possible, caps are in sync. | 22 // Test that if NVPR is possible, caps are in sync. |
| 23 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { | 23 for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
| 24 GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::Co
ntextType>(i); | 24 GrContextFactory::GLContextType glCtxType = static_cast<GrContextFactory
::GLContextType>(i); |
| 25 GrContext* context = testFactory.get(ctxType, | 25 GrContext* context = testFactory.get(glCtxType, |
| 26 GrContextFactory::kEnableNVPR_Conte
xtOptions); | 26 GrContextFactory::kEnableNVPR_GLCon
textOptions); |
| 27 if (!context) { | 27 if (!context) { |
| 28 continue; | 28 continue; |
| 29 } | 29 } |
| 30 REPORTER_ASSERT( | 30 REPORTER_ASSERT( |
| 31 reporter, | 31 reporter, |
| 32 context->caps()->shaderCaps()->pathRenderingSupport()); | 32 context->caps()->shaderCaps()->pathRenderingSupport()); |
| 33 } | 33 } |
| 34 } | 34 } |
| 35 | 35 |
| 36 DEF_GPUTEST(GrContextFactory_NoPathRenderingUnlessNVPRRequested, reporter, /*fac
tory*/) { | 36 DEF_GPUTEST(GrContextFactory_NoPathRenderingUnlessNVPRRequested, reporter, /*fac
tory*/) { |
| 37 // Test that if NVPR is not requested, the context never has path rendering
support. | 37 // Test that if NVPR is not requested, the context never has path rendering
support. |
| 38 | 38 |
| 39 GrContextFactory testFactory; | 39 GrContextFactory testFactory; |
| 40 for (int i = 0; i <= GrContextFactory::kLastContextType; ++i) { | 40 for (int i = 0; i <= GrContextFactory::kLastGLContextType; ++i) { |
| 41 GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType)i
; | 41 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext
Type)i; |
| 42 GrContext* context = testFactory.get(ctxType); | 42 GrContext* context = testFactory.get(glCtxType); |
| 43 if (context) { | 43 if (context) { |
| 44 REPORTER_ASSERT( | 44 REPORTER_ASSERT( |
| 45 reporter, | 45 reporter, |
| 46 !context->caps()->shaderCaps()->pathRenderingSupport()); | 46 !context->caps()->shaderCaps()->pathRenderingSupport()); |
| 47 } | 47 } |
| 48 } | 48 } |
| 49 } | 49 } |
| 50 | 50 |
| 51 DEF_GPUTEST(GrContextFactory_RequiredSRGBSupport, reporter, /*factory*/) { | 51 DEF_GPUTEST(GrContextFactory_RequiredSRGBSupport, reporter, /*factory*/) { |
| 52 // Test that if sRGB support is requested, the context always has that capab
ility | 52 // Test that if sRGB support is requested, the context always has that capab
ility |
| 53 // or the context creation fails. Also test that if the creation fails, a co
ntext | 53 // or the context creation fails. Also test that if the creation fails, a co
ntext |
| 54 // created without that flag would not have had sRGB support. | 54 // created without that flag would not have had sRGB support. |
| 55 GrContextFactory testFactory; | 55 GrContextFactory testFactory; |
| 56 // Test that if sRGB is requested, caps are in sync. | 56 // Test that if sRGB is requested, caps are in sync. |
| 57 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { | 57 for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
| 58 GrContextFactory::ContextType ctxType = static_cast<GrContextFactory::Co
ntextType>(i); | 58 GrContextFactory::GLContextType glCtxType = static_cast<GrContextFactory
::GLContextType>(i); |
| 59 GrContext* context = | 59 GrContext* context = |
| 60 testFactory.get(ctxType, GrContextFactory::kRequireSRGBSupport_Conte
xtOptions); | 60 testFactory.get(glCtxType, |
| 61 GrContextFactory::kRequireSRGBSupport_GLContextOptio
ns); |
| 61 | 62 |
| 62 if (context) { | 63 if (context) { |
| 63 REPORTER_ASSERT(reporter, context->caps()->srgbSupport()); | 64 REPORTER_ASSERT(reporter, context->caps()->srgbSupport()); |
| 64 } else { | 65 } else { |
| 65 context = testFactory.get(ctxType); | 66 context = testFactory.get(glCtxType); |
| 66 if (context) { | 67 if (context) { |
| 67 REPORTER_ASSERT(reporter, !context->caps()->srgbSupport()); | 68 REPORTER_ASSERT(reporter, !context->caps()->srgbSupport()); |
| 68 } | 69 } |
| 69 } | 70 } |
| 70 } | 71 } |
| 71 } | 72 } |
| 72 | 73 |
| 73 DEF_GPUTEST(GrContextFactory_abandon, reporter, /*factory*/) { | 74 DEF_GPUTEST(GrContextFactory_abandon, reporter, /*factory*/) { |
| 74 GrContextFactory testFactory; | 75 GrContextFactory testFactory; |
| 75 for (int i = 0; i < GrContextFactory::kContextTypeCnt; ++i) { | 76 for (int i = 0; i < GrContextFactory::kGLContextTypeCnt; ++i) { |
| 76 GrContextFactory::ContextType ctxType = (GrContextFactory::ContextType)
i; | 77 GrContextFactory::GLContextType glCtxType = (GrContextFactory::GLContext
Type) i; |
| 77 GrContextFactory::ContextInfo info1 = testFactory.getContextInfo(ctxType
); | 78 GrContextFactory::ContextInfo info1 = |
| 79 testFactory.getContextInfo(glCtxType); |
| 78 if (!info1.fGrContext) { | 80 if (!info1.fGrContext) { |
| 79 continue; | 81 continue; |
| 80 } | 82 } |
| 81 REPORTER_ASSERT(reporter, info1.fGLContext); | 83 REPORTER_ASSERT(reporter, info1.fGLContext); |
| 82 // Ref for comparison. The API does not explicitly say that this stays
alive. | 84 // Ref for comparison. The API does not explicitly say that this stays
alive. |
| 83 info1.fGrContext->ref(); | 85 info1.fGrContext->ref(); |
| 84 testFactory.abandonContexts(); | 86 testFactory.abandonContexts(); |
| 85 | 87 |
| 86 // Test that we get different context after abandon. | 88 // Test that we get different context after abandon. |
| 87 GrContextFactory::ContextInfo info2 = | 89 GrContextFactory::ContextInfo info2 = |
| 88 testFactory.getContextInfo(ctxType); | 90 testFactory.getContextInfo(glCtxType); |
| 89 REPORTER_ASSERT(reporter, info2.fGrContext); | 91 REPORTER_ASSERT(reporter, info2.fGrContext); |
| 90 REPORTER_ASSERT(reporter, info2.fGLContext); | 92 REPORTER_ASSERT(reporter, info2.fGLContext); |
| 91 REPORTER_ASSERT(reporter, info1.fGrContext != info2.fGrContext); | 93 REPORTER_ASSERT(reporter, info1.fGrContext != info2.fGrContext); |
| 92 // fGLContext should also change, but it also could get the same address
. | 94 // fGLContext should also change, but it also could get the same address
. |
| 93 | 95 |
| 94 info1.fGrContext->unref(); | 96 info1.fGrContext->unref(); |
| 95 } | 97 } |
| 96 } | 98 } |
| 97 | 99 |
| 98 #endif | 100 #endif |
| OLD | NEW |