diff options
author | bsalomon <bsalomon@google.com> | 2015-03-16 14:00:52 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-03-16 14:00:52 -0700 |
commit | 6f7f2012eed634695dc76aad720d3ee0820bd9d2 (patch) | |
tree | f910b5b871b9da01b28d189845b504cacc40e344 | |
parent | 82b0748f1c440059cf5f33fceef3b94de9e04052 (diff) |
Move GrAutoLocaleSetter to new file and fix issue with null locale
TBR=egdaniel@google.com
NOTREECHECKS=true
Review URL: https://codereview.chromium.org/1002623004
-rw-r--r-- | gyp/gpu.gypi | 1 | ||||
-rw-r--r-- | include/gpu/GrTypesPriv.h | 47 | ||||
-rw-r--r-- | src/gpu/GrAutoLocaleSetter.h | 64 | ||||
-rw-r--r-- | src/gpu/gl/builders/GrGLProgramBuilder.cpp | 1 | ||||
-rw-r--r-- | tests/GLProgramsTest.cpp | 1 |
5 files changed, 67 insertions, 47 deletions
diff --git a/gyp/gpu.gypi b/gyp/gpu.gypi index 737915d96b..2207f87817 100644 --- a/gyp/gpu.gypi +++ b/gyp/gpu.gypi @@ -53,6 +53,7 @@ '<(skia_src_path)/gpu/GrAARectRenderer.cpp', '<(skia_src_path)/gpu/GrAARectRenderer.h', '<(skia_src_path)/gpu/GrAddPathRenderers_default.cpp', + '<(skia_src_path)/gpu/GrAutoLocaleSetter.h', '<(skia_src_path)/gpu/GrAllocator.h', '<(skia_src_path)/gpu/GrAtlas.cpp', '<(skia_src_path)/gpu/GrAtlas.h', diff --git a/include/gpu/GrTypesPriv.h b/include/gpu/GrTypesPriv.h index 22b55bffa0..412de897c6 100644 --- a/include/gpu/GrTypesPriv.h +++ b/include/gpu/GrTypesPriv.h @@ -264,51 +264,4 @@ 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) || defined(SK_BUILD_FOR_IOS) -#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) - uselocale(fOldLocale); - 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/GrAutoLocaleSetter.h b/src/gpu/GrAutoLocaleSetter.h new file mode 100644 index 0000000000..dd17bbef68 --- /dev/null +++ b/src/gpu/GrAutoLocaleSetter.h @@ -0,0 +1,64 @@ +/* + * Copyright 2015 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef GrAutoLocaleSetter_DEFINED +#define GrAutoLocaleSetter_DEFINED + +#include "GrTypes.h" + +#if !defined(SK_BUILD_FOR_ANDROID) +#include <locale.h> +#endif + +#if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) +#include <xlocale.h> +#endif + +/** + * 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. + */ +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); + if (fLocale) { + 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) + if (fLocale) { + uselocale(fOldLocale); + 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 8669d239c7..a2b8a34157 100644 --- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp +++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp @@ -14,6 +14,7 @@ #include "gl/GrGLSLPrettyPrint.h" #include "gl/GrGLUniformHandle.h" #include "gl/GrGLXferProcessor.h" +#include "GrAutoLocaleSetter.h" #include "GrCoordTransform.h" #include "GrGLProgramBuilder.h" #include "GrTexture.h" diff --git a/tests/GLProgramsTest.cpp b/tests/GLProgramsTest.cpp index d67d1118ed..b2204b4b2b 100644 --- a/tests/GLProgramsTest.cpp +++ b/tests/GLProgramsTest.cpp @@ -12,6 +12,7 @@ #if SK_SUPPORT_GPU && SK_ALLOW_STATIC_GLOBAL_INITIALIZERS +#include "GrAutoLocaleSetter.h" #include "GrContextFactory.h" #include "GrInvariantOutput.h" #include "GrPipeline.h" |