diff options
author | 2016-06-07 17:21:10 -0700 | |
---|---|---|
committer | 2016-06-07 17:21:10 -0700 | |
commit | 4dbbd04314cc0606f8d3bafe515c97e52c180f73 (patch) | |
tree | 9c5f935ce0a61cf51d0dfe0d62f727b72f5e8481 /src | |
parent | 50bcb189f8785a599a3024d8eba4681c2e8ca37a (diff) |
SkLeanWindows.h: #include "Windows.h" fewer places
$ git grep -l '<windows.h>' include src
include/private/SkLeanWindows.h
$ git grep -l SkLeanWindows.h | grep '\.h$'
include/ports/SkTypeface_win.h
include/utils/win/SkHRESULT.h
include/utils/win/SkTScopedComPtr.h
include/views/SkEvent.h
src/core/SkMathPriv.h
src/ports/SkTypeface_win_dw.h
src/utils/SkThreadUtils_win.h
src/utils/win/SkWGL.h
The same for `#include <intrin.h>` that was found in SkMath.h.
Those functions that needed it are moved to SkMathPriv.h.
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2041943002
CQ_INCLUDE_TRYBOTS=tryserver.chromium.win:win_chromium_compile_dbg_ng,win_chromium_compile_rel_ng
Review-Url: https://codereview.chromium.org/2041943002
Diffstat (limited to 'src')
32 files changed, 108 insertions, 40 deletions
diff --git a/src/core/SkEdge.cpp b/src/core/SkEdge.cpp index 49df95b568..d91c3e6bce 100644 --- a/src/core/SkEdge.cpp +++ b/src/core/SkEdge.cpp @@ -8,7 +8,7 @@ #include "SkEdge.h" #include "SkFDot6.h" -#include "SkMath.h" +#include "SkMathPriv.h" /* In setLine, setQuadratic, setCubic, the first thing we do is to convert diff --git a/src/core/SkMathPriv.h b/src/core/SkMathPriv.h index 1b64a6cd33..fca09f3ffc 100644 --- a/src/core/SkMathPriv.h +++ b/src/core/SkMathPriv.h @@ -92,4 +92,70 @@ static inline float SkPinToUnitFloat(float x) { static inline uint32_t SkBSwap32(uint32_t v) { return __builtin_bswap32(v); } #endif +//! Returns the number of leading zero bits (0...32) +int SkCLZ_portable(uint32_t); + +#ifndef SkCLZ + #if defined(SK_BUILD_FOR_WIN32) + #include <intrin.h> + + static inline int SkCLZ(uint32_t mask) { + if (mask) { + unsigned long index; + _BitScanReverse(&index, mask); + // Suppress this bogus /analyze warning. The check for non-zero + // guarantees that _BitScanReverse will succeed. +#pragma warning(suppress : 6102) // Using 'index' from failed function call + return index ^ 0x1F; + } else { + return 32; + } + } + #elif defined(SK_CPU_ARM32) || defined(__GNUC__) || defined(__clang__) + static inline int SkCLZ(uint32_t mask) { + // __builtin_clz(0) is undefined, so we have to detect that case. + return mask ? __builtin_clz(mask) : 32; + } + #else + #define SkCLZ(x) SkCLZ_portable(x) + #endif +#endif + +/** + * Returns the smallest power-of-2 that is >= the specified value. If value + * is already a power of 2, then it is returned unchanged. It is undefined + * if value is <= 0. + */ +static inline int SkNextPow2(int value) { + SkASSERT(value > 0); + return 1 << (32 - SkCLZ(value - 1)); +} + +/** + * Returns the log2 of the specified value, were that value to be rounded up + * to the next power of 2. It is undefined to pass 0. Examples: + * SkNextLog2(1) -> 0 + * SkNextLog2(2) -> 1 + * SkNextLog2(3) -> 2 + * SkNextLog2(4) -> 2 + * SkNextLog2(5) -> 3 + */ +static inline int SkNextLog2(uint32_t value) { + SkASSERT(value != 0); + return 32 - SkCLZ(value - 1); +} + +/////////////////////////////////////////////////////////////////////////////// + +/** + * Return the next power of 2 >= n. + */ +static inline uint32_t GrNextPow2(uint32_t n) { + return n ? (1 << (32 - SkCLZ(n - 1))) : 1; +} + +static inline int GrNextPow2(int n) { + SkASSERT(n >= 0); // this impl only works for non-neg. + return n ? (1 << (32 - SkCLZ(n - 1))) : 1; +} #endif diff --git a/src/core/SkMipMap.cpp b/src/core/SkMipMap.cpp index 76f1718e7f..e6f4bad6d2 100644 --- a/src/core/SkMipMap.cpp +++ b/src/core/SkMipMap.cpp @@ -9,7 +9,7 @@ #include "SkBitmap.h" #include "SkColorPriv.h" #include "SkHalf.h" -#include "SkMath.h" +#include "SkMathPriv.h" #include "SkNx.h" #include "SkTypes.h" diff --git a/src/core/SkScan_Hairline.cpp b/src/core/SkScan_Hairline.cpp index a023ca1f24..fc9e82818d 100644 --- a/src/core/SkScan_Hairline.cpp +++ b/src/core/SkScan_Hairline.cpp @@ -7,6 +7,7 @@ #include "SkScan.h" #include "SkBlitter.h" +#include "SkMathPriv.h" #include "SkRasterClip.h" #include "SkFDot6.h" #include "SkLineClipper.h" diff --git a/src/core/SkSemaphore.cpp b/src/core/SkSemaphore.cpp index 2286c0b2bb..1ebe51b15c 100644 --- a/src/core/SkSemaphore.cpp +++ b/src/core/SkSemaphore.cpp @@ -5,6 +5,7 @@ * found in the LICENSE file. */ +#include "../private/SkLeanWindows.h" #include "../private/SkSemaphore.h" #if defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS) diff --git a/src/core/SkTSort.h b/src/core/SkTSort.h index 51b103cb5d..7101bab9ba 100644 --- a/src/core/SkTSort.h +++ b/src/core/SkTSort.h @@ -10,7 +10,7 @@ #define SkTSort_DEFINED #include "SkTypes.h" -#include "SkMath.h" +#include "SkMathPriv.h" /* A comparison functor which performs the comparison 'a < b'. */ template <typename T> struct SkTCompareLT { diff --git a/src/core/SkTaskGroup.cpp b/src/core/SkTaskGroup.cpp index 7a58c865a7..d151510cfa 100644 --- a/src/core/SkTaskGroup.cpp +++ b/src/core/SkTaskGroup.cpp @@ -5,6 +5,7 @@ * found in the LICENSE file. */ +#include "SkLeanWindows.h" #include "SkOnce.h" #include "SkSemaphore.h" #include "SkSpinlock.h" diff --git a/src/core/SkThreadID.cpp b/src/core/SkThreadID.cpp index 589b4da05a..948884d0ce 100644 --- a/src/core/SkThreadID.cpp +++ b/src/core/SkThreadID.cpp @@ -5,10 +5,10 @@ * found in the LICENSE file. */ +#include "SkLeanWindows.h" #include "SkThreadID.h" #ifdef SK_BUILD_FOR_WIN - #include <windows.h> SkThreadID SkGetThreadID() { return GetCurrentThreadId(); } #else #include <pthread.h> diff --git a/src/core/SkTime.cpp b/src/core/SkTime.cpp index e89d5b9b3a..4ed08928ba 100644 --- a/src/core/SkTime.cpp +++ b/src/core/SkTime.cpp @@ -5,6 +5,7 @@ * found in the LICENSE file. */ +#include "SkLeanWindows.h" #include "SkString.h" #include "SkTime.h" #include "SkTypes.h" @@ -25,10 +26,8 @@ void SkTime::DateTime::toISO8601(SkString* dst) const { } } - #ifdef SK_BUILD_FOR_WIN32 -#include "windows.h" void SkTime::GetDateTime(DateTime* dt) { if (dt) { SYSTEMTIME st; diff --git a/src/effects/gradients/SkClampRange.cpp b/src/effects/gradients/SkClampRange.cpp index 0bf30f14ea..5fd1c0369e 100644 --- a/src/effects/gradients/SkClampRange.cpp +++ b/src/effects/gradients/SkClampRange.cpp @@ -6,7 +6,7 @@ */ #include "SkClampRange.h" -#include "SkMath.h" +#include "SkMathPriv.h" static int SkCLZ64(uint64_t value) { int count = 0; diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp index 691c0ab83a..a381f311aa 100644 --- a/src/gpu/GrGpu.cpp +++ b/src/gpu/GrGpu.cpp @@ -21,7 +21,7 @@ #include "GrStencilAttachment.h" #include "GrSurfacePriv.h" #include "GrTexturePriv.h" -#include "SkTypes.h" +#include "SkMathPriv.h" GrMesh& GrMesh::operator =(const GrMesh& di) { fPrimitiveType = di.fPrimitiveType; diff --git a/src/gpu/GrPathUtils.cpp b/src/gpu/GrPathUtils.cpp index fcb32cbd9a..aa55dade96 100644 --- a/src/gpu/GrPathUtils.cpp +++ b/src/gpu/GrPathUtils.cpp @@ -9,6 +9,7 @@ #include "GrTypes.h" #include "SkGeometry.h" +#include "SkMathPriv.h" SkScalar GrPathUtils::scaleToleranceToSrc(SkScalar devTol, const SkMatrix& viewM, diff --git a/src/gpu/GrRectanizer_pow2.h b/src/gpu/GrRectanizer_pow2.h index 451589db0a..296e0520bf 100644 --- a/src/gpu/GrRectanizer_pow2.h +++ b/src/gpu/GrRectanizer_pow2.h @@ -9,6 +9,7 @@ #define GrRectanizer_pow2_DEFINED #include "GrRectanizer.h" +#include "SkMathPriv.h" #include "SkPoint.h" // This Rectanizer quantizes the incoming rects to powers of 2. Each power diff --git a/src/gpu/GrResourceProvider.cpp b/src/gpu/GrResourceProvider.cpp index 9fa202af6c..efbcdba248 100644 --- a/src/gpu/GrResourceProvider.cpp +++ b/src/gpu/GrResourceProvider.cpp @@ -15,6 +15,7 @@ #include "GrResourceCache.h" #include "GrResourceKey.h" #include "GrStencilAttachment.h" +#include "SkMathPriv.h" GR_DECLARE_STATIC_UNIQUE_KEY(gQuadIndexBufferKey); diff --git a/src/gpu/GrTextureProvider.cpp b/src/gpu/GrTextureProvider.cpp index 1053ab272b..69792ede81 100644 --- a/src/gpu/GrTextureProvider.cpp +++ b/src/gpu/GrTextureProvider.cpp @@ -10,6 +10,7 @@ #include "GrResourceCache.h" #include "GrGpu.h" #include "../private/GrSingleOwner.h" +#include "SkMathPriv.h" #include "SkTArray.h" #define ASSERT_SINGLE_OWNER \ diff --git a/src/gpu/batches/GrAtlasTextBatch.cpp b/src/gpu/batches/GrAtlasTextBatch.cpp index 5a41457c58..32a64c3b17 100644 --- a/src/gpu/batches/GrAtlasTextBatch.cpp +++ b/src/gpu/batches/GrAtlasTextBatch.cpp @@ -11,6 +11,7 @@ #include "GrResourceProvider.h" #include "SkGlyphCache.h" +#include "SkMathPriv.h" #include "effects/GrBitmapTextGeoProc.h" #include "effects/GrDistanceFieldGeoProc.h" diff --git a/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp b/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp index 1eae5d7502..5f26fdde34 100644 --- a/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp +++ b/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp @@ -7,11 +7,11 @@ #include "SkTypes.h" #if defined(SK_BUILD_FOR_WIN32) +#include "SkLeanWindows.h" + #include "gl/GrGLInterface.h" #include "gl/GrGLAssembleInterface.h" #include "gl/GrGLUtil.h" -#define WIN32_LEAN_AND_MEAN -#include <windows.h> class AutoLibraryUnload { public: diff --git a/src/ports/SkDebug_win.cpp b/src/ports/SkDebug_win.cpp index b0c5725a79..da1e2b573f 100644 --- a/src/ports/SkDebug_win.cpp +++ b/src/ports/SkDebug_win.cpp @@ -5,16 +5,16 @@ * found in the LICENSE file. */ - - #include "SkTypes.h" + #if defined(SK_BUILD_FOR_WIN32) -static const size_t kBufferSize = 2048; +#include "SkLeanWindows.h" #include <stdarg.h> #include <stdio.h> -#include <windows.h> + +static const size_t kBufferSize = 2048; void SkDebugf(const char format[], ...) { char buffer[kBufferSize + 1]; diff --git a/src/ports/SkFontHost_mac.cpp b/src/ports/SkFontHost_mac.cpp index 0cc436f7c3..c129a6b24b 100644 --- a/src/ports/SkFontHost_mac.cpp +++ b/src/ports/SkFontHost_mac.cpp @@ -29,6 +29,7 @@ #include "SkFontMgr.h" #include "SkGlyph.h" #include "SkMaskGamma.h" +#include "SkMathPriv.h" #include "SkMutex.h" #include "SkOTTable_glyf.h" #include "SkOTTable_head.h" diff --git a/src/ports/SkOSFile_win.cpp b/src/ports/SkOSFile_win.cpp index 6bdf9ab163..cf46cea985 100644 --- a/src/ports/SkOSFile_win.cpp +++ b/src/ports/SkOSFile_win.cpp @@ -8,8 +8,8 @@ #include "SkTypes.h" #if defined(SK_BUILD_FOR_WIN32) +#include "SkLeanWindows.h" #include "SkOSFile.h" - #include "SkTFitsIn.h" #include <io.h> diff --git a/src/ports/SkOSLibrary_win.cpp b/src/ports/SkOSLibrary_win.cpp index 63d8d2d383..b6d8dd3183 100644 --- a/src/ports/SkOSLibrary_win.cpp +++ b/src/ports/SkOSLibrary_win.cpp @@ -8,7 +8,7 @@ #if defined(SK_BUILD_FOR_WIN32) #include "SkOSLibrary.h" -#include <windows.h> +#include "SkLeanWindows.h" void* DynamicLoadLibrary(const char* libraryName) { return LoadLibraryA(libraryName); diff --git a/src/ports/SkTLS_win.cpp b/src/ports/SkTLS_win.cpp index 8bc55a0f2c..c349ad99c2 100644 --- a/src/ports/SkTLS_win.cpp +++ b/src/ports/SkTLS_win.cpp @@ -7,8 +7,9 @@ #include "SkTypes.h" #if defined(SK_BUILD_FOR_WIN32) -#include "SkTLS.h" +#include "SkLeanWindows.h" #include "SkMutex.h" +#include "SkTLS.h" static bool gOnce = false; static DWORD gTlsIndex; diff --git a/src/ports/SkTypeface_win_dw.h b/src/ports/SkTypeface_win_dw.h index 3e429f47cb..11b3fb5ffc 100644 --- a/src/ports/SkTypeface_win_dw.h +++ b/src/ports/SkTypeface_win_dw.h @@ -11,10 +11,10 @@ #include "SkAdvancedTypefaceMetrics.h" #include "SkDWrite.h" #include "SkHRESULT.h" +#include "SkLeanWindows.h" #include "SkTScopedComPtr.h" #include "SkTypeface.h" #include "SkTypefaceCache.h" -#include "SkTypes.h" #include <dwrite.h> #if SK_HAS_DWRITE_1_H diff --git a/src/utils/SkTextureCompressor.cpp b/src/utils/SkTextureCompressor.cpp index e308f6e480..086214ec59 100644 --- a/src/utils/SkTextureCompressor.cpp +++ b/src/utils/SkTextureCompressor.cpp @@ -14,6 +14,7 @@ #include "SkBitmapProcShader.h" #include "SkData.h" #include "SkEndian.h" +#include "SkMathPriv.h" #include "SkOpts.h" #ifndef SK_IGNORE_ETC1_SUPPORT diff --git a/src/utils/SkTextureCompressor_ASTC.cpp b/src/utils/SkTextureCompressor_ASTC.cpp index 02f4f17144..8a96b911ea 100644 --- a/src/utils/SkTextureCompressor_ASTC.cpp +++ b/src/utils/SkTextureCompressor_ASTC.cpp @@ -10,7 +10,7 @@ #include "SkBlitter.h" #include "SkEndian.h" -#include "SkMath.h" +#include "SkMathPriv.h" // This table contains the weight values for each texel. This is used in determining // how to convert a 12x12 grid of alpha values into a 6x5 grid of index values. Since diff --git a/src/utils/SkThreadUtils_win.h b/src/utils/SkThreadUtils_win.h index 51b32fad6f..b1de4816cf 100644 --- a/src/utils/SkThreadUtils_win.h +++ b/src/utils/SkThreadUtils_win.h @@ -8,8 +8,7 @@ #ifndef SkThreadUtils_WinData_DEFINED #define SkThreadUtils_WinData_DEFINED -#include "SkTypes.h" - +#include "SkLeanWindows.h" #include "SkThreadUtils.h" class SkThread_WinData : SkNoncopyable { diff --git a/src/utils/win/SkAutoCoInitialize.cpp b/src/utils/win/SkAutoCoInitialize.cpp index 3b7b42b74f..f6da67dcae 100644 --- a/src/utils/win/SkAutoCoInitialize.cpp +++ b/src/utils/win/SkAutoCoInitialize.cpp @@ -8,12 +8,11 @@ #include "SkTypes.h" #if defined(SK_BUILD_FOR_WIN32) - -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#include <ole2.h> #include "SkAutoCoInitialize.h" +#include <objbase.h> +#include <winerror.h> + SkAutoCoInitialize::SkAutoCoInitialize() : fHR( CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED | COINIT_DISABLE_OLE1DDE) diff --git a/src/utils/win/SkIStream.cpp b/src/utils/win/SkIStream.cpp index ad9bf05076..560a947fcf 100644 --- a/src/utils/win/SkIStream.cpp +++ b/src/utils/win/SkIStream.cpp @@ -8,9 +8,6 @@ #include "SkTypes.h" #if defined(SK_BUILD_FOR_WIN32) -#define WIN32_LEAN_AND_MEAN -#include <windows.h> -#include <ole2.h> #include "SkIStream.h" #include "SkStream.h" diff --git a/src/utils/win/SkWGL.h b/src/utils/win/SkWGL.h index ebd95e7a83..3799377cc3 100644 --- a/src/utils/win/SkWGL.h +++ b/src/utils/win/SkWGL.h @@ -10,6 +10,8 @@ #ifndef SkWGL_DEFINED #define SkWGL_DEFINED +#include "SkLeanWindows.h" + /** * Working with WGL extensions can be a pain. Among the reasons is that You must * have a GL context to get the proc addresses, but you want to use the procs to @@ -22,16 +24,6 @@ * an extension. */ -#if !defined(WIN32_LEAN_AND_MEAN) - #define WIN32_LEAN_AND_MEAN - #define SK_LOCAL_LEAN_AND_MEAN -#endif -#include <windows.h> -#if defined(SK_LOCAL_LEAN_AND_MEAN) - #undef WIN32_LEAN_AND_MEAN - #undef SK_LOCAL_LEAN_AND_MEAN -#endif - #define SK_WGL_DRAW_TO_WINDOW 0x2001 #define SK_WGL_ACCELERATION 0x2003 #define SK_WGL_SUPPORT_OPENGL 0x2010 diff --git a/src/views/win/SkOSWindow_win.cpp b/src/views/win/SkOSWindow_win.cpp index a5aafd05d1..c93d60b2d6 100644 --- a/src/views/win/SkOSWindow_win.cpp +++ b/src/views/win/SkOSWindow_win.cpp @@ -8,6 +8,8 @@ #if defined(SK_BUILD_FOR_WIN) +#include "SkLeanWindows.h" + #include <GL/gl.h> #include <WindowsX.h> #include "win/SkWGL.h" diff --git a/src/views/win/skia_win.cpp b/src/views/win/skia_win.cpp index 8996ddac4d..fc07bd46da 100644 --- a/src/views/win/skia_win.cpp +++ b/src/views/win/skia_win.cpp @@ -4,10 +4,11 @@ * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ -#include <windows.h> -#include <tchar.h> #include "SkTypes.h" + +#include <tchar.h> + #include "SkApplication.h" #include "SkOSWindow_Win.h" diff --git a/src/xps/SkXPSDevice.cpp b/src/xps/SkXPSDevice.cpp index eb983fc0d7..ca0ee04add 100644 --- a/src/xps/SkXPSDevice.cpp +++ b/src/xps/SkXPSDevice.cpp @@ -8,6 +8,8 @@ #include "SkTypes.h" #if defined(SK_BUILD_FOR_WIN32) +#include "SkLeanWindows.h" + #ifndef UNICODE #define UNICODE #endif |