Move from SkChunkAlloc to SkArenaAlloc for PathOps
Attempt two. Remove ~SkOpContour because it is handled by the SkArenaAlloc. Change-Id: Id3049db97aebcc1009d403a031f2fac219f58f2f Reviewed-on: https://skia-review.googlesource.com/9381 Reviewed-by: Derek Sollenberger <djsollen@google.com> Commit-Queue: Herb Derby <herb@google.com>
This commit is contained in:
parent
5c7780e350
commit
c3cc5fa6de
@ -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));
|
||||
|
@ -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);
|
||||
|
@ -21,12 +21,6 @@ public:
|
||||
reset();
|
||||
}
|
||||
|
||||
~SkOpContour() {
|
||||
if (fNext) {
|
||||
fNext->~SkOpContour();
|
||||
}
|
||||
}
|
||||
|
||||
bool operator<(const SkOpContour& rh) const {
|
||||
return fBounds.fTop == rh.fBounds.fTop
|
||||
? fBounds.fLeft < rh.fBounds.fLeft
|
||||
@ -277,7 +271,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;
|
||||
|
@ -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
|
||||
|
@ -11,7 +11,7 @@
|
||||
#include "SkPathOpsTypes.h"
|
||||
#include "SkPoint.h"
|
||||
|
||||
class SkChunkAlloc;
|
||||
class SkArenaAlloc;
|
||||
class SkOpAngle;
|
||||
class SkOpContour;
|
||||
class SkOpGlobalState;
|
||||
|
@ -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>();
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -419,7 +419,7 @@ static void makeSegment(SkOpContour* contour, const SkDQuad& quad, SkPoint short
|
||||
}
|
||||
|
||||
static void testQuadAngles(skiatest::Reporter* reporter, const SkDQuad& quad1, const SkDQuad& quad2,
|
||||
int testNo, SkChunkAlloc* allocator) {
|
||||
int testNo, SkArenaAlloc* allocator) {
|
||||
SkPoint shortQuads[2][3];
|
||||
|
||||
SkOpContourHead contour;
|
||||
@ -558,7 +558,8 @@ static void testQuadAngles(skiatest::Reporter* reporter, const SkDQuad& quad1, c
|
||||
}
|
||||
|
||||
DEF_TEST(PathOpsAngleOverlapHullsOne, reporter) {
|
||||
SkChunkAlloc allocator(4096);
|
||||
char storage[4096];
|
||||
SkArenaAlloc allocator(storage);
|
||||
// gPathOpsAngleIdeasVerbose = true;
|
||||
const QuadPts quads[] = {
|
||||
{{{939.4808349609375, 914.355224609375}, {-357.7921142578125, 590.842529296875}, {736.8936767578125, -350.717529296875}}},
|
||||
@ -573,7 +574,8 @@ DEF_TEST(PathOpsAngleOverlapHullsOne, reporter) {
|
||||
}
|
||||
|
||||
DEF_TEST(PathOpsAngleOverlapHulls, reporter) {
|
||||
SkChunkAlloc allocator(4096);
|
||||
char storage[4096];
|
||||
SkArenaAlloc allocator(storage);
|
||||
if (!gPathOpsAngleIdeasVerbose) { // takes a while to run -- so exclude it by default
|
||||
return;
|
||||
}
|
||||
|
@ -239,7 +239,8 @@ static CircleData circleDataSet[] = {
|
||||
static const int circleDataSetSize = (int) SK_ARRAY_COUNT(circleDataSet);
|
||||
|
||||
DEF_TEST(PathOpsAngleCircle, reporter) {
|
||||
SkChunkAlloc allocator(4096);
|
||||
char storage[4096];
|
||||
SkArenaAlloc allocator(storage);
|
||||
SkOpContourHead contour;
|
||||
SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
|
||||
contour.init(&state, false, false);
|
||||
@ -431,7 +432,8 @@ struct FourPoints {
|
||||
};
|
||||
|
||||
DEF_TEST(PathOpsAngleAfter, reporter) {
|
||||
SkChunkAlloc allocator(4096);
|
||||
char storage[4096];
|
||||
SkArenaAlloc allocator(storage);
|
||||
SkOpContourHead contour;
|
||||
SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
|
||||
contour.init(&state, false, false);
|
||||
@ -503,7 +505,8 @@ void SkOpSegment::debugAddAngle(double startT, double endT) {
|
||||
}
|
||||
|
||||
DEF_TEST(PathOpsAngleAllOnOneSide, reporter) {
|
||||
SkChunkAlloc allocator(4096);
|
||||
char storage[4096];
|
||||
SkArenaAlloc allocator(storage);
|
||||
SkOpContourHead contour;
|
||||
SkOpGlobalState state(&contour, &allocator SkDEBUGPARAMS(false) SkDEBUGPARAMS(nullptr));
|
||||
contour.init(&state, false, false);
|
||||
|
Loading…
Reference in New Issue
Block a user