Clean up a few includes, introduce iwyu.

The current include-what-you-use with current clang is much less
noisy and more useful than it has been in the past. This change
introduces a few IWYU directives (which are helpful documentation for
humans as well) and fixes a few sets of includes.

Review URL: https://codereview.chromium.org/1207893002
diff --git a/include/core/SkAtomics.h b/include/core/SkAtomics.h
index be94164..d31d9c6 100644
--- a/include/core/SkAtomics.h
+++ b/include/core/SkAtomics.h
@@ -67,6 +67,7 @@
     T fVal;
 };
 
+// IWYU pragma: begin_exports
 #if defined(_MSC_VER)
     #include "../ports/SkAtomics_std.h"
 #elif !defined(SK_BUILD_FOR_IOS) && defined(__ATOMIC_RELAXED)
@@ -74,6 +75,7 @@
 #else
     #include "../ports/SkAtomics_sync.h"
 #endif
+// IWYU pragma: end_exports
 
 // From here down we have shims for our old atomics API, to be weaned off of.
 // We use the default sequentially-consistent memory order to make things simple
diff --git a/include/core/SkMutex.h b/include/core/SkMutex.h
index 08b220c..eb5e29b 100644
--- a/include/core/SkMutex.h
+++ b/include/core/SkMutex.h
@@ -11,11 +11,13 @@
 // This file is not part of the public Skia API.
 #include "SkTypes.h"
 
+// IWYU pragma: begin_exports
 #if defined(SK_BUILD_FOR_WIN)
     #include "../ports/SkMutex_win.h"
 #else
     #include "../ports/SkMutex_pthread.h"
 #endif
+// IWYU pragma: end_exports
 
 template <typename Lock>
 class SkAutoTAcquire : SkNoncopyable {
diff --git a/include/core/SkPostConfig.h b/include/core/SkPostConfig.h
index 2074230..6f3e2d1 100644
--- a/include/core/SkPostConfig.h
+++ b/include/core/SkPostConfig.h
@@ -8,7 +8,7 @@
 #ifndef SkPostConfig_DEFINED
 #define SkPostConfig_DEFINED
 
-#if defined(SK_BUILD_FOR_WIN32) || defined(SK_BUILD_FOR_WINCE)
+#if defined(SK_BUILD_FOR_WIN32)
 #  define SK_BUILD_FOR_WIN
 #endif
 
@@ -215,13 +215,6 @@
 #endif
 
 //////////////////////////////////////////////////////////////////////////////////////////////
-#ifndef SK_BUILD_FOR_WINCE
-#  include <string.h>
-#  include <stdlib.h>
-#else
-#  define _CMNINTRIN_DECLARE_ONLY
-#  include "cmnintrin.h"
-#endif
 
 #if defined SK_DEBUG && defined SK_BUILD_FOR_WIN32
 #  ifdef free
diff --git a/include/core/SkTypes.h b/include/core/SkTypes.h
index 1b0b12c..1a165a1 100644
--- a/include/core/SkTypes.h
+++ b/include/core/SkTypes.h
@@ -8,9 +8,11 @@
 #ifndef SkTypes_DEFINED
 #define SkTypes_DEFINED
 
+// IWYU pragma: begin_exports
 #include "SkPreConfig.h"
 #include "SkUserConfig.h"
 #include "SkPostConfig.h"
+#include <stddef.h>
 #include <stdint.h>
 #include <sys/types.h>
 
@@ -19,6 +21,10 @@
 #elif SK_CPU_SSE_LEVEL >= SK_CPU_SSE_LEVEL_SSE2
     #include <immintrin.h>
 #endif
+// IWYU pragma: end_exports
+
+#include <stdlib.h>
+#include <string.h>
 
 /** \file SkTypes.h
 */
diff --git a/include/ports/SkFontMgr_indirect.h b/include/ports/SkFontMgr_indirect.h
index 96ba363..2e28640 100644
--- a/include/ports/SkFontMgr_indirect.h
+++ b/include/ports/SkFontMgr_indirect.h
@@ -10,16 +10,17 @@
 
 #include "SkDataTable.h"
 #include "SkFontMgr.h"
-#include "SkFontStyle.h"
 #include "SkMutex.h"
+#include "SkRefCnt.h"
 #include "SkRemotableFontMgr.h"
 #include "SkTArray.h"
 #include "SkTypeface.h"
+#include "SkTypes.h"
 
 class SkData;
-class SkStream;
+class SkFontStyle;
+class SkStreamAsset;
 class SkString;
-class SkTypeface;
 
 class SK_API SkFontMgr_Indirect : public SkFontMgr {
 public:
diff --git a/include/ports/SkRemotableFontMgr.h b/include/ports/SkRemotableFontMgr.h
index 63c032c..23abd7f 100644
--- a/include/ports/SkRemotableFontMgr.h
+++ b/include/ports/SkRemotableFontMgr.h
@@ -11,10 +11,10 @@
 #include "SkFontStyle.h"
 #include "SkRefCnt.h"
 #include "SkTemplates.h"
+#include "SkTypes.h"
 
 class SkDataTable;
 class SkStreamAsset;
-class SkString;
 
 struct SK_API SkFontIdentity {
     static const uint32_t kInvalidDataId = 0xFFFFFFFF;
@@ -35,8 +35,6 @@
 
 class SK_API SkRemotableFontIdentitySet : public SkRefCnt {
 public:
-    
-
     SkRemotableFontIdentitySet(int count, SkFontIdentity** data);
 
     int count() const { return fCount; }
@@ -57,8 +55,6 @@
 
 class SK_API SkRemotableFontMgr : public SkRefCnt {
 public:
-    
-
     /**
      *  Returns the names of the known fonts on the system.
      *  Will not return NULL, will return an empty table if no families exist.
diff --git a/src/fonts/SkFontMgr_indirect.cpp b/src/fonts/SkFontMgr_indirect.cpp
index 172d541..6ad8bfb 100644
--- a/src/fonts/SkFontMgr_indirect.cpp
+++ b/src/fonts/SkFontMgr_indirect.cpp
@@ -5,17 +5,22 @@
  * found in the LICENSE file.
  */
 
-#include "SkFontMgr_indirect.h"
-
 #include "SkDataTable.h"
+#include "SkFontMgr.h"
+#include "SkFontMgr_indirect.h"
 #include "SkFontStyle.h"
+#include "SkMutex.h"
 #include "SkOnce.h"
+#include "SkRefCnt.h"
+#include "SkRemotableFontMgr.h"
 #include "SkStream.h"
-#include "SkTSearch.h"
+#include "SkString.h"
+#include "SkTArray.h"
 #include "SkTypeface.h"
+#include "SkTypes.h"
+#include "SkTemplates.h"
 
 class SkData;
-class SkString;
 
 class SkStyleSet_Indirect : public SkFontStyleSet {
 public:
diff --git a/src/ports/SkDebug_stdio.cpp b/src/ports/SkDebug_stdio.cpp
index 8ff27ade..9e72d47 100644
--- a/src/ports/SkDebug_stdio.cpp
+++ b/src/ports/SkDebug_stdio.cpp
@@ -1,4 +1,3 @@
-
 /*
  * Copyright 2006 The Android Open Source Project
  *
@@ -6,7 +5,6 @@
  * found in the LICENSE file.
  */
 
-
 #include "SkTypes.h"
 
 #include <stdarg.h>
diff --git a/src/ports/SkDiscardableMemory_none.cpp b/src/ports/SkDiscardableMemory_none.cpp
index 51c3164..7e5c0ae 100644
--- a/src/ports/SkDiscardableMemory_none.cpp
+++ b/src/ports/SkDiscardableMemory_none.cpp
@@ -5,6 +5,7 @@
  * found in the LICENSE file.
  */
 
+#include "SkDiscardableMemory.h"
 #include "SkDiscardableMemoryPool.h"
 #include "SkTypes.h"
 
diff --git a/src/ports/SkFontConfigInterface_direct.cpp b/src/ports/SkFontConfigInterface_direct.cpp
index 8589cc2..9ef088d 100644
--- a/src/ports/SkFontConfigInterface_direct.cpp
+++ b/src/ports/SkFontConfigInterface_direct.cpp
@@ -7,17 +7,21 @@
 
 /* migrated from chrome/src/skia/ext/SkFontHost_fontconfig_direct.cpp */
 
-#include <unistd.h>
-#include <fcntl.h>
-
-#include <fontconfig/fontconfig.h>
-
 #include "SkBuffer.h"
+#include "SkDataTable.h"
 #include "SkFontConfigInterface.h"
-#include "SkLazyPtr.h"
+#include "SkFontStyle.h"
 #include "SkMutex.h"
 #include "SkStream.h"
 #include "SkString.h"
+#include "SkTArray.h"
+#include "SkTDArray.h"
+#include "SkTemplates.h"
+#include "SkTypeface.h"
+#include "SkTypes.h"
+
+#include <fontconfig/fontconfig.h>
+#include <unistd.h>
 
 size_t SkFontConfigInterface::FontIdentity::writeToMemory(void* addr) const {
     size_t size = sizeof(fID) + sizeof(fTTCIndex);
diff --git a/src/ports/SkFontHost_fontconfig.cpp b/src/ports/SkFontHost_fontconfig.cpp
index 2fdb16e..540d805 100644
--- a/src/ports/SkFontHost_fontconfig.cpp
+++ b/src/ports/SkFontHost_fontconfig.cpp
@@ -8,8 +8,6 @@
 #include "SkFontConfigInterface.h"
 #include "SkFontConfigTypeface.h"
 #include "SkFontDescriptor.h"
-#include "SkFontHost_FreeType_common.h"
-#include "SkFontStream.h"
 #include "SkStream.h"
 #include "SkTypeface.h"
 #include "SkTypefaceCache.h"
diff --git a/src/ports/SkFontMgr_android.cpp b/src/ports/SkFontMgr_android.cpp
index f85539c..88045a4 100644
--- a/src/ports/SkFontMgr_android.cpp
+++ b/src/ports/SkFontMgr_android.cpp
@@ -5,20 +5,27 @@
  * found in the LICENSE file.
  */
 
+#include "SkFixed.h"
 #include "SkFontDescriptor.h"
 #include "SkFontHost_FreeType_common.h"
 #include "SkFontMgr.h"
 #include "SkFontMgr_android.h"
 #include "SkFontMgr_android_parser.h"
 #include "SkFontStyle.h"
+#include "SkRefCnt.h"
+#include "SkString.h"
 #include "SkStream.h"
+#include "SkTArray.h"
 #include "SkTDArray.h"
 #include "SkTSearch.h"
+#include "SkTemplates.h"
 #include "SkTypeface.h"
 #include "SkTypefaceCache.h"
 
 #include <limits>
 
+class SkData;
+
 class SkTypeface_Android : public SkTypeface_FreeType {
 public:
     SkTypeface_Android(const SkFontStyle& style,
@@ -275,9 +282,9 @@
     }
     static int match_score(const SkFontStyle& pattern, const SkFontStyle& candidate) {
         int score = 0;
-        score += abs((pattern.width() - candidate.width()) * 100);
-        score += abs((pattern.isItalic() == candidate.isItalic()) ? 0 : 1000);
-        score += abs(pattern.weight() - candidate.weight());
+        score += SkTAbs((pattern.width() - candidate.width()) * 100);
+        score += SkTAbs((pattern.isItalic() == candidate.isItalic()) ? 0 : 1000);
+        score += SkTAbs(pattern.weight() - candidate.weight());
         return score;
     }
 
@@ -400,13 +407,7 @@
                 continue;
             }
 
-            SkPaint paint;
-            paint.setTypeface(face);
-            paint.setTextEncoding(SkPaint::kUTF32_TextEncoding);
-
-            uint16_t glyphID;
-            paint.textToGlyphs(&character, sizeof(character), &glyphID);
-            if (glyphID != 0) {
+            if (face->charsToGlyphs(&character, SkTypeface::kUTF32_Encoding, NULL, 0)) {
                 return face.detach();
             }
         }
diff --git a/src/ports/SkFontMgr_android_parser.cpp b/src/ports/SkFontMgr_android_parser.cpp
index 5ca6d4f..53decf3 100644
--- a/src/ports/SkFontMgr_android_parser.cpp
+++ b/src/ports/SkFontMgr_android_parser.cpp
@@ -9,12 +9,13 @@
 #include "SkStream.h"
 #include "SkTDArray.h"
 #include "SkTSearch.h"
-#include "SkTypeface.h"
+#include "SkTemplates.h"
 
-#include <expat.h>
 #include <dirent.h>
+#include <expat.h>
 
 #include <stdlib.h>
+#include <string.h>
 
 #define LMP_SYSTEM_FONTS_FILE "/system/etc/fonts.xml"
 #define OLD_SYSTEM_FONTS_FILE "/system/etc/system_fonts.xml"
diff --git a/src/ports/SkFontMgr_android_parser.h b/src/ports/SkFontMgr_android_parser.h
index d2a4305..175a6fa 100644
--- a/src/ports/SkFontMgr_android_parser.h
+++ b/src/ports/SkFontMgr_android_parser.h
@@ -8,8 +8,11 @@
 #ifndef SkFontMgr_android_parser_DEFINED
 #define SkFontMgr_android_parser_DEFINED
 
+#include "SkFixed.h"
 #include "SkString.h"
+#include "SkTArray.h"
 #include "SkTDArray.h"
+#include "SkTypes.h"
 
 #include <climits>
 #include <limits>
diff --git a/src/ports/SkFontMgr_custom.cpp b/src/ports/SkFontMgr_custom.cpp
index cea0b48..835acd7 100644
--- a/src/ports/SkFontMgr_custom.cpp
+++ b/src/ports/SkFontMgr_custom.cpp
@@ -5,22 +5,25 @@
  * found in the LICENSE file.
  */
 
-#include "SkFontHost_FreeType_common.h"
 #include "SkFontDescriptor.h"
+#include "SkFontHost_FreeType_common.h"
 #include "SkFontMgr.h"
 #include "SkFontMgr_custom.h"
-#include "SkDescriptor.h"
+#include "SkFontStyle.h"
 #include "SkOSFile.h"
-#include "SkPaint.h"
-#include "SkRTConf.h"
-#include "SkString.h"
+#include "SkRefCnt.h"
 #include "SkStream.h"
-#include "SkTSearch.h"
-#include "SkTypefaceCache.h"
+#include "SkString.h"
 #include "SkTArray.h"
+#include "SkTemplates.h"
+#include "SkTypeface.h"
+#include "SkTypefaceCache.h"
+#include "SkTypes.h"
 
 #include <limits>
 
+class SkData;
+
 /** The base SkTypeface implementation for the custom font manager. */
 class SkTypeface_Custom : public SkTypeface_FreeType {
 public:
diff --git a/src/ports/SkFontMgr_fontconfig.cpp b/src/ports/SkFontMgr_fontconfig.cpp
index 7000e31..e98bd01 100644
--- a/src/ports/SkFontMgr_fontconfig.cpp
+++ b/src/ports/SkFontMgr_fontconfig.cpp
@@ -6,19 +6,27 @@
  */
 
 #include "SkDataTable.h"
+#include "SkFixed.h"
 #include "SkFontDescriptor.h"
 #include "SkFontHost_FreeType_common.h"
 #include "SkFontMgr.h"
 #include "SkFontStyle.h"
 #include "SkMath.h"
 #include "SkMutex.h"
-#include "SkString.h"
-#include "SkStream.h"
-#include "SkTDArray.h"
-#include "SkTypefaceCache.h"
 #include "SkOSFile.h"
+#include "SkRefCnt.h"
+#include "SkStream.h"
+#include "SkString.h"
+#include "SkTDArray.h"
+#include "SkTemplates.h"
+#include "SkTypeface.h"
+#include "SkTypefaceCache.h"
+#include "SkTypes.h"
 
 #include <fontconfig/fontconfig.h>
+#include <string.h>
+
+class SkData;
 
 // FC_POSTSCRIPT_NAME was added with b561ff20 which ended up in 2.10.92
 // Ubuntu 12.04 is on 2.8.0, 13.10 is on 2.10.93
diff --git a/src/ports/SkFontMgr_fontconfig_factory.cpp b/src/ports/SkFontMgr_fontconfig_factory.cpp
index b959acb..78792fa 100644
--- a/src/ports/SkFontMgr_fontconfig_factory.cpp
+++ b/src/ports/SkFontMgr_fontconfig_factory.cpp
@@ -7,6 +7,7 @@
 
 #include "SkFontMgr.h"
 #include "SkFontMgr_fontconfig.h"
+#include "SkTypes.h"
 
 SkFontMgr* SkFontMgr::Factory() {
     return SkFontMgr_New_FontConfig(NULL);
diff --git a/src/ports/SkGlobalInitialization_default.cpp b/src/ports/SkGlobalInitialization_default.cpp
index 0f7d71b..fb496f6 100644
--- a/src/ports/SkGlobalInitialization_default.cpp
+++ b/src/ports/SkGlobalInitialization_default.cpp
@@ -5,12 +5,8 @@
  * found in the LICENSE file.
  */
 
-#include "SkTypes.h"
-
 #include "SkBitmapProcShader.h"
-#include "SkMallocPixelRef.h"
 #include "SkPathEffect.h"
-#include "SkPixelRef.h"
 #include "SkXfermode.h"
 
 #include "Sk1DPathEffect.h"
diff --git a/src/ports/SkMemory_malloc.cpp b/src/ports/SkMemory_malloc.cpp
index 0b936c9..f9836c0 100644
--- a/src/ports/SkMemory_malloc.cpp
+++ b/src/ports/SkMemory_malloc.cpp
@@ -1,12 +1,12 @@
-
 /*
  * Copyright 2011 Google Inc.
  *
  * Use of this source code is governed by a BSD-style license that can be
  * found in the LICENSE file.
  */
+
 #include "SkTypes.h"
-#include <stdio.h>
+
 #include <stdlib.h>
 
 #define SK_DEBUGFAILF(fmt, ...) \
diff --git a/src/ports/SkOSFile_posix.cpp b/src/ports/SkOSFile_posix.cpp
index cea688b..6f64478 100644
--- a/src/ports/SkOSFile_posix.cpp
+++ b/src/ports/SkOSFile_posix.cpp
@@ -6,12 +6,14 @@
  */
 
 #include "SkOSFile.h"
-
+#include "SkString.h"
 #include "SkTFitsIn.h"
+#include "SkTemplates.h"
 #include "SkTypes.h"
 
 #include <dirent.h>
 #include <stdio.h>
+#include <string.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
diff --git a/src/ports/SkOSFile_stdio.cpp b/src/ports/SkOSFile_stdio.cpp
index d634625..a7d776a 100644
--- a/src/ports/SkOSFile_stdio.cpp
+++ b/src/ports/SkOSFile_stdio.cpp
@@ -6,11 +6,11 @@
  */
 
 #include "SkOSFile.h"
+#include "SkTypes.h"
 
 #include <errno.h>
 #include <stdio.h>
 #include <sys/stat.h>
-#include <sys/types.h>
 
 #ifdef _WIN32
 #include <direct.h>
diff --git a/src/ports/SkTime_Unix.cpp b/src/ports/SkTime_Unix.cpp
index 2d5fa27..84f1a4e 100644
--- a/src/ports/SkTime_Unix.cpp
+++ b/src/ports/SkTime_Unix.cpp
@@ -6,8 +6,8 @@
  * found in the LICENSE file.
  */
 
-
 #include "SkTime.h"
+#include "SkTypes.h"
 
 #include <sys/time.h>
 #include <time.h>