aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkUtils.cpp
diff options
context:
space:
mode:
authorGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-29 18:29:48 +0000
committerGravatar commit-bot@chromium.org <commit-bot@chromium.org@2bbb7eff-a529-9590-31e7-b0007b416f81>2014-05-29 18:29:48 +0000
commitd3c6b3f1c89ad1336830957a1e9b235dd86910f2 (patch)
tree0945e97d54ddbf462b493aafd0e12f75d818a88e /src/core/SkUtils.cpp
parent448e2a3b3935d91e7bf84dc5b0367b92d2e2a518 (diff)
Tinker with SkLazyFnPtr a bit.
I moved the choice function from a get() arg to a template parameter. I think this removes some of the overemphasis on "choose" from the call site, making it a bit more clear it's normally very cheap. It's also now more in line with what I'm thinking now for the general SkLazyPtr<T>, which needs a "create" parameter just like SkLazyFnPtr's "choose", but also a "destroy" that it might use both in .get() but also at process exit. That "destroy" needs to be made part of the type to be called at exit, so might as well make "create" and "choose" template parameters too so it's all consistent. Also, add (C). BUG=skia: R=bungeman@google.com, mtklein@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/298393005 git-svn-id: http://skia.googlecode.com/svn/trunk@14971 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'src/core/SkUtils.cpp')
-rw-r--r--src/core/SkUtils.cpp36
1 files changed, 21 insertions, 15 deletions
diff --git a/src/core/SkUtils.cpp b/src/core/SkUtils.cpp
index 591a198c65..eff718b20f 100644
--- a/src/core/SkUtils.cpp
+++ b/src/core/SkUtils.cpp
@@ -113,34 +113,40 @@ static void sk_memcpy32_portable(uint32_t dst[], const uint32_t src[], int count
memcpy(dst, src, count * sizeof(uint32_t));
}
-static SkMemset16Proc choose_memset16() {
+namespace {
+// These three methods technically need external linkage to be passed as template parameters.
+// Since they can't be static, we hide them in an anonymous namespace instead.
+
+SkMemset16Proc choose_memset16() {
SkMemset16Proc proc = SkMemset16GetPlatformProc();
return proc ? proc : sk_memset16_portable;
}
-void sk_memset16(uint16_t dst[], uint16_t value, int count) {
- SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemset16Proc, choice);
- return choice.get(choose_memset16)(dst, value, count);
-}
-
-static SkMemset32Proc choose_memset32() {
+SkMemset32Proc choose_memset32() {
SkMemset32Proc proc = SkMemset32GetPlatformProc();
return proc ? proc : sk_memset32_portable;
}
-void sk_memset32(uint32_t dst[], uint32_t value, int count) {
- SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemset32Proc, choice);
- return choice.get(choose_memset32)(dst, value, count);
-}
-
-static SkMemcpy32Proc choose_memcpy32() {
+SkMemcpy32Proc choose_memcpy32() {
SkMemcpy32Proc proc = SkMemcpy32GetPlatformProc();
return proc ? proc : sk_memcpy32_portable;
}
+} // namespace
+
+void sk_memset16(uint16_t dst[], uint16_t value, int count) {
+ SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemset16Proc, proc, choose_memset16);
+ proc.get()(dst, value, count);
+}
+
+void sk_memset32(uint32_t dst[], uint32_t value, int count) {
+ SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemset32Proc, proc, choose_memset32);
+ proc.get()(dst, value, count);
+}
+
void sk_memcpy32(uint32_t dst[], const uint32_t src[], int count) {
- SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemcpy32Proc, choice);
- return choice.get(choose_memcpy32)(dst, src, count);
+ SK_DECLARE_STATIC_LAZY_FN_PTR(SkMemcpy32Proc, proc, choose_memcpy32);
+ proc.get()(dst, src, count);
}
///////////////////////////////////////////////////////////////////////////////