diff options
author | Mike Klein <mtklein@google.com> | 2015-07-29 11:50:09 -0400 |
---|---|---|
committer | Mike Klein <mtklein@google.com> | 2015-07-29 11:50:09 -0400 |
commit | 1e8a58b5680508c241f25f03af5b57502221f215 (patch) | |
tree | 0b0389d4a98a124a8c564f129a190ca5eeae744d /src | |
parent | 3b2fb981ab8d011077eb6de7eec5fe1f590906b3 (diff) |
Revert "Move headers with no dependencies."
This reverts commit 117842223bd13325b6da26110d80e0590c1a742b.
No good:
https://uberchromegw.corp.google.com/i/client.skia/builders/Mac%20Builder/builds/3465/steps/compile/logs/stdio
BUG=skia:4126
Review URL: https://codereview.chromium.org/1262173002 .
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkFunction.h | 75 | ||||
-rw-r--r-- | src/core/SkPathPriv.h | 64 | ||||
-rw-r--r-- | src/core/SkRecords.h | 2 | ||||
-rw-r--r-- | src/gpu/SkGpuFenceSync.h | 29 |
4 files changed, 169 insertions, 1 deletions
diff --git a/src/core/SkFunction.h b/src/core/SkFunction.h new file mode 100644 index 0000000000..8e41cba929 --- /dev/null +++ b/src/core/SkFunction.h @@ -0,0 +1,75 @@ +/* + * 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 "SkTemplates.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(SkNEW_ARGS(LambdaImpl<Fn>, (fn))) {} + + SkFunction(R (*fn)(Args...)) : fFunction(SkNEW_ARGS(FnPtrImpl, (fn))) {} + + SkFunction(const SkFunction& other) { *this = other; } + SkFunction& operator=(const SkFunction& other) { + if (this != &other) { + fFunction.reset(other.fFunction ? other.fFunction->clone() : nullptr); + } + return *this; + } + + R operator()(Args... args) const { + SkASSERT(fFunction.get()); + return fFunction->call(Forward(args)...); + } + +private: + // ~= std::forward. This moves its argument if possible, falling back to a copy if not. + template <typename T> static T&& Forward(T& v) { return (T&&)v; } + + 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(Forward(args)...); } + Interface* clone() const override { return SkNEW_ARGS(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(Forward(args)...); } + Interface* clone() const override { return SkNEW_ARGS(FnPtrImpl, (fFn)); } + private: + R (*fFn)(Args...); + }; + + SkAutoTDelete<Interface> fFunction; +}; + +#endif//SkFunction_DEFINED diff --git a/src/core/SkPathPriv.h b/src/core/SkPathPriv.h new file mode 100644 index 0000000000..934c730660 --- /dev/null +++ b/src/core/SkPathPriv.h @@ -0,0 +1,64 @@ +/* + * 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 SkPathPriv_DEFINED +#define SkPathPriv_DEFINED + +#include "SkPath.h" + +class SkPathPriv { +public: + enum FirstDirection { + kCW_FirstDirection, // == SkPath::kCW_Direction + kCCW_FirstDirection, // == SkPath::kCCW_Direction + kUnknown_FirstDirection, + }; + + static FirstDirection AsFirstDirection(SkPath::Direction dir) { + // since we agree numerically for the values in Direction, we can just cast. + return (FirstDirection)dir; + } + + /** + * Return the opposite of the specified direction. kUnknown is its own + * opposite. + */ + static FirstDirection OppositeFirstDirection(FirstDirection dir) { + static const FirstDirection gOppositeDir[] = { + kCCW_FirstDirection, kCW_FirstDirection, kUnknown_FirstDirection, + }; + return gOppositeDir[dir]; + } + + /** + * Tries to quickly compute the direction of the first non-degenerate + * contour. If it can be computed, return true and set dir to that + * direction. If it cannot be (quickly) determined, return false and ignore + * the dir parameter. If the direction was determined, it is cached to make + * subsequent calls return quickly. + */ + static bool CheapComputeFirstDirection(const SkPath&, FirstDirection* dir); + + /** + * Returns true if the path's direction can be computed via + * cheapComputDirection() and if that computed direction matches the + * specified direction. If dir is kUnknown, returns true if the direction + * cannot be computed. + */ + static bool CheapIsFirstDirection(const SkPath& path, FirstDirection dir) { + FirstDirection computedDir = kUnknown_FirstDirection; + (void)CheapComputeFirstDirection(path, &computedDir); + return computedDir == dir; + } + + static bool LastVerbIsClose(const SkPath& path) { + int count = path.countVerbs(); + return count >= 1 && path.fPathRef->verbs()[~(count - 1)] == SkPath::Verb::kClose_Verb; + } +}; + +#endif diff --git a/src/core/SkRecords.h b/src/core/SkRecords.h index 13332a0fc9..9ab04c91e4 100644 --- a/src/core/SkRecords.h +++ b/src/core/SkRecords.h @@ -8,10 +8,10 @@ #ifndef SkRecords_DEFINED #define SkRecords_DEFINED -#include "../private/SkPathPriv.h" #include "SkCanvas.h" #include "SkDrawable.h" #include "SkMatrix.h" +#include "SkPathPriv.h" #include "SkPicture.h" #include "SkRSXform.h" #include "SkTextBlob.h" diff --git a/src/gpu/SkGpuFenceSync.h b/src/gpu/SkGpuFenceSync.h new file mode 100644 index 0000000000..b78398fed8 --- /dev/null +++ b/src/gpu/SkGpuFenceSync.h @@ -0,0 +1,29 @@ + +/* + * 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 SkGpuFenceSync_DEFINED +#define SkGpuFenceSync_DEFINED + +#include "SkTypes.h" + +typedef void* SkPlatformGpuFence; + +/* + * This class provides an interface to interact with fence syncs. A fence sync is an object that the + * client can insert into the GPU command stream, and then at any future time, wait until all + * commands that were issued before the fence have completed. + */ +class SkGpuFenceSync { +public: + virtual SkPlatformGpuFence SK_WARN_UNUSED_RESULT insertFence() const = 0; + virtual bool flushAndWaitFence(SkPlatformGpuFence) const = 0; + virtual void deleteFence(SkPlatformGpuFence) const = 0; + + virtual ~SkGpuFenceSync() {} +}; + +#endif |