#include "SkPoint.h"
#include "SkColor.h"
-class SkCanvas;
-class SkPaint;
+class SkArenaAlloc;
+class SkCanvas;
+class SkPaint;
struct SkRect;
-class SkString;
+class SkString;
/** \class SkDrawLooper
Subclasses of SkDrawLooper can be attached to a SkPaint. Where they are,
/**
* Called right before something is being drawn. Returns a Context
* whose next() method should be called until it returns false.
- * The caller has to ensure that the storage pointer provides enough
- * memory for the Context. The required size can be queried by calling
- * contextSize(). It is also the caller's responsibility to destroy the
- * object after use.
*/
- virtual Context* createContext(SkCanvas*, void* storage) const = 0;
-
- /**
- * Returns the number of bytes needed to store subclasses of Context (belonging to the
- * corresponding SkDrawLooper subclass).
- */
- virtual size_t contextSize() const = 0;
-
+ virtual Context* makeContext(SkCanvas*, SkArenaAlloc*) const = 0;
/**
* The fast bounds functions are used to enable the paint to be culled early
#include "SkDrawLooper.h"
#include "SkColor.h"
+class SkArenaAlloc;
class SkMaskFilter;
class SkColorFilter;
return sk_sp<SkDrawLooper>(new SkBlurDrawLooper(color, sigma, dx, dy, flags));
}
- SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const override;
-
- size_t contextSize() const override { return sizeof(BlurDrawLooperContext); }
+ SkDrawLooper::Context* makeContext(SkCanvas*, SkArenaAlloc*) const override;
SK_TO_STRING_OVERRIDE()
SK_DECLARE_PUBLIC_FLATTENABLE_DESERIALIZATION_PROCS(SkBlurDrawLooper)
LayerInfo();
};
- SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const override;
-
- size_t contextSize() const override { return sizeof(LayerDrawLooperContext); }
+ SkDrawLooper::Context* makeContext(SkCanvas*, SkArenaAlloc*) const override;
bool asABlurShadow(BlurShadowRec* rec) const override;
* found in the LICENSE file.
*/
+#include "SkArenaAlloc.h"
#include "SkBitmapDevice.h"
#include "SkCanvas.h"
#include "SkCanvasPriv.h"
#include "SkRRect.h"
#include "SkShadowPaintFilterCanvas.h"
#include "SkShadowShader.h"
-#include "SkSmallAllocator.h"
#include "SkSpecialImage.h"
#include "SkSurface_Base.h"
#include "SkTextBlob.h"
}
if (SkDrawLooper* looper = paint.getLooper()) {
- fLooperContext = fLooperContextAllocator.createWithIniter(
- looper->contextSize(),
- [&](void* buffer) {
- return looper->createContext(canvas, buffer);
- });
+ fLooperContext = looper->makeContext(canvas, &fAlloc);
fIsSimple = false;
} else {
fLooperContext = nullptr;
}
private:
- SkLazyPaint fLazyPaintInit; // base paint storage in case we need to modify it
+ SkLazyPaint fLazyPaintInit; // base paint storage in case we need to modify it
SkLazyPaint fLazyPaintPerLooper; // per-draw-looper storage, so the looper can modify it
SkCanvas* fCanvas;
const SkPaint& fOrigPaint;
bool fDone;
bool fIsSimple;
SkDrawLooper::Context* fLooperContext;
- SkSmallAllocator<1, 32> fLooperContextAllocator;
+ char fStorage[48];
+ SkArenaAlloc fAlloc {fStorage};
bool doNext(SkDrawFilter::Type drawType);
};
* found in the LICENSE file.
*/
+#include "SkArenaAlloc.h"
#include "SkDrawLooper.h"
#include "SkCanvas.h"
#include "SkMatrix.h"
#include "SkPaint.h"
#include "SkRect.h"
-#include "SkSmallAllocator.h"
bool SkDrawLooper::canComputeFastBounds(const SkPaint& paint) const {
SkCanvas canvas;
- SkSmallAllocator<1, 32> allocator;
+ char storage[48];
+ SkArenaAlloc alloc {storage};
- SkDrawLooper::Context* context = allocator.createWithIniter(
- this->contextSize(),
- [&](void* buffer) {
- return this->createContext(&canvas, buffer);
- });
+ SkDrawLooper::Context* context = this->makeContext(&canvas, &alloc);
for (;;) {
SkPaint p(paint);
if (context->next(&canvas, &p)) {
const SkRect src = s;
SkCanvas canvas;
- SkSmallAllocator<1, 32> allocator;
+ char storage[48];
+ SkArenaAlloc alloc {storage};
*dst = src; // catch case where there are no loops
- SkDrawLooper::Context* context = allocator.createWithIniter(
- this->contextSize(),
- [&](void* buffer) {
- return this->createContext(&canvas, buffer);
- });
+ SkDrawLooper::Context* context = this->makeContext(&canvas, &alloc);
+
for (bool firstTime = true;; firstTime = false) {
SkPaint p(paint);
if (context->next(&canvas, &p)) {
* found in the LICENSE file.
*/
+#include "SkArenaAlloc.h"
#include "SkBlurDrawLooper.h"
#include "SkBlurMask.h" // just for SkBlurMask::ConvertRadiusToSigma
#include "SkBlurMaskFilter.h"
////////////////////////////////////////////////////////////////////////////////////////
-SkDrawLooper::Context* SkBlurDrawLooper::createContext(SkCanvas*, void* storage) const {
- return new (storage) BlurDrawLooperContext(this);
+
+SkDrawLooper::Context* SkBlurDrawLooper::makeContext(SkCanvas*, SkArenaAlloc* alloc) const {
+ return alloc->make<BlurDrawLooperContext>(this);
}
SkBlurDrawLooper::BlurDrawLooperContext::BlurDrawLooperContext(
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
+#include "SkArenaAlloc.h"
#include "SkCanvas.h"
#include "SkColor.h"
#include "SkReadBuffer.h"
}
}
-SkLayerDrawLooper::Context* SkLayerDrawLooper::createContext(SkCanvas* canvas, void* storage) const {
+SkLayerDrawLooper::Context*
+SkLayerDrawLooper::makeContext(SkCanvas* canvas, SkArenaAlloc* alloc) const {
canvas->save();
- return new (storage) LayerDrawLooperContext(this);
+ return alloc->make<LayerDrawLooperContext>(this);
}
static SkColor xferColor(SkColor src, SkColor dst, SkBlendMode mode) {
* found in the LICENSE file.
*/
+#include "SkArenaAlloc.h"
#include "SkBitmap.h"
#include "SkBitmapDevice.h"
#include "SkCanvas.h"
#include "SkRect.h"
#include "SkRefCnt.h"
#include "SkScalar.h"
-#include "SkSmallAllocator.h"
#include "Test.h"
static SkBitmap make_bm(int w, int h) {
SkCanvas canvas(&device);
SkPaint paint;
auto looper(looperBuilder.detach());
- SkSmallAllocator<1, 32> allocator;
- SkDrawLooper::Context* context = allocator.createWithIniter(
- looper->contextSize(),
- [&](void* buffer) {
- return looper->createContext(&canvas, buffer);
- });
+ SkArenaAlloc alloc{48};
+ SkDrawLooper::Context* context = looper->makeContext(&canvas, &alloc);
// The back layer should come first.
REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
SkCanvas canvas(&device);
SkPaint paint;
auto looper(looperBuilder.detach());
- SkSmallAllocator<1, 32> allocator;
- SkDrawLooper::Context* context = allocator.createWithIniter(
- looper->contextSize(),
- [&](void* buffer) {
- return looper->createContext(&canvas, buffer);
- });
+ SkArenaAlloc alloc{48};
+ SkDrawLooper::Context* context = looper->makeContext(&canvas, &alloc);
// The back layer should come first.
REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
SkCanvas canvas(&device);
SkPaint paint;
sk_sp<SkDrawLooper> looper(looperBuilder.detach());
- SkSmallAllocator<1, 32> allocator;
- SkDrawLooper::Context* context = allocator.createWithIniter(
- looper->contextSize(),
- [&](void* buffer) {
- return looper->createContext(&canvas, buffer);
- });
+ SkArenaAlloc alloc{48};
+ SkDrawLooper::Context* context = looper->makeContext(&canvas, &alloc);
// The back layer should come first.
REPORTER_ASSERT(reporter, context->next(&canvas, &paint));
* found in the LICENSE file.
*/
+#include "SkArenaAlloc.h"
#include "SkCanvas.h"
#include "SkDrawLooper.h"
#include "SkLightingImageFilter.h"
class TestLooper : public SkDrawLooper {
public:
- SkDrawLooper::Context* createContext(SkCanvas*, void* storage) const override {
- return new (storage) TestDrawLooperContext;
+ SkDrawLooper::Context* makeContext(SkCanvas*, SkArenaAlloc* alloc) const override {
+ return alloc->make<TestDrawLooperContext>();
}
- size_t contextSize() const override { return sizeof(TestDrawLooperContext); }
-
#ifndef SK_IGNORE_TO_STRING
void toString(SkString* str) const override {
str->append("TestLooper:");