aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2017-03-01 13:44:39 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-01 19:36:08 +0000
commit4b1b04d8ecb3dd8c67d9e1724e7a1898a51dbf32 (patch)
tree331d25f0d0ed69d60231ef3b0df5f7d0a8b99786
parent24429c68c56683252e3fc2a79d9b660eaf96ec0c (diff)
Use SkArenaAlloc in SkEdgeBuilder.
Change-Id: Ie3557469d018b857dc6fb4543d367fcd8768f0b7 Reviewed-on: https://skia-review.googlesource.com/9115 Reviewed-by: Yuqian Li <liyuqian@google.com> Commit-Queue: Herb Derby <herb@google.com>
-rw-r--r--src/core/SkEdgeBuilder.cpp30
-rw-r--r--src/core/SkEdgeBuilder.h4
2 files changed, 14 insertions, 20 deletions
diff --git a/src/core/SkEdgeBuilder.cpp b/src/core/SkEdgeBuilder.cpp
index 22942f4d2a..ceb8f1ad31 100644
--- a/src/core/SkEdgeBuilder.cpp
+++ b/src/core/SkEdgeBuilder.cpp
@@ -12,10 +12,6 @@
#include "SkLineClipper.h"
#include "SkGeometry.h"
-template <typename T> static T* typedAllocThrow(SkChunkAlloc& alloc) {
- return static_cast<T*>(alloc.allocThrow(sizeof(T)));
-}
-
///////////////////////////////////////////////////////////////////////////////
SkEdgeBuilder::SkEdgeBuilder() : fAlloc(16*1024) {
@@ -125,7 +121,7 @@ bool SkEdgeBuilder::vertical_line(const SkAnalyticEdge* edge) {
void SkEdgeBuilder::addLine(const SkPoint pts[]) {
if (fAnalyticAA) {
- SkAnalyticEdge* edge = typedAllocThrow<SkAnalyticEdge>(fAlloc);
+ SkAnalyticEdge* edge = fAlloc.make<SkAnalyticEdge>();
if (edge->setLine(pts[0], pts[1])) {
if (vertical_line(edge) && fList.count()) {
Combine combine = CombineVertical(edge, (SkAnalyticEdge*)*(fList.end() - 1));
@@ -143,7 +139,7 @@ unallocate_analytic_edge:
// TODO: unallocate edge from storage...
}
} else {
- SkEdge* edge = typedAllocThrow<SkEdge>(fAlloc);
+ SkEdge* edge = fAlloc.make<SkEdge>();
if (edge->setLine(pts[0], pts[1], fShiftUp)) {
if (vertical_line(edge) && fList.count()) {
Combine combine = CombineVertical(edge, (SkEdge*)*(fList.end() - 1));
@@ -165,14 +161,14 @@ unallocate_edge:
void SkEdgeBuilder::addQuad(const SkPoint pts[]) {
if (fAnalyticAA) {
- SkAnalyticQuadraticEdge* edge = typedAllocThrow<SkAnalyticQuadraticEdge>(fAlloc);
+ SkAnalyticQuadraticEdge* edge = fAlloc.make<SkAnalyticQuadraticEdge>();
if (edge->setQuadratic(pts)) {
fList.push(edge);
} else {
// TODO: unallocate edge from storage...
}
} else {
- SkQuadraticEdge* edge = typedAllocThrow<SkQuadraticEdge>(fAlloc);
+ SkQuadraticEdge* edge = fAlloc.make<SkQuadraticEdge>();
if (edge->setQuadratic(pts, fShiftUp)) {
fList.push(edge);
} else {
@@ -183,14 +179,14 @@ void SkEdgeBuilder::addQuad(const SkPoint pts[]) {
void SkEdgeBuilder::addCubic(const SkPoint pts[]) {
if (fAnalyticAA) {
- SkAnalyticCubicEdge* edge = typedAllocThrow<SkAnalyticCubicEdge>(fAlloc);
+ SkAnalyticCubicEdge* edge = fAlloc.make<SkAnalyticCubicEdge>();
if (edge->setCubic(pts)) {
fList.push(edge);
} else {
// TODO: unallocate edge from storage...
}
} else {
- SkCubicEdge* edge = typedAllocThrow<SkCubicEdge>(fAlloc);
+ SkCubicEdge* edge = fAlloc.make<SkCubicEdge>();
if (edge->setCubic(pts, fShiftUp)) {
fList.push(edge);
} else {
@@ -254,15 +250,13 @@ int SkEdgeBuilder::buildPoly(const SkPath& path, const SkIRect* iclip, int shift
// segments.
maxEdgeCount *= SkLineClipper::kMaxClippedLineSegments;
}
+
size_t edgeSize = fAnalyticAA ? sizeof(SkAnalyticEdge) : sizeof(SkEdge);
- size_t maxEdgeSize = maxEdgeCount * edgeSize;
- size_t maxEdgePtrSize = maxEdgeCount * sizeof(char*);
+ char* edge = fAnalyticAA ? (char*)fAlloc.makeArrayDefault<SkAnalyticEdge>(maxEdgeCount)
+ : (char*)fAlloc.makeArrayDefault<SkEdge>(maxEdgeCount);
- // lets store the edges and their pointers in the same block
- char* storage = (char*)fAlloc.allocThrow(maxEdgeSize + maxEdgePtrSize);
- char* edge = (char*)storage;
- char** edgePtr = (char**)(storage + maxEdgeSize);
- // Record the beginning of our pointers, so we can return them to the caller
+ SkDEBUGCODE(char* edgeStart = edge);
+ char** edgePtr = fAlloc.makeArrayDefault<char*>(maxEdgeCount);
fEdgeList = (void**)edgePtr;
if (iclip) {
@@ -334,7 +328,7 @@ int SkEdgeBuilder::buildPoly(const SkPath& path, const SkIRect* iclip, int shift
}
}
}
- SkASSERT((char*)edge <= (char*)fEdgeList);
+ SkASSERT((size_t)(edge - edgeStart) <= maxEdgeCount * edgeSize);
SkASSERT(edgePtr - (char**)fEdgeList <= maxEdgeCount);
return SkToInt(edgePtr - (char**)fEdgeList);
}
diff --git a/src/core/SkEdgeBuilder.h b/src/core/SkEdgeBuilder.h
index 097e796de7..413d873423 100644
--- a/src/core/SkEdgeBuilder.h
+++ b/src/core/SkEdgeBuilder.h
@@ -7,7 +7,7 @@
#ifndef SkEdgeBuilder_DEFINED
#define SkEdgeBuilder_DEFINED
-#include "SkChunkAlloc.h"
+#include "SkArenaAlloc.h"
#include "SkRect.h"
#include "SkTDArray.h"
@@ -42,7 +42,7 @@ private:
bool vertical_line(const SkEdge* edge);
bool vertical_line(const SkAnalyticEdge* edge);
- SkChunkAlloc fAlloc;
+ SkArenaAlloc fAlloc;
SkTDArray<void*> fList;
/*