aboutsummaryrefslogtreecommitdiffhomepage
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
parent3aa5fce54e1d8f4a682eaf6446fa73df962b3778 (diff)
Replace SkFunction with std::function
TBR=reed@google.com No public API changes. Review URL: https://codereview.chromium.org/1441753002
-rw-r--r--dm/DMSrcSink.cpp10
-rw-r--r--gyp/core.gypi1
-rw-r--r--include/private/SkFunction.h76
-rw-r--r--include/views/SkOSWindow_Win.h8
-rw-r--r--src/gpu/GrTextureParamsAdjuster.h5
-rw-r--r--tests/CPlusPlusEleven.cpp1
-rw-r--r--tests/FunctionTest.cpp70
-rw-r--r--tools/BUILD.public.expected2
8 files changed, 11 insertions, 162 deletions
diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp
index 358124782a..c9178c06dc 100644
--- a/dm/DMSrcSink.cpp
+++ b/dm/DMSrcSink.cpp
@@ -14,7 +14,6 @@
#include "SkData.h"
#include "SkDocument.h"
#include "SkError.h"
-#include "SkFunction.h"
#include "SkImageGenerator.h"
#include "SkMultiPictureDraw.h"
#include "SkNullCanvas.h"
@@ -30,6 +29,7 @@
#include "SkTLogic.h"
#include "SkXMLWriter.h"
#include "SkSwizzler.h"
+#include <functional>
DEFINE_bool(multiPage, false, "For document-type backends, render the source"
" into multiple pages");
@@ -1058,16 +1058,16 @@ Error RasterSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString*) con
// Several examples below.
static Error draw_to_canvas(Sink* sink, SkBitmap* bitmap, SkWStream* stream, SkString* log,
- SkISize size, SkFunction<Error(SkCanvas*)> draw) {
+ SkISize size, std::function<Error(SkCanvas*)> draw) {
class ProxySrc : public Src {
public:
- ProxySrc(SkISize size, SkFunction<Error(SkCanvas*)> draw) : fSize(size), fDraw(draw) {}
+ ProxySrc(SkISize size, std::function<Error(SkCanvas*)> draw) : fSize(size), fDraw(draw) {}
Error draw(SkCanvas* canvas) const override { return fDraw(canvas); }
Name name() const override { sk_throw(); return ""; } // Won't be called.
SkISize size() const override { return fSize; }
private:
- SkISize fSize;
- SkFunction<Error(SkCanvas*)> fDraw;
+ SkISize fSize;
+ std::function<Error(SkCanvas*)> fDraw;
};
return sink->draw(ProxySrc(size, draw), bitmap, stream, log);
}
diff --git a/gyp/core.gypi b/gyp/core.gypi
index f54998e28c..6446fe1d0c 100644
--- a/gyp/core.gypi
+++ b/gyp/core.gypi
@@ -398,7 +398,6 @@
'<(skia_include_path)/private/SkChecksum.h',
'<(skia_include_path)/private/SkFloatBits.h',
'<(skia_include_path)/private/SkFloatingPoint.h',
- '<(skia_include_path)/private/SkFunction.h',
'<(skia_include_path)/private/SkGpuFenceSync.h',
'<(skia_include_path)/private/SkMiniRecorder.h',
'<(skia_include_path)/private/SkMutex.h',
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);
}
diff --git a/src/gpu/GrTextureParamsAdjuster.h b/src/gpu/GrTextureParamsAdjuster.h
index 0a3d529703..cad3920466 100644
--- a/src/gpu/GrTextureParamsAdjuster.h
+++ b/src/gpu/GrTextureParamsAdjuster.h
@@ -11,7 +11,6 @@
#include "GrTextureParams.h"
#include "GrResourceKey.h"
#include "GrTexture.h"
-#include "SkFunction.h"
#include "SkTLazy.h"
class GrContext;
@@ -106,7 +105,7 @@ public:
* @param textureMatrix Matrix to apply to local coordinates to compute
* texel coordinates. The post-transformed coordinates
* should be in texels (relative to this->width() and
- * this->height()) and not be normalized.
+ * this->height()) and not be normalized.
* @param constraintRect Subrect of content area to be rendered. The
* constraint rect is relative to the content area.
* @param filterConstriant Indicates whether filtering is limited to
@@ -145,7 +144,7 @@ private:
typedef GrTextureProducer INHERITED;
};
-/**
+/**
* Base class for sources that start out as something other than a texture (encoded image,
* picture, ...).
*/
diff --git a/tests/CPlusPlusEleven.cpp b/tests/CPlusPlusEleven.cpp
index 4f74b80225..5c2123dc47 100644
--- a/tests/CPlusPlusEleven.cpp
+++ b/tests/CPlusPlusEleven.cpp
@@ -6,7 +6,6 @@
*/
#include "Test.h"
#include "SkTemplates.h"
-#include "SkFunction.h"
namespace {
class Moveable {
diff --git a/tests/FunctionTest.cpp b/tests/FunctionTest.cpp
deleted file mode 100644
index cf6b78905f..0000000000
--- a/tests/FunctionTest.cpp
+++ /dev/null
@@ -1,70 +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.
- */
-
-#include "SkFunction.h"
-#include "Test.h"
-
-static void test_add_five(skiatest::Reporter* r, SkFunction<int(int)>& f) {
- REPORTER_ASSERT(r, f(3) == 8);
- REPORTER_ASSERT(r, f(4) == 9);
-}
-
-static void test_add_five(skiatest::Reporter* r, SkFunction<int(int)>&& f) { test_add_five(r, f); }
-
-static int add_five(int x) { return x + 5; }
-
-struct AddFive {
- int operator()(int x) const { return x + 5; };
-};
-
-class MoveOnlyThree : SkNoncopyable {
-public:
- MoveOnlyThree() {}
- MoveOnlyThree(MoveOnlyThree&&) {}
- MoveOnlyThree& operator=(MoveOnlyThree&&) { return *this; }
-
- int val() { return 3; }
-};
-
-DEF_TEST(Function, r) {
- // We should be able to turn a function pointer, an explicit functor, or a
- // lambda into an SkFunction all equally well.
- test_add_five(r, &add_five);
- test_add_five(r, AddFive());
- test_add_five(r, [](int x) { return x + 5; });
-
- // AddFive and the lambda above are both small enough to test small-object optimization.
- // Now test a lambda that's much too large for the small-object optimization.
- int a = 1, b = 1, c = 1, d = 1, e = 1;
- test_add_five(r, [&](int x) { return x + a + b + c + d + e; });
-
- // Makes sure we forward arguments when calling SkFunction.
- SkFunction<int(int, MoveOnlyThree&&, int)> f([](int x, MoveOnlyThree&& three, int y) {
- return x * three.val() + y;
- });
- REPORTER_ASSERT(r, f(2, MoveOnlyThree(), 4) == 10);
-
- // SkFunctions can go in containers.
- SkTArray<SkFunction<int(int)>> add_fivers;
- add_fivers.push_back(&add_five);
- add_fivers.push_back(AddFive());
- add_fivers.push_back([](int x) { return x + 5; });
- add_fivers.push_back([&](int x) { return x + a + b + c + d + e; });
- for (auto& f : add_fivers) {
- test_add_five(r, f);
- }
-
- // SkFunctions are assignable.
- SkFunction<int(int)> empty;
- empty = [](int x) { return x + 5; };
- test_add_five(r, empty);
-
- // This all is silly acrobatics, but it should at least work correctly.
- SkFunction<int(int)> emptyA, emptyB(emptyA);
- emptyA = emptyB;
- emptyA = emptyA;
-}
diff --git a/tools/BUILD.public.expected b/tools/BUILD.public.expected
index 63d25e3ac2..f9231d91e5 100644
--- a/tools/BUILD.public.expected
+++ b/tools/BUILD.public.expected
@@ -363,7 +363,6 @@ DM_SRCS = ['dm/DM.cpp',
'tests/FontNamesTest.cpp',
'tests/FontObjTest.cpp',
'tests/FrontBufferedStreamTest.cpp',
- 'tests/FunctionTest.cpp',
'tests/GLInterfaceValidationTest.cpp',
'tests/GLProgramsTest.cpp',
'tests/GeometryTest.cpp',
@@ -979,7 +978,6 @@ SRCS = ['include/private/SkAtomics.h',
'include/private/SkChecksum.h',
'include/private/SkFloatBits.h',
'include/private/SkFloatingPoint.h',
- 'include/private/SkFunction.h',
'include/private/SkGpuFenceSync.h',
'include/private/SkMiniRecorder.h',
'include/private/SkMutex.h',