#include "SkData.h"
#include "SkDocument.h"
#include "SkError.h"
-#include "SkFunction.h"
#include "SkImageGenerator.h"
#include "SkMultiPictureDraw.h"
#include "SkNullCanvas.h"
#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");
// 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);
}
'<(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',
+++ /dev/null
-/*
- * 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
#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"
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);
}
#include "GrTextureParams.h"
#include "GrResourceKey.h"
#include "GrTexture.h"
-#include "SkFunction.h"
#include "SkTLazy.h"
class GrContext;
* @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
typedef GrTextureProducer INHERITED;
};
-/**
+/**
* Base class for sources that start out as something other than a texture (encoded image,
* picture, ...).
*/
*/
#include "Test.h"
#include "SkTemplates.h"
-#include "SkFunction.h"
namespace {
class Moveable {
+++ /dev/null
-/*
- * 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;
-}
'tests/FontNamesTest.cpp',
'tests/FontObjTest.cpp',
'tests/FrontBufferedStreamTest.cpp',
- 'tests/FunctionTest.cpp',
'tests/GLInterfaceValidationTest.cpp',
'tests/GLProgramsTest.cpp',
'tests/GeometryTest.cpp',
'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',