aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-07-30 07:30:16 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-07-30 07:30:16 -0700
commit8317a1832f55e175531ee7ae7ccd12a3a15e3c75 (patch)
treefbc782b3198b75c3aac5541d20af5f3d91d07e87 /src
parentdbf9f014a8a1f2f9c0ecfccb12d7dd5f4cfac240 (diff)
Lay groundwork for SkOpts.
This doesn't really do anything yet. It's just the CPU detection code, skeleton new .cpp files, and a few little .gyp tweaks. BUG=skia:4117 Committed: https://skia.googlesource.com/skia/+/ce2c5055cee5d5d3c9fc84c1b3eeed4b4d84a827 Review URL: https://codereview.chromium.org/1255193002
Diffstat (limited to 'src')
-rw-r--r--src/core/SkGraphics.cpp79
-rw-r--r--src/core/SkOpts.cpp55
-rw-r--r--src/core/SkOpts.h22
-rw-r--r--src/opts/SkOpts_neon.cpp14
-rw-r--r--src/opts/SkOpts_sse2.cpp14
-rw-r--r--src/opts/SkOpts_sse41.cpp14
-rw-r--r--src/opts/SkOpts_ssse3.cpp14
7 files changed, 137 insertions, 75 deletions
diff --git a/src/core/SkGraphics.cpp b/src/core/SkGraphics.cpp
index 7acee85c4d..093e7a6f3b 100644
--- a/src/core/SkGraphics.cpp
+++ b/src/core/SkGraphics.cpp
@@ -14,6 +14,7 @@
#include "SkGeometry.h"
#include "SkMath.h"
#include "SkMatrix.h"
+#include "SkOpts.h"
#include "SkPath.h"
#include "SkPathEffect.h"
#include "SkPixelRef.h"
@@ -39,17 +40,10 @@ void SkGraphics::GetVersion(int32_t* major, int32_t* minor, int32_t* patch) {
}
}
-#define typesizeline(type) { #type , sizeof(type) }
-
-#ifdef BUILD_EMBOSS_TABLE
- extern void SkEmbossMask_BuildTable();
-#endif
-
-#ifdef BUILD_RADIALGRADIENT_TABLE
- extern void SkRadialGradient_BuildTable();
-#endif
-
void SkGraphics::Init() {
+ // SkGraphics::Init() must be thread-safe and idempotent.
+ SkOpts::Init();
+
#ifdef SK_DEVELOPER
skRTConfRegistry().possiblyDumpFile();
skRTConfRegistry().validate();
@@ -58,71 +52,6 @@ void SkGraphics::Init() {
skRTConfRegistry().printNonDefault();
}
#endif
-
-#ifdef BUILD_EMBOSS_TABLE
- SkEmbossMask_BuildTable();
-#endif
-#ifdef BUILD_RADIALGRADIENT_TABLE
- SkRadialGradient_BuildTable();
-#endif
-
-#ifdef SK_DEBUGx
- int i;
-
- static const struct {
- const char* fTypeName;
- size_t fSizeOf;
- } gTypeSize[] = {
- typesizeline(char),
- typesizeline(short),
- typesizeline(int),
- typesizeline(long),
- typesizeline(size_t),
- typesizeline(void*),
-
- typesizeline(S8CPU),
- typesizeline(U8CPU),
- typesizeline(S16CPU),
- typesizeline(U16CPU),
-
- typesizeline(SkPoint),
- typesizeline(SkRect),
- typesizeline(SkMatrix),
- typesizeline(SkPath),
- typesizeline(SkGlyph),
- typesizeline(SkRefCnt),
-
- typesizeline(SkPaint),
- typesizeline(SkCanvas),
- typesizeline(SkBlitter),
- typesizeline(SkShader),
- typesizeline(SkXfermode),
- typesizeline(SkPathEffect)
- };
-
-#ifdef SK_CPU_BENDIAN
- SkDebugf("SkGraphics: big-endian\n");
-#else
- SkDebugf("SkGraphics: little-endian\n");
-#endif
-
- {
- char test = 0xFF;
- int itest = test; // promote to int, see if it sign-extended
- if (itest < 0)
- SkDebugf("SkGraphics: char is signed\n");
- else
- SkDebugf("SkGraphics: char is unsigned\n");
- }
- for (i = 0; i < (int)SK_ARRAY_COUNT(gTypeSize); i++) {
- SkDebugf("SkGraphics: sizeof(%s) = %d\n",
- gTypeSize[i].fTypeName, gTypeSize[i].fSizeOf);
- }
- SkDebugf("SkGraphics: font cache limit %dK\n",
- GetFontCacheLimit() >> 10);
-
-#endif
-
}
void SkGraphics::Term() {
diff --git a/src/core/SkOpts.cpp b/src/core/SkOpts.cpp
new file mode 100644
index 0000000000..4f7c5e9345
--- /dev/null
+++ b/src/core/SkOpts.cpp
@@ -0,0 +1,55 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkOnce.h"
+#include "SkOpts.h"
+
+#if defined(SK_CPU_X86)
+ #if defined(SK_BUILD_FOR_WIN32)
+ #include <intrin.h>
+ static void cpuid(uint32_t abcd[4]) { __cpuid((int*)abcd, 1); }
+ #else
+ #include <cpuid.h>
+ static void cpuid(uint32_t abcd[4]) { __get_cpuid(1, abcd+0, abcd+1, abcd+2, abcd+3); }
+ #endif
+#elif !defined(SK_ARM_HAS_NEON) && defined(SK_CPU_ARM32) && defined(SK_BUILD_FOR_ANDROID)
+ #include <cpu-features.h>
+#endif
+
+namespace SkOpts {
+ // (Define default function pointer values here...)
+
+ // Each Init_foo() is defined in src/opts/SkOpts_foo.cpp.
+ void Init_sse2();
+ void Init_ssse3();
+ void Init_sse41();
+ void Init_neon();
+ //TODO: _dsp2, _armv7, _armv8, _x86, _x86_64, _sse42, _avx, avx2, ... ?
+
+ static void init() {
+ #if defined(SK_CPU_X86)
+ uint32_t abcd[] = {0,0,0,0};
+ cpuid(abcd);
+ if (abcd[3] & (1<<26)) { Init_sse2(); }
+ if (abcd[2] & (1<< 9)) { Init_ssse3(); }
+ if (abcd[2] & (1<<19)) { Init_sse41(); }
+ #elif defined(SK_ARM_HAS_NEON)
+ Init_neon();
+ #elif defined(SK_CPU_ARM32) && defined(SK_BUILD_FOR_ANDROID)
+ if (android_getCpuFeatures() & ANDROID_CPU_ARM_FEATURE_NEON) { Init_neon(); }
+ #endif
+ }
+
+ SK_DECLARE_STATIC_ONCE(gInitOnce);
+ void Init() { SkOnce(&gInitOnce, init); }
+
+#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
+ static struct AutoInit {
+ AutoInit() { Init(); }
+ } gAutoInit;
+#endif
+}
diff --git a/src/core/SkOpts.h b/src/core/SkOpts.h
new file mode 100644
index 0000000000..71abae5d7a
--- /dev/null
+++ b/src/core/SkOpts.h
@@ -0,0 +1,22 @@
+/*
+ * 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 SkOpts_DEFINED
+#define SkOpts_DEFINED
+
+#include "SkTypes.h"
+
+namespace SkOpts {
+ // Call to replace pointers to portable functions with pointers to CPU-specific functions.
+ // Thread-safe and idempotent.
+ // Called by SkGraphics::Init(), and automatically #if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS.
+ void Init();
+
+ // (Function pointers go here).
+}
+
+#endif//SkOpts_DEFINED
diff --git a/src/opts/SkOpts_neon.cpp b/src/opts/SkOpts_neon.cpp
new file mode 100644
index 0000000000..3508b35318
--- /dev/null
+++ b/src/opts/SkOpts_neon.cpp
@@ -0,0 +1,14 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkOpts.h"
+
+namespace SkOpts {
+ void Init_neon() {
+
+ }
+}
diff --git a/src/opts/SkOpts_sse2.cpp b/src/opts/SkOpts_sse2.cpp
new file mode 100644
index 0000000000..31afa8cae7
--- /dev/null
+++ b/src/opts/SkOpts_sse2.cpp
@@ -0,0 +1,14 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkOpts.h"
+
+namespace SkOpts {
+ void Init_sse2() {
+
+ }
+}
diff --git a/src/opts/SkOpts_sse41.cpp b/src/opts/SkOpts_sse41.cpp
new file mode 100644
index 0000000000..72e5682463
--- /dev/null
+++ b/src/opts/SkOpts_sse41.cpp
@@ -0,0 +1,14 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkOpts.h"
+
+namespace SkOpts {
+ void Init_sse41() {
+
+ }
+}
diff --git a/src/opts/SkOpts_ssse3.cpp b/src/opts/SkOpts_ssse3.cpp
new file mode 100644
index 0000000000..de3296654f
--- /dev/null
+++ b/src/opts/SkOpts_ssse3.cpp
@@ -0,0 +1,14 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkOpts.h"
+
+namespace SkOpts {
+ void Init_ssse3() {
+
+ }
+}