Combine some duplicate code in AA using template

BUG=skia:

Change-Id: Id048425e8199167feba0268f89f526bbf5b7242b
Reviewed-on: https://skia-review.googlesource.com/9832
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Yuqian Li <liyuqian@google.com>
This commit is contained in:
Yuqian Li 2017-03-17 11:26:29 -04:00 committed by Skia Commit-Bot
parent 5f3b94074e
commit a33b43d796
3 changed files with 40 additions and 68 deletions

View File

@ -38,4 +38,43 @@ void sk_fill_path(const SkPath& path, const SkIRect& clipRect,
void sk_blit_above(SkBlitter*, const SkIRect& avoid, const SkRegion& clip);
void sk_blit_below(SkBlitter*, const SkIRect& avoid, const SkRegion& clip);
template<class EdgeType>
static inline void remove_edge(EdgeType* edge) {
edge->fPrev->fNext = edge->fNext;
edge->fNext->fPrev = edge->fPrev;
}
template<class EdgeType>
static inline void insert_edge_after(EdgeType* edge, EdgeType* afterMe) {
edge->fPrev = afterMe;
edge->fNext = afterMe->fNext;
afterMe->fNext->fPrev = edge;
afterMe->fNext = edge;
}
template<class EdgeType>
static void backward_insert_edge_based_on_x(EdgeType* edge) {
SkFixed x = edge->fX;
EdgeType* prev = edge->fPrev;
while (prev->fPrev && prev->fX > x) {
prev = prev->fPrev;
}
if (prev->fNext != edge) {
remove_edge(edge);
insert_edge_after(edge, prev);
}
}
// Start from the right side, searching backwards for the point to begin the new edge list
// insertion, marching forwards from here. The implementation could have started from the left
// of the prior insertion, and search to the right, or with some additional caching, binary
// search the starting point. More work could be done to determine optimal new edge insertion.
template<class EdgeType>
static EdgeType* backward_insert_start(EdgeType* prev, SkFixed x) {
while (prev->fPrev && prev->fX > x) {
prev = prev->fPrev;
}
return prev;
}
#endif

View File

@ -1232,37 +1232,6 @@ END_WALK:
///////////////////////////////////////////////////////////////////////////////
static inline void remove_edge(SkAnalyticEdge* edge) {
edge->fPrev->fNext = edge->fNext;
edge->fNext->fPrev = edge->fPrev;
}
static inline void insert_edge_after(SkAnalyticEdge* edge, SkAnalyticEdge* afterMe) {
edge->fPrev = afterMe;
edge->fNext = afterMe->fNext;
afterMe->fNext->fPrev = edge;
afterMe->fNext = edge;
}
static void backward_insert_edge_based_on_x(SkAnalyticEdge* edge) {
SkFixed x = edge->fX;
SkAnalyticEdge* prev = edge->fPrev;
while (prev->fPrev && prev->fX > x) {
prev = prev->fPrev;
}
if (prev->fNext != edge) {
remove_edge(edge);
insert_edge_after(edge, prev);
}
}
static SkAnalyticEdge* backward_insert_start(SkAnalyticEdge* prev, SkFixed x) {
while (prev->fPrev && prev->fX > x) {
prev = prev->fPrev;
}
return prev;
}
static inline void updateNextNextY(SkFixed y, SkFixed nextY, SkFixed* nextNextY) {
*nextNextY = y > nextY && y < *nextNextY ? y : *nextNextY;
}

View File

@ -36,42 +36,6 @@
#define validate_sort(edge)
#endif
static inline void remove_edge(SkEdge* edge) {
edge->fPrev->fNext = edge->fNext;
edge->fNext->fPrev = edge->fPrev;
}
static inline void insert_edge_after(SkEdge* edge, SkEdge* afterMe) {
edge->fPrev = afterMe;
edge->fNext = afterMe->fNext;
afterMe->fNext->fPrev = edge;
afterMe->fNext = edge;
}
static void backward_insert_edge_based_on_x(SkEdge* edge SkDECLAREPARAM(int, curr_y)) {
SkFixed x = edge->fX;
SkEdge* prev = edge->fPrev;
while (prev->fX > x) {
prev = prev->fPrev;
}
if (prev->fNext != edge) {
remove_edge(edge);
insert_edge_after(edge, prev);
}
}
// Start from the right side, searching backwards for the point to begin the new edge list
// insertion, marching forwards from here. The implementation could have started from the left
// of the prior insertion, and search to the right, or with some additional caching, binary
// search the starting point. More work could be done to determine optimal new edge insertion.
static SkEdge* backward_insert_start(SkEdge* prev, SkFixed x) {
while (prev->fX > x) {
prev = prev->fPrev;
}
return prev;
}
static void insert_new_edges(SkEdge* newEdge, int curr_y) {
if (newEdge->fFirstY != curr_y) {
return;
@ -191,7 +155,7 @@ static void walk_edges(SkEdge* prevHead, SkPath::FillType fillType,
currE->fX = newX;
NEXT_X:
if (newX < prevX) { // ripple currE backwards until it is x-sorted
backward_insert_edge_based_on_x(currE SkPARAM(curr_y));
backward_insert_edge_based_on_x(currE);
} else {
prevX = newX;
}