De-virtualize SkBitmapController

Fold its only subclass (SkDefaultBitmapController) into base.

Change-Id: I77f5c9f3b459d644d5749b8ec34722ec6c2228bf
Reviewed-on: https://skia-review.googlesource.com/141541
Reviewed-by: Mike Reed <reed@google.com>
Commit-Queue: Florin Malita <fmalita@chromium.org>
diff --git a/src/core/SkBitmapController.cpp b/src/core/SkBitmapController.cpp
index ed16f9b..dfe1668 100644
--- a/src/core/SkBitmapController.cpp
+++ b/src/core/SkBitmapController.cpp
@@ -16,34 +16,16 @@
 
 ///////////////////////////////////////////////////////////////////////////////////////////////////
 
-SkBitmapController::State* SkBitmapController::requestBitmap(const SkBitmapProvider& provider,
+SkBitmapController::State* SkBitmapController::RequestBitmap(const SkBitmapProvider& provider,
                                                              const SkMatrix& inv,
                                                              SkFilterQuality quality,
                                                              SkArenaAlloc* alloc) {
-    State* state = this->onRequestBitmap(provider, inv, quality, alloc);
-    if (state) {
-        if (nullptr == state->fPixmap.addr()) {
-            state = nullptr;
-        }
-    }
-    return state;
+    auto* state = alloc->make<SkBitmapController::State>(provider, inv, quality);
+
+    return state->pixmap().addr() ? state : nullptr;
 }
 
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-class SkDefaultBitmapControllerState : public SkBitmapController::State {
-public:
-    SkDefaultBitmapControllerState(const SkBitmapProvider&, const SkMatrix& inv, SkFilterQuality);
-
-private:
-    SkBitmap                fResultBitmap;
-    sk_sp<const SkMipMap>   fCurrMip;
-
-    bool processHighRequest(const SkBitmapProvider&);
-    bool processMediumRequest(const SkBitmapProvider&);
-};
-
-bool SkDefaultBitmapControllerState::processHighRequest(const SkBitmapProvider& provider) {
+bool SkBitmapController::State::processHighRequest(const SkBitmapProvider& provider) {
     if (fQuality != kHigh_SkFilterQuality) {
         return false;
     }
@@ -78,7 +60,7 @@
  *  Modulo internal errors, this should always succeed *if* the matrix is downscaling
  *  (in this case, we have the inverse, so it succeeds if fInvMatrix is upscaling)
  */
-bool SkDefaultBitmapControllerState::processMediumRequest(const SkBitmapProvider& provider) {
+bool SkBitmapController::State::processMediumRequest(const SkBitmapProvider& provider) {
     SkASSERT(fQuality <= kMedium_SkFilterQuality);
     if (fQuality != kMedium_SkFilterQuality) {
         return false;
@@ -126,9 +108,9 @@
     return false;
 }
 
-SkDefaultBitmapControllerState::SkDefaultBitmapControllerState(const SkBitmapProvider& provider,
-                                                               const SkMatrix& inv,
-                                                               SkFilterQuality qual) {
+SkBitmapController::State::State(const SkBitmapProvider& provider,
+                                 const SkMatrix& inv,
+                                 SkFilterQuality qual) {
     fInvMatrix = inv;
     fQuality = qual;
 
@@ -142,10 +124,3 @@
     // and will destroy us if it is nullptr.
     fPixmap.reset(fResultBitmap.info(), fResultBitmap.getPixels(), fResultBitmap.rowBytes());
 }
-
-SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBitmapProvider& bm,
-                                                                      const SkMatrix& inverse,
-                                                                      SkFilterQuality quality,
-                                                                      SkArenaAlloc* alloc) {
-    return alloc->make<SkDefaultBitmapControllerState>(bm, inverse, quality);
-}
diff --git a/src/core/SkBitmapController.h b/src/core/SkBitmapController.h
index 394a7cf..2ac6c8c 100644
--- a/src/core/SkBitmapController.h
+++ b/src/core/SkBitmapController.h
@@ -12,6 +12,7 @@
 #include "SkBitmapCache.h"
 #include "SkFilterQuality.h"
 #include "SkMatrix.h"
+#include "SkMipMap.h"
 
 class SkBitmapProvider;
 
@@ -22,42 +23,31 @@
 public:
     class State : ::SkNoncopyable {
     public:
-        virtual ~State() {}
+        State(const SkBitmapProvider&, const SkMatrix& inv, SkFilterQuality);
 
         const SkPixmap& pixmap() const { return fPixmap; }
         const SkMatrix& invMatrix() const { return fInvMatrix; }
         SkFilterQuality quality() const { return fQuality; }
 
-    protected:
-        SkPixmap        fPixmap;
-        SkMatrix        fInvMatrix;
-        SkFilterQuality fQuality;
-
     private:
-        friend class SkBitmapController;
+        bool processHighRequest(const SkBitmapProvider&);
+        bool processMediumRequest(const SkBitmapProvider&);
+
+        SkPixmap              fPixmap;
+        SkMatrix              fInvMatrix;
+        SkFilterQuality       fQuality;
+
+        // Pixmap storage.
+        SkBitmap              fResultBitmap;
+        sk_sp<const SkMipMap> fCurrMip;
+
     };
 
-    virtual ~SkBitmapController() {}
+    static State* RequestBitmap(const SkBitmapProvider&, const SkMatrix& inverse, SkFilterQuality,
+                                SkArenaAlloc*);
 
-    State* requestBitmap(const SkBitmapProvider&, const SkMatrix& inverse, SkFilterQuality,
-                         SkArenaAlloc*);
-
-protected:
-    virtual State* onRequestBitmap(const SkBitmapProvider&, const SkMatrix& inv, SkFilterQuality,
-                                   SkArenaAlloc*) = 0;
-};
-
-///////////////////////////////////////////////////////////////////////////////////////////////////
-
-#include "SkMipMap.h"
-
-class SkDefaultBitmapController : public SkBitmapController {
-public:
-    SkDefaultBitmapController() {}
-
-protected:
-    State* onRequestBitmap(const SkBitmapProvider&, const SkMatrix& inverse, SkFilterQuality,
-                           SkArenaAlloc*) override;
+private:
+    SkBitmapController() = delete;
 };
 
 #endif
diff --git a/src/core/SkBitmapProcState.cpp b/src/core/SkBitmapProcState.cpp
index 8fea0a3..9290dcd 100644
--- a/src/core/SkBitmapProcState.cpp
+++ b/src/core/SkBitmapProcState.cpp
@@ -84,8 +84,7 @@
     fInvMatrix = inv;
     fFilterQuality = paint.getFilterQuality();
 
-    SkDefaultBitmapController controller;
-    fBMState = controller.requestBitmap(fProvider, inv, paint.getFilterQuality(), &fAlloc);
+    fBMState = SkBitmapController::RequestBitmap(fProvider, inv, paint.getFilterQuality(), &fAlloc);
 
     // Note : we allow the controller to return an empty (zero-dimension) result. Should we?
     if (nullptr == fBMState || fBMState->pixmap().info().isEmpty()) {
diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp
index cf85d85..938b7d6 100644
--- a/src/shaders/SkImageShader.cpp
+++ b/src/shaders/SkImageShader.cpp
@@ -275,8 +275,7 @@
     auto quality = rec.fPaint.getFilterQuality();
 
     SkBitmapProvider provider(fImage.get());
-    SkDefaultBitmapController controller;
-    SkBitmapController::State* state = controller.requestBitmap(provider, matrix, quality, alloc);
+    const auto* state = SkBitmapController::RequestBitmap(provider, matrix, quality, alloc);
     if (!state) {
         return false;
     }