aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkBitmapController.cpp
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-07-19 17:20:37 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-07-20 00:43:37 +0000
commite32500f0642df381fd79731df2f7a4a4a71a46e2 (patch)
tree05747f712923791d6df14077714cede88d9d51ff /src/core/SkBitmapController.cpp
parent3e583cba8af153952e31925e0d4bfbc71cfa43b8 (diff)
Assume HQ is handled by pipeline, delete legacy code-path
CQ_INCLUDE_TRYBOTS=skia.primary:Test-Debian9-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD Bug: skia: Change-Id: If6f0d0a57463bf99a66d674e65a62ce3931d0116 Reviewed-on: https://skia-review.googlesource.com/24644 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/core/SkBitmapController.cpp')
-rw-r--r--src/core/SkBitmapController.cpp140
1 files changed, 16 insertions, 124 deletions
diff --git a/src/core/SkBitmapController.cpp b/src/core/SkBitmapController.cpp
index d3e47aeae9..586210d4b7 100644
--- a/src/core/SkBitmapController.cpp
+++ b/src/core/SkBitmapController.cpp
@@ -6,15 +6,13 @@
*/
#include "SkBitmap.h"
+#include "SkBitmapCache.h"
#include "SkBitmapController.h"
#include "SkBitmapProvider.h"
#include "SkMatrix.h"
-#include "SkPixelRef.h"
+#include "SkMipMap.h"
#include "SkTemplates.h"
-// RESIZE_LANCZOS3 is another good option, but chrome prefers mitchell at the moment
-#define kHQ_RESIZE_METHOD SkBitmapScaler::RESIZE_MITCHELL
-
///////////////////////////////////////////////////////////////////////////////////////////////////
SkBitmapController::State* SkBitmapController::requestBitmap(const SkBitmapProvider& provider,
@@ -33,70 +31,24 @@ SkBitmapController::State* SkBitmapController::requestBitmap(const SkBitmapProvi
///////////////////////////////////////////////////////////////////////////////////////////////////
-#include "SkBitmapCache.h"
-#include "SkBitmapScaler.h"
-#include "SkMipMap.h"
-#include "SkResourceCache.h"
-
class SkDefaultBitmapControllerState : public SkBitmapController::State {
public:
- SkDefaultBitmapControllerState(const SkBitmapProvider&,
- const SkMatrix& inv,
- SkFilterQuality,
- bool canShadeHQ);
+ SkDefaultBitmapControllerState(const SkBitmapProvider&, const SkMatrix& inv, SkFilterQuality);
private:
- SkBitmap fResultBitmap;
- sk_sp<const SkMipMap> fCurrMip;
- bool fCanShadeHQ;
+ SkBitmap fResultBitmap;
+ sk_sp<const SkMipMap> fCurrMip;
- bool processHQRequest(const SkBitmapProvider&);
+ bool processHighRequest(const SkBitmapProvider&);
bool processMediumRequest(const SkBitmapProvider&);
};
-// Check to see that the size of the bitmap that would be produced by
-// scaling by the given inverted matrix is less than the maximum allowed.
-static inline bool cache_size_okay(const SkBitmapProvider& provider, const SkMatrix& invMat) {
- size_t maximumAllocation = SkResourceCache::GetEffectiveSingleAllocationByteLimit();
- if (0 == maximumAllocation) {
- return true;
- }
- // float matrixScaleFactor = 1.0 / (invMat.scaleX * invMat.scaleY);
- // return ((origBitmapSize * matrixScaleFactor) < maximumAllocationSize);
- // Skip the division step:
- const size_t size = provider.info().getSafeSize(provider.info().minRowBytes());
- SkScalar invScaleSqr = invMat.getScaleX() * invMat.getScaleY();
- return size < (maximumAllocation * SkScalarAbs(invScaleSqr));
-}
-
-/*
- * High quality is implemented by performing up-right scale-only filtering and then
- * using bilerp for any remaining transformations.
- */
-bool SkDefaultBitmapControllerState::processHQRequest(const SkBitmapProvider& provider) {
+bool SkDefaultBitmapControllerState::processHighRequest(const SkBitmapProvider& provider) {
if (fQuality != kHigh_SkFilterQuality) {
return false;
}
- // Our default return state is to downgrade the request to Medium, w/ or w/o setting fBitmap
- // to a valid bitmap. If we succeed, we will set this to Low instead.
fQuality = kMedium_SkFilterQuality;
-#ifdef SK_USE_MIP_FOR_DOWNSCALE_HQ
- return false;
-#endif
-
- bool supported = false;
- switch (provider.info().colorType()) {
- case kRGBA_8888_SkColorType:
- case kBGRA_8888_SkColorType:
- supported = true;
- break;
- default:
- break;
- }
- if (!supported || !cache_size_okay(provider, fInvMatrix) || fInvMatrix.hasPerspective()) {
- return false; // can't handle the reqeust
- }
SkScalar invScaleX = fInvMatrix.getScaleX();
SkScalar invScaleY = fInvMatrix.getScaleY();
@@ -111,68 +63,14 @@ bool SkDefaultBitmapControllerState::processHQRequest(const SkBitmapProvider& pr
invScaleX = SkScalarAbs(invScaleX);
invScaleY = SkScalarAbs(invScaleY);
- if (SkScalarNearlyEqual(invScaleX, 1) && SkScalarNearlyEqual(invScaleY, 1)) {
- return false; // no need for HQ
- }
-
- if (invScaleX > 1 || invScaleY > 1) {
- return false; // only use HQ when upsampling
- }
-
- // If the shader can natively handle HQ filtering, let it do it.
- if (fCanShadeHQ) {
- fQuality = kHigh_SkFilterQuality;
- SkAssertResult(provider.asBitmap(&fResultBitmap));
- return true;
- }
-
- const int dstW = SkScalarRoundToScalar(provider.width() / invScaleX);
- const int dstH = SkScalarRoundToScalar(provider.height() / invScaleY);
- const SkBitmapCacheDesc desc = provider.makeCacheDesc(dstW, dstH);
-
- if (!SkBitmapCache::Find(desc, &fResultBitmap)) {
- SkBitmap orig;
- if (!provider.asBitmap(&orig)) {
- return false;
- }
- SkPixmap src;
- if (!orig.peekPixels(&src)) {
- return false;
- }
-
- SkPixmap dst;
- SkBitmapCache::RecPtr rec;
- const SkImageInfo info = SkImageInfo::Make(desc.fScaledWidth, desc.fScaledHeight,
- src.colorType(), src.alphaType());
- if (provider.isVolatile()) {
- if (!fResultBitmap.tryAllocPixels(info)) {
- return false;
- }
- SkASSERT(fResultBitmap.getPixels());
- fResultBitmap.peekPixels(&dst);
- fResultBitmap.setImmutable(); // a little cheat, as we haven't resized yet, but ok
- } else {
- rec = SkBitmapCache::Alloc(desc, info, &dst);
- if (!rec) {
- return false;
- }
- }
- if (!SkBitmapScaler::Resize(dst, src, kHQ_RESIZE_METHOD)) {
- return false; // we failed to create fScaledBitmap
- }
- if (rec) {
- SkBitmapCache::Add(std::move(rec), &fResultBitmap);
- SkASSERT(fResultBitmap.getPixels());
- provider.notifyAddedToCache();
- }
+ if (invScaleX >= 1 - SK_ScalarNearlyZero || invScaleY >= 1 - SK_ScalarNearlyZero) {
+ // we're down-scaling so abort HQ
+ return false;
}
- SkASSERT(fResultBitmap.getPixels());
- SkASSERT(fResultBitmap.isImmutable());
-
- fInvMatrix.postScale(SkIntToScalar(dstW) / provider.width(),
- SkIntToScalar(dstH) / provider.height());
- fQuality = kLow_SkFilterQuality;
+ // Confirmed that we can use HQ (w/ rasterpipeline)
+ fQuality = kHigh_SkFilterQuality;
+ (void)provider.asBitmap(&fResultBitmap);
return true;
}
@@ -235,20 +133,15 @@ bool SkDefaultBitmapControllerState::processMediumRequest(const SkBitmapProvider
SkDefaultBitmapControllerState::SkDefaultBitmapControllerState(const SkBitmapProvider& provider,
const SkMatrix& inv,
- SkFilterQuality qual,
- bool canShadeHQ) {
+ SkFilterQuality qual) {
fInvMatrix = inv;
fQuality = qual;
- fCanShadeHQ = canShadeHQ;
-
- bool processed = this->processHQRequest(provider) || this->processMediumRequest(provider);
- if (processed) {
+ if (this->processHighRequest(provider) || this->processMediumRequest(provider)) {
SkASSERT(fResultBitmap.getPixels());
} else {
(void)provider.asBitmap(&fResultBitmap);
}
- SkASSERT(fCanShadeHQ || fQuality <= kLow_SkFilterQuality);
// fResultBitmap.getPixels() may be null, but our caller knows to check fPixmap.addr()
// and will destroy us if it is nullptr.
@@ -259,6 +152,5 @@ SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBi
const SkMatrix& inverse,
SkFilterQuality quality,
void* storage, size_t size) {
- return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size,
- bm, inverse, quality, fCanShadeHQ);
+ return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm, inverse, quality);
}