diff options
author | Florin Malita <fmalita@chromium.org> | 2018-07-16 12:32:09 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-07-19 14:18:25 +0000 |
commit | 84364ee71dad9adeb1beb99b19e27d0c32e6c429 (patch) | |
tree | c7dc7724b92f802a2cf4e0c896551475d8f095d7 /src | |
parent | 81bb123957abbc51a68591ceff287040daffa8a1 (diff) |
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>
Diffstat (limited to 'src')
-rw-r--r-- | src/core/SkBitmapController.cpp | 43 | ||||
-rw-r--r-- | src/core/SkBitmapController.h | 40 | ||||
-rw-r--r-- | src/core/SkBitmapProcState.cpp | 3 | ||||
-rw-r--r-- | src/shaders/SkImageShader.cpp | 3 |
4 files changed, 26 insertions, 63 deletions
diff --git a/src/core/SkBitmapController.cpp b/src/core/SkBitmapController.cpp index ed16f9bc21..dfe16682c6 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); -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&); -}; + return state->pixmap().addr() ? state : nullptr; +} -bool SkDefaultBitmapControllerState::processHighRequest(const SkBitmapProvider& provider) { +bool SkBitmapController::State::processHighRequest(const SkBitmapProvider& provider) { if (fQuality != kHigh_SkFilterQuality) { return false; } @@ -78,7 +60,7 @@ bool SkDefaultBitmapControllerState::processHighRequest(const SkBitmapProvider& * 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 @@ bool SkDefaultBitmapControllerState::processMediumRequest(const SkBitmapProvider 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 @@ SkDefaultBitmapControllerState::SkDefaultBitmapControllerState(const SkBitmapPro // 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 394a7cfd1a..2ac6c8c9d7 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 @@ class SkBitmapController : ::SkNoncopyable { 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&); - virtual ~SkBitmapController() {} + SkPixmap fPixmap; + SkMatrix fInvMatrix; + SkFilterQuality fQuality; - State* requestBitmap(const SkBitmapProvider&, const SkMatrix& inverse, SkFilterQuality, - SkArenaAlloc*); - -protected: - virtual State* onRequestBitmap(const SkBitmapProvider&, const SkMatrix& inv, SkFilterQuality, - SkArenaAlloc*) = 0; -}; + // Pixmap storage. + SkBitmap fResultBitmap; + sk_sp<const SkMipMap> fCurrMip; -/////////////////////////////////////////////////////////////////////////////////////////////////// - -#include "SkMipMap.h" + }; -class SkDefaultBitmapController : public SkBitmapController { -public: - SkDefaultBitmapController() {} + static State* RequestBitmap(const SkBitmapProvider&, const SkMatrix& inverse, SkFilterQuality, + SkArenaAlloc*); -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 8fea0a3b6e..9290dcd388 100644 --- a/src/core/SkBitmapProcState.cpp +++ b/src/core/SkBitmapProcState.cpp @@ -84,8 +84,7 @@ bool SkBitmapProcInfo::init(const SkMatrix& inv, const SkPaint& paint) { 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 cf85d85f2d..938b7d6da8 100644 --- a/src/shaders/SkImageShader.cpp +++ b/src/shaders/SkImageShader.cpp @@ -275,8 +275,7 @@ bool SkImageShader::onAppendStages(const StageRec& rec) const { 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; } |