remove unneeded bitmapprovider abstraction

Change-Id: Idd413389bb0828a6fc73b7285b4ed7b6fe48af6f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/231638
Reviewed-by: Florin Malita <fmalita@chromium.org>
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2019-08-01 15:35:20 -04:00 committed by Skia Commit-Bot
parent 40f9138361
commit 64acf4f7cf
13 changed files with 42 additions and 113 deletions

View File

@ -123,8 +123,6 @@ skia_core_sources = [
"$_src/core/SkBitmapProcState.cpp",
"$_src/core/SkBitmapProcState.h",
"$_src/core/SkBitmapProcState_matrixProcs.cpp",
"$_src/core/SkBitmapProvider.cpp",
"$_src/core/SkBitmapProvider.h",
"$_src/core/SkBlendMode.cpp",
"$_src/core/SkBlitBWMaskTemplate.h",
"$_src/core/SkBlitRow.h",

View File

@ -9,9 +9,9 @@
#include "include/core/SkPixelRef.h"
#include "include/core/SkRect.h"
#include "src/core/SkBitmapCache.h"
#include "src/core/SkBitmapProvider.h"
#include "src/core/SkMipMap.h"
#include "src/core/SkResourceCache.h"
#include "src/image/SkImage_Base.h"
/**
* Use this for bitmapcache and mipmapcache entries.
@ -284,18 +284,17 @@ static SkResourceCache::DiscardableFactory get_fact(SkResourceCache* localCache)
: SkResourceCache::GetDiscardableFactory();
}
const SkMipMap* SkMipMapCache::AddAndRef(const SkBitmapProvider& provider,
SkResourceCache* localCache) {
const SkMipMap* SkMipMapCache::AddAndRef(const SkImage_Base* image, SkResourceCache* localCache) {
SkBitmap src;
if (!provider.asBitmap(&src)) {
if (!image->getROPixels(&src)) {
return nullptr;
}
SkMipMap* mipmap = SkMipMap::Build(src, get_fact(localCache));
if (mipmap) {
MipMapRec* rec = new MipMapRec(provider.makeCacheDesc(), mipmap);
MipMapRec* rec = new MipMapRec(SkBitmapCacheDesc::Make(image), mipmap);
CHECK_LOCAL(localCache, add, Add, rec);
provider.notifyAddedToCache();
image->notifyAddedToRasterCache();
}
return mipmap;
}

View File

@ -12,8 +12,8 @@
#include <memory>
class SkBitmap;
class SkBitmapProvider;
class SkImage;
class SkImage_Base;
struct SkImageInfo;
class SkMipMap;
class SkPixmap;
@ -60,7 +60,7 @@ class SkMipMapCache {
public:
static const SkMipMap* FindAndRef(const SkBitmapCacheDesc&,
SkResourceCache* localCache = nullptr);
static const SkMipMap* AddAndRef(const SkBitmapProvider&,
static const SkMipMap* AddAndRef(const SkImage_Base*,
SkResourceCache* localCache = nullptr);
};

View File

@ -11,21 +11,21 @@
#include "src/core/SkArenaAlloc.h"
#include "src/core/SkBitmapCache.h"
#include "src/core/SkBitmapController.h"
#include "src/core/SkBitmapProvider.h"
#include "src/core/SkMipMap.h"
#include "src/image/SkImage_Base.h"
///////////////////////////////////////////////////////////////////////////////////////////////////
SkBitmapController::State* SkBitmapController::RequestBitmap(const SkBitmapProvider& provider,
SkBitmapController::State* SkBitmapController::RequestBitmap(const SkImage_Base* image,
const SkMatrix& inv,
SkFilterQuality quality,
SkArenaAlloc* alloc) {
auto* state = alloc->make<SkBitmapController::State>(provider, inv, quality);
auto* state = alloc->make<SkBitmapController::State>(image, inv, quality);
return state->pixmap().addr() ? state : nullptr;
}
bool SkBitmapController::State::processHighRequest(const SkBitmapProvider& provider) {
bool SkBitmapController::State::processHighRequest(const SkImage_Base* image) {
if (fQuality != kHigh_SkFilterQuality) {
return false;
}
@ -52,7 +52,7 @@ bool SkBitmapController::State::processHighRequest(const SkBitmapProvider& provi
// Confirmed that we can use HQ (w/ rasterpipeline)
fQuality = kHigh_SkFilterQuality;
(void)provider.asBitmap(&fResultBitmap);
(void)image->getROPixels(&fResultBitmap);
return true;
}
@ -60,7 +60,7 @@ bool SkBitmapController::State::processHighRequest(const SkBitmapProvider& provi
* 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 SkBitmapController::State::processMediumRequest(const SkBitmapProvider& provider) {
bool SkBitmapController::State::processMediumRequest(const SkImage_Base* image) {
SkASSERT(fQuality <= kMedium_SkFilterQuality);
if (fQuality != kMedium_SkFilterQuality) {
return false;
@ -76,9 +76,9 @@ bool SkBitmapController::State::processMediumRequest(const SkBitmapProvider& pro
}
if (invScaleSize.width() > SK_Scalar1 || invScaleSize.height() > SK_Scalar1) {
fCurrMip.reset(SkMipMapCache::FindAndRef(provider.makeCacheDesc()));
fCurrMip.reset(SkMipMapCache::FindAndRef(SkBitmapCacheDesc::Make(image)));
if (nullptr == fCurrMip.get()) {
fCurrMip.reset(SkMipMapCache::AddAndRef(provider));
fCurrMip.reset(SkMipMapCache::AddAndRef(image));
if (nullptr == fCurrMip.get()) {
return false;
}
@ -104,16 +104,16 @@ bool SkBitmapController::State::processMediumRequest(const SkBitmapProvider& pro
return false;
}
SkBitmapController::State::State(const SkBitmapProvider& provider,
SkBitmapController::State::State(const SkImage_Base* image,
const SkMatrix& inv,
SkFilterQuality qual) {
fInvMatrix = inv;
fQuality = qual;
if (this->processHighRequest(provider) || this->processMediumRequest(provider)) {
if (this->processHighRequest(image) || this->processMediumRequest(image)) {
SkASSERT(fResultBitmap.getPixels());
} else {
(void)provider.asBitmap(&fResultBitmap);
(void)image->getROPixels(&fResultBitmap);
}
// fResultBitmap.getPixels() may be null, but our caller knows to check fPixmap.addr()

View File

@ -14,7 +14,7 @@
#include "src/core/SkBitmapCache.h"
#include "src/core/SkMipMap.h"
class SkBitmapProvider;
class SkImage_Base;
/**
* Handles request to scale, filter, and lock a bitmap to be rasterized.
@ -23,15 +23,15 @@ class SkBitmapController : ::SkNoncopyable {
public:
class State : ::SkNoncopyable {
public:
State(const SkBitmapProvider&, const SkMatrix& inv, SkFilterQuality);
State(const SkImage_Base*, const SkMatrix& inv, SkFilterQuality);
const SkPixmap& pixmap() const { return fPixmap; }
const SkMatrix& invMatrix() const { return fInvMatrix; }
SkFilterQuality quality() const { return fQuality; }
private:
bool processHighRequest(const SkBitmapProvider&);
bool processMediumRequest(const SkBitmapProvider&);
bool processHighRequest(const SkImage_Base*);
bool processMediumRequest(const SkImage_Base*);
SkPixmap fPixmap;
SkMatrix fInvMatrix;
@ -43,7 +43,7 @@ public:
};
static State* RequestBitmap(const SkBitmapProvider&, const SkMatrix& inverse, SkFilterQuality,
static State* RequestBitmap(const SkImage_Base*, const SkMatrix& inverse, SkFilterQuality,
SkArenaAlloc*);
private:

View File

@ -119,9 +119,8 @@ static void S32_alpha_D32_nofilter_DX(const SkBitmapProcState& s,
}
}
SkBitmapProcInfo::SkBitmapProcInfo(const SkBitmapProvider& provider,
SkTileMode tmx, SkTileMode tmy)
: fProvider(provider)
SkBitmapProcInfo::SkBitmapProcInfo(const SkImage_Base* image, SkTileMode tmx, SkTileMode tmy)
: fImage(image)
, fTileModeX(tmx)
, fTileModeY(tmy)
, fBMState(nullptr)
@ -173,7 +172,7 @@ bool SkBitmapProcInfo::init(const SkMatrix& inv, const SkPaint& paint) {
fInvMatrix = inv;
fFilterQuality = paint.getFilterQuality();
fBMState = SkBitmapController::RequestBitmap(fProvider, inv, paint.getFilterQuality(), &fAlloc);
fBMState = SkBitmapController::RequestBitmap(fImage, 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

@ -16,7 +16,6 @@
#include "include/private/SkTemplates.h"
#include "src/core/SkArenaAlloc.h"
#include "src/core/SkBitmapController.h"
#include "src/core/SkBitmapProvider.h"
#include "src/core/SkMatrixPriv.h"
#include "src/core/SkMipMap.h"
@ -29,10 +28,10 @@ typedef SkFixed3232 SkFractionalInt;
class SkPaint;
struct SkBitmapProcInfo {
SkBitmapProcInfo(const SkBitmapProvider&, SkTileMode tmx, SkTileMode tmy);
SkBitmapProcInfo(const SkImage_Base*, SkTileMode tmx, SkTileMode tmy);
~SkBitmapProcInfo();
const SkBitmapProvider fProvider;
const SkImage_Base* fImage;
SkPixmap fPixmap;
SkMatrix fInvMatrix; // This changes based on tile mode.
@ -55,8 +54,8 @@ private:
};
struct SkBitmapProcState : public SkBitmapProcInfo {
SkBitmapProcState(const SkBitmapProvider& prov, SkTileMode tmx, SkTileMode tmy)
: SkBitmapProcInfo(prov, tmx, tmy) {}
SkBitmapProcState(const SkImage_Base* image, SkTileMode tmx, SkTileMode tmy)
: SkBitmapProcInfo(image, tmx, tmy) {}
bool setup(const SkMatrix& inv, const SkPaint& paint) {
return this->init(inv, paint) && this->chooseProcs();

View File

@ -1,21 +0,0 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "src/core/SkBitmapProvider.h"
#include "src/image/SkImage_Base.h"
SkBitmapCacheDesc SkBitmapProvider::makeCacheDesc() const {
return SkBitmapCacheDesc::Make(fImage);
}
void SkBitmapProvider::notifyAddedToCache() const {
as_IB(fImage)->notifyAddedToRasterCache();
}
bool SkBitmapProvider::asBitmap(SkBitmap* bm) const {
return as_IB(fImage)->getROPixels(bm);
}

View File

@ -1,41 +0,0 @@
/*
* Copyright 2015 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#ifndef SkBitmapProvider_DEFINED
#define SkBitmapProvider_DEFINED
#include "include/core/SkImage.h"
#include "src/core/SkBitmapCache.h"
class SkBitmapProvider {
public:
explicit SkBitmapProvider(const SkImage* img)
: fImage(img) {
SkASSERT(img);
}
SkBitmapProvider(const SkBitmapProvider& other)
: fImage(other.fImage)
{}
SkBitmapCacheDesc makeCacheDesc() const;
void notifyAddedToCache() const;
// Only call this if you're sure you need the bits, since it maybe expensive
// ... cause a decode and cache, or gpu-readback
bool asBitmap(SkBitmap*) const;
private:
// Stack-allocated only.
void* operator new(size_t) = delete;
void* operator new(size_t, void*) = delete;
// 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;
};
#endif

View File

@ -9,7 +9,6 @@
#include "src/core/SkArenaAlloc.h"
#include "src/core/SkBitmapProcState.h"
#include "src/core/SkBitmapProvider.h"
#include "src/core/SkXfermodePriv.h"
static bool only_scale_and_translate(const SkMatrix& matrix) {
@ -94,7 +93,7 @@ private:
SkShaderBase::Context* SkBitmapProcLegacyShader::MakeContext(
const SkShaderBase& shader, SkTileMode tmx, SkTileMode tmy,
const SkBitmapProvider& provider, const ContextRec& rec, SkArenaAlloc* alloc)
const SkImage_Base* image, const ContextRec& rec, SkArenaAlloc* alloc)
{
SkMatrix totalInverse;
// Do this first, so we know the matrix can be inverted.
@ -102,7 +101,7 @@ SkShaderBase::Context* SkBitmapProcLegacyShader::MakeContext(
return nullptr;
}
SkBitmapProcState* state = alloc->make<SkBitmapProcState>(provider, tmx, tmy);
SkBitmapProcState* state = alloc->make<SkBitmapProcState>(image, tmx, tmy);
if (!state->setup(totalInverse, *rec.fPaint)) {
return nullptr;
}

View File

@ -10,14 +10,14 @@
#include "src/core/SkImagePriv.h"
#include "src/shaders/SkShaderBase.h"
class SkBitmapProvider;
class SkImage_Base;
class SkBitmapProcLegacyShader : public SkShaderBase {
private:
friend class SkImageShader;
static Context* MakeContext(const SkShaderBase&, SkTileMode tmx, SkTileMode tmy,
const SkBitmapProvider&, const ContextRec&, SkArenaAlloc* alloc);
const SkImage_Base*, const ContextRec&, SkArenaAlloc* alloc);
typedef SkShaderBase INHERITED;
};

View File

@ -7,7 +7,6 @@
#include "src/core/SkArenaAlloc.h"
#include "src/core/SkBitmapController.h"
#include "src/core/SkBitmapProvider.h"
#include "src/core/SkColorSpacePriv.h"
#include "src/core/SkColorSpaceXformSteps.h"
#include "src/core/SkRasterPipeline.h"
@ -135,7 +134,7 @@ SkShaderBase::Context* SkImageShader::onMakeContext(const ContextRec& rec,
}
return SkBitmapProcLegacyShader::MakeContext(*this, fTileModeX, fTileModeY,
SkBitmapProvider(fImage.get()), rec, alloc);
as_IB(fImage.get()), rec, alloc);
}
#endif
@ -303,8 +302,8 @@ bool SkImageShader::onAppendStages(const SkStageRec& rec) const {
}
auto quality = rec.fPaint.getFilterQuality();
SkBitmapProvider provider(fImage.get());
const auto* state = SkBitmapController::RequestBitmap(provider, matrix, quality, alloc);
const auto* state = SkBitmapController::RequestBitmap(as_IB(fImage.get()),
matrix, quality, alloc);
if (!state) {
return false;
}

View File

@ -11,10 +11,10 @@
#include "include/core/SkPictureRecorder.h"
#include "include/core/SkSurface.h"
#include "src/core/SkBitmapCache.h"
#include "src/core/SkBitmapProvider.h"
#include "src/core/SkMakeUnique.h"
#include "src/core/SkMipMap.h"
#include "src/core/SkResourceCache.h"
#include "src/image/SkImage_Base.h"
#include "src/lazy/SkDiscardableMemoryPool.h"
#include "tests/Test.h"
@ -45,13 +45,12 @@ static void test_mipmapcache(skiatest::Reporter* reporter, SkResourceCache* cach
src.allocN32Pixels(5, 5);
src.setImmutable();
sk_sp<SkImage> img = SkImage::MakeFromBitmap(src);
SkBitmapProvider provider(img.get());
const auto desc = provider.makeCacheDesc();
const auto desc = SkBitmapCacheDesc::Make(img.get());
const SkMipMap* mipmap = SkMipMapCache::FindAndRef(desc, cache);
REPORTER_ASSERT(reporter, nullptr == mipmap);
mipmap = SkMipMapCache::AddAndRef(provider, cache);
mipmap = SkMipMapCache::AddAndRef(as_IB(img.get()), cache);
REPORTER_ASSERT(reporter, mipmap);
{
@ -88,9 +87,8 @@ static void test_mipmap_notify(skiatest::Reporter* reporter, SkResourceCache* ca
src[i].allocN32Pixels(5, 5);
src[i].setImmutable();
img[i] = SkImage::MakeFromBitmap(src[i]);
SkBitmapProvider provider(img[i].get());
SkMipMapCache::AddAndRef(provider, cache)->unref();
desc[i] = provider.makeCacheDesc();
SkMipMapCache::AddAndRef(as_IB(img[i].get()), cache)->unref();
desc[i] = SkBitmapCacheDesc::Make(img[i].get());
}
for (int i = 0; i < N; ++i) {