diff options
author | halcanary <halcanary@google.com> | 2016-05-31 11:23:42 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-31 11:23:42 -0700 |
commit | bfa9275968d11d459b30a485cedcb55c7fecf9d7 (patch) | |
tree | 88678ba0e909a3e06bf9eaa8ef6b6ba25150a713 | |
parent | a9ef92a5ede83f27e61297e87751ec657a564fef (diff) |
SkXPS: clean up SkConstexprMath
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2000853003
Review-Url: https://codereview.chromium.org/2000853003
-rw-r--r-- | gyp/xps.gyp | 1 | ||||
-rw-r--r-- | src/xps/SkConstexprMath.h | 54 | ||||
-rw-r--r-- | src/xps/SkXPSDevice.cpp | 18 |
3 files changed, 11 insertions, 62 deletions
diff --git a/gyp/xps.gyp b/gyp/xps.gyp index 2c96e36137..f326770ec4 100644 --- a/gyp/xps.gyp +++ b/gyp/xps.gyp @@ -22,7 +22,6 @@ '../src/utils', # needed to get SkBitSet.h ], 'sources': [ - '../src/xps/SkConstexprMath.h', '../src/xps/SkDocument_XPS.cpp', '../src/xps/SkXPSDevice.cpp', '../src/xps/SkXPSDevice.h', diff --git a/src/xps/SkConstexprMath.h b/src/xps/SkConstexprMath.h deleted file mode 100644 index 9625d5112b..0000000000 --- a/src/xps/SkConstexprMath.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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)) - -// Compile-time constant maximum value of two unsigned values. -template <uintmax_t a, uintmax_t b> struct SkTUMax { - static const uintmax_t value = (b < a) ? a : b; -}; - -#endif diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp index aef9dc8baf..eb983fc0d7 100644 --- a/src/xps/SkXPSDevice.cpp +++ b/src/xps/SkXPSDevice.cpp @@ -18,9 +18,9 @@ #include <XpsObjectModel.h> #include <T2EmbApi.h> #include <FontSub.h> +#include <limits> #include "SkColor.h" -#include "SkConstexprMath.h" #include "SkData.h" #include "SkDraw.h" #include "SkEndian.h" @@ -190,6 +190,10 @@ bool SkXPSDevice::beginSheet( return true; } +template <typename T> static constexpr size_t sk_digits_in() { + return static_cast<size_t>(std::numeric_limits<T>::digits10 + 1); +} + HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page, const unsigned int pageNum, IXpsOMImageResource** image) { @@ -202,10 +206,9 @@ HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page, "Could not create thumbnail generator."); SkTScopedComPtr<IOpcPartUri> partUri; - static const size_t size = SkTUMax< - SK_ARRAY_COUNT(L"/Documents/1/Metadata/.png") + SK_DIGITS_IN(pageNum), - SK_ARRAY_COUNT(L"/Metadata/" L_GUID_ID L".png") - >::value; + constexpr size_t size = SkTMax( + SK_ARRAY_COUNT(L"/Documents/1/Metadata/.png") + sk_digits_in<decltype(pageNum)>(), + SK_ARRAY_COUNT(L"/Metadata/" L_GUID_ID L".png")); wchar_t buffer[size]; if (pageNum > 0) { swprintf_s(buffer, size, L"/Documents/1/Metadata/%u.png", pageNum); @@ -229,8 +232,9 @@ HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page, HRESULT SkXPSDevice::createXpsPage(const XPS_SIZE& pageSize, IXpsOMPage** page) { - static const size_t size = SK_ARRAY_COUNT(L"/Documents/1/Pages/.fpage") - + SK_DIGITS_IN(fCurrentPage); + constexpr size_t size = + SK_ARRAY_COUNT(L"/Documents/1/Pages/.fpage") + + sk_digits_in<decltype(fCurrentPage)>(); wchar_t buffer[size]; swprintf_s(buffer, size, L"/Documents/1/Pages/%u.fpage", this->fCurrentPage); |