diff options
author | bsalomon <bsalomon@google.com> | 2015-03-16 11:56:29 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-16 11:56:29 -0700 |
commit | 3318ee7d5e9ac352bcf8ab6af5724d9a94e6e198 (patch) | |
tree | ad94bcb33aa4933ee8fb2f79186bcbb920d79c9d | |
parent | 741143878b23d22cd9cb7b9cba8055179115ce17 (diff) |
Use C locale for numerics when emitting shaders.
BUG=skia:3330
Review URL: https://codereview.chromium.org/1012723002
-rw-r--r-- | include/gpu/GrTypesPriv.h | 47 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLProgramBuilder.cpp | 2 | ||||
-rw-r--r-- | tests/GLProgramsTest.cpp | 8 |
3 files changed, 57 insertions, 0 deletions
diff --git a/include/gpu/GrTypesPriv.h b/include/gpu/GrTypesPriv.h index 412de897c6..151de1991a 100644 --- a/include/gpu/GrTypesPriv.h +++ b/include/gpu/GrTypesPriv.h @@ -264,4 +264,51 @@ private: SkIRect fRect; }; + +/** + * Helper class for ensuring that we don't use the wrong locale when building shaders. Android + * doesn't support locale in the NDK, so this is a no-op there. + */ +#if !defined(SK_BUILD_FOR_ANDROID) +#include <locale.h> +#endif + +#if defined(SK_BUILD_FOR_MAC) +#include <xlocale.h> +#endif + +class GrAutoLocaleSetter { +public: + GrAutoLocaleSetter (const char* name) { +#if defined(SK_BUILD_FOR_WIN) + fOldPerThreadLocale = _configthreadlocale(_ENABLE_PER_THREAD_LOCALE); + fOldLocale = setlocale(LC_ALL, name); +#elif !defined(SK_BUILD_FOR_ANDROID) + fLocale = newlocale(LC_ALL, name, 0); + fOldLocale = uselocale(fLocale); +#else + (void) name; // suppress unused param warning. +#endif + } + + ~GrAutoLocaleSetter () { +#if defined(SK_BUILD_FOR_WIN) + setlocale(LC_ALL, fOldLocale); + _configthreadlocale(fOldPerThreadLocale); +#elif !defined(SK_BUILD_FOR_ANDROID) + SkASSERT(uselocale(fOldLocale) == fLocale); + freelocale(fLocale); +#endif + } + +private: +#if defined(SK_BUILD_FOR_WIN) + int fOldPerThreadLocale; + const char* fOldLocale; +#elif !defined(SK_BUILD_FOR_ANDROID) + locale_t fOldLocale; + locale_t fLocale; +#endif +}; + #endif diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp index bad1d63ae7..8669d239c7 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp +++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp @@ -53,6 +53,8 @@ private: const int GrGLProgramBuilder::kVarsPerBlock = 8; GrGLProgram* GrGLProgramBuilder::CreateProgram(const DrawArgs& args, GrGLGpu* gpu) { + GrAutoLocaleSetter als("C"); + // create a builder. This will be handed off to effects so they can use it to add // uniforms, varyings, textures, etc SkAutoTDelete<GrGLProgramBuilder> builder(CreateProgramBuilder(args, gpu)); diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index 897e261e5a..d67d1118ed 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -337,6 +337,14 @@ bool GrDrawTarget::programUnitTest(int maxStages) { } DEF_GPUTEST(GLPrograms, reporter, factory) { + // Set a locale that would cause shader compilation to fail because of , as decimal separator. + // skbug 3330 +#ifdef SK_BUILD_FOR_WIN + GrAutoLocaleSetter als("sv-SE"); +#else + GrAutoLocaleSetter als("sv_SE.UTF-8"); +#endif + for (int type = 0; type < GrContextFactory::kLastGLContextType; ++type) { GrContext* context = factory->get(static_cast<GrContextFactory::GLContextType>(type)); if (context) { |