aboutsummaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorGravatar mtklein <mtklein@chromium.org>2015-11-12 10:41:05 -0800
committerGravatar Commit bot <commit-bot@chromium.org>2015-11-12 10:41:05 -0800
commit64593525debc63339e1bf9ddb8a0e998f7d976a3 (patch)
treefef4af677389ebf339a80d67294809b64041f798 /include
parent3aa5fce54e1d8f4a682eaf6446fa73df962b3778 (diff)
Replace SkFunction with std::function
TBR=reed@google.com No public API changes. Review URL: https://codereview.chromium.org/1441753002
Diffstat (limited to 'include')
-rw-r--r--include/private/SkFunction.h76
-rw-r--r--include/views/SkOSWindow_Win.h8
2 files changed, 4 insertions, 80 deletions
diff --git a/include/private/SkFunction.h b/include/private/SkFunction.h
deleted file mode 100644
index 6be95394c8..0000000000
--- a/include/private/SkFunction.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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 SkFunction_DEFINED
-#define SkFunction_DEFINED
-
-// TODO: document, more pervasive move support in constructors, small-Fn optimization
-
-#include "SkUtility.h"
-#include "SkUniquePtr.h"
-#include "SkTypes.h"
-
-template <typename> class SkFunction;
-
-template <typename R, typename... Args>
-class SkFunction<R(Args...)> {
-public:
- SkFunction() {}
-
- template <typename Fn>
- SkFunction(const Fn& fn)
- : fFunction(new LambdaImpl<Fn>(fn)) {}
-
- SkFunction(R (*fn)(Args...)) : fFunction(new FnPtrImpl(fn)) {}
-
- SkFunction(const SkFunction& other) { *this = other; }
- SkFunction& operator=(const SkFunction& other) {
- if (this != &other) {
- fFunction.reset(other.fFunction.get() ? other.fFunction->clone() : nullptr);
- }
- return *this;
- }
-
- R operator()(Args... args) const {
- SkASSERT(fFunction.get());
- return fFunction->call(skstd::forward<Args>(args)...);
- }
-
-private:
- struct Interface {
- virtual ~Interface() {}
- virtual R call(Args...) const = 0;
- virtual Interface* clone() const = 0;
- };
-
- template <typename Fn>
- class LambdaImpl final : public Interface {
- public:
- LambdaImpl(const Fn& fn) : fFn(fn) {}
-
- R call(Args... args) const override { return fFn(skstd::forward<Args>(args)...); }
- Interface* clone() const override { return new LambdaImpl<Fn>(fFn); }
-
- private:
- Fn fFn;
- };
-
- class FnPtrImpl final : public Interface {
- public:
- FnPtrImpl(R (*fn)(Args...)) : fFn(fn) {}
-
- R call(Args... args) const override { return fFn(skstd::forward<Args>(args)...); }
- Interface* clone() const override { return new FnPtrImpl(fFn); }
-
- private:
- R (*fFn)(Args...);
- };
-
- skstd::unique_ptr<Interface> fFunction;
-};
-
-#endif//SkFunction_DEFINED
diff --git a/include/views/SkOSWindow_Win.h b/include/views/SkOSWindow_Win.h
index b65d4c29df..c1a68c621e 100644
--- a/include/views/SkOSWindow_Win.h
+++ b/include/views/SkOSWindow_Win.h
@@ -10,9 +10,9 @@
#ifndef SkOSWindow_Win_DEFINED
#define SkOSWindow_Win_DEFINED
-#include "../private/SkFunction.h"
#include "../private/SkTHash.h"
#include "SkWindow.h"
+#include <functional>
#if SK_ANGLE
#include "EGL/egl.h"
@@ -71,9 +71,9 @@ public:
return *win;
}
- // Iterates SkFunction over all the SkOSWindows and their corresponding HWNDs.
- // The void* argument to the SkFunction is a HWND.
- static void ForAllWindows(const SkFunction<void(void*, SkOSWindow**)>& f) {
+ // Iterates f over all the SkOSWindows and their corresponding HWNDs.
+ // The void* argument to f is a HWND.
+ static void ForAllWindows(const std::function<void(void*, SkOSWindow**)>& f) {
gHwndToOSWindowMap.foreach(f);
}