Remove use of SkSmallAllocator from all Loopers.
authorHerb Derby <herb@google.com>
Wed, 8 Feb 2017 20:12:19 +0000 (15:12 -0500)
committerSkia Commit-Bot <skia-commit-bot@chromium.org>
Wed, 8 Feb 2017 21:08:02 +0000 (21:08 +0000)
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>

include/core/SkDrawLooper.h
include/effects/SkBlurDrawLooper.h
include/effects/SkLayerDrawLooper.h
src/core/SkCanvas.cpp
src/core/SkDrawLooper.cpp
src/effects/SkBlurDrawLooper.cpp
src/effects/SkLayerDrawLooper.cpp
tests/LayerDrawLooperTest.cpp
tests/QuickRejectTest.cpp

index 28d7d8b..0b0ae05 100644 (file)
 #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
index a429f50..84f87ae 100644 (file)
@@ -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)
index df112c8..c0a9534 100644 (file)
@@ -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;
 
index 64ef348..6c6752e 100644 (file)
@@ -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);
 };
index e372e8f..54c9af1 100644 (file)
@@ -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)) {
index e554295..4d21c00 100644 (file)
@@ -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(
index 737cdf6..5c0cf6b 100644 (file)
@@ -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) {
index 8fcbf16..2910341 100644 (file)
@@ -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));
index 452aa8b..6f472dc 100644 (file)
@@ -5,6 +5,7 @@
  * 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:");