aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core
diff options
context:
space:
mode:
authorGravatar Hal Canary <halcanary@google.com>2018-06-18 15:50:09 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-20 15:20:11 +0000
commitc36f7e735f0e059bab02405f9c4affc4b1bf7b92 (patch)
tree1279a20b2f8af12e0839fdeb41769aac4f4ee668 /include/core
parentce6a5dcbb3c8cf9cffeed1f96c19fc8a6c0cf078 (diff)
SkTypes.h: general cleanup
- SkToBool now inline function. - SK_Invalid{Gen|Unique}ID, SK_MSecMax now constexpr. - SkNoncopyable deleted methods marked private. - Consistant comment style. Change-Id: I1af6889fdf4274d6d698e8f11b29075dbe39ba12 Reviewed-on: https://skia-review.googlesource.com/135446 Reviewed-by: Cary Clark <caryclark@google.com> Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'include/core')
-rw-r--r--include/core/SkTypes.h92
1 files changed, 47 insertions, 45 deletions
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index e001bb1068..9ab72c75e0 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -22,7 +22,7 @@
*/
/** See SkGraphics::GetVersion() to retrieve these at runtime
- */
+*/
#define SKIA_VERSION_MAJOR 1
#define SKIA_VERSION_MINOR 0
#define SKIA_VERSION_PATCH 0
@@ -70,40 +70,39 @@ SK_API extern void sk_abort_no_print(void);
#define SkDEBUGCODE(...)
#define SkDEBUGF(args)
- // unlike SkASSERT, this guy executes its condition in the non-debug build.
+ // unlike SkASSERT, this macro executes its condition in the non-debug build.
// The if is present so that this can be used with functions marked SK_WARN_UNUSED_RESULT.
#define SkAssertResult(cond) if (cond) {} do {} while(false)
#endif
////////////////////////////////////////////////////////////////////////////////
-/**
- * Fast type for unsigned 8 bits. Use for parameter passing and local
- * variables, not for storage
- */
+/** Fast type for unsigned 8 bits. Use for parameter passing and local
+ variables, not for storage
+*/
typedef unsigned U8CPU;
-/**
- * Fast type for signed 16 bits. Use for parameter passing and local variables,
- * not for storage
- */
+/** Fast type for signed 16 bits. Use for parameter passing and local variables,
+ not for storage
+*/
typedef int S16CPU;
-/**
- * Fast type for unsigned 16 bits. Use for parameter passing and local
- * variables, not for storage
- */
+/** Fast type for unsigned 16 bits. Use for parameter passing and local
+ variables, not for storage
+*/
typedef unsigned U16CPU;
-/** Returns 0 or 1 based on the condition
+/** @return false or true based on the condition
*/
-#define SkToBool(cond) ((cond) != 0)
+template <typename T> static constexpr bool SkToBool(const T& x) { return 0 != x; }
+
+static constexpr int16_t SK_MaxS16 = INT16_MAX;
+static constexpr int16_t SK_MinS16 = -SK_MaxS16;
+
+static constexpr int32_t SK_MaxS32 = INT32_MAX;
+static constexpr int32_t SK_MinS32 = -SK_MaxS32;
+static constexpr int32_t SK_NaN32 = INT32_MIN;
-#define SK_MaxS16 INT16_MAX
-#define SK_MinS16 -SK_MaxS16
-#define SK_MaxS32 INT32_MAX
-#define SK_MinS32 -SK_MaxS32
-#define SK_NaN32 INT32_MIN
static constexpr int64_t SK_MaxS64 = INT64_MAX;
static constexpr int64_t SK_MinS64 = -SK_MaxS64;
@@ -115,9 +114,10 @@ static inline constexpr int64_t SkLeftShift(int64_t value, int32_t shift) {
return (int64_t) ((uint64_t) value << shift);
}
-//////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
-/** Returns the number of entries in an array (not a pointer) */
+/** @return the number of entries in an array (not a pointer)
+*/
template <typename T, size_t N> char (&SkArrayCountHelper(T (&array)[N]))[N];
#define SK_ARRAY_COUNT(array) (sizeof(SkArrayCountHelper(array)))
@@ -154,22 +154,25 @@ typedef int32_t SkUnichar;
typedef uint16_t SkGlyphID;
/** 32 bit value to hold a millisecond duration
- * Note that SK_MSecMax is about 25 days.
- */
+ Note that SK_MSecMax is about 25 days.
+*/
typedef uint32_t SkMSec;
-/** maximum representable milliseconds; 24d 20h 31m 23.647s.
+
+/** Maximum representable milliseconds; 24d 20h 31m 23.647s.
*/
-#define SK_MSecMax 0x7FFFFFFF
+static constexpr SkMSec SK_MSecMax = INT32_MAX;
/** The generation IDs in Skia reserve 0 has an invalid marker.
- */
-#define SK_InvalidGenID 0
+*/
+static constexpr uint32_t SK_InvalidGenID = 0;
+
/** The unique IDs in Skia reserve 0 has an invalid marker.
- */
-#define SK_InvalidUniqueID 0
+*/
+static constexpr uint32_t SK_InvalidUniqueID = 0;
/** Generic swap function. Classes with efficient swaps should specialize this function to take
- their fast path. This function is used by SkTSort. */
+ their fast path. This function is used by SkTSort.
+*/
template <typename T> static inline void SkTSwap(T& a, T& b) {
T c(std::move(a));
a = std::move(b);
@@ -222,37 +225,35 @@ static inline int32_t SkFastMin32(int32_t value, int32_t max) {
return value;
}
-/** Returns value pinned between min and max, inclusively. */
+/** @return value pinned (clamped) between min and max, inclusively.
+*/
template <typename T> static constexpr const T& SkTPin(const T& value, const T& min, const T& max) {
return SkTMax(SkTMin(value, max), min);
}
+////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////
-
-/**
- * Indicates whether an allocation should count against a cache budget.
- */
+/** Indicates whether an allocation should count against a cache budget.
+*/
enum class SkBudgeted : bool {
kNo = false,
kYes = true
};
-/**
- * Indicates whether a backing store needs to be an exact match or can be larger
- * than is strictly necessary
- */
+/** Indicates whether a backing store needs to be an exact match or can be
+ larger than is strictly necessary
+*/
enum class SkBackingFit {
kApprox,
kExact
};
-//////////////////////////////////////////////////////////////////////////////
+////////////////////////////////////////////////////////////////////////////////
/** \class SkNoncopyable
-SkNoncopyable is the base class for objects that do not want to
-be copied. It hides its copy-constructor and its assignment-operator.
+ SkNoncopyable is the base class for objects that do not want to
+ be copied. It hides its copy-constructor and its assignment-operator.
*/
class SK_API SkNoncopyable {
public:
@@ -261,6 +262,7 @@ public:
SkNoncopyable(SkNoncopyable&&) = default;
SkNoncopyable& operator =(SkNoncopyable&&) = default;
+private:
SkNoncopyable(const SkNoncopyable&) = delete;
SkNoncopyable& operator=(const SkNoncopyable&) = delete;
};