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 - -template -struct SK_LOG { - //! Compile-time constant ceiling(logB(N)). - static const uintmax_t value = 1 + SK_LOG::value; -}; -template -struct SK_LOG<1, B> { - static const uintmax_t value = 0; -}; -template -struct SK_LOG<0, B> { - static const uintmax_t value = 0; -}; - -template -struct SK_2N1 { - //! Compile-time constant (2^N)-1. - static const uintmax_t value = (SK_2N1::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::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 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 #include #include +#include #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 static constexpr size_t sk_digits_in() { + return static_cast(std::numeric_limits::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 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(), + 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(); wchar_t buffer[size]; swprintf_s(buffer, size, L"/Documents/1/Pages/%u.fpage", this->fCurrentPage);