aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2017-02-08 15:12:19 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-02-08 21:08:02 +0000
commit73fe7b07e6391da81dfc48d600d7b3141be1f471 (patch)
tree34df5836e6c9360d69a9da9293cd2823d316191a
parent16c149664d3f95e1cabded8a1b7b3d105222c236 (diff)
Remove use of SkSmallAllocator from all Loopers.
R=reed@google.com Change-Id: I22b140ee8e12900de13bc623adb30b5fca3051f9 Reviewed-on: https://skia-review.googlesource.com/7658 Reviewed-by: Mike Reed <reed@google.com> Commit-Queue: Herb Derby <herb@google.com>
-rw-r--r--include/core/SkDrawLooper.h20
-rw-r--r--include/effects/SkBlurDrawLooper.h5
-rw-r--r--include/effects/SkLayerDrawLooper.h4
-rw-r--r--src/core/SkCanvas.cpp13
-rw-r--r--src/core/SkDrawLooper.cpp21
-rw-r--r--src/effects/SkBlurDrawLooper.cpp6
-rw-r--r--src/effects/SkLayerDrawLooper.cpp6
-rw-r--r--tests/LayerDrawLooperTest.cpp26
-rw-r--r--tests/QuickRejectTest.cpp7
9 files changed, 39 insertions, 69 deletions
diff --git a/include/core/SkDrawLooper.h b/include/core/SkDrawLooper.h
index 28d7d8beef..0b0ae05868 100644
--- a/include/core/SkDrawLooper.h
+++ b/include/core/SkDrawLooper.h
@@ -15,10 +15,11 @@
#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,
@@ -61,19 +62,8 @@ public:
/**
* 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
diff --git a/include/effects/SkBlurDrawLooper.h b/include/effects/SkBlurDrawLooper.h
index a429f50b36..84f87ae243 100644
--- a/include/effects/SkBlurDrawLooper.h
+++ b/include/effects/SkBlurDrawLooper.h
@@ -12,6 +12,7 @@
#include "SkDrawLooper.h"
#include "SkColor.h"
+class SkArenaAlloc;
class SkMaskFilter;
class SkColorFilter;
@@ -40,9 +41,7 @@ public:
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)
diff --git a/include/effects/SkLayerDrawLooper.h b/include/effects/SkLayerDrawLooper.h
index df112c8394..c0a95345d4 100644
--- a/include/effects/SkLayerDrawLooper.h
+++ b/include/effects/SkLayerDrawLooper.h
@@ -71,9 +71,7 @@ public:
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;
diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp
index 64ef348e13..6c6752e636 100644
--- a/src/core/SkCanvas.cpp
+++ b/src/core/SkCanvas.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkArenaAlloc.h"
#include "SkBitmapDevice.h"
#include "SkCanvas.h"
#include "SkCanvasPriv.h"
@@ -33,7 +34,6 @@
#include "SkRRect.h"
#include "SkShadowPaintFilterCanvas.h"
#include "SkShadowShader.h"
-#include "SkSmallAllocator.h"
#include "SkSpecialImage.h"
#include "SkSurface_Base.h"
#include "SkTextBlob.h"
@@ -509,11 +509,7 @@ public:
}
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;
@@ -546,7 +542,7 @@ public:
}
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;
@@ -557,7 +553,8 @@ private:
bool fDone;
bool fIsSimple;
SkDrawLooper::Context* fLooperContext;
- SkSmallAllocator<1, 32> fLooperContextAllocator;
+ char fStorage[48];
+ SkArenaAlloc fAlloc {fStorage};
bool doNext(SkDrawFilter::Type drawType);
};
diff --git a/src/core/SkDrawLooper.cpp b/src/core/SkDrawLooper.cpp
index e372e8f157..54c9af19fa 100644
--- a/src/core/SkDrawLooper.cpp
+++ b/src/core/SkDrawLooper.cpp
@@ -5,22 +5,19 @@
* 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)) {
@@ -41,14 +38,12 @@ void SkDrawLooper::computeFastBounds(const SkPaint& paint, const SkRect& s,
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)) {
diff --git a/src/effects/SkBlurDrawLooper.cpp b/src/effects/SkBlurDrawLooper.cpp
index e55429510c..4d21c004c9 100644
--- a/src/effects/SkBlurDrawLooper.cpp
+++ b/src/effects/SkBlurDrawLooper.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkArenaAlloc.h"
#include "SkBlurDrawLooper.h"
#include "SkBlurMask.h" // just for SkBlurMask::ConvertRadiusToSigma
#include "SkBlurMaskFilter.h"
@@ -96,8 +97,9 @@ bool SkBlurDrawLooper::asABlurShadow(BlurShadowRec* rec) const {
////////////////////////////////////////////////////////////////////////////////////////
-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(
diff --git a/src/effects/SkLayerDrawLooper.cpp b/src/effects/SkLayerDrawLooper.cpp
index 737cdf6cc2..5c0cf6bf7b 100644
--- a/src/effects/SkLayerDrawLooper.cpp
+++ b/src/effects/SkLayerDrawLooper.cpp
@@ -4,6 +4,7 @@
* 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"
@@ -34,9 +35,10 @@ SkLayerDrawLooper::~SkLayerDrawLooper() {
}
}
-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) {
diff --git a/tests/LayerDrawLooperTest.cpp b/tests/LayerDrawLooperTest.cpp
index 8fcbf1615c..2910341be8 100644
--- a/tests/LayerDrawLooperTest.cpp
+++ b/tests/LayerDrawLooperTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkArenaAlloc.h"
#include "SkBitmap.h"
#include "SkBitmapDevice.h"
#include "SkCanvas.h"
@@ -15,7 +16,6 @@
#include "SkRect.h"
#include "SkRefCnt.h"
#include "SkScalar.h"
-#include "SkSmallAllocator.h"
#include "Test.h"
static SkBitmap make_bm(int w, int h) {
@@ -58,12 +58,8 @@ static void test_frontToBack(skiatest::Reporter* reporter) {
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));
@@ -101,12 +97,8 @@ static void test_backToFront(skiatest::Reporter* reporter) {
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));
@@ -144,12 +136,8 @@ static void test_mixed(skiatest::Reporter* reporter) {
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));
diff --git a/tests/QuickRejectTest.cpp b/tests/QuickRejectTest.cpp
index 452aa8b742..6f472dcd86 100644
--- a/tests/QuickRejectTest.cpp
+++ b/tests/QuickRejectTest.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkArenaAlloc.h"
#include "SkCanvas.h"
#include "SkDrawLooper.h"
#include "SkLightingImageFilter.h"
@@ -17,12 +18,10 @@
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:");