From e13a69baac9dc326510009fa7c0c5966aee9240c Mon Sep 17 00:00:00 2001 From: Florin Malita Date: Thu, 10 Nov 2016 11:10:30 -0500 Subject: [PATCH] Simplify SkBitmapProvider We're no longer using SkBitmap sources for SkBitmapProvider, so we can restrict it to SkImage only. At this point we could also remove it, but I think it'll come in handy when we add shader subset support. BUG=skia:5806 R=reed@google.com GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=4655 Change-Id: I298da253cc8f7c1205b543521e62060a202a9f78 Reviewed-on: https://skia-review.googlesource.com/4655 Reviewed-by: Mike Reed Commit-Queue: Florin Malita --- src/core/SkBitmapController.cpp | 4 --- src/core/SkBitmapProcState.cpp | 10 ------ src/core/SkBitmapProcState.h | 5 --- src/core/SkBitmapProvider.cpp | 57 +++++++-------------------------- src/core/SkBitmapProvider.h | 9 ++---- 5 files changed, 13 insertions(+), 72 deletions(-) diff --git a/src/core/SkBitmapController.cpp b/src/core/SkBitmapController.cpp index 435940b84c..4fee11db28 100644 --- a/src/core/SkBitmapController.cpp +++ b/src/core/SkBitmapController.cpp @@ -21,10 +21,6 @@ SkBitmapController::State* SkBitmapController::requestBitmap(const SkBitmapProvi const SkMatrix& inv, SkFilterQuality quality, void* storage, size_t storageSize) { - if (!provider.validForDrawing()) { - return nullptr; - } - State* state = this->onRequestBitmap(provider, inv, quality, storage, storageSize); if (state) { if (nullptr == state->fPixmap.addr()) { diff --git a/src/core/SkBitmapProcState.cpp b/src/core/SkBitmapProcState.cpp index 7b88ab644a..33ab736215 100644 --- a/src/core/SkBitmapProcState.cpp +++ b/src/core/SkBitmapProcState.cpp @@ -46,16 +46,6 @@ SkBitmapProcInfo::SkBitmapProcInfo(const SkBitmapProvider& provider, , fBMState(nullptr) {} -SkBitmapProcInfo::SkBitmapProcInfo(const SkBitmap& bm, - SkShader::TileMode tmx, SkShader::TileMode tmy, - SkDestinationSurfaceColorMode colorMode) - : fProvider(SkBitmapProvider(bm)) - , fTileModeX(tmx) - , fTileModeY(tmy) - ,fColorMode(colorMode) - , fBMState(nullptr) -{} - SkBitmapProcInfo::~SkBitmapProcInfo() { SkInPlaceDeleteCheck(fBMState, fBMStateStorage.get()); } diff --git a/src/core/SkBitmapProcState.h b/src/core/SkBitmapProcState.h index 1818406f61..6b4317e1a0 100644 --- a/src/core/SkBitmapProcState.h +++ b/src/core/SkBitmapProcState.h @@ -30,8 +30,6 @@ class SkPaint; struct SkBitmapProcInfo { SkBitmapProcInfo(const SkBitmapProvider&, SkShader::TileMode tmx, SkShader::TileMode tmy, SkDestinationSurfaceColorMode); - SkBitmapProcInfo(const SkBitmap&, SkShader::TileMode tmx, SkShader::TileMode tmy, - SkDestinationSurfaceColorMode); ~SkBitmapProcInfo(); const SkBitmapProvider fProvider; @@ -61,9 +59,6 @@ struct SkBitmapProcState : public SkBitmapProcInfo { SkBitmapProcState(const SkBitmapProvider& prov, SkShader::TileMode tmx, SkShader::TileMode tmy, SkDestinationSurfaceColorMode colorMode) : SkBitmapProcInfo(prov, tmx, tmy, colorMode) {} - SkBitmapProcState(const SkBitmap& bitmap, SkShader::TileMode tmx, SkShader::TileMode tmy, - SkDestinationSurfaceColorMode colorMode) - : SkBitmapProcInfo(bitmap, tmx, tmy, colorMode) {} bool setup(const SkMatrix& inv, const SkPaint& paint) { return this->init(inv, paint) && this->chooseProcs(); diff --git a/src/core/SkBitmapProvider.cpp b/src/core/SkBitmapProvider.cpp index 37f8dc9d52..8347d32d7f 100644 --- a/src/core/SkBitmapProvider.cpp +++ b/src/core/SkBitmapProvider.cpp @@ -10,74 +10,39 @@ #include "SkPixelRef.h" int SkBitmapProvider::width() const { - return fImage ? fImage->width() : fBitmap.width(); + return fImage->width(); } int SkBitmapProvider::height() const { - return fImage ? fImage->height() : fBitmap.height(); + return fImage->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 (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; + return fImage->uniqueID(); } SkImageInfo SkBitmapProvider::info() const { - if (fImage) { - return as_IB(fImage)->onImageInfo(); - } else { - return fBitmap.info(); - } + return as_IB(fImage)->onImageInfo(); } bool SkBitmapProvider::isVolatile() const { - if (fImage) { - // add flag to images? - const SkBitmap* bm = as_IB(fImage)->onPeekBitmap(); - return bm ? bm->isVolatile() : false; - } else { - return fBitmap.isVolatile(); - } + // add flag to images? + const SkBitmap* bm = as_IB(fImage)->onPeekBitmap(); + return bm ? bm->isVolatile() : false; } SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc(int w, int h) const { - return fImage ? SkBitmapCacheDesc::Make(fImage, w, h) : SkBitmapCacheDesc::Make(fBitmap, w, h); + return SkBitmapCacheDesc::Make(fImage, w, h); } SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc() const { - return fImage ? SkBitmapCacheDesc::Make(fImage) : SkBitmapCacheDesc::Make(fBitmap); + return SkBitmapCacheDesc::Make(fImage); } void SkBitmapProvider::notifyAddedToCache() const { - if (fImage) { - as_IB(fImage)->notifyAddedToCache(); - } else { - fBitmap.pixelRef()->notifyAddedToCache(); - } + as_IB(fImage)->notifyAddedToCache(); } bool SkBitmapProvider::asBitmap(SkBitmap* bm) const { - if (fImage) { - return as_IB(fImage)->getROPixels(bm, SkImage::kAllow_CachingHint); - } else { - *bm = fBitmap; - return true; - } + return as_IB(fImage)->getROPixels(bm, SkImage::kAllow_CachingHint); } diff --git a/src/core/SkBitmapProvider.h b/src/core/SkBitmapProvider.h index 2080104b87..2e878b18ab 100644 --- a/src/core/SkBitmapProvider.h +++ b/src/core/SkBitmapProvider.h @@ -8,24 +8,20 @@ #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(img) {} + explicit SkBitmapProvider(const SkImage* img) : fImage(img) { SkASSERT(img); } SkBitmapProvider(const SkBitmapProvider& other) - : fBitmap(other.fBitmap) - , fImage(other.fImage) + : fImage(other.fImage) {} int width() const; int height() const; uint32_t getID() const; - bool validForDrawing() const; SkImageInfo info() const; bool isVolatile() const; @@ -42,7 +38,6 @@ private: void* operator new(size_t) = delete; void* operator new(size_t, void*) = delete; - SkBitmap fBitmap; // SkBitmapProvider is always short-lived/stack allocated, and the source image is guaranteed // to outlive its scope => we can store a raw ptr to avoid ref churn. const SkImage* fImage; -- 2.34.1