plumb through arenaalloc
- simplifies the older pattern of storage/size - removes a dynamic allocation in defaultbitmapcontroller Bug: skia: Change-Id: Ibc937d3e0c057e78cc0c8bf7d9ad2d824eb240d9 Reviewed-on: https://skia-review.googlesource.com/141321 Reviewed-by: Florin Malita <fmalita@chromium.org> Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
parent
eef6d69abc
commit
7e83f89dd6
@ -5,6 +5,7 @@
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkArenaAlloc.h"
|
||||
#include "SkBitmap.h"
|
||||
#include "SkBitmapCache.h"
|
||||
#include "SkBitmapController.h"
|
||||
@ -18,11 +19,10 @@
|
||||
SkBitmapController::State* SkBitmapController::requestBitmap(const SkBitmapProvider& provider,
|
||||
const SkMatrix& inv,
|
||||
SkFilterQuality quality,
|
||||
void* storage, size_t storageSize) {
|
||||
State* state = this->onRequestBitmap(provider, inv, quality, storage, storageSize);
|
||||
SkArenaAlloc* alloc) {
|
||||
State* state = this->onRequestBitmap(provider, inv, quality, alloc);
|
||||
if (state) {
|
||||
if (nullptr == state->fPixmap.addr()) {
|
||||
SkInPlaceDeleteCheck(state, storage);
|
||||
state = nullptr;
|
||||
}
|
||||
}
|
||||
@ -146,6 +146,6 @@ SkDefaultBitmapControllerState::SkDefaultBitmapControllerState(const SkBitmapPro
|
||||
SkBitmapController::State* SkDefaultBitmapController::onRequestBitmap(const SkBitmapProvider& bm,
|
||||
const SkMatrix& inverse,
|
||||
SkFilterQuality quality,
|
||||
void* storage, size_t size) {
|
||||
return SkInPlaceNewCheck<SkDefaultBitmapControllerState>(storage, size, bm, inverse, quality);
|
||||
SkArenaAlloc* alloc) {
|
||||
return alloc->make<SkDefaultBitmapControllerState>(bm, inverse, quality);
|
||||
}
|
||||
|
@ -40,15 +40,11 @@ public:
|
||||
virtual ~SkBitmapController() {}
|
||||
|
||||
State* requestBitmap(const SkBitmapProvider&, const SkMatrix& inverse, SkFilterQuality,
|
||||
void* storage, size_t storageSize);
|
||||
|
||||
State* requestBitmap(const SkBitmapProvider& bp, const SkMatrix& inv, SkFilterQuality quality) {
|
||||
return this->requestBitmap(bp, inv, quality, nullptr, 0);
|
||||
}
|
||||
SkArenaAlloc*);
|
||||
|
||||
protected:
|
||||
virtual State* onRequestBitmap(const SkBitmapProvider&, const SkMatrix& inv, SkFilterQuality,
|
||||
void* storage, size_t storageSize) = 0;
|
||||
SkArenaAlloc*) = 0;
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@ -61,7 +57,7 @@ public:
|
||||
|
||||
protected:
|
||||
State* onRequestBitmap(const SkBitmapProvider&, const SkMatrix& inverse, SkFilterQuality,
|
||||
void* storage, size_t storageSize) override;
|
||||
SkArenaAlloc*) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -37,9 +37,7 @@ SkBitmapProcInfo::SkBitmapProcInfo(const SkBitmapProvider& provider,
|
||||
, fBMState(nullptr)
|
||||
{}
|
||||
|
||||
SkBitmapProcInfo::~SkBitmapProcInfo() {
|
||||
SkInPlaceDeleteCheck(fBMState, fBMStateStorage.get());
|
||||
}
|
||||
SkBitmapProcInfo::~SkBitmapProcInfo() {}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@ -87,8 +85,8 @@ bool SkBitmapProcInfo::init(const SkMatrix& inv, const SkPaint& paint) {
|
||||
fFilterQuality = paint.getFilterQuality();
|
||||
|
||||
SkDefaultBitmapController controller;
|
||||
fBMState = controller.requestBitmap(fProvider, inv, paint.getFilterQuality(),
|
||||
fBMStateStorage.get(), fBMStateStorage.size());
|
||||
fBMState = controller.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()) {
|
||||
return false;
|
||||
|
@ -8,6 +8,7 @@
|
||||
#ifndef SkBitmapProcState_DEFINED
|
||||
#define SkBitmapProcState_DEFINED
|
||||
|
||||
#include "SkArenaAlloc.h"
|
||||
#include "SkBitmap.h"
|
||||
#include "SkBitmapController.h"
|
||||
#include "SkBitmapProvider.h"
|
||||
@ -49,7 +50,7 @@ private:
|
||||
enum {
|
||||
kBMStateSize = 136 // found by inspection. if too small, we will call new/delete
|
||||
};
|
||||
SkAlignedSStorage<kBMStateSize> fBMStateStorage;
|
||||
SkSTArenaAlloc<kBMStateSize> fAlloc;
|
||||
SkBitmapController::State* fBMState;
|
||||
};
|
||||
|
||||
|
@ -276,9 +276,7 @@ bool SkImageShader::onAppendStages(const StageRec& rec) const {
|
||||
|
||||
SkBitmapProvider provider(fImage.get());
|
||||
SkDefaultBitmapController controller;
|
||||
std::unique_ptr<SkBitmapController::State> state {
|
||||
controller.requestBitmap(provider, matrix, quality)
|
||||
};
|
||||
SkBitmapController::State* state = controller.requestBitmap(provider, matrix, quality, alloc);
|
||||
if (!state) {
|
||||
return false;
|
||||
}
|
||||
@ -311,11 +309,9 @@ bool SkImageShader::onAppendStages(const StageRec& rec) const {
|
||||
p->append(SkRasterPipeline::seed_shader);
|
||||
|
||||
struct MiscCtx {
|
||||
std::unique_ptr<SkBitmapController::State> state;
|
||||
SkColor4f paint_color;
|
||||
};
|
||||
auto misc = alloc->make<MiscCtx>();
|
||||
misc->state = std::move(state); // Extend lifetime to match the pipeline's.
|
||||
swizzle_rb(Sk4f_fromL32(rec.fPaint.getColor())).store(misc->paint_color.vec()); // sRGBA floats
|
||||
p->append_matrix(alloc, matrix);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user