Syntactic sugar, gets rid of some boilerplate.
Change-Id: Ibdb28b7a8f1d5e4a4e18c12d423b987d7194e340
Reviewed-on: https://skia-review.googlesource.com/17837
Commit-Queue: Florin Malita <fmalita@chromium.org>
Reviewed-by: Herb Derby <herb@google.com>
SkPixmap srcPixmap{fInfo, fBitmap.get(), static_cast<size_t>(4 * width)};
- char storage[600];
- SkArenaAlloc allocator{storage, sizeof(storage), 512};
+ SkSTArenaAlloc<600> allocator(512);
SkLinearBitmapPipeline pipeline{
fInvert, filterQuality, fXTile, fYTile, SK_ColorBLACK, srcPixmap, &allocator};
uint32_t flags = 0;
auto procN = SkXfermode::GetD32Proc(SkBlendMode::kSrcOver, flags);
- char storage[512];
- SkArenaAlloc allocator{storage, sizeof(storage)};
+ SkSTArenaAlloc<512> allocator;
SkLinearBitmapPipeline pipeline{
inv, filterQuality,
SkShader::kRepeat_TileMode, SkShader::kRepeat_TileMode,
enum Tracking {kDontTrack, kTrack};
SkArenaAlloc(char* block, size_t size, size_t, Tracking tracking = kDontTrack);
- template <size_t kSize>
- SkArenaAlloc(char (&block)[kSize], size_t extraSize = kSize, Tracking tracking = kDontTrack)
- : SkArenaAlloc(block, kSize, extraSize, tracking)
- {}
-
SkArenaAlloc(size_t extraSize, Tracking tracking = kDontTrack)
: SkArenaAlloc(nullptr, 0, extraSize, tracking)
{}
uint32_t fFib0 {1}, fFib1 {1};
};
+// Helper for defining allocators with inline/reserved storage.
+// For argument declarations, stick to the base type (SkArenaAlloc).
+template <size_t InlineStorageSize>
+class SkSTArenaAlloc : public SkArenaAlloc {
+public:
+ explicit SkSTArenaAlloc(size_t extraSize = InlineStorageSize, Tracking tracking = kDontTrack)
+ : INHERITED(fInlineStorage, InlineStorageSize, extraSize, tracking) {}
+
+private:
+ char fInlineStorage[InlineStorageSize];
+
+ using INHERITED = SkArenaAlloc;
+};
+
#endif//SkFixedAlloc_DEFINED
// Owned by fAlloc, which will handle the delete.
SkBlitter* fBlitter;
- char fStorage[kSkBlitterContextSize];
- SkArenaAlloc fAlloc{fStorage};
+ SkSTArenaAlloc<kSkBlitterContextSize> fAlloc;
};
#define SkAutoBlitterChoose(...) SK_REQUIRE_LOCAL_VAR(SkAutoBlitterChoose)
bool fDone;
bool fIsSimple;
SkDrawLooper::Context* fLooperContext;
- char fStorage[48];
- SkArenaAlloc fAlloc {fStorage};
+ SkSTArenaAlloc<48> fAlloc;
bool doNext(SkDrawFilter::Type drawType);
};
int ix = SkScalarRoundToInt(matrix.getTranslateX());
int iy = SkScalarRoundToInt(matrix.getTranslateY());
if (clipHandlesSprite(*fRC, ix, iy, pmap)) {
- char storage[kSkBlitterContextSize];
- SkArenaAlloc allocator{storage};
+ SkSTArenaAlloc<kSkBlitterContextSize> allocator;
// blitter will be owned by the allocator.
SkBlitter* blitter = SkBlitter::ChooseSprite(fDst, *paint, pmap, ix, iy, &allocator);
if (blitter) {
if (nullptr == paint.getColorFilter() && clipHandlesSprite(*fRC, x, y, pmap)) {
// blitter will be owned by the allocator.
- char storage[kSkBlitterContextSize];
- SkArenaAlloc allocator{storage};
+ SkSTArenaAlloc<kSkBlitterContextSize> allocator;
SkBlitter* blitter = SkBlitter::ChooseSprite(fDst, paint, pmap, x, y, &allocator);
if (blitter) {
SkScan::FillIRect(bounds, *fRC, blitter);
bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) const {
SkCanvas canvas;
- char storage[48];
- SkArenaAlloc alloc {storage};
+ SkSTArenaAlloc<48> alloc;
SkDrawLooper::Context* context = this->makeContext(&canvas, &alloc);
for (;;) {
const SkRect src = s;
SkCanvas canvas;
- char storage[48];
- SkArenaAlloc alloc {storage};
+ SkSTArenaAlloc<48> alloc;
*dst = src; // catch case where there are no loops
SkDrawLooper::Context* context = this->makeContext(&canvas, &alloc);
constexpr size_t outerSize = sizeof(SkTriColorShader) +
sizeof(SkComposeShader) +
(sizeof(SkPoint) + sizeof(SkPM4f)) * defCount;
- char outerStorage[outerSize];
- SkArenaAlloc outerAlloc(outerStorage, sizeof(outerStorage));
+ SkSTArenaAlloc<outerSize> outerAlloc;
SkPoint* devVerts = outerAlloc.makeArray<SkPoint>(count);
fMatrix->mapPoints(devVerts, vertices, count);
p.setShader(sk_ref_sp(shader));
while (vertProc(&state)) {
- char innerStorage[2048];
- SkArenaAlloc innerAlloc(innerStorage, sizeof(innerStorage));
+ SkSTArenaAlloc<2048> innerAlloc;
const SkMatrix* ctm = fMatrix;
SkMatrix tmpCtm;
bool vertical_line(const SkEdge* edge);
bool vertical_line(const SkAnalyticEdge* edge);
- char fStorage[512];
- SkArenaAlloc fAlloc{fStorage};
+ SkSTArenaAlloc<512> fAlloc;
SkTDArray<void*> fList;
/*
class SkRasterPipeline_ : public SkRasterPipeline {
public:
SkRasterPipeline_()
- : SkRasterPipeline(&fBuiltinAlloc)
- , fBuiltinAlloc(fBuffer) {}
+ : SkRasterPipeline(&fBuiltinAlloc) {}
private:
- char fBuffer[bytes];
- SkArenaAlloc fBuiltinAlloc;
+ SkSTArenaAlloc<bytes> fBuiltinAlloc;
};
#include "SkPathOpsCommon.h"
static bool one_contour(const SkPath& path) {
- char storage[256];
- SkArenaAlloc allocator(storage);
+ SkSTArenaAlloc<256> allocator;
int verbCount = path.countVerbs();
uint8_t* verbs = (uint8_t*) allocator.makeArrayDefault<uint8_t>(verbCount);
(void) path.getVerbs(verbs, verbCount);
path->setFillType(fillType);
return true;
}
- char storage[4096];
- SkArenaAlloc allocator(storage);
+ SkSTArenaAlloc<4096> allocator;
SkOpContourHead contourHead;
SkOpGlobalState globalState(&contourHead, &allocator SkDEBUGPARAMS(false)
SkDEBUGPARAMS(nullptr));
bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result
SkDEBUGPARAMS(bool skipAssert) SkDEBUGPARAMS(const char* testName)) {
- char storage[4096];
- SkArenaAlloc allocator(storage); // FIXME: add a constant expression here, tune
+ SkSTArenaAlloc<4096> allocator; // FIXME: add a constant expression here, tune
SkOpContour contour;
SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour);
SkOpGlobalState globalState(contourList, &allocator
return true;
}
// turn path into list of segments
- char storage[4096];
- SkArenaAlloc allocator(storage); // FIXME: constant-ize, tune
+ SkSTArenaAlloc<4096> allocator; // FIXME: constant-ize, tune
SkOpContour contour;
SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour);
SkOpGlobalState globalState(contourList, &allocator
*result = path.getBounds();
return true;
}
- char storage[4096];
- SkArenaAlloc allocator(storage); // FIXME: constant-ize, tune
+ SkSTArenaAlloc<4096> allocator; // FIXME: constant-ize, tune
SkOpContour contour;
SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour);
SkOpGlobalState globalState(contourList, &allocator SkDEBUGPARAMS(false)
}
bool SkOpSpan::sortableTop(SkOpContour* contourHead) {
- char storage[1024];
- SkArenaAlloc allocator(storage);
+ SkSTArenaAlloc<1024> allocator;
int dirOffset;
double t = get_t_guess(fTopTTry++, &dirOffset);
SkOpRayHit hitBase;
flags |= SkVertices::kHasColors_BuilderFlag;
}
- char allocStorage[2048];
- SkArenaAlloc alloc(allocStorage, sizeof(allocStorage));
+ SkSTArenaAlloc<2048> alloc;
SkRGBAf* cornerColors = srcColors ? alloc.makeArray<SkRGBAf>(4) : nullptr;
SkRGBAf* tmpColors = srcColors ? alloc.makeArray<SkRGBAf>(vertexCount) : nullptr;
auto convertCS = interpColorsLinearly ? SkColorSpace::MakeSRGB() : nullptr;
{
created = 0;
destroyed = 0;
- char block[64];
- SkArenaAlloc arena{block};
+ SkSTArenaAlloc<64> arena;
REPORTER_ASSERT(r, *arena.make<int>(3) == 3);
Foo* foo = arena.make<Foo>(3, 4.0f);
REPORTER_ASSERT(r, destroyed == 11);
{
- char storage[64];
- SkArenaAlloc arena{storage};
+ SkSTArenaAlloc<64> arena;
arena.makeArrayDefault<char>(256);
arena.reset();
arena.reset();
{
created = 0;
destroyed = 0;
- char storage[64];
- SkArenaAlloc arena{storage};
+ SkSTArenaAlloc<64> arena;
Start start;
Node* current = nullptr;
{
created = 0;
destroyed = 0;
- char storage[64];
- SkArenaAlloc arena{storage};
+ SkSTArenaAlloc<64> arena;
sk_sp<FooRefCnt> f = arena.makeSkSp<FooRefCnt>(4, 5.0f);
REPORTER_ASSERT(r, f->x == 4);
}
DEF_TEST(PathOpsAngleOverlapHullsOne, reporter) {
- char storage[4096];
- SkArenaAlloc allocator(storage);
+ SkSTArenaAlloc<4096> allocator;
// gPathOpsAngleIdeasVerbose = true;
const QuadPts quads[] = {
{{{939.4808349609375, 914.355224609375}, {-357.7921142578125, 590.842529296875}, {736.8936767578125, -350.717529296875}}},
}
DEF_TEST(PathOpsAngleOverlapHulls, reporter) {
- char storage[4096];
- SkArenaAlloc allocator(storage);
+ SkSTArenaAlloc<4096> allocator;
if (!gPathOpsAngleIdeasVerbose) { // takes a while to run -- so exclude it by default
return;
}
static const int circleDataSetSize = (int) SK_ARRAY_COUNT(circleDataSet);
DEF_TEST(PathOpsAngleCircle, reporter) {
- char storage[4096];
- SkArenaAlloc allocator(storage);
+ SkSTArenaAlloc<4096> allocator;
SkOpContourHead contour;
SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
contour.init(&state, false, false);
};
DEF_TEST(PathOpsAngleAfter, reporter) {
- char storage[4096];
- SkArenaAlloc allocator(storage);
+ SkSTArenaAlloc<4096> allocator;
SkOpContourHead contour;
SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
contour.init(&state, false, false);
}
DEF_TEST(PathOpsAngleAllOnOneSide, reporter) {
- char storage[4096];
- SkArenaAlloc allocator(storage);
+ SkSTArenaAlloc<4096> allocator;
SkOpContourHead contour;
SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
contour.init(&state, false, false);