aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2017-03-01 16:48:12 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-06 19:48:56 +0000
commit38c60180241e335e368fdadbf7856aff114ff668 (patch)
tree46b5945d5390ee1296dfe0991209a2e3eb57d070 /src
parentf12248ab10a8eba612b1cde8b1177de45bc712c7 (diff)
Move from SkChunkAlloc to SkArenaAlloc for PathOps
Change-Id: Iab111a4ebcae4e896b1fdfe285def9ef0ae2ab6b Reviewed-on: https://skia-review.googlesource.com/7314 Reviewed-by: Cary Clark <caryclark@google.com> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/pathops/SkOpBuilder.cpp10
-rw-r--r--src/pathops/SkOpContour.cpp4
-rw-r--r--src/pathops/SkOpContour.h2
-rw-r--r--src/pathops/SkOpSegment.h6
-rw-r--r--src/pathops/SkOpSpan.h2
-rw-r--r--src/pathops/SkOpTAllocator.h18
-rw-r--r--src/pathops/SkPathOpsOp.cpp3
-rw-r--r--src/pathops/SkPathOpsSimplify.cpp3
-rw-r--r--src/pathops/SkPathOpsTSect.h24
-rw-r--r--src/pathops/SkPathOpsTightBounds.cpp3
-rw-r--r--src/pathops/SkPathOpsTypes.cpp3
-rw-r--r--src/pathops/SkPathOpsTypes.h8
-rw-r--r--src/pathops/SkPathOpsWinding.cpp7
13 files changed, 47 insertions, 46 deletions
diff --git a/src/pathops/SkOpBuilder.cpp b/src/pathops/SkOpBuilder.cpp
index abff9827d5..c4eb0a91b5 100644
--- a/src/pathops/SkOpBuilder.cpp
+++ b/src/pathops/SkOpBuilder.cpp
@@ -5,6 +5,7 @@
* found in the LICENSE file.
*/
+#include "SkArenaAlloc.h"
#include "SkMatrix.h"
#include "SkOpEdgeBuilder.h"
#include "SkPathPriv.h"
@@ -12,10 +13,10 @@
#include "SkPathOpsCommon.h"
static bool one_contour(const SkPath& path) {
- SkChunkAlloc allocator(256);
+ char storage[256];
+ SkArenaAlloc allocator(storage);
int verbCount = path.countVerbs();
- uint8_t* verbs = (uint8_t*) allocator.alloc(sizeof(uint8_t) * verbCount,
- SkChunkAlloc::kThrow_AllocFailType);
+ uint8_t* verbs = (uint8_t*) allocator.makeArrayDefault<uint8_t>(verbCount);
(void) path.getVerbs(verbs, verbCount);
for (int index = 1; index < verbCount; ++index) {
if (verbs[index] == SkPath::kMove_Verb) {
@@ -50,7 +51,8 @@ bool SkOpBuilder::FixWinding(SkPath* path) {
path->setFillType(fillType);
return true;
}
- SkChunkAlloc allocator(4096);
+ char storage[4096];
+ SkArenaAlloc allocator(storage);
SkOpContourHead contourHead;
SkOpGlobalState globalState(&contourHead, &allocator SkDEBUGPARAMS(false)
SkDEBUGPARAMS(nullptr));
diff --git a/src/pathops/SkOpContour.cpp b/src/pathops/SkOpContour.cpp
index 62380ab4fa..ea1659ee2b 100644
--- a/src/pathops/SkOpContour.cpp
+++ b/src/pathops/SkOpContour.cpp
@@ -62,7 +62,7 @@ void SkOpContourBuilder::addCurve(SkPath::Verb verb, const SkPoint pts[4], SkSca
this->addLine(pts);
return;
}
- SkChunkAlloc* allocator = fContour->globalState()->allocator();
+ SkArenaAlloc* allocator = fContour->globalState()->allocator();
switch (verb) {
case SkPath::kQuad_Verb: {
SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 3);
@@ -106,7 +106,7 @@ void SkOpContourBuilder::addQuad(SkPoint pts[3]) {
void SkOpContourBuilder::flush() {
if (!fLastIsLine)
return;
- SkChunkAlloc* allocator = fContour->globalState()->allocator();
+ SkArenaAlloc* allocator = fContour->globalState()->allocator();
SkPoint* ptStorage = SkOpTAllocator<SkPoint>::AllocateArray(allocator, 2);
memcpy(ptStorage, fLastLine, sizeof(fLastLine));
(void) fContour->addLine(ptStorage);
diff --git a/src/pathops/SkOpContour.h b/src/pathops/SkOpContour.h
index a7a6beefc7..eca45aa20d 100644
--- a/src/pathops/SkOpContour.h
+++ b/src/pathops/SkOpContour.h
@@ -277,7 +277,7 @@ public:
SkDEBUGCODE(fDebugIndent -= 2);
}
- void rayCheck(const SkOpRayHit& base, SkOpRayDir dir, SkOpRayHit** hits, SkChunkAlloc* );
+ void rayCheck(const SkOpRayHit& base, SkOpRayDir dir, SkOpRayHit** hits, SkArenaAlloc*);
void reset() {
fTail = nullptr;
diff --git a/src/pathops/SkOpSegment.h b/src/pathops/SkOpSegment.h
index 17c8a8f67e..561fa80779 100644
--- a/src/pathops/SkOpSegment.h
+++ b/src/pathops/SkOpSegment.h
@@ -169,8 +169,8 @@ public:
void debugValidate() const;
#if DEBUG_COINCIDENCE_ORDER
- void debugResetCoinT() const;
- void debugSetCoinT(int, SkScalar ) const;
+ void debugResetCoinT() const;
+ void debugSetCoinT(int, SkScalar ) const;
#endif
#if DEBUG_COIN
@@ -333,7 +333,7 @@ public:
bool ptsDisjoint(double t1, const SkPoint& pt1, double t2, const SkPoint& pt2) const;
- void rayCheck(const SkOpRayHit& base, SkOpRayDir dir, SkOpRayHit** hits, SkChunkAlloc*);
+ void rayCheck(const SkOpRayHit& base, SkOpRayDir dir, SkOpRayHit** hits, SkArenaAlloc*);
void release(const SkOpSpan* );
#if DEBUG_COIN
diff --git a/src/pathops/SkOpSpan.h b/src/pathops/SkOpSpan.h
index 219020a575..fea3309598 100644
--- a/src/pathops/SkOpSpan.h
+++ b/src/pathops/SkOpSpan.h
@@ -11,7 +11,7 @@
#include "SkPathOpsTypes.h"
#include "SkPoint.h"
-class SkChunkAlloc;
+class SkArenaAlloc;
class SkOpAngle;
class SkOpContour;
class SkOpGlobalState;
diff --git a/src/pathops/SkOpTAllocator.h b/src/pathops/SkOpTAllocator.h
index e8835f02e6..599c445f12 100644
--- a/src/pathops/SkOpTAllocator.h
+++ b/src/pathops/SkOpTAllocator.h
@@ -7,26 +7,22 @@
#ifndef SkOpTAllocator_DEFINED
#define SkOpTAllocator_DEFINED
-#include "SkChunkAlloc.h"
+#include "SkArenaAlloc.h"
// T is SkOpAngle2, SkOpSpan2, or SkOpSegment2
template<typename T>
class SkOpTAllocator {
public:
- static T* Allocate(SkChunkAlloc* allocator) {
- void* ptr = allocator->allocThrow(sizeof(T));
- T* record = (T*) ptr;
- return record;
+ static T* Allocate(SkArenaAlloc* allocator) {
+ return allocator->make<T>();
}
- static T* AllocateArray(SkChunkAlloc* allocator, int count) {
- void* ptr = allocator->allocThrow(sizeof(T) * count);
- T* record = (T*) ptr;
- return record;
+ static T* AllocateArray(SkArenaAlloc* allocator, int count) {
+ return allocator->makeArrayDefault<T>(count);
}
- static T* New(SkChunkAlloc* allocator) {
- return new (Allocate(allocator)) T();
+ static T* New(SkArenaAlloc* allocator) {
+ return allocator->make<T>();
}
};
diff --git a/src/pathops/SkPathOpsOp.cpp b/src/pathops/SkPathOpsOp.cpp
index f6b08ead07..fd08aaaad1 100644
--- a/src/pathops/SkPathOpsOp.cpp
+++ b/src/pathops/SkPathOpsOp.cpp
@@ -217,7 +217,8 @@ extern void (*gVerboseFinalize)();
bool OpDebug(const SkPath& one, const SkPath& two, SkPathOp op, SkPath* result
SkDEBUGPARAMS(bool skipAssert) SkDEBUGPARAMS(const char* testName)) {
- SkChunkAlloc allocator(4096); // FIXME: add a constant expression here, tune
+ char storage[4096];
+ SkArenaAlloc allocator(storage); // FIXME: add a constant expression here, tune
SkOpContour contour;
SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour);
SkOpGlobalState globalState(contourList, &allocator
diff --git a/src/pathops/SkPathOpsSimplify.cpp b/src/pathops/SkPathOpsSimplify.cpp
index eb71e73f4a..e671ab81a9 100644
--- a/src/pathops/SkPathOpsSimplify.cpp
+++ b/src/pathops/SkPathOpsSimplify.cpp
@@ -146,7 +146,8 @@ bool SimplifyDebug(const SkPath& path, SkPath* result
return true;
}
// turn path into list of segments
- SkChunkAlloc allocator(4096); // FIXME: constant-ize, tune
+ char storage[4096];
+ SkArenaAlloc allocator(storage); // FIXME: constant-ize, tune
SkOpContour contour;
SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour);
SkOpGlobalState globalState(contourList, &allocator
diff --git a/src/pathops/SkPathOpsTSect.h b/src/pathops/SkPathOpsTSect.h
index 4f2480d62f..ef0799de4f 100644
--- a/src/pathops/SkPathOpsTSect.h
+++ b/src/pathops/SkPathOpsTSect.h
@@ -7,7 +7,7 @@
#ifndef SkPathOpsTSect_DEFINED
#define SkPathOpsTSect_DEFINED
-#include "SkChunkAlloc.h"
+#include "SkArenaAlloc.h"
#include "SkPathOpsBounds.h"
#include "SkPathOpsRect.h"
#include "SkIntersections.h"
@@ -85,7 +85,7 @@ struct SkTSpanBounded {
template<typename TCurve, typename OppCurve>
class SkTSpan {
public:
- void addBounded(SkTSpan<OppCurve, TCurve>* , SkChunkAlloc* );
+ void addBounded(SkTSpan<OppCurve, TCurve>* , SkArenaAlloc* );
double closestBoundedT(const SkDPoint& pt) const;
bool contains(double t) const;
@@ -174,11 +174,11 @@ public:
initBounds(curve);
}
- bool split(SkTSpan* work, SkChunkAlloc* heap) {
+ bool split(SkTSpan* work, SkArenaAlloc* heap) {
return splitAt(work, (work->fStartT + work->fEndT) * 0.5, heap);
}
- bool splitAt(SkTSpan* work, double t, SkChunkAlloc* heap);
+ bool splitAt(SkTSpan* work, double t, SkArenaAlloc* heap);
double startT() const {
return fStartT;
@@ -317,7 +317,7 @@ private:
void removeSpans(SkTSpan<TCurve, OppCurve>* span, SkTSect<OppCurve, TCurve>* opp);
void removedEndCheck(SkTSpan<TCurve, OppCurve>* span);
- void resetRemovedEnds() {
+ void resetRemovedEnds() {
fRemovedStartT = fRemovedEndT = false;
}
@@ -331,7 +331,7 @@ private:
void validateBounded() const;
const TCurve& fCurve;
- SkChunkAlloc fHeap;
+ SkArenaAlloc fHeap;
SkTSpan<TCurve, OppCurve>* fHead;
SkTSpan<TCurve, OppCurve>* fCoincident;
SkTSpan<TCurve, OppCurve>* fDeleted;
@@ -389,9 +389,8 @@ void SkTCoincident<TCurve, OppCurve>::setPerp(const TCurve& c1, double t,
}
template<typename TCurve, typename OppCurve>
-void SkTSpan<TCurve, OppCurve>::addBounded(SkTSpan<OppCurve, TCurve>* span, SkChunkAlloc* heap) {
- SkTSpanBounded<OppCurve, TCurve>* bounded = new (heap->allocThrow(
- sizeof(SkTSpanBounded<OppCurve, TCurve>)))(SkTSpanBounded<OppCurve, TCurve>);
+void SkTSpan<TCurve, OppCurve>::addBounded(SkTSpan<OppCurve, TCurve>* span, SkArenaAlloc* heap) {
+ SkTSpanBounded<OppCurve, TCurve>* bounded = heap->make<SkTSpanBounded<OppCurve, TCurve>>();
bounded->fBounded = span;
bounded->fNext = fBounded;
fBounded = bounded;
@@ -756,7 +755,7 @@ bool SkTSpan<TCurve, OppCurve>::removeBounded(const SkTSpan<OppCurve, TCurve>* o
}
template<typename TCurve, typename OppCurve>
-bool SkTSpan<TCurve, OppCurve>::splitAt(SkTSpan* work, double t, SkChunkAlloc* heap) {
+bool SkTSpan<TCurve, OppCurve>::splitAt(SkTSpan* work, double t, SkArenaAlloc* heap) {
fStartT = t;
fEndT = work->fEndT;
if (fStartT == fEndT) {
@@ -858,7 +857,7 @@ void SkTSpan<TCurve, OppCurve>::validatePerpPt(double t, const SkDPoint& pt) con
template<typename TCurve, typename OppCurve>
-SkTSect<TCurve, OppCurve>::SkTSect(const TCurve& c
+SkTSect<TCurve, OppCurve>::SkTSect(const TCurve& c
SkDEBUGPARAMS(SkOpGlobalState* debugGlobalState)
PATH_OPS_DEBUG_T_SECT_PARAMS(int id))
: fCurve(c)
@@ -884,8 +883,7 @@ SkTSpan<TCurve, OppCurve>* SkTSect<TCurve, OppCurve>::addOne() {
result = fDeleted;
fDeleted = result->fNext;
} else {
- result = new (fHeap.allocThrow(sizeof(SkTSpan<TCurve, OppCurve>)))(
- SkTSpan<TCurve, OppCurve>);
+ result = fHeap.make<SkTSpan<TCurve, OppCurve>>();
#if DEBUG_T_SECT
++fDebugAllocatedCount;
#endif
diff --git a/src/pathops/SkPathOpsTightBounds.cpp b/src/pathops/SkPathOpsTightBounds.cpp
index f379c9e9a7..4236d2d545 100644
--- a/src/pathops/SkPathOpsTightBounds.cpp
+++ b/src/pathops/SkPathOpsTightBounds.cpp
@@ -47,7 +47,8 @@ bool TightBounds(const SkPath& path, SkRect* result) {
*result = path.getBounds();
return true;
}
- SkChunkAlloc allocator(4096); // FIXME: constant-ize, tune
+ char storage[4096];
+ SkArenaAlloc allocator(storage); // FIXME: constant-ize, tune
SkOpContour contour;
SkOpContourHead* contourList = static_cast<SkOpContourHead*>(&contour);
SkOpGlobalState globalState(contourList, &allocator SkDEBUGPARAMS(false)
diff --git a/src/pathops/SkPathOpsTypes.cpp b/src/pathops/SkPathOpsTypes.cpp
index 5f87076c24..bddfd7e508 100644
--- a/src/pathops/SkPathOpsTypes.cpp
+++ b/src/pathops/SkPathOpsTypes.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 "SkFloatBits.h"
#include "SkOpCoincidence.h"
#include "SkPathOpsTypes.h"
@@ -225,7 +226,7 @@ double SkDCubeRoot(double x) {
}
SkOpGlobalState::SkOpGlobalState(SkOpContourHead* head,
- SkChunkAlloc* allocator
+ SkArenaAlloc* allocator
SkDEBUGPARAMS(bool debugSkipAssert)
SkDEBUGPARAMS(const char* testName))
: fAllocator(allocator)
diff --git a/src/pathops/SkPathOpsTypes.h b/src/pathops/SkPathOpsTypes.h
index f525ea49db..2fef8266c2 100644
--- a/src/pathops/SkPathOpsTypes.h
+++ b/src/pathops/SkPathOpsTypes.h
@@ -22,7 +22,7 @@ enum SkPathOpsMask {
kEvenOdd_PathOpsMask = 1
};
-class SkChunkAlloc;
+class SkArenaAlloc;
class SkOpCoincidence;
class SkOpContour;
class SkOpContourHead;
@@ -39,7 +39,7 @@ enum class SkOpPhase : char {
class SkOpGlobalState {
public:
SkOpGlobalState(SkOpContourHead* head,
- SkChunkAlloc* allocator SkDEBUGPARAMS(bool debugSkipAssert)
+ SkArenaAlloc* allocator SkDEBUGPARAMS(bool debugSkipAssert)
SkDEBUGPARAMS(const char* testName));
enum {
@@ -50,7 +50,7 @@ public:
return fAllocatedOpSpan;
}
- SkChunkAlloc* allocator() {
+ SkArenaAlloc* allocator() {
return fAllocator;
}
@@ -181,7 +181,7 @@ public:
}
private:
- SkChunkAlloc* fAllocator;
+ SkArenaAlloc* fAllocator;
SkOpCoincidence* fCoincidence;
SkOpContourHead* fContourHead;
int fNested;
diff --git a/src/pathops/SkPathOpsWinding.cpp b/src/pathops/SkPathOpsWinding.cpp
index 7a61fd56b0..724e6f47bc 100644
--- a/src/pathops/SkPathOpsWinding.cpp
+++ b/src/pathops/SkPathOpsWinding.cpp
@@ -101,7 +101,7 @@ struct SkOpRayHit {
};
void SkOpContour::rayCheck(const SkOpRayHit& base, SkOpRayDir dir, SkOpRayHit** hits,
- SkChunkAlloc* allocator) {
+ SkArenaAlloc* allocator) {
// if the bounds extreme is outside the best, we're done
SkScalar baseXY = pt_xy(base.fPt, dir);
SkScalar boundsXY = rect_side(fBounds, dir);
@@ -116,7 +116,7 @@ void SkOpContour::rayCheck(const SkOpRayHit& base, SkOpRayDir dir, SkOpRayHit**
}
void SkOpSegment::rayCheck(const SkOpRayHit& base, SkOpRayDir dir, SkOpRayHit** hits,
- SkChunkAlloc* allocator) {
+ SkArenaAlloc* allocator) {
if (!sideways_overlap(fBounds, base.fPt, dir)) {
return;
}
@@ -233,7 +233,8 @@ static double get_t_guess(int tTry, int* dirOffset) {
}
bool SkOpSpan::sortableTop(SkOpContour* contourHead) {
- SkChunkAlloc allocator(1024);
+ char storage[1024];
+ SkArenaAlloc allocator(storage);
int dirOffset;
double t = get_t_guess(fTopTTry++, &dirOffset);
SkOpRayHit hitBase;