Use hairline when line width <= 1.0, instead of < 1.0.

This speeds line drawing up considerably when drawing with
default linewidth on canvas.

Review: http://codereview.appspot.com/883047/show



git-svn-id: http://skia.googlecode.com/svn/trunk@538 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
anatoly@google.com 2010-04-12 13:51:28 +00:00
parent 229d9b3953
commit a956e4fe2e
5 changed files with 44 additions and 6 deletions

View File

@ -89,14 +89,20 @@ public:
protected:
virtual void onDraw(SkCanvas* canvas) {
static const SkScalar gSizes[] = {
SkScalar gSizes[] = {
SkIntToScalar(7), 0
};
size_t sizes = SK_ARRAY_COUNT(gSizes);
if (this->hasStrokeWidth()) {
gSizes[0] = this->getStrokeWidth();
sizes = 1;
}
SkPaint paint;
paint.setStrokeCap(SkPaint::kRound_Cap);
for (size_t i = 0; i < SK_ARRAY_COUNT(gSizes); i++) {
for (size_t i = 0; i < sizes; i++) {
paint.setStrokeWidth(gSizes[i]);
this->setupPaint(&paint);
canvas->drawPoints(fMode, N * 2,
@ -132,4 +138,3 @@ static BenchRegistry gRRectReg2(RRectFactory2);
static BenchRegistry gPointsReg(PointsFactory);
static BenchRegistry gLinesReg(LinesFactory);
static BenchRegistry gPolygonReg(PolygonFactory);

View File

@ -9,6 +9,7 @@ SkBenchmark::SkBenchmark(void* defineDict) {
fForceAlpha = 0xFF;
fForceAA = true;
fDither = SkTriState::kDefault;
fHasStrokeWidth = false;
}
const char* SkBenchmark::getName() {

View File

@ -42,6 +42,19 @@ public:
fDither = state;
}
void setStrokeWidth(SkScalar width) {
strokeWidth = width;
fHasStrokeWidth = true;
}
SkScalar getStrokeWidth() {
return strokeWidth;
}
bool hasStrokeWidth() {
return fHasStrokeWidth;
}
const char* findDefine(const char* key) const;
bool findDefine32(const char* key, int32_t* value) const;
bool findDefineScalar(const char* key, SkScalar* value) const;
@ -60,9 +73,10 @@ private:
bool fForceAA;
bool fForceFilter;
SkTriState::State fDither;
bool fHasStrokeWidth;
SkScalar strokeWidth;
};
typedef SkTRegistry<SkBenchmark*, void*> BenchRegistry;
#endif

View File

@ -201,6 +201,8 @@ int main (int argc, char * const argv[]) {
bool doClip = false;
bool doPict = false;
const char* matchStr = NULL;
bool hasStrokeWidth = false;
float strokeWidth;
SkString outDir;
SkBitmap::Config outConfig = SkBitmap::kNo_Config;
@ -260,6 +262,19 @@ int main (int argc, char * const argv[]) {
return -1;
}
forceAlpha = wantAlpha ? 0x80 : 0xFF;
} else if (strcmp(*argv, "-strokeWidth") == 0) {
argv++;
if (argv < stop) {
const char *strokeWidthStr = *argv;
if (sscanf(strokeWidthStr, "%f", &strokeWidth) != 1) {
log_error("bad arg for -strokeWidth\n");
return -1;
}
hasStrokeWidth = true;
} else {
log_error("missing arg for -strokeWidth\n");
return -1;
}
} else if (strcmp(*argv, "-match") == 0) {
argv++;
if (argv < stop) {
@ -314,6 +329,9 @@ int main (int argc, char * const argv[]) {
bench->setForceAA(forceAA);
bench->setForceFilter(forceFilter);
bench->setDither(forceDither);
if (hasStrokeWidth) {
bench->setStrokeWidth(strokeWidth);
}
// only run benchmarks if their name contains matchStr
if (matchStr && strstr(bench->getName(), matchStr) == NULL) {

View File

@ -789,7 +789,7 @@ static bool map_radius(const SkMatrix& matrix, SkScalar* value) {
matrix.mapVectors(dst, src, 2);
SkScalar len0 = fast_len(dst[0]);
SkScalar len1 = fast_len(dst[1]);
if (len0 < SK_Scalar1 && len1 < SK_Scalar1) {
if (len0 <= SK_Scalar1 && len1 <= SK_Scalar1) {
*value = SkScalarAve(len0, len1);
return true;
}