Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(225)

Unified Diff: src/gpu/GrAutoLocaleSetter.h

Issue 1002623004: Move GrAutoLocaleSetter to new file and fix issue with null locale (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: remove extra newline Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/gpu/GrTypesPriv.h ('k') | src/gpu/gl/builders/GrGLProgramBuilder.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/gpu/GrAutoLocaleSetter.h
diff --git a/src/gpu/GrAutoLocaleSetter.h b/src/gpu/GrAutoLocaleSetter.h
new file mode 100644
index 0000000000000000000000000000000000000000..dd17bbef68637c6e5f35625beaac3ccb262d8bbf
--- /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
+
« no previous file with comments | « include/gpu/GrTypesPriv.h ('k') | src/gpu/gl/builders/GrGLProgramBuilder.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698