diff options
author | bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-10-10 13:19:10 +0000 |
---|---|---|
committer | bungeman@google.com <bungeman@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2011-10-10 13:19:10 +0000 |
commit | b29c883fb46ac6099440d82ac57b86d25386daed (patch) | |
tree | 2782e96a58d3dea8b2299d8d980eeeedbf08c0a8 /include/device/xps/SkConstexprMath.h | |
parent | 1c04bf97b6245b55ac58c2f3902f8ca95ca91c3d (diff) |
Add xps device to skia.
http://codereview.appspot.com/5076041/
git-svn-id: http://skia.googlecode.com/svn/trunk@2437 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/device/xps/SkConstexprMath.h')
-rw-r--r-- | include/device/xps/SkConstexprMath.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/include/device/xps/SkConstexprMath.h b/include/device/xps/SkConstexprMath.h new file mode 100644 index 0000000000..65b70b6eea --- /dev/null +++ b/include/device/xps/SkConstexprMath.h @@ -0,0 +1,52 @@ +/* + * Copyright 2011 Google Inc. + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#ifndef SkConstexprMath_DEFINED +#define SkConstexprMath_DEFINED + +#include "SkTypes.h" +#include <limits.h> + +template <uintmax_t N, uintmax_t B> +struct SK_LOG { + //! Compile-time constant ceiling(logB(N)). + static const uintmax_t value = 1 + SK_LOG<N/B, B>::value; +}; +template <uintmax_t B> +struct SK_LOG<1, B> { + static const uintmax_t value = 0; +}; +template <uintmax_t B> +struct SK_LOG<0, B> { + static const uintmax_t value = 0; +}; + +template<uintmax_t N> +struct SK_2N1 { + //! Compile-time constant (2^N)-1. + static const uintmax_t value = (SK_2N1<N-1>::value << 1) + 1; +}; +template<> +struct SK_2N1<1> { + static const uintmax_t value = 1; +}; + +/** Compile-time constant number of base n digits in type t + if the bits of type t are considered as unsigned base two. +*/ +#define SK_BASE_N_DIGITS_IN(n, t) (\ + SK_LOG<SK_2N1<(sizeof(t) * CHAR_BIT)>::value, n>::value\ +) +/** Compile-time constant number of base 10 digits in type t + if the bits of type t are considered as unsigned base two. +*/ +#define SK_DIGITS_IN(t) SK_BASE_N_DIGITS_IN(10, (t)) + +//! a > b ? a : b +#define SK_MAX(a,b) (((a) > (b)) ? (a) : (b)) + +#endif |