move SkBitmapProvider to its own file

BUG=skia:

Review URL: https://codereview.chromium.org/1346713002
diff --git a/src/core/SkBitmapController.cpp b/src/core/SkBitmapController.cpp
index c75d2ea..5cfa525 100644
--- a/src/core/SkBitmapController.cpp
+++ b/src/core/SkBitmapController.cpp
@@ -7,7 +7,7 @@
 
 #include "SkBitmap.h"
 #include "SkBitmapController.h"
-#include "SkImage_Base.h"
+#include "SkBitmapProvider.h"
 #include "SkMatrix.h"
 #include "SkPixelRef.h"
 #include "SkTemplates.h"
@@ -17,76 +17,6 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-int SkBitmapProvider::width() const {
-    return fImage ? fImage->width() : fBitmap.width();
-}
-
-int SkBitmapProvider::height() const {
-    return fImage ? fImage->height() : fBitmap.height();
-}
-
-uint32_t SkBitmapProvider::getID() const {
-    return fImage ? fImage->uniqueID() : fBitmap.getGenerationID();
-}
-
-bool SkBitmapProvider::validForDrawing() const {
-    if (!fImage) {
-        if (0 == fBitmap.width() || 0 == fBitmap.height()) {
-            return false;
-        }
-        if (nullptr == fBitmap.pixelRef()) {
-            return false;   // no pixels to read
-        }
-        if (fBitmap.getTexture()) {
-            // we can handle texture (ugh) since lockPixels will perform a read-back
-            return true;
-        }
-        if (kIndex_8_SkColorType == fBitmap.colorType()) {
-            SkAutoLockPixels alp(fBitmap); // but we need to call it before getColorTable() is safe.
-            if (!fBitmap.getColorTable()) {
-                return false;
-            }
-        }
-    }
-    return true;
-}
-
-SkImageInfo SkBitmapProvider::info() const {
-    if (fImage) {
-        SkAlphaType at = fImage->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
-        return SkImageInfo::MakeN32(fImage->width(), fImage->height(), at);
-    } else {
-        return fBitmap.info();
-    }
-}
-
-SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc(int w, int h) const {
-    return fImage ? SkBitmapCacheDesc::Make(fImage, w, h) : SkBitmapCacheDesc::Make(fBitmap, w, h);
-}
-
-SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc() const {
-    return fImage ? SkBitmapCacheDesc::Make(fImage) : SkBitmapCacheDesc::Make(fBitmap);
-}
-
-void SkBitmapProvider::notifyAddedToCache() const {
-    if (fImage) {
-        // TODO
-    } else {
-        fBitmap.pixelRef()->notifyAddedToCache();
-    }
-}
-
-bool SkBitmapProvider::asBitmap(SkBitmap* bm) const {
-    if (fImage) {
-        return as_IB(fImage)->getROPixels(bm);
-    } else {
-        *bm = fBitmap;
-        return true;
-    }
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
 SkBitmapController::State* SkBitmapController::requestBitmap(const SkBitmapProvider& provider,
                                                              const SkMatrix& inv,
                                                              SkFilterQuality quality,
diff --git a/src/core/SkBitmapController.h b/src/core/SkBitmapController.h
index e6c4443..32e73e8 100644
--- a/src/core/SkBitmapController.h
+++ b/src/core/SkBitmapController.h
@@ -11,37 +11,9 @@
 #include "SkBitmap.h"
 #include "SkBitmapCache.h"
 #include "SkFilterQuality.h"
-#include "SkImage.h"
 #include "SkMatrix.h"
 
-class SkBitmapProvider {
-public:
-    explicit SkBitmapProvider(const SkBitmap& bm) : fBitmap(bm) {}
-    explicit SkBitmapProvider(const SkImage* img) : fImage(SkSafeRef(img)) {}
-    SkBitmapProvider(const SkBitmapProvider& other)
-        : fBitmap(other.fBitmap)
-        , fImage(SkSafeRef(other.fImage.get()))
-    {}
-
-    int width() const;
-    int height() const;
-    uint32_t getID() const;
-
-    bool validForDrawing() const;
-    SkImageInfo info() const;
-
-    SkBitmapCacheDesc makeCacheDesc(int w, int h) const;
-    SkBitmapCacheDesc makeCacheDesc() const;
-    void notifyAddedToCache() const;
-
-    // Only call this if you're sure you need the bits, since it make be expensive
-    // ... cause a decode and cache, or gpu-readback
-    bool asBitmap(SkBitmap*) const;
-
-private:
-    SkBitmap fBitmap;
-    SkAutoTUnref<const SkImage> fImage;
-};
+class SkBitmapProvider;
 
 /**
  *  Handles request to scale, filter, and lock a bitmap to be rasterized.
diff --git a/src/core/SkBitmapProcShader.cpp b/src/core/SkBitmapProcShader.cpp
index 36bfb1e..125f480 100644
--- a/src/core/SkBitmapProcShader.cpp
+++ b/src/core/SkBitmapProcShader.cpp
@@ -7,6 +7,7 @@
 
 #include "SkBitmapProcShader.h"
 #include "SkBitmapProcState.h"
+#include "SkBitmapProvider.h"
 #include "SkColorPriv.h"
 #include "SkErrorInternals.h"
 #include "SkPixelRef.h"
@@ -78,7 +79,7 @@
 
 SkShader::Context* SkBitmapProcShader::MakeContext(const SkShader& shader,
                                                    TileMode tmx, TileMode tmy,
-                                                   const SkBitmap& bitmap,
+                                                   const SkBitmapProvider& provider,
                                                    const ContextRec& rec, void* storage) {
     SkMatrix totalInverse;
     // Do this first, so we know the matrix can be inverted.
@@ -87,8 +88,7 @@
     }
 
     void* stateStorage = (char*)storage + sizeof(BitmapProcShaderContext);
-    SkBitmapProcState* state = new (stateStorage) SkBitmapProcState(SkBitmapProvider(bitmap),
-                                                                    tmx, tmy);
+    SkBitmapProcState* state = new (stateStorage) SkBitmapProcState(provider, tmx, tmy);
 
     SkASSERT(state);
     if (!state->chooseProcs(totalInverse, *rec.fPaint)) {
@@ -100,7 +100,8 @@
 }
 
 SkShader::Context* SkBitmapProcShader::onCreateContext(const ContextRec& rec, void* storage) const {
-    return MakeContext(*this, (TileMode)fTileModeX, (TileMode)fTileModeY, fRawBitmap, rec, storage);
+    return MakeContext(*this, (TileMode)fTileModeX, (TileMode)fTileModeY,
+                       SkBitmapProvider(fRawBitmap), rec, storage);
 }
 
 SkBitmapProcShader::BitmapProcShaderContext::BitmapProcShaderContext(const SkShader& shader,
diff --git a/src/core/SkBitmapProcShader.h b/src/core/SkBitmapProcShader.h
index 9e90f9f..85e1fd0 100644
--- a/src/core/SkBitmapProcShader.h
+++ b/src/core/SkBitmapProcShader.h
@@ -14,6 +14,7 @@
 #include "SkSmallAllocator.h"
 
 struct SkBitmapProcState;
+class SkBitmapProvider;
 
 class SkBitmapProcShader : public SkShader {
 public:
@@ -65,8 +66,8 @@
     friend class SkImageShader;
 
     static size_t ContextSize();
-    static Context* MakeContext(const SkShader&, TileMode tmx, TileMode tmy, const SkBitmap&,
-                                const ContextRec&, void* storage);
+    static Context* MakeContext(const SkShader&, TileMode tmx, TileMode tmy,
+                                const SkBitmapProvider&, const ContextRec&, void* storage);
 
     typedef SkShader INHERITED;
 };
diff --git a/src/core/SkBitmapProcState.h b/src/core/SkBitmapProcState.h
index b66299c..2ce76bc 100644
--- a/src/core/SkBitmapProcState.h
+++ b/src/core/SkBitmapProcState.h
@@ -11,9 +11,11 @@
 #include "SkBitmap.h"
 #include "SkBitmapController.h"
 #include "SkBitmapFilter.h"
+#include "SkBitmapProvider.h"
 #include "SkMatrix.h"
 #include "SkMipMap.h"
 #include "SkPaint.h"
+#include "SkShader.h"
 #include "SkTemplates.h"
 
 typedef SkFixed3232    SkFractionalInt;
diff --git a/src/core/SkBitmapProvider.cpp b/src/core/SkBitmapProvider.cpp
new file mode 100644
index 0000000..96e29f8
--- /dev/null
+++ b/src/core/SkBitmapProvider.cpp
@@ -0,0 +1,79 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkBitmapProvider.h"
+#include "SkImage_Base.h"
+#include "SkPixelRef.h"
+
+int SkBitmapProvider::width() const {
+    return fImage ? fImage->width() : fBitmap.width();
+}
+
+int SkBitmapProvider::height() const {
+    return fImage ? fImage->height() : fBitmap.height();
+}
+
+uint32_t SkBitmapProvider::getID() const {
+    return fImage ? fImage->uniqueID() : fBitmap.getGenerationID();
+}
+
+bool SkBitmapProvider::validForDrawing() const {
+    if (!fImage) {
+        if (0 == fBitmap.width() || 0 == fBitmap.height()) {
+            return false;
+        }
+        if (nullptr == fBitmap.pixelRef()) {
+            return false;   // no pixels to read
+        }
+        if (fBitmap.getTexture()) {
+            // we can handle texture (ugh) since lockPixels will perform a read-back
+            return true;
+        }
+        if (kIndex_8_SkColorType == fBitmap.colorType()) {
+            SkAutoLockPixels alp(fBitmap); // but we need to call it before getColorTable() is safe.
+            if (!fBitmap.getColorTable()) {
+                return false;
+            }
+        }
+    }
+    return true;
+}
+
+SkImageInfo SkBitmapProvider::info() const {
+    if (fImage) {
+        SkAlphaType at = fImage->isOpaque() ? kOpaque_SkAlphaType : kPremul_SkAlphaType;
+        return SkImageInfo::MakeN32(fImage->width(), fImage->height(), at);
+    } else {
+        return fBitmap.info();
+    }
+}
+
+SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc(int w, int h) const {
+    return fImage ? SkBitmapCacheDesc::Make(fImage, w, h) : SkBitmapCacheDesc::Make(fBitmap, w, h);
+}
+
+SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc() const {
+    return fImage ? SkBitmapCacheDesc::Make(fImage) : SkBitmapCacheDesc::Make(fBitmap);
+}
+
+void SkBitmapProvider::notifyAddedToCache() const {
+    if (fImage) {
+        // TODO
+    } else {
+        fBitmap.pixelRef()->notifyAddedToCache();
+    }
+}
+
+bool SkBitmapProvider::asBitmap(SkBitmap* bm) const {
+    if (fImage) {
+        return as_IB(fImage)->getROPixels(bm);
+    } else {
+        *bm = fBitmap;
+        return true;
+    }
+}
+
diff --git a/src/core/SkBitmapProvider.h b/src/core/SkBitmapProvider.h
new file mode 100644
index 0000000..72964e4
--- /dev/null
+++ b/src/core/SkBitmapProvider.h
@@ -0,0 +1,44 @@
+/*
+ * Copyright 2015 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkBitmapProvider_DEFINED
+#define SkBitmapProvider_DEFINED
+
+#include "SkBitmap.h"
+#include "SkImage.h"
+#include "SkBitmapCache.h"
+
+class SkBitmapProvider {
+public:
+    explicit SkBitmapProvider(const SkBitmap& bm) : fBitmap(bm) {}
+    explicit SkBitmapProvider(const SkImage* img) : fImage(SkSafeRef(img)) {}
+    SkBitmapProvider(const SkBitmapProvider& other)
+        : fBitmap(other.fBitmap)
+        , fImage(SkSafeRef(other.fImage.get()))
+    {}
+
+    int width() const;
+    int height() const;
+    uint32_t getID() const;
+
+    bool validForDrawing() const;
+    SkImageInfo info() const;
+
+    SkBitmapCacheDesc makeCacheDesc(int w, int h) const;
+    SkBitmapCacheDesc makeCacheDesc() const;
+    void notifyAddedToCache() const;
+
+    // Only call this if you're sure you need the bits, since it maybe expensive
+    // ... cause a decode and cache, or gpu-readback
+    bool asBitmap(SkBitmap*) const;
+
+private:
+    SkBitmap fBitmap;
+    SkAutoTUnref<const SkImage> fImage;
+};
+
+#endif