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>
This commit is contained in:
Florin Malita 2018-07-16 12:32:09 -04:00 committed by Skia Commit-Bot
parent 81bb123957
commit 84364ee71d
4 changed files with 28 additions and 65 deletions

View File

@ -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 @@ 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);
}

View File

@ -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&);
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

View File

@ -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()) {

View File

@ -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;
}