зеркало из https://github.com/mozilla/moz-skia.git
create inline version of setLine that assumes no clip. 10% faster for dashing gms
Review URL: https://codereview.appspot.com/6455078 git-svn-id: http://skia.googlecode.com/svn/trunk@4920 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
Родитель
a5e65ec434
Коммит
b6a2ba7b48
|
@ -11,6 +11,8 @@
|
|||
#define SkEdge_DEFINED
|
||||
|
||||
#include "SkRect.h"
|
||||
#include "SkFDot6.h"
|
||||
#include "SkMath.h"
|
||||
|
||||
struct SkEdge {
|
||||
enum Type {
|
||||
|
@ -33,6 +35,8 @@ struct SkEdge {
|
|||
|
||||
int setLine(const SkPoint& p0, const SkPoint& p1, const SkIRect* clip,
|
||||
int shiftUp);
|
||||
// call this version if you know you don't have a clip
|
||||
inline int setLine(const SkPoint& p0, const SkPoint& p1, int shiftUp);
|
||||
inline int updateLine(SkFixed ax, SkFixed ay, SkFixed bx, SkFixed by);
|
||||
void chopLineWithClip(const SkIRect& clip);
|
||||
|
||||
|
@ -78,4 +82,52 @@ struct SkCubicEdge : public SkEdge {
|
|||
int updateCubic();
|
||||
};
|
||||
|
||||
int SkEdge::setLine(const SkPoint& p0, const SkPoint& p1, int shift) {
|
||||
SkFDot6 x0, y0, x1, y1;
|
||||
|
||||
{
|
||||
#ifdef SK_SCALAR_IS_FLOAT
|
||||
float scale = float(1 << (shift + 6));
|
||||
x0 = int(p0.fX * scale);
|
||||
y0 = int(p0.fY * scale);
|
||||
x1 = int(p1.fX * scale);
|
||||
y1 = int(p1.fY * scale);
|
||||
#else
|
||||
shift = 10 - shift;
|
||||
x0 = p0.fX >> shift;
|
||||
y0 = p0.fY >> shift;
|
||||
x1 = p1.fX >> shift;
|
||||
y1 = p1.fY >> shift;
|
||||
#endif
|
||||
}
|
||||
|
||||
int winding = 1;
|
||||
|
||||
if (y0 > y1) {
|
||||
SkTSwap(x0, x1);
|
||||
SkTSwap(y0, y1);
|
||||
winding = -1;
|
||||
}
|
||||
|
||||
int top = SkFDot6Round(y0);
|
||||
int bot = SkFDot6Round(y1);
|
||||
|
||||
// are we a zero-height line?
|
||||
if (top == bot) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
SkFixed slope = SkFDot6Div(x1 - x0, y1 - y0);
|
||||
|
||||
fX = SkFDot6ToFixed(x0 + SkFixedMul(slope, (32 - y0) & 63)); // + SK_Fixed1/2
|
||||
fDX = slope;
|
||||
fFirstY = top;
|
||||
fLastY = bot - 1;
|
||||
fCurveCount = 0;
|
||||
fWinding = SkToS8(winding);
|
||||
fCurveShift = 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -24,7 +24,7 @@ SkEdgeBuilder::SkEdgeBuilder() : fAlloc(16*1024) {
|
|||
|
||||
void SkEdgeBuilder::addLine(const SkPoint pts[]) {
|
||||
SkEdge* edge = typedAllocThrow<SkEdge>(fAlloc);
|
||||
if (edge->setLine(pts[0], pts[1], NULL, fShiftUp)) {
|
||||
if (edge->setLine(pts[0], pts[1], fShiftUp)) {
|
||||
fList.push(edge);
|
||||
} else {
|
||||
// TODO: unallocate edge from storage...
|
||||
|
@ -118,7 +118,7 @@ int SkEdgeBuilder::buildPoly(const SkPath& path, const SkIRect* iclip,
|
|||
int lineCount = SkLineClipper::ClipLine(pts, clip, lines);
|
||||
SkASSERT(lineCount <= SkLineClipper::kMaxClippedLineSegments);
|
||||
for (int i = 0; i < lineCount; i++) {
|
||||
if (edge->setLine(lines[i], lines[i + 1], NULL, shiftUp)) {
|
||||
if (edge->setLine(lines[i], lines[i + 1], shiftUp)) {
|
||||
*edgePtr++ = edge++;
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ int SkEdgeBuilder::buildPoly(const SkPath& path, const SkIRect* iclip,
|
|||
// the corresponding line/quad/cubic verbs
|
||||
break;
|
||||
case SkPath::kLine_Verb:
|
||||
if (edge->setLine(pts[0], pts[1], NULL, shiftUp)) {
|
||||
if (edge->setLine(pts[0], pts[1], shiftUp)) {
|
||||
*edgePtr++ = edge++;
|
||||
}
|
||||
break;
|
||||
|
|
Загрузка…
Ссылка в новой задаче